Search in sources :

Example 6 with MavenProject

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)));
    }
}
Also used : Path(java.nio.file.Path) 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) Test(org.junit.Test)

Example 7 with MavenProject

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;
}
Also used : ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) Artifact(org.apache.maven.artifact.Artifact) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) MalformedURLException(java.net.MalformedURLException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 8 with MavenProject

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";
        }
    };
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MavenProject(org.apache.maven.project.MavenProject) Build(org.apache.maven.model.Build) Model(org.apache.maven.model.Model) List(java.util.List)

Example 9 with MavenProject

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");
}
Also used : MavenProject(org.apache.maven.project.MavenProject)

Example 10 with MavenProject

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");
}
Also used : MavenProject(org.apache.maven.project.MavenProject)

Aggregations

MavenProject (org.apache.maven.project.MavenProject)291 File (java.io.File)134 ArrayList (java.util.ArrayList)63 Artifact (org.apache.maven.artifact.Artifact)63 Model (org.apache.maven.model.Model)57 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)36 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)32 Assembly (org.apache.maven.plugins.assembly.model.Assembly)28 IOException (java.io.IOException)27 EasyMockSupport (org.easymock.classextension.EasyMockSupport)27 ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)20 HashSet (java.util.HashSet)16 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)16 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)16 HashMap (java.util.HashMap)15 LinkedHashSet (java.util.LinkedHashSet)15 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)15 MavenSession (org.apache.maven.execution.MavenSession)15 FileSet (org.apache.maven.plugins.assembly.model.FileSet)15 Logger (org.codehaus.plexus.logging.Logger)15