1 26 package org.objectweb.jonas.ant; 27 28 import java.io.File ; 29 30 import org.apache.tools.ant.BuildException; 31 import org.apache.tools.ant.Task; 32 import org.apache.tools.ant.taskdefs.Java; 33 import org.apache.tools.ant.types.Path; 34 35 41 public abstract class BootstrapTask extends Task { 42 43 46 private static final String BOOTSTRAP_CLASS = "org.objectweb.jonas.server.Bootstrap"; 47 48 51 private static final String DEFAULT_SERVER_NAME = "jonas"; 52 53 56 private String taskName = "JOnAS"; 57 58 61 private File jonasRoot = null; 62 63 66 private String serverName = DEFAULT_SERVER_NAME; 67 68 71 private File jonasBase = null; 72 73 76 private String catalinaHome = null; 77 78 81 private String jettyHome = null; 82 83 86 private String jvmOpts = null; 87 88 91 private Path classpath = null; 92 93 97 public void setJonasRoot(File jonasRoot) { 98 this.jonasRoot = jonasRoot; 99 } 100 101 105 public void setJonasbase(File jonasBase) { 106 this.jonasBase = jonasBase; 107 } 108 109 113 public void setJvmopts(String jvmOpts) { 114 this.jvmOpts = jvmOpts; 115 } 116 117 121 public Path createClasspath() { 122 return new Path(getProject()); 123 } 124 125 129 public void setClasspath(Path classpath) { 130 this.classpath = classpath; 131 } 132 133 137 protected Java getBootstraptask(String definedClass) { 138 139 if (jonasRoot == null) { 140 String jr = getProject().getProperty("jonas.root"); 142 jonasRoot = new File (jr); 143 144 if (jr == null) { 145 throw new BuildException("attribute jonasroot is necessary."); 146 } 147 } 148 149 if (jonasBase == null) { 150 jonasBase = jonasRoot; 151 } 152 153 Java bootstrapTask = (Java) getProject().createTask("java"); 154 bootstrapTask.setTaskName(taskName); 155 bootstrapTask.setFork(true); 156 bootstrapTask.setFailonerror(true); 157 158 bootstrapTask.createJvmarg().setValue("-Djonas.name=" + serverName); 160 161 bootstrapTask.createJvmarg().setValue("-Dinstall.root=" + jonasRoot); 163 164 bootstrapTask.createJvmarg().setValue("-Djonas.base=" + jonasBase); 166 167 bootstrapTask.createJvmarg().setValue("-Djonas.default.classloader=true"); 169 bootstrapTask.createJvmarg().setValue("-Djonas.classpath="); 170 bootstrapTask.createJvmarg().setValue( 171 "-Djava.naming.factory.initial=org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory"); 172 173 File jonasLibDir = new File (jonasRoot, "lib"); 175 File jonasLibEndorsedDir = new File (jonasLibDir, "endorsed"); 176 bootstrapTask.createJvmarg().setValue( 177 "-Djavax.rmi.CORBA.PortableRemoteObjectClass=org.objectweb.carol.rmi.multi.MultiPRODelegate"); 178 bootstrapTask.createJvmarg().setValue( 179 "-Djava.naming.factory.initial=org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory"); 180 bootstrapTask.createJvmarg().setValue("-Djava.endorsed.dirs=" + jonasLibEndorsedDir.getPath()); 181 182 bootstrapTask.createJvmarg().setValue( 184 "-Djava.rmi.server.RMIClassLoaderSpi=org.objectweb.jonas.server.RemoteClassLoaderSpi"); 185 186 if (catalinaHome != null) { 188 bootstrapTask.createJvmarg().setValue("-Dcatalina.home=" + catalinaHome); 189 } 190 bootstrapTask.createJvmarg().setValue("-Dcatalina.base=" + jonasBase); 191 192 if (jettyHome != null) { 193 bootstrapTask.createJvmarg().setValue("-Djetty.home=" + jettyHome); 194 } 195 196 String jonasConfigDir = jonasBase + File.separator + "conf"; 198 File javaPolicyFile = new File (jonasConfigDir, "java.policy"); 199 if (javaPolicyFile.exists()) { 200 bootstrapTask.createJvmarg().setValue("-Djava.security.policy=" + javaPolicyFile.getPath()); 201 } 202 File javaAuthLoginFile = new File (jonasConfigDir, "jaas.config"); 203 bootstrapTask.createJvmarg().setValue("-Djava.security.auth.login.config=" + javaAuthLoginFile.getPath()); 204 205 bootstrapTask.createArg().setValue(definedClass); 207 208 classpath = new Path(getProject(), jonasConfigDir); 210 211 String bootJar = jonasRoot + File.separator + "lib" + File.separator + "common" + File.separator 213 + "ow_jonas_bootstrap.jar"; 214 classpath.append(new Path(getProject(), bootJar)); 215 216 String toolsJar = System.getProperty("java.home") + File.separator + ".." + File.separator + "lib" 218 + File.separator + "tools.jar"; 219 classpath.append(new Path(getProject(), toolsJar)); 220 221 bootstrapTask.setClasspath(classpath); 223 224 bootstrapTask.setClassname(BOOTSTRAP_CLASS); 226 227 if (jvmOpts != null && !jvmOpts.equals("")) { 229 bootstrapTask.createJvmarg().setLine(jvmOpts); 230 } 231 232 if (serverName != null) { 234 bootstrapTask.createArg().setValue("-n"); 235 bootstrapTask.createArg().setValue(getServerName()); 236 } 237 238 return bootstrapTask; 239 240 } 241 242 245 public String getTaskName() { 246 return taskName; 247 } 248 249 253 public void setTaskName(String taskName) { 254 this.taskName = taskName; 255 } 256 257 260 public String getServerName() { 261 return serverName; 262 } 263 264 268 public void setServerName(String serverName) { 269 this.serverName = serverName; 270 } 271 272 275 public String getCatalinaHome() { 276 return catalinaHome; 277 } 278 279 283 public void setCatalinaHome(String catalinaHome) { 284 this.catalinaHome = catalinaHome; 285 } 286 287 290 public String getJettyHome() { 291 return jettyHome; 292 } 293 294 298 public void setJettyHome(String jettyHome) { 299 this.jettyHome = jettyHome; 300 } 301 304 public File getJonasRoot() { 305 return jonasRoot; 306 } 307 308 } | Popular Tags |