Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Bandera.java

00001 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00002  * Bandera, a Java(TM) analysis and transformation toolkit           *
00003  * Copyright (C) 1998-2001 SAnToS Laboratories (santos@cis.ksu.edu)  *
00004 
00005  * All rights reserved.                                              *
00006  *                                                                   *
00007  * This work was done as a project in the SAnToS Laboratory,         *
00008  * Department of Computing and Information Sciences, Kansas State    *
00009  * University, USA (http://www.cis.ksu.edu/santos).                  *
00010  * It is understood that any modification not identified as such is  *
00011  * not covered by the preceding statement.                           *
00012  *                                                                   *
00013  * This work is free software; you can redistribute it and/or        *
00014  * modify it under the terms of the GNU Library General Public       *
00015  * License as published by the Free Software Foundation; either      *
00016  * version 2 of the License, or (at your option) any later version.  *
00017  *                                                                   *
00018  * This work is distributed in the hope that it will be useful,      *
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00021  * Library General Public License for more details.                  *
00022  *                                                                   *
00023  * You should have received a copy of the GNU Library General Public *
00024  * License along with this toolkit; if not, write to the             *
00025  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00026  * Boston, MA  02111-1307, USA.                                      *
00027  *                                                                   *
00028  * Java is a trademark of Sun Microsystems, Inc.                     *
00029  *                                                                   *
00030  * To submit a bug report, send a comment, or get the latest news on *
00031  * this project and other SAnToS projects, please visit the web-site *
00032  *                http://www.cis.ksu.edu/santos                      *
00033  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00034 import java.util.*;
00035 import java.io.*;
00036 import edu.ksu.cis.bandera.bui.session.datastructure.*;
00037 import edu.ksu.cis.bandera.bui.session.*;
00038 import edu.ksu.cis.bandera.bui.*;
00039 import edu.ksu.cis.bandera.util.*;
00040 
00041 public class Bandera {
00042     private static final String sessionExtension = ".session";  // The default session file extension
00043     private static StringBuffer summary = new StringBuffer();
00044     private static boolean isDump;
00045     private static boolean genReport;
00046     private static String expectedPath;
00047 /**
00048  * 
00049  * @param b boolean
00050  */
00051 public static void assert(boolean b) {}
00052   public static void beginAtomic(){}  
00053 /**
00054  * 
00055  * @return boolean
00056  */
00057 public static boolean choose() {
00058     return false;
00059 }
00060 private static void doOneSession(Session ses) {
00061     if (ses == null)
00062         throw new RuntimeException("Cannot run null session!");
00063     //  CoreDriver driver = new CoreDriver(ses);
00064     Driver driver = new Driver();
00065     driver.initCmdLine(ses, isDump, genReport, expectedPath);
00066     summary.append("--------------------------------------------------------------------------------\n");
00067     summary.append("Session: " + ses.getName() + "\n\n");
00068     driver.run();
00069     //  summary.append(driver.getMessage());
00070     summary.append(driver.getSummary());
00071     driver = null;
00072     summary.append("\n--------------------------------------------------------------------------------\n");
00073 }
00074   public static void endAtomic(){}  
00075 /**
00076  * 
00077  */
00078 private static void help()
00079 {
00080     System.out.println("Bandera parameter list:");
00081     System.out.println("   -h, --h, --help, -?, --?, -help Print this help screen.");
00082     System.out.println("   -s   {sesfile} [sesnames...] --> run Bandera with specified session file.");
00083     System.out.println("        If your session file doesn't end with " + sessionExtension + " Bandera will append it.");
00084     System.out.println("        If you omit the sesnames part, it will run *ALL* sessions in the");
00085     System.out.println("        session file.");
00086     System.out.println("        You can run only some sessions of the session file by listing it, e.g.:");
00087     System.out.println("          java Bandera -s test ses1 dedlok multitrd3");
00088     System.out.println("        This will run bandera using test." + sessionExtension + " and run");
00089     System.out.println("        ses1, dedlok, and multitrd3 sessions.\n");
00090     System.out.println("   -sd  does the same things as -s except it dumps Jimple and Java codes");
00091     System.out.println("        in intermediate steps.");
00092     System.out.println("   -st <path> does the same things as -rd except it generates test report");
00093     System.out.println("   -r   {sesfile} [sesnames...] --> run Mr. Roboto with specified session file.");
00094     System.out.println("   -rd  does the same things as -r except it dumps Jimple and Java codes");
00095     System.out.println("        in intermediate steps.");
00096     System.out.println("   -rt <path> does the same things as -rd except it generates test report");
00097     System.out.println("Running Bandera without parameter will bring you to the GUI directly.\nSee manual for details.");
00098 }
00099 /**
00100  * 
00101  * @param args java.lang.String[]
00102  */
00103 public static void main(String[] args) {
00104     if (args.length == 0) {
00105         edu.ksu.cis.bandera.bui.BUI.main(args);
00106     } else {
00107         // This is where help is
00108         if ((args.length == 1) && ((args[0].equals("-h")) || (args[0].equals("--help")) || (args[0].equals("-help")) || (args[0].equals("-?")) || (args[0].equals("--h") || (args[0].equals("--?"))))) {
00109             help();
00110             return;
00111         }
00112 
00113         // This is the real cmd line driver
00114         if ((args.length >= 2) && (args[0].equals("-s") || args[0].equals("-sd") || args[0].equals("-st"))) {
00115             Preferences.load();
00116             //Logger.on();
00117             // The second or third parameter would be the session file
00118             int sessionIdx = 1;
00119             if (args[0].equals("-sd"))
00120                 isDump = true;
00121             if (args[0].equals("-st")) {
00122                 isDump = true;
00123                 genReport = true;
00124                 expectedPath = args[1];
00125                 sessionIdx = 2;
00126                 if (args.length < 3) {
00127                     help();
00128                     return;
00129                 }
00130             }
00131             String st;
00132             if (args[sessionIdx].endsWith(sessionExtension))
00133                 st = args[sessionIdx];
00134             else
00135                 st = args[sessionIdx] + sessionExtension;
00136 
00137             // Session filename already parsed
00138             try {
00139                 // Load the session file mentioned
00140                 Sessions allses = null;
00141                 try {
00142                     allses = new SessionsSaverLoader().load(st);
00143                     if (allses == null)
00144                         throw new Exception();
00145                     summary.append("Execution Summary:\n\nSession file " + st + " is successfully loaded.\n\n");
00146                 } catch (Exception ex) {
00147                     throw new Exception("Cannot load session file '" + st + "'");
00148                 }
00149 
00150                 // If no session name mentioned, just run every session inside that file.
00151                 if (args.length == sessionIdx + 1) {
00152                     for (Enumeration e = allses.getSessions().elements(); e.hasMoreElements();) {
00153                         doOneSession((Session) e.nextElement());
00154                     }
00155                 } else {
00156                     // Otherwise, iterate the args[2,3,...] for the session name wanted
00157                     for (int i = sessionIdx + 1; i < args.length; i++) {
00158                         doOneSession(allses.getSession(args[i]));
00159                     }
00160                 }
00161             } catch (Exception e) {
00162                 summary.append("Error: " + e.getMessage());
00163             }
00164 
00165             // Print out the summary of execution
00166             if (genReport)
00167                 edu.ksu.cis.bandera.report.HTMLReportGenerator.generateSummary(st, "index.html");
00168             System.out.println(summary);
00169             //Logger.off();
00170             Preferences.save();
00171             System.exit(0);
00172         } else
00173             if ((args.length >= 2) && ((args[0].equals("-r")) || (args[0].equals("-rd"))) || (args[0].equals("-rt"))) {
00174                 Preferences.load();
00175                 //Logger.on();
00176                 // The second or third parameter would be the session file
00177                 int sessionIdx = 1;
00178                 if (args[0].equals("-rd"))
00179                     isDump = true;
00180                 if (args[0].equals("-rt")) {
00181                     isDump = true;
00182                     genReport = true;
00183                     expectedPath = args[1];
00184                     sessionIdx = 2;
00185                     if (args.length < 3) {
00186                         help();
00187                         return;
00188                     }
00189                 }
00190                 String st;
00191                 if (args[sessionIdx].endsWith(sessionExtension))
00192                     st = args[sessionIdx];
00193                 else
00194                     st = args[sessionIdx] + sessionExtension;
00195 
00196                 // Session filename already parsed
00197                 try {
00198                     // Load the session file mentioned
00199                     Sessions allses = null;
00200                     try {
00201                         allses = new SessionsSaverLoader().load(st);
00202                         if (allses == null)
00203                             throw new Exception();
00204                         summary.append("Execution Summary:\n\nSession file " + st + " is successfully loaded.\n\n");
00205                     } catch (Exception ex) {
00206                         throw new Exception("Cannot load session file '" + st + "'");
00207                     }
00208                     Vector sessionNames = new Vector();
00209                     // If no session name mentioned, just run every session inside that file.
00210                     if (args.length == 2) {
00211                         for (Enumeration e = allses.getSessions().elements(); e.hasMoreElements();) {
00212                             sessionNames.add(((Session) e.nextElement()).getName());
00213                         }
00214                     } else {
00215                         // Otherwise, iterate the args[2,3,...] for the session name wanted
00216                         for (int i = 0; i < args.length - 2; i++) {
00217                             Session s = allses.getSession(args[i + 2]);
00218                             if (s != null)
00219                                 sessionNames.add(s.getName());
00220                             else
00221                                 System.out.println("Session " + args[i + 2] + " is not found!\n");
00222                         }
00223                     }
00224                     edu.ksu.cis.bandera.bui.BUI.main(new String[0]);
00225                     new edu.ksu.cis.bandera.bui.roboto.MrRoboto(st, sessionNames, isDump, genReport, expectedPath).run();
00226                 } catch (Exception e) {
00227                     summary.append("Error: " + e.getMessage());
00228                 }
00229                 // Print out the summary of execution
00230                 if (genReport)
00231                     edu.ksu.cis.bandera.report.HTMLReportGenerator.generateSummary(st, "index.html");
00232                 System.out.println(summary);
00233                 //Logger.off();
00234                 Preferences.save();
00235                 System.exit(0);
00236             } else { // User says something else, so error...
00237                 System.out.println("Error! See help for details!");
00238                 help();
00239             }
00240     }
00241 }
00242   /**
00243    *
00244    * nondeterministic choice of integers in the range 0 to n
00245    */
00246   public static int random(int n)
00247   {
00248     if(n>=0){
00249       for(int i=1; i<=n; i++)
00250         if(choose())
00251           return i;
00252       return 0;
00253     }
00254     else
00255     System.out.println("Bad argument");
00256     return -1;
00257    
00258   }  
00259   /**
00260    *
00261    * nondetermnistic choice between true and false
00262    */                                                                 
00263   public static boolean randomBool()
00264   {
00265     return choose();
00266   }  
00267 }

Generated at Thu Feb 7 06:40:29 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001