Search in sources :

Example 1 with InvalidArtifactCoordinateException

use of com.google.devtools.build.workspace.maven.Resolver.InvalidArtifactCoordinateException 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"));
        }
    }
}
Also used : LabelSyntaxException(com.google.devtools.build.lib.cmdline.LabelSyntaxException) DefaultModelResolver(com.google.devtools.build.workspace.maven.DefaultModelResolver) RepositoryName(com.google.devtools.build.lib.cmdline.RepositoryName) ModelSource(org.apache.maven.model.building.ModelSource) InvalidArtifactCoordinateException(com.google.devtools.build.workspace.maven.Resolver.InvalidArtifactCoordinateException) Target(com.google.devtools.build.lib.packages.Target) AttributeMap(com.google.devtools.build.lib.packages.AttributeMap) UnresolvableModelException(org.apache.maven.model.resolution.UnresolvableModelException) Rule(com.google.devtools.build.workspace.maven.Rule) Location(com.google.devtools.build.lib.events.Location)

Aggregations

LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)1 RepositoryName (com.google.devtools.build.lib.cmdline.RepositoryName)1 Location (com.google.devtools.build.lib.events.Location)1 AttributeMap (com.google.devtools.build.lib.packages.AttributeMap)1 Target (com.google.devtools.build.lib.packages.Target)1 DefaultModelResolver (com.google.devtools.build.workspace.maven.DefaultModelResolver)1 InvalidArtifactCoordinateException (com.google.devtools.build.workspace.maven.Resolver.InvalidArtifactCoordinateException)1 Rule (com.google.devtools.build.workspace.maven.Rule)1 ModelSource (org.apache.maven.model.building.ModelSource)1 UnresolvableModelException (org.apache.maven.model.resolution.UnresolvableModelException)1