Skip to content

Commit

Permalink
Fix #518 Rely on configurers for Configuration classes instead of using
Browse files Browse the repository at this point in the history
reflection
  • Loading branch information
ppalaga committed Jan 23, 2020
1 parent 7f9ec9c commit 8d3a3b0
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.component.aws.ec2.EC2Configuration;

class AwsEc2Processor {
public static final String AWS_EC2_APPLICATION_ARCHIVE_MARKERS = "com/amazonaws";
Expand Down Expand Up @@ -58,8 +57,7 @@ void process(CombinedIndexBuildItem combinedIndexBuildItem,
Endpoint.class.getCanonicalName(),
Region.class.getCanonicalName(),
Service.class.getCanonicalName(),
CredentialScope.class.getCanonicalName(),
EC2Configuration.class.getCanonicalName()));
CredentialScope.class.getCanonicalName()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.component.aws.ecs.ECSConfiguration;

class AwsEcsProcessor {

Expand Down Expand Up @@ -59,7 +58,6 @@ void process(CombinedIndexBuildItem combinedIndexBuildItem,
Endpoint.class.getCanonicalName(),
Region.class.getCanonicalName(),
Service.class.getCanonicalName(),
CredentialScope.class.getCanonicalName(),
ECSConfiguration.class.getCanonicalName()));
CredentialScope.class.getCanonicalName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.component.aws.eks.EKSConfiguration;

class AwsEKSProcessor {

Expand Down Expand Up @@ -59,7 +58,6 @@ void process(CombinedIndexBuildItem combinedIndexBuildItem,
Endpoint.class.getCanonicalName(),
Region.class.getCanonicalName(),
Service.class.getCanonicalName(),
CredentialScope.class.getCanonicalName(),
EKSConfiguration.class.getCanonicalName()));
CredentialScope.class.getCanonicalName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.component.aws.iam.IAMConfiguration;

class AwsIamProcessor {

Expand Down Expand Up @@ -59,7 +58,6 @@ void process(CombinedIndexBuildItem combinedIndexBuildItem,
Endpoint.class.getCanonicalName(),
Region.class.getCanonicalName(),
Service.class.getCanonicalName(),
CredentialScope.class.getCanonicalName(),
IAMConfiguration.class.getCanonicalName()));
CredentialScope.class.getCanonicalName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.component.aws.firehose.KinesisFirehoseConfiguration;
import org.apache.camel.component.aws.kinesis.KinesisConfiguration;

class AwsKinesisProcessor {

Expand Down Expand Up @@ -60,8 +58,6 @@ void process(CombinedIndexBuildItem combinedIndexBuildItem,
Endpoint.class.getCanonicalName(),
Region.class.getCanonicalName(),
Service.class.getCanonicalName(),
CredentialScope.class.getCanonicalName(),
KinesisConfiguration.class.getCanonicalName(),
KinesisFirehoseConfiguration.class.getCanonicalName()));
CredentialScope.class.getCanonicalName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.component.aws.kms.KMSConfiguration;

class AwsKmsProcessor {

Expand Down Expand Up @@ -59,7 +58,6 @@ void process(CombinedIndexBuildItem combinedIndexBuildItem,
Endpoint.class.getCanonicalName(),
Region.class.getCanonicalName(),
Service.class.getCanonicalName(),
CredentialScope.class.getCanonicalName(),
KMSConfiguration.class.getCanonicalName()));
CredentialScope.class.getCanonicalName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.component.aws.lambda.LambdaConfiguration;

class AwsLambdaProcessor {

Expand Down Expand Up @@ -59,7 +58,6 @@ void process(CombinedIndexBuildItem combinedIndexBuildItem,
Endpoint.class.getCanonicalName(),
Region.class.getCanonicalName(),
Service.class.getCanonicalName(),
CredentialScope.class.getCanonicalName(),
LambdaConfiguration.class.getCanonicalName()));
CredentialScope.class.getCanonicalName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import org.apache.camel.component.aws.s3.S3Configuration;

class AwsS3Processor {

Expand Down Expand Up @@ -68,8 +67,7 @@ void process(CombinedIndexBuildItem combinedIndexBuildItem,
Region.class.getCanonicalName(),
Service.class.getCanonicalName(),
CredentialScope.class.getCanonicalName(),
AWSS3V4Signer.class.getCanonicalName(),
S3Configuration.class.getCanonicalName()));
AWSS3V4Signer.class.getCanonicalName()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.component.aws.sns.SnsConfiguration;

