Skip to content

Commit afec50e

Browse files
cushoncopybara-github
authored andcommitted
Automated rollback of commit 72bd870.
*** Reason for rollback *** Android Studio didn't end up needing this *** Original change description *** Enable GenClass to take Java source jars as inputs to extract their corresponding class files from an input class jar. No parsing of the Java files is done, so the classes to extract are just based on the Java file's path in the source jar (i.e. the only compilation unit is assumed to be a class that matches the name of the file, and that the Java file's package matches its path in the jar.) RELNOTES: None. PiperOrigin-RevId: 316563736
1 parent 1bbc79d commit afec50e

File tree

3 files changed

+2
-79
lines changed

3 files changed

+2
-79
lines changed

src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClass.java

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.nio.file.attribute.BasicFileAttributes;
3131
import java.util.Arrays;
3232
import java.util.Enumeration;
33-
import java.util.List;
3433
import java.util.function.Predicate;
3534
import java.util.jar.JarEntry;
3635
import java.util.jar.JarFile;
@@ -68,12 +67,6 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc)
6867
public static void main(String[] args) throws IOException {
6968
GenClassOptions options = GenClassOptionsParser.parse(Arrays.asList(args));
7069
Manifest manifest = readManifest(options.manifest());
71-
72-
if (!options.getGeneratedSourceJars().isEmpty()) {
73-
Manifest generatedJarsManifest = readGeneratedSourceJars(options.getGeneratedSourceJars());
74-
manifest = Manifest.newBuilder(manifest).mergeFrom(generatedJarsManifest).build();
75-
}
76-
7770
deleteTree(options.tempDir());
7871
Files.createDirectories(options.tempDir());
7972
extractGeneratedClasses(options.classJar(), manifest, options.tempDir());
@@ -89,49 +82,6 @@ private static Manifest readManifest(Path path) throws IOException {
8982
return manifest;
9083
}
9184

92-
/** Reads the list of source jars and generates a Manifest based on the jars' entries. */
93-
@VisibleForTesting
94-
static Manifest readGeneratedSourceJars(List<Path> generatedSourceJarPaths) throws IOException {
95-
96-
Manifest.Builder manifestBuilder = Manifest.newBuilder();
97-
for (Path generatedSourceJarPath : generatedSourceJarPaths) {
98-
99-
try (JarFile jar = new JarFile(generatedSourceJarPath.toFile())) {
100-
101-
Enumeration<JarEntry> entries = jar.entries();
102-
while (entries.hasMoreElements()) {
103-
104-
JarEntry entry = entries.nextElement();
105-
String path = entry.getName();
106-
if (!path.endsWith(".java")) {
107-
continue;
108-
}
109-
110-
// This assumes that there is only 1 compilation unit in the Java file, and that the Java
111-
// file's package matches its path in the jar.
112-
113-
int lastSlash = path.lastIndexOf("/");
114-
String className = path.substring(lastSlash + 1, path.length() - ".java".length());
115-
String pkg;
116-
if (lastSlash == -1) {
117-
pkg = "";
118-
} else {
119-
pkg = path.substring(0, lastSlash).replace('/', '.');
120-
}
121-
manifestBuilder.addCompilationUnit(
122-
CompilationUnit.newBuilder()
123-
.setPath(path)
124-
.setPkg(pkg)
125-
.setGeneratedByAnnotationProcessor(true)
126-
.addTopLevel(className)
127-
.build());
128-
}
129-
}
130-
}
131-
132-
return manifestBuilder.build();
133-
}
134-
13585
/**
13686
* For each top-level class in the compilation matching the given predicate, determine the path
13787
* prefix of classes corresponding to that compilation unit.

src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClassOptions.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import static com.google.common.base.Preconditions.checkNotNull;
1818

19-
import com.google.common.collect.ImmutableList;
2019
import java.nio.file.Path;
2120

2221
/** The options for a {@GenClass} action. */
@@ -25,7 +24,6 @@ public final class GenClassOptions {
2524
/** A builder for {@link GenClassOptions}. */
2625
public static final class Builder {
2726
private Path manifest;
28-
private final ImmutableList.Builder<Path> generatedSourceJars = ImmutableList.builder();
2927
private Path classJar;
3028
private Path outputJar;
3129
private Path tempDir;
@@ -36,10 +34,6 @@ public void setManifest(Path manifest) {
3634
this.manifest = manifest;
3735
}
3836

39-
public void addGeneratedSourceJar(Path generatedSourceJar) {
40-
this.generatedSourceJars.add(generatedSourceJar);
41-
}
42-
4337
public void setClassJar(Path classJar) {
4438
this.classJar = classJar;
4539
}
@@ -53,25 +47,17 @@ public void setTempDir(Path tempDir) {
5347
}
5448

5549
GenClassOptions build() {
56-
return new GenClassOptions(
57-
manifest, generatedSourceJars.build(), classJar, outputJar, tempDir);
50+
return new GenClassOptions(manifest, classJar, outputJar, tempDir);
5851
}
5952
}
6053

6154
private final Path manifest;
62-
private final ImmutableList<Path> generatedSourceJars;
6355
private final Path classJar;
6456
private final Path outputJar;
6557
private final Path tempDir;
6658

67-
private GenClassOptions(
68-
Path manifest,
69-
ImmutableList<Path> generatedSourceJars,
70-
Path classJar,
71-
Path outputJar,
72-
Path tempDir) {
59+
private GenClassOptions(Path manifest, Path classJar, Path outputJar, Path tempDir) {
7360
this.manifest = checkNotNull(manifest);
74-
this.generatedSourceJars = checkNotNull(generatedSourceJars);
7561
this.classJar = checkNotNull(classJar);
7662
this.outputJar = checkNotNull(outputJar);
7763
this.tempDir = checkNotNull(tempDir);
@@ -82,16 +68,6 @@ public Path manifest() {
8268
return manifest;
8369
}
8470

85-
/**
86-
* The list of paths to jars containing generated Java source files corresponding to classes in
87-
* the input class jar which should be included in the gen jar. The packages of the Java source
88-
* files must match their path in the jar, and there can be only 1 top-level compilation unit,
89-
* because the list of compilation units in the Java file will be based on the file's name.
90-
*/
91-
public ImmutableList<Path> getGeneratedSourceJars() {
92-
return generatedSourceJars;
93-
}
94-
9571
/** The path to the compilation's class jar. */
9672
public Path classJar() {
9773
return classJar;

src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClassOptionsParser.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ public static GenClassOptions parse(Iterable<String> args) {
3030
case "--manifest_proto":
3131
builder.setManifest(readPath(it));
3232
break;
33-
case "--generated_source_jar":
34-
builder.addGeneratedSourceJar(readPath(it));
35-
break;
3633
case "--class_jar":
3734
builder.setClassJar(readPath(it));
3835
break;

0 commit comments

Comments
 (0)