org.apache.maven.model.Profile Java Examples

The following examples show how to use org.apache.maven.model.Profile. 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: NBModelBuilder.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public ModelBuildingResult build(ModelBuildingRequest request) throws ModelBuildingException {
    ModelBuildingResult toRet = super.build(request);
    Model eff = toRet.getEffectiveModel();
    InputSource source = new InputSource();
    source.setLocation("");
    InputLocation location = new InputLocation(-1, -1, source);
    eff.setLocation(NETBEANS_PROFILES, location);
    for (String id : toRet.getModelIds()) {
        Model mdl = toRet.getRawModel(id);
        for (Profile p : mdl.getProfiles()) {
            source.setLocation(source.getLocation() + "|" + p.getId());
        }
    }
    return toRet;
}
 
Example #2
Source File: WriteActiveProfileProperties.java    From properties-maven-plugin with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
public void execute()
    throws MojoExecutionException
{
    validateOutputFile();
    List<?> list = getProject().getActiveProfiles();
    if ( getLog().isInfoEnabled() )
    {
        getLog().debug( list.size() + " profile(s) active" );
    }
    Properties properties = new Properties();
    for ( Iterator<?> iter = list.iterator(); iter.hasNext(); )
    {
        Profile profile = (Profile) iter.next();
        if ( profile.getProperties() != null )
        {
            properties.putAll( profile.getProperties() );
        }
    }

    writeProperties( properties, getOutputFile() );
}
 
Example #3
Source File: NativeBuildMojo.java    From client-maven-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void execute() throws MojoExecutionException {
    getLog().debug("Start building");

    // prepare the execution:
    final InvocationRequest invocationRequest = new DefaultInvocationRequest();
    invocationRequest.setProfiles(project.getActiveProfiles().stream()
            .map(Profile::getId)
            .collect(Collectors.toList()));
    invocationRequest.setPomFile(new File(pom));

    invocationRequest.setGoals(Arrays.asList("client:compile", "client:link"));

    final Invoker invoker = new DefaultInvoker();
    // execute:
    try {
        final InvocationResult invocationResult = invoker.execute(invocationRequest);
        if (invocationResult.getExitCode() != 0) {
            throw new MojoExecutionException("Error, client:build failed", invocationResult.getExecutionException());
        }
    } catch (MavenInvocationException e) {
        e.printStackTrace();
        throw new MojoExecutionException("Error", e);
    }

}
 
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> 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 #5
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 #6
Source File: Project.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
/**
 * This method will scan the dependencies in the potentially active Profiles in this project and
 * return a fully resolved list.  Note that this will only return full dependencies not managed
 * i.e. those with a group, artifact and version.
 *
 * Note that while updating the {@link Dependency} 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 ArtifactRef} to the original {@link Dependency}
 * @throws ManipulationException if an error occurs
 */
public Map<Profile, Map<ArtifactRef, Dependency>> getResolvedProfileDependencies( MavenSessionHandler session) throws ManipulationException
{
    Map<Profile, Map<ArtifactRef, Dependency>> resolvedProfileDependencies = new HashMap<>();

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

        resolveDeps( session, profile.getDependencies(), false, profileDeps );

        resolvedProfileDependencies.put( profile, profileDeps );
    }

    return resolvedProfileDependencies;
}
 
Example #7
Source File: Project.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
/**
 * This method will scan the dependencies in the potentially active Profiles in this project and
 * return a fully resolved list. Note that this will return all dependencies including managed
 * i.e. those with a group, artifact and potentially empty version.
 *
 * Note that while updating the {@link Dependency} 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 ArtifactRef} to the original {@link Dependency}
 * @throws ManipulationException if an error occurs
 */
