diff --git a/core/deployment/src/main/java/io/quarkus/deployment/util/ArtifactInfoUtil.java b/core/deployment/src/main/java/io/quarkus/deployment/util/ArtifactInfoUtil.java index 4fc1c5974687f8..03c7d237923c05 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/util/ArtifactInfoUtil.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/util/ArtifactInfoUtil.java @@ -87,11 +87,11 @@ public static Map.Entry groupIdAndArtifactId(Class clazz, */ public static Map.Entry groupIdAndArtifactId(FileSystem fs) throws IOException { Path metaInfPath = fs.getPath("/META-INF"); - return doGroupIdAndArtifactId(metaInfPath); + return groupIdAndArtifactId(metaInfPath); } - private static AbstractMap.SimpleEntry doGroupIdAndArtifactId(Path metaInfPath) throws IOException { - Optional pomProperties = Files.walk(metaInfPath) + public static AbstractMap.SimpleEntry groupIdAndArtifactId(Path pomPropertiesContainer) throws IOException { + Optional pomProperties = Files.walk(pomPropertiesContainer) .filter(Files::isRegularFile) .filter(p -> p.toString().endsWith("pom.properties")) .findFirst(); diff --git a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java index 41231cc4f8513c..2362dd66f9320b 100644 --- a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java +++ b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.io.Reader; import java.io.StringReader; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; import java.net.URLDecoder; @@ -581,28 +582,46 @@ void collectTemplates(BuildProducer devTemplatePaths) ClassLoader classLoader = DevConsoleProcessor.class.getClassLoader(); Enumeration devTemplateURLs = classLoader.getResources("/dev-templates"); while (devTemplateURLs.hasMoreElements()) { - String devTemplatesURL = devTemplateURLs.nextElement().toExternalForm(); - if (devTemplatesURL.startsWith("jar:file:") && devTemplatesURL.endsWith("!/dev-templates")) { - String jarPath = devTemplatesURL.substring(9, devTemplatesURL.length() - 15); + URL devTemplatesURL = devTemplateURLs.nextElement(); + String devTemplatesURLStr = devTemplatesURL.toExternalForm(); + if (devTemplatesURLStr.startsWith("jar:file:") && devTemplatesURLStr.endsWith("!/dev-templates")) { + String jarPath = devTemplatesURLStr.substring(9, devTemplatesURLStr.length() - 15); if (File.separatorChar == '\\') { // on Windows this will be /C:/some/path, so turn it into C:\some\path jarPath = jarPath.substring(1).replace('/', '\\'); } try (FileSystem fs = FileSystems .newFileSystem(Paths.get(URLDecoder.decode(jarPath, StandardCharsets.UTF_8.name())), classLoader)) { - scanTemplates(fs, devTemplatePaths); + scanTemplates(fs, null, fs.getRootDirectories(), devTemplatePaths); + } + } else if ("file".equals(devTemplatesURL.getProtocol())) { + // This can happen if you run an example app in dev mode + // and this app is part of a multi-module project which also declares the extension + // Just try to locate the pom.properties file in the target/maven-archiver directory + // Note that this hack will not work if addMavenDescriptor=false or if the pomPropertiesFile is overriden + Path classes = Paths.get(devTemplatesURL.toURI()).getParent(); + Path target = classes != null ? classes.getParent() : null; + if (target != null) { + Path mavenArchiver = target.resolve("maven-archiver"); + if (mavenArchiver.toFile().canRead()) { + scanTemplates(null, mavenArchiver, Collections.singleton(classes), devTemplatePaths); + } } } } - } catch (IOException e) { + } catch (IOException | URISyntaxException e) { throw new RuntimeException(e); } } - private void scanTemplates(FileSystem fs, BuildProducer devTemplatePaths) throws IOException { - Entry entry = ArtifactInfoUtil.groupIdAndArtifactId(fs); + private void scanTemplates(FileSystem fs, Path pomPropertiesPath, Iterable rootDirectories, + BuildProducer devTemplatePaths) + throws IOException { + Entry entry = fs != null ? ArtifactInfoUtil.groupIdAndArtifactId(fs) + : ArtifactInfoUtil.groupIdAndArtifactId(pomPropertiesPath); if (entry == null) { - throw new RuntimeException("Artifact at " + fs + " is missing pom metadata"); + throw new RuntimeException("Missing pom metadata [fileSystem: " + fs + ", rootDirectories: " + rootDirectories + + ", pomPath: " + pomPropertiesPath + "]"); } String prefix; // don't move stuff for our "root" dev console artifact, since it includes the main template @@ -611,12 +630,13 @@ private void scanTemplates(FileSystem fs, BuildProducer() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { - if (dir.toString().equals("/") || dir.startsWith(devTemplatesPath)) + if (dir.equals(root) || dir.toString().equals("/") || dir.startsWith(devTemplatesPath)) return FileVisitResult.CONTINUE; return FileVisitResult.SKIP_SUBTREE; }