-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12664 from mswiderski/cl-reset
Make deployment class loader resettable and coordinate the reset via a BuildItem
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...rc/main/java/io/quarkus/deployment/builditem/AdditionalClassLoaderResourcesBuildItem.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,19 @@ | ||
package io.quarkus.deployment.builditem; | ||
|
||
import java.util.Map; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
public final class AdditionalClassLoaderResourcesBuildItem extends MultiBuildItem { | ||
|
||
final Map<String, byte[]> resources; | ||
|
||
public AdditionalClassLoaderResourcesBuildItem(Map<String, byte[]> resources) { | ||
this.resources = resources; | ||
} | ||
|
||
public Map<String, byte[]> getResources() { | ||
return resources; | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...nt/src/main/java/io/quarkus/deployment/steps/AdditionalClassLoaderResourcesBuildStep.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,45 @@ | ||
package io.quarkus.deployment.steps; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
|
||
import io.quarkus.bootstrap.classloading.QuarkusClassLoader; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.AdditionalClassLoaderResourcesBuildItem; | ||
import io.quarkus.deployment.builditem.AdditionalIndexedClassesBuildItem; | ||
|
||
public class AdditionalClassLoaderResourcesBuildStep { | ||
|
||
@BuildStep | ||
void appendAdditionalClassloaderResources(BuildProducer<AdditionalIndexedClassesBuildItem> producer, | ||
List<AdditionalClassLoaderResourcesBuildItem> additionalResources) { | ||
|
||
if (!additionalResources.isEmpty()) { | ||
QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader(); | ||
|
||
Map<String, byte[]> collected = new LinkedHashMap<String, byte[]>(); | ||
List<String> additionalClassesToIndex = new ArrayList<String>(); | ||
for (AdditionalClassLoaderResourcesBuildItem item : additionalResources) { | ||
|
||
for (Entry<String, byte[]> entry : item.getResources().entrySet()) { | ||
additionalClassesToIndex.add(entry.getKey()); | ||
|
||
collected.put(entry.getKey(), entry.getValue()); | ||
// add it also as resources to allow index to work properly | ||
collected.put(entry.getKey().replace('.', '/') + ".class", entry.getValue()); | ||
|
||
} | ||
} | ||
|
||
cl.reset(collected, Collections.emptyMap()); | ||
// produce the AdditionalIndexedClassesBuildItem so this build step | ||
// is actually invoked and allow to directly index all the classes | ||
producer.produce(new AdditionalIndexedClassesBuildItem(additionalClassesToIndex.stream().toArray(String[]::new))); | ||
} | ||
} | ||
} |
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