public Map<Profile, Map<ArtifactRef, Dependency>> getAllResolvedProfileDependencies( MavenSessionHandler session) throws ManipulationException
{
    Map<Profile, Map<ArtifactRef, Dependency>> allResolvedProfileDependencies = new HashMap<>();

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

        resolveDeps( session, profile.getDependencies(), true, profileDeps );

        allResolvedProfileDependencies.put( profile, profileDeps );
    }

    return allResolvedProfileDependencies;
}
 
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 dependencies in the dependencyManagement section of the potentially active Profiles in
 * this project and return a fully resolved list. Note that while updating the {@link Dependency}
 * 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 ArtifactRef} to the original {@link Dependency} (that were within DependencyManagement)
 * @throws ManipulationException if an error occurs
 */
public Map<Profile, Map<ArtifactRef, Dependency>> getResolvedProfileManagedDependencies( MavenSessionHandler session) throws ManipulationException
{
    Map<Profile, Map<ArtifactRef, Dependency>> resolvedProfileManagedDependencies = new HashMap<>();

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

        final DependencyManagement dm = profile.getDependencyManagement();

        if ( dm != null )
        {
            resolveDeps( session, dm.getDependencies(), false, profileDeps );
        }

        resolvedProfileManagedDependencies.put( profile, profileDeps );
    }
    return resolvedProfileManagedDependencies;
}
 
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 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 #10
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 #11
Source File: ProfileUtils.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
public static List<Profile> getProfiles ( MavenSessionHandler session, Model model)
{
    final List<Profile> result = new ArrayList<>( );
    final List<Profile> profiles = model.getProfiles();
    final boolean scanActiveProfiles = Boolean.parseBoolean( session.getUserProperties().getProperty( PROFILE_SCANNING, PROFILE_SCANNING_DEFAULT ) );

    if ( profiles != null )
    {
        if ( scanActiveProfiles )
        {
            for ( Profile p : profiles )
            {
                if ( session.getActiveProfiles().contains( p.getId() ) )
                {
                    result.add( p );
                }
            }
        }
        else
        {
            result.addAll( profiles );
        }
    }
    return result;
}
 
Example #12
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 #13
Source File: MavenModelBuilder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void completeWorkspaceProjectBuildRequest(ModelBuildingRequest request) {
    final Set<String> addedProfiles = new HashSet<>();
    final List<Profile> profiles = request.getProfiles();
    profiles.forEach(p -> addedProfiles.add(p.getId()));

    activeSettingsProfiles.forEach(p -> {
        if (!addedProfiles.contains(p.getId())) {
            profiles.add(p);
            request.getActiveProfileIds().add(p.getId());
        }
    });

    request.getActiveProfileIds().addAll(mvnOptions.getActiveProfileIds());
    request.getInactiveProfileIds().addAll(mvnOptions.getInactiveProfileIds());
    request.setUserProperties(System.getProperties());
}
 
Example #14
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 #15
Source File: DistributionEnforcingManipulator.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
private Map<String, Plugin> getPluginMap( final ModelBase base )
{
    final BuildBase build;
    if ( base instanceof Model )
    {
        build = ( (Model) base ).getBuild();
    }
    else
    {
        build = ( (Profile) base ).getBuild();
    }

    if ( build == null )
    {
        return Collections.emptyMap();
    }

    final Map<String, Plugin> result = build.getPluginsAsMap();
    if ( result == null )
    {
        return Collections.emptyMap();
    }

    return result;
}
 
Example #16
Source File: PluginConfigXmlDocument.java    From ci.maven with Apache License 2.0 5 votes vote down vote up
public void createActiveBuildProfilesElement(String name, List<Profile> value) {
    if (value == null || value.isEmpty()) {
        return;
    }
    Element child = doc.createElement(name);
    for (int i = 0; i < value.size(); i++) {
        createElement(child, "profileId", value.get(i).getId());
    }
    doc.getDocumentElement().appendChild(child);
}
 
Example #17
Source File: PomHelper.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a set of all child modules for a project, including any defined in profiles (ignoring profile
 * activation).
 *
 * @param model The project model.
 * @param logger The logger to use.
 * @return the set of all child modules of the project.
 */
