|
From: <caw...@us...> - 2007-05-15 17:37:52
|
Revision: 2481
http://svn.sourceforge.net/rubyeclipse/?rev=2481&view=rev
Author: cawilliams
Date: 2007-05-15 10:37:49 -0700 (Tue, 15 May 2007)
Log Message:
-----------
a first stab at replacing the portions of things that were hooked into the old symbol index
Modified Paths:
--------------
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/FailureTab.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestHierarchyTab.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestUnitMessages.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestUnitMessages.properties
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestUnitView.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestunitPlugin.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/testunit/launcher/TestUnitLaunchConfigurationDelegate.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/testunit/launcher/TestUnitLaunchShortcut.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenEditorAction.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenTestAction.java
Removed Paths:
-------------
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenLocationAction.java
trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenSymbolAction.java
Modified: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/FailureTab.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/FailureTab.java 2007-05-15 17:36:41 UTC (rev 2480)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/FailureTab.java 2007-05-15 17:37:49 UTC (rev 2481)
@@ -37,8 +37,6 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
-import org.rubypeople.rdt.core.RubyCore;
-import org.rubypeople.rdt.internal.core.symbols.ISymbolFinder;
import org.rubypeople.rdt.testunit.ITestRunListener;
/**
@@ -152,7 +150,7 @@
String methodName = getMethodName();
if (className != null) {
System.err.println("MethodName: " + methodName);
- manager.add(OpenSymbolAction.forMethod(className, methodName, getSymbolFinder(), getShell()));
+ manager.add(new OpenTestAction(fRunnerViewPart, className, methodName, true));
manager.add(new Separator());
manager.add(new RerunAction(fRunnerViewPart, getSelectedTestId(),
className, methodName, ILaunchManager.RUN_MODE));
@@ -166,10 +164,6 @@
}
}
- private ISymbolFinder getSymbolFinder() {
- return RubyCore.getPlugin().getSymbolFinder();
- }
-
private TableItem getSelectedItem() {
int index = fTable.getSelectionIndex();
if (index == -1) return null;
@@ -276,7 +270,7 @@
void handleDoubleClick(MouseEvent e) {
if (fTable.getSelectionCount() > 0)
- OpenSymbolAction.forMethod(getClassName(), getMethodName(), getSymbolFinder(), getShell()).run();
+ new OpenTestAction(fRunnerViewPart, getClassName(), getMethodName(), true).run();
}
private Shell getShell() {
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenEditorAction.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenEditorAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenEditorAction.java 2007-05-15 17:37:49 UTC (rev 2481)
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.testunit.ui;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyModel;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.ui.rubyeditor.EditorUtility;
+
+/**
+ * Abstract Action for opening a Ruby editor.
+ */
+public abstract class OpenEditorAction extends Action {
+ protected String fClassName;
+ protected TestUnitView fTestRunner;
+ private final boolean fActivate;
+
+ protected OpenEditorAction(TestUnitView testRunner, String testClassName) {
+ this(testRunner, testClassName, true);
+ }
+
+ public OpenEditorAction(TestUnitView testRunner, String className, boolean activate) {
+ super(TestUnitMessages.OpenEditorAction_action_label);
+ fClassName= className;
+ fTestRunner= testRunner;
+ fActivate= activate;
+ }
+
+ /*
+ * @see IAction#run()
+ */
+ public void run() {
+ ITextEditor textEditor= null;
+ try {
+ IRubyElement element= findElement(getLaunchedProject(), fClassName);
+ if (element == null) {
+ MessageDialog.openError(getShell(),
+ TestUnitMessages.OpenEditorAction_error_cannotopen_title, TestUnitMessages.OpenEditorAction_error_cannotopen_message);
+ return;
+ }
+ textEditor= (ITextEditor)EditorUtility.openInEditor(element, fActivate);
+ } catch (CoreException e) {
+ ErrorDialog.openError(getShell(), TestUnitMessages.OpenEditorAction_error_dialog_title, TestUnitMessages.OpenEditorAction_error_dialog_message, e.getStatus());
+ return;
+ }
+ if (textEditor == null) {
+ fTestRunner.setInfoMessage(TestUnitMessages.OpenEditorAction_message_cannotopen);
+ return;
+ }
+ reveal(textEditor);
+ }
+
+ protected Shell getShell() {
+ return fTestRunner.getSite().getShell();
+ }
+
+ protected IRubyProject getLaunchedProject() {
+ return fTestRunner.getLaunchedProject();
+ }
+
+ protected String getClassName() {
+ return fClassName;
+ }
+
+ protected abstract IRubyElement findElement(IRubyProject project, String className) throws CoreException;
+
+ protected abstract void reveal(ITextEditor editor);
+
+ protected IType findType(IRubyProject project, String className) throws RubyModelException {
+ return internalFindType(project, className, new HashSet());
+ }
+
+ private IType internalFindType(IRubyProject project, String className, Set/*<IRubyProject>*/ visitedProjects) throws RubyModelException {
+ if (visitedProjects.contains(project))
+ return null;
+
+ IType type= project.findType(className, (IProgressMonitor) null);
+ if (type != null)
+ return type;
+
+ //fix for bug 87492: visit required projects explicitly to also find not exported types
+ visitedProjects.add(project);
+ IRubyModel javaModel= project.getRubyModel();
+ String[] requiredProjectNames= project.getRequiredProjectNames();
+ for (int i= 0; i < requiredProjectNames.length; i++) {
+ IRubyProject requiredProject= javaModel.getRubyProject(requiredProjectNames[i]);
+ if (requiredProject.exists()) {
+ type= internalFindType(requiredProject, className, visitedProjects);
+ if (type != null)
+ return type;
+ }
+ }
+ return null;
+ }
+
+}
Deleted: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenLocationAction.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenLocationAction.java 2007-05-15 17:36:41 UTC (rev 2480)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenLocationAction.java 2007-05-15 17:37:49 UTC (rev 2481)
@@ -1,23 +0,0 @@
-package org.rubypeople.rdt.internal.testunit.ui;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.rubypeople.rdt.internal.core.symbols.Location;
-import org.rubypeople.rdt.internal.ui.util.PositionBasedEditorOpener;
-
-
-public class OpenLocationAction extends Action implements IAction {
-
- private final Location location;
-
- public OpenLocationAction(Location location) {
- super(location.getFilename());
- this.location = location;
- }
-
- public void run() {
- new PositionBasedEditorOpener(location.getFilename(), location.getPosition()).open();
- }
-
-
-}
Deleted: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenSymbolAction.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenSymbolAction.java 2007-05-15 17:36:41 UTC (rev 2480)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenSymbolAction.java 2007-05-15 17:37:49 UTC (rev 2481)
@@ -1,99 +0,0 @@
-package org.rubypeople.rdt.internal.testunit.ui;
-
-import java.util.Set;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Shell;
-import org.rubypeople.rdt.internal.core.symbols.ClassSymbol;
-import org.rubypeople.rdt.internal.core.symbols.ISymbolFinder;
-import org.rubypeople.rdt.internal.core.symbols.Location;
-import org.rubypeople.rdt.internal.core.symbols.MethodSymbol;
-import org.rubypeople.rdt.internal.core.symbols.Symbol;
-import org.rubypeople.rdt.internal.ui.RubyPluginImages;
-import org.rubypeople.rdt.internal.ui.dialogs.ElementListSelectionDialog;
-import org.rubypeople.rdt.internal.ui.util.PositionBasedEditorOpener;
-
-public class OpenSymbolAction extends Action implements IAction {
-
- private final Symbol symbol;
- private final ISymbolFinder finder;
- private final Shell shell;
- private String dialogTitle;
-
- public static IAction forClass(String className, ISymbolFinder finder, Shell shell) {
- return new OpenSymbolAction(new ClassSymbol(className), finder, shell, "Open Class");
- }
-
- public static IAction forMethod(String className, String testMethod,
- ISymbolFinder finder, Shell shell) {
- return new OpenSymbolAction(new MethodSymbol(className, testMethod), finder, shell, "Open Method");
- }
-
- public OpenSymbolAction(Symbol symbol, ISymbolFinder finder, Shell shell, String title) {
- super(TestUnitMessages.OpenEditor_action_label);
- this.shell = shell;
- this.symbol = symbol;
- this.finder = finder;
- this.dialogTitle = title;
- }
-
-
- public void run() {
- Set locations = finder.find(symbol);
- if (locations.size() == 0)
- return;
-
- Location location;
- if (locations.size() == 1) {
- location = (Location) locations.iterator().next();
- } else {
- ElementListSelectionDialog selectionDialog
- = new ElementListSelectionDialog(shell, new LocationLabel());
- selectionDialog.setElements(locations.toArray());
- selectionDialog.setMessage("Select a location");
- selectionDialog.setTitle(dialogTitle);
- selectionDialog.open();
- if (selectionDialog.getReturnCode() == SWT.CANCEL)
- return;
- location= (Location) selectionDialog.getResult()[0];
- }
- PositionBasedEditorOpener editorOpener
- = new PositionBasedEditorOpener(location.getFilename(),
- location.getPosition());
- editorOpener.open();
- }
-
-
- private final class LocationLabel implements ILabelProvider {
- public Image getImage(Object element) {
- return RubyPluginImages.get(RubyPluginImages.IMG_CTOOLS_RUBY_PAGE);
- }
-
- public String getText(Object element) {
- Location location = (Location) element;
- IFile sourceFile = location.getSourceFile();
- return sourceFile.getName() + ":" + location.getPosition().getStartLine() + " - " + sourceFile.getFullPath().removeLastSegments(1);
- }
-
- public void addListener(ILabelProviderListener listener) {
- }
-
- public void dispose() {
- }
-
- public boolean isLabelProperty(Object element, String property) {
- return false;
- }
-
- public void removeListener(ILabelProviderListener listener) {
- }
- }
-
-
-}
Added: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenTestAction.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenTestAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/OpenTestAction.java 2007-05-15 17:37:49 UTC (rev 2481)
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.testunit.ui;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.rubypeople.rdt.core.IMethod;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.ISourceRange;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.RubyConventions;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.core.util.Messages;
+
+/**
+ * Open a class on a Test method.
+ */
+public class OpenTestAction extends OpenEditorAction {
+
+ private String fMethodName;
+ private ISourceRange fRange;
+
+ public OpenTestAction(TestUnitView testRunner, String className, String method) {
+ this(testRunner, className, method, true);
+ }
+
+ public OpenTestAction(TestUnitView testRunner, String className) {
+ this(testRunner, className, null);
+ }
+
+ public OpenTestAction(TestUnitView testRunner, String className, String method, boolean activate) {
+ super(testRunner, className, activate);
+// PlatformUI.getWorkbench().getHelpSystem().setHelp(this, ITestUnitHelpContextIds.OPENTEST_ACTION);
+ fMethodName= method;
+ }
+
+ protected IRubyElement findElement(IRubyProject project, String className) throws RubyModelException {
+ IType type= findType(project, className);
+ if (type == null)
+ return null;
+
+ if (fMethodName == null)
+ return type;
+
+ IMethod method= findMethod(type);
+// if (method == null) { FIXME When we have type hierarchies implemented, uncomment this!
+// ITypeHierarchy typeHierarchy= type.newSupertypeHierarchy(null);
+// IType[] types= typeHierarchy.getAllSuperclasses(type);
+// for (int i= 0; i < types.length; i++) {
+// method= findMethod(types[i]);
+// if (method != null)
+// break;
+// }
+// }
+ if (method == null) {
+ String title= TestUnitMessages.OpenTestAction_error_title;
+ String message= Messages.format(TestUnitMessages.OpenTestAction_error_methodNoFound, fMethodName);
+ MessageDialog.openInformation(getShell(), title, message);
+ return type;
+ }
+ fRange= method.getNameRange();
+ return method;
+ }
+
+ IMethod findMethod(IType type) {
+ IStatus status= RubyConventions.validateMethodName(fMethodName);
+ if (! status.isOK())
+ return null;
+ IMethod method= type.getMethod(fMethodName, new String[0]);
+ if (method != null && method.exists())
+ return method;
+ return null;
+ }
+
+ protected void reveal(ITextEditor textEditor) {
+ if (fRange != null)
+ textEditor.selectAndReveal(fRange.getOffset(), fRange.getLength());
+ }
+
+ public boolean isEnabled() {
+ try {
+ return findType(getLaunchedProject(), getClassName()) != null;
+ } catch (RubyModelException e) {
+ }
+ return false;
+ }
+}
Modified: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestHierarchyTab.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestHierarchyTab.java 2007-05-15 17:36:41 UTC (rev 2480)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestHierarchyTab.java 2007-05-15 17:37:49 UTC (rev 2481)
@@ -41,12 +41,8 @@
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
-import org.rubypeople.rdt.core.RubyCore;
-import org.rubypeople.rdt.internal.core.symbols.ClassSymbol;
-import org.rubypeople.rdt.internal.core.symbols.ISymbolFinder;
import org.rubypeople.rdt.testunit.ITestRunListener;
/*
@@ -412,13 +408,11 @@
return;
IAction action = null;
-
- Shell shell = fTree.getShell();
- ISymbolFinder finder = RubyCore.getPlugin().getSymbolFinder();
+
if (isSuiteSelected())
- action= OpenSymbolAction.forClass(getClassName(), finder, shell);
+ action= new OpenTestAction(fTestRunnerPart, getClassName());
else
- action= OpenSymbolAction.forMethod(getClassName(), getTestMethod(), finder, shell);
+ action= new OpenTestAction(fTestRunnerPart, getClassName(), getTestMethod());
if (action != null && action.isEnabled())
action.run();
@@ -426,18 +420,15 @@
public void menuAboutToShow(IMenuManager manager) {
if (fTree.getSelectionCount() > 0) {
- Shell shell = fTree.getShell();
- ISymbolFinder symbolFinder = RubyCore.getPlugin().getSymbolFinder();
if (isSuiteSelected()) {
- manager.add(OpenSymbolAction.forClass(getClassName(), symbolFinder, shell));
+ manager.add(new OpenTestAction(fTestRunnerPart, getClassName()));
manager.add(new Separator());
if (testClassExists(getClassName()) && !fTestRunnerPart.lastLaunchIsKeptAlive()) {
manager.add(new RerunAction(fTestRunnerPart, getSelectedTestId(), getClassName(), null, ILaunchManager.RUN_MODE));
manager.add(new RerunAction(fTestRunnerPart, getSelectedTestId(), getClassName(), null, ILaunchManager.DEBUG_MODE));
}
} else {
- manager.add(OpenSymbolAction.forMethod(getClassName(),
- getTestMethod(), symbolFinder, shell));
+ manager.add(new OpenTestAction(fTestRunnerPart, getClassName(), getTestMethod(), true));
manager.add(new Separator());
manager.add(new RerunAction(fTestRunnerPart, getSelectedTestId(), getClassName(), getTestMethod(), ILaunchManager.RUN_MODE));
manager.add(new RerunAction(fTestRunnerPart, getSelectedTestId(), getClassName(), getTestMethod(), ILaunchManager.DEBUG_MODE));
@@ -448,7 +439,7 @@
}
private boolean testClassExists(String className) {
- return RubyCore.getPlugin().getSymbolFinder().find(new ClassSymbol(className)).size() > 0;
+ return true; // FIXME We need to re-implement this!
}
public void newTreeEntry(String treeEntry) {
Modified: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestUnitMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestUnitMessages.java 2007-05-15 17:36:41 UTC (rev 2480)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestUnitMessages.java 2007-05-15 17:37:49 UTC (rev 2481)
@@ -71,6 +71,15 @@
public static String TestRunnerViewPart_toggle_vertical_label;
public static String TestRunnerViewPart_toggle_automatic_label;
public static String TestRunnerViewPart_layout_menu;
+ public static String OpenEditorAction_error_cannotopen_title;
+ public static String OpenEditorAction_error_cannotopen_message;
+ public static String OpenEditorAction_error_dialog_title;
+ public static String OpenEditorAction_error_dialog_message;
+ public static String OpenEditorAction_message_cannotopen;
+ public static String OpenTestAction_error_title;
+ public static String OpenTestAction_error_methodNoFound;
+ public static String TestUnitBaseLaunchConfiguration_error_invalidproject;
+ public static String JUnitBaseLaunchConfiguration_dialog_title;
static {
NLS.initializeMessages(BUNDLE_NAME, TestUnitMessages.class);
Modified: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestUnitMessages.properties
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestUnitMessages.properties 2007-05-15 17:36:41 UTC (rev 2480)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestUnitMessages.properties 2007-05-15 17:37:49 UTC (rev 2481)
@@ -17,7 +17,15 @@
HierarchyRunView_tab_title=Hierarchy
OpenEditorAction_action_label=&Go to File
+OpenEditorAction_error_cannotopen_title=Cannot Open Editor
+OpenEditorAction_error_cannotopen_message=Test class not found in selected project
+OpenEditorAction_error_dialog_title=Error
+OpenEditorAction_error_dialog_message=Cannot open editor
+OpenEditorAction_message_cannotopen=Cannot open editor
+OpenTestAction_error_title=Go To Test
+OpenTestAction_error_methodNoFound=Method ''{0}'' not found. Opening the test class.
+
TestRunnerViewPart_jobName=Update JUnit
TestRunnerViewPart_rerunaction_label=Rerun Last Test
TestRunnerViewPart_rerunaction_tooltip=Rerun Last Test
Modified: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestUnitView.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestUnitView.java 2007-05-15 17:36:41 UTC (rev 2480)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestUnitView.java 2007-05-15 17:37:49 UTC (rev 2481)
@@ -63,6 +63,8 @@
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyProject;
import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.internal.core.RubyModelManager;
+import org.rubypeople.rdt.launching.IRubyLaunchConfigurationConstants;
import org.rubypeople.rdt.testunit.ITestRunListener;
import org.rubypeople.rdt.testunit.launcher.TestUnitLaunchConfigurationDelegate;
@@ -474,6 +476,14 @@
public void startTestRunListening(int port, IType type, ILaunch launch) {
if(type != null) fTestProject= type.getRubyProject();
+ else {
+ try {
+ String projectName = launch.getLaunchConfiguration().getAttribute(IRubyLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null);
+ fTestProject = RubyModelManager.getRubyModelManager().getRubyModel().getRubyProject(projectName);
+ } catch (CoreException e) {
+ TestunitPlugin.log(e);
+ }
+ }
fLaunchMode = launch.getLaunchMode();
aboutToLaunch();
@@ -488,12 +498,11 @@
fTestRunnerClient.startListening(listenerArray, port);
fLastLaunch = launch;
- // TODO Uncomment now that we have the type object!
- // setViewPartTitle(type);
- // if (type instanceof IType)
- // setTitleToolTip(((IType)type).getFullyQualifiedName());
- // else
- // setTitleToolTip(type.getElementName());
+ setViewPartTitle(type);
+ if (type instanceof IType)
+ setTitleToolTip(((IType)type).getFullyQualifiedName());
+// else
+// setTitleToolTip(type.getElementName());
}
protected void aboutToLaunch() {
Modified: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestunitPlugin.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestunitPlugin.java 2007-05-15 17:36:41 UTC (rev 2480)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/internal/testunit/ui/TestunitPlugin.java 2007-05-15 17:37:49 UTC (rev 2481)
@@ -246,20 +246,15 @@
if (config != null) {
String typeStr = launch.getAttribute(TestUnitLaunchConfigurationDelegate.TESTTYPE_ATTR);
- // String fileName= launch.getAttribute(TestUnitLaunchConfigurationDelegate.LAUNCH_CONTAINER_ATTR);
if (typeStr != null) {
- // FIXME Get the handle on the test type from the model somehow!
- // IFile script = RubyCore.find(fileName);
- // if (element instanceof IRubyType)
- // launchedType= (IRubyType) element;
+ launchedType = (IType) RubyCore.create(typeStr);
}
-
}
fTrackedLaunches.remove(launch);
final IType finalType= launchedType;
- final int finalPort = Integer.parseInt(launch.getAttribute(TESTUNIT_PORT_ATTR)) ;
+ final int finalPort = Integer.parseInt(launch.getAttribute(TESTUNIT_PORT_ATTR));
getDisplay().asyncExec(new Runnable() {
public void run() {
connectTestRunner(launch, finalType, finalPort);
Modified: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/testunit/launcher/TestUnitLaunchConfigurationDelegate.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/testunit/launcher/TestUnitLaunchConfigurationDelegate.java 2007-05-15 17:36:41 UTC (rev 2480)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/testunit/launcher/TestUnitLaunchConfigurationDelegate.java 2007-05-15 17:37:49 UTC (rev 2481)
@@ -4,11 +4,22 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.IType;
import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.SocketUtil;
+import org.rubypeople.rdt.internal.testunit.ui.TestUnitMessages;
import org.rubypeople.rdt.internal.testunit.ui.TestunitPlugin;
+import org.rubypeople.rdt.launching.IRubyLaunchConfigurationConstants;
import org.rubypeople.rdt.launching.RubyLaunchDelegate;
public class TestUnitLaunchConfigurationDelegate extends RubyLaunchDelegate {
@@ -30,11 +41,72 @@
private int port = -1;
@Override
- public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ IType[] testTypes = findTestTypes(configuration, monitor);
+
+// setDefaultSourceLocator(launch, configuration);
launch.setAttribute(TestunitPlugin.TESTUNIT_PORT_ATTR, Integer.toString(getPort()));
+ if (testTypes.length > 0) launch.setAttribute(TESTTYPE_ATTR, testTypes[0].getHandleIdentifier());
+
+
super.launch(configuration, mode, launch, monitor);
}
+ protected IType[] findTestTypes(ILaunchConfiguration configuration, IProgressMonitor pm) throws CoreException {
+ IRubyProject javaProject= getRubyProject(configuration);
+ if ((javaProject == null) || !javaProject.exists()) {
+ informAndAbort(TestUnitMessages.TestUnitBaseLaunchConfiguration_error_invalidproject, null, IRubyLaunchConfigurationConstants.ERR_NOT_A_RUBY_PROJECT);
+ }
+// if (!TestSearchEngine.hasTestCaseType(javaProject)) {
+// informAndAbort(TestUnitMessages.JUnitBaseLaunchConfiguration_error_junitnotonpath, null, ITestUnitStatusConstants.ERR_JUNIT_NOT_ON_PATH);
+// }
+
+ String containerHandle = configuration.getAttribute(LAUNCH_CONTAINER_ATTR, ""); //$NON-NLS-1$
+ if (containerHandle.length() > 0) {
+ IRubyElement element = RubyCore.create(containerHandle);
+ IRubyScript script = (IRubyScript) element;
+ if (script != null) return new IType[] { script.findPrimaryType() };
+ }
+ String testTypeName= configuration.getAttribute(TESTTYPE_ATTR, (String) null);
+ if (testTypeName != null && testTypeName.length() > 0) {
+ return new IType[] {javaProject.findType(testTypeName, pm)};
+ }
+ return new IType[0];
+ }
+
+ protected void informAndAbort(String message, Throwable exception, int code) throws CoreException {
+ IStatus status= new Status(IStatus.INFO, TestunitPlugin.PLUGIN_ID, code, message, exception);
+ if (showStatusMessage(status))
+ throw new CoreException(status);
+ abort(message, exception, code);
+ }
+
+ private boolean showStatusMessage(final IStatus status) {
+ final boolean[] success= new boolean[] { false };
+ getDisplay().syncExec(
+ new Runnable() {
+ public void run() {
+ Shell shell= TestunitPlugin.getActiveWorkbenchShell();
+ if (shell == null)
+ shell= getDisplay().getActiveShell();
+ if (shell != null) {
+ MessageDialog.openInformation(shell, TestUnitMessages.JUnitBaseLaunchConfiguration_dialog_title, status.getMessage());
+ success[0]= true;
+ }
+ }
+ }
+ );
+ return success[0];
+ }
+
+ private Display getDisplay() {
+ Display display;
+ display= Display.getCurrent();
+ if (display == null)
+ display= Display.getDefault();
+ return display;
+ }
+
public static String getTestRunnerPath() {
String directory = RubyCore.getOSDirectory(TestunitPlugin.getDefault());
File pluginDirFile = new File(directory, "ruby");
@@ -55,7 +127,7 @@
@Override
public String getProgramArguments(ILaunchConfiguration configuration) throws CoreException {
StringBuffer buffer = new StringBuffer();
- buffer.append(configuration.getAttribute(TestUnitLaunchConfigurationDelegate.LAUNCH_CONTAINER_ATTR, ""));
+ buffer.append(getLaunchContainerPath(configuration));
buffer.append(' ');
buffer.append(Integer.toString(getPort()));
buffer.append(' ');
@@ -66,4 +138,13 @@
buffer.append(configuration.getAttribute(TestUnitLaunchConfigurationDelegate.TESTNAME_ATTR, ""));
return buffer.toString();
}
+
+ private String getLaunchContainerPath(ILaunchConfiguration configuration) throws CoreException {
+ String container = configuration.getAttribute(TestUnitLaunchConfigurationDelegate.LAUNCH_CONTAINER_ATTR, "");
+ IRubyElement element = (IRubyElement) RubyCore.create(container);
+ if (element != null)
+ return element.getResource().getLocation().toFile().getAbsolutePath();
+ // otherwise it may be an actual path!
+ return container;
+ }
}
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/testunit/launcher/TestUnitLaunchShortcut.java
===================================================================
--- trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/testunit/launcher/TestUnitLaunchShortcut.java 2007-05-15 17:36:41 UTC (rev 2480)
+++ trunk/org.rubypeople.rdt.testunit/src/org/rubypeople/rdt/testunit/launcher/TestUnitLaunchShortcut.java 2007-05-15 17:37:49 UTC (rev 2481)
@@ -29,11 +29,9 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
import org.rubypeople.rdt.core.IRubyElement;
-import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.debug.ui.launcher.RubyApplicationShortcut;
import org.rubypeople.rdt.internal.testunit.ui.TestUnitMessages;
import org.rubypeople.rdt.internal.testunit.ui.TestunitPlugin;
-import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.launching.IRubyLaunchConfigurationConstants;
import org.rubypeople.rdt.launching.RubyRuntime;
@@ -116,13 +114,15 @@
* @return
*/
private String getContainer(IRubyElement rubyElement) {
- try {
- IFile rubyFile = (IFile) rubyElement.getUnderlyingResource();
- return rubyFile.getProjectRelativePath().toString();
- } catch (RubyModelException e) {
- RubyPlugin.log(e);
- return rubyElement.getElementName();
- }
+ return rubyElement.getHandleIdentifier(); // XXX We always held the absolute file path here before (and RadRails relies on this!) Now what do we do?!
+//
+// try {
+// IFile rubyFile = (IFile) rubyElement.getUnderlyingResource();
+// return rubyFile.getProjectRelativePath().toString();
+// } catch (RubyModelException e) {
+// RubyPlugin.log(e);
+// return rubyElement.getElementName();
+// }
}
protected ILaunchConfiguration createConfiguration(IFile rubyFile, String container, String testName) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|