You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2018/07/25 17:20:40 UTC

[maven-studies] branch maven-extention-demo updated: show Plexus annotations that work on Maven 3.0.x unlike JSR-330

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

hboutemy pushed a commit to branch maven-extention-demo
in repository https://gitbox.apache.org/repos/asf/maven-studies.git


The following commit(s) were added to refs/heads/maven-extention-demo by this push:
     new 8b27402  show Plexus annotations that work on Maven 3.0.x unlike JSR-330
8b27402 is described below

commit 8b274024f037f1284b8a33c2c269d69c48a27a6f
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Wed Jul 25 19:20:22 2018 +0200

    show Plexus annotations that work on Maven 3.0.x unlike JSR-330
---
 pom.xml                                            | 19 ++++++++++++++++++-
 src/it/-Dmaven.ext.class.path/verify.groovy        | 20 +++++++++++++-------
 src/it/mvnExtensions/invoker.properties            |  3 +++
 src/it/mvnExtensions/verify.groovy                 | 20 +++++++++++++-------
 src/it/pomExtension/verify.groovy                  | 22 ++++++++++++++--------
 .../apache/maven/demo/extension/EventSpyDemo.java  |  3 ++-
 ...mo.java => LifecycleParticipantDemoJsr330.java} | 12 +++++++-----
 ...mo.java => LifecycleParticipantDemoPlexus.java} | 16 +++++++---------
 8 files changed, 77 insertions(+), 38 deletions(-)

diff --git a/pom.xml b/pom.xml
index eb0c7ec..291b640 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,12 +54,17 @@ under the License.
   </properties>
 
   <dependencies>
-    <!-- using JSR-330 javax.inject annotations instead of Plexus Container Annotations -->
+    <!-- using JSR-330 javax.inject annotations for LifecycleParticipantDemoJsr330 -->
     <dependency>
       <groupId>javax.inject</groupId>
       <artifactId>javax.inject</artifactId>
       <version>1</version>
     </dependency>
+    <!-- using  Plexus Container Annotations for LifecycleParticipantDemoPlexus -->
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-component-annotations</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-core</artifactId>
@@ -90,6 +95,18 @@ under the License.
           </execution>
         </executions>
       </plugin>
+      <!-- Use Plexus Component Metadata Maven Plugin to extract Plexus Component annotations -->
+      <plugin>
+        <groupId>org.codehaus.plexus</groupId>
+        <artifactId>plexus-component-metadata</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>generate-metadata</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
       <!-- don't install or deploy artifact: this study is not intended for that currently -->
       <plugin>
         <artifactId>maven-install-plugin</artifactId>
diff --git a/src/it/-Dmaven.ext.class.path/verify.groovy b/src/it/-Dmaven.ext.class.path/verify.groovy
index b14f241..13be2d3 100644
--- a/src/it/-Dmaven.ext.class.path/verify.groovy
+++ b/src/it/-Dmaven.ext.class.path/verify.groovy
@@ -16,15 +16,21 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-assert new File(basedir, 'build.log').exists();
+assert new File( basedir, 'build.log' ).exists();
 
-content = new File(basedir, 'build.log').text;
+content = new File( basedir, 'build.log' ).text;
 
-assert content.contains( 'EventSpyDemo init:');
-assert content.contains( 'EventSpyDemo close');
+assert content.contains( 'LifecycleParticipantDemoPlexus afterSessionStart' );
+assert content.contains( 'LifecycleParticipantDemoPlexus afterProjectsRead' );
+// do not test since valid only since Maven 3.2.1: previous tests are sufficient
+//assert content.contains( 'LifecycleParticipantDemoPlexus afterSessionEnd' );
 
-assert content.contains( 'LifecycleParticipantDemo afterSessionStart');
-assert content.contains( 'LifecycleParticipantDemo afterProjectsRead');
-assert content.contains( 'LifecycleParticipantDemo afterSessionEnd');
+assert content.contains( 'LifecycleParticipantDemoJsr330 afterSessionStart' );
+assert content.contains( 'LifecycleParticipantDemoJsr330 afterProjectsRead' );
+// do not test since valid only since Maven 3.2.1: previous tests are sufficient
+//assert content.contains( 'LifecycleParticipantDemoJsr330 afterSessionEnd' );
+
+assert content.contains( 'EventSpyDemo init:' );
+assert content.contains( 'EventSpyDemo close' );
 
 return true;
\ No newline at end of file
diff --git a/src/it/mvnExtensions/invoker.properties b/src/it/mvnExtensions/invoker.properties
index d9a77de..4cc1626 100755
--- a/src/it/mvnExtensions/invoker.properties
+++ b/src/it/mvnExtensions/invoker.properties
@@ -16,3 +16,6 @@
 # under the License.
 
 invoker.goals=clean verify
