-
Notifications
You must be signed in to change notification settings - Fork 5
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
Set JAVA_HOME
in gradle-jdks-setup script
#447
Changes from 12 commits
d2fab83
bcbcb4b
b97f469
1cf1a67
4cdd6c7
39acc92
e269cf6
6794c75
fa57ae2
8c2a628
0726559
b6bb8d8
6f1043b
6f9a3e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type: fix | ||
fix: | ||
description: gradle-jdks-setup.sh script sets `JAVA_HOME` to gradle JDK | ||
links: | ||
- https://github.com/palantir/gradle-jdks/pull/447 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,6 @@ | |
import com.palantir.gradle.jdks.setup.common.CurrentArch; | ||
import com.palantir.gradle.jdks.setup.common.Os; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
@@ -46,27 +45,26 @@ public class GradleJdkInstallationSetupIntegrationTest { | |
private static final AmazonCorrettoJdkDistribution CORRETTO_JDK_DISTRIBUTION = new AmazonCorrettoJdkDistribution(); | ||
private static final boolean DO_NOT_INSTALL_CURL = false; | ||
private static final boolean INSTALL_CURL = true; | ||
private static final CaResources caResources = new CaResources(new StdLogger()); | ||
|
||
@TempDir | ||
private Path workingDir; | ||
|
||
@Test | ||
public void can_setup_jdk_with_certs_centos() throws IOException, InterruptedException { | ||
setupGradleDirectoryStructure(Os.LINUX_GLIBC); | ||
assertJdkWithNoCertsWasSetUp(dockerBuildAndRunTestingScript("centos:7", "/bin/bash", DO_NOT_INSTALL_CURL)); | ||
dockerBuildAndRunTestingScript("centos:7", "/bin/bash", DO_NOT_INSTALL_CURL); | ||
} | ||
|
||
@Test | ||
public void can_setup_jdk_with_certs_ubuntu() throws IOException, InterruptedException { | ||
setupGradleDirectoryStructure(Os.LINUX_GLIBC); | ||
assertJdkWithNoCertsWasSetUp(dockerBuildAndRunTestingScript("ubuntu:20.04", "/bin/bash", INSTALL_CURL)); | ||
dockerBuildAndRunTestingScript("ubuntu:20.04", "/bin/bash", INSTALL_CURL); | ||
} | ||
|
||
@Test | ||
public void can_setup_jdk_with_certs_alpine() throws IOException, InterruptedException { | ||
setupGradleDirectoryStructure(Os.LINUX_MUSL); | ||
assertJdkWithNoCertsWasSetUp(dockerBuildAndRunTestingScript("alpine:3.16.0", "/bin/sh", DO_NOT_INSTALL_CURL)); | ||
dockerBuildAndRunTestingScript("alpine:3.16.0", "/bin/sh", DO_NOT_INSTALL_CURL); | ||
} | ||
|
||
private Path setupGradleDirectoryStructure(Os os) throws IOException { | ||
|
@@ -134,28 +132,14 @@ private Path setupGradleDirectoryStructure(Os os) throws IOException { | |
// copy the testing script to the working directory | ||
Files.copy(Path.of("src/integrationTest/resources/testing-script.sh"), workingDir.resolve("testing-script.sh")); | ||
|
||
// copy the certs to the working directory | ||
caResources | ||
.readPalantirRootCaFromSystemTruststore() | ||
.map(AliasContentCert::getContent) | ||
.ifPresent(content -> { | ||
try { | ||
Files.write(workingDir.resolve("palantir.crt"), content.getBytes(StandardCharsets.UTF_8)); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to write cert", e); | ||
} | ||
}); | ||
Comment on lines
-138
to
-147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No longer need this as we just read certs from the system truststore right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||
|
||
Files.copy(Path.of("src/integrationTest/resources/example.com.crt"), workingDir.resolve("example.com.crt")); | ||
|
||
return gradleDirectory; | ||
} | ||
|
||
private static void writeFileContent(Path path, String content) throws IOException { | ||
Files.writeString(path, content + "\n"); | ||
} | ||
|
||
private String dockerBuildAndRunTestingScript(String baseImage, String shell, boolean installCurl) | ||
private void dockerBuildAndRunTestingScript(String baseImage, String shell, boolean installCurl) | ||
throws IOException, InterruptedException { | ||
Path dockerFile = Path.of("src/integrationTest/resources/template.Dockerfile"); | ||
String dockerImage = String.format("jdk-test-%s", baseImage); | ||
|
@@ -173,7 +157,10 @@ private String dockerBuildAndRunTestingScript(String baseImage, String shell, bo | |
"-f", | ||
dockerFile.toAbsolutePath().toString(), | ||
workingDir.toAbsolutePath().toString())); | ||
return runCommandWithZeroExitCode(List.of("docker", "run", "--rm", dockerImage, shell, "/testing-script.sh")); | ||
assertThat(runCommandWithZeroExitCode( | ||
List.of("docker", "run", "--rm", dockerImage, shell, "/testing-script.sh"))) | ||
.contains("openjdk version \"21.0.4\"") | ||
.contains("JAVA_HOME is set to /root/.gradle/gradle-jdks/amazon-corretto-11.0.21.9.1"); | ||
} | ||
|
||
private static String runCommandWithZeroExitCode(List<String> commandArguments) | ||
|
@@ -193,12 +180,4 @@ private static String runCommandWithZeroExitCode(List<String> commandArguments, | |
.isEqualTo(0); | ||
return output; | ||
} | ||
|
||
private static void assertJdkWithNoCertsWasSetUp(String output) { | ||
assertThat(output).contains("Corretto-11.0.21.9.1").contains("Example.com cert: gradleJdks_example.com"); | ||
|
||
if (caResources.readPalantirRootCaFromSystemTruststore().isPresent()) { | ||
assertThat(output).contains("Palantir cert: gradlejdks_palantir3rd-generationrootca"); | ||
} | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,18 @@ | |
set -e | ||
|
||
/root/.gradle/gradle-jdks/amazon-corretto-11.0.21.9.1/bin/java -version | ||
if [ -f /palantir.crt ];then | ||
echo "Palantir cert:" $(/root/.gradle/gradle-jdks/amazon-corretto-11.0.21.9.1/bin/keytool -keystore /root/.gradle/gradle-jdks/amazon-corretto-11.0.21.9.1/lib/security/cacerts -list -alias gradlejdks_palantir3rd-generationrootca -storepass changeit) | ||
# Running again the gradle-jdk-setup to check the JAVA_HOME. | ||
|
||
# >>> Gradle JDK setup >>> | ||
# !! Contents within this block are managed by 'palantir/gradle-jdks' !! | ||
if [ -f gradle/gradle-jdks-setup.sh ]; then | ||
if ! . gradle/gradle-jdks-setup.sh; then | ||
echo "Failed to set up JDK, running gradle/gradle-jdks-setup.sh failed with non-zero exit code" | ||
exit 1 | ||
fi | ||
# Setting JAVA_HOME to the gradle daemon to make sure gradlew uses this jdk for `JAVACMD` | ||
JAVA_HOME="$GRADLE_DAEMON_JDK" | ||
fi | ||
echo "Example.com cert:" $(/root/.gradle/gradle-jdks/amazon-corretto-11.0.21.9.1/bin/keytool -keystore /root/.gradle/gradle-jdks/amazon-corretto-11.0.21.9.1/lib/security/cacerts -list -alias gradleJdks_example.com -storepass changeit) | ||
# <<< Gradle JDK setup <<< | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this manually placed here or is it kept up to date with |
||
|
||
echo "JAVA_HOME is set to: $JAVA_HOME" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,7 @@ gradle_daemon_jdk_distribution_local_path=$(read_value "$APP_GRADLE_DIR"/jdks/"$ | |
"$GRADLE_JDKS_HOME"/"$gradle_daemon_jdk_distribution_local_path"/bin/java -cp "$APP_GRADLE_DIR"/gradle-jdks-setup.jar com.palantir.gradle.jdks.setup.GradleJdkInstallationSetup daemonSetup "$APP_HOME" "$GRADLE_JDKS_HOME/$gradle_daemon_jdk_distribution_local_path" | ||
|
||
# [Used by ./gradlew only] Setting the Gradle Daemon Java Home to the JDK distribution | ||
set -- "-Dorg.gradle.java.home=$GRADLE_JDKS_HOME/$gradle_daemon_jdk_distribution_local_path" "$@" | ||
export GRADLE_DAEMON_JDK="$GRADLE_JDKS_HOME/$gradle_daemon_jdk_distribution_local_path" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not setting the JAVA_HOME directly here as this script is called by the palantir-gradle-jdks intellij plugin as well and I don't think we should modify the JAVA_HOME there (when gradle jdk automanagement is set, then we also set the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am I right in thinking setting JAVA_HOME wouldn't really do anything bad though? We'd set the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not that I think it really matters, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think you are right (I tested this initially inside Intellij) and it seemed fine. But I wouldn't want to add to any confusion if in the end something inside Intellij changes and the java home is somehow used. |
||
set -- "-Dorg.gradle.java.home=$GRADLE_DAEMON_JDK" "$@" | ||
|
||
cleanup |
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.
the integration tests were not running before :(