Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency Inclusion Functionality #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,6 +78,9 @@ public class ComponentMojo extends AbstractMojo {
@Parameter(required = false)
private List<Dependency> excludeDependencies;

@Parameter
private List<Dependency> includeDependencies;

@Parameter(defaultValue = "true")
private boolean generateTouchUiDialogs;

Expand All @@ -103,7 +107,12 @@ public void execute() throws MojoExecutionException, MojoFailureException {
Reflections reflections = ComponentMojoUtil.getReflections(classLoader);

List<CtClass> classList =
ComponentMojoUtil.getAllComponentAnnotations(classPool, reflections, getExcludedClasses());
ComponentMojoUtil.getAllComponentAnnotations(
classPool,
reflections,
getExcludedClasses(),
getIncludedClasses()
);

WidgetRegistry widgetRegistry =
new DefaultWidgetRegistry(classPool, classLoader, reflections, getAdditionalFeatures());
Expand Down Expand Up @@ -136,28 +145,52 @@ componentPathBase, componentPathSuffix, defaultComponentGroup, getArchiveFileFor
}

private Set<String> getExcludedClasses() throws DependencyResolutionRequiredException, MalformedURLException {

getLog().debug("Constructing set of excluded Class names");
if (!hasIncludeDependencies() && hasExcludeDependencies()) {
List<String> dependencyPaths = getDependencyPaths(excludeDependencies);
if (!dependencyPaths.isEmpty()) {
return getClassNames(dependencyPaths);
}
} else {
getLog().debug("Excluded Class names skipped");
}
return Collections.emptySet();
}

List<String> excludedDependencyPaths = getExcludedDependencyPaths();

if (excludedDependencyPaths != null) {
ClassLoader exclusionClassLoader =
ComponentMojoUtil.getClassLoader(excludedDependencyPaths, this.getClass().getClassLoader());
private Set<String> getIncludedClasses() throws DependencyResolutionRequiredException, MalformedURLException {
getLog().debug("Constructing set of included Class names");
if (hasIncludeDependencies()) {
List<String> 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<String> getClassNames(List<String> dependencyPaths) throws MalformedURLException {
ClassLoader exclusionClassLoader =
ComponentMojoUtil.getClassLoader(dependencyPaths, this.getClass().getClassLoader());

Set<String> excludedClassNames = reflections.getStore().getTypesAnnotatedWith(Component.class.getName());
Reflections reflections = ComponentMojoUtil.getReflections(exclusionClassLoader);

return excludedClassNames;
}
Set<String> excludedClassNames = reflections.getStore()
.getTypesAnnotatedWith(Component.class.getName());

return null;
return excludedClassNames;
}

@SuppressWarnings("unchecked")
private List<String> getExcludedDependencyPaths() throws DependencyResolutionRequiredException {
if (excludeDependencies != null && !excludeDependencies.isEmpty()) {
private List<String> getDependencyPaths(List<Dependency> dependencies) throws DependencyResolutionRequiredException {
if (dependencies != null && !dependencies.isEmpty()) {
getLog().debug("Exclusions Found");

List<Artifact> compileArtifacts = project.getCompileArtifacts();
Expand All @@ -166,7 +199,7 @@ private List<String> getExcludedDependencyPaths() throws DependencyResolutionReq

Set<String> excludedArtifactIdentifiers = new HashSet<String>();

for (Dependency curDependency : excludeDependencies) {
for (Dependency curDependency : dependencies) {
excludedArtifactIdentifiers.add(curDependency.getGroupId() + ":" + curDependency.getArtifactId());
}

Expand All @@ -193,7 +226,7 @@ private List<String> getExcludedDependencyPaths() throws DependencyResolutionReq
return excludedClasspathElements;
}

return null;
return Collections.emptyList();

}

Expand Down Expand Up @@ -222,4 +255,12 @@ private List<String> getAdditionalFeatures() {

return additionalFeatures;
}

private boolean hasIncludeDependencies(){
return includeDependencies != null && !includeDependencies.isEmpty();
}

private boolean hasExcludeDependencies(){
return excludeDependencies != null && !excludeDependencies.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -512,28 +512,37 @@ public static List<InPlaceEditorConfigHolder> 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<CtClass> getAllComponentAnnotations(ClassPool classPool, Reflections reflections,
Set<String> excludedClasses) throws ClassNotFoundException, NotFoundException, MalformedURLException {
final Set<String> excludedClasses, Set<String> includedClasses) throws ClassNotFoundException, NotFoundException, MalformedURLException {
getLog().debug("Scanning for Components");

List<CtClass> classes = new ArrayList<CtClass>();

Set<Class<?>> 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()));
}
}
}

Expand Down
21 changes: 20 additions & 1 deletion src/site/markdown/configuration.md.vm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ $symbol_pound$symbol_pound$symbol_pound Maven POM
<artifactId>dependency-artifact-id</artifactId>
</dependency>
</excludeDependencies>
<includeDependencies>
<dependency>
<groupId>dependency.group.id</groupId>
<artifactId>dependency-artifact-id</artifactId>
</dependency>
</includeDependencies>
<additionalFeatures>
<additionalFeature>feature-flag</additionalFeature>
<additionalFeature>another-feature-flag</additionalFeature>
Expand Down Expand Up @@ -138,7 +144,7 @@ $symbol_pound$symbol_pound Configurable Properties
</td>
</tr>
<tr>
<td>excludedDependencies</td>
<td>excludeDependencies</td>
<td>List</td>
<td></td>
<td>A list of Dependencies whose Components should be excluded from the construction process. XML
Expand All @@ -149,6 +155,19 @@ $symbol_pound$symbol_pound Configurable Properties
<b>Currently unavailable in the Gradle Plugin.</b>
</td>
</tr>
<tr>
<td>includeDependencies</td>
<td>List</td>
<td></td>
<td>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
<br/>
<br/>
<b>Currently unavailable in the Gradle Plugin.</b>
</td>
</tr>
<tr>
<td>generateTouchUiDialogs</td>
<td>Boolean</td>
Expand Down