diff --git a/cq-component-maven-plugin/src/main/java/com/citytechinc/cq/component/maven/ComponentMojo.java b/cq-component-maven-plugin/src/main/java/com/citytechinc/cq/component/maven/ComponentMojo.java index 6918423e..ec04a070 100644 --- a/cq-component-maven-plugin/src/main/java/com/citytechinc/cq/component/maven/ComponentMojo.java +++ b/cq-component-maven-plugin/src/main/java/com/citytechinc/cq/component/maven/ComponentMojo.java @@ -18,6 +18,7 @@ import java.io.File; import java.net.MalformedURLException; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -77,6 +78,9 @@ public class ComponentMojo extends AbstractMojo { @Parameter(required = false) private List excludeDependencies; + @Parameter + private List includeDependencies; + @Parameter(defaultValue = "true") private boolean generateTouchUiDialogs; @@ -103,7 +107,12 @@ public void execute() throws MojoExecutionException, MojoFailureException { Reflections reflections = ComponentMojoUtil.getReflections(classLoader); List classList = - ComponentMojoUtil.getAllComponentAnnotations(classPool, reflections, getExcludedClasses()); + ComponentMojoUtil.getAllComponentAnnotations( + classPool, + reflections, + getExcludedClasses(), + getIncludedClasses() + ); WidgetRegistry widgetRegistry = new DefaultWidgetRegistry(classPool, classLoader, reflections, getAdditionalFeatures()); @@ -136,28 +145,52 @@ componentPathBase, componentPathSuffix, defaultComponentGroup, getArchiveFileFor } private Set getExcludedClasses() throws DependencyResolutionRequiredException, MalformedURLException { - getLog().debug("Constructing set of excluded Class names"); + if (!hasIncludeDependencies() && hasExcludeDependencies()) { + List dependencyPaths = getDependencyPaths(excludeDependencies); + if (!dependencyPaths.isEmpty()) { + return getClassNames(dependencyPaths); + } + } else { + getLog().debug("Excluded Class names skipped"); + } + return Collections.emptySet(); + } - List excludedDependencyPaths = getExcludedDependencyPaths(); - - if (excludedDependencyPaths != null) { - ClassLoader exclusionClassLoader = - ComponentMojoUtil.getClassLoader(excludedDependencyPaths, this.getClass().getClassLoader()); + private Set getIncludedClasses() throws DependencyResolutionRequiredException, MalformedURLException { + getLog().debug("Constructing set of included Class names"); + if (hasIncludeDependencies()) { + List dependencyPaths = getDependencyPaths(includeDependencies); + if (!dependencyPaths.isEmpty()) { + return getClassNames(dependencyPaths); + } + } else { + getLog().debug("Included Class names skipped"); + } + return Collections.emptySet(); + } - Reflections reflections = ComponentMojoUtil.getReflections(exclusionClassLoader); + /** + * Retrieve class names annotated with {@link Component} from specified dependency paths + * @param dependencyPaths to obtain available class names + * @return set of available class names + * @throws MalformedURLException if error occurs + */ + private Set getClassNames(List dependencyPaths) throws MalformedURLException { + ClassLoader exclusionClassLoader = + ComponentMojoUtil.getClassLoader(dependencyPaths, this.getClass().getClassLoader()); - Set excludedClassNames = reflections.getStore().getTypesAnnotatedWith(Component.class.getName()); + Reflections reflections = ComponentMojoUtil.getReflections(exclusionClassLoader); - return excludedClassNames; - } + Set excludedClassNames = reflections.getStore() + .getTypesAnnotatedWith(Component.class.getName()); - return null; + return excludedClassNames; } @SuppressWarnings("unchecked") - private List getExcludedDependencyPaths() throws DependencyResolutionRequiredException { - if (excludeDependencies != null && !excludeDependencies.isEmpty()) { + private List getDependencyPaths(List dependencies) throws DependencyResolutionRequiredException { + if (dependencies != null && !dependencies.isEmpty()) { getLog().debug("Exclusions Found"); List compileArtifacts = project.getCompileArtifacts(); @@ -166,7 +199,7 @@ private List getExcludedDependencyPaths() throws DependencyResolutionReq Set excludedArtifactIdentifiers = new HashSet(); - for (Dependency curDependency : excludeDependencies) { + for (Dependency curDependency : dependencies) { excludedArtifactIdentifiers.add(curDependency.getGroupId() + ":" + curDependency.getArtifactId()); } @@ -193,7 +226,7 @@ private List getExcludedDependencyPaths() throws DependencyResolutionReq return excludedClasspathElements; } - return null; + return Collections.emptyList(); } @@ -222,4 +255,12 @@ private List getAdditionalFeatures() { return additionalFeatures; } + + private boolean hasIncludeDependencies(){ + return includeDependencies != null && !includeDependencies.isEmpty(); + } + + private boolean hasExcludeDependencies(){ + return excludeDependencies != null && !excludeDependencies.isEmpty(); + } } diff --git a/cq-component-maven-plugin/src/main/java/com/citytechinc/cq/component/maven/util/ComponentMojoUtil.java b/cq-component-maven-plugin/src/main/java/com/citytechinc/cq/component/maven/util/ComponentMojoUtil.java index f542541c..f1dc8f8d 100644 --- a/cq-component-maven-plugin/src/main/java/com/citytechinc/cq/component/maven/util/ComponentMojoUtil.java +++ b/cq-component-maven-plugin/src/main/java/com/citytechinc/cq/component/maven/util/ComponentMojoUtil.java @@ -512,28 +512,37 @@ public static List getInPlaceEditorAnnotations(ClassP * * @param classPool * @param reflections + * @param classes * @return A List of classes annotated as Components * @throws ClassNotFoundException * @throws NotFoundException * @throws MalformedURLException */ public static List getAllComponentAnnotations(ClassPool classPool, Reflections reflections, - Set excludedClasses) throws ClassNotFoundException, NotFoundException, MalformedURLException { + final Set excludedClasses, Set includedClasses) throws ClassNotFoundException, NotFoundException, MalformedURLException { getLog().debug("Scanning for Components"); List classes = new ArrayList(); Set> annotatedClasses = reflections.getTypesAnnotatedWith(Component.class); - if (excludedClasses != null && !excludedClasses.isEmpty()) { - for (Class c : annotatedClasses) { - if (!excludedClasses.contains(c.getName())) { + if (includedClasses.isEmpty()) { + if (!excludedClasses.isEmpty()) { + for (Class c : annotatedClasses) { + if (!excludedClasses.contains(c.getName())) { + classes.add(classPool.getCtClass(c.getName())); + } + } + } else { + for (Class c : annotatedClasses) { classes.add(classPool.getCtClass(c.getName())); } } } else { for (Class c : annotatedClasses) { - classes.add(classPool.getCtClass(c.getName())); + if (includedClasses.contains(c.getName())) { + classes.add(classPool.getCtClass(c.getName())); + } } } diff --git a/src/site/markdown/configuration.md.vm b/src/site/markdown/configuration.md.vm index f7101e1e..ffefcfbf 100644 --- a/src/site/markdown/configuration.md.vm +++ b/src/site/markdown/configuration.md.vm @@ -33,6 +33,12 @@ $symbol_pound$symbol_pound$symbol_pound Maven POM dependency-artifact-id + + + dependency.group.id + dependency-artifact-id + + feature-flag another-feature-flag @@ -138,7 +144,7 @@ $symbol_pound$symbol_pound Configurable Properties - excludedDependencies + excludeDependencies List A list of Dependencies whose Components should be excluded from the construction process. XML @@ -149,6 +155,19 @@ $symbol_pound$symbol_pound Configurable Properties Currently unavailable in the Gradle Plugin. + + includeDependencies + List + + A list of Dependencies whose Components should be included to the construction process. XML + files will be generated by this plugin for any Java Classes annotated as Components which are + members of any of the Dependencies in this list. If this dependency was specified excludeDependencies + will be skipped +
+
+ Currently unavailable in the Gradle Plugin. + + generateTouchUiDialogs Boolean