Skip to content

Commit

Permalink
Remove references to old coverage implementation
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 713382378
Change-Id: If32778574a51375b33a694aa5d31515337d71566
  • Loading branch information
cushon authored and copybara-github committed Jan 8, 2025
1 parent 4e597f2 commit 228519f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void buildJar(JavaLibraryBuildRequest build) throws IOException {
jar.setJarOwner(build.getTargetLabel(), build.getInjectingRuleKind());
processor = build.getJacocoInstrumentationProcessor();
if (processor != null) {
processor.processRequest(build, processor.isNewCoverageImplementation() ? jar : null);
processor.processRequest(build, jar);
}
} finally {
jar.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.List;
Expand All @@ -53,18 +52,9 @@ public static JacocoInstrumentationProcessor create(List<String> args)

private Path instrumentedClassesDirectory;
private final String coverageInformation;
private final boolean isNewCoverageImplementation;

private JacocoInstrumentationProcessor(String coverageInfo) {
this.coverageInformation = coverageInfo;
// This is part of the new Java coverage implementation where JacocoInstrumentationProcessor
// receives a file that includes the relative paths of the uninstrumented Java files, instead
// of the metadata jar.
this.isNewCoverageImplementation = coverageInfo.endsWith(".txt");
}

public boolean isNewCoverageImplementation() {
return isNewCoverageImplementation;
}

/**
Expand All @@ -76,20 +66,12 @@ public void processRequest(JavaLibraryBuildRequest build, JarCreator jar) throws
// multiple threads performing read/write/delete actions on the instrumented classes directory.
instrumentedClassesDirectory = getMetadataDirRelativeToJar(build.getOutputJar());
Files.createDirectories(instrumentedClassesDirectory);
if (jar == null) {
jar = new JarCreator(coverageInformation);
}
jar.setNormalize(true);
jar.setCompression(build.compressJar());
Instrumenter instr = new Instrumenter(new OfflineInstrumentationAccessGenerator());
instrumentRecursively(instr, build.getClassDir());
jar.addDirectory(instrumentedClassesDirectory);
if (isNewCoverageImplementation) {
jar.addEntry(coverageInformation, coverageInformation);
} else {
jar.execute();
cleanup();
}
jar.addEntry(coverageInformation, coverageInformation);
}

public void cleanup() throws IOException {
Expand Down Expand Up @@ -124,14 +106,9 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
// We first move the original .class file to our metadata directory, then instrument it
// and output the instrumented version in the regular classes output directory.
Path instrumentedCopy = file;
Path uninstrumentedCopy;
if (isNewCoverageImplementation) {
Path absoluteUninstrumentedCopy = Paths.get(file + ".uninstrumented");
uninstrumentedCopy =
instrumentedClassesDirectory.resolve(root.relativize(absoluteUninstrumentedCopy));
} else {
uninstrumentedCopy = instrumentedClassesDirectory.resolve(root.relativize(file));
}
Path absoluteUninstrumentedCopy = Path.of(file + ".uninstrumented");
Path uninstrumentedCopy =
instrumentedClassesDirectory.resolve(root.relativize(absoluteUninstrumentedCopy));
Files.createDirectories(uninstrumentedCopy.getParent());
Files.move(file, uninstrumentedCopy);
try (InputStream input =
Expand Down

0 comments on commit 228519f

Please sign in to comment.