Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make deployment class loader resettable and coordinate the reset via a BuildItem #12664

Merged
merged 1 commit into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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