|
|
@@ -1,5 +1,9 @@ |
|
|
package hudson.plugins.fitnesse; |
|
|
|
|
|
import java.io.BufferedWriter; |
|
|
import java.io.FileWriter; |
|
|
import java.io.IOException; |
|
|
import java.io.PrintStream; |
|
|
import java.text.ParseException; |
|
|
import java.text.SimpleDateFormat; |
|
|
import java.util.ArrayList; |
|
@@ -28,7 +32,17 @@ |
|
|
SUMMARY, DETAIL }); |
|
|
|
|
|
private Counts summary; |
|
|
private Map<String, Counts> allCounts = new HashMap<String, Counts>(); |
|
|
private final Map<String, Counts> allCounts = new HashMap<String, Counts>(); |
|
|
|
|
|
private final String rootDirName; |
|
|
private final PrintStream logger; |
|
|
|
|
|
public NativePageCounts(PrintStream logger, String rootDirName) { |
|
|
this.logger = logger; |
|
|
this.rootDirName = rootDirName; |
|
|
logger.println("Write fitnesse results to: " + rootDirName); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Stores the actual fitnesse results. We do not want to merge them into |
|
|
* build.xml since the results may have size of several MB. E.g. in a suite |
|
@@ -39,34 +53,24 @@ |
|
|
* The allContents is read later on. The content is written to separate |
|
|
* files. |
|
|
*/ |
|
|
private Map<String, String> allContents = new HashMap<String, String>(); |
|
|
|
|
|
@Override |
|
|
public void startElement(String uri, String localName, String qName, |
|
|
Attributes attributes) { |
|
|
if (COUNTABLE.contains(qName)) { |
|
|
String page = attributes.getValue(PAGE); |
|
|
String pseudoPage = attributes.getValue(PSEUDO_PAGE); |
|
|
String content = attributes.getValue(CONTENT); |
|
|
String targetPage = page == null || page.equals("") ? pseudoPage : page; |
|
|
|
|
|
Counts counts = new Counts( |
|
|
page == null || page.equals("") ? pseudoPage : page, |
|
|
qName.equals(SUMMARY) ? "" : resultsDateOf(attributes |
|
|
.getValue(APPROX_RESULT_DATE)), |
|
|
targetPage, |
|
|
qName.equals(SUMMARY) ? "" : resultsDateOf(attributes.getValue(APPROX_RESULT_DATE)), |
|
|
Integer.parseInt(attributes.getValue(RIGHT)), |
|
|
Integer.parseInt(attributes.getValue(WRONG)), |
|
|
Integer.parseInt(attributes.getValue(IGNORED)), |
|
|
Integer.parseInt(attributes.getValue(EXCEPTIONS)), "" // see |
|
|
// above, |
|
|
// do |
|
|
// not |
|
|
// put |
|
|
// fitnesse-results |
|
|
// into |
|
|
// build.xml |
|
|
Integer.parseInt(attributes.getValue(EXCEPTIONS)), |
|
|
writeFitnesseResultFiles(targetPage, attributes.getValue(CONTENT)) |
|
|
); |
|
|
allContents.put(page, content); // see above, save actual result for |
|
|
// later usage |
|
|
|
|
|
if (qName.equals(SUMMARY)) |
|
|
summary = counts; |
|
|
allCounts.put(counts.page, counts); |
|
@@ -84,14 +88,6 @@ public int size() { |
|
|
return allCounts.size(); |
|
|
} |
|
|
|
|
|
/** |
|
|
* |
|
|
* @return the fitnesse results (html-content) |
|
|
*/ |
|
|
public Map<String, String> getAllContents() { |
|
|
return allContents; |
|
|
} |
|
|
|
|
|
public Counts getSummary() { |
|
|
if (summary != null && summary.right == 0 && summary.wrong == 0 |
|
|
&& summary.ignored == 0 && summary.exceptions == 0) { |
|
@@ -138,20 +134,19 @@ public Counts getSummary() { |
|
|
public final int wrong; |
|
|
public final int ignored; |
|
|
public final int exceptions; |
|
|
public final String content; |
|
|
public String content; // TODO this useless field ! |
|
|
// stores the file-path where to find the actual fitnesse result (html) |
|
|
// does anybody has a better idea: how to restore the path when the user clicks on the details link? |
|
|
public String contentFile; |
|
|
public final String contentFile; |
|
|
|
|
|
public Counts(String page, String resultsDate, int right, int wrong, |
|
|
int ignored, int exceptions, String content) { |
|
|
public Counts(String page, String resultsDate, int right, int wrong, int ignored, |
|
|
int exceptions, String contentFile) { |
|
|
this.page = page; |
|
|
this.resultsDate = resultsDate; |
|
|
this.right = right; |
|
|
this.wrong = wrong; |
|
|
this.ignored = ignored; |
|
|
this.exceptions = exceptions; |
|
|
this.content = content; |
|
|
this.contentFile = contentFile; |
|
|
} |
|
|
|
|
|
public Date resultsDateAsDate() throws ParseException { |
|
@@ -166,4 +161,42 @@ public String toString() { |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
/** |
|
|
* Gets a parsed fitnesse result and writes it to separate file. Putting the |
|
|
* fitnesse result in a separate file as performance reasons. E.g. for a huge |
|
|
* Test-Suite the actual fitnesse result can grow up to several MB. First |
|
|
* implementation of fitnesse plugin has stored the result to the build.xml. |
|
|
* This was very handy to present the result but slowed down jenkins since a |
|
|
* request to the fitnesse result leat to putting the entire build.xml into |
|
|
* the memory. With this function the fitnesse result is only load to memory |
|
|
* if the user clicks on it. |
|
|
*/ |
|
|
private String writeFitnesseResultFiles(String pageName, String htmlContent) { |
|
|
if (null == htmlContent) { |
|
|
logger.println("Could not find content for page: " + pageName); |
|
|
return null; |
|
|
} |
|
|
BufferedWriter out = null; |
|
|
String fileName = rootDirName + pageName + ".htm"; |
|
|
try { |
|
|
// Create separate file for every test in a suite |
|
|
FileWriter fstream = new FileWriter(fileName); |
|
|
out = new BufferedWriter(fstream); |
|
|
out.write(htmlContent); |
|
|
// Just store the path to the filename. |
|
|
return fileName; |
|
|
} catch (IOException e) { |
|
|
logger.println("Error while writing to out file" + fileName + "\n" + e.toString()); |
|
|
} finally { |
|
|
if (null != out) { |
|
|
try { |
|
|
out.close(); |
|
|
} catch (IOException e) { |
|
|
logger.println("Could not close out stream: " + fileName + "\n" + e.toString()); |
|
|
} |
|
|
} |
|
|
} |
|
|
return null; |
|
|
} |
|
|
} |