1 2 12 package com.versant.core.jdo.tools.ant; 13 14 15 16 import org.apache.tools.ant.BuildException; 17 import org.apache.tools.ant.AntClassLoader; 18 import org.apache.tools.ant.types.Path; 19 import org.apache.tools.ant.types.Reference; 20 import org.apache.tools.ant.taskdefs.MatchingTask; 21 22 23 import com.versant.core.metadata.ModelMetaData; 24 import com.versant.core.logging.LogEventStore; 25 import com.versant.core.common.config.ConfigParser; 26 import com.versant.core.common.config.ConfigInfo; 27 import com.versant.core.util.classhelper.ClassHelper; 28 import com.versant.core.storagemanager.StorageManagerFactory; 29 import com.versant.core.storagemanager.StorageManagerFactoryBuilder; 30 31 32 33 36 public class JdoTaskBase 37 38 extends MatchingTask 39 { 40 41 public static String DEFAULT_CONFIG_FILENAME = "versant.properties"; 42 protected String configFilename = DEFAULT_CONFIG_FILENAME; 43 44 protected ModelMetaData metaData; 45 protected LogEventStore pes; 46 protected StorageManagerFactory smf; 47 protected StorageManagerFactory innermostSmf; 48 protected ClassLoader taskClassLoader; 49 50 51 protected Path classpath; 52 53 54 55 public void setConfig(String config) { 56 configFilename = config; 57 } 58 59 public String getConfig() { 60 return configFilename; 61 } 62 63 public void setProject(String config) { 64 setConfig(config); 65 } 66 67 public void log(String msg) { 68 if (project == null) { 69 System.out.println(msg); 70 } 71 72 else { 73 super.log(msg); 74 } 75 76 } 77 78 81 82 public void setClasspath(Path classpath) { 83 if (classpath == null) { 84 this.classpath = classpath; 85 } else { 86 classpath.append(classpath); 87 } 88 } 89 90 91 92 protected ClassLoader getClassLoader() { 93 94 if (taskClassLoader != null) return taskClassLoader; 95 ClassLoader cl = getClass().getClassLoader(); 96 if (cl == null) { 97 cl = ClassHelper.get().getSystemClassLoader(); 98 } 99 if (classpath == null || project == null) { 100 taskClassLoader = cl; 101 } else { 102 taskClassLoader = new AntClassLoader(cl, project, classpath, true); 103 } 104 return taskClassLoader; 105 106 107 } 108 109 112 113 public Path createClasspath() { 114 if (classpath == null) { 115 classpath = new Path(project); 116 } 117 return classpath.createPath(); 118 } 119 120 121 124 125 public void setClasspathRef(Reference r) { 126 createClasspath().setRefid(r); 127 } 128 129 130 133 134 public Path getClasspath() { 135 return classpath; 136 } 137 138 139 140 141 145 public void execute() 146 { 147 ConfigParser p = new ConfigParser(); 149 150 Thread.currentThread().setContextClassLoader(getClassLoader()); 151 ConfigInfo config = p.parseResource(configFilename, getClassLoader()); 152 config.validate(); 153 154 155 156 168 169 StorageManagerFactoryBuilder b = new StorageManagerFactoryBuilder(); 170 b.setConfig(config); 171 172 b.setLoader(getClassLoader()); 173 174 b.setOnlyMetaData(!isCreateConnectionPool()); 175 b.setFullInit(false); 176 smf = b.createStorageManagerFactory(); 177 for (innermostSmf = smf; ;) { 178 StorageManagerFactory next = 179 innermostSmf.getInnerStorageManagerFactory(); 180 if (next == null) break; 181 innermostSmf = next; 182 } 183 pes = b.getLogEventStore(); 184 } 185 186 190 protected boolean isCreateConnectionPool() { 191 return true; 192 } 193 194 198 protected void initDataStores() { 199 } 201 202 public ModelMetaData getMetaData() { 203 return metaData; 204 } 205 206 public StorageManagerFactory getSmf() { 207 return smf; 208 } 209 210 public StorageManagerFactory getInnermostSmf() { 211 return innermostSmf; 212 } 213 214 public LogEventStore getPerfEventStore() { 215 return pes; 216 } 217 218 public void throwBuildException(String str) { 219 throwBuildException(str, null); 220 } 221 222 public void throwBuildException(String str, Throwable e) { 223 224 throw new BuildException(str, e); 225 226 227 } 228 } 229 | Popular Tags |