/* * Copyright 2008 Wishnu Prasetya. * * This file is part of T2. * T2 is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License (GPL) as published by the * Free Software Foundation; either version 3 of the License, or any * later version. * * T2 is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * A copy of the GNU General Public License can be found in T2 distribution. * If it is missing, see http://www.gnu.org/licenses. */ package t2ext; import java.io.File; import org.apache.tools.ant.DefaultLogger; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; import t2ext.bcel.ControlFlow; import t2ext.util.FileCopy; import t2ext.util.InfoFile; import t2ext.weaver.WeaverCreator; import t2ext.xml.XMLBuilder; /** * @author Maaike Gerritsen */ // TODO: handle exceptions properly public class T2Extension { public static void main(String[] args) { long time = System.currentTimeMillis(); boolean correctParams = checkParams(args); if(!correctParams) return; FileCopy.createTempDir(); // Save the initial arguments InfoFile infoFile = new InfoFile(); boolean correctArgs = infoFile.setInfo(args); if(!correctArgs){ errorMessage(); return; } String className = args[0]; String jarDir = args[1]; // Create the Ant build.xml XMLBuilder builder = new XMLBuilder(className, jarDir, args); builder.createBuildFile(); // Make copies of the input files FileCopy fc = new FileCopy(className, jarDir, infoFile); fc.createCopyJar(jarDir); //fc.copyDirectory(); // TODO check what this was supposed to do in the first place fc.backupCUT(); // Create CFG ControlFlow cFlow = new ControlFlow(className, infoFile); //cFlow.printInstructions(); cFlow.createControlFlow(); //System.out.println("-----------"); //cFlow.printInstructions(); // Make a new ant runner Project ant = new Project(); ant.init(); ProjectHelper.configureProject(ant, new File(FileCopy.TEMP_DIR+"build.xml")); // Make sure we can see the output DefaultLogger consoleLogger = new DefaultLogger(); consoleLogger.setErrorPrintStream(System.err); consoleLogger.setOutputPrintStream(System.out); consoleLogger.setMessageOutputLevel(Project.MSG_INFO); ant.addBuildListener(consoleLogger); // Add ...? to the T2ECopy.jar (perhaps the original .class?) // FIXME it doesn't seem to do anything atm ant.executeTarget("addJar"); fc.deleteOriginal(); WeaverCreator creator = new WeaverCreator(); creator.createWeaver(); ant.executeTarget("weaver"); System.out.println("DEBUG: exiting system"); System.exit(0); // FIXME everything below this ant.executeTarget("addWeaverToJar"); ant.executeTarget("toajc"); ant.executeTarget("rndengine"); fc.setDirectoryToOld(); long time2 = System.currentTimeMillis(); long millis = time2-time; System.out.println("runtime in milliseconds: "+millis); } private static boolean checkParams(String[] args) { if(args.length<2){ errorMessage(); return false; } return true; } // TODO change this message private static void errorMessage() { StringBuffer buffer = new StringBuffer(); buffer.append("\n"); buffer.append("T2Extension needs at least two arguments: \n \n"); buffer.append("- The full name (including package) of the class to be tested \n"); buffer.append("- The location of this jar \n \n"); buffer.append("It is also possible to specify how many times T2Extension should \n"); buffer.append("improve on branch coverage. Add --maxattempts=number to the arguments.\n"); buffer.append("The default is 3. \n \n"); buffer.append("It is also possible to include T2 options. \n \n"); System.out.println(buffer.toString()); } // private static List readNameFile() { // List test = new ArrayList(); // try { // FileInputStream in = new FileInputStream("/home/maaike/thesis/jar/test/bla/name.txt"); // BufferedInputStream bi = new BufferedInputStream(in); // int ch = 0; // StringBuffer buf = new StringBuffer(); // while ((ch = bi.read()) > -1) { // buf.append((char) ch); // } // if (buf.length() > 0) { // String content = buf.toString(); // String[] split = content.split("NAME: "); // for(int i=0;i getList() { // List list = new ArrayList(); // String[] bla = test().split(","); // for(int i=0;i