Search in sources :

Example 86 with MavenSession

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

the class MavenContextConfigurator method afterFrameworkStarted.

@Override
public void afterFrameworkStarted(EmbeddedEquinox framework) {
    MavenSession session = context.getSession();
    File localRepoRoot = new File(session.getLocalRepository().getBasedir());
    MavenLoggerAdapter mavenLogger = new MavenLoggerAdapter(logger, false);
    Properties globalProps = getGlobalProperties(session);
    MavenContext mavenContext = new MavenContextImpl(localRepoRoot, session.isOffline(), mavenLogger, globalProps);
    framework.registerService(MavenContext.class, mavenContext);
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) MavenContextImpl(org.eclipse.tycho.core.shared.MavenContextImpl) MavenLoggerAdapter(org.eclipse.tycho.osgi.adapters.MavenLoggerAdapter) MavenContext(org.eclipse.tycho.core.shared.MavenContext) Properties(java.util.Properties) File(java.io.File)

Example 87 with MavenSession

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

the class TychoTest method testImplicitTargetEnvironment.

public void testImplicitTargetEnvironment() throws Exception {
    File basedir = getBasedir("projects/implicitenvironment/simple");
    List<MavenProject> projects = getSortedProjects(basedir);
    assertEquals(1, projects.size());
    // assertEquals("ambiguous", projects.get(0).getArtifactId());
    // assertEquals("none", projects.get(0).getArtifactId());
    assertEquals("simple", projects.get(0).getArtifactId());
    DefaultTargetPlatformConfigurationReader resolver = lookup(DefaultTargetPlatformConfigurationReader.class);
    MavenSession session;
    TargetPlatformConfiguration configuration;
    List<TargetEnvironment> environments;
    // ambiguous
    // session = newMavenSession(projects.get(0), projects);
    // configuration = resolver.getTargetPlatformConfiguration(session, session.getCurrentProject());
    // environments = configuration.getEnvironments();
    // assertEquals(0, environments.size());
    // none
    // session = newMavenSession(projects.get(0), projects);
    // configuration = resolver.getTargetPlatformConfiguration(session, session.getCurrentProject());
    // environments = configuration.getEnvironments();
    // assertEquals(0, environments.size());
    // simple
    session = newMavenSession(projects.get(0), projects);
    configuration = resolver.getTargetPlatformConfiguration(session, session.getCurrentProject());
    environments = configuration.getEnvironments();
    assertEquals(1, environments.size());
    TargetEnvironment env = environments.get(0);
    assertEquals("foo", env.getOs());
    assertEquals("bar", env.getWs());
    assertEquals("munchy", env.getArch());
}
Also used : DefaultTargetPlatformConfigurationReader(org.eclipse.tycho.core.resolver.DefaultTargetPlatformConfigurationReader) MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) TargetEnvironment(org.eclipse.tycho.core.shared.TargetEnvironment) File(java.io.File) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration)

Example 88 with MavenSession

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

the class AbstractTychoMojoTestCase method newMavenSession.

protected MavenSession newMavenSession(MavenProject project, List<MavenProject> projects) throws Exception {
    MavenExecutionRequest request = newMavenExecutionRequest(new File(project.getBasedir(), "pom.xml"));
    MavenExecutionResult result = new DefaultMavenExecutionResult();
    DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
    MavenSession session = new MavenSession(getContainer(), repositorySession, request, result);
    session.setProjects(projects);
    session.setCurrentProject(project);
    return session;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) DefaultRepositorySystemSession(org.sonatype.aether.util.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) File(java.io.File)

Example 89 with MavenSession

use of org.apache.maven.execution.MavenSession in project antlr4 by tunnelvisionlabs.

the class Antlr4MojoTest method importsCustomLayout.

