use of com.google.devtools.build.workspace.maven.Rule in project bazel by bazelbuild.
the class ResultWriter method writeBuild.
/**
* Write library rules to depend on the transitive closure of all of these rules.
*/
public void writeBuild(PrintStream outputStream) {
writeHeader(outputStream);
for (Rule rule : rules) {
outputStream.println("java_library(");
outputStream.println(" name = \"" + rule.name() + "\",");
outputStream.println(" visibility = [\"//visibility:public\"],");
outputStream.println(" exports = [");
outputStream.println(" \"@" + rule.name() + "//jar\",");
for (Rule r : rule.getDependencies()) {
outputStream.println(" \"@" + r.name() + "//jar\",");
}
outputStream.println(" ],");
outputStream.println(")");
outputStream.println();
}
}
use of com.google.devtools.build.workspace.maven.Rule in project bazel by bazelbuild.
the class ResultWriterTest method testBuildFile.
@Test
public void testBuildFile() throws Exception {
Rule rule = new Rule(new DefaultArtifact("x:y:1.2.3"));
Rule dep1 = new Rule(new DefaultArtifact("dep:dep1:4.5.6"));
rule.addDependency(dep1);
Rule dep2 = new Rule(new DefaultArtifact("dep:dep2:7.8.9"));
rule.addDependency(dep2);
Set<Rule> rules = ImmutableSet.of(rule, dep1, dep2);
String content = getBuildFileContent(ImmutableList.<String>of(), rules);
assertThat(content).contains("java_library(\n" + " name = \"x_y\",\n" + " visibility = [\"//visibility:public\"],\n" + " exports = [\n" + " \"@x_y//jar\",\n" + " \"@dep_dep1//jar\",\n" + " \"@dep_dep2//jar\",\n" + " ],\n" + ")");
}
use of com.google.devtools.build.workspace.maven.Rule in project bazel by bazelbuild.
the class ResultWriterTest method testParents.
@Test
public void testParents() throws Exception {
Rule rule = new Rule(new DefaultArtifact("x:y:1.2.3"));
rule.addParent("some parent");
Set<Rule> rules = ImmutableSet.of(rule);
String content = getWorkspaceFileContent(ImmutableList.<String>of(), rules);
assertThat(content).contains("# some parent\n" + "maven_jar(\n" + " name = \"x_y\",\n" + " artifact = \"x:y:1.2.3\",\n" + ")");
}
use of com.google.devtools.build.workspace.maven.Rule 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"));
}
}
}
use of com.google.devtools.build.workspace.maven.Rule in project bazel by bazelbuild.
the class ResultWriterTest method testArtifacts.
@Test
public void testArtifacts() throws Exception {
Set<Rule> rules = ImmutableSet.of(new Rule(new DefaultArtifact("x:y:1.2.3")));
String content = getWorkspaceFileContent(ImmutableList.<String>of(), rules);
assertThat(content).contains("maven_jar(\n" + " name = \"x_y\",\n" + " artifact = \"x:y:1.2.3\",\n" + ")");
}
Aggregations