Skip to content

Commit

Permalink
Merge pull request #39483 from Ladicek/application-archive-resolved-d…
Browse files Browse the repository at this point in the history
…ependency

Add ApplicationArchive.getResolvedDependency()
  • Loading branch information
Ladicek authored Mar 19, 2024
2 parents 306fa0a + b755b61 commit c80bfb1
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.bootstrap.model.PathsCollection;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.paths.OpenPathTree;
import io.quarkus.paths.PathCollection;

Expand Down Expand Up @@ -83,6 +84,12 @@ public interface ApplicationArchive {
*/
ArtifactKey getKey();

/**
*
* @return the resolved artifact or {@code null} if not available
*/
ResolvedDependency getResolvedDependency();

/**
* Applies a function to the content tree of the archive.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.quarkus.bootstrap.model.PathsCollection;
import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.paths.OpenPathTree;
import io.quarkus.paths.PathCollection;
import io.quarkus.paths.PathList;
Expand All @@ -20,12 +21,12 @@ public final class ApplicationArchiveImpl extends MultiBuildItem implements Appl

private final IndexView indexView;
private final OpenPathTree openTree;
private final ArtifactKey artifactKey;
private final ResolvedDependency resolvedDependency;

public ApplicationArchiveImpl(IndexView indexView, OpenPathTree openTree, ArtifactKey artifactKey) {
public ApplicationArchiveImpl(IndexView indexView, OpenPathTree openTree, ResolvedDependency resolvedDependency) {
this.indexView = indexView;
this.openTree = openTree;
this.artifactKey = artifactKey;
this.resolvedDependency = resolvedDependency;
}

@Override
Expand Down Expand Up @@ -68,14 +69,22 @@ public PathCollection getResolvedPaths() {
* @return archive key
*/
public AppArtifactKey getArtifactKey() {
return artifactKey == null ? null
: new AppArtifactKey(artifactKey.getGroupId(), artifactKey.getArtifactId(), artifactKey.getClassifier(),
artifactKey.getType());
if (resolvedDependency == null) {
return null;
}
ArtifactKey artifactKey = resolvedDependency.getKey();
return new AppArtifactKey(artifactKey.getGroupId(), artifactKey.getArtifactId(), artifactKey.getClassifier(),
artifactKey.getType());
}

@Override
public ArtifactKey getKey() {
return artifactKey;
return resolvedDependency != null ? resolvedDependency.getKey() : null;
}

@Override
public ResolvedDependency getResolvedDependency() {
return resolvedDependency;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ ApplicationArchivesBuildItem build(

return new ApplicationArchivesBuildItem(
new ApplicationArchiveImpl(appindex.getIndex(), tree,
curateOutcomeBuildItem.getApplicationModel().getAppArtifact().getKey()),
curateOutcomeBuildItem.getApplicationModel().getAppArtifact()),
applicationArchives);
}

Expand Down Expand Up @@ -187,7 +187,7 @@ private void addIndexDependencyPaths(List<IndexDependencyBuildItem> indexDepende
&& !root.getResolvedPaths().contains(path)
&& indexedDeps.add(path)) {
try {
appArchives.add(createApplicationArchive(buildCloseables, indexCache, path, dep.getKey(),
appArchives.add(createApplicationArchive(buildCloseables, indexCache, path, dep,
removedResources));
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand All @@ -199,10 +199,11 @@ private void addIndexDependencyPaths(List<IndexDependencyBuildItem> indexDepende
}

private static ApplicationArchive createApplicationArchive(QuarkusBuildCloseablesBuildItem buildCloseables,
IndexCache indexCache, Path dep, ArtifactKey artifactKey, Map<ArtifactKey, Set<String>> removedResources)
IndexCache indexCache, Path dep, ResolvedDependency resolvedDependency,
Map<ArtifactKey, Set<String>> removedResources)
throws IOException {
LOGGER.debugf("Indexing dependency: %s", dep);
final Set<String> removed = removedResources.get(artifactKey);
final Set<String> removed = resolvedDependency != null ? removedResources.get(resolvedDependency.getKey()) : null;
final OpenPathTree openTree;
final IndexView index;
if (Files.isDirectory(dep)) {
Expand All @@ -212,7 +213,7 @@ private static ApplicationArchive createApplicationArchive(QuarkusBuildCloseable
openTree = buildCloseables.add(PathTree.ofArchive(dep).open());
index = handleJarPath(dep, indexCache, removed);
}
return new ApplicationArchiveImpl(index, openTree, artifactKey);
return new ApplicationArchiveImpl(index, openTree, resolvedDependency);
}

private static void addMarkerFilePaths(Set<String> applicationArchiveMarkers,
Expand Down Expand Up @@ -253,7 +254,7 @@ private static void addMarkerFilePaths(Set<String> applicationArchiveMarkers,
}
indexCache.cache.put(rootPath, index);
}
appArchives.add(new ApplicationArchiveImpl(index, tree, dependencyKey));
appArchives.add(new ApplicationArchiveImpl(index, tree, cpe.getResolvedDependency()));
return null;
}

Expand All @@ -267,7 +268,7 @@ private static void addMarkerFilePaths(Set<String> applicationArchiveMarkers,
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return new ApplicationArchiveImpl(index, tree, dependencyKey);
return new ApplicationArchiveImpl(index, tree, cpe.getResolvedDependency());
});
if (archive != null) {
appArchives.add(archive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ private boolean possiblyBeanArchive(ApplicationArchive archive,
LOGGER.warnf("Detected bean archive with bean discovery mode of 'all', "
+ "this is not portable in CDI Lite and is treated as 'annotated' in Quarkus! "
+ "Path to beans.xml: %s",
archive.getKey() != null ? archive.getKey().toGacString() + ":" + pathVisit.getPath()
archive.getResolvedDependency() != null
? archive.getResolvedDependency().toCompactCoords() + ":" + pathVisit.getPath()
: pathVisit.getPath());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.ResolvedDependency;

/**
* Split package (same package coming from multiple app archives) is considered a bad practice and
Expand Down Expand Up @@ -105,9 +105,9 @@ void splitPackageDetection(ApplicationArchivesBuildItem archivesBuildItem,
Set<String> splitPackages = new TreeSet<>();
while (iterator.hasNext()) {
final ApplicationArchive next = iterator.next();
final ArtifactKey a = next.getKey();
ResolvedDependency dep = next.getResolvedDependency();
// can be null for instance in test mode where all application classes go under target/classes
if (a == null) {
if (dep == null) {
if (archivesBuildItem.getRootArchive().equals(next)) {
// the archive we found is a root archive, e.g. application classes
splitPackages.add("application classes");
Expand All @@ -122,8 +122,8 @@ void splitPackageDetection(ApplicationArchivesBuildItem archivesBuildItem,
}
}
} else {
// Generates an app archive information in form of groupId:artifactId:classifier:type
splitPackages.add(a.toString());
// Generates an app archive information in form of groupId:artifactId[:classifier][:type]:version
splitPackages.add(dep.toCompactCoords());
}
}
splitPackagesWarning.append(splitPackages.stream().collect(Collectors.joining(", ", "[", "]")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ static class ClassFilteredBannedElement implements ClassPathElement {
}

@Override
public ArtifactKey getDependencyKey() {
return delegate.getDependencyKey();
public ResolvedDependency getResolvedDependency() {
return delegate.getResolvedDependency();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ public interface ClassPathElement extends Closeable {
* this element does not represent any Maven artifact
*/
default ArtifactKey getDependencyKey() {
ResolvedDependency resolvedDependency = getResolvedDependency();
return resolvedDependency != null ? resolvedDependency.getKey() : null;
}

/**
* If this classpath element represents a Maven artifact, the method will return it,
* otherwise - null.
*
* @return the Maven artifact this classpath element represents or null, in case
* this element does not represent any Maven artifact
*/
default ResolvedDependency getResolvedDependency() {
return null;
}

Expand Down Expand Up @@ -85,7 +97,7 @@ static ClassPathElement fromPath(Path path, boolean runtime) {
}

static ClassPathElement fromDependency(ResolvedDependency dep) {
return new PathTreeClassPathElement(dep.getContentTree(), dep.isRuntimeCp(), dep.getKey());
return new PathTreeClassPathElement(dep.getContentTree(), dep.isRuntimeCp(), dep);
}

static ClassPathElement EMPTY = new ClassPathElement() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.function.Function;
import java.util.jar.Manifest;

import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.paths.OpenPathTree;

public class FilteredClassPathElement implements ClassPathElement {
Expand All @@ -23,8 +23,8 @@ public FilteredClassPathElement(ClassPathElement delegate, Collection<String> re
}

@Override
public ArtifactKey getDependencyKey() {
return delegate.getDependencyKey();
public ResolvedDependency getResolvedDependency() {
return delegate.getResolvedDependency();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import org.jboss.logging.Logger;

import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.paths.OpenPathTree;
import io.quarkus.paths.PathTree;
import io.quarkus.paths.PathVisit;
Expand All @@ -36,18 +36,18 @@ public class PathTreeClassPathElement extends AbstractClassPathElement {
private final ReadWriteLock lock;
private final OpenPathTree pathTree;
private final boolean runtime;
private final ArtifactKey dependencyKey;
private final ResolvedDependency resolvedDependency;
private volatile Set<String> resources;

public PathTreeClassPathElement(PathTree pathTree, boolean runtime) {
this(pathTree, runtime, null);
}

public PathTreeClassPathElement(PathTree pathTree, boolean runtime, ArtifactKey dependencyKey) {
public PathTreeClassPathElement(PathTree pathTree, boolean runtime, ResolvedDependency resolvedDependency) {
this.pathTree = Objects.requireNonNull(pathTree, "Path tree is null").open();
this.lock = new ReentrantReadWriteLock();
this.runtime = runtime;
this.dependencyKey = dependencyKey;
this.resolvedDependency = resolvedDependency;
}

@Override
Expand All @@ -56,8 +56,8 @@ public boolean isRuntime() {
}

@Override
public ArtifactKey getDependencyKey() {
return dependencyKey;
public ResolvedDependency getResolvedDependency() {
return resolvedDependency;
}

@Override
Expand Down

0 comments on commit c80bfb1

Please sign in to comment.