Skip to content

Commit

Permalink
Add Dozer component extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed Nov 19, 2019
1 parent 46636b1 commit fb27cd4
Show file tree
Hide file tree
Showing 26 changed files with 1,306 additions and 2 deletions.
31 changes: 31 additions & 0 deletions docs/modules/ROOT/pages/extensions/dozer.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[[dozer]]
= Dozer Extension

*Since Camel Quarkus 0.5.0*

The Dozer component provides the ability to map between Java beans using the http://camel.apache.org/dozer-type-conversion.html[Dozer] mapping framework.

Maven users will need to add the following dependency to their `pom.xml` for this extension.

[source,xml]
------------------------------------------------------------
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-dozer</artifactId>
</dependency>
------------------------------------------------------------

== Usage

The extension provides support for the Camel https://camel.apache.org/components/latest/dozer-component.html[Dozer Component].

=== Configuration

The Dozer extension can automatically register a `DozerBeanMapperConfiguration` bean with the Camel registry which references your mapping files.

Use the following configuration property to specify the location(s) of your Dozer mapping configuration files.

[source,properties]
----
quarkus.camel.dozer.mapping-files = dozerMappings.xml,file:foo/bar/custom-mappings.xml,http://foo/bar/mapping.xml
----
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ As of Camel Quarkus {camel-quarkus-last-release} the following Camel artifacts a
== Camel Components

// components: START
Number of Camel components: 38 in 33 JAR artifacts (0 deprecated)
Number of Camel components: 39 in 34 JAR artifacts (0 deprecated)

[width="100%",cols="4,1,5",options="header"]
|===
Expand Down Expand Up @@ -42,6 +42,9 @@ Number of Camel components: 38 in 33 JAR artifacts (0 deprecated)
| link:https://camel.apache.org/components/latest/direct-component.html[Direct] (camel-quarkus-direct) +
`direct:name` | 0.2 | The direct component provides direct, synchronous call to another endpoint from the same CamelContext.

| xref:extensions/dozer.adoc[Dozer] (camel-quarkus-dozer) +
`dozer:name` | 0.4 | The dozer component provides the ability to map between Java beans using the Dozer mapping library.

| link:https://camel.apache.org/components/latest/exec-component.html[Exec] (camel-quarkus-exec) +
`exec:executable` | 0.4 | The exec component can be used to execute OS system commands.

