Java Code Examples for org.apache.maven.model.Profile#getBuild()

The following examples show how to use org.apache.maven.model.Profile#getBuild() . 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: 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 2
Source File: CheckPluginDependencyVersions.java    From unleash-maven-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private Multimap<ArtifactCoordinates, ArtifactCoordinates> getSnapshots(Profile profile,
    PomPropertyResolver propertyResolver) {
  this.log.debug("\t\tChecking direct plugin references of profile '" + profile.getId() + "'");
  Multimap<ArtifactCoordinates, ArtifactCoordinates> result = HashMultimap.create();
  BuildBase build = profile.getBuild();
  if (build != null) {
    for (Plugin plugin : build.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 3
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 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>> getResolvedProfilePlugins( MavenSessionHandler session )
                throws ManipulationException
{
    Map<Profile, Map<ProjectVersionRef, Plugin>> resolvedProfilePlugins = new HashMap<>();

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

        if ( profile.getBuild() != null )
        {
            resolvePlugins( session, profile.getBuild().getPlugins(), PluginResolver.NONE, profileDeps );

        }
        resolvedProfilePlugins.put( profile, profileDeps );
    }

    return resolvedProfilePlugins;
}
 
Example 4
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 potentially active Profiles in this project including those without a
 * version 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>> getAllResolvedProfilePlugins( MavenSessionHandler session )
                throws ManipulationException
{
    Map<Profile, Map<ProjectVersionRef, Plugin>> allResolvedProfilePlugins = new HashMap<>();

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

        if ( profile.getBuild() != null )
        {
            resolvePlugins( session, profile.getBuild().getPlugins(), PluginResolver.ALL, profileDeps );

        }
        allResolvedProfilePlugins.put( profile, profileDeps );
    }

    return allResolvedProfilePlugins;
}
 
Example 5
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 6
Source File: PluginRemovalManipulator.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
private boolean apply( final Project project, final Model model )
{
    final PluginRemovalState state = session.getState( PluginRemovalState.class );

    if (logger.isDebugEnabled())
    {
        logger.debug( "Applying plugin changes to: {}", ga( project ) );
    }


    boolean result = false;
    List<ProjectRef> pluginsToRemove = state.getPluginRemoval();
    if ( model.getBuild() != null )
    {
        result = scanPlugins( pluginsToRemove, model.getBuild().getPlugins() );
    }

    for ( final Profile profile : ProfileUtils.getProfiles( session, model) )
    {
        if ( profile.getBuild() != null && scanPlugins( pluginsToRemove, profile.getBuild().getPlugins() ) )
        {
            result = true;
        }
    }
    return result;
}
 
Example 7
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 8
Source File: CheckPluginVersions.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private Set<ArtifactCoordinates> getSnapshots(Profile profile, PomPropertyResolver propertyResolver) {
  this.log.debug("\t\tChecking direct plugin references of profile '" + profile.getId() + "'");
  BuildBase build = profile.getBuild();
  if (build != null) {
    Collection<Plugin> snapshots = Collections2.filter(build.getPlugins(), new IsSnapshotPlugin(propertyResolver));
    return Sets.newHashSet(Collections2.transform(snapshots, PluginToCoordinates.INSTANCE));
  }
  return Collections.emptySet();
}
 
Example 9
Source File: DistributionEnforcingManipulatorTest.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
private void assertSkip( final Model model, final String profileId )
{
    BuildBase build = null;
    if ( profileId != null )
    {
        final List<Profile> profiles = model.getProfiles();
        if ( profiles != null )
        {
            for ( final Profile profile : profiles )
            {
                if ( profileId.equals( profile.getId() ) )
                {
                    build = profile.getBuild();
                }
            }
        }
    }
    else
    {
        build = model.getBuild();
    }

    assertThat( build, notNullValue() );

    final Plugin plugin =
        build.getPluginsAsMap()
             .get( ga( MAVEN_PLUGIN_GROUPID, true ? MAVEN_DEPLOY_ARTIFACTID : MAVEN_INSTALL_ARTIFACTID ) );

    assertThat( plugin, notNullValue() );

    assertThat( plugin.getConfiguration()
                      .toString()
                      .contains( "<skip>" + Boolean.FALSE + "</skip>" ), equalTo( true ) );
}
 
Example 10
Source File: ProjectVersionEnforcingManipulator.java    From pom-manipulation-ext with Apache License 2.0 4 votes vote down vote up
/**
 * For each project in the current build set, reset the version if using project.version
*/
@Override
public Set<Project> applyChanges( final List<Project> projects )
{
    final ProjectVersionEnforcingState state = session.getState( ProjectVersionEnforcingState.class );
    if ( !session.isEnabled() ||
                    !session.anyStateEnabled( State.activeByDefault ) ||
                    state == null || !state.isEnabled() )
    {
        logger.debug( "Project version enforcement is disabled." );
        return Collections.emptySet();
    }

    final Set<Project> changed = new HashSet<>();

    for ( final Project project : projects )
    {
        final Model model = project.getModel();

        model.getProperties().stringPropertyNames().stream().filter( k -> model.getProperties().getProperty( k ).equals(
                        Version.PROJECT_VERSION ) ).
                        forEach( k -> {
                            logger.debug( "Replacing project.version within properties for project {} with key {}", project, k );
                            model.getProperties().setProperty( k, project.getVersion() );
                            changed.add( project );
                        } );

        // TODO: We _could_ change it everywhere but it only really breaks in POM files.
        if ( model.getPackaging().equals( "pom" ) )
        {
            enforceDependencyProjectVersion( project, model.getDependencies(), changed );

            if ( model.getDependencyManagement() != null )
            {
                enforceDependencyProjectVersion( project, model.getDependencyManagement().getDependencies(), changed );
            }

            if ( model.getBuild() != null )
            {
                enforcePluginProjectVersion( project, model.getBuild().getPlugins(), changed );

                if ( model.getBuild().getPluginManagement() != null )
                {
                    enforcePluginProjectVersion( project, model.getBuild().getPluginManagement().getPlugins(), changed );
                }
            }

            final List<Profile> profiles = ProfileUtils.getProfiles( session, model);
            for ( final Profile profile : profiles )
            {
                enforceDependencyProjectVersion( project, profile.getDependencies(), changed );
                if ( profile.getDependencyManagement() != null )
                {
                    enforceDependencyProjectVersion( project, profile.getDependencyManagement().getDependencies(), changed );
                }
                if ( profile.getBuild() != null )
                {
                    enforcePluginProjectVersion( project, profile.getBuild().getPlugins(), changed );

                    if ( profile.getBuild().getPluginManagement() != null )
                    {
                        enforcePluginProjectVersion( project, profile.getBuild().getPluginManagement().getPlugins(), changed );
                    }
                }
            }
        }
    }
    if (!changed.isEmpty())
    {
        logger.warn( "Using ${project.version} in pom files may lead to unexpected errors with inheritance." );
    }
    return changed;
}