Skip to content

Commit

Permalink
First working release version.
Browse files Browse the repository at this point in the history
  • Loading branch information
ustaudinger committed Apr 18, 2015
1 parent ef1b7d5 commit 140dcce
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 54 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Installation
------------

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

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

mcp will look for templates in MODEL_HOME/templates.

Expand Down
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# order of tasks is important.
mvn clean package dependency:copy-dependencies assembly:assembly
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
<artifactId>log4j-core</artifactId>
<version>2.1</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.5.0</version>
</dependency>
</dependencies>

<build>
Expand Down
86 changes: 47 additions & 39 deletions src/main/assembly/zip.xml
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>bin</id>
<formats>
<format>tar.gz</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/cmd</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/src/main/resources/templates</directory>
<outputDirectory>/templates</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
</fileSets>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>bin</id>
<formats>
<format>tar.gz</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/cmd</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/main/resources/templates</directory>
<outputDirectory>/templates</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/target/dependency</directory>
<outputDirectory>/lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
2 changes: 1 addition & 1 deletion src/main/java/com/stormdealers/mcp/MCPMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class MCPMain {

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

String modelHomeFolder = System.getProperty("MCP_HOME");
String modelHomeFolder = System.getenv("MCP_HOME");
if(modelHomeFolder==null){
System.err.println("No MCP_HOME system declaration found. Set/Export MCP_HOME to point to your templates folder. ");
System.exit(1);
Expand Down
27 changes: 16 additions & 11 deletions src/main/java/com/stormdealers/mcp/VelocityRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.FileResourceLoader;

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

private void createFolder(String folder) {
log.info("Creating folder if it doesn't exist: " + folder);
File f = new File(folder);
if (!f.exists())
if (!f.exists()){
log.info("Creating folder " + folder);
f.mkdirs();
}
}

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

VelocityEngine ve = new VelocityEngine();
// Tried using classpath, but discarded it.
// ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
// ve.setProperty("classpath.resource.loader.class",
// ClasspathResourceLoader.class.getName());
ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
ve.setProperty("file.resource.loader.class", FileResourceLoader.class.getName());
// setting it empty, so we can use an absolute path
ve.setProperty("file.resource.loader.path", "");
ve.init();
VelocityContext ctx = new VelocityContext();
ctx.put("ENTITY", eo);

// now, let's expand the template path in case we are using one of our
// default templates.
if (template.startsWith("templates/")) {
// ok, we assume it's one of our default templates in MODEL_HOME
String modelHomeFolder = System.getProperty("MCP_HOME");
// ok, we assume it's one of our default templates in MCP_HOME
String modelHomeFolder = System.getenv("MCP_HOME");
if (!modelHomeFolder.endsWith(File.separator))
modelHomeFolder = modelHomeFolder + File.separator;
template = modelHomeFolder + template;
}



Template t = ve.getTemplate(template);
StringWriter writer = new StringWriter();
t.merge(ctx, writer);
System.out.println(writer);
// System.out.println(writer);

log.info("Writing file " + fullFileName);
FileWriter fileWriter = new FileWriter(fullFileName);
fileWriter.write(writer.toString());
fileWriter.flush();
fileWriter.flush();
fileWriter.close();

}
}
15 changes: 15 additions & 0 deletions src/main/resources/log4j2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Configuration:
status: warn

Appenders:
Console:
name: Console
target: SYSTEM_OUT
PatternLayout:
Pattern: "%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"

Loggers:
Root:
level: info
AppenderRef:
ref: Console

0 comments on commit 140dcce

Please sign in to comment.