From 548bea1008ae6938fef3635222f1ff63dd46db93 Mon Sep 17 00:00:00 2001 From: shleh Date: Sat, 18 Sep 2004 17:42:48 +0000 Subject: [PATCH] new class to manage icons. Showing failures,etc on a test suite. --- net.sourceforge.phpeclipse.phpunit/icons/start.gif | Bin 0 -> 359 bytes .../phpeclipse/phpunit/PHPUnitImages.java | 94 ++++++++++++++++++++ .../phpeclipse/phpunit/PHPUnitPlugin.java | 52 ++++++------ .../phpeclipse/phpunit/PHPUnitView.java | 63 +++----------- .../phpeclipse/phpunit/TestPoolLabelProvider.java | 63 ++++++-------- .../phpeclipse/phpunit/testpool/TestCase.java | 5 + .../phpeclipse/phpunit/testpool/TestPool.java | 2 - .../phpeclipse/phpunit/testpool/TestSuite.java | 71 ++++++++++++---- 8 files changed, 218 insertions(+), 132 deletions(-) create mode 100644 net.sourceforge.phpeclipse.phpunit/icons/start.gif create mode 100644 net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitImages.java diff --git a/net.sourceforge.phpeclipse.phpunit/icons/start.gif b/net.sourceforge.phpeclipse.phpunit/icons/start.gif new file mode 100644 index 0000000000000000000000000000000000000000..1486517a607092ba4c6b95373850d2408961dcbc GIT binary patch literal 359 zcmZ?wbhEHb6krfwxXQpFmhCE$>n54!E}icoQ{bso79d~jEnnoVP~@#t=BHW_s9qJM zRU4*R6|7Sirc)oL*ATAX5N^~QW!w^D(h_6T92vg4C}MSC1dv=+=({}4cX_Jsved-& ziHRE$n)fv}?`>$_+nBpGK6h)}6)65>VPs&i zV$cBzgZ#w6*5bgGx=359->u6lbfUt1p(!S!oi@D_CT(+3vXl#F%i!UfY2V9MRG7Kj zSd81PP$%Qvtg~&KJyj;K%Qnf%$+2;SGb<}8DYLLx>AUJra%EIkV`Q4FGf7{2D#If8 w`MOiIji&nR8|toGXJ8y|WofFnUC-2Vvz7TiGZXVYZWbmMhmRb0b!4yx0NTKZh5!Hn literal 0 HcmV?d00001 diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitImages.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitImages.java new file mode 100644 index 0000000..006336a --- /dev/null +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitImages.java @@ -0,0 +1,94 @@ +package net.sourceforge.phpeclipse.phpunit; + +import java.net.MalformedURLException; +import java.net.URL; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.graphics.Image; + +public class PHPUnitImages { + + protected static final String NAME_PREFIX = + "net.sourceforge.phpeclipse.phpunit"; + protected static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length(); + + protected static URL iconBaseURL; + + static { + String pathSuffix = "icons/"; + try { + iconBaseURL = + new URL( + PHPUnitPlugin.getDefault().getDescriptor().getInstallURL(), + pathSuffix); + } catch (MalformedURLException e) { + //PHPUnitPlugin.log(e); + e.printStackTrace(); + } + } + + protected static final ImageRegistry IMAGE_REGISTRY = new ImageRegistry(); + + /* + * Available cached Images in the Java plugin image registry. + */ + + public static final String IMG_SELECT_TEST_SUITE = + NAME_PREFIX + "tsuite.gif"; + public static final String IMG_RUN_TEST_SUITE = NAME_PREFIX + "start.gif"; + public static final String IMG_TEST_ERROR = NAME_PREFIX + "testerr.gif"; + public static final String IMG_TEST_FAILURE = NAME_PREFIX + "testfail.gif"; + public static final String IMG_TEST_PASS = NAME_PREFIX + "testok.gif"; + public static final String IMG_TEST_SUITE_ERROR = NAME_PREFIX + "tsuiteerror.gif"; + public static final String IMG_TEST_SUITE_PASS = NAME_PREFIX + "tsuiteok.gif"; + public static final String IMG_TEST_SUITE_FAILURE = NAME_PREFIX + "tsuitefail.gif"; + + + + + public static final ImageDescriptor DESC_SELECT_TEST_SUITE = createManaged(IMG_SELECT_TEST_SUITE); + public static final ImageDescriptor DESC_RUN_TEST_SUITE =createManaged(IMG_RUN_TEST_SUITE); + public static final ImageDescriptor DESC_TEST_ERROR = createManaged(IMG_TEST_ERROR); + public static final ImageDescriptor DESC_TEST_FAILURE = createManaged(IMG_TEST_FAILURE); + public static final ImageDescriptor DESC_TEST_PASS = createManaged(IMG_TEST_PASS); + public static final ImageDescriptor DESC_TEST_SUITE_ERROR = createManaged(IMG_TEST_SUITE_ERROR); + public static final ImageDescriptor DESC_TEST_SUITE_PASS = createManaged(IMG_TEST_SUITE_PASS); + public static final ImageDescriptor DESC_TEST_SUITE_FAILURE = createManaged(IMG_TEST_SUITE_FAILURE); + + /** + * Returns the image managed under the given key in this registry. + * + * @param key the image's key + * @return the image managed under the given key + */ + public static Image get(String key) { + return IMAGE_REGISTRY.get(key); + } + + public static ImageRegistry getImageRegistry() { + return IMAGE_REGISTRY; + } + + //---- Helper methods to access icons on the file system -------------------------------------- + + protected static ImageDescriptor createManaged(String name) { + try { + ImageDescriptor result = + ImageDescriptor.createFromURL( + makeIconFileURL(name.substring(NAME_PREFIX_LENGTH))); + IMAGE_REGISTRY.put(name, result); + return result; + } catch (MalformedURLException e) { + return ImageDescriptor.getMissingImageDescriptor(); + } + } + + protected static URL makeIconFileURL(String name) + throws MalformedURLException { + if (iconBaseURL == null) + throw new MalformedURLException(); + + return new URL(iconBaseURL, name); + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitPlugin.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitPlugin.java index e3873a4..fb89999 100644 --- a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitPlugin.java +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitPlugin.java @@ -6,15 +6,13 @@ */ package net.sourceforge.phpeclipse.phpunit; -import java.net.MalformedURLException; -import java.net.URL; import java.util.ResourceBundle; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPluginDescriptor; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.plugin.AbstractUIPlugin; @@ -31,21 +29,42 @@ public class PHPUnitPlugin extends AbstractUIPlugin { private static PHPUnitPlugin plugin; private ResourceBundle resourceBundle; - + public static final String PLUGIN_ID= "net.sourceforge.phpeclipse.phpunit"; //$NON-NLS-1$ /** * @param descriptor */ public PHPUnitPlugin(IPluginDescriptor descriptor) { + super(descriptor); - plugin = this; - + System.out.println("desc: " + descriptor.getInstallURL()); + + + plugin= this; + + + String pathSuffix= "icons/"; //$NON-NLS-1$ + + System.out.println("" + Platform.getLocation()); + + System.out.println("" + Platform.getPluginStateLocation(plugin)); + + System.out.println("" + Platform.getLogFileLocation()); + + + } + public String getPath() { + return plugin.getDescriptor().getInstallURL().getFile(); + } + + + public static PHPUnitPlugin getDefault() { return plugin; } @@ -158,25 +177,6 @@ public class PHPUnitPlugin extends AbstractUIPlugin { super.startup(); } - /** - * @param string - */ - public static ImageDescriptor getImageDescriptor(String name) { - - String iconPath = "icons/"; - try { - URL installURL = getDefault().getDescriptor().getInstallURL(); - URL url = new URL(installURL, iconPath + name); - - System.out.println("url:" + url.toExternalForm()); - - return ImageDescriptor.createFromURL(url); - } catch (MalformedURLException e) { - // should not happen - return ImageDescriptor.getMissingImageDescriptor(); - } - - - } + } diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitView.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitView.java index 9f388dd..e304352 100644 --- a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitView.java +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitView.java @@ -6,8 +6,6 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; import net.sourceforge.phpeclipse.phpunit.testpool.TestCase; import net.sourceforge.phpeclipse.phpunit.testpool.TestPool; @@ -15,8 +13,6 @@ import net.sourceforge.phpeclipse.phpunit.testpool.TestSuite; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -183,11 +179,6 @@ public class PHPUnitView extends ViewPart { final IActionBars actionBars = getViewSite().getActionBars(); IToolBarManager toolBarManager = actionBars.getToolBarManager(); - String iconsPath = "C:\\Documents and Settings\\Ali Echihabi\\My Documents\\workspace.eclipse2.1\\net.sourceforge.phpeclipse.phpunit\\icons"; - - ImageDescriptor descriptor = null; - String icon = ""; - Action selectTestAction = new Action() { public void run() { @@ -195,16 +186,10 @@ public class PHPUnitView extends ViewPart { testSuiteToRun = dialog.open(); } }; + selectTestAction.setText("Select Test Suite"); - selectTestAction.setToolTipText("Select Test Suite"); - try { - icon = "tsuite.gif"; - descriptor = ImageDescriptor.createFromURL(new URL("file://" + iconsPath + "//" + icon)); - selectTestAction.setImageDescriptor(descriptor); - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + selectTestAction.setToolTipText("Select Test Suite"); + selectTestAction.setImageDescriptor(PHPUnitImages.DESC_SELECT_TEST_SUITE); toolBarManager.add(selectTestAction); @@ -228,18 +213,11 @@ public class PHPUnitView extends ViewPart { } }; + startTestAction.setText("Start Test"); startTestAction.setToolTipText("Start Test Suite"); - - try { - icon = "start.gif"; - descriptor = ImageDescriptor.createFromURL(new URL("file://" + iconsPath + "//" + icon)); - startTestAction.setImageDescriptor(descriptor); - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - + startTestAction.setImageDescriptor(PHPUnitImages.DESC_RUN_TEST_SUITE); + toolBarManager.add(startTestAction); } @@ -275,29 +253,7 @@ public class PHPUnitView extends ViewPart { } - // action to start tests: - public void startTests() throws IOException { - -// // preparation: -// // take the full test suite (could containt other test suites). -// // create temp php file that starts that suite and uses socketTestReport -// // as a test result reporter. -// // add listener: localhost , port 13579 -// // start listening at port. -// -// testPool = new TestPool("RUN MONDAY 11:15 PM"); -// listenForReports(); -// -// try { -// Runtime.getRuntime().exec("php.exe \"C:/Program Files/Apache Group/Apache2/htdocs/phpUnit/suite.php\""); -// } catch (Exception e) { -// -// e.printStackTrace(); -// } - - startTests("C:/Program Files/Apache Group/Apache2/htdocs/phpUnit/suite.php"); - } public void startTests(String testSuite) throws IOException { @@ -322,7 +278,10 @@ public class PHPUnitView extends ViewPart { out.write("