1 20 package org.apache.cactus.integration.ant.container; 21 22 import java.io.File ; 23 import java.io.FileNotFoundException ; 24 25 import org.apache.tools.ant.taskdefs.Java; 26 import org.apache.tools.ant.types.Path; 27 import org.apache.tools.ant.types.Environment.Variable; 28 29 35 public abstract class AbstractJavaContainer extends AbstractContainer 36 { 37 39 42 private File output; 43 44 48 private boolean append; 49 50 51 54 private String jvmArgs; 55 56 58 63 public final void setOutput(File theOutput) 64 { 65 this.output = theOutput; 66 } 67 68 74 public final void setAppend(boolean isAppend) 75 { 76 this.append = isAppend; 77 } 78 79 80 85 public final void setJVMArgs(String theJVMArgs) 86 { 87 this.jvmArgs = theJVMArgs; 88 } 89 90 92 98 protected final Java createJavaForShutDown() 99 { 100 Java java = (Java) createAntTask("java"); 101 java.setFork(true); 102 103 addExtraClasspath(java); 105 106 return java; 107 } 108 109 115 protected final Java createJavaForStartUp() 116 { 117 Java java = (Java) createAntTask("java"); 118 java.setFork(true); 119 java.setOutput(this.output); 120 java.setAppend(this.append); 121 122 if (this.jvmArgs != null) 124 { 125 getLog().trace( 126 "Passing arguments to the container JVM: " + this.jvmArgs); 127 java.createJvmarg().setLine(this.jvmArgs); 128 } 129 130 addExtraClasspath(java); 132 133 if (getSystemProperties() != null) 135 { 136 for (int i = 0; i < getSystemProperties().length; i++) 137 { 138 java.addSysproperty( 139 createSysProperty(getSystemProperties()[i].getKey(), 140 getSystemProperties()[i].getValue())); 141 } 142 } 143 144 return java; 145 } 146 147 152 private void addExtraClasspath(Java theJavaCommand) 153 { 154 Path classpath = theJavaCommand.createClasspath(); 155 if (getContainerClasspath() != null) 156 { 157 classpath.addExisting(getContainerClasspath()); 158 } 159 } 160 161 169 protected final Variable createSysProperty(String theKey, File theFile) 170 { 171 Variable var = new Variable(); 172 var.setKey(theKey); 173 var.setFile(theFile); 174 return var; 175 } 176 177 185 protected final Variable createSysProperty(String theKey, Path thePath) 186 { 187 Variable var = new Variable(); 188 var.setKey(theKey); 189 var.setPath(thePath); 190 return var; 191 } 192 193 201 protected final Variable createSysProperty(String theKey, String theValue) 202 { 203 Variable var = new Variable(); 204 var.setKey(theKey); 205 var.setValue(theValue); 206 return var; 207 } 208 209 217 protected final File getToolsJar() throws FileNotFoundException 218 { 219 String javaHome = System.getProperty("java.home"); 220 File toolsJar = new File (javaHome, "../lib/tools.jar"); 221 if (!toolsJar.isFile()) 222 { 223 throw new FileNotFoundException (toolsJar.getAbsolutePath()); 224 } 225 return toolsJar; 226 } 227 228 234 protected final void addToolsJarToClasspath(Path theClasspath) 235 { 236 if (!isOSX()) 239 { 240 try 241 { 242 theClasspath.createPathElement().setLocation(getToolsJar()); 243 } 244 catch (FileNotFoundException fnfe) 245 { 246 getLog().warn( 247 "Couldn't find tools.jar (needed for JSP compilation)"); 248 } 249 } 250 } 251 252 255 protected final String getJVMArgs() 256 { 257 return this.jvmArgs; 258 } 259 260 262 269 private boolean isOSX() 270 { 271 return (System.getProperty("mrj.version") != null); 272 } 273 274 } 275 | Popular Tags |