Return-Path: X-Original-To: apmail-felix-commits-archive@www.apache.org Delivered-To: apmail-felix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ED8CA9155 for ; Tue, 22 May 2012 06:04:50 +0000 (UTC) Received: (qmail 34746 invoked by uid 500); 22 May 2012 06:04:50 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 34537 invoked by uid 500); 22 May 2012 06:04:49 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 34406 invoked by uid 99); 22 May 2012 06:04:44 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 May 2012 06:04:44 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 May 2012 06:04:39 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 84BE1238890B for ; Tue, 22 May 2012 06:04:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1341309 [1/2] - in /felix/sandbox/cziegeler/scrplugin/generator: ./ src/main/java/org/apache/felix/scrplugin/ src/main/java/org/apache/felix/scrplugin/helper/ src/main/java/org/apache/felix/scrplugin/om/ src/main/java/org/apache/felix/scrp... Date: Tue, 22 May 2012 06:04:18 -0000 To: commits@felix.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120522060419.84BE1238890B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cziegeler Date: Tue May 22 06:04:18 2012 New Revision: 1341309 URL: http://svn.apache.org/viewvc?rev=1341309&view=rev Log: New scr plugin Modified: felix/sandbox/cziegeler/scrplugin/generator/pom.xml felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ClassScanner.java felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/IssueLog.java felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/AbstractObject.java felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Implementation.java felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Interface.java felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Property.java felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Service.java felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java Modified: felix/sandbox/cziegeler/scrplugin/generator/pom.xml URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/pom.xml?rev=1341309&r1=1341308&r2=1341309&view=diff ============================================================================== --- felix/sandbox/cziegeler/scrplugin/generator/pom.xml (original) +++ felix/sandbox/cziegeler/scrplugin/generator/pom.xml Tue May 22 06:04:18 2012 @@ -52,6 +52,11 @@ 3.1 compile + + org.osgi + org.osgi.core + 4.2.0 + Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java?rev=1341309&r1=1341308&r2=1341309&view=diff ============================================================================== --- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java (original) +++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java Tue May 22 06:04:18 2012 @@ -18,13 +18,25 @@ */ package org.apache.felix.scrplugin; - import java.io.File; +import java.util.ArrayList; +import java.util.List; +import org.apache.felix.scrplugin.description.ClassDescription; +import org.apache.felix.scrplugin.description.ComponentDescription; +import org.apache.felix.scrplugin.description.SpecVersion; import org.apache.felix.scrplugin.helper.AnnotationProcessorManager; import org.apache.felix.scrplugin.helper.ClassScanner; import org.apache.felix.scrplugin.helper.IssueLog; - +import org.apache.felix.scrplugin.helper.StringUtils; +import org.apache.felix.scrplugin.om.Component; +import org.apache.felix.scrplugin.om.Components; +import org.apache.felix.scrplugin.om.Context; +import org.apache.felix.scrplugin.om.Implementation; +import org.apache.felix.scrplugin.om.Reference; +import org.apache.felix.scrplugin.om.metatype.MetaData; +import org.apache.felix.scrplugin.xml.ComponentDescriptorIO; +import org.apache.felix.scrplugin.xml.MetaTypeIO; /** * The SCRDescriptorGenerator class does the hard work of @@ -32,10 +44,8 @@ import org.apache.felix.scrplugin.helper * configured by clients and the {@link #execute()} method called to generate * the descriptor files. *

- * When using this class carefully consider calling all setter methods - * to properly configure the generator. All setter method document, which - * default value is assumed for the respective property if the setter is - * not called. + * When using this class carefully consider calling all setter methods to properly configure the generator. All setter + * method document, which default value is assumed for the respective property if the setter is not called. *

