Line 2: |
|
|
|
|
|
= Embed the content of a report into a notification = |
|
= Embed the content of a report into a notification = |
|
|
+ |
Script notes:
|
|
|
+ |
* No notes
|
|
|
+ |
==== AHPSCRIPTS-23 ====
|
|
|
+ |
<pre>import com.urbancode.anthill3.domain.jobtrace.*;
|
|
|
+ |
import com.urbancode.anthill3.domain.workflow.*;
|
|
|
+ |
import com.urbancode.anthill3.runtime.paths.*;
|
|
|
+ |
import com.urbancode.devilfish.services.var.VarService;
|
|
|
+ |
import java.io.*;
|
|
|
|
|
|
|
+ |
private String getFileAsString(File file)
|
|
|
+ |
throws IOException {
|
|
|
+ |
StringBuffer result = new StringBuffer();
|
|
|
+ |
|
|
|
+ |
if (file.exists() && file.isFile()) {
|
|
|
+ |
InputStream inStream = new FileInputStream(file);
|
|
|
+ |
try {
|
|
|
+ |
byte[] buffer = new byte[4096];
|
|
|
+ |
int length = 0;
|
|
|
+ |
while ((length = inStream.read(buffer)) > 0) {
|
|
|
+ |
result.append(new String(buffer, 0, length));
|
|
|
+ |
}
|
|
|
+ |
}
|
|
|
+ |
finally {
|
|
|
+ |
try {
|
|
|
+ |
inStream.close();
|
|
|
+ |
}
|
|
|
+ |
catch (Exception e) {}
|
|
|
+ |
}
|
|
|
+ |
}
|
|
|
+ |
return result.toString();
|
|
|
+ |
}
|
|
|
|
|
|
|
|
|
|
|
+ |
String REPORT_NAME = "Fitnesse Reports"; // change to the name of your
|
|
|
+ |
reports
|
|
|
|
|
|
|
+ |
WorkflowCase workflow = (WorkflowCase) context.get("workflow");
|
|
|
+ |
JobTrace[] jobTraceArray = workflow.getJobTraceArray();
|
|
|
|
|
|
|
+ |
// find the job trace you want in some meaningful way
|
|
|
+ |
JobTrace jobTrace = jobTraceArray[0];
|
|
|
|
|
|
|
+ |
VarService vs = VarService.getInstance();
|
|
|
+ |
String reportsPath = PublishPathHelper.getInstance().getPublishPath(jobTrace,
|
|
|
+ |
REPORT_NAME);
|
|
|
+ |
File reportDir = new File(vs.resolve(reportsPath));
|
|
|
|
|
|
|
+ |
if (reportDir.exists() && reportDir.isDirectory()) {
|
|
|
+ |
File[] reportFiles = reportDir.listFiles();
|
|
|
+ |
String[] reports = new String[reportFiles.length];
|
|
|
+ |
for (int f=0; f<reportFiles.length; f++) {
|
|
|
+ |
reports[f] = getFileAsString(reportFiles[f]);
|
|
|
+ |
}
|
|
|
+ |
context.put("reports", reports);
|
|
|
+ |
}</pre>
|