Search in sources :

Example 1 with MavenExecutionResult

use of org.apache.maven.execution.MavenExecutionResult in project kie-wb-common by kiegroup.

the class MavenBuildExecutor method executeMaven.

public static void executeMaven(final File pom, final PrintStream stdout, final PrintStream stderr, final Properties properties, final String... goals) {
    final PrintStream oldout = System.out;
    final PrintStream olderr = System.err;
    final Properties oldProperties = System.getProperties();
    if (properties != null) {
        properties.keySet().forEach((o) -> {
            if (properties.getProperty((String) o) != null) {
                System.setProperty((String) o, properties.getProperty((String) o));
            }
        });
    }
    final MavenEmbedder mavenEmbedder = newMavenEmbedder();
    try {
        if (stdout != null) {
            System.setOut(stdout);
        }
        if (stderr != null) {
            System.setErr(stderr);
        }
        final MavenRequest mavenRequest = MavenProjectLoader.createMavenRequest(false);
        mavenRequest.setGoals(Arrays.asList(goals));
        mavenRequest.setPom(pom.getAbsolutePath());
        final MavenExecutionResult result = mavenEmbedder.execute(mavenRequest);
        if (result.hasExceptions()) {
            for (Throwable t : result.getExceptions()) {
                LOG.error("Error Running Maven", t);
            }
            throw new BuildException("Maven found issues trying to build the pom file: " + pom.getAbsolutePath() + ". Look at the Error Logs for more information");
        }
    } catch (final MavenEmbedderException ex) {
        throw new BuildException("Maven coudn't build the project for pom file: " + pom.getAbsolutePath(), ex);
    } finally {
        System.setProperties(oldProperties);
        mavenEmbedder.dispose();
        System.setOut(oldout);
        System.setErr(olderr);
    }
}
Also used : PrintStream(java.io.PrintStream) MavenEmbedder(org.appformer.maven.integration.embedder.MavenEmbedder) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) MavenEmbedderException(org.appformer.maven.integration.embedder.MavenEmbedderException) BuildException(org.guvnor.ala.exceptions.BuildException) Properties(java.util.Properties) MavenRequest(org.appformer.maven.integration.embedder.MavenRequest)

Example 2 with MavenExecutionResult

use of org.apache.maven.execution.MavenExecutionResult in project kie-wb-common by kiegroup.

the class AFMavenCli method execute.

protected int execute(AFCliRequest cliRequest) throws MavenExecutionRequestPopulationException {
    MavenExecutionRequest request = executionRequestPopulator.populateDefaults(cliRequest.getRequest());
    eventSpyDispatcher.onEvent(request);
    MavenExecutionResult result = maven.execute(request);
    eventSpyDispatcher.onEvent(result);
    eventSpyDispatcher.close();
    if (result.hasExceptions()) {
        ExceptionHandler handler = new DefaultExceptionHandler();
        Map<String, String> references = new LinkedHashMap<String, String>();
        MavenProject project = null;
        for (Throwable exception : result.getExceptions()) {
            ExceptionSummary summary = handler.handleException(exception);
            logSummary(summary, references, "", cliRequest.isShowErrors());
            if (project == null && exception instanceof LifecycleExecutionException) {
                project = ((LifecycleExecutionException) exception).getProject();
            }
        }
        slf4jLogger.error("");
        if (!cliRequest.isShowErrors()) {
            slf4jLogger.error("To see the full stack trace of the errors, re-run Maven with the -e switch.");
        }
        if (!slf4jLogger.isDebugEnabled()) {
            slf4jLogger.error("Re-run Maven using the -X switch to enable full debug logging.");
        }
        if (!references.isEmpty()) {
            slf4jLogger.error("");
            slf4jLogger.error("For more information about the errors and possible solutions" + ", please read the following articles:");
            for (Entry<String, String> entry : references.entrySet()) {
                slf4jLogger.error(entry.getValue() + " " + entry.getKey());
            }
        }
        if (project != null && !project.equals(result.getTopologicallySortedProjects().get(0))) {
            slf4jLogger.error("");
            slf4jLogger.error("After correcting the problems, you can resume the build with the command");
            slf4jLogger.error("  mvn <goals> -rf :" + project.getArtifactId());
        }
        if (MavenExecutionRequest.REACTOR_FAIL_NEVER.equals(cliRequest.getRequest().getReactorFailureBehavior())) {
            slf4jLogger.info("Build failures were ignored.");
            return 0;
        } else {
            return 1;
        }
    } else {
        return 0;
    }
}
Also used : DefaultExceptionHandler(org.apache.maven.exception.DefaultExceptionHandler) ExceptionHandler(org.apache.maven.exception.ExceptionHandler) ExceptionSummary(org.apache.maven.exception.ExceptionSummary) MavenProject(org.apache.maven.project.MavenProject) LifecycleExecutionException(org.apache.maven.lifecycle.LifecycleExecutionException) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultExceptionHandler(org.apache.maven.exception.DefaultExceptionHandler) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with MavenExecutionResult

