Skip to content

Commit

Permalink
Reduce split packages in o.e.tests
Browse files Browse the repository at this point in the history
Split packages cause a lot of troubles and this is test harness code so
it's better to live without them.
  • Loading branch information
akurtakov committed Sep 20, 2024
1 parent a1f08dc commit 6e6a136
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 155 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ Bundle-Version: 3.20.300.qualifier
Bundle-Activator: org.eclipse.test.internal.performance.PerformanceTestPlugin
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Import-Package: org.junit.jupiter.api,
org.junit.platform.suite.api,
org.eclipse.test
Export-Package: org.eclipse.perfmsr.core,
org.eclipse.test,
org.eclipse.test.internal;x-internal:=true,
org.eclipse.test.internal.performance,
org.eclipse.test.internal.performance.data,
org.eclipse.test.internal.performance.db,
org.eclipse.test.internal.performance.eval,
org.eclipse.test.internal.performance.tests,
org.eclipse.test.performance
Import-Package: org.junit.jupiter.api,
org.junit.platform.suite.api
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.test;visibility:=reexport,
org.junit
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Require-Bundle: org.apache.ant,
org.eclipse.ui;bundle-version="[3.112.0,4.0.0)",
org.eclipse.core.runtime,
org.eclipse.ui.ide.application,
org.eclipse.equinox.app
org.eclipse.equinox.app,
org.junit
Import-Package: org.junit.jupiter.api,
org.junit.platform.engine,
org.junit.platform.engine.discovery,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2017 IBM Corporation and others.
* Copyright (c) 2015, 2016 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -11,6 +11,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/

package org.eclipse.test;

import java.awt.AWTException;
Expand All @@ -19,26 +20,114 @@
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.URISyntaxException;
import java.net.URL;

import javax.imageio.ImageIO;

public class AwtScreenshot {

public static void main(String[] args) {
try {
System.setProperty("java.awt.headless", "false");
Robot robot = new Robot();
Rectangle rect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage image = robot.createScreenCapture(rect);
File file = new File(args[0]);
ImageIO.write(image, "png", file);

System.out.println("AWT screenshot saved to: " + file.getAbsolutePath());
} catch (HeadlessException | AWTException | IOException e) {
e.printStackTrace();
}
}
private static final int TIMEOUT_SECONDS = 15;

public static void main(String[] args) {
try {
System.setProperty("java.awt.headless", "false");
Robot robot = new Robot();
Rectangle rect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage image = robot.createScreenCapture(rect);
File file = new File(args[0]);
ImageIO.write(image, "png", file);

System.out.println("AWT screenshot saved to: " + file.getAbsolutePath());
} catch (HeadlessException | AWTException | IOException e) {
e.printStackTrace();
}
}

static class StreamForwarder extends Thread {

private InputStream fProcessOutput;

private PrintStream fStream;

public StreamForwarder(InputStream processOutput, PrintStream stream) {
fProcessOutput = processOutput;
fStream = stream;
}

@Override
public void run() {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(fProcessOutput))) {
String line = null;
while ((line = reader.readLine()) != null) {
fStream.println(line);
}
} catch (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)) {
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.io.File;

import org.eclipse.core.runtime.Platform;
import org.eclipse.test.internal.AwtScreenshot;

/**
* Helper class to take screenshots from running tests.
Expand Down

0 comments on commit 6e6a136

Please sign in to comment.