1 21 22 package org.apache.derbyTesting.functionTests.harness; 23 24 import java.util.Enumeration ; 25 import java.util.Properties ; 26 import java.util.Vector ; 27 import java.util.StringTokenizer ; 28 import java.io.File ; 29 import java.io.IOException ; 30 31 import org.apache.derby.impl.tools.sysinfo.ZipInfoProperties; 32 import org.apache.derbyTesting.junit.SecurityManagerSetup; 33 34 35 68 69 70 public abstract class jvm { 71 72 76 public String flags = null; 78 public boolean noasyncgc = false; 80 public boolean verbosegc = false; 82 public boolean noclassgc = false; 84 public long ss = -1; 86 public long oss = -1; 88 public long ms = -1; 90 public long mx = -1; 92 public String classpath = null; 95 public String prof = null; 97 public boolean verify = false; 100 public boolean noverify = false; 103 public boolean nojit = false; 105 public Vector D = null; 107 public String javaCmd = "java"; 109 public String majorVersion = ""; 111 public String minorVersion = ""; 112 public int imajor = 0; 113 public int iminor = 0; 114 String hostName; 115 116 private static String DEFAULT_POLICY="util/derby_tests.policy"; 119 private static String DEFAULT_CODEBASE="/classes"; 120 121 public jvm() { } 123 124 public jvm(boolean noasyncgc, boolean verbosegc, boolean noclassgc, 125 long ss, long oss, long ms, long mx, String classpath, String prof, 126 boolean verify, boolean noverify, boolean nojit, Vector D) { 127 this.noasyncgc=noasyncgc; 128 this.noclassgc=noclassgc; 129 this.verbosegc=verbosegc; 130 this.ss=ss; 131 this.oss=oss; 132 this.ms=ms; 133 this.mx=mx; 134 this.classpath=classpath; 135 this.prof=prof; 136 this.verify=verify; 137 this.noverify=noverify; 138 this.nojit=nojit; 139 this.D=D; 140 } 141 public jvm(String classpath, Vector D) { 143 this.classpath=classpath; 144 this.D=D; 145 } 146 public jvm(long ms, long mx, String classpath, Vector D) { 148 this.ms=ms; 149 this.mx=mx; 150 this.classpath=classpath; 151 this.D=D; 152 } 153 154 158 public abstract String getDintro(); 159 public abstract String getName(); 160 public void setNoasyncgc(boolean noasyncgc) { this.noasyncgc=noasyncgc; } 161 public void setNoclassgc(boolean noclassgc) { this.noclassgc=noclassgc; } 162 public void setVerbosegc(boolean verbosegc) { this.verbosegc=verbosegc; } 163 public void setSs(long ss) { this.ss=ss; } 164 public void setOss(long oss) { this.oss=oss; } 165 public void setMs(long ms) { this.ms = ms; } 166 public void setMx(long mx) { this.mx = mx; } 167 public void setClasspath(String classpath) { this.classpath = classpath; } 168 public void setProf(String prof) { this.prof=prof; } 169 public void setVerify(boolean verify) { this.verify=verify; } 170 public void setNoverify(boolean noverify) { this.noverify=noverify; } 171 public void setNojit(boolean nojit) { this.nojit=nojit; } 172 public void setD(Vector D) { this.D = D; } 173 public void setFlags(String flags) { this.flags = flags; } 174 public void setJavaCmd(String jcmd) { this.javaCmd = jcmd; } 175 176 177 public Vector getCommandLine() 178 { 179 Vector v = new Vector (); 180 v.addElement(javaCmd); 181 v.addElement("-Duser.language=en"); 182 v.addElement("-Duser.country=US"); 183 if ( (flags != null) && (flags.length()>0) ) 184 { 185 StringTokenizer st = new StringTokenizer (flags); 186 while (st.hasMoreTokens()) 187 { 188 v.addElement(st.nextToken()); 189 } 190 } 191 return v; 192 } 193 194 int verboselevel = -1; 196 public void warn(String msg) { 197 if (verboselevel == -1) { 198 try { 199 verboselevel = Integer.parseInt((String )(System.getProperty("verbose"))); 200 } catch (Exception e) { 201 verboselevel = 0; 202 } 203 } 204 if (verboselevel >0) 205 System.out.println("jvm: "+msg); 206 } 207 208 213 public static jvm getJvm(String jvmName) throws ClassNotFoundException , InstantiationException , IllegalAccessException { 214 jvm result = null; 215 try { 216 result = (jvm)Class.forName(jvmName).newInstance(); 217 } catch (ClassNotFoundException e) { 218 result = (jvm)Class.forName("org.apache.derbyTesting.functionTests.harness."+jvmName).newInstance(); 219 } 220 return result; 221 } 222 223 232 public static jvm getCurrentJvm() throws Exception 233 { 234 String jvmName = System.getProperty("jvm"); 235 if ( (jvmName == null) || (jvmName.length()==0) ) 236 { 237 String javaVersion = System.getProperty("java.version"); 238 if (javaVersion.startsWith("1.2")) 239 jvmName = "jdk12"; 240 else 241 jvmName = "currentjvm"; 242 } 243 return getJvm(jvmName); 244 } 245 246 249 public int getMajorVersion() 250 { 251 return imajor; 252 } 253 254 257 public int getMinorVersion() 258 { 259 return iminor; 260 } 261 262 266 public void setVersion() throws Exception 267 { 268 String javaVersion = System.getProperty("java.version"); 270 int i = javaVersion.indexOf('.'); 271 int j = javaVersion.indexOf('.', i+1); 272 majorVersion = javaVersion.substring(0, i); 273 minorVersion = javaVersion.substring(i+1, j); 274 Integer minor = new Integer (minorVersion); 275 iminor = minor.intValue(); 276 Integer major = new Integer (majorVersion); 277 imajor = major.intValue(); 278 279 String jvmName = System.getProperty("jvm"); 280 281 if ( (jvmName == null) || (jvmName.length()==0) ) 282 { 283 if (iminor < 2) 284 jvmName = "currentjvm"; 285 else 286 jvmName = "jdk" + majorVersion + minorVersion; 287 } 288 } 289 290 294 protected static String guessWSHome() 295 { 296 String wshome=""; 297 String jhome = System.getProperty("java.home"); 298 String sep = System.getProperty("file.separator"); 299 wshome = jhome.substring(0,jhome.indexOf(sep + "jre")); 302 wshome = wshome.substring(0,wshome.lastIndexOf(sep)); 303 return wshome; 304 } 305 306 public static String findCodeBase(boolean[] isJar) 307 { 308 String classpath = System.getProperty("java.class.path"); 309 char sep = '/'; 310 ZipInfoProperties zip[]= 311 org.apache.derby.impl.tools.sysinfo.Main.getAllInfo (classpath); 312 for (int i = 0; i < zip.length; i++) 313 { 314 String location = zip[i].getLocation().replace('\\','/'); 316 if (location.indexOf("derbynet.jar") != -1) 317 { 318 isJar[0] = true; 319 return location.substring(0,location.lastIndexOf(sep)); 320 } 321 else if ((location.indexOf("classes") != -1) && 322 location.indexOf(".jar") == -1) 323 { 324 isJar[0] = false; 325 return location; 326 } 327 } 328 return null; 329 } 330 331 334 protected void setSecurityProps() throws java.io.IOException , ClassNotFoundException 335 { 336 D = jvm.getSecurityProps(D); 337 338 } 339 340 static Vector getSecurityProps(Vector D) throws ClassNotFoundException , IOException 341 { 342 if (D == null) 343 D = new Vector (); 344 345 String userDir = System.getProperty("user.dir"); 346 String policyFile = userDir + baseName(DEFAULT_POLICY); 347 348 String serverCodeBase = System.getProperty("serverCodeBase"); 349 boolean[] isJar = new boolean[1]; 350 if (serverCodeBase == null) 351 serverCodeBase = findCodeBase(isJar); 352 353 354 if (serverCodeBase == null) 355 { 356 String ws = guessWSHome(); 357 serverCodeBase = ws + DEFAULT_CODEBASE; 358 359 } 360 361 File pf = new File (policyFile); 362 File cb = new File (serverCodeBase); 363 364 if (!pf.exists()) 365 { 366 System.out.println("WARNING: Running without Security manager." + 367 "policy File (" + policyFile + 368 ") or serverCodeBase(" + serverCodeBase + 369 ") not available"); 370 return D; 371 } 372 373 D.addElement("java.security.manager"); 374 D.addElement("java.security.policy=" + pf.getAbsolutePath()); 375 376 Properties jusetup = 377 SecurityManagerSetup.getPolicyFilePropertiesForOldHarness(); 378 for (Enumeration p = jusetup.keys(); p.hasMoreElements(); ) 382 { 383 String key = (String ) p.nextElement(); 384 D.addElement(key + "=" + jusetup.getProperty(key)); 385 } 386 387 388 D.addElement("derbyTesting.codedir=" + cb.getAbsolutePath()); 390 String hostName = (System.getProperty("hostName")); 391 if (hostName == null) 392 hostName="localhost"; 393 D.addElement("derbyTesting.serverhost=" + hostName); 394 D.addElement("derbyTesting.clienthost=" + hostName); 397 398 return D; 399 400 } 401 402 406 private static String baseName(String resourceName) 407 { 408 409 return resourceName.substring(resourceName.lastIndexOf("/"),resourceName.length()); 410 } 411 } 412 | Popular Tags |