Skip to content
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

[Gradle JDK automanagment] GradleWrapperMain patching #341

Merged
merged 73 commits into from May 17, 2024

Conversation

crogoz
Copy link
Contributor

@crogoz crogoz commented Apr 5, 2024

Before this PR

After this PR

Part of: #333

Workflow changes:

Modifies GradleWrapperMain when running ./gradlew wrapper:

  • extracts gradle-wrapper.jar content into a new directory
  • renames the old class GradleWrapperMain into OriginalGradleWrapperMain using ASM
  • Creates a new GradleWrapperMain class that delegates the installation of the jdks (see explanation below) to the ./gradle/gradle-jdks-setup.sh script
  • Disables the auto-provisioning of the JDKs (gradle doc)& the autodetection(gradle docs)
  • Sets the custom toolchain installation paths (gradle docs) to the installed jdks.
  • creates the new gradle-wrapper.jar file

Modifies ./gradle/gradle-jdks-setup.sh script:

  • installs all the jdks that are configured in the gradle/jdks configuration directory
  • appends a property(running.from.gradlew) to the GradlwWrapperMain args; this ensures that if GradleWrapperMain was already called through ./gradlew we won't need to do any extra setup.

Modifies the ./gradlew patch to include the running.from.gradlew property

Implementation changes:

  • new subproject gradle-jdks-setup-common that groups the classes (CurrentOs/CurrentArch/Os/Arch/CommandRunner etc.). It will be added in the fatJar gradle-jdks-setup-all*.jar

==COMMIT_MSG==
[Gradle JDK automanagment] GradleWrapperMain patching logic
==COMMIT_MSG==

Possible downsides?

@crogoz crogoz marked this pull request as ready for review May 2, 2024 13:13
@crogoz crogoz requested a review from CRogers May 2, 2024 13:13
@crogoz crogoz changed the title WIP [Gradle JDK automanagment] GradleWrapperMain patching [Gradle JDK automanagment] GradleWrapperMain patching May 2, 2024
// Set the daemon Java Home
String osName = CurrentOs.get().uiName();
String archName = CurrentArch.get().uiName();
Path daemonKdkMajorVersionPath = projectHome.resolve("gradle/gradle-daemon-jdk-version");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

daemonJdk?

}
for (File file : files) {
if (file.isDirectory()) {
paths.addAll(getAllInstallationsPaths(file, gradleJdksInstallationDir, localPathPattern));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to use Files.walk or Files.visitFileTree here rather than manually doing the recursive file exploration.

Copy link
Contributor

@CRogers CRogers May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, why is this searching the file tree - shouldn't the installation path be at a fixed known location inside $projectRoot/gradle/jdks/....? Why do the file searching?

.getCodeSource()
.getLocation()
.toURI();
} catch (URISyntaxException var3) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably give this a better name than var3, even if it's e (was this copied from a decompiler?)

} else {
try {
return Paths.get(location);
} catch (NoClassDefFoundError var2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -14,13 +14,16 @@ dependencies {
api project(':gradle-jdks-distributions')
api project(':gradle-jdks-json')
api project(':gradle-jdks-setup')
api project(':gradle-jdks-setup-common')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think because the files that were moved to gradle-jdks-setup-common were originally in gradle-jdks-distributions, we should make it an api dep from gradle-jdks-distributions not here?

@@ -66,4 +69,5 @@ tasks.withType(JavaCompile).configureEach {

tasks.test {
environment("PROJECT_VERSION", project.version)
dependsOn ':gradle-jdks-setup:fatJar'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GradleJdkInstallationSetupIntegrationTest is inside the integrationTest source set, so I think this dependsOn needs to go on under tasks.named('integrationTest').configure {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that's actually in gradle-jdks-setup

@@ -21,10 +22,23 @@ dependencies {
integrationTestImplementation 'org.assertj:assertj-core'
}

task fatJar(type: Jar) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well use tasks.register('fatJar', Jar) { for Gradle best practices.

tasks.withType(JavaCompile) {
options.errorprone.disable 'PreferSafeLoggableExceptions'
}

tasks.integrationTest {
environment("PROJECT_VERSION", project.version)
}

tasks.build.dependsOn tasks.fatJar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are we going to ship the fat jar to people? I guess we don't have the code in the plugin to do this yet (?), but I imagine we're either going to include the fat jar as a resource or download it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, we don't have yet the code in the plugin to do this yet.
I think it needs to be distributed alongside "./gradle-jdks.setup.sh" and the "gradle/" files. I was thinking of downloading it (similar how the wrapper.jar gets added to a project). I'll do this in the next PR.

@bulldozer-bot bulldozer-bot bot merged commit 11fb6b3 into develop May 17, 2024
6 checks passed
@bulldozer-bot bulldozer-bot bot deleted the cr/patching2 branch May 17, 2024 15:52
@svc-autorelease
Copy link
Collaborator

Released 0.38.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants