use of org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException in project felix by apache.
the class BundleAllPlugin method bundleAll.
/**
* Bundle a project and its transitive dependencies up to some depth level
*
* @param project
* @param maxDepth how deep to process the dependency tree
* @throws MojoExecutionException
*/
protected BundleInfo bundleAll(MavenProject project, int maxDepth) throws MojoExecutionException {
if (alreadyBundled(project.getArtifact())) {
getLog().debug("Ignoring project already processed " + project.getArtifact());
return null;
}
if (m_artifactsBeingProcessed.contains(project.getArtifact())) {
getLog().warn("Ignoring artifact due to dependency cycle " + project.getArtifact());
return null;
}
m_artifactsBeingProcessed.add(project.getArtifact());
DependencyNode dependencyTree;
try {
dependencyTree = m_dependencyTreeBuilder.buildDependencyTree(project, localRepository, m_factory, m_artifactMetadataSource, null, m_collector);
} catch (DependencyTreeBuilderException e) {
throw new MojoExecutionException("Unable to build dependency tree", e);
}
BundleInfo bundleInfo = new BundleInfo();
if (!dependencyTree.hasChildren()) {
/* no need to traverse the tree */
return bundleRoot(project, bundleInfo);
}
getLog().debug("Will bundle the following dependency tree" + LS + dependencyTree);
for (Iterator it = dependencyTree.inverseIterator(); it.hasNext(); ) {
DependencyNode node = (DependencyNode) it.next();
if (!it.hasNext()) {
/* this is the root, current project */
break;
}
if (node.getState() != DependencyNode.INCLUDED) {
continue;
}
if (Artifact.SCOPE_SYSTEM.equals(node.getArtifact().getScope())) {
getLog().debug("Ignoring system scoped artifact " + node.getArtifact());
continue;
}
Artifact artifact;
try {
artifact = resolveArtifact(node.getArtifact());
} catch (ArtifactNotFoundException e) {
if (ignoreMissingArtifacts) {
continue;
}
throw new MojoExecutionException("Artifact was not found in the repo" + node.getArtifact(), e);
}
node.getArtifact().setFile(artifact.getFile());
int nodeDepth = node.getDepth();
if (nodeDepth > maxDepth) {
/* node is deeper than we want */
getLog().debug("Ignoring " + node.getArtifact() + ", depth is " + nodeDepth + ", bigger than " + maxDepth);
continue;
}
MavenProject childProject;
try {
childProject = m_mavenProjectBuilder.buildFromRepository(artifact, remoteRepositories, localRepository, true);
if (childProject.getDependencyArtifacts() == null) {
childProject.setDependencyArtifacts(childProject.createArtifacts(m_factory, null, null));
}
} catch (InvalidDependencyVersionException e) {
throw new MojoExecutionException("Invalid dependency version for artifact " + artifact);
} catch (ProjectBuildingException e) {
throw new MojoExecutionException("Unable to build project object for artifact " + artifact, e);
}
childProject.setArtifact(artifact);
getLog().debug("Child project artifact location: " + childProject.getArtifact().getFile());
if ((Artifact.SCOPE_COMPILE.equals(artifact.getScope())) || (Artifact.SCOPE_RUNTIME.equals(artifact.getScope()))) {
BundleInfo subBundleInfo = bundleAll(childProject, maxDepth - 1);
if (subBundleInfo != null) {
bundleInfo.merge(subBundleInfo);
}
} else {
getLog().debug("Not processing due to scope (" + childProject.getArtifact().getScope() + "): " + childProject.getArtifact());
}
}
return bundleRoot(project, bundleInfo);
}
Aggregations