Skip to content

Commit c8b0157

Browse files
committed
Inline scip-gradle-plugin BuildInfo and Logging helpers
1 parent 7d89bd4 commit c8b0157

5 files changed

Lines changed: 53 additions & 117 deletions

File tree

build.sbt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,7 @@ lazy val gradlePlugin = project
9999
List(
100100
"dev.gradleplugins" % "gradle-api" % V.gradle % Provided,
101101
"dev.gradleplugins" % "gradle-test-kit" % V.gradle % Provided
102-
),
103-
// The plugin's BuildInfo.version (the scip-javac Maven coordinate used as a
104-
// fallback when no jar is provided) is read at runtime from this generated
105-
// properties resource, mirroring the scip-java CLI's scip-java.properties.
106-
(Compile / resourceGenerators) +=
107-
Def.task {
108-
val file = (Compile / resourceManaged).value / "scip-gradle.properties"
109-
IO.createDirectory(file.getParentFile)
110-
val props = new Properties()
111-
props.put("version", version.value)
112-
IO.write(props, "scip-gradle", file)
113-
Seq(file)
114-
}.taskValue
102+
)
115103
)
116104

117105
lazy val javacPlugin = project

scip-gradle-plugin/src/main/java/com/sourcegraph/gradle/scip/BuildInfo.java

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

scip-gradle-plugin/src/main/java/com/sourcegraph/gradle/scip/Logging.java

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

scip-gradle-plugin/src/main/java/com/sourcegraph/gradle/scip/ScipGradlePlugin.java

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515

1616
public class ScipGradlePlugin implements Plugin<Project> {
1717

18+
// `--add-exports` flags required so our compiler plugin can access javac
19+
// internals. Required on JDK 17+ (JEP 403), no-op on 11-16. Kept in sync with
20+
// `javacModuleOptions` in build.sbt.
21+
private static final List<String> JAVAC_MODULE_OPTIONS =
22+
List.of(
23+
"-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
24+
"-J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
25+
"-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
26+
"-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
27+
"-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED");
28+
1829
@Override
1930
public void apply(Project project) {
2031
project.afterEvaluate(this::configureProject);
@@ -29,17 +40,6 @@ private void configureProject(Project project) {
2940

3041
Object targetRoot = extraProperties.getOrDefault("scipTarget", project.getBuildDir());
3142

32-
String javacPluginVersion = BuildInfo.version;
33-
34-
Object javacPluginJar = extraProperties.get("javacPluginJar");
35-
36-
// We fall back to the javac plugin published to Maven if there is no jar
37-
// specified. The JAR would usually be provided by the auto-indexer.
38-
Object javacPluginDep =
39-
javacPluginJar != null
40-
? project.files(javacPluginJar)
41-
: "com.sourcegraph:scip-javac:" + javacPluginVersion;
42-
4343
File sourceRoot = project.getRootDir();
4444

4545
// List of compilation commands that we will need to trigger to index all
@@ -61,6 +61,16 @@ private void configureProject(Project project) {
6161

6262
boolean compilerPluginAdded;
6363
try {
64+
// The CLI's init script writes the absolute path of the embedded
65+
// scip-javac jar into the `javacPluginJar` extra property.
66+
Object javacPluginJar = extraProperties.get("javacPluginJar");
67+
if (javacPluginJar == null) {
68+
throw new IllegalStateException(
69+
"javacPluginJar extra property must be set by the "
70+
+ "scip-java init script when indexing Java sources");
71+
}
72+
Object javacPluginDep = project.files(javacPluginJar);
73+
6474
project.getDependencies().add("compileOnly", javacPluginDep);
6575

6676
if (hasAnnotationPath) {
@@ -76,14 +86,16 @@ private void configureProject(Project project) {
7686
// dependencies to it. The project will be skipped (no SCIP output) and
7787
// the post-build check in `GradleBuildTool` will surface a clearer
7888
// error.
79-
Logging.warn(
80-
"scip-java: failed to attach SCIP compiler plugin to project '"
81-
+ project.getName()
82-
+ "' ("
83-
+ exc.getClass().getSimpleName()
84-
+ ": "
85-
+ exc.getMessage()
86-
+ "). This subproject will not be indexed.");
89+
project
90+
.getLogger()
91+
.warn(
92+
"scip-java: failed to attach SCIP compiler plugin to project '"
93+
+ project.getName()
94+
+ "' ("
95+
+ exc.getClass().getSimpleName()
96+
+ ": "
97+
+ exc.getMessage()
98+
+ "). This subproject will not be indexed.");
8799
compilerPluginAdded = false;
88100
}
89101

@@ -98,7 +110,7 @@ private void configureProject(Project project) {
98110
// 11-16.
99111
ForkOptions forkOptions = task.getOptions().getForkOptions();
100112
List<String> jvmArgs =
101-
BuildInfo.javacModuleOptions.stream()
113+
JAVAC_MODULE_OPTIONS.stream()
102114
.map(arg -> arg.startsWith("-J") ? arg.substring(2) : arg)
103115
.collect(Collectors.toList());
104116
if (forkOptions.getJvmArgs() == null) {

scip-gradle-plugin/src/main/java/com/sourcegraph/gradle/scip/WriteDependencies.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,29 +87,31 @@ public void printResolvedDependencies() throws IOException {
8787
publication.getGroupId(),
8888
publication.getArtifactId(),
8989
publication.getVersion());
90-
Logging.warn(
91-
"Failed to extract `main` source set from publication `"
92-
+ publicationName
93-
+ "` in project `"
90+
getLogger()
91+
.warn(
92+
"Failed to extract `main` source set from publication `"
93+
+ publicationName
94+
+ "` in project `"
95+
+ projectName
96+
+ "`.\n"
97+
+ CROSS_REPO_BANNER
98+
+ "\nHere's the raw error message:\n \""
99+
+ exception.getMessage()
100+
+ "\"\nContinuing without cross-repository support.");
101+
}
102+
}
103+
} catch (Exception exception) {
104+
getLogger()
105+
.warn(
106+
"Failed to extract Maven publication from the project `"
94107
+ projectName
95108
+ "`.\n"
96109
+ CROSS_REPO_BANNER
97-
+ "\nHere's the raw error message:\n \""
110+
+ "\nHere's the raw error message ("
111+
+ exception.getClass()
112+
+ "):\n \""
98113
+ exception.getMessage()
99114
+ "\"\nContinuing without cross-repository support.");
100-
}
101-
}
102-
} catch (Exception exception) {
103-
Logging.warn(
104-
"Failed to extract Maven publication from the project `"
105-
+ projectName
106-
+ "`.\n"
107-
+ CROSS_REPO_BANNER
108-
+ "\nHere's the raw error message ("
109-
+ exception.getClass()
110-
+ "):\n \""
111-
+ exception.getMessage()
112-
+ "\"\nContinuing without cross-repository support.");
113115
}
114116

115117
project

0 commit comments

Comments
 (0)