Example usage for org.apache.maven.execution ExecutionEvent getMojoExecution

List of usage examples for org.apache.maven.execution ExecutionEvent getMojoExecution

Introduction

In this page you can find the example usage for org.apache.maven.execution ExecutionEvent getMojoExecution.

Prototype

MojoExecution getMojoExecution();

Source Link

Document

Gets the current mojo execution (if any).

Usage

From source file:co.leantechniques.maven.Project.java

License:Apache License

private PluginExecution addExecution(ExecutionEvent event) {
    MojoExecution mojoExecution = event.getMojoExecution();
    PluginExecution execution = new PluginExecution(plugin(event), mojoExecution.getGoal(),
            mojoExecution.getExecutionId());
    pluginExecutions.add(execution);/*w w  w. java 2  s . co m*/
    indexedExecutions.put(generateKeyFrom(event), execution);
    return execution;
}

From source file:co.leantechniques.maven.Project.java

License:Apache License

private String generateKeyFrom(ExecutionEvent event) {
    MojoExecution mojoExecution = event.getMojoExecution();
    return mojoExecution.getGroupId() + mojoExecution.getArtifactId() + mojoExecution.getGoal()
            + mojoExecution.getExecutionId();
}

From source file:co.leantechniques.maven.Project.java

License:Apache License

private Artifact plugin(ExecutionEvent event) {
    return new Artifact(event.getMojoExecution().getGroupId(), event.getMojoExecution().getArtifactId(),
            event.getMojoExecution().getVersion());
}

From source file:com.ccoe.build.profiler.lifecycle.MavenLifecycleProfiler.java

License:Apache License

@Override
public void onEvent(Object event) throws Exception {

    if (event instanceof SettingsBuildingRequest) {
        SettingsBuildingRequest settingBuildingRequest = (SettingsBuildingRequest) event;
        userSettingFile = settingBuildingRequest.getUserSettingsFile();
        globalSettingFile = settingBuildingRequest.getGlobalSettingsFile();
    }/*ww w  .  j  a va  2s  .  c  om*/

    if (event instanceof MavenExecutionRequest) {
        MavenExecutionRequest mer = (MavenExecutionRequest) event;
        debug = (mer.getLoggingLevel() == MavenExecutionRequest.LOGGING_LEVEL_DEBUG);
        context.getData().put("baseAdd", mer.getBaseDirectory());
    }

    if (event instanceof ExecutionEvent) {

        ExecutionEvent executionEvent = (ExecutionEvent) event;

        if (executionEvent.getType() == ExecutionEvent.Type.ProjectDiscoveryStarted) {
            discoveryProfile = new DiscoveryProfile(context, executionEvent, userSettingFile, globalSettingFile,
                    debug);

        } else if (executionEvent.getType() == ExecutionEvent.Type.SessionStarted) {
            sessionProfile = new SessionProfile(context, executionEvent, debug);
        } else if (executionEvent.getType() == ExecutionEvent.Type.SessionEnded) {
            projectProfile.addPhaseProfile(phaseProfile);

            //if can accelerate,we will not generate the dependency file

            sessionProfile.stop();
            discoveryProfile.stop();
            OutputRenderer renderer = new OutputRenderer(sessionProfile, discoveryProfile);
            renderer.renderToScreen();
            // renderer.renderToJSON();
        } else if (executionEvent.getType() == ExecutionEvent.Type.ProjectStarted) {
            projectProfile = new ProjectProfile(context, executionEvent.getProject(), executionEvent);
        } else if (executionEvent.getType() == ExecutionEvent.Type.ProjectSucceeded
                || executionEvent.getType() == ExecutionEvent.Type.ProjectFailed) {

            if (phaseProfile != null)
                phaseProfile.stop();
            projectProfile.stop();
            sessionProfile.addProjectProfile(projectProfile);
        } else if (executionEvent.getType() == ExecutionEvent.Type.MojoStarted) {
            String phase = executionEvent.getMojoExecution().getLifecyclePhase();
            if (phaseProfile == null) {
                phaseProfile = new PhaseProfile(context, phase, executionEvent);
            } else if (phase == null) {
                phaseProfile.stop();
                projectProfile.addPhaseProfile(phaseProfile);
                phaseProfile = new PhaseProfile(context, "default", executionEvent);
            } else if (!phase.equals(phaseProfile.getPhase())) {
                phaseProfile.stop();
                projectProfile.addPhaseProfile(phaseProfile);
                phaseProfile = new PhaseProfile(context, phase, executionEvent);
            }
            mojoProfile = new MojoProfile(context, executionEvent.getMojoExecution(), executionEvent);
        } else if (executionEvent.getType() == ExecutionEvent.Type.MojoSucceeded
                || executionEvent.getType() == ExecutionEvent.Type.MojoFailed) {
            mojoProfile.stop();
            phaseProfile.addMojoProfile(mojoProfile);
        }
    }
}

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//  w w  w .  j  a  va2s.  co m
 *            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.paulhammant.buildradiatorextension.BuildRadiatorEventSpy.java

