Search in sources :

Example 21 with InvocationRequest

use of org.apache.maven.shared.invoker.InvocationRequest in project scala-maven-plugin by davidB.

the class ScalaContinuousTestMojo method postCompileActions.

@Override
protected void postCompileActions() throws Exception {
    if (test == null) {
        getLog().info("Now running all the unit tests. Use -Dtest=FooTest to run a single test by name");
    } else {
        getLog().info("Now running tests matching: " + test);
    }
    final InvocationRequest request = new DefaultInvocationRequest();
    request.setLocalRepositoryDirectory(localRepositoryPath);
    request.setInteractive(false);
    request.setErrorHandler(new SystemOutHandler(true));
    request.setOutputHandler(new SystemOutHandler(true));
    request.setBaseDirectory(project.getBasedir());
    request.setPomFile(new File(project.getBasedir(), "pom.xml"));
    request.setGoals(getMavenGoals());
    request.setOffline(false);
    if (test != null) {
        Properties properties = new Properties();
        properties.put("test", test);
        request.setProperties(properties);
    }
    if (getLog().isDebugEnabled()) {
        try {
            getLog().debug("Executing: " + new MavenCommandLineBuilder().build(request));
        } catch (CommandLineConfigurationException e) {
            getLog().debug("Failed to display command line: " + e.getMessage());
        }
    }
    try {
        invoker.execute(request);
    } catch (final MavenInvocationException e) {
        getLog().debug("Error invoking Maven: " + e.getMessage(), e);
        throw new BuildFailureException("Maven invocation failed. " + e.getMessage(), e);
    }
}
Also used : DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) InvocationRequest(org.apache.maven.shared.invoker.InvocationRequest) BuildFailureException(org.apache.maven.BuildFailureException) MavenInvocationException(org.apache.maven.shared.invoker.MavenInvocationException) SystemOutHandler(org.apache.maven.shared.invoker.SystemOutHandler) DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) MavenCommandLineBuilder(org.apache.maven.shared.invoker.MavenCommandLineBuilder) CommandLineConfigurationException(org.apache.maven.shared.invoker.CommandLineConfigurationException) Properties(java.util.Properties) File(java.io.File)

Example 22 with InvocationRequest

use of org.apache.maven.shared.invoker.InvocationRequest in project maven-plugins by apache.

the class InvokerPropertiesTest method testConfigureRequestProject.

public void testConfigureRequestProject() throws Exception {
    Properties props = new Properties();
    InvokerProperties facade = new InvokerProperties(props);
    InvocationRequest request = new DefaultInvocationRequest();
    File tempPom = File.createTempFile("maven-invoker-plugin-test", ".pom");
    File tempDir = tempPom.getParentFile();
    request.setBaseDirectory(tempDir);
    facade.configureInvocation(request, 0);
    assertEquals(tempDir, request.getBaseDirectory());
    assertEquals(null, request.getPomFile());
    props.setProperty("invoker.project", tempPom.getName());
    request.setBaseDirectory(tempDir);
    facade.configureInvocation(request, 0);
    assertEquals(tempDir, request.getBaseDirectory());
    assertEquals(tempPom, request.getPomFile());
    props.setProperty("invoker.project", "");
    request.setBaseDirectory(tempDir);
    facade.configureInvocation(request, 0);
    assertEquals(tempDir, request.getBaseDirectory());
    assertEquals(null, request.getPomFile());
    tempPom.delete();
}
Also used : InvokerProperties(org.apache.maven.plugins.invoker.InvokerProperties) DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) InvocationRequest(org.apache.maven.shared.invoker.InvocationRequest) DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) InvokerProperties(org.apache.maven.plugins.invoker.InvokerProperties) Properties(java.util.Properties) File(java.io.File)

Example 23 with InvocationRequest

use of org.apache.maven.shared.invoker.InvocationRequest in project maven-plugins by apache.

the class InvokerPropertiesTest method testConfigureRequestRecursion.

