Skip to content

Commit

Permalink
Format code and apply JDT clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Oct 29, 2022
1 parent 388e5aa commit 929c6a5
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 155 deletions.
Expand Up @@ -39,11 +39,11 @@
import org.junit.platform.launcher.TestPlan;

/**
* Contains some common behaviour that's used by our internal {@link TestResultFormatter}s
* Contains some common behaviour that's used by our internal
* {@link TestResultFormatter}s
*/
abstract class AbstractJUnitResultFormatter implements TestResultFormatter {


protected static String NEW_LINE = System.lineSeparator();
protected TestExecutionContext context;

Expand Down Expand Up @@ -82,46 +82,48 @@ public void setContext(final TestExecutionContext context) {
}

/**
* @return Returns true if there's any stdout data, that was generated during the
* tests, is available for use. Else returns false.
* @return Returns true if there's any stdout data, that was generated during
* the tests, is available for use. Else returns false.
*/
boolean hasSysOut() {
return this.sysOutStore != null && this.sysOutStore.hasData();
}

/**
* @return Returns true if there's any stderr data, that was generated during the
* tests, is available for use. Else returns false.
* @return Returns true if there's any stderr data, that was generated during
* the tests, is available for use. Else returns false.
*/
boolean hasSysErr() {
return this.sysErrStore != null && this.sysErrStore.hasData();
}

/**
* @return Returns a {@link Reader} for reading any stdout data that was generated
* during the test execution. It is expected that the {@link #hasSysOut()} be first
* called to see if any such data is available and only if there is, then this method
* be called
* @throws IOException If there's any I/O problem while creating the {@link Reader}
* @return Returns a {@link Reader} for reading any stdout data that was
* generated during the test execution. It is expected that the
* {@link #hasSysOut()} be first called to see if any such data is
* available and only if there is, then this method be called
* @throws IOException If there's any I/O problem while creating the
* {@link Reader}
*/
Reader getSysOutReader() throws IOException {
return this.sysOutStore.getReader();
}

/**
* @return Returns a {@link Reader} for reading any stderr data that was generated
* during the test execution. It is expected that the {@link #hasSysErr()} be first
* called to see if any such data is available and only if there is, then this method
* be called
* @throws IOException If there's any I/O problem while creating the {@link Reader}
* @return Returns a {@link Reader} for reading any stderr data that was
* generated during the test execution. It is expected that the
* {@link #hasSysErr()} be first called to see if any such data is
* available and only if there is, then this method be called
* @throws IOException If there's any I/O problem while creating the
* {@link Reader}
*/
Reader getSysErrReader() throws IOException {
return this.sysErrStore.getReader();
}

/**
* Writes out any stdout data that was generated during the
* test execution. If there was no such data then this method just returns.
* Writes out any stdout data that was generated during the test execution. If
* there was no such data then this method just returns.
*
* @param writer The {@link Writer} to use. Cannot be null.
* @throws IOException If any I/O problem occurs during writing the data
Expand All @@ -132,8 +134,8 @@ void writeSysOut(final Writer writer) throws IOException {
}

/**
* Writes out any stderr data that was generated during the
* test execution. If there was no such data then this method just returns.
* Writes out any stderr data that was generated during the test execution. If
* there was no such data then this method just returns.
*
* @param writer The {@link Writer} to use. Cannot be null.
* @throws IOException If any I/O problem occurs during writing the data
Expand All @@ -143,7 +145,8 @@ void writeSysErr(final Writer writer) throws IOException {
this.writeFrom(this.sysErrStore, writer);
}

static Optional<TestIdentifier> traverseAndFindTestClass(final TestPlan testPlan, final TestIdentifier testIdentifier) {
static Optional<TestIdentifier> traverseAndFindTestClass(final TestPlan testPlan,
final TestIdentifier testIdentifier) {
if (isTestClass(testIdentifier).isPresent()) {
return Optional.of(testIdentifier);
}
Expand Down Expand Up @@ -184,22 +187,24 @@ public void close() throws IOException {

protected void handleException(final Throwable t) {
// we currently just log it and move on.
this.context.getProject().ifPresent(p -> p.log("Exception in listener "
+ AbstractJUnitResultFormatter.this.getClass().getName(), t, Project.MSG_DEBUG));
this.context.getProject()
.ifPresent(p -> p.log("Exception in listener " + AbstractJUnitResultFormatter.this.getClass().getName(),
t, Project.MSG_DEBUG));
}


/*
A "store" for sysout/syserr content that gets sent to the AbstractJUnitResultFormatter.
This store first uses a relatively decent sized in-memory buffer for storing the sysout/syserr
content. This in-memory buffer will be used as long as it can fit in the new content that
keeps coming in. When the size limit is reached, this store switches to a file based store
by creating a temporarily file and writing out the already in-memory held buffer content
and any new content that keeps arriving to this store. Once the file has been created,
the in-memory buffer will never be used any more and in fact is destroyed as soon as the
file is created.
Instances of this class are not thread-safe and users of this class are expected to use necessary thread
safety guarantees, if they want to use an instance of this class by multiple threads.
* A "store" for sysout/syserr content that gets sent to the
* AbstractJUnitResultFormatter. This store first uses a relatively decent sized
* in-memory buffer for storing the sysout/syserr content. This in-memory buffer
* will be used as long as it can fit in the new content that keeps coming in.
* When the size limit is reached, this store switches to a file based store by
* creating a temporarily file and writing out the already in-memory held buffer
* content and any new content that keeps arriving to this store. Once the file
* has been created, the in-memory buffer will never be used any more and in
* fact is destroyed as soon as the file is created. Instances of this class are
* not thread-safe and users of this class are expected to use necessary thread
* safety guarantees, if they want to use an instance of this class by multiple
* threads.
*/
private static final class SysOutErrContentStore implements Closeable {
private static final int DEFAULT_CAPACITY_IN_BYTES = 50 * 1024; // 50 KB
Expand Down Expand Up @@ -269,8 +274,8 @@ private FileOutputStream createFileStore() throws IOException {

/*
* Returns a Reader for reading the sysout/syserr content. If there's no data
* available in this store, then this returns a Reader which when used for read operations,
* will immediately indicate an EOF.
* available in this store, then this returns a Reader which when used for read
* operations, will immediately indicate an EOF.
*/
Reader getReader() throws IOException {
if (this.usingFileStore && this.filePath != null) {
Expand All @@ -280,15 +285,16 @@ Reader getReader() throws IOException {
return new BufferedReader(new FileReader(this.filePath.toFile()));
}
if (this.inMemoryStore != null) {
return new InputStreamReader(new ByteArrayInputStream(this.inMemoryStore.array(), 0, this.inMemoryStore.position()));
return new InputStreamReader(
new ByteArrayInputStream(this.inMemoryStore.array(), 0, this.inMemoryStore.position()));
}
// no data to read, so we return an "empty" reader
return EMPTY_READER;
}

/*
* Returns true if this store has any data (either in-memory or in a file). Else
* returns false.
* Returns true if this store has any data (either in-memory or in a file). Else
* returns false.
*/
boolean hasData() {
if (this.inMemoryStore != null && this.inMemoryStore.position() > 0) {
Expand Down
10 changes: 5 additions & 5 deletions bundles/org.eclipse.test/src/org/eclipse/test/AwtScreenshot.java
Expand Up @@ -29,14 +29,14 @@ 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]);
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) {
} catch (HeadlessException | AWTException | IOException e) {
e.printStackTrace();
}
}
Expand Down
36 changes: 22 additions & 14 deletions bundles/org.eclipse.test/src/org/eclipse/test/ClassLoaderTools.java
Expand Up @@ -32,7 +32,8 @@ class ClassLoaderTools {
public static ClassLoader getPluginClassLoader(String getfTestPluginName, ClassLoader currentTCCL) {
Bundle bundle = Platform.getBundle(getfTestPluginName);
if (bundle == null) {
throw new IllegalArgumentException("Bundle \"" + getfTestPluginName + "\" not found. Possible causes include missing dependencies, too restrictive version ranges, or a non-matching required execution environment."); //$NON-NLS-1$ //$NON-NLS-2$
throw new IllegalArgumentException("Bundle \"" + getfTestPluginName //$NON-NLS-1$
+ "\" not found. Possible causes include missing dependencies, too restrictive version ranges, or a non-matching required execution environment."); //$NON-NLS-1$
}
return new TestBundleClassLoader(bundle, currentTCCL);
}
Expand All @@ -42,10 +43,10 @@ public static String getClassPlugin(String className) {
String plugin = null;
while (index != -1) {
plugin = className.substring(0, index);
if(Platform.getBundle(plugin) != null) {
if (Platform.getBundle(plugin) != null) {
break;
}
index = className.lastIndexOf('.', index-1);
index = className.lastIndexOf('.', index - 1);
}
return plugin;
}
Expand Down Expand Up @@ -80,7 +81,7 @@ protected Class<?> findClass(String name) throws ClassNotFoundException {
@Override
protected URL findResource(String name) {
URL url = bundle.getResource(name);
if(url == null) {
if (url == null) {
url = currentTCCL.getResource(name);
}
return url;
Expand All @@ -89,7 +90,7 @@ protected URL findResource(String name) {
@Override
protected Enumeration<URL> findResources(String name) throws IOException {
Enumeration<URL> enumeration = bundle.getResources(name);
if(enumeration == null) {
if (enumeration == null) {
enumeration = currentTCCL.getResources(name);
}
return enumeration;
Expand All @@ -98,8 +99,9 @@ protected Enumeration<URL> findResources(String name) throws IOException {
@Override
public Enumeration<URL> getResources(String res) throws IOException {
Enumeration<URL> urls = currentTCCL.getResources(res);
if(urls.hasMoreElements())
if (urls.hasMoreElements()) {
return urls;
}

List<URL> resources = new ArrayList<>(6);
String location = null;
Expand All @@ -110,41 +112,46 @@ public Enumeration<URL> getResources(String res) throws IOException {
if (location != null && location.startsWith("reference:")) { //$NON-NLS-1$
location = location.substring(10, location.length());
URI uri = URI.create(location);
String newPath =( uri.getPath() == null ? "" : uri.getPath()) + "bin" + '/' + res; //$NON-NLS-1$
String newPath = (uri.getPath() == null ? "" : uri.getPath()) + "bin" + '/' + res; //$NON-NLS-1$
URI newUri = uri.resolve(newPath).normalize();
if(newUri.isAbsolute())
if (newUri.isAbsolute()) {
url = newUri.toURL();
}
}
if (url != null) {
File f = new File(url.getFile());
if (f.exists())
if (f.exists()) {
resources.add(url);
}
else
}
} else {
return Collections.emptyEnumeration();
}

return Collections.enumeration(resources);
}
}

static class MultiBundleClassLoader extends ClassLoader {
private List<Bundle> bundleList;
private final List<Bundle> bundleList;

public MultiBundleClassLoader(List<Bundle> platformEngineBundles) {
this.bundleList = platformEngineBundles;

}

public Class<?> findClasss(String name) throws ClassNotFoundException {
return findClass(name);
}

@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
Class<?> c = null;
for (Bundle temp : bundleList) {
try {
c = temp.loadClass(name);
if (c != null)
if (c != null) {
return c;
}
} catch (ClassNotFoundException e) {
}
}
Expand All @@ -156,8 +163,9 @@ protected URL findResource(String name) {
URL url = null;
for (Bundle temp : bundleList) {
url = temp.getResource(name);
if (url != null)
if (url != null) {
return url;
}
}
return url;
}
Expand Down
Expand Up @@ -24,22 +24,23 @@
*/
public class CoreTestApplication implements IApplication {
/** true if workspace tests should log their deltas */
private static boolean deltas= false;
private static boolean deltas = false;

/**
* Runs a set of tests as defined by the given command line args.
* This is the platform application entry point.
* Runs a set of tests as defined by the given command line args. This is the
* platform application entry point.
*/
public Object run(Object arguments) throws Exception {
String[] args= Platform.getCommandLineArgs();//getCommand//processCommandLine((String[]) arguments);
String[] args = Platform.getCommandLineArgs();// getCommand//processCommandLine((String[]) arguments);
return Integer.valueOf(runTests(args));
}

@Override
public Object start(IApplicationContext context) throws Exception {
String[] args = (String[]) context.getArguments().get("application.args");
if (args == null)
if (args == null) {
args = new String[0];
}
return run(args);
}

Expand Down Expand Up @@ -79,24 +80,26 @@ protected String[] processCommandLine(String[] args) {
}
++i;

// done checking for args. Remember where an arg was found
// done checking for args. Remember where an arg was found
if (found) {
configArgs[configArgIndex++] = i - 1;
configArgs[configArgIndex++] = i;
}
}

//remove all the arguments consumed by this argument parsing
if (configArgIndex == 0)
// remove all the arguments consumed by this argument parsing
if (configArgIndex == 0) {
return args;
}
String[] passThruArgs = new String[args.length - configArgIndex];
configArgIndex = 0;
int j = 0;
for (int i = 0; i < args.length; i++) {
if (i == configArgs[configArgIndex])
if (i == configArgs[configArgIndex]) {
configArgIndex++;
else
} else {
passThruArgs[j++] = args[i];
}
}
return passThruArgs;
}
Expand Down

0 comments on commit 929c6a5

Please sign in to comment.