Search in sources :

Example 31 with MavenSession

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()));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) File(java.io.File) Test(org.junit.Test)

Example 32 with MavenSession

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()));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) Test(org.junit.Test)

Example 33 with MavenSession

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

Example 34 with MavenSession

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

Example 35 with MavenSession

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

Aggregations

MavenSession (org.apache.maven.execution.MavenSession)117 File (java.io.File)65 MavenProject (org.apache.maven.project.MavenProject)47 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)30 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)23 Test (org.junit.Test)21 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)20 LegacySupport (org.apache.maven.plugin.LegacySupport)19 Properties (java.util.Properties)18 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)18 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)16 MojoExecution (org.apache.maven.plugin.MojoExecution)13 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)13 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)11 Artifact (org.apache.maven.artifact.Artifact)10 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)9 ManipulationSession (org.commonjava.maven.ext.core.ManipulationSession)8 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)7 Settings (org.apache.maven.settings.Settings)7 ArrayList (java.util.ArrayList)6