Java Code Examples for org.apache.maven.shared.utils.cli.CommandLineException

The following examples show how to use org.apache.maven.shared.utils.cli.CommandLineException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: butterfly   Source File: MavenGoalTest.java    License: MIT License 6 votes vote down vote up
@Test
public void isInvokerExceptionWithNullDataIfNonZeroExitCodeAndHandlerGetResultThrows() throws MavenInvocationException {
    InvocationResult r = Mockito.mock(InvocationResult.class);
    CommandLineException invokerException = new CommandLineException("test error");
    IllegalStateException resultException = new IllegalStateException("exception");
    Mockito.when(multipleOutputHandler.getResult()).thenThrow(resultException);
    Mockito.when(r.getExitCode()).thenReturn(1);
    Mockito.when(r.getExecutionException()).thenReturn(invokerException);
    Mockito.when(invoker.execute(request)).thenReturn(r);
    MavenInvocationOutputHandler genericHandler = new GenericErrorsOutputHandler();
    mavenGoal.setOutputHandlers(genericHandler);
    TUExecutionResult result = mavenGoal.execution(new File("/blah/pom.xml"), null);
    assertEquals(result.getException(), invokerException);
    assertEquals(result.getValue(), null);
    assertEquals(mavenGoal.getOutputHandlers(), new MavenInvocationOutputHandler[]{genericHandler});
}
 
Example 2
Source Project: quarkus   Source File: MavenProcessInvoker.java    License: Apache License 2.0 5 votes vote down vote up
private static Process executeCommandLine(Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr)
        throws CommandLineException {
    if (cl == null) {
        throw new IllegalArgumentException("the command line cannot be null.");
    } else {
        final Process p = cl.execute();
        final StreamPumper outputPumper = new StreamPumper(p.getInputStream(), systemOut);
        final StreamPumper errorPumper = new StreamPumper(p.getErrorStream(), systemErr);

        outputPumper.start();
        errorPumper.start();

        new Thread(() -> {
            try {
                // Wait for termination
                p.waitFor();
                outputPumper.waitUntilDone();
                errorPumper.waitUntilDone();
            } catch (Exception e) {
                outputPumper.disable();
                errorPumper.disable();
                e.printStackTrace();
            }
        }).start();

        return p;
    }
}
 
Example 3
Source Project: quarkus   Source File: MavenProcessInvocationResult.java    License: Apache License 2.0 5 votes vote down vote up
public MavenProcessInvocationResult setException(CommandLineException exception) {
    // Print the stack trace immediately to give some feedback early
    // In intellij, the used `mvn` executable is not "executable" by default on Mac and probably linux.
    // You need to chmod +x the file.
    exception.printStackTrace();
    this.exception = exception;
    return this;
}
 
Example 4
Source Project: butterfly   Source File: MavenGoalTest.java    License: MIT License 5 votes vote down vote up
@Test
public void isInvokerExceptionWithResultDataIfNonZeroExitCodeAndHandlerGetResultIsValid() throws MavenInvocationException {
    InvocationResult r = Mockito.mock(InvocationResult.class);
    Map<Class<? extends MavenInvocationOutputHandler>, Object> value = new HashMap<Class<? extends MavenInvocationOutputHandler>, Object>();
    value.put(new GenericErrorsOutputHandler().getClass(), "Hello!");
    CommandLineException invokerException = new CommandLineException("test error");
    Mockito.when(multipleOutputHandler.getResult()).thenReturn(value);
    Mockito.when(r.getExitCode()).thenReturn(1);
    Mockito.when(r.getExecutionException()).thenReturn(invokerException);
    Mockito.when(invoker.execute(request)).thenReturn(r);
    TUExecutionResult result = mavenGoal.execution(new File("/blah/pom.xml"), null);
    assertEquals(result.getException(), invokerException);
    assertEquals(result.getValue(), value);
}
 
