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

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

Introduction

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

Prototype

public boolean isExecutionRoot() 

Source Link

Usage

From source file:io.teecube.t3.GenericReplacerMojo.java

License:Apache License

private void signGPG(MavenProject p)
        throws MojoExecutionException, MavenInvocationException, MojoFailureException, IOException {
    InvocationRequest request = getInvocationRequest(p);
    Invoker invoker = getInvoker();

    InvocationResult result = invoker.execute(request);
    if (result.getExitCode() != 0) {
        CommandLineException executionException = result.getExecutionException();
        if (executionException != null) {
            throw new MojoFailureException("Error during project build: " + executionException.getMessage(),
                    executionException);
        } else {/*w  ww  .j av  a 2 s .  co m*/
            throw new MojoFailureException("Error during project build: " + result.getExitCode());
        }
    }
    if (!p.isExecutionRoot() || p.getModel().getModules().isEmpty()) {
        File gpgTempDirectory = null;
        try {
            URL gpgTempDirectoryURL = new URL(request.getProperties().get("url").toString());
            gpgTempDirectory = new File(gpgTempDirectoryURL.getFile());
            File pomGpgSignature = new File(gpgTempDirectory,
                    p.getGroupId().replaceAll("\\.", "/") + "/" + p.getArtifactId() + "/" + p.getVersion() + "/"
                            + p.getArtifactId() + "-" + p.getVersion() + ".pom.asc");
            File gpgSignatureDest = new File(p.getBuild().getDirectory(), pomGpgSignature.getName());
            pomGpgSignature = new File(p.getFile().getParentFile(), "pom.xml.asc");
            org.apache.commons.io.FileUtils.copyFile(pomGpgSignature, gpgSignatureDest);
        } finally {
            if (gpgTempDirectory != null && gpgTempDirectory.exists()) {
                org.apache.commons.io.FileUtils.deleteDirectory(gpgTempDirectory);
            }
            File ascFile = new File(p.getFile().getParentFile(), "pom.xml.asc");
            if (ascFile.exists()) {
                ascFile.delete();
            }
        }
    }
}

From source file:io.teecube.t3.GenericReplacerMojo.java

License:Apache License

private InvocationRequest getInvocationRequest(MavenProject p) throws MojoExecutionException, IOException {
    InvocationRequest request = new DefaultInvocationRequest();
    request.setPomFile(p.getFile());/*from   w  ww. j  a  v a2  s .  c o m*/
    if (p.isExecutionRoot() && !p.getModel().getModules().isEmpty()) {
        request.setGoals(Lists.newArrayList("gpg:sign"));
    } else {
        File gpgDirectory = Files.createTempDir();
        request.setGoals(Lists.newArrayList("gpg:sign-and-deploy-file"));
        Properties properties = new Properties();
        properties.put("file", p.getFile().getAbsolutePath());
        //         properties.put("pomFile", p.getFile().getAbsolutePath());
        properties.put("groupId", p.getGroupId());
        properties.put("artifactId", p.getArtifactId());
        properties.put("version", p.getVersion());
        properties.put("repositoryId", "null");
        properties.put("url", gpgDirectory.toURI().toURL().toString());
        request.setProperties(properties);
    }
    request.setRecursive(false);
    this.tempSettingsFile = createAndSetTempSettings(request);
    return request;
}

From source file:org.apache.james.mailet.AggregateMailetdocsReport.java

License:Apache License

/**
 * Build descriptors for mailets contained 
 * within subprojects.//from  w ww . j a  v  a2s.  co m
 * @param project not null
 */
protected final List<MailetMatcherDescriptor> buildDescriptors(MavenProject project) {
    final DefaultDescriptorsExtractor extractor = new DefaultDescriptorsExtractor();
    if (project.isExecutionRoot()) {
        logProject(project);
        for (MavenProject subproject : reactorProjects) {
            logSubproject(subproject);
            extractor.extract(subproject, getLog());
        }
    } else {
        logNoSubprojects(project);
        extractor.extract(project, getLog());
    }
    return extractor.descriptors();
}

From source file:org.jasig.maven.legal.util.ResourceFinder.java

License:Apache License

