Skip to content

Commit 140dcce

Browse files
author
ustaudinger
committed
First working release version.
1 parent ef1b7d5 commit 140dcce

7 files changed

Lines changed: 88 additions & 54 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Installation
1313
------------
1414

1515
Download the distribution tar.gz and unzip it to a folder of your choice.
16-
Create an environment variable MODEL_HOME that points to your mcp root directory (the one with the mcp command in it).
16+
Create an environment variable MCP_HOME that points to your mcp root directory (the one with the mcp command in it).
1717

18-
Then add MODEL_HOME folder to your $PATH variable, so that you can invoke 'mcp'.
18+
Then add MCP_HOME folder to your $PATH variable, so that you can invoke 'mcp'.
1919

2020
mcp will look for templates in MODEL_HOME/templates.
2121

build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# order of tasks is important.
2+
mvn clean package dependency:copy-dependencies assembly:assembly

pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929
<artifactId>log4j-core</artifactId>
3030
<version>2.1</version>
3131
</dependency>
32-
32+
<dependency>
33+
<groupId>com.fasterxml.jackson.dataformat</groupId>
34+
<artifactId>jackson-dataformat-yaml</artifactId>
35+
<version>2.5.0</version>
36+
</dependency>
3337
</dependencies>
3438

3539
<build>

src/main/assembly/zip.xml

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,48 @@
1-
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
4-
<id>bin</id>
5-
<formats>
6-
<format>tar.gz</format>
7-
</formats>
8-
<fileSets>
9-
<fileSet>
10-
<directory>${project.basedir}</directory>
11-
<outputDirectory>/</outputDirectory>
12-
<includes>
13-
<include>README*</include>
14-
<include>LICENSE*</include>
15-
<include>NOTICE*</include>
16-
</includes>
17-
</fileSet>
18-
<fileSet>
19-
<directory>${project.build.directory}</directory>
20-
<outputDirectory>/</outputDirectory>
21-
<includes>
22-
<include>*.jar</include>
23-
</includes>
24-
</fileSet>
25-
<fileSet>
26-
<directory>${project.basedir}/src/cmd</directory>
27-
<outputDirectory>/</outputDirectory>
28-
<includes>
29-
<include>*</include>
30-
</includes>
31-
</fileSet>
32-
<fileSet>
33-
<directory>${project.basedir}/src/src/main/resources/templates</directory>
34-
<outputDirectory>/templates</outputDirectory>
35-
<includes>
36-
<include>*</include>
37-
</includes>
38-
</fileSet>
39-
</fileSets>
1+
<assembly
2+
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
5+
<id>bin</id>
6+
<formats>
7+
<format>tar.gz</format>
8+
</formats>
9+
<fileSets>
10+
<fileSet>
11+
<directory>${project.basedir}</directory>
12+
<outputDirectory>/</outputDirectory>
13+
<includes>
14+
<include>README*</include>
15+
<include>LICENSE*</include>
16+
<include>NOTICE*</include>
17+
</includes>
18+
</fileSet>
19+
<fileSet>
20+
<directory>${project.build.directory}</directory>
21+
<outputDirectory>/lib</outputDirectory>
22+
<includes>
23+
<include>*.jar</include>
24+
</includes>
25+
</fileSet>
26+
<fileSet>
27+
<directory>${project.basedir}/src/cmd</directory>
28+
<outputDirectory>/</outputDirectory>
29+
<includes>
30+
<include>*</include>
31+
</includes>
32+
</fileSet>
33+
<fileSet>
34+
<directory>${project.basedir}/src/main/resources/templates</directory>
35+
<outputDirectory>/templates</outputDirectory>
36+
<includes>
37+
<include>*</include>
38+
</includes>
39+
</fileSet>
40+
<fileSet>
41+
<directory>${project.basedir}/target/dependency</directory>
42+
<outputDirectory>/lib</outputDirectory>
43+
<includes>
44+
<include>*.jar</include>
45+
</includes>
46+
</fileSet>
47+
</fileSets>
4048
</assembly>

