Example usage for org.apache.maven.execution MavenExecutionRequest getExecutionListener

List of usage examples for org.apache.maven.execution MavenExecutionRequest getExecutionListener

Introduction

In this page you can find the example usage for org.apache.maven.execution MavenExecutionRequest getExecutionListener.

Prototype

ExecutionListener getExecutionListener();

Source Link

Usage

From source file:com.github.htfv.maven.plugins.buildconfigurator.core.configurators.propertyfiles.PropertyFileConfigurator.java

License:Apache License

/**
 * Reinterpolates all elements of the project model.
 *
 * @param ctx//from  ww  w  .j ava2 s. c  om
 *            The configuration context.
 * @param resultBuilder
 *            The result builder.
 */
private void reinterpolateProjectModel(final ConfigurationContext ctx, final Result.Builder resultBuilder) {
    //
    // Maven interpolates expressions when it loads the model. Since the
    // properties are loaded after the model, we have to interpolate
    // expressions again.
    //
    // It is actually not required for mojo parameters, because parameters
    // are interpolated before mojo is executed. However, it can be a
    // problem if mojo accesses model, like maven-resources-plugin accessing
    // project.build.resources.
    //
    // We take a conservative approach and only replace properties which
    // were loaded by the build configurator.
    //

    final ModelInterpolator interpolator = new ModelInterpolator(resultBuilder.newProperties());

    interpolator.interpolateModel(ctx.getProject().getModel());

    //
    // Maven interpolates mojo parameters before execution, but it skips
    // parameters of the PlexusConfiguration type. Updating the model now
    // has no effect, because execution plan is already calculated and mojo
    // configuration is copied to mojo execution. We cannot get access to
    // mojo execution, so we register a listener which will be called before
    // mojo is executed.
    //

    if (!ctx.getRequest().isConnectorRequest()) {
        final MavenSession mavenSession = ctx.getMavenSession();
        final MavenExecutionRequest executionRequest = mavenSession.getRequest();
        final ExecutionListener executionListener = executionRequest.getExecutionListener();

        executionRequest.setExecutionListener(new DelegatingExecutionListener(executionListener) {
            @Override
            public void mojoStarted(final ExecutionEvent event) {
                interpolator.interpolateDOM(event.getMojoExecution().getConfiguration());

                super.mojoStarted(event);
            }

            @Override
            public void projectFailed(final ExecutionEvent event) {
                event.getSession().getRequest().setExecutionListener(getDelegate());
                super.projectFailed(event);
            }

            @Override
            public void projectSucceeded(final ExecutionEvent event) {
                event.getSession().getRequest().setExecutionListener(getDelegate());
                super.projectSucceeded(event);
            }
        });
    }
}

From source file:com.soebes.maven.extensions.BuildTimeProfiler.java

License:Apache License

private void executionRequestEventHandler(MavenExecutionRequest event) {
    // event.getUserProperties().put( "revision", "1.2.3-SNAPSHOT" );
    // event.getSystemProperties().put( "revision", "1.2.3-SNAPSHOT" );
    // Can we do something more useful here?
    LOGGER.debug("MBTP: executionRequestEventHandler: {}", event.getExecutionListener());
}

From source file:com.sumologic.maven.stats.SumoLogicProfilingParticipant.java

License:Apache License

private void ensureInstalled(MavenSession session) {
    if (!installed) {
        synchronized (this) {
            if (!installed) { // Double lock makes this thread safe and does not repeat the work
                MavenExecutionRequest request = session.getRequest();
                ExecutionListener currentListener = request.getExecutionListener();

                String sumoEndpoint = session.getCurrentProject().getProperties()
                        .getProperty("sumologic.http.endpoint");
                ProfilingSerializer serializer = new JsonProfilingSerializer();
                ProfilingPublisher profilingPublisher = new SumoLogicProfilingPublisher(logger, sumoEndpoint,
                        serializer);/*from  ww w.  j  a v a 2  s  . c o  m*/
                ExecutionListener profilingListener = new ProfilePublishingExecutionListener(
                        profilingPublisher);

                ExecutionListener chainedListener = ChainedExecutionListener.buildFrom(currentListener,
                        profilingListener);
                request.setExecutionListener(chainedListener);

                installed = true;
            }
        }
    }
}

From source file:io.fabric8.vertx.maven.plugin.mojos.MojoSpy.java

License:Apache License

public MojoSpy(MavenExecutionRequest request) {
    this.delegate = request.getExecutionListener();
    this.request = request;
}

From source file:io.reactiverse.vertx.maven.plugin.mojos.MojoSpy.java

License:Apache License

private MojoSpy(MavenExecutionRequest request) {
    this.delegate = request.getExecutionListener();
    this.request = request;
}

From source file:io.takari.maven.timeline.BuildEventsExtension.java

License:Apache License

