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 22, 2020
1 parent a96274a commit a719887
Show file tree
Hide file tree
Showing 24 changed files with 683 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
34 changes: 30 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,29 @@ 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.

== Camel Quarkus limitations

Configuration property `contentCache` doesn't have any effect on endpoint in native mode.
The resources used in native mode have to be embed in the native executable (see following chapter),
therefore they can not be changed during runtime.


== 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 @@ -142,7 +142,6 @@
<module>thrift</module>
<module>twilio</module>
<module>univocity-parsers</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 @@ -182,6 +182,7 @@
<module>timer</module>
<module>twitter</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,80 @@
/*
* 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"))
.sorted()
.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 fir 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].
3 changes: 3 additions & 0 deletions extensions/velocity/runtime/src/main/doc/limitations.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Configuration property `contentCache` doesn't have any effect on endpoint in native mode.
The resources used in native mode have to be embed in the native executable (see following chapter),
therefore they can not be changed during runtime.
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 @@ -154,6 +154,7 @@
<module>tika</module>
<module>twitter</module>
<module>validator</module>
<module>velocity</module>
<module>vertx</module>
<module>vertx-websocket</module>
<module>weather</module>
Expand Down

0 comments on commit a719887

Please sign in to comment.