1 29 30 package com.caucho.java; 31 32 import com.caucho.loader.EnvironmentLocal; 33 import com.caucho.vfs.MemoryPath; 34 import com.caucho.vfs.MergePath; 35 import com.caucho.vfs.Path; 36 import com.caucho.vfs.Vfs; 37 38 import javax.annotation.PostConstruct; 39 40 public class WorkDir { 41 private static final EnvironmentLocal<Path> _localWorkDir 42 = new EnvironmentLocal<Path>("caucho.work-dir"); 43 44 private Path _path; 45 46 public WorkDir() 47 { 48 } 49 50 53 public static Path getLocalWorkDir() 54 { 55 return getLocalWorkDir(Thread.currentThread().getContextClassLoader()); 56 } 57 58 61 public static Path getLocalWorkDir(ClassLoader loader) 62 { 63 Path path = _localWorkDir.get(loader); 64 65 if (path != null) 66 return path; 67 68 if (com.caucho.server.util.CauchoSystem.isWindows()) 70 path = Vfs.lookup("file:/c:/tmp/caucho"); 71 else 72 path = Vfs.lookup("file:/tmp/caucho"); 73 74 _localWorkDir.setGlobal(path); 75 76 try { 77 path.mkdirs(); 78 } catch (java.io.IOException e) { 79 } 80 81 return path; 82 } 83 84 87 public static void setLocalWorkDir(Path path) 88 { 89 setLocalWorkDir(path, Thread.currentThread().getContextClassLoader()); 90 } 91 92 95 public static void setLocalWorkDir(Path path, ClassLoader loader) 96 { 97 try { 98 if (path instanceof MergePath) 99 path = ((MergePath) path).getWritePath(); 100 101 if (path instanceof MemoryPath) { 102 String pathName = path.getPath(); 103 104 path = Vfs.lookup("file:/tmp/caucho/qa/" + pathName); 105 } 106 107 } catch (Exception e) { 109 throw new RuntimeException (e); 110 } 111 112 _localWorkDir.set(path, loader); 113 } 114 115 118 public void setValue(Path path) 119 { 120 _path = path; 121 } 122 123 126 public void setId(Path path) 127 throws java.io.IOException 128 { 129 setValue(path); 130 } 131 132 135 @PostConstruct 136 public void init() 137 { 138 setLocalWorkDir(_path); 139 } 140 } 141 142 | Popular Tags |