private URL searchProjectTree(MavenProject project, String resource) {
    // first search relatively to the base directory
    URL res = toURL(new File(project.getBasedir(), resource));
    if (res != null) {
        return res;
    }/*  w  w  w  . j ava  2s. c o m*/

    //Look up the project tree to try and find a match as well.
    final MavenProject parent = project.getParent();
    if (!project.isExecutionRoot() && parent != null && parent.getBasedir() != null) {
        return this.searchProjectTree(parent, resource);
    }

    return null;
}

From source file:org.jetbrains.maven.embedder.MavenEmbedder.java

License:Apache License

@Nonnull
private MavenExecutionResult readProject(@Nonnull final MavenExecutionRequest request) {
    ProfileManager globalProfileManager = request.getGlobalProfileManager();
    globalProfileManager.loadSettingsProfiles(request.getSettings());

    MavenProject rootProject = null;/*from  www .j  a  v a 2s  .  co  m*/
    final List<Exception> exceptions = new ArrayList<Exception>();
    Object result = null;
    try {
        final File pomFile = new File(request.getPomFile());
        if (!pomFile.exists()) {
            throw new FileNotFoundException("File doesn't exist: " + pomFile.getPath());
        }

        final Method getProjectsMethod = DefaultMaven.class.getDeclaredMethod("getProjects",
                MavenExecutionRequest.class);
        getProjectsMethod.setAccessible(true);
        Maven maven = getComponent(Maven.class);
        result = getProjectsMethod.invoke(maven, request);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        return handleException(e.getTargetException());
    } catch (Exception e) {
        return handleException(e);
    }

    if (result != null) {
        MavenProjectBuilder builder = getComponent(MavenProjectBuilder.class);
        for (Object p : (List) result) {
            MavenProject project = (MavenProject) p;
            try {
                builder.calculateConcreteState(project, request.getProjectBuilderConfiguration(), false);
            } catch (ModelInterpolationException e) {
                exceptions.add(e);
            }

            if (project.isExecutionRoot()) {
                rootProject = project;
            }
        }

        if (rootProject == null && exceptions.isEmpty()) {
            throw new RuntimeException("Could't build project for unknown reason");
        }
    }

    return new MavenExecutionResult(rootProject, exceptions);
}

From source file:org.jfrog.jade.plugins.idea.AbstractIdeaMojo.java

License:Apache License

protected void doDependencyResolution() throws InvalidDependencyVersionException, ProjectBuildingException,
        InvalidVersionSpecificationException {
    // If the execution root project is not a parent (meaning it is last one in reactor list)
    // Then the mojo will inherit manually its configuration
    if (reactorProjects != null) {
        int nbProjects = reactorProjects.size();
        // Get the last project it contains the specific ideaj configuration
        if (nbProjects > 1) {
            MavenProject lastproject = reactorProjects.get(nbProjects - 1);
            if (lastproject.isExecutionRoot()) {
                //noinspection unchecked
                List<Plugin> plugins = lastproject.getBuildPlugins();
                fillPluginSettings(plugins, "jade-idea-plugin", this, null);
            }/*from   w  w  w  .  j  a  v  a2  s .  c om*/
        }
    }

    MavenProject project = getExecutedProject();
    ArtifactRepository localRepo = getLocalRepository();
    Map managedVersions = createManagedVersionMap();

    try {
        ArtifactResolutionResult result = getArtifactResolver().resolveTransitively(getProjectArtifacts(),
                project.getArtifact(), managedVersions, localRepo, project.getRemoteArtifactRepositories(),
                artifactMetadataSource);

        project.setArtifacts(result.getArtifacts());
    } catch (ArtifactNotFoundException e) {
        getLog().debug(e.getMessage(), e);

        StringBuffer msg = new StringBuffer();
        msg.append("An error occurred during dependency resolution.\n\n");
        msg.append("    Failed to retrieve ").append(e.getDownloadUrl()).append("\n");
        msg.append("from the following repositories:");
        for (Iterator repositories = e.getRemoteRepositories().iterator(); repositories.hasNext();) {
            ArtifactRepository repository = (ArtifactRepository) repositories.next();
            msg.append("\n    ").append(repository.getId()).append("(").append(repository.getUrl()).append(")");
        }
        msg.append("\nCaused by: ").append(e.getMessage());

        getLog().warn(msg);
    } catch (ArtifactResolutionException e) {
        getLog().debug(e.getMessage(), e);

        StringBuffer msg = new StringBuffer();
        msg.append("An error occurred during dependency resolution of the following artifact:\n\n");
        msg.append("    ").append(e.getGroupId()).append(":").append(e.getArtifactId()).append(e.getVersion())
                .append("\n\n");
        msg.append("Caused by: ").append(e.getMessage());

        getLog().warn(msg);
    }
}

