Skip to content

Commit

Permalink
fix: support the latest GraalVM release (#5)
Browse files Browse the repository at this point in the history
* ci: upgrade GraalVM versions

* ci: fix workflows

* fix: add necessary metadata to new versions

* fix: support Java 17

* fix: add options to the gu command

* fix: support the latest format of ResourceBundleUsage

refs oracle/graal#3557

* chore: reformat

* fix: stop using Java9 feature for Java8 compatibility

Arrays.compare() is not ready to use for Java8

* fix: handle nullness of lists properly

* fix: handle nullness of lists properly
  • Loading branch information
KengoTODA authored Jan 29, 2022
1 parent c3423b4 commit b64e9b0
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 29 deletions.
28 changes: 11 additions & 17 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,23 @@ jobs:
fail-fast: false
matrix:
graal:
- 20.3.0
- 21.0.0
- 21.1.0
- 21.2.0
- 21.3.0
- 20.3.5
- 21.3.1
- 22.0.0.2
javaVersion:
- java8
- java11
- java16
- java17
nativeImage:
- installed
- "uninstalled"
exclude:
- graal: 20.3.0
- graal: 20.3.5
javaVersion: java17
- graal: 20.3.5
javaVersion: java8
- graal: 20.3.0
javaVersion: java16
- graal: 21.0.0
javaVersion: java16
- graal: 21.3.0
- graal: 22.0.0.2
javaVersion: java8
- graal: 21.3.0
javaVersion: java16
name: "test ${{ matrix.graal }}.${{ matrix.javaVersion }}(native-image: ${{ matrix.nativeImage }})"
if: contains( github.ref , 'refs/heads/release' ) == false

Expand All @@ -80,11 +74,11 @@ jobs:
echo $JAVA_HOME
- name: Install GraalVM native-image
run: gu install native-image
run: gu install native-image --auto-yes --non-interactive
if: "startsWith(matrix.nativeImage, 'installed')"

- name: Get latest gradle version if Java16
if: "${{ 'java16' == matrix.javaVersion }}"
- name: Get latest gradle version if Java17
if: "${{ 'java17' == matrix.javaVersion }}"
id: latest-gradle
run: grep -A 1 " version:" ./.github/workflows/versions.yml | tail -n 1 | sed 's/[- :]//g' | tr -d '"' | awk '{print "::set-output name=version::" $1}'

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void installNativeImage() {
.exec(
execSpec -> {
execSpec.setExecutable(graalVmUpdaterCommand);
execSpec.args("install", "native-image");
execSpec.args("install", "native-image", "--auto-yes", "--non-interactive");
});
}

Expand Down
49 changes: 49 additions & 0 deletions src/main/java/org/mikeneck/graalvm/GraalVmVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public enum GraalVmVersion {
GRAAL_21_3_0_JAVA_16("21.3.0-java16", new GraalVm21Matcher("21.3.0", "java16")),
GRAAL_20_3_4_JAVA_8("20.3.4-java8", new GraalVm20Matcher("20.3.4", "java8")),
GRAAL_20_3_4_JAVA_11("20.3.4-java11", new GraalVm20Matcher("20.3.4", "java11")),
GRAAL_20_3_5_JAVA_11("20.3.5-java11", new GraalVm20Matcher("20.3.5", "java11")),
GRAAL_21_3_1_JAVA_8("21.3.1-java8", new GraalVm21Matcher("21.3.1", "java8")),
GRAAL_21_3_1_JAVA_11("21.3.1-java11", new GraalVm21Matcher("21.3.1", "java11")),
GRAAL_21_3_1_JAVA_16("21.3.1-java17", new GraalVm21Matcher("21.3.1", "java17")),
GRAAL_22_0_0_2_JAVA_11("22.0.0.2-java11", new GraalVm22Matcher("22.0.0.2", "java11")),
GRAAL_22_0_0_2_JAVA_17("22.0.0.2-java17", new GraalVm22Matcher("22.0.0.2", "java17")),
;

@NotNull final String version;
Expand Down Expand Up @@ -195,6 +201,8 @@ private static String javaVersionOf(String javaVersion) {
return "11.0";
} else if ("java16".equals(javaVersion)) {
return "16.0";
} else if ("java17".equals(javaVersion)) {
return "17.0";
}
throw new IllegalArgumentException(String.format("unknown java version %s", javaVersion));
}
Expand Down Expand Up @@ -301,4 +309,45 @@ public boolean matchesVersion(@NotNull Map<String, String> properties) {
return delegate.getJavaVersion();
}
}

