- static File hostRootDir() {
- if(Platform.getProperty("nestedvm.root") != null) {
- File f = new File(Platform.getProperty("nestedvm.root"));
- if(f.isDirectory()) return f;
- // fall through to case below
- }
- String cwd = Platform.getProperty("user.dir");
- File f = new File(cwd != null ? cwd : ".");
- if(!f.exists()) throw new Error("Couldn't get File for cwd");
- f = new File(f.getAbsolutePath());
- while(f.getParent() != null) f = new File(f.getParent());
- // This works around a bug in some versions of ClassPath
- if(f.getPath().length() == 0) f = new File("/");
- return f;
- }
-
- static String reverseMap(String f) {
- if(f.startsWith("/") && File.separatorChar == '/') return f;
-
- Vector vec = new Vector();
- File root = HostFS.hostRootDir();
- String s = new File(f).getAbsolutePath();
- File d = new File(s);
- while(!d.equals(root)) {
- vec.addElement(d.getName());
- if((s = d.getParent()) == null) break;
- d = new File(s);
- }
- String ret = null;
- if(s != null) {
- ret="/";
- for(int i=vec.size()-1;i>=0;i--) ret += (String) vec.elementAt(i) + (i==0?"":"/");
- }
- return ret;
- }
-