src/main/java/com/stormdealers/mcp/MCPMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class MCPMain {
1212

1313
public static void main(String[] args) throws Exception {
1414

15-
String modelHomeFolder = System.getProperty("MCP_HOME");
15+
String modelHomeFolder = System.getenv("MCP_HOME");
1616
if(modelHomeFolder==null){
1717
System.err.println("No MCP_HOME system declaration found. Set/Export MCP_HOME to point to your templates folder. ");
1818
System.exit(1);

src/main/java/com/stormdealers/mcp/VelocityRenderer.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.apache.velocity.Template;
1111
import org.apache.velocity.VelocityContext;
1212
import org.apache.velocity.app.VelocityEngine;
13+
import org.apache.velocity.runtime.RuntimeConstants;
14+
import org.apache.velocity.runtime.resource.loader.FileResourceLoader;
1315

1416
import com.stormdealers.mcp.model.EntityObject;
1517
import com.stormdealers.mcp.model.Generatable;
@@ -29,10 +31,11 @@ public class VelocityRenderer implements IProjectProcess {
2931
private final Logger log = LogManager.getLogger(VelocityRenderer.class);
3032

3133
private void createFolder(String folder) {
32-
log.info("Creating folder if it doesn't exist: " + folder);
3334
File f = new File(folder);
34-
if (!f.exists())
35+
if (!f.exists()){
36+
log.info("Creating folder " + folder);
3537
f.mkdirs();
38+
}
3639
}
3740

3841
public void processProjectObject(ProjectObject po) throws RenderException {
@@ -148,32 +151,34 @@ private void renderToFolder(EntityObject eo, String template, String folder, Str
148151

149152
VelocityEngine ve = new VelocityEngine();
150153
// Tried using classpath, but discarded it.
151-
// ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
152-
// ve.setProperty("classpath.resource.loader.class",
153-
// ClasspathResourceLoader.class.getName());
154+
ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
155+
ve.setProperty("file.resource.loader.class", FileResourceLoader.class.getName());
156+
// setting it empty, so we can use an absolute path
157+
ve.setProperty("file.resource.loader.path", "");
154158
ve.init();
155159
VelocityContext ctx = new VelocityContext();
156160
ctx.put("ENTITY", eo);
157161

158162
// now, let's expand the template path in case we are using one of our
159163
// default templates.
160164
if (template.startsWith("templates/")) {
161-
// ok, we assume it's one of our default templates in MODEL_HOME
162-
String modelHomeFolder = System.getProperty("MCP_HOME");
165+
// ok, we assume it's one of our default templates in MCP_HOME
166+
String modelHomeFolder = System.getenv("MCP_HOME");
163167
if (!modelHomeFolder.endsWith(File.separator))
164168
modelHomeFolder = modelHomeFolder + File.separator;
165169
template = modelHomeFolder + template;
166170
}
167-
171+
172+
168173
Template t = ve.getTemplate(template);
169174
StringWriter writer = new StringWriter();
170175
t.merge(ctx, writer);
171-
System.out.println(writer);
176+
// System.out.println(writer);
172177

178+
log.info("Writing file " + fullFileName);
173179
FileWriter fileWriter = new FileWriter(fullFileName);
174180
fileWriter.write(writer.toString());
175-
fileWriter.flush();
181+
fileWriter.flush();
176182
fileWriter.close();
177-
178183
}
179184
}

src/main/resources/log4j2.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Configuration:
2+
status: warn
3+
4+
Appenders:
5+
Console:
6+
name: Console
7+
target: SYSTEM_OUT
8+
PatternLayout:
9+
Pattern: "%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"
10+
11+
Loggers:
12+
Root:
13+
level: info
14+
AppenderRef:
15+
ref: Console

0 commit comments

Comments
 (0)