use of com.google.devtools.build.workspace.maven.DefaultModelResolver in project bazel by bazelbuild.
the class WorkspaceResolver method resolveTransitiveDependencies.
/**
* Calculates transitive dependencies of the given //external package.
*/
public void resolveTransitiveDependencies(Package externalPackage) {
Location location = Location.fromFile(externalPackage.getFilename());
for (Target target : externalPackage.getTargets()) {
// Targets are //external:foo.
if (target.getTargetKind().startsWith("maven_jar ")) {
RepositoryName repositoryName;
try {
repositoryName = RepositoryName.create("@" + target.getName());
} catch (LabelSyntaxException e) {
handler.handle(Event.error(location, "Invalid repository name for " + target + ": " + e.getMessage()));
return;
}
com.google.devtools.build.lib.packages.Rule workspaceRule = externalPackage.getRule(repositoryName.strippedName());
DefaultModelResolver modelResolver = resolver.getModelResolver();
AttributeMap attributeMap = AggregatingAttributeMapper.of(workspaceRule);
Rule rule;
try {
rule = new Rule(Resolver.getArtifact(attributeMap.get("artifact", Type.STRING)));
} catch (InvalidArtifactCoordinateException e) {
handler.handle(Event.error(location, "Couldn't get attribute: " + e.getMessage()));
return;
}
if (attributeMap.isAttributeValueExplicitlySpecified("repository")) {
modelResolver.addUserRepository(attributeMap.get("repository", Type.STRING));
rule.setRepository(attributeMap.get("repository", Type.STRING), handler);
}
if (attributeMap.isAttributeValueExplicitlySpecified("sha1")) {
rule.setSha1(attributeMap.get("sha1", Type.STRING));
} else {
rule.setSha1(resolver.downloadSha1(rule));
}
ModelSource modelSource;
try {
modelSource = modelResolver.resolveModel(rule.groupId(), rule.artifactId(), rule.version());
} catch (UnresolvableModelException e) {
handler.handle(Event.error("Could not resolve model for " + target + ": " + e.getMessage()));
continue;
}
resolver.addArtifact(rule, modelSource.getLocation());
resolver.resolveEffectiveModel(modelSource, Sets.<String>newHashSet(), rule);
} else if (!target.getTargetKind().startsWith("bind") && !target.getTargetKind().startsWith("source ")) {
handler.handle(Event.warn(location, "Cannot fetch transitive dependencies for " + target + " yet, skipping"));
}
}
}
Aggregations