Expand Down
79 changes: 79 additions & 0 deletions extensions/dozer/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-dozer-parent</artifactId>
<version>0.4.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-dozer-deployment</artifactId>
<name>Camel Quarkus :: Dozer :: Deployment</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-bom-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jaxb-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-dozer</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/*
* 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.dozer.deployment;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;

import java.io.File;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;

import com.github.dozermapper.core.builder.model.jaxb.AllowedExceptionsDefinition;
import com.github.dozermapper.core.builder.model.jaxb.ClassDefinition;
import com.github.dozermapper.core.builder.model.jaxb.ConfigurationDefinition;
import com.github.dozermapper.core.builder.model.jaxb.ConverterTypeDefinition;
import com.github.dozermapper.core.builder.model.jaxb.CopyByReferencesDefinition;
import com.github.dozermapper.core.builder.model.jaxb.CustomConvertersDefinition;
import com.github.dozermapper.core.builder.model.jaxb.FieldDefinition;
import com.github.dozermapper.core.builder.model.jaxb.FieldDefinitionDefinition;
import com.github.dozermapper.core.builder.model.jaxb.FieldExcludeDefinition;
import com.github.dozermapper.core.builder.model.jaxb.FieldType;
import com.github.dozermapper.core.builder.model.jaxb.MappingDefinition;
import com.github.dozermapper.core.builder.model.jaxb.MappingsDefinition;
import com.github.dozermapper.core.builder.model.jaxb.Relationship;
import com.github.dozermapper.core.builder.model.jaxb.Type;
import com.github.dozermapper.core.builder.model.jaxb.VariableDefinition;
import com.github.dozermapper.core.builder.model.jaxb.VariablesDefinition;
import com.sun.el.ExpressionFactoryImpl;

import org.apache.camel.component.dozer.CustomMapper;
import org.apache.camel.component.dozer.DozerConfiguration;
import org.apache.camel.component.dozer.ExpressionMapper;
import org.apache.camel.component.dozer.VariableMapper;
import org.apache.camel.converter.dozer.DozerBeanMapperConfiguration;
import org.apache.camel.converter.dozer.DozerThreadContextClassLoader;
import org.apache.camel.quarkus.component.dozer.CamelDozerConfig;
import org.apache.camel.quarkus.component.dozer.CamelDozerRecorder;
import org.apache.camel.quarkus.core.deployment.CamelBeanBuildItem;

class DozerProcessor {

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

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep
void configureCamelDozer(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
BuildProducer<NativeImageResourceBuildItem> nativeImage,
CamelDozerConfig camelDozerConfig) {

// Add user Dozer mapping files to the image
camelDozerConfig.mappingFiles
.stream()
.map(this::mappingPathToURI)
// No scheme means classpath URI
.filter(uri -> uri.getScheme() == null)
.map(uri -> new NativeImageResourceBuildItem(uri.getPath()))
.forEach(nativeImage::produce);

// Add Dozer JAXB resources to the image
nativeImage.produce(new NativeImageResourceBuildItem(
"dtd/bean-mapping.dtd",
"dtd/bean-mapping-6.0.0.dtd",
"dtd/bean-mapping-6.2.0.dtd",
"schema/bean-mapping.xsd",
"schema/bean-mapping-6.0.0.xsd",
"schema/bean-mapping-6.2.0.xsd",
"com/github/dozermapper/core/builder/model/jaxb/jaxb.index"));

reflectiveClass.produce(new ReflectiveClassBuildItem(false, false,
BigDecimal[].class,
BigInteger[].class,
Boolean[].class,
Byte[].class,
Calendar[].class,
Character[].class,
Class[].class,
Date[].class,
java.sql.Date[].class,
Double[].class,
File[].class,
Float[].class,
Integer[].class,
Long[].class,
Object[].class,
Short[].class,
String[].class,
Time[].class,
Timestamp[].class,
URL[].class,
DozerThreadContextClassLoader.class,
ExpressionFactoryImpl.class));

reflectiveClass.produce(
new ReflectiveClassBuildItem(false, false,
"com.github.dozermapper.core.builder.model.jaxb.package-info",
"com.sun.org.apache.xerces.internal.impl.dv.xs.SchemaDVFactoryImpl"));

reflectiveClass.produce(new ReflectiveClassBuildItem(true, false,
CustomMapper.class,
DozerConfiguration.class,
ExpressionMapper.class,
VariableMapper.class));

reflectiveClass.produce(new ReflectiveClassBuildItem(true, true,
AllowedExceptionsDefinition.class,
ClassDefinition.class,
ConfigurationDefinition.class,
ConverterTypeDefinition.class,
CopyByReferencesDefinition.class,
CustomConvertersDefinition.class,
FieldDefinition.class,
FieldDefinitionDefinition.class,
FieldExcludeDefinition.class,
FieldType.class,
MappingDefinition.class,
MappingsDefinition.class,
Relationship.class,
Type.class,
VariableDefinition.class,
VariablesDefinition.class));
}

@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelBeanBuildItem configureCamelDozerBeanMappings(BuildProducer<CamelBeanBuildItem> camelBeanBuildItemBuildProducer,
CamelDozerConfig camelDozerConfig,
CamelDozerRecorder camelDozerRecorder) {

CamelBeanBuildItem camelBeanBuildItem = null;

if (!camelDozerConfig.mappingFiles.isEmpty()) {
// Bind DozerBeanMapperConfiguration to the Camel registry for the user provided Dozer mapping files
camelBeanBuildItem = new CamelBeanBuildItem(
"dozerBeanMappingConfiguration",
DozerBeanMapperConfiguration.class.getName(),
camelDozerRecorder.createDozerBeanMapperConfiguration(camelDozerConfig.mappingFiles));
}

return camelBeanBuildItem;
}

private URI mappingPathToURI(String mappingPath) {
try {
return new URI(mappingPath);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
}
39 changes: 39 additions & 0 deletions extensions/dozer/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-build-parent</artifactId>
<version>0.4.1-SNAPSHOT</version>
<relativePath>../../poms/build-parent/pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-dozer-parent</artifactId>
<name>Camel Quarkus :: Dozer</name>
<packaging>pom</packaging>

<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>

0 comments on commit fb27cd4

Please sign in to comment.