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 9, 2022
1 parent 11c644d commit f959510
Show file tree
Hide file tree
Showing 141 changed files with 4,430 additions and 1,237 deletions.
7 changes: 0 additions & 7 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@
<google-cloud-functions.version>1.0.4</google-cloud-functions.version>
<commons-compress.version>1.21</commons-compress.version>
<gson.version>2.8.6</gson.version>
<webjars-locator-core.version>0.48</webjars-locator-core.version>
<log4j2-jboss-logmanager.version>1.1.1.Final</log4j2-jboss-logmanager.version>
<log4j2-api.version>2.17.1</log4j2-api.version>
<log4j-jboss-logmanager.version>1.2.2.Final</log4j-jboss-logmanager.version>
Expand Down Expand Up @@ -4918,12 +4917,6 @@
<version>${snakeyaml.version}</version>
</dependency>

<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator-core</artifactId>
<version>${webjars-locator-core.version}</version>
</dependency>

<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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.Consumer;
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 +83,29 @@ public interface ApplicationArchive {
*/
ArtifactKey getKey();

/**
* Applies 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 apply(Function<OpenPathTree, T> func);

/**
* Accepts a consumer for the content tree of the archive.
*
* @param func consumer
*/
void accept(Consumer<OpenPathTree> 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 apply(tree -> tree.getPath(path));
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
package io.quarkus.deployment;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import java.util.function.Consumer;
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 +36,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 +77,41 @@ public AppArtifactKey getArtifactKey() {
public ArtifactKey getKey() {
return artifactKey;
}

@Override
public <T> T apply(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().open()) {
return func.apply(openTree);
} catch (IOException e) {
throw new UncheckedIOException("Failed to open path tree with root " + openTree.getOriginalTree().getRoots(), e);
}
}

@Override
public void accept(Consumer<OpenPathTree> func) {
if (openTree.isOpen()) {
try {
func.accept(openTree);
return;
} catch (Exception e) {
if (openTree.isOpen()) {
throw e;
}
}
}
try (OpenPathTree openTree = this.openTree.getOriginalTree().open()) {
func.accept(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
Loading

0 comments on commit f959510

Please sign in to comment.