Skip to content

Commit

Permalink
Make Truffle from GraalVM 23.1 work with Quarkus in prod mode
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Nov 24, 2023
1 parent 315ec1e commit 1d4ab0b
Showing 1 changed file with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.UncheckedIOException;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import io.quarkus.bootstrap.forkjoin.QuarkusForkJoinWorkerThread;
import io.quarkus.bootstrap.logging.InitialConfigurator;
Expand All @@ -38,10 +42,7 @@ public static void main(String... args) throws Throwable {

private static void doRun(Object args) throws IOException, ClassNotFoundException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
String path = QuarkusEntryPoint.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String decodedPath = URLDecoder.decode(path, "UTF-8");
Path appRoot = new File(decodedPath).toPath().getParent().getParent().getParent();

Path appRoot = getAppRoot();
if (Boolean.parseBoolean(System.getenv("QUARKUS_LAUNCH_DEVMODE"))) {
DevModeMediator.doDevMode(appRoot);
} else if (Boolean.getBoolean("quarkus.launch.rebuild")) {
Expand All @@ -66,6 +67,35 @@ private static void doRun(Object args) throws IOException, ClassNotFoundExceptio
}
}

/**
* This attempts to set {@code java.class.path} with all the jars in the system.
* It is not a complete solution as it only includes jar dependencies
*/
public static void setClassPathSystemProp() {
try {
Path appRoot = getAppRoot();
Path libDir = appRoot.resolve("lib");
Path bootLibs = libDir.resolve("boot");
Path mainLibs = libDir.resolve("main");

Stream<Path> bootLibsStream = Files.list(bootLibs);
Stream<Path> mainLibsStream = Files.list(mainLibs);

var result = Stream.concat(bootLibsStream, mainLibsStream).map(p -> p.toAbsolutePath().toString())
.collect(Collectors.joining(":"));

System.setProperty("java.class.path", result);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

private static Path getAppRoot() {
String path = QuarkusEntryPoint.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String decodedPath = URLDecoder.decode(path, StandardCharsets.UTF_8);
return new File(decodedPath).toPath().getParent().getParent().getParent();
}

private static void doReaugment(Path appRoot) throws IOException, ClassNotFoundException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
if (!Files.exists(appRoot.resolve(LIB_DEPLOYMENT_DEPLOYMENT_CLASS_PATH_DAT))) {
Expand Down

0 comments on commit 1d4ab0b

Please sign in to comment.