-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
38 changed files
with
322 additions
and
51 deletions.
There are no files selected for viewing
46 changes: 0 additions & 46 deletions
46
...t/src/main/java/org/apache/camel/quarkus/component/beanio/deployment/BeanioProcessor.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
...t/src/main/java/org/apache/camel/quarkus/component/beanio/deployment/BeanioProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.quarkus.component.beanio.deployment; | ||
|
||
import java.io.IOException; | ||
import java.util.Properties; | ||
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.CombinedIndexBuildItem; | ||
import io.quarkus.deployment.builditem.FeatureBuildItem; | ||
import io.quarkus.deployment.builditem.IndexDependencyBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; | ||
import org.beanio.BeanReaderErrorHandler; | ||
import org.beanio.annotation.Record; | ||
import org.beanio.stream.RecordParserFactory; | ||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.AnnotationTarget; | ||
import org.jboss.jandex.AnnotationTarget.Kind; | ||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.IndexView; | ||
|
||
class BeanioProcessor { | ||
private static final String FEATURE = "camel-beanio"; | ||
|
||
@BuildStep | ||
FeatureBuildItem feature() { | ||
return new FeatureBuildItem(FEATURE); | ||
} | ||
|
||
@BuildStep | ||
IndexDependencyBuildItem indexDependencies() { | ||
return new IndexDependencyBuildItem("com.github.beanio", "beanio"); | ||
} | ||
|
||
@BuildStep | ||
BeanioPropertiesBuildItem beanioProperties() { | ||
try { | ||
Properties properties = new Properties(); | ||
properties.load(Thread.currentThread().getContextClassLoader() | ||
.getResourceAsStream("org/beanio/internal/config/beanio.properties")); | ||
return new BeanioPropertiesBuildItem(properties); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@BuildStep | ||
void nativeImageResources(BuildProducer<NativeImageResourceBuildItem> nativeImageResource) { | ||
nativeImageResource.produce(new NativeImageResourceBuildItem("org/beanio/internal/config/beanio.properties")); | ||
nativeImageResource.produce(new NativeImageResourceBuildItem("beanio.properties")); | ||
} | ||
|
||
@BuildStep | ||
void registerForReflection( | ||
BeanioPropertiesBuildItem beanioProperties, | ||
CombinedIndexBuildItem combinedIndex, | ||
BuildProducer<ReflectiveClassBuildItem> reflectiveClass) { | ||
Properties properties = beanioProperties.getProperties(); | ||
|
||
Set<String> handlersAndFactories = properties.keySet() | ||
.stream() | ||
.filter(key -> key.toString().contains("Factory") || key.toString().contains("Handler")) | ||
.map(properties::get) | ||
.map(Object::toString) | ||
.collect(Collectors.toUnmodifiableSet()); | ||
reflectiveClass.produce(ReflectiveClassBuildItem.builder(handlersAndFactories.toArray(new String[0])).build()); | ||
|
||
IndexView index = combinedIndex.getIndex(); | ||
Set<String> recordParsers = index.getAllKnownImplementors(RecordParserFactory.class) | ||
.stream() | ||
.map(ClassInfo::name) | ||
.map(DotName::toString) | ||
.collect(Collectors.toUnmodifiableSet()); | ||
reflectiveClass.produce(ReflectiveClassBuildItem.builder(recordParsers.toArray(new String[0])).methods(true).build()); | ||
|
||
Set<String> parserConfiguration = index.getKnownClasses() | ||
.stream() | ||
.map(ClassInfo::name) | ||
.map(DotName::toString) | ||
.filter(name -> name.startsWith("org.beanio") && name.endsWith("ParserConfiguration")) | ||
.collect(Collectors.toUnmodifiableSet()); | ||
reflectiveClass | ||
.produce(ReflectiveClassBuildItem.builder(parserConfiguration.toArray(new String[0])).methods(true).build()); | ||
|
||
Set<String> errorHandlers = index.getAllKnownImplementors(BeanReaderErrorHandler.class) | ||
.stream() | ||
.map(ClassInfo::name) | ||
.map(DotName::toString) | ||
.collect(Collectors.toUnmodifiableSet()); | ||
reflectiveClass.produce(ReflectiveClassBuildItem.builder(errorHandlers.toArray(new String[0])).build()); | ||
|
||
Set<String> recordClasses = index.getAnnotations(Record.class) | ||
.stream() | ||
.map(AnnotationInstance::target) | ||
.filter(target -> target.kind().equals(Kind.CLASS)) | ||
.map(AnnotationTarget::asClass) | ||
.map(ClassInfo::name) | ||
.map(DotName::toString) | ||
.collect(Collectors.toUnmodifiableSet()); | ||
reflectiveClass | ||
.produce(ReflectiveClassBuildItem.builder(recordClasses.toArray(new String[0])).fields(true).methods(true) | ||
.build()); | ||
} | ||
|
||
@BuildStep | ||
void registerResourceBundles(BeanioPropertiesBuildItem beanioProperties, | ||
BuildProducer<NativeImageResourceBundleBuildItem> nativeImageResourceBundle) { | ||
Properties properties = beanioProperties.getProperties(); | ||
properties.keySet() | ||
.stream() | ||
.filter(key -> key.toString().endsWith(".messages")) | ||
.map(properties::get) | ||
.map(Object::toString) | ||
.map(NativeImageResourceBundleBuildItem::new) | ||
.forEach(nativeImageResourceBundle::produce); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
.../java/org/apache/camel/quarkus/component/beanio/deployment/BeanioPropertiesBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.quarkus.component.beanio.deployment; | ||
|
||
import java.util.Properties; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
public final class BeanioPropertiesBuildItem extends SimpleBuildItem { | ||
private final Properties properties; | ||
|
||
public BeanioPropertiesBuildItem(Properties properties) { | ||
this.properties = properties; | ||
} | ||
|
||
public Properties getProperties() { | ||
return properties; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
=== BeanIO in native mode | ||
|
||
==== XML mapping files | ||
|
||
When BeanIO configuration is defined in XML files that are read from the classpath. | ||
You must ensure each file is added to the native application image. | ||
To do this, add the `quarkus.native.resources.includes` configuration property to `application.properties`. For example. | ||
|
||
[source,properties] | ||
---- | ||
quarkus.native.resources.includes=mapping.xml,model/other-mapping.xml | ||
---- | ||
|
||
More information about selecting resources for inclusion in the native executable can be found at xref:user-guide/native-mode.adoc#embedding-resource-in-native-executable[Embedding resources in native executable]. | ||
|
||
==== BeanIO Record classes | ||
|
||
All classes that participate in BeanIO marshal / unmarshal operations must be registered for reflection. | ||
|
||
This can be achieved with the `@RegisterForReflection` | ||
annotation or with configuration property `quarkus.camel.native.reflection.include-patterns`. For example: | ||
|
||
[source,java] | ||
---- | ||
@RegisterForReflection | ||
public class Employee { | ||
... | ||
} | ||
---- | ||
|
||
Refer to the xref:user-guide/native-mode.adoc#reflection[Native mode] user guide for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.