Search in sources :

Example 6 with DefaultMavenExecutionResult

use of org.apache.maven.execution.DefaultMavenExecutionResult in project pom-manipulation-ext by release-engineering.

the class Cli method createSession.

private void createSession(File target, File settings) {
    try {
        PlexusContainer container = new DefaultPlexusContainer();
        pomIO = container.lookup(PomIO.class);
        session = container.lookup(ManipulationSession.class);
        manipulationManager = container.lookup(ManipulationManager.class);
        final MavenExecutionRequest req = new DefaultMavenExecutionRequest().setUserProperties(System.getProperties()).setUserProperties(userProps).setRemoteRepositories(Collections.<ArtifactRepository>emptyList());
        ArtifactRepository ar = null;
        if (settings == null) {
            // No, this is not a typo. If current default is null, supply new local and global.
            // This function passes in settings to make it easier to test.
            this.settings = settings = new File(System.getProperty("user.home"), ".m2/settings.xml");
            ar = new MavenArtifactRepository();
            ar.setUrl("file://" + System.getProperty("user.home") + "/.m2/repository");
            req.setLocalRepository(ar);
        }
        req.setUserSettingsFile(settings);
        req.setGlobalSettingsFile(settings);
        MavenExecutionRequestPopulator executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);
        executionRequestPopulator.populateFromSettings(req, parseSettings(settings));
        executionRequestPopulator.populateDefaults(req);
        if (ar != null) {
            ar.setUrl("file://" + req.getLocalRepositoryPath());
        }
        if (userProps != null && userProps.containsKey("maven.repo.local")) {
            if (ar == null) {
                ar = new MavenArtifactRepository();
            }
            ar.setUrl("file://" + userProps.getProperty("maven.repo.local"));
            req.setLocalRepository(ar);
        }
        final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult());
        mavenSession.getRequest().setPom(target);
        session.setMavenSession(mavenSession);
    } catch (ComponentLookupException e) {
        logger.debug("Caught problem instantiating ", e);
        System.err.println("Unable to start Cli subsystem");
        System.exit(100);
    } catch (PlexusContainerException e) {
        logger.debug("Caught problem instantiating ", e);
        System.err.println("Unable to start Cli subsystem");
        System.exit(100);
    } catch (SettingsBuildingException e) {
        logger.debug("Caught problem parsing settings file ", e);
        System.err.println("Unable to parse settings.xml file");
        System.exit(100);
    } catch (MavenExecutionRequestPopulationException e) {
        logger.debug("Caught problem populating maven request from settings file ", e);
        System.err.println("Unable to create maven execution request from settings.xml file");
        System.exit(100);
    }
}
Also used : PlexusContainerException(org.codehaus.plexus.PlexusContainerException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) PlexusContainer(org.codehaus.plexus.PlexusContainer) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ManipulationManager(org.commonjava.maven.ext.core.ManipulationManager) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) PomIO(org.commonjava.maven.ext.io.PomIO) MavenSession(org.apache.maven.execution.MavenSession) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) File(java.io.File) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Example 7 with DefaultMavenExecutionResult

use of org.apache.maven.execution.DefaultMavenExecutionResult in project pom-manipulation-ext by release-engineering.

the class DistributionEnforcingManipulatorTest method setMavenSession.

private void setMavenSession() throws Exception {
    final MavenExecutionRequest req = new DefaultMavenExecutionRequest().setUserProperties(userCliProperties).setRemoteRepositories(Collections.<ArtifactRepository>emptyList());
    final PlexusContainer container = new DefaultPlexusContainer();
    final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult());
    session.setMavenSession(mavenSession);
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) PlexusContainer(org.codehaus.plexus.PlexusContainer) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest)

Example 8 with DefaultMavenExecutionResult

use of org.apache.maven.execution.DefaultMavenExecutionResult in project pom-manipulation-ext by release-engineering.

the class PropertiesUtilsTest method createUpdateSession.

private ManipulationSession createUpdateSession() throws Exception {
    ManipulationSession session = new ManipulationSession();
    session.setState(new DependencyState(p));
    session.setState(new VersioningState(p));
    session.setState(new CommonState(p));
    final MavenExecutionRequest req = new DefaultMavenExecutionRequest().setUserProperties(p).setRemoteRepositories(Collections.<ArtifactRepository>emptyList());
    final PlexusContainer container = new DefaultPlexusContainer();
    final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult());
    session.setMavenSession(mavenSession);
    return session;
}
Also used : CommonState(org.commonjava.maven.ext.core.state.CommonState) MavenSession(org.apache.maven.execution.MavenSession) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) PlexusContainer(org.codehaus.plexus.PlexusContainer) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) DependencyState(org.commonjava.maven.ext.core.state.DependencyState) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) VersioningState(org.commonjava.maven.ext.core.state.VersioningState)

