Skip to content

Commit

Permalink
AWT: JNI registrations depend on GraalVM version
Browse files Browse the repository at this point in the history
  • Loading branch information
Karm committed Apr 11, 2023
1 parent b42efd0 commit 764dacb
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 187 deletions.
7 changes: 0 additions & 7 deletions core/builder/src/main/java/io/quarkus/builder/Json.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public static JsonArrayBuilder array() {
}

/**
*
* @param ignoreEmptyBuilders
* @return the new JSON array builder
* @see JsonBuilder#ignoreEmptyBuilders
Expand All @@ -62,15 +61,13 @@ static JsonArrayBuilder array(boolean ignoreEmptyBuilders) {
}

/**
*
* @return the new JSON object builder, empty builders are not ignored
*/
public static JsonObjectBuilder object() {
return new JsonObjectBuilder(false);
}

/**
*
* @param ignoreEmptyBuilders
* @return the new JSON object builder
* @see JsonBuilder#ignoreEmptyBuilders
Expand All @@ -84,7 +81,6 @@ abstract static class JsonBuilder<T> {
protected boolean ignoreEmptyBuilders = false;

/**
*
* @param ignoreEmptyBuilders If set to true all empty builders added to this builder will be ignored during
* {@link #build()}
*/
Expand All @@ -93,13 +89,11 @@ abstract static class JsonBuilder<T> {
}

/**
*
* @return <code>true</code> if there are no elements/properties, <code>false</code> otherwise
*/
abstract boolean isEmpty();

/**
*
* @return a string representation
* @throws IOException
*/
Expand All @@ -108,7 +102,6 @@ abstract static class JsonBuilder<T> {
abstract void appendTo(Appendable appendable) throws IOException;

/**
*
* @param value
* @return <code>true</code> if the value is null or an empty builder and {@link #ignoreEmptyBuilders} is set to
* <code>true</code>, <code>false</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,24 @@ public abstract class NativeImageBuildRunner {

private static final Logger log = Logger.getLogger(NativeImageBuildRunner.class);

private static GraalVM.Version graalVMVersion = null;

public GraalVM.Version getGraalVMVersion() {
final GraalVM.Version graalVMVersion;
try {
String[] versionCommand = getGraalVMVersionCommand(Collections.singletonList("--version"));
log.debugf(String.join(" ", versionCommand).replace("$", "\\$"));
Process versionProcess = new ProcessBuilder(versionCommand)
.redirectErrorStream(true)
.start();
versionProcess.waitFor();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(versionProcess.getInputStream(), StandardCharsets.UTF_8))) {
graalVMVersion = GraalVM.Version.of(reader.lines());
if (graalVMVersion == null) {
try {
final String[] versionCommand = getGraalVMVersionCommand(Collections.singletonList("--version"));
log.debugf(String.join(" ", versionCommand).replace("$", "\\$"));
final Process versionProcess = new ProcessBuilder(versionCommand)
.redirectErrorStream(true)
.start();
versionProcess.waitFor();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(versionProcess.getInputStream(), StandardCharsets.UTF_8))) {
graalVMVersion = GraalVM.Version.of(reader.lines());
}
} catch (Exception e) {
throw new RuntimeException("Failed to get GraalVM version", e);
}
} catch (Exception e) {
throw new RuntimeException("Failed to get GraalVM version", e);
}
return graalVMVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,21 +275,23 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, LocalesBuildTimeCon
}
}

// See https://github.com/oracle/graal/issues/4921
try (DirectoryStream<Path> sharedLibs = Files.newDirectoryStream(outputDir, "*.{so,dll}")) {
sharedLibs.forEach(src -> {
Path dst = null;
try {
dst = Path.of(outputTargetBuildItem.getOutputDirectory().toAbsolutePath().toString(),
src.getFileName().toString());
log.debugf("Copying a shared lib from %s to %s.", src, dst);
Files.copy(src, dst, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
log.errorf("Could not copy shared lib from %s to %s. Continuing. Error: %s", src, dst, e);
}
});
} catch (IOException e) {
log.errorf("Could not list files in directory %s. Continuing. Error: %s", outputDir, e);
if (graalVMVersion.compareTo(GraalVM.Version.VERSION_23_0_0) >= 0) {
// See https://github.com/oracle/graal/issues/4921
try (DirectoryStream<Path> sharedLibs = Files.newDirectoryStream(outputDir, "*.{so,dll}")) {
sharedLibs.forEach(src -> {
Path dst = null;
try {
dst = Path.of(outputTargetBuildItem.getOutputDirectory().toAbsolutePath().toString(),
src.getFileName().toString());
log.debugf("Copying a shared lib from %s to %s.", src, dst);
Files.copy(src, dst, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
log.errorf("Could not copy shared lib from %s to %s. Continuing. Error: %s", src, dst, e);
}
});
} catch (IOException e) {
log.errorf("Could not list files in directory %s. Continuing. Error: %s", outputDir, e);
}
}

System.setProperty("native.image.path", finalExecutablePath.toAbsolutePath().toString());
Expand Down
Loading

0 comments on commit 764dacb

Please sign in to comment.