1 21 22 package org.apache.derbyTesting.functionTests.tests.tools; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.lang.Process ; 27 import java.lang.Runtime ; 28 import java.lang.SecurityException ; 29 import java.net.URL ; 30 import java.security.CodeSource ; 31 import java.util.Vector ; 32 33 import org.apache.derbyTesting.functionTests.harness.BackgroundStreamSaver; 34 import org.apache.derbyTesting.functionTests.harness.jvm; 35 36 public class derbyrunjartest { 37 38 public static void main(String [] args) throws Exception 39 { 40 CodeSource cs = null; 42 try { 43 cs = org.apache.derby.iapi.tools.run.class.getProtectionDomain().getCodeSource(); 44 } catch (SecurityException se) { 45 System.out.println("Security exception: " + se.getMessage()); 46 } 47 48 URL result = cs.getLocation(); 49 jvm jvm = null; 50 String derbyrunloc = null; 51 52 if (result.toString().endsWith(".jar")) { 53 derbyrunloc = result.toString().substring(5); 54 if (System.getProperty("os.name").startsWith("Windows")) 55 derbyrunloc = derbyrunloc.substring(1); 56 57 if ((System.getProperty("java.vm.name") != null) && 58 System.getProperty("java.vm.name").equals("J9")) { 59 jvm = jvm.getJvm("j9_13"); 60 } else { 61 jvm = jvm.getJvm("currentjvm"); } 63 } 64 65 String [][] testCommands = new String [][] { 66 {"ij", "--help"}, 67 {"sysinfo", "-cp", "help"}, 68 {"dblook"}, 69 {"server"}, 70 }; 71 72 for (int i = 0; i < testCommands.length; i++) { 73 runtool(jvm, derbyrunloc, testCommands[i]); 74 } 75 } 76 77 private static void runtool(jvm jvm, String loc, String [] args) 78 throws IOException 79 { 80 System.out.println(concatenate(args) + ':'); 81 82 if (jvm == null) { 83 org.apache.derby.iapi.tools.run.main(args); 84 return; 85 } 86 87 Vector cmd = jvm.getCommandLine(); 88 cmd.addElement("-jar"); 89 cmd.addElement(loc); 90 for (int i=0; i < args.length; i++) { 91 cmd.addElement(args[i]); 92 } 93 String command = concatenate((String []) cmd.toArray(new String [0])); 94 95 Process pr = null; 96 97 try 98 { 99 pr = Runtime.getRuntime().exec(command); 100 BackgroundStreamSaver saver = 101 new BackgroundStreamSaver(pr.getInputStream(), System.out); 102 saver.finish(); 103 pr.waitFor(); 104 pr.destroy(); 105 } catch(Throwable t) { 106 System.out.println("Process exception: " + t.getMessage()); 107 if (pr != null) 108 { 109 pr.destroy(); 110 pr = null; 111 } 112 } 113 } 114 115 private static String concatenate(String [] args) { 116 StringBuffer buf = new StringBuffer (); 117 for (int i = 0; i < args.length; i++) { 118 buf.append(args[i]); 119 if (i + 1 < args.length) buf.append(' '); 120 } 121 return buf.toString(); 122 } 123 } 124 | Popular Tags |