Skip to content

Commit

Permalink
Add MapStruct native support
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed Jul 26, 2023
1 parent 7cb3ed4 commit b237553
Show file tree
Hide file tree
Showing 44 changed files with 1,934 additions and 197 deletions.
3 changes: 2 additions & 1 deletion docs/antora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ asciidoc:
quarkus-version: 3.2.2.Final # replace ${quarkus.version}
graalvm-version: 22.3.2 # replace ${graalvm.version}
graalvm-docs-version: 22.3
mapstruct-version: 1.5.5.Final # replace ${mapstruct.version}
min-maven-version: 3.8.2 # replace ${min-maven-version}
target-maven-version: 3.9.3 # replace ${target-maven-version}

Expand All @@ -52,7 +53,7 @@ asciidoc:
link-quarkus-code-generator: code.quarkus.io
link-quarkus-cxf-doc: https://quarkiverse.github.io/quarkiverse-docs/quarkus-cxf/dev
link-quarkus-cxf-source: https://github.com/quarkiverse/quarkus-cxf/tree/main

# Misc
javaxOrJakartaPackagePrefix: jakarta # this can be switched to javax in older branches

Expand Down
6 changes: 3 additions & 3 deletions docs/modules/ROOT/examples/components/mapstruct.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
cqArtifactId: camel-quarkus-mapstruct
cqArtifactIdBase: mapstruct
cqNativeSupported: false
cqStatus: Preview
cqNativeSupported: true
cqStatus: Stable
cqDeprecated: false
cqJvmSince: 3.0.0
cqNativeSince: n/a
cqNativeSince: 3.0.0
cqCamelPartName: mapstruct
cqCamelPartTitle: MapStruct
cqCamelPartDescription: Type Conversion using Mapstruct
Expand Down
68 changes: 63 additions & 5 deletions docs/modules/ROOT/pages/reference/extensions/mapstruct.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
= MapStruct
:linkattrs:
:cq-artifact-id: camel-quarkus-mapstruct
:cq-native-supported: false
:cq-status: Preview
:cq-status-deprecation: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-status-deprecation: Stable
:cq-description: Type Conversion using Mapstruct
:cq-deprecated: false
:cq-jvm-since: 3.0.0
:cq-native-since: n/a
:cq-native-since: 3.0.0

ifeval::[{doc-show-badges} == true]
[.badges]
[.badge-key]##JVM since##[.badge-supported]##3.0.0## [.badge-key]##Native##[.badge-unsupported]##unsupported##
[.badge-key]##JVM since##[.badge-supported]##3.0.0## [.badge-key]##Native since##[.badge-supported]##3.0.0##
endif::[]

Type Conversion using Mapstruct
Expand All @@ -29,6 +29,10 @@ Please refer to the above link for usage and configuration details.
[id="extensions-mapstruct-maven-coordinates"]
== Maven coordinates

https://{link-quarkus-code-generator}/?extension-search=camel-quarkus-mapstruct[Create a new project with this extension on {link-quarkus-code-generator}, window="_blank"]

Or add the coordinates to your existing project:

[source,xml]
----
<dependency>
Expand All @@ -39,3 +43,57 @@ Please refer to the above link for usage and configuration details.
ifeval::[{doc-show-user-guide-link} == true]
Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
endif::[]

[id="extensions-mapstruct-usage"]
== Usage
[id="extensions-mapstruct-usage-annotation-processor"]
=== Annotation Processor

To use MapStruct, you must configure your build to use an annotation processor.

[id="extensions-mapstruct-usage-maven"]
==== Maven

[source,xml]
----
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>{mapstruct-version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
----

[id="extensions-mapstruct-usage-gradle"]
==== Gradle

[source,gradle]
----
dependencies {
annotationProcessor 'org.mapstruct:mapstruct-processor:{mapstruct-version}'
testAnnotationProcessor 'org.mapstruct:mapstruct-processor:{mapstruct-version}'
}
----

[id="extensions-mapstruct-usage-mapper-definition-discovery"]
=== Mapper definition discovery

By default, {project-name} will automatically discover the package paths of your `@Mapper` annotated interfaces or abstract classes and
pass them to the Camel MapStruct component.

If you want finer control over the specific packages that are scanned, then you can set a configuration property in `application.properties`.

[source,properties]
----
camel.component.mapstruct.mapper-package-name = com.first.package,org.second.package
----

This file was deleted.

1 change: 0 additions & 1 deletion extensions-jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
<module>jt400</module>
<module>ldif</module>
<module>lucene</module>
<module>mapstruct</module>
<module>mvel</module>
<module>printer</module>
<module>pulsar</module>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.mapstruct.deployment;

import java.util.Set;

import io.quarkus.builder.item.SimpleBuildItem;
import io.quarkus.runtime.RuntimeValue;
import org.apache.camel.quarkus.component.mapstruct.ConversionMethodInfo;

/**
* Holds info about generated TypeConverter ConversionMethod.
*/
public final class ConversionMethodInfoRuntimeValuesBuildItem extends SimpleBuildItem {
private final Set<RuntimeValue<ConversionMethodInfo>> conversionMethodInfoRuntimeValues;

public ConversionMethodInfoRuntimeValuesBuildItem(
Set<RuntimeValue<ConversionMethodInfo>> conversionMethodInfoRuntimeValues) {
this.conversionMethodInfoRuntimeValues = conversionMethodInfoRuntimeValues;
}

public Set<RuntimeValue<ConversionMethodInfo>> getConversionMethodInfoRuntimeValues() {
return conversionMethodInfoRuntimeValues;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.mapstruct.deployment;

import java.util.Set;

import io.quarkus.builder.item.SimpleBuildItem;

/**
* Holds the set of discovered MapStruct Mapper packages.
*/
public final class MapStructMapperPackagesBuildItem extends SimpleBuildItem {
private final Set<String> mapperPackages;

public MapStructMapperPackagesBuildItem(Set<String> mapperPackages) {
this.mapperPackages = mapperPackages;
}

public Set<String> getMapperPackages() {
return mapperPackages;
}
}
Loading

0 comments on commit b237553

Please sign in to comment.