Skip to content

Commit

Permalink
Update default GraalVM version to 19.0.2 (was 1.0.0-rc12) (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
carterkozak authored and markelliot committed Aug 2, 2019
1 parent 5394b07 commit b5567e4
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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 `1.0.0-rc12`)
* `graalVersion`: the version string to use when downloading GraalVM (defaults to `19.0.2`)
* `downloadBaseUrl`: the base download URL to use (defaults to `https://github.com/oracle/graal/releases/download/`)


Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/palantir/gradle/graal/ExtractGraalTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package com.palantir.gradle.graal;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.Directory;
import org.gradle.api.file.DirectoryProperty;
Expand Down Expand Up @@ -61,6 +63,33 @@ public final void extractGraal() {
spec.args("-xzf", inputTgz.get().getAsFile().getAbsolutePath());
spec.workingDir(cacheDir.get().resolve(graalVersion.get()));
});
File nativeImageExecutable = getExecutable("native-image");
if (!nativeImageExecutable.isFile()) {
getProject().exec(spec -> {
File graalUpdateExecutable = getExecutable("gu");
if (!graalUpdateExecutable.isFile()) {
throw new IllegalStateException("Failed to find Graal update binary: " + graalUpdateExecutable);
}
spec.executable(graalUpdateExecutable.getAbsolutePath());
spec.args("install", "native-image");
});
}
}

private File getExecutable(String binaryName) {
return cacheDir.get()
.resolve(Paths.get(graalVersion.get(), "graalvm-ce-" + graalVersion.get()))
.resolve(getArchitectureSpecifiedBinaryPath(binaryName))
.toFile();
}

private Path getArchitectureSpecifiedBinaryPath(String binaryName) {
switch (Platform.operatingSystem()) {
case MAC: return Paths.get("Contents", "Home", "bin", binaryName);
case LINUX: return Paths.get("bin", binaryName);
default:
throw new IllegalStateException("No GraalVM support for " + Platform.operatingSystem());
}
}

@InputFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class GraalExtension {

private static final String DEFAULT_DOWNLOAD_BASE_URL = "https://github.com/oracle/graal/releases/download/";
private static final String DEFAULT_GRAAL_VERSION = "1.0.0-rc12";
private static final String DEFAULT_GRAAL_VERSION = "19.0.2";

private final Property<String> downloadBaseUrl;
private final Property<String> graalVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,63 @@ class GradleGraalEndToEndSpec extends IntegrationSpec {
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'
}
'''

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
File output = new File(getProjectDir(), "build/graal/hello-world");

then:
output.exists()
output.getAbsolutePath().execute().text.equals("hello, world!\n")

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)!\n")
}

def 'test 1.0.0-rc5 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!");
Expand Down Expand Up @@ -65,7 +121,7 @@ class GradleGraalEndToEndSpec extends IntegrationSpec {
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)!");
Expand All @@ -85,10 +141,10 @@ class GradleGraalEndToEndSpec extends IntegrationSpec {
directory("src/main/java/com/palantir/test")
file("src/main/java/com/palantir/test/Main.java") << '''
package com.palantir.test;
import java.io.IOException;
import java.net.URL;
public final class Main {
public static final void main(String[] args) throws IOException {
String result = convertStreamToString(new URL("http://www.google.com/").openStream());
Expand Down Expand Up @@ -125,8 +181,29 @@ class GradleGraalEndToEndSpec extends IntegrationSpec {
output.getAbsolutePath().execute().text.toLowerCase().contains("<html")
}

def 'can build shared libraries on default version'() {
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'
}
'''

when:
runTasksSuccessfully('sharedLibrary')
File dylibFile = new File(getProjectDir(), "build/graal/hello-world." + getSharedLibPrefixByOs())

then:
dylibFile.exists()
}

def 'can build shared libraries'() {
def 'can build shared libraries on 1.0.0-rc5'() {
setup:
directory("src/main/java/com/palantir/test")
file("src/main/java/com/palantir/test/Main.java") << '''
Expand Down

0 comments on commit b5567e4

Please sign in to comment.