use of org.apache.maven.execution.MavenSession in project antlr4 by antlr.
the class Antlr4MojoTest method importTokens.
@Test
public void importTokens() throws Exception {
Path baseDir = resources.getBasedir("importTokens").toPath();
Path antlrDir = baseDir.resolve("src/main/antlr4");
Path generatedSources = baseDir.resolve("target/generated-sources/antlr4");
Path genParser = generatedSources.resolve("test/SimpleParser.java");
Path tokens = antlrDir.resolve("imports/SimpleLexer.tokens");
MavenProject project = maven.readMavenProject(baseDir.toFile());
MavenSession session = maven.newMavenSession(project);
MojoExecution exec = maven.newMojoExecution("antlr4");
// //////////////////////////////////////////////////////////////////////
// 1st - all grammars have to be processed
// //////////////////////////////////////////////////////////////////////
assertFalse(Files.exists(genParser));
maven.executeMojo(session, project, exec);
assertTrue(Files.exists(genParser));
// //////////////////////////////////////////////////////////////////////
// 2nd - nothing has been modified, no grammars have to be processed
// //////////////////////////////////////////////////////////////////////
{
byte[] sum = checksum(genParser);
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(sum, checksum(genParser)));
}
try (Change change = Change.of(tokens, "DOT=4")) {
byte[] sum = checksum(genParser);
maven.executeMojo(session, project, exec);
assertFalse(Arrays.equals(sum, checksum(genParser)));
}
}
use of org.apache.maven.execution.MavenSession in project antlr4 by antlr.
the class Antlr4MojoTest method importsStandardLayout.
@Test
public void importsStandardLayout() throws Exception {
Path baseDir = resources.getBasedir("importsStandard").toPath();
Path antlrDir = baseDir.resolve("src/main/antlr4");
Path generatedSources = baseDir.resolve("target/generated-sources/antlr4");
Path genTestLexer = generatedSources.resolve("test/TestLexer.java");
Path genTestParser = generatedSources.resolve("test/TestParser.java");
Path genHello = generatedSources.resolve("test/HelloParser.java");
Path baseGrammar = antlrDir.resolve("imports/TestBaseLexer.g4");
Path baseGrammar2 = antlrDir.resolve("imports/TestBaseLexer2.g4");
Path lexerGrammar = antlrDir.resolve("test/TestLexer.g4");
Path parserGrammar = antlrDir.resolve("test/TestParser.g4");
MavenProject project = maven.readMavenProject(baseDir.toFile());
MavenSession session = maven.newMavenSession(project);
MojoExecution exec = maven.newMojoExecution("antlr4");
// //////////////////////////////////////////////////////////////////////
// 1st - all grammars have to be processed
// //////////////////////////////////////////////////////////////////////
assertFalse(Files.exists(genHello));
assertFalse(Files.exists(genTestParser));
assertFalse(Files.exists(genTestLexer));
maven.executeMojo(session, project, exec);
assertTrue(Files.exists(genHello));
assertTrue(Files.exists(genTestParser));
assertTrue(Files.exists(genTestLexer));
byte[] origTestLexerSum = checksum(genTestLexer);
byte[] origTestParserSum = checksum(genTestParser);
byte[] origHelloSum = checksum(genHello);
// //////////////////////////////////////////////////////////////////////
// 2nd - nothing has been modified, no grammars have to be processed
// //////////////////////////////////////////////////////////////////////
{
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// modify the grammar to make checksum comparison detect a change
try (Change change = Change.of(baseGrammar, "DOT: '.' ;")) {
maven.executeMojo(session, project, exec);
assertFalse(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// Restore file and confirm it was restored.
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
// modify the grammar to make checksum comparison detect a change
try (Change change = Change.of(baseGrammar2, "BANG: '!' ;")) {
maven.executeMojo(session, project, exec);
assertFalse(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// Restore file and confirm it was restored.
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
// modify the grammar to make checksum comparison detect a change
try (Change change = Change.of(lexerGrammar, "FOO: 'foo' ;")) {
maven.executeMojo(session, project, exec);
assertFalse(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// Restore file and confirm it was restored.
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
// modify the grammar to make checksum comparison detect a change
try (Change change = Change.of(parserGrammar, " t : WS* ;")) {
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// Restore file and confirm it was restored.
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.
the class DefaultDependencyResolverTest method newMavenSession.
protected MavenSession newMavenSession(MavenProject project) {
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
MavenExecutionResult result = new DefaultMavenExecutionResult();
MavenRepositorySystemSession repoSession = new MavenRepositorySystemSession();
repoSession.setLocalRepositoryManager(LegacyLocalRepositoryManager.wrap(new StubArtifactRepository("target/local-repo"), null));
MavenSession session = new MavenSession(getContainer(), repoSession, request, result);
session.setCurrentProject(project);
session.setProjects(Arrays.asList(project));
return session;
}
use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.
the class AssemblyExpressionEvaluatorTest method testShouldResolveContextValueBeforeModelPropertyOrModelGroupIdInAssemblyId.
public void testShouldResolveContextValueBeforeModelPropertyOrModelGroupIdInAssemblyId() throws ExpressionEvaluationException {
final Model model = new Model();
model.setArtifactId("artifact-id");
model.setGroupId("group.id");
model.setVersion("1");
model.setPackaging("jar");
final Properties props = new Properties();
props.setProperty("groupId", "other.id");
model.setProperties(props);
final EasyMockSupport mm = new EasyMockSupport();
MavenSession session = mm.createControl().createMock(MavenSession.class);
final Properties execProps = new Properties();
execProps.setProperty("groupId", "still.another.id");
PropertiesBasedValueSource cliProps = new PropertiesBasedValueSource(execProps);
expect(session.getExecutionProperties()).andReturn(execProps).anyTimes();
expect(session.getUserProperties()).andReturn(new Properties()).anyTimes();
AssemblerConfigurationSource cs = mm.createControl().createMock(AssemblerConfigurationSource.class);
expect(cs.getCommandLinePropsInterpolator()).andReturn(FixedStringSearchInterpolator.create(cliProps)).anyTimes();
expect(cs.getRepositoryInterpolator()).andReturn(FixedStringSearchInterpolator.create()).anyTimes();
expect(cs.getEnvInterpolator()).andReturn(FixedStringSearchInterpolator.create()).anyTimes();
expect(cs.getMavenSession()).andReturn(session).anyTimes();
expect(cs.getProject()).andReturn(new MavenProject(model));
final IMocksControl lrCtl = mm.createControl();
final ArtifactRepository lr = lrCtl.createMock(ArtifactRepository.class);
expect(lr.getBasedir()).andReturn("/path/to/local/repo").anyTimes();
expect(cs.getLocalRepository()).andReturn(lr).anyTimes();
mm.replayAll();
final Object result = new AssemblyExpressionEvaluator(cs).evaluate("assembly.${groupId}");
assertEquals("assembly.still.another.id", result);
mm.verifyAll();
}
use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.
the class AssemblyFormatUtilsTest method testEvalFileNameMapping_ShouldResolveArtifactIdAndBaseVersionInOutDir_UseArtifactInfo_WithValidMainProject.
public void testEvalFileNameMapping_ShouldResolveArtifactIdAndBaseVersionInOutDir_UseArtifactInfo_WithValidMainProject() throws AssemblyFormattingException {
final MavenProject mainProject = createProject("group", "main", "1", null);
final String artifactVersion = "2-20070807.112233-1";
final String artifactBaseVersion = "2-SNAPSHOT";
final MavenProject artifactProject = createProject("group", "artifact", artifactVersion, null);
final ArtifactMock artifactMock = new ArtifactMock(mockManager, "group", "artifact", artifactVersion, "jar", true, artifactBaseVersion);
artifactProject.setArtifact(artifactMock.getArtifact());
final MavenSession session = mockManager.createMock(MavenSession.class);
expect(session.getExecutionProperties()).andReturn(null).anyTimes();
expect(session.getUserProperties()).andReturn(new Properties()).anyTimes();
final AssemblerConfigurationSource cs = mockManager.createMock(AssemblerConfigurationSource.class);
expect(cs.getMavenSession()).andReturn(session).anyTimes();
DefaultAssemblyArchiverTest.setupInterpolators(cs);
mockManager.replayAll();
final String result = AssemblyFormatUtils.evaluateFileNameMapping("${artifact.artifactId}-${artifact.baseVersion}", artifactMock.getArtifact(), mainProject, null, cs, AssemblyFormatUtils.moduleProjectInterpolator(null), AssemblyFormatUtils.artifactProjectInterpolator(artifactProject));
/*
final Artifact artifact = artifactMock.getArtifact();
final String result =
AssemblyFormatUtils.evaluateFileNameMapping( "${artifact.artifactId}-${artifact.baseVersion}",
moduleArtifactInterpolator( null ),
moduleProjectInterpolator( null ),
artifactInterpolator( artifact ),
artifactProjectInterpolator( artifactProject ),
mainArtifactPropsOnly( mainProject ),
classifierRules( artifact ),
FixedStringSearchInterpolator.empty() );
*/
assertEquals("artifact-2-SNAPSHOT", result);
mockManager.verifyAll();
// clear out for next call.
mockManager.resetAll();
}
Aggregations