Search in sources :

Example 1 with LevelState

use of scala_maven_executions.LogProcessorUtils.LevelState in project scala-maven-plugin by davidB.

the class JavaMainCallerByFork method run.

@Override
public boolean run(boolean displayCmd, boolean throwFailure) throws Exception {
    List<String> cmd = buildCommand();
    displayCmd(displayCmd, cmd);
    Executor exec = new DefaultExecutor();
    // err and out are redirected to out
    if (!_redirectToLog) {
        exec.setStreamHandler(new PumpStreamHandler(System.out, System.err, System.in));
    } else {
        exec.setStreamHandler(new PumpStreamHandler(new LogOutputStream() {

            private LevelState _previous = new LevelState();

            @Override
            protected void processLine(String line, int level) {
                try {
                    _previous = LogProcessorUtils.levelStateOf(line, _previous);
                    switch(_previous.level) {
                        case ERROR:
                            requester.getLog().error(line);
                            break;
                        case WARNING:
                            requester.getLog().warn(line);
                            break;
                        default:
                            requester.getLog().info(line);
                            break;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }));
    }
    CommandLine cl = new CommandLine(cmd.get(0));
    for (int i = 1; i < cmd.size(); i++) {
        cl.addArgument(cmd.get(i), false);
    }
    try {
        int exitValue = exec.execute(cl);
        if (exitValue != 0) {
            if (throwFailure) {
                throw new MojoFailureException("command line returned non-zero value:" + exitValue);
            }
            return false;
        }
        if (!displayCmd)
            tryDeleteArgFile(cmd);
        return true;
    } catch (ExecuteException exc) {
        if (throwFailure) {
            throw exc;
        }
        return false;
    }
}
Also used : CommandLine(org.apache.commons.exec.CommandLine) Executor(org.apache.commons.exec.Executor) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) PumpStreamHandler(org.apache.commons.exec.PumpStreamHandler) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ExecuteException(org.apache.commons.exec.ExecuteException) LevelState(scala_maven_executions.LogProcessorUtils.LevelState) LogOutputStream(org.apache.commons.exec.LogOutputStream) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ExecuteException(org.apache.commons.exec.ExecuteException)

Example 2 with LevelState

use of scala_maven_executions.LogProcessorUtils.LevelState in project scala-maven-plugin by davidB.

the class LogProcessorUtilsTest method jdkSplit.

@Test
public void jdkSplit() throws Exception {
    LevelState previous = new LevelState();
    previous = assertLevelState("/home/hub/p/eee/src/main/scala:-1: info: compiling", previous, Level.INFO, null);
    previous = assertLevelState("Compiling 128 source files to /home/hub/p/eee/target/classes at 1312794546514", previous, Level.INFO, null);
    previous = assertLevelState("Recompiling 1 files", previous, Level.INFO, null);
    previous = assertLevelState("/home/hub/p/eee/src/main/scala/Service.scala:72: error: type mismatch;", previous, Level.ERROR, "^");
    previous = assertLevelState("found : Unit", previous, Level.ERROR, "^");
    previous = assertLevelState("required: () => Any", previous, Level.ERROR, "^");
    previous = assertLevelState("f()", previous, Level.ERROR, "^");
    previous = assertLevelState(" ^", previous, Level.ERROR, null);
    previous = assertLevelState("/home/hub/p/eee/src/main/scala/src/main/scala/Service.scala:79: error: type mismatch;", previous, Level.ERROR, "^");
    previous = assertLevelState("found : Unit", previous, Level.ERROR, "^");
    previous = assertLevelState("required: () => Any", previous, Level.ERROR, "^");
    previous = assertLevelState("f()", previous, Level.ERROR, "^");
    previous = assertLevelState("^", previous, Level.ERROR, null);
    previous = assertLevelState("two errors found", previous, Level.ERROR, null);
    previous = assertLevelState("------------------------------------------------------------------------", previous, Level.INFO, null);
    previous = assertLevelState("BUILD ERROR", previous, Level.ERROR, null);
    previous = assertLevelState("------------------------------------------------------------------------", previous, Level.INFO, null);
    previous = assertLevelState("wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1(Exit value: 1)", previous, Level.ERROR, null);
}
Also used : LevelState(scala_maven_executions.LogProcessorUtils.LevelState) Test(org.junit.Test)

Example 3 with LevelState

use of scala_maven_executions.LogProcessorUtils.LevelState in project scala-maven-plugin by davidB.

the class LogProcessorUtilsTest method assertLevelState.

private LevelState assertLevelState(String input, LevelState previous, Level expectedLevel, String expectedUntilContains) throws Exception {
    LevelState back = LogProcessorUtils.levelStateOf(input, previous);
    assertEquals(expectedLevel, back.level);
    assertEquals(expectedUntilContains, back.untilContains);
    return back;
}
Also used : LevelState(scala_maven_executions.LogProcessorUtils.LevelState)

Aggregations

LevelState (scala_maven_executions.LogProcessorUtils.LevelState)3 CommandLine (org.apache.commons.exec.CommandLine)1 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)1 ExecuteException (org.apache.commons.exec.ExecuteException)1 Executor (org.apache.commons.exec.Executor)1 LogOutputStream (org.apache.commons.exec.LogOutputStream)1 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 Test (org.junit.Test)1