Skip to content

Commit

Permalink
Merge pull request #20500 from aloubyansky/bootstrap-artifact-api
Browse files Browse the repository at this point in the history
Bootstrap API refactoring
  • Loading branch information
stuartwdouglas committed Oct 6, 2021
2 parents 84d9188 + 870cfb7 commit 657ae29
Show file tree
Hide file tree
Showing 195 changed files with 4,714 additions and 4,513 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

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

/**
* Represents an archive that is part of application code.
Expand All @@ -25,64 +27,70 @@ public interface ApplicationArchive {
IndexView getIndex();

/**
* 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.
*
* Returns a path representing the archive root. Note that if this is a jar archive this is not the path to the
* 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 #getResolvedPaths()}
*/
@Deprecated
Path getArchiveRoot();
Path getArchiveLocation();

/**
* @deprecated in favor of {@link #getRootDirectories()}
*
* @return <code>true</code> if this archive is a jar
* @deprecated does not appear to be used anywhere and now it shouldn't be
*/
@Deprecated
boolean isJarArchive();

/**
* 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.
* Returns paths representing the archive root directories. Note that every path in this collection
* is guaranteed to be a directory. If the actual application archive appears to be a JAR,
* this collection will include a path to the root of the mounted {@link java.nio.file.FileSystem}
* created from the JAR.
*
* @deprecated in favor of {@link #getPaths()}
* @return The archive root directories.
*/
@Deprecated
Path getArchiveLocation();
PathsCollection getRootDirs();

/**
*
* Returns paths representing the archive root directories. Note that every path in this collection
* is guaranteed to be a directory. If the actual application archive appears to be a JAR,
* this collection will include a path to the root of the mounted {@link java.nio.file.FileSystem}
* created from the JAR.
*
* @return The archive root directories.
*/
PathsCollection getRootDirs();
PathCollection getRootDirectories();

/**
*
* @deprecated in favor of {@link #getResolvedPaths()}
* @return The paths representing the application root paths.
*/
@Deprecated
PathsCollection getPaths();

/**
*
* @return The paths representing the application root paths.
*/
PathCollection getResolvedPaths();

/**
* @deprecated in favor of {@link #getKey()}
* @return the artifact key or null if not available
*/
AppArtifactKey getArtifactKey();

/**
*
* @return the artifact key or null if not available
*/
ArtifactKey getKey();

