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

Recursively gather children projects dependencies #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -22,6 +22,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.apache.maven.artifact.Artifact;
Expand All @@ -33,6 +34,7 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.artifact.filter.collection.AbstractArtifactsFilter;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
Expand Down Expand Up @@ -184,6 +186,22 @@ private void addPomDependencies(File baseDefinition, File outputXmlFile)
writeXmlFile(doc, outputXmlFile);
}

/**
* Recursively gathers project dependencies
*
* @param p The project to examine
* @param deps A set where dependencies will be added
*/
@SuppressWarnings("unchecked")
private void walkDependencies(MavenProject p, Set<Artifact> deps) {
List<MavenProject> collected = p.getCollectedProjects();
if (collected != null)
for (MavenProject sub : collected)
walkDependencies(sub, deps);
Set<Artifact> newdeps = p.getDependencyArtifacts();
if (newdeps != null)
deps.addAll(p.getDependencyArtifacts());
}

/**
* Resolves Maven project dependencies.
Expand All @@ -192,7 +210,9 @@ private void addPomDependencies(File baseDefinition, File outputXmlFile)
* @throws MojoExecutionException
*/
private Collection<Artifact> resolveDependencies() throws MojoExecutionException {
return getResolvedDependencies(true);
HashSet<Artifact> deps = new HashSet<Artifact>();
walkDependencies(project, deps);
return deps;
}


Expand All @@ -202,8 +222,10 @@ private Set<String> getArtifactDirs(Collection<? extends Artifact> artifacts)
Set<String> artifactDirs = new LinkedHashSet<String>();
for (Artifact artifact : artifacts) {
File artifactFile = artifact.getFile();
String artifactDir = artifactFile.getParentFile().getCanonicalPath();
artifactDirs.add(artifactDir);
if (artifactFile != null) {
String artifactDir = artifactFile.getParentFile().getCanonicalPath();
artifactDirs.add(artifactDir);
}
}

return artifactDirs;
Expand Down