static class GraalVm22Matcher implements Matcher {

final String graalVmVersion;
final String simplifiedJavaVersion;
final String javaVersion;
final GraalVm20Matcher delegate;

GraalVm22Matcher(String graalVmVersion, String javaVersion) {
this.graalVmVersion = graalVmVersion;
this.simplifiedJavaVersion = javaVersion;
this.javaVersion = javaVersion;
this.delegate = new GraalVm20Matcher(graalVmVersion, javaVersion);
}

@Override
public String toString() {
@SuppressWarnings("StringBufferReplaceableByString")
final StringBuilder sb = new StringBuilder("GraalVm22Matcher{");
sb.append("graalVmVersion='").append(graalVmVersion).append('\'');
sb.append(", simplifiedJavaVersion='").append(simplifiedJavaVersion).append('\'');
sb.append(", javaVersion='").append(javaVersion).append('\'');
sb.append('}');
return sb.toString();
}

@Override
public boolean matchesVersion(@NotNull Map<String, String> properties) {
return delegate.matchesVersion(properties);
}

@Override
public @NotNull String getGraalVmVersion() {
return delegate.getGraalVmVersion();
}

@Override
public @NotNull String getJavaVersion() {
return delegate.getJavaVersion();
}
}
}
84 changes: 74 additions & 10 deletions src/main/java/org/mikeneck/graalvm/config/BundleUsage.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,106 @@
package org.mikeneck.graalvm.config;

import java.util.Objects;
import java.util.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class BundleUsage implements Comparable<BundleUsage> {

@NotNull public String name = "";
@Nullable public List<String> classNames;
@Nullable public List<String> locales;

public BundleUsage() {}

BundleUsage(@NotNull String name) {
this(name, null, null);
}

BundleUsage(
@NotNull String name, @Nullable List<String> classNames, @Nullable List<String> locales) {
this.name = name;
this.classNames = classNames;
this.locales = locales;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof BundleUsage)) return false;
if (o == null || getClass() != o.getClass()) return false;

BundleUsage that = (BundleUsage) o;
return name.equals(that.name);
if (!name.equals(that.name)) return false;
if (!Objects.equals(classNames, that.classNames)) return false;
return Objects.equals(locales, that.locales);
}

@Override
public int hashCode() {
return Objects.hash(name);
int result = name.hashCode();
result = 31 * result + Objects.hashCode(classNames);
result = 31 * result + Objects.hashCode(locales);
return result;
}

@SuppressWarnings("StringBufferReplaceableByString")
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("ResourceBundleUsage{");
sb.append("name='").append(name).append('\'');
sb.append('}');
return sb.toString();
return "BundleUsage{"
+ "name='"
+ name
+ '\''
+ ", classNames="
+ classNames
+ ", locales="
+ locales
+ '}';
}

@Override
public int compareTo(@NotNull BundleUsage o) {
return this.name.compareTo(o.name);
int nameResult = name.compareTo(o.name);
if (nameResult != 0) {
return nameResult;
}
if (o.classNames == null && classNames != null) {
return 1;
} else if (classNames == null && o.classNames != null) {
return -1;
} else if (classNames != null && o.classNames != null) {
Iterator<String> iterator = o.classNames.iterator();
for (String className : classNames) {
if (!iterator.hasNext()) {
return 1;
}
String other = iterator.next();
int current = className.compareTo(other);
if (current != 0) {
return current;
}
}
if (iterator.hasNext()) {
return -1;
}
}
if (o.locales == null && locales != null) {
return 1;
} else if (locales == null && o.locales != null) {
return -1;
} else if (o.locales != null && locales != null) {
Iterator<String> iterator = o.locales.iterator();
for (String locale : locales) {
if (!iterator.hasNext()) {
return 1;
}
String other = iterator.next();
int current = locale.compareTo(other);
if (current != 0) {
return current;
}
}
if (iterator.hasNext()) {
return -1;
}
}
return 0;
}
}

0 comments on commit b64e9b0

Please sign in to comment.