1 package org.jacorb.test.common.launch; 2 3 23 24 import java.io.*; 25 import java.util.*; 26 import java.util.regex.*; 27 import java.lang.reflect.*; 28 29 import org.jacorb.test.common.*; 30 31 41 public abstract class JacORBLauncher 42 { 43 private static Map launchers; 44 private static Properties testProperties; 45 private static List versions; 46 47 protected String jacorbHome; 48 protected boolean coverage; 49 50 protected JacORBLauncher (String jacorbHome, boolean coverage) 51 { 52 this.jacorbHome = jacorbHome; 53 this.coverage = coverage; 54 } 55 56 public abstract Process launch (String classpath, 57 Properties props, 58 String mainClass, 59 String [] args); 60 61 public String getJacorbHome() 62 { 63 return jacorbHome; 64 } 65 66 public List propsToArgList (Properties props) 67 { 68 List result = new ArrayList(); 69 70 if (props == null) return result; 71 72 for (Iterator i = props.keySet().iterator(); i.hasNext();) 73 { 74 String key = (String )i.next(); 75 String value = props.getProperty(key); 76 result.add ("-D" + key + "=" + value); 77 } 78 79 return result; 80 } 81 82 public String [] toStringArray (List l) 83 { 84 return ((String [])l.toArray (new String [0])); 85 } 86 87 91 public static Properties getTestProperties() 92 { 93 if (testProperties == null) 94 { 95 try 96 { 97 InputStream in = new FileInputStream 98 ( 99 TestUtils.testHome() + "/test.properties" 100 ); 101 testProperties = new Properties(); 102 testProperties.load (in); 103 } 104 catch (IOException ex) 105 { 106 testProperties = null; 107 throw new RuntimeException (ex); 108 } 109 } 110 return testProperties; 111 } 112 113 116 public static List getVersions() 117 { 118 if (versions == null) 119 { 120 versions = new ArrayList(); 121 for (int i=0; ; i++) 122 { 123 String key = "jacorb.test.jacorb_version." + i + ".id"; 124 String value = getTestProperties().getProperty(key); 125 if (value == null) break; 126 versions.add (value); 127 } 128 } 129 return versions; 130 } 131 132 137 public static JacORBLauncher getLauncher (String version, 138 boolean coverage) 139 { 140 int index = getVersions().indexOf (version); 141 if (index == -1) throw new RuntimeException 142 ( 143 "JacORB version " + version + " not available" 144 ); 145 String key = "jacorb.test.jacorb_version." + index + ".home"; 146 String home = getTestProperties().getProperty(key); 147 if (home == null) 148 { 149 if (version.equals("cvs")) 150 home = getCVSHome(); 151 else 152 throw new RuntimeException 153 ( 154 "No home directory for JacORB version " + version 155 ); 156 } 157 key = "jacorb.test.jacorb_version." + index + ".launcher"; 158 String launcherClassName = getTestProperties().getProperty(key); 159 if (launcherClassName == null) throw new RuntimeException 160 ( 161 "No launcher class defined for JacORB version " + version 162 ); 163 try 164 { 165 Class launcherClass = Class.forName (launcherClassName); 166 Constructor c = launcherClass.getConstructor 167 ( 168 new Class [] { java.lang.String .class, 169 boolean.class } 170 ); 171 return (JacORBLauncher)c.newInstance 172 ( 173 new Object [] { home, new Boolean (coverage) } 174 ); 175 } 176 catch (Exception ex) 177 { 178 throw new RuntimeException (ex); 179 } 180 } 181 182 private static String getCVSHome() 183 { 184 String testHome = TestUtils.testHome(); 185 Pattern homePattern = Pattern.compile 186 ( 187 "^(.*?)/test/regression" 188 ); 189 Matcher m = homePattern.matcher (testHome); 190 if (m.matches()) 191 return m.group(1); 192 else 193 throw new RuntimeException ("couldn't find CVS home: " 194 + testHome); 195 } 196 197 } 198 | Popular Tags |