Skip to content

Commit

Permalink
Prepare for GraalVM and JDK 11
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenneg committed Nov 11, 2019
1 parent 65c33bd commit e4aa525
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.quarkus.runtime.graal;

import java.net.Inet4Address;

import org.wildfly.common.net.Inet;

import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.RecomputeFieldValue;
import com.oracle.svm.core.annotate.TargetClass;

@TargetClass(Inet.class)
final class Target_org_wildfly_common_net_Inet {

/*
* The following fields recomputations are required because of a new restriction in GraalVM 19.3.0 that prohibits the
* presence of java.net.Inet4Address in the image heap.
*/

@Alias
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias)
public static Inet4Address INET4_ANY = Inet.getInet4Address(0, 0, 0, 0);

@Alias
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias)
public static Inet4Address INET4_LOOPBACK = Inet.getInet4Address(127, 0, 0, 1);

@Alias
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias)
public static Inet4Address INET4_BROADCAST = Inet.getInet4Address(255, 255, 255, 255);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@
import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.jdk.JDK8OrEarlier;

@TargetClass(className = "sun.misc.URLClassPath$Loader")
@TargetClass(className = "sun.misc.URLClassPath$Loader", onlyWith = JDK8OrEarlier.class)
final class Target_sun_misc_URLClassPath$Loader {

@Alias
public Target_sun_misc_URLClassPath$Loader(URL url) {
}
}

@TargetClass(className = "sun.misc.URLClassPath$FileLoader")
@TargetClass(className = "sun.misc.URLClassPath$FileLoader", onlyWith = JDK8OrEarlier.class)
final class Target_sun_misc_URLClassPath$FileLoader {

@Alias
public Target_sun_misc_URLClassPath$FileLoader(URL url) throws IOException {
}
}

@TargetClass(className = "sun.misc.URLClassPath")
@TargetClass(className = "sun.misc.URLClassPath", onlyWith = JDK8OrEarlier.class)
final class Target_sun_misc_URLClassPath {

@Substitute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.wildfly.common.net.CidrAddress;

/**
* Test some MicroProfile config primitives.
Expand All @@ -19,6 +20,9 @@ public class MicroProfileConfigResource {
@ConfigProperty(name = "microprofile.custom.value")
MicroProfileCustomValue value;

@ConfigProperty(name = "microprofile.cidr-address")
CidrAddress cidrAddress;

@Inject
Config config;

Expand All @@ -36,4 +40,10 @@ public String getPropertyNames() throws Exception {
public String getCustomValue() {
return Integer.toString(value.getNumber());
}

@GET
@Path("/get-cidr-address")
public String getCidrAddress() {
return cidrAddress.getNetworkAddress().getHostAddress();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ web-message=A message
schedulerservice.cron.expr=0/10 * * * * ?

microprofile.custom.value = 456
microprofile.cidr-address=10.0.0.20/24
configproperties.message=Hello
configproperties.other=1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ public void testMicroprofileConfigGetCustomValue() {
.when().get("/microprofile-config/get-custom-value")
.then().body(is("456"));
}

@Test
public void testCidrAddress() {
RestAssured
.when().get("/microprofile-config/get-cidr-address")
.then().body(is("10.0.0.0"));
}
}

0 comments on commit e4aa525

Please sign in to comment.