/* * 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.util; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import t2ext.T2Extension; /** * Saves some of the command line arguments to T2 in infoFile.info for later use. * * TODO what about other parameters? * * @author Maaike Gerritsen */ public class InfoFile implements Serializable { private static final long serialVersionUID = 1L; public int objectDepth = 4; public int saveGoodTraces = 100; public String saveFile = ""; public boolean saveTraces = false; public boolean inclPrivate = false; public boolean exclDefault = false; public boolean exclProtected = false; public boolean publicOnly = false; public boolean exclStatic = false; public boolean exclFields = false; public List methodsToBeChecked = new ArrayList(); public List methodsToBeExcluded = new ArrayList(); public double nullProbability = 0.1; public double pickPoolProbability = 0.7; public int maximumAttempts = 1; public boolean noArgumentsPresent = false; public boolean endMethods = false; public String elementType = ""; public boolean setInfo(String[] info) { String lastArg = ""; try { if(info.length==2){ noArgumentsPresent = true; save(); return true; } for (int i = 0; i < info.length; i++) { String arg = info[i].trim(); lastArg = arg; if (arg.contains("depthobj")) { String[] split = arg.split("="); objectDepth = Integer.parseInt(split[split.length - 1]); } else if (arg.equals("-d")) { objectDepth = Integer.parseInt(info[i + 1]); } else if (arg.contains("savegoodtr")) { String[] split = arg.split("="); saveGoodTraces = Integer.parseInt(split[split.length - 1]); saveTraces = true; } else if (arg.contains("savefile")) { String[] split = arg.split("="); saveFile = split[split.length - 1]; if (!saveFile.endsWith(".tr")) saveFile += ".tr"; } else if (arg.equals("--inclprivate")) { inclPrivate = true; } else if (arg.equals("--excldefault")) exclDefault = true; else if (arg.equals("--pathoptm")) endMethods = true; else if (arg.equals("--exclprotected")) exclProtected = true; else if (arg.equals("--pubonly")) publicOnly = true; else if (arg.equals("--exclstatic")) exclStatic = true; else if (arg.equals("exclfield")) exclFields = true; else if (arg.contains("--meth")) { String[] split = arg.split("="); methodsToBeChecked.add(split[split.length - 1]); exclFields = true; } else if (arg.contains("--xmeth")) { String[] split = arg.split("="); methodsToBeExcluded.add(split[split.length - 1]); } else if (arg.contains("nullprob")) { String[] split = arg.split("="); nullProbability = Double .parseDouble(split[split.length - 1]); } else if (arg.contains("pickpoolprob")) { String[] split = arg.split("="); pickPoolProbability = Double .parseDouble(split[split.length - 1]); } else if (arg.contains("maxattempts")) { String[] split = arg.split("="); maximumAttempts = Integer.parseInt(split[split.length - 1]); } else if (arg.contains("elemty")){ String[] split = arg.split("="); elementType = split[split.length - 1]; } else { //System.out.println("Unsaved argument: "+arg); } } save(); } catch (Exception e) { System.out.println("The following argument is not correct: " + lastArg); return false; } return true; } public void save() { try { ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream(FileCopy.TEMP_DIR+"infoFile.info")); System.out.println("Saving arguments in "+FileCopy.TEMP_DIR+"infoFile.info"); oos.writeObject(this); oos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static InfoFile load() { InfoFile info = null; try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream( FileCopy.TEMP_DIR+"infoFile.info")); System.out.println("Loading arguments from "+FileCopy.TEMP_DIR+"infoFile.info"); info = (InfoFile) ois.readObject(); ois.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } return info; } }