Example 9 with DefaultMavenExecutionResult

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

the class BuildProjectCommand method execute.

@Override
public MavenExecutionResult execute() throws MavenEmbedderException {
    final MavenExecutionResult result = new DefaultMavenExecutionResult();
    final MavenEmbedder mavenEmbedder = createMavenEmbedder();
    final String pomPath = baseDirectory + FileSystems.getDefault().getSeparator() + POMServiceImpl.POM_XML;
    try {
        final File pomFile = new File(pomPath);
        mavenEmbedder.buildProjects(pomFile, false);
    } catch (ProjectBuildingException e) {
        result.addException(e);
    } finally {
        mavenEmbedder.dispose();
    }
    return result;
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenEmbedder(org.appformer.maven.integration.embedder.MavenEmbedder) File(java.io.File)

Example 10 with DefaultMavenExecutionResult

use of org.apache.maven.execution.DefaultMavenExecutionResult in project gradle by gradle.

the class MavenProjectsCreator method createNow.

private Set<MavenProject> createNow(Settings settings, File pomFile) throws PlexusContainerException, ComponentLookupException, MavenExecutionRequestPopulationException, ProjectBuildingException {
    ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration().setClassWorld(new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader())).setName("mavenCore").setClassPathScanning(PlexusConstants.SCANNING_INDEX).setAutoWiring(true);
    DefaultPlexusContainer container = new DefaultPlexusContainer(containerConfiguration);
    ProjectBuilder builder = container.lookup(ProjectBuilder.class);
    MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
    final Properties properties = SystemProperties.getInstance().withSystemProperties(() -> {
        final Properties currentProperties = new Properties();
        currentProperties.putAll(System.getProperties());
        return currentProperties;
    });
    executionRequest.setSystemProperties(properties);
    MavenExecutionRequestPopulator populator = container.lookup(MavenExecutionRequestPopulator.class);
    populateFromSettings(settings, executionRequest, populator);
    populator.populateDefaults(executionRequest);
    ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
    buildingRequest.getRemoteRepositories().forEach(repository -> {
        if (repository.getId().equals(RepositorySystem.DEFAULT_REMOTE_REPO_ID)) {
            repository.setUrl(RepositoryHandler.MAVEN_CENTRAL_URL);
        }
    });
    buildingRequest.setProcessPlugins(false);
    MavenProject mavenProject = builder.build(pomFile, buildingRequest).getProject();
    Set<MavenProject> reactorProjects = new LinkedHashSet<>();
    // TODO adding the parent project first because the converter needs it this way ATM. This is oversimplified.
    // the converter should not depend on the order of reactor projects.
    // we should add coverage for nested multi-project builds with multiple parents.
    reactorProjects.add(mavenProject);
    List<ProjectBuildingResult> allProjects = builder.build(ImmutableList.of(pomFile), true, buildingRequest);
    // noinspection NullableProblems
    CollectionUtils.collect(allProjects, reactorProjects, ProjectBuildingResult::getProject);
    MavenExecutionResult result = new DefaultMavenExecutionResult();
    result.setProject(mavenProject);
    RepositorySystemSession repoSession = new DefaultRepositorySystemSession();
    @SuppressWarnings("deprecation") MavenSession session = new MavenSession(container, repoSession, executionRequest, result);
    session.setCurrentProject(mavenProject);
    return reactorProjects;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ClassWorld(org.codehaus.plexus.classworlds.ClassWorld) Properties(java.util.Properties) SystemProperties(org.gradle.internal.SystemProperties) ContainerConfiguration(org.codehaus.plexus.ContainerConfiguration) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) MavenSession(org.apache.maven.execution.MavenSession) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) ProjectBuilder(org.apache.maven.project.ProjectBuilder) MavenProject(org.apache.maven.project.MavenProject) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ProjectBuildingResult(org.apache.maven.project.ProjectBuildingResult) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Aggregations

DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)14 MavenSession (org.apache.maven.execution.MavenSession)12 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)9 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)9 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)8 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)5 File (java.io.File)4 LegacySupport (org.apache.maven.plugin.LegacySupport)4 PlexusContainer (org.codehaus.plexus.PlexusContainer)4 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)4 StubArtifactRepository (org.apache.maven.plugin.testing.stubs.StubArtifactRepository)3 MavenProject (org.apache.maven.project.MavenProject)3 ManipulationSession (org.commonjava.maven.ext.core.ManipulationSession)3 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)3 DefaultMaven (org.apache.maven.DefaultMaven)2 Maven (org.apache.maven.Maven)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)2 MavenExecutionRequestPopulator (org.apache.maven.execution.MavenExecutionRequestPopulator)2 ProjectBuilder (org.apache.maven.project.ProjectBuilder)2