Skip to content

Commit 6e6a136

Browse files
committed
Reduce split packages in o.e.tests
Split packages cause a lot of troubles and this is test harness code so it's better to live without them.
1 parent a1f08dc commit 6e6a136

File tree

8 files changed

+115
-155
lines changed

8 files changed

+115
-155
lines changed

eclipse.platform.releng/bundles/org.eclipse.test.performance/.classpath

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
4-
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="src">
5+
<attributes>
6+
<attribute name="test" value="true"/>
7+
</attributes>
8+
</classpathentry>
59
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
610
<attributes>
711
<attribute name="module" value="true"/>

eclipse.platform.releng/bundles/org.eclipse.test.performance/META-INF/MANIFEST.MF

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ Bundle-Version: 3.20.300.qualifier
66
Bundle-Activator: org.eclipse.test.internal.performance.PerformanceTestPlugin
77
Bundle-Vendor: %Plugin.providerName
88
Bundle-Localization: plugin
9+
Import-Package: org.junit.jupiter.api,
10+
org.junit.platform.suite.api,
11+
org.eclipse.test
912
Export-Package: org.eclipse.perfmsr.core,
10-
org.eclipse.test,
11-
org.eclipse.test.internal;x-internal:=true,
1213
org.eclipse.test.internal.performance,
1314
org.eclipse.test.internal.performance.data,
1415
org.eclipse.test.internal.performance.db,
1516
org.eclipse.test.internal.performance.eval,
1617
org.eclipse.test.internal.performance.tests,
1718
org.eclipse.test.performance
18-
Import-Package: org.junit.jupiter.api,
19-
org.junit.platform.suite.api
2019
Require-Bundle: org.eclipse.core.runtime,
20+
org.eclipse.test;visibility:=reexport,
2121
org.junit
2222
Bundle-ActivationPolicy: lazy
2323
Bundle-ClassPath: .

eclipse.platform.releng/bundles/org.eclipse.test.performance/src/org/eclipse/test/internal/AwtScreenshot.java

Lines changed: 0 additions & 133 deletions
This file was deleted.

eclipse.platform.releng/bundles/org.eclipse.test/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Require-Bundle: org.apache.ant,
1010
org.eclipse.ui;bundle-version="[3.112.0,4.0.0)",
1111
org.eclipse.core.runtime,
1212
org.eclipse.ui.ide.application,
13-
org.eclipse.equinox.app
13+
org.eclipse.equinox.app,
14+
org.junit
1415
Import-Package: org.junit.jupiter.api,
1516
org.junit.platform.engine,
1617
org.junit.platform.engine.discovery,
Lines changed: 104 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2015, 2017 IBM Corporation and others.
2+
* Copyright (c) 2015, 2016 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -11,6 +11,7 @@
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
1313
*******************************************************************************/
14+
1415
package org.eclipse.test;
1516

1617
import java.awt.AWTException;
@@ -19,26 +20,114 @@
1920
import java.awt.Robot;
2021
import java.awt.Toolkit;
2122
import java.awt.image.BufferedImage;
23+
import java.io.BufferedReader;
2224
import java.io.File;
2325
import java.io.IOException;
26+
import java.io.InputStream;
27+
import java.io.InputStreamReader;
28+
import java.io.PrintStream;
29+
import java.net.URISyntaxException;
30+
import java.net.URL;
2431

2532
import javax.imageio.ImageIO;
2633

2734
public class AwtScreenshot {
2835

29-
public static void main(String[] args) {
30-
try {
31-
System.setProperty("java.awt.headless", "false");
32-
Robot robot = new Robot();
33-
Rectangle rect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
34-
BufferedImage image = robot.createScreenCapture(rect);
35-
File file = new File(args[0]);
36-
ImageIO.write(image, "png", file);
37-
38-
System.out.println("AWT screenshot saved to: " + file.getAbsolutePath());
39-
} catch (HeadlessException | AWTException | IOException e) {
40-
e.printStackTrace();
41-
}
42-
}
36+
private static final int TIMEOUT_SECONDS = 15;
37+
38+
public static void main(String[] args) {
39+
try {
40+
System.setProperty("java.awt.headless", "false");
41+
Robot robot = new Robot();
42+
Rectangle rect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
43+
BufferedImage image = robot.createScreenCapture(rect);
44+
File file = new File(args[0]);
45+
ImageIO.write(image, "png", file);
46+
47+
System.out.println("AWT screenshot saved to: " + file.getAbsolutePath());
48+
} catch (HeadlessException | AWTException | IOException e) {
49+
e.printStackTrace();
50+
}
51+
}
52+
53+
static class StreamForwarder extends Thread {
54+
55+
private InputStream fProcessOutput;
56+
57+
private PrintStream fStream;
58+
59+
public StreamForwarder(InputStream processOutput, PrintStream stream) {
60+
fProcessOutput = processOutput;
61+
fStream = stream;
62+
}
63+
64+
@Override
65+
public void run() {
66+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(fProcessOutput))) {
67+
String line = null;
68+
while ((line = reader.readLine()) != null) {
69+
fStream.println(line);
70+
}
71+
} catch (IOException e) {
72+
e.printStackTrace();
73+
}
74+
}
75+
}
76+
77+
public static void dumpAwtScreenshot(String screenshotFile) {
78+
try {
79+
URL location = AwtScreenshot.class.getProtectionDomain().getCodeSource().getLocation();
80+
String cp = location.toURI().getPath();
81+
if (new File(cp).isDirectory() && !cp.endsWith(File.separatorChar + "bin" + File.separatorChar)) {
82+
cp += "bin" + File.separatorChar;
83+
}
84+
String javaHome = System.getProperty("java.home");
85+
String javaExe = javaHome + File.separatorChar + "bin" + File.separatorChar + "java";
86+
if (File.separatorChar == '\\') {
87+
javaExe += ".exe"; // assume it's Windows
88+
}
89+
String[] args = new String[] { javaExe, "-cp", cp, AwtScreenshot.class.getName(), screenshotFile };
90+
// System.out.println("Start process: " + Arrays.asList(args));
91+
ProcessBuilder processBuilder = new ProcessBuilder(args);
92+
if ("Mac OS X".equals(System.getProperty("os.name"))) {
93+
processBuilder.environment().put("AWT_TOOLKIT", "CToolkit");
94+
}
95+
Process process = processBuilder.start();
96+
97+
@SuppressWarnings("resource") // never close process streams
98+
InputStream errorStream = process.getErrorStream();
99+
100+
@SuppressWarnings("resource") // never close process streams
101+
InputStream inputStream = process.getInputStream();
102+
103+
new StreamForwarder(errorStream, System.out).start();
104+
new StreamForwarder(inputStream, System.out).start();
105+
long end = System.currentTimeMillis() + TIMEOUT_SECONDS * 1000;
106+
boolean done = false;
107+
do {
108+
try {
109+
process.exitValue();
110+
done = true;
111+
} catch (IllegalThreadStateException e) {
112+
try {
113+
Thread.sleep(100);
114+
} catch (InterruptedException e1) {
115+
// continue
116+
}
117+
}
118+
} while (!done && System.currentTimeMillis() < end);
43119

120+
if (done) {
121+
int exitCode = process.exitValue();
122+
if (exitCode != 0) {
123+
System.out.println("AwtScreenshot VM finished with exit code " + exitCode + ".");
124+
}
125+
} else {
126+
process.destroy();
127+
System.out.println("Killed AwtScreenshot VM after " + TIMEOUT_SECONDS + " seconds.");
128+
}
129+
} catch (URISyntaxException | IOException e) {
130+
e.printStackTrace();
131+
}
132+
}
44133
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.io.File;
1717

1818
import org.eclipse.core.runtime.Platform;
19-
import org.eclipse.test.internal.AwtScreenshot;
2019

2120
/**
2221
* Helper class to take screenshots from running tests.

0 commit comments

Comments
 (0)