Skip to content

Commit

Permalink
Dev UI - handle file protocol for DevConsoleRuntimeTemplateInfoBuildItem
Browse files Browse the repository at this point in the history
- resolves quarkusio#17915
- follows up on quarkusio#17007
  • Loading branch information
mkouba committed Jun 16, 2021
1 parent 787bc2c commit 3260b9b
Showing 1 changed file with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public static Map.Entry<String, String> groupIdAndArtifactId(Class<?> clazz) {
public static Map.Entry<String, String> groupIdAndArtifactId(Class<?> clazz,
CurateOutcomeBuildItem curateOutcomeBuildItem) {
try {
URL jarLocation = clazz.getProtectionDomain().getCodeSource().getLocation();
if (jarLocation.toString().endsWith(".jar")) {
try (FileSystem fs = FileSystems.newFileSystem(Paths.get(jarLocation.toURI()),
URL codeLocation = clazz.getProtectionDomain().getCodeSource().getLocation();
if (codeLocation.toString().endsWith(".jar")) {
try (FileSystem fs = FileSystems.newFileSystem(Paths.get(codeLocation.toURI()),
Thread.currentThread().getContextClassLoader())) {
Entry<String, String> ret = groupIdAndArtifactId(fs);
if (ret == null) {
Expand All @@ -55,7 +55,7 @@ public static Map.Entry<String, String> groupIdAndArtifactId(Class<?> clazz,
}
} else if (curateOutcomeBuildItem != null) {
// this is needed only for QuarkusDevModeTest inside Quarkus where the class is read from the corresponding directory
Path path = Paths.get(jarLocation.toURI());
Path path = Paths.get(codeLocation.toURI());
for (AppDependency i : curateOutcomeBuildItem.getEffectiveModel().getFullDeploymentDeps()) {
for (Path p : i.getArtifact().getPaths()) {
if (path.equals(p)) {
Expand All @@ -69,6 +69,30 @@ public static Map.Entry<String, String> groupIdAndArtifactId(Class<?> clazz,
}
}
return new AbstractMap.SimpleEntry<>("unspecified", "unspecified");
} else if ("file".equals(codeLocation.getProtocol())) {
// E.g. /quarkus/extensions/arc/deployment/target/classes/io/quarkus/arc/deployment/devconsole
// 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 location = Paths.get(codeLocation.toURI());
while (!isDeploymentTargetClasses(location) && location.getParent() != null) {
location = location.getParent();
}
if (location != null) {
Path mavenArchiver = location.getParent().resolve("maven-archiver");
if (mavenArchiver.toFile().canRead()) {
Entry<String, String> ret = groupIdAndArtifactId(mavenArchiver);
if (ret == null) {
throw new RuntimeException(
"Unable to determine groupId and artifactId of the extension that contains "
+ clazz.getName()
+ " because the directory doesn't contain the necessary metadata");
}
return ret;
}
}
return new AbstractMap.SimpleEntry<>("unspecified", "unspecified");
} else {
return new AbstractMap.SimpleEntry<>("unspecified", "unspecified");
}
Expand All @@ -78,6 +102,21 @@ public static Map.Entry<String, String> groupIdAndArtifactId(Class<?> clazz,
}
}

static boolean isDeploymentTargetClasses(Path location) {
if (!location.getFileName().toString().equals("classes")) {
return false;
}
Path target = location.getParent();
if (target == null || !target.getFileName().toString().equals("target")) {
return false;
}
Path deployment = location.getParent().getParent();
if (deployment == null || !deployment.getFileName().toString().equals("deployment")) {
return false;
}
return true;
}

/**
* Returns a Map.Entry containing the groupId and the artifactId of the module the contains the BuildItem
* <p>
Expand Down

0 comments on commit 3260b9b

Please sign in to comment.