From 228519f1b0762db1f89a4170dbd8474d6fb4203d Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 8 Jan 2025 12:40:48 -0800 Subject: [PATCH] Remove references to old coverage implementation PiperOrigin-RevId: 713382378 Change-Id: If32778574a51375b33a694aa5d31515337d71566 --- .../buildjar/SimpleJavaLibraryBuilder.java | 2 +- .../JacocoInstrumentationProcessor.java | 31 +++---------------- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/SimpleJavaLibraryBuilder.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/SimpleJavaLibraryBuilder.java index d62e749d6daca2..4902c5095fadae 100644 --- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/SimpleJavaLibraryBuilder.java +++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/SimpleJavaLibraryBuilder.java @@ -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(); diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/instrumentation/JacocoInstrumentationProcessor.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/instrumentation/JacocoInstrumentationProcessor.java index 35f8019f85db01..fd3b9b17d34be9 100644 --- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/instrumentation/JacocoInstrumentationProcessor.java +++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/instrumentation/JacocoInstrumentationProcessor.java @@ -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; @@ -53,18 +52,9 @@ public static JacocoInstrumentationProcessor create(List 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; } /** @@ -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 { @@ -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 =