Search in sources :

Example 1 with ReactorManager

use of org.apache.maven.execution.ReactorManager in project intellij-community by JetBrains.

the class MavenEmbedder method execute.

@NotNull
public MavenExecutionResult execute(@NotNull final File file, @NotNull final List<String> activeProfiles, @NotNull final List<String> inactiveProfiles, @NotNull final List<String> goals, @NotNull final List<String> selectedProjects, boolean alsoMake, boolean alsoMakeDependents) {
    try {
        MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles, goals);
        if (!selectedProjects.isEmpty()) {
            request.setRecursive(true);
            request.setSelectedProjects(selectedProjects);
            if (alsoMake && alsoMakeDependents) {
                request.setMakeBehavior(ReactorManager.MAKE_BOTH_MODE);
            } else if (alsoMake) {
                request.setMakeBehavior(ReactorManager.MAKE_MODE);
            } else if (alsoMakeDependents) {
                request.setMakeBehavior(ReactorManager.MAKE_DEPENDENTS_MODE);
            }
        }
        Maven maven = getComponent(Maven.class);
        Method method = maven.getClass().getDeclaredMethod("doExecute", MavenExecutionRequest.class, EventDispatcher.class);
        method.setAccessible(true);
        ReactorManager reactor = (ReactorManager) method.invoke(maven, request, request.getEventDispatcher());
        return new MavenExecutionResult(reactor.getTopLevelProject(), Collections.<Exception>emptyList());
    } catch (InvocationTargetException e) {
        return handleException(e.getTargetException());
    } catch (NoSuchMethodException e) {
        // should never happen
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        // should never happen
        throw new RuntimeException(e);
    }
}
Also used : DefaultMaven(org.apache.maven.DefaultMaven) Maven(org.apache.maven.Maven) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) Method(java.lang.reflect.Method) ReactorManager(org.apache.maven.execution.ReactorManager) InvocationTargetException(java.lang.reflect.InvocationTargetException) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ReactorManager

use of org.apache.maven.execution.ReactorManager in project maven-plugins by apache.

the class RemoteResourcesMojoTest method lookupProcessMojoWithSettings.

protected ProcessRemoteResourcesMojo lookupProcessMojoWithSettings(final MavenProject project, ArrayList<String> bundles) throws Exception {
    final ProcessRemoteResourcesMojo mojo = lookupProcessMojo();
    MavenSession session = new MavenSession(getContainer(), // Settings settings,
    null, // ArtifactRepository localRepository,
    null, // EventDispatcher eventDispatcher,
    null, new ReactorManager(new ArrayList<MavenProject>()), Arrays.asList("install"), project.getBasedir().toString(), new Properties(), Calendar.getInstance().getTime());
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "outputDirectory", new File(project.getBuild().getOutputDirectory()));
    setVariableValueToObject(mojo, "resourceBundles", bundles);
    setVariableValueToObject(mojo, "mavenSession", session);
    setVariableValueToObject(mojo, "remoteArtifactRepositories", project.getRemoteArtifactRepositories());
    setVariableValueToObject(mojo, "resources", project.getResources());
    return mojo;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ArrayList(java.util.ArrayList) ReactorManager(org.apache.maven.execution.ReactorManager) Properties(java.util.Properties) File(java.io.File)

Aggregations

ReactorManager (org.apache.maven.execution.ReactorManager)2 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 DefaultMaven (org.apache.maven.DefaultMaven)1 Maven (org.apache.maven.Maven)1 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)1 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)1 MavenSession (org.apache.maven.execution.MavenSession)1 NotNull (org.jetbrains.annotations.NotNull)1