Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ maven.install(
"com.google.auto.value:auto-value-annotations:1.11.0",
"com.google.code.findbugs:jsr305:3.0.2",
"com.github.ben-manes.caffeine:caffeine:3.2.1",
"org.eclipse.jdt:ecj:3.42.0",
# ASM (needed for coverage together with Jacoco)
"org.ow2.asm:asm:9.7.1",
"org.ow2.asm:asm-analysis:9.7.1",
Expand Down
16 changes: 1 addition & 15 deletions compiler/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ java_library(
],
deps = [
"@bazel_org_jacoco_core//jar",
":ecj",
":work_request_handlers",
"//compiler/src/main/protobuf:deps_java_proto",
"//compiler/src/main/protobuf:java_compilation_java_proto",
Expand All @@ -46,23 +45,10 @@ java_library(
"@maven//:com_github_ben_manes_caffeine_caffeine",
"@maven//:com_google_guava_guava",
"@maven//:com_google_code_findbugs_jsr305",
"@maven//:org_eclipse_jdt_ecj",
],
plugins = [
java_plugin_artifact("com.google.auto.value:auto-value", "com.google.auto.value.processor.AutoValueProcessor"),
],
)

# Eclipse Java Compiler
java_library(
name = "ecj",
srcs = glob(["src/main/ecj/**/*.java"]),
javacopts = [
"-nowarn",
"-XepDisableAllChecks",
],
resource_strip_prefix = "compiler/src/main/ecj/",
resources = glob(
["src/main/ecj/**"],
exclude = ["**/*.java"],
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URI;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -47,11 +48,11 @@
import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
import org.eclipse.jdt.internal.compiler.batch.ClasspathLocation;
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
import org.eclipse.jdt.internal.compiler.batch.FileSystem.ClasspathAnswer;
import org.eclipse.jdt.internal.compiler.batch.Main;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;

Expand Down Expand Up @@ -170,7 +171,7 @@ public FileSystem getLibraryAccess() {
// we use this to collect information about all used dependencies during
// compilation
FileSystem nameEnvironment = super.getLibraryAccess();
nameEnvironment.nameEnvironmentListener = this::recordNameEnvironmentAnswer;
nameEnvironment.setNameEnvironmentAnswerListener(this::recordNameEnvironmentAnswer);
return nameEnvironment;
}

Expand Down Expand Up @@ -214,18 +215,13 @@ protected void recordAnnotationProcessingAndPackageInfo(CompilationResult result
processingModule.recordUnit(builder.build());
}

protected void recordNameEnvironmentAnswer(ClasspathAnswer classpathAnswer) {
Classpath classpath = classpathAnswer.source;
if (classpath instanceof ClasspathLocation) {
String jar = ((ClasspathLocation) classpath).getPath();
protected void recordNameEnvironmentAnswer(NameEnvironmentAnswer answer) {
IBinaryType binaryType = answer.getBinaryType();
if (binaryType != null) {
String jar = extractBinaryTypeJarPath(binaryType);
if (jar != null && jar.endsWith(".jar")) {
Path jarPath = Path.of(jar);
if (processedJars.add(jarPath)) {
// we assume jars come from the execroot; JDT uses absolute/canonical paths
// therefore we translate the path back into an execroot relative path for Bazel
// to be happy
jarPath = sandboxPathPrefix.relativize(jarPath);

// update the dependency proto
if (usedDependencyCollectionMode != UsedDependencyCollectionMode.None) {
if (directJars.contains(jarPath)) {
Expand Down Expand Up @@ -640,6 +636,37 @@ public static ClassLoader getPlatformClassLoader() {
}
}

/**
* Extract the jar file path from a binary type URI. The URI of a binary type is generally in this format:
* <pre>
* jar:file://<path to jar>.jar!<path to class>
* </pre>
* We only use URIs that start with "jar:file:///" and containing ".jar!", e.g.:
* <pre>
* jar:file:///.../header_junit-jupiter-api-5.13.3.jar!/org/junit/jupiter/api/Test.class
* </pre>
* The URI format is coming from {@link org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader}, in particular see:
* <ul>
* <li>{@link org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader#read(ZipFile, String, boolean)}</li>
* <li>{@link org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader#toUri(String)}</li>
* </ul>
*
* @param binaryType a jar path is extracted from the URI of this binary type
* @return the path of the binary types jar or {@code null} if the URI didn't match the expected format
*/
private static String extractBinaryTypeJarPath(IBinaryType binaryType) {
URI binaryTypeUri = binaryType.getURI();
String uri= binaryTypeUri.toString();
String prefix = "jar:file:///";
String suffix = ".jar!";
int index = uri.indexOf(".jar!");
String jar = null;
if (uri.startsWith(prefix) && index != -1) {
jar = uri.substring(prefix.length(), index + suffix.length() - 1);
}
return jar;
}

private BlazeEcjMain() {
}
}
}

This file was deleted.

19 changes: 0 additions & 19 deletions compiler/src/main/ecj/README.md

This file was deleted.

36 changes: 0 additions & 36 deletions compiler/src/main/ecj/about.html

This file was deleted.

This file was deleted.

Loading