}
private DependencyDTO buildFrom(DependencyNode node) {
Artifact artifact = node.getArtifact();
if (artifact != null) {
DependencyDTO answer = new DependencyDTO();
answer.setGroupId(artifact.getGroupId());
answer.setArtifactId(artifact.getArtifactId());
answer.setVersion(artifact.getVersion());
answer.setClassifier(artifact.getClassifier());
String scope = artifact.getScope();
answer.setScope(scope);
answer.setType(artifact.getType());
// there is a bug if we try to resolve the current projects artifact for a "jar" packaging
// before we've installed it then this operation will force the jar not be installed
// so lets ignore this for the maven project's artifact
if (artifact.getClassifier() == null && "jar".equals(artifact.getType())) {
if (project.getArtifact().equals(artifact)) {
getLog().debug("Ignoring bundle check on the maven project artifact: " + artifact + " as this causes issues with the maven-install-plugin and we can assume the project packaging is accurate");
} else {
try {
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(artifact);
request.setRemoteRepositories(remoteRepositories);
request.setLocalRepository(localRepository);
resolver.resolve(request);
JarInputStream jis = new JarInputStream(new FileInputStream(artifact.getFile()));
Manifest man = jis.getManifest();
String bsn = man.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
if (bsn != null) {
answer.setType("bundle");
} else {
// Try to find a matching servicemix bundle for it
/*
Map<String, String> bundles = getAllServiceMixBundles();
getLog().debug("Trying to find a matching bundle for " + artifact);
String match = bundles.get(artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion());
if (match != null) {
String[] parts = match.split(":");
answer.setGroupId(parts[0]);
answer.setArtifactId(parts[1]);
answer.setVersion(parts[2]);
getLog().info("Replacing artifact " + artifact + " with servicemix bundle " + match);
}
*/
}
} catch (Exception e) {
getLog().debug("Error checking artifact type for " + artifact, e);
}
}
}
answer.setOptional(artifact.isOptional());
String type = answer.getType();
if (type != null && type.equals("pom")) {
getLog().debug("Ignoring pom.xml for " + answer);
return null;
}
int state = node.getState();
if (state != DependencyNode.INCLUDED) {
getLog().debug("Ignoring " + node);
return null;
}
if (isWarProject()) {
if (scope != null && !scope.equals("provided")) {
getLog().debug("WAR packaging so ignoring non-provided scope " + scope + " for " + node);
return null;
}
}
List children = node.getChildren();
for (Object child : children) {
if (child instanceof DependencyNode) {
DependencyNode childNode = (DependencyNode) child;
if (childNode.getState() == DependencyNode.INCLUDED) {
String childScope = childNode.getArtifact().getScope();
if (!"test".equals(childScope) && !"provided".equals(childScope)) {
DependencyDTO childDTO = buildFrom(childNode);
if (childDTO != null) {
answer.addChild(childDTO);
}
} else {
getLog().debug("Ignoring artifact " + childNode.getArtifact() + " with scope " + childScope);