Search in sources :

Example 1 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest in project che by eclipse.

the class MavenServerImpl method newMavenRequest.

public MavenExecutionRequest newMavenRequest(File pom, List<String> activeProfiles, List<String> inactiveProfiles, List<String> goals) {
    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    try {
        getMavenComponent(MavenExecutionRequestPopulator.class).populateFromSettings(request, settings);
        request.setGoals(goals);
        request.setPom(pom);
        getMavenComponent(MavenExecutionRequestPopulator.class).populateDefaults(request);
        request.setSystemProperties(properties);
        request.setActiveProfiles(activeProfiles);
        request.setInactiveProfiles(inactiveProfiles);
        request.setStartTime(buildDate);
        return request;
    } catch (MavenExecutionRequestPopulationException e) {
        throw new RuntimeException(e);
    }
}
Also used : MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Example 2 with MavenExecutionRequest

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

the class MavenEmbedder method readProject.

@NotNull
public MavenExecutionResult readProject(@NotNull final File file, @NotNull final List<String> activeProfiles, @NotNull final List<String> inactiveProfiles) {
    MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles, Collections.<String>emptyList());
    request.getGlobalProfileManager().loadSettingsProfiles(mySettings);
    request.setRecursive(false);
    return readProject(request);
}
Also used : MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest 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 4 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest 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 5 with MavenExecutionRequest

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

the class AFMavenCli method loadCoreExtensions.

protected List<CoreExtensionEntry> loadCoreExtensions(AFCliRequest cliRequest, ClassRealm containerRealm, Set<String> providedArtifacts) {
    if (cliRequest.getMultiModuleProjectDirectory() == null) {
        return Collections.emptyList();
    }
    Path extensionsFile = Paths.get(cliRequest.getMultiModuleProjectDirectory().toString(), EXTENSIONS_FILENAME);
    if (!java.nio.file.Files.isRegularFile(extensionsFile)) {
        return Collections.emptyList();
    }
    try {
        List<CoreExtension> extensions = readCoreExtensionsDescriptor(extensionsFile);
        if (extensions.isEmpty()) {
            return Collections.emptyList();
        }
        ContainerConfiguration cc = // 
        new DefaultContainerConfiguration().setClassWorld(// 
        cliRequest.getClassWorld()).setRealm(// 
        containerRealm).setClassPathScanning(// 
        PlexusConstants.SCANNING_INDEX).setAutoWiring(// 
        true).setName("maven");
        DefaultPlexusContainer container = new DefaultPlexusContainer(cc, new AbstractModule() {

            @Override
            protected void configure() {
                bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
            }
        });
        try {
            container.setLookupRealm(null);
            container.setLoggerManager(plexusLoggerManager);
            container.getLoggerManager().setThresholds(cliRequest.getRequest().getLoggingLevel());
            Thread.currentThread().setContextClassLoader(container.getContainerRealm());
            executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);
            configurationProcessors = container.lookupMap(AFConfigurationProcessor.class);
            configure(cliRequest);
            MavenExecutionRequest request = DefaultMavenExecutionRequest.copy(cliRequest.getRequest());
            request = populateRequest(cliRequest, request);
            request = executionRequestPopulator.populateDefaults(request);
            BootstrapCoreExtensionManager resolver = container.lookup(BootstrapCoreExtensionManager.class);
            return resolver.loadCoreExtensions(request, providedArtifacts, extensions);
        } finally {
            executionRequestPopulator = null;
            container.dispose();
        }
    } catch (RuntimeException e) {
        // runtime exceptions are most likely bugs in maven, let them bubble up to the user
        throw e;
    } catch (Exception e) {
        slf4jLogger.warn("Failed to read extensions descriptor " + extensionsFile + ": " + e.getMessage());
    }
    return Collections.emptyList();
}
Also used : Path(java.nio.file.Path) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ContainerConfiguration(org.codehaus.plexus.ContainerConfiguration) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) LifecycleExecutionException(org.apache.maven.lifecycle.LifecycleExecutionException) InternalErrorException(org.apache.maven.InternalErrorException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) FileNotFoundException(java.io.FileNotFoundException) ParseException(org.apache.commons.cli.ParseException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) IOException(java.io.IOException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) AbstractModule(com.google.inject.AbstractModule) CoreExtension(org.apache.maven.cli.internal.extension.model.CoreExtension) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) BootstrapCoreExtensionManager(org.apache.maven.cli.internal.BootstrapCoreExtensionManager) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Aggregations

MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)56 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)40 File (java.io.File)24 MavenSession (org.apache.maven.execution.MavenSession)20 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)14 MavenProject (org.apache.maven.project.MavenProject)14 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)10 IOException (java.io.IOException)9 MavenExecutionRequestPopulationException (org.apache.maven.execution.MavenExecutionRequestPopulationException)9 MavenExecutionRequestPopulator (org.apache.maven.execution.MavenExecutionRequestPopulator)9 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)8 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)7 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)7 FileNotFoundException (java.io.FileNotFoundException)6 Path (java.nio.file.Path)6 Properties (java.util.Properties)6 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)6 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)6 LifecycleExecutionException (org.apache.maven.lifecycle.LifecycleExecutionException)5 ProjectBuilder (org.apache.maven.project.ProjectBuilder)5