8000 Unconditionally add agent in Gradle plugin, add protobuf codegen test by keynmol · Pull Request #630 · sourcegraph/scip-java · GitHub
[go: up one dir, main page]

Skip to content

Unconditionally add agent in Gradle plugin, add protobuf codegen test #630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Unconditionally add agent and deduplicate arguments if necessary
  • Loading branch information
keynmol committed Aug 8, 2023
commit 3f91aadb8bdfd42ed1dd76ce603dcf86e2b892f0
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ public class SemanticdbAgent {

public static void premain(String agentArgs, Instrumentation inst) {
// NOTE(olafur): Uncoment below if you want see all the loaded classes.
// PrintStream logger = newLogger();
// inst.addTransformer(
// new ClassFileTransformer() {
// @Override
// public byte[] transform(
// ClassLoader loader,
// String className,
// Class<?> classBeingRedefined,
// ProtectionDomain protectionDomain,
// byte[] classfileBuffer) {
// logger.println(className);
// return classfileBuffer;
// }
// });
// PrintStream logger = newLogger();
// inst.addTransformer(
// new ClassFileTransformer() {
// @Override
// public byte[] transform(
// ClassLoader loader,
// String className,
// Class<?> classBeingRedefined,
// ProtectionDomain protectionDomain,
// byte[] classfileBuffer) {
// logger.println(className);
// return classfileBuffer;
// }
// });
new AgentBuilder.Default()
.disableClassFormatChanges()
.type(
Expand Down Expand Up @@ -156,6 +156,7 @@ public static void build(
}

boolean isProcessorpathUpdated = false;
boolean semanticdbAlreadyAdded = false;
String previousOption = "";

ArrayList<String> newOptions = new ArrayList<>();
Expand All @@ -172,6 +173,10 @@ public static void build(
case "-Xlint":
break;
default:
if (option.startsWith("-Xplugin:semanticdb")) {
semanticdbAlreadyAdded = true;
break;
}
if (option.startsWith("-Xplugin:ErrorProne")) {
break;
}
Expand All @@ -180,33 +185,36 @@ public static void build(
}
previousOption = option;
}
if (!isProcessorpathUpdated) {
newOptions.add("-classpath");
newOptions.add(PLUGINPATH);
}
newOptions.add(
String.format(
"-Xplugin:semanticdb -sourceroot:%s -targetroot:%s", SOURCEROOT, TARGETROOT));

if (DEBUGPATH != null) {
ArrayList<String> debuglines = new ArrayList<>();
debuglines.add("============== Java Home: " + System.getProperty("java.home"));
debuglines.add("============== Old Options");
debuglines.addAll(arguments);
debuglines.add("============== New Options");
debuglines.addAll(newOptions);
if (!semanticdbAlreadyAdded) {

try {
Files.write(
Paths.get(DEBUGPATH),
debuglines,
StandardOpenOption.CREATE,
StandardOpenOption.APPEND);
} catch (IOException e) {
if (!isProcessorpathUpdated) {
newOptions.add("-classpath");
newOptions.add(PLUGINPATH);
}
}
newOptions.add(
String.format(
"-Xplugin:semanticdb -sourceroot:%s -targetroot:%s", SOURCEROOT, TARGETROOT));

if (DEBUGPATH != null) {
ArrayList<String> debuglines = new ArrayList<>();
debuglines.add("============== Java Home: " + System.getProperty("java.home"));
debuglines.add("============== Old Options");
debuglines.addAll(arguments);
debuglines.add("============== New Options");
debuglines.addAll(newOptions);

arguments = newOptions;
try {
Files.write(
Paths.get(DEBUGPATH),
debuglines,
StandardOpenOption.CREATE,
StandardOpenOption.APPEND);
} catch (IOException e) {
}
}

arguments = newOptions;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class SemanticdbGradlePlugin extends Plugin[Project] {
task.getOptions().setFork(true)
task.getOptions().setIncremental(false)

if (compilerPluginAdded)
if (compilerPluginAdded) {
task
.getOptions()
.getCompilerArgs()
Expand All @@ -169,21 +169,21 @@ class SemanticdbGradlePlugin extends Plugin[Project] {
s"-Xplugin:semanticdb -targetroot:$targetRoot -sourceroot:$sourceRoot"
).asJava
)
else
agentJar.foreach { agentpath =>
javacPluginJar.foreach { pluginpath =>
val jvmArgs = task.getOptions.getForkOptions.getJvmArgs

jvmArgs.addAll(
List(
s"-javaagent:$agentpath",
s"-Dsemanticdb.pluginpath=$pluginpath",
s"-Dsemanticdb.sourceroot=$sourceRoot",
s"-Dsemanticdb.targetroot=$targetRoot"
).asJava
)
}
}
agentJar.foreach { agentpath =>
javacPluginJar.foreach { pluginpath =>
val jvmArgs = task.getOptions.getForkOptions.getJvmArgs

jvmArgs.addAll(
List(
s"-javaagent:$agentpath",
s"-Dsemanticdb.pluginpath=$pluginpath",
s"-Dsemanticdb.sourceroot=$sourceRoot",
s"-Dsemanticdb.targetroot=$targetRoot"
).asJava
)
}
}

}
}
Expand Down
0