public void testConfigureRequestRecursion() throws Exception {
    Properties props = new Properties();
    InvokerProperties facade = new InvokerProperties(props);
    InvocationRequest request = new DefaultInvocationRequest();
    request.setRecursive(true);
    facade.configureInvocation(request, 0);
    assertTrue(request.isRecursive());
    request.setRecursive(false);
    facade.configureInvocation(request, 0);
    assertFalse(request.isRecursive());
    props.setProperty("invoker.nonRecursive", "true");
    facade.configureInvocation(request, 0);
    assertFalse(request.isRecursive());
    props.setProperty("invoker.nonRecursive", "false");
    facade.configureInvocation(request, 0);
    assertTrue(request.isRecursive());
}
Also used : InvokerProperties(org.apache.maven.plugins.invoker.InvokerProperties) DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) InvocationRequest(org.apache.maven.shared.invoker.InvocationRequest) DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) InvokerProperties(org.apache.maven.plugins.invoker.InvokerProperties) Properties(java.util.Properties)

Example 24 with InvocationRequest

use of org.apache.maven.shared.invoker.InvocationRequest in project maven-plugins by apache.

the class InvokerPropertiesTest method testConfigureRequestFailureBehavior.

public void testConfigureRequestFailureBehavior() throws Exception {
    Properties props = new Properties();
    InvokerProperties facade = new InvokerProperties(props);
    InvocationRequest request = new DefaultInvocationRequest();
    request.setReactorFailureBehavior(InvocationRequest.ReactorFailureBehavior.FailAtEnd);
    facade.configureInvocation(request, 0);
    assertEquals(InvocationRequest.ReactorFailureBehavior.FailAtEnd, request.getReactorFailureBehavior());
    props.setProperty("invoker.failureBehavior", InvocationRequest.ReactorFailureBehavior.FailNever.getLongOption());
    facade.configureInvocation(request, 0);
    assertEquals("fail-never", request.getReactorFailureBehavior().getLongOption());
}
Also used : InvokerProperties(org.apache.maven.plugins.invoker.InvokerProperties) DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) InvocationRequest(org.apache.maven.shared.invoker.InvocationRequest) DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) InvokerProperties(org.apache.maven.plugins.invoker.InvokerProperties) Properties(java.util.Properties)

Example 25 with InvocationRequest

use of org.apache.maven.shared.invoker.InvocationRequest in project maven-plugins by apache.

the class InvokerPropertiesTest method testConfigureRequestProfiles.

public void testConfigureRequestProfiles() throws Exception {
    Properties props = new Properties();
    InvokerProperties facade = new InvokerProperties(props);
    InvocationRequest request = new DefaultInvocationRequest();
    request.setProfiles(Collections.singletonList("test"));
    facade.configureInvocation(request, 0);
    assertEquals(Collections.singletonList("test"), request.getProfiles());
    props.setProperty("invoker.profiles", "verify");
    facade.configureInvocation(request, 0);
    assertEquals(Collections.singletonList("verify"), request.getProfiles());
    props.setProperty("invoker.profiles", "   ");
    facade.configureInvocation(request, 0);
    assertEquals(Arrays.asList(new String[0]), request.getProfiles());
    props.setProperty("invoker.profiles", "  clean , test   verify  ,");
    facade.configureInvocation(request, 0);
    assertEquals(Arrays.asList(new String[] { "clean", "test", "verify" }), request.getProfiles());
    props.setProperty("invoker.profiles", "");
    facade.configureInvocation(request, 0);
    assertEquals(Arrays.asList(new String[0]), request.getProfiles());
}
Also used : InvokerProperties(org.apache.maven.plugins.invoker.InvokerProperties) DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) InvocationRequest(org.apache.maven.shared.invoker.InvocationRequest) DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) InvokerProperties(org.apache.maven.plugins.invoker.InvokerProperties) Properties(java.util.Properties)

Aggregations

DefaultInvocationRequest (org.apache.maven.shared.invoker.DefaultInvocationRequest)31 InvocationRequest (org.apache.maven.shared.invoker.InvocationRequest)31 File (java.io.File)19 MavenInvocationException (org.apache.maven.shared.invoker.MavenInvocationException)17 Properties (java.util.Properties)15 InvocationResult (org.apache.maven.shared.invoker.InvocationResult)15 DefaultInvoker (org.apache.maven.shared.invoker.DefaultInvoker)14 Invoker (org.apache.maven.shared.invoker.Invoker)13 InvokerProperties (org.apache.maven.plugins.invoker.InvokerProperties)7 IOException (java.io.IOException)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 CommandLineConfigurationException (org.apache.maven.shared.invoker.CommandLineConfigurationException)2 MavenCommandLineBuilder (org.apache.maven.shared.invoker.MavenCommandLineBuilder)2 RunFailureException (org.apache.maven.shared.scriptinterpreter.RunFailureException)2 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1