@Test
public void importsCustomLayout() throws Exception {
    File baseDir = resources.getBasedir("importsCustom");
    File antlrDir = new File(baseDir, "src/main/antlr4");
    File generatedSources = new File(baseDir, "src/main/java");
    File genTestLexer = new File(generatedSources, "foo/TestLexer.java");
    File genTestParser = new File(generatedSources, "foo/TestParser.java");
    File genHello = new File(generatedSources, "foo/HelloParser.java");
    File baseGrammar = new File(antlrDir, "imports/TestBaseLexer.g4");
    File lexerGrammar = new File(antlrDir, "TestLexer.g4");
    File parserGrammar = new File(antlrDir, "TestParser.g4");
    Xpp3Dom outputDirectory = TestMavenRuntime.newParameter("outputDirectory", "src/main/java/foo");
    Xpp3Dom arguments = new Xpp3Dom("arguments");
    arguments.addChild(TestMavenRuntime.newParameter("argument", "-package"));
    arguments.addChild(TestMavenRuntime.newParameter("argument", "foo"));
    MavenProject project = maven.readMavenProject(baseDir);
    MavenSession session = maven.newMavenSession(project);
    MojoExecution exec = maven.newMojoExecution("antlr4", outputDirectory, arguments);
    // //////////////////////////////////////////////////////////////////////
    // 1st - all grammars have to be processed
    // //////////////////////////////////////////////////////////////////////
    assertFalse(genHello.exists());
    assertFalse(genTestParser.exists());
    assertFalse(genTestLexer.exists());
    maven.executeMojo(session, project, exec);
    assertTrue(genHello.isFile());
    assertTrue(genTestParser.isFile());
    assertTrue(genTestLexer.isFile());
    // //////////////////////////////////////////////////////////////////////
    // 2nd - nothing has been modified, no grammars have to be processed
    // //////////////////////////////////////////////////////////////////////
    {
        byte[] testLexerSum = checksum(genTestLexer);
        byte[] testParserSum = checksum(genTestParser);
        byte[] helloSum = checksum(genHello);
        maven.executeMojo(session, project, exec);
        assertTrue(Arrays.equals(testLexerSum, checksum(genTestLexer)));
        assertTrue(Arrays.equals(testParserSum, checksum(genTestParser)));
        assertTrue(Arrays.equals(helloSum, checksum(genHello)));
    }
    // //////////////////////////////////////////////////////////////////////
    // 3rd - the imported grammar changed, every dependency has to be processed
    // //////////////////////////////////////////////////////////////////////
    // modify the grammar to make checksum comparison detect a change
    Change change = Change.of(baseGrammar, "DOT: '.' ;");
    try {
        byte[] testLexerSum = checksum(genTestLexer);
        byte[] testParserSum = checksum(genTestParser);
        byte[] helloSum = checksum(genHello);
        maven.executeMojo(session, project, exec);
        assertFalse(Arrays.equals(testLexerSum, checksum(genTestLexer)));
        assertFalse(Arrays.equals(testParserSum, checksum(genTestParser)));
        assertTrue(Arrays.equals(helloSum, checksum(genHello)));
    } finally {
        change.close();
    }
    // //////////////////////////////////////////////////////////////////////
    // 4th - the lexer grammar changed, the parser grammar has to be processed as well
    // //////////////////////////////////////////////////////////////////////
    // modify the grammar to make checksum comparison detect a change
    change = Change.of(lexerGrammar, "fragment DOT : '.';");
    try {
        byte[] testLexerSum = checksum(genTestLexer);
        byte[] testParserSum = checksum(genTestParser);
        byte[] helloSum = checksum(genHello);
        maven.executeMojo(session, project, exec);
        assertFalse(Arrays.equals(testLexerSum, checksum(genTestLexer)));
        assertFalse(Arrays.equals(testParserSum, checksum(genTestParser)));
        assertTrue(Arrays.equals(helloSum, checksum(genHello)));
    } finally {
        change.close();
    }
    // //////////////////////////////////////////////////////////////////////
    // 5th - the parser grammar changed, no other grammars have to be processed
    // //////////////////////////////////////////////////////////////////////
    // modify the grammar to make checksum comparison detect a change
    change = Change.of(parserGrammar, " t : WS* ;");
    try {
        byte[] testLexerSum = checksum(genTestLexer);
        byte[] testParserSum = checksum(genTestParser);
        byte[] helloSum = checksum(genHello);
        maven.executeMojo(session, project, exec);
        assumeTrue(Arrays.equals(testLexerSum, checksum(genTestLexer)));
        assertFalse(Arrays.equals(testParserSum, checksum(genTestParser)));
        assertTrue(Arrays.equals(helloSum, checksum(genHello)));
    } finally {
        change.close();
    }
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MavenProject(org.apache.maven.project.MavenProject) MojoExecution(org.apache.maven.plugin.MojoExecution) File(java.io.File) Test(org.junit.Test)

Example 90 with MavenSession

use of org.apache.maven.execution.MavenSession in project sts4 by spring-projects.

the class MavenBridge method createSession.

@SuppressWarnings("deprecation")
public MavenSession createSession(MavenExecutionRequest request, MavenProject project) throws MavenException {
    RepositorySystemSession repoSession = createRepositorySession(request);
    MavenExecutionResult result = new DefaultMavenExecutionResult();
    MavenSession mavenSession = new MavenSession(plexus, repoSession, request, result);
    if (project != null) {
        mavenSession.setProjects(Collections.singletonList(project));
    }
    return mavenSession;
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) MavenSession(org.apache.maven.execution.MavenSession) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult)

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