You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2007/11/13 22:35:02 UTC

svn commit: r594649 - in /felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin: Constants.java SCRDescriptorMojo.java om/Component.java

Author: fmeschbe
Date: Tue Nov 13 13:35:01 2007
New Revision: 594649

URL: http://svn.apache.org/viewvc?rev=594649&view=rev
Log:
FELIX-419 Implementing new ds attribute for @scr.component JavaDoc tag allowing to prevent
generation (and validation) of Declarative Services Descriptor for a class and thus only
generate the MetaType service descriptor

Modified:
    felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java
    felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
    felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java

Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java?rev=594649&r1=594648&r2=594649&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java (original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java Tue Nov 13 13:35:01 2007
@@ -45,6 +45,8 @@
 
     public static final String COMPONENT_ABSTRACT = "abstract";
 
+    public static final String COMPONENT_DS = "ds";
+
     public static final String COMPONENT_CREATE_PID = "create-pid";
 
     public static final String PROPERTY = "scr.property";

Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java?rev=594649&r1=594648&r2=594649&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java (original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java Tue Nov 13 13:35:01 2007
@@ -126,7 +126,9 @@
                 this.getLog().debug("Processing service class " + javaSources[i].getName());
                 final Component comp = this.createComponent(javaSources[i], tag, metaData);
                 if (comp != null) {
-                    if ( comp.isAbstract() ) {
+                    if ( !comp.isDs() ) {
+                        getLog().debug("Not adding descriptor " + comp);
+                    } else if ( comp.isAbstract() ) {
                         this.getLog().debug("Adding abstract descriptor " + comp);
                         abstractComponents.addComponent(comp);
                     } else {
@@ -144,6 +146,26 @@
             throw new MojoFailureException("SCR Descriptor parsing had failures (see log)");
         }
 
+        // write meta type info if there is a file
+        if (!StringUtils.isEmpty(this.metaTypeName)) {
+
+            File mtFile = new File(this.outputDirectory, "OSGI-INF" + File.separator + "metatype" + File.separator + this.metaTypeName);
+            if ( metaData.getDescriptors().size() > 0 ) {
+                this.getLog().info("Generating "
+                    + metaData.getDescriptors().size()
+                    + " MetaType Descriptors to " + mtFile);
+                mtFile.getParentFile().mkdirs();
+                MetaTypeIO.write(metaData, mtFile);
+            } else {
+                if ( mtFile.exists() ) {
+                    mtFile.delete();
+                }
+            }
+
+        } else {
+            this.getLog().info("Have no meta type file name, not writing metatype info");
+        }
+
         // if we have abstract descriptors, write them
         final File adFile = new File(this.outputDirectory, Constants.ABSTRACT_DESCRIPTOR_RELATIVE_PATH);
         if ( !abstractComponents.getComponents().isEmpty() ) {
@@ -180,22 +202,6 @@
 
         ComponentDescriptorIO.write(components, descriptorFile);
 
-        // check file name
-        if (StringUtils.isEmpty(this.metaTypeName)) {
-            this.getLog().error("Meta type file name must not be empty.");
-            return;
-        }
-
-        // create metatype information
-        File mtFile = new File(this.outputDirectory, "OSGI-INF" + File.separator + "metatype" + File.separator + this.metaTypeName);
-        if ( metaData.getDescriptors().size() > 0 ) {
-            mtFile.getParentFile().mkdirs();
-            MetaTypeIO.write(metaData, mtFile);
-        } else {
-            if ( mtFile.exists() ) {
-                mtFile.delete();
-            }
-        }
 
         // now add the descriptor file to the maven resources
         final String ourRsrcPath = this.outputDirectory.getAbsolutePath();
@@ -315,6 +321,7 @@
                 pid.setValue(component.getName());
             }
         }
+
         final List issues = new ArrayList();
         final List warnings = new ArrayList();
         component.validate(issues, warnings);
@@ -343,6 +350,10 @@
         // check if this is an abstract definition
         final String abstractType = tag.getNamedParameter(Constants.COMPONENT_ABSTRACT);
         component.setAbstract((abstractType == null ? false : "yes".equalsIgnoreCase(abstractType) || "true".equalsIgnoreCase(abstractType)));
+
+        // check if this is a definition to ignore
+        final String ds = tag.getNamedParameter(Constants.COMPONENT_DS);
+        component.setDs((ds == null) ? true : ("yes".equalsIgnoreCase(ds) || "true".equalsIgnoreCase(ds)));
 
         String name = tag.getNamedParameter(Constants.COMPONENT_NAME);
         component.setName(StringUtils.isEmpty(name) ? component.getImplementation().getClassame() : name);

Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java?rev=594649&r1=594648&r2=594649&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java (original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java Tue Nov 13 13:35:01 2007
@@ -62,6 +62,9 @@
     /** Is this an abstract description? */
     protected boolean isAbstract;
 
+    /** Is this a descriptor to be ignored ? */
+    protected boolean isDs;
+
     /**
      * Default constructor.
      */
@@ -169,6 +172,14 @@
         this.isAbstract = isAbstract;
     }
 
+    public boolean isDs() {
+        return isDs;
+    }
+
+    public void setDs(boolean isDs) {
+        this.isDs = isDs;
+    }
+
     /**
      * Validate the component description.
      * If errors occur a message is added to the issues list,
@@ -176,6 +187,12 @@
      */
     public void validate(List issues, List warnings)
     throws MojoExecutionException {
+
+        // nothing to check if this is ignored
+        if (!isDs()) {
+            return;
+        }
+
         final JavaClassDescription javaClass = this.tag.getJavaClassDescription();
         if (javaClass == null) {
             issues.add(this.getMessage("Tag not declared in a Java Class"));