-
Notifications
You must be signed in to change notification settings - Fork 435
gradle: add java toolchain if missing #5646
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
base: main
Are you sure you want to change the base?
Conversation
@@ -147,6 +211,11 @@ public K.CompilationUnit visitCompilationUnit(K.CompilationUnit cu, ExecutionCon | |||
if (getCursor().pollMessage(TARGET_COMPATIBILITY_FOUND) == null) { | |||
c = addCompatibilityTypeToSourceFile(c, "target", ctx); | |||
} | |||
if (Boolean.TRUE.equals(addToolchainIfMissing)) { | |||
if (getCursor().pollMessage(JAVA_TOOLCHAIN_FOUND) == null) { | |||
// todo : c = addJavaToolchainToSourceFile(c, ctx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This TODO comment needs to be addressed.
@@ -135,6 +149,56 @@ private G.CompilationUnit addCompatibilityTypeToSourceFile(G.CompilationUnit c, | |||
} | |||
return c; | |||
} | |||
|
|||
private G.CompilationUnit addJavaToolchainToSourceFile(G.CompilationUnit c, ExecutionContext ctx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: is there a better way to implement "addJavaToolchainToSourceFile"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is basically what we've done elsewhere. Another option could be a GroovyTemplate (or KotlinTemplate respectively), but overall it's essentially the same.
@Option(displayName = "Add Java toolchain if missing", | ||
description = "Adds the specified Java toolchain if one is not found.", | ||
required = false) | ||
@Nullable | ||
Boolean addToolchainIfMissing; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an idea, but we could possibly use DeclarationStyle as the mechanism to describe how you as a user want the version to be defined. There's already the addIfMissing
option, so that could work as a possibility.
@@ -135,6 +149,56 @@ private G.CompilationUnit addCompatibilityTypeToSourceFile(G.CompilationUnit c, | |||
} | |||
return c; | |||
} | |||
|
|||
private G.CompilationUnit addJavaToolchainToSourceFile(G.CompilationUnit c, ExecutionContext ctx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is basically what we've done elsewhere. Another option could be a GroovyTemplate (or KotlinTemplate respectively), but overall it's essentially the same.
} | ||
newStatements.add(s); | ||
} | ||
c = c.withStatements(newStatements); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we use ListUtils.concat(before, toolchain)
like we do on the other side. It's a little more idiomatic that way.
What's changed?
This PR modifies
It introduces a new recipe option:
When this option is set to true, the recipe will attempt to add a Java toolchain block
to the Gradle build file.
What's your motivation?
I want to be able to add a Java toolchain to a Gradle build file