/**
* 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 getRootDirs().resolveExistingOrNull(path);
return getRootDirectories().resolveExistingOrNull(path);
}

/**
Expand All @@ -94,8 +102,8 @@ default Path getChildPath(String path) {
* @param consumer entry consumer
*/
default void processEntry(String path, BiConsumer<Path, Path> consumer) {
final Iterator<Path> dirs = getRootDirs().iterator();
final Iterator<Path> paths = getPaths().iterator();
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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
package io.quarkus.deployment;

import java.io.Closeable;
import java.nio.file.Path;

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.PathCollection;
import io.quarkus.paths.PathList;

public final class ApplicationArchiveImpl extends MultiBuildItem implements ApplicationArchive {

private final IndexView indexView;
private final PathsCollection rootDirs;
private final boolean jar;
private final PathsCollection paths;
private final AppArtifactKey artifactKey;
private final PathCollection rootDirs;
private final PathCollection paths;
private final ArtifactKey artifactKey;

public ApplicationArchiveImpl(IndexView indexView, Path archiveRoot, Closeable closeable, boolean jar,
Path archiveLocation, AppArtifactKey artifactKey) {
this(indexView, PathsCollection.of(archiveRoot), PathsCollection.of(archiveLocation), artifactKey);
public ApplicationArchiveImpl(IndexView indexView, Path archiveRoot,
Path archiveLocation, ArtifactKey artifactKey) {
this(indexView, PathList.of(archiveRoot), PathList.of(archiveLocation), artifactKey);
}

public ApplicationArchiveImpl(IndexView indexView, PathsCollection rootDirs, PathsCollection paths,
AppArtifactKey artifactKey) {
this(indexView, rootDirs, paths, false, artifactKey);
}

private ApplicationArchiveImpl(IndexView indexView, PathsCollection rootDirs, PathsCollection paths, boolean jar,
AppArtifactKey artifactKey) {
public ApplicationArchiveImpl(IndexView indexView, PathCollection rootDirs, PathCollection paths,
ArtifactKey artifactKey) {
this.indexView = indexView;
this.rootDirs = rootDirs;
this.paths = paths;
this.jar = jar;
this.artifactKey = artifactKey;
}

Expand All @@ -43,35 +38,41 @@ public IndexView getIndex() {

@Override
@Deprecated
public Path getArchiveRoot() {
return rootDirs.iterator().next();
public Path getArchiveLocation() {
return paths.iterator().next();
}

@Override
@Deprecated
public boolean isJarArchive() {
return jar;
public PathsCollection getRootDirs() {
return PathsCollection.from(rootDirs);
}

@Override
@Deprecated
public Path getArchiveLocation() {
return paths.iterator().next();
public PathCollection getRootDirectories() {
return rootDirs;
}

@Override
public PathsCollection getRootDirs() {
return rootDirs;
@Deprecated
public PathsCollection getPaths() {
return PathsCollection.from(paths);
}

@Override
public PathsCollection getPaths() {
public PathCollection getResolvedPaths() {
return paths;
}

@Override
public AppArtifactKey getArtifactKey() {
return artifactKey;
return artifactKey == null ? null
: new AppArtifactKey(artifactKey.getGroupId(), artifactKey.getArtifactId(), artifactKey.getClassifier(),
artifactKey.getType());
}

@Override
public ArtifactKey getKey() {
return artifactKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
import java.util.Map;

import io.quarkus.bootstrap.model.AppModel;
import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.util.BootstrapUtils;

public class CodeGenContext {
private final AppModel model;
private final ApplicationModel model;
private final Path outDir;
private final Path workDir;
private final Path inputDir;
private final boolean redirectIO;
private final Map<String, String> properties;

public CodeGenContext(AppModel model, Path outDir, Path workDir, Path inputDir, boolean redirectIO,
public CodeGenContext(ApplicationModel model, Path outDir, Path workDir, Path inputDir, boolean redirectIO,
Map<String, String> properties) {
this.model = model;
this.outDir = outDir;
Expand All @@ -23,7 +25,16 @@ public CodeGenContext(AppModel model, Path outDir, Path workDir, Path inputDir,
this.properties = properties;
}

/**
* @deprecated in favor of {@link #applicationModel()}
* @return
*/
@Deprecated
public AppModel appModel() {
return BootstrapUtils.convert(model);
}

public ApplicationModel applicationModel() {
return model;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.ServiceLoader;
import java.util.function.Consumer;

import io.quarkus.bootstrap.model.AppModel;
import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.model.PathsCollection;
import io.quarkus.bootstrap.prebuild.CodeGenException;
import io.quarkus.deployment.codegen.CodeGenData;
Expand All @@ -20,11 +20,10 @@
public class CodeGenerator {

// used by Gradle
@SuppressWarnings("unused")
public static void initAndRun(ClassLoader classLoader,
PathsCollection sourceParentDirs, Path generatedSourcesDir, Path buildDir,
Consumer<Path> sourceRegistrar,
AppModel appModel, Map<String, String> properties) throws CodeGenException {
ApplicationModel appModel, Map<String, String> properties) throws CodeGenException {
List<CodeGenData> generators = init(classLoader, sourceParentDirs, generatedSourcesDir, buildDir, sourceRegistrar);
for (CodeGenData generator : generators) {
generator.setRedirectIO(true);
Expand Down Expand Up @@ -82,7 +81,7 @@ private static <T> T callWithClassloader(ClassLoader deploymentClassLoader, Code
*/
public static boolean trigger(ClassLoader deploymentClassLoader,
CodeGenData data,
AppModel appModel,
ApplicationModel appModel,
Map<String, String> properties) throws CodeGenException {
return callWithClassloader(deploymentClassLoader, () -> {
CodeGenProvider provider = data.provider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.jboss.logging.Logger;
import org.wildfly.common.function.Functions;

import io.quarkus.bootstrap.model.AppModel;
import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.builder.BuildChainBuilder;
import io.quarkus.builder.BuildContext;
import io.quarkus.builder.BuildStepBuilder;
Expand Down Expand Up @@ -125,7 +125,7 @@ private static boolean isRecorder(AnnotatedElement element) {
* @throws ClassNotFoundException if a build step class is not found
*/
public static Consumer<BuildChainBuilder> loadStepsFrom(ClassLoader classLoader, Properties buildSystemProps,
AppModel appModel, LaunchMode launchMode, DevModeType devModeType,
ApplicationModel appModel, LaunchMode launchMode, DevModeType devModeType,
Consumer<ConfigBuilder> configCustomizer)
throws IOException, ClassNotFoundException {
// populate with all known types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.jboss.logging.Logger;

import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.bootstrap.model.AppModel;
import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.model.PathsCollection;
import io.quarkus.builder.BuildChain;
import io.quarkus.builder.BuildChainBuilder;
Expand All @@ -36,6 +36,7 @@
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem;
import io.quarkus.dev.spi.DevModeType;
import io.quarkus.paths.PathCollection;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.util.JavaVersionUtil;

Expand All @@ -50,12 +51,12 @@ public class QuarkusAugmentor {
private final List<Consumer<BuildChainBuilder>> buildChainCustomizers;
private final LaunchMode launchMode;
private final DevModeType devModeType;
private final List<PathsCollection> additionalApplicationArchives;
private final List<PathCollection> additionalApplicationArchives;
private final Collection<Path> excludedFromIndexing;
private final LiveReloadBuildItem liveReloadBuildItem;
private final Properties buildSystemProperties;
private final Path targetDir;
private final AppModel effectiveModel;
private final ApplicationModel effectiveModel;
private final String baseName;
private final Consumer<ConfigBuilder> configCustomizer;
private final boolean rebuild;
Expand Down Expand Up @@ -154,7 +155,7 @@ public BuildResult run() throws Exception {
.produce(new BuildSystemTargetBuildItem(targetDir, baseName, rebuild,
buildSystemProperties == null ? new Properties() : buildSystemProperties))
.produce(new AppModelProviderBuildItem(effectiveModel));
for (PathsCollection i : additionalApplicationArchives) {
for (PathCollection i : additionalApplicationArchives) {
execBuilder.produce(new AdditionalApplicationArchiveBuildItem(i));
}
BuildResult buildResult = execBuilder.execute();
Expand Down Expand Up @@ -189,7 +190,7 @@ public static final class Builder {

public DevModeType auxiliaryDevModeType;
boolean rebuild;
List<PathsCollection> additionalApplicationArchives = new ArrayList<>();
List<PathCollection> additionalApplicationArchives = new ArrayList<>();
Collection<Path> excludedFromIndexing = Collections.emptySet();
ClassLoader classLoader;
PathsCollection root;
Expand All @@ -200,7 +201,7 @@ public static final class Builder {
LiveReloadBuildItem liveReloadState = new LiveReloadBuildItem();
Properties buildSystemProperties;

AppModel effectiveModel;
ApplicationModel effectiveModel;
String baseName = "quarkus-application";
Consumer<ConfigBuilder> configCustomizer;
ClassLoader deploymentClassLoader;
Expand All @@ -213,11 +214,11 @@ public Builder addBuildChainCustomizer(Consumer<BuildChainBuilder> customizer) {
return this;
}

public List<PathsCollection> getAdditionalApplicationArchives() {
public List<PathCollection> getAdditionalApplicationArchives() {
return additionalApplicationArchives;
}

public Builder addAdditionalApplicationArchive(PathsCollection archive) {
public Builder addAdditionalApplicationArchive(PathCollection archive) {
this.additionalApplicationArchives.add(archive);
return this;
}
Expand Down Expand Up @@ -328,7 +329,7 @@ public Builder setTargetDir(Path outputDir) {
return this;
}

public Builder setEffectiveModel(AppModel effectiveModel) {
public Builder setEffectiveModel(ApplicationModel effectiveModel) {
this.effectiveModel = effectiveModel;
return this;
}
Expand Down

0 comments on commit 657ae29

Please sign in to comment.