Skip to content

Commit

Permalink
Avoid race condition when creating 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.
  • Loading branch information
gsmet authored and ebullient committed Apr 29, 2021
1 parent 049322c commit 58f78c5
Showing 1 changed file with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,33 @@ public ServiceStartBuildItem setupDeploymentSideHandling(List<DevTemplatePathBui
return null;
}

@Record(ExecutionTime.RUNTIME_INIT)
@BuildStep(onlyIf = IsDevelopment.class)
public void setupDevConsoleRoutes(List<DevConsoleRouteBuildItem> routes,
BuildProducer<RouteBuildItem> routeBuildItemBuildProducer,
public void setupDevConsoleRoutes(
DevConsoleRecorder recorder,
List<DevConsoleRouteBuildItem> routes,
CurateOutcomeBuildItem curateOutcomeBuildItem,
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());

for (DevConsoleRouteBuildItem i : routes) {
Entry<String, String> groupAndArtifact = i.groupIdAndArtifactId(curateOutcomeBuildItem);
// if the handler is a proxy, then that means it's been produced by a recorder and therefore belongs in the regular runtime Vert.x instance
Expand Down Expand Up @@ -313,29 +330,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 58f78c5

Please sign in to comment.