diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/BootstrapConstants.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/BootstrapConstants.java index 9d0a77e3aad46..366b96744a89b 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/BootstrapConstants.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/BootstrapConstants.java @@ -28,6 +28,7 @@ public interface BootstrapConstants { String META_INF = "META-INF"; String DESCRIPTOR_PATH = META_INF + '/' + DESCRIPTOR_FILE_NAME; + String BUILD_STEPS_PATH = META_INF + "/quarkus-build-steps.list"; String PROP_DEPLOYMENT_ARTIFACT = "deployment-artifact"; String PROP_PROVIDES_CAPABILITIES = "provides-capabilities"; diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/BootstrapAppModelResolver.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/BootstrapAppModelResolver.java index 4f7d8ff9b9dfc..c713a2c7cde11 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/BootstrapAppModelResolver.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/BootstrapAppModelResolver.java @@ -8,8 +8,10 @@ import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException; import io.quarkus.bootstrap.resolver.maven.BuildDependencyGraphVisitor; import io.quarkus.bootstrap.resolver.maven.DeploymentInjectingDependencyVisitor; +import io.quarkus.bootstrap.resolver.maven.DeploymentInjectionException; import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; import io.quarkus.bootstrap.resolver.maven.SimpleDependencyGraphTransformationContext; +import io.quarkus.bootstrap.util.ZipUtils; import io.quarkus.bootstrap.workspace.ProcessedSources; import io.quarkus.bootstrap.workspace.WorkspaceModule; import io.quarkus.maven.dependency.ArtifactCoords; @@ -21,6 +23,9 @@ import io.quarkus.maven.dependency.ResolvedDependencyBuilder; import io.quarkus.paths.PathCollection; import io.quarkus.paths.PathList; +import java.io.IOException; +import java.nio.file.FileSystem; +import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; @@ -191,6 +196,7 @@ private ApplicationModel doResolveModel(ArtifactCoords coords, } final ResolvedDependency appArtifact = resolve(coords, mvnArtifact, managedRepos); + final boolean preferWorkspacePaths = !containsExtensionMetadata(appArtifact) && (devmode || test); final ApplicationModelBuilder appBuilder = new ApplicationModelBuilder().setAppArtifact(appArtifact); if (appArtifact.getWorkspaceModule() != null) { @@ -227,7 +233,8 @@ private ApplicationModel doResolveModel(ArtifactCoords coords, final DeploymentInjectingDependencyVisitor deploymentInjector; try { - deploymentInjector = new DeploymentInjectingDependencyVisitor(mvn, managedDeps, repos, appBuilder, devmode || test, + deploymentInjector = new DeploymentInjectingDependencyVisitor(mvn, managedDeps, repos, appBuilder, + preferWorkspacePaths, collectReloadableDeps && reloadableModules.isEmpty()); deploymentInjector.injectDeploymentDependencies(resolvedDeps); } catch (BootstrapDependencyProcessingException e) { @@ -276,7 +283,7 @@ private ApplicationModel doResolveModel(ArtifactCoords coords, } } appBuilder.addDependency( - toAppArtifact(dep.getArtifact(), module, devmode || test) + toAppArtifact(dep.getArtifact(), module, false) .setScope(dep.getDependency().getScope()) .setFlags(flags).build()); } @@ -288,6 +295,36 @@ private ApplicationModel doResolveModel(ArtifactCoords coords, return appBuilder.build(); } + private static boolean containsExtensionMetadata(ResolvedDependency dep) { + if (!ArtifactCoords.TYPE_JAR.equals(dep.getType())) { + return false; + } + for (Path path : dep.getResolvedPaths()) { + if (!Files.exists(path)) { + continue; + } + if (Files.isDirectory(path)) { + if (containsExtensionMetadata(path)) { + return true; + } + } else { + try (FileSystem artifactFs = ZipUtils.newFileSystem(path)) { + if (containsExtensionMetadata(artifactFs.getPath(""))) { + return true; + } + } catch (IOException e) { + throw new DeploymentInjectionException("Failed to read " + path, e); + } + } + } + return false; + } + + private static boolean containsExtensionMetadata(final Path path) { + return Files.exists(path.resolve(BootstrapConstants.BUILD_STEPS_PATH)) + || Files.exists(path.resolve(BootstrapConstants.DESCRIPTOR_PATH)); + } + private io.quarkus.maven.dependency.ResolvedDependency resolve(ArtifactCoords appArtifact, Artifact mvnArtifact, List managedRepos) throws BootstrapMavenException { diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/DeploymentInjectingDependencyVisitor.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/DeploymentInjectingDependencyVisitor.java index 037684a8b9207..ac5e92d03ccda 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/DeploymentInjectingDependencyVisitor.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/DeploymentInjectingDependencyVisitor.java @@ -183,31 +183,33 @@ private void visitRuntimeDependency(DependencyNode node) { } Artifact artifact = node.getArtifact(); - ResolvedDependencyBuilder newRtDep = null; - if (allRuntimeDeps.add(getKey(artifact))) { + final boolean add = allRuntimeDeps.add(getKey(artifact)); + if (add) { artifact = resolve(artifact); - WorkspaceModule module = null; - if (resolver.getProjectModuleResolver() != null) { - module = resolver.getProjectModuleResolver().getProjectModule(artifact.getGroupId(), artifact.getArtifactId()); - } - newRtDep = toAppArtifact(artifact, module, preferWorkspacePaths) - .setRuntimeCp() - .setDeploymentCp() - .setOptional(node.getDependency().isOptional()) - .setScope(node.getDependency().getScope()) - .setDirect(collectingDirectDeps); - if (module != null) { - newRtDep.setWorkspaceModule().setReloadable(); - if (collectReloadableModules) { - appBuilder.addReloadableWorkspaceModule(new GACT(artifact.getGroupId(), artifact.getArtifactId())); - } - } } try { final ExtensionDependency extDep = getExtensionDependencyOrNull(node, artifact); - if (newRtDep != null) { + if (add) { + WorkspaceModule module = null; + if (resolver.getProjectModuleResolver() != null) { + module = resolver.getProjectModuleResolver().getProjectModule(artifact.getGroupId(), + artifact.getArtifactId()); + } + final ResolvedDependencyBuilder newRtDep = toAppArtifact(artifact, module, + preferWorkspacePaths && extDep == null && collectingTopExtensionRuntimeNodes) + .setRuntimeCp() + .setDeploymentCp() + .setOptional(node.getDependency().isOptional()) + .setScope(node.getDependency().getScope()) + .setDirect(collectingDirectDeps); + if (module != null) { + newRtDep.setWorkspaceModule().setReloadable(); + if (collectReloadableModules) { + appBuilder.addReloadableWorkspaceModule(new GACT(artifact.getGroupId(), artifact.getArtifactId())); + } + } if (extDep != null) { newRtDep.setRuntimeExtensionArtifact(); }