You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2022/07/22 06:29:24 UTC

[maven-compiler-plugin] branch master updated: usage of reflection is not needed anymore (#140)

This is an automated email from the ASF dual-hosted git repository.

olamy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-compiler-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new cdfeb52  usage of reflection is not needed anymore (#140)
cdfeb52 is described below

commit cdfeb52351fea48d49cfdd8da896c42c66b547a8
Author: Olivier Lamy <ol...@apache.org>
AuthorDate: Fri Jul 22 16:29:20 2022 +1000

    usage of reflection is not needed anymore (#140)
    
    * usage of reflection is not needed anymore
    * fix possible NPE for test...
    
    Signed-off-by: Olivier Lamy <ol...@apache.org>
---
 .../plugin/compiler/AbstractCompilerMojo.java      | 39 ++++------------------
 .../maven/plugin/compiler/TestCompilerMojo.java    |  6 ++--
 2 files changed, 9 insertions(+), 36 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
index cf6b86c..6f27504 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
@@ -48,6 +48,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
 import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
 import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.execution.MavenExecutionRequest;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecution;
@@ -1496,7 +1497,7 @@ public abstract class AbstractCompilerMojo
             catch ( InclusionScanException e )
             {
                 throw new MojoExecutionException(
-                    "Error scanning source root: \'" + sourceRoot + "\' for stale files to recompile.", e );
+                    "Error scanning source root: '" + sourceRoot + "' for stale files to recompile.", e );
             }
         }
 
@@ -1536,42 +1537,14 @@ public abstract class AbstractCompilerMojo
      */
     protected int getRequestThreadCount()
     {
-        try
-        {
-            Method getRequestMethod = session.getClass().getMethod( "getRequest" );
-            Object mavenExecutionRequest = getRequestMethod.invoke( this.session );
-            Method getThreadCountMethod = mavenExecutionRequest.getClass().getMethod( "getThreadCount" );
-            String threadCount = (String) getThreadCountMethod.invoke( mavenExecutionRequest );
-            return Integer.parseInt( threadCount );
-        }
-        catch ( Exception e )
-        {
-            getLog().debug( "unable to get threadCount for the current build: " + e.getMessage() );
-        }
-        return 1;
+        return session.getRequest().getDegreeOfConcurrency();
     }
 
     protected Date getBuildStartTime()
     {
-        Date buildStartTime = null;
-        try
-        {
-            Method getRequestMethod = session.getClass().getMethod( "getRequest" );
-            Object mavenExecutionRequest = getRequestMethod.invoke( session );
-            Method getStartTimeMethod = mavenExecutionRequest.getClass().getMethod( "getStartTime" );
-            buildStartTime = (Date) getStartTimeMethod.invoke( mavenExecutionRequest );
-        }
-        catch ( Exception e )
-        {
-            getLog().debug( "unable to get start time for the current build: " + e.getMessage() );
-        }
-
-        if ( buildStartTime == null )
-        {
-            return new Date();
-        }
-
-        return buildStartTime;
+        MavenExecutionRequest request = session.getRequest();
+        Date buildStartTime = request == null ? new Date() : request.getStartTime();
+        return buildStartTime == null ? new Date() : buildStartTime;
     }
 
 
diff --git a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
index 9d9469f..4368304 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
@@ -306,7 +306,7 @@ public class TestCompilerMojo
 
         if ( release != null )
         {
-            if ( Integer.valueOf( release ) < 9 )
+            if ( Integer.parseInt( release ) < 9 )
             {
                 pathElements = Collections.emptyMap();
                 modulepathElements = Collections.emptyList();
@@ -314,7 +314,7 @@ public class TestCompilerMojo
                 return;
             }
         }
-        else if ( Double.valueOf( getTarget() ) < Double.valueOf( MODULE_INFO_TARGET ) )
+        else if ( Double.parseDouble( getTarget() ) < Double.parseDouble( MODULE_INFO_TARGET ) )
         {
             pathElements = Collections.emptyMap();
             modulepathElements = Collections.emptyList();
@@ -440,7 +440,7 @@ public class TestCompilerMojo
         if ( testIncludes.isEmpty() && testExcludes.isEmpty() )
         {
             testIncludes = Collections.singleton( defaultIncludePattern );
-            scanner = new SimpleSourceInclusionScanner( testIncludes, Collections.<String>emptySet() );
+            scanner = new SimpleSourceInclusionScanner( testIncludes, Collections.emptySet() );
         }
         else
         {