* Instances of this class are not thread save and should not be reused. */ @@ -56,16 +66,15 @@ public class SCRDescriptorGenerator { private Options options = new Options(); /** - * Create an instance of this generator using the given {@link Log} - * instance of logging. + * Create an instance of this generator using the given {@link Log} instance + * of logging. */ - public SCRDescriptorGenerator(final Log logger ) { + public SCRDescriptorGenerator(final Log logger) { this.logger = logger; } /** - * Set the project. - * This is required. + * Set the project. This is required. */ public void setProject(final Project p) { this.project = p; @@ -81,295 +90,263 @@ public class SCRDescriptorGenerator { /** * Sets the directory where the descriptor files will be created. *

- * This field has no default value and this setter must called prior - * to calling {@link #execute()}. + * This field has no default value and this setter must called prior to calling {@link #execute()}. */ - public void setOutputDirectory( final File outputDirectory ) { + public void setOutputDirectory(final File outputDirectory) { this.outputDirectory = outputDirectory; } /** * Sets the name of the SCR declaration descriptor file. This file will be - * created in the OSGI-INF directory below the - * {@link #setOutputDirectory(File) output directory}. + * created in the OSGI-INF directory below the {@link #setOutputDirectory(File) output directory}. *

- * This file will be overwritten if already existing. If no descriptors - * are created the file is actually removed. + * This file will be overwritten if already existing. If no descriptors are created the file is actually removed. *

* The default value of this property is serviceComponents.xml. */ - public void setFinalName( final String finalName ) { + public void setFinalName(final String finalName) { this.finalName = finalName; } /** * Sets the name of the file taking the Metatype Service descriptors. This - * file will be created in the OSGI-INF/metatype directory below the - * {@link #setOutputDirectory(File) output directory}. + * file will be created in the OSGI-INF/metatype directory below the {@link #setOutputDirectory(File) output directory} + * . *

- * This file will be overwritten if already existing. If no descriptors - * are created the file is actually removed. + * This file will be overwritten if already existing. If no descriptors are created the file is actually removed. *

* The default value of this property is metatype.xml. */ - public void setMetaTypeName( final String metaTypeName ) { + public void setMetaTypeName(final String metaTypeName) { this.metaTypeName = metaTypeName; } /** * Actually generates the Declarative Services and Metatype descriptors - * scanning the java sources provided by the - * {@link #setDescriptorManager(JavaClassDescriptorManager) descriptor manager}. - * + * scanning the java sources provided by the {@link #setDescriptorManager(JavaClassDescriptorManager) descriptor + * manager}. + * * @return true if descriptors have been generated. - * + * * @throws SCRDescriptorException * @throws SCRDescriptorFailureException */ - public boolean execute() - throws SCRDescriptorException, SCRDescriptorFailureException { - if ( this.project == null ) { + public boolean execute() throws SCRDescriptorException, SCRDescriptorFailureException { + if (this.project == null) { throw new SCRDescriptorFailureException("Project has not been set!"); } - this.logger.debug( "Starting SCRDescriptorMojo...." ); - this.logger.debug( "..generating accessors: " + this.options.isGenerateAccessors() ); + this.logger.debug("Starting SCRDescriptorMojo...."); + this.logger.debug("..generating accessors: " + this.options.isGenerateAccessors()); // check speck version configuration - if ( this.options.getSpecVersion() == null ) { - this.logger.debug( "..auto detecting spec version" ); + if (this.options.getSpecVersion() == null) { + this.logger.debug("..auto detecting spec version"); } else { - this.logger.debug( "..using spec version " + this.options.getSpecVersion().getName()); + this.logger.debug("..using spec version " + this.options.getSpecVersion().getName()); } // create a log - final IssueLog iLog = new IssueLog( this.options.isStrictMode() ); + final IssueLog iLog = new IssueLog(this.options.isStrictMode()); // create the annotation processor manager final AnnotationProcessor aProcessor = new AnnotationProcessorManager(options.getAnnotationProcessors(), - this.project.getClassLoader()); + this.project.getClassLoader()); // create the class scanner - and start scanning final ClassScanner scanner = new ClassScanner(); - scanner.execute(logger, project, aProcessor); - return true; - /* + final List scannedDescriptions = scanner.execute(logger, project, aProcessor); + final MetaData metaData = new MetaData(); - metaData.setLocalization( MetaTypeService.METATYPE_DOCUMENTS_LOCATION + "/metatype" ); + // metaData.setLocalization(MetaTypeService.METATYPE_DOCUMENTS_LOCATION + // + "/metatype"); - // iterate through all source classes and check for component tag - final JavaClassDescription[] javaSources = descriptorManager.getSourceDescriptions(); - Arrays.sort( javaSources, new JavaClassDescriptionInheritanceComparator() ); - - final List scannedComponents = new ArrayList(); - for ( int i = 0; i < javaSources.length; i++ ) - { - this.logger.debug( "Testing source " + javaSources[i].getName() ); - final JavaTag tag = javaSources[i].getTagByName( Constants.COMPONENT ); - if ( tag != null ) - { - // FELIX-2853 : Deprecate javadoc tags. - // This is not the most clever way of doing this, but it is the least intrusive... - if ( javaSources[i] instanceof QDoxJavaClassDescription - && !(javaSources[i] instanceof AnnotationJavaClassDescription)) { - iLog.addDeprecationWarning("Class " + javaSources[i].getName() + " is using deprecated javadoc tags ", - tag.getSourceLocation(), tag.getLineNumber()); - } - this.logger.debug( "Processing service class " + javaSources[i].getName() ); - // check if there is more than one component tag! - if ( javaSources[i].getTagsByName( Constants.COMPONENT, false ).length > 1 ) - { - iLog.addError( "Class " + javaSources[i].getName() + " has more than one " + Constants.COMPONENT - + " tag." + " Merge the tags to a single tag.", tag.getSourceLocation(), tag.getLineNumber() ); - } - else - { - try { - final Component comp = this.createComponent( javaSources[i], tag, metaData, iLog ); - if ( this.specVersion == null || comp.getSpecVersion().ordinal() > specVersion.ordinal() ) { + SpecVersion specVersion = options.getSpecVersion(); + + final List processedComponents = new ArrayList(); + for (final ClassDescription desc : scannedDescriptions) { + this.logger.debug("Processing component class " + desc.getSource()); + + // check if there is more than one component definition + if (desc.getDescriptions(ComponentDescription.class).size() > 1) { + iLog.addError("Class has more than one component definition." + " Merge the definitions to a single definition.", + desc.getSource()); + } else { + try { + final Component comp = this.createComponent(desc, metaData, iLog); + if (comp.getSpecVersion() != null) { + if (specVersion == null || comp.getSpecVersion().ordinal() > specVersion.ordinal()) { // if a spec version has been configured and a component requires a higher // version, this is considered an error! - if ( this.specVersion != null ) { - iLog.addError( "Component " + comp + " requires spec version " + comp.getSpecVersion().name() - + " but plugin is configured to use version " + this.specVersion, tag - .getSourceLocation(), tag.getLineNumber() ); + if (this.options.getSpecVersion() != null) { + iLog.addError("Component " + comp + " requires spec version " + comp.getSpecVersion().name() + + " but plugin is configured to use version " + this.options.getSpecVersion(), + desc.getSource()); } else { specVersion = comp.getSpecVersion(); } } - scannedComponents.add( comp ); - } catch ( final SCRDescriptorException sde ) { - iLog.addError( sde.getMessage(), sde.getSourceLocation(), sde.getLineNumber() ); } + processedComponents.add(comp); + } catch (final SCRDescriptorException sde) { + iLog.addError(sde.getMessage(), sde.getSourceLocation()); } } } - this.logger.debug( "..generating descriptor for spec version: " + this.specVersion ); + // if spec version is still not set, we're using lowest available + specVersion = SpecVersion.VERSION_1_0; + this.logger.debug("..generating descriptor for spec version: " + specVersion); // now check for abstract components and fill components objects final Components components = new Components(); - final Components abstractComponents = new Components(); - components.setSpecVersion( specVersion ); - abstractComponents.setSpecVersion( specVersion ); + components.setSpecVersion(specVersion); - for ( final Component comp : scannedComponents ) - { + for (final Component comp : processedComponents) { final int errorCount = iLog.getNumberOfErrors(); // before we can validate we should check the references for bind/unbind method // in order to create them if possible - for ( final Reference ref : comp.getReferences() ) - { + for (final Reference ref : comp.getReferences()) { // if this is a field with a single cardinality, // we look for the bind/unbind methods // and create them if they are not availabe - if ( this.generateAccessors && !ref.isLookupStrategy() ) - { - if ( ref.getJavaTag().getField() != null - && comp.getJavaClassDescription() instanceof ModifiableJavaClassDescription ) - { - if ( ref.getCardinality().equals( "0..1" ) || ref.getCardinality().equals( "1..1" ) ) - { - final String bindValue = ref.getBind(); - final String unbindValue = ref.getUnbind(); - final String name = ref.getName(); - final String type = ref.getInterfacename(); - - boolean createBind = false; - boolean createUnbind = false; - // Only create method if no bind name has been specified - if ( bindValue == null && ref.findMethod( specVersion, "bind" ) == null ) - { - // create bind method - createBind = true; - } - if ( unbindValue == null && ref.findMethod( specVersion, "unbind" ) == null ) - { - // create unbind method - createUnbind = true; - } - if ( createBind || createUnbind ) - { - ( ( ModifiableJavaClassDescription ) comp.getJavaClassDescription() ).addMethods( name, - type, createBind, createUnbind ); - } - } - } + if (this.options.isGenerateAccessors() && !ref.isLookupStrategy()) { + /* + * if (ref.getJavaTag().getField() != null + * && comp.getJavaClassDescription() instanceof ModifiableJavaClassDescription) { + * if (ref.getCardinality().equals("0..1") || ref.getCardinality().equals("1..1")) { + * final String bindValue = ref.getBind(); + * final String unbindValue = ref.getUnbind(); + * final String name = ref.getName(); + * final String type = ref.getInterfacename(); + * + * boolean createBind = false; + * boolean createUnbind = false; + * // Only create method if no bind name has been specified + * if (bindValue == null && ref.findMethod(specVersion, "bind") == null) { + * // create bind method + * createBind = true; + * } + * if (unbindValue == null && ref.findMethod(specVersion, "unbind") == null) { + * // create unbind method + * createUnbind = true; + * } + * if (createBind || createUnbind) { + * ((ModifiableJavaClassDescription) comp.getJavaClassDescription()).addMethods(name, type, + * createBind, createUnbind); + * } + * } + * } + */ } } - comp.validate( specVersion, iLog ); + final Context ctx = new Context(); + ctx.setClassDescription(comp.getClassDescription()); + ctx.setIssueLog(iLog); + ctx.setProject(project); + ctx.setSpecVersion(specVersion); + + comp.validate(ctx); + // ignore component if it has errors - if ( iLog.getNumberOfErrors() == errorCount ) - { - if ( !comp.isDs() ) - { - logger.debug( "Ignoring descriptor " + comp ); - } - else if ( comp.isAbstract() ) - { - this.logger.debug( "Adding abstract descriptor " + comp ); - abstractComponents.addComponent( comp ); - } - else - { - this.logger.debug( "Adding descriptor " + comp ); - components.addComponent( comp ); - abstractComponents.addComponent( comp ); + if (iLog.getNumberOfErrors() == errorCount) { + if (!comp.isDs()) { + logger.debug("Ignoring descriptor " + comp); + } else if (!comp.isAbstract()) { + this.logger.debug("Adding descriptor " + comp); + components.addComponent(comp); } } } // log issues - iLog.logMessages( logger ); + iLog.logMessages(logger); // after checking all classes, throw if there were any failures - if ( iLog.hasErrors() ) - { - throw new SCRDescriptorFailureException( "SCR Descriptor parsing had failures (see log)" ); + if (iLog.hasErrors()) { + throw new SCRDescriptorFailureException("SCR Descriptor parsing had failures (see log)"); } boolean addResources = false; // write meta type info if there is a file name - if ( !StringUtils.isEmpty( this.metaTypeName ) ) - { - File mtFile = new File( this.outputDirectory, "OSGI-INF" + File.separator + "metatype" + File.separator - + this.metaTypeName ); + if (!StringUtils.isEmpty(this.metaTypeName)) { + File mtFile = new File(this.outputDirectory, "OSGI-INF" + File.separator + "metatype" + File.separator + + this.metaTypeName); final int size = metaData.getOCDs().size() + metaData.getDesignates().size(); - if ( size > 0 ) - { - this.logger.info( "Generating " + size + " MetaType Descriptors to " + mtFile ); + if (size > 0) { + this.logger.info("Generating " + size + " MetaType Descriptors to " + mtFile); mtFile.getParentFile().mkdirs(); - MetaTypeIO.write( metaData, mtFile ); + MetaTypeIO.write(metaData, mtFile); addResources = true; - } - else - { - if ( mtFile.exists() ) - { + } else { + if (mtFile.exists()) { mtFile.delete(); } } - } - else - { - this.logger.info( "Meta type file name is not set: meta type info is not written." ); - } - - // if we have descriptors, write them in our scr private file (for component inheritance) - final File adFile = new File( this.outputDirectory, Constants.ABSTRACT_DESCRIPTOR_RELATIVE_PATH ); - if ( !abstractComponents.getComponents().isEmpty() ) - { - this.logger.info( "Writing abstract service descriptor " + adFile + " with " - + abstractComponents.getComponents().size() + " entries." ); - adFile.getParentFile().mkdirs(); - ComponentDescriptorIO.write( abstractComponents, adFile, true ); - addResources = true; - } - else - { - this.logger.debug( "No abstract SCR Descriptors found in project." ); - // remove file - if ( adFile.exists() ) - { - this.logger.debug( "Removing obsolete abstract service descriptor " + adFile ); - adFile.delete(); - } + } else { + this.logger.info("Meta type file name is not set: meta type info is not written."); } // check descriptor file - final File descriptorFile = StringUtils.isEmpty( this.finalName ) ? null : new File( new File( - this.outputDirectory, "OSGI-INF" ), this.finalName ); + final File descriptorFile = StringUtils.isEmpty(this.finalName) ? null : new File(new File(this.outputDirectory, + "OSGI-INF"), this.finalName); // terminate if there is nothing else to write - if ( components.getComponents().isEmpty() ) - { - this.logger.debug( "No SCR Descriptors found in project." ); + if (components.getComponents().isEmpty()) { + this.logger.debug("No SCR Descriptors found in project."); // remove file if it exists - if ( descriptorFile != null && descriptorFile.exists() ) - { - this.logger.debug( "Removing obsolete service descriptor " + descriptorFile ); + if (descriptorFile != null && descriptorFile.exists()) { + this.logger.debug("Removing obsolete service descriptor " + descriptorFile); descriptorFile.delete(); } - } - else - { - if ( descriptorFile == null ) - { - throw new SCRDescriptorFailureException( "Descriptor file name must not be empty." ); + } else { + if (descriptorFile == null) { + throw new SCRDescriptorFailureException("Descriptor file name must not be empty."); } // finally the descriptors have to be written .... descriptorFile.getParentFile().mkdirs(); // ensure parent dir - this.logger.info( "Generating " + components.getComponents().size() + " Service Component Descriptors to " - + descriptorFile ); + this.logger.info("Generating " + components.getComponents().size() + " Service Component Descriptors to " + + descriptorFile); - ComponentDescriptorIO.write( components, descriptorFile, false ); + ComponentDescriptorIO.write(components, descriptorFile); addResources = true; } - return addResources;*/ + return addResources; + } + + private Component createComponent(final ClassDescription desc, final MetaData metaData, final IssueLog iLog) + throws SCRDescriptorException { + final ComponentDescription componentDesc = desc.getDescriptions(ComponentDescription.class).get(0); + final Component comp = new Component(desc, desc.getSource(), componentDesc.getAnnotation().getName()); + + comp.setAbstract(componentDesc.isAbstract()); + comp.setDs(componentDesc.isCreateDs()); + comp.setEnabled(componentDesc.getEnabled()); + comp.setImmediate(componentDesc.getImmediate()); + if (componentDesc.getActivate() != null) { + comp.setActivate(componentDesc.getActivate().getName()); + } + if (componentDesc.getConfigurationPolicy() != null) { + comp.setConfigurationPolicy(componentDesc.getConfigurationPolicy().name()); + } + if (componentDesc.getDeactivate() != null) { + comp.setDeactivate(componentDesc.getDeactivate().getName()); + } + comp.setFactory(componentDesc.getFactory()); + if (componentDesc.getModified() != null) { + comp.setModified(componentDesc.getModified().getName()); + } + comp.setName(componentDesc.getName()); + comp.setSpecVersion(componentDesc.getSpecVersion()); + + final Implementation impl = new Implementation(desc.getDescribedClass().getName()); + comp.setImplementation(impl); + + return comp; } } Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ClassScanner.java URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ClassScanner.java?rev=1341309&r1=1341308&r2=1341309&view=diff ============================================================================== --- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ClassScanner.java (original) +++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ClassScanner.java Tue May 22 06:04:18 2012 @@ -53,17 +53,27 @@ import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.FieldNode; import org.objectweb.asm.tree.MethodNode; +/** + * The class scanner scans class files for annotations and invokes + * the {@link AnnotationProcessor} on each scanned class file. + */ public class ClassScanner { /** * Scan all class files for annotations and process them. + * + * @param log + * The log to use + * @param project + * The project environment + * @param aProcessor + * The annotation processor */ - public void execute(final Log log, - final Project project, - final AnnotationProcessor aProcessor) - throws SCRDescriptorException, SCRDescriptorFailureException { + public List execute(final Log log, final Project project, final AnnotationProcessor aProcessor) + throws SCRDescriptorException, SCRDescriptorFailureException { + final List result = new ArrayList(); - for(final Source src : project.getSources()) { + for (final Source src : project.getSources()) { log.debug("Scanning class " + src.getClassName()); try { @@ -83,12 +93,14 @@ public class ClassScanner { // create descriptions final List descriptions = extractAnnotation(classNode, annotatedClass); - if ( descriptions.size() > 0 ) { + if (descriptions.size() > 0) { // process descriptions final ClassDescription desc = new ClassDescription(annotatedClass, src.getFile().toString()); aProcessor.process(new ScannedClass(descriptions, annotatedClass), desc); - if ( desc.getDescriptions(ComponentDescription.class).size() > 0 ) { - log.info("Found " + desc); + + if (desc.getDescriptions(ComponentDescription.class).size() > 0) { + log.debug("Found component description " + desc + " in " + src.getClassName()); + result.add(desc); } } } catch (final ClassNotFoundException cnfe) { @@ -97,17 +109,19 @@ public class ClassScanner { throw new SCRDescriptorFailureException("Unable to scan class files: " + src.getClassName(), ioe); } } + return result; } /** * Extract annotations */ - private final List extractAnnotation(final ClassNode classNode, final Class annotatedClass) { + private final List extractAnnotation(final ClassNode classNode, final Class annotatedClass) + throws SCRDescriptorException { final List descriptions = new ArrayList(); // first parse class annotations @SuppressWarnings("unchecked") final List annotations = classNode.invisibleAnnotations; - if ( annotations != null ) { + if (annotations != null) { for (final AnnotationNode annotation : annotations) { this.parseAnnotation(descriptions, annotation, annotatedClass); } @@ -115,20 +129,50 @@ public class ClassScanner { // second parse method annotations @SuppressWarnings("unchecked") final List methods = classNode.methods; - if ( methods != null ) { - for(final MethodNode method : methods) { + if (methods != null) { + for (final MethodNode method : methods) { @SuppressWarnings("unchecked") final List annos = method.invisibleAnnotations; - if ( annos != null ) { - // TODO - check signature and throw if not found! + if (annos != null) { final String name = method.name; + String signature = method.signature; + if (signature != null) { + // remove generics + int pos; + while ((pos = signature.indexOf('<')) > 0) { + final int lastPos = signature.indexOf('>'); + signature = signature.substring(0, pos) + signature.substring(lastPos + 1); + } + // remove everthing after the brackets and replace slash with dot + pos = signature.lastIndexOf(')'); + signature = signature.substring(0, pos + 1); + signature = signature.replace('/', '.'); + } final Method[] allMethods = annotatedClass.getDeclaredMethods(); Method found = null; - for(final Method m : allMethods) { - if ( m.getName().equals(name) ) { - found = m; + for (final Method m : allMethods) { + if (m.getName().equals(name)) { + if (m.getParameterTypes().length == 0 && signature == null) { + found = m; + } + if (m.getParameterTypes().length > 0 && signature != null) { + final StringBuilder sb = new StringBuilder("("); + for (final Class c : m.getParameterTypes()) { + sb.append("L"); + sb.append(c.getName()); + sb.append(";"); + } + sb.append(")"); + if (sb.toString().equals(signature)) { + found = m; + } + } } } + if (found == null) { + throw new SCRDescriptorException("Annotated method " + name + " not found.", + annotatedClass.getName(), -1); + } for (final AnnotationNode annotation : annos) { parseAnnotation(descriptions, annotation, found); } @@ -139,17 +183,17 @@ public class ClassScanner { // third parse field annotations @SuppressWarnings("unchecked") final List fields = classNode.fields; - if ( fields != null ) { - for(final FieldNode field : fields) { + if (fields != null) { + for (final FieldNode field : fields) { @SuppressWarnings("unchecked") final List annos = field.invisibleAnnotations; - if ( annos != null ) { + if (annos != null) { // TODO - throw if not found final String name = field.name; final Field[] allFields = annotatedClass.getDeclaredFields(); Field found = null; - for(final Field f : allFields) { - if ( f.getName().equals(name) ) { + for (final Field f : allFields) { + if (f.getName().equals(name)) { found = f; } } @@ -172,41 +216,40 @@ public class ClassScanner { /** * Parse annotation and create a description. */ - private void parseAnnotation(final List descriptions, - final AnnotationNode annotation, - final Object annotatedObject) { + private void parseAnnotation(final List descriptions, final AnnotationNode annotation, + final Object annotatedObject) { // desc has the format 'L' + className.replace('.', '/') + ';' final String name = annotation.desc.substring(1, annotation.desc.length() - 1).replace('/', '.'); Map values = null; - if ( annotation.values != null ) { + if (annotation.values != null) { values = new HashMap(); final Iterator i = annotation.values.iterator(); - while ( i.hasNext() ) { + while (i.hasNext()) { final Object vName = i.next(); Object value = i.next(); // convert type to class name string - if ( value instanceof Type ) { - value = ((Type)value).getClassName(); - } else if ( value instanceof List ) { - final List objects = (List)value; - if ( objects.size() > 0 ) { - if ( objects.get(0) instanceof Type ) { + if (value instanceof Type) { + value = ((Type) value).getClassName(); + } else if (value instanceof List) { + final List objects = (List) value; + if (objects.size() > 0) { + if (objects.get(0) instanceof Type) { final String[] classNames = new String[objects.size()]; int index = 0; - for(final Object v : objects) { - classNames[index] = ((Type)v).getClassName(); + for (final Object v : objects) { + classNames[index] = ((Type) v).getClassName(); index++; } value = classNames; - } else if ( objects.get(0) instanceof AnnotationNode ) { + } else if (objects.get(0) instanceof AnnotationNode) { final List innerDesc = new ArrayList(); - for(final Object v : objects) { - parseAnnotation(innerDesc, (AnnotationNode)v, annotatedObject); + for (final Object v : objects) { + parseAnnotation(innerDesc, (AnnotationNode) v, annotatedObject); } - if ( annotatedObject instanceof Method ) { + if (annotatedObject instanceof Method) { value = innerDesc.toArray(new MethodAnnotation[innerDesc.size()]); - } else if ( annotatedObject instanceof Field ) { + } else if (annotatedObject instanceof Field) { value = innerDesc.toArray(new FieldAnnotation[innerDesc.size()]); } else { value = innerDesc.toArray(new ClassAnnotation[innerDesc.size()]); @@ -224,10 +267,10 @@ public class ClassScanner { } final ScannedAnnotation a; - if ( annotatedObject instanceof Method ) { + if (annotatedObject instanceof Method) { a = new MethodAnnotation(name, values, (Method) annotatedObject); ((Method) annotatedObject).setAccessible(true); - } else if ( annotatedObject instanceof Field ) { + } else if (annotatedObject instanceof Field) { a = new FieldAnnotation(name, values, (Field) annotatedObject); ((Field) annotatedObject).setAccessible(true); } else { Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/IssueLog.java URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/IssueLog.java?rev=1341309&r1=1341308&r2=1341309&view=diff ============================================================================== --- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/IssueLog.java (original) +++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/IssueLog.java Tue May 22 06:04:18 2012 @@ -18,7 +18,9 @@ */ package org.apache.felix.scrplugin.helper; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import org.apache.felix.scrplugin.Log; @@ -44,86 +46,72 @@ public class IssueLog { } public boolean hasErrors() { - return errors.size() > 0 || - (this.strictMode && (warnings.size() > 0 || this.deprecationWarnings.size() > 0)); + return errors.size() > 0 || (this.strictMode && (warnings.size() > 0 || this.deprecationWarnings.size() > 0)); } - public void addError(final String message, final String location, final int lineNumber) { - errors.add( new Entry( message, location, lineNumber ) ); + public void addError(final String message, final String location) { + errors.add(new Entry(message, location)); } - public void addWarning(final String message, final String location, final int lineNumber) { - warnings.add( new Entry( message, location, lineNumber ) ); + public void addWarning(final String message, final String location) { + warnings.add(new Entry(message, location)); } - public void addDeprecationWarning(final String message, final String location, final int lineNumber) { - deprecationWarnings.add( new Entry( message, location, lineNumber ) ); + public void addDeprecationWarning(final String message, final String location) { + deprecationWarnings.add(new Entry(message, location)); } - public void logMessages( final Log log ) - { + public void logMessages(final Log log) { // now log warnings and errors (warnings first) // in strict mode everything is an error! final Iterator depWarnings = this.deprecationWarnings.iterator(); - while ( depWarnings.hasNext() ) - { + while (depWarnings.hasNext()) { final Entry entry = depWarnings.next(); - if ( strictMode ) - { - log.error( entry.message, entry.location, entry.lineNumber); - } - else - { - log.warn( entry.message, entry.location, entry.lineNumber); + if (strictMode) { + log.error(entry.toString()); + } else { + log.warn(entry.toString()); } } - if ( this.deprecationWarnings.size() > 0 ) { - final String msg = "It is highly recommended to fix these problems, as future versions might not " + - "support these features anymore."; - if ( strictMode ) - { - log.error( msg ); - } - else - { - log.warn( msg ); + if (this.deprecationWarnings.size() > 0) { + final String msg = "It is highly recommended to fix these problems, as future versions might not " + + "support these features anymore."; + if (strictMode) { + log.error(msg); + } else { + log.warn(msg); } } final Iterator warnings = this.warnings.iterator(); - while ( warnings.hasNext() ) - { + while (warnings.hasNext()) { final Entry entry = warnings.next(); - if ( strictMode ) - { - log.error( entry.message, entry.location, entry.lineNumber); - } - else - { - log.warn( entry.message, entry.location, entry.lineNumber); + if (strictMode) { + log.error(entry.toString()); + } else { + log.warn(entry.toString()); } } final Iterator errors = this.errors.iterator(); - while ( errors.hasNext() ) - { + while (errors.hasNext()) { final Entry entry = errors.next(); - log.error( entry.message, entry.location, entry.lineNumber); + log.error(entry.toString()); } } - private static class Entry - { + private static class Entry { final String message; final String location; - final int lineNumber; - - Entry( final String message, final String location, final int lineNumber ) - { + Entry(final String message, final String location) { this.message = message; this.location = location; - this.lineNumber = lineNumber; + } + + @Override + public String toString() { + return this.location + " : " + this.message; } } } Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/AbstractObject.java URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/AbstractObject.java?rev=1341309&r1=1341308&r2=1341309&view=diff ============================================================================== --- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/AbstractObject.java (original) +++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/AbstractObject.java Tue May 22 06:04:18 2012 @@ -21,8 +21,7 @@ package org.apache.felix.scrplugin.om; import org.apache.felix.scrplugin.helper.IssueLog; /** - * The AbstractObject - * is the base class for the all classes of the scr om. + * The AbstractObject is the base class for the all classes of the scr om. */ public abstract class AbstractObject { @@ -30,19 +29,16 @@ public abstract class AbstractObject { private final String sourceLocation; - private final int lineNumber; - - protected AbstractObject(final String annotationName, final String sourceLocation, final int lineNumber) { + protected AbstractObject(final String annotationName, final String sourceLocation) { this.annotationName = annotationName; this.sourceLocation = sourceLocation; - this.lineNumber = lineNumber; } protected void logWarn(IssueLog iLog, String message) { - iLog.addWarning( "@" + this.annotationName + ": " + message, sourceLocation, lineNumber ); + iLog.addWarning("@" + this.annotationName + ": " + message, sourceLocation); } protected void logError(IssueLog iLog, String message) { - iLog.addError( "@" + this.annotationName + ": " + message, sourceLocation, lineNumber ); + iLog.addError("@" + this.annotationName + ": " + message, sourceLocation); } } Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java?rev=1341309&r1=1341308&r2=1341309&view=diff ============================================================================== --- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java (original) +++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java Tue May 22 06:04:18 2012 @@ -24,12 +24,12 @@ import java.util.List; import org.apache.felix.scrplugin.Constants; import org.apache.felix.scrplugin.SCRDescriptorException; -import org.apache.felix.scrplugin.helper.IssueLog; +import org.apache.felix.scrplugin.description.ClassDescription; +import org.apache.felix.scrplugin.description.SpecVersion; /** - * Component - * is a described component. - * + * Component is a described component. + * */ public class Component extends AbstractObject { @@ -76,35 +76,42 @@ public class Component extends AbstractO protected String modified; /** The spec version. */ - protected int specVersion; + protected SpecVersion specVersion; + + private final ClassDescription classDescription; /** * Default constructor. */ public Component() { - this(null, null, -1); + this(null, null, null); } /** * Constructor from java source. */ - public Component(final String annotationName, final String sourceLocation, final int lineNumber) { - super(annotationName, sourceLocation, lineNumber); + public Component(final ClassDescription cDesc, final String annotationName, final String sourceLocation) { + super(annotationName, sourceLocation); + this.classDescription = cDesc; + } + + public ClassDescription getClassDescription() { + return this.classDescription; } /** * Get the spec version. */ - public int getSpecVersion() { + public SpecVersion getSpecVersion() { return this.specVersion; } /** * Set the spec version. */ - public void setSpecVersion(int value) { + public void setSpecVersion(final SpecVersion value) { // only set a higher version, never "downgrade" - if (this.specVersion < value) { + if (this.specVersion == null || this.specVersion.ordinal() < value.ordinal()) { this.specVersion = value; } } @@ -243,12 +250,10 @@ public class Component extends AbstractO } /** - * Validate the component description. - * If errors occur a message is added to the issues list, - * warnings can be added to the warnings list. + * Validate the component description. If errors occur a message is added to + * the issues list, warnings can be added to the warnings list. */ - public void validate(final Context context) - throws SCRDescriptorException { + public void validate(final Context context) throws SCRDescriptorException { // nothing to check if this is ignored if (!isDs()) { return; @@ -257,88 +262,98 @@ public class Component extends AbstractO final int currentIssueCount = context.getIssueLog().getNumberOfErrors(); // if the service is abstract, we do not validate everything - if ( !this.isAbstract ) { + if (!this.isAbstract) { // ensure non-abstract, public class - if (!Modifier.isPublic(context.getClassDescription().getDescribedClass().getModifiers()) ) { - this.logError( context.getIssueLog(), "Class must be public: " + context.getClassDescription().getDescribedClass().getName() ); + if (!Modifier.isPublic(context.getClassDescription().getDescribedClass().getModifiers())) { + this.logError(context.getIssueLog(), "Class must be public: " + + context.getClassDescription().getDescribedClass().getName()); } - if (Modifier.isAbstract(context.getClassDescription().getDescribedClass().getModifiers()) || context.getClassDescription().getDescribedClass().isInterface()) { - this.logError( context.getIssueLog(), "Class must be concrete class (not abstract or interface) : " + context.getClassDescription().getDescribedClass().getName() ); + if (Modifier.isAbstract(context.getClassDescription().getDescribedClass().getModifiers()) + || context.getClassDescription().getDescribedClass().isInterface()) { + this.logError(context.getIssueLog(), "Class must be concrete class (not abstract or interface) : " + + context.getClassDescription().getDescribedClass().getName()); } // no errors so far, let's continue - if ( context.getIssueLog().getNumberOfErrors() == currentIssueCount ) { - final String activateName = this.activate == null ? "activate" : this.activate; - final String deactivateName = this.deactivate == null ? "deactivate" : this.deactivate; - - // check activate and deactivate methods - this.checkLifecycleMethod(specVersion, javaClass, activateName, true, iLog); - this.checkLifecycleMethod(specVersion, javaClass, deactivateName, false, iLog); - - if ( this.modified != null && specVersion >= Constants.VERSION_1_1 ) { - this.checkLifecycleMethod(specVersion, javaClass, this.modified, true, iLog); - } - // ensure public default constructor - boolean constructorFound = true; - JavaMethod[] methods = javaClass.getMethods(); - for (int i = 0; methods != null && i < methods.length; i++) { - if (methods[i].isConstructor()) { - // if public default, succeed - if (methods[i].isPublic() - && (methods[i].getParameters() == null || methods[i].getParameters().length == 0)) { - constructorFound = true; - break; - } - - // non-public/non-default constructor found, must have explicit - constructorFound = false; - } - } - if (!constructorFound) { - this.logError( context.getIssueLog(), "Class must have public default constructor: " + javaClass.getName() ); - } - - // verify properties - for(final Property prop : this.getProperties()) { - prop.validate(specVersion, context.getIssueLog()); - } - - // verify service - boolean isServiceFactory = false; - if (this.getService() != null) { - if ( this.getService().getInterfaces().size() == 0 ) { - this.logError( context.getIssueLog(), "Service interface information is missing!" ); - } - this.getService().validate(context); - isServiceFactory = this.getService().isServicefactory(); - } - - // serviceFactory must not be true for immediate of component factory - if (isServiceFactory && this.isImmediate() != null && this.isImmediate().booleanValue() && this.getFactory() != null) { - this.logError( context.getIssueLog(), "Component must not be a ServiceFactory, if immediate and/or component factory: " + javaClass.getName() ); - } - - // immediate must not be true for component factory - if (this.isImmediate() != null && this.isImmediate().booleanValue() && this.getFactory() != null) { - this.logError( context.getIssueLog(), "Component must not be immediate if component factory: " + javaClass.getName() ); - } - } + /* + * if (context.getIssueLog().getNumberOfErrors() == currentIssueCount) { + * final String activateName = this.activate == null ? "activate" : this.activate; + * final String deactivateName = this.deactivate == null ? "deactivate" : this.deactivate; + * + * // check activate and deactivate methods + * this.checkLifecycleMethod(specVersion, javaClass, activateName, true, iLog); + * this.checkLifecycleMethod(specVersion, javaClass, deactivateName, false, iLog); + * + * if (this.modified != null && specVersion >= Constants.VERSION_1_1) { + * this.checkLifecycleMethod(specVersion, javaClass, this.modified, true, iLog); + * } + * // ensure public default constructor + * boolean constructorFound = true; + * JavaMethod[] methods = javaClass.getMethods(); + * for (int i = 0; methods != null && i < methods.length; i++) { + * if (methods[i].isConstructor()) { + * // if public default, succeed + * if (methods[i].isPublic() + * && (methods[i].getParameters() == null || methods[i].getParameters().length == 0)) { + * constructorFound = true; + * break; + * } + * + * // non-public/non-default constructor found, must have + * // explicit + * constructorFound = false; + * } + * } + * if (!constructorFound) { + * this.logError(context.getIssueLog(), "Class must have public default constructor: " + javaClass.getName()); + * } + * + * // verify properties + * for (final Property prop : this.getProperties()) { + * prop.validate(specVersion, context.getIssueLog()); + * } + * + * // verify service + * boolean isServiceFactory = false; + * if (this.getService() != null) { + * if (this.getService().getInterfaces().size() == 0) { + * this.logError(context.getIssueLog(), "Service interface information is missing!"); + * } + * this.getService().validate(context); + * isServiceFactory = this.getService().isServicefactory(); + * } + * + * // serviceFactory must not be true for immediate of component + * // factory + * if (isServiceFactory && this.isImmediate() != null && this.isImmediate().booleanValue() + * && this.getFactory() != null) { + * this.logError(context.getIssueLog(), + * "Component must not be a ServiceFactory, if immediate and/or component factory: " + * + javaClass.getName()); + * } + * + * // immediate must not be true for component factory + * if (this.isImmediate() != null && this.isImmediate().booleanValue() && this.getFactory() != null) { + * this.logError(context.getIssueLog(), + * "Component must not be immediate if component factory: " + javaClass.getName()); + * } + * } + */ } - if ( context.getIssueLog().getNumberOfErrors() == currentIssueCount ) { + if (context.getIssueLog().getNumberOfErrors() == currentIssueCount) { // verify references - for(final Reference ref : this.getReferences()) { + for (final Reference ref : this.getReferences()) { ref.validate(context, this.isAbstract); } } // check additional stuff if version is 1.1 - if ( specVersion >= Constants.VERSION_1_1 ) { + if (specVersion != null && specVersion.ordinal() >= SpecVersion.VERSION_1_1.ordinal()) { final String cp = this.getConfigurationPolicy(); - if ( cp != null - && !Constants.COMPONENT_CONFIG_POLICY_IGNORE.equals(cp) - && !Constants.COMPONENT_CONFIG_POLICY_REQUIRE.equals(cp) - && !Constants.COMPONENT_CONFIG_POLICY_OPTIONAL.equals(cp) ) { - this.logError( iLog, "Component has an unknown value for configuration policy: " + cp ); + if (cp != null && !Constants.COMPONENT_CONFIG_POLICY_IGNORE.equals(cp) + && !Constants.COMPONENT_CONFIG_POLICY_REQUIRE.equals(cp) + && !Constants.COMPONENT_CONFIG_POLICY_OPTIONAL.equals(cp)) { + this.logError(context.getIssueLog(), "Component has an unknown value for configuration policy: " + cp); } } @@ -352,110 +367,118 @@ public class Component extends AbstractO /** * Check for existence of lifecycle methods. - * @param specVersion The spec version - * @param javaClass The java class to inspect. - * @param methodName The method name. - * @param warnings The list of warnings used to add new warnings. - */ - protected void checkLifecycleMethod(final int specVersion, - final JavaClassDescription javaClass, - final String methodName, - final boolean isActivate, - final IssueLog iLog) - throws SCRDescriptorException { - // first candidate is (de)activate(ComponentContext) - JavaMethod method = javaClass.getMethodBySignature(methodName, new String[] {TYPE_COMPONENT_CONTEXT}); - if ( method == null ) { - if ( specVersion >= Constants.VERSION_1_1) { - // second candidate is (de)activate(BundleContext) - method = javaClass.getMethodBySignature(methodName, new String[] {TYPE_BUNDLE_CONTEXT}); - if ( method == null ) { - // third candidate is (de)activate(Map) - method = javaClass.getMethodBySignature(methodName, new String[] {TYPE_MAP}); - - if ( method == null ) { - // if this is a deactivate method, we have two additional possibilities - // a method with parameter of type int and one of type Integer - if ( !isActivate ) { - method = javaClass.getMethodBySignature(methodName, new String[] {TYPE_INT}); - if ( method == null ) { - method = javaClass.getMethodBySignature(methodName, new String[] {TYPE_INTEGER}); - } - } - - // fourth candidate is (de)activate with two or three arguments (type must be BundleContext, ComponentCtx and Map) - // as we have to iterate now and the fifth candidate is zero arguments - // we already store this option - JavaMethod zeroArgMethod = null; - JavaMethod found = method; - final JavaMethod[] methods = javaClass.getMethods(); - int i = 0; - while ( i < methods.length ) { - if ( methodName.equals(methods[i].getName()) ) { - - if ( methods[i].getParameters().length == 0 ) { - zeroArgMethod = methods[i]; - } else if ( methods[i].getParameters().length >= 2 ) { - boolean valid = true; - for(int m=0; m= Constants.VERSION_1_1) { + * // second candidate is (de)activate(BundleContext) + * method = javaClass.getMethodBySignature(methodName, new String[] { TYPE_BUNDLE_CONTEXT }); + * if (method == null) { + * // third candidate is (de)activate(Map) + * method = javaClass.getMethodBySignature(methodName, new String[] { TYPE_MAP }); + * + * if (method == null) { + * // if this is a deactivate method, we have two + * // additional possibilities + * // a method with parameter of type int and one of type + * // Integer + * if (!isActivate) { + * method = javaClass.getMethodBySignature(methodName, new String[] { TYPE_INT }); + * if (method == null) { + * method = javaClass.getMethodBySignature(methodName, new String[] { TYPE_INTEGER }); + * } + * } + * + * // fourth candidate is (de)activate with two or three + * // arguments (type must be BundleContext, ComponentCtx + * // and Map) + * // as we have to iterate now and the fifth candidate is + * // zero arguments + * // we already store this option + * JavaMethod zeroArgMethod = null; + * JavaMethod found = method; + * final JavaMethod[] methods = javaClass.getMethods(); + * int i = 0; + * while (i < methods.length) { + * if (methodName.equals(methods[i].getName())) { + * + * if (methods[i].getParameters().length == 0) { + * zeroArgMethod = methods[i]; + * } else if (methods[i].getParameters().length >= 2) { + * boolean valid = true; + * for (int m = 0; m < methods[i].getParameters().length; m++) { + * final String type = methods[i].getParameters()[m].getType(); + * if (!type.equals(TYPE_BUNDLE_CONTEXT) && !type.equals(TYPE_COMPONENT_CONTEXT) + * && !type.equals(TYPE_MAP)) { + * // if this is deactivate, int and + * // integer are possible as well + * if (isActivate || (!type.equals(TYPE_INT) && !type.equals(TYPE_INTEGER))) { + * valid = false; + * } + * } + * } + * if (valid) { + * if (found == null) { + * found = methods[i]; + * } else { + * // print warning + * this.logWarn(iLog, "Lifecycle method " + methods[i].getName() + * + " occurs several times with different matching signature."); + * } + * } + * } + * } + * i++; + * } + * if (found != null) { + * method = found; + * } else { + * method = zeroArgMethod; + * } + * } + * } + * } + * // if no method is found, we check for any method with that name to + * // print some warnings! + * if (method == null) { + * final JavaMethod[] methods = javaClass.getMethods(); + * for (int i = 0; i < methods.length; i++) { + * if (methodName.equals(methods[i].getName())) { + * if (methods[i].getParameters().length != 1) { + * this.logWarn(iLog, "Lifecycle method " + methods[i].getName() + " has wrong number of arguments"); + * } else { + * this.logWarn(iLog, + * "Lifecycle method " + methods[i].getName() + " has wrong argument " + * + methods[i].getParameters()[0].getType()); + * } + * } + * } + * } + * } + * // method must be protected for version 1.0 + * if (method != null && specVersion == Constants.VERSION_1_0) { + * // check protected + * if (method.isPublic()) { + * this.logWarn(iLog, "Lifecycle method " + method.getName() + " should be declared protected"); + * } else if (!method.isProtected()) { + * this.logWarn(iLog, "Lifecycle method " + method.getName() + + * " has wrong qualifier, public or protected required"); + * } + * } + * } + */ /** * Return the configuration policy. @@ -473,21 +496,14 @@ public class Component extends AbstractO @Override public String toString() { - return "Component " + this.name + " (" + - "enabled=" + (enabled==null?"":enabled) + - ", immediate=" + (immediate == null?"":immediate) + - ", abstract=" + isAbstract + - ", isDS=" + isDs + - (factory != null ? ", factory="+factory:"")+ - (configurationPolicy != null ? ", configurationPolicy=" + configurationPolicy : "") + - (activate != null ? ", activate=" + activate : "") + - (deactivate != null ? ", deactivate=" + deactivate : "") + - (modified != null ? ", modified=" + modified : "") + - ", specVersion=" + specVersion + - ", implementation=" + implementation + - ", service=" + service + - ", properties=" + properties + - ", references=" + references + - ")"; + return "Component " + this.name + " (" + "enabled=" + (enabled == null ? "" : enabled) + ", immediate=" + + (immediate == null ? "" : immediate) + ", abstract=" + isAbstract + ", isDS=" + isDs + + (factory != null ? ", factory=" + factory : "") + + (configurationPolicy != null ? ", configurationPolicy=" + configurationPolicy : "") + + (activate != null ? ", activate=" + activate : "") + + (deactivate != null ? ", deactivate=" + deactivate : "") + + (modified != null ? ", modified=" + modified : "") + ", specVersion=" + specVersion + + ", implementation=" + implementation + ", service=" + service + ", properties=" + properties + + ", references=" + references + ")"; } } \ No newline at end of file Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Implementation.java URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Implementation.java?rev=1341309&r1=1341308&r2=1341309&view=diff ============================================================================== --- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Implementation.java (original) +++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Implementation.java Tue May 22 06:04:18 2012 @@ -20,13 +20,13 @@ package org.apache.felix.scrplugin.om; /** * Implementation - * + * * contains the class name implementing the component. */ public class Implementation { /** The class name. */ - private String className; + private final String className; public Implementation(final String name) { this.className = name; @@ -35,8 +35,4 @@ public class Implementation { public String getClassName() { return this.className; } - - public void setClassName(final String name) { - this.className = name; - } } Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Interface.java URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Interface.java?rev=1341309&r1=1341308&r2=1341309&view=diff ============================================================================== --- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Interface.java (original) +++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Interface.java Tue May 22 06:04:18 2012 @@ -22,7 +22,7 @@ import org.apache.felix.scrplugin.SCRDes /** * Interface - * + * * contains an interface name the component is implementing * (the interface name can also be a class name) */ @@ -35,14 +35,14 @@ public class Interface extends AbstractO * Default constructor. */ public Interface() { - this(null, null, -1); + this(null, null); } /** * Constructor from java source. */ - public Interface(final String annotationName, final String sourceLocation, final int lineNumber) { - super(annotationName, sourceLocation, lineNumber); + public Interface(final String annotationName, final String sourceLocation) { + super(annotationName, sourceLocation); } /** @@ -64,16 +64,15 @@ public class Interface extends AbstractO * If errors occur a message is added to the issues list, * warnings can be added to the warnings list. */ - public void validate(final Context context) - throws SCRDescriptorException { + public void validate(final Context context) throws SCRDescriptorException { if (context.getClassDescription().getDescribedClass().isInterface()) { - this.logError( context.getIssueLog(), "Must be declared in a Java class - not an interface" ); + this.logError(context.getIssueLog(), "Must be declared in a Java class - not an interface"); } else { try { final Class interfaceClass = context.getProject().getClassLoader().loadClass(this.interfaceName); - if ( !interfaceClass.isAssignableFrom(context.getClassDescription().getDescribedClass()) ) { + if (!interfaceClass.isAssignableFrom(context.getClassDescription().getDescribedClass())) { // interface not implemented - this.logError( context.getIssueLog(), "Class must implement provided interface " + this.interfaceName); + this.logError(context.getIssueLog(), "Class must implement provided interface " + this.interfaceName); } } catch (final ClassNotFoundException cnfe) { throw new SCRDescriptorException("Unable to load interface class.", cnfe); Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Property.java URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Property.java?rev=1341309&r1=1341308&r2=1341309&view=diff ============================================================================== --- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Property.java (original) +++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Property.java Tue May 22 06:04:18 2012 @@ -24,7 +24,7 @@ import org.apache.felix.scrplugin.descri /** * Property.java... - * + * */ public class Property extends AbstractObject { @@ -42,14 +42,14 @@ public class Property extends AbstractOb * Default constructor. */ public Property() { - this(null, null, -1); + this(null, null); } /** * Constructor from java source. */ - public Property(final String annotationName, final String sourceLocation, final int lineNumber) { - super(annotationName, sourceLocation, lineNumber); + public Property(final String annotationName, final String sourceLocation) { + super(annotationName, sourceLocation); } public String getName() { @@ -92,20 +92,21 @@ public class Property extends AbstractOb * warnings can be added to the warnings list. */ public void validate(final Context context) { - if ( name == null || name.trim().length() == 0 ) { - this.logError( context.getIssueLog(), "Property name can not be empty." ); + if (name == null || name.trim().length() == 0) { + this.logError(context.getIssueLog(), "Property name can not be empty."); } - if ( type != null ) { + if (type != null) { try { PropertyType.valueOf(this.type); } catch (final IllegalArgumentException iae) { - this.logError( context.getIssueLog(), "Property " + name + " has unknown type: " + type ); + this.logError(context.getIssueLog(), "Property " + name + " has unknown type: " + type); } // now check for old and new char - if ( context.getSpecVersion() == SpecVersion.VERSION_1_0 && type.equals(Constants.PROPERTY_TYPE_CHAR_1_1) ) { + if (context.getSpecVersion() == SpecVersion.VERSION_1_0 && type.equals(Constants.PROPERTY_TYPE_CHAR_1_1)) { type = Constants.PROPERTY_TYPE_CHAR; } - if ( context.getSpecVersion().ordinal() >= SpecVersion.VERSION_1_1.ordinal() && type.equals(Constants.PROPERTY_TYPE_CHAR) ) { + if (context.getSpecVersion().ordinal() >= SpecVersion.VERSION_1_1.ordinal() + && type.equals(Constants.PROPERTY_TYPE_CHAR)) { type = Constants.PROPERTY_TYPE_CHAR_1_1; } }