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);
}
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());
}
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;
}
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();
}
}
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;
}
Aggregations