+
+# .mvn/extensions.xml feature added in Maven 3.3.1
+invoker.maven.version = 3.3.1+
diff --git a/src/it/mvnExtensions/verify.groovy b/src/it/mvnExtensions/verify.groovy
index b14f241..13be2d3 100644
--- a/src/it/mvnExtensions/verify.groovy
+++ b/src/it/mvnExtensions/verify.groovy
@@ -16,15 +16,21 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-assert new File(basedir, 'build.log').exists();
+assert new File( basedir, 'build.log' ).exists();
 
-content = new File(basedir, 'build.log').text;
+content = new File( basedir, 'build.log' ).text;
 
-assert content.contains( 'EventSpyDemo init:');
-assert content.contains( 'EventSpyDemo close');
+assert content.contains( 'LifecycleParticipantDemoPlexus afterSessionStart' );
+assert content.contains( 'LifecycleParticipantDemoPlexus afterProjectsRead' );
+// do not test since valid only since Maven 3.2.1: previous tests are sufficient
+//assert content.contains( 'LifecycleParticipantDemoPlexus afterSessionEnd' );
 
-assert content.contains( 'LifecycleParticipantDemo afterSessionStart');
-assert content.contains( 'LifecycleParticipantDemo afterProjectsRead');
-assert content.contains( 'LifecycleParticipantDemo afterSessionEnd');
+assert content.contains( 'LifecycleParticipantDemoJsr330 afterSessionStart' );
+assert content.contains( 'LifecycleParticipantDemoJsr330 afterProjectsRead' );
+// do not test since valid only since Maven 3.2.1: previous tests are sufficient
+//assert content.contains( 'LifecycleParticipantDemoJsr330 afterSessionEnd' );
+
+assert content.contains( 'EventSpyDemo init:' );
+assert content.contains( 'EventSpyDemo close' );
 
 return true;
\ No newline at end of file
diff --git a/src/it/pomExtension/verify.groovy b/src/it/pomExtension/verify.groovy
index 573b69f..1f3a97f 100644
--- a/src/it/pomExtension/verify.groovy
+++ b/src/it/pomExtension/verify.groovy
@@ -16,16 +16,22 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-assert new File(basedir, 'build.log').exists();
+assert new File( basedir, 'build.log' ).exists();
 
-content = new File(basedir, 'build.log').text;
+content = new File( basedir, 'build.log' ).text;
 
-// EventSpy not activated when POM extension
-assert !content.contains( 'EventSpyDemo init:');
-assert !content.contains( 'EventSpyDemo close');
+assert !content.contains( 'LifecycleParticipantDemoPlexus afterSessionStart' ); // not yet activated when POM extension
+assert content.contains( 'LifecycleParticipantDemoPlexus afterProjectsRead' );
+// do not test since valid only since Maven 3.2.1: previous tests are sufficient
+//assert content.contains( 'LifecycleParticipantDemoPlexus afterSessionEnd' );
+
+assert !content.contains( 'LifecycleParticipantDemoJsr330 afterSessionStart' ); // not yet activated when POM extension
+assert content.contains( 'LifecycleParticipantDemoJsr330 afterProjectsRead' );
+// do not test since valid only since Maven 3.2.1: previous tests are sufficient
+//assert content.contains( 'LifecycleParticipantDemoJsr330 afterSessionEnd' );
 
-assert !content.contains( 'LifecycleParticipantDemo afterSessionStart'); // not yet activated when POM extension
-assert content.contains( 'LifecycleParticipantDemo afterProjectsRead');
-assert content.contains( 'LifecycleParticipantDemo afterSessionEnd');
+// EventSpy not activated when POM extension
+assert !content.contains( 'EventSpyDemo init:' );
+assert !content.contains( 'EventSpyDemo close' );
 
 return true;
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/demo/extension/EventSpyDemo.java b/src/main/java/org/apache/maven/demo/extension/EventSpyDemo.java
index 3d68d60..30cc589 100644
--- a/src/main/java/org/apache/maven/demo/extension/EventSpyDemo.java
+++ b/src/main/java/org/apache/maven/demo/extension/EventSpyDemo.java
@@ -32,7 +32,8 @@ import org.codehaus.plexus.classworlds.realm.ClassRealm;
 
 /**
  * Event Spy demo (since Maven 3.0.2, with <a href="https://issues.apache.org/jira/browse/MNG-4936">MNG-4936</a>).
- * Notice: event spies are not activated from POM build extensions.
+ * <p>Notice: event spies are not activated from POM build extensions.
+ * <p>Notice: JSR-330 annotations do not work on Maven 3.0.x, but only starting with 3.1
  */
 @Named( "demo" )
 @Singleton
