Skip to content

Commit 3fe08f3

Browse files
authored
Merge pull request #51 from hazendaz/master
Upgraded to velocity 2.0
2 parents 73dbfd3 + 4e4d4e3 commit 3fe08f3

17 files changed

+96
-165
lines changed

pom.xml

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
<groupId>org.mybatis.scripting</groupId>
3030
<artifactId>mybatis-velocity</artifactId>
31-
<version>1.5-SNAPSHOT</version>
31+
<version>2.0-SNAPSHOT</version>
3232
<packaging>jar</packaging>
3333

3434
<name>MyBatis Velocity</name>
@@ -62,6 +62,17 @@
6262
<properties>
6363
<findbugs.onlyAnalyze>org.mybatis.scripting.velocity.*</findbugs.onlyAnalyze>
6464
<gcu.product>Velocity</gcu.product>
65+
66+
<!-- Maven set to java 7 to align with new velocity -->
67+
<maven.compiler.source>1.7</maven.compiler.source>
68+
<maven.compiler.target>1.7</maven.compiler.target>
69+
<maven.compiler.testTarget>1.7</maven.compiler.testTarget>
70+
<maven.compiler.testSource>1.7</maven.compiler.testSource>
71+
72+
<!-- Animal Sniffer Signature -->
73+
<signature.group>org.codehaus.mojo.signature</signature.group>
74+
<signature.artifact>java17</signature.artifact>
75+
<signature.version>1.0</signature.version>
6576
</properties>
6677

6778
<dependencies>
@@ -72,18 +83,13 @@
7283
</dependency>
7384
<dependency>
7485
<groupId>org.apache.velocity</groupId>
75-
<artifactId>velocity</artifactId>
76-
<version>1.7</version>
86+
<artifactId>velocity-engine-core</artifactId>
87+
<version>2.0</version>
7788
</dependency>
7889
<dependency>
79-
<groupId>commons-collections</groupId>
80-
<artifactId>commons-collections</artifactId>
81-
<version>3.2.2</version>
82-
</dependency>
83-
<dependency>
84-
<groupId>commons-lang</groupId>
85-
<artifactId>commons-lang</artifactId>
86-
<version>2.6</version>
90+
<groupId>org.apache.commons</groupId>
91+
<artifactId>commons-lang3</artifactId>
92+
<version>3.7</version>
8793
</dependency>
8894
<!-- TEST -->
8995
<dependency>
@@ -99,32 +105,20 @@
99105
<scope>test</scope>
100106
</dependency>
101107
<dependency>
102-
<groupId>log4j</groupId>
103-
<artifactId>log4j</artifactId>
104-
<version>1.2.17</version>
108+
<groupId>org.slf4j</groupId>
109+
<artifactId>slf4j-simple</artifactId>
110+
<version>1.7.25</version>
105111
<scope>test</scope>
106112
</dependency>
107113
</dependencies>
108114

109115
<build>
110116
<plugins>
111-
<plugin>
112-
<groupId>org.apache.maven.plugins</groupId>
113-
<artifactId>maven-surefire-plugin</artifactId>
114-
<configuration>
115-
<systemProperties>
116-
<property>
117-
<name>log4j.configuration</name>
118-
<value>file:src/test/resources/log4j.xml</value>
119-
</property>
120-
</systemProperties>
121-
</configuration>
122-
</plugin>
123117
<plugin>
124118
<groupId>org.apache.maven.plugins</groupId>
125119
<artifactId>maven-release-plugin</artifactId>
126120
<configuration>
127-
<arguments>-Prelease,bundle</arguments>
121+
<releaseProfiles>release,bundle</releaseProfiles>
128122
</configuration>
129123
</plugin>
130124
</plugins>

src/main/java/org/mybatis/scripting/velocity/FastLinkedList.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,9 +24,9 @@ public final class FastLinkedList<E extends Serializable> implements Serializabl
2424

2525
private static final long serialVersionUID = 1L;
2626

27-
private Node first = null;
27+
private Node first;
2828

29-
private Node last = null;
29+
private Node last;
3030

3131
public FastLinkedList() {
3232
this.last = this.first;

src/main/java/org/mybatis/scripting/velocity/InDirective.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,14 @@
2121
import java.util.Iterator;
2222

2323
import org.apache.velocity.context.InternalContextAdapter;
24-
import org.apache.velocity.exception.MethodInvocationException;
25-
import org.apache.velocity.exception.ParseErrorException;
26-
import org.apache.velocity.exception.ResourceNotFoundException;
2724
import org.apache.velocity.exception.TemplateInitException;
2825
import org.apache.velocity.exception.VelocityException;
2926
import org.apache.velocity.runtime.RuntimeServices;
3027
import org.apache.velocity.runtime.directive.StopCommand;
31-
import org.apache.velocity.runtime.parser.ParserTreeConstants;
3228
import org.apache.velocity.runtime.parser.node.ASTReference;
3329
import org.apache.velocity.runtime.parser.node.ASTStringLiteral;
3430
import org.apache.velocity.runtime.parser.node.Node;
31+
import org.apache.velocity.runtime.parser.node.ParserTreeConstants;
3532
import org.apache.velocity.util.introspection.Info;
3633

3734
/**
@@ -59,7 +56,7 @@ public String getName() {
5956
}
6057

6158
@Override
62-
public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException {
59+
public void init(RuntimeServices rs, InternalContextAdapter context, Node node) {
6360
super.init(rs, context, node);
6461
final int n = node.jjtGetNumChildren() - 1;
6562
for (int i = 1; i < n; i++) {
@@ -74,12 +71,8 @@ public void init(RuntimeServices rs, InternalContextAdapter context, Node node)
7471
}
7572
else if (child.getType() == ParserTreeConstants.JJTSTRINGLITERAL) {
7673
String value = (String) ((ASTStringLiteral) child).value(context);
77-
switch (i) {
78-
case 2:
79-
this.column = value;
80-
break;
81-
default:
82-
break;
74+
if (i == 2) {
75+
this.column = value;
8376
}
8477
}
8578
else {
@@ -90,8 +83,7 @@ else if (child.getType() == ParserTreeConstants.JJTSTRINGLITERAL) {
9083
}
9184

9285
@Override
93-
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException,
94-
ParseErrorException, MethodInvocationException {
86+
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException {
9587
Object listObject = node.jjtGetChild(0).value(context);
9688
if (listObject == null) {
9789
return false;

src/main/java/org/mybatis/scripting/velocity/ParameterMappingCollector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@
2424
public class ParameterMappingCollector {
2525

2626
private final ParameterMapping[] parameterMappingSources;
27-
private final List<ParameterMapping> parameterMappings = new ArrayList<ParameterMapping>();
27+
private final List<ParameterMapping> parameterMappings = new ArrayList<>();
2828
private final Map<String, Object> context;
2929
private final Configuration configuration;
3030

src/main/java/org/mybatis/scripting/velocity/ParameterMappingSourceParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,7 +56,7 @@ public String getSql() {
5656

5757
private static class ParameterMappingTokenHandler extends BaseBuilder implements TokenHandler {
5858

59-
private final List<ParameterMapping> parameterMappings = new ArrayList<ParameterMapping>();
59+
private final List<ParameterMapping> parameterMappings = new ArrayList<>();
6060
private final Class<?> parameterType;
6161

6262
public ParameterMappingTokenHandler(Configuration newConfiguration, Class<?> newParameterType) {

src/main/java/org/mybatis/scripting/velocity/RepeatDirective.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,19 +21,16 @@
2121
import java.util.Iterator;
2222
import org.apache.velocity.context.ChainedInternalContextAdapter;
2323
import org.apache.velocity.context.InternalContextAdapter;
24-
import org.apache.velocity.exception.MethodInvocationException;
25-
import org.apache.velocity.exception.ParseErrorException;
26-
import org.apache.velocity.exception.ResourceNotFoundException;
2724
import org.apache.velocity.exception.TemplateInitException;
2825
import org.apache.velocity.exception.VelocityException;
2926
import org.apache.velocity.runtime.RuntimeServices;
3027
import org.apache.velocity.runtime.directive.Directive;
3128
import org.apache.velocity.runtime.directive.Scope;
3229
import org.apache.velocity.runtime.directive.StopCommand;
33-
import org.apache.velocity.runtime.parser.ParserTreeConstants;
3430
import org.apache.velocity.runtime.parser.node.ASTReference;
3531
import org.apache.velocity.runtime.parser.node.ASTStringLiteral;
3632
import org.apache.velocity.runtime.parser.node.Node;
33+
import org.apache.velocity.runtime.parser.node.ParserTreeConstants;
3734
import org.apache.velocity.util.introspection.Info;
3835

3936
/**
@@ -56,7 +53,7 @@ public String getName() {
5653
}
5754

5855
@Override
59-
public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException {
56+
public void init(RuntimeServices rs, InternalContextAdapter context, Node node) {
6057
super.init(rs, context, node);
6158
final int n = node.jjtGetNumChildren() - 1;
6259
for (int i = 1; i < n; i++) {
@@ -91,7 +88,7 @@ public void init(RuntimeServices rs, InternalContextAdapter context, Node node)
9188

9289
@Override
9390
public boolean render(InternalContextAdapter context, Writer writer, Node node)
94-
throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
91+
throws IOException {
9592

9693
Object listObject = node.jjtGetChild(0).value(context);
9794

@@ -254,7 +251,7 @@ protected NullHolderContext(String key, InternalContextAdapter context) {
254251
}
255252

256253
@Override
257-
public Object get(String key) throws MethodInvocationException {
254+
public Object get(String key) {
258255
return (this.active && this.loopVariableKey.equals(key))
259256
? null
260257
: super.get(key);
@@ -270,12 +267,7 @@ public Object put(String key, Object value) {
270267
}
271268

272269
@Override
273-
public Object localPut(final String key, final Object value) {
274-
return put(key, value);
275-
}
276-
277-
@Override
278-
public Object remove(Object key) {
270+
public Object remove(String key) {
279271
if (this.loopVariableKey.equals(key)) {
280272
this.active = false;
281273
}

src/main/java/org/mybatis/scripting/velocity/SQLScriptSource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ public SQLScriptSource(Configuration newConfiguration, String script, Class<?> p
4545
@Override
4646
public BoundSql getBoundSql(Object parameterObject) {
4747

48-
final Map<String, Object> context = new HashMap<String, Object>();
48+
final Map<String, Object> context = new HashMap<>();
4949
final ParameterMappingCollector pmc = new ParameterMappingCollector(this.parameterMappingSources, context, this.configuration);
5050

5151
context.put(DATABASE_ID_KEY, this.configuration.getDatabaseId());

src/main/java/org/mybatis/scripting/velocity/SetDirective.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,9 +18,6 @@
1818
import java.io.IOException;
1919
import java.io.StringWriter;
2020
import org.apache.velocity.context.InternalContextAdapter;
21-
import org.apache.velocity.exception.MethodInvocationException;
22-
import org.apache.velocity.exception.ParseErrorException;
23-
import org.apache.velocity.exception.ResourceNotFoundException;
2421
import org.apache.velocity.runtime.parser.node.ASTBlock;
2522
import org.apache.velocity.runtime.parser.node.Node;
2623

@@ -32,7 +29,7 @@ public String getName() {
3229
}
3330

3431
@Override
35-
protected Params getParams(InternalContextAdapter context, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
32+
protected Params getParams(InternalContextAdapter context, Node node) throws IOException {
3633
final Params params = new Params();
3734
params.setPrefix("SET");
3835
params.setSuffixOverrides(",");

src/main/java/org/mybatis/scripting/velocity/TrimDirective.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,9 +20,6 @@
2020
import java.io.Writer;
2121
import java.util.Locale;
2222
import org.apache.velocity.context.InternalContextAdapter;
23-
import org.apache.velocity.exception.MethodInvocationException;
24-
import org.apache.velocity.exception.ParseErrorException;
25-
import org.apache.velocity.exception.ResourceNotFoundException;
2623
import org.apache.velocity.runtime.directive.Directive;
2724
import org.apache.velocity.runtime.parser.node.ASTBlock;
2825
import org.apache.velocity.runtime.parser.node.Node;
@@ -40,15 +37,15 @@ public final int getType() {
4037
}
4138

4239
@Override
43-
public final boolean render(InternalContextAdapter ica, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
40+
public final boolean render(InternalContextAdapter ica, Writer writer, Node node) throws IOException {
4441
Params p = getParams(ica, node);
4542
if (p == null) {
4643
return false;
4744
}
4845
return render(p, writer);
4946
}
5047

51-
public boolean render(final Params params, final Writer writer) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
48+
public boolean render(final Params params, final Writer writer) throws IOException {
5249
int leftIndex = 0;
5350
int rightIndex = params.maxBody;
5451
if (rightIndex == 0) {
@@ -93,9 +90,9 @@ protected static final class Params {
9390

9491
String suffix = "";
9592

96-
FastLinkedList<String> prefixOverrides = new FastLinkedList<String>();
93+
FastLinkedList<String> prefixOverrides = new FastLinkedList<>();
9794

98-
FastLinkedList<String> suffixOverrides = new FastLinkedList<String>();
95+
FastLinkedList<String> suffixOverrides = new FastLinkedList<>();
9996

10097
String body = "";
10198

@@ -153,7 +150,7 @@ public void setSuffix(String value) {
153150

154151
}
155152

156-
protected Params getParams(final InternalContextAdapter context, final Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
153+
protected Params getParams(final InternalContextAdapter context, final Node node) throws IOException {
157154
final Params params = new Params();
158155
final int nodes = node.jjtGetNumChildren();
159156
for (int i = 0; i < nodes; i++) {

0 commit comments

Comments
 (0)