Search in sources :

Example 6 with MojoExecution

use of org.apache.maven.plugin.MojoExecution in project xtext-xtend by eclipse.

the class XtendProjectConfigurator method configure.

@Override
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
    addNature(request.getProject(), XtextProjectHelper.NATURE_ID, monitor);
    OutputConfiguration config = new XtendOutputConfigurationProvider().getOutputConfigurations().iterator().next();
    for (MojoExecution execution : getMojoExecutions(request, monitor)) {
        String goal = execution.getGoal();
        if (goal.equals("compile")) {
            readCompileConfig(config, request, execution);
        } else if (goal.equals("testCompile")) {
            readTestCompileConfig(config, request, execution);
        } else if (goal.equals("xtend-install-debug-info")) {
            readDebugInfoConfig(config, request, execution);
        } else if (goal.equals("xtend-test-install-debug-info")) {
            readTestDebugInfoConfig(config, request, execution);
        }
    }
    writePreferences(config, request.getProject());
}
Also used : MojoExecution(org.apache.maven.plugin.MojoExecution) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) XtendOutputConfigurationProvider(org.eclipse.xtend.core.compiler.XtendOutputConfigurationProvider)

Example 7 with MojoExecution

use of org.apache.maven.plugin.MojoExecution 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)));
    }
}
Also used : Path(java.nio.file.Path) MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) MojoExecution(org.apache.maven.plugin.MojoExecution) Test(org.junit.Test)

Example 8 with MojoExecution

use of org.apache.maven.plugin.MojoExecution 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 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));
    ////////////////////////////////////////////////////////////////////////
    // 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)) {
        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) MavenProject(org.apache.maven.project.MavenProject) MojoExecution(org.apache.maven.plugin.MojoExecution) Test(org.junit.Test)

Example 9 with MojoExecution

use of org.apache.maven.plugin.MojoExecution in project maven-plugins by apache.

the class CompilerMojoTestCase method getMockMojoExecution.

private MojoExecution getMockMojoExecution() {
    MojoDescriptor md = new MojoDescriptor();
    md.setGoal("compile");
    MojoExecution me = new MojoExecution(md);
    PluginDescriptor pd = new PluginDescriptor();
    pd.setArtifactId("maven-compiler-plugin");
    md.setPluginDescriptor(pd);
    return me;
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) MojoExecution(org.apache.maven.plugin.MojoExecution)

Example 10 with MojoExecution

use of org.apache.maven.plugin.MojoExecution in project bndtools by bndtools.

the class BndConfigurator method execJarMojo.

private void execJarMojo(IMavenProjectFacade projectFacade, IProgressMonitor monitor) throws CoreException {
    MavenProject mavenProject = projectFacade.getMavenProject();
    if (mavenProject == null) {
        mavenProject = projectFacade.getMavenProject(monitor);
    }
    final IMaven maven = MavenPlugin.getMaven();
    final MavenExecutionPlan plan = maven.calculateExecutionPlan(mavenProject, Arrays.asList("jar:jar"), true, monitor);
    final List<MojoExecution> mojoExecutions = plan.getMojoExecutions();
    if (mojoExecutions != null) {
        for (MojoExecution mojoExecution : mojoExecutions) {
            MavenPlugin.getMaven().execute(mavenProject, mojoExecution, monitor);
        }
    }
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MojoExecution(org.apache.maven.plugin.MojoExecution) MavenExecutionPlan(org.apache.maven.lifecycle.MavenExecutionPlan) IMaven(org.eclipse.m2e.core.embedder.IMaven)

Aggregations

MojoExecution (org.apache.maven.plugin.MojoExecution)11 MavenProject (org.apache.maven.project.MavenProject)7 MavenSession (org.apache.maven.execution.MavenSession)5 Test (org.junit.Test)5 Path (java.nio.file.Path)4 MojoDescriptor (org.apache.maven.plugin.descriptor.MojoDescriptor)3 IOException (java.io.IOException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)2 File (java.io.File)1 InputStream (java.io.InputStream)1 ServerSocket (java.net.ServerSocket)1 URL (java.net.URL)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)1 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)1 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)1 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)1 MavenExecutionPlan (org.apache.maven.lifecycle.MavenExecutionPlan)1 LifecycleExecutionPlanCalculator (org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator)1