Skip to content

Commit

Permalink
Avoid race condition when creating the Dev UI routes
Browse files Browse the repository at this point in the history
We need the static resources route to be defined before /dev/* and this
wasn't guaranteed with two concurrent methods.

(cherry picked from commit dda1c9e)
  • Loading branch information
gsmet committed Mar 10, 2021
1 parent 4d2a230 commit 06e4ab8
Showing 1 changed file with 21 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,21 +296,37 @@ public ServiceStartBuildItem setupDeploymentSideHandling(List<DevTemplatePathBui
@Record(ExecutionTime.RUNTIME_INIT)
@Consume(LoggingSetupBuildItem.class)
@BuildStep(onlyIf = IsDevelopment.class)
public void setupDevConsoleRoutes(List<DevConsoleRouteBuildItem> routes,
BuildProducer<RouteBuildItem> routeBuildItemBuildProducer,
LogStreamRecorder recorder,
public void setupDevConsoleRoutes(
DevConsoleRecorder recorder,
LogStreamRecorder logStreamRecorder,
List<DevConsoleRouteBuildItem> routes,
CurateOutcomeBuildItem curateOutcomeBuildItem,
HistoryHandlerBuildItem historyHandlerBuildItem,
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
LaunchModeBuildItem launchModeBuildItem) {
LaunchModeBuildItem launchModeBuildItem,
ShutdownContextBuildItem shutdownContext,
BuildProducer<RouteBuildItem> routeBuildItemBuildProducer) throws IOException {
if (launchModeBuildItem.getDevModeType().orElse(null) != DevModeType.LOCAL) {
return;
}

// Add the static resources
AppArtifact devConsoleResourcesArtifact = WebJarUtil.getAppArtifact(curateOutcomeBuildItem, "io.quarkus",
"quarkus-vertx-http-deployment");

Path devConsoleStaticResourcesDeploymentPath = WebJarUtil.copyResourcesForDevOrTest(curateOutcomeBuildItem,
launchModeBuildItem,
devConsoleResourcesArtifact, STATIC_RESOURCES_PATH);

routeBuildItemBuildProducer.produce(nonApplicationRootPathBuildItem.routeBuilder()
.route("dev/resources/*")
.handler(recorder.devConsoleHandler(devConsoleStaticResourcesDeploymentPath.toString(), shutdownContext))
.build());

// Add the log stream
routeBuildItemBuildProducer.produce(nonApplicationRootPathBuildItem.routeBuilder()
.route("dev/logstream")
.handler(recorder.websocketHandler(historyHandlerBuildItem.value))
.handler(logStreamRecorder.websocketHandler(historyHandlerBuildItem.value))
.build());

for (DevConsoleRouteBuildItem i : routes) {
Expand Down Expand Up @@ -340,29 +356,6 @@ public void setupDevConsoleRoutes(List<DevConsoleRouteBuildItem> routes,
.build());
}

@BuildStep(onlyIf = IsDevelopment.class)
@Record(ExecutionTime.RUNTIME_INIT)
public void deployStaticResources(DevConsoleRecorder recorder, CurateOutcomeBuildItem curateOutcomeBuildItem,
LaunchModeBuildItem launchMode, ShutdownContextBuildItem shutdownContext,
BuildProducer<RouteBuildItem> routeBuildItemBuildProducer,
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
LaunchModeBuildItem launchModeBuildItem) throws IOException {

if (launchModeBuildItem.getDevModeType().orElse(DevModeType.LOCAL) != DevModeType.LOCAL) {
return;
}
AppArtifact devConsoleResourcesArtifact = WebJarUtil.getAppArtifact(curateOutcomeBuildItem, "io.quarkus",
"quarkus-vertx-http-deployment");

Path devConsoleStaticResourcesDeploymentPath = WebJarUtil.copyResourcesForDevOrTest(curateOutcomeBuildItem, launchMode,
devConsoleResourcesArtifact, STATIC_RESOURCES_PATH);

routeBuildItemBuildProducer.produce(nonApplicationRootPathBuildItem.routeBuilder()
.route("dev/resources/*")
.handler(recorder.devConsoleHandler(devConsoleStaticResourcesDeploymentPath.toString(), shutdownContext))
.build());
}

private Engine buildEngine(List<DevTemplatePathBuildItem> devTemplatePaths,
List<RouteBuildItem> allRoutes,
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem) {
Expand Down

0 comments on commit 06e4ab8

Please sign in to comment.