Skip to content

Commit

Permalink
Merge pull request #12664 from mswiderski/cl-reset
Browse files Browse the repository at this point in the history
Make deployment class loader resettable and coordinate the reset via a BuildItem
  • Loading branch information
jaikiran authored Oct 13, 2020
2 parents 6aab4a7 + 1671dce commit 8070d9f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
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;
}

}
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)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ public QuarkusClassLoader createDeploymentClassLoader() {
builder.addElement(ClassPathElement.fromPath(root));
}

builder.setResettableElement(new MemoryClassPathElement(Collections.emptyMap()));

//additional user class path elements first
for (AdditionalDependency i : quarkusBootstrap.getAdditionalApplicationArchives()) {
for (Path root : i.getArchivePath()) {
Expand Down

0 comments on commit 8070d9f

Please sign in to comment.