class AwsSNSProcessor {

Expand Down Expand Up @@ -61,8 +60,7 @@ void process(CombinedIndexBuildItem combinedIndexBuildItem,
Region.class.getCanonicalName(),
Service.class.getCanonicalName(),
CredentialScope.class.getCanonicalName(),
AWS4Signer.class.getCanonicalName(),
SnsConfiguration.class.getCanonicalName()));
AWS4Signer.class.getCanonicalName()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.component.aws.sqs.SqsConfiguration;

class AwsSQSProcessor {

Expand Down Expand Up @@ -61,7 +60,6 @@ void process(CombinedIndexBuildItem combinedIndexBuildItem,
Region.class.getCanonicalName(),
Service.class.getCanonicalName(),
CredentialScope.class.getCanonicalName(),
AWS4Signer.class.getCanonicalName(),
SqsConfiguration.class.getCanonicalName()));
AWS4Signer.class.getCanonicalName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.component.aws.translate.TranslateConfiguration;

class AwsTranslateProcessor {

Expand Down Expand Up @@ -61,7 +60,6 @@ void process(CombinedIndexBuildItem combinedIndexBuildItem,
Region.class.getCanonicalName(),
Service.class.getCanonicalName(),
CredentialScope.class.getCanonicalName(),
AWS4Signer.class.getCanonicalName(),
TranslateConfiguration.class.getCanonicalName()));
AWS4Signer.class.getCanonicalName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.GeneratedResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveMethodBuildItem;
Expand Down Expand Up @@ -68,6 +71,66 @@ public static class Core {
PropertiesComponent.class,
DataFormat.class);

/**
* A list of classes annotated with <code>@UriParams</code> which we accept to be registered for reflection
* mostly because there are errors when they are removed. TODO: solve the underlying problems and remove as
* many entries as possible from the list.
*/
private static final Set<String> URI_PARAMS_WHITELIST = new HashSet<>(Arrays.asList(
"org.apache.camel.support.processor.DefaultExchangeFormatter",
"org.apache.camel.component.pdf.PdfConfiguration",
"org.apache.camel.component.netty.NettyConfiguration",
"org.apache.camel.component.netty.NettyServerBootstrapConfiguration",
"org.apache.camel.component.fhir.FhirUpdateEndpointConfiguration",
"org.apache.camel.component.fhir.FhirOperationEndpointConfiguration",
"org.apache.camel.component.fhir.FhirConfiguration",
"org.apache.camel.component.fhir.FhirLoadPageEndpointConfiguration",
"org.apache.camel.component.fhir.FhirSearchEndpointConfiguration",
"org.apache.camel.component.fhir.FhirTransactionEndpointConfiguration",
"org.apache.camel.component.fhir.FhirCreateEndpointConfiguration",
"org.apache.camel.component.fhir.FhirValidateEndpointConfiguration",
"org.apache.camel.component.fhir.FhirReadEndpointConfiguration",
"org.apache.camel.component.fhir.FhirCapabilitiesEndpointConfiguration",
"org.apache.camel.component.fhir.FhirHistoryEndpointConfiguration",
"org.apache.camel.component.fhir.FhirMetaEndpointConfiguration",
"org.apache.camel.component.fhir.FhirPatchEndpointConfiguration",
"org.apache.camel.component.fhir.FhirDeleteEndpointConfiguration",

/* org.apache.camel.component.consul.* can be removed after the upgrade to Camel 3.1 */
"org.apache.camel.component.consul.ConsulConfiguration",
"org.apache.camel.component.consul.ConsulClientConfiguration",
"org.apache.camel.component.consul.health.ConsulHealthCheckRepositoryConfiguration",
"org.apache.camel.component.consul.cloud.ConsulServiceRegistryConfiguration"));

