1 25 package org.objectweb.jonas.ant; 26 27 import java.io.File ; 28 29 import org.apache.tools.ant.AntClassLoader; 30 import org.apache.tools.ant.BuildException; 31 import org.apache.tools.ant.DirectoryScanner; 32 import org.apache.tools.ant.Project; 33 import org.apache.tools.ant.taskdefs.Java; 34 import org.apache.tools.ant.taskdefs.MatchingTask; 35 import org.apache.tools.ant.types.Path; 36 37 42 public class WsGenTask extends MatchingTask { 43 44 45 private static final String BOOTSTRAP_CLASS = "org.objectweb.jonas.server.Bootstrap"; 46 47 48 private static final String WSGEN_CLASS = "org.objectweb.jonas_ws.wsgen.WsGen"; 49 50 51 private File destination = null; 52 53 54 private File source = null; 55 56 57 private boolean validation = true; 58 59 60 private String javac = null; 61 62 63 private String javac_opts = null; 64 65 66 private boolean keep_gen = false; 67 68 69 private boolean no_config = false; 70 71 72 private boolean verbose = false; 73 74 75 private boolean debug = false; 76 77 78 private boolean jvmDebug = false; 79 80 81 private File jonas_root = null; 82 83 84 private File jonas_base = null; 85 86 public void setDestdir(File d) { 87 destination = d; 88 } 89 90 public void setSrcdir(File s) { 91 source = s; 92 } 93 94 public void setValidation(boolean v) { 95 validation = v; 96 } 97 98 public void setJavac(String j) { 99 javac = j; 100 } 101 102 public void setJavacopts(String opts) { 103 javac_opts = opts; 104 } 105 106 public void setKeepgen(boolean k) { 107 keep_gen = k; 108 } 109 110 public void setNoconfig(boolean c) { 111 no_config = c; 112 } 113 114 public void setVerbose(boolean v) { 115 verbose = v; 116 } 117 118 public void setDebug(boolean b) { 119 debug = b; 120 } 121 122 126 public void setJvmdebug(boolean d) { 127 jvmDebug = d; 128 } 129 130 public void setJonasroot(File jr) { 131 jonas_root = jr; 132 } 133 134 public void setJonasbase(File jb) { 135 jonas_base = jb; 136 } 137 138 141 public void execute() throws BuildException { 142 143 initWsGenTask(); 145 146 DirectoryScanner ds = getDirectoryScanner(source); 148 ds.scan(); 149 String [] files = ds.getIncludedFiles(); 150 151 for (int i = 0; i < files.length; i++) { 152 153 Java wsgen = createWsGen(source + File.separator + files[i]); 154 155 log("Calling WsGen task for '" + source + File.separator + files[i] + "'.", Project.MSG_VERBOSE); 157 158 if (wsgen.executeJava() != 0) { 159 throw new BuildException("WsGen reported an error."); 160 } 161 } 162 163 } 164 165 private Java createWsGen(String filename) throws BuildException { 166 167 Java wsgenTask = null; boolean error = false; 170 wsgenTask = (Java) getProject().createTask("java"); 171 wsgenTask.setTaskName("wsgen"); 172 wsgenTask.setFork(true); 173 174 wsgenTask.createJvmarg().setValue("-Dinstall.root=" + jonas_root); 176 177 wsgenTask.createJvmarg().setValue("-Djonas.base=" + jonas_base); 179 180 File endorsedDir = new File (new File (jonas_root, "lib"), "endorsed"); 182 wsgenTask.createJvmarg().setValue("-Djava.endorsed.dirs=" + endorsedDir); 183 184 String jonasConfigDir = jonas_root + File.separator + "conf"; 186 File javaPolicyFile = new File (jonasConfigDir, "java.policy"); 187 if (javaPolicyFile.exists()) { 188 wsgenTask.createJvmarg().setValue("-Djava.security.policy=" 189 + javaPolicyFile.toString()); 190 } 191 192 if (jvmDebug) { 194 wsgenTask.createJvmarg().setLine("-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=12345,suspend=y"); 195 } 196 197 wsgenTask.createArg().setValue(WSGEN_CLASS); 199 200 wsgenTask.createArg().setValue("-d"); 201 wsgenTask.createArg().setFile(destination); 202 203 String bootJar = jonas_root + File.separator + "lib" + File.separator + "common" 205 + File.separator + "ow_jonas_bootstrap.jar"; 206 Path classpath = new Path(getProject(), bootJar); 207 208 log("Using classpath: " + classpath.toString(), Project.MSG_VERBOSE); 209 wsgenTask.setClasspath(classpath); 210 211 if (!checkBootstrapClassName(classpath)) { 212 log("Cannot find bootstrap class in classpath.", Project.MSG_ERR); 213 throw new BuildException("Bootstrap class not found, please check the classpath."); 214 } else { 215 wsgenTask.setClassname(BOOTSTRAP_CLASS); 216 } 217 218 if (keep_gen) { 220 wsgenTask.createArg().setValue("-keepgenerated"); 221 } 222 223 if (no_config) { 225 wsgenTask.createArg().setValue("-noconfig"); 226 } 227 228 if (!validation) { 230 wsgenTask.createArg().setValue("-novalidation"); 231 } 232 233 if (javac != null) { 235 wsgenTask.createArg().setValue("-javac"); 236 wsgenTask.createArg().setLine(javac); 237 } 238 239 if (javac_opts != null && !javac_opts.equals("")) { 241 wsgenTask.createArg().setValue("-javacopts"); 242 wsgenTask.createArg().setLine(javac_opts); 243 } 244 245 if (verbose) { 247 wsgenTask.createArg().setValue("-verbose"); 248 } 249 250 if (debug) { 252 wsgenTask.createArg().setValue("-debug"); 253 } 254 255 wsgenTask.createArg().setValue(filename); 257 258 return wsgenTask; 259 260 } 261 262 private void initWsGenTask() throws BuildException { 263 if (jonas_root == null ) { 265 String jr = getProject().getProperty("jonas.root"); 267 jonas_root = new File (jr); 268 269 if (jr == null) { 270 throw new BuildException("attribute jonasroot is necessary."); 271 } 272 } 273 274 if (jonas_base == null) { 276 String jb = getProject().getProperty("jonas.base"); 277 if (jb == null) { 278 jonas_base = jonas_root; 279 } else { 280 jonas_base = new File (jb); 281 } 282 283 } 284 285 if (destination == null) { 287 destination = getProject().getBaseDir(); 288 } 289 290 293 } 294 300 private boolean checkBootstrapClassName(Path classpath) { 301 log("Looking for bootstrap class in classpath: " + classpath.toString(), Project.MSG_VERBOSE); 302 AntClassLoader cl = new AntClassLoader(classpath.getProject(), classpath); 303 try { 304 cl.loadClass(BOOTSTRAP_CLASS); 305 log("Found Bootstrap class '" + BOOTSTRAP_CLASS 306 + "' in classpath.", Project.MSG_VERBOSE); 307 } catch (ClassNotFoundException cnf1) { 308 log("Bootstrap class '" + BOOTSTRAP_CLASS 309 + "' not found in classpath.", Project.MSG_VERBOSE); 310 return false; 311 } 312 return true; 313 } 314 315 } 316 | Popular Tags |