public static Set<String> getAllChildModules( Model model, Log logger )
{
    logger.debug( "Finding child modules..." );
    Set<String> childModules = new TreeSet<String>();
    childModules.addAll( model.getModules() );
    for ( Profile profile : model.getProfiles() )
    {
        childModules.addAll( profile.getModules() );
    }
    debugModules( logger, "Child modules:", childModules );
    return childModules;
}
 
Example #18
Source File: RootLocationMojo.java    From build-helper-maven-plugin with MIT License 5 votes vote down vote up
/**
 * Returns a set of all child modules for a project, including any defined in profiles (ignoring profile activation).
 *
 * @param project The project.
 * @return the set of all child modules of the project (canonical paths).
 */
private Set<String> getAllChildModules( MavenProject project ) throws IOException
{
    Model model = project.getOriginalModel();
    Set<String> paths = new TreeSet<>();
    paths.addAll( getChildModuleCanoncialPath( project, model.getModules() ));
    for ( Profile profile : model.getProfiles() )
    {
        paths.addAll( getChildModuleCanoncialPath( project, profile.getModules() ));
    }
    return paths;
}
 
Example #19
Source File: CreateMavenBundlePom.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
/**
 * skip depoly phase in publich to cloud in parent pom, enable in nexus.
 */
private Profile addProfileForCloud() {
    Profile deployCloudProfile = new Profile();
    deployCloudProfile.setId("deploy-cloud");
    Activation deployCloudActivation = new Activation();
    ActivationProperty activationProperty = new ActivationProperty();
    activationProperty.setName("!altDeploymentRepository");
    deployCloudActivation.setProperty(activationProperty);
    deployCloudProfile.setActivation(deployCloudActivation);
    deployCloudProfile.setBuild(new Build());
    deployCloudProfile.getBuild().addPlugin(addSkipDeployFeatureMavenPlugin());
    return deployCloudProfile;
}
 
Example #20
Source File: CreateMavenDataServicePom.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
/**
 * DOC skip depoly phase in publich to cloud in parent pom, enable in nexus.
 */
private Profile addProfileForCloud() {
    Profile deployCloudProfile = new Profile();
    deployCloudProfile.setId("deploy-cloud");
    Activation deployCloudActivation = new Activation();
    ActivationProperty activationProperty = new ActivationProperty();
    activationProperty.setName("!altDeploymentRepository");
    deployCloudActivation.setProperty(activationProperty);
    deployCloudProfile.setActivation(deployCloudActivation);
    deployCloudProfile.setBuild(new Build());
    deployCloudProfile.getBuild().addPlugin(addSkipDeployFeatureMavenPlugin());
    return deployCloudProfile;
}
 
Example #21
Source File: POM.java    From pomutils with Apache License 2.0 5 votes vote down vote up
public Properties getProfileProperties(String profileId) {
	if (profileId == null) {
		throw new IllegalArgumentException("profileId is null");
	}
	for (Profile profile : getRawModel().getProfiles()) {
		if (profileId.equals(profile.getId())) {
			return profile.getProperties();
		}
	}
	return new Properties();
}
 
Example #22
Source File: POM.java    From pomutils with Apache License 2.0 5 votes vote down vote up
private List<String> getProfilesPropertyNames() {
	List<String> propertyNames = new ArrayList<String>();
	for (Profile profile : getProfiles()) {
		propertyNames.addAll(getProfileProperties(profile.getId()).stringPropertyNames());
	}
	return propertyNames;
}
 
Example #23
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 #24
Source File: ProfileInjectionManipulator.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
/**
 * Apply the profile injection changes to the top level pom.
 */
@Override
public Set<Project> applyChanges( final List<Project> projects )
    throws ManipulationException
{
    final ProfileInjectionState state = session.getState( ProfileInjectionState.class );
    if ( !session.isEnabled() || !state.isEnabled() )
    {
        logger.debug( getClass().getSimpleName() + ": Nothing to do!" );
        return Collections.emptySet();
    }

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

    for ( ProjectVersionRef p : state.getRemoteProfileInjectionMgmt() )
    {
        final List<Profile> remoteProfiles = modelBuilder.resolveRawModel( p ).getProfiles();

        projects.stream().filter( Project::isInheritanceRoot ).forEach( project -> {
                logger.info( "Applying changes to: {} ", ga( project ) );
                project.updateProfiles( remoteProfiles );
                changed.add( project );
            } );
    }

    return changed;
}
 
Example #25
Source File: PropertiesUtils.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
/**
 * Recursively update properties.
 *
 * @param session the DependencyState
 * @param project the current set of projects we are scanning.
 * @param ignoreStrict whether to ignore strict alignment.
 * @param key a key to look for.
 * @param newValue a value to look for.
 * @return {@code PropertyUpdate} enumeration showing status of any changes.
 * @throws ManipulationException if an error occurs
 */
public static PropertyUpdate updateProperties( ManipulationSession session, Project project, boolean ignoreStrict,
                                               String key, String newValue ) throws ManipulationException
{
    final String resolvedValue = PropertyResolver.resolveProperties( session, project.getInheritedList(), "${" + key + '}' );

    logger.debug( "Fully resolvedValue is {} for {} ", resolvedValue, key );

    if ( "project.version".equals( key ) )
    {
        logger.debug( "Not updating key {} with {} ", key, newValue );
        return PropertyUpdate.IGNORE;
    }

    for ( final Project p : project.getReverseInheritedList() )
    {
        if ( p.getModel().getProperties().containsKey( key ) )
        {
            logger.trace( "Searching properties of {} ", p );
            return internalUpdateProperty( session, p, ignoreStrict, key, newValue, resolvedValue,
                                           p.getModel().getProperties() );
        }
        else
        {
            for ( Profile pr : ProfileUtils.getProfiles( session, p.getModel() ) )
            {
                logger.trace( "Searching properties of profile {} within project {} ", pr.getId(), p );
                // Lets check the profiles for property updates...
                if ( pr.getProperties().containsKey( key ) )
                {
                    return internalUpdateProperty( session, p, ignoreStrict, key, newValue, resolvedValue, pr.getProperties() );
                }
            }
        }
    }

    return PropertyUpdate.NOTFOUND;
}
 
Example #26
Source File: FlattenMojo.java    From flatten-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the {@link List} of {@link Dependency dependencies} for the flattened POM. These are all resolved
 * {@link Dependency dependencies} except for those added from {@link Profile profiles}.
 *
 * @param effectiveModel is the effective POM {@link Model} to process.
 * @return the {@link List} of {@link Dependency dependencies}.
 * @throws MojoExecutionException if anything goes wrong.
 */
protected List<Dependency> createFlattenedDependencies( Model effectiveModel )
        throws MojoExecutionException {
    List<Dependency> flattenedDependencies = new ArrayList<Dependency>();
    // resolve all direct and inherited dependencies...
    try {
        createFlattenedDependencies( effectiveModel, flattenedDependencies );
    }
    catch (Exception e) {
        throw new MojoExecutionException("unable to create flattened dependencies", e);
    }
    if ( isEmbedBuildProfileDependencies() )
    {
        Model projectModel = this.project.getModel();
        Dependencies modelDependencies = new Dependencies();
        modelDependencies.addAll( projectModel.getDependencies() );
        for ( Profile profile : projectModel.getProfiles() )
        {
            // build-time driven activation (by property or file)?
            if ( isBuildTimeDriven( profile.getActivation() ) )
            {
                List<Dependency> profileDependencies = profile.getDependencies();
                for ( Dependency profileDependency : profileDependencies )
                {
                    if ( modelDependencies.contains( profileDependency ) )
                    {
                        // our assumption here is that the profileDependency has been added to model because of
                        // this build-time driven profile. Therefore we need to add it to the flattened POM.
                        // Non build-time driven profiles will remain in the flattened POM with their dependencies
                        // and
                        // allow dynamic dependencies due to OS or JDK.
                        flattenedDependencies.add( modelDependencies.resolve(profileDependency) );
                    }
                }
            }
        }
        getLog().debug( "Resolved " + flattenedDependencies.size() + " dependency/-ies for flattened POM." );
    }
    return flattenedDependencies;
}
 
Example #27
Source File: ProjectComparator.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
private static Set<ProjectVersionRef> handlePlugins( MavenSessionHandler session, Project project, Profile profile,
                                                    Type type )
                throws ManipulationUncheckedException
{
    try
    {
        switch (type)
        {
            case PLUGINS:
            {
                return project.getResolvedPlugins( session ).keySet();
            }
            case MANAGED_PLUGINS:
            {
                return project.getResolvedManagedPlugins( session ).keySet();
            }
            case PROFILE_PLUGINS:
            {
                return project.getResolvedProfilePlugins( session ).getOrDefault( profile, Collections.emptyMap() ).keySet();
            }
            case PROFILE_MANAGED_PLUGINS:
            {
                return project.getResolvedProfileManagedPlugins( session ).getOrDefault( profile, Collections.emptyMap() ).keySet();
            }
            default:
            {
                throw new ManipulationException( "Invalid type {}", type );
            }
        }
    }
    catch ( ManipulationException e )
    {
        throw new ManipulationUncheckedException( e );
    }
}
 
Example #28
Source File: MavenModelBuilder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public MavenModelBuilder(WorkspaceModelResolver wsModelResolver, BootstrapMavenOptions mvnOptions,
        List<Profile> activeSettingsProfiles) {
    builder = new BootstrapModelBuilderFactory().newInstance();
    workspaceResolver = wsModelResolver;
    this.activeSettingsProfiles = activeSettingsProfiles;
    this.mvnOptions = mvnOptions;
}
 
Example #29
Source File: MicroprofileServersAddon.java    From microprofile-starter with Apache License 2.0 5 votes vote down vote up
private Profile findProfile(String profileName) {
    Profile result = null;

    for (Profile profile : serverPomModel.getProfiles()) {
        if (profile.getId().equals(profileName)) {
            result = profile;
        }
    }
    return result;
}
 
Example #30
Source File: MicroprofileServersAddon.java    From microprofile-starter with Apache License 2.0 5 votes vote down vote up
@Override
public void adaptMavenModel(Model pomFile, JessieModel model, boolean mainProject) {

    String serverName = options.get("server").getSingleValue();
    // From MP 3.2 on with Helidon, one of the Maven deps changed
    // So I created a new profile with correct naming.  The solution with the MP version in the profile name is not really useful in this case
    // since it will be for several MP releases.
    if ("helidon".equals(serverName) && model.getSpecification().getMicroProfileVersion().ordinal() <= MicroProfileVersion.MP32.ordinal()) {
        serverName = "helidon2";
    }
    String profileName = serverName + "-" + model.getSpecification().getMicroProfileVersion().getCode();

    Profile profile = findProfile(profileName);
    if (profile == null) {
        profile = findProfile(serverName);
    }

    if (profile == null) {
        throw new JessieUnexpectedException("Profile not found " + profileName);
    }

    Profile selectedProfile = profile.clone();
    selectedProfile.setId(serverName);
    Activation activeByDefault = new Activation();
    activeByDefault.setActiveByDefault(true);
    selectedProfile.setActivation(activeByDefault);
    pomFile.getProfiles().add(selectedProfile);

    if (microprofileSpecs.contains(MicroprofileSpec.JWT_AUTH) && mainProject) {
        mavenHelper.addDependency(pomFile, "io.vertx", "vertx-auth-jwt", VERTX_JWT_VERSION);
    }

    if (model.hasMainAndSecondaryProject()) {
        if (mainProject) {
            pomFile.setArtifactId(model.getMaven().getArtifactId() + "-" + JessieModel.MAIN_INDICATOR);
        } else {
            pomFile.setArtifactId(model.getMaven().getArtifactId() + "-" + JessieModel.SECONDARY_INDICATOR);
        }
    }
}