@Override
public void afterProjectsRead(MavenSession session) {
    MavenExecutionRequest request = session.getRequest();
    ExecutionListener original = request.getExecutionListener();
    BuildEventListener listener = new BuildEventListener(logFile(session), mavenTimelineFile(session));
    ExecutionListener chain = new ExecutionListenerChain(original, listener);
    request.setExecutionListener(chain);
}

From source file:net.gageot.maven.BuildEventsExtension.java

License:Apache License

@Override
public void afterProjectsRead(MavenSession session) {
    MavenExecutionRequest request = session.getRequest();

    ExecutionListener original = request.getExecutionListener();
    BuildEventListener listener = new BuildEventListener(logFile(session));
    ExecutionListener chain = new ExecutionListenerChain(original, listener);

    request.setExecutionListener(chain);
}

From source file:org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.java

License:Open Source License

private void registerExecutionListener(MavenSession session) {
    MavenExecutionRequest request = session.getRequest();
    ChainedExecutionListener listener = new ChainedExecutionListener(request.getExecutionListener());
    listener.addListener(new AbstractExecutionListener() {

        @Override/*ww  w .java  2s . c o m*/
        public void sessionEnded(ExecutionEvent event) {
            try {
                EquinoxServiceFactory equinoxServiceFactory = plexus.lookup(EquinoxServiceFactory.class);
                if (equinoxServiceFactory != null) {
                    plexus.release(equinoxServiceFactory);
                }
            } catch (ComponentLifecycleException e) {
                // we tried
            } catch (ComponentLookupException e) {
                // we tried
            }
        }

    });
    request.setExecutionListener(listener);
}

From source file:org.sourcepit.common.maven.testing.EmbeddedMaven.java

License:Apache License

public MavenExecutionResult2 buildProject(File pom, Properties userProperties, boolean resolveDependencies)
        throws Exception {
    final MavenExecutionRequest request = newMavenExecutionRequest(pom, newSystemProperties(), userProperties,
            "compile");
    request.getProjectBuildingRequest().setProcessPlugins(false);
    request.getProjectBuildingRequest().setResolveDependencies(resolveDependencies);

    final MavenSession[] session = new MavenSession[1];
    request.setExecutionListener(new ChainedExecutionListener(request.getExecutionListener()) {
        @Override//from w ww  .  j a va  2  s  . co m
        public void sessionStarted(ExecutionEvent event) {
            super.sessionStarted(event);
            session[0] = event.getSession();
            throw new IllegalStateException();
        }
    });

    final MavenExecutionResult2 tmpResult = execute(request);
    if (session[0] == null) {
        if (tmpResult.hasExceptions()) {
            throw new IllegalStateException(tmpResult.getExceptions().get(0));
        }
    }

    final MavenExecutionResult2 result = new MavenExecutionResult2Impl(session[0], session[0].getResult());
    if (request.getProjectBuildingRequest().isResolveDependencies()) {
        Set<Artifact> projectArtifacts = new HashSet<Artifact>();

        for (MavenProject mavenProject : result.getTopologicallySortedProjects()) {
            File artifactFile = MavenProjectUtils.getOutputDir(mavenProject);
            if (artifactFile == null) {
                artifactFile = mavenProject.getBasedir();
            }
            mavenProject.getArtifact().setFile(artifactFile);
            mavenProject.getArtifact().setResolved(true);

            projectArtifacts.add(mavenProject.getArtifact());

            mavenProject.addLifecyclePhase("clean");
            mavenProject.addLifecyclePhase("process-resources");
            mavenProject.addLifecyclePhase("compile");

            ArrayList<String> scopesToCollect = new ArrayList<String>();
            Collections.addAll(scopesToCollect, "system", "compile", "provided", "runtime", "test");

            try {
                resolver.resolveProjectDependencies(mavenProject, scopesToCollect, scopesToCollect,
                        result.getSession(), true, Collections.<Artifact>emptySet());
            } catch (LifecycleExecutionException e) {
                result.addException(e);
            }

            mavenProject.setArtifactFilter(new CumulativeScopeArtifactFilter(scopesToCollect));
        }
    }
    if (result.hasExceptions()) {
        throw new IllegalStateException(result.getExceptions().get(0));
    }

    return result;
}

From source file:org.sourcepit.common.maven.testing.EmbeddedMaven.java

License:Apache License

public MavenExecutionResult2 execute(MavenExecutionRequest request) {
    final MavenSession[] session = new MavenSession[1];
    request.setExecutionListener(new ChainedExecutionListener(request.getExecutionListener()) {
        @Override//w ww.ja  v a  2  s. c  om
        public void sessionStarted(ExecutionEvent event) {
            super.sessionStarted(event);
            session[0] = event.getSession();
        }
    });

    final MavenSession currentSession = buildContext.getSession();
    final MavenExecutionResult result;
    try {
        eventSpyDispatcher.onEvent(request);
        result = maven.execute(request);
        eventSpyDispatcher.onEvent(result);
    } finally {
        buildContext.setSession(currentSession);
    }

    return new MavenExecutionResult2Impl(session[0], result);
}