Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer workspace paths only for artifacts that are not extensions or their dependencies #20572

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
}
Expand All @@ -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<RemoteRepository> managedRepos) throws BootstrapMavenException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does bringing if (extDep!=null)... under if(add) do?

newRtDep.setRuntimeExtensionArtifact();
}
Expand Down