From 27635113ff92008fadbd6e8dcdac1031a1eefc72 Mon Sep 17 00:00:00 2001 From: Andrew Pigram Date: Tue, 17 Sep 2013 15:38:35 +1000 Subject: [PATCH] Made entity classes serializable to allow caching. Added template_root argument that will set Mustache's file root. All filenames will, therefore, be relative paths. Updated test case to reflect argument changes and test caching in the full run. --- src/net/foxopen/jira/changelog/Change.java | 4 ++- src/net/foxopen/jira/changelog/Changelog.java | 9 ++++-- .../jira/changelog/ChangelogBuilder.java | 3 +- .../jira/changelog/ChangelogTemplate.java | 4 ++- src/net/foxopen/jira/changelog/Type.java | 5 ++-- .../jira/changelog/ChangelogTemplateTest.java | 30 +++++++++++-------- 6 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/net/foxopen/jira/changelog/Change.java b/src/net/foxopen/jira/changelog/Change.java index f691be4..02a8026 100644 --- a/src/net/foxopen/jira/changelog/Change.java +++ b/src/net/foxopen/jira/changelog/Change.java @@ -1,6 +1,7 @@ package net.foxopen.jira.changelog; import java.util.Comparator; +import java.io.Serializable; /** * Represents a JIRA issue for display in the changelog. @@ -8,8 +9,9 @@ * @author apigram * @version 1.03.00 */ -public class Change { +public class Change implements Serializable { + private static final long serialVersionUID = 4315403361667148998L; private String issueKey; private String issueType; private String description; diff --git a/src/net/foxopen/jira/changelog/Changelog.java b/src/net/foxopen/jira/changelog/Changelog.java index 74ba6da..9d65894 100644 --- a/src/net/foxopen/jira/changelog/Changelog.java +++ b/src/net/foxopen/jira/changelog/Changelog.java @@ -20,7 +20,8 @@ public static void showUsage() { System.out.println(": The password used to log into JIRA."); System.out.println(": The name of the project in JIRA."); System.out.println(": The name of the version this changelog is for."); - System.out.println(": A CSV list of paths to template files. Each templated changelog is saved into a new file which can be processed at a later stage."); + System.out.println(": The path on disk to the directory that contains the template files."); + System.out.println(": A CSV list of template file names. Each templated changelog is saved into a new file which can be processed at a later stage."); System.out.println(" (optional): One or more of the following flags:"); // TODO: If this JQL causes no issues to be returned, it causes a hard // error. Handle this more nicely. @@ -53,6 +54,7 @@ public static void main(String[] args) { final String jiraPassword = args[currentArgument++]; final String jiraProjectKey = args[currentArgument++]; final String versionName = args[currentArgument++]; + final String templateRoot = args[currentArgument++]; final String templateList = args[currentArgument++]; String[] templates = templateList.split(","); @@ -81,6 +83,7 @@ public static void main(String[] args) { Logger.log("--object-cache-path flag found. Using " + objectCachePath + " as the object cache."); } else if (args[currentArgument].equals("--changelog-file-name")) { filenameList = args[++currentArgument]; + filenameList = filenameList.replace("\"", ""); files = filenameList.split(","); if (files.length != templates.length) { Logger.err("Output file list does not match template file list."); @@ -118,7 +121,7 @@ public static void main(String[] args) { File f; for (int i = 0; i < templates.length; i++) { - f = new File(templates[i]); + f = new File(templateRoot + '/' + templates[i]); if (!f.exists()) { Logger.err("Template file " + f.getName() + " does not exist!"); System.exit(2); @@ -143,7 +146,7 @@ public static void main(String[] args) { files[i] = "changelog" + i + ".txt"; } } - clWriter.build(jiraApi.getVersionInfoList(), files, templates, ending); + clWriter.build(jiraApi.getVersionInfoList(), files, templateRoot, templates, ending); Logger.log("Done - Success!"); } diff --git a/src/net/foxopen/jira/changelog/ChangelogBuilder.java b/src/net/foxopen/jira/changelog/ChangelogBuilder.java index f816040..5c7a48d 100644 --- a/src/net/foxopen/jira/changelog/ChangelogBuilder.java +++ b/src/net/foxopen/jira/changelog/ChangelogBuilder.java @@ -27,9 +27,10 @@ public class ChangelogBuilder { * @param ending A value indicating the kind of newlines to be used in the * changelog file. */ - public void build(List versionInfoList, String[] files, String[] templates, LineEnding ending) { + public void build(List versionInfoList, String[] files, String templateRoot, String[] templates, LineEnding ending) { FileWriter writer = null; int fileIndex = 0; + ChangelogTemplate.fileRoot = templateRoot; // build the changelog for the file using the file template. try { diff --git a/src/net/foxopen/jira/changelog/ChangelogTemplate.java b/src/net/foxopen/jira/changelog/ChangelogTemplate.java index 644da41..226f244 100644 --- a/src/net/foxopen/jira/changelog/ChangelogTemplate.java +++ b/src/net/foxopen/jira/changelog/ChangelogTemplate.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.io.StringWriter; import com.github.mustachejava.*; +import java.io.File; /** * Incorporates the base logic for Mustache templates for changelogs saved as @@ -22,6 +23,7 @@ public class ChangelogTemplate { static HashMap scopes = new HashMap(); static String LF; + static String fileRoot; /** * Generate and output a changelog based off a template file. @@ -40,7 +42,7 @@ public class ChangelogTemplate { public static void createChangelog(List versions, Writer output, String templateFile, LineEnding ending) { StringWriter out = new StringWriter(); String buffer = null; // templated file content. This buffer is used to convert the line endings. - MustacheFactory mf = new DefaultMustacheFactory(); + MustacheFactory mf = new DefaultMustacheFactory(new File(fileRoot)); Mustache template = mf.compile(templateFile); // assemble the JSON hash map diff --git a/src/net/foxopen/jira/changelog/Type.java b/src/net/foxopen/jira/changelog/Type.java index fa5bf80..3b3d61f 100644 --- a/src/net/foxopen/jira/changelog/Type.java +++ b/src/net/foxopen/jira/changelog/Type.java @@ -5,6 +5,7 @@ package net.foxopen.jira.changelog; import java.util.LinkedList; +import java.io.Serializable; /** * Defines an issue category (bug, task, support ticket, etc.) @@ -12,8 +13,8 @@ * @author apigram * @version 1.03.00 */ -public class Type { - +public class Type implements Serializable { + private static final long serialVersionUID = 4317423361667148998L; String name; LinkedList issues; diff --git a/test/net/foxopen/jira/changelog/ChangelogTemplateTest.java b/test/net/foxopen/jira/changelog/ChangelogTemplateTest.java index 9a4d3dd..f111912 100644 --- a/test/net/foxopen/jira/changelog/ChangelogTemplateTest.java +++ b/test/net/foxopen/jira/changelog/ChangelogTemplateTest.java @@ -12,7 +12,6 @@ import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.fail; import java.util.Properties; -import junit.framework.Assert; /** * Test case for generating file and module changelog templates @@ -60,7 +59,8 @@ protected void tearDown() throws Exception { public void testTextChangelog() throws Exception { System.out.println("textChangelog"); try { - ChangelogTemplate.createChangelog(versions, output, "examples/plain-text.mustache", LineEnding.NATIVE); + ChangelogTemplate.fileRoot = "examples"; + ChangelogTemplate.createChangelog(versions, output, "plain-text.mustache", LineEnding.NATIVE); } catch (Exception e) { fail("Exception raised."); e.printStackTrace(); @@ -76,7 +76,8 @@ public void testTextChangelog() throws Exception { public void testHTMLChangelog() throws Exception { System.out.println("HTMLChangelog"); try { - ChangelogTemplate.createChangelog(versions, output, "examples/html.mustache", LineEnding.NATIVE); + ChangelogTemplate.fileRoot = "examples"; + ChangelogTemplate.createChangelog(versions, output, "html.mustache", LineEnding.NATIVE); } catch (Exception e) { fail("Exception raised."); e.printStackTrace(); @@ -92,7 +93,8 @@ public void testHTMLChangelog() throws Exception { public void testXMLChangelog() throws Exception { System.out.println("XMLChangelog"); try { - ChangelogTemplate.createChangelog(versions, output, "examples/xml.mustache", LineEnding.NATIVE); + ChangelogTemplate.fileRoot = "examples"; + ChangelogTemplate.createChangelog(versions, output, "xml.mustache", LineEnding.NATIVE); } catch (Exception e) { fail("Exception raised."); e.printStackTrace(); @@ -111,16 +113,19 @@ public void testFullRun() throws Exception { Properties properties = new Properties(); properties.load(new FileInputStream("credentials.properties")); System.out.println("fullRun"); - String[] args = new String[9]; + String[] args = new String[12]; args[0] = properties.getProperty("url"); args[1] = properties.getProperty("username"); args[2] = properties.getProperty("password"); args[3] = properties.getProperty("project"); args[4] = properties.getProperty("version"); - args[5] = "examples/html.mustache"; - args[6] = "--debug"; - args[7] = "--changelog-file-name"; - args[8] = "changelog.html"; + args[5] = "examples"; + args[6] = "html.mustache,plain-text.mustache"; + args[7] = "--debug"; + args[8] = "--changelog-file-name"; + args[9] = "changelog.html,changelog.txt"; + args[10] = "--object-cache-path"; + args[11] = "cache"; // wrapper function has same effect as main, minus the System.exit call. Changelog.main(args); @@ -135,9 +140,10 @@ public void testLineEndings() throws Exception { FileWriter out2 = new FileWriter("testWindows.txt"); FileWriter out3 = new FileWriter("testNIX.txt"); try { - ChangelogTemplate.createChangelog(versions, out1, "examples/plain-text.mustache", LineEnding.NATIVE); - ChangelogTemplate.createChangelog(versions, out2, "examples/plain-text.mustache", LineEnding.WINDOWS); - ChangelogTemplate.createChangelog(versions, out3, "examples/plain-text.mustache", LineEnding.NIX); + ChangelogTemplate.fileRoot = "examples"; + ChangelogTemplate.createChangelog(versions, out1, "plain-text.mustache", LineEnding.NATIVE); + ChangelogTemplate.createChangelog(versions, out2, "plain-text.mustache", LineEnding.WINDOWS); + ChangelogTemplate.createChangelog(versions, out3, "plain-text.mustache", LineEnding.NIX); } catch (Exception e) { fail("Exception raised."); e.printStackTrace();