diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java index 30102d4b7b..8448232fdc 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java @@ -172,6 +172,28 @@ public class JavaCommon { } } + /** + * Creates an action to aggregate all metadata artifacts into a single + * <target_name>_instrumented.jar file. + */ + public static void createInstrumentedJarAction( + RuleContext ruleContext, + JavaSemantics semantics, + List<Artifact> metadataArtifacts, + Artifact instrumentedJar, + String mainClass) + throws InterruptedException { + // In Jacoco's setup, metadata artifacts are real jars. + new DeployArchiveBuilder(semantics, ruleContext) + .setOutputJar(instrumentedJar) + // We need to save the original mainClass because we're going to run inside CoverageRunner + .setJavaStartClass(mainClass) + .setAttributes(new JavaTargetAttributes.Builder(semantics).build()) + .addRuntimeJars(ImmutableList.copyOf(metadataArtifacts)) + .setCompression(DeployArchiveBuilder.Compression.UNCOMPRESSED) + .build(); + } + public static ImmutableList<String> getConstraints(RuleContext ruleContext) { return ruleContext.getRule().isAttrDefined("constraints", Type.STRING_LIST) ? ImmutableList.copyOf(ruleContext.attributes().get("constraints", Type.STRING_LIST)) @@ -717,6 +739,7 @@ public class JavaCommon { .addTransitiveTargets(runtimeDepInfo, true, ClasspathType.RUNTIME_ONLY) .build(); attributes.addRuntimeClassPathEntries(args.getRuntimeJars()); + attributes.addInstrumentationMetadataEntries(args.getInstrumentationMetadata()); } /** |