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

Fix the original JAR path check in the JarResultBuildStep #28259

Merged
merged 1 commit into from
Sep 29, 2022
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 @@ -57,6 +57,7 @@ public class QuarkusAugmentor {
private final Path targetDir;
private final ApplicationModel effectiveModel;
private final String baseName;
private final String originalBaseName;
private final boolean rebuild;
private final boolean auxiliaryApplication;
private final Optional<DevModeType> auxiliaryDevModeType;
Expand All @@ -75,6 +76,7 @@ public class QuarkusAugmentor {
this.targetDir = builder.targetDir;
this.effectiveModel = builder.effectiveModel;
this.baseName = builder.baseName;
this.originalBaseName = builder.originalBaseName;
this.deploymentClassLoader = builder.deploymentClassLoader;
this.rebuild = builder.rebuild;
this.devModeType = builder.devModeType;
Expand Down Expand Up @@ -149,7 +151,7 @@ public BuildResult run() throws Exception {
.produce(new LaunchModeBuildItem(launchMode,
devModeType == null ? Optional.empty() : Optional.of(devModeType), auxiliaryApplication,
auxiliaryDevModeType, test))
.produce(new BuildSystemTargetBuildItem(targetDir, baseName, rebuild,
.produce(new BuildSystemTargetBuildItem(targetDir, baseName, originalBaseName, rebuild,
buildSystemProperties == null ? new Properties() : buildSystemProperties))
.produce(new AppModelProviderBuildItem(effectiveModel));
for (PathCollection i : additionalApplicationArchives) {
Expand Down Expand Up @@ -194,6 +196,8 @@ public static Builder builder() {

public static final class Builder {

private static final String QUARKUS_APPLICATION = "quarkus-application";

public DevModeType auxiliaryDevModeType;
boolean rebuild;
List<PathCollection> additionalApplicationArchives = new ArrayList<>();
Expand All @@ -208,7 +212,8 @@ public static final class Builder {
Properties buildSystemProperties;

ApplicationModel effectiveModel;
String baseName = "quarkus-application";
String baseName = QUARKUS_APPLICATION;
String originalBaseName = QUARKUS_APPLICATION;
ClassLoader deploymentClassLoader;
DevModeType devModeType;
boolean test;
Expand Down Expand Up @@ -302,6 +307,11 @@ public Builder setBaseName(String baseName) {
return this;
}

public Builder setOriginalBaseName(String originalBaseName) {
this.originalBaseName = originalBaseName;
return this;
}

public Properties getBuildSystemProperties() {
return buildSystemProperties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public void accept(CuratedApplication curatedApplication, Map<String, Object> re
if (quarkusBootstrap.getBaseName() != null) {
builder.setBaseName(quarkusBootstrap.getBaseName());
}
if (quarkusBootstrap.getOriginalBaseName() != null) {
builder.setOriginalBaseName(quarkusBootstrap.getOriginalBaseName());
}

boolean auxiliaryApplication = curatedApplication.getQuarkusBootstrap().isAuxiliaryApplication();
builder.setAuxiliaryApplication(auxiliaryApplication);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,28 @@ public final class BuildSystemTargetBuildItem extends SimpleBuildItem {

private final Path outputDirectory;
private final String baseName;
private final String originalBaseName;
private final boolean rebuild;
private final Properties buildSystemProps;

/**
* @deprecated in favor of {@link #BuildSystemTargetBuildItem(Path, String, String, boolean, Properties)}
*
* @param outputDirectory build output directory
* @param baseName base runner name
* @param rebuild indicates whether the application is being re-built
* @param buildSystemProps build system properties
*/
@Deprecated(forRemoval = true)
public BuildSystemTargetBuildItem(Path outputDirectory, String baseName, boolean rebuild, Properties buildSystemProps) {
this(outputDirectory, baseName, baseName, rebuild, buildSystemProps);
}

public BuildSystemTargetBuildItem(Path outputDirectory, String baseName, String originalBaseName, boolean rebuild,
Properties buildSystemProps) {
this.outputDirectory = outputDirectory;
this.baseName = baseName;
this.originalBaseName = originalBaseName;
this.rebuild = rebuild;
this.buildSystemProps = buildSystemProps;
}
Expand All @@ -30,6 +46,10 @@ public String getBaseName() {
return baseName;
}

public String getOriginalBaseName() {
return originalBaseName;
}

public boolean isRebuild() {
return rebuild;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,32 @@ public final class OutputTargetBuildItem extends SimpleBuildItem {

private final Path outputDirectory;
private final String baseName;
private final String originalBaseName;
private final boolean rebuild;
private final Properties buildSystemProperties;
private final Optional<Set<ArtifactKey>> includedOptionalDependencies;

/**
* @deprecated in favor of {@link #OutputTargetBuildItem(Path, String, String, boolean, Properties, Optional)}
*
* @param outputDirectory build output directory
* @param baseName base runner name
* @param rebuild indicates whether the application is being re-built
* @param buildSystemProperties build system properties
* @param includedOptionalDependencies included optional dependencies
*/
@Deprecated(forRemoval = true)
public OutputTargetBuildItem(Path outputDirectory, String baseName, boolean rebuild, Properties buildSystemProperties,
Optional<Set<ArtifactKey>> includedOptionalDependencies) {
this(outputDirectory, baseName, baseName, rebuild, buildSystemProperties, includedOptionalDependencies);
}

public OutputTargetBuildItem(Path outputDirectory, String baseName, String originalBaseName, boolean rebuild,
Properties buildSystemProperties,
Optional<Set<ArtifactKey>> includedOptionalDependencies) {
this.outputDirectory = outputDirectory;
this.baseName = baseName;
this.originalBaseName = originalBaseName;
this.rebuild = rebuild;
this.buildSystemProperties = buildSystemProperties;
this.includedOptionalDependencies = includedOptionalDependencies;
Expand All @@ -34,10 +52,25 @@ public Path getOutputDirectory() {
return outputDirectory;
}

/**
* Base name for the Quarkus application runner file.
*
* @return base name for the Quarkus application runner file
*/
public String getBaseName() {
return baseName;
}

/**
* The base name (not including the extension) of the original JAR generated by the build system.
* This name could be different from the value of {@ #getBaseName()}, which will be used for the Quarkus runner file.
*
* @return name of the original JAR generated by the build system
*/
public String getOriginalBaseName() {
return originalBaseName;
}

public boolean isRebuild() {
return rebuild;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,13 @@ OutputTargetBuildItem outputTarget(BuildSystemTargetBuildItem bst, PackageConfig
Optional<Set<ArtifactKey>> includedOptionalDependencies;
if (packageConfig.filterOptionalDependencies) {
includedOptionalDependencies = Optional.of(packageConfig.includedOptionalDependencies
.map(set -> set.stream().map(s -> (ArtifactKey) GACT.fromString(s)).collect(Collectors.toSet()))
.map(set -> set.stream().map(s -> ArtifactKey.fromString(s)).collect(Collectors.toSet()))
.orElse(Collections.emptySet()));
} else {
includedOptionalDependencies = Optional.empty();
}
return new OutputTargetBuildItem(path, name, bst.isRebuild(), bst.getBuildSystemProps(), includedOptionalDependencies);
return new OutputTargetBuildItem(path, name, bst.getOriginalBaseName(), bst.isRebuild(), bst.getBuildSystemProps(),
includedOptionalDependencies);
}

@BuildStep(onlyIf = JarRequired.class)
Expand Down Expand Up @@ -283,7 +284,7 @@ private JarBuildItem buildUberJar(CurateOutcomeBuildItem curateOutcomeBuildItem,

//for uberjars we move the original jar, so there is only a single jar in the output directory
final Path standardJar = outputTargetBuildItem.getOutputDirectory()
.resolve(outputTargetBuildItem.getBaseName() + ".jar");
.resolve(outputTargetBuildItem.getOriginalBaseName() + ".jar");

final Path originalJar = Files.exists(standardJar) ? standardJar : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ private BuildResult runAugment(boolean firstRun, Set<String> changedResources,
if (quarkusBootstrap.getBaseName() != null) {
builder.setBaseName(quarkusBootstrap.getBaseName());
}
if (quarkusBootstrap.getOriginalBaseName() != null) {
builder.setOriginalBaseName(quarkusBootstrap.getOriginalBaseName());
}

boolean auxiliaryApplication = curatedApplication.getQuarkusBootstrap().isAuxiliaryApplication();
builder.setAuxiliaryApplication(auxiliaryApplication);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.Dependency;
import io.quarkus.maven.dependency.GACT;
import io.quarkus.maven.dependency.GACTV;
import io.quarkus.maven.dependency.ResolvedArtifactDependency;
import io.quarkus.runtime.LaunchMode;
import io.smallrye.common.expression.Expression;
Expand All @@ -59,7 +57,7 @@ public class QuarkusBootstrapProvider implements Closeable {
.concurrencyLevel(4).softValues().initialCapacity(10).build();

static ArtifactKey getProjectId(MavenProject project) {
return new GACT(project.getGroupId(), project.getArtifactId());
return ArtifactKey.ga(project.getGroupId(), project.getArtifactId());
}

public RepositorySystem repositorySystem() {
Expand Down Expand Up @@ -209,12 +207,13 @@ private CuratedApplication doBootstrap(QuarkusBootstrapMojo mojo, LaunchMode mod
final List<MavenProject> localProjects = mojo.mavenProject().getCollectedProjects();
final Set<ArtifactKey> localProjectKeys = new HashSet<>(localProjects.size());
for (MavenProject p : localProjects) {
localProjectKeys.add(new GACT(p.getGroupId(), p.getArtifactId()));
localProjectKeys.add(ArtifactKey.ga(p.getGroupId(), p.getArtifactId()));
}
reloadableModules = new HashSet<>(localProjects.size() + 1);
for (Artifact a : mojo.mavenProject().getArtifacts()) {
if (localProjectKeys.contains(new GACT(a.getGroupId(), a.getArtifactId()))) {
reloadableModules.add(new GACT(a.getGroupId(), a.getArtifactId(), a.getClassifier(), a.getType()));
if (localProjectKeys.contains(ArtifactKey.ga(a.getGroupId(), a.getArtifactId()))) {
reloadableModules
.add(ArtifactKey.of(a.getGroupId(), a.getArtifactId(), a.getClassifier(), a.getType()));
}
}
reloadableModules.add(appArtifact.getKey());
Expand All @@ -228,7 +227,6 @@ private CuratedApplication doBootstrap(QuarkusBootstrapMojo mojo, LaunchMode mod
} catch (AppModelResolverException e) {
throw new MojoExecutionException("Failed to bootstrap application in " + mode + " mode", e);
}

QuarkusBootstrap.Builder builder = QuarkusBootstrap.builder()
.setAppArtifact(appModel.getAppArtifact())
.setExistingModel(appModel)
Expand All @@ -237,6 +235,7 @@ private CuratedApplication doBootstrap(QuarkusBootstrapMojo mojo, LaunchMode mod
.setBuildSystemProperties(effectiveProperties)
.setProjectRoot(mojo.baseDir().toPath())
.setBaseName(mojo.finalName())
.setOriginalBaseName(mojo.mavenProject().getBuild().getFinalName())
.setTargetDirectory(mojo.buildDir().toPath())
.setForcedDependencies(forcedDependencies);

Expand Down Expand Up @@ -277,12 +276,12 @@ protected CuratedApplication bootstrapApplication(QuarkusBootstrapMojo mojo, Lau
return prodApp == null ? prodApp = doBootstrap(mojo, mode) : prodApp;
}

protected GACTV managingProject(QuarkusBootstrapMojo mojo) {
protected ArtifactCoords managingProject(QuarkusBootstrapMojo mojo) {
if (mojo.appArtifactCoords() == null) {
return null;
}
final Artifact artifact = mojo.mavenProject().getArtifact();
return new GACTV(artifact.getGroupId(), artifact.getArtifactId(),
return ArtifactCoords.of(artifact.getGroupId(), artifact.getArtifactId(),
artifact.getClassifier(), artifact.getArtifactHandler().getExtension(),
artifact.getVersion());
}
Expand Down Expand Up @@ -321,7 +320,7 @@ private ArtifactCoords appArtifact(QuarkusBootstrapMojo mojo)
}
final String groupId = coordsArr[0];
final String artifactId = coordsArr[1];
String classifier = "";
String classifier = ArtifactCoords.DEFAULT_CLASSIFIER;
String type = ArtifactCoords.TYPE_JAR;
String version = null;
if (coordsArr.length == 3) {
Expand Down Expand Up @@ -349,7 +348,7 @@ private ArtifactCoords appArtifact(QuarkusBootstrapMojo mojo)
}
}

return new GACTV(groupId, artifactId, classifier, type, version);
return ArtifactCoords.of(groupId, artifactId, classifier, type, version);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class QuarkusBootstrap implements Serializable {

private final Properties buildSystemProperties;
private final String baseName;
private final String originalBaseName;
private final Path targetDirectory;

private final Mode mode;
Expand Down Expand Up @@ -102,6 +103,7 @@ private QuarkusBootstrap(Builder builder) {
this.test = builder.test;
this.localProjectDiscovery = builder.localProjectDiscovery;
this.baseName = builder.baseName;
this.originalBaseName = builder.originalJarName;
this.baseClassLoader = builder.baseClassLoader;
this.targetDirectory = builder.targetDirectory;
this.appModelResolver = builder.appModelResolver;
Expand Down Expand Up @@ -235,6 +237,10 @@ public String getBaseName() {
return baseName;
}

public String getOriginalBaseName() {
return originalBaseName;
}

public ClassLoader getBaseClassLoader() {
return baseClassLoader;
}
Expand Down Expand Up @@ -262,6 +268,7 @@ public List<ClassLoaderEventListener> getClassLoaderEventListeners() {
public Builder clonedBuilder() {
Builder builder = new Builder()
.setBaseName(baseName)
.setOriginalBaseName(originalBaseName)
.setProjectRoot(projectRoot)
.setBaseClassLoader(baseClassLoader)
.setBuildSystemProperties(buildSystemProperties)
Expand Down Expand Up @@ -304,6 +311,7 @@ public static class Builder {
boolean rebuild;
PathCollection applicationRoot;
String baseName;
String originalJarName;
Path projectRoot;
ClassLoader baseClassLoader = ClassLoader.getSystemClassLoader();
final List<AdditionalDependency> additionalApplicationArchives = new ArrayList<>();
Expand Down Expand Up @@ -417,6 +425,11 @@ public Builder setBaseName(String baseName) {
return this;
}

public Builder setOriginalBaseName(String originalJarName) {
this.originalJarName = originalJarName;
return this;
}

public Builder setBaseClassLoader(ClassLoader baseClassLoader) {
this.baseClassLoader = baseClassLoader;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,19 @@ public void testUberJarMavenPluginConfiguration()
throws MavenInvocationException, IOException, InterruptedException {
testDir = initProject("projects/uberjar-maven-plugin-config");
running = new RunningInvoker(testDir, false);
final MavenProcessInvocationResult result = running.execute(Collections.singletonList("package"),
Collections.emptyMap());
final MavenProcessInvocationResult result = running.execute(List.of("install", "-DskipTests"), Map.of());
assertThat(result.getProcess().waitFor()).isEqualTo(0);

final Path localRunner = getTargetDir().toPath().resolve("acme-quarkus-runner.jar");
assertThat(localRunner).exists();

// make sure the runner jar was attached, there was a bug of the runner jar not being attached when the
// finalName option in the Quarkus plugin didn't match the finalName ocnfigured in the POM's build section
final Path installedRunner = running.getLocalRepositoryDirectory().toPath().resolve("org").resolve("acme")
.resolve("acme")
.resolve("1.0-SNAPSHOT").resolve("acme-1.0-SNAPSHOT-runner.jar");
assertThat(installedRunner).exists();

verifyUberJar();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
</goals>
</execution>
</executions>
<configuration>
<finalName>acme-quarkus</finalName>
</configuration>
</plugin>
</plugins>
</build>
Expand Down