Skip to content

Commit

Permalink
Velocity Support apache#837
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriOndrusek committed Sep 24, 2020
1 parent 382c8c8 commit 9dc9471
Show file tree
Hide file tree
Showing 23 changed files with 747 additions and 136 deletions.
6 changes: 3 additions & 3 deletions docs/modules/ROOT/pages/reference/components/velocity.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
= Velocity
:cq-artifact-id: camel-quarkus-velocity
:cq-artifact-id-base: velocity
:cq-native-supported: false
:cq-status: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-deprecated: false
:cq-jvm-since: 1.1.0
:cq-native-since: n/a
:cq-native-since: 1.2.0
:cq-camel-part-name: velocity
:cq-camel-part-title: Velocity
:cq-camel-part-description: Transform messages using a Velocity template.
Expand Down
27 changes: 23 additions & 4 deletions docs/modules/ROOT/pages/reference/extensions/velocity.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

= Velocity
:cq-artifact-id: camel-quarkus-velocity
:cq-native-supported: false
:cq-status: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-description: Transform messages using a Velocity template.
:cq-deprecated: false
:cq-jvm-since: 1.1.0
:cq-native-since: n/a
:cq-native-since: 1.2.0

[.badges]
[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native##[.badge-unsupported]##unsupported##
[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native since##[.badge-supported]##1.2.0##

Transform messages using a Velocity template.

Expand All @@ -32,3 +32,22 @@ Please refer to the above link for usage and configuration details.
----

Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.

== Additional Camel Quarkus configuration

Beyond standard usages described above, a trick is needed when using velocity templates from classpath resources in native mode. In such a situation, one needs to explicitly embed the resources in the native executable by specifying the `include-patterns` option.

For instance, the route below would load the velocity template from a classpath resource named _template/simple.vm_:
[source,java]
----
from("direct:start").to("velocity://template/simple.vm");
----

In order to work in native mode the `include-patterns` configuration should be set. For instance, in the `application.properties` file as below :
[source,properties]
----
quarkus.camel.native.resources.include-patterns = template/*.vm
----

More information about selecting resources for inclusion in the native executable could be found at xref:user-guide/native-mode.adoc#embedding-resource-in-native-executable[Embedding resource in native executable].

1 change: 0 additions & 1 deletion extensions-jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
<module>syslog</module>
<module>thrift</module>
<module>twilio</module>
<module>velocity</module>
<module>web3j</module>
<module>weka</module>
<module>wordpress</module>
Expand Down

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
<module>twitter</module>
<module>univocity-parsers</module>
<module>validator</module>
<module>velocity</module>
<module>vertx</module>
<module>vertx-http</module>
<module>vertx-websocket</module>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.velocity.deployment;

import java.util.ArrayList;
import java.util.TreeMap;

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.ReflectiveClassBuildItem;
import org.apache.camel.component.velocity.CamelVelocityClasspathResourceLoader;
import org.apache.camel.support.DefaultExchange;
import org.apache.camel.support.MessageSupport;
import org.jboss.jandex.IndexView;

import static java.util.stream.Collectors.toCollection;

class VelocityProcessor {

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

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

@BuildStep
NativeImageResourceBuildItem initResources() {
return new NativeImageResourceBuildItem(
"org/apache/velocity/runtime/defaults/velocity.properties",
"org/apache/velocity/runtime/defaults/directive.properties");
}

@BuildStep
ReflectiveClassBuildItem registerForReflection(CombinedIndexBuildItem combinedIndex) {
IndexView index = combinedIndex.getIndex();

ArrayList<String> dtos = index.getKnownClasses().stream().map(ci -> ci.name().toString())
.filter(n -> n.startsWith("org.apache.velocity.runtime") ||
n.startsWith("org.apache.velocity.util.introspection"))
.collect(toCollection(ArrayList::new));

dtos.add(CamelVelocityClasspathResourceLoader.class.getName());

return new ReflectiveClassBuildItem(false, false, dtos.toArray(new String[dtos.size()]));
}

@BuildStep
ReflectiveClassBuildItem registerForReflectionWithMethods() {
return new ReflectiveClassBuildItem(true, false,
TreeMap.class.getName(),
//required for supplemental context
MessageSupport.class.getName(),
//required for values in properties
DefaultExchange.class.getName());
}

@BuildStep
IndexDependencyBuildItem registerDependencyForIndex() {
return new IndexDependencyBuildItem("org.apache.velocity", "velocity-engine-core");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@
<modules>
<module>deployment</module>
<module>runtime</module>
<module>integration-test</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

<properties>
<camel.quarkus.jvmSince>1.1.0</camel.quarkus.jvmSince>
<camel.quarkus.nativeSince>1.2.0</camel.quarkus.nativeSince>
</properties>

<dependencyManagement>
Expand Down
15 changes: 15 additions & 0 deletions extensions/velocity/runtime/src/main/doc/configuration.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Beyond standard usages described above, a trick is needed when using velocity templates from classpath resources in native mode. In such a situation, one needs to explicitly embed the resources in the native executable by specifying the `include-patterns` option.

For instance, the route below would load the velocity template from a classpath resource named _template/simple.vm_:
[source,java]
----
from("direct:start").to("velocity://template/simple.vm");
----

In order to work in native mode the `include-patterns` configuration should be set. For instance, in the `application.properties` file as below :
[source,properties]
----
quarkus.camel.native.resources.include-patterns = template/*.vm
----
More information about selecting resources for inclusion in the native executable could be found at xref:user-guide/native-mode.adoc#embedding-resource-in-native-executable[Embedding resource in native executable].
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
name: "Camel Velocity"
description: "Transform messages using a Velocity template"
metadata:
unlisted: true
guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/velocity.html"
categories:
- "integration"
status:
- "preview"
- "stable"
1 change: 1 addition & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
<module>twitter</module>
<module>univocity-parsers</module>
<module>validator</module>
<module>velocity</module>
<module>vertx</module>
<module>vertx-websocket</module>
<module>weather</module>
Expand Down

0 comments on commit 9dc9471

Please sign in to comment.