private void writePluginManagement(PluginManagement pluginManagement, String tagName, XmlSerializer serializer) throws java.io.IOException { serializer.startTag(NAMESPACE, tagName); flush(serializer); StringBuffer b = b(serializer); int start = b.length(); if ((pluginManagement.getPlugins() != null) && (pluginManagement.getPlugins().size() > 0)) { serializer.startTag(NAMESPACE, "plugins"); for (Iterator iter = pluginManagement.getPlugins().iterator(); iter.hasNext();) { Plugin o = (Plugin) iter.next(); writePlugin(o, "plugin", serializer); } serializer.endTag(NAMESPACE, "plugins"); } serializer.endTag(NAMESPACE, tagName).flush(); logLocation(pluginManagement, "", start, b.length()); }
private Map<String, String> collectManaged(Project prj) { NbMavenProject project = prj.getLookup().lookup(NbMavenProject.class); Map<String, String> toRet = new HashMap<String, String>(); if (project == null) { //#154462 return toRet; } PluginManagement pluginManagement = project.getMavenProject().getPluginManagement(); if (pluginManagement == null) { // #189404 return toRet; } for (org.apache.maven.model.Plugin plg : pluginManagement.getPlugins()) { if (plg.getGroupId().equals(Constants.GROUP_APACHE_PLUGINS)) { continue; // #189261 - might be from superpom } toRet.put(plg.getKey(), plg.getVersion()); } return toRet; }
private Multimap<ArtifactCoordinates, ArtifactCoordinates> getSnapshotsFromManagement(MavenProject project, PomPropertyResolver propertyResolver) { this.log.debug("\t\tChecking managed plugins"); Multimap<ArtifactCoordinates, ArtifactCoordinates> result = HashMultimap.create(); Build build = project.getBuild(); if (build != null) { PluginManagement pluginManagement = build.getPluginManagement(); if (pluginManagement != null) { for (Plugin plugin : pluginManagement.getPlugins()) { Collection<Dependency> snapshots = Collections2.filter(plugin.getDependencies(), new IsSnapshotDependency(propertyResolver)); if (!snapshots.isEmpty()) { result.putAll(PluginToCoordinates.INSTANCE.apply(plugin), Collections2.transform(snapshots, DependencyToCoordinates.INSTANCE)); } } } } return result; }
private Multimap<ArtifactCoordinates, ArtifactCoordinates> getSnapshotsFromManagement(Profile profile, PomPropertyResolver propertyResolver) { this.log.debug("\t\tChecking managed plugins of profile '" + profile.getId() + "'"); Multimap<ArtifactCoordinates, ArtifactCoordinates> result = HashMultimap.create(); BuildBase build = profile.getBuild(); if (build != null) { PluginManagement pluginManagement = build.getPluginManagement(); if (pluginManagement != null) { for (Plugin plugin : pluginManagement.getPlugins()) { Collection<Dependency> snapshots = Collections2.filter(plugin.getDependencies(), new IsSnapshotDependency(propertyResolver)); if (!snapshots.isEmpty()) { result.putAll(PluginToCoordinates.INSTANCE.apply(plugin), Collections2.transform(snapshots, DependencyToCoordinates.INSTANCE)); } } } } return result; }
private void visitBuildPluginManagement( ModelVisitor visitor, PluginManagement pluginManagement ) { List<Plugin> plugins = pluginManagement.getPlugins(); if ( plugins != null ) { ListIterator<Plugin> pluginIterator = plugins.listIterator(); while ( pluginIterator.hasNext() ) { Plugin plugin = pluginIterator.next(); visitor.visitBuildPluginManagementPlugin( plugin ); visitBuildPluginManagementPlugin( visitor, plugin ); plugin = visitor.replaceBuildPluginManagementPlugin( plugin ); if ( plugin == null ) pluginIterator.remove(); else pluginIterator.set( plugin ); } } }
private void visitProfileBuildPluginManagement( ModelVisitor visitor, PluginManagement pluginManagement ) { List<Plugin> plugins = pluginManagement.getPlugins(); if ( plugins != null ) { ListIterator<Plugin> pluginIterator = plugins.listIterator(); while ( pluginIterator.hasNext() ) { Plugin plugin = pluginIterator.next(); visitor.visitProfileBuildPluginManagementPlugin( plugin ); visitProfileBuildPluginManagementPlugin( visitor, plugin ); plugin = visitor.replaceProfileBuildPluginManagementPlugin( plugin ); if ( plugin == null ) pluginIterator.remove(); else pluginIterator.set( plugin ); } } }
/** * Returns the rule configurations from the <tt>pluginManagement</tt> as well * as the <tt>plugins</tt> section. * * @param build the build to inspect. * @return configuration of the rules, may be an empty list. */ final List<Xpp3Dom> getRuleConfigurations( final Build build ) { @SuppressWarnings( "unchecked" ) final Map<String, Plugin> plugins = build.getPluginsAsMap(); final List<Xpp3Dom> ruleConfigurationsForPlugins = getRuleConfigurations( plugins ); final PluginManagement pluginManagement = build.getPluginManagement(); if ( pluginManagement != null ) { @SuppressWarnings( "unchecked" ) final Map<String, Plugin> pluginsFromManagementAsMap = pluginManagement.getPluginsAsMap(); List<Xpp3Dom> ruleConfigurationsFromManagement = getRuleConfigurations( pluginsFromManagementAsMap ); ruleConfigurationsForPlugins.addAll( ruleConfigurationsFromManagement ); } return ruleConfigurationsForPlugins; }
/** * Test of execute method, of class RequirePropertyDiverges. */ @Test public void testExecuteInParentWithConfigurationInPluginManagement() throws EnforcerRuleException { RequirePropertyDiverges mockInstance = createMockRule(); final MavenProject project = createMavenProject( "company", "company-parent-pom" ); final Build build = new Build(); // create pluginManagement final Plugin pluginInManagement = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0"); final Xpp3Dom configuration = createPluginConfiguration(); pluginInManagement.setConfiguration( configuration ); final PluginManagement pluginManagement = new PluginManagement(); pluginManagement.addPlugin( pluginInManagement ); build.setPluginManagement( pluginManagement ); // create plugins final Plugin pluginInPlugins = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0"); build.addPlugin( pluginInPlugins ); // add build project.getOriginalModel().setBuild( build ); //project.getOriginalModel().setBuild( build ); setUpHelper( project, "parentValue" ); mockInstance.execute( helper ); }
/** * Test of execute method, of class RequirePropertyDiverges. */ @Test public void testExecuteInParentWithConfigurationInExecution() throws EnforcerRuleException { RequirePropertyDiverges mockInstance = createMockRule(); final MavenProject project = createMavenProject( "company", "company-parent-pom" ); final Build build = new Build(); build.setPluginManagement( new PluginManagement() ); final Plugin plugin = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0" ); final Xpp3Dom configuration = createPluginConfiguration(); PluginExecution pluginExecution = new PluginExecution(); pluginExecution.setConfiguration( configuration ); plugin.addExecution( pluginExecution ); build.addPlugin( plugin ); project.getOriginalModel().setBuild( build ); setUpHelper(project, "parentValue"); mockInstance.execute( helper ); }
/** * This method will scan the plugins in the pluginManagement section of this project and return a fully * resolved list. Note that while updating the {@link Plugin} reference returned will be reflected in * the Model as it is the same object, if you wish to remove or add items to the Model then you must * use {@link #getModel()} * * @param session MavenSessionHandler, used by {@link PropertyResolver} * @return a list of fully resolved {@link ProjectVersionRef} to the original {@link Plugin} * @throws ManipulationException if an error occurs */ public HashMap<ProjectVersionRef, Plugin> getResolvedManagedPlugins ( MavenSessionHandler session) throws ManipulationException { if ( resolvedManagedPlugins == null ) { resolvedManagedPlugins = new HashMap<>( ); if ( getModel().getBuild() != null ) { final PluginManagement pm = getModel().getBuild().getPluginManagement(); if ( !( pm == null || pm.getPlugins() == null ) ) { resolvePlugins( session, pm.getPlugins(), resolvedManagedPlugins ); } } } return resolvedManagedPlugins; }
/** * This method will scan the plugins in the pluginManagement section in the potentially active Profiles * in this project and return a fully resolved list. Note that while updating the {@link Plugin} * reference returned will be reflected in the Model as it is the same object, if you wish to remove * or add items to the Model then you must use {@link #getModel()} * * @param session MavenSessionHandler, used by {@link PropertyResolver} * @return a list of fully resolved {@link ProjectVersionRef} to the original {@link Plugin} * @throws ManipulationException if an error occurs */ public HashMap<Profile,HashMap<ProjectVersionRef,Plugin>> getResolvedProfileManagedPlugins( MavenSessionHandler session ) throws ManipulationException { if ( resolvedProfileManagedPlugins == null ) { resolvedProfileManagedPlugins = new HashMap<>(); for ( final Profile profile : ProfileUtils.getProfiles( session, model ) ) { HashMap<ProjectVersionRef, Plugin> profileDeps = new HashMap<>(); if ( profile.getBuild() != null ) { final PluginManagement pm = profile.getBuild().getPluginManagement(); if ( !( pm == null || pm.getPlugins() == null ) ) { resolvePlugins( session, pm.getPlugins(), profileDeps ); } } resolvedProfileManagedPlugins.put( profile, profileDeps ); } } return resolvedProfileManagedPlugins; }
public void expandPluginConfiguration( Model model, ModelBuildingRequest request, ModelProblemCollector problems ) { Build build = model.getBuild(); if ( build != null ) { expand( build.getPlugins() ); PluginManagement pluginManagement = build.getPluginManagement(); if ( pluginManagement != null ) { expand( pluginManagement.getPlugins() ); } } }
/** * Method updatePluginManagement * * @param value * @param element * @param counter * @param xmlTag */ protected void updatePluginManagement( PluginManagement value, String xmlTag, Counter counter, Element element ) { boolean shouldExist = value != null; Element root = updateElement( counter, element, xmlTag, shouldExist ); if ( shouldExist ) { Counter innerCount = new Counter( counter.getDepth() + 1 ); iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" ); } }
private Set<ArtifactCoordinates> getSnapshotsFromManagement(MavenProject project, PomPropertyResolver propertyResolver) { this.log.debug("\t\tChecking managed plugins"); Build build = project.getBuild(); if (build != null) { PluginManagement pluginManagement = build.getPluginManagement(); if (pluginManagement != null) { Collection<Plugin> snapshots = Collections2.filter(pluginManagement.getPlugins(), new IsSnapshotPlugin(propertyResolver)); return Sets.newHashSet(Collections2.transform(snapshots, PluginToCoordinates.INSTANCE)); } } return Collections.emptySet(); }
private Set<ArtifactCoordinates> getSnapshotsFromManagement(Profile profile, PomPropertyResolver propertyResolver) { this.log.debug("\t\tChecking managed plugins of profile '" + profile.getId() + "'"); BuildBase build = profile.getBuild(); if (build != null) { PluginManagement pluginManagement = build.getPluginManagement(); if (pluginManagement != null) { Collection<Plugin> snapshots = Collections2.filter(pluginManagement.getPlugins(), new IsSnapshotPlugin(propertyResolver)); return Sets.newHashSet(Collections2.transform(snapshots, PluginToCoordinates.INSTANCE)); } } return Collections.emptySet(); }
private MavenProject createParentProject() { final MavenProject project = createMavenProject( "company", "company-parent-pom" ); final Build build = new Build(); build.setPluginManagement( new PluginManagement() ); final Plugin plugin = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0"); final Xpp3Dom configuration = createPluginConfiguration(); plugin.setConfiguration( configuration ); build.addPlugin( plugin ); project.getOriginalModel().setBuild( build ); return project; }
@Override public PluginManagement get( Model model ) { if ( model.getBuild() == null ) { return null; } return model.getBuild().getPluginManagement(); }
@Override public void set( Model model, PluginManagement value ) { if ( model.getBuild() == null ) { model.setBuild( new Build() ); } model.getBuild().setPluginManagement( value ); }
/** * Returns all dependencies defined in dependency management of the root pom. * * @return */ private Set<Artifact> getProjectPluginManagement() { Set<Artifact> result = new LinkedHashSet<Artifact>(); PluginManagement pluginManagement = getProject().getPluginManagement(); if (pluginManagement != null) { for (Plugin plugin : pluginManagement.getPlugins()) { result.add(toArtifact(plugin)); } } return result; }
/** * * @param project project to search in * @return Maven plugin with specific group and artifact ID registered in given project's plugin management, * if any or null otherise. */ protected Plugin getPluginFromManagement(MavenProject project) { PluginManagement management = project.getPluginManagement(); if (management == null) { return null; } return getMatching(management.getPlugins()); }
public Map<String, Plugin> getManagedPluginMap( final ModelBase base ) { if ( base instanceof Model ) { final Build build = ( (Model) base ).getBuild(); if ( build == null ) { return Collections.emptyMap(); } final PluginManagement pm = build.getPluginManagement(); if ( pm == null ) { return Collections.emptyMap(); } final Map<String, Plugin> result = pm.getPluginsAsMap(); if ( result == null ) { return Collections.emptyMap(); } return result; } return Collections.emptyMap(); }
public PluginManagement getPluginManagement() { PluginManagement pluginMgmt = null; Build build = getModel().getBuild(); if ( build != null ) { pluginMgmt = build.getPluginManagement(); } return pluginMgmt; }
public void mergeManagedBuildPlugins( Model model ) { Build build = model.getBuild(); if ( build != null ) { PluginManagement pluginManagement = build.getPluginManagement(); if ( pluginManagement != null ) { mergePluginContainer_Plugins( build, pluginManagement ); } } }
public PluginManagement getPluginManagement() { return null; }
/** * Returns a plugin from a pom based on its group id and artifact id * <p> * It searches in the build section, then the reporting section and finally the pluginManagement section * </p> * * @param pom the project pom * @param groupId the plugin group id * @param artifactId the plugin artifact id * @return the plugin if it exists, null otherwise */ @CheckForNull public static MavenPlugin getPlugin(MavenProject pom, String groupId, String artifactId) { Object pluginConfiguration = null; // look for plugin in <build> section Plugin plugin = getPlugin(pom.getBuildPlugins(), groupId, artifactId); if (plugin != null) { pluginConfiguration = plugin.getConfiguration(); } else { // look for plugin in reporting Reporting reporting = pom.getModel().getReporting(); if (reporting != null) { ReportPlugin reportPlugin = getReportPlugin(reporting.getPlugins(), groupId, artifactId); if (reportPlugin != null) { pluginConfiguration = reportPlugin.getConfiguration(); } } } // look for plugin in <pluginManagement> section PluginManagement pluginManagement = pom.getPluginManagement(); if (pluginManagement != null) { Plugin pluginFromManagement = getPlugin(pluginManagement.getPlugins(), groupId, artifactId); if (pluginFromManagement != null) { Object pluginConfigFromManagement = pluginFromManagement.getConfiguration(); if (pluginConfiguration == null) { pluginConfiguration = pluginConfigFromManagement; } else if (pluginConfigFromManagement != null) { Xpp3Dom.mergeXpp3Dom((Xpp3Dom) pluginConfiguration, (Xpp3Dom) pluginConfigFromManagement); } } } if (pluginConfiguration != null) { return new MavenPlugin(pluginConfiguration); } return null; }
@Override public PluginManagement replaceBuildPluginManagement( PluginManagement pluginManagement ) { return pluginManagement; }
@Override public PluginManagement replaceProfileBuildPluginManagement( PluginManagement pluginManagement ) { return pluginManagement; }
@Override public void visitBuildPluginManagement( PluginManagement pluginManagement ) { }
@Override public void visitProfileBuildPluginManagement( PluginManagement pluginManagement ) { }
private void visitProfileBuild( ModelVisitor visitor, BuildBase buildBase ) { List<Resource> resources = buildBase.getResources(); if ( resources != null ) { ListIterator<Resource> resourceIterator = resources.listIterator(); while ( resourceIterator.hasNext() ) { Resource resource = resourceIterator.next(); visitor.visitProfileBuildResource( resource ); visitProfileBuildResource( visitor, resource ); resource = visitor.replaceProfileBuildResource( resource ); if ( resource == null ) resourceIterator.remove(); else resourceIterator.set( resource ); } } List<Resource> testResources = buildBase.getTestResources(); if ( testResources != null ) { ListIterator<Resource> testResourceIterator = testResources.listIterator(); while ( testResourceIterator.hasNext() ) { Resource testResource = testResourceIterator.next(); visitor.visitProfileBuildTestResource( testResource ); visitProfileBuildTestResource( visitor, testResource ); testResource = visitor.replaceProfileBuildTestResource( testResource ); if ( testResource == null ) testResourceIterator.remove(); else testResourceIterator.set( testResource ); } } List<String> filters = buildBase.getFilters(); if ( filters != null ) { ListIterator<String> filterIterator = filters.listIterator(); while ( filterIterator.hasNext() ) { String filter = filterIterator.next(); visitor.visitProfileBuildFilter( filter ); filter = visitor.replaceProfileBuildFilter( filter ); if ( filter == null ) filterIterator.remove(); else filterIterator.set( filter ); } } PluginManagement pluginManagement = buildBase.getPluginManagement(); if ( pluginManagement != null ) { visitor.visitProfileBuildPluginManagement( pluginManagement ); visitProfileBuildPluginManagement( visitor, pluginManagement ); pluginManagement = visitor.replaceProfileBuildPluginManagement( pluginManagement ); buildBase.setPluginManagement( pluginManagement ); } List<Plugin> plugins = buildBase.getPlugins(); if ( plugins != null ) { ListIterator<Plugin> pluginIterator = plugins.listIterator(); while ( pluginIterator.hasNext() ) { Plugin plugin = pluginIterator.next(); visitor.visitProfileBuildPlugin( plugin ); visitProfileBuildPlugin( visitor, plugin ); plugin = visitor.replaceProfileBuildPlugin( plugin ); if ( plugin == null ) pluginIterator.remove(); else pluginIterator.set( plugin ); } } }
@SuppressWarnings( "unchecked" ) public void assembleBuildInheritance( Build childBuild, Build parentBuild, boolean handleAsInheritance ) { // The build has been set but we want to step in here and fill in // values that have not been set by the child. if ( childBuild.getSourceDirectory() == null ) { childBuild.setSourceDirectory( parentBuild.getSourceDirectory() ); } if ( childBuild.getScriptSourceDirectory() == null ) { childBuild.setScriptSourceDirectory( parentBuild.getScriptSourceDirectory() ); } if ( childBuild.getTestSourceDirectory() == null ) { childBuild.setTestSourceDirectory( parentBuild.getTestSourceDirectory() ); } if ( childBuild.getOutputDirectory() == null ) { childBuild.setOutputDirectory( parentBuild.getOutputDirectory() ); } if ( childBuild.getTestOutputDirectory() == null ) { childBuild.setTestOutputDirectory( parentBuild.getTestOutputDirectory() ); } // Extensions are accumulated mergeExtensionLists( childBuild, parentBuild ); if ( childBuild.getDirectory() == null ) { childBuild.setDirectory( parentBuild.getDirectory() ); } if ( childBuild.getDefaultGoal() == null ) { childBuild.setDefaultGoal( parentBuild.getDefaultGoal() ); } if ( childBuild.getFinalName() == null ) { childBuild.setFinalName( parentBuild.getFinalName() ); } ModelUtils.mergeFilterLists( childBuild.getFilters(), parentBuild.getFilters() ); List<Resource> resources = childBuild.getResources(); if ( ( resources == null ) || resources.isEmpty() ) { childBuild.setResources( parentBuild.getResources() ); } resources = childBuild.getTestResources(); if ( ( resources == null ) || resources.isEmpty() ) { childBuild.setTestResources( parentBuild.getTestResources() ); } // Plugins are aggregated if Plugin.inherit != false ModelUtils.mergePluginLists( childBuild, parentBuild, handleAsInheritance ); // Plugin management :: aggregate PluginManagement dominantPM = childBuild.getPluginManagement(); PluginManagement recessivePM = parentBuild.getPluginManagement(); if ( ( dominantPM == null ) && ( recessivePM != null ) ) { // FIXME: Filter out the inherited == false stuff! childBuild.setPluginManagement( recessivePM ); } else { ModelUtils.mergePluginLists( childBuild.getPluginManagement(), parentBuild.getPluginManagement(), false ); } }
public void testShouldNotFailWhenManagedPluginDepReferencesCurrentProject() throws CycleDetectedException, DuplicateProjectException { MavenProject project = createProject( "group", "artifact", "1.0" ); Build build = project.getModel().getBuild(); PluginManagement pMgmt = new PluginManagement(); Plugin plugin = createPlugin( "other.group", "other-artifact", "1.0" ); Dependency dep = createDependency( "group", "artifact", "1.0" ); plugin.addDependency( dep ); pMgmt.addPlugin( plugin ); build.setPluginManagement( pMgmt ); new ProjectSorter( Collections.singletonList( project ) ); }
protected void mergePluginManagement( PluginManagement target, PluginManagement source, boolean sourceDominant, Map<Object, Object> context ) { mergePluginContainer( target, source, sourceDominant, context ); }
@Override public PluginManagement getPluginManagement() { return getDelegate().getPluginManagement(); }
PluginManagement replaceBuildPluginManagement( PluginManagement pluginManagement );
PluginManagement replaceProfileBuildPluginManagement( PluginManagement pluginManagement );
void visitBuildPluginManagement( PluginManagement pluginManagement );
void visitProfileBuildPluginManagement( PluginManagement pluginManagement );