fix #239 - add property javaVersion to support GraalVM 19.3+ (#255)

* fix #239 - add property javaVersion to support GraalVM 19.3+

* fix download / tests that use the new Java version cache subdir

* fix #239 - use VS 2019 for Java 11+ and add Java 11 E2E tests

* fix #239 - add options to specify VS path

* fix #239 - require JDK 8 and JDK 11 tests

* add automatic detection of Visual Studio installation

* update readme.md for the new GraalVM 19.3+ support

* fix #239 - autodetect vs path and throw exception

* fix #239 - detect vs vars path but fail when needed

* fix #239 - rename VS and Windows related variables and method to contain windows for clarity

* format

* changelog

Co-authored-by: David Kirstein <dak@batix.com>
Co-authored-by: Cosmin Polifronie <cosmin.polifronie@gmail.com>
Co-authored-by: Carter Kozak <ckozak@ckozak.net>
This commit is contained in:
Daniel Mühlbachler 2020-05-18 18:16:39 +02:00 committed by GitHub
parent 9fba6125d8
commit 7e9bcf1bbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 873 additions and 43 deletions

View file

View file

@ -0,0 +1,6 @@
type: feature
feature:
description: Add property javaVersion to support GraalVM 19.3+
links:
- https://github.com/palantir/dialogue/pull/255
- https://github.com/palantir/dialogue/pull/239

View file

@ -19,6 +19,25 @@ jobs:
root: .
paths: [ . ]
compile-jdk11:
docker: [{ image: 'circleci/openjdk:11-node' }]
resource_class: medium+
steps:
- checkout
- restore_cache: { key: 'gradle-wrapper-v2-jdk11-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}' }
- restore_cache: { key: 'gradle-cache-v2-jdk11-{{ checksum "versions.props" }}-{{ checksum "build.gradle" }}' }
- run: ./gradlew --profile --parallel --stacktrace resolveConfigurations
- save_cache:
key: 'gradle-wrapper-v2-jdk11-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}'
paths: [ ~/.gradle/wrapper ]
- save_cache:
key: 'gradle-cache-v2-jdk11-{{ checksum "versions.props" }}-{{ checksum "build.gradle" }}'
paths: [ ~/.gradle/caches ]
- run: ./gradlew --profile --parallel --stacktrace classes testClasses
- persist_to_workspace:
root: .
paths: [ . ]
check:
docker: [{ image: 'circleci/openjdk:8-node' }]
resource_class: medium+
@ -27,7 +46,23 @@ jobs:
- restore_cache: { key: 'gradle-wrapper-v2-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}' }
- restore_cache: { key: 'gradle-cache-v2-{{ checksum "versions.props" }}-{{ checksum "build.gradle" }}' }
- restore_cache: { key: 'graal-cache' }
- run: sudo apt-get update && sudo apt-get install build-essential zlib1g-dev
- run: (sudo apt-get update || sudo apt-get update) && sudo apt-get install build-essential zlib1g-dev
- run: ./gradlew --profile --parallel --stacktrace --continue check
- save_cache:
key: 'graal-cache'
paths: [ ~/.gradle/caches/com.palantir.graal ]
- store_test_results: { path: build/test-results }
- store_artifacts: { path: build/reports/tests }
check-jdk11:
docker: [{ image: 'circleci/openjdk:11-node' }]
resource_class: medium+
steps:
- attach_workspace: { at: . }
- restore_cache: { key: 'gradle-wrapper-v2-jdk11-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}' }
- restore_cache: { key: 'gradle-cache-v2-jdk11-{{ checksum "versions.props" }}-{{ checksum "build.gradle" }}' }
- restore_cache: { key: 'graal-cache' }
- run: (sudo apt-get update || sudo apt-get update) && sudo apt-get install build-essential zlib1g-dev
- run: ./gradlew --profile --parallel --stacktrace --continue check
- save_cache:
key: 'graal-cache'
@ -65,10 +100,17 @@ workflows:
requires: [ compile ]
filters: { tags: { only: /.*/ } }
- compile-jdk11:
filters: { tags: { only: /.*/ } }
- check-jdk11:
requires: [ compile-jdk11 ]
filters: { tags: { only: /.*/ } }
- trial-publish:
requires: [ compile ]
- publish:
requires: [ check ]
requires: [ check, check-jdk11 ]
filters: { tags: { only: /.*/ }, branches: { only: develop } }

View file

