Skip to content

Commit

Permalink
Made entity classes serializable to allow caching.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Andrew Pigram committed Sep 17, 2013
1 parent 0e7b95f commit 2763511
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/net/foxopen/jira/changelog/Change.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package net.foxopen.jira.changelog;

import java.util.Comparator;
import java.io.Serializable;

/**
* Represents a JIRA issue for display in the changelog.
*
* @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;
Expand Down
9 changes: 6 additions & 3 deletions src/net/foxopen/jira/changelog/Changelog.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public static void showUsage() {
System.out.println("<JIRA_password>: The password used to log into JIRA.");
System.out.println("<JIRA_project_name>: The name of the project in JIRA.");
System.out.println("<version>: The name of the version this changelog is for.");
System.out.println("<template_list>: 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("<template_root>: The path on disk to the directory that contains the template files.");
System.out.println("<template_list>: 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("<flags> (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.
Expand Down Expand Up @@ -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(",");
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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);
Expand All @@ -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!");
}
Expand Down
3 changes: 2 additions & 1 deletion src/net/foxopen/jira/changelog/ChangelogBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<VersionInfo> versionInfoList, String[] files, String[] templates, LineEnding ending) {
public void build(List<VersionInfo> 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 {
Expand Down
4 changes: 3 additions & 1 deletion src/net/foxopen/jira/changelog/ChangelogTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +23,7 @@ public class ChangelogTemplate {

static HashMap<String, Object> scopes = new HashMap<String, Object>();
static String LF;
static String fileRoot;

/**
* Generate and output a changelog based off a template file.
Expand All @@ -40,7 +42,7 @@ public class ChangelogTemplate {
public static void createChangelog(List<VersionInfo> 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
Expand Down
5 changes: 3 additions & 2 deletions src/net/foxopen/jira/changelog/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
package net.foxopen.jira.changelog;

import java.util.LinkedList;
import java.io.Serializable;

/**
* Defines an issue category (bug, task, support ticket, etc.)
*
* @author apigram
* @version 1.03.00
*/
public class Type {

public class Type implements Serializable {
private static final long serialVersionUID = 4317423361667148998L;
String name;
LinkedList<Change> issues;

Expand Down
30 changes: 18 additions & 12 deletions test/net/foxopen/jira/changelog/ChangelogTemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit 2763511

Please sign in to comment.