Skip to content

Commit

Permalink
Support for project modules that produce multiple JARs (with classifi…
Browse files Browse the repository at this point in the history
…ers)
  • Loading branch information
aloubyansky committed Jan 5, 2022
1 parent 77ed3b6 commit 8578ea9
Show file tree
Hide file tree
Showing 137 changed files with 4,131 additions and 1,208 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package io.quarkus.deployment;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Iterator;
import java.util.function.BiConsumer;
import java.util.function.Function;

import org.jboss.jandex.IndexView;

import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.bootstrap.model.PathsCollection;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.paths.OpenPathTree;
import io.quarkus.paths.PathCollection;

/**
Expand Down Expand Up @@ -83,34 +82,22 @@ public interface ApplicationArchive {
*/
ArtifactKey getKey();

/**
* Allows to apply a function to the content tree of the archive.
*
* @param <T> result type of the function
* @param func function to apply
* @return the result of the function
*/
<T> T withContentTree(Function<OpenPathTree, T> func);

/**
* Convenience method, returns the child path if it exists, otherwise null.
*
* @param path The child path
* @return The child path, or null if it does not exist.
*/
default Path getChildPath(String path) {
return getRootDirectories().resolveExistingOrNull(path);
}

/**
* Searches for the specified entry among the archive paths. If a root path appears to be a JAR,
* the entry will be searched among its entries. The first matched entry will be passed to the
* consumer along with its root path.
*
* @param path relative entry path
* @param consumer entry consumer
*/
default void processEntry(String path, BiConsumer<Path, Path> consumer) {
final Iterator<Path> dirs = getRootDirectories().iterator();
final Iterator<Path> paths = getResolvedPaths().iterator();
while (dirs.hasNext()) {
final Path child = dirs.next().resolve(path);
if (Files.exists(child)) {
consumer.accept(child, paths.next());
return;
}
paths.next();
}
return withContentTree(tree -> tree.getPath(path));
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
package io.quarkus.deployment;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import java.util.function.Function;

import org.jboss.jandex.IndexView;

import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.bootstrap.model.PathsCollection;
import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.paths.OpenPathTree;
import io.quarkus.paths.PathCollection;
import io.quarkus.paths.PathList;

public final class ApplicationArchiveImpl extends MultiBuildItem implements ApplicationArchive {

private final IndexView indexView;
private final PathCollection rootDirs;
private final PathCollection paths;
private final OpenPathTree openTree;
private final ArtifactKey artifactKey;

public ApplicationArchiveImpl(IndexView indexView, Path archiveRoot,
Path archiveLocation, ArtifactKey artifactKey) {
this(indexView, PathList.of(archiveRoot), PathList.of(archiveLocation), artifactKey);
}

public ApplicationArchiveImpl(IndexView indexView, PathCollection rootDirs, PathCollection paths,
ArtifactKey artifactKey) {
public ApplicationArchiveImpl(IndexView indexView, OpenPathTree openTree, ArtifactKey artifactKey) {
this.indexView = indexView;
this.rootDirs = rootDirs;
this.paths = paths;
this.openTree = openTree;
this.artifactKey = artifactKey;
}

Expand All @@ -39,32 +35,37 @@ public IndexView getIndex() {
@Override
@Deprecated
public Path getArchiveLocation() {
return paths.iterator().next();
return openTree.getOriginalTree().getRoots().iterator().next();
}

@Override
@Deprecated
public PathsCollection getRootDirs() {
return PathsCollection.from(rootDirs);
return PathsCollection.from(openTree.getRoots());
}

@Override
public PathCollection getRootDirectories() {
return rootDirs;
return PathList.from(openTree.getRoots());
}

@Override
@Deprecated
public PathsCollection getPaths() {
return PathsCollection.from(paths);
return PathsCollection.from(openTree.getOriginalTree().getRoots());
}

@Override
public PathCollection getResolvedPaths() {
return paths;
return PathList.from(openTree.getOriginalTree().getRoots());
}

@Override
@Deprecated
/**
* @deprecated in favor of {@link #getKey()}
* @return archive key
*/
public AppArtifactKey getArtifactKey() {
return artifactKey == null ? null
: new AppArtifactKey(artifactKey.getGroupId(), artifactKey.getArtifactId(), artifactKey.getClassifier(),
Expand All @@ -75,4 +76,22 @@ public AppArtifactKey getArtifactKey() {
public ArtifactKey getKey() {
return artifactKey;
}

@Override
public <T> T withContentTree(Function<OpenPathTree, T> func) {
if (openTree.isOpen()) {
try {
return func.apply(openTree);
} catch (Exception e) {
if (openTree.isOpen()) {
throw e;
}
}
}
try (OpenPathTree openTree = this.openTree.getOriginalTree().openTree()) {
return func.apply(openTree);
} catch (IOException e) {
throw new UncheckedIOException("Failed to open path tree with root " + openTree.getOriginalTree().getRoots(), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import java.util.function.Consumer;

import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.model.PathsCollection;
import io.quarkus.bootstrap.prebuild.CodeGenException;
import io.quarkus.deployment.codegen.CodeGenData;
import io.quarkus.paths.PathCollection;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.configuration.ConfigUtils;
import io.smallrye.config.PropertiesConfigSource;
Expand All @@ -25,7 +25,7 @@ public class CodeGenerator {

// used by Gradle and Maven
public static void initAndRun(ClassLoader classLoader,
PathsCollection sourceParentDirs, Path generatedSourcesDir, Path buildDir,
PathCollection sourceParentDirs, Path generatedSourcesDir, Path buildDir,
Consumer<Path> sourceRegistrar, ApplicationModel appModel, Properties properties,
String launchMode) throws CodeGenException {
List<CodeGenData> generators = init(classLoader, sourceParentDirs, generatedSourcesDir, buildDir, sourceRegistrar);
Expand All @@ -36,7 +36,7 @@ public static void initAndRun(ClassLoader classLoader,
}

public static List<CodeGenData> init(ClassLoader deploymentClassLoader,
PathsCollection sourceParentDirs,
PathCollection sourceParentDirs,
Path generatedSourcesDir,
Path buildDir,
Consumer<Path> sourceRegistrar) throws CodeGenException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.model.PathsCollection;
import io.quarkus.builder.BuildChain;
import io.quarkus.builder.BuildChainBuilder;
import io.quarkus.builder.BuildExecutionBuilder;
Expand Down Expand Up @@ -46,7 +45,7 @@ public class QuarkusAugmentor {

private final ClassLoader classLoader;
private final ClassLoader deploymentClassLoader;
private final PathsCollection root;
private final PathCollection root;
private final Set<Class<? extends BuildItem>> finalResults;
private final List<Consumer<BuildChainBuilder>> buildChainCustomizers;
private final LaunchMode launchMode;
Expand Down Expand Up @@ -193,7 +192,7 @@ public static final class Builder {
List<PathCollection> additionalApplicationArchives = new ArrayList<>();
Collection<Path> excludedFromIndexing = Collections.emptySet();
ClassLoader classLoader;
PathsCollection root;
PathCollection root;
Path targetDir;
Set<Class<? extends BuildItem>> finalResults = new HashSet<>();
private final List<Consumer<BuildChainBuilder>> buildChainCustomizers = new ArrayList<>();
Expand Down Expand Up @@ -274,7 +273,7 @@ public Builder setClassLoader(ClassLoader classLoader) {
return this;
}

public PathsCollection getRoot() {
public PathCollection getRoot() {
return root;
}

Expand All @@ -283,7 +282,7 @@ public <T extends BuildItem> Builder addFinal(Class<T> clazz) {
return this;
}

public Builder setRoot(PathsCollection root) {
public Builder setRoot(PathCollection root) {
this.root = root;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import io.quarkus.bootstrap.model.PathsCollection;
import io.quarkus.builder.item.SimpleBuildItem;
import io.quarkus.fs.util.ZipUtils;
import io.quarkus.paths.PathCollection;
import io.quarkus.paths.PathList;

public final class ArchiveRootBuildItem extends SimpleBuildItem {

Expand All @@ -29,7 +31,7 @@ public Builder addArchiveRoot(Path root) {
return this;
}

public Builder addArchiveRoots(PathsCollection paths) {
public Builder addArchiveRoots(PathCollection paths) {
paths.forEach(archiveRoots::add);
return this;
}
Expand Down Expand Up @@ -57,8 +59,8 @@ public static Builder builder() {

private final Path archiveRoot;
private final Collection<Path> excludedFromIndexing;
private final PathsCollection rootDirs;
private final PathsCollection paths;
private final PathCollection rootDirs;
private final PathCollection paths;

public ArchiveRootBuildItem(Path appClassesDir) {
this(appClassesDir, appClassesDir);
Expand All @@ -73,17 +75,17 @@ private ArchiveRootBuildItem(Path archiveLocation, Path archiveRoot, Collection<
if (!Files.isDirectory(archiveRoot)) {
throw new IllegalArgumentException(archiveRoot + " does not point to the application output directory");
}
this.rootDirs = PathsCollection.of(archiveRoot);
this.paths = PathsCollection.of(archiveLocation);
this.rootDirs = PathList.of(archiveRoot);
this.paths = PathList.of(archiveLocation);
this.archiveRoot = archiveRoot;
this.excludedFromIndexing = excludedFromIndexing;
}

private ArchiveRootBuildItem(Builder builder, QuarkusBuildCloseablesBuildItem buildCloseables) throws IOException {
this.excludedFromIndexing = builder.excludedFromIndexing;
if (!builder.archiveRoots.isEmpty()) {
final PathsCollection.Builder rootDirs = PathsCollection.builder();
final PathsCollection.Builder paths = PathsCollection.builder();
final PathList.Builder rootDirs = PathList.builder();
final PathList.Builder paths = PathList.builder();
for (Path root : builder.archiveRoots) {
paths.add(root);
if (Files.isDirectory(root)) {
Expand All @@ -106,7 +108,7 @@ private ArchiveRootBuildItem(Builder builder, QuarkusBuildCloseablesBuildItem bu
* If this archive is a jar file it will return the path to the jar file on the file system,
* otherwise it will return the directory that this corresponds to.
*
* @deprecated in favor of {@link #getPaths()}
* @deprecated in favor of {@link #getResolvedPaths()}
*/
@Deprecated
public Path getArchiveLocation() {
Expand All @@ -124,7 +126,7 @@ public Path getArchiveLocation() {
* jar, but rather a path to the root of the mounted {@link com.sun.nio.zipfs.ZipFileSystem}
*
* @return The archive root.
* @deprecated in favor of {@link #getRootDirs()}
* @deprecated in favor of {@link #getRootDirectories()}
*/
@Deprecated
public Path getArchiveRoot() {
Expand All @@ -133,22 +135,49 @@ public Path getArchiveRoot() {

/**
* Collection of path representing the archive's root directories. If there is a JAR among the paths
* (returned by {@link #getPaths()} this method will return the path to the root of the mounted
* (returned by {@link #getResolvedPaths()} this method will return the path to the root of the mounted
* {@link java.nio.file.ZipFileSystem}
* instead.
*
* @deprecated in favor of {@link #getRootDirectories()}
*
* @return Collection of path representing the archive's root directories.
*/
@Deprecated
public PathsCollection getRootDirs() {
return PathsCollection.from(rootDirs);
}

/**
* Collection of path representing the archive's root directories. If there is a JAR among the paths
* (returned by {@link #getResolvedPaths()} this method will return the path to the root of the mounted
* {@link java.nio.file.ZipFileSystem}
* instead.
*
* @return Collection of path representing the archive's root directories.
*/
public PathCollection getRootDirectories() {
return rootDirs;
}

/**
* Collection of paths that collectively constitute the application archive's content.
*
* @deprecated in favor of {@link #getResolvedPaths()}
*
* @return collection of paths that collectively constitute the application archive content.
*/
@Deprecated
public PathsCollection getPaths() {
return PathsCollection.from(paths);
}

/**
* Collection of paths that collectively constitute the application archive's content.
*
* @return collection of paths that collectively constitute the application archive content.
*/
public PathCollection getResolvedPaths() {
return paths;
}

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

import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.deployment.pkg.NativeConfig;
import io.quarkus.deployment.util.GlobUtil;
import io.quarkus.util.GlobUtil;

/**
* A build item that indicates that a set of resource paths defined by regular expression patterns or globs should be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.List;
import java.util.Set;

import io.quarkus.bootstrap.model.PathsCollection;
import io.quarkus.paths.PathCollection;

public interface CompilationProvider extends Closeable {

Expand All @@ -23,7 +23,7 @@ default Set<String> handledSourcePaths() {

void compile(Set<File> files, Context context);

Path getSourcePath(Path classFilePath, PathsCollection sourcePaths, String classesPath);
Path getSourcePath(Path classFilePath, PathCollection sourcePaths, String classesPath);

@Override
default void close() throws IOException {
Expand Down Expand Up @@ -58,7 +58,6 @@ public Context(
String targetJvmVersion,
List<String> compilePluginArtifacts,
List<String> compilerPluginOptions) {

this.name = name;
this.classpath = classpath;
this.projectDirectory = projectDirectory;
Expand Down
Loading

0 comments on commit 8578ea9

Please sign in to comment.