use of org.apache.maven.execution.MavenExecutionResult in project tycho by eclipse.

the class ArtifactDependencyWalkerTest method getTargetPlatform.

protected DependencyArtifacts getTargetPlatform() throws Exception {
    LocalDependencyResolver resolver = (LocalDependencyResolver) lookup(DependencyResolver.class, LocalDependencyResolver.ROLE_HINT);
    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setLocalRepository(new StubArtifactRepository(System.getProperty("java.io.tmpdir")));
    MavenExecutionResult result = new DefaultMavenExecutionResult();
    DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
    MavenSession session = new MavenSession(getContainer(), repositorySession, request, result);
    session.setProjects(new ArrayList<MavenProject>());
    lookup(LegacySupport.class).setSession(session);
    MavenProject project = new MavenProject();
    resolver.setLocation(new File("src/test/resources/targetplatforms/basic"));
    DependencyArtifacts platform = resolver.resolveDependencies(session, project, null, DefaultReactorProject.adapt(session), null);
    return platform;
}
Also used : DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) LegacySupport(org.apache.maven.plugin.LegacySupport) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DependencyResolver(org.eclipse.tycho.core.DependencyResolver) LocalDependencyResolver(org.eclipse.tycho.core.osgitools.targetplatform.LocalDependencyResolver) MavenSession(org.apache.maven.execution.MavenSession) LocalDependencyResolver(org.eclipse.tycho.core.osgitools.targetplatform.LocalDependencyResolver) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) MavenProject(org.apache.maven.project.MavenProject) StubArtifactRepository(org.apache.maven.plugin.testing.stubs.StubArtifactRepository) File(java.io.File)

Example 4 with MavenExecutionResult

use of org.apache.maven.execution.MavenExecutionResult in project tycho by eclipse.

the class LocalDependencyResolverTest method getTargetPlatform.

protected DependencyArtifacts getTargetPlatform(File location) throws Exception, IOException {
    LocalDependencyResolver resolver = (LocalDependencyResolver) lookup(DependencyResolver.class, LocalDependencyResolver.ROLE_HINT);
    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setLocalRepository(new StubArtifactRepository(location.getAbsolutePath()));
    MavenExecutionResult result = new DefaultMavenExecutionResult();
    DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
    MavenSession session = new MavenSession(getContainer(), repositorySession, request, result);
    session.setProjects(new ArrayList<MavenProject>());
    lookup(LegacySupport.class).setSession(session);
    MavenProject project = new MavenProject();
    resolver.setLocation(location);
    DependencyArtifacts platform = resolver.resolveDependencies(session, project, null, DefaultReactorProject.adapt(session), null);
    return platform;
}
Also used : DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) LegacySupport(org.apache.maven.plugin.LegacySupport) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DependencyResolver(org.eclipse.tycho.core.DependencyResolver) LocalDependencyResolver(org.eclipse.tycho.core.osgitools.targetplatform.LocalDependencyResolver) MavenSession(org.apache.maven.execution.MavenSession) LocalDependencyResolver(org.eclipse.tycho.core.osgitools.targetplatform.LocalDependencyResolver) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) MavenProject(org.apache.maven.project.MavenProject) StubArtifactRepository(org.apache.maven.plugin.testing.stubs.StubArtifactRepository)

Example 5 with MavenExecutionResult

use of org.apache.maven.execution.MavenExecutionResult in project tycho by eclipse.

the class MavenDependencyCollectorTest method getSortedProjects.

private List<MavenProject> getSortedProjects(MavenExecutionRequest request) {
    request.getProjectBuildingRequest().setProcessPlugins(false);
    MavenExecutionResult result = maven.execute(request);
    if (result.hasExceptions()) {
        throw new CompoundRuntimeException(result.getExceptions());
    }
    return result.getTopologicallySortedProjects();
}
Also used : MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) CompoundRuntimeException(org.eclipse.tycho.testing.CompoundRuntimeException)

Aggregations

MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)15 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)11 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)8 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)7 MavenSession (org.apache.maven.execution.MavenSession)7 File (java.io.File)6 MavenProject (org.apache.maven.project.MavenProject)5 Properties (java.util.Properties)3 StubArtifactRepository (org.apache.maven.plugin.testing.stubs.StubArtifactRepository)3 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)3 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)3 LegacySupport (org.apache.maven.plugin.LegacySupport)2 ProjectBuilder (org.apache.maven.project.ProjectBuilder)2 ProjectBuildingResult (org.apache.maven.project.ProjectBuildingResult)2 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)2 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)2 DependencyResolver (org.eclipse.tycho.core.DependencyResolver)2 LocalDependencyResolver (org.eclipse.tycho.core.osgitools.targetplatform.LocalDependencyResolver)2 PrintStream (java.io.PrintStream)1 Field (java.lang.reflect.Field)1