Skip to content

Commit

Permalink
Merge pull request #41591 from gsmet/clean-IsolatedDevModeMain
Browse files Browse the repository at this point in the history
Clean up IsolatedDevModeMain when closing a bit more
  • Loading branch information
gsmet authored Jul 2, 2024
2 parents dbf1368 + 1cc97ce commit 8abd7e2
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 8abd7e2

Please sign in to comment.