License:Open Source License

@Override
public void onEvent(Object event) throws Exception {

    try {//  ww w  .j  a  v a  2s .  c o  m

        try {
            if (event instanceof ExecutionEvent) {
                ExecutionEvent executionEvent = (ExecutionEvent) event;
                MavenProject project = executionEvent.getProject();
                String lifecyclePhase = executionEvent.getMojoExecution().getLifecyclePhase();
                String phase = lifecyclePhase.substring(lifecyclePhase.lastIndexOf(':') + 1);
                String execution = executionEvent.getMojoExecution().getExecutionId();

                String currentArtifactId = project.getArtifactId();

                if (!projectPropertiesDone) {
                    this.buildRadiatorInterop.projectProperties(project.getProperties(),
                            project.getArtifactId());
                    projectPropertiesDone = true;
                }

                String status = executionEvent.getType().toString();
                if (executionEvent.getType() == ExecutionEvent.Type.MojoStarted) {
                    status = "started";
                } else if (executionEvent.getType() == ExecutionEvent.Type.MojoFailed) {
                    status = "failed";
                } else if (executionEvent.getType() == ExecutionEvent.Type.MojoSucceeded) {
                    status = "passed";
                }

                this.buildRadiatorInterop.executionEvent(phase, execution, currentArtifactId, status);

            }
            if (event instanceof DefaultMavenExecutionResult) {
                DefaultMavenExecutionResult dmer = (DefaultMavenExecutionResult) event;
                this.buildRadiatorInterop.executionResult(
                        dmer.getBuildSummary(dmer.getProject()) instanceof BuildSuccess,
                        dmer.getBuildSummary(dmer.getProject()) instanceof BuildFailure);
            }
        } catch (NullPointerException e) {
            // do nothing
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

From source file:com.sloshydog.timely.ExecutionEventKey.java

License:Apache License

public ExecutionEventKey(ExecutionEvent event) {
    group = event.getProject().getGroupId();
    project = event.getProject().getArtifactId();
    phase = event.getMojoExecution().getLifecyclePhase();
    goal = event.getMojoExecution().getGoal();
}

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

License:Apache License

private void executionEventHandler(ExecutionEvent executionEvent) {
    Type type = executionEvent.getType();
    switch (type) {
    case ProjectDiscoveryStarted:
        // Start reading the pom files..
        discoveryTimer.discoveryStart();
        break;/*from  w  w  w  . j  av a2 s  . c o  m*/
    case SessionStarted:
        // Reading of pom files done and structure now there.
        discoveryTimer.discoveryStop();
        // executionEvent.getSession().getProjectDependencyGraph().getSortedProjects();
        sessionTimer.sessionStart();
        break;
    case SessionEnded:
        // Everything is done.
        sessionTimer.sessionStop();
        break;

    case ForkStarted:
        forkTimer.start();
        break;
    case ForkFailed:
    case ForkSucceeded:
        forkTimer.stop();
        break;

    case ForkedProjectStarted:
        forkProject.projectStart(executionEvent);
        break;
    case ForkedProjectFailed:
    case ForkedProjectSucceeded:
        forkProject.projectStop(executionEvent);
        break;

    case MojoStarted:
        String phase = executionEvent.getMojoExecution().getLifecyclePhase();
        collectAllLifeCylcePhases(phase);
        // Key: phase, project, mojo
        mojoTimer.mojoStart(executionEvent);
        break;

    case MojoFailed:
    case MojoSucceeded:
    case MojoSkipped:
        mojoTimer.mojoStop(executionEvent);
        break;

    case ProjectStarted:
        projectTimer.projectStart(executionEvent);
        break;

    case ProjectFailed:
    case ProjectSucceeded:
    case ProjectSkipped:
        projectTimer.projectStop(executionEvent);
        break;

    default:
        LOGGER.error("MBTP: executionEventHandler: {}", type);
        break;
    }

}

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

License:Apache License

public void mojoStart(ExecutionEvent event) {
    ProjectMojo pm = new ProjectMojo(createProjectKey(event.getProject()),
            createMojoKey(event.getMojoExecution()));
    timerEvents.put(pm, new SystemTime().start());
}

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

License:Apache License

public void mojoStop(ExecutionEvent event) {
    ProjectMojo pm = new ProjectMojo(createProjectKey(event.getProject()),
            createMojoKey(event.getMojoExecution()));
    if (!timerEvents.containsKey(pm)) {
        throw new IllegalArgumentException("Unknown mojoId (" + pm + ")");
    }/*from   w w w .j  a v a2  s .co  m*/
    timerEvents.get(pm).stop();
}