use of org.apache.maven.project.MavenProject in project antlr4 by antlr.
the class Antlr4MojoTest method importsCustomLayout.
@Test
public void importsCustomLayout() throws Exception {
Path baseDir = resources.getBasedir("importsCustom").toPath();
Path antlrDir = baseDir.resolve("src/main/antlr4");
Path generatedSources = baseDir.resolve("src/main/java");
Path genTestLexer = generatedSources.resolve("foo/TestLexer.java");
Path genTestParser = generatedSources.resolve("foo/TestParser.java");
Path genHello = generatedSources.resolve("foo/HelloParser.java");
Path baseGrammar = antlrDir.resolve("imports/TestBaseLexer.g4");
Path lexerGrammar = antlrDir.resolve("TestLexer.g4");
Path parserGrammar = antlrDir.resolve("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.toFile());
MavenSession session = maven.newMavenSession(project);
MojoExecution exec = maven.newMojoExecution("antlr4", outputDirectory, arguments);
////////////////////////////////////////////////////////////////////////
// 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));
////////////////////////////////////////////////////////////////////////
// 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)));
}
// modify the grammar to make checksum comparison detect a change
try (Change change = Change.of(baseGrammar, "DOT: '.' ;")) {
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)));
}
// modify the grammar to make checksum comparison detect a change
try (Change change = Change.of(lexerGrammar, "fragment DOT : '.';")) {
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)));
}
// modify the grammar to make checksum comparison detect a change
try (Change change = Change.of(parserGrammar, " t : WS* ;")) {
byte[] testLexerSum = checksum(genTestLexer);
byte[] testParserSum = checksum(genTestParser);
byte[] helloSum = checksum(genHello);
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(testLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(testParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(helloSum, checksum(genHello)));
}
}
use of org.apache.maven.project.MavenProject in project camel by apache.
the class RunMojo method resolveExecutableDependencies.
private Set<Artifact> resolveExecutableDependencies(Artifact executablePomArtifact, boolean ignoreFailures) throws MojoExecutionException {
Set<Artifact> executableDependencies = null;
try {
MavenProject executableProject = this.projectBuilder.buildFromRepository(executablePomArtifact, this.remoteRepositories, this.localRepository);
// get all of the dependencies for the executable project
List<Artifact> dependencies = CastUtils.cast(executableProject.getDependencies());
// make Artifacts of all the dependencies
Set<Artifact> dependencyArtifacts = CastUtils.cast(MavenMetadataSource.createArtifacts(this.artifactFactory, dependencies, null, null, null));
// not forgetting the Artifact of the project itself
dependencyArtifacts.add(executableProject.getArtifact());
// resolve runtime dependencies transitively to obtain a comprehensive list of assemblies
ArtifactResolutionResult result = artifactResolver.resolveTransitively(dependencyArtifacts, executablePomArtifact, Collections.emptyMap(), this.localRepository, this.remoteRepositories, metadataSource, new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME), Collections.emptyList());
executableDependencies = CastUtils.cast(result.getArtifacts());
} catch (Exception ex) {
if (ignoreFailures) {
getLog().debug("Ignoring maven resolving dependencies failure " + ex.getMessage());
} else {
throw new MojoExecutionException("Encountered problems resolving dependencies of the executable " + "in preparation for its execution.", ex);
}
}
return executableDependencies;
}
use of org.apache.maven.project.MavenProject in project camel by apache.
the class AbstractGeneratorMojoTest method configureGeneratorMojo.
protected void configureGeneratorMojo(AbstractGeneratorMojo mojo) {
mojo.componentName = COMPONENT_NAME;
mojo.scheme = SCHEME;
mojo.outPackage = OUT_PACKAGE;
mojo.componentPackage = COMPONENT_PACKAGE;
mojo.project = new MavenProject((Model) null) {
@Override
public List getTestClasspathElements() throws DependencyResolutionRequiredException {
return Collections.EMPTY_LIST;
}
@Override
public Build getBuild() {
return new Build() {
private static final long serialVersionUID = 1L;
@Override
public String getTestSourceDirectory() {
return OUT_DIR;
}
};
}
@Override
public String getGroupId() {
return "org.apache.camel.component";
}
@Override
public String getArtifactId() {
return "camel-test";
}
@Override
public String getVersion() {
return "1.0-SNAPSHOT";
}
};
}
use of org.apache.maven.project.MavenProject in project yeoman-maven-plugin by trecloux.
the class YeomanMojoTest method test_should_run_all_commands_with_default_configuration.
public void test_should_run_all_commands_with_default_configuration() throws Exception {
MavenProject project = getMavenProject("src/test/resources/test-mojo-default-pom.xml");
YeomanMojo yeomanMojo = (YeomanMojo) lookupConfiguredMojo(project, "build");
List<String> commands = executeMojoAndCaptureCommands(yeomanMojo);
assertThat(commands).containsExactly("node --version", "npm --version", "npm install", "bower --version", "bower install --no-color", "grunt --version", "grunt test --no-color", "grunt build --no-color");
}
use of org.apache.maven.project.MavenProject in project yeoman-maven-plugin by trecloux.
the class YeomanMojoTest method test_should_skip_build_when_flag_set.
public void test_should_skip_build_when_flag_set() throws Exception {
MavenProject project = getMavenProject("src/test/resources/test-mojo-default-pom.xml");
YeomanMojo yeomanMojo = (YeomanMojo) lookupConfiguredMojo(project, "build");
yeomanMojo.skipBuild = true;
List<String> commands = executeMojoAndCaptureCommands(yeomanMojo);
assertThat(commands).containsExactly("node --version", "npm --version", "npm install", "bower --version", "bower install --no-color", "grunt --version", "grunt test --no-color");
}
Aggregations