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

Discontinue support for *JarRequiredBuildItem #44518

Merged
merged 2 commits into from
Nov 15, 2024
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
@@ -1,6 +1,5 @@
package io.quarkus.deployment.cmd;

import static io.quarkus.deployment.pkg.PackageConfig.JarConfig.JarType.*;
import static io.quarkus.deployment.pkg.steps.JarResultBuildStep.DEFAULT_FAST_JAR_DIRECTORY_NAME;
import static io.quarkus.deployment.pkg.steps.JarResultBuildStep.QUARKUS_RUN_JAR;

Expand All @@ -14,9 +13,7 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.pkg.PackageConfig;
import io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem;
import io.quarkus.deployment.pkg.builditem.LegacyJarRequiredBuildItem;
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem;
import io.quarkus.deployment.pkg.builditem.UberJarRequiredBuildItem;

public class RunCommandProcessor {
private static final String JAVA_HOME_SYS = "java.home";
Expand All @@ -31,25 +28,18 @@ public RunCommandActionResultBuildItem commands(List<RunCommandActionBuildItem>
@BuildStep
public void defaultJavaCommand(PackageConfig packageConfig,
OutputTargetBuildItem jar,
List<UberJarRequiredBuildItem> uberJarRequired,
List<LegacyJarRequiredBuildItem> legacyJarRequired,
BuildProducer<RunCommandActionBuildItem> cmds,
BuildSystemTargetBuildItem buildSystemTarget) {

Path jarPath = null;
if (legacyJarRequired.isEmpty() && (!uberJarRequired.isEmpty()
|| packageConfig.jar().type() == UBER_JAR)) {
jarPath = jar.getOutputDirectory()
Path jarPath = switch (packageConfig.jar().type()) {
case UBER_JAR -> jar.getOutputDirectory()
.resolve(jar.getBaseName() + packageConfig.computedRunnerSuffix() + ".jar");
} else if (!legacyJarRequired.isEmpty()
|| packageConfig.jar().type() == LEGACY_JAR) {
// todo: legacy JAR should be using runnerSuffix()
jarPath = jar.getOutputDirectory()
case LEGACY_JAR -> jar.getOutputDirectory()
.resolve(jar.getBaseName() + packageConfig.computedRunnerSuffix() + ".jar");
} else {
jarPath = jar.getOutputDirectory().resolve(DEFAULT_FAST_JAR_DIRECTORY_NAME).resolve(QUARKUS_RUN_JAR);

}
case FAST_JAR, MUTABLE_JAR -> jar.getOutputDirectory()
.resolve(DEFAULT_FAST_JAR_DIRECTORY_NAME).resolve(QUARKUS_RUN_JAR);
};

List<String> args = new ArrayList<>();
args.add(determineJavaPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import io.quarkus.builder.item.MultiBuildItem;

/**
* marker build item that extensions can use to force legacy jar creation
* Ignored.
* To force legacy-JAR creation, implement a configuration customizer which resets the
* default {@code quarkus.package.jar.type} to {@code legacy-jar},
* and add a validation step to your processor which verifies that {@code legacy-jar}
* is selected, throwing an error otherwise.
*/
@Deprecated
@Deprecated(forRemoval = true)
public final class LegacyJarRequiredBuildItem extends MultiBuildItem {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import io.quarkus.builder.item.MultiBuildItem;

/**
* marker build item that extensions can use to force uber jar creation
* Ignored.
* To force uber-JAR creation, implement a configuration customizer which resets the
* default {@code quarkus.package.jar.type} to {@code uber-jar},
* and add a validation step to your processor which verifies that {@code uber-jar}
* is selected, throwing an error otherwise.
*/
@Deprecated
@Deprecated(forRemoval = true)
public final class UberJarRequiredBuildItem extends MultiBuildItem {
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@
import io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.deployment.pkg.builditem.JarBuildItem;
import io.quarkus.deployment.pkg.builditem.LegacyJarRequiredBuildItem;
import io.quarkus.deployment.pkg.builditem.NativeImageSourceJarBuildItem;
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem;
import io.quarkus.deployment.pkg.builditem.UberJarIgnoredResourceBuildItem;
import io.quarkus.deployment.pkg.builditem.UberJarMergedResourceBuildItem;
import io.quarkus.deployment.pkg.builditem.UberJarRequiredBuildItem;
import io.quarkus.deployment.util.FileUtil;
import io.quarkus.fs.util.ZipUtils;
import io.quarkus.maven.dependency.ArtifactKey;
Expand Down Expand Up @@ -197,10 +195,8 @@ public JarBuildItem buildRunnerJar(CurateOutcomeBuildItem curateOutcomeBuildItem
ClassLoadingConfig classLoadingConfig,
List<GeneratedClassBuildItem> generatedClasses,
List<GeneratedResourceBuildItem> generatedResources,
List<UberJarRequiredBuildItem> uberJarRequired,
List<UberJarMergedResourceBuildItem> uberJarMergedResourceBuildItems,
List<UberJarIgnoredResourceBuildItem> uberJarIgnoredResourceBuildItems,
List<LegacyJarRequiredBuildItem> legacyJarRequired,
QuarkusBuildCloseablesBuildItem closeablesBuildItem,
List<AdditionalApplicationArchiveBuildItem> additionalApplicationArchiveBuildItems,
MainClassBuildItem mainClassBuildItem, Optional<AppCDSRequestedBuildItem> appCDS) throws Exception {
Expand All @@ -209,27 +205,21 @@ public JarBuildItem buildRunnerJar(CurateOutcomeBuildItem curateOutcomeBuildItem
handleAppCDSSupportFileGeneration(transformedClasses, generatedClasses, appCDS.get());
}

if (!uberJarRequired.isEmpty() && !legacyJarRequired.isEmpty()) {
throw new RuntimeException(
"Extensions with conflicting package types. One extension requires uber-jar another requires legacy format");
}

if (legacyJarRequired.isEmpty() && (!uberJarRequired.isEmpty()
|| packageConfig.jar().type() == UBER_JAR)) {
return buildUberJar(curateOutcomeBuildItem, outputTargetBuildItem, transformedClasses, applicationArchivesBuildItem,
packageConfig, applicationInfo, generatedClasses, generatedResources, uberJarMergedResourceBuildItems,
uberJarIgnoredResourceBuildItems, mainClassBuildItem, classLoadingConfig);
} else if (!legacyJarRequired.isEmpty() || packageConfig.jar().type() == LEGACY_JAR) {
return buildLegacyThinJar(curateOutcomeBuildItem, outputTargetBuildItem, transformedClasses,
return switch (packageConfig.jar().type()) {
case UBER_JAR ->
buildUberJar(curateOutcomeBuildItem, outputTargetBuildItem, transformedClasses, applicationArchivesBuildItem,
packageConfig, applicationInfo, generatedClasses, generatedResources, uberJarMergedResourceBuildItems,
uberJarIgnoredResourceBuildItems, mainClassBuildItem, classLoadingConfig);
case LEGACY_JAR -> buildLegacyThinJar(curateOutcomeBuildItem, outputTargetBuildItem, transformedClasses,
applicationArchivesBuildItem,
packageConfig, applicationInfo, generatedClasses, generatedResources, mainClassBuildItem,
classLoadingConfig);
} else {
return buildThinJar(curateOutcomeBuildItem, outputTargetBuildItem, transformedClasses, applicationArchivesBuildItem,
packageConfig, classLoadingConfig, applicationInfo, generatedClasses,
generatedResources,
additionalApplicationArchiveBuildItems, mainClassBuildItem);
}
case FAST_JAR, MUTABLE_JAR ->
buildThinJar(curateOutcomeBuildItem, outputTargetBuildItem, transformedClasses, applicationArchivesBuildItem,
packageConfig, classLoadingConfig, applicationInfo, generatedClasses,
generatedResources,
additionalApplicationArchiveBuildItems, mainClassBuildItem);
};
}

// the idea here is to just dump the class names of the generated and transformed classes into a file
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.quarkus.amazon.lambda.deployment;

import java.util.OptionalInt;

import io.smallrye.config.ConfigSourceInterceptor;
import io.smallrye.config.ConfigSourceInterceptorContext;
import io.smallrye.config.ConfigSourceInterceptorFactory;
import io.smallrye.config.ConfigValue;
import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.SmallRyeConfigBuilderCustomizer;

/**
* A configuration customizer to change the default packaging to legacy-jar.
*/
public final class ConfigurationCustomizer implements SmallRyeConfigBuilderCustomizer {
public void configBuilder(final SmallRyeConfigBuilder builder) {
builder.withInterceptorFactories(new ConfigSourceInterceptorFactory() {
public ConfigSourceInterceptor getInterceptor(final ConfigSourceInterceptorContext context) {
return (ic, name) -> switch (name) {
case "quarkus.package.jar.type" ->
ConfigValue.builder().withName(name).withValue("legacy-jar").build();
default -> ic.proceed(name);
};
}

public OptionalInt getPriority() {
return OptionalInt.of(Integer.MIN_VALUE + 100);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

Expand All @@ -16,12 +17,13 @@
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.jboss.logging.Logger;

import io.quarkus.builder.BuildException;
import io.quarkus.deployment.IsNormal;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.pkg.PackageConfig;
import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem;
import io.quarkus.deployment.pkg.builditem.JarBuildItem;
import io.quarkus.deployment.pkg.builditem.LegacyJarRequiredBuildItem;
import io.quarkus.deployment.pkg.builditem.NativeImageBuildItem;
import io.quarkus.deployment.pkg.builditem.NativeImageRunnerBuildItem;
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem;
Expand All @@ -35,11 +37,6 @@
public class FunctionZipProcessor {
private static final Logger log = Logger.getLogger(FunctionZipProcessor.class);

@BuildStep(onlyIf = IsNormal.class, onlyIfNot = NativeBuild.class)
public void requireLegacy(BuildProducer<LegacyJarRequiredBuildItem> required) {
required.produce(new LegacyJarRequiredBuildItem());
}

/**
* Function.zip is same as the runner jar plus dependencies in lib/
* plus anything in src/main/zip.jvm
Expand All @@ -51,8 +48,16 @@ public void requireLegacy(BuildProducer<LegacyJarRequiredBuildItem> required) {
*/
@BuildStep(onlyIf = IsNormal.class, onlyIfNot = NativeBuild.class)
public void jvmZip(OutputTargetBuildItem target,
PackageConfig packageConfig,
BuildProducer<ArtifactResultBuildItem> artifactResultProducer,
JarBuildItem jar) throws Exception {

if (packageConfig.jar().type() != PackageConfig.JarConfig.JarType.LEGACY_JAR) {
throw new BuildException("Lambda deployments need to use a legacy JAR, " +
"please set 'quarkus.package.jar.type=legacy-jar' inside your application.properties",
List.of());
}

Path zipPath = target.getOutputDirectory().resolve("function.zip");
Path zipDir = findJvmZipDir(target.getOutputDirectory());
try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipPath.toFile())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.quarkus.amazon.lambda.deployment.ConfigurationCustomizer
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
import io.quarkus.arc.processor.BuiltinScope;
import io.quarkus.builder.BuildException;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.IsNormal;
import io.quarkus.deployment.annotations.BuildProducer;
Expand All @@ -53,7 +54,6 @@
import io.quarkus.deployment.pkg.PackageConfig;
import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem;
import io.quarkus.deployment.pkg.builditem.JarBuildItem;
import io.quarkus.deployment.pkg.builditem.LegacyJarRequiredBuildItem;
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;

Expand All @@ -64,13 +64,6 @@ public class AzureFunctionsProcessor {
protected static final String LOCAL_SETTINGS_JSON = "local.settings.json";
public static final String FUNCTION_JSON = "function.json";

@BuildStep
public LegacyJarRequiredBuildItem forceLegacy(PackageConfig config) {
// TODO: Instead of this, consume a LegacyJarBuildItem
// Azure Functions need a legacy jar and no runner
return new LegacyJarRequiredBuildItem();
}

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(Feature.AZURE_FUNCTIONS);
Expand All @@ -93,6 +86,11 @@ public ArtifactResultBuildItem packageFunctions(List<AzureFunctionBuildItem> fun
log.warn("No azure functions exist in deployment");
return null;
}
if (packageConfig.jar().type() != PackageConfig.JarConfig.JarType.LEGACY_JAR) {
throw new BuildException("Azure Function deployment need to use a legacy JAR, " +
"please set 'quarkus.package.jar.type=legacy-jar' inside your application.properties",
List.of());
}
AnnotationHandler handler = new AnnotationHandlerImpl();
HashSet<Method> methods = new HashSet<>();
for (AzureFunctionBuildItem item : functions)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.quarkus.azure.functions.deployment;

import java.util.OptionalInt;

import io.smallrye.config.ConfigSourceInterceptor;
import io.smallrye.config.ConfigSourceInterceptorContext;
import io.smallrye.config.ConfigSourceInterceptorFactory;
import io.smallrye.config.ConfigValue;
import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.SmallRyeConfigBuilderCustomizer;

/**
* A configuration customizer to change the default packaging to legacy-jar.
*/
public final class ConfigurationCustomizer implements SmallRyeConfigBuilderCustomizer {
public void configBuilder(final SmallRyeConfigBuilder builder) {
builder.withInterceptorFactories(new ConfigSourceInterceptorFactory() {
public ConfigSourceInterceptor getInterceptor(final ConfigSourceInterceptorContext context) {
return (ic, name) -> switch (name) {
case "quarkus.package.jar.type" ->
ConfigValue.builder().withName(name).withValue("legacy-jar").build();
default -> ic.proceed(name);
};
}

public OptionalInt getPriority() {
return OptionalInt.of(Integer.MIN_VALUE + 100);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.quarkus.azure.functions.deployment.ConfigurationCustomizer
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
import io.quarkus.deployment.pkg.builditem.JarBuildItem;
import io.quarkus.deployment.pkg.builditem.NativeImageBuildItem;
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem;
import io.quarkus.deployment.pkg.builditem.UberJarRequiredBuildItem;
import io.quarkus.deployment.pkg.builditem.UpxCompressedBuildItem;
import io.quarkus.deployment.pkg.steps.JarResultBuildStep;
import io.quarkus.deployment.pkg.steps.NativeBuild;
Expand Down Expand Up @@ -155,7 +154,6 @@ public void buildFromJar(ContainerImageConfig containerImageConfig, ContainerIma
Optional<ContainerImagePushRequestBuildItem> pushRequest,
List<ContainerImageLabelBuildItem> containerImageLabels,
Optional<AppCDSResultBuildItem> appCDSResult,
List<UberJarRequiredBuildItem> uberJarRequired,
BuildProducer<ArtifactResultBuildItem> artifactResultProducer,
BuildProducer<ContainerImageBuilderBuildItem> containerImageBuilder) {

Expand All @@ -167,20 +165,17 @@ public void buildFromJar(ContainerImageConfig containerImageConfig, ContainerIma

JibContainerBuilder jibContainerBuilder;
PackageConfig.JarConfig.JarType jarType = packageConfig.jar().type();
if (jarType == LEGACY_JAR || jarType == UBER_JAR
|| !uberJarRequired.isEmpty()) {
jibContainerBuilder = createContainerBuilderFromLegacyJar(determineBaseJvmImage(jibConfig, compiledJavaVersion),
jibConfig, containerImageConfig,
sourceJar, outputTarget, mainClass, containerImageLabels);
} else if (jarType == FAST_JAR || jarType == MUTABLE_JAR) {
jibContainerBuilder = createContainerBuilderFromFastJar(determineBaseJvmImage(jibConfig, compiledJavaVersion),
jibConfig, containerImageConfig, sourceJar, curateOutcome,
containerImageLabels,
appCDSResult, jarType == MUTABLE_JAR);
} else {
throw new IllegalArgumentException(
"JAR type '" + jarType + "' is not supported by the container-image-jib extension");
}
jibContainerBuilder = switch (jarType) {
case LEGACY_JAR, UBER_JAR ->
createContainerBuilderFromLegacyJar(determineBaseJvmImage(jibConfig, compiledJavaVersion),
jibConfig, containerImageConfig,
sourceJar, outputTarget, mainClass, containerImageLabels);
case FAST_JAR, MUTABLE_JAR ->
createContainerBuilderFromFastJar(determineBaseJvmImage(jibConfig, compiledJavaVersion),
jibConfig, containerImageConfig, sourceJar, curateOutcome,
containerImageLabels,
appCDSResult, jarType == MUTABLE_JAR);
};
setUser(jibConfig, jibContainerBuilder);
setPlatforms(jibConfig, jibContainerBuilder);
handleExtraFiles(outputTarget, jibContainerBuilder);
Expand Down Expand Up @@ -396,16 +391,12 @@ private RegistryImage toRegistryImage(ImageReference imageReference, Optional<St
}

private Logger.Level toJBossLoggingLevel(LogEvent.Level level) {
switch (level) {
case ERROR:
return Logger.Level.ERROR;
case WARN:
return Logger.Level.WARN;
case LIFECYCLE:
return Logger.Level.INFO;
default:
return Logger.Level.DEBUG;
}
return switch (level) {
case ERROR -> Logger.Level.ERROR;
case WARN -> Logger.Level.WARN;
case LIFECYCLE -> Logger.Level.INFO;
default -> Logger.Level.DEBUG;
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,10 @@
import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem;
import io.quarkus.deployment.pkg.builditem.JarBuildItem;
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem;
import io.quarkus.deployment.pkg.builditem.UberJarRequiredBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;

public class CloudFunctionsDeploymentBuildStep {

@BuildStep
public UberJarRequiredBuildItem forceUberJar() {
// Google Cloud Function needs a single JAR inside a dedicated directory
return new UberJarRequiredBuildItem();
}

/**
* Creates a target/deployment dir and copy the uber jar in it.
* This facilitates the usage of the 'gcloud' command.
Expand Down
Loading
Loading