Example 5
Source Project: enkan   Source File: MavenCompiler.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public CompileResult execute(Transport t) {
    final InvocationRequest request = new DefaultInvocationRequest();
    request.setPomFile(new File("pom.xml"));
    request.setGoals(Collections.singletonList("compile"));

    final Invoker invoker = new DefaultInvoker();
    final File mavenHome = new File(Env.getString("MAVEN_HOME",
            Env.getString("M2_HOME", "/opt/maven")));
    if (!mavenHome.exists()) {
        throw new IllegalStateException("MAVEN_HOME not set");
    }
    invoker.setWorkingDirectory(new File(projectDirectory));
    invoker.setMavenHome(mavenHome);
    invoker.setOutputHandler(line -> t.send(ReplResponse.withOut(line)));
    invoker.setErrorHandler(line -> t.send(ReplResponse.withErr(line)));

    CompileResult result = new CompileResult();
    try {
        InvocationResult invocationResult = invoker.execute(request);
        CommandLineException clEx = invocationResult.getExecutionException();
        result.setExecutionException(clEx);
    } catch (MavenInvocationException ex) {
        result.setExecutionException(ex);
    }
    return result;
}
 
Example 6
Source Project: webstart   Source File: DefaultSignTool.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void generateKey( SignConfig config, File keystoreFile )
        throws MojoExecutionException
{
    KeyToolGenerateKeyPairRequest request = config.createKeyGenRequest( keystoreFile );

    try
    {
        JavaToolResult result = keyTool.execute( request );

        CommandLineException exception = result.getExecutionException();
        if ( exception != null )
        {
            throw new MojoExecutionException( "Could not generate key store " + keystoreFile, exception );
        }
        int exitCode = result.getExitCode();
        if ( exitCode != 0 )
        {
            throw new MojoExecutionException(
                    "Could not generate key store " + keystoreFile + ", use -X to have detail of error" );
        }
    }
    catch ( JavaToolException e )
    {
        throw new MojoExecutionException( "Could not find keytool", e );
    }
}
 
Example 7
Source Project: webstart   Source File: DefaultSignTool.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void sign( SignConfig config, File jarFile, File signedJar )
        throws MojoExecutionException
{

    JarSignerRequest request = config.createSignRequest( jarFile, signedJar );

    try
    {
        JavaToolResult result = jarSigner.execute( request );

        CommandLineException exception = result.getExecutionException();
        if ( exception != null )
        {
            throw new MojoExecutionException( "Could not sign jar " + jarFile, exception );
        }
        int exitCode = result.getExitCode();
        if ( exitCode != 0 )
        {
            throw new MojoExecutionException(
                    "Could not sign jar " + jarFile + ", use -X to have detail of error" );
        }
    }
    catch ( JavaToolException e )
    {
        throw new MojoExecutionException( "Could not find jarSigner", e );
    }
}
 
Example 8
Source Project: webstart   Source File: DefaultSignTool.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void verify( SignConfig config, File jarFile, boolean certs )
        throws MojoExecutionException
{

    JarSignerRequest request = config.createVerifyRequest( jarFile, certs );

    try
    {
        JavaToolResult result = jarSigner.execute( request );

        CommandLineException exception = result.getExecutionException();
        if ( exception != null )
        {
            throw new MojoExecutionException( "Could not verify jar " + jarFile, exception );
        }
        int exitCode = result.getExitCode();
        if ( exitCode != 0 )
        {
            throw new MojoExecutionException(
                    "Could not verify jar " + jarFile + ", use -X to have detail of error" );
        }
    }
    catch ( JavaToolException e )
    {
        throw new MojoExecutionException( "Could not find jarSigner", e );
    }
}
 
Example 9
Source Project: quarkus   Source File: MavenProcessInvoker.java    License: Apache License 2.0 4 votes vote down vote up
private Process executeCommandLine(Commandline cli, InvocationRequest request)
        throws CommandLineException {
    InvocationOutputHandler outputHandler = request.getOutputHandler(this.outputHandler);
    InvocationOutputHandler errorHandler = request.getErrorHandler(this.errorHandler);
    return executeCommandLine(cli, outputHandler, errorHandler);
}
 
Example 10
Source Project: quarkus   Source File: MavenProcessInvocationResult.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public CommandLineException getExecutionException() {
    return exception;
}