Search in sources :

Example 56 with MavenSession

use of org.apache.maven.execution.MavenSession in project drools by kiegroup.

the class MavenEmbedder method init.

void init() throws MavenEmbedderException {
    try {
        this.mavenExecutionRequest = this.buildMavenExecutionRequest(mavenRequest);
        RepositorySystemSession rss = ((DefaultMaven) componentProvider.lookup(Maven.class)).newRepositorySession(mavenExecutionRequest);
        mavenSession = new MavenSession(componentProvider.getPlexusContainer(), rss, mavenExecutionRequest, new DefaultMavenExecutionResult());
        componentProvider.lookup(LegacySupport.class).setSession(mavenSession);
    } catch (MavenEmbedderException e) {
        log.error("Unable to build MavenEmbedder", e);
        throw e;
    } catch (ComponentLookupException e) {
        log.error("Unable to build MavenEmbedder", e);
        throw new MavenEmbedderException(e.getMessage(), e);
    }
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultMaven(org.apache.maven.DefaultMaven) Maven(org.apache.maven.Maven) MavenSession(org.apache.maven.execution.MavenSession) LegacySupport(org.apache.maven.plugin.LegacySupport) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) DefaultMaven(org.apache.maven.DefaultMaven) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException)

Example 57 with MavenSession

use of org.apache.maven.execution.MavenSession in project meecrowave by apache.

the class MeecrowaveBundleMojoTest method bundle.

@Test
public void bundle() throws Exception {
    final File moduleBase = jarLocation(MeecrowaveBundleMojoTest.class).getParentFile().getParentFile();
    final File basedir = new File(moduleBase, "src/test/resources/" + getClass().getSimpleName());
    final File pom = new File(basedir, "pom.xml");
    final MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setBaseDirectory(basedir);
    final ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
    final DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repositorySession, new LocalRepository(new File(moduleBase, "target/fake"), "")));
    configuration.setRepositorySession(repositorySession);
    final MavenProject project = mojo.lookup(ProjectBuilder.class).build(pom, configuration).getProject();
    final Build build = new Build();
    final File buildDir = new File("target/" + getClass().getName() + "/build");
    build.setDirectory(buildDir.getAbsolutePath());
    project.setBuild(build);
    final MavenSession session = mojo.newMavenSession(project);
    final MojoExecution execution = mojo.newMojoExecution("bundle");
    execution.getConfiguration().addChild(new Xpp3Dom("enforceMeecrowave") {

        {
            setValue(Boolean.FALSE.toString());
        }
    });
    execution.getConfiguration().addChild(new Xpp3Dom("enforceCommonsCli") {

        {
            setValue(Boolean.FALSE.toString());
        }
    });
    execution.getConfiguration().addChild(new Xpp3Dom("conf") {

        {
            setValue("src/main/meecrowave/conf");
        }
    });
    execution.getConfiguration().addChild(new Xpp3Dom("webapp") {

        {
            setValue("src/main/webapp");
        }
    });
    mojo.executeMojo(session, project, execution);
    assertTrue(buildDir.exists());
    try (final ZipFile zip = new ZipFile(new File(buildDir, "test-meecrowave-distribution.zip"))) {
        assertTrue(zip.getEntry("test-distribution/docBase/sub/index.html") != null);
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) LocalRepository(org.eclipse.aether.repository.LocalRepository) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) MavenSession(org.apache.maven.execution.MavenSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) MavenProject(org.apache.maven.project.MavenProject) ZipFile(java.util.zip.ZipFile) MojoExecution(org.apache.maven.plugin.MojoExecution) Build(org.apache.maven.model.Build) SimpleLocalRepositoryManagerFactory(org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test)

Example 58 with MavenSession

use of org.apache.maven.execution.MavenSession in project docker-maven-plugin by fabric8io.

the class DockerFileUtilTest method mockMojoParams.

