This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch MINVOKER-267 in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git
commit 8ebd1c550beb038a7350a178e8102e5a3b151954 Author: Slawomir Jaranowski <s.jaranow...@gmail.com> AuthorDate: Fri Jul 24 21:03:28 2020 +0200 [MINVOKER-267] Update maven-script-interpreter to 1.3 --- pom.xml | 2 +- .../maven/plugins/invoker/AbstractInvokerMojo.java | 52 +++++++++----------- .../apache/maven/plugins/invoker/FileLogger.java | 17 +++++-- .../maven/plugins/invoker/RunFailureException.java | 55 ++++++++++++++++++++++ 4 files changed, 91 insertions(+), 35 deletions(-) diff --git a/pom.xml b/pom.xml index 1777c77..98bdf1f 100644 --- a/pom.xml +++ b/pom.xml @@ -130,7 +130,7 @@ under the License. <dependency> <groupId>org.apache.maven.shared</groupId> <artifactId>maven-script-interpreter</artifactId> - <version>1.2</version> + <version>1.3</version> <exclusions> <!-- there's already a direct dependency to groovy-all --> <exclusion> diff --git a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java index cf1d7e5..cb4f853 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java +++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java @@ -47,8 +47,8 @@ import org.apache.maven.shared.invoker.InvocationResult; import org.apache.maven.shared.invoker.Invoker; import org.apache.maven.shared.invoker.MavenCommandLineBuilder; import org.apache.maven.shared.invoker.MavenInvocationException; -import org.apache.maven.shared.scriptinterpreter.RunErrorException; -import org.apache.maven.shared.scriptinterpreter.RunFailureException; +import org.apache.maven.shared.scriptinterpreter.ScriptException; +import org.apache.maven.shared.scriptinterpreter.ScriptReturnException; import org.apache.maven.shared.scriptinterpreter.ScriptRunner; import org.apache.maven.shared.utils.logging.MessageBuilder; import org.apache.maven.toolchain.MisconfiguredToolchainException; @@ -912,7 +912,7 @@ public abstract class AbstractInvokerMojo { scriptClassPath = null; } - scriptRunner = new ScriptRunner( getLog() ); + scriptRunner = new ScriptRunner( ); scriptRunner.setScriptEncoding( encoding ); scriptRunner.setGlobalVariable( "localRepositoryPath", localRepositoryPath ); if ( scriptVariables != null ) @@ -1819,17 +1819,6 @@ public abstract class AbstractInvokerMojo buildJob.setFailureMessage( "Skipped due to " + message.toString() ); } } - catch ( RunErrorException e ) - { - buildJob.setResult( BuildJob.Result.ERROR ); - buildJob.setFailureMessage( e.getMessage() ); - - if ( !suppressSummaries ) - { - getLog().info( " " + e.getMessage() ); - getLog().info( pad( buildJob ).failure( "ERROR" ).a( ' ' ) + formatTime( buildJob.getTime() ) ); - } - } catch ( RunFailureException e ) { buildJob.setResult( e.getType() ); @@ -2040,7 +2029,7 @@ public abstract class AbstractInvokerMojo * @return <code>true</code> if the project was launched or <code>false</code> if the selector script indicated that * the project should be skipped. * @throws org.apache.maven.plugin.MojoExecutionException If the project could not be launched. - * @throws org.apache.maven.shared.scriptinterpreter.RunFailureException If either a hook script or the build itself + * @throws RunFailureException If either a hook script or the build itself * failed. */ private boolean runBuild( File basedir, File pomFile, File settingsFile, File actualJavaHome, @@ -2070,22 +2059,26 @@ public abstract class AbstractInvokerMojo { try { - scriptRunner.run( "selector script", basedir, selectorScript, context, logger, BuildJob.Result.SKIPPED, - false ); + scriptRunner.run( "selector script", basedir, selectorScript, context, logger ); } - catch ( RunErrorException e ) + catch ( ScriptReturnException e ) { selectorResult = false; - throw e; + return false; } - catch ( RunFailureException e ) + catch ( ScriptException e ) { - selectorResult = false; - return false; + throw new RunFailureException( BuildJob.Result.ERROR, e ); } - scriptRunner.run( "pre-build script", basedir, preBuildHookScript, context, logger, - BuildJob.Result.FAILURE_PRE_HOOK, false ); + try + { + scriptRunner.run( "pre-build script", basedir, preBuildHookScript, context, logger ); + } + catch ( ScriptException e ) + { + throw new RunFailureException( BuildJob.Result.FAILURE_PRE_HOOK, e ); + } final InvocationRequest request = new DefaultInvocationRequest(); @@ -2227,15 +2220,18 @@ public abstract class AbstractInvokerMojo { try { - scriptRunner.run( "post-build script", basedir, postBuildHookScript, context, logger, - BuildJob.Result.FAILURE_POST_HOOK, true ); + scriptRunner.run( "post-build script", basedir, postBuildHookScript, context, logger ); } catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } + catch ( ScriptException e ) + { + throw new RunFailureException( e.getMessage(), BuildJob.Result.FAILURE_POST_HOOK, e ); + } } - private void setupLoggerForBuildJob( FileLogger logger, final InvocationRequest request ) + private void setupLoggerForBuildJob( final FileLogger logger, final InvocationRequest request ) { if ( logger != null ) { @@ -2359,8 +2355,6 @@ public abstract class AbstractInvokerMojo * @param invocationIndex The index of the invocation for which to check the exit code, must not be negative. * @param invokerProperties The invoker properties used to check the exit code, must not be <code>null</code>. * @param logger The build logger, may be <code>null</code> if logging is disabled. - * @throws org.apache.maven.shared.scriptinterpreter.RunFailureException If the invocation result indicates a build - * failure. */ private void verify( InvocationResult result, int invocationIndex, InvokerProperties invokerProperties, FileLogger logger ) diff --git a/src/main/java/org/apache/maven/plugins/invoker/FileLogger.java b/src/main/java/org/apache/maven/plugins/invoker/FileLogger.java index 9e67115..dfe009b 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/FileLogger.java +++ b/src/main/java/org/apache/maven/plugins/invoker/FileLogger.java @@ -24,14 +24,14 @@ import java.io.IOException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.shared.invoker.InvocationOutputHandler; -import org.apache.maven.shared.scriptinterpreter.ExecutionLogger; +import org.apache.maven.shared.scriptinterpreter.FileLoggerMirrorHandler; /** * */ class FileLogger extends org.apache.maven.shared.scriptinterpreter.FileLogger - implements InvocationOutputHandler, ExecutionLogger + implements InvocationOutputHandler { /** @@ -43,7 +43,7 @@ class FileLogger FileLogger( File outputFile ) throws IOException { - super( outputFile, null ); + super( outputFile ); } /** @@ -53,10 +53,17 @@ class FileLogger * @param log The mojo logger to additionally output messages to, may be <code>null</code> if not used. * @throws IOException If the output file could not be created. */ - FileLogger( File outputFile, Log log ) + FileLogger( File outputFile, final Log log ) throws IOException { - super( outputFile, log ); + super( outputFile, new FileLoggerMirrorHandler() + { + @Override + public void consumeOutput( String message ) + { + log.info( message ); + } + } ); } } diff --git a/src/main/java/org/apache/maven/plugins/invoker/RunFailureException.java b/src/main/java/org/apache/maven/plugins/invoker/RunFailureException.java new file mode 100644 index 0000000..1966fc6 --- /dev/null +++ b/src/main/java/org/apache/maven/plugins/invoker/RunFailureException.java @@ -0,0 +1,55 @@ +package org.apache.maven.plugins.invoker; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Provide an error during test invocation. + * + * @author Slawomir Jaranowski + */ +public class RunFailureException extends Exception +{ + + private final String type; + + public RunFailureException( String message, String type ) + { + super( message ); + this.type = type; + } + + public RunFailureException( String type, Throwable cause ) + { + super( cause ); + this.type = type; + + } + + public RunFailureException( String message, String type, Throwable cause ) + { + super( message, cause ); + this.type = type; + } + + public String getType() + { + return type; + } +}