diff --git a/src/main/java/org/apache/maven/demo/extension/LifecycleParticipantDemo.java b/src/main/java/org/apache/maven/demo/extension/LifecycleParticipantDemoJsr330.java
similarity index 77%
copy from src/main/java/org/apache/maven/demo/extension/LifecycleParticipantDemo.java
copy to src/main/java/org/apache/maven/demo/extension/LifecycleParticipantDemoJsr330.java
index 8e29dd5..149afa1 100644
--- a/src/main/java/org/apache/maven/demo/extension/LifecycleParticipantDemo.java
+++ b/src/main/java/org/apache/maven/demo/extension/LifecycleParticipantDemoJsr330.java
@@ -29,22 +29,24 @@ import org.apache.maven.execution.MavenSession;
 /**
  * Lifecycle Participant demo (feature added in Maven 3.0-alpha-3 with
  * <a href="https://issues.apache.org/jira/browse/MNG-4224">MNG-4224</a>).
+ * defined with <a href="/maven-jsr330.html">JSR-330 javax.inject annotations</a>.
+ * Notice: such JSR-330 annotations do not work on Maven 3.0.x, but only starting with 3.1
  */
-@Named( "demo" )
+@Named( "demo-jsr330" )
 @Singleton
-public class LifecycleParticipantDemo
+public class LifecycleParticipantDemoJsr330
     extends AbstractMavenLifecycleParticipant
 {
     public void afterProjectsRead( MavenSession session )
         throws MavenExecutionException
     {
-        System.err.println( "LifecycleParticipantDemo afterProjectsRead" );
+        System.err.println( "LifecycleParticipantDemoJsr330 afterProjectsRead" );
     }
 
     public void afterSessionStart( MavenSession session )
         throws MavenExecutionException
     {
-        System.err.println( "LifecycleParticipantDemo afterSessionStart" );
+        System.err.println( "LifecycleParticipantDemoJsr330 afterSessionStart" );
     }
 
     /*
@@ -53,6 +55,6 @@ public class LifecycleParticipantDemo
    public void afterSessionEnd( MavenSession session )
        throws MavenExecutionException
    {
-       System.err.println( "LifecycleParticipantDemo afterSessionEnd" );
+       System.err.println( "LifecycleParticipantDemoJsr330 afterSessionEnd" );
    }
 }
diff --git a/src/main/java/org/apache/maven/demo/extension/LifecycleParticipantDemo.java b/src/main/java/org/apache/maven/demo/extension/LifecycleParticipantDemoPlexus.java
similarity index 74%
rename from src/main/java/org/apache/maven/demo/extension/LifecycleParticipantDemo.java
rename to src/main/java/org/apache/maven/demo/extension/LifecycleParticipantDemoPlexus.java
index 8e29dd5..ea373ef 100644
--- a/src/main/java/org/apache/maven/demo/extension/LifecycleParticipantDemo.java
+++ b/src/main/java/org/apache/maven/demo/extension/LifecycleParticipantDemoPlexus.java
@@ -19,32 +19,30 @@ package org.apache.maven.demo.extension;
  * under the License.
  */
 
-import javax.inject.Named;
-import javax.inject.Singleton;
-
 import org.apache.maven.AbstractMavenLifecycleParticipant;
 import org.apache.maven.MavenExecutionException;
 import org.apache.maven.execution.MavenSession;
+import org.codehaus.plexus.component.annotations.Component;
 
 /**
  * Lifecycle Participant demo (feature added in Maven 3.0-alpha-3 with
  * <a href="https://issues.apache.org/jira/browse/MNG-4224">MNG-4224</a>).
+ * defined with <a href="/plugin-developers/cookbook/plexus-plugin-upgrade.html">Plexus annotations</a>.
  */
-@Named( "demo" )
-@Singleton
-public class LifecycleParticipantDemo
+@Component( role = AbstractMavenLifecycleParticipant.class, hint = "demo-plexus" )
+public class LifecycleParticipantDemoPlexus
     extends AbstractMavenLifecycleParticipant
 {
     public void afterProjectsRead( MavenSession session )
         throws MavenExecutionException
     {
-        System.err.println( "LifecycleParticipantDemo afterProjectsRead" );
+        System.err.println( "LifecycleParticipantDemoPlexus afterProjectsRead" );
     }
 
     public void afterSessionStart( MavenSession session )
         throws MavenExecutionException
     {
-        System.err.println( "LifecycleParticipantDemo afterSessionStart" );
+        System.err.println( "LifecycleParticipantDemoPlexus afterSessionStart" );
     }
 
     /*
@@ -53,6 +51,6 @@ public class LifecycleParticipantDemo
    public void afterSessionEnd( MavenSession session )
        throws MavenExecutionException
    {
-       System.err.println( "LifecycleParticipantDemo afterSessionEnd" );
+       System.err.println( "LifecycleParticipantDemoPlexus afterSessionEnd" );
    }
 }