1 28 29 package com.caucho.make; 30 31 import com.caucho.config.DynamicBean; 32 import com.caucho.config.DynamicItem; 33 import com.caucho.loader.DynamicClassLoader; 34 import com.caucho.loader.EnvironmentLocal; 35 import com.caucho.loader.Loader; 36 import com.caucho.log.Log; 37 import com.caucho.server.util.CauchoSystem; 38 import com.caucho.util.CharBuffer; 39 import com.caucho.vfs.Dependency; 40 import com.caucho.vfs.JarPath; 41 import com.caucho.vfs.Path; 42 43 import java.util.ArrayList ; 44 import java.util.logging.Level ; 45 import java.util.logging.Logger ; 46 47 51 public class MakeLoader extends Loader implements DynamicBean, Make { 52 private static final Logger log = Log.open(MakeLoader.class); 53 54 private static final EnvironmentLocal<DynamicItem[]> _localConfig = 55 new EnvironmentLocal<DynamicItem[]>(); 56 57 private static DynamicItem []_configItems; 58 59 private Path _path; 61 62 private ArrayList <Dependency> _dependList = new ArrayList <Dependency>(); 64 private ArrayList <Make> _makeList = new ArrayList <Make>(); 65 66 69 public MakeLoader() 70 { 71 } 72 73 public DynamicItem []getDynamicConfigurationElements() 74 { 75 DynamicItem []configItems = _localConfig.get(); 76 77 if (configItems == null) { 78 ArrayList <DynamicItem> items = new ArrayList <DynamicItem>(); 79 80 84 85 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 86 87 try { 88 Class taskClass = Class.forName("com.caucho.ejb.doclet.EjbDocletTask", 89 false, 90 loader); 91 92 items.add(new DynamicItem("ejb-doclet", taskClass, "make")); 93 } catch (Throwable e) { 94 log.log(Level.FINEST, e.toString(), e); 95 } 96 97 configItems = items.toArray(new DynamicItem[items.size()]); 98 99 _localConfig.set(configItems); 100 } 101 102 return configItems; 103 } 104 105 108 public void setPath(Path path) 109 { 110 _path = path; 111 } 112 113 116 public Path getPath() 117 { 118 return _path; 119 } 120 121 124 public void setLoader(DynamicClassLoader loader) 125 { 126 super.setLoader(loader); 127 128 loader.addURL(_path); 129 } 130 131 138 public Path getPath(String name) 139 { 140 for (int i = 0; i < _makeList.size(); i++) { 141 Make make = _makeList.get(i); 142 143 try { 144 make.make(); 145 } catch (Exception e) { 146 throw new RuntimeException (e); 147 } 148 } 149 150 return _path.lookup(name); 151 } 152 153 156 public void addTask(TaskConfig task) 157 { 158 Object obj = task.getTask(); 159 160 if (obj instanceof Make) 161 _makeList.add((Make) obj); 162 } 163 164 167 public void addMake(Make make) 168 { 169 _makeList.add(make); 170 } 171 172 175 public void make() 176 throws Exception 177 { 178 } 179 180 183 protected String getClassPath(String head) 184 { 185 CharBuffer cb = new CharBuffer(); 186 187 if (! head.equals("")) { 188 cb.append(head); 189 cb.append(CauchoSystem.getPathSeparatorChar()); 190 } 191 192 if (_path instanceof JarPath) 193 cb.append(((JarPath) _path).getContainer().getNativePath()); 194 else if (_path.isDirectory()) 195 cb.append(_path.getNativePath()); 196 197 return cb.toString(); 198 } 199 200 203 public String toString() 204 { 205 return "MakeLoader[" + _path + "]"; 206 } 207 208 static { 209 }; 210 } 211 212 213 | Popular Tags |