Skip to content

Commit

Permalink
CAMEL-11819:camel-velocity - Upgrade to 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
kkakarla authored and davsclaus committed Sep 28, 2017
1 parent 20de42c commit 952f08b
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<artifactId>velocity-engine-core</artifactId>
<version>${velocity-version}</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
import org.apache.camel.util.IntrospectionSupport;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.jsse.SSLContextParameters;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.log4j.Logger;
import org.apache.maven.plugin.AbstractMojo;
Expand All @@ -80,7 +80,6 @@
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.log.Log4JLogChute;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
import org.eclipse.jetty.client.HttpProxy;
import org.eclipse.jetty.client.Origin;
Expand All @@ -90,6 +89,7 @@
import org.eclipse.jetty.client.util.BasicAuthentication;
import org.eclipse.jetty.client.util.DigestAuthentication;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.slf4j.LoggerFactory;

/**
* Goal to generate DTOs for Salesforce SObjects
Expand Down Expand Up @@ -496,9 +496,7 @@ static VelocityEngine createVelocityEngine() {
final Properties velocityProperties = new Properties();
velocityProperties.setProperty(RuntimeConstants.RESOURCE_LOADER, "cloader");
velocityProperties.setProperty("cloader.resource.loader.class", ClasspathResourceLoader.class.getName());
velocityProperties.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, Log4JLogChute.class.getName());
velocityProperties.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM + ".log4j.logger", LOG.getName());

velocityProperties.setProperty(RuntimeConstants.RUNTIME_LOG_NAME, LOG.getName());
final VelocityEngine engine = new VelocityEngine(velocityProperties);

return engine;
Expand Down
2 changes: 1 addition & 1 deletion components/camel-velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<artifactId>velocity-engine-core</artifactId>
<version>${velocity-version}</version>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
package org.apache.camel.component.velocity;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

import org.apache.camel.spi.ClassResolver;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
import org.apache.velocity.util.ExtProperties;

/**
* Camel specific {@link ClasspathResourceLoader} that loads resources using the
Expand All @@ -33,20 +35,20 @@ public class CamelVelocityClasspathResourceLoader extends ClasspathResourceLoade
private ClassResolver resolver;

@Override
public void init(ExtendedProperties configuration) {
public void init(ExtProperties configuration) {
super.init(configuration);
resolver = (ClassResolver) this.rsvc.getProperty("CamelClassResolver");
ObjectHelper.notNull(resolver, "ClassResolver");
}

@Override
public InputStream getResourceStream(String name) throws ResourceNotFoundException {
public Reader getResourceReader(String name, String encoding) throws ResourceNotFoundException {
InputStream is = resolver.loadResourceAsStream(name);
if (is == null) {
return super.getResourceStream(name);
return super.getResourceReader(name, encoding);
} else {
return is;
return new InputStreamReader(is);
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.context.Context;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.log.CommonsLogLogChute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
* Transforms the message using a Velocity template.
Expand Down Expand Up @@ -90,8 +92,10 @@ private synchronized VelocityEngine getVelocityEngine() throws Exception {
properties.setProperty(RuntimeConstants.RESOURCE_LOADER, "file, class");
properties.setProperty("class.resource.loader.description", "Camel Velocity Classpath Resource Loader");
properties.setProperty("class.resource.loader.class", CamelVelocityClasspathResourceLoader.class.getName());
properties.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, CommonsLogLogChute.class.getName());
properties.setProperty(CommonsLogLogChute.LOGCHUTE_COMMONS_LOG_NAME, VelocityEndpoint.class.getName());
final Logger velocityLogger = LoggerFactory.getLogger("org.apache.camel.maven.Velocity");
properties.setProperty(RuntimeConstants.RUNTIME_LOG_NAME, velocityLogger.getName());



// load the velocity properties from property file which may overrides the default ones
if (ObjectHelper.isNotEmpty(getPropertiesFile())) {
Expand Down
2 changes: 1 addition & 1 deletion examples/camel-example-reportincident-wssecurity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@

<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<artifactId>velocity-engine-core</artifactId>
<version>${velocity-version}</version>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@
<validation-api-version>1.1.0.Final</validation-api-version>
<velocity-bundle-version>1.7_6</velocity-bundle-version>
<velocity-tools-version>2.0</velocity-tools-version>
<velocity-version>1.7</velocity-version>
<velocity-version>2.0</velocity-version>
<vertx-version>3.4.2</vertx-version>
<vysper-version>0.7</vysper-version>
<weld1-version>1.1.28.Final</weld1-version>
Expand Down
10 changes: 8 additions & 2 deletions tooling/maven/camel-api-component-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-site-renderer</artifactId>
<version>1.6</version>
<exclusions>
<exclusion>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand All @@ -116,7 +122,7 @@
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<artifactId>velocity-engine-core</artifactId>
<version>${velocity-version}</version>
</dependency>

Expand Down Expand Up @@ -157,7 +163,7 @@
<!-- VelocityEngine javadoc for testing -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<artifactId>velocity-engine-core</artifactId>
<version>${velocity-version}</version>
<classifier>javadoc</classifier>
<scope>test</scope>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<artifactId>velocity-engine-core</artifactId>
<version>@velocity-version@</version>
</dependency>
<!-- VelocityEngine javadoc for generating API classes -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<artifactId>velocity-engine-core</artifactId>
<version>@velocity-version@</version>
<classifier>javadoc</classifier>
<scope>provided</scope>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.log.Log4JLogChute;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -88,17 +87,21 @@ protected static void clearSharedProjectState() {
}
}

protected static VelocityEngine getEngine() {
protected static VelocityEngine getEngine() throws MojoExecutionException {
if (engine == null) {
// initialize velocity to load resources from class loader and use Log4J
Properties velocityProperties = new Properties();
velocityProperties.setProperty(RuntimeConstants.RESOURCE_LOADER, "cloader");
velocityProperties.setProperty("cloader.resource.loader.class", ClasspathResourceLoader.class.getName());
velocityProperties.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, Log4JLogChute.class.getName());
final Logger velocityLogger = LoggerFactory.getLogger("org.apache.camel.maven.Velocity");
velocityProperties.setProperty(Log4JLogChute.RUNTIME_LOG_LOG4J_LOGGER, velocityLogger.getName());
engine = new VelocityEngine(velocityProperties);
engine.init();
velocityProperties.setProperty(RuntimeConstants.RUNTIME_LOG_NAME, velocityLogger.getName());
try {
engine = new VelocityEngine(velocityProperties);
engine.init();
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
}

}
return engine;
}
Expand Down Expand Up @@ -141,7 +144,12 @@ protected void mergeTemplate(VelocityContext context, File outFile, String templ
context.put("newLine", "\n");

// load velocity template
final Template template = getEngine().getTemplate(templateName, "UTF-8");
Template template = null;
try {
template = getEngine().getTemplate(templateName, "UTF-8");
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
}

// generate file
BufferedWriter writer = null;
Expand Down

0 comments on commit 952f08b

Please sign in to comment.