private MojoParameters mockMojoParams() {
    MavenProject project = new MavenProject();
    project.setArtifactId("docker-maven-plugin");
    Properties projectProperties = project.getProperties();
    projectProperties.put("base", "java");
    projectProperties.put("name", "guenther");
    projectProperties.put("age", "42");
    projectProperties.put("ext", "png");
    Settings settings = new Settings();
    ArtifactRepository localRepository = new MavenArtifactRepository() {

        public String getBasedir() {
            return "repository";
        }
    };
    @SuppressWarnings("deprecation") MavenSession session = new MavenSession(null, settings, localRepository, null, null, Collections.<String>emptyList(), ".", null, null, new Date(System.currentTimeMillis()));
    // Maven CLI override: -DcliOverride=cliValue
    session.getUserProperties().setProperty("cliOverride", "cliValue");
    // Java system property: -Duser.name=somebody
    session.getSystemProperties().put("user.name", "somebody");
    return new MojoParameters(session, project, null, null, null, settings, "src", "target", Collections.singletonList(project));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) Settings(org.apache.maven.settings.Settings)

Example 59 with MavenSession

use of org.apache.maven.execution.MavenSession in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManagerTest method mockMojoParams.

private MojoParameters mockMojoParams(MavenProject project) {
    Settings settings = new Settings();
    ArtifactRepository localRepository = new MavenArtifactRepository() {

        @Mock
        public String getBasedir() {
            return "repository";
        }
    };
    @SuppressWarnings("deprecation") MavenSession session = new MavenSession(null, settings, localRepository, null, null, Collections.<String>emptyList(), ".", null, null, new Date());
    return new MojoParameters(session, project, null, null, null, settings, "src", "target", Collections.singletonList(project));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) MojoParameters(io.fabric8.maven.docker.util.MojoParameters) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) Settings(org.apache.maven.settings.Settings) Date(java.util.Date)

Example 60 with MavenSession

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

the class MavenServerImpl method runMavenRequest.

public void runMavenRequest(MavenExecutionRequest request, Runnable runnable) {
    DefaultMaven maven = (DefaultMaven) getMavenComponent(Maven.class);
    RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
    request.getProjectBuildingRequest().setRepositorySession(repositorySystemSession);
    MavenSession mavenSession = new MavenSession(container, repositorySystemSession, request, new DefaultMavenExecutionResult());
    LegacySupport legacySupport = getMavenComponent(LegacySupport.class);
    MavenSession previousSession = legacySupport.getSession();
    legacySupport.setSession(mavenSession);
    try {
        for (AbstractMavenLifecycleParticipant participant : getLifecycleParticipants(Collections.emptyList())) {
            participant.afterSessionStart(mavenSession);
        }
        runnable.run();
    } catch (MavenExecutionException e) {
        throw new RuntimeException(e);
    } finally {
        legacySupport.setSession(previousSession);
    }
}
Also used : DefaultMaven(org.apache.maven.DefaultMaven) Maven(org.apache.maven.Maven) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) MavenSession(org.apache.maven.execution.MavenSession) MavenExecutionException(org.apache.maven.MavenExecutionException) LegacySupport(org.apache.maven.plugin.LegacySupport) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) AbstractMavenLifecycleParticipant(org.apache.maven.AbstractMavenLifecycleParticipant) DefaultMaven(org.apache.maven.DefaultMaven)

Aggregations

MavenSession (org.apache.maven.execution.MavenSession)118 File (java.io.File)65 MavenProject (org.apache.maven.project.MavenProject)47 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)30 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)23 Test (org.junit.Test)21 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)20 LegacySupport (org.apache.maven.plugin.LegacySupport)20 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)18 Properties (java.util.Properties)17 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)16 MojoExecution (org.apache.maven.plugin.MojoExecution)13 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)13 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)12 Artifact (org.apache.maven.artifact.Artifact)10 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)9 ManipulationSession (org.commonjava.maven.ext.core.ManipulationSession)8 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)7 Settings (org.apache.maven.settings.Settings)7 ArrayList (java.util.ArrayList)6