From source file:org.kloeckner.maven.plugin.util.VersionRangeUtils.java

License:Apache License

public static MavenProject getRootProject(List<MavenProject> reactorProjects) {
    MavenProject project = reactorProjects.get(0);
    for (MavenProject currentProject : reactorProjects) {
        if (currentProject.isExecutionRoot()) {
            project = currentProject;/* ww w .jav  a2s .  co m*/
            break;
        }
    }
    return project;
}

From source file:org.mobicents.maven.plugin.EclipseMojo.java

License:Open Source License

/**
 * @see org.apache.maven.plugin.Mojo#execute()
 *///  w w w  .  j a  va 2s  .  c  o m
public void execute() throws MojoExecutionException

{
    if (!project.isExecutionRoot() && !generateProjectsForModules) {
        getLog().warn(
                "Skipping module because execution root project didn't configured generateProjectsForModules property as true");
        return;
    }
    try {
        final MavenProject rootProject = this.getRootProject();
        final ProjectWriter projectWriter = new ProjectWriter(rootProject, this.getLog());
        projectWriter.write(eclipseProjectName != null ? eclipseProjectName : project.getArtifactId());
        final Map originalCompileSourceRoots = this.collectProjectCompileSourceRoots();
        final List projects = this.collectProjects();
        this.processCompileSourceRoots(projects);
        final ClasspathWriter classpathWriter = new ClasspathWriter(rootProject, this.getLog());
        //TODO refactor to pass all arguments as an Options class or this will keep increasing the method signature
        classpathWriter.write(projects, this.repositoryVariableName, this.artifactFactory,
                this.artifactResolver, this.localRepository, this.artifactMetadataSource,
                this.classpathArtifactTypes, this.project.getRemoteArtifactRepositories(),
                this.resolveTransitiveDependencies, this.classpathMerge, this.classpathExcludes,
                this.includeResourcesDirectory);
        // - reset to the original source roots
        for (final Iterator iterator = projects.iterator(); iterator.hasNext();) {
            final MavenProject project = (MavenProject) iterator.next();
            project.getCompileSourceRoots().clear();
            project.getCompileSourceRoots().addAll((List) originalCompileSourceRoots.get(project));
        }
    } catch (Throwable throwable) {
        throwable.printStackTrace();
        throw new MojoExecutionException("Error creating eclipse configuration", throwable);
    }

}

From source file:org.ops4j.pax.construct.clone.CloneMojo.java

License:Apache License

/**
 * Analyze major project and build the right pax-create-project call
 * /*from  w  ww .j  a  v  a  2 s  .  c  o m*/
 * @param script build script
 * @param project major Maven project
 */
private void handleMajorProject(PaxScript script, MavenProject project) {
    if (unify && !project.isExecutionRoot()) {
        // exclude the local poms settings from the unified project
        m_handledDirs.add(new File(project.getBasedir(), "poms"));
        return;
    }

    PaxCommandBuilder command = script.call(PaxScript.CREATE_PROJECT);

    command.option('g', project.getGroupId());
    command.option('a', project.getArtifactId());
    command.option('v', project.getVersion());

    setTargetDirectory(command, project.getBasedir().getParentFile());
    registerProject(project);

    m_majorProjectMap.put(project, command);
}

From source file:org.ops4j.pax.construct.clone.CloneMojo.java

License:Apache License

/**
 * Analyze the position of this project in the tree, as not all projects need their own distinct set of "poms"
 * /*from   w  w w .  jav a 2s  .  c  o  m*/
 * @param project Maven POM project
 * @return true if this project requires a pax-create-project call
 */
private boolean isMajorProject(MavenProject project) {
    if (project.isExecutionRoot()) {
        // top-most project
        return true;
    }

    // disconnected project, or project with its own set of "poms" where settings can be customized
    return (null == project.getParent() || new File(project.getBasedir(), "poms").isDirectory());
}