org.apache.maven.model.PluginManagement Java Examples

The following examples show how to use org.apache.maven.model.PluginManagement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocationAwareMavenXpp3Writer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #2
Source File: OverridePluginManagementError.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: CheckPluginDependencyVersions.java    From unleash-maven-plugin with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: CheckPluginDependencyVersions.java    From unleash-maven-plugin with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: RequirePropertyDiverges.java    From extra-enforcer-rules with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: RequirePropertyDivergesTest.java    From extra-enforcer-rules with Apache License 2.0 6 votes vote down vote up
/**
 * 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 );
}
 
Example #7
Source File: RequirePropertyDivergesTest.java    From extra-enforcer-rules with Apache License 2.0 6 votes vote down vote up
/**
 * 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 );
}
 
Example #8
Source File: Project.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
/**
 * 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 Map<ProjectVersionRef, Plugin> getResolvedManagedPlugins ( MavenSessionHandler session) throws ManipulationException
{
    Map<ProjectVersionRef, Plugin> resolvedManagedPlugins = new HashMap<>();

    if ( getModel().getBuild() != null )
    {
        final PluginManagement pm = getModel().getBuild().getPluginManagement();
        if ( !( pm == null || pm.getPlugins() == null ) )
        {
            resolvePlugins( session, pm.getPlugins(), PluginResolver.PLUGIN_DEFAULTS, resolvedManagedPlugins );
        }
    }

    return resolvedManagedPlugins;
}
 
Example #9
Source File: Project.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
/**
 * 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 Map<Profile,Map<ProjectVersionRef,Plugin>> getResolvedProfileManagedPlugins( MavenSessionHandler session )
                throws ManipulationException
{
    Map<Profile, Map<ProjectVersionRef, Plugin>> resolvedProfileManagedPlugins = new HashMap<>();

    for ( final Profile profile : ProfileUtils.getProfiles( session, model ) )
    {
        Map<ProjectVersionRef, Plugin> profileDeps = new HashMap<>();

        if ( profile.getBuild() != null )
        {
            final PluginManagement pm = profile.getBuild().getPluginManagement();

            if ( pm != null )
            {
                resolvePlugins( session, pm.getPlugins(), PluginResolver.PLUGIN_DEFAULTS, profileDeps );
            }
        }
        resolvedProfileManagedPlugins.put( profile, profileDeps );
    }
    return resolvedProfileManagedPlugins;
}
 
Example #10
Source File: CheckPluginVersions.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
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();
}
 
Example #11
Source File: CheckPluginVersions.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
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();
}
 
Example #12
Source File: RequirePropertyDivergesTest.java    From extra-enforcer-rules with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #13
Source File: PomProperty.java    From flatten-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public PluginManagement get( Model model )
{
    if ( model.getBuild() == null )
    {
        return null;
    }
    return model.getBuild().getPluginManagement();
}
 
Example #14
Source File: PomProperty.java    From flatten-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void set( Model model, PluginManagement value )
{
    if ( model.getBuild() == null )
    {
        model.setBuild( new Build() );
    }
    model.getBuild().setPluginManagement( value );
}
 
Example #15
Source File: GenerateBomMojo.java    From sundrio with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #16
Source File: DistributionEnforcingManipulator.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
private 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();
}