Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 47778 Details for
Bug 90628
JUnit integration between Hyades and JDT. (theme 3)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Intermediate patch
patch_90628.patch (text/plain), 123.55 KB, created by
Julien Canches
on 2006-08-11 13:11:57 EDT
(
hide
)
Description:
Intermediate patch
Filename:
MIME Type:
Creator:
Julien Canches
Created:
2006-08-11 13:11:57 EDT
Size:
123.55 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.hyades.test.tools.ui_90628 >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JUnitFolderProxyNode.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JUnitFolderProxyNode.java,v >retrieving revision 1.3 >diff -u -r1.3 JUnitFolderProxyNode.java >--- src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JUnitFolderProxyNode.java 9 Jun 2005 09:33:48 -0000 1.3 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JUnitFolderProxyNode.java 11 Aug 2006 17:09:30 -0000 >@@ -12,10 +12,7 @@ > **********************************************************************/ > package org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator; > >-import java.util.List; >- > import org.eclipse.core.resources.IContainer; >-import org.eclipse.hyades.test.tools.ui.java.internal.util.TestJavaUtil; > import org.eclipse.hyades.test.ui.navigator.IFileProxyManager; > import org.eclipse.hyades.test.ui.navigator.IResourceChangeListenerProxyNode; > import org.eclipse.hyades.test.ui.navigator.ITestFolderContentValidator; >@@ -38,7 +35,6 @@ > /** the type of test that this provider proxy node covers */ > private String type; > private String name; >- private List sourceFolders; > private ITestFolderContentValidator validator; > private IFileProxyManager fileProxyManager; > >@@ -59,7 +55,6 @@ > } > protected JUnitFolderProxyNode(IContainer container, ITestFolderContentValidator validator, String type, IFileProxyManager fileProxyManager, Object parent) { > super(container, validator, fileProxyManager, false, parent); >- sourceFolders = TestJavaUtil.getSourceFolders(JavaCore.create(container.getProject())); > this.validator = validator; > this.fileProxyManager = fileProxyManager; > } >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/PackageProxyNode.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/PackageProxyNode.java,v >retrieving revision 1.3 >diff -u -r1.3 PackageProxyNode.java >--- src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/PackageProxyNode.java 9 Jun 2005 09:33:48 -0000 1.3 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/PackageProxyNode.java 11 Aug 2006 17:09:30 -0000 >@@ -139,6 +139,9 @@ > return null; > } > } >+ if (adapter.isAssignableFrom(IPackageFragment.class)) { >+ return fragment; >+ } > return null; > } > >@@ -329,7 +332,7 @@ > } else { > //- this should never arrive, because the proxy of a folder > //- should be a IResourceChangeListenerProxyNode >- UiPlugin.logError("The proxy node derived from a folder should be a IResourceChangeListenerProxyNode"); // $NON-NLS-1$ >+ UiPlugin.logError("The proxy node derived from a folder should be a IResourceChangeListenerProxyNode"); // $NON-NLS-1$ //$NON-NLS-1$ > } > } > } >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JUnitTypeProvider.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JUnitTypeProvider.java,v >retrieving revision 1.7 >diff -u -r1.7 JUnitTypeProvider.java >--- src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JUnitTypeProvider.java 21 Apr 2006 14:24:40 -0000 1.7 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JUnitTypeProvider.java 11 Aug 2006 17:09:30 -0000 >@@ -36,8 +36,8 @@ > public class JUnitTypeProvider implements ITypeProvider, IResourceChangeListener, IDisposable { > > /** The file proxy manager used to cache file proxies */ >- private IFileProxyManager fileProxyManager; >- private IProxyNodeListener refresher; >+ protected IFileProxyManager fileProxyManager; >+ protected IProxyNodeListener refresher; > > private Map projectToProxyMap = new HashMap(); > >@@ -53,9 +53,9 @@ > return null; > } > if(projectToProxyMap.containsKey(project)) { >- return (JUnitTypeProviderProxyNode) projectToProxyMap.get(project); >+ return (ITypeProviderProxyNode) projectToProxyMap.get(project); > } else { >- JUnitTypeProviderProxyNode node = JUnitTypeProviderProxyNode.create(project, type, fileProxyManager, project); >+ ITypeProviderProxyNode node = createTypeProviderProxyNode(project, type); > if (node != null) { > projectToProxyMap.put(project, node); > } >@@ -69,6 +69,10 @@ > // return node; > } > >+ protected ITypeProviderProxyNode createTypeProviderProxyNode(IProject project, String type) { >+ return JUnitTypeProviderProxyNode.create(project, type, fileProxyManager, project); >+ } >+ > /* (non-Javadoc) > * @see org.eclipse.hyades.test.ui.navigator.ITypeProvider#init(org.eclipse.hyades.test.ui.navigator.ITypeProviderContext) > */ >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JUnitTypeProviderProxyNode.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JUnitTypeProviderProxyNode.java,v >retrieving revision 1.6 >diff -u -r1.6 JUnitTypeProviderProxyNode.java >--- src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JUnitTypeProviderProxyNode.java 9 Jun 2005 09:33:48 -0000 1.6 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JUnitTypeProviderProxyNode.java 11 Aug 2006 17:09:30 -0000 >@@ -113,9 +113,9 @@ > IPackageFragmentRoot root = getProjectAsSourceFolder(project); > if(root == null) { > //- the current project is not a source folder >- proxy = JUnitFolderProxyNode.create(project, validator, type, fileProxyManager, parent); >+ proxy = createNonSourceFolderProxyNode(project, type, fileProxyManager, parent); > } else { >- proxy = SourceFolderProxyNode.create(root, validator, fileProxyManager, parent); >+ proxy = createSourceFolderProxyNode(fileProxyManager, parent, root); > } > AssociationMappingRegistry registry = (AssociationMappingRegistry)TestUIExtension.getTestSuiteMappingRegistry(); > IAssociationMapping associationMapping = registry.getAssociationMapping(HyadesUIPlugin.EP_TYPE_DESCRIPTIONS); >@@ -130,8 +130,29 @@ > this.fileProxyManager = fileProxyManager; > this.parent = parent; > } >+ >+ /** >+ * @param fileProxyManager >+ * @param parent >+ * @param root >+ * @return >+ */ >+ protected IProxyNode createSourceFolderProxyNode(IFileProxyManager fileProxyManager, Object parent, IPackageFragmentRoot root) { >+ return SourceFolderProxyNode.create(root, validator, fileProxyManager, parent); >+ } >+ >+ /** >+ * @param project >+ * @param type >+ * @param fileProxyManager >+ * @param parent >+ * @return >+ */ >+ protected IProxyNode createNonSourceFolderProxyNode(IProject project, String type, IFileProxyManager fileProxyManager, Object parent) { >+ return JUnitFolderProxyNode.create(project, validator, type, fileProxyManager, parent); >+ } > >- private IProxyNode getDelegate() { >+ protected IProxyNode getDelegate() { > return proxy; > } > >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/JUnitImportWizard.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/JUnitImportWizard.java,v >retrieving revision 1.8 >diff -u -r1.8 JUnitImportWizard.java >--- src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/JUnitImportWizard.java 22 May 2006 18:21:29 -0000 1.8 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/JUnitImportWizard.java 11 Aug 2006 17:09:30 -0000 >@@ -20,7 +20,6 @@ > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.SubProgressMonitor; >-import org.eclipse.hyades.test.tools.core.common.TestCommon; > import org.eclipse.hyades.test.tools.core.java.JUnitTestSuiteFacade; > import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin; > import org.eclipse.hyades.test.tools.ui.java.TestJavaImages; >@@ -57,7 +56,9 @@ > * @see Wizard#performFinish > */ > public boolean performFinish() { >+ page1.saveDialogSettings(); > final List junitScripts = page1.getSelectedElements(); >+ final String type = page1.getSelectedType(); > IRunnableWithProgress operation = new WorkspaceModifyOperation() { > public void execute(IProgressMonitor monitor) throws InvocationTargetException { > try { >@@ -67,7 +68,7 @@ > //- by construction all elements checked should be of type ICompilationUnit > if (object instanceof ICompilationUnit) { > ICompilationUnit cu = (ICompilationUnit) object; >- generateTest(cu, new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); >+ generateTest(type, cu, new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); > } else { > ToolsUiPlugin.logError("Returned element of JUnit scripts selection page should be a Compilation Unit"); //$NON-NLS-1$ > } >@@ -93,10 +94,10 @@ > * @param project > * @param overwrite > */ >- protected void generateTest(ICompilationUnit cu, SubProgressMonitor monitor) { >+ protected void generateTest(String type, ICompilationUnit cu, SubProgressMonitor monitor) { > monitor.beginTask(MessageFormat.format(ToolsUiPlugin.getString("GENERATING_LABEL"), new Object[]{ cu.getElementName()}), 1); //$NON-NLS-1$ > try { >- JUnitTestSuiteFacade.createTestSuite(cu, TestCommon.JUNIT_TEST_SUITE_TYPE, /*force*/false); >+ JUnitTestSuiteFacade.createTestSuite(cu, type, /*force*/false); > } catch (CoreException e) { > UiPlugin.logError(e); > } finally { >@@ -115,6 +116,7 @@ > > public void addPages() { > page1 = createJUnitScriptsSelectionPage(); >+ page1.init(selection); > addPage(page1); > } > >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/JUnitScriptsSelectionPage.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/JUnitScriptsSelectionPage.java,v >retrieving revision 1.4 >diff -u -r1.4 JUnitScriptsSelectionPage.java >--- src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/JUnitScriptsSelectionPage.java 25 Oct 2005 15:49:32 -0000 1.4 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/JUnitScriptsSelectionPage.java 11 Aug 2006 17:09:30 -0000 >@@ -11,29 +11,58 @@ > *******************************************************************************/ > package org.eclipse.hyades.test.tools.ui.java.internal.junit.wizard; > >+import java.util.ArrayList; >+import java.util.Iterator; > import java.util.List; > > import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.IAdaptable; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitExtensionsRegistry; >+import org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitExtensionsRegistry.JUnitTestSuiteFactoryDescriptor; >+import org.eclipse.hyades.test.tools.core.java.IJUnitTestSuiteFactory; > import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin; >+import org.eclipse.hyades.test.ui.TestUIExtension; >+import org.eclipse.hyades.ui.HyadesUIPlugin; >+import org.eclipse.hyades.ui.extension.IAssociationDescriptor; >+import org.eclipse.hyades.ui.extension.IAssociationMapping; >+import org.eclipse.hyades.ui.internal.extension.AssociationMappingRegistry; > import org.eclipse.hyades.ui.util.TreeSelector; > import org.eclipse.jdt.core.ICompilationUnit; > import org.eclipse.jdt.core.IJavaModel; > import org.eclipse.jdt.core.JavaCore; > import org.eclipse.jdt.ui.JavaElementLabelProvider; >+import org.eclipse.jface.dialogs.IDialogSettings; > import org.eclipse.jface.viewers.CheckStateChangedEvent; >+import org.eclipse.jface.viewers.ComboViewer; > import org.eclipse.jface.viewers.ICheckStateListener; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.ISelectionChangedListener; >+import org.eclipse.jface.viewers.IStructuredContentProvider; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.viewers.LabelProvider; >+import org.eclipse.jface.viewers.SelectionChangedEvent; >+import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.jface.viewers.Viewer; > import org.eclipse.jface.wizard.WizardPage; > import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.layout.GridData; > import org.eclipse.swt.layout.GridLayout; > import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Label; > > /** > * @author jgout > */ > public class JUnitScriptsSelectionPage extends WizardPage implements ICheckStateListener { > >- private TreeSelector selector; >+ private static final String DS_TYPE = "type"; //$NON-NLS-1$ >+ >+ private TreeSelector selector; >+ private ComboViewer testFactoryList; >+ private JUnitWorkspaceContentProvider contentProvider; >+ protected List initialSelection; > > public JUnitScriptsSelectionPage() { > super("JUnitScriptSelectionPage"); //$NON-NLS-1$ >@@ -45,24 +74,131 @@ > public void createControl(Composite parent) { > initializeDialogUnits(parent); > Composite composite = new Composite(parent, SWT.NULL); >- GridLayout gl = new GridLayout(); >- gl.numColumns = 1; >+ GridLayout gl = new GridLayout(2, false); > composite.setLayout(gl); >- composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); >+ gl.verticalSpacing = 20; >+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); > composite.setFont(parent.getFont()); >+ >+ Label label = new Label(composite, SWT.NONE); >+ label.setText("Destination type:"); >+ label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); >+ testFactoryList = new ComboViewer(composite, SWT.DROP_DOWN | SWT.READ_ONLY); >+ testFactoryList.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); >+ testFactoryList.setContentProvider(new IStructuredContentProvider() { >+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >+ // n/a >+ } >+ public void dispose() { >+ // NOP >+ } >+ public Object[] getElements(Object inputElement) { >+ return JUnitExtensionsRegistry.getInstance().getAvailableFactories(/*updateSupport*/false); >+ } >+ }); >+ testFactoryList.setLabelProvider(new LabelProvider() { >+ public String getText(Object element) { >+ String type = ((JUnitExtensionsRegistry.JUnitTestSuiteFactoryDescriptor)element).getType(); >+ AssociationMappingRegistry registry = (AssociationMappingRegistry)TestUIExtension.getTestSuiteMappingRegistry(); >+ IAssociationMapping associationMapping = registry.getAssociationMapping(HyadesUIPlugin.EP_TYPE_DESCRIPTIONS); >+ IAssociationDescriptor descriptor = associationMapping.getDefaultAssociationDescriptor(type); >+ return descriptor.getName(); >+ } >+ public Image getImage(Object element) { >+ String type = ((JUnitExtensionsRegistry.JUnitTestSuiteFactoryDescriptor)element).getType(); >+ AssociationMappingRegistry registry = (AssociationMappingRegistry)TestUIExtension.getTestSuiteMappingRegistry(); >+ IAssociationMapping associationMapping = registry.getAssociationMapping(HyadesUIPlugin.EP_TYPE_DESCRIPTIONS); >+ IAssociationDescriptor descriptor = associationMapping.getDefaultAssociationDescriptor(type); >+ return descriptor.getImage(); >+ } >+ }); >+ testFactoryList.setInput(ResourcesPlugin.getWorkspace().getRoot()); >+ testFactoryList.addSelectionChangedListener(new ISelectionChangedListener() { >+ public void selectionChanged(SelectionChangedEvent event) { >+ IJUnitTestSuiteFactory factory = getTestSuiteFactory(); >+ if (factory != null) { >+ contentProvider.setJUnitTestSuiteFactory(factory); >+ List checkedElements; >+ if (initialSelection != null) { >+ checkedElements = initialSelection; >+ initialSelection = null; >+ } else { >+ checkedElements = selector.getSelectedElements(); >+ } >+ IJavaModel javaWorkspace = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); >+ selector.setInput(null); >+ selector.setInput(javaWorkspace); >+ selector.setInitialCheckedElements(checkedElements); >+ setPageComplete(true); >+ setErrorMessage(null); >+ } else { >+ selector.setInput(null); >+ setPageComplete(false); >+ setErrorMessage("The selected generator has encountered an internal error"); >+ } >+ } >+ }); >+ > //- build the selection widget > IJavaModel javaWorkspace = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); > JavaElementLabelProvider javaLabelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT); >- JUnitWorkspaceContentProvider contentProvider = createContentProvider(); >+ contentProvider = new JUnitWorkspaceContentProvider(); > selector = new TreeSelector(composite, javaWorkspace, contentProvider, javaLabelProvider, SWT.BORDER); > contentProvider.setRunnableContext(this.getContainer()); > selector.getTreeViewer().addCheckStateListener(this); >+ selector.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); >+ >+ readDialogSettings(); >+ > setPageComplete(false); > setControl(composite); > } > >- protected JUnitWorkspaceContentProvider createContentProvider() { >- return new JUnitWorkspaceContentProvider(); >+ protected void init(IStructuredSelection selection) { >+ Iterator it = selection.iterator(); >+ initialSelection = new ArrayList(selection.size()); >+ while (it.hasNext()) { >+ Object o = it.next(); >+ if (o instanceof IAdaptable) { >+ ICompilationUnit cu = (ICompilationUnit) ((IAdaptable)o).getAdapter(ICompilationUnit.class); >+ if (cu != null) { >+ initialSelection.add(cu); >+ } >+ } >+ } >+ } >+ >+ protected IJUnitTestSuiteFactory getTestSuiteFactory() { >+ ISelection selection = testFactoryList.getSelection(); >+ if (selection instanceof IStructuredSelection) { >+ JUnitExtensionsRegistry.JUnitTestSuiteFactoryDescriptor descr = >+ (JUnitExtensionsRegistry.JUnitTestSuiteFactoryDescriptor) ((IStructuredSelection)selection).getFirstElement(); >+ if (descr != null) { >+ return descr.getFactory(); >+ } >+ } >+ return null; >+ } >+ >+ public String getSelectedType() { >+ ISelection selection = testFactoryList.getSelection(); >+ if (selection instanceof IStructuredSelection) { >+ JUnitTestSuiteFactoryDescriptor descr = >+ (JUnitTestSuiteFactoryDescriptor) ((IStructuredSelection)selection).getFirstElement(); >+ if (descr != null) { >+ return descr.getType(); >+ } >+ } >+ return null; >+ } >+ >+ public void setSelectedType(String type) { >+ JUnitTestSuiteFactoryDescriptor descr = JUnitExtensionsRegistry.getInstance().getDescriptor(type); >+ if (descr != null) { >+ testFactoryList.setSelection(new StructuredSelection(descr)); >+ } else { >+ testFactoryList.setSelection(StructuredSelection.EMPTY); >+ } > } > > public List getSelectedElements() { >@@ -72,4 +208,32 @@ > public void checkStateChanged(CheckStateChangedEvent event) { > setPageComplete(selector.getSelectedElements().size() != 0); > } >+ >+ protected IDialogSettings getDialogSettings() { >+ IDialogSettings pluginSettings = ToolsUiPlugin.getDefault().getDialogSettings(); >+ IDialogSettings settings = pluginSettings.getSection(JUnitScriptsSelectionPage.class.getName()); >+ if (settings == null) { >+ settings = pluginSettings.addNewSection(JUnitScriptsSelectionPage.class.getName()); >+ } >+ return settings; >+ } >+ >+ protected void readDialogSettings() { >+ IDialogSettings settings = getDialogSettings(); >+ String type = settings.get(DS_TYPE); >+ if (type != null) { >+ setSelectedType(type); >+ } >+ if (getSelectedType() == null) { >+ // Default to the first item in list >+ Object o = testFactoryList.getElementAt(0); >+ if (o != null) testFactoryList.setSelection(new StructuredSelection(o)); >+ } >+ } >+ >+ /*package*/ void saveDialogSettings() { >+ IDialogSettings settings = getDialogSettings(); >+ settings.put(DS_TYPE, getSelectedType()); >+ } >+ > } >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/JUnitWorkspaceContentProvider.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/JUnitWorkspaceContentProvider.java,v >retrieving revision 1.4 >diff -u -r1.4 JUnitWorkspaceContentProvider.java >--- src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/JUnitWorkspaceContentProvider.java 26 Jul 2005 14:20:44 -0000 1.4 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/wizard/JUnitWorkspaceContentProvider.java 11 Aug 2006 17:09:30 -0000 >@@ -17,10 +17,16 @@ > import java.util.List; > import java.util.Map; > >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.NullProgressMonitor; > import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; > import org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitModelUpdater; >+import org.eclipse.hyades.test.tools.core.internal.plugin.util.PDEProjectUtil; >+import org.eclipse.hyades.test.tools.core.java.IJUnitTestSuiteFactory; >+import org.eclipse.hyades.test.tools.core.java.JUnitTestSuiteFacade; > import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin; > import org.eclipse.jdt.core.ICompilationUnit; > import org.eclipse.jdt.core.IJavaElement; >@@ -41,9 +47,16 @@ > > private Map children = new HashMap(); > private IRunnableContext context; >+ private IJUnitTestSuiteFactory factory; >+ >+ public void setJUnitTestSuiteFactory(IJUnitTestSuiteFactory factory) { >+ if (factory != this.factory) { >+ this.factory = factory; >+ children.clear(); >+ } >+ } > > private Object[] initChildren(Object element) { >- > //- java project > if (element instanceof IJavaProject) { > IJavaProject jProject = (IJavaProject) element; >@@ -102,7 +115,7 @@ > try { > IJavaElement [] compilationUnits = pack.getChildren(); > for(int c = 0; c < compilationUnits.length; c++) { >- if(isJUnitScript(compilationUnits[c])) { >+ if(isDisplayed(compilationUnits[c])) { > //- Actually, the current compilation unit is a JUnit script, we need to keep it > ret.add(compilationUnits[c]); > } >@@ -120,19 +133,17 @@ > * @param element > * @return > */ >- private boolean isJUnitScript(IJavaElement element) { >+ private boolean isDisplayed(IJavaElement element) { > if (element instanceof ICompilationUnit) { >- ICompilationUnit cu = (ICompilationUnit) element; >- IType mainType = cu.findPrimaryType(); >- try { >- if (mainType != null) { >- if (SourcePage.isTestImplementor(mainType)) { >- // Has a TestSuite already been defined for this type? >- return JUnitModelUpdater.findTestSuite(mainType, new ResourceSetImpl()) == null; >- } >+ ICompilationUnit cu = (ICompilationUnit)element; >+ if (factory.isSupported(cu)) { >+ try { >+ return JUnitModelUpdater.findTestSuiteFile((IFile)cu.getUnderlyingResource()) == null; >+ } catch (JavaModelException e) { >+ return false; >+ } catch (CoreException e) { >+ return false; > } >- } catch (JavaModelException e) { >- ToolsUiPlugin.logError(e); > } > } > return false; >@@ -140,7 +151,8 @@ > > public Object[] getChildren(Object element) { > if (element instanceof IJavaModel) { >- return super.getChildren(element); >+ Object[] projects = super.getChildren(element); >+ return filterProjects(projects); > } > if (!children.containsKey(element)) { > Object[] ch = initChildren(element); >@@ -151,6 +163,19 @@ > } > } > >+ private Object[] filterProjects(Object[] projects) { >+ if (factory == null) { >+ return NO_CHILDREN; >+ } >+ ArrayList result = new ArrayList(projects.length); >+ for (int i = 0; i < projects.length; i++) { >+ if (factory.isSupported((IJavaProject)projects[i])) { >+ result.add(projects[i]); >+ } >+ } >+ return result.toArray(); >+ } >+ > public boolean hasChildren(Object element) { > if (element instanceof IJavaProject) { > // Always assume true. Digging into the project would be too >Index: plugin.xml >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/plugin.xml,v >retrieving revision 1.45 >diff -u -r1.45 plugin.xml >--- plugin.xml 10 Aug 2006 16:33:36 -0000 1.45 >+++ plugin.xml 11 Aug 2006 17:09:30 -0000 >@@ -440,6 +440,17 @@ > menubarPath="org.eclipse.ui.OpenWithSubMenu" > id="org.eclipse.hyades.test.tools.ui.JUnitTestSuiteOpenCode"/> > </objectContribution> >+ <objectContribution >+ adaptable="false" >+ id="org.eclipse.hyades.test.tools.ui.RegularJUnitTestSuiteContribution" >+ objectClass="org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator.RegularJUnitTestSuiteProxyNode"> >+ <action >+ class="org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator.actions.ImportRegularJUnitTestSuiteAction" >+ enablesFor="*" >+ id="org.eclipse.hyades.test.tools.ui.RegularJUnitTestSuiteImport" >+ label="Create Model" >+ menubarPath="org.eclipse.ui.OpenWithSubMenu"/> >+ </objectContribution> > </extension> > <extension > point="org.eclipse.ui.popupMenus"> >@@ -514,19 +525,6 @@ > </wizard> > </extension> > <extension >- point="org.eclipse.ui.importWizards"> >- <wizard >- category="org.eclipse.tptp.platform.category.test.import" >- class="org.eclipse.hyades.test.tools.ui.plugin.internal.junit.wizard.PluginJUnitImportWizard" >- icon="icons/full/etool16/newpluginjsuite_wiz.gif" >- id="org.eclipse.hyades.test.tools.ui.plugin.import.junit" >- name="%PluginJUnitImportWizard.name"> >- <description> >- %PluginJUnitImportWizard.description >- </description> >- </wizard> >- </extension> >- <extension > point="org.eclipse.hyades.ui.editorExtensions"> > <editorExtension > class="org.eclipse.hyades.test.tools.ui.java.internal.junit.editor.JUnitEditorExtension" >@@ -580,6 +578,30 @@ > recorderMessageHandlers="org.eclipse.hyades.execution.recorder.http.local.HttpRecorderDataProcessor" > wizardPageProvider="org.eclipse.tptp.test.tools.internal.recorder.http.providers.HttpRecorderWizardProvider"/> > </extension> >+ <extension >+ point="org.eclipse.hyades.ui.typeDescriptions"> >+ <typeDescription >+ name="Other JUnit tests" >+ icon="icons/full/obj16/java_jsuite.gif" >+ type="org.eclipse.hyades.test.other.junit.testSuite" >+ description="JUnit tests not imported to TPTP" >+ extension="testsuite"> >+ </typeDescription> >+ <typeDescription >+ name="JUnit test method" >+ icon="icons/full/obj16/java_test.gif" >+ type="org.eclipse.hyades.test.other.junit.testCase" >+ description="JUnit test method not imported to TPTP" >+ extension="testcase"> >+ </typeDescription> >+ </extension> >+ <extension >+ point="org.eclipse.hyades.test.ui.testNavigatorTypeProvider"> >+ <provider >+ class="org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator.RegularJUnitProvider" >+ label="Other JUnit tests" >+ type="org.eclipse.hyades.test.other.junit.testSuite"/> >+ </extension> > <extension > point="org.eclipse.ui.preferencePages"> > <page >Index: plugin.properties >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/plugin.properties,v >retrieving revision 1.52 >diff -u -r1.52 plugin.properties >--- plugin.properties 10 Aug 2006 16:32:15 -0000 1.52 >+++ plugin.properties 11 Aug 2006 17:09:30 -0000 >@@ -475,6 +475,3 @@ > WIZ_NEW_WORKBENCH_LOCATION_DSC = Creates a new location for an Eclipse workbench. A workbench location is used to specify where a TPTP JUnit Plug-in test will run. > WORKBENCH_PROPERTY_GROUP_TTL = Eclipse Workbench Properties > WORKBENCH_PROPERTY_GROUP_DSC = This location defines the following workbench properties: >-PluginJUnitImportWizard.name = JUnit plug-in tests to TPTP >-PluginJUnitImportWizard.description = Import JUnit Tests in the workspace as TPTP plug-in tests. >-PluginJUnitImportWizard.title = Import JUnit plug-in tests to TPTP >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/editor/SourceInfoViewer.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.ui/src/org/eclipse/hyades/test/tools/ui/java/internal/junit/editor/SourceInfoViewer.java,v >retrieving revision 1.19 >diff -u -r1.19 SourceInfoViewer.java >--- src/org/eclipse/hyades/test/tools/ui/java/internal/junit/editor/SourceInfoViewer.java 10 Aug 2006 16:32:14 -0000 1.19 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/editor/SourceInfoViewer.java 11 Aug 2006 17:09:30 -0000 >@@ -36,6 +36,7 @@ > import org.eclipse.hyades.test.core.util.EMFUtil; > import org.eclipse.hyades.test.tools.core.CorePlugin; > import org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitModelUpdater; >+import org.eclipse.hyades.test.tools.core.java.JUnitTestSuiteFacade; > import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin; > import org.eclipse.hyades.test.tools.ui.java.internal.util.TestJavaUtil; > import org.eclipse.hyades.test.ui.editor.form.util.EditorForm; >@@ -466,7 +467,8 @@ > markDirty(); > } else if (e.widget == updateFromCodeButton) { > try { >- if (JUnitModelUpdater.updateTestSuiteFromCode((ITestSuite)getImplementor().getOwner())) { >+ ITestSuite testSuite = (ITestSuite)getImplementor().getOwner(); >+ if (JUnitModelUpdater.updateTestSuiteFromCode(testSuite, JUnitTestSuiteFacade.getJUnitSourceFile(testSuite))) { > markDirty(); > } > } catch (CoreException e1) { >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitPackageProxyNode.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitPackageProxyNode.java >diff -N src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitPackageProxyNode.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitPackageProxyNode.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,69 @@ >+/********************************************************************** >+ * Copyright (c) 2005 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 >+ * $Id: PackageProxyNode.java,v 1.3 2005/06/09 09:33:48 jgout Exp $ >+ * >+ * Contributors: >+ * IBM - Initial API and implementation >+ **********************************************************************/ >+package org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator; >+ >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IPackageFragment; >+import org.eclipse.jdt.ui.ISharedImages; >+import org.eclipse.jdt.ui.JavaUI; >+import org.eclipse.swt.graphics.Image; >+ >+/** >+ * Proxy node for a package. This proxy contains all JUnit test found in the corresponding java package. >+ * @author jcanches >+ * @since 4.3 >+ */ >+public class RegularJUnitPackageProxyNode extends JavaParentElementProxyNode { >+ >+ public static RegularJUnitPackageProxyNode create(IPackageFragment fragment, Object parent) { >+ RegularJUnitPackageProxyNode proxy = new RegularJUnitPackageProxyNode(fragment, parent); >+ if(proxy.getChildren().length > 0) { >+ return proxy; >+ } >+ return null; >+ } >+ >+ private RegularJUnitPackageProxyNode(IPackageFragment fragment, Object parent) { >+ super(fragment, parent); >+ } >+ >+ public IPackageFragment getPackageFragment() { >+ return (IPackageFragment)getJavaElement(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.hyades.test.ui.navigator.IProxyNode#getText() >+ */ >+ public String getText() { >+ String name = getJavaElement().getElementName(); >+ if ("".equals(name)) { //$NON-NLS-1$ >+ name = "(default package)"; >+ } >+ return name; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.hyades.test.ui.navigator.IProxyNode#getImage() >+ */ >+ public Image getImage() { >+ return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_PACKAGE); >+ } >+ >+ protected JavaElementProxyNode createChildProxy(IJavaElement childElement) { >+ if (childElement instanceof ICompilationUnit) { >+ return RegularJUnitTestSuiteProxyNode.create((ICompilationUnit)childElement, this); >+ } >+ return null; >+ } >+ >+} >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitTestSuiteProxyNode.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitTestSuiteProxyNode.java >diff -N src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitTestSuiteProxyNode.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitTestSuiteProxyNode.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,138 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator; >+ >+import java.util.ArrayList; >+import java.util.Iterator; >+import java.util.List; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; >+import org.eclipse.hyades.models.common.facades.behavioral.ITestCase; >+import org.eclipse.hyades.models.common.facades.behavioral.ITestSuite; >+import org.eclipse.hyades.models.common.testprofile.TPFTestSuite; >+import org.eclipse.hyades.test.tools.core.common.TestCommon; >+import org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitModelUpdater; >+import org.eclipse.hyades.test.tools.core.java.JUnitTestSuiteFacade; >+import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin; >+import org.eclipse.hyades.test.tools.ui.java.internal.junit.wizard.SourcePage; >+import org.eclipse.hyades.test.ui.TestUIImages; >+import org.eclipse.hyades.test.ui.navigator.IProxyNode; >+import org.eclipse.hyades.test.ui.navigator.ITestSuiteProxyNode; >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.IJavaElementDelta; >+import org.eclipse.jdt.core.IType; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.ui.IMemento; >+ >+public class RegularJUnitTestSuiteProxyNode extends JavaElementProxyNode implements ITestSuiteProxyNode/*, IPersistableProxyNode*/ { >+ >+ private IProxyNode[] children; >+ >+ public static RegularJUnitTestSuiteProxyNode create(ICompilationUnit cu, Object parent) { >+ if (isJUnitScript(cu)) { >+ return new RegularJUnitTestSuiteProxyNode(cu, parent); >+ } >+ return null; >+ } >+ >+ /** Checks whether the given java element is a JUnit test script >+ * @param element >+ * @return >+ */ >+ private static boolean isJUnitScript(ICompilationUnit element) { >+ ICompilationUnit cu = (ICompilationUnit) element; >+ IType mainType = cu.findPrimaryType(); >+ try { >+ if (mainType != null) { >+ if (SourcePage.isTestImplementor(mainType)) { >+ // Has a TestSuite already been defined for this type? >+ return JUnitModelUpdater.findTestSuite(mainType, new ResourceSetImpl()) == null; >+ } >+ } >+ } catch (JavaModelException e) { >+ ToolsUiPlugin.logError(e); >+ } >+ return false; >+ } >+ >+ private RegularJUnitTestSuiteProxyNode(ICompilationUnit cu, Object parent) { >+ super(cu, parent); >+ computeChildren(); >+ } >+ >+ private void computeChildren() { >+ try { >+ ITestSuite testSuite = JUnitTestSuiteFacade.createTestSuite(getCompilationUnit(), TestCommon.JUNIT_TEST_SUITE_TYPE); >+ List _children = new ArrayList(testSuite.getITestCases().size()); >+ Iterator it = testSuite.getITestCases().iterator(); >+ while (it.hasNext()) { >+ ITestCase tc = (ITestCase) it.next(); >+ IProxyNode proxy = new RegularJUnitTestCaseProxyNode(tc, this); >+ _children.add(proxy); >+ } >+ this.children = (IProxyNode[])_children.toArray(new IProxyNode[_children.size()]); >+ } catch (CoreException e) { >+ this.children = new IProxyNode[0]; >+ } >+ } >+ >+ public ICompilationUnit getCompilationUnit() { >+ return (ICompilationUnit)getJavaElement(); >+ } >+ >+ public TPFTestSuite getTestSuite() { >+ try { >+ return (TPFTestSuite) JUnitTestSuiteFacade.createTestSuite(getCompilationUnit(), TestCommon.JUNIT_TEST_SUITE_TYPE); >+ } catch (CoreException e) { >+ ToolsUiPlugin.logError(e); >+ return null; >+ } >+ } >+ >+ public String getType() { >+ return TestCommon.OTHER_JUNIT_TEST_SUITE_TYPE; >+ } >+ >+ public IProxyNode[] getChildren() { >+ return children; >+ } >+ >+ public Image getImage() { >+ // TODO Auto-generated method stub >+ return TestUIImages.INSTANCE.getImage(TestUIImages.IMG_TEST_SUITE); >+ } >+ >+ public String getFactoryID() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public boolean saveState(IMemento memento) { >+ // TODO Auto-generated method stub >+ return false; >+ } >+ >+ public IProxyNode elementChanged(IJavaElementDelta delta) { >+ if (delta.getKind() == IJavaElementDelta.CHANGED) { >+ int flags = delta.getFlags(); >+ if ((flags & IJavaElementDelta.F_PRIMARY_RESOURCE) != 0) { >+ computeChildren(); >+ return this; >+ } >+ } >+ return null; >+ } >+ >+} >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JavaParentElementProxyNode.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JavaParentElementProxyNode.java >diff -N src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JavaParentElementProxyNode.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JavaParentElementProxyNode.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,165 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator; >+ >+import java.util.ArrayList; >+import java.util.Collections; >+import java.util.List; >+ >+import org.eclipse.hyades.test.ui.navigator.IProxyNode; >+import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IJavaElementDelta; >+import org.eclipse.jdt.core.IParent; >+import org.eclipse.jdt.core.JavaModelException; >+ >+/** >+ * Proxy node representing a java element that contains java elements. >+ * @author jcanches >+ * @since 4.3 >+ */ >+public abstract class JavaParentElementProxyNode extends JavaElementProxyNode { >+ >+ protected JavaElementProxyNode[] children; >+ >+ protected JavaParentElementProxyNode(IJavaElement element, Object parent) { >+ super(element, parent); >+ setChildren(computeChildren()); >+ } >+ >+ protected abstract JavaElementProxyNode createChildProxy(IJavaElement childElement); >+ >+ public IProxyNode[] getChildren() { >+ return children; >+ } >+ >+ protected final synchronized void setChildren(List _children) { >+ children = (JavaElementProxyNode[])_children.toArray(new JavaElementProxyNode[_children.size()]); >+ } >+ >+ protected List computeChildren() { >+ if (getJavaElement() instanceof IParent) { >+ try { >+ IJavaElement[] elements = ((IParent)getJavaElement()).getChildren(); >+ List _children = new ArrayList(elements.length); >+ for (int i = 0; i < elements.length; i++) { >+ JavaElementProxyNode proxy = createChildProxy(elements[i]); >+ if (proxy != null) { >+ _children.add(proxy); >+ } >+ } >+ return _children; >+ } catch (JavaModelException e) { >+ return Collections.EMPTY_LIST; >+ } >+ } >+ return Collections.EMPTY_LIST; >+ } >+ >+ public IProxyNode elementChanged(IJavaElementDelta delta) { >+ IProxyNode lowestChanged = null; >+ IJavaElementDelta[] deltas = delta.getAffectedChildren(); >+ for (int i = 0; i < deltas.length; i++) { >+ IJavaElementDelta childDelta = deltas[i]; >+ IJavaElement childElement = childDelta.getElement(); >+ IProxyNode lowestChild = null; >+ switch(childDelta.getKind()) { >+ case IJavaElementDelta.ADDED: { >+ JavaElementProxyNode proxy = createChildProxy(childElement); >+ if (proxy != null) { >+ addChildProxy(proxy); >+ lowestChild = this; >+ } >+ break; >+ } case IJavaElementDelta.REMOVED: { >+ JavaElementProxyNode proxy = getChildProxy(childElement); >+ if (proxy != null) { >+ removeChildProxy(proxy); >+ lowestChild = this; >+ } >+ break; >+ } case IJavaElementDelta.CHANGED: { >+ JavaElementProxyNode proxy = getChildProxy(childElement); >+ if (proxy != null) { >+ lowestChild = proxy.elementChanged(childDelta); >+ if (proxy.getChildren().length == 0) { >+ removeChildProxy(proxy); >+ lowestChild = this; >+ } >+ } else { >+ proxy = createChildProxy(childElement); >+ if (proxy != null) { >+ addChildProxy(proxy); >+ lowestChild = this; >+ } >+ } >+ break; >+ } >+ } >+ if (lowestChild != null) { >+ if (lowestChanged == null) { >+ lowestChanged = lowestChild; >+ } else { >+ lowestChanged = this; >+ } >+ } >+ } >+ return lowestChanged; >+ } >+ >+ protected final JavaElementProxyNode getChildProxy(IJavaElement element) { >+ for (int i = 0; i < children.length; i++) { >+ if (element.equals(children[i].getJavaElement())) { >+ return children[i]; >+ } >+ } >+ return null; >+ } >+ >+ protected final void replaceChildProxy(JavaElementProxyNode oldProxy, JavaElementProxyNode newProxy) { >+ for (int i = 0; i < children.length; i++) { >+ if(children[i] == oldProxy) { >+ children[i] = newProxy; >+ break; >+ } >+ } >+ } >+ >+ protected final boolean addChildProxy(JavaElementProxyNode proxy) { >+ if(proxy == null) return false; >+ JavaElementProxyNode[] newChildren = new JavaElementProxyNode[children.length + 1]; >+ for (int i = 0; i < children.length; i++) { >+ //- if the proxy to add is already a child do not add it >+ if(children[i].equals(proxy)) { >+ return false; >+ } >+ newChildren[i] = children[i]; >+ } >+ newChildren[children.length] = proxy; >+ //- change the children of the current proxy node >+ children = newChildren; >+ return true; >+ } >+ >+ protected final void removeChildProxy(JavaElementProxyNode proxy) { >+ JavaElementProxyNode[] newChildren = new JavaElementProxyNode[children.length - 1]; >+ int j = 0; >+ for (int i = 0; i < children.length; i++) { >+ if(children[i] != proxy) { >+ newChildren[j++] = children[i]; >+ } >+ } >+ //- change the children of the current proxy node >+ children = newChildren; >+ } >+ >+} >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitTestCaseProxyNode.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitTestCaseProxyNode.java >diff -N src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitTestCaseProxyNode.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitTestCaseProxyNode.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,87 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator; >+ >+import org.eclipse.core.resources.IResource; >+import org.eclipse.hyades.models.common.facades.behavioral.ITestCase; >+import org.eclipse.hyades.models.common.testprofile.TPFTestCase; >+import org.eclipse.hyades.test.tools.core.common.TestCommon; >+import org.eclipse.hyades.test.ui.TestUIExtension; >+import org.eclipse.hyades.test.ui.TestUIImages; >+import org.eclipse.hyades.test.ui.navigator.IProxyNode; >+import org.eclipse.hyades.test.ui.navigator.ITestCaseProxyNode; >+import org.eclipse.hyades.ui.HyadesUIPlugin; >+import org.eclipse.hyades.ui.extension.IAssociationDescriptor; >+import org.eclipse.hyades.ui.extension.IAssociationMapping; >+import org.eclipse.hyades.ui.internal.extension.AssociationMappingRegistry; >+import org.eclipse.swt.graphics.Image; >+ >+public class RegularJUnitTestCaseProxyNode implements ITestCaseProxyNode { >+ >+ private RegularJUnitTestSuiteProxyNode parent; >+ private String name; >+ private String id; >+ >+ public RegularJUnitTestCaseProxyNode(ITestCase testCase, RegularJUnitTestSuiteProxyNode parent) { >+ this.parent = parent; >+ this.name = testCase.getName(); >+ this.id = testCase.getId(); >+ } >+ >+ public TPFTestCase getTestCase() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public String getType() { >+ return TestCommon.OTHER_JUNIT_TEST_CASE_TYPE; >+ } >+ >+ public IProxyNode[] getChildren() { >+ return new IProxyNode[0]; >+ } >+ >+ public Image getImage() { >+ AssociationMappingRegistry registry = (AssociationMappingRegistry)TestUIExtension.getTestCaseMappingRegistry(); >+ IAssociationMapping associationMapping = registry.getAssociationMapping(HyadesUIPlugin.EP_TYPE_DESCRIPTIONS); >+ IAssociationDescriptor descriptor = associationMapping.getDefaultAssociationDescriptor(getType()); >+ if(descriptor != null) { >+ return descriptor.getImage(); >+ } else { >+ //- the type of this element wasn't registered by any extension (hyades.ui.typeDescriptions) >+ return TestUIImages.INSTANCE.getImage(TestUIImages.IMG_TEST_CASE); >+ } >+ } >+ >+ public Object getParent() { >+ return parent; >+ } >+ >+ public String getText() { >+ return name; >+ } >+ >+ public Object getAdapter(Class adapter) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public String getIdentifier() { >+ return id; >+ } >+ >+ public IResource getUnderlyingResource() { >+ return parent.getUnderlyingResource(); >+ } >+ >+} >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitProviderProxyNode.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitProviderProxyNode.java >diff -N src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitProviderProxyNode.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitProviderProxyNode.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,161 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator; >+ >+import org.eclipse.hyades.test.ui.TestUIExtension; >+import org.eclipse.hyades.test.ui.UiPlugin; >+import org.eclipse.hyades.test.ui.internal.navigator.TestNavigator; >+import org.eclipse.hyades.test.ui.navigator.IProxyNode; >+import org.eclipse.hyades.test.ui.navigator.ITypeProviderProxyNode; >+import org.eclipse.hyades.ui.HyadesUIPlugin; >+import org.eclipse.hyades.ui.extension.IAssociationDescriptor; >+import org.eclipse.hyades.ui.extension.IAssociationMapping; >+import org.eclipse.hyades.ui.internal.extension.AssociationMappingRegistry; >+import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IJavaElementDelta; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IPackageFragmentRoot; >+import org.eclipse.swt.graphics.Image; >+ >+/** >+ * Top-level proxy node under a project, for representing "other junit tests". >+ * This proxy is associated to a Java project, and shows source folders as childs, or >+ * directly packages if the java project is the source folder itself. >+ * @author jcanches >+ * @since 4.3 >+ */ >+public class RegularJUnitProviderProxyNode extends JavaParentElementProxyNode implements ITypeProviderProxyNode { >+ >+ private String name; >+ private String imageKey; >+ >+ public static RegularJUnitProviderProxyNode create(IJavaProject project, String type, Object parent) { >+ RegularJUnitProviderProxyNode proxy = new RegularJUnitProviderProxyNode(project, type, parent); >+ if(proxy.getChildren().length > 0) { >+ return proxy; >+ } >+ return null; >+ } >+ >+ protected RegularJUnitProviderProxyNode(IJavaProject project, String type, Object parent) { >+ super(project, parent); >+ AssociationMappingRegistry registry = (AssociationMappingRegistry)TestUIExtension.getTestSuiteMappingRegistry(); >+ IAssociationMapping associationMapping = registry.getAssociationMapping(HyadesUIPlugin.EP_TYPE_DESCRIPTIONS); >+ IAssociationDescriptor descriptor = associationMapping.getDefaultAssociationDescriptor(type); >+ if (descriptor != null) { >+ this.name = descriptor.getName(); >+ } else { >+ this.name = "[Invalid Descriptor]"; //$NON-NLS-1$ >+ } >+ this.imageKey = TestNavigator.getTypeProviderManager().getImageKeyFor(type); >+ } >+ >+ protected JavaElementProxyNode createChildProxy(IJavaElement childElement) { >+ if (childElement instanceof IPackageFragmentRoot) { >+ return RegularJUnitSourceFolderProxyNode.create((IPackageFragmentRoot)childElement, this); >+ } >+ return null; >+ } >+ >+ private boolean isSourceFolder() { >+ if (children.length == 1) { >+ return ((RegularJUnitSourceFolderProxyNode)children[0]).isProjectRoot(); >+ } >+ return false; >+ } >+ >+ public IJavaProject getJavaProject() { >+ return (IJavaProject)getJavaElement(); >+ } >+ >+ public Image getImage() { >+ return UiPlugin.getInstance().getImageRegistry().get(this.imageKey); >+ } >+ >+ public String getText() { >+ return name; >+ } >+ >+ public IProxyNode elementChanged(IJavaElementDelta delta) { >+ if (delta.getKind() == IJavaElementDelta.CHANGED) { >+ IJavaElementDelta[] deltas = delta.getAffectedChildren(); >+ IProxyNode lowestChanged = null; >+ for (int i = 0; i < deltas.length; i++) { >+ IProxyNode lowestChild = null; >+ IJavaElementDelta childDelta = deltas[i]; >+ IJavaElement elem = childDelta.getElement(); >+ if (elem.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) { >+ if (childDelta.getKind() == IJavaElementDelta.ADDED >+ || (childDelta.getKind() == IJavaElementDelta.CHANGED >+ && (childDelta.getFlags() & IJavaElementDelta.F_ADDED_TO_CLASSPATH) > 0)) { >+ lowestChild = packageFragmentRootAdded((IPackageFragmentRoot)elem); >+ } else if (childDelta.getKind() == IJavaElementDelta.REMOVED >+ || (childDelta.getKind() == IJavaElementDelta.CHANGED >+ && (childDelta.getFlags() & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) > 0)) { >+ lowestChild = packageFragmentRootRemoved((IPackageFragmentRoot)elem); >+ } else if (childDelta.getKind() == IJavaElementDelta.CHANGED >+ && (childDelta.getFlags() & IJavaElementDelta.F_CHILDREN) > 0) { >+ lowestChild = packageFragmentRootChanged((IPackageFragmentRoot)elem, childDelta); >+ } >+ } >+ if (lowestChild != null) { >+ if(lowestChanged == null) { >+ lowestChanged = lowestChild; >+ } else { >+ lowestChanged = this; >+ } >+ } >+ } >+ return lowestChanged; >+ } >+ return null; >+ } >+ >+ private IProxyNode packageFragmentRootAdded(IPackageFragmentRoot root) { >+ RegularJUnitSourceFolderProxyNode proxy = RegularJUnitSourceFolderProxyNode.create(root, this); >+ if (proxy != null) { >+ addChildProxy(proxy); >+ return this; >+ } >+ return null; >+ } >+ >+ private IProxyNode packageFragmentRootRemoved(IPackageFragmentRoot root) { >+ JavaElementProxyNode proxy = getChildProxy(root); >+ if (proxy != null) { >+ removeChildProxy(proxy); >+ return this; >+ } >+ return null; >+ } >+ >+ private IProxyNode packageFragmentRootChanged(IPackageFragmentRoot root, IJavaElementDelta delta) { >+ JavaElementProxyNode proxy = getChildProxy(root); >+ if (proxy != null) { >+ IProxyNode lowestChanged = proxy.elementChanged(delta); >+ if (proxy.getChildren().length == 0) { >+ removeChildProxy(proxy); >+ return this; >+ } >+ return lowestChanged; >+ } else { >+ proxy = RegularJUnitSourceFolderProxyNode.create(root, this); >+ if (proxy != null) { >+ addChildProxy(proxy); >+ return this; >+ } >+ } >+ return null; >+ } >+ >+} >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitProvider.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitProvider.java >diff -N src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,104 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator; >+ >+import java.util.HashMap; >+import java.util.Map; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.hyades.test.ui.navigator.IFileProxyManager; >+import org.eclipse.hyades.test.ui.navigator.IProxyNodeListener; >+import org.eclipse.hyades.test.ui.navigator.ITypeProvider; >+import org.eclipse.hyades.test.ui.navigator.ITypeProviderContext; >+import org.eclipse.hyades.test.ui.navigator.ITypeProviderProxyNode; >+import org.eclipse.hyades.ui.util.IDisposable; >+import org.eclipse.jdt.core.ElementChangedEvent; >+import org.eclipse.jdt.core.IElementChangedListener; >+import org.eclipse.jdt.core.IJavaElementDelta; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.JavaCore; >+ >+/** >+ * A provider showing Java projects content, with non-JUnit classes filtered out. >+ * @author jcanches >+ * @since 4.3 >+ */ >+public class RegularJUnitProvider implements ITypeProvider, IElementChangedListener, IDisposable { >+ >+ /** The file proxy manager used to cache file proxies */ >+ protected IFileProxyManager fileProxyManager; >+ protected IProxyNodeListener refresher; >+ >+ private Map projectToProxyMap = new HashMap(); >+ >+ public RegularJUnitProvider() { >+ JavaCore.addElementChangedListener(this, ElementChangedEvent.POST_CHANGE); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.hyades.test.ui.navigator.ITypeProvider#get(org.eclipse.core.resources.IProject, java.lang.String) >+ */ >+ public ITypeProviderProxyNode get(IProject project, String type) { >+ IJavaProject jproject = JavaCore.create(project); >+ if(!jproject.exists()) return null; >+ RegularJUnitProviderProxyNode proxy = (RegularJUnitProviderProxyNode) projectToProxyMap.get(jproject); >+ if(proxy == null) { >+ proxy = RegularJUnitProviderProxyNode.create(jproject, type, this); >+ if (proxy != null) { >+ projectToProxyMap.put(jproject, proxy); >+ } >+ } >+ return proxy; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.hyades.test.ui.navigator.ITypeProvider#init(org.eclipse.hyades.test.ui.navigator.ITypeProviderContext) >+ */ >+ public void init(ITypeProviderContext context) { >+ fileProxyManager = context.getFileProxyManager(); >+ refresher = context.getProxyNodeListener(); >+ } >+ >+ public void dispose() { >+ JavaCore.removeElementChangedListener(this); >+ } >+ >+ public void elementChanged(ElementChangedEvent event) { >+ IJavaElementDelta[] children = event.getDelta().getAffectedChildren(); >+ for(int i = 0; i < children.length; i++) { >+ IJavaProject jproject = (IJavaProject) children[i].getElement(); >+ RegularJUnitProviderProxyNode node = (RegularJUnitProviderProxyNode) projectToProxyMap.get(jproject); >+ if (node != null) { >+ Object lowestChange = node.elementChanged(children[i]); >+ if(node.getChildren().length == 0) { >+ lowestChange = jproject.getProject(); >+ projectToProxyMap.remove(jproject); >+ } >+ if (lowestChange != null) { >+ refresher.nodeChanged(lowestChange); >+ } >+ } >+ } >+ } >+ >+ public void notifyChanged(RegularJUnitProviderProxyNode proxy) { >+ if (proxy.getChildren().length == 0) { >+ IJavaProject project = proxy.getJavaProject(); >+ projectToProxyMap.remove(project); >+ refresher.nodeChanged(project); >+ } else { >+ refresher.nodeChanged(proxy); >+ } >+ } >+ >+} >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JavaElementProxyNode.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JavaElementProxyNode.java >diff -N src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JavaElementProxyNode.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/JavaElementProxyNode.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,82 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator; >+ >+import org.eclipse.core.resources.IResource; >+import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin; >+import org.eclipse.hyades.test.ui.navigator.IProxyNode; >+import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.JavaModelException; >+ >+/** >+ * Proxy node representing a java element. >+ * @author jcanches >+ * @since 4.3 >+ */ >+public abstract class JavaElementProxyNode implements IJavaElementChangedListenerProxyNode { >+ >+ protected static final JavaElementProxyNode[] NO_CHILDREN = new JavaElementProxyNode[0]; >+ >+ private Object parent; >+ private IJavaElement element; >+ >+ protected JavaElementProxyNode(IJavaElement element, Object parent) { >+ this.parent = parent; >+ this.element = element; >+ } >+ >+ public IProxyNode[] getChildren() { >+ return NO_CHILDREN; >+ } >+ >+ public Object getParent() { >+ return parent; >+ } >+ >+ public String getText() { >+ return element.getElementName(); >+ } >+ >+ public Object getAdapter(Class adapter) { >+ if (adapter.isAssignableFrom(element.getClass())) { >+ return element; >+ } >+ try { >+ IResource res = element.getCorrespondingResource(); >+ if (adapter.isAssignableFrom(res.getClass())) { >+ return res; >+ } >+ } catch (JavaModelException e) { >+ return null; >+ } >+ return null; >+ } >+ >+ public String getIdentifier() { >+ return element.getHandleIdentifier(); >+ } >+ >+ public IResource getUnderlyingResource() { >+ try { >+ return element.getUnderlyingResource(); >+ } catch (JavaModelException e) { >+ ToolsUiPlugin.logError(e); >+ return null; >+ } >+ } >+ >+ public IJavaElement getJavaElement() { >+ return element; >+ } >+ >+} >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/IJavaElementChangedListenerProxyNode.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/IJavaElementChangedListenerProxyNode.java >diff -N src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/IJavaElementChangedListenerProxyNode.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/IJavaElementChangedListenerProxyNode.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,33 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator; >+ >+import org.eclipse.hyades.test.ui.navigator.IProxyNode; >+import org.eclipse.jdt.core.IJavaElementDelta; >+ >+/** >+ * A proxy node that is able to modify itself in reaction to changes in the java model. >+ * @author jcanches >+ * @since 4.3 >+ */ >+public interface IJavaElementChangedListenerProxyNode extends IProxyNode { >+ >+ /** >+ * Processes the delta, rooted at the java element that this proxy is associated to. >+ * @param delta >+ * @return The lowest proxy, in the subtree of the proxy, that needs to be refreshed >+ * by a viewer. This may be this proxy itself. >+ */ >+ IProxyNode elementChanged(IJavaElementDelta delta); >+ >+} >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/actions/ImportRegularJUnitTestSuiteAction.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/actions/ImportRegularJUnitTestSuiteAction.java >diff -N src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/actions/ImportRegularJUnitTestSuiteAction.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/actions/ImportRegularJUnitTestSuiteAction.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,42 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator.actions; >+ >+import org.eclipse.hyades.test.tools.ui.java.internal.junit.wizard.JUnitImportWizard; >+import org.eclipse.jface.action.IAction; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.wizard.WizardDialog; >+import org.eclipse.ui.IActionDelegate; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PlatformUI; >+ >+public class ImportRegularJUnitTestSuiteAction implements IActionDelegate { >+ >+ private IStructuredSelection selection; >+ >+ public void run(IAction action) { >+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); >+ JUnitImportWizard wizard = new JUnitImportWizard(); >+ wizard.init(window.getWorkbench(), selection); >+ WizardDialog dialog = new WizardDialog(window.getShell(), wizard); >+ dialog.open(); >+ } >+ >+ public void selectionChanged(IAction action, ISelection selection) { >+ if (selection instanceof IStructuredSelection) { >+ this.selection = (IStructuredSelection) selection; >+ } >+ } >+ >+} >Index: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitSourceFolderProxyNode.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitSourceFolderProxyNode.java >diff -N src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitSourceFolderProxyNode.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/ui/java/internal/junit/navigator/RegularJUnitSourceFolderProxyNode.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,67 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.ui.java.internal.junit.navigator; >+ >+import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IPackageFragment; >+import org.eclipse.jdt.core.IPackageFragmentRoot; >+import org.eclipse.jdt.ui.ISharedImages; >+import org.eclipse.jdt.ui.JavaUI; >+import org.eclipse.swt.graphics.Image; >+ >+/** >+ * Proxy node for a source folder. This proxy represents a package fragment root, >+ * and has package proxy as children. >+ * @author jcanches >+ * @since 4.3 >+ */ >+public class RegularJUnitSourceFolderProxyNode extends JavaParentElementProxyNode { >+ >+ private boolean isProjectRoot; >+ >+ public static RegularJUnitSourceFolderProxyNode create(IPackageFragmentRoot root, Object parent) { >+ RegularJUnitSourceFolderProxyNode proxy = new RegularJUnitSourceFolderProxyNode(root, parent); >+ if (proxy.getChildren().length == 0) { >+ return null; >+ } >+ return proxy; >+ } >+ >+ private RegularJUnitSourceFolderProxyNode(IPackageFragmentRoot root, Object parent) { >+ super(root, parent); >+ isProjectRoot = root.getPath().equals(root.getJavaProject().getPath()); >+ } >+ >+ public Image getImage() { >+ return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_PACKFRAG_ROOT); >+ } >+ >+ protected JavaElementProxyNode createChildProxy(IJavaElement childElement) { >+ if (childElement instanceof IPackageFragment) { >+ return RegularJUnitPackageProxyNode.create((IPackageFragment)childElement, this); >+ } >+ return null; >+ } >+ >+ public boolean isProjectRoot() { >+ return isProjectRoot; >+ } >+ >+ public String getText() { >+ if (isProjectRoot) { >+ return "[project root]"; >+ } >+ return super.getText(); >+ } >+ >+} >#P org.eclipse.hyades.test.tools.core_90628 >Index: src/org/eclipse/hyades/test/tools/core/common/TestCommon.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/common/TestCommon.java,v >retrieving revision 1.4 >diff -u -r1.4 TestCommon.java >--- src/org/eclipse/hyades/test/tools/core/common/TestCommon.java 7 Oct 2005 14:49:10 -0000 1.4 >+++ src/org/eclipse/hyades/test/tools/core/common/TestCommon.java 11 Aug 2006 17:09:33 -0000 >@@ -54,4 +54,7 @@ > > public final static String PLUGIN_JUNIT_TEST_SUITE_TYPE = "org.eclipse.hyades.test.plugin.junit.testSuite"; //$NON-NLS-1$ > >+ public final static String OTHER_JUNIT_TEST_SUITE_TYPE = "org.eclipse.hyades.test.other.junit.testSuite"; //$NON-NLS-1$ >+ public final static String OTHER_JUNIT_TEST_CASE_TYPE = "org.eclipse.hyades.test.other.junit.testCase"; //$NON-NLS-1$ >+ > } >Index: src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestSuite.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestSuite.java,v >retrieving revision 1.11 >diff -u -r1.11 GenTestSuite.java >--- src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestSuite.java 29 Jul 2006 01:57:42 -0000 1.11 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestSuite.java 11 Aug 2006 17:09:33 -0000 >@@ -4,7 +4,7 @@ > * 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 >- * $Id: GenTestSuite.java,v 1.11 2006/07/29 01:57:42 sschneid Exp $ >+ * $Id$ > * > * Contributors: > * IBM Corporation - initial API and implementation >Index: src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestSuiteConstructor.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestSuiteConstructor.java,v >retrieving revision 1.2 >diff -u -r1.2 GenTestSuiteConstructor.java >--- src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestSuiteConstructor.java 29 Jul 2006 01:57:42 -0000 1.2 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestSuiteConstructor.java 11 Aug 2006 17:09:33 -0000 >@@ -4,7 +4,7 @@ > * 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 >- * $Id: GenTestSuiteConstructor.java,v 1.2 2006/07/29 01:57:42 sschneid Exp $ >+ * $Id$ > * > * Contributors: > * IBM Corporation - initial API and implementation >Index: src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenSuiteMethod.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenSuiteMethod.java,v >retrieving revision 1.10 >diff -u -r1.10 GenSuiteMethod.java >--- src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenSuiteMethod.java 29 Jul 2006 21:36:45 -0000 1.10 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenSuiteMethod.java 11 Aug 2006 17:09:33 -0000 >@@ -4,7 +4,7 @@ > * 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 >- * $Id: GenSuiteMethod.java,v 1.10 2006/07/29 21:36:45 sschneid Exp $ >+ * $Id$ > * > * Contributors: > * IBM Corporation - initial API and implementation >Index: src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestMethod.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestMethod.java,v >retrieving revision 1.9 >diff -u -r1.9 GenTestMethod.java >--- src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestMethod.java 29 Jul 2006 21:36:45 -0000 1.9 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/codegen/GenTestMethod.java 11 Aug 2006 17:09:33 -0000 >@@ -4,7 +4,7 @@ > * 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 >- * $Id: GenTestMethod.java,v 1.9 2006/07/29 21:36:45 sschneid Exp $ >+ * $Id$ > * > * Contributors: > * IBM Corporation - initial API and implementation >Index: src/org/eclipse/hyades/test/tools/core/java/JUnitTestSuiteFacade.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/java/JUnitTestSuiteFacade.java,v >retrieving revision 1.15 >diff -u -r1.15 JUnitTestSuiteFacade.java >--- src/org/eclipse/hyades/test/tools/core/java/JUnitTestSuiteFacade.java 19 May 2006 15:44:46 -0000 1.15 >+++ src/org/eclipse/hyades/test/tools/core/java/JUnitTestSuiteFacade.java 11 Aug 2006 17:09:33 -0000 >@@ -24,31 +24,29 @@ > import org.eclipse.emf.ecore.resource.Resource; > import org.eclipse.emf.ecore.resource.ResourceSet; > import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; >-import org.eclipse.hyades.models.common.facades.behavioral.ITestCase; > import org.eclipse.hyades.models.common.facades.behavioral.ITestSuite; >-import org.eclipse.hyades.models.common.facades.behavioral.impl.HyadesFactory; > import org.eclipse.hyades.models.common.util.ICommonConstants; > import org.eclipse.hyades.test.core.util.EMFUtil; > import org.eclipse.hyades.test.tools.core.CorePlugin; > import org.eclipse.hyades.test.tools.core.common.TestCommon; >-import org.eclipse.hyades.test.tools.core.common.util.TestCommonUtil; >-import org.eclipse.hyades.test.tools.core.internal.common.codegen.Helper; >-import org.eclipse.hyades.test.tools.core.internal.java.codegen.JUnitGenerator; >+import org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitExtensionsRegistry; > import org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitModelUpdater; > import org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitProjectBuilder; >+import org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitTypeFactory; > import org.eclipse.jdt.core.ICompilationUnit; > import org.eclipse.jdt.core.IJavaElement; >-import org.eclipse.jdt.core.IMethod; > import org.eclipse.jdt.core.IPackageFragmentRoot; > import org.eclipse.jdt.core.IType; > import org.eclipse.jdt.core.JavaCore; > import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.osgi.util.NLS; > > /** > * <p>Provides high-level methods for navigating between JUnit source files (as JDT model > * elements) and TPTP concepts (as TPTP Test Model elements).</p> > * <p><b>This API is provisional and is subject to changes in future releases.</b></p> > * @author jcanches >+ * @since 4.1 > */ > public class JUnitTestSuiteFacade { > >@@ -82,76 +80,52 @@ > public static ITestSuite createTestSuite(ICompilationUnit junitTestCompilationUnit, String type, boolean force) throws CoreException { > String name = junitTestCompilationUnit.getElementName(); > name = name.substring(0, name.indexOf('.')); >- try { >- IFile javaFile = (IFile)junitTestCompilationUnit.getCorrespondingResource(); >- IFile testSuiteFile = javaFile >- .getParent() >- .getFile(new Path(name + "." + ICommonConstants.TEST_SUITE_FILE_EXTENSION)); //$NON-NLS-1$ >- >- if (testSuiteFile.exists()) { >- if (force) { >- testSuiteFile.delete(/*force*/true, /*keepHistory*/true, null); >- } else { >- throw new CoreException(new Status( >- IStatus.ERROR, >- CorePlugin.PLUGIN_ID, >- 1, >- "Resource already exists: " + testSuiteFile.getFullPath(), //$NON-NLS-1$ >- null)); >- } >+ IFile javaFile = (IFile)junitTestCompilationUnit.getCorrespondingResource(); >+ IFile testSuiteFile = javaFile >+ .getParent() >+ .getFile(new Path(name + "." + ICommonConstants.TEST_SUITE_FILE_EXTENSION)); //$NON-NLS-1$ >+ >+ ITestSuite testSuite = createTestSuite(junitTestCompilationUnit, type); >+ testSuite.setName(name); >+ saveTestSuite(testSuite, testSuiteFile, force); >+ return testSuite; >+ } >+ >+ public static ITestSuite createTestSuite(ICompilationUnit cu, String type) throws CoreException { >+ IJUnitTestSuiteFactory factory = JUnitExtensionsRegistry.getInstance().getFactory(type); >+ if (factory == null) { >+ throw new CoreException(makeErrorStatus(NLS.bind("No JUnit test suite factory registered for the type {0}", type), null)); //$NON-NLS-1$ >+ } >+ ITestSuite testSuite = factory.generate(cu); >+ // Store in the Test Suite the reference to the JUnit code: >+ testSuite.getImplementor().setLocation(getPackageFragmentRoot(cu).getCorrespondingResource().getFullPath().toString()); >+ testSuite.getImplementor().setResource(cu.findPrimaryType().getFullyQualifiedName()); >+ return testSuite; >+ } >+ >+ public static void saveTestSuite(ITestSuite testSuite, IFile file, boolean force) throws CoreException { >+ if (file.exists()) { >+ if (force) { >+ file.delete(/*force*/true, /*keepHistory*/true, null); >+ } else { >+ throw new CoreException(makeErrorStatus(NLS.bind("Resource {0} already exists.", file.getFullPath()), null)); //$NON-NLS-1$ > } >- ResourceSet resourceSet = new ResourceSetImpl(); >- URI uri = URI.createPlatformResourceURI(testSuiteFile.getFullPath().toString()); >- Resource resource = resourceSet.createResource(uri); >- ITestSuite testSuite = HyadesFactory.INSTANCE.createTestSuite(resource); >- testSuite.setType(type); >- testSuite.setName(name); >- >- HyadesFactory.INSTANCE.createImplementor(testSuite, /*isExternalImplementor*/true); >- // This TestSuite has a code-implemented behavior: >- JUnitModelUpdater.setImplementorBlock(testSuite.getImplementor(), null); >- // Store in the Test Suite the reference to the JUnit code: >- testSuite.getImplementor().setLocation(getPackageFragmentRoot(junitTestCompilationUnit).getCorrespondingResource().getFullPath().toString()); >- testSuite.getImplementor().setResource(junitTestCompilationUnit.findPrimaryType().getFullyQualifiedName()); >- >- populateTestCases(testSuite, junitTestCompilationUnit); >- >+ } >+ ResourceSet resourceSet = new ResourceSetImpl(); >+ URI uri = URI.createPlatformResourceURI(file.getFullPath().toString()); >+ Resource resource = resourceSet.createResource(uri); >+ IJUnitTestSuiteFactory factory = new JUnitTypeFactory(); >+ resource.getContents().add(testSuite); >+ >+ try { > EMFUtil.save(resource); >- JUnitProjectBuilder.installBuilder(testSuiteFile.getProject()); >- JUnitProjectBuilder.installBuilder(javaFile.getProject()); >- JUnitModelUpdater.associateTestSuiteToJUnitSourceFile(javaFile, testSuiteFile); >- return testSuite; > } catch (Exception e) { >- CorePlugin.logError(e); >- return null; >+ throw new CoreException(makeErrorStatus("Problem in saving resource " + file.getFullPath(), e)); //$NON-NLS-1$ > } >- } >- >- /** >- * Populates an empty JUnit ITestSuite with one ITestCase for each test method found >- * in compilation unit cu. >- * For the more generic case where the ITestSuite already owns ITestCase children which >- * need to updated according to the new state of the source code, see >- * ModelUpdater.updateTestSuiteFromCode(ITestSuite). >- * @param testSuite >- * @param cu >- * @throws JavaModelException >- * @see org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitModelUpdater#updateTestSuiteFromCode(ITestSuite) >- */ >- private static void populateTestCases(ITestSuite testSuite, ICompilationUnit cu) throws JavaModelException { >- boolean isExternalBehavior = testSuite.getImplementor().isExternalImplementor(); >- IType mainType = cu.findPrimaryType(); >- if (mainType != null) { >- IMethod[] methods = mainType.getMethods(); >- //List testCases = testSuite.getITestCases(); >- for (int i = 0; i < methods.length; i++) { >- if (JUnitGenerator.isTestMethod(methods[i])) { >- String methodName = methods[i].getElementName(); >- ITestCase tc = TestCommonUtil.createTestCase(testSuite, TestCommon.JUNIT_TEST_CASE_TYPE, /*externalBehavior*/true, methodName); >- Helper.setTestMethodName(tc, methodName); >- } >- } >- } >+ JUnitProjectBuilder.installBuilder(file.getProject()); >+ IFile javaFile = getJUnitSourceFile(testSuite); >+ JUnitProjectBuilder.installBuilder(javaFile.getProject()); >+ JUnitModelUpdater.associateTestSuiteToJUnitSourceFile(javaFile, file); > } > > /** >@@ -209,4 +183,13 @@ > return null; > } > >+ private static IStatus makeErrorStatus(String message, Throwable exception) { >+ return new Status(IStatus.ERROR, >+ CorePlugin.PLUGIN_ID, >+ 1, >+ message, >+ exception); >+ } >+ >+ > } >Index: src/org/eclipse/hyades/test/tools/core/internal/manual/codegen/GenTestSuite.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/manual/codegen/GenTestSuite.java,v >retrieving revision 1.11 >diff -u -r1.11 GenTestSuite.java >--- src/org/eclipse/hyades/test/tools/core/internal/manual/codegen/GenTestSuite.java 29 Jul 2006 01:57:42 -0000 1.11 >+++ src/org/eclipse/hyades/test/tools/core/internal/manual/codegen/GenTestSuite.java 11 Aug 2006 17:09:33 -0000 >@@ -4,7 +4,7 @@ > * 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 >- * $Id: GenTestSuite.java,v 1.11 2006/07/29 01:57:42 sschneid Exp $ >+ * $Id$ > * > * Contributors: > * IBM - Initial API and implementation >Index: src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitModelUpdater.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitModelUpdater.java,v >retrieving revision 1.5 >diff -u -r1.5 JUnitModelUpdater.java >--- src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitModelUpdater.java 10 Aug 2006 16:32:23 -0000 1.5 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitModelUpdater.java 11 Aug 2006 17:09:33 -0000 >@@ -12,9 +12,7 @@ > > package org.eclipse.hyades.test.tools.core.internal.java.modelsync; > >-import java.util.ArrayList; > import java.util.Iterator; >-import java.util.List; > > import org.eclipse.core.resources.IContainer; > import org.eclipse.core.resources.IFile; >@@ -24,16 +22,13 @@ > import org.eclipse.core.resources.ResourcesPlugin; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; >-import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Path; >-import org.eclipse.core.runtime.Status; > import org.eclipse.emf.ecore.EObject; > import org.eclipse.emf.ecore.resource.ResourceSet; > import org.eclipse.hyades.models.common.configuration.CFGClass; > import org.eclipse.hyades.models.common.configuration.CFGInstance; > import org.eclipse.hyades.models.common.facades.behavioral.IBlock; > import org.eclipse.hyades.models.common.facades.behavioral.IImplementor; >-import org.eclipse.hyades.models.common.facades.behavioral.ITestCase; > import org.eclipse.hyades.models.common.facades.behavioral.ITestSuite; > import org.eclipse.hyades.models.common.fragments.BVRInteraction; > import org.eclipse.hyades.models.common.interactions.BVRLifeline; >@@ -43,18 +38,11 @@ > import org.eclipse.hyades.models.common.util.ICommonConstants; > import org.eclipse.hyades.test.core.util.EMFUtil; > import org.eclipse.hyades.test.tools.core.CorePlugin; >-import org.eclipse.hyades.test.tools.core.common.TestCommon; >-import org.eclipse.hyades.test.tools.core.common.util.TestCommonUtil; >-import org.eclipse.hyades.test.tools.core.internal.common.codegen.ASTHelper; >-import org.eclipse.hyades.test.tools.core.internal.common.codegen.Helper; >-import org.eclipse.hyades.test.tools.core.internal.java.codegen.JUnitGenerator; >-import org.eclipse.hyades.test.tools.core.java.JUnitTestSuiteFacade; >+import org.eclipse.hyades.test.tools.core.java.IJUnitTestSuiteFactory; >+import org.eclipse.hyades.test.tools.core.java.IJUnitTestSuiteUpdateFactory; > import org.eclipse.jdt.core.ICompilationUnit; >-import org.eclipse.jdt.core.IMethod; > import org.eclipse.jdt.core.IType; > import org.eclipse.jdt.core.JavaCore; >-import org.eclipse.jdt.core.JavaModelException; >-import org.eclipse.jdt.core.dom.TagElement; > > /** > * This class provides methods for creating/updating a JUnit TestSuite model >@@ -69,128 +57,26 @@ > > /** > * Update the Test Suite model in order to take the last changes from the code >- * into account. Invoking this method updates the list of TestCases belonging to >- * the specified TestSuite.<br> >- * This method does the following: >- * <ul> >- * <li>For each test method (ie "void testXxxx()") in the code, ensures that there is a TestCase >- * associated to it. If not, creates a TestCase with the same name as the test method.</li> >- * <li>For each TestCase, ensures that the method it is associated with still exists. >- * If not, deletes the TestCase.</li> >- * </ul> >+ * into account. This is done by invoking the registered update factory for the type >+ * of the test suite. If no update factory is registered, this method does nothing and return >+ * <code>false</code>. > * @param testSuite >+ * @param javaFile > * @return <code>true</code> if any update was applied to the specified test suite, > * or <code>false</code> if the test suite was already up-to-date. > * @throws CoreException > */ >- public static boolean updateTestSuiteFromCode(ITestSuite testSuite) throws CoreException { >+ public static boolean updateTestSuiteFromCode(ITestSuite testSuite, IFile junitCode) throws CoreException { > boolean changed = false; >- IFile junitCode = JUnitTestSuiteFacade.getJUnitSourceFile(testSuite); >- if (junitCode != null) { >+ IJUnitTestSuiteFactory factory = JUnitExtensionsRegistry.getInstance().getFactory(testSuite.getType()); >+ if (factory instanceof IJUnitTestSuiteUpdateFactory) { >+ IJUnitTestSuiteUpdateFactory ufactory = (IJUnitTestSuiteUpdateFactory) factory; > ICompilationUnit cu = JavaCore.createCompilationUnitFrom(junitCode); >- if (!cu.isStructureKnown()) { >- throw new CoreException(makeErrorStatus("JUnit Compilation Unit structure is unknown", null)); //$NON-NLS-1$ >- } >- IType primaryType = cu.findPrimaryType(); >- if (cu == null) { >- throw new CoreException(makeErrorStatus("JUnit Compilation Unit has no primary type", null)); //$NON-NLS-1$ >- } >- boolean isExternalBehavior = testSuite.getImplementor().isExternalImplementor(); >- // Search for new test methods (=do not have a matching test case) >- IMethod[] methods = primaryType.getMethods(); >- List usedTestCases = new ArrayList(methods.length); >- for (int i = 0; i < methods.length; i++) { >- if (JUnitGenerator.isTestMethod(methods[i])) { >- ITestCase testCase = findTestCase(testSuite, methods[i]); >- if (testCase == null) { >- String methodName = methods[i].getElementName(); >- testCase = TestCommonUtil.createTestCase(testSuite, TestCommon.JUNIT_TEST_CASE_TYPE, isExternalBehavior, methodName); >- testCase.getImplementor().setResource(methodName); >- changed = true; >- } >- usedTestCases.add(testCase); >- if (updateTestCaseDescription(methods[i], testCase)) { >- changed = true; >- } >- } >- } >- // Search for Test Cases that do not have a matching test method >- List unusedTestCases = new ArrayList(); >- Iterator it = testSuite.getITestCases().iterator(); >- while (it.hasNext()) { >- ITestCase testCase = (ITestCase) it.next(); >- if (!usedTestCases.contains(testCase)) { >- String methodName = Helper.getTestMethodName(testCase); >- if (methodName != null) { >- IMethod method = primaryType.getMethod(methodName, new String[0]); >- if (!method.exists()) { >- unusedTestCases.add(testCase); >- } >- } >- } >- } >- // Remove test cases that are not associated to a test method any more >- it = unusedTestCases.iterator(); >- while (it.hasNext()) { >- EObject testCase = (EObject)it.next(); >- EMFUtil.remove(testCase); >- changed = true; >- } >- } >- return changed; >- } >- >- private static boolean updateTestCaseDescription(IMethod method, ITestCase testCase) throws JavaModelException { >- TagElement sourceTag = ASTHelper.getJavadocDescription(method); >- if (sourceTag == null) { >- if (testCase.getDescription() != null && testCase.getDescription().length() > 0) { >- testCase.setDescription(null); >- return true; >- } >- return false; >- } >- >- String sourceDescription = ASTHelper.extractDescription(sourceTag); >- if (sourceDescription.startsWith(testCase.getName())) { >- sourceDescription = sourceDescription.substring(testCase.getName().length()); >- if (sourceDescription.startsWith("\n")) sourceDescription = sourceDescription.substring("\n".length()); //$NON-NLS-1$//$NON-NLS-2$ >- } >- >- String tcDescription = testCase.getDescription(); >- if (tcDescription == null) tcDescription = ""; //$NON-NLS-1$ >- if (!Helper.compareJavaComments(sourceDescription, tcDescription)) { >- testCase.setDescription(sourceDescription.trim()); >- return true; >+ return ufactory.update(testSuite, cu); > } > return false; > } > >- private static ITestCase findTestCase(ITestSuite testSuite, IMethod testMethod) { >- Iterator it = testSuite.getITestCases().iterator(); >- Helper helper = new Helper(); >- try { >- String testMethodName = testMethod.getElementName(); >- while (it.hasNext()) { >- ITestCase testCase = (ITestCase) it.next(); >- String methodName = Helper.getTestMethodName(testCase); >- if (testMethodName.equals(methodName)) { >- return testCase; >- } >- } >- } finally { >- helper.dispose(); >- } >- return null; >- } >- >- private static IStatus makeErrorStatus(String message, Throwable exception) { >- return new Status(IStatus.ERROR, >- CorePlugin.PLUGIN_ID, >- 1, >- message, >- exception); >- } >- > /** > * This method is temporarily public. Clients should not use it. > * @param implementor >@@ -270,7 +156,7 @@ > } > } > >- private static IFile findTestSuiteFile(IFile javaFile) throws CoreException { >+ public static IFile findTestSuiteFile(IFile javaFile) throws CoreException { > // First method (typical): use the marker to find the test suite definition > IFile file = getRegisteredTestSuiteFile(javaFile); > if (file != null) { >Index: src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitProjectBuilder.java >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitProjectBuilder.java,v >retrieving revision 1.6 >diff -u -r1.6 JUnitProjectBuilder.java >--- src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitProjectBuilder.java 10 Aug 2006 16:32:23 -0000 1.6 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitProjectBuilder.java 11 Aug 2006 17:09:33 -0000 >@@ -124,7 +124,7 @@ > try { > TPFTestSuite testSuite = (TPFTestSuite)JUnitTestSuiteFacade.findTestSuite(javaFile, new ResourceSetImpl()); > if (testSuite != null) { >- if (JUnitModelUpdater.updateTestSuiteFromCode(testSuite)) { >+ if (JUnitModelUpdater.updateTestSuiteFromCode(testSuite, javaFile)) { > SaveManager.saveResource(testSuite); > IFile file = EMFUtil.getWorkspaceFile(testSuite); > file.refreshLocal(0, null); >Index: plugin.xml >=================================================================== >RCS file: /home/tptp/test/org.eclipse.hyades.test.tools.core/plugin.xml,v >retrieving revision 1.40 >diff -u -r1.40 plugin.xml >--- plugin.xml 10 Aug 2006 16:32:24 -0000 1.40 >+++ plugin.xml 11 Aug 2006 17:09:33 -0000 >@@ -3,6 +3,7 @@ > <plugin> > > <extension-point id="nodeHandlers" name="org.eclipse.hyades.test.tools.core.nodeHandlers" schema="schema/nodeHandlers.exsd"/> >+ <extension-point id="junitFactory" name="JUnit Test Model Factory" schema="schema/junitFactory.exsd"/> > > <extension > point="org.eclipse.hyades.test.core.launchconfigLaunchableType"> >@@ -285,6 +286,17 @@ > <service class="org.eclipse.hyades.test.tools.core.services.AgentControllerVerificationService"/> > </extension> > <extension >+ point="org.eclipse.hyades.test.tools.core.junitFactory"> >+ <factory >+ class="org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitTypeFactory" >+ type="org.eclipse.hyades.test.java.junit.testSuite" >+ updateSupport="true"/> >+ <factory >+ class="org.eclipse.hyades.test.tools.core.internal.plugin.modelsync.JUnitPluginTypeFactory" >+ type="org.eclipse.hyades.test.plugin.junit.testSuite" >+ updateSupport="true"/> >+ </extension> >+ <extension > id="junit" > name="TPTP JUnit source metadata" > point="org.eclipse.core.resources.markers"> >Index: schema/junitFactory.exsd >=================================================================== >RCS file: schema/junitFactory.exsd >diff -N schema/junitFactory.exsd >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ schema/junitFactory.exsd 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,119 @@ >+<?xml version='1.0' encoding='UTF-8'?> >+<!-- Schema file written by PDE --> >+<schema targetNamespace="org.eclipse.hyades.test.tools.core"> >+<annotation> >+ <appInfo> >+ <meta.schema plugin="org.eclipse.hyades.test.tools.core" id="junitFactory" name="JUnit Test Model Factory"/> >+ </appInfo> >+ <documentation> >+ This extension point registers a JUnit test model factory. A JUnit test model factory generates a TPTP test model from a java source file. Such a factory has also the optional capability of updating a test model to reflect changes occurred in the java source file it is associated to. >+ </documentation> >+ </annotation> >+ >+ <element name="extension"> >+ <complexType> >+ <sequence minOccurs="0" maxOccurs="unbounded"> >+ <element ref="factory"/> >+ </sequence> >+ <attribute name="point" type="string" use="required"> >+ <annotation> >+ <documentation> >+ >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="id" type="string"> >+ <annotation> >+ <documentation> >+ >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="name" type="string"> >+ <annotation> >+ <documentation> >+ >+ </documentation> >+ <appInfo> >+ <meta.attribute translatable="true"/> >+ </appInfo> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <element name="factory"> >+ <complexType> >+ <attribute name="class" type="string" use="required"> >+ <annotation> >+ <documentation> >+ The class implementing the factory. >+ </documentation> >+ <appInfo> >+ <meta.attribute kind="java" basedOn="org.eclipse.hyades.test.tools.core.java.IJUnitTestSuiteFactory"/> >+ </appInfo> >+ </annotation> >+ </attribute> >+ <attribute name="updateSupport" type="boolean" use="required"> >+ <annotation> >+ <documentation> >+ Whether the class supports test suite model update. If true, class must implement org.eclipse.hyades.test.tools.core.java.IJUnitTestSuiteUpdateFactory. >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="type" type="string" use="required"> >+ <annotation> >+ <documentation> >+ The type of test suite that this factory generates. >+ </documentation> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <annotation> >+ <appInfo> >+ <meta.section type="since"/> >+ </appInfo> >+ <documentation> >+ [Enter the first release in which this extension point appears.] >+ </documentation> >+ </annotation> >+ >+ <annotation> >+ <appInfo> >+ <meta.section type="examples"/> >+ </appInfo> >+ <documentation> >+ [Enter extension point usage example here.] >+ </documentation> >+ </annotation> >+ >+ <annotation> >+ <appInfo> >+ <meta.section type="apiInfo"/> >+ </appInfo> >+ <documentation> >+ [Enter API information here.] >+ </documentation> >+ </annotation> >+ >+ <annotation> >+ <appInfo> >+ <meta.section type="implementation"/> >+ </appInfo> >+ <documentation> >+ [Enter information about supplied implementation of this extension point.] >+ </documentation> >+ </annotation> >+ >+ <annotation> >+ <appInfo> >+ <meta.section type="copyright"/> >+ </appInfo> >+ <documentation> >+ >+ </documentation> >+ </annotation> >+ >+</schema> >Index: src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitExtensionsRegistry.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitExtensionsRegistry.java >diff -N src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitExtensionsRegistry.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitExtensionsRegistry.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,139 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.core.internal.java.modelsync; >+ >+import java.util.ArrayList; >+import java.util.Collection; >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.Map; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.core.runtime.IExtension; >+import org.eclipse.core.runtime.IExtensionPoint; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.hyades.test.tools.core.CorePlugin; >+import org.eclipse.hyades.test.tools.core.java.IJUnitTestSuiteFactory; >+import org.eclipse.jface.resource.ImageDescriptor; >+ >+public class JUnitExtensionsRegistry { >+ >+ private static JUnitExtensionsRegistry instance; >+ private final static String EXT_POINT_ID = CorePlugin.getID() + ".junitFactory"; //$NON-NLS-1$ >+ >+ public static JUnitExtensionsRegistry getInstance() { >+ if (instance == null) { >+ instance = new JUnitExtensionsRegistry(); >+ } >+ return instance; >+ } >+ >+ private Map factoryDescriptors; >+ >+ private JUnitExtensionsRegistry() { >+ registerFactories(); >+ } >+ >+ public class JUnitTestSuiteFactoryDescriptor { >+ private IConfigurationElement element; >+ private IJUnitTestSuiteFactory factory; >+ public JUnitTestSuiteFactoryDescriptor(IConfigurationElement element) { >+ this.element = element; >+ } >+ public String getType() { >+ return element.getAttribute("type"); //$NON-NLS-1$ >+ } >+ public boolean isUpdateCapable() { >+ return Boolean.valueOf(element.getAttribute("updateSupport")).booleanValue(); //$NON-NLS-1$ >+ } >+ public IJUnitTestSuiteFactory getFactory() { >+ if (factory == null) { >+ try { >+ factory =(IJUnitTestSuiteFactory)element.createExecutableExtension("class"); //$NON-NLS-1$ >+ } catch (CoreException e) { >+ CorePlugin.logError(e); >+ invalidFactory(this); >+ } >+ } >+ return factory; >+ } >+ public boolean equals(Object obj) { >+ if (!(obj instanceof JUnitTestSuiteFactoryDescriptor)) return false; >+ if (getType() == null) return false; // This is an error case >+ JUnitTestSuiteFactoryDescriptor other = (JUnitTestSuiteFactoryDescriptor) obj; >+ return getType().equals(other.getType()); >+ } >+ public int hashCode() { >+ String type = getType(); >+ if (type == null) return super.hashCode(); >+ else return type.hashCode(); >+ } >+ >+ } >+ >+ protected void invalidFactory(JUnitTestSuiteFactoryDescriptor descr) { >+ factoryDescriptors.remove(descr.getType()); >+ } >+ >+ public IJUnitTestSuiteFactory getFactory(String type) { >+ JUnitTestSuiteFactoryDescriptor descr = getDescriptor(type); >+ if (descr != null) { >+ return descr.getFactory(); >+ } >+ return null; >+ } >+ >+ public JUnitTestSuiteFactoryDescriptor getDescriptor(String type) { >+ return (JUnitTestSuiteFactoryDescriptor) factoryDescriptors.get(type); >+ } >+ >+ public JUnitTestSuiteFactoryDescriptor[] getAvailableFactories(boolean updateSupport) { >+ Collection list; >+ if (updateSupport) { >+ list = getUpdateCapableFactories(); >+ } else { >+ list = factoryDescriptors.values(); >+ } >+ JUnitTestSuiteFactoryDescriptor[] ret = new JUnitTestSuiteFactoryDescriptor[list.size()]; >+ return (JUnitTestSuiteFactoryDescriptor[]) factoryDescriptors.values().toArray(ret); >+ } >+ >+ private Collection getUpdateCapableFactories() { >+ Collection values = factoryDescriptors.values(); >+ ArrayList ret = new ArrayList(values.size()); >+ Iterator it = values.iterator(); >+ while (it.hasNext()) { >+ JUnitTestSuiteFactoryDescriptor descr = (JUnitTestSuiteFactoryDescriptor) it.next(); >+ if (descr.isUpdateCapable()) { >+ ret.add(descr); >+ } >+ } >+ return ret; >+ } >+ >+ private void registerFactories() { >+ factoryDescriptors = new HashMap(); >+ IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(EXT_POINT_ID); >+ IExtension[] extensions = point.getExtensions(); >+ for (int i = 0; i < extensions.length; i++) { >+ IExtension extension = extensions[i]; >+ IConfigurationElement[] elements = extension.getConfigurationElements(); >+ for (int j = 0; j < elements.length; j++) { >+ IConfigurationElement element = elements[j]; >+ JUnitTestSuiteFactoryDescriptor descr = new JUnitTestSuiteFactoryDescriptor(element); >+ factoryDescriptors.put(descr.getType(), descr); >+ } >+ } >+ } >+} >Index: src/org/eclipse/hyades/test/tools/core/java/IJUnitTestSuiteUpdateFactory.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/core/java/IJUnitTestSuiteUpdateFactory.java >diff -N src/org/eclipse/hyades/test/tools/core/java/IJUnitTestSuiteUpdateFactory.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/core/java/IJUnitTestSuiteUpdateFactory.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,40 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.core.java; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.hyades.models.common.facades.behavioral.ITestSuite; >+import org.eclipse.jdt.core.ICompilationUnit; >+ >+/** >+ * A factory capable of generating and updating a test suite model from a compilation >+ * unit. >+ * @author jcanches >+ * @since 4.3 >+ */ >+public interface IJUnitTestSuiteUpdateFactory extends IJUnitTestSuiteFactory { >+ >+ /** >+ * Updates a test suite model to take the changes occurred in a compilation >+ * unit since the last time the test suite model was generated or updated. >+ * @param testSuite A test suite that has been generated or updated by this >+ * factory in a point in the past. >+ * @param cu A compilation that may have arbitrary changes since the last update >+ * or generation. >+ * @return Whether the testSuite was changed by the update. Returning <code>false</code> >+ * means that the changes in the compilation unit did not have any effect on the test >+ * suite model. >+ */ >+ boolean update(ITestSuite testSuite, ICompilationUnit cu) throws CoreException; >+ >+} >Index: src/org/eclipse/hyades/test/tools/core/internal/plugin/modelsync/JUnitPluginTypeFactory.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/core/internal/plugin/modelsync/JUnitPluginTypeFactory.java >diff -N src/org/eclipse/hyades/test/tools/core/internal/plugin/modelsync/JUnitPluginTypeFactory.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/core/internal/plugin/modelsync/JUnitPluginTypeFactory.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,56 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.core.internal.plugin.modelsync; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.hyades.test.tools.core.common.TestCommon; >+import org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitTypeFactory; >+import org.eclipse.hyades.test.tools.core.internal.plugin.util.PDEProjectUtil; >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.JavaModelException; >+ >+/** >+ * This test suite factory handles the generation and update of test suite models >+ * of type "TPTP Plug-in JUnit". It is identical in all aspects to {@link JUnitTypeFactory}, >+ * except that generated test suites are of JUnit plug-in type. >+ * @author jcanches >+ * @since 4.3 >+ */ >+public class JUnitPluginTypeFactory extends JUnitTypeFactory { >+ >+ protected String getTestSuiteType() { >+ return TestCommon.PLUGIN_JUNIT_TEST_SUITE_TYPE; >+ } >+ >+ public boolean isSupported(ICompilationUnit cu) { >+ try { >+ IProject project = cu.getUnderlyingResource().getProject(); >+ if (!PDEProjectUtil.isStrictPluginProject(project)) { >+ return false; >+ } >+ } catch (JavaModelException e) { >+ return false; >+ } >+ return super.isSupported(cu); >+ } >+ >+ public boolean isSupported(IJavaProject project) { >+ IProject rproject = project.getProject(); >+ if (!PDEProjectUtil.isStrictPluginProject(rproject)) { >+ return false; >+ } >+ return super.isSupported(project); >+ } >+ >+} >Index: src/org/eclipse/hyades/test/tools/core/java/IJUnitTestSuiteFactory.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/core/java/IJUnitTestSuiteFactory.java >diff -N src/org/eclipse/hyades/test/tools/core/java/IJUnitTestSuiteFactory.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/core/java/IJUnitTestSuiteFactory.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,55 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.core.java; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.hyades.models.common.facades.behavioral.ITestSuite; >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.IJavaProject; >+ >+/** >+ * A factory capable of generating a test suite model from a JUnit source. >+ * @author jcanches >+ * @since 4.3 >+ */ >+public interface IJUnitTestSuiteFactory { >+ >+ /** >+ * Returns whether this factory supports test suite generation for a given compilation unit. >+ * @param cu A compilation unit >+ * @return Whether test suite generaton is supported for <code>cu</code>. >+ */ >+ boolean isSupported(ICompilationUnit cu); >+ >+ /** >+ * Generates a test suite for a given compilation unit. >+ * @param cu A compilation unit >+ * @return A test suite. >+ */ >+ ITestSuite generate(ICompilationUnit cu) throws CoreException; >+ >+ /** >+ * Determines whether the factory supports test suite generation for compilation >+ * units found in the given project. This method exists for improving performance, and >+ * as such should respond quicky. In no way it should dig into a complete project to check if >+ * there is a supported compilation unit. In case of doubt, it should return <code>true</code>. >+ * @param project A java project. >+ * @return <code>true</code> if this factory may support generation for compilation >+ * units in the project (even if it does not support generation for <strong>all</strong> >+ * the compilation units of the project), and <code>false</code> if it does not support >+ * generation for the project at all. >+ */ >+ public boolean isSupported(IJavaProject project); >+ >+ >+} >Index: src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitTypeFactory.java >=================================================================== >RCS file: src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitTypeFactory.java >diff -N src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitTypeFactory.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/hyades/test/tools/core/internal/java/modelsync/JUnitTypeFactory.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,256 @@ >+/******************************************************************************* >+ * Copyright (c) 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 >+ * $Id: $ >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.hyades.test.tools.core.internal.java.modelsync; >+ >+import java.util.ArrayList; >+import java.util.Iterator; >+import java.util.List; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.resource.Resource; >+import org.eclipse.emf.ecore.resource.impl.ResourceImpl; >+import org.eclipse.hyades.models.common.facades.behavioral.ITestCase; >+import org.eclipse.hyades.models.common.facades.behavioral.ITestSuite; >+import org.eclipse.hyades.models.common.facades.behavioral.impl.HyadesFactory; >+import org.eclipse.hyades.test.core.util.EMFUtil; >+import org.eclipse.hyades.test.tools.core.CorePlugin; >+import org.eclipse.hyades.test.tools.core.common.TestCommon; >+import org.eclipse.hyades.test.tools.core.common.util.TestCommonUtil; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.ASTHelper; >+import org.eclipse.hyades.test.tools.core.internal.common.codegen.Helper; >+import org.eclipse.hyades.test.tools.core.internal.java.codegen.JUnitGenerator; >+import org.eclipse.hyades.test.tools.core.java.IJUnitTestSuiteUpdateFactory; >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IMethod; >+import org.eclipse.jdt.core.IType; >+import org.eclipse.jdt.core.ITypeHierarchy; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.core.dom.TagElement; >+ >+/** >+ * This test suite factory handles the generation and update of test suite models >+ * of type "TPTP JUnit". >+ * @author jcanches >+ * @since 4.3 >+ */ >+public class JUnitTypeFactory implements IJUnitTestSuiteUpdateFactory { >+ >+ /** >+ * Sub-classes should redefine this method to support an additional type. >+ * @return The test suite type that this factory can generate. >+ */ >+ protected String getTestSuiteType() { >+ return TestCommon.JUNIT_TEST_SUITE_TYPE; >+ } >+ >+ /** >+ * This implementation accepts generation for the given compilation unit provided that >+ * its main type implements a JUnit test interface. >+ */ >+ public boolean isSupported(ICompilationUnit cu) { >+ try { >+ IType type = cu.findPrimaryType(); >+ if (type != null) { >+ ITypeHierarchy typeHier= type.newSupertypeHierarchy(null); >+ IType[] superInterfaces= typeHier.getAllInterfaces(); >+ for (int i= 0; i < superInterfaces.length; i++) { >+ if (superInterfaces[i].getFullyQualifiedName().equals(Helper.JUNIT_TEST_CLASS_NAME)) >+ return true; >+ } >+ } >+ return false; >+ } catch (JavaModelException e) { >+ return false; >+ } >+ } >+ >+ /** >+ * Generates a basic model, with no model behavior, and one test case per test method. >+ */ >+ public ITestSuite generate(ICompilationUnit cu) throws JavaModelException { >+ Resource resource = new ResourceImpl(); >+ ITestSuite testSuite = HyadesFactory.INSTANCE.createTestSuite(resource); >+ testSuite.setType(getTestSuiteType()); >+ >+ HyadesFactory.INSTANCE.createImplementor(testSuite, /*isExternalImplementor*/true); >+ // This TestSuite has a code-implemented behavior: >+ JUnitModelUpdater.setImplementorBlock(testSuite.getImplementor(), null); >+ >+ populateTestCases(testSuite, cu); >+ return testSuite; >+ } >+ >+ /** >+ * Updates the Test Suite model in order to take the last changes from the code >+ * into account. Invoking this method updates the list of TestCases belonging to >+ * the specified TestSuite.<br> >+ * This method does the following: >+ * <ul> >+ * <li>for each test method (ie "void testXxxx()") in the code, ensures that there is a TestCase >+ * associated to it. If not, creates a TestCase with the same name as the test method.</li> >+ * <li>for each TestCase, ensures that the method it is associated with still exists. >+ * If not, deletes the TestCase.</li> >+ * </ul> >+ * @param testSuite >+ * @param cu >+ * @return <code>true</code> if any update was applied to the specified test suite, >+ * or <code>false</code> if the test suite was already up-to-date. >+ * @throws CoreException >+ */ >+ public boolean update(ITestSuite testSuite, ICompilationUnit cu) throws CoreException { >+ boolean changed = false; >+ if (!cu.isStructureKnown()) { >+ throw new CoreException(makeErrorStatus("JUnit Compilation Unit structure is unknown", null)); //$NON-NLS-1$ >+ } >+ IType primaryType = cu.findPrimaryType(); >+ if (cu == null) { >+ throw new CoreException(makeErrorStatus("JUnit Compilation Unit has no primary type", null)); //$NON-NLS-1$ >+ } >+ boolean isExternalBehavior = testSuite.getImplementor().isExternalImplementor(); >+ // Search for new test methods (=do not have a matching test case) >+ IMethod[] methods = primaryType.getMethods(); >+ List usedTestCases = new ArrayList(methods.length); >+ for (int i = 0; i < methods.length; i++) { >+ if (JUnitGenerator.isTestMethod(methods[i])) { >+ ITestCase testCase = findTestCase(testSuite, methods[i]); >+ if (testCase == null) { >+ String methodName = methods[i].getElementName(); >+ testCase = TestCommonUtil.createTestCase(testSuite, TestCommon.JUNIT_TEST_CASE_TYPE, isExternalBehavior, methodName); >+ testCase.getImplementor().setResource(methodName); >+ changed = true; >+ } >+ usedTestCases.add(testCase); >+ if (updateTestCaseDescription(methods[i], testCase)) { >+ changed = true; >+ } >+ } >+ } >+ // Search for Test Cases that do not have a matching test method >+ List unusedTestCases = new ArrayList(); >+ Iterator it = testSuite.getITestCases().iterator(); >+ while (it.hasNext()) { >+ ITestCase testCase = (ITestCase) it.next(); >+ if (!usedTestCases.contains(testCase)) { >+ String methodName = Helper.getTestMethodName(testCase); >+ if (methodName != null) { >+ IMethod method = primaryType.getMethod(methodName, new String[0]); >+ if (!method.exists()) { >+ unusedTestCases.add(testCase); >+ } >+ } >+ } >+ } >+ // Remove test cases that are not associated to a test method any more >+ it = unusedTestCases.iterator(); >+ while (it.hasNext()) { >+ EObject testCase = (EObject)it.next(); >+ EMFUtil.remove(testCase); >+ changed = true; >+ } >+ return changed; >+ } >+ >+ private static boolean updateTestCaseDescription(IMethod method, ITestCase testCase) throws JavaModelException { >+ TagElement sourceTag = ASTHelper.getJavadocDescription(method); >+ if (sourceTag == null) { >+ if (testCase.getDescription() != null && testCase.getDescription().length() > 0) { >+ testCase.setDescription(null); >+ return true; >+ } >+ return false; >+ } >+ >+ String sourceDescription = ASTHelper.extractDescription(sourceTag); >+ if (sourceDescription.startsWith(testCase.getName())) { >+ sourceDescription = sourceDescription.substring(testCase.getName().length()); >+ if (sourceDescription.startsWith("\n")) sourceDescription = sourceDescription.substring("\n".length()); //$NON-NLS-1$//$NON-NLS-2$ >+ } >+ >+ String tcDescription = testCase.getDescription(); >+ if (tcDescription == null) tcDescription = ""; //$NON-NLS-1$ >+ if (!Helper.compareJavaComments(sourceDescription, tcDescription)) { >+ testCase.setDescription(sourceDescription.trim()); >+ return true; >+ } >+ return false; >+ } >+ >+ /** >+ * Populates an empty JUnit ITestSuite with one ITestCase for each test method found >+ * in compilation unit cu. >+ * For the more generic case where the ITestSuite already owns ITestCase children which >+ * need to updated according to the new state of the source code, see >+ * ModelUpdater.updateTestSuiteFromCode(ITestSuite). >+ * @param testSuite >+ * @param cu >+ * @throws JavaModelException >+ * @see org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitModelUpdater#updateTestSuiteFromCode(ITestSuite) >+ */ >+ private static void populateTestCases(ITestSuite testSuite, ICompilationUnit cu) throws JavaModelException { >+ boolean isExternalBehavior = testSuite.getImplementor().isExternalImplementor(); >+ IType mainType = cu.findPrimaryType(); >+ if (mainType != null) { >+ IMethod[] methods = mainType.getMethods(); >+ //List testCases = testSuite.getITestCases(); >+ for (int i = 0; i < methods.length; i++) { >+ if (JUnitGenerator.isTestMethod(methods[i])) { >+ String methodName = methods[i].getElementName(); >+ ITestCase tc = TestCommonUtil.createTestCase(testSuite, TestCommon.JUNIT_TEST_CASE_TYPE, /*externalBehavior*/true, methodName); >+ Helper.setTestMethodName(tc, methodName); >+ } >+ } >+ } >+ } >+ >+ /** >+ * Returns the test case matching a given test method, or <code>null</code> if there >+ * is none. >+ * @param testSuite >+ * @param testMethod >+ * @return >+ */ >+ private static ITestCase findTestCase(ITestSuite testSuite, IMethod testMethod) { >+ Iterator it = testSuite.getITestCases().iterator(); >+ Helper helper = new Helper(); >+ try { >+ String testMethodName = testMethod.getElementName(); >+ while (it.hasNext()) { >+ ITestCase testCase = (ITestCase) it.next(); >+ String methodName = Helper.getTestMethodName(testCase); >+ if (testMethodName.equals(methodName)) { >+ return testCase; >+ } >+ } >+ } finally { >+ helper.dispose(); >+ } >+ return null; >+ } >+ >+ private static IStatus makeErrorStatus(String message, Throwable exception) { >+ return new Status(IStatus.ERROR, >+ CorePlugin.PLUGIN_ID, >+ 1, >+ message, >+ exception); >+ } >+ >+ public boolean isSupported(IJavaProject project) { >+ return true; >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 90628
: 47778