diff --git a/.circleci/config.yml b/.circleci/config.yml index b53d861..56ccc3c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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+ @@ -35,6 +54,22 @@ jobs: - 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 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 } + trial-publish: docker: [{ image: 'circleci/openjdk:8-node' }] steps: @@ -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 } } diff --git a/src/main/java/com/palantir/gradle/graal/BaseGraalCompileTask.java b/src/main/java/com/palantir/gradle/graal/BaseGraalCompileTask.java index d053780..1ff0526 100644 --- a/src/main/java/com/palantir/gradle/graal/BaseGraalCompileTask.java +++ b/src/main/java/com/palantir/gradle/graal/BaseGraalCompileTask.java @@ -158,7 +158,7 @@ public abstract class BaseGraalCompileTask extends DefaultTask { if (!Files.exists(startCmd.getParent())) { Files.createDirectories(startCmd.getParent()); } - Files.writeString(startCmd, cmdContent); + Files.write(startCmd, cmdContent.getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/palantir/gradle/graal/GraalExtension.java b/src/main/java/com/palantir/gradle/graal/GraalExtension.java index c6a7116..d6077ab 100644 --- a/src/main/java/com/palantir/gradle/graal/GraalExtension.java +++ b/src/main/java/com/palantir/gradle/graal/GraalExtension.java @@ -16,23 +16,24 @@ package com.palantir.gradle.graal; +import java.util.Arrays; +import java.util.List; import org.gradle.api.GradleException; import org.gradle.api.Project; import org.gradle.api.provider.ListProperty; import org.gradle.api.provider.Property; import org.gradle.api.provider.Provider; -import java.util.Arrays; -import java.util.List; - /** * 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 String WINDOWS_7_ENV_PATH = "C:\\Program Files\\Microsoft SDKs\\" + + "Windows\\v7.1\\Bin\\SetEnv.cmd"; private static final String DEFAULT_VS_VERSION = "2019"; private static final String DEFAULT_VS_EDITION = "Community"; - private static final String DEFAULT_VS_VARS_PATH = "C:\\Program Files (x86)\\Microsoft Visual Studio\\{version}\\{edition}\\VC\\Auxiliary\\Build\\vcvars64.bat"; + private static final String DEFAULT_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 DOWNLOAD_BASE_URL_GRAAL_19_3 = "https://github.com/graalvm/graalvm-ce-builds/releases/download/"; @@ -138,7 +139,7 @@ public class GraalExtension { return vsVarsPath.orElse(getDefaultVsVarsPath()); } - private final String getDefaultVsVarsPath() { + private String getDefaultVsVarsPath() { return Integer.parseInt(javaVersion.get()) >= 11 ? DEFAULT_VS_VARS_PATH .replaceAll("\\{version}", vsVersion.getOrElse(DEFAULT_VS_VERSION)) diff --git a/src/test/groovy/com/palantir/gradle/graal/GradleGraalEndToEndSpec.groovy b/src/test/groovy/com/palantir/gradle/graal/GradleGraalEndToEndSpec.groovy index 555eea6..4c654d2 100644 --- a/src/test/groovy/com/palantir/gradle/graal/GradleGraalEndToEndSpec.groovy +++ b/src/test/groovy/com/palantir/gradle/graal/GradleGraalEndToEndSpec.groovy @@ -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,6 +89,7 @@ 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") @@ -147,6 +151,7 @@ class GradleGraalEndToEndSpec extends IntegrationSpec { 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") @@ -210,6 +215,7 @@ class GradleGraalEndToEndSpec extends IntegrationSpec { } // there is no RC version for Windows + @Requires({ JavaVersionUtil.runtimeMajorVersion() == 8 }) @IgnoreIf({ Platform.operatingSystem() == WINDOWS }) def 'test 1.0.0-rc5 nativeImage'() { setup: @@ -272,6 +278,7 @@ class GradleGraalEndToEndSpec extends IntegrationSpec { output.getAbsolutePath().execute().text.equals("hello, world (modified)!" + System.lineSeparator()) } + @Requires({ JavaVersionUtil.runtimeMajorVersion() == 8 }) def 'allows specifying additional properties on default version'() { setup: directory("src/main/java/com/palantir/test") @@ -321,6 +328,7 @@ class GradleGraalEndToEndSpec extends IntegrationSpec { output.getAbsolutePath().execute().text.toLowerCase().contains(">' + file("cacheDir/1.0.0-rc3/8/graalvm-ce-1.0.0-rc3-amd64.tar.gz").text == '<>' } // 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/8/graalvm-ce-java8-19.0.0-amd64.tar.gz").text == '<>' + file("cacheDir/19.0.0/8/graalvm-ce-19.0.0-amd64.tar.gz").text == '<>' } @Requires({ Platform.operatingSystem() == Platform.OperatingSystem.WINDOWS }) diff --git a/src/test/groovy/com/palantir/gradle/graal/util/JavaVersionUtil.java b/src/test/groovy/com/palantir/gradle/graal/util/JavaVersionUtil.java new file mode 100644 index 0000000..0ec742f --- /dev/null +++ b/src/test/groovy/com/palantir/gradle/graal/util/JavaVersionUtil.java @@ -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() {} +}