Author: agudian Date: Sat Dec 26 15:57:13 2015 New Revision: 1721738 URL: http://svn.apache.org/viewvc?rev=1721738&view=rev Log: [MCOMPILER-211] Prevent possible NPE when m-compiler-p is used within an m2e-execution in Eclipse
Modified: maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java Modified: maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java?rev=1721738&r1=1721737&r2=1721738&view=diff ============================================================================== --- maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java (original) +++ maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java Sat Dec 26 15:57:13 2015 @@ -60,9 +60,8 @@ import java.util.Map; import java.util.Set; /** - * TODO: At least one step could be optimized, currently the plugin will do two - * scans of all the source code if the compiler has to have the entire set of - * sources. This is currently the case for at least the C# compiler and most + * TODO: At least one step could be optimized, currently the plugin will do two scans of all the source code if the + * compiler has to have the entire set of sources. This is currently the case for at least the C# compiler and most * likely all the other .NET compilers too. * * @author others @@ -219,12 +218,12 @@ public abstract class AbstractCompilerMo * Sets the arguments to be passed to the compiler (prepending a dash) if {@link #fork} is set to <code>true</code>. * </p> * <p> - * This is because the list of valid arguments passed to a Java compiler - * varies based on the compiler version. + * This is because the list of valid arguments passed to a Java compiler varies based on the compiler version. * </p> * <p> * To pass <code>-Xmaxerrs 1000 -Xlint -Xlint:-path -Averbose=true</code> you should include the following: * </p> + * * <pre> * <compilerArguments> * <Xmaxerrs>1000</Xmaxerrs> @@ -235,7 +234,7 @@ public abstract class AbstractCompilerMo * </pre> * * @since 2.0.1 - * @deprecated use {@link #compilerArgs} instead. + * @deprecated use {@link #compilerArgs} instead. */ @Parameter @Deprecated @@ -257,7 +256,7 @@ public abstract class AbstractCompilerMo */ @Parameter protected List<String> compilerArgs; - + /** * <p> * Sets the unformatted single argument string to be passed to the compiler if {@link #fork} is set to @@ -405,6 +404,7 @@ public abstract class AbstractCompilerMo protected abstract File getGeneratedSourcesDirectory(); + @Override public void execute() throws MojoExecutionException, CompilationFailureException { @@ -1058,20 +1058,25 @@ public abstract class AbstractCompilerMo protected Date getBuildStartTime() { + Date buildStartTime = null; try { Method getRequestMethod = session.getClass().getMethod( "getRequest" ); Object mavenExecutionRequest = getRequestMethod.invoke( session ); Method getStartTimeMethod = mavenExecutionRequest.getClass().getMethod( "getStartTime" ); - Date buildStartTime = (Date) getStartTimeMethod.invoke( mavenExecutionRequest ); - return buildStartTime; + buildStartTime = (Date) getStartTimeMethod.invoke( mavenExecutionRequest ); } catch ( Exception e ) { getLog().debug( "unable to get start time for the current build: " + e.getMessage() ); } - return new Date(); + if ( buildStartTime == null ) + { + return new Date(); + } + + return buildStartTime; }