@ -23,8 +23,14 @@ Configuration
Configure this plugin and its wrappers around GraalVM tools through the `graal` extension with the following options:
**General GraalVM controls**
* `graalVersion`: the version string to use when downloading GraalVM (defaults to `19.2.0`)
* `graalVersion`: the version string to use when downloading GraalVM (defaults to `20.0.0`)
* `downloadBaseUrl`: the base download URL to use (defaults to `https://github.com/oracle/graal/releases/download/`)
* `javaVersion`: the Java version to use (can be either `8` or `11`, defaults to `8`)
* for `8`: Windows SDK 7.1 will be used (`C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd`)
* for `11`: Visual Studio Build Tools will be used (`C:\Program Files (x86)\Microsoft Visual Studio\{version}\\{edition}\\VC\\Auxiliary\\Build\\vcvars64.bat`)
* `windowsVsVersion`: the version of Visual Studio to use (can be either `2017` or `2019`, by default a search will be performed and the newest will be selected)
* `windowsVsEdition`: the edition of Visual Studio to use (can be either `Community`, `Professional` or `Enterprise`, by default a search will be performed and the biggest will be selected)
* `windowsVsVarsPath`: path to vcvars64.bat (optional, if it's set it will disable the 2 searches for `vsVersion` and `vsEdition`)
**`native-image` controls**

View file

@ -28,6 +28,7 @@ import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.file.RegularFile;
import org.gradle.api.file.RegularFileProperty;
@ -47,9 +48,13 @@ public abstract class BaseGraalCompileTask extends DefaultTask {
private final ListProperty<String> options = getProject().getObjects().listProperty(String.class);
private final RegularFileProperty outputFile = getProject().getObjects().fileProperty();
private final Property<String> graalVersion = getProject().getObjects().property(String.class);
private final Property<String> javaVersion = getProject().getObjects().property(String.class);
private final Property<String> windowsVsVarsPath = getProject().getObjects().property(String.class);
private final Property<Configuration> classpath = getProject().getObjects().property(Configuration.class);
private final RegularFileProperty jarFile = getProject().getObjects().fileProperty();
private final Property<Path> cacheDir = getProject().getObjects().property(Path.class);
private final Property<String> graalDirectoryName =
getProject().getObjects().property(String.class);
public BaseGraalCompileTask() {
setGroup(GradleGraalPlugin.TASK_GROUP);
@ -70,7 +75,7 @@ public abstract class BaseGraalCompileTask extends DefaultTask {
protected final String getExecutable() {
return cacheDir.get()
.resolve(Paths.get(graalVersion.get(), "graalvm-ce-" + graalVersion.get()))
.resolve(Paths.get(graalVersion.get(), javaVersion.get(), graalDirectoryName.get()))
.resolve(getArchitectureSpecifiedBinaryPath())
.toFile()
.getAbsolutePath();
@ -146,9 +151,15 @@ public abstract class BaseGraalCompileTask extends DefaultTask {
outputRedirection = " >nul 2>&1";
}
String argsString = spec.getArgs().stream().collect(Collectors.joining(" ", " ", "\r\n"));
if (windowsVsVarsPath.get().isEmpty()) {
throw new GradleException("Couldn't find an installation of Windows SDK 7.1 suitable for GraalVM.");
}
String argsString =
spec.getArgs().stream().map(s -> "\"" + s + "\"").collect(Collectors.joining(" ", " ", "\r\n"));
String command = "call \"" + windowsVsVarsPath.get() + "\"";
String cmdContent = "@echo off\r\n"
+ "call \"C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Bin\\SetEnv.cmd\""
+ command
+ outputRedirection + "\r\n"
+ "\"" + spec.getExecutable() + "\"" + argsString;
Path buildPath = getProject().getBuildDir().toPath();
@ -197,6 +208,24 @@ public abstract class BaseGraalCompileTask extends DefaultTask {
graalVersion.set(provider);
}
@Input
public final Provider<String> getJavaVersion() {
return javaVersion;
}
public final void setJavaVersion(Provider<String> provider) {
javaVersion.set(provider);
}
@Input
public final Provider<String> getWindowsVsVarsPath() {
return windowsVsVarsPath;
}
public final void setWindowsVsVarsPath(Provider<String> provider) {
windowsVsVarsPath.set(provider);
}
@InputFiles
@Classpath
public final Provider<Configuration> getClasspath() {
@ -229,6 +258,10 @@ public abstract class BaseGraalCompileTask extends DefaultTask {
cacheDir.set(value);
}
final void setGraalDirectoryName(String value) {
graalDirectoryName.set(value);
}
public final void setOptions(Provider<List<String>> options) {
this.options.set(options);
}

View file

@ -35,13 +35,14 @@ public class DownloadGraalTask extends DefaultTask {
// RC versions don't have a windows variant, so no [ext] is needed
private static final String ARTIFACT_PATTERN_RC_VERSION =
"[url]/vm-[version]/graalvm-ce-[version]-[os]-[arch].tar.gz";
"[url]/vm-[version]/graalvm-ce-[javaVersion]-[version]-[os]-[arch].tar.gz";
private static final String ARTIFACT_PATTERN_RELEASE_VERSION =
"[url]/vm-[version]/graalvm-ce-[os]-[arch]-[version].[ext]";
"[url]/vm-[version]/graalvm-ce-[javaVersion]-[os]-[arch]-[version].[ext]";
private static final String FILENAME_PATTERN = "graalvm-ce-[version]-[arch].[ext]";
private static final String FILENAME_PATTERN = "graalvm-ce-[javaVersion]-[version]-[arch].[ext]";
private final Property<String> graalVersion = getProject().getObjects().property(String.class);
private final Property<String> javaVersion = getProject().getObjects().property(String.class);
private final Property<String> downloadBaseUrl = getProject().getObjects().property(String.class);
private final Property<Path> cacheDir = getProject().getObjects().property(Path.class);
@ -54,8 +55,7 @@ public class DownloadGraalTask extends DefaultTask {
@TaskAction
public final void downloadGraal() throws IOException {
Path cache = getCacheSubdirectory().get();
Files.createDirectories(cache);
Files.createDirectories(getArchive().get().getAsFile().toPath().getParent());
final String artifactPattern =
isGraalRcVersion() ? ARTIFACT_PATTERN_RC_VERSION : ARTIFACT_PATTERN_RELEASE_VERSION;
@ -67,7 +67,8 @@ public class DownloadGraalTask extends DefaultTask {
@OutputFile
public final Provider<RegularFile> getArchive() {
return getProject().getLayout().file(getCacheSubdirectory().map(dir -> dir.resolve(render(FILENAME_PATTERN))
return getProject().getLayout().file(getCacheSubdirectory().map(dir -> dir.resolve(javaVersion.get())
.resolve(render(FILENAME_PATTERN))
.toFile()));
}
@ -80,6 +81,15 @@ public class DownloadGraalTask extends DefaultTask {
graalVersion.set(provider);
}
@Input
public final Provider<String> getJavaVersion() {
return javaVersion;
}
public final void setJavaVersion(Provider<String> provider) {
javaVersion.set(provider);
}
@Input
public final Provider<String> getDownloadBaseUrl() {
return downloadBaseUrl;
@ -94,11 +104,16 @@ public class DownloadGraalTask extends DefaultTask {
}
private String render(String pattern) {
final String computedJavaVersion = GraalVersionUtil.isGraalVersionGreatherThan19_3(graalVersion.get())
? "java" + javaVersion.get()
: ""; // for GraalVM >= 19.3 the naming contains java8 or java11
return pattern.replaceAll("\\[url\\]", downloadBaseUrl.get())
.replaceAll("\\[version\\]", graalVersion.get())
.replaceAll("\\[javaVersion\\]", computedJavaVersion)
.replaceAll("\\[os\\]", getOperatingSystem())
.replaceAll("\\[arch\\]", getArchitecture())
.replaceAll("\\[ext\\]", getArchiveExtension());
.replaceAll("\\[ext\\]", getArchiveExtension())
.replaceAll("--", "-"); // for GraalVM < 19.3 there's only a Java8 package
}
private String getOperatingSystem() {

View file

@ -45,8 +45,11 @@ public class ExtractGraalTask extends DefaultTask {
private final RegularFileProperty inputArchive = getProject().getObjects().fileProperty();
private final Property<String> graalVersion = getProject().getObjects().property(String.class);
private final Property<String> javaVersion = getProject().getObjects().property(String.class);
private final DirectoryProperty outputDirectory = getProject().getObjects().directoryProperty();
private final Property<Path> cacheDir = getProject().getObjects().property(Path.class);
private final Property<String> graalDirectoryName =
getProject().getObjects().property(String.class);
public ExtractGraalTask() {
setGroup(GradleGraalPlugin.TASK_GROUP);
@ -54,12 +57,13 @@ public class ExtractGraalTask extends DefaultTask {
+ " copy method.");
onlyIf(task -> !getOutputDirectory().get().getAsFile().exists());
outputDirectory.set(graalVersion.map(v -> getProject()
outputDirectory.set(cacheDir.map(cd -> getProject()
.getLayout()
.getProjectDirectory()
.dir(cacheDir.get().toFile().getAbsolutePath())
.dir(v)
.dir("graalvm-ce-" + v)));
.dir(graalVersion.get())
.dir(javaVersion.get())
.dir(graalDirectoryName.get())));
}
@TaskAction
@ -70,7 +74,7 @@ public class ExtractGraalTask extends DefaultTask {
Project project = getProject();
File inputArchiveFile = inputArchive.get().getAsFile();
Path versionedCacheDir = cacheDir.get().resolve(graalVersion.get());
Path versionedCacheDir = cacheDir.get().resolve(Paths.get(graalVersion.get(), javaVersion.get()));
if (inputArchiveFile.getName().endsWith(".zip")) {
project.copy(copySpec -> {
@ -113,7 +117,7 @@ public class ExtractGraalTask extends DefaultTask {
}
return cacheDir.get()
.resolve(Paths.get(graalVersion.get(), "graalvm-ce-" + graalVersion.get()))
.resolve(Paths.get(graalVersion.get(), javaVersion.get(), graalDirectoryName.get()))
.resolve(getArchitectureSpecifiedBinaryPath(binaryName + binaryExtension))
.toFile();
}
@ -148,6 +152,15 @@ public class ExtractGraalTask extends DefaultTask {
graalVersion.set(provider);
}
@Input
public final Provider<String> getJavaVersion() {
return javaVersion;
}
public final void setJavaVersion(Provider<String> provider) {
javaVersion.set(provider);
}
@OutputDirectory
public final Provider<Directory> getOutputDirectory() {
return outputDirectory;
@ -156,4 +169,8 @@ public class ExtractGraalTask extends DefaultTask {
final void setCacheDir(Path value) {
cacheDir.set(value);
}
final void setGraalDirectoryName(String value) {
graalDirectoryName.set(value);
}
}

View file

@ -0,0 +1,44 @@
/*
* (c) Copyright 2018 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.palantir.gradle.graal;
import java.io.File;
import java.util.AbstractSet;
import java.util.HashSet;
import java.util.List;
public final class FileUtil {
public static String getFirstFromDirectory(File directory, List<String> searchList) {
if (!directory.exists()) {
return null;
}
AbstractSet<String> subDirectoriesNames = new HashSet<String>();
File[] subDirectories = directory.listFiles(File::isDirectory);
for (File subDirectory : subDirectories) {
subDirectoriesNames.add(subDirectory.getName());
}
for (String stringToSearch : searchList) {
if (subDirectoriesNames.contains(stringToSearch)) {
return stringToSearch;
}
}
return null;
}
private FileUtil() {}
}

View file

@ -16,6 +16,8 @@
package com.palantir.gradle.graal;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
@ -23,14 +25,33 @@ import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
/** Contains options and settings for tuning GraalVM use. */
/**
* Contains options and settings for tuning GraalVM use.
*/
public class GraalExtension {
private static final String WINDOWS_7_ENV_PATH =
"C:\\Program Files\\Microsoft SDKs\\" + "Windows\\v7.1\\Bin\\SetEnv.cmd";
private static final List<String> SUPPORTED_WINDOWS_VS_VERSIONS = Arrays.asList("2019", "2017");
private static final List<String> SUPPORTED_WINDOWS_VS_EDITIONS =
Arrays.asList("Enterprise", "Professional", "Community");
private static final String DEFAULT_WINDOWS_VS_PATH = "C:\\Program Files (x86)\\" + "Microsoft Visual Studio";
private static final String DEFAULT_WINDOWS_VS_VARS_PATH = "C:\\Program Files (x86)\\Microsoft Visual Studio\\"
+ "{version}\\{edition}\\VC\\Auxiliary\\"
+ "Build\\vcvars64.bat";
private static final String DEFAULT_DOWNLOAD_BASE_URL = "https://github.com/oracle/graal/releases/download/";
private static final String DEFAULT_GRAAL_VERSION = "19.2.0";
private static final String DOWNLOAD_BASE_URL_GRAAL_19_3 =
"https://github.com/graalvm/graalvm-ce-builds/" + "releases/download/";
private static final String DEFAULT_GRAAL_VERSION = "20.0.0";
private static final List<String> SUPPORTED_JAVA_VERSIONS = Arrays.asList("11", "8");
private static final String DEFAULT_JAVA_VERSION = "8";
private final Property<String> downloadBaseUrl;
private final Property<String> graalVersion;
private final Property<String> javaVersion;
private final Property<String> windowsVsVarsPath;
private final Property<String> windowsVsVersion;
private final Property<String> windowsVsEdition;
private final Property<String> mainClass;
private final Property<String> outputName;
private final ListProperty<String> options;
@ -38,13 +59,17 @@ public class GraalExtension {
public GraalExtension(Project project) {
downloadBaseUrl = project.getObjects().property(String.class);
graalVersion = project.getObjects().property(String.class);
javaVersion = project.getObjects().property(String.class);
windowsVsVarsPath = project.getObjects().property(String.class);
windowsVsVersion = project.getObjects().property(String.class);
windowsVsEdition = project.getObjects().property(String.class);
mainClass = project.getObjects().property(String.class);
outputName = project.getObjects().property(String.class);
options = project.getObjects().listProperty(String.class).empty(); // .empty() required to initialize
// defaults
downloadBaseUrl.set(DEFAULT_DOWNLOAD_BASE_URL);
graalVersion.set(DEFAULT_GRAAL_VERSION);
javaVersion.set(DEFAULT_JAVA_VERSION);
}
public final void downloadBaseUrl(String value) {
@ -54,17 +79,20 @@ public class GraalExtension {
/**
* Returns the base URL to use for downloading GraalVM binaries.
*
* <p>Defaults to {@link #DEFAULT_DOWNLOAD_BASE_URL}.</p>
* <p>Defaults to {@link #DEFAULT_DOWNLOAD_BASE_URL} for GraalVM lower than 19.3.</p>
* <p>Defaults to {@link #DOWNLOAD_BASE_URL_GRAAL_19_3} for GraalVM higher or equal to 19.3.</p>
*/
public final Provider<String> getDownloadBaseUrl() {
return downloadBaseUrl;
return downloadBaseUrl.orElse(getDefaultDownloadBaseUrl());
}
public final void mainClass(String value) {
mainClass.set(value);
}
/** Returns the main class to use as the entry point to the generated executable file. */
/**
* Returns the main class to use as the entry point to the generated executable file.
*/
public final Provider<String> getMainClass() {
return mainClass;
}
@ -86,6 +114,78 @@ public class GraalExtension {
graalVersion.set(value);
}
/**
* Returns the javaVersion for GraalVM to use.
*
* <p>Defaults to {@link #DEFAULT_JAVA_VERSION}</p>
*/
public final Provider<String> getJavaVersion() {
return javaVersion;
}
public final void javaVersion(String value) {
if (!SUPPORTED_JAVA_VERSIONS.contains(value)) {
throw new GradleException(
"Java version " + value + " is not supported. Supported versions are: " + SUPPORTED_JAVA_VERSIONS);
}
javaVersion.set(value);
}
/**
* Returns the VS 64-bit Variables Path to use.
*
* <p>Defaults to {@link #DEFAULT_WINDOWS_VS_VARS_PATH} for JDK higher or equal to 11</p>
* <p>Defaults to {@link #WINDOWS_7_ENV_PATH} for JDK lower than 11</p>
*/
public final Provider<String> getWindowsVsVarsPath() {
return windowsVsVarsPath.orElse(searchWindowsVsVarsPath());
}
private String searchWindowsVsVarsPath() {
String searchedVsVersion = windowsVsVersion.getOrElse(getNewestWindowsVsVersionInstalled());
String searchedVsEdition = windowsVsEdition.getOrElse(getBiggestWindowsVsEditionInstalled(searchedVsVersion));
if (searchedVsEdition == null || searchedVsVersion == null) {
return "";
}
String searchedVsVarsPath = Integer.parseInt(javaVersion.get()) >= 11
? DEFAULT_WINDOWS_VS_VARS_PATH
.replaceAll("\\{version}", searchedVsVersion)
.replaceAll("\\{edition}", searchedVsEdition)
: WINDOWS_7_ENV_PATH;
if (WINDOWS_7_ENV_PATH.equals(searchedVsVarsPath)) {
if (!new File(WINDOWS_7_ENV_PATH).exists()) {
return "";
}
}
return searchedVsVarsPath;
}
private String getNewestWindowsVsVersionInstalled() {
return FileUtil.getFirstFromDirectory(new File(DEFAULT_WINDOWS_VS_PATH), SUPPORTED_WINDOWS_VS_VERSIONS);
}
private String getBiggestWindowsVsEditionInstalled(String version) {
if (version == null) {
return null;
}
return FileUtil.getFirstFromDirectory(
new File(DEFAULT_WINDOWS_VS_PATH, version), SUPPORTED_WINDOWS_VS_EDITIONS);
}
public final void windowsVsVarsPath(String value) {
windowsVsVarsPath.set(value);
}
public final void windowsVsVersion(String value) {
windowsVsVersion.set(value);
}
public final void windowsVsEdition(String value) {
windowsVsEdition.set(value);
}
/**
* Returns the graalVersion of GraalVM to use.
*
@ -96,7 +196,7 @@ public class GraalExtension {
}
public final Provider<List<String>> getOptions() {
return this.options;
return options;
}
/**
@ -108,4 +208,21 @@ public class GraalExtension {
}
this.options.add(option);
}
public final String getGraalDirectoryName() {
if (GraalVersionUtil.isGraalVersionGreatherThan19_3(graalVersion.get())) {
return "graalvm-ce-java" + javaVersion.get() + "-" + graalVersion.get();
}
return "graalvm-ce-" + graalVersion.get();
}
private String getDefaultDownloadBaseUrl() {
if (GraalVersionUtil.isGraalVersionGreatherThan19_3(graalVersion.get())) {
return DOWNLOAD_BASE_URL_GRAAL_19_3;
} else if (!javaVersion.get().equals("8")) {
throw new GradleException("Unsupported Java version for GraalVM version.");
}
return DEFAULT_DOWNLOAD_BASE_URL;
}
}

View file

@ -0,0 +1,32 @@
/*
* (c) Copyright 2018 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.palantir.gradle.graal;
public final class GraalVersionUtil {
public static boolean isGraalVersionGreatherThan19_3(String graalVersion) {
try {
final String[] versionSplit = graalVersion.split("\\.", -1);
final int majorVersion = Integer.valueOf(versionSplit[0]);
final int minorVersion = Integer.valueOf(versionSplit[1]);
return majorVersion > 19 || (majorVersion == 19 && minorVersion >= 3);
} catch (NumberFormatException ignored) {
return false;
}
}
private GraalVersionUtil() {}
}

View file

@ -62,6 +62,7 @@ public class GradleGraalPlugin implements Plugin<Project> {
TaskProvider<DownloadGraalTask> downloadGraal = project.getTasks()
.register("downloadGraalTooling", DownloadGraalTask.class, task -> {
task.setGraalVersion(extension.getGraalVersion());
task.setJavaVersion(extension.getJavaVersion());
task.setDownloadBaseUrl(extension.getDownloadBaseUrl());
task.setCacheDir(cacheDir);
});
@ -69,8 +70,10 @@ public class GradleGraalPlugin implements Plugin<Project> {
TaskProvider<ExtractGraalTask> extractGraal = project.getTasks()
.register("extractGraalTooling", ExtractGraalTask.class, task -> {
task.setGraalVersion(extension.getGraalVersion());
task.setJavaVersion(extension.getJavaVersion());
task.setInputArchive(downloadGraal.get().getArchive());
task.setCacheDir(cacheDir);
task.setGraalDirectoryName(extension.getGraalDirectoryName());
task.dependsOn(downloadGraal);
});
@ -79,9 +82,12 @@ public class GradleGraalPlugin implements Plugin<Project> {
task.setMainClass(extension.getMainClass());
task.setOutputName(extension.getOutputName());
task.setGraalVersion(extension.getGraalVersion());
task.setJavaVersion(extension.getJavaVersion());
task.setWindowsVsVarsPath(extension.getWindowsVsVarsPath());
task.setJarFile(jar.map(j -> j.getOutputs().getFiles().getSingleFile()));
task.setClasspath(project.getConfigurations().named("runtimeClasspath"));
task.setCacheDir(cacheDir);
task.setGraalDirectoryName(extension.getGraalDirectoryName());
task.setOptions(extension.getOptions());
task.dependsOn(extractGraal);
task.dependsOn(jar);
@ -91,9 +97,12 @@ public class GradleGraalPlugin implements Plugin<Project> {
project.getTasks().register("sharedLibrary", SharedLibraryTask.class, task -> {
task.setOutputName(extension.getOutputName());
task.setGraalVersion(extension.getGraalVersion());
task.setJavaVersion(extension.getJavaVersion());
task.setWindowsVsVarsPath(extension.getWindowsVsVarsPath());
task.setJarFile(sharedLibrary.map(j -> j.getOutputs().getFiles().getSingleFile()));
task.setClasspath(project.getConfigurations().named("runtimeClasspath"));
task.setCacheDir(cacheDir);
task.setGraalDirectoryName(extension.getGraalDirectoryName());
task.setOptions(extension.getOptions());
task.dependsOn(extractGraal);
task.dependsOn(sharedLibrary);

View file

@ -0,0 +1,121 @@
/*
* (c) Copyright 2018 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.palantir.gradle.graal
import com.palantir.gradle.graal.util.JavaVersionUtil
import nebula.test.ProjectSpec
import org.gradle.api.GradleException
import spock.lang.Requires
class GradleExtensionSpec extends ProjectSpec {
GraalExtension extension
def setup() {
extension = new GraalExtension(project)
}
def 'extension returns the correct Graal download URL and directory name for default Java version and graalVersion 19.2.0'() {
when:
extension.graalVersion("19.2.0")
then:
extension.getDownloadBaseUrl().get() =~ "https://github.com/oracle/graal/releases/download/"
extension.getGraalDirectoryName() =~ "graalvm-ce-19.2.0"
}
def 'extension returns the correct Graal download URL and directory name for default Java version and graalVersion 19.3.0'() {
when:
extension.graalVersion("19.3.0")
then:
extension.getDownloadBaseUrl().get() =~ "https://github.com/graalvm/graalvm-ce-builds/releases/download/"
extension.getGraalDirectoryName() =~ "graalvm-ce-java8-19.3.0"
}
def 'extension returns the correct Graal download URL and directory name for Java version 8 and graalVersion 19.2.0'() {
when:
extension.javaVersion("8")
extension.graalVersion("19.2.0")
then:
extension.getDownloadBaseUrl().get() =~ "https://github.com/oracle/graal/releases/download/"
extension.getGraalDirectoryName() =~ "graalvm-ce-19.2.0"
}
def 'extension returns the correct Graal download URL and directory name for Java version 8 and graalVersion 19.3.0'() {
when:
extension.javaVersion("8")
extension.graalVersion("19.3.0")
then:
extension.getDownloadBaseUrl().get() =~ "https://github.com/graalvm/graalvm-ce-builds/releases/download/"
extension.getGraalDirectoryName() =~ "graalvm-ce-java8-19.3.0"
}
def 'extension should throw exception for graalVersion 19.2.0 and Java version 11'() {
when:
extension.javaVersion("11")
extension.graalVersion("19.2.0")
extension.getDownloadBaseUrl()
then:
thrown GradleException
}
def 'extension returns the correct Graal download URL and directory name for Java version 11 and graalVersion 19.3.0'() {
when:
extension.javaVersion("11")
extension.graalVersion("19.3.0")
then:
extension.getDownloadBaseUrl().get() =~ "https://github.com/graalvm/graalvm-ce-builds/releases/download/"
extension.getGraalDirectoryName() =~ "graalvm-ce-java11-19.3.0"
}
def 'extension should throw exception for unsupported Java version'() {
when:
extension.javaVersion("12")
then:
thrown GradleException
}
@Requires({ Platform.operatingSystem() == Platform.OperatingSystem.WINDOWS && JavaVersionUtil.runtimeMajorVersion() == 8 })
def 'extension returns the correct Windows VS Vars Path for default Java version 8'() {
expect:
extension.getWindowsVsVarsPath().get() == "C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Bin\\SetEnv.cmd"
}
@Requires({ Platform.operatingSystem() == Platform.OperatingSystem.WINDOWS && JavaVersionUtil.runtimeMajorVersion() == 11 })
def 'extension returns the correct Windows VS Vars Path for Java version 11 and set Windows VS Version and Edition'() {
when:
extension.javaVersion("11")
extension.windowsVsVersion("2019")
extension.windowsVsEdition("Enterprise")
then:
extension.getWindowsVsVarsPath().get() == "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"
}
def 'extension returns the provided Windows VS Vars Path'() {
when:
extension.windowsVsVarsPath("path")
then:
extension.getWindowsVsVarsPath().get() =~ "path"
}
}

View file

@ -16,9 +16,11 @@
package com.palantir.gradle.graal
import com.palantir.gradle.graal.util.JavaVersionUtil
import nebula.test.IntegrationSpec
import nebula.test.functional.ExecutionResult
import spock.lang.IgnoreIf
import spock.lang.Requires
import static com.palantir.gradle.graal.Platform.OperatingSystem.LINUX
import static com.palantir.gradle.graal.Platform.OperatingSystem.MAC
@ -26,6 +28,7 @@ import static com.palantir.gradle.graal.Platform.OperatingSystem.WINDOWS
class GradleGraalEndToEndSpec extends IntegrationSpec {
@Requires({ JavaVersionUtil.runtimeMajorVersion() == 8 })
def 'test default version nativeImage'() {
setup:
directory("src/main/java/com/palantir/test")
@ -86,7 +89,133 @@ class GradleGraalEndToEndSpec extends IntegrationSpec {
output.getAbsolutePath().execute().text.equals("hello, world (modified)!" + System.lineSeparator())
}
@Requires({ JavaVersionUtil.runtimeMajorVersion() == 8 })
def 'test version 19.3.0 nativeImage'() {
setup:
directory("src/main/java/com/palantir/test")
file("src/main/java/com/palantir/test/Main.java") << '''
package com.palantir.test;
public final class Main {
public static final void main(String[] args) {
System.out.println("hello, world!");
}
}
'''
buildFile << '''
apply plugin: 'com.palantir.graal'
graal {
mainClass 'com.palantir.test.Main'
outputName 'hello-world'
graalVersion '19.3.0'
}
'''
when:
ExecutionResult result = runTasksSuccessfully('nativeImage') // note, this accesses your real ~/.gradle cache
println "Gradle Standard Out:\n" + result.standardOutput
println "Gradle Standard Error:\n" + result.standardError
def outputPath = "build/graal/hello-world"
if (Platform.operatingSystem() == WINDOWS) {
outputPath += ".exe"
}
File output = new File(getProjectDir(), outputPath)
then:
output.exists()
output.getAbsolutePath().execute().text.equals("hello, world!" + System.lineSeparator())
when:
ExecutionResult result2 = runTasksSuccessfully('nativeImage')
then:
result2.wasUpToDate(':nativeImage')
when:
new File(getProjectDir(), "src/main/java/com/palantir/test/Main.java").text = '''
package com.palantir.test;
public final class Main {
public static final void main(String[] args) {
System.out.println("hello, world (modified)!");
}
}
'''
ExecutionResult result3 = runTasksSuccessfully('nativeImage')
then:
println result3.standardOutput
!result3.wasUpToDate(':nativeImage')
output.getAbsolutePath().execute().text.equals("hello, world (modified)!" + System.lineSeparator())
}
@Requires({ JavaVersionUtil.runtimeMajorVersion() == 11 })
def 'test version 19.3.0 nativeImage Java 11'() {
setup:
directory("src/main/java/com/palantir/test")
file("src/main/java/com/palantir/test/Main.java") << '''
package com.palantir.test;
public final class Main {
public static final void main(String[] args) {
System.out.println("hello, world!");
}
}
'''
buildFile << '''
apply plugin: 'com.palantir.graal'
graal {
mainClass 'com.palantir.test.Main'
outputName 'hello-world'
graalVersion '19.3.0'
javaVersion '11'
}
'''
when:
ExecutionResult result = runTasksSuccessfully('nativeImage') // note, this accesses your real ~/.gradle cache
println "Gradle Standard Out:\n" + result.standardOutput
println "Gradle Standard Error:\n" + result.standardError
def outputPath = "build/graal/hello-world"
if (Platform.operatingSystem() == WINDOWS) {
outputPath += ".exe"
}
File output = new File(getProjectDir(), outputPath)
then:
output.exists()
output.getAbsolutePath().execute().text.equals("hello, world!" + System.lineSeparator())
when:
ExecutionResult result2 = runTasksSuccessfully('nativeImage')
then:
result2.wasUpToDate(':nativeImage')
when:
new File(getProjectDir(), "src/main/java/com/palantir/test/Main.java").text = '''
package com.palantir.test;
public final class Main {
public static final void main(String[] args) {
System.out.println("hello, world (modified)!");
}
}
'''
ExecutionResult result3 = runTasksSuccessfully('nativeImage')
then:
println result3.standardOutput
!result3.wasUpToDate(':nativeImage')
output.getAbsolutePath().execute().text.equals("hello, world (modified)!" + System.lineSeparator())
}
// there is no RC version for Windows
@Requires({ JavaVersionUtil.runtimeMajorVersion() == 8 })
@IgnoreIf({ Platform.operatingSystem() == WINDOWS })
def 'test 1.0.0-rc5 nativeImage'() {
setup:
@ -149,7 +278,8 @@ class GradleGraalEndToEndSpec extends IntegrationSpec {
output.getAbsolutePath().execute().text.equals("hello, world (modified)!" + System.lineSeparator())
}
def 'allows specifying additional properties'() {
@Requires({ JavaVersionUtil.runtimeMajorVersion() == 8 })
def 'allows specifying additional properties on default version'() {
setup:
directory("src/main/java/com/palantir/test")
file("src/main/java/com/palantir/test/Main.java") << '''
@ -198,6 +328,7 @@ class GradleGraalEndToEndSpec extends IntegrationSpec {
output.getAbsolutePath().execute().text.toLowerCase().contains("<html")
}
@Requires({ JavaVersionUtil.runtimeMajorVersion() == 8 })
def 'can build shared libraries on default version'() {
setup:
directory("src/main/java/com/palantir/test")
@ -220,7 +351,57 @@ class GradleGraalEndToEndSpec extends IntegrationSpec {
dylibFile.exists()
}
@Requires({ JavaVersionUtil.runtimeMajorVersion() == 8 })
def 'can build shared libraries on version 19.3.0'() {
setup:
directory("src/main/java/com/palantir/test")
file("src/main/java/com/palantir/test/Main.java") << '''
package com.palantir.test;
public final class Main {}
'''
buildFile << '''
apply plugin: 'com.palantir.graal'
graal {
outputName 'hello-world'
graalVersion '19.3.0'
}
'''
when:
runTasksSuccessfully('sharedLibrary')
File dylibFile = new File(getProjectDir(), "build/graal/hello-world." + getSharedLibPrefixByOs())
then:
dylibFile.exists()
}
@Requires({ JavaVersionUtil.runtimeMajorVersion() == 11 })
def 'can build shared libraries on version 19.3.0 Java 11'() {
setup:
directory("src/main/java/com/palantir/test")
file("src/main/java/com/palantir/test/Main.java") << '''
package com.palantir.test;
public final class Main {}
'''
buildFile << '''
apply plugin: 'com.palantir.graal'
graal {
outputName 'hello-world'
graalVersion '19.3.0'
javaVersion '11'
}
'''
when:
runTasksSuccessfully('sharedLibrary')
File dylibFile = new File(getProjectDir(), "build/graal/hello-world." + getSharedLibPrefixByOs())
then:
dylibFile.exists()
}
// there is no RC version for Windows
@Requires({ JavaVersionUtil.runtimeMajorVersion() == 8 })
@IgnoreIf({ Platform.operatingSystem() == WINDOWS })
def 'can build shared libraries on 1.0.0-rc5'() {
setup:
@ -245,19 +426,7 @@ class GradleGraalEndToEndSpec extends IntegrationSpec {
dylibFile.exists()
}
def getSharedLibPrefixByOs() {
switch (Platform.operatingSystem()) {
case MAC:
return "dylib"
case LINUX:
return "so"
case WINDOWS:
return "dll"
default:
throw new IllegalStateException("No GraalVM support for " + Platform.operatingSystem())
}
}
@Requires({ JavaVersionUtil.runtimeMajorVersion() == 8 })
def 'should not allow empty mainClass on nativeImage'() {
buildFile << '''
apply plugin: 'com.palantir.graal'
@ -278,6 +447,7 @@ class GradleGraalEndToEndSpec extends IntegrationSpec {
result.standardError.contains("No value has been specified for property 'mainClass'")
}
@Requires({ JavaVersionUtil.runtimeMajorVersion() == 8 })
def 'should not allow to add -H:Name'() {
buildFile << '''
apply plugin: 'com.palantir.graal'
@ -299,4 +469,18 @@ class GradleGraalEndToEndSpec extends IntegrationSpec {
then:
result.standardError.contains("Use 'outputName' instead of")
}
def getSharedLibPrefixByOs() {
switch (Platform.operatingSystem()) {
case MAC:
return "dylib"
case LINUX:
return "so"
case WINDOWS:
return "dll"
default:
throw new IllegalStateException("No GraalVM support for " + Platform.operatingSystem())
}
}
}

View file

@ -75,7 +75,7 @@ class GradleGraalPluginIntegrationSpec extends IntegrationSpec {
server.takeRequest().requestUrl.toString() =~ "http://(localhost|127\\.0\\.0\\.1):${server.port}" +
"/oracle/graal/releases/download//vm-1.0.0-rc3/graalvm-ce-1.0.0-rc3-(macos|linux)-amd64.tar.gz"
file("cacheDir/1.0.0-rc3/graalvm-ce-1.0.0-rc3-amd64.tar.gz").text == '<<tgz>>'
file("cacheDir/1.0.0-rc3/8/graalvm-ce-1.0.0-rc3-amd64.tar.gz").text == '<<tgz>>'
}
// for Windows the download is a .zip, this is tested below
@ -108,7 +108,7 @@ class GradleGraalPluginIntegrationSpec extends IntegrationSpec {
server.takeRequest().path =~
"/oracle/graal/releases/download//vm-19.0.0/graalvm-ce-(darwin|linux)-amd64-19.0.0.tar.gz"
file("cacheDir/19.0.0/graalvm-ce-19.0.0-amd64.tar.gz").text == '<<tgz>>'
file("cacheDir/19.0.0/8/graalvm-ce-19.0.0-amd64.tar.gz").text == '<<tgz>>'
}
@Requires({ Platform.operatingSystem() == Platform.OperatingSystem.WINDOWS })
@ -138,9 +138,141 @@ class GradleGraalPluginIntegrationSpec extends IntegrationSpec {
// e.g. Docker Desktop puts "127.0.0.1 kubernetes.docker.internal" in there, which ends up in `requestUrl`
// so the comparison is only made for `path`
server.takeRequest().path =~
"/oracle/graal/releases/download//vm-19.0.0/graalvm-ce-windows-amd64-19.0.0.zip"
"/oracle/graal/releases/download//vm-19.0.0/graalvm-ce-windows-amd64-19.0.0.zip"
file("cacheDir/19.0.0/graalvm-ce-19.0.0-amd64.zip").text == '<<zip>>'
file("cacheDir/19.0.0/8/graalvm-ce-19.0.0-amd64.zip").text == '<<zip>>'
}
// for Windows the download is a .zip, this is tested below
@IgnoreIf({ Platform.operatingSystem() == Platform.OperatingSystem.WINDOWS })
def 'allows specifying GA graal version Java 8 19.3+ (non-windows)'() {
setup:
buildFile << """
apply plugin: 'com.palantir.graal'
graal {
graalVersion '19.3.0'
downloadBaseUrl '${fakeBaseUrl}'
}
"""
server.enqueue(new MockResponse().setBody('<<tgz>>'))
when:
ExecutionResult result = runTasksSuccessfully('downloadGraalTooling')
then:
println result.getStandardOutput()
result.wasExecuted(':downloadGraalTooling')
!result.wasUpToDate(':downloadGraalTooling')
!result.wasSkipped(':downloadGraalTooling')
// `requestUrl` can contain "127.0.0.1" instead of "localhost"
// worse yet, it can contain any hostname that is defined for 127.0.0.1 in the hosts file
// e.g. Docker Desktop puts "127.0.0.1 kubernetes.docker.internal" in there, which ends up in `requestUrl`
// so the comparison is only made for `path`
server.takeRequest().path =~
"oracle/graal/releases/download//vm-19.3.0/graalvm-ce-java8-(darwin|linux)-amd64-19.3.0.tar.gz"
file("cacheDir/19.3.0/8/graalvm-ce-java8-19.3.0-amd64.tar.gz").text == '<<tgz>>'
}
@Requires({ Platform.operatingSystem() == Platform.OperatingSystem.WINDOWS })
def 'allows specifying GA graal version Java 8 19.3+ (windows)'() {
setup:
buildFile << """
apply plugin: 'com.palantir.graal'
graal {
graalVersion '19.3.0'
downloadBaseUrl '${fakeBaseUrl}'
}
"""
server.enqueue(new MockResponse().setBody('<<zip>>'))
when:
ExecutionResult result = runTasksSuccessfully('downloadGraalTooling')
then:
println result.getStandardOutput()
result.wasExecuted(':downloadGraalTooling')
!result.wasUpToDate(':downloadGraalTooling')
!result.wasSkipped(':downloadGraalTooling')
// `requestUrl` can contain "127.0.0.1" instead of "localhost"
// worse yet, it can contain any hostname that is defined for 127.0.0.1 in the hosts file
// e.g. Docker Desktop puts "127.0.0.1 kubernetes.docker.internal" in there, which ends up in `requestUrl`
// so the comparison is only made for `path`
server.takeRequest().path =~
"oracle/graal/releases/download//vm-19.3.0/graalvm-ce-java8-windows-amd64-19.3.0.zip"
file("cacheDir/19.3.0/8/graalvm-ce-java8-19.3.0-amd64.zip").text == '<<zip>>'
}
// for Windows the download is a .zip, this is tested below
@IgnoreIf({ Platform.operatingSystem() == Platform.OperatingSystem.WINDOWS })
def 'allows specifying GA graal version Java 11 19.3+ (non-windows)'() {
setup:
buildFile << """
apply plugin: 'com.palantir.graal'
graal {
graalVersion '19.3.0'
javaVersion '11'
downloadBaseUrl '${fakeBaseUrl}'
}
"""
server.enqueue(new MockResponse().setBody('<<tgz>>'))
when:
ExecutionResult result = runTasksSuccessfully('downloadGraalTooling')
then:
println result.getStandardOutput()
result.wasExecuted(':downloadGraalTooling')
!result.wasUpToDate(':downloadGraalTooling')
!result.wasSkipped(':downloadGraalTooling')
// `requestUrl` can contain "127.0.0.1" instead of "localhost"
// worse yet, it can contain any hostname that is defined for 127.0.0.1 in the hosts file
// e.g. Docker Desktop puts "127.0.0.1 kubernetes.docker.internal" in there, which ends up in `requestUrl`
// so the comparison is only made for `path`
server.takeRequest().path =~
"oracle/graal/releases/download//vm-19.3.0/graalvm-ce-java11-(darwin|linux)-amd64-19.3.0.tar.gz"
file("cacheDir/19.3.0/11/graalvm-ce-java11-19.3.0-amd64.tar.gz").text == '<<tgz>>'
}
@Requires({ Platform.operatingSystem() == Platform.OperatingSystem.WINDOWS })
def 'allows specifying GA graal version Java 11 19.3+ (windows)'() {
setup:
buildFile << """
apply plugin: 'com.palantir.graal'
graal {
graalVersion '19.3.0'
javaVersion '11'
downloadBaseUrl '${fakeBaseUrl}'
}
"""
server.enqueue(new MockResponse().setBody('<<zip>>'))
when:
ExecutionResult result = runTasksSuccessfully('downloadGraalTooling')
then:
println result.getStandardOutput()
result.wasExecuted(':downloadGraalTooling')
!result.wasUpToDate(':downloadGraalTooling')
!result.wasSkipped(':downloadGraalTooling')
// `requestUrl` can contain "127.0.0.1" instead of "localhost"
// worse yet, it can contain any hostname that is defined for 127.0.0.1 in the hosts file
// e.g. Docker Desktop puts "127.0.0.1 kubernetes.docker.internal" in there, which ends up in `requestUrl`
// so the comparison is only made for `path`
server.takeRequest().path =~
"oracle/graal/releases/download//vm-19.3.0/graalvm-ce-java11-windows-amd64-19.3.0.zip"
file("cacheDir/19.3.0/11/graalvm-ce-java11-19.3.0-amd64.zip").text == '<<zip>>'
}
def 'downloadGraalTooling behaves incrementally'() {

View file

@ -0,0 +1,38 @@
/*
* (c) Copyright 2018 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.palantir.gradle.graal
import nebula.test.ProjectSpec
import org.gradle.api.GradleException
import spock.lang.Specification
class GradleVersionUtilSpec extends Specification {
def 'should detect Graal version 19.2.0 is not 19.3+'() {
expect:
!GraalVersionUtil.isGraalVersionGreatherThan19_3("19.2.0")
}
def 'should detect Graal version 19.3.0 is not 19.3+'() {
expect:
GraalVersionUtil.isGraalVersionGreatherThan19_3("19.3.0")
}
def 'should detect Graal version empty is not 19.3+'() {
expect:
!GraalVersionUtil.isGraalVersionGreatherThan19_3("")
}
}

View file

@ -0,0 +1,34 @@
/*
* (c) Copyright 2018 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.palantir.gradle.graal.util;
public class JavaVersionUtil {
public static int runtimeMajorVersion() {
String version = System.getProperty("java.version");
if (version.startsWith("1.")) {
version = version.substring(2, 3);
} else {
int dot = version.indexOf(".");
if (dot != -1) {
version = version.substring(0, dot);
}
}
return Integer.parseInt(version);
}
private JavaVersionUtil() {}
}