Skip to content

Commit

Permalink
Clean up IsolatedDevModeMain when closing a bit more
Browse files Browse the repository at this point in the history
Also avoid keeping a reference to the IsolatedDevModeMain instance in
the AugmentAction.
  • Loading branch information
gsmet committed Jul 1, 2024
1 parent ac65f68 commit 1cc97ce
Showing 1 changed file with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ public void close() {
restarting = true;
if (codeGenWatcher != null) {
codeGenWatcher.shutdown();
codeGenWatcher = null;
}

for (int i = listeners.size() - 1; i >= 0; i--) {
Expand All @@ -320,6 +321,7 @@ public void close() {
log.warn("Unable to invoke 'beforeShutdown' of " + listeners.get(i).getClass(), e);
}
}
listeners.clear();

try {
stop();
Expand All @@ -341,10 +343,13 @@ public void close() {
for (HotReplacementSetup i : hotReplacementSetups) {
i.close();
}
hotReplacementSetups.clear();
} finally {
try {
DevConsoleManager.close();
curatedApplication.close();
curatedApplication = null;
augmentAction = null;
} finally {
if (shutdownThread != null) {
try {
Expand Down Expand Up @@ -401,29 +406,7 @@ public void run() {
}

augmentAction = new AugmentActionImpl(curatedApplication,
List.of(new Consumer<BuildChainBuilder>() {
@Override
public void accept(BuildChainBuilder buildChainBuilder) {
buildChainBuilder.addBuildStep(new BuildStep() {
@Override
public void execute(BuildContext context) {
//we need to make sure all hot reloadable classes are application classes
context.produce(new ApplicationClassPredicateBuildItem(new Predicate<String>() {
@Override
public boolean test(String s) {
QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread()
.getContextClassLoader();
String resourceName = ClassloadHelper.fromClassNameToResourceName(s);
//if the class file is present in this (and not the parent) CL then it is an application class
List<ClassPathElement> res = cl
.getElementsWithResource(resourceName, true);
return !res.isEmpty();
}
}));
}
}).produces(ApplicationClassPredicateBuildItem.class).build();
}
}),
List.of(new AddApplicationClassPredicateBuildStep()),
List.of());

// code generators should be initialized before the runtime compilation is setup to properly configure the sources directories
Expand Down Expand Up @@ -475,4 +458,29 @@ public void run() {
throw toThrow;
}
}

private static class AddApplicationClassPredicateBuildStep implements Consumer<BuildChainBuilder> {

@Override
public void accept(BuildChainBuilder buildChainBuilder) {
buildChainBuilder.addBuildStep(new BuildStep() {
@Override
public void execute(BuildContext context) {
//we need to make sure all hot reloadable classes are application classes
context.produce(new ApplicationClassPredicateBuildItem(new Predicate<String>() {
@Override
public boolean test(String s) {
QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread()
.getContextClassLoader();
String resourceName = ClassloadHelper.fromClassNameToResourceName(s);
//if the class file is present in this (and not the parent) CL then it is an application class
List<ClassPathElement> res = cl
.getElementsWithResource(resourceName, true);
return !res.isEmpty();
}
}));
}
}).produces(ApplicationClassPredicateBuildItem.class).build();
}
}
}

0 comments on commit 1cc97ce

Please sign in to comment.