From 34faea6d40af502f25e232be41cd783230fe01ac Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Wed, 28 Sep 2022 15:53:49 +0200 Subject: [PATCH] Fix the original JAR check when the finalName in the Quarkus plugin is different from the one in the POM's build section --- .../quarkus/deployment/QuarkusAugmentor.java | 14 ++++++-- .../deployment/jbang/JBangAugmentorImpl.java | 3 ++ .../builditem/BuildSystemTargetBuildItem.java | 20 +++++++++++ .../pkg/builditem/OutputTargetBuildItem.java | 33 +++++++++++++++++++ .../pkg/steps/JarResultBuildStep.java | 7 ++-- .../runner/bootstrap/AugmentActionImpl.java | 3 ++ .../maven/QuarkusBootstrapProvider.java | 21 ++++++------ .../bootstrap/app/QuarkusBootstrap.java | 13 ++++++++ .../java/io/quarkus/maven/it/PackageIT.java | 13 ++++++-- .../uberjar-maven-plugin-config/pom.xml | 3 ++ 10 files changed, 112 insertions(+), 18 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/QuarkusAugmentor.java b/core/deployment/src/main/java/io/quarkus/deployment/QuarkusAugmentor.java index ca3519a4be75a..dba8f2b5eeb88 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/QuarkusAugmentor.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/QuarkusAugmentor.java @@ -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 auxiliaryDevModeType; @@ -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; @@ -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) { @@ -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 additionalApplicationArchives = new ArrayList<>(); @@ -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; @@ -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; } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/jbang/JBangAugmentorImpl.java b/core/deployment/src/main/java/io/quarkus/deployment/jbang/JBangAugmentorImpl.java index 01eeaca5051ee..946699643f592 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/jbang/JBangAugmentorImpl.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/jbang/JBangAugmentorImpl.java @@ -54,6 +54,9 @@ public void accept(CuratedApplication curatedApplication, Map 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); diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/builditem/BuildSystemTargetBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/builditem/BuildSystemTargetBuildItem.java index 3fa8da77c6a2b..ccec015fef4c1 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/builditem/BuildSystemTargetBuildItem.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/builditem/BuildSystemTargetBuildItem.java @@ -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; } @@ -30,6 +46,10 @@ public String getBaseName() { return baseName; } + public String getOriginalBaseName() { + return originalBaseName; + } + public boolean isRebuild() { return rebuild; } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/builditem/OutputTargetBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/builditem/OutputTargetBuildItem.java index 24479c85b677c..6eb601ace4e1d 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/builditem/OutputTargetBuildItem.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/builditem/OutputTargetBuildItem.java @@ -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> 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> includedOptionalDependencies) { + this(outputDirectory, baseName, baseName, rebuild, buildSystemProperties, includedOptionalDependencies); + } + + public OutputTargetBuildItem(Path outputDirectory, String baseName, String originalBaseName, boolean rebuild, + Properties buildSystemProperties, + Optional> includedOptionalDependencies) { this.outputDirectory = outputDirectory; this.baseName = baseName; + this.originalBaseName = originalBaseName; this.rebuild = rebuild; this.buildSystemProperties = buildSystemProperties; this.includedOptionalDependencies = includedOptionalDependencies; @@ -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; } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java index 3e092d838d8fa..dd28e38cf88ac 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java @@ -158,12 +158,13 @@ OutputTargetBuildItem outputTarget(BuildSystemTargetBuildItem bst, PackageConfig Optional> 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) @@ -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; diff --git a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java index 6d9cca4a075da..a2007cf6732db 100644 --- a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java +++ b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java @@ -291,6 +291,9 @@ private BuildResult runAugment(boolean firstRun, Set 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); diff --git a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java index d3529126378ca..7815865536442 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java @@ -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; @@ -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() { @@ -209,12 +207,13 @@ private CuratedApplication doBootstrap(QuarkusBootstrapMojo mojo, LaunchMode mod final List localProjects = mojo.mavenProject().getCollectedProjects(); final Set 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()); @@ -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) @@ -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); @@ -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()); } @@ -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) { @@ -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 diff --git a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/QuarkusBootstrap.java b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/QuarkusBootstrap.java index 001b08b33e944..3757ed11b36e3 100644 --- a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/QuarkusBootstrap.java +++ b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/QuarkusBootstrap.java @@ -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; @@ -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; @@ -235,6 +237,10 @@ public String getBaseName() { return baseName; } + public String getOriginalBaseName() { + return originalBaseName; + } + public ClassLoader getBaseClassLoader() { return baseClassLoader; } @@ -262,6 +268,7 @@ public List getClassLoaderEventListeners() { public Builder clonedBuilder() { Builder builder = new Builder() .setBaseName(baseName) + .setOriginalBaseName(originalBaseName) .setProjectRoot(projectRoot) .setBaseClassLoader(baseClassLoader) .setBuildSystemProperties(buildSystemProperties) @@ -304,6 +311,7 @@ public static class Builder { boolean rebuild; PathCollection applicationRoot; String baseName; + String originalJarName; Path projectRoot; ClassLoader baseClassLoader = ClassLoader.getSystemClassLoader(); final List additionalApplicationArchives = new ArrayList<>(); @@ -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; diff --git a/integration-tests/maven/src/test/java/io/quarkus/maven/it/PackageIT.java b/integration-tests/maven/src/test/java/io/quarkus/maven/it/PackageIT.java index 0f9806b0f26b3..c3565bb6b3e35 100644 --- a/integration-tests/maven/src/test/java/io/quarkus/maven/it/PackageIT.java +++ b/integration-tests/maven/src/test/java/io/quarkus/maven/it/PackageIT.java @@ -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(); } diff --git a/integration-tests/maven/src/test/resources-filtered/projects/uberjar-maven-plugin-config/pom.xml b/integration-tests/maven/src/test/resources-filtered/projects/uberjar-maven-plugin-config/pom.xml index 3885f5e319342..4bb9c2d219eea 100644 --- a/integration-tests/maven/src/test/resources-filtered/projects/uberjar-maven-plugin-config/pom.xml +++ b/integration-tests/maven/src/test/resources-filtered/projects/uberjar-maven-plugin-config/pom.xml @@ -61,6 +61,9 @@ + + acme-quarkus +