aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--java/Makefile8
-rw-r--r--java/pom.xml52
-rw-r--r--java/src/main/java/org/pablotron/luigi/Cache.java (renamed from java/pablotron/luigi/Cache.java)10
-rw-r--r--java/src/main/java/org/pablotron/luigi/Filter.java (renamed from java/pablotron/luigi/Filter.java)2
-rw-r--r--java/src/main/java/org/pablotron/luigi/FilterReference.java (renamed from java/pablotron/luigi/FilterReference.java)2
-rw-r--r--java/src/main/java/org/pablotron/luigi/LuigiError.java (renamed from java/pablotron/luigi/LuigiError.java)2
-rw-r--r--java/src/main/java/org/pablotron/luigi/Parser.java (renamed from java/pablotron/luigi/Parser.java)12
-rw-r--r--java/src/main/java/org/pablotron/luigi/Template.java (renamed from java/pablotron/luigi/Template.java)14
-rw-r--r--java/src/main/java/org/pablotron/luigi/Test.java (renamed from java/pablotron/luigi/Test.java)10
-rw-r--r--java/src/main/java/org/pablotron/luigi/actions/Action.java (renamed from java/pablotron/luigi/actions/Action.java)6
-rw-r--r--java/src/main/java/org/pablotron/luigi/actions/FilterAction.java (renamed from java/pablotron/luigi/actions/FilterAction.java)10
-rw-r--r--java/src/main/java/org/pablotron/luigi/actions/TextAction.java (renamed from java/pablotron/luigi/actions/TextAction.java)8
-rw-r--r--java/src/test/java/org/pablotron/luigi/tests/TemplateTest.java69
14 files changed, 166 insertions, 40 deletions
diff --git a/.gitignore b/.gitignore
index 675d0c0..a026d80 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ php/docs/
php/examples/*
ruby/*.gem
ruby/docs/
+java/target/
diff --git a/java/Makefile b/java/Makefile
index fee0c59..2643080 100644
--- a/java/Makefile
+++ b/java/Makefile
@@ -1,14 +1,14 @@
-SOURCES=$(shell find . -type f -name \*.java)
-OUT=luigi-template.jar
+SOURCES=$(shell find src/main/java -type f -name \*.java)
+OUT=$(shell pwd)/luigi-template.jar
all: $(SOURCES)
javac $(SOURCES)
$(OUT): all
- jar cf $(OUT) pablotron
+ cd src/main/java && jar cf $(OUT) org
jar: $(OUT)
clean:
- find . -type f -name \*.class -exec rm -f '{}' ';'
+ find src/main/java -type f -name \*.class -exec rm -f '{}' ';'
rm -f $(OUT)
diff --git a/java/pom.xml b/java/pom.xml
new file mode 100644
index 0000000..63e777d
--- /dev/null
+++ b/java/pom.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.pablotron.luigi</groupId>
+ <artifactId>luigi-template</artifactId>
+ <version>0.4.2</version>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
+
+ <junit.jupiter.version>5.3.0</junit.jupiter.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <version>${junit.jupiter.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ <version>${junit.jupiter.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <version>${junit.jupiter.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <!-- JUnit 5 requires Surefire version 2.22.0 or higher -->
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.22.0</version>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/java/pablotron/luigi/Cache.java b/java/src/main/java/org/pablotron/luigi/Cache.java
index b550b46..97fa0ab 100644
--- a/java/pablotron/luigi/Cache.java
+++ b/java/src/main/java/org/pablotron/luigi/Cache.java
@@ -1,11 +1,11 @@
-package pablotron.luigi;
+package org.pablotron.luigi;
import java.util.Map;
import java.util.HashMap;
-import pablotron.luigi.Filter;
-import pablotron.luigi.Template;
-import pablotron.luigi.LuigiError;
-import pablotron.luigi.actions.Action;
+import org.pablotron.luigi.Filter;
+import org.pablotron.luigi.Template;
+import org.pablotron.luigi.LuigiError;
+import org.pablotron.luigi.actions.Action;
public final class Cache {
private final Map<String, String> strings;
diff --git a/java/pablotron/luigi/Filter.java b/java/src/main/java/org/pablotron/luigi/Filter.java
index d89beab..b00491f 100644
--- a/java/pablotron/luigi/Filter.java
+++ b/java/src/main/java/org/pablotron/luigi/Filter.java
@@ -1,4 +1,4 @@
-package pablotron.luigi;
+package org.pablotron.luigi;
import java.util.Map;
import java.util.HashMap;
diff --git a/java/pablotron/luigi/FilterReference.java b/java/src/main/java/org/pablotron/luigi/FilterReference.java
index d0f9d3d..38c134b 100644
--- a/java/pablotron/luigi/FilterReference.java
+++ b/java/src/main/java/org/pablotron/luigi/FilterReference.java
@@ -1,4 +1,4 @@
-package pablotron.luigi;
+package org.pablotron.luigi;
public final class FilterReference {
public final String name;
diff --git a/java/pablotron/luigi/LuigiError.java b/java/src/main/java/org/pablotron/luigi/LuigiError.java
index 4ff4c01..edeb7c7 100644
--- a/java/pablotron/luigi/LuigiError.java
+++ b/java/src/main/java/org/pablotron/luigi/LuigiError.java
@@ -1,4 +1,4 @@
-package pablotron.luigi;
+package org.pablotron.luigi;
public class LuigiError extends Exception {
public LuigiError(final String message) {
diff --git a/java/pablotron/luigi/Parser.java b/java/src/main/java/org/pablotron/luigi/Parser.java
index 0e415c4..5be4a9c 100644
--- a/java/pablotron/luigi/Parser.java
+++ b/java/src/main/java/org/pablotron/luigi/Parser.java
@@ -1,14 +1,14 @@
-package pablotron.luigi;
+package org.pablotron.luigi;
import java.util.ArrayList;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
-import pablotron.luigi.actions.Action;
-import pablotron.luigi.actions.FilterAction;
-import pablotron.luigi.actions.TextAction;
-import pablotron.luigi.FilterReference;
-import pablotron.luigi.LuigiError;
+import org.pablotron.luigi.actions.Action;
+import org.pablotron.luigi.actions.FilterAction;
+import org.pablotron.luigi.actions.TextAction;
+import org.pablotron.luigi.FilterReference;
+import org.pablotron.luigi.LuigiError;
public final class Parser {
private static final Pattern RE_ACTION = Pattern.compile(
diff --git a/java/pablotron/luigi/Template.java b/java/src/main/java/org/pablotron/luigi/Template.java
index 8ab1d77..2b17a54 100644
--- a/java/pablotron/luigi/Template.java
+++ b/java/src/main/java/org/pablotron/luigi/Template.java
@@ -1,10 +1,10 @@
-package pablotron.luigi;
+package org.pablotron.luigi;
import java.util.Map;
-import pablotron.luigi.Parser;
-import pablotron.luigi.Filter;
-import pablotron.luigi.LuigiError;
-import pablotron.luigi.actions.Action;
+import org.pablotron.luigi.Parser;
+import org.pablotron.luigi.Filter;
+import org.pablotron.luigi.LuigiError;
+import org.pablotron.luigi.actions.Action;
public final class Template {
private static final String VERSION = "0.4.0";
@@ -34,4 +34,8 @@ public final class Template {
return r.toString();
}
+
+ public String toString() {
+ return this.template;
+ }
};
diff --git a/java/pablotron/luigi/Test.java b/java/src/main/java/org/pablotron/luigi/Test.java
index 7163c52..2a560e2 100644
--- a/java/pablotron/luigi/Test.java
+++ b/java/src/main/java/org/pablotron/luigi/Test.java
@@ -1,12 +1,12 @@
-package pablotron.luigi;
+package org.pablotron.luigi;
import java.util.Map;
import java.util.HashMap;
-import pablotron.luigi.LuigiError;
-import pablotron.luigi.Filter;
-import pablotron.luigi.Template;
-import pablotron.luigi.Cache;
+import org.pablotron.luigi.LuigiError;
+import org.pablotron.luigi.Filter;
+import org.pablotron.luigi.Template;
+import org.pablotron.luigi.Cache;
public final class Test {
// test template
diff --git a/java/pablotron/luigi/actions/Action.java b/java/src/main/java/org/pablotron/luigi/actions/Action.java
index 010622a..9708199 100644
--- a/java/pablotron/luigi/actions/Action.java
+++ b/java/src/main/java/org/pablotron/luigi/actions/Action.java
@@ -1,8 +1,8 @@
-package pablotron.luigi.actions;
+package org.pablotron.luigi.actions;
import java.util.Map;
-import pablotron.luigi.Filter;
-import pablotron.luigi.LuigiError;
+import org.pablotron.luigi.Filter;
+import org.pablotron.luigi.LuigiError;
public interface Action {
public String run(
diff --git a/java/pablotron/luigi/actions/FilterAction.java b/java/src/main/java/org/pablotron/luigi/actions/FilterAction.java
index b69923b..9115a68 100644
--- a/java/pablotron/luigi/actions/FilterAction.java
+++ b/java/src/main/java/org/pablotron/luigi/actions/FilterAction.java
@@ -1,10 +1,10 @@
-package pablotron.luigi.actions;
+package org.pablotron.luigi.actions;
import java.util.Map;
-import pablotron.luigi.actions.Action;
-import pablotron.luigi.FilterReference;
-import pablotron.luigi.Filter;
-import pablotron.luigi.LuigiError;
+import org.pablotron.luigi.actions.Action;
+import org.pablotron.luigi.FilterReference;
+import org.pablotron.luigi.Filter;
+import org.pablotron.luigi.LuigiError;
public final class FilterAction implements Action {
private final String key;
diff --git a/java/pablotron/luigi/actions/TextAction.java b/java/src/main/java/org/pablotron/luigi/actions/TextAction.java
index 3024f23..0ad4382 100644
--- a/java/pablotron/luigi/actions/TextAction.java
+++ b/java/src/main/java/org/pablotron/luigi/actions/TextAction.java
@@ -1,9 +1,9 @@
-package pablotron.luigi.actions;
+package org.pablotron.luigi.actions;
import java.util.Map;
-import pablotron.luigi.actions.Action;
-import pablotron.luigi.Filter;
-import pablotron.luigi.LuigiError;
+import org.pablotron.luigi.actions.Action;
+import org.pablotron.luigi.Filter;
+import org.pablotron.luigi.LuigiError;
public final class TextAction implements Action {
private final String text;
diff --git a/java/src/test/java/org/pablotron/luigi/tests/TemplateTest.java b/java/src/test/java/org/pablotron/luigi/tests/TemplateTest.java
new file mode 100644
index 0000000..5ff9ede
--- /dev/null
+++ b/java/src/test/java/org/pablotron/luigi/tests/TemplateTest.java
@@ -0,0 +1,69 @@
+import java.util.Map;
+import java.util.HashMap;
+
+import org.pablotron.luigi.LuigiError;
+import org.pablotron.luigi.Template;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.junit.jupiter.api.Test;
+
+
+public final class TemplateTest {
+ private static final Map<String, String> TEST_ARGS = new HashMap<String, String>() {{
+ put("bar", "foo");
+ }};
+
+ private static final Map<String, String> TEST_MULTIPLE_ARGS = new HashMap<String, String>() {{
+ put("bar", "foo");
+ put("baz", "bar");
+ }};
+
+ @Test
+ public void testNew() throws LuigiError {
+ final Template t = new Template("");
+
+ assertNotNull(t);
+ }
+
+ @Test
+ public void testRun() throws LuigiError {
+ final Template t = new Template("foo%{bar}");
+ final String r = t.run(TEST_ARGS);
+
+ assertEquals("foofoo", r);
+ }
+
+ @Test
+ public void testMultipleKeys() throws LuigiError {
+ final Template t = new Template("foo%{bar}%{baz}");
+ final String r = t.run(TEST_MULTIPLE_ARGS);
+
+ assertEquals("foofoobar", r);
+ }
+
+ @Test
+ public void testWhitespace() throws LuigiError {
+ final Template t = new Template("%{ bar}%{ bar }%{bar }");
+ final String r = t.run(TEST_ARGS);
+
+ assertEquals("foofoofoo", r);
+ }
+
+ @Test
+ public void testNewlines() throws LuigiError {
+ final Template t = new Template("%{\nbar}%{\n bar\n }%{bar\n}");
+ final String r = t.run(TEST_ARGS);
+
+ assertEquals("foofoofoo", r);
+ }
+
+ @Test
+ public void testToString() throws LuigiError {
+ final Template t = new Template("foo%{bar}");
+ final String r = t.toString();
+
+ assertEquals("foo%{bar}", r);
+ }
+};