Skip to content

Commit

Permalink
Use bundled JDK by default when testing in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-vieira authored and costin committed Mar 8, 2023
1 parent dcd2dfc commit 75dfb61
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 24 deletions.
1 change: 0 additions & 1 deletion .ci/java-versions-aarch64.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
# are 'java' or 'openjdk' followed by the major release number.

ES_BUILD_JAVA=jdk17
ES_RUNTIME_JAVA=jdk17
1 change: 0 additions & 1 deletion .ci/java-versions-fips.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
# are 'java' or 'openjdk' followed by the major release number.

ES_BUILD_JAVA=openjdk17
ES_RUNTIME_JAVA=openjdk17
1 change: 0 additions & 1 deletion .ci/java-versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
# are 'java' or 'openjdk' followed by the major release number.

ES_BUILD_JAVA=openjdk17
ES_RUNTIME_JAVA=openjdk17
2 changes: 1 addition & 1 deletion .ci/matrix-runtime-javas-fips.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is used as part of a matrix build in Jenkins where the
# values below are included as an axis of the matrix.

ES_RUNTIME_JAVA:
RUNTIME_JAVA_HOME:
- openjdk17
2 changes: 1 addition & 1 deletion .ci/matrix-runtime-javas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# which Elasticsearch will be tested. Valid Java versions are 'java'
# or 'openjdk' followed by the major release number.

ES_RUNTIME_JAVA:
RUNTIME_JAVA_HOME:
- graalvm-ce17
- openjdk17
- openjdk18
Expand Down
2 changes: 0 additions & 2 deletions .ci/scripts/packaging-test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdent

$AppProps = ConvertFrom-StringData (Get-Content .ci/java-versions.properties -raw)
$env:ES_BUILD_JAVA=$AppProps.ES_BUILD_JAVA
$env:ES_RUNTIME_JAVA=$AppProps.ES_RUNTIME_JAVA
$env:JAVA_TOOL_OPTIONS=''

$ErrorActionPreference="Stop"
Expand All @@ -23,7 +22,6 @@ Copy-Item .ci/init.gradle -Destination $gradleInit
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Machine")
$env:PATH="C:\Users\jenkins\.java\$env:ES_BUILD_JAVA\bin\;$env:PATH"
$env:JAVA_HOME=$null
$env:SYSTEM_JAVA_HOME="C:\Users\jenkins\.java\$env:ES_RUNTIME_JAVA"
Remove-Item -Recurse -Force \tmp -ErrorAction Ignore
New-Item -ItemType directory -Path \tmp

Expand Down
4 changes: 0 additions & 4 deletions .ci/scripts/packaging-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ sudo useradd vagrant
set -e

. .ci/java-versions.properties
RUNTIME_JAVA_HOME=$HOME/.java/$ES_RUNTIME_JAVA
BUILD_JAVA_HOME=$HOME/.java/$ES_BUILD_JAVA

rm -Rfv $HOME/.gradle/init.d/ && mkdir -p $HOME/.gradle/init.d
Expand Down Expand Up @@ -57,7 +56,6 @@ fi
sudo bash -c 'cat > /etc/sudoers.d/elasticsearch_vars' << SUDOERS_VARS
Defaults env_keep += "ES_JAVA_HOME"
Defaults env_keep += "JAVA_HOME"
Defaults env_keep += "SYSTEM_JAVA_HOME"
SUDOERS_VARS
sudo chmod 0440 /etc/sudoers.d/elasticsearch_vars

Expand All @@ -74,9 +72,7 @@ git config --global --add safe.directory $WORKSPACE
# be explicit about Gradle home dir so we use the same even with sudo
sudo -E env \
PATH=$BUILD_JAVA_HOME/bin:`sudo bash -c 'echo -n $PATH'` \
RUNTIME_JAVA_HOME=`readlink -f -n $RUNTIME_JAVA_HOME` \
--unset=ES_JAVA_HOME \
--unset=JAVA_HOME \
SYSTEM_JAVA_HOME=`readlink -f -n $RUNTIME_JAVA_HOME` \
./gradlew -g $HOME/.gradle --scan --parallel --continue $@

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import org.elasticsearch.gradle.Architecture
import org.elasticsearch.gradle.OS
import org.elasticsearch.gradle.VersionProperties
import org.elasticsearch.gradle.internal.info.BuildParams
import org.elasticsearch.gradle.internal.precommit.ThirdPartyAuditPrecommitPlugin
import org.elasticsearch.gradle.internal.precommit.ThirdPartyAuditTask
import org.elasticsearch.gradle.internal.test.rest.RestTestBasePlugin
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask

Expand Down Expand Up @@ -54,4 +56,12 @@ configure(allprojects) {
}
}
}

project.plugins.withType(ThirdPartyAuditPrecommitPlugin) {
project.getTasks().withType(ThirdPartyAuditTask.class).configureEach {
if (BuildParams.getIsRuntimeJavaHomeSet() == false) {
javaHome.set(providers.provider(() -> "${project.jdks.provisioned_runtime.javaHomePath}"))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.tasks.TaskProvider;

import java.io.File;
import java.nio.file.Path;

public class ThirdPartyAuditPrecommitPlugin extends PrecommitPlugin {
Expand Down Expand Up @@ -61,7 +62,7 @@ public TaskProvider<? extends Task> createTask(Project project) {
}));
t.dependsOn(resourcesTask);
if (BuildParams.getIsRuntimeJavaHomeSet()) {
t.setJavaHome(BuildParams.getRuntimeJavaHome().getPath());
t.getJavaHome().set(project.provider(BuildParams::getRuntimeJavaHome).map(File::getPath));
}
t.getTargetCompatibility().set(project.provider(BuildParams::getRuntimeJavaVersion));
t.setSignatureFile(resourcesDir.resolve("forbidden/third-party-audit.txt").toFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public abstract class ThirdPartyAuditTask extends DefaultTask {

private File signatureFile;

private String javaHome;
private Property<String> javaHome;

private final Property<JavaVersion> targetCompatibility;

Expand All @@ -106,6 +106,7 @@ public ThirdPartyAuditTask(
this.fileSystemOperations = fileSystemOperations;
this.projectLayout = projectLayout;
this.targetCompatibility = objectFactory.property(JavaVersion.class);
this.javaHome = objectFactory.property(String.class);
}

@Input
Expand All @@ -127,16 +128,11 @@ public void setSignatureFile(File signatureFile) {
this.signatureFile = signatureFile;
}

@Input
@Optional
public String getJavaHome() {
@Internal
public Property<String> getJavaHome() {
return javaHome;
}

public void setJavaHome(String javaHome) {
this.javaHome = javaHome;
}

@Internal
public File getJarExpandDir() {
return projectLayout.getBuildDirectory().dir("precommit/thirdPartyAudit").get().dir(getName()).getAsFile();
Expand Down Expand Up @@ -335,8 +331,8 @@ private String formatClassList(Set<String> classList) {
private String runForbiddenAPIsCli() throws IOException {
ByteArrayOutputStream errorOut = new ByteArrayOutputStream();
ExecResult result = execOperations.javaexec(spec -> {
if (javaHome != null) {
spec.setExecutable(javaHome + "/bin/java");
if (javaHome.isPresent()) {
spec.setExecutable(javaHome.get() + "/bin/java");
}
spec.classpath(getForbiddenAPIsClasspath(), classpath);
spec.jvmArgs("-Xmx1g");
Expand Down Expand Up @@ -368,8 +364,8 @@ private Set<String> runJdkJarHellCheck() throws IOException {
spec.getMainClass().set(JDK_JAR_HELL_MAIN_CLASS);
spec.args(getJarExpandDir());
spec.setIgnoreExitValue(true);
if (javaHome != null) {
spec.setExecutable(javaHome + "/bin/java");
if (javaHome.isPresent()) {
spec.setExecutable(javaHome.get() + "/bin/java");
}
spec.setStandardOutput(standardOut);
});
Expand Down

0 comments on commit 75dfb61

Please sign in to comment.