Skip to content

Commit

Permalink
Ensure that native-sources package results in the configuration as na…
Browse files Browse the repository at this point in the history
…tive

Furthermore, fail the build when native-sources is requested but the extension
creates its own output

Related to: quarkusio#15233 (comment)
  • Loading branch information
geoand committed Feb 24, 2021
1 parent b0b1210 commit a90ca4b
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.deployment.metrics.MetricsCapabilityBuildItem;
import io.quarkus.deployment.metrics.MetricsFactoryConsumerBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
import io.quarkus.gizmo.AnnotationCreator;
import io.quarkus.gizmo.BranchResult;
import io.quarkus.gizmo.BytecodeCreator;
Expand Down Expand Up @@ -169,7 +169,7 @@ void registerMetrics(LogMetricsHandlerRecorder recorder, LogBuildTimeConfig log,
}
}

@BuildStep(onlyIf = NativeBuild.class)
@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
void setUpMinLevelLogging(LogBuildTimeConfig log,
final BuildProducer<GeneratedClassBuildItem> generatedTraceLogger) {
ClassOutput output = new GeneratedClassGizmoAdaptor(generatedTraceLogger, false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.quarkus.deployment.pkg.steps;

import java.util.function.BooleanSupplier;

import io.quarkus.deployment.pkg.PackageConfig;

/**
* Supplier that can be used to only run build steps in the
* native or native sources builds.
*/
public class NativeOrNativeSourcesBuild implements BooleanSupplier {

private final PackageConfig packageConfig;

NativeOrNativeSourcesBuild(PackageConfig packageConfig) {
this.packageConfig = packageConfig;
}

@Override
public boolean getAsBoolean() {
return packageConfig.type.equalsIgnoreCase(PackageConfig.NATIVE)
|| packageConfig.type.equalsIgnoreCase(PackageConfig.NATIVE_SOURCES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.quarkus.deployment.builditem.nativeimage.NativeImageSystemPropertyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
import io.quarkus.runtime.ssl.SslContextConfigurationRecorder;

//TODO: this should go away, once we decide on which one of the API's we want
Expand Down Expand Up @@ -89,7 +89,7 @@ void build(SslContextConfigurationRecorder sslContextConfigurationRecorder,
}
}

@BuildStep(onlyIf = NativeBuild.class)
@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
void reinitHostNameUtil(BuildProducer<RuntimeReinitializedClassBuildItem> runtimeReInitClass) {
// certain libraries like JBoss logging internally use this class to determine the hostname
// of the system. This HostName class computes and stores the hostname as a static field in a class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.SystemPropertyBuildItem;
import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import io.quarkus.deployment.pkg.steps.NativeSourcesBuild;
import io.quarkus.jackson.runtime.ObjectMapperProducer;
import io.quarkus.runtime.LaunchMode;

@SuppressWarnings("unchecked")
public final class AmazonLambdaCommonProcessor {

@BuildStep(onlyIf = NativeSourcesBuild.class)
void failForNativeSources(BuildProducer<ArtifactResultBuildItem> artifactResultProducer) {
throw new IllegalArgumentException(
"The Amazon Lambda extensions are incompatible with the 'native-sources' package type.");
}

/**
* Lambda custom runtime does not like ipv6.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.ApplicationInfoBuildItem;
import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem;
import io.quarkus.deployment.pkg.steps.NativeSourcesBuild;

public class ContainerImageProcessor {

private static final String UNKNOWN_USER = "?";
private static final Logger log = Logger.getLogger(ContainerImageProcessor.class);

@BuildStep(onlyIf = NativeSourcesBuild.class)
void failForNativeSources(BuildProducer<ArtifactResultBuildItem> artifactResultProducer) {
throw new IllegalArgumentException(
"The Container Imagee extensions are incompatible with the 'native-sources' package type.");
}

@BuildStep
public void publishImageInfo(ApplicationInfoBuildItem app,
ContainerImageConfig containerImageConfig, Capabilities capabilities,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

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.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;
import io.quarkus.deployment.pkg.steps.NativeSourcesBuild;

public class CloudFunctionDeploymentBuildStep {
@BuildStep
Expand All @@ -21,6 +23,12 @@ public UberJarRequiredBuildItem forceUberJar() {
return new UberJarRequiredBuildItem();
}

@BuildStep(onlyIf = NativeSourcesBuild.class)
void failForNativeSources(BuildProducer<ArtifactResultBuildItem> artifactResultProducer) {
throw new IllegalArgumentException(
"The Google Cloud extensions are incompatible with the 'native-sources' package type.");
}

/**
* Creates a target/deployment dir and copy the uber jar in it.
* This facilitates the usage of the 'glcoud' command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.configuration.ConfigurationError;
import io.quarkus.deployment.index.IndexingUtil;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
import io.quarkus.deployment.recording.RecorderContext;
import io.quarkus.deployment.util.IoUtil;
import io.quarkus.deployment.util.ServiceUtil;
Expand Down Expand Up @@ -611,7 +611,7 @@ public void produceLoggingCategories(HibernateOrmConfig hibernateOrmConfig,
}
}

@BuildStep(onlyIf = NativeBuild.class)
@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
public void registerStaticMetamodelClassesForReflection(CombinedIndexBuildItem index,
BuildProducer<ReflectiveClassBuildItem> reflective) {
Collection<AnnotationInstance> annotationInstances = index.getIndex().getAnnotations(STATIC_METAMODEL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.metrics.MetricsCapabilityBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
import io.quarkus.jaeger.runtime.JaegerBuildTimeConfig;
import io.quarkus.jaeger.runtime.JaegerConfig;
import io.quarkus.jaeger.runtime.JaegerDeploymentRecorder;
Expand All @@ -23,7 +23,7 @@

public class JaegerProcessor {

@BuildStep(onlyIf = NativeBuild.class)
@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
@Record(ExecutionTime.STATIC_INIT)
void setVersion(JaegerDeploymentRecorder jdr) {
jdr.setJaegerVersion(JaegerTracer.getVersionFromProperties());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageSystemPropertyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
import io.quarkus.jdbc.mysql.runtime.MySQLAgroalConnectionConfigurer;
import io.quarkus.jdbc.mysql.runtime.MySQLServiceBindingConverter;

Expand Down Expand Up @@ -87,7 +87,7 @@ NativeImageSystemPropertyBuildItem disableAbandonedConnectionCleanUpInNativeMode
return new NativeImageSystemPropertyBuildItem("com.mysql.cj.disableAbandonedConnectionCleanup", "true");
}

@BuildStep(onlyIfNot = NativeBuild.class)
@BuildStep(onlyIfNot = NativeOrNativeSourcesBuild.class)
SystemPropertyBuildItem disableAbandonedConnectionCleanUpInJVMMode() {
return new SystemPropertyBuildItem("com.mysql.cj.disableAbandonedConnectionCleanup", "true");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
import io.quarkus.deployment.util.ServiceUtil;
import io.quarkus.liquibase.LiquibaseDataSource;
import io.quarkus.liquibase.LiquibaseFactory;
Expand Down Expand Up @@ -82,7 +82,7 @@ public SystemPropertyBuildItem disableHub() {
return new SystemPropertyBuildItem("liquibase.hub.mode", "off");
}

@BuildStep(onlyIf = NativeBuild.class)
@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
@Record(STATIC_INIT)
void nativeImageConfiguration(
LiquibaseRecorder recorder,
Expand Down

0 comments on commit a90ca4b

Please sign in to comment.