@BuildStep
void bannedReflectiveClasses(
CombinedIndexBuildItem combinedIndex,
List<ReflectiveClassBuildItem> reflectiveClass,
BuildProducer<GeneratedResourceBuildItem> dummy // to force the execution of this method
) {
final DotName uriParamsDotName = DotName.createSimple("org.apache.camel.spi.UriParams");

final Set<String> bannedClassNames = combinedIndex.getIndex()
.getAnnotations(uriParamsDotName)
.stream()
.filter(ai -> ai.target().kind() == Kind.CLASS)
.map(ai -> ai.target().asClass().name().toString())
.collect(Collectors.toSet());

Set<String> violations = reflectiveClass.stream()
.map(ReflectiveClassBuildItem::getClassNames)
.flatMap(Collection::stream)
.filter(cl -> !URI_PARAMS_WHITELIST.contains(cl))
.filter(bannedClassNames::contains)
.collect(Collectors.toSet());

if (!violations.isEmpty()) {
throw new IllegalStateException(
"The following classes should either be whitelisted via NativeImageProcessor.Core.URI_PARAMS_WHITELIST or they should not be registered for reflection via ReflectiveClassBuildItem: "
+ violations);
}
}

@BuildStep
void reflectiveItems(
CombinedIndexBuildItem combinedIndex,
Expand All @@ -92,7 +155,8 @@ void reflectiveItems(
.filter(ai -> {
AnnotationValue av = ai.value("loader");
boolean isLoader = av != null && av.asBoolean();
// filter out camel-base converters which are automatically inlined in the CoreStaticTypeConverterLoader
// filter out camel-base converters which are automatically inlined in the
// CoreStaticTypeConverterLoader
// need to revisit with Camel 3.0.0-M3 which should improve this area
if (ai.target().asClass().name().toString().startsWith("org.apache.camel.converter.")) {
log.debug("Ignoring core " + ai + " " + ai.target().asClass().name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.jaxb.deployment.JaxbFileRootBuildItem;
import org.apache.camel.component.dozer.DozerConfiguration;
import org.apache.camel.converter.dozer.DozerBeanMapperConfiguration;
import org.apache.camel.converter.dozer.DozerThreadContextClassLoader;
import org.apache.camel.quarkus.component.dozer.CamelDozerConfig;
Expand Down Expand Up @@ -121,7 +120,6 @@ void configureCamelDozer(BuildProducer<ReflectiveClassBuildItem> reflectiveClass
reflectiveClass.produce(new ReflectiveClassBuildItem(
true,
false,
DozerConfiguration.class,
DozerBeanMapperConfiguration.class));

if (camelDozerConfig.mappingFiles.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.component.file.remote.FtpConfiguration;
import org.apache.camel.component.file.remote.FtpsConfiguration;
import org.apache.camel.component.file.remote.RemoteFileConfiguration;
import org.apache.camel.component.file.remote.SftpConfiguration;

class FtpProcessor {

Expand All @@ -37,11 +33,6 @@ FeatureBuildItem feature() {

@BuildStep
void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false,
RemoteFileConfiguration.class,
FtpConfiguration.class,
FtpsConfiguration.class,
SftpConfiguration.class));

reflectiveClass.produce(new ReflectiveClassBuildItem(true, true,
"com.jcraft.jsch.CipherNone",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,11 @@

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.component.infinispan.InfinispanConfiguration;

class InfinispanProcessor {

private static final String FEATURE = "camel-infinispan";

@BuildStep
ReflectiveClassBuildItem reflection() {
return new ReflectiveClassBuildItem(true, true, InfinispanConfiguration.class);
}

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.component.paho.PahoConfiguration;
import org.eclipse.paho.client.mqttv3.internal.SSLNetworkModuleFactory;
import org.eclipse.paho.client.mqttv3.internal.TCPNetworkModuleFactory;
import org.eclipse.paho.client.mqttv3.logging.JSR47Logger;
Expand All @@ -40,8 +39,7 @@ class PahoProcessor {
private static final List<Class<?>> PAHO_REFLECTIVE_CLASSES = Arrays.asList(
JSR47Logger.class,
TCPNetworkModuleFactory.class,
SSLNetworkModuleFactory.class,
PahoConfiguration.class);
SSLNetworkModuleFactory.class);

@Inject
BuildProducer<NativeImageResourceBuildItem> resource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.component.twitter.AbstractTwitterComponent;
import org.apache.camel.component.twitter.TwitterConfiguration;

class TwitterProcessor {
private static final String FEATURE = "camel-twitter";
Expand All @@ -34,7 +33,6 @@ FeatureBuildItem feature() {
@BuildStep
void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false,
AbstractTwitterComponent.class,
TwitterConfiguration.class));
AbstractTwitterComponent.class));
}
}

0 comments on commit 8d3a3b0

Please sign in to comment.