[GitHub] asfgit closed pull request #5: Preserving the annotations at runtime is very useful for testing

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] asfgit closed pull request #5: Preserving the annotations at runtime is very useful for testing

GitBox
asfgit closed pull request #5: Preserving the annotations at runtime is very useful for testing
URL: https://github.com/apache/maven-plugin-tools/pull/5
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/maven-plugin-annotations/pom.xml b/maven-plugin-annotations/pom.xml
index 64b986a2..b02d029d 100644
--- a/maven-plugin-annotations/pom.xml
+++ b/maven-plugin-annotations/pom.xml
@@ -37,5 +37,11 @@
       <artifactId>maven-artifact</artifactId>
       <version>3.0</version>
     </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.11</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>
diff --git a/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Component.java b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Component.java
index 9afbd65b..22d24490 100644
--- a/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Component.java
+++ b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Component.java
@@ -35,7 +35,7 @@
  * @since 3.0
  */
 @Documented
-@Retention( RetentionPolicy.CLASS )
+@Retention( RetentionPolicy.RUNTIME )
 @Target( { ElementType.FIELD } )
 @Inherited
 public @interface Component
diff --git a/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Parameter.java b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Parameter.java
index ec9dbcf6..b4d28fc6 100644
--- a/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Parameter.java
+++ b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Parameter.java
@@ -35,7 +35,7 @@
  * @since 3.0
  */
 @Documented
-@Retention( RetentionPolicy.CLASS )
+@Retention( RetentionPolicy.RUNTIME )
 @Target( { ElementType.FIELD } )
 @Inherited
 public @interface Parameter
diff --git a/maven-plugin-annotations/src/test/java/org/apache/maven/plugins/annotations/RuntimeAnnotationsTest.java b/maven-plugin-annotations/src/test/java/org/apache/maven/plugins/annotations/RuntimeAnnotationsTest.java
new file mode 100644
index 00000000..11ab04b0
--- /dev/null
+++ b/maven-plugin-annotations/src/test/java/org/apache/maven/plugins/annotations/RuntimeAnnotationsTest.java
@@ -0,0 +1,45 @@
+package org.apache.maven.plugins.annotations;
+
+import java.lang.reflect.Field;
+
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class RuntimeAnnotationsTest {
+
+  @Rule
+  public TestName name = new TestName();
+
+  @Parameter
+  private String parameter;
+
+
+
+  @Test
+  public void parameter() {
+    Assert.assertTrue(field().isAnnotationPresent(Parameter.class));
+  }
+
+  @Component
+  private Object component;
+
+  @Test
+  public void component() {
+    Assert.assertTrue(field().isAnnotationPresent(Component.class));
+  }
+
+
+  private Field field() {
+    try {
+      return getClass().getDeclaredField(name.getMethodName());
+    }
+    catch (NoSuchFieldException e) {
+      throw new RuntimeException(e);
+    }
+    catch (SecurityException e) {
+      throw new RuntimeException(e);
+    }
+  }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]