forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Truffle from GraalVM 23.1 work in all Quarkus modes
Fixes: quarkusio#36242
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...oyment/src/main/java/io/quarkus/deployment/builditem/SetClassPathSystemPropBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.quarkus.deployment.builditem; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
/** | ||
* A marker build item to make Quarkus set the {@code java.class.path} system property. | ||
* This system property is used in rare by libraries (Truffle for example) to create their own ClassLoaders. | ||
* The value of the system property is simply best effort, as there is no way to faithfully represent | ||
* the Quarkus ClassLoader hierarchies in a system property value. | ||
*/ | ||
public final class SetClassPathSystemPropBuildItem extends MultiBuildItem { | ||
} |
53 changes: 53 additions & 0 deletions
53
core/deployment/src/main/java/io/quarkus/deployment/steps/ClassPathSystemPropBuildStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.quarkus.deployment.steps; | ||
|
||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.ExecutionTime; | ||
import io.quarkus.deployment.annotations.Record; | ||
import io.quarkus.deployment.builditem.SetClassPathSystemPropBuildItem; | ||
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; | ||
import io.quarkus.maven.dependency.ResolvedDependency; | ||
import io.quarkus.runtime.ClassPathSystemPropertyRecorder; | ||
|
||
public class ClassPathSystemPropBuildStep { | ||
|
||
@BuildStep | ||
public void produce(BuildProducer<SetClassPathSystemPropBuildItem> producer, CurateOutcomeBuildItem curateOutcome) { | ||
boolean truffleUsed = curateOutcome.getApplicationModel().getDependencies().stream() | ||
.anyMatch(d -> d.getGroupId().equals("org.graalvm.polyglot")); | ||
if (truffleUsed) { | ||
producer.produce(new SetClassPathSystemPropBuildItem()); | ||
} | ||
} | ||
|
||
@BuildStep | ||
@Record(ExecutionTime.STATIC_INIT) | ||
public void set(List<SetClassPathSystemPropBuildItem> setCPItems, | ||
CurateOutcomeBuildItem curateOutcome, | ||
ClassPathSystemPropertyRecorder recorder) { | ||
if (setCPItems.isEmpty()) { | ||
return; | ||
} | ||
Collection<ResolvedDependency> runtimeDependencies = curateOutcome.getApplicationModel().getRuntimeDependencies(); | ||
List<Path> parentFirst = new ArrayList<>(); | ||
List<Path> regular = new ArrayList<>(); | ||
for (ResolvedDependency dependency : runtimeDependencies) { | ||
if (dependency.isClassLoaderParentFirst()) { | ||
parentFirst.addAll(dependency.getContentTree().getRoots()); | ||
} else { | ||
regular.addAll(dependency.getContentTree().getRoots()); | ||
|
||
} | ||
} | ||
String classPathValue = Stream.concat(parentFirst.stream(), regular.stream()).map(p -> p.toAbsolutePath().toString()) | ||
.collect(Collectors.joining(":")); | ||
recorder.set(classPathValue); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
core/runtime/src/main/java/io/quarkus/runtime/ClassPathSystemPropertyRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.quarkus.runtime; | ||
|
||
import io.quarkus.runtime.annotations.Recorder; | ||
|
||
@Recorder | ||
public class ClassPathSystemPropertyRecorder { | ||
|
||
public void set(String value) { | ||
System.setProperty("java.class.path", value); | ||
} | ||
} |