use of org.apache.maven.execution.MavenSession in project pom-manipulation-ext by release-engineering.
the class CliTest method checkLocalRepositoryWithExplicitMavenRepoAndSettings.
@Test
public void checkLocalRepositoryWithExplicitMavenRepoAndSettings() throws Exception {
File folder = temp.newFolder();
Cli c = new Cli();
executeMethod(c, "run", new Object[] { new String[] { "-settings=" + getClass().getResource("/settings-test.xml").getFile(), "-Dmaven.repo.local=" + folder.toString() } });
ManipulationSession session = (ManipulationSession) FieldUtils.readField(c, "session", true);
MavenSession ms = (MavenSession) FieldUtils.readField(session, "mavenSession", true);
assertTrue(ms.getLocalRepository().getBasedir().equals(folder.toString()));
assertTrue(ms.getRequest().getLocalRepository().getBasedir().equals(ms.getRequest().getLocalRepositoryPath().toString()));
}
use of org.apache.maven.execution.MavenSession in project pom-manipulation-ext by release-engineering.
the class CliTest method checkLocalRepositoryWithSettings.
@Test
public void checkLocalRepositoryWithSettings() throws Exception {
Cli c = new Cli();
executeMethod(c, "run", new Object[] { new String[] { "-settings=" + getClass().getResource("/settings-test.xml").getFile() } });
ManipulationSession session = (ManipulationSession) FieldUtils.readField(c, "session", true);
MavenSession ms = (MavenSession) FieldUtils.readField(session, "mavenSession", true);
assertTrue(ms.getRequest().getLocalRepository().getBasedir().equals(ms.getRequest().getLocalRepositoryPath().toString()));
}
use of org.apache.maven.execution.MavenSession in project antlr4 by tunnelvisionlabs.
the class Antlr4MojoTest method importsStandardLayout.
@Test
public void importsStandardLayout() throws Exception {
File baseDir = resources.getBasedir("importsStandard");
File antlrDir = new File(baseDir, "src/main/antlr4");
File generatedSources = new File(baseDir, "target/generated-sources/antlr4");
File genTestLexer = new File(generatedSources, "test/TestLexer.java");
File genTestParser = new File(generatedSources, "test/TestParser.java");
File genHello = new File(generatedSources, "test/HelloParser.java");
File baseGrammar = new File(antlrDir, "imports/TestBaseLexer.g4");
File baseGrammar2 = new File(antlrDir, "imports/TestBaseLexer2.g4");
File lexerGrammar = new File(antlrDir, "test/TestLexer.g4");
File parserGrammar = new File(antlrDir, "test/TestParser.g4");
MavenProject project = maven.readMavenProject(baseDir);
MavenSession session = maven.newMavenSession(project);
MojoExecution exec = maven.newMojoExecution("antlr4");
// //////////////////////////////////////////////////////////////////////
// 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());
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)));
}
// //////////////////////////////////////////////////////////////////////
// 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 {
maven.executeMojo(session, project, exec);
assertFalse(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
} finally {
change.close();
}
// 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)));
// //////////////////////////////////////////////////////////////////////
// 4th - the second imported grammar changed, every dependency has to be processed
// //////////////////////////////////////////////////////////////////////
// modify the grammar to make checksum comparison detect a change
change = Change.of(baseGrammar2, "BANG: '!' ;");
try {
maven.executeMojo(session, project, exec);
assertFalse(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
} finally {
change.close();
}
// 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)));
// //////////////////////////////////////////////////////////////////////
// 5th - 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, "FOO: 'foo' ;");
try {
maven.executeMojo(session, project, exec);
assertFalse(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
} finally {
change.close();
}
// 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)));
// //////////////////////////////////////////////////////////////////////
// 6th - 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 {
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
} finally {
change.close();
}
// 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 antlr4 by tunnelvisionlabs.
the class Antlr4MojoTest method importTokens.
@Test
public void importTokens() throws Exception {
File baseDir = resources.getBasedir("importTokens");
File antlrDir = new File(baseDir, "src/main/antlr4");
File generatedSources = new File(baseDir, "target/generated-sources/antlr4");
File genParser = new File(generatedSources, "test/SimpleParser.java");
File tokens = new File(antlrDir, "imports/SimpleLexer.tokens");
MavenProject project = maven.readMavenProject(baseDir);
MavenSession session = maven.newMavenSession(project);
MojoExecution exec = maven.newMojoExecution("antlr4");
// //////////////////////////////////////////////////////////////////////
// 1st - all grammars have to be processed
// //////////////////////////////////////////////////////////////////////
assertFalse(genParser.exists());
maven.executeMojo(session, project, exec);
assertTrue(genParser.isFile());
// //////////////////////////////////////////////////////////////////////
// 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)));
}
// //////////////////////////////////////////////////////////////////////
// 3rd - the imported grammar changed, every dependency has to be processed
// //////////////////////////////////////////////////////////////////////
Change change = Change.of(tokens, "DOT=4");
try {
byte[] sum = checksum(genParser);
maven.executeMojo(session, project, exec);
assertFalse(Arrays.equals(sum, checksum(genParser)));
} finally {
change.close();
}
}
use of org.apache.maven.execution.MavenSession in project antlr4 by tunnelvisionlabs.
the class Antlr4MojoTest method processWhenDependencyRemoved.
@Test
public void processWhenDependencyRemoved() throws Exception {
File baseDir = resources.getBasedir("dependencyRemoved");
File antlrDir = new File(baseDir, "src/main/antlr4");
File baseGrammar = new File(antlrDir, "imports/HelloBase.g4");
MavenProject project = maven.readMavenProject(baseDir);
MavenSession session = maven.newMavenSession(project);
MojoExecution exec = maven.newMojoExecution("antlr4");
maven.executeMojo(session, project, exec);
Change temp = Change.of(baseGrammar);
try {
// if the base grammar no longer exists, processing must be performed
assertTrue(baseGrammar.delete());
thrown.expect(MojoExecutionException.class);
thrown.expectMessage("ANTLR 4 caught 1 build errors.");
maven.executeMojo(session, project, exec);
} finally {
temp.close();
}
}
Aggregations