From: pcm <pcm...@us...> - 2005-05-12 06:25:40
|
Update of /cvsroot/javapathfinder/javapathfinder/src/gov/nasa/jpf In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9219/src/gov/nasa/jpf Modified Files: Config.java JPF.java Log Message: * added Config support for an alternate lookup dir, which should be used when JPF doesn't find a property file in the current dir, and before it tries to load the properties from resources. The dir is initialized from the +jpf.basedir=<dir> option, which is in turn now automatically set when using the bin/jpf script. This should make it easier to run JPF from within Eclipse, but outside its root dir (e.g. from where the application code resides) * hot fixed the BFSearch MJIEnv problem (ThreadInfo(ThreadData) ctor). THIS IS NOT YET THE REAL SOLUTION, since we want to get away from static references, but it buys us time to do the proper refactoring. Index: JPF.java =================================================================== RCS file: /cvsroot/javapathfinder/javapathfinder/src/gov/nasa/jpf/JPF.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- JPF.java 11 May 2005 18:05:34 -0000 1.2 +++ JPF.java 12 May 2005 06:25:32 -0000 1.3 @@ -220,36 +220,54 @@ jpf.run(); } } - + /** - * answer the filename of the JPF properties file to use. If it's not - * specified via '-config', the default "jpf.properties" is used. + * find the value of an arg that is either specific as + * "-key=value" or as "-key value". If not found, the supplied + * defValue is returned */ - static String getConfigFileName(String[] args) { - String pf = "jpf.properties"; + static String getArg(String[] args, String pattern, String defValue, boolean consume) { + String s = defValue; for (int i = 0; i < args.length; i++) { String arg = args[i]; if (arg != null) { - - if (arg.matches("-c(onfig)?(=.+)?")) { + if (arg.matches(pattern)) { int idx=arg.indexOf('='); if (idx > 0) { - pf = arg.substring(idx+1); - args[i]=null; + s = arg.substring(idx+1); + if (consume) { + args[i]=null; + } } else if (i < args.length-1) { - pf = args[i+1]; - args[i] = null; - args[i+1] = null; + s = args[i+1]; + if (consume) { + args[i] = null; + args[i+1] = null; + } } break; } } } - return pf; + return s; } - + + /** + * what property file to look for + */ + static String getConfigFileName (String[] args) { + return getArg(args, "-c(onfig)?(=.+)?", "jpf.properties", true); + } + + /** + * where to look for the file (if it's not in the current dir) + */ + static String getRootDirName (String[] args) { + return getArg(args, "[+]jpf[.]basedir(=.+)?", null, false); // stupid compiler complaining about escape seq + } + /** * return a Config object that holds the JPF options. This first * loads the properties from a (potentially configured) properties file, and @@ -257,8 +275,9 @@ */ public static Config createConfig (String[] args) { String pf = getConfigFileName(args); + String rd = getRootDirName(args); - return new Config(args, pf, JPF.class); + return new Config(args, pf, rd, JPF.class); } /** Index: Config.java =================================================================== RCS file: /cvsroot/javapathfinder/javapathfinder/src/gov/nasa/jpf/Config.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Config.java 3 May 2005 03:31:59 -0000 1.2 +++ Config.java 12 May 2005 06:25:32 -0000 1.3 @@ -96,15 +96,15 @@ /** * this is our internal defaults ctor */ - private Config (Class codeBase) { - gotProperties = loadFile("default.properties", codeBase); + private Config (String alternatePath, Class codeBase) { + gotProperties = loadFile("default.properties", alternatePath, codeBase); } - public Config (String[] args, String fileName, Class codeBase) { - super( new Config(codeBase == null ? codeBase = getCallerClass(1) : codeBase)); + public Config (String[] args, String fileName, String alternatePath, Class codeBase) { + super(new Config( alternatePath, (codeBase == null) ? codeBase = getCallerClass(1) : codeBase)); this.fileName = fileName; - gotProperties = loadFile(fileName, codeBase); + gotProperties = loadFile(fileName, alternatePath, codeBase); processArgs(args); normalizeValues(); @@ -153,21 +153,28 @@ } } - boolean loadFile(String fileName, Class codeBase) { + boolean loadFile(String fileName, String alternatePath, Class codeBase) { InputStream is = null; try { // first, try to load from a file File f = new File(fileName); + if (!f.exists()) { + // Ok, try alternatePath, if fileName wasn't absolute + if (!f.isAbsolute() && (alternatePath != null)) { + f = new File(alternatePath, fileName); + } + } + if (f.exists()) { is = new FileInputStream(f); - Debug.println(Debug.MESSAGE, "reading config from file: " + fileName); - } else { + Debug.println(Debug.MESSAGE, "reading config from file: " + f.getAbsolutePath()); + } else { // if there is no file, try to load as a resource (jar) Class clazz = (codeBase != null) ? codeBase : Config.class; is = clazz.getResourceAsStream(fileName); if (is != null) { - Debug.println(Debug.MESSAGE, "reading config from resource: " + fileName); + Debug.println(Debug.MESSAGE, "reading config from resource: " + fileName); } } |