protected void runScript(String[] cmd, JTextArea txaMsg) { String strg = ""; if (cmd == null) return; Process prcs = null; try { Messages.postDebug("Running script: " + cmd[2]); Runtime rt = Runtime.getRuntime(); prcs = rt.exec(cmd); if (prcs == null) return; InputStream istrm = prcs.getInputStream(); if (istrm == null) return; BufferedReader bfr = new BufferedReader(new InputStreamReader(istrm)); while ((strg = bfr.readLine()) != null) { // System.out.println(strg); strg = strg.trim(); // Messages.postDebug(strg); strg = strg.toLowerCase(); if (txaMsg != null) { txaMsg.append(strg); txaMsg.append("\n"); } } } catch (Exception e) { // e.printStackTrace(); Messages.writeStackTrace(e); Messages.postDebug(e.toString()); } finally { // It is my understanding that these streams are left // open sometimes depending on the garbage collector. // So, close them. try { if (prcs != null) { OutputStream os = prcs.getOutputStream(); if (os != null) os.close(); InputStream is = prcs.getInputStream(); if (is != null) is.close(); is = prcs.getErrorStream(); if (is != null) is.close(); } } catch (Exception ex) { Messages.writeStackTrace(ex); } } }
// Creates a new thread, runs the program in that thread, and reports any errors as needed. private void run(String clazz) { try { // Makes sure the JVM resets if it's already running. if (JVMrunning) kill(); // Some String constants for java path and OS-specific separators. String separator = System.getProperty("file.separator"); String path = System.getProperty("java.home") + separator + "bin" + separator + "java"; // Tries to run compiled code. ProcessBuilder builder = new ProcessBuilder(path, clazz); // Should be good now! Everything past this is on you. Don't mess it up. println( "Build succeeded on " + java.util.Calendar.getInstance().getTime().toString(), progErr); println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", progErr); JVM = builder.start(); // Note that as of right now, there is no support for input. Only output. Reader errorReader = new InputStreamReader(JVM.getErrorStream()); Reader outReader = new InputStreamReader(JVM.getInputStream()); // Writer inReader = new OutputStreamWriter(JVM.getOutputStream()); redirectErr = redirectIOStream(errorReader, err); redirectOut = redirectIOStream(outReader, out); // redirectIn = redirectIOStream(null, inReader); } catch (Exception e) { // This catches any other errors we might get. println("Some error thrown", progErr); logError(e.toString()); displayLog(); return; } }
private static void exec(String command) { try { System.out.println("Invoking: " + command); Process p = Runtime.getRuntime().exec(command); // get standard output BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = input.readLine()) != null) { System.out.println(line); } input.close(); // get error output input = new BufferedReader(new InputStreamReader(p.getErrorStream())); while ((line = input.readLine()) != null) { System.out.println(line); } input.close(); p.waitFor(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
// executes the input string as a shell command and returns its output as string public static String executeString(String komut) throws IOException, InterruptedException { /** * Runtime run = Runtime.getRuntime(); String verbose = ""; try{ Process pr = run.exec(komut); * pr.waitFor(); BufferedReader br = new BufferedReader(new * InputStreamReader(pr.getInputStream())); while ((verbose+=br.readLine())!=null) { // Bu * satırda program bekliyor. br.readLine() --> program bekliyor. } } catch(Exception ex) { * verbose=ex.toString(); } */ String verbose = ""; try { Runtime run = Runtime.getRuntime(); // Process myProcess = run.exec(komut); String[] komutDizi = komut.split(" "); /* * http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4 */ Process myProcess = run.exec(komutDizi); /* * http://stackoverflow.com/questions/1081084/is-java-runtime-execstring-platform-independent * I had some code that ran commands through * Runtime.getRuntime.exec(String), and it worked on Windows. When I * moved the code to Linux, it broke, and the only way of fixing it * was to switch to the exec(String[]) version. If I leave things * this way, will the code work the same on Windows and Linux, or * should I use the exec(String) on Windows and exec(String[]) on * Linux? */ InputStream instream = myProcess .getInputStream(); // BufferedReader.readLine() --> program bekliyor. InputStream // çalışıyor. int c; while ((c = instream.read()) != -1) { verbose += String.valueOf((char) c); } instream.close(); } catch (Exception ex) { verbose = ex.toString(); } return verbose; }
// 22.10.10 -- copied from above method, only with sa argument... public static void executeCommand(String[] sa, String stdout, String stderr) throws IOException { // System.out.println("Executing: " + sa); Runtime rt = Runtime.getRuntime(); Process p = rt.exec(sa); // System.out.println("one..."); // this code from diffpdf... // any error message? StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream()); // any output? StreamGobbler outputGobbler = new StreamGobbler(p.getInputStream()); // kick them off errorGobbler.start(); outputGobbler.start(); // System.out.println("two..."); // any error??? try { int exitVal = p.waitFor(); // System.out.println("fooo..."); // int exitVal2 = proc.exitValue(); } catch (InterruptedException ex) { // TODO Auto-generated catch block ex.printStackTrace(); } // System.out.println("three..."); // 15.03.07 these two lines uncommented // as there was a process still running! // processor utilisation in the GUI is now back down to // normal stdout = errorGobbler.getData(); stderr = outputGobbler.getData(); System.out.println(stdout); System.err.println(stderr); }
// Run selected test cases. private void runTests() { for (int i = 0; i < tests.size(); i++) { // If box for test is checked, run it. if (tests.get(i).isSelected()) { // Get the URLs of all of the required files. String folderURL = tests.get(i).getText(); String testURL = folderURL.concat(folderURL.substring(folderURL.lastIndexOf('/'))); String efgFile = testURL + ".EFG"; String guiFile = testURL + ".GUI"; String tstFile = testURL + ".TST"; String prgFile = testURL + ".PRG"; // attempt to read in file with program's parameters try { FileInputStream fstream = new FileInputStream(prgFile); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); HashMap<String, String> prgParams = new HashMap<String, String>(); String strLine; while ((strLine = br.readLine()) != null) { // add found parameters into prgParams as <key, value> String[] matches = strLine.split("="); prgParams.put(matches[0], matches[1]); } if (prgParams.containsKey("path") && prgParams.containsKey("main")) { programPath = prgParams.get("path"); mainClass = prgParams.get("main"); } in.close(); } catch (Exception e) { System.err.println(e.getMessage()); } System.out.println("We hit Run"); // Run the replayer using the three test files. System.out.println( "../../../dist/guitar/jfc-replayer.sh -cp " + programPath + " -c " + mainClass + " -g " + guiFile + " -e " + efgFile + " -t " + tstFile); try { Runtime rt = Runtime.getRuntime(); Process proc = rt.exec( "../../../dist/guitar/jfc-replayer.sh -cp " + programPath + " -c " + mainClass + " -g " + guiFile + " -e " + efgFile + " -t " + tstFile); // InputStream ips = proc.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); } catch (Exception e) { e.printStackTrace(); } } } }
public synchronized RenderedImage runDCRaw(dcrawMode mode, boolean secondaryPixels) throws IOException, UnknownImageTypeException, BadImageFileException { if (!m_decodable || (mode == dcrawMode.full && m_rawColors != 3)) throw new UnknownImageTypeException("Unsuported Camera"); RenderedImage result = null; File of = null; try { if (mode == dcrawMode.preview) { if (m_thumbWidth >= 1024 && m_thumbHeight >= 768) { mode = dcrawMode.thumb; } } long t1 = System.currentTimeMillis(); of = File.createTempFile("LZRAWTMP", ".ppm"); boolean four_colors = false; final String makeModel = m_make + ' ' + m_model; for (String s : four_color_cameras) if (s.equalsIgnoreCase(makeModel)) { four_colors = true; break; } if (secondaryPixels) runDCRawInfo(true); String cmd[]; switch (mode) { case full: if (four_colors) cmd = new String[] { DCRAW_PATH, "-F", of.getAbsolutePath(), "-v", "-f", "-H", "1", "-t", "0", "-o", "0", "-4", m_fileName }; else if (m_filters == -1 || (m_make != null && m_make.equalsIgnoreCase("SIGMA"))) cmd = new String[] { DCRAW_PATH, "-F", of.getAbsolutePath(), "-v", "-H", "1", "-t", "0", "-o", "0", "-4", m_fileName }; else if (secondaryPixels) cmd = new String[] { DCRAW_PATH, "-F", of.getAbsolutePath(), "-v", "-j", "-H", "1", "-t", "0", "-s", "1", "-d", "-4", m_fileName }; else cmd = new String[] { DCRAW_PATH, "-F", of.getAbsolutePath(), "-v", "-j", "-H", "1", "-t", "0", "-d", "-4", m_fileName }; break; case preview: cmd = new String[] { DCRAW_PATH, "-F", of.getAbsolutePath(), "-v", "-t", "0", "-o", "1", "-w", "-h", m_fileName }; break; case thumb: cmd = new String[] {DCRAW_PATH, "-F", of.getAbsolutePath(), "-v", "-e", m_fileName}; break; default: throw new IllegalArgumentException("Unknown mode " + mode); } String ofName = null; synchronized (DCRaw.class) { Process p = null; InputStream dcrawStdErr; InputStream dcrawStdOut; if (ForkDaemon.INSTANCE != null) { ForkDaemon.INSTANCE.invoke(cmd); dcrawStdErr = ForkDaemon.INSTANCE.getStdErr(); dcrawStdOut = ForkDaemon.INSTANCE.getStdOut(); } else { p = Runtime.getRuntime().exec(cmd); dcrawStdErr = new BufferedInputStream(p.getErrorStream()); dcrawStdOut = p.getInputStream(); } String line, args; // output expected on stderr while ((line = readln(dcrawStdErr)) != null) { // System.out.println(line); if ((args = match(line, DCRAW_OUTPUT)) != null) ofName = args.substring(0, args.indexOf(" ...")); } // Flush stdout just in case... while ((line = readln(dcrawStdOut)) != null) ; // System.out.println(line); if (p != null) { dcrawStdErr.close(); try { p.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } m_error = p.exitValue(); p.destroy(); } else m_error = 0; } System.out.println("dcraw value: " + m_error); if (m_error > 0) { of.delete(); throw new BadImageFileException(of); } if (!ofName.equals(of.getPath())) { of.delete(); of = new File(ofName); } if (of.getName().endsWith(".jpg") || of.getName().endsWith(".tiff")) { if (of.getName().endsWith(".jpg")) { try { LCJPEGReader jpegReader = new LCJPEGReader(of.getPath()); result = jpegReader.getImage(); } catch (Exception e) { e.printStackTrace(); } } else { try { LCTIFFReader tiffReader = new LCTIFFReader(of.getPath()); result = tiffReader.getImage(null); } catch (Exception e) { e.printStackTrace(); } } long t2 = System.currentTimeMillis(); int totalData = result.getWidth() * result.getHeight() * result.getColorModel().getNumColorComponents() * (result.getColorModel().getTransferType() == DataBuffer.TYPE_BYTE ? 1 : 2); System.out.println("Read " + totalData + " bytes in " + (t2 - t1) + "ms"); } else { ImageData imageData; try { imageData = readPPM(of); } catch (Exception e) { e.printStackTrace(); throw new BadImageFileException(of, e); } // do not change the initial image geometry // m_width = Math.min(m_width, imageData.width); // m_height = Math.min(m_height, imageData.height); long t2 = System.currentTimeMillis(); int totalData = imageData.width * imageData.height * imageData.bands * (imageData.dataType == DataBuffer.TYPE_BYTE ? 1 : 2); System.out.println("Read " + totalData + " bytes in " + (t2 - t1) + "ms"); final ColorModel cm; if (mode == dcrawMode.full) { if (imageData.bands == 1) { cm = new ComponentColorModel( ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false, Transparency.OPAQUE, DataBuffer.TYPE_USHORT); } else { cm = JAIContext.colorModel_linear16; } } else { if (imageData.bands == 3) cm = new ComponentColorModel( JAIContext.sRGBColorSpace, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); else if (imageData.bands == 4) cm = new ComponentColorModel( JAIContext.CMYKColorSpace, false, false, Transparency.OPAQUE, imageData.dataType); else throw new UnknownImageTypeException("Weird number of bands: " + imageData.bands); } final DataBuffer buf = imageData.dataType == DataBuffer.TYPE_BYTE ? new DataBufferByte( (byte[]) imageData.data, imageData.bands * imageData.width * imageData.height) : new DataBufferUShort( (short[]) imageData.data, imageData.bands * imageData.width * imageData.height); final WritableRaster raster = Raster.createInterleavedRaster( buf, imageData.width, imageData.height, imageData.bands * imageData.width, imageData.bands, imageData.bands == 3 ? new int[] {0, 1, 2} : new int[] {0}, null); result = new BufferedImage(cm, raster, false, null); } } catch (IOException e) { if (of != null) of.delete(); throw e; } finally { if (of != null) of.delete(); } return result; }
private void runDCRawInfo(boolean secondary) throws IOException { String info[] = {DCRAW_PATH, "-v", "-i", "-t", "0", m_fileName}; String secondaryInfo[] = {DCRAW_PATH, "-v", "-i", "-s", "1", "-t", "0", m_fileName}; synchronized (DCRaw.class) { Process p = null; InputStream dcrawStdOut; InputStream dcrawStdErr; if (ForkDaemon.INSTANCE != null) { ForkDaemon.INSTANCE.invoke(secondary ? secondaryInfo : info); dcrawStdOut = ForkDaemon.INSTANCE.getStdOut(); dcrawStdErr = ForkDaemon.INSTANCE.getStdErr(); } else { p = Runtime.getRuntime().exec(secondary ? secondaryInfo : info); dcrawStdOut = p.getInputStream(); dcrawStdErr = new BufferedInputStream(p.getErrorStream()); } // output expected on stdout String line, args; while ((line = readln(dcrawStdOut)) != null) { // System.out.println(line); String search; if (secondary) { if (line.startsWith(search = CAMERA_MULTIPLIERS)) { String multipliers[] = line.substring(search.length()).split("\\s"); m_secondary_cam_mul[0] = Float.parseFloat(multipliers[0]); m_secondary_cam_mul[1] = Float.parseFloat(multipliers[1]); m_secondary_cam_mul[2] = Float.parseFloat(multipliers[2]); m_secondary_cam_mul[3] = Float.parseFloat(multipliers[3]); } } else { // if (line.startsWith(search = FILENAME)) { // String filename = line.substring(search.length()); // } else if (line.startsWith(search = TIMESTAMP)) { String timestamp = line.substring(search.length()); try { m_captureDateTime = new SimpleDateFormat().parse(timestamp).getTime(); } catch (ParseException e) { m_captureDateTime = 0; } } else if (line.startsWith(search = CAMERA)) { String camera = line.substring(search.length()); m_make = camera.substring(0, camera.indexOf(' ')); m_model = camera.substring(m_make.length() + 1); } else if (line.startsWith(search = ISO)) { String iso = line.substring(search.length()); m_iso = Integer.decode(iso); } else if (line.startsWith(search = SHUTTER)) { String shutterSpeed = line.substring(search.length() + 2); float exposureTime = 0; try { exposureTime = Float.valueOf(shutterSpeed.substring(0, shutterSpeed.indexOf(" sec"))); if (exposureTime != 0) m_shutterSpeed = 1 / exposureTime; } catch (NumberFormatException e) { } } else if (line.startsWith(search = APERTURE)) { String aperture = line.substring(search.length() + 2); try { m_aperture = Float.valueOf(aperture); } catch (NumberFormatException e) { } } else if (line.startsWith(search = FOCAL_LENGTH)) { String focalLenght = line.substring(search.length()); try { m_focalLength = Float.valueOf(focalLenght.substring(0, focalLenght.indexOf(" mm"))); } catch (NumberFormatException e) { } // } else if (line.startsWith(search = NUM_RAW_IMAGES)) { // String numRawImages = line.substring(search.length()); // } else if (line.startsWith(search = EMBEDDED_ICC_PROFILE)) { // String embeddedICCProfile = line.substring(search.length()); } else if (line.startsWith(CANNOT_DECODE)) { m_decodable = false; } else if ((args = match(line, THUMB_SIZE)) != null) { String sizes[] = args.split(" x "); m_thumbWidth = Integer.decode(sizes[0]); m_thumbHeight = Integer.decode(sizes[1]); } else if ((args = match(line, FULL_SIZE)) != null) { String sizes[] = args.split(" x "); m_fullWidth = Integer.decode(sizes[0]); m_fullHeight = Integer.decode(sizes[1]); } else if ((args = match(line, IMAGE_SIZE)) != null) { String sizes[] = args.split(" x "); m_rawWidth = Integer.decode(sizes[0]); m_rawHeight = Integer.decode(sizes[1]); } else if ((args = match(line, OUTPUT_SIZE)) != null) { String sizes[] = args.split(" x "); m_width = Integer.decode(sizes[0]); m_height = Integer.decode(sizes[1]); } else if (line.startsWith(search = RAW_COLORS)) { String rawColors = line.substring(search.length()); m_rawColors = Integer.decode(rawColors); } else if (line.startsWith(search = FILTER_PATTERN)) { String pattern = line.substring(search.length()); if (pattern.length() >= 8 && !pattern.substring(0, 4).equals(pattern.substring(4, 8))) m_filters = -1; else if (pattern.startsWith("BGGR")) m_filters = 0x16161616; else if (pattern.startsWith("GRBG")) m_filters = 0x61616161; else if (pattern.startsWith("GBRG")) m_filters = 0x49494949; else if (pattern.startsWith("RGGB")) m_filters = 0x94949494; else m_filters = -1; } else if (line.startsWith(search = DAYLIGHT_MULTIPLIERS)) { String multipliers[] = line.substring(search.length()).split("\\s"); m_pre_mul[0] = Float.parseFloat(multipliers[0]); m_pre_mul[1] = Float.parseFloat(multipliers[1]); m_pre_mul[2] = Float.parseFloat(multipliers[2]); m_pre_mul[3] = m_pre_mul[1]; } else if (line.startsWith(search = CAMERA_MULTIPLIERS)) { String multipliers[] = line.substring(search.length()).split("\\s"); m_cam_mul[0] = Float.parseFloat(multipliers[0]); m_cam_mul[1] = Float.parseFloat(multipliers[1]); m_cam_mul[2] = Float.parseFloat(multipliers[2]); m_cam_mul[3] = Float.parseFloat(multipliers[3]); } else if (line.startsWith(CAMERA_RGB_PROFILE)) { String rgb_cam[] = line.substring(CAMERA_RGB_PROFILE.length()).split("\\s"); m_rgb_cam = new float[9]; for (int i = 0; i < 9; i++) { m_rgb_cam[i] = Float.parseFloat(rgb_cam[i]); } } else if (line.startsWith(CAMERA_XYZ_PROFILE)) { String xyz_cam[] = line.substring(CAMERA_XYZ_PROFILE.length()).split("\\s"); m_xyz_cam = new float[9]; for (int i = 0; i < 9; i++) { m_xyz_cam[i] = Float.parseFloat(xyz_cam[i]); } } } } // Flush stderr just in case... while ((line = readln(dcrawStdErr)) != null) ; // System.out.println(line); if (p != null) { dcrawStdOut.close(); try { p.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } m_error = p.exitValue(); p.destroy(); } else m_error = 0; } }
/** * Starts the debugger. The method stops the current debugging (if any) and takes information from * the provided info (containing the class to start and arguments to pass it and name of class to * stop debugging in) and starts new debugging session. * * @param info debugger info about class to start * @exception DebuggerException if an error occures during the start of the debugger */ public void startDebugger(DebuggerInfo info) throws DebuggerException { debuggerInfo = info; if (remoteDebugger != null) finishDebugger(); // S ystem.out.println("startDebugger " + info); // NOI18N // RemoteDebugging support hostName = null; password = null; boolean local = true; if (info instanceof ReconnectDebuggerInfo) { ReconnectDebuggerInfo rdi = (ReconnectDebuggerInfo) info; hostName = rdi.getHostName(); password = rdi.getPassword(); local = false; } else if (info instanceof RemoteDebuggerInfo) { hostName = ((RemoteDebuggerInfo) info).getHostName(); password = ((RemoteDebuggerInfo) info).getPassword(); local = false; } boolean stopOnMain = info.getStopClassName() != null; stopOnMainFlag = stopOnMain; // S ystem.out.println ("ToolsDebugger.startDebugger " + info.getStopClassName ()); // NOI18N // T hread.dumpStack (); synchronizer = new RequestSynchronizer(); // open output window ... super.startDebugger(info); // start & init remote debugger ................................................ // process = null; if (local) { // create process & read password for local debugging // create starting string & NbProcessDescriptor NbProcessDescriptor debugerProcess; if (info instanceof ProcessDebuggerInfo) debugerProcess = ((ProcessDebuggerInfo) info).getDebuggerProcess(); else debugerProcess = ProcessDebuggerType.DEFAULT_DEBUGGER_PROCESS; HashMap map; if (info instanceof ToolsDebugger10Info) { map = Utils.processDebuggerInfo( info, "-debug", // NOI18N "sun.tools.debug.EmptyApp" // NOI18N ); map.put(ToolsDebugger10Type.JAVA_HOME_SWITCH, ((ToolsDebugger10Info) info).getJavaHome()); } else { if (info instanceof ToolsDebugger11Info) { String javaHome11 = ((ToolsDebugger11Info) info).getJavaHome(); if ((javaHome11 == null) || (javaHome11.trim().length() == 0)) { finishDebugger(); throw new DebuggerException(bundle.getString("EXC_JDK11_home_is_not_set")); } map = Utils.processDebuggerInfo( info, "-debug -nojit", // NOI18N "sun.tools.debug.EmptyApp" // NOI18N ); map.put(ToolsDebugger11Type.JAVA_HOME_SWITCH, javaHome11); } else { map = Utils.processDebuggerInfo( info, "-Xdebug", // NOI18N "sun.tools.agent.EmptyApp" // NOI18N ); } } MapFormat format = new MapFormat(map); String s = format.format( debugerProcess.getProcessName() + " " + debugerProcess.getArguments() // NOI18N ); println(s, ERR_OUT); // start process & read password ...................................... try { process = debugerProcess.exec(format); BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(process.getInputStream())); password = bufferedreader.readLine(); showOutput(process, ERR_OUT, ERR_OUT); connectInput(process); } catch (java.lang.Exception e) { finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_While_create_debuggee")) .format( new Object[] {format.format(debugerProcess.getProcessName()), e.toString()}), e); } if (password == null) { // no reply finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_While_connect_to_debuggee")) .format(new Object[] {format.format(debugerProcess.getProcessName())})); } if (password.indexOf("=") < 0) { // NOI18N // unexpected reply println(bundle.getString("CTL_Unexpected_reply") + ": " + password, ERR_OUT); showOutput(process, ERR_OUT + STD_OUT, ERR_OUT); finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_Unecpected_debugger_reply")) .format(new Object[] {password})); } password = password.substring(password.indexOf("=") + 1); // NOI18N println(bundle.getString("CTL_Password") + ": " + password, ERR_OUT); hostName = "127.0.0.1"; // NOI18N } // end of local debugging specific else if (info instanceof ReconnectDebuggerInfo) { println(bundle.getString("CTL_Reconnecting"), ERR_OUT | STD_OUT); } else println(bundle.getString("CTL_Connecting_to") + ": " + hostName + ":" + password, ERR_OUT); // start RemoteDebugger ................................................... try { remoteDebugger = new RemoteDebugger( hostName, password.length() < 1 ? null : password, new ToolsCallback(this), isShowMessages()); } catch (java.net.ConnectException e) { finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_Cannot_connect_to_debuggee")) .format(new Object[] {e.toString()}), e); } catch (Throwable e) { if (e instanceof ThreadDeath) throw (ThreadDeath) e; // e.printStackTrace (); finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_Cannot_connect_to_debuggee")) .format(new Object[] {e.toString()}), e); } // create arguments for main class ............................................... mainClassName = info.getClassName(); RemoteClass cls; String[] args = null; if ((mainClassName != null) && (mainClassName.length() > 0)) { String[] infoArgs = info.getArguments(); args = new String[infoArgs.length + 1]; args[0] = mainClassName; System.arraycopy(infoArgs, 0, args, 1, infoArgs.length); // args[0] = name of class // args[...] = parameters // find main class ......................................................... try { cls = remoteDebugger.findClass(mainClassName); } catch (Throwable e) { if (e instanceof ThreadDeath) throw (ThreadDeath) e; finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_Cannot_find_class")) .format(new Object[] {mainClassName, e.toString()}), e); } if (cls == null) { finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_Cannot_find_class")) .format(new Object[] {mainClassName, new ClassNotFoundException().toString()})); } } // set breakpoint on stop class method ............................................... if (stopOnMain) { RemoteClass stopClass = null; try { stopClass = remoteDebugger.findClass(stopClassName = info.getStopClassName()); } catch (Throwable e) { if (e instanceof ThreadDeath) throw (ThreadDeath) e; println( bundle.getString("MSG_Exc_while_finding_class") + stopClassName + '\n' + e, ERR_OUT); } if (stopClass == null) { println(bundle.getString("CTL_No_such_class") + ": " + stopClassName, ERR_OUT); } else { try { RemoteField[] rf = stopClass.getMethods(); int i, k = rf.length; Type t = Type.tMethod(Type.tVoid, new Type[] {Type.tArray(Type.tString)}); Type startT = Type.tMethod(Type.tVoid); RemoteField startM = null; RemoteField initM = null; RemoteField constM = null; for (i = 0; i < k; i++) { if (rf[i].getName().equals("main") && // NOI18N rf[i].getType().equals(t)) break; else if (rf[i].getName().equals("start") && // NOI18N rf[i].getType().equals(startT)) startM = rf[i]; else if (rf[i].getName().equals("init") && // NOI18N rf[i].getType().equals(startT)) initM = rf[i]; else if (rf[i].getName().equals("<init>") && // NOI18N rf[i].getType().equals(startT)) constM = rf[i]; } if (i < k) // [PENDING] stop on non main too !!!!!!!!!!!!!!!!!!!!! stopClass.setBreakpointMethod(rf[i]); // have main else if (initM != null) stopClass.setBreakpointMethod(initM); else if (startM != null) stopClass.setBreakpointMethod(startM); else if (constM != null) stopClass.setBreakpointMethod(constM); // S ystem.out.println ("Stop: " + (i <k) + " " + initM +" " + startM +" " + constM); // // NOI18N /* pendingBreakpoints = new RemoteField [1]; pendingBreakpoints [0] = rf[i]; pendingBreakpointsClass = stopClass;*/ } catch (Throwable e) { if (e instanceof ThreadDeath) throw (ThreadDeath) e; println(bundle.getString("MSG_Exc_while_setting_breakpoint") + '\n' + e, ERR_OUT); } } } // stopOnMain setBreakpoints(); updateWatches(); println(bundle.getString("CTL_Debugger_running"), STL_OUT); setDebuggerState(DEBUGGER_RUNNING); // run debugged class ............................................... if (args != null) { RemoteThreadGroup rtg = null; try { rtg = remoteDebugger.run(args.length, args); // threadGroup.setRemoteThreadGroup (rtg); } catch (Throwable e) { if (e instanceof ThreadDeath) throw (ThreadDeath) e; finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_While_calling_run")) .format(new Object[] {mainClassName, e.toString()}), e); } if (rtg == null) { finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_While_calling_run")) .format( new Object[] { mainClassName, "" // NOI18N })); } } // start refresh thread ................................................. if (debuggerThread != null) debuggerThread.stop(); debuggerThread = new Thread( new Runnable() { public void run() { for (; ; ) { try { Thread.sleep(5000); } catch (InterruptedException ex) { } if (getState() == DEBUGGER_RUNNING) try { threadGroup.threadChanged(); } catch (Throwable e) { if (e instanceof ThreadDeath) throw (ThreadDeath) e; if (e instanceof java.net.SocketException) { debuggerThread = null; try { finishDebugger(); } catch (Throwable ee) { if (ee instanceof ThreadDeath) throw (ThreadDeath) ee; } Thread.currentThread().stop(); } } } } }, "Debugger refresh thread"); // NOI18N debuggerThread.setPriority(Thread.MIN_PRIORITY); debuggerThread.start(); }