You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ju...@apache.org on 2012/01/11 18:24:17 UTC

svn commit: r1230159 - in /sling/trunk/maven: adapter-annotations/src/main/java/org/apache/sling/adapter/annotations/ maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/

Author: justin
Date: Wed Jan 11 17:24:17 2012
New Revision: 1230159

URL: http://svn.apache.org/viewvc?rev=1230159&view=rev
Log:
SLING-2354 - adding Adaptables annotation

Added:
    sling/trunk/maven/adapter-annotations/src/main/java/org/apache/sling/adapter/annotations/Adaptables.java
Modified:
    sling/trunk/maven/adapter-annotations/src/main/java/org/apache/sling/adapter/annotations/Adaptable.java
    sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/GenerateAdapterMetadataMojo.java

Modified: sling/trunk/maven/adapter-annotations/src/main/java/org/apache/sling/adapter/annotations/Adaptable.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/adapter-annotations/src/main/java/org/apache/sling/adapter/annotations/Adaptable.java?rev=1230159&r1=1230158&r2=1230159&view=diff
==============================================================================
--- sling/trunk/maven/adapter-annotations/src/main/java/org/apache/sling/adapter/annotations/Adaptable.java (original)
+++ sling/trunk/maven/adapter-annotations/src/main/java/org/apache/sling/adapter/annotations/Adaptable.java Wed Jan 11 17:24:17 2012
@@ -25,7 +25,7 @@ import java.lang.annotation.RetentionPol
 import java.lang.annotation.Target;
 
 /**
- * The <code>AdaptableInfo</code> annotation defines metadata about an implementation
+ * The <code>Adaptable</code> annotation defines metadata about an implementation
  * of <code>org.apache.sling.api.adapter.Adaptable</code>.
  */
 @Target(ElementType.TYPE)

Added: sling/trunk/maven/adapter-annotations/src/main/java/org/apache/sling/adapter/annotations/Adaptables.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/adapter-annotations/src/main/java/org/apache/sling/adapter/annotations/Adaptables.java?rev=1230159&view=auto
==============================================================================
--- sling/trunk/maven/adapter-annotations/src/main/java/org/apache/sling/adapter/annotations/Adaptables.java (added)
+++ sling/trunk/maven/adapter-annotations/src/main/java/org/apache/sling/adapter/annotations/Adaptables.java Wed Jan 11 17:24:17 2012
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+package org.apache.sling.adapter.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * The <code>Adaptables</code> annotation allows multiple
+ * <code>org.apache.sling.api.adapter.annotations.Adaptable</code> annotations
+ * to be added to a single class.
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.CLASS)
+@Documented
+public @interface Adaptables {
+
+    /**
+     * The adaptable annotations.
+     */
+    Adaptable[] value();
+
+}

Modified: sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/GenerateAdapterMetadataMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/GenerateAdapterMetadataMojo.java?rev=1230159&r1=1230158&r2=1230159&view=diff
==============================================================================
--- sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/GenerateAdapterMetadataMojo.java (original)
+++ sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/GenerateAdapterMetadataMojo.java Wed Jan 11 17:24:17 2012
@@ -22,6 +22,8 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -32,6 +34,8 @@ import org.apache.maven.plugin.MojoExecu
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
 import org.apache.sling.adapter.annotations.Adaptable;
+import org.apache.sling.adapter.annotations.Adaptables;
+import org.apache.sling.commons.json.JSONArray;
 import org.apache.sling.commons.json.JSONException;
 import org.apache.sling.commons.json.JSONObject;
 import org.codehaus.plexus.util.IOUtil;
@@ -55,6 +59,8 @@ public class GenerateAdapterMetadataMojo
 
     private static final String ADAPTABLE_DESC = "L" + Adaptable.class.getName().replace('.', '/') + ";";
 
+    private static final String ADAPTABLES_DESC = "L" + Adaptables.class.getName().replace('.', '/') + ";";
+
     private static final String DEFAULT_CONDITION = "If the adaptable is a %s.";
 
     private static String getSimpleName(final ClassNode clazz) {
@@ -106,10 +112,9 @@ public class GenerateAdapterMetadataMojo
             final AnnotationDB annotationDb = new AnnotationDB();
             annotationDb.scanArchives(buildOutputDirectory.toURI().toURL());
 
-            final Set<String> annotatedClassNames = annotationDb.getAnnotationIndex().get(Adaptable.class.getName());
-            if (annotatedClassNames.isEmpty()) {
-                getLog().debug("No classes found with adaptable annotations.");
-            }
+            final Set<String> annotatedClassNames = new HashSet<String>();
+            addAnnotatedClasses(annotationDb, annotatedClassNames, Adaptable.class);
+            addAnnotatedClasses(annotationDb, annotatedClassNames, Adaptables.class);
 
             for (final String annotatedClassName : annotatedClassNames) {
                 getLog().info(String.format("found adaptable annotation on %s", annotatedClassName));
@@ -130,6 +135,8 @@ public class GenerateAdapterMetadataMojo
                 for (final AnnotationNode annotation : annotations) {
                     if (ADAPTABLE_DESC.equals(annotation.desc)) {
                         parseAdaptableAnnotation(annotation, classNode, descriptor);
+                    } else if (ADAPTABLES_DESC.equals(annotation.desc)) {
+                        parseAdaptablesAnnotation(annotation, classNode, descriptor);
                     }
                 }
 
@@ -153,6 +160,15 @@ public class GenerateAdapterMetadataMojo
 
     }
 
+    private void addAnnotatedClasses(final AnnotationDB annotationDb, final Set<String> annotatedClassNames, final Class<? extends Annotation> clazz) {
+        Set<String> classNames = annotationDb.getAnnotationIndex().get(clazz.getName());
+        if (classNames == null || classNames.isEmpty()) {
+            getLog().debug("No classes found with adaptable annotations.");
+        } else {
+            annotatedClassNames.addAll(classNames);
+        }
+    }
+
     private void addResource() {
         final String ourRsrcPath = this.outputDirectory.getAbsolutePath();
         boolean found = false;
@@ -170,11 +186,30 @@ public class GenerateAdapterMetadataMojo
 
     }
 
+    private void parseAdaptablesAnnotation(final AnnotationNode annotation, final ClassNode classNode,
+            final JSONObject descriptor) throws JSONException {
+        final Iterator<?> it = annotation.values.iterator();
+        while (it.hasNext()) {
+            Object name = it.next();
+            Object value = it.next();
+            if ("value".equals(name)) {
+                @SuppressWarnings("unchecked")
+                final List<AnnotationNode> annotations = (List<AnnotationNode>) value;
+                for (final AnnotationNode innerAnnotation : annotations) {
+                    if (ADAPTABLE_DESC.equals(innerAnnotation.desc)) {
+                        parseAdaptableAnnotation(innerAnnotation, classNode, descriptor);
+                    }
+                }
+            }
+        }
+    }
+
     @SuppressWarnings("unchecked")
     private void parseAdaptableAnnotation(final AnnotationNode annotation, final ClassNode annotatedClass,
             final JSONObject descriptor) throws JSONException {
         String adaptableClassName = null;
         List<AnnotationNode> adapters = null;
+        String servicePid = null;
 
         final List<?> values = annotation.values;