You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2022/02/24 16:05:18 UTC

[maven-shared-incremental] branch mvn4 updated: Switch a few core plugins to the new api

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

gnodet pushed a commit to branch mvn4
in repository https://gitbox.apache.org/repos/asf/maven-shared-incremental.git


The following commit(s) were added to refs/heads/mvn4 by this push:
     new 89197fc  Switch a few core plugins to the new api
89197fc is described below

commit 89197fc9bb5f10e9909f9b11565b07af99c460ec
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Feb 24 17:00:58 2022 +0100

    Switch a few core plugins to the new api
---
 pom.xml                                            |  5 +-
 .../shared/incremental/IncrementalBuildHelper.java | 69 ++++++++--------------
 2 files changed, 28 insertions(+), 46 deletions(-)

diff --git a/pom.xml b/pom.xml
index 44ed372..f1f4db5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,9 +65,10 @@
   <dependencies>
     <dependency>
       <groupId>org.apache.maven</groupId>
-      <artifactId>maven-plugin-api</artifactId>
+      <artifactId>maven-core-api</artifactId>
       <version>${mavenVersion}</version>
     </dependency>
+    <!--
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-core</artifactId>
@@ -111,6 +112,7 @@
         </exclusion>
       </exclusions>
     </dependency>
+    -->
     <dependency>
       <groupId>org.apache.maven.shared</groupId>
       <artifactId>maven-shared-utils</artifactId>
@@ -135,7 +137,6 @@
       <plugin>
         <groupId>org.codehaus.plexus</groupId>
         <artifactId>plexus-component-metadata</artifactId>
-        <version>1.7.1</version>
         <executions>
           <execution>
             <goals>
diff --git a/src/main/java/org/apache/maven/shared/incremental/IncrementalBuildHelper.java b/src/main/java/org/apache/maven/shared/incremental/IncrementalBuildHelper.java
index cebe33f..3e63e5b 100644
--- a/src/main/java/org/apache/maven/shared/incremental/IncrementalBuildHelper.java
+++ b/src/main/java/org/apache/maven/shared/incremental/IncrementalBuildHelper.java
@@ -19,10 +19,9 @@ package org.apache.maven.shared.incremental;
  * under the License.
  */
 
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugin.MojoExecution;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.project.MavenProject;
+import org.apache.maven.api.MojoExecution;
+import org.apache.maven.api.Project;
+import org.apache.maven.api.plugin.MojoException;
 import org.apache.maven.shared.utils.io.DirectoryScanResult;
 import org.apache.maven.shared.utils.io.DirectoryScanner;
 import org.apache.maven.shared.utils.io.FileUtils;
@@ -53,7 +52,7 @@ public class IncrementalBuildHelper
     /**
      * Needed for storing the status for the incremental build support.
      */
-    private MavenProject mavenProject;
+    private Project mavenProject;
 
     /**
      * Used for detecting changes between the Mojo execution.
@@ -67,12 +66,7 @@ public class IncrementalBuildHelper
      */
     private String[] filesBeforeAction = new String[0];
 
-    public IncrementalBuildHelper( MojoExecution mojoExecution, MavenSession mavenSession )
-    {
-        this( mojoExecution, getMavenProject( mavenSession ) );
-    }
-
-    public IncrementalBuildHelper( MojoExecution mojoExecution, MavenProject mavenProject )
+    public IncrementalBuildHelper( MojoExecution mojoExecution, Project mavenProject )
     {
         if ( mavenProject == null )
         {
@@ -88,19 +82,6 @@ public class IncrementalBuildHelper
     }
 
     /**
-     * small helper method to allow for the nullcheck in the ct invocation
-     */
-    private static MavenProject getMavenProject( MavenSession mavenSession )
-    {
-        if ( mavenSession == null )
-        {
-            throw new IllegalArgumentException( "MavenSession must not be null!" );
-        }
-
-        return mavenSession.getCurrentProject();
-    }
-
-    /**
      * Get the existing DirectoryScanner used by this helper,
      * or create new a DirectoryScanner if none is yet set.
      * The DirectoryScanner is used for detecting changes in a directory
@@ -130,22 +111,22 @@ public class IncrementalBuildHelper
      * @return the directory for storing status information of the current Mojo execution.
      */
     public File getMojoStatusDirectory()
-        throws MojoExecutionException
+        throws MojoException
     {
         if ( mojoExecution == null )
         {
-            throw new MojoExecutionException( "MojoExecution could not get resolved" );
+            throw new MojoException( "MojoExecution could not get resolved" );
         }
 
-        File buildOutputDirectory = new File( mavenProject.getBuild().getDirectory() );
+        File buildOutputDirectory = new File( mavenProject.getModel().getBuild().getDirectory() );
 
         //X TODO the executionId contains -cli and -mojoname
         //X we should remove those postfixes as it should not make
         //X any difference whether being run on the cli or via build
         String mojoStatusPath =
             MAVEN_STATUS_ROOT + File.separator
-                + mojoExecution.getMojoDescriptor().getPluginDescriptor().getArtifactId() + File.separator
-                + mojoExecution.getMojoDescriptor().getGoal() + File.separator + mojoExecution.getExecutionId();
+                + mojoExecution.getPlugin().getArtifactId() + File.separator
+                + mojoExecution.getGoal() + File.separator + mojoExecution.getExecutionId();
 
         File mojoStatusDir = new File( buildOutputDirectory, mojoStatusPath );
 
@@ -164,10 +145,10 @@ public class IncrementalBuildHelper
      *
      * @param incrementalBuildHelperRequest
      * @return <code>true</code> if the set of inputFiles got changed since the last build.
-     * @throws MojoExecutionException
+     * @throws MojoException
      */
     public boolean inputFileTreeChanged( IncrementalBuildHelperRequest incrementalBuildHelperRequest )
-        throws MojoExecutionException
+        throws MojoException
     {
         File mojoConfigBase = getMojoStatusDirectory();
         File mojoConfigFile = new File( mojoConfigBase, INPUT_FILES_LST_FILENAME );
@@ -182,7 +163,7 @@ public class IncrementalBuildHelper
             }
             catch ( IOException e )
             {
-                throw new MojoExecutionException( "Error reading old mojo status " + mojoConfigFile, e );
+                throw new MojoException( "Error reading old mojo status " + mojoConfigFile, e );
             }
         }
 
@@ -201,7 +182,7 @@ public class IncrementalBuildHelper
         }
         catch ( IOException e )
         {
-            throw new MojoExecutionException( "Error while storing the mojo status", e );
+            throw new MojoException( "Error while storing the mojo status", e );
         }
 
         return ( dsr.getFilesAdded().length > 0 || dsr.getFilesRemoved().length > 0 );
@@ -216,10 +197,10 @@ public class IncrementalBuildHelper
      *
      * @param dirScanner
      * @return <code>true</code> if the set of inputFiles got changed since the last build.
-     * @throws MojoExecutionException
+     * @throws MojoException
      */
     public boolean inputFileTreeChanged( DirectoryScanner dirScanner )
-        throws MojoExecutionException
+        throws MojoException
     {
         File mojoConfigBase = getMojoStatusDirectory();
         File mojoConfigFile = new File( mojoConfigBase, INPUT_FILES_LST_FILENAME );
@@ -234,7 +215,7 @@ public class IncrementalBuildHelper
             }
             catch ( IOException e )
             {
-                throw new MojoExecutionException( "Error reading old mojo status " + mojoConfigFile, e );
+                throw new MojoException( "Error reading old mojo status " + mojoConfigFile, e );
             }
         }
 
@@ -247,7 +228,7 @@ public class IncrementalBuildHelper
         }
         catch ( IOException e )
         {
-            throw new MojoExecutionException( "Error while storing new mojo status" + mojoConfigFile, e );
+            throw new MojoException( "Error while storing new mojo status" + mojoConfigFile, e );
         }
 
         DirectoryScanResult dsr = dirScanner.diffIncludedFiles( oldInputFiles );
@@ -276,10 +257,10 @@ public class IncrementalBuildHelper
      *
      * @param incrementalBuildHelperRequest
      * @return all files which got created in the previous build and have been deleted now.
-     * @throws MojoExecutionException
+     * @throws MojoException
      */
     public String[] beforeRebuildExecution( IncrementalBuildHelperRequest incrementalBuildHelperRequest )
-        throws MojoExecutionException
+        throws MojoException
     {
         File mojoConfigBase = getMojoStatusDirectory();
         File mojoConfigFile = new File( mojoConfigBase, CREATED_FILES_LST_FILENAME );
@@ -297,7 +278,7 @@ public class IncrementalBuildHelper
         }
         catch ( IOException e )
         {
-            throw new MojoExecutionException( "Error reading old mojo status", e );
+            throw new MojoException( "Error reading old mojo status", e );
         }
 
         // we remember all files which currently exist in the output directory
@@ -320,10 +301,10 @@ public class IncrementalBuildHelper
      *
      * @param incrementalBuildHelperRequest will contains file sources to store if create files are not yet stored
      *
-     * @throws MojoExecutionException
+     * @throws MojoException
      */
     public void afterRebuildExecution( IncrementalBuildHelperRequest incrementalBuildHelperRequest )
-        throws MojoExecutionException
+        throws MojoException
     {
         DirectoryScanner diffScanner = getDirectoryScanner();
         // now scan the same directory again and create a diff
@@ -339,7 +320,7 @@ public class IncrementalBuildHelper
         }
         catch ( IOException e )
         {
-            throw new MojoExecutionException( "Error while storing the mojo status", e );
+            throw new MojoException( "Error while storing the mojo status", e );
         }
 
         // in case of clean compile the file is not created so next compile won't see it
@@ -354,7 +335,7 @@ public class IncrementalBuildHelper
             }
             catch ( IOException e )
             {
-                throw new MojoExecutionException( "Error while storing the mojo status", e );
+                throw new MojoException( "Error while storing the mojo status", e );
             }
         }