Example usage for org.apache.maven.execution MavenSession getSortedProjects

List of usage examples for org.apache.maven.execution MavenSession getSortedProjects

Introduction

In this page you can find the example usage for org.apache.maven.execution MavenSession getSortedProjects.

Prototype

@Deprecated
    public List<MavenProject> getSortedProjects() 

Source Link

Usage

From source file:org.mobicents.maven.plugin.utils.ProjectUtils.java

License:Open Source License

/**
 * Attempts to retrieve the Maven project for the given <code>pom</code>.
 *
 * @param pom the POM to find.//from w w w  . j a v a2  s. c  om
 * @return the maven project with the matching POM.
 */
private static MavenProject getProjectFromSession(final MavenSession session, final File pom) {
    MavenProject foundProject = null;
    for (final Iterator projectIterator = session.getSortedProjects().iterator(); projectIterator.hasNext();) {
        final MavenProject project = (MavenProject) projectIterator.next();
        final File projectPom = new File(project.getBasedir(), POM_FILE);
        if (projectPom.equals(pom)) {
            foundProject = project;
        }
    }
    return foundProject;
}

From source file:org.sonar.batch.MavenReactor.java

License:Open Source License

public MavenReactor(MavenSession mavenSession) {
    this.sortedProjects = mavenSession.getSortedProjects();
}

From source file:org.sonatype.maven.mojo.execution.MojoExecution.java

License:Open Source License

/**
 * Returns true if the current project is the last one being executed in this build.
 *
 * @param mavenSession the MavenSession//from  w w  w  .  j ava 2 s. c o m
 * @return true if last project is being built.
 */
public static boolean isCurrentTheLastProjectInExecution(final MavenSession mavenSession) {
    final MavenProject currentProject = mavenSession.getCurrentProject();
    final MavenProject lastProject = mavenSession.getSortedProjects()
            .get(mavenSession.getSortedProjects().size() - 1);

    return currentProject == lastProject;
}

From source file:org.sonatype.maven.mojo.execution.MojoExecution.java

License:Open Source License

/**
 * Returns first MavenProject from projects being built that has this Mojo defined.
 *
 * @param mavenSession     the MavenSession.
 * @param pluginGroupId    the plugin's groupId.
 * @param pluginArtifactId the plugin's artifactId.
 * @param goal             the goal to search for and have execution or {@code null} if just interested in plugin
 *                         presence.//from  w w  w  .j a v  a2s . com
 * @return MavenProject of first project with given plugin is being built or null.
 */
public static MavenProject getFirstProjectWithMojoInExecution(final MavenSession mavenSession,
        final String pluginGroupId, final String pluginArtifactId, final String goal) {
    final ArrayList<MavenProject> projects = new ArrayList<MavenProject>(mavenSession.getSortedProjects());
    MavenProject firstWithThisMojo = null;
    for (MavenProject project : projects) {
        if (null != findPlugin(project.getBuild(), pluginGroupId, pluginArtifactId, goal)) {
            firstWithThisMojo = project;
            break;
        }
    }
    return firstWithThisMojo;
}

From source file:org.sonatype.maven.mojo.execution.MojoExecution.java

License:Open Source License

/**
 * Returns last MavenProject from projects being built that has this Mojo defined.
 *
 * @param mavenSession     the MavenSession.
 * @param pluginGroupId    the plugin's groupId.
 * @param pluginArtifactId the plugin's artifactId.
 * @param goal             the goal to search for and have execution or {@code null} if just interested in plugin
 *                         presence.//w w  w .ja v a  2s  .c om
 * @return MavenProject of last project with given plugin is being built or null.
 */
public static MavenProject getLastProjectWithMojoInExecution(final MavenSession mavenSession,
        final String pluginGroupId, final String pluginArtifactId, final String goal) {
    final ArrayList<MavenProject> projects = new ArrayList<MavenProject>(mavenSession.getSortedProjects());
    Collections.reverse(projects);
    MavenProject lastWithThisMojo = null;
    for (MavenProject project : projects) {
        if (null != findPlugin(project.getBuild(), pluginGroupId, pluginArtifactId, goal)) {
            lastWithThisMojo = project;
            break;
        }
    }
    return lastWithThisMojo;
}