From 3c023819cd6ea871402387284a74090433293e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Mon, 7 Oct 2024 11:02:00 +0200 Subject: [PATCH] AwtScreenshot: Do not add "bin" to classpath #1486 for "Eclipse-BundleShape: dir" in MANIFEST.MF fix "Error: Could not find or load main class org.eclipse.test.AwtScreenshot" https://github.com/eclipse-platform/eclipse.platform.swt/issues/1486 --- .../src/org/eclipse/test/AwtScreenshot.java | 115 +++++++++--------- 1 file changed, 59 insertions(+), 56 deletions(-) diff --git a/eclipse.platform.releng/bundles/org.eclipse.test/src/org/eclipse/test/AwtScreenshot.java b/eclipse.platform.releng/bundles/org.eclipse.test/src/org/eclipse/test/AwtScreenshot.java index 7f0558beb57..cdea5023f82 100644 --- a/eclipse.platform.releng/bundles/org.eclipse.test/src/org/eclipse/test/AwtScreenshot.java +++ b/eclipse.platform.releng/bundles/org.eclipse.test/src/org/eclipse/test/AwtScreenshot.java @@ -74,60 +74,63 @@ public void run() { } } - public static void dumpAwtScreenshot(String screenshotFile) { - try { - URL location = AwtScreenshot.class.getProtectionDomain().getCodeSource().getLocation(); - String cp = location.toURI().getPath(); - if (new File(cp).isDirectory() && !cp.endsWith(File.separatorChar + "bin" + File.separatorChar)) { - cp += "bin" + File.separatorChar; - } - String javaHome = System.getProperty("java.home"); - String javaExe = javaHome + File.separatorChar + "bin" + File.separatorChar + "java"; - if (File.separatorChar == '\\') { - javaExe += ".exe"; // assume it's Windows - } - String[] args = new String[] { javaExe, "-cp", cp, AwtScreenshot.class.getName(), screenshotFile }; - // System.out.println("Start process: " + Arrays.asList(args)); - ProcessBuilder processBuilder = new ProcessBuilder(args); - if ("Mac OS X".equals(System.getProperty("os.name"))) { - processBuilder.environment().put("AWT_TOOLKIT", "CToolkit"); - } - Process process = processBuilder.start(); - - @SuppressWarnings("resource") // never close process streams - InputStream errorStream = process.getErrorStream(); - - @SuppressWarnings("resource") // never close process streams - InputStream inputStream = process.getInputStream(); - - new StreamForwarder(errorStream, System.out).start(); - new StreamForwarder(inputStream, System.out).start(); - long end = System.currentTimeMillis() + TIMEOUT_SECONDS * 1000; - boolean done = false; - do { - try { - process.exitValue(); - done = true; - } catch (IllegalThreadStateException e) { - try { - Thread.sleep(100); - } catch (InterruptedException e1) { - // continue - } - } - } while (!done && System.currentTimeMillis() < end); - - if (done) { - int exitCode = process.exitValue(); - if (exitCode != 0) { - System.out.println("AwtScreenshot VM finished with exit code " + exitCode + "."); - } - } else { - process.destroy(); - System.out.println("Killed AwtScreenshot VM after " + TIMEOUT_SECONDS + " seconds."); - } - } catch (URISyntaxException | IOException e) { - e.printStackTrace(); - } - } + public static void dumpAwtScreenshot(String screenshotFile) { + try { + URL location = AwtScreenshot.class.getProtectionDomain().getCodeSource().getLocation(); + String cp = location.toURI().getPath(); + if (new File(cp).isDirectory() && !cp.endsWith(File.separatorChar + "bin" + File.separatorChar) + && new File(cp + "bin" + File.separatorChar).isDirectory()) { + cp += "bin" + File.separatorChar; + } + String javaHome = System.getProperty("java.home"); + String javaExe = javaHome + File.separatorChar + "bin" + File.separatorChar + "java"; + if (File.separatorChar == '\\') { + javaExe += ".exe"; // assume it's Windows + } + String[] args = new String[] { javaExe, "-cp", cp, AwtScreenshot.class.getName(), screenshotFile }; + // System.out.println("Start process: " + Arrays.asList(args)); + ProcessBuilder processBuilder = new ProcessBuilder(args); + if ("Mac OS X".equals(System.getProperty("os.name"))) { + processBuilder.environment().put("AWT_TOOLKIT", "CToolkit"); + } + Process process = processBuilder.start(); + + @SuppressWarnings("resource") // never close process streams + InputStream errorStream = process.getErrorStream(); + + @SuppressWarnings("resource") // never close process streams + InputStream inputStream = process.getInputStream(); + + new StreamForwarder(errorStream, System.out).start(); + new StreamForwarder(inputStream, System.out).start(); + long end = System.currentTimeMillis() + TIMEOUT_SECONDS * 1000; + boolean done = false; + do { + try { + process.exitValue(); + done = true; + } catch (IllegalThreadStateException e) { + try { + Thread.sleep(100); + } catch (InterruptedException e1) { + // continue + } + } + } while (!done && System.currentTimeMillis() < end); + + if (done) { + int exitCode = process.exitValue(); + if (exitCode != 0) { + new RuntimeException("AwtScreenshot VM finished with exit code " + exitCode + ".") + .printStackTrace(); + } + } else { + process.destroy(); + new RuntimeException("Killed AwtScreenshot VM after " + TIMEOUT_SECONDS + " seconds.") + .printStackTrace(); + } + } catch (URISyntaxException | IOException e) { + e.printStackTrace(); + } + } }