Skip to content

Commit 2f50834

Browse files
authored
Use ecj from maven (#1)
* Delete ecj sources, as ecj will be downloaded from mvn * Adjust BlazeEcjMain to changes in latest ecj
1 parent 5a87b68 commit 2f50834

File tree

641 files changed

+79
-244260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

641 files changed

+79
-244260
lines changed

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ maven.install(
3131
"com.google.auto.value:auto-value-annotations:1.11.0",
3232
"com.google.code.findbugs:jsr305:3.0.2",
3333
"com.github.ben-manes.caffeine:caffeine:3.2.1",
34+
"org.eclipse.jdt:ecj:3.42.0",
3435
# ASM (needed for coverage together with Jacoco)
3536
"org.ow2.asm:asm:9.7.1",
3637
"org.ow2.asm:asm-analysis:9.7.1",

compiler/BUILD

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ java_library(
3636
],
3737
deps = [
3838
"@bazel_org_jacoco_core//jar",
39-
":ecj",
4039
":work_request_handlers",
4140
"//compiler/src/main/protobuf:deps_java_proto",
4241
"//compiler/src/main/protobuf:java_compilation_java_proto",
@@ -46,23 +45,10 @@ java_library(
4645
"@maven//:com_github_ben_manes_caffeine_caffeine",
4746
"@maven//:com_google_guava_guava",
4847
"@maven//:com_google_code_findbugs_jsr305",
48+
"@maven//:org_eclipse_jdt_ecj",
4949
],
5050
plugins = [
5151
java_plugin_artifact("com.google.auto.value:auto-value", "com.google.auto.value.processor.AutoValueProcessor"),
5252
],
5353
)
5454

55-
# Eclipse Java Compiler
56-
java_library(
57-
name = "ecj",
58-
srcs = glob(["src/main/ecj/**/*.java"]),
59-
javacopts = [
60-
"-nowarn",
61-
"-XepDisableAllChecks",
62-
],
63-
resource_strip_prefix = "compiler/src/main/ecj/",
64-
resources = glob(
65-
["src/main/ecj/**"],
66-
exclude = ["**/*.java"],
67-
),
68-
)

compiler/src/main/buildjar/com/google/devtools/build/buildjar/javac/BlazeEcjMain.java

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.InputStream;
2828
import java.io.PrintWriter;
2929
import java.io.StringWriter;
30+
import java.net.URI;
3031
import java.nio.file.Path;
3132
import java.util.ArrayList;
3233
import java.util.HashMap;
@@ -47,11 +48,11 @@
4748
import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
4849
import org.eclipse.jdt.internal.compiler.batch.ClasspathLocation;
4950
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
50-
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
51-
import org.eclipse.jdt.internal.compiler.batch.FileSystem.ClasspathAnswer;
5251
import org.eclipse.jdt.internal.compiler.batch.Main;
5352
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
53+
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
5454
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
55+
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
5556
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
5657
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
5758

@@ -170,7 +171,7 @@ public FileSystem getLibraryAccess() {
170171
// we use this to collect information about all used dependencies during
171172
// compilation
172173
FileSystem nameEnvironment = super.getLibraryAccess();
173-
nameEnvironment.nameEnvironmentListener = this::recordNameEnvironmentAnswer;
174+
nameEnvironment.setNameEnvironmentAnswerListener(this::recordNameEnvironmentAnswer);
174175
return nameEnvironment;
175176
}
176177

@@ -214,18 +215,13 @@ protected void recordAnnotationProcessingAndPackageInfo(CompilationResult result
214215
processingModule.recordUnit(builder.build());
215216
}
216217

217-
protected void recordNameEnvironmentAnswer(ClasspathAnswer classpathAnswer) {
218-
Classpath classpath = classpathAnswer.source;
219-
if (classpath instanceof ClasspathLocation) {
220-
String jar = ((ClasspathLocation) classpath).getPath();
218+
protected void recordNameEnvironmentAnswer(NameEnvironmentAnswer answer) {
219+
IBinaryType binaryType = answer.getBinaryType();
220+
if (binaryType != null) {
221+
String jar = extractBinaryTypeJarPath(binaryType);
221222
if (jar != null && jar.endsWith(".jar")) {
222223
Path jarPath = Path.of(jar);
223224
if (processedJars.add(jarPath)) {
224-
// we assume jars come from the execroot; JDT uses absolute/canonical paths
225-
// therefore we translate the path back into an execroot relative path for Bazel
226-
// to be happy
227-
jarPath = sandboxPathPrefix.relativize(jarPath);
228-
229225
// update the dependency proto
230226
if (usedDependencyCollectionMode != UsedDependencyCollectionMode.None) {
231227
if (directJars.contains(jarPath)) {
@@ -640,6 +636,37 @@ public static ClassLoader getPlatformClassLoader() {
640636
}
641637
}
642638

639+
/**
640+
* Extract the jar file path from a binary type URI. The URI of a binary type is generally in this format:
641+
* <pre>
642+
* jar:file://<path to jar>.jar!<path to class>
643+
* </pre>
644+
* We only use URIs that start with "jar:file:///" and containing ".jar!", e.g.:
645+
* <pre>
646+
* jar:file:///.../header_junit-jupiter-api-5.13.3.jar!/org/junit/jupiter/api/Test.class
647+
* </pre>
648+
* The URI format is coming from {@link org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader}, in particular see:
649+
* <ul>
650+
* <li>{@link org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader#read(ZipFile, String, boolean)}</li>
651+
* <li>{@link org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader#toUri(String)}</li>
652+
* </ul>
653+
*
654+
* @param binaryType a jar path is extracted from the URI of this binary type
655+
* @return the path of the binary types jar or {@code null} if the URI didn't match the expected format
656+
*/
657+
private static String extractBinaryTypeJarPath(IBinaryType binaryType) {
658+
URI binaryTypeUri = binaryType.getURI();
659+
String uri= binaryTypeUri.toString();
660+
String prefix = "jar:file:///";
661+
String suffix = ".jar!";
662+
int index = uri.indexOf(".jar!");
663+
String jar = null;
664+
if (uri.startsWith(prefix) && index != -1) {
665+
jar = uri.substring(prefix.length(), index + suffix.length() - 1);
666+
}
667+
return jar;
668+
}
669+
643670
private BlazeEcjMain() {
644671
}
645-
}
672+
}

compiler/src/main/ecj/META-INF/services/javax.tools.JavaCompiler

Lines changed: 0 additions & 1 deletion
This file was deleted.

compiler/src/main/ecj/README.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

compiler/src/main/ecj/about.html

Lines changed: 0 additions & 36 deletions
This file was deleted.

compiler/src/main/ecj/org/eclipse/jdt/core/compiler/CategorizedProblem.java

Lines changed: 0 additions & 179 deletions
This file was deleted.

0 commit comments

Comments
 (0)