remove mylyn core net dependency and removed corresponding code
This commit is contained in:
@@ -11,7 +11,6 @@ Require-Bundle: org.eclipse.core.runtime,
|
||||
org.eclipse.swtbot.eclipse.gef.finder,
|
||||
org.eclipse.ui.ide,
|
||||
org.eclipse.ui.views.properties.tabbed,
|
||||
org.eclipse.mylyn.commons.net,
|
||||
org.eclipse.core.net,
|
||||
org.springsource.ide.eclipse.commons.core,
|
||||
org.springsource.ide.eclipse.commons.frameworks.core
|
||||
|
||||
@@ -1,171 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Pivotal Software, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal Software, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springsource.ide.eclipse.commons.tests.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.springsource.ide.eclipse.commons.core.HttpUtil;
|
||||
|
||||
|
||||
/**
|
||||
* Manages a cache of downloaded files used by tests.
|
||||
*
|
||||
* @author Kris De Volder, Steffen Pingel
|
||||
*
|
||||
* @since 2.8
|
||||
*/
|
||||
public class DownloadManager {
|
||||
|
||||
/**
|
||||
* An instance of this interface represent an action to execute on a downloaded
|
||||
* File. The action may indicate failure by throwing an exception or by
|
||||
* returning false. A failed action may trigger the DownloadManager to
|
||||
* clear the cache and try again for a limited number of times.
|
||||
*/
|
||||
public interface DownloadRequestor {
|
||||
void exec(File downloadedFile) throws Exception;
|
||||
}
|
||||
|
||||
private final String cacheDirectory;
|
||||
|
||||
private static DownloadManager defaultInstance = null;
|
||||
|
||||
public static DownloadManager getDefault() {
|
||||
if (defaultInstance==null) {
|
||||
defaultInstance = new DownloadManager();
|
||||
}
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
public DownloadManager() {
|
||||
this(System.getProperty(
|
||||
"com.springsource.sts.tests.cache",
|
||||
System.getProperty("user.home") + File.separatorChar + ".sts-test-cache"));
|
||||
deleteBuildSnapshots();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build snapshots from a previous test run shouldn't be used from the cache. So delete them
|
||||
* when the DownloadManager instance is created.
|
||||
*/
|
||||
private void deleteBuildSnapshots() {
|
||||
//Only do this on the build site, locally it is easy enough to delete buildsnaps manually
|
||||
// as needed/desired.
|
||||
if (StsTestUtil.isOnBuildSite()) {
|
||||
File cache = new File(cacheDirectory);
|
||||
if (cache.isDirectory()) {
|
||||
String[] names = cache.list();
|
||||
for (String name : names) {
|
||||
if (name.contains("SNAPSHOT")) {
|
||||
try {
|
||||
new File(cache, name).delete();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DownloadManager(String cacheDir) {
|
||||
this.cacheDirectory = cacheDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is deprecated, please use doWithDownload to provide proper recovery
|
||||
* for cache corruption.
|
||||
*/
|
||||
@Deprecated
|
||||
public File downloadFile(URI uri) throws URISyntaxException, FileNotFoundException, CoreException, IOException {
|
||||
String protocol = uri.getScheme();
|
||||
if ("file".equals(protocol)) {
|
||||
return new File(uri);
|
||||
}
|
||||
|
||||
String path = uri.getPath();
|
||||
int i = path.lastIndexOf("/");
|
||||
if (i >= 0) {
|
||||
path = path.substring(i + 1);
|
||||
}
|
||||
|
||||
File target = new File(cacheDirectory, path);
|
||||
if (target.exists()) {
|
||||
return target;
|
||||
}
|
||||
|
||||
File cache = new File(cacheDirectory);
|
||||
if (!cache.exists()) {
|
||||
cache.mkdirs();
|
||||
}
|
||||
|
||||
File targetPart = new File(cache, path + ".part");
|
||||
FileOutputStream out = new FileOutputStream(targetPart);
|
||||
try {
|
||||
System.out.println("Downloading " + uri + " to " + target);
|
||||
HttpUtil.download(uri, out, null);
|
||||
}
|
||||
finally {
|
||||
out.close();
|
||||
}
|
||||
|
||||
if (!targetPart.renameTo(target)) {
|
||||
throw new IOException("Error while renaming " + targetPart + " to " + target);
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method tries to download or fetch a File from the cache, then passes the
|
||||
* downloaded file to the DownloadRequestor.
|
||||
* <p>
|
||||
* If the requestor fails to properly execute on the downloaded file, the cache
|
||||
* will be presumed to be corrupt. The file will be deleted from the cache
|
||||
* and the download will be tried again. (for a limited number of times)
|
||||
*/
|
||||
public void doWithDownload(URI target, DownloadRequestor action) throws Exception {
|
||||
int tries = 4; // try at most X times
|
||||
Exception e = null;
|
||||
File downloadedFile = null;
|
||||
do {
|
||||
tries--;
|
||||
try {
|
||||
downloadedFile = downloadFile(target);
|
||||
action.exec(downloadedFile);
|
||||
return; // action and download succeeded without exceptions
|
||||
} catch (Exception caught) {
|
||||
caught.printStackTrace();
|
||||
//Presume the cache may be corrupt!
|
||||
System.out.println("Delete corrupt download: "+downloadedFile);
|
||||
//downloaded file may be null if download failed, rather than its processing:
|
||||
if (downloadedFile!=null) {
|
||||
downloadedFile.delete();
|
||||
}
|
||||
e = caught;
|
||||
}
|
||||
} while (tries>0);
|
||||
//Can only get here if action or download failed...
|
||||
//thus, e can not be null.
|
||||
throw e;
|
||||
}
|
||||
|
||||
public File getCacheDir() {
|
||||
return new File(cacheDirectory);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,283 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Pivotal Software, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal Software, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springsource.ide.eclipse.commons.tests.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.ProxySelector;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestFailure;
|
||||
import junit.framework.TestListener;
|
||||
import junit.framework.TestResult;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.core.internal.jobs.JobManager;
|
||||
import org.eclipse.core.net.proxy.IProxyData;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.mylyn.commons.net.WebUtil;
|
||||
import org.eclipse.mylyn.internal.commons.net.CommonsNetPlugin;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swtbot.swt.finder.utils.ClassUtils;
|
||||
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
|
||||
import org.eclipse.swtbot.swt.finder.utils.SWTUtils;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
/**
|
||||
* Prints the name of each test to System.err when it started and dumps a stack
|
||||
* trace of all thread to System.err if a test takes longer than 10 minutes.
|
||||
* @author Steffen Pingel
|
||||
* @author Kris De Volder
|
||||
*/
|
||||
public class ManagedTestSuite extends TestSuite {
|
||||
|
||||
private class DumpThreadTask extends TimerTask {
|
||||
|
||||
private final Test test;
|
||||
|
||||
private final Thread testThread;
|
||||
|
||||
public DumpThreadTask(Test test, Thread testThread) {
|
||||
this.test = test;
|
||||
this.testThread = testThread;
|
||||
}
|
||||
|
||||
private void dumpJobs() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(MessageFormat.format("Jobs:\n", test.toString()));
|
||||
Job[] jobs = Job.getJobManager().find(null);
|
||||
for (Job job : jobs) {
|
||||
sb.append(job.getName().toString());
|
||||
sb.append(" [");
|
||||
sb.append(JobManager.printState(job.getState()));
|
||||
sb.append(", ");
|
||||
sb.append(job.getClass().getName());
|
||||
sb.append("]");
|
||||
sb.append("\n");
|
||||
}
|
||||
System.err.println(sb.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// dump all thread for diagnosis
|
||||
StringBuffer sb = StsTestUtil.getStackDumps();
|
||||
System.err.println(
|
||||
MessageFormat.format("Test {0} is taking too long:\n", test.toString()) +
|
||||
sb.toString());
|
||||
dumpJobs();
|
||||
|
||||
// killTest("Test is taking too long");
|
||||
|
||||
// capture screenshot for diagnosis
|
||||
final String fileName = "screenshots/screenshot-" + ClassUtils.simpleClassName(test.getClass()) + "." //$NON-NLS-1$ //$NON-NLS-2$
|
||||
+ SWTBotPreferences.SCREENSHOT_FORMAT.toLowerCase();
|
||||
File screenshotFile = new File("screenshots");
|
||||
System.err.println("Captured screenshot to " + screenshotFile.getAbsolutePath());
|
||||
screenshotFile.mkdirs();
|
||||
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
// This deadlocks when run in UI thread!
|
||||
SWTUtils.captureScreenshot(fileName);
|
||||
}
|
||||
});
|
||||
|
||||
// attempt to close any modal dialogs
|
||||
if (test instanceof ShutdownWatchdog) {
|
||||
Display.getDefault().asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
||||
if (window != null) {
|
||||
Shell shell = window.getShell();
|
||||
Shell[] shells = window.getShell().getDisplay().getShells();
|
||||
for (Shell child : shells) {
|
||||
if (child != shell) {
|
||||
child.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void killTest(String debugInfo) {
|
||||
try {
|
||||
// Yes, the stop method is deprecated, but I don't know another
|
||||
// way to attempt to stop a runaway test without the cooperation
|
||||
// of the test/thread itself. This may not work as desired in
|
||||
// all cases, but is almost certainly better than leaving the
|
||||
// "stuck" test hanging.
|
||||
System.err.println("[TIMEOUT] " + test);
|
||||
testThread.stop();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private class Listener implements TestListener {
|
||||
|
||||
private DumpThreadTask task;
|
||||
|
||||
private Timer timer = new Timer(true);
|
||||
|
||||
public void addError(Test test, Throwable t) {
|
||||
System.err.println("[ERROR]");
|
||||
}
|
||||
|
||||
public void addFailure(Test test, AssertionFailedError t) {
|
||||
System.err.println("[FAILURE]");
|
||||
}
|
||||
|
||||
private void dumpList(String header, Enumeration<TestFailure> failures) {
|
||||
System.err.println(header);
|
||||
while (failures.hasMoreElements()) {
|
||||
TestFailure failure = failures.nextElement();
|
||||
System.err.print(" ");
|
||||
System.err.println(failure.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void dumpResults(TestResult result) {
|
||||
System.err.println();
|
||||
dumpList("Failures: ", result.failures());
|
||||
|
||||
System.err.println();
|
||||
dumpList("Errors: ", result.errors());
|
||||
|
||||
int failedCount = result.errorCount() + result.failureCount();
|
||||
System.err.println();
|
||||
System.err.println(MessageFormat.format("{0} out of {1} tests failed", failedCount, result.runCount()));
|
||||
}
|
||||
|
||||
public void endTest(Test test) {
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void startTest(Test test) {
|
||||
Thread testThread = Thread.currentThread();
|
||||
System.err.println("Running " + test.toString());
|
||||
task = new DumpThreadTask(test, testThread);
|
||||
try {
|
||||
timer.scheduleAtFixedRate(task, DELAY, DELAY);
|
||||
} catch (IllegalStateException e) {
|
||||
//No idea where, who or why, but timer gets 'canceled'.
|
||||
// We'll need a new one
|
||||
timer = new Timer(true);
|
||||
timer.scheduleAtFixedRate(task, DELAY, DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ShutdownWatchdog implements Test {
|
||||
|
||||
public int countTestCases() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void run(TestResult result) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ShutdownWatchdog";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public long DELAY = 10 * 60 * 1000;
|
||||
|
||||
private final Listener listener = new Listener();
|
||||
|
||||
public ManagedTestSuite() {
|
||||
}
|
||||
|
||||
public ManagedTestSuite(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(TestResult result) {
|
||||
result.addListener(listener);
|
||||
dumpSystemInfo();
|
||||
super.run(result);
|
||||
listener.dumpResults(result);
|
||||
|
||||
// add dummy test to dump threads in case shutdown hangs
|
||||
listener.startTest(new ShutdownWatchdog());
|
||||
}
|
||||
|
||||
private void dumpSystemInfo() {
|
||||
try {
|
||||
if (Platform.isRunning() && CommonsNetPlugin.getProxyService() != null
|
||||
&& CommonsNetPlugin.getProxyService().isSystemProxiesEnabled()
|
||||
&& !CommonsNetPlugin.getProxyService().hasSystemProxies()) {
|
||||
// XXX e3.5/gtk.x86_64 activate manual proxy configuration which
|
||||
// defaults to Java system properties if system proxy support is
|
||||
// not available
|
||||
System.err.println("Forcing manual proxy configuration");
|
||||
CommonsNetPlugin.getProxyService().setSystemProxiesEnabled(false);
|
||||
CommonsNetPlugin.getProxyService().setProxiesEnabled(true);
|
||||
}
|
||||
|
||||
Properties p = System.getProperties();
|
||||
if (Platform.isRunning()) {
|
||||
p.put("build.system", Platform.getOS() + "-" + Platform.getOSArch() + "-" + Platform.getWS());
|
||||
}
|
||||
else {
|
||||
p.put("build.system", "standalone");
|
||||
}
|
||||
String info = "System: ${os.name} ${os.version} (${os.arch}) / ${build.system} / ${java.vendor} ${java.vm.name} ${java.version}";
|
||||
for (Entry<Object, Object> entry : p.entrySet()) {
|
||||
info = info.replaceFirst(Pattern.quote("${" + entry.getKey() + "}"), entry.getValue().toString());
|
||||
}
|
||||
System.err.println(info);
|
||||
System.err.print("Proxy : " + WebUtil.getProxy("google.com", IProxyData.HTTP_PROXY_TYPE) + " (Platform)");
|
||||
try {
|
||||
System.err.print(" / " + ProxySelector.getDefault().select(new URI("https://google.com")) + " (Java)");
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
// ignore
|
||||
}
|
||||
System.err.println();
|
||||
System.err.println();
|
||||
}
|
||||
catch (ConcurrentModificationException e) {
|
||||
// Not sure why but sometimes thrown by the code that is dumping out
|
||||
// system properties!
|
||||
// Catch and print it, but don't abort the test runner simply
|
||||
// because this info can't be dumped.
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Pivotal Software, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal Software, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springsource.ide.eclipse.commons.tests.util;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* A test to test ManagedTestSuite. We want to try to more gracefully handle
|
||||
* hanging tests by terminating just the offending test, not the whole build.
|
||||
* <p>
|
||||
* This test isn't part of the build and isn't supposed to "pass". It's just
|
||||
* something I wipped up to play around with ManagedTestSuite.
|
||||
* <p>
|
||||
* In Eclipse: run this test as JUnitPluginTest/SWTBotTest and the expected behaviour is to
|
||||
* see "testThatHangs" fail and the other tests pass (rather than the test run
|
||||
* hanging).
|
||||
* @author Kris De Volder
|
||||
*/
|
||||
public class TestTests {
|
||||
|
||||
public static class HangingTest extends TestCase {
|
||||
|
||||
public void testThatHangs() throws Exception {
|
||||
while (true) {
|
||||
}
|
||||
}
|
||||
|
||||
public void testGoodOne() throws Exception {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class GoodTest extends TestCase {
|
||||
public void testGoodA() throws Exception {
|
||||
}
|
||||
|
||||
public void testGoodB() throws Exception {
|
||||
}
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
ManagedTestSuite suite = new ManagedTestSuite(TestTests.class.getName());
|
||||
suite.DELAY = 15000; // Make this go a little faster :-)
|
||||
suite.addTestSuite(HangingTest.class);
|
||||
suite.addTestSuite(GoodTest.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user