Skip to content

Commit b82fb57

Browse files
committed
U fix line separator problem generating assets with velocity
1 parent b087683 commit b82fb57

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

pom.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>io.github.fvarrui</groupId>
55
<artifactId>javapackager</artifactId>
6-
<version>0.9.3-SNAPSHOT</version>
6+
<version>0.9.2-SNAPSHOT</version>
77
<packaging>maven-plugin</packaging>
88

99
<name>JavaPackager Maven Plugin</name>
@@ -14,8 +14,6 @@
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
<maven.compiler.source>1.8</maven.compiler.source>
1616
<maven.compiler.target>1.8</maven.compiler.target>
17-
<line.separator>
18-
</line.separator>
1917
</properties>
2018

2119
<licenses>

src/main/java/io/github/fvarrui/javapackager/utils/VelocityUtils.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package io.github.fvarrui.javapackager.utils;
22

3+
import static org.apache.commons.io.FileUtils.writeStringToFile;
4+
35
import java.io.File;
4-
import java.io.FileWriter;
56
import java.io.IOException;
67
import java.util.Map;
78

@@ -12,6 +13,7 @@
1213
import org.apache.velocity.runtime.RuntimeConstants;
1314
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
1415
import org.apache.velocity.runtime.resource.loader.FileResourceLoader;
16+
import org.apache.velocity.util.StringBuilderWriter;
1517

1618
public class VelocityUtils {
1719

@@ -35,22 +37,21 @@ public class VelocityUtils {
3537

3638
public static void render(String templatePath, File output, Map<String, Object> info) throws MojoExecutionException {
3739
try {
38-
39-
VelocityContext context = new VelocityContext();
40-
context.put("info", info);
41-
42-
Template template = velocityEngine.getTemplate(templatePath, "UTF-8");
43-
44-
FileWriter fw = new FileWriter(output);
45-
46-
template.merge(context, fw);
47-
48-
fw.flush();
49-
fw.close();
50-
40+
String data = render(templatePath, info);
41+
data = data.replaceAll("\\r\\n", "\n").replaceAll("\\r", "\n");
42+
writeStringToFile(output, data, "UTF-8");
5143
} catch (IOException e) {
5244
throw new MojoExecutionException(e.getMessage(), e);
5345
}
5446
}
47+
48+
public static String render(String templatePath, Map<String, Object> info) throws MojoExecutionException {
49+
VelocityContext context = new VelocityContext();
50+
context.put("info", info);
51+
Template template = velocityEngine.getTemplate(templatePath, "UTF-8");
52+
StringBuilderWriter writer = new StringBuilderWriter();
53+
template.merge(context, writer);
54+
return writer.toString();
55+
}
5556

5657
}

0 commit comments

Comments
 (0)