perfsonar-dev - [pS-dev] [GEANT/SA2/ps-java-services] r6231 - in trunk/perfsonar-base/messaging: . src/main/java/net/geant/perfsonar/templates src/test/java/net/geant/perfsonar/templates
Subject: perfsonar development work
List archive
[pS-dev] [GEANT/SA2/ps-java-services] r6231 - in trunk/perfsonar-base/messaging: . src/main/java/net/geant/perfsonar/templates src/test/java/net/geant/perfsonar/templates
Chronological Thread
- From:
- To:
- Subject: [pS-dev] [GEANT/SA2/ps-java-services] r6231 - in trunk/perfsonar-base/messaging: . src/main/java/net/geant/perfsonar/templates src/test/java/net/geant/perfsonar/templates
- Date: Wed, 20 Mar 2013 21:53:14 +0000 (GMT)
- Authentication-results: sfpop-ironport01.merit.edu; dkim=neutral (message not signed) header.i=none
Author: psnc.pietrzak
Date: 2013-03-20 21:53:14 +0000 (Wed, 20 Mar 2013)
New Revision: 6231
Added:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/templates/TemplateEngineTest.java
Modified:
trunk/perfsonar-base/messaging/pom.xml
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/templates/TemplateEngine.java
Log:
Bug fix for reading templates from remote jar files.
Modified: trunk/perfsonar-base/messaging/pom.xml
===================================================================
--- trunk/perfsonar-base/messaging/pom.xml 2013-03-20 21:51:22 UTC (rev
6230)
+++ trunk/perfsonar-base/messaging/pom.xml 2013-03-20 21:53:14 UTC (rev
6231)
@@ -71,18 +71,25 @@
<artifactId>jlibs-xmldog</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ <version>1.8.2</version>
+ </dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
</dependency>
-
<dependency>
- <groupId>org.codehaus.groovy</groupId>
- <artifactId>groovy-all</artifactId>
+ <groupId>net.geant.perfsonar.base</groupId>
+ <artifactId>messaging-test-data</artifactId>
+ <version>1.0.0</version>
+ <scope>test</scope>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
@@ -109,8 +116,7 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
-
<version>2.3.2</version><!--$NO-MVN-MAN-VER$-->
- <!-- Groovy Eclipse Compiler does not work
with 3.0 -->
+
<version>2.3.2</version><!--$NO-MVN-MAN-VER$--> <!-- Groovy Eclipse Compiler
does not work with 3.0 -->
<!-- This also means that one has to install
the Groovy-Eclipse configurator for m2Eclipse -->
<!-- See
http://groovy.codehaus.org/Groovy-Eclipse+compiler+plugin+for+Maven#Groovy-EclipsecompilerpluginforMaven-Groovy-Eclipseconfiguratorform2Eclipse
-->
<configuration>
@@ -138,5 +144,41 @@
</executions>
</plugin>
</plugins>
+ <pluginManagement>
+ <plugins>
+ <!--This plugin's configuration is used to
store Eclipse m2e settings only. It has no influence on the Maven build
itself.-->
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+
<artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+
<pluginExecution>
+
<pluginExecutionFilter>
+
<groupId>
+
org.apache.maven.plugins
+
</groupId>
+
<artifactId>
+
maven-compiler-plugin
+
</artifactId>
+
<versionRange>
+
[2.3.2,)
+
</versionRange>
+
<goals>
+
<goal>testCompile</goal>
+
<goal>compile</goal>
+
</goals>
+
</pluginExecutionFilter>
+
<action>
+
<ignore></ignore>
+
</action>
+
</pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
</build>
</project>
Modified:
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/templates/TemplateEngine.java
===================================================================
---
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/templates/TemplateEngine.java
2013-03-20 21:51:22 UTC (rev 6230)
+++
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/templates/TemplateEngine.java
2013-03-20 21:53:14 UTC (rev 6231)
@@ -1,14 +1,11 @@
package net.geant.perfsonar.templates;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Provides facade to the underlying template engine. This implementation
uses
@@ -18,8 +15,6 @@
*
*/
public class TemplateEngine {
- protected static Logger logger =
LoggerFactory.getLogger("TemplateEngine");
-
private final static VelocityEngine templateEngine = new
VelocityEngine();
private final static VelocityContext context = new VelocityContext();
@@ -31,23 +26,14 @@
private static InputStream getTemplate(Class<?> homeDir, String name)
throws IOException {
- String fullPath = getFullPath(homeDir, name);
- logger.debug("Trying to load template: {}", fullPath);
- final InputStream in =
homeDir.getClassLoader().getResourceAsStream(fullPath);
+ final InputStream in = homeDir.getResourceAsStream(name);
+
if (in == null)
throw new IOException("Template " + name + " cannot
be found.");
return in;
}
- private static String getFullPath(Class<?> homeDir, String name) {
- String result = homeDir.getPackage().getName();
- for (; result.indexOf(".") != -1; result = result.replace(".",
- File.separator))
- ;
- return result + File.separator + name;
- }
-
/**
* Writes to the stream provided by writer argument, the template
found in
* the directory where the given class is stored using the template
provided
Added:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/templates/TemplateEngineTest.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/templates/TemplateEngineTest.java
(rev 0)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/templates/TemplateEngineTest.java
2013-03-20 21:53:14 UTC (rev 6231)
@@ -0,0 +1,20 @@
+package net.geant.perfsonar.templates;
+
+import static org.junit.Assert.*;
+
+import java.io.StringWriter;
+import net.geant.perfsonar.messaging.data.Dummy;
+
+import org.junit.Test;
+
+public class TemplateEngineTest {
+
+ @Test
+ public void shouldProcessTemplateFromJar() throws Exception {
+ final StringWriter out = new StringWriter();
+ TemplateEngine.put("name", "John Doe");
+ TemplateEngine.evaluate(out, Dummy.class, "Hello.template");
+ assertEquals("Hello John Doe!", out.toString());
+ }
+
+}
- [pS-dev] [GEANT/SA2/ps-java-services] r6231 - in trunk/perfsonar-base/messaging: . src/main/java/net/geant/perfsonar/templates src/test/java/net/geant/perfsonar/templates, svn-noreply, 03/20/2013
Archive powered by MHonArc 2.6.16.