00001 package edu.ksu.cis.bandera.report;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 import java.io.*;
00036 import java.util.*;
00037 import edu.ksu.cis.bandera.util.Preferences;
00038 import edu.ksu.cis.bandera.bui.session.datastructure.Session;
00039 import edu.ksu.cis.bandera.specification.datastructure.*;
00040 public class HTMLReportGenerator {
00041 private static Vector sessions = new Vector();
00042 private static Hashtable sessionSummaryTable = new Hashtable();
00043
00044
00045
00046
00047
00048
00049
00050 private static boolean generateBIRCSummary(String expectedPath, String resultPath, PrintWriter pw) {
00051 boolean isOk = true;
00052 String path1 = expectedPath + File.separator + "birc";
00053 String path2 = resultPath + File.separator + "birc";
00054 File file1 = new File(path1);
00055 File file2 = new File(path2);
00056 pw.println("<p><a name = \"BIRC\"><font size=\"5\"><strong>BIRC</strong></font></a></p>");
00057 pw.println("<ul>");
00058 isOk = generateFileSummary(expectedPath, resultPath, "report" + File.separator + "birc.report", "Report", pw) && isOk;
00059 {
00060 pw.println("<li><font size=\"3\">File(s):</font></li>");
00061 String[] files = file1.list();
00062 if (files == null) {
00063 pw.println("<ul>");
00064 pw.println("<li><font size=\"3\">Not found</font></li>");
00065 pw.println("</ul>");
00066 } else {
00067 pw.println("<ul>");
00068 for (int i = 0; i < files.length; i++) {
00069 isOk = generateFileSummary(expectedPath, resultPath, "birc" + File.separator + files[i], files[i], pw) && isOk;
00070 }
00071 pw.println("</ul>");
00072 }
00073 }
00074 pw.println("</ul>");
00075 return isOk;
00076 }
00077
00078
00079
00080
00081
00082
00083
00084 private static boolean generateBOFASummary(String expectedPath, String resultPath, PrintWriter pw) {
00085 boolean isOk = true;
00086 String path1 = expectedPath + File.separator + "bofa";
00087 String path2 = resultPath + File.separator + "bofa";
00088 File file1 = new File(path1);
00089 File file2 = new File(path2);
00090 pw.println("<p><a name = \"BOFA\"><font size=\"5\"><strong>BOFA</strong></font></a></p>");
00091 pw.println("<ul>");
00092 isOk = generateFileSummary(expectedPath, resultPath, "report" + File.separator + "bofa.report", "Report", pw) && isOk;
00093 {
00094 pw.println("<li><font size=\"3\">File(s):</font></li>");
00095 String[] files = file1.list();
00096 if (files == null) {
00097 pw.println("<ul>");
00098 pw.println("<li><font size=\"3\">Not found</font></li>");
00099 pw.println("</ul>");
00100 } else {
00101 pw.println("<ul>");
00102 for (int i = 0; i < files.length; i++) {
00103 isOk = generateFileSummary(expectedPath, resultPath, "bofa" + File.separator + files[i], files[i], pw) && isOk;
00104 }
00105 pw.println("</ul>");
00106 }
00107 }
00108 pw.println("</ul>");
00109 return isOk;
00110 }
00111
00112
00113
00114
00115
00116
00117
00118 private static boolean generateBSLSummary(String expectedPath, String resultPath, PrintWriter pw) {
00119 boolean isOk = true;
00120 String path1 = expectedPath + File.separator + "bsl";
00121 String path2 = resultPath + File.separator + "bsl";
00122 File file1 = new File(path1);
00123 File file2 = new File(path2);
00124 pw.println("<p><a name = \"BSL\"><font size=\"5\"><strong>BSL</strong></font></a></p>");
00125 pw.println("<ul>");
00126 isOk = generateFileSummary(expectedPath, resultPath, "report" + File.separator + "bsl.report", "Report", pw) && isOk;
00127 {
00128 pw.println("<li><font size=\"3\">File(s):</font></li>");
00129 String[] files = file1.list();
00130 if (files == null) {
00131 pw.println("<ul>");
00132 pw.println("<li><font size=\"3\">Not found</font></li>");
00133 pw.println("</ul>");
00134 } else {
00135 pw.println("<ul>");
00136 for (int i = 0; i < files.length; i++) {
00137 isOk = generateFileSummary(expectedPath, resultPath, "bsl" + File.separator + files[i], files[i], pw) && isOk;
00138 }
00139 pw.println("</ul>");
00140 }
00141 }
00142 pw.println("</ul>");
00143 return isOk;
00144 }
00145
00146
00147
00148
00149
00150
00151
00152
00153 private static boolean generateFileSummary(String expectedPath, String resultPath, String filename, String name, PrintWriter pw) {
00154 boolean result = true;
00155 String expectedFilePath = expectedPath + File.separator + filename;
00156 String resultFilePath = resultPath + File.separator + filename;
00157 if (new File(expectedFilePath).exists()) {
00158 if (new File(resultFilePath).exists()) {
00159 pw.print("<li>");
00160 pw.print("<a href=\"" + filename + "\"><font size=\"3\"><em>" + name + "</em></font></a> ");
00161 if (isEqual(expectedFilePath, resultFilePath)) {
00162 pw.print("<font size=\"3\"> (Ok)</font>");
00163 } else {
00164 result = false;
00165 pw.print("<font size=\"3\"> (Failed: <a href=\".." + File.separator + expectedFilePath + "\"><em>expected result</em></a>)</font>");
00166 }
00167 pw.println("</li>");
00168 } else {
00169 result = false;
00170 pw.println("<li><font size=\"3\">" + name + " was not available for the current result " + resultFilePath + "</font></li>");
00171 }
00172 } else {
00173 if (new File(resultFilePath).exists()) {
00174 result = false;
00175 pw.println("<li><font size=\"3\">" + name + " was not available for the expected result " + expectedFilePath + "</font></li>");
00176 } else {
00177 pw.println("<li><font size=\"3\">" + name + " was not available for both the expected and the current result</font></li>");
00178 }
00179 }
00180 return result;
00181 }
00182
00183
00184
00185
00186
00187
00188
00189 private static boolean generateInlinerSummary(String expectedPath, String resultPath, PrintWriter pw) {
00190 boolean isOk = true;
00191 String path1 = expectedPath + File.separator + "inlined";
00192 String path2 = resultPath + File.separator + "inlined";
00193 File file1 = new File(path1);
00194 File file2 = new File(path2);
00195 pw.println("<p><a name = \"Inliner\"><font size=\"5\"><strong>Inliner</strong></font></a></p>");
00196 pw.println("<ul>");
00197 isOk = generateFileSummary(expectedPath, resultPath, "report" + File.separator + "inliner.report", "Report", pw) && isOk;
00198 {
00199 pw.println("<li><font size=\"3\">File(s):</font></li>");
00200 String[] files = file1.list();
00201 if (files == null) {
00202 pw.println("<ul>");
00203 pw.println("<li><font size=\"3\">Not found</font></li>");
00204 pw.println("</ul>");
00205 } else {
00206 pw.println("<ul>");
00207 for (int i = 0; i < files.length; i++) {
00208 isOk = generateFileSummary(expectedPath, resultPath, "inlined" + File.separator + files[i], files[i], pw) && isOk;
00209 }
00210 pw.println("</ul>");
00211 }
00212 }
00213 pw.println("</ul>");
00214 return isOk;
00215 }
00216
00217
00218
00219
00220
00221
00222
00223 private static boolean generateJJJCSummary(String expectedPath, String resultPath, PrintWriter pw) {
00224 boolean isOk = true;
00225 String path1 = expectedPath + File.separator + "original";
00226 String path2 = resultPath + File.separator + "original";
00227 File file1 = new File(path1);
00228 File file2 = new File(path2);
00229 pw.println("<p><a name = \"JJJC\"><font size=\"5\"><strong>JJJC</strong></font></a></p>");
00230 pw.println("<ul>");
00231 isOk = generateFileSummary(expectedPath, resultPath, "report" + File.separator + "jjjc.report", "Report", pw) && isOk;
00232 {
00233 pw.println("<li><font size=\"3\">File(s):</font></li>");
00234 String[] files = file1.list();
00235 if (files == null) {
00236 pw.println("<ul>");
00237 pw.println("<li><font size=\"3\">Not found</font></li>");
00238 pw.println("</ul>");
00239 } else {
00240 pw.println("<ul>");
00241 for (int i = 0; i < files.length; i++) {
00242 isOk = generateFileSummary(expectedPath, resultPath, "original" + File.separator + files[i], files[i], pw) && isOk;
00243 }
00244 pw.println("</ul>");
00245 }
00246 }
00247 pw.println("</ul>");
00248 return isOk;
00249 }
00250
00251
00252
00253
00254
00255 private static void generatePropertySummary(Property p, PrintWriter pw) {
00256 TemporalLogicProperty tlp = p.getActivatedTemporalLogicProperty();
00257 TreeSet aps = p.getActivatedAssertionProperties();
00258 pw.println("<p><font size=\"5\"><strong>Property</strong></font></p>");
00259 pw.println("<ul>");
00260 pw.println("<li><font size=\"3\">Temporal Property:</font></li>");
00261 pw.println("<ul>");
00262 if (tlp == null) {
00263 pw.println("<li><font size=\"3\">None</font></li>");
00264 } else {
00265 pw.println("<li><font face=\"Courier New\" size=\"2\">" + tlp.expand() + "</font></li>");
00266 }
00267 pw.println("</ul>");
00268 pw.println("<li>Assertion Properties:</li>");
00269 pw.println("<ul>");
00270 if (aps.size() == 0) {
00271 pw.println("<li><font size=\"3\">None</font></li>");
00272 } else {
00273 for (Iterator i = aps.iterator(); i.hasNext();) {
00274 pw.println("<li><font face=\"Courier New\" size=\"3\">" + ((AssertionProperty) i.next()).getStringRepresentation() + "</font></li>");
00275 }
00276 }
00277 pw.println("</ul>");
00278 pw.println("</ul>");
00279 }
00280
00281
00282
00283
00284
00285 private static void generateSessionInfo(Session s, PrintWriter pw) {
00286 pw.println("<p><font size=\"5\"><strong>Session</strong></font></p>");
00287 pw.println("<pre>" + s.getStringRepresentation() + "</pre>");
00288 pw.println("<p><font size=\"5\"><strong>Files</strong></font></p>");
00289 pw.println("<ul>");
00290 pw.println("<li><a href=\".." + File.separator + s.getFilename() + "\"><font size=\"3\"><em>Main java file</em></font></a></li>");
00291 if ("".equals(s.getSpecFilename())) {
00292 pw.println("<li><font size=\"3\">No specification file</font></li>");
00293 } else {
00294 pw.println("<li><a href=\".." + File.separator + s.getSpecFilename() + "\"><font size=\"3\"><em>Specification file</em></font></a></li>");
00295 }
00296 if ("".equals(s.getAbsFilename())) {
00297 pw.println("<li><font size=\"3\">No abstraction file</font></li>");
00298 } else {
00299 pw.println("<li><a href=\".." + File.separator + s.getAbsFilename() + "\"><font size=\"3\"><em>Abstraction file</em></font></a></li>");
00300 }
00301 pw.println("</ul>");
00302 }
00303
00304
00305
00306
00307
00308
00309
00310 public static void generateSessionSummary(String htmlPath, Session session, String expectedPath, String resultPath) {
00311 sessions.add(session);
00312 Vector failedComponents = new Vector();
00313 try {
00314 String title = "Report for Session " + session.getName();
00315 PrintWriter pw = new PrintWriter(new FileWriter(htmlPath));
00316 pw.println("<html>");
00317 pw.println("<head>");
00318 pw.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
00319 pw.println("<title>" + title + "</title>");
00320 pw.println("</head>");
00321 pw.print("<body bgcolor=\"" + Preferences.getReportHTMLBackgroundColor() + "\"");
00322 if ("".equals(Preferences.getReportHTMLBackgroundImage())) {
00323 pw.println(">");
00324 } else {
00325 pw.println(" background = \"" + Preferences.getReportHTMLBackgroundImage() + "\">");
00326 }
00327 pw.println("<blockquote>");
00328 pw.println("<p><font size=\"7\"><strong>" + title + "</strong></font></p>");
00329 pw.println("<p><font size=\"4\"><strong>" + new Date() + "</strong></font></p>");
00330 pw.println("<p> </p>");
00331 generateSessionInfo(session, pw);
00332 generatePropertySummary(edu.ksu.cis.bandera.bui.BUI.property, pw);
00333 if (!generateJJJCSummary(expectedPath, resultPath, pw)) {
00334 failedComponents.add("JJJC");
00335 }
00336 if (!generateBSLSummary(expectedPath, resultPath, pw)) {
00337 failedComponents.add("BSL");
00338 }
00339 if (!generateBOFASummary(expectedPath, resultPath, pw)) {
00340 failedComponents.add("BOFA");
00341 }
00342 if (!generateSlicerSummary(expectedPath, resultPath, pw)) {
00343 failedComponents.add("Slicer");
00344 }
00345 if (!generateSLABSSummary(expectedPath, resultPath, pw)) {
00346 failedComponents.add("SLABS");
00347 }
00348 if (!generateInlinerSummary(expectedPath, resultPath, pw)) {
00349 failedComponents.add("Inliner");
00350 }
00351 if (!generateBIRCSummary(expectedPath, resultPath, pw)) {
00352 failedComponents.add("BIRC");
00353 }
00354 pw.println("<hr>");
00355 if ("".equals(Preferences.getReportHTMLBackImage())) {
00356 pw.println("<a href=\".." + File.separator + "index.html\"><font size=\"3\"><em>Back</em></font></a>");
00357 } else {
00358 pw.println("<a href=\".." + File.separator + "index.html\"><img src=\"" + Preferences.getReportHTMLBackImage() + "\" border=\"0\"></a>");
00359 }
00360 pw.println("</blockquote>");
00361 pw.println("</body>");
00362 pw.println("</html>");
00363 pw.close();
00364 } catch (Exception e) {
00365 failedComponents.add("Error writing " + htmlPath);
00366 }
00367 sessionSummaryTable.put(session, failedComponents);
00368 }
00369
00370
00371
00372
00373
00374
00375
00376 private static boolean generateSLABSSummary(String expectedPath, String resultPath, PrintWriter pw) {
00377 boolean isOk = true;
00378 String path1 = expectedPath + File.separator + "abstracted";
00379 String path2 = resultPath + File.separator + "abstracted";
00380 File file1 = new File(path1);
00381 File file2 = new File(path2);
00382 pw.println("<p><a name = \"SLABS\"><font size=\"5\"><strong>SLABS</strong></font></a></p>");
00383 pw.println("<ul>");
00384 isOk = generateFileSummary(expectedPath, resultPath, "report" + File.separator + "slabs.report", "Report", pw) && isOk;
00385 {
00386 pw.println("<li><font size=\"3\">File(s):</font></li>");
00387 String[] files = file1.list();
00388 if (files == null) {
00389 pw.println("<ul>");
00390 pw.println("<li><font size=\"3\">Not found</font></li>");
00391 pw.println("</ul>");
00392 } else {
00393 pw.println("<ul>");
00394 for (int i = 0; i < files.length; i++) {
00395 isOk = generateFileSummary(expectedPath, resultPath, "abstracted" + File.separator + files[i], files[i], pw) && isOk;
00396 }
00397 pw.println("</ul>");
00398 }
00399 }
00400 pw.println("</ul>");
00401 return isOk;
00402 }
00403
00404
00405
00406
00407
00408
00409
00410 private static boolean generateSlicerSummary(String expectedPath, String resultPath, PrintWriter pw) {
00411 boolean isOk = true;
00412 String path1 = expectedPath + File.separator + "sliced";
00413 String path2 = resultPath + File.separator + "sliced";
00414 File file1 = new File(path1);
00415 File file2 = new File(path2);
00416 pw.println("<p><a name = \"Slicer\"><font size=\"5\"><strong>Slicer</strong></font></a></p>");
00417 pw.println("<ul>");
00418 isOk = generateFileSummary(expectedPath, resultPath, "report" + File.separator + "slicer.report", "Report", pw) && isOk;
00419 {
00420 pw.println("<li><font size=\"3\">File(s):</font></li>");
00421 String[] files = file1.list();
00422 if (files == null) {
00423 pw.println("<ul>");
00424 pw.println("<li><font size=\"3\">Not found</font></li>");
00425 pw.println("</ul>");
00426 } else {
00427 pw.println("<ul>");
00428 for (int i = 0; i < files.length; i++) {
00429 isOk = generateFileSummary(expectedPath, resultPath, "sliced" + File.separator + files[i], files[i], pw) && isOk;
00430 }
00431 pw.println("</ul>");
00432 }
00433 }
00434 pw.println("</ul>");
00435 return isOk;
00436 }
00437
00438
00439
00440
00441 public static void generateSummary(String filename, String path) {
00442 try {
00443 String title = "Report for " + filename;
00444 PrintWriter pw = new PrintWriter(new FileWriter(path));
00445 pw.println("<html>");
00446 pw.println("<head>");
00447 pw.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
00448 pw.println("<title>" + title + "</title>");
00449 pw.println("</head>");
00450 pw.print("<body bgcolor=\"" + Preferences.getReportHTMLBackgroundColor() + "\"");
00451 if ("".equals(Preferences.getReportHTMLBackgroundImage())) {
00452 pw.println(">");
00453 } else {
00454 pw.println(" background = \"" + Preferences.getReportHTMLBackgroundImage() + "\">");
00455 }
00456 pw.println("<blockquote>");
00457 pw.println("<p><font size=\"7\"><strong>Report for <a href = \"" + filename + "\"><em>" + filename + "</em></a></strong></font></p>");
00458 pw.println("<p><font size=\"4\"><strong>" + new Date() + "</strong></font></p>");
00459 pw.println("<p> </p>");
00460 pw.println("<ul>");
00461 for (Iterator i = sessions.iterator(); i.hasNext();) {
00462 Session s = (Session) i.next();
00463 Vector v = (Vector) sessionSummaryTable.get(s);
00464 if (v.size() > 0) {
00465 String componentName = (String) v.firstElement();
00466 String component = "<a href=\"temp$" + s.getName() + File.separator + "index.html#" + componentName + "\"><font size=\"3\"><em>" + componentName + "<em></font></a>";
00467 pw.println("<li><font size=\"3\"><a href=\"temp$" + s.getName() + File.separator + "index.html\"><em>" + s.getName() + "</em></a> (Failed: " + component + ")</font></li>");
00468 } else {
00469 pw.println("<li><font size=\"3\"><a href=\"temp$" + s.getName() + File.separator + "index.html\"><em>" + s.getName() + "</em></a> (Ok)</font></li>");
00470 }
00471 }
00472 pw.println("</ul>");
00473 pw.println("<hr>");
00474 if ("".equals(Preferences.getReportHTMLBackImage())) {
00475 pw.println("<a href=\".." + File.separator + "index.html\"><font size=\"3\"><em>Back</em></font></a>");
00476 } else {
00477 pw.println("<a href=\".." + File.separator + "index.html\"><img src=\"" + Preferences.getReportHTMLBackImage() + "\" border=\"0\"></a>");
00478 }
00479 pw.println("</blockquote>");
00480 pw.println("</body>");
00481 pw.println("</html>");
00482 pw.close();
00483 } catch (Exception e) {
00484 System.out.println("Error writing " + path);
00485 }
00486 }
00487
00488
00489
00490
00491
00492
00493 private static boolean isEqual(String path1, String path2) {
00494 return new File(path1).length() == new File(path2).length();
00495 }
00496 }