From c83bb84aa5b9c87db15d7273cd34b97dca328180 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Tue, 28 Jul 2020 12:00:04 +1000 Subject: [PATCH] Remote dev clean up - Don't run the remote sync handler in local dev - Clarify in the doc's that you don't run maven on the remote side Fixes #10998 --- .../io/quarkus/deployment/dev/DevModeMain.java | 9 +++++++-- .../deployment/dev/IsolatedDevModeMain.java | 12 +++++++----- .../deployment/dev/IsolatedRemoteDevModeMain.java | 5 ++++- .../deployment/dev/RuntimeUpdatesProcessor.java | 14 +++++++++++++- .../quarkus/deployment/mutability/DevModeTask.java | 2 ++ .../main/java/io/quarkus/dev/spi/DevModeType.java | 7 +++++++ .../io/quarkus/dev/spi/HotReplacementContext.java | 7 +++++++ docs/src/main/asciidoc/maven-tooling.adoc | 4 ++++ .../vertx/http/runtime/VertxHttpRecorder.java | 4 +++- 9 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 core/devmode-spi/src/main/java/io/quarkus/dev/spi/DevModeType.java diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/DevModeMain.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/DevModeMain.java index 17b1f78943c22..e3cc91007e1d6 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/DevModeMain.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/DevModeMain.java @@ -15,7 +15,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Collections; +import java.util.HashMap; import java.util.Map; import java.util.Properties; @@ -29,6 +29,7 @@ import io.quarkus.bootstrap.model.PathsCollection; import io.quarkus.deployment.util.ProcessUtil; import io.quarkus.dev.appstate.ApplicationStateNotification; +import io.quarkus.dev.spi.DevModeType; /** * The main entry point for the dev mojo execution @@ -135,11 +136,15 @@ public void start() throws Exception { Properties buildSystemProperties = new Properties(); buildSystemProperties.putAll(context.getBuildSystemProperties()); bootstrapBuilder.setBuildSystemProperties(buildSystemProperties); + + Map map = new HashMap<>(); + map.put(DevModeContext.class.getName(), context); + map.put(DevModeType.class.getName(), DevModeType.LOCAL); curatedApplication = bootstrapBuilder.setTest(context.isTest()).build().bootstrap(); realCloseable = (Closeable) curatedApplication.runInAugmentClassLoader( context.getAlternateEntryPoint() == null ? IsolatedDevModeMain.class.getName() : context.getAlternateEntryPoint(), - Collections.singletonMap(DevModeContext.class.getName(), context)); + map); } catch (Throwable t) { log.error("Quarkus dev mode failed to start", t); throw new RuntimeException(t); diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedDevModeMain.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedDevModeMain.java index 9cb72286042ad..08fc3d718e0d7 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedDevModeMain.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedDevModeMain.java @@ -41,6 +41,7 @@ import io.quarkus.deployment.builditem.ApplicationClassPredicateBuildItem; import io.quarkus.deployment.codegen.CodeGenData; import io.quarkus.deployment.util.FSWatchUtil; +import io.quarkus.dev.spi.DevModeType; import io.quarkus.dev.spi.HotReplacementSetup; import io.quarkus.runner.bootstrap.AugmentActionImpl; import io.quarkus.runtime.ApplicationLifecycleManager; @@ -183,7 +184,7 @@ public synchronized void restartApp(Set changedResources) { } } - private RuntimeUpdatesProcessor setupRuntimeCompilation(DevModeContext context, Path appRoot) + private RuntimeUpdatesProcessor setupRuntimeCompilation(DevModeContext context, Path appRoot, DevModeType devModeType) throws Exception { if (!context.getAllModules().isEmpty()) { ServiceLoader serviceLoader = ServiceLoader.load(CompilationProvider.class); @@ -201,7 +202,7 @@ private RuntimeUpdatesProcessor setupRuntimeCompilation(DevModeContext context, return null; } RuntimeUpdatesProcessor processor = new RuntimeUpdatesProcessor(appRoot, context, compiler, - this::restartApp, null); + devModeType, this::restartApp, null); for (HotReplacementSetup service : ServiceLoader.load(HotReplacementSetup.class, curatedApplication.getBaseRuntimeClassLoader())) { @@ -264,7 +265,7 @@ public void close() { //the main entry point, but loaded inside the augmentation class loader @Override - public void accept(CuratedApplication o, Map o2) { + public void accept(CuratedApplication o, Map params) { Timing.staticInitStarted(o.getBaseRuntimeClassLoader()); //https://github.com/quarkusio/quarkus/issues/9748 //if you have an app with all daemon threads then the app thread @@ -287,7 +288,7 @@ public void run() { try { curatedApplication = o; - Object potentialContext = o2.get(DevModeContext.class.getName()); + Object potentialContext = params.get(DevModeContext.class.getName()); if (potentialContext instanceof DevModeContext) { context = (DevModeContext) potentialContext; } else { @@ -336,7 +337,8 @@ public boolean test(String s) { sourcePath -> module.addSourcePaths(singleton(sourcePath.toAbsolutePath().toString())))); } } - runtimeUpdatesProcessor = setupRuntimeCompilation(context, (Path) o2.get(APP_ROOT)); + runtimeUpdatesProcessor = setupRuntimeCompilation(context, (Path) params.get(APP_ROOT), + (DevModeType) params.get(DevModeType.class.getName())); if (runtimeUpdatesProcessor != null) { runtimeUpdatesProcessor.checkForFileChange(); runtimeUpdatesProcessor.checkForChangedClasses(); diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedRemoteDevModeMain.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedRemoteDevModeMain.java index bd598701aa60e..630ffb6dc0314 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedRemoteDevModeMain.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedRemoteDevModeMain.java @@ -38,6 +38,7 @@ import io.quarkus.deployment.mutability.DevModeTask; import io.quarkus.deployment.pkg.PackageConfig; import io.quarkus.deployment.pkg.steps.JarResultBuildStep; +import io.quarkus.dev.spi.DevModeType; import io.quarkus.dev.spi.HotReplacementSetup; import io.quarkus.dev.spi.RemoteDevState; import io.quarkus.runner.bootstrap.AugmentActionImpl; @@ -121,8 +122,10 @@ private RuntimeUpdatesProcessor setupRuntimeCompilation(DevModeContext context, log.error("Failed to create compiler, runtime compilation will be unavailable", e); return null; } + //this is never the remote side RuntimeUpdatesProcessor processor = new RuntimeUpdatesProcessor(applicationRoot, context, compiler, - this::regenerateApplication, new BiConsumer() { + DevModeType.REMOTE_LOCAL_SIDE, this::regenerateApplication, + new BiConsumer() { @Override public void accept(DevModeContext.ModuleInfo moduleInfo, String s) { copiedStaticResources.computeIfAbsent(moduleInfo, ss -> new HashSet<>()).add(s); diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/RuntimeUpdatesProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/RuntimeUpdatesProcessor.java index e7b1e393417d6..ff9c291504eee 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/RuntimeUpdatesProcessor.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/RuntimeUpdatesProcessor.java @@ -34,6 +34,7 @@ import io.quarkus.bootstrap.runner.Timing; import io.quarkus.deployment.util.FSWatchUtil; import io.quarkus.deployment.util.FileUtil; +import io.quarkus.dev.spi.DevModeType; import io.quarkus.dev.spi.HotReplacementContext; import io.quarkus.dev.spi.HotReplacementSetup; @@ -46,6 +47,7 @@ public class RuntimeUpdatesProcessor implements HotReplacementContext, Closeable private final Path applicationRoot; private final DevModeContext context; private final ClassLoaderCompiler compiler; + private final DevModeType devModeType; volatile Throwable compileProblem; // file path -> isRestartNeeded @@ -78,10 +80,12 @@ public class RuntimeUpdatesProcessor implements HotReplacementContext, Closeable private final BiConsumer copyResourceNotification; public RuntimeUpdatesProcessor(Path applicationRoot, DevModeContext context, ClassLoaderCompiler compiler, - Consumer> restartCallback, BiConsumer copyResourceNotification) { + DevModeType devModeType, Consumer> restartCallback, + BiConsumer copyResourceNotification) { this.applicationRoot = applicationRoot; this.context = context; this.compiler = compiler; + this.devModeType = devModeType; this.restartCallback = restartCallback; this.copyResourceNotification = copyResourceNotification; } @@ -147,6 +151,11 @@ public boolean isTest() { return context.isTest(); } + @Override + public DevModeType getDevModeType() { + return devModeType; + } + @Override public boolean doScan(boolean userInitiated) throws IOException { final long startNanoseconds = System.nanoTime(); @@ -200,6 +209,9 @@ public void consumeNoRestartChanges(Consumer> consumer) { @Override public Set syncState(Map fileHashes) { + if (getDevModeType() != DevModeType.REMOTE_SERVER_SIDE) { + throw new RuntimeException("Can only sync state on the server side of remote dev mode"); + } Set ret = new HashSet<>(); try { Map ourHashes = new HashMap<>(IsolatedRemoteDevModeMain.createHashes(applicationRoot)); diff --git a/core/deployment/src/main/java/io/quarkus/deployment/mutability/DevModeTask.java b/core/deployment/src/main/java/io/quarkus/deployment/mutability/DevModeTask.java index 4d25956d8dab1..5dbdd223da32e 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/mutability/DevModeTask.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/mutability/DevModeTask.java @@ -32,6 +32,7 @@ import io.quarkus.deployment.dev.DevModeContext; import io.quarkus.deployment.dev.IsolatedDevModeMain; import io.quarkus.deployment.pkg.steps.JarResultBuildStep; +import io.quarkus.dev.spi.DevModeType; @SuppressWarnings("Unused") public class DevModeTask { @@ -65,6 +66,7 @@ public static Closeable main(Path appRoot) throws Exception { Map map = new HashMap<>(); map.put(DevModeContext.class.getName(), context); map.put(IsolatedDevModeMain.APP_ROOT, appRoot); + map.put(DevModeType.class.getName(), DevModeType.REMOTE_SERVER_SIDE); return (Closeable) bootstrap.runInAugmentClassLoader(IsolatedDevModeMain.class.getName(), map); diff --git a/core/devmode-spi/src/main/java/io/quarkus/dev/spi/DevModeType.java b/core/devmode-spi/src/main/java/io/quarkus/dev/spi/DevModeType.java new file mode 100644 index 0000000000000..03229cdffed79 --- /dev/null +++ b/core/devmode-spi/src/main/java/io/quarkus/dev/spi/DevModeType.java @@ -0,0 +1,7 @@ +package io.quarkus.dev.spi; + +public enum DevModeType { + LOCAL, + REMOTE_LOCAL_SIDE, + REMOTE_SERVER_SIDE +} diff --git a/core/devmode-spi/src/main/java/io/quarkus/dev/spi/HotReplacementContext.java b/core/devmode-spi/src/main/java/io/quarkus/dev/spi/HotReplacementContext.java index c2e6b14bfe14b..c5ce87305b032 100644 --- a/core/devmode-spi/src/main/java/io/quarkus/dev/spi/HotReplacementContext.java +++ b/core/devmode-spi/src/main/java/io/quarkus/dev/spi/HotReplacementContext.java @@ -26,6 +26,13 @@ public interface HotReplacementContext { */ boolean isTest(); + /** + * Will return true if this is the remote side of a remote dev session + * + * @return + */ + DevModeType getDevModeType(); + /** * * @return {@code true} if a restart was performed, {@code false} otherwise diff --git a/docs/src/main/asciidoc/maven-tooling.adoc b/docs/src/main/asciidoc/maven-tooling.adoc index 007a3fe3b247b..c63409ff1735f 100644 --- a/docs/src/main/asciidoc/maven-tooling.adoc +++ b/docs/src/main/asciidoc/maven-tooling.adoc @@ -178,6 +178,10 @@ on bare metal you can just set this via the `export QUARKUS_LAUNCH_DEVMODE=true` docker start the image with `-e QUARKUS_LAUNCH_DEVMODE=true`. When the application starts you should now see the following line in the logs: `Profile dev activated. Live Coding activated`. +NOTE: The remote side does not need to include Maven or any other development tools. The normal `fast-jar` Dockerfile +that is generated with a new Quarkus application is all you need. If you are using bare metal launch the Quarkus runner +jar, do not attempt to run normal devmode. + Now you need to connect your local agent to the remote host, using the `remote-dev` command: [source,shell] diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java index 5a39a7b39d5e4..c2cbaf82bc514 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java @@ -38,6 +38,7 @@ import io.quarkus.arc.Arc; import io.quarkus.arc.runtime.BeanContainer; import io.quarkus.bootstrap.runner.Timing; +import io.quarkus.dev.spi.DevModeType; import io.quarkus.dev.spi.HotReplacementContext; import io.quarkus.netty.runtime.virtual.VirtualAddress; import io.quarkus.netty.runtime.virtual.VirtualChannel; @@ -400,7 +401,8 @@ public void handle(RoutingContext event) { } }); } - if (launchMode == LaunchMode.DEVELOPMENT && liveReloadConfig.password.isPresent()) { + if (launchMode == LaunchMode.DEVELOPMENT && liveReloadConfig.password.isPresent() + && hotReplacementContext.getDevModeType() == DevModeType.REMOTE_SERVER_SIDE) { root = remoteSyncHandler = new RemoteSyncHandler(liveReloadConfig.password.get(), root, hotReplacementContext); } rootHandler = root;