From 1913330f81f809db1f29bc61230af818baac5cc6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 6 Jun 2014 19:49:12 -0400 Subject: [PATCH 2/2] qdox2 --- .../SourceComponentDescriptorExtractor.java | 11 +++++----- .../metadata/gleaner/QDoxComponentGleaner.java | 24 +++++++++------------- .../metadata/gleaner/SourceComponentGleaner.java | 4 ++-- .../metadata/gleaner/QDoxComponentGleanerTest.java | 6 +++--- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/metadata/SourceComponentDescriptorExtractor.java b/src/main/java/org/codehaus/plexus/metadata/SourceComponentDescriptorExtractor.java index 522e9ad..9b357fc 100644 --- a/src/main/java/org/codehaus/plexus/metadata/SourceComponentDescriptorExtractor.java +++ b/src/main/java/org/codehaus/plexus/metadata/SourceComponentDescriptorExtractor.java @@ -16,6 +16,7 @@ package org.codehaus.plexus.metadata; import java.io.File; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -24,7 +25,7 @@ import org.codehaus.plexus.metadata.gleaner.QDoxComponentGleaner; import org.codehaus.plexus.metadata.gleaner.SourceComponentGleaner; import org.codehaus.plexus.util.StringUtils; -import com.thoughtworks.qdox.JavaDocBuilder; +import com.thoughtworks.qdox.JavaProjectBuilder; import com.thoughtworks.qdox.model.JavaClass; /** @@ -66,7 +67,7 @@ public class SourceComponentDescriptorExtractor List> descriptors = new ArrayList>(); // Scan the sources - JavaDocBuilder builder = new JavaDocBuilder(); + JavaProjectBuilder builder = new JavaProjectBuilder(); if ( StringUtils.isNotEmpty( sourceEncoding ) ) { @@ -80,12 +81,12 @@ public class SourceComponentDescriptorExtractor builder.addSourceTree( dir ); } - JavaClass[] classes = builder.getClasses(); + Collection classes = builder.getClasses(); // For each class we find, try to glean off a descriptor - for ( int i = 0; i < classes.length; i++ ) + for ( JavaClass klass : classes ) { - ComponentDescriptor descriptor = gleaner.glean( builder, classes[i] ); + ComponentDescriptor descriptor = gleaner.glean( builder, klass ); if ( descriptor != null ) { diff --git a/src/main/java/org/codehaus/plexus/metadata/gleaner/QDoxComponentGleaner.java b/src/main/java/org/codehaus/plexus/metadata/gleaner/QDoxComponentGleaner.java index a1396d9..f818fea 100644 --- a/src/main/java/org/codehaus/plexus/metadata/gleaner/QDoxComponentGleaner.java +++ b/src/main/java/org/codehaus/plexus/metadata/gleaner/QDoxComponentGleaner.java @@ -45,7 +45,7 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; import org.codehaus.plexus.util.StringUtils; -import com.thoughtworks.qdox.JavaDocBuilder; +import com.thoughtworks.qdox.JavaProjectBuilder; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaField; @@ -90,7 +90,7 @@ public class QDoxComponentGleaner // ComponentGleaner Implementation // ---------------------------------------------------------------------- - public ComponentDescriptor glean( JavaDocBuilder classCache, JavaClass javaClass ) + public ComponentDescriptor glean( JavaProjectBuilder classCache, JavaClass javaClass ) throws ComponentGleanerException { DocletTag tag = javaClass.getTagByName( PLEXUS_COMPONENT_TAG ); @@ -255,7 +255,7 @@ public class QDoxComponentGleaner // Remove any Plexus specific interfaces from the calculation // ---------------------------------------------------------------------- - List interfaces = new ArrayList( Arrays.asList( javaClass.getImplementedInterfaces() ) ); + List interfaces = new ArrayList( javaClass.getImplementedInterfaces() ); for ( Iterator it = interfaces.iterator(); it.hasNext(); ) { @@ -344,10 +344,10 @@ public class QDoxComponentGleaner return role; } - private void findRequirements( JavaDocBuilder classCache, ComponentDescriptor componentDescriptor, + private void findRequirements( JavaProjectBuilder classCache, ComponentDescriptor componentDescriptor, JavaClass javaClass ) { - JavaField[] fields = javaClass.getFields(); + List fields = javaClass.getFields(); // ---------------------------------------------------------------------- // Search the super class for requirements @@ -362,10 +362,8 @@ public class QDoxComponentGleaner // Search the current class for requirements // ---------------------------------------------------------------------- - for ( int i = 0; i < fields.length; i++ ) + for ( JavaField field : fields ) { - JavaField field = fields[i]; - DocletTag tag = field.getTagByName( PLEXUS_REQUIREMENT_TAG ); if ( tag == null ) @@ -379,7 +377,7 @@ public class QDoxComponentGleaner // Role // ---------------------------------------------------------------------- - String requirementClass = field.getType().getJavaClass().getFullyQualifiedName(); + String requirementClass = field.getType().getFullyQualifiedName(); boolean isMap = requirementClass.equals( Map.class.getName() ) || requirementClass.equals( Collection.class.getName() ); @@ -483,7 +481,7 @@ public class QDoxComponentGleaner private void findConfiguration( XmlPlexusConfiguration configuration, JavaClass javaClass ) throws ComponentGleanerException { - JavaField[] fields = javaClass.getFields(); + List fields = javaClass.getFields(); // ---------------------------------------------------------------------- // Search the super class for configurable fields. @@ -498,10 +496,8 @@ public class QDoxComponentGleaner // Search the current class for configurable fields. // ---------------------------------------------------------------------- - for ( int i = 0; i < fields.length; i++ ) + for ( JavaField field : fields ) { - JavaField field = fields[i]; - DocletTag tag = field.getTagByName( PLEXUS_CONFIGURATION_TAG ); if ( tag == null ) @@ -565,4 +561,4 @@ public class QDoxComponentGleaner return value; } -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/metadata/gleaner/SourceComponentGleaner.java b/src/main/java/org/codehaus/plexus/metadata/gleaner/SourceComponentGleaner.java index d8e26c5..6a027c9 100644 --- a/src/main/java/org/codehaus/plexus/metadata/gleaner/SourceComponentGleaner.java +++ b/src/main/java/org/codehaus/plexus/metadata/gleaner/SourceComponentGleaner.java @@ -18,7 +18,7 @@ package org.codehaus.plexus.metadata.gleaner; import org.codehaus.plexus.component.repository.ComponentDescriptor; -import com.thoughtworks.qdox.JavaDocBuilder; +import com.thoughtworks.qdox.JavaProjectBuilder; import com.thoughtworks.qdox.model.JavaClass; /** @@ -30,6 +30,6 @@ public interface SourceComponentGleaner { String ROLE = SourceComponentGleaner.class.getName(); - ComponentDescriptor glean( JavaDocBuilder classCache, JavaClass javaClass ) + ComponentDescriptor glean( JavaProjectBuilder classCache, JavaClass javaClass ) throws ComponentGleanerException; } \ No newline at end of file diff --git a/src/test/java/org/codehaus/plexus/metadata/gleaner/QDoxComponentGleanerTest.java b/src/test/java/org/codehaus/plexus/metadata/gleaner/QDoxComponentGleanerTest.java index c94531e..7ac7395 100644 --- a/src/test/java/org/codehaus/plexus/metadata/gleaner/QDoxComponentGleanerTest.java +++ b/src/test/java/org/codehaus/plexus/metadata/gleaner/QDoxComponentGleanerTest.java @@ -23,7 +23,7 @@ import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.configuration.PlexusConfiguration; -import com.thoughtworks.qdox.JavaDocBuilder; +import com.thoughtworks.qdox.JavaProjectBuilder; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaSource; @@ -37,7 +37,7 @@ public class QDoxComponentGleanerTest { private QDoxComponentGleaner gleaner; - private JavaDocBuilder builder; + private JavaProjectBuilder builder; // @Override protected void setUp() @@ -46,7 +46,7 @@ public class QDoxComponentGleanerTest super.setUp(); gleaner = new QDoxComponentGleaner(); - builder = new JavaDocBuilder(); + builder = new JavaProjectBuilder(); } // @Override -- 2.0.0