1 23 24 34 35 package com.sun.ejb.codegen; 36 37 import java.util.*; 38 import java.io.*; 39 import java.util.logging.Level ; 40 import com.sun.enterprise.util.OS; 41 import com.sun.enterprise.util.io.FileUtils; 42 import com.sun.enterprise.server.Constants; 43 import sun.rmi.rmic.Main; 44 45 class RMICompiler extends Compiler 46 { 47 private static final String RMIC_EXT_DIRS_OPTION = "-extdirs"; 48 49 RMICompiler(List theOptions, List theFiles) throws JavaCompilerException 50 { 51 super(theOptions, theFiles); 52 } 53 54 56 void setClasspath(String cp) 57 { 58 classpath = cp; 59 } 60 61 63 protected void internal_compile() throws JavaCompilerException, ProcessExecutorException 64 { 65 try 66 { 67 if(nativeExternalCompile()) 68 return; 69 } 70 catch(Throwable t) 71 { 72 logger.log(Level.WARNING, 73 "ejb.rmic_compilation_exception", t); 74 } 80 81 nativeCompile(); 82 } 83 84 86 private boolean nativeExternalCompile() throws ProcessExecutorException 87 { 88 if(classpath == null || javaExe == null) 89 return false; 90 91 92 ArrayList cmd = new ArrayList(); 93 cmd.add(javaExe.getPath()); 94 cmd.add("-classpath"); 95 cmd.add(classpath); 96 if (OS.isDarwin()) { 97 cmd.add("-Djava.endorsed.dirs=" + System.getProperty("com.sun.aas.installRoot") + 99 File.separatorChar + "lib" + File.separatorChar + "endorsed"); 100 } 101 cmd.add("-D" + JAVA_EXT_DIRS_SYS_PROP + "=" 102 + System.getProperty(JAVA_EXT_DIRS_SYS_PROP)); 103 cmd.add("sun.rmi.rmic.Main"); 104 cmd.addAll(options); 105 addJavaFiles(cmd); 106 String [] cmds = new String [cmd.size()]; 107 cmds = (String [])cmd.toArray(cmds); 108 109 runProcess(cmds, getRmicTimeout() * files.size()); 110 logCompilerName("rmic in external JVM"); 111 return true; 112 } 113 114 116 135 136 138 private void nativeCompile() throws JavaCompilerException 139 { 140 options.add(RMIC_EXT_DIRS_OPTION); 143 options.add(System.getProperty(JAVA_EXT_DIRS_SYS_PROP)); 144 options.addAll(files); 145 String [] cmds = new String [options.size()]; 146 cmds = (String [])options.toArray(cmds); 147 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 148 149 Main compiler = new Main(baos, "rmic"); 150 boolean good = compiler.compile(cmds); 151 153 String output = baos.toString(); 154 parseGeneratedFilenames(output); 155 156 if(!good) 157 { 158 throw new JavaCompilerException("rmi_compiler.error", 159 "RMI compiler returned an error: {0}", output); 160 } 161 162 logCompilerName("native rmic (sun.rmi.rmic.Main)"); 163 } 164 165 167 protected void internal_init() 168 { 169 rmicExe = null; 170 javaExe = null; 171 String rmicName, javaName; 172 173 if(jdkDir == null) 174 return; 175 176 if(OS.isWindows()) 177 { 178 rmicName = "rmic.exe"; 179 javaName = "java.exe"; 180 } 181 else 182 { 183 rmicName = "rmic"; 184 javaName = "java"; 185 } 186 187 rmicExe = new File(jdkDir + "/bin/" + rmicName); 189 190 if(rmicExe.exists()) 191 rmicExe = FileUtils.safeGetCanonicalFile(rmicExe); 192 else 193 rmicExe = null; 194 195 javaExe = new File(jdkDir + "/bin/" + javaName); 197 198 if(javaExe.exists()) 199 javaExe = FileUtils.safeGetCanonicalFile(javaExe); 200 else 201 javaExe = null; 202 203 logger.log(Level.FINE, "[RMICompiler] after internal_init: " 204 + "javaExe: " + javaExe + "; rmicExe: " + rmicExe); 205 } 206 207 222 private static int getRmicTimeout() 223 { 224 if(timeout < 0 ) 225 { 226 timeout = getTimeout(Constants.RMIC_TIMEOUT_MS, Constants.DEFAULT_RMIC_TIMEOUT_MS, 5000, 300000); 227 } 228 return timeout; 229 } 230 231 241 private void parseGeneratedFilenames(String s) 242 { 243 generatedFilenames = new HashSet(); 244 245 StringTokenizer tk = new StringTokenizer(s); 246 247 while(tk.hasMoreTokens()) 248 { 249 String token = tk.nextToken(); 250 251 if(token.equals("[generated") && tk.hasMoreTokens()) 252 { 253 String fName = tk.nextToken(); 254 generatedFilenames.add(fName); 255 logger.log(Level.FINER, "[RMIC] Generated: " + fName); 256 } 257 } 258 } 259 260 Set getGeneratedFilenames() 261 { 262 return generatedFilenames; 263 } 264 265 267 private File rmicExe, javaExe; 268 private Set generatedFilenames = null; 269 private String classpath = null; 270 private static int timeout = -1; 271 } 272 | Popular Tags |