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

kwin pushed a commit to branch feature/incremental-build-support
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit f64069b167e71b204443cfcd46fecc8064b694f9
Author: Konrad Windszus <[email protected]>
AuthorDate: Fri Oct 28 13:24:58 2022 +0200

    MDEP-674 Add m2e lifecycle metadata
    
    Use BuildContext to notify about newly generated files/folders
---
 pom.xml                                            | 11 +++-
 .../plugins/dependency/AbstractDependencyMojo.java | 20 +++++++
 .../META-INF/m2e/lifecycle-mapping-metadata.xml    | 68 ++++++++++++++++++++++
 3 files changed, 97 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index b3de43a3..39eab2b9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -247,6 +247,15 @@ under the License.
       <version>${resolverVersion}</version>
       <scope>provided</scope>
     </dependency>
+    <!-- incremental build support 
(http://www.eclipse.org/m2e/documentation/m2e-making-maven-plugins-compat.html) 
-->
+    <dependency>
+      <groupId>org.sonatype.plexus</groupId>
+      <artifactId>plexus-build-api</artifactId>
+      <version>0.0.7</version>
+      <scope>compile</scope>
+    </dependency>
+    
+    <!-- test -->
     <dependency>
       <groupId>org.eclipse.aether</groupId>
       <artifactId>aether-connector-basic</artifactId>
@@ -265,8 +274,6 @@ under the License.
       <version>${resolverVersion}</version>
       <scope>test</scope>
     </dependency>
-
-    <!-- test -->
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
diff --git 
a/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java 
b/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java
index 16756cb2..574d4cec 100644
--- 
a/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java
+++ 
b/src/main/java/org/apache/maven/plugins/dependency/AbstractDependencyMojo.java
@@ -46,6 +46,7 @@ import 
org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelecto
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.ReflectionUtils;
 import org.codehaus.plexus.util.StringUtils;
+import org.sonatype.plexus.build.incremental.BuildContext;
 
 /**
  * @author <a href="mailto:[email protected]";>Brian Fox</a>
@@ -59,6 +60,19 @@ public abstract class AbstractDependencyMojo
     @Component
     private ArchiverManager archiverManager;
 
+
+    /**
+     * For m2e incremental build support
+     */
+    @Component
+    private BuildContext buildContext;
+
+    /**
+     * Skip plugin execution during incremental builds (e.g. triggered from 
M2E).
+     */
+    @Parameter( defaultValue = "false" )
+    private boolean skipDuringIncrementalBuild;
+
     /**
      * <p>
      * will use the jvm chmod, this is available for user and all level group 
level will be ignored
@@ -189,6 +203,7 @@ public abstract class AbstractDependencyMojo
             }
 
             FileUtils.copyFile( artifact, destFile );
+            buildContext.refresh( destFile );
         }
         catch ( IOException e )
         {
@@ -326,6 +341,7 @@ public abstract class AbstractDependencyMojo
         {
             throw new MojoExecutionException( "Error unpacking file: " + file 
+ " to: " + location, e );
         }
+        buildContext.refresh( location );
     }
 
     private void silenceUnarchiver( UnArchiver unArchiver )
@@ -410,6 +426,10 @@ public abstract class AbstractDependencyMojo
      */
     public boolean isSkip()
     {
+        if ( skipDuringIncrementalBuild && buildContext.isIncremental() )
+        {
+            return true;
+        }
         return skip;
     }
 
diff --git a/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml 
b/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
new file mode 100644
index 00000000..39432065
--- /dev/null
+++ b/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
@@ -0,0 +1,68 @@
+<!--
+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.
+-->
+<lifecycleMappingMetadata>
+    <pluginExecutions>
+        <pluginExecution>
+            <pluginExecutionFilter>
+                <goals>
+                    <goal>copy</goal>
+                    <goal>copy-dependencies</goal>
+                    <goal>properties</goal>
+                    <goal>unpack</goal>
+                    <goal>unpack-dependencies</goal>
+                </goals>
+            </pluginExecutionFilter>
+            <action>
+                <execute>
+                    <runOnIncremental>true</runOnIncremental>
+                    <runOnConfiguration>false</runOnConfiguration>
+                </execute>
+            </action>
+        </pluginExecution>
+        <pluginExecution>
+            <pluginExecutionFilter>
+                <goals>
+                    <goal>analyze</goal>
+                    <goal>analyze-dep-mgmt</goal>
+                    <goal>analyze-only</goal>
+                    <goal>analyze-report</goal>
+                    <goal>analyze-duplicate</goal>
+                    <goal>build-classpath</goal>
+                    <goal>display-ancestors</goal>
+                    <goal>get</goal>
+                    <goal>go-offline</goal>
+                    <goal>list</goal>
+                    <goal>list-classes</goal>
+                    <goal>list-repositories</goal>
+                    <goal>purge-local-repository</goal>
+                    <goal>resolve</goal>
+                    <goal>resolve-plugins</goal>
+                    <goal>sources</goal>
+                    <goal>tree</goal>
+                </goals>
+            </pluginExecutionFilter>
+            <action>
+                <execute>
+                    <runOnIncremental>false</runOnIncremental>
+                    <runOnConfiguration>false</runOnConfiguration>
+                </execute>
+            </action>
+        </pluginExecution>
+    </pluginExecutions>
+</lifecycleMappingMetadata>
\ No newline at end of file

Reply via email to