Example usage for org.apache.maven.project MavenProject getActiveProfiles

List of usage examples for org.apache.maven.project MavenProject getActiveProfiles

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getActiveProfiles.

Prototype

public List<Profile> getActiveProfiles() 

Source Link

Usage

From source file:net.oneandone.maven.rules.common.AbstractRule.java

License:Apache License

private Set<BuildBase> getDefinedActiveBuilds(MavenProject project) {
    HashSet<BuildBase> activeBuilds = new HashSet<>();
    final Model originalModel = project.getOriginalModel();
    final Build build = originalModel.getBuild();
    activeBuilds.add(build);/*www .j  av a2 s  .  c o  m*/

    final List<Profile> originalProfiles = originalModel.getProfiles();
    if (originalProfiles != null) {
        for (Profile profile : project.getActiveProfiles()) {
            // check active profile is defined in project
            for (Profile originalProfile : originalProfiles) {
                if (originalProfile.equals(profile)) {
                    activeBuilds.add(originalProfile.getBuild());
                }
            }
        }
    }
    // remove possible null entries
    activeBuilds.remove(null);
    return activeBuilds;
}

From source file:org.apache.myfaces.trinidadbuild.plugin.jdeveloper.JDeveloperMojo.java

License:Apache License

private List<String> getProfilesExecution(MavenProject project) {
    List<String> values = new ArrayList<String>();
    values.add(" -Ppackage -Plib-package ");

    if (project != null && project.getActiveProfiles() != null) {
        Iterator iterador = project.getActiveProfiles().iterator();
        if (iterador != null) {
            for (Iterator<Profile> i = iterador; i.hasNext();) {
                Profile profile = i.next();
                if (profile != null && profile.getActivation() != null
                        && profile.getActivation().getProperty() != null
                        && profile.getActivation().getProperty().getValue() != null
                        && profile.getActivation().getProperty().getName() != null) {
                    values.add(String.format(" -D%s=%s ", profile.getActivation().getProperty().getName(),
                            profile.getActivation().getProperty().getValue()));
                }/*  w  ww . j  a  v  a  2 s.  com*/
            }
        }
    }
    /*
     * this.getLog().info("Profiles " +
     * this.project.getExecutionProject().getProjectBuildingRequest().getProfiles());
     * for(Iterator<Profile> i = this.project.getProjectBuildingRequest().getProfiles().iterator();
     * i.hasNext();){
     * Profile profile = i.next();
     * values.add(String.format(" -D%s=%s ", profile.getActivation().getProperty().getName(),
     * profile.getActivation().getProperty().getValue()));
     * }
     */
    return values;
}

From source file:org.codehaus.mojo.versions.api.PomHelper.java

License:Apache License

/**
 * Examines the project to find any properties which are associated with versions of artifacts in the project.
 *
 * @param helper  Our versions helper./*from   ww w  .  jav  a  2s  . c  o m*/
 * @param project The project to examine.
 * @return An array of properties that are associated within the project.
 * @throws ExpressionEvaluationException if an expression cannot be evaluated.
 * @throws IOException                   if the project's pom file cannot be parsed.
 * @since 1.0-alpha-3
 */
public static PropertyVersionsBuilder[] getPropertyVersionsBuilders(VersionsHelper helper, MavenProject project)
        throws ExpressionEvaluationException, IOException {
    ExpressionEvaluator expressionEvaluator = helper.getExpressionEvaluator(project);
    Model model = getRawModel(project);
    Map<String, PropertyVersionsBuilder> result = new TreeMap<String, PropertyVersionsBuilder>();

    Set<String> activeProfiles = new TreeSet<String>();
    for (Profile profile : (List<Profile>) project.getActiveProfiles()) {
        activeProfiles.add(profile.getId());
    }

    // add any properties from profiles first (as they override properties from the project
    for (Profile profile : model.getProfiles()) {
        if (!activeProfiles.contains(profile.getId())) {
            continue;
        }
        addProperties(helper, result, profile.getId(), profile.getProperties());
        if (profile.getDependencyManagement() != null) {
            addDependencyAssocations(helper, expressionEvaluator, result,
                    profile.getDependencyManagement().getDependencies(), false);
        }
        addDependencyAssocations(helper, expressionEvaluator, result, profile.getDependencies(), false);
        if (profile.getBuild() != null) {
            if (profile.getBuild().getPluginManagement() != null) {
                addPluginAssociations(helper, expressionEvaluator, result,
                        profile.getBuild().getPluginManagement().getPlugins());
            }
            addPluginAssociations(helper, expressionEvaluator, result, profile.getBuild().getPlugins());
        }
        if (profile.getReporting() != null) {
            addReportPluginAssociations(helper, expressionEvaluator, result,
                    profile.getReporting().getPlugins());
        }
    }

    // second, we add all the properties in the pom
    addProperties(helper, result, null, model.getProperties());
    if (model.getDependencyManagement() != null) {
        addDependencyAssocations(helper, expressionEvaluator, result,
                model.getDependencyManagement().getDependencies(), false);
    }
    addDependencyAssocations(helper, expressionEvaluator, result, model.getDependencies(), false);
    if (model.getBuild() != null) {
        if (model.getBuild().getPluginManagement() != null) {
            addPluginAssociations(helper, expressionEvaluator, result,
                    model.getBuild().getPluginManagement().getPlugins());
        }
        addPluginAssociations(helper, expressionEvaluator, result, model.getBuild().getPlugins());
    }
    if (model.getReporting() != null) {
        addReportPluginAssociations(helper, expressionEvaluator, result, model.getReporting().getPlugins());
    }

    // third, we add any associations from the active profiles
    for (Profile profile : model.getProfiles()) {
        if (!activeProfiles.contains(profile.getId())) {
            continue;
        }
        if (profile.getDependencyManagement() != null) {
            addDependencyAssocations(helper, expressionEvaluator, result,
                    profile.getDependencyManagement().getDependencies(), false);
        }
        addDependencyAssocations(helper, expressionEvaluator, result, profile.getDependencies(), false);
        if (profile.getBuild() != null) {
            if (profile.getBuild().getPluginManagement() != null) {
                addPluginAssociations(helper, expressionEvaluator, result,
                        profile.getBuild().getPluginManagement().getPlugins());
            }
            addPluginAssociations(helper, expressionEvaluator, result, profile.getBuild().getPlugins());
        }
        if (profile.getReporting() != null) {
            addReportPluginAssociations(helper, expressionEvaluator, result,
                    profile.getReporting().getPlugins());
        }
    }

    // finally, remove any properties without associations
    purgeProperties(result);

    return result.values().toArray(new PropertyVersionsBuilder[result.values().size()]);
}

From source file:org.commonjava.maven.plugins.betterdep.AbstractDepgraphGoal.java

License:Open Source License

protected void readFromReactorProjects() throws MojoExecutionException {
    getLog().info("Initializing direct graph relationships from reactor projects: " + projects);
    for (final MavenProject project : projects) {
        final List<Profile> activeProfiles = project.getActiveProfiles();
        if (activeProfiles != null) {
            for (final Profile profile : activeProfiles) {
                profiles.add(RelationshipUtils.profileLocation(profile.getId()));
            }/* ww w  .  ja  v  a  2  s  .c om*/
        }

        final ProjectVersionRef projectRef = new SimpleProjectVersionRef(project.getGroupId(),
                project.getArtifactId(), project.getVersion());
        roots.add(projectRef);

        final List<Dependency> deps = project.getDependencies();
        //            final List<ProjectVersionRef> roots = new ArrayList<ProjectVersionRef>( deps.size() );

        URI localUri;
        try {
            localUri = new URI(MavenLocationExpander.LOCAL_URI);
        } catch (final URISyntaxException e) {
            throw new MojoExecutionException(
                    "Failed to construct dummy local URI to use as the source of the current project in the depgraph: "
                            + e.getMessage(),
                    e);
        }

        final int index = 0;
        for (final Dependency dep : deps) {
            final ProjectVersionRef depRef = new SimpleProjectVersionRef(dep.getGroupId(), dep.getArtifactId(),
                    dep.getVersion());

            //                roots.add( depRef );

            final List<Exclusion> exclusions = dep.getExclusions();
            final List<ProjectRef> excludes = new ArrayList<ProjectRef>();
            if (exclusions != null && !exclusions.isEmpty()) {
                for (final Exclusion exclusion : exclusions) {
                    excludes.add(new SimpleProjectRef(exclusion.getGroupId(), exclusion.getArtifactId()));
                }
            }

            rootRels.add(new SimpleDependencyRelationship(localUri, projectRef,
                    new SimpleArtifactRef(depRef, dep.getType(), dep.getClassifier(), dep.isOptional()),
                    DependencyScope.getScope(dep.getScope()), index, false,
                    excludes.toArray(new ProjectRef[excludes.size()])));
        }

        final DependencyManagement dm = project.getDependencyManagement();
        if (dm != null) {
            final List<Dependency> managed = dm.getDependencies();
            int i = 0;
            for (final Dependency dep : managed) {
                if ("pom".equals(dep.getType()) && "import".equals(dep.getScope())) {
                    final ProjectVersionRef depRef = new SimpleProjectVersionRef(dep.getGroupId(),
                            dep.getArtifactId(), dep.getVersion());
                    rootRels.add(new SimpleBomRelationship(localUri, projectRef, depRef, i++));
                }
            }
        }

        ProjectVersionRef lastParent = projectRef;
        MavenProject parent = project.getParent();
        while (parent != null) {
            final ProjectVersionRef parentRef = new SimpleProjectVersionRef(parent.getGroupId(),
                    parent.getArtifactId(), parent.getVersion());

            rootRels.add(new SimpleParentRelationship(localUri, projectRef, parentRef));

            lastParent = parentRef;
            parent = parent.getParent();
        }

        rootRels.add(new SimpleParentRelationship(lastParent));
    }

}

From source file:org.eclipse.che.maven.server.MavenServerImpl.java

License:Open Source License

private List<String> getActiveProfiles(MavenProject project) throws RemoteException {
    List<Profile> profiles = new ArrayList<>();

    try {/*w  w  w  .  j  a va2s .co  m*/
        while (project != null) {
            profiles.addAll(project.getActiveProfiles());
            project = project.getParent();
        }
    } catch (Exception e) {
        MavenServerContext.getLogger().info(e);
    }

    return profiles.stream().filter(p -> p.getId() != null).map(Profile::getId).collect(Collectors.toList());
}

From source file:org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.java

License:Open Source License

private static PluginManagement getPluginManagement(MavenProject mavenProject) throws CoreException {
    Model model = new Model();

    Build build = new Build();
    model.setBuild(build);/*from  www . j av  a 2s .com*/

    PluginManagement result = new PluginManagement();
    build.setPluginManagement(result);

    if (mavenProject == null) {
        return null;
    }

    addBuild(result, mavenProject.getOriginalModel().getBuild());

    for (Profile profile : mavenProject.getActiveProfiles()) {
        addBuild(result, profile.getBuild());
    }

    MavenImpl maven = (MavenImpl) MavenPlugin.getMaven();
    maven.interpolateModel(mavenProject, model);

    return result;
}

From source file:org.hudsonci.maven.eventspy_30.handler.ProfileLogger.java

License:Open Source License

@SuppressWarnings("unused")
public static void log(final ExecutionEvent event) {
    if (disabled)
        return;/*from ww  w  .j a va  2 s .c  o m*/

    for (MavenProject project : event.getSession().getProjects()) {
        log.debug("*** Examining profiles for {}.", project.getName());
        logProfileList(project.getActiveProfiles(), "active");
        logProfileList(project.getModel().getProfiles(), "model");

        //logProfiles( event.getSession().getProjectBuildingRequest().getProfiles(), "ProjectBuildingRequest" );
        logProfileList(project.getProjectBuildingRequest().getProfiles(), "ProjectBuildingRequest");

        log.debug("InjectedProfileIds");
        for (Entry<String, List<String>> entry : project.getInjectedProfileIds().entrySet()) {
            log.debug("  from {} are {}", entry.getKey(), entry.getValue());
        }

        Settings settings = event.getSession().getSettings();
        logSettingsProfileList(settings.getProfiles(), "session-settings");

        log.debug("Collected projects: {}", project.getCollectedProjects());
        log.debug("Project references: {}", project.getProjectReferences());
    }
}

From source file:org.jetbrains.idea.maven.server.embedder.Maven2ServerEmbedderImpl.java

License:Apache License

private Collection<String> collectActivatedProfiles(MavenProject mavenProject) {
    // for some reason project's active profiles do not contain parent's profiles - only local and settings'.
    // parent's profiles do not contain settings' profiles.

    List<Profile> profiles = new ArrayList<Profile>();
    while (mavenProject != null) {
        if (profiles != null) {
            profiles.addAll(mavenProject.getActiveProfiles());
        }/*from   w  w  w.j  ava2s  .  c om*/
        mavenProject = mavenProject.getParent();
    }
    return collectProfilesIds(profiles);
}

From source file:org.jetbrains.idea.maven.server.Maven30ServerEmbedderImpl.java

License:Apache License

private static Collection<String> collectActivatedProfiles(MavenProject mavenProject) throws RemoteException {
    // for some reason project's active profiles do not contain parent's profiles - only local and settings'.
    // parent's profiles do not contain settings' profiles.

    List<Profile> profiles = new ArrayList<Profile>();
    try {/*from  w  w  w . j a va  2  s.  c  om*/
        while (mavenProject != null) {
            profiles.addAll(mavenProject.getActiveProfiles());
            mavenProject = mavenProject.getParent();
        }
    } catch (Exception e) {
        // don't bother user if maven failed to build parent project
        Maven3ServerGlobals.getLogger().info(e);
    }
    return collectProfilesIds(profiles);
}

From source file:org.kloeckner.maven.plugin.VersionRange.java

License:Apache License

private Map<String, String> getOriginalVersionMap(MavenProject projects) {
    HashMap<String, String> hashMap = new HashMap<String, String>();

    // TODO depmgmt, parent ...
    if (projects.getParentArtifact() != null) {
        hashMap.put(/*from  w  w  w.j a  va  2 s  .c o  m*/
                ArtifactUtils.versionlessKey(projects.getParentArtifact().getGroupId(),
                        projects.getParentArtifact().getArtifactId()),
                projects.getParentArtifact().getArtifactId());
    }
    hashMap.putAll(buildVersionsMap(projects.getDependencies()));
    if (projects.getDependencyManagement() != null) {
        hashMap.putAll(buildVersionsMap(projects.getDependencyManagement().getDependencies()));
    }

    for (Profile profile : projects.getActiveProfiles()) {
        hashMap.putAll(buildVersionsMap(profile.getDependencies()));
        if (profile.getDependencyManagement() != null) {
            hashMap.putAll(buildVersionsMap(profile.getDependencyManagement().getDependencies()));
        }
    }

    return hashMap;
}