From: <jsa...@us...> - 2008-11-21 11:56:14
|
Revision: 113 http://flexotask.svn.sourceforge.net/flexotask/?rev=113&view=rev Author: jsauerbach Date: 2008-11-21 11:56:10 +0000 (Fri, 21 Nov 2008) Log Message: ----------- Let the classpath container contain at least a simple project entry for projects that extend flexotask extension points even if those projects were never installed as plugins. To support this along with all the corner cases of projects being created and destroyed, add a "Recompute Classpaths" action and group it (along with the existing "Convert to Flexotask Project" action into a Flexotask Tooks submenu. Modified Paths: -------------- trunk/flexotask-development/plugin.xml trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/ConvertToFlexotaskProject.java trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/FlexotaskClasspathInitializer.java trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/GlobalTiming.java Added Paths: ----------- trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/CommonProjectAction.java trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/RecomputeClasspaths.java trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/BasicLibraryProvider.java Modified: trunk/flexotask-development/plugin.xml =================================================================== --- trunk/flexotask-development/plugin.xml 2008-11-18 20:29:20 UTC (rev 112) +++ trunk/flexotask-development/plugin.xml 2008-11-21 11:56:10 UTC (rev 113) @@ -56,14 +56,26 @@ adaptable="true" objectClass="org.eclipse.core.resources.IProject" nameFilter="*" - id="FlexotaskBuilder.contribution1"> + id="com.ibm.realtime.flexotask.development.menuContribution"> <action label="Convert to Flexotask Project" class="com.ibm.realtime.flexotask.development.wizards.ConvertToFlexotaskProject" - menubarPath="additions" + menubarPath="com.ibm.realtime.flexotask.development.menu/additions" enablesFor="+" id="FlexotaskBuilder.convertProjectAction"> </action> + <menu + id="com.ibm.realtime.flexotask.development.menu" + label="Fle&xotask Tools" + path="additions"> + </menu> + <action + class="com.ibm.realtime.flexotask.development.wizards.RecomputeClasspaths" + enablesFor="+" + id="com.ibm.realtime.flexotask.development.classpath" + label="Recompute Classpaths" + menubarPath="com.ibm.realtime.flexotask.development.menu/additions"> + </action> </objectContribution> </extension> <extension Added: trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/CommonProjectAction.java =================================================================== --- trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/CommonProjectAction.java (rev 0) +++ trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/CommonProjectAction.java 2008-11-21 11:56:10 UTC (rev 113) @@ -0,0 +1,100 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package com.ibm.realtime.flexotask.development.wizards; + +import java.util.Iterator; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IObjectActionDelegate; +import org.eclipse.ui.IWorkbenchPart; + +import com.ibm.realtime.flexotask.editor.FlexotaskClasspathInitializer; + +/** + * Common superclass of Flexotask Tools actions that are capable of operating on multiple + * projects + */ +abstract class CommonProjectAction implements IObjectActionDelegate { + /** The selection, from which the set of projects is to be determined */ + private ISelection selection; + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) + */ + public void run(IAction action) { + if (selection instanceof IStructuredSelection) { + for (Iterator it = ((IStructuredSelection) selection).iterator(); it.hasNext();) { + Object element = it.next(); + IProject project = null; + if (element instanceof IProject) { + project = (IProject) element; + } + else if (element instanceof IAdaptable) { + project = (IProject) ((IAdaptable) element) + .getAdapter(IProject.class); + } + if (project != null) { + processProject(project); + } + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) + */ + public void selectionChanged(IAction action, ISelection selection) { + this.selection = selection; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) + */ + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + } + + /** + * Method to test whether a project already has a Flexotask classpath container + * @param project the IJavaProject to test + * @return true iff the Flexotask classpath container is configured + * @throws JavaModelException + */ + protected boolean hasFlexotaskClasspath(IJavaProject project) throws JavaModelException { + IClasspathEntry[] entries = project.getRawClasspath(); + for (int i = 0; i < entries.length; i++) { + IClasspathEntry entry = entries[i]; + if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { + IPath containerPath = entry.getPath(); + if (containerPath.segmentCount() == 2 && FlexotaskClasspathInitializer.CONTAINER_ID.equals(containerPath.segment(0))) { + return true; + } + } + } + return false; + } + + /** + * Action to take on individual projects + * @param project the project on which the action is currently being taken + */ + abstract void processProject(IProject project); +} Property changes on: trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/CommonProjectAction.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/ConvertToFlexotaskProject.java =================================================================== --- trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/ConvertToFlexotaskProject.java 2008-11-18 20:29:20 UTC (rev 112) +++ trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/ConvertToFlexotaskProject.java 2008-11-21 11:56:10 UTC (rev 113) @@ -13,83 +13,33 @@ */ package com.ibm.realtime.flexotask.development.wizards; -import java.util.Iterator; - import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; import com.ibm.realtime.flexotask.development.builder.FlexotaskNature; -import com.ibm.realtime.flexotask.editor.FlexotaskClasspathInitializer; /** * Action to convert a project (even one that has some Flexotask facilities already) to a full-fledged * Flexotask project including all the supporting facilities */ -public class ConvertToFlexotaskProject implements IObjectActionDelegate { - /** The selection, from which the project is to be determined */ - private ISelection selection; - - /* (non-Javadoc) - * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) - */ - public void run(IAction action) { - if (selection instanceof IStructuredSelection) { - for (Iterator it = ((IStructuredSelection) selection).iterator(); it.hasNext();) { - Object element = it.next(); - IProject project = null; - if (element instanceof IProject) { - project = (IProject) element; - } - else if (element instanceof IAdaptable) { - project = (IProject) ((IAdaptable) element) - .getAdapter(IProject.class); - } - if (project != null) { - convert(project); - } - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) - */ - public void selectionChanged(IAction action, ISelection selection) { - this.selection = selection; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) - */ - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - } - +public class ConvertToFlexotaskProject extends CommonProjectAction { /** * Perform the conversion operation on a project * @param project the project to convert */ - private void convert(IProject project) { + void processProject(IProject project) { IProjectDescription description; try { description = project.getDescription(); @@ -110,7 +60,7 @@ /* Present information to the user if some or all of the actions are unnecessary and get permission * to proceed. */ - if (!shouldProceed(haveNature, haveLibraries, generated.exists())) { + if (!shouldProceed(haveNature, haveLibraries, generated.exists(), project.getName())) { return; } @@ -135,43 +85,24 @@ } /** - * Method to test whether a project already has a Flexotask classpath container - * @param project the IJavaProject to test - * @return true iff the Flexotask classpath container is configured - * @throws JavaModelException - */ - private boolean hasFlexotaskClasspath(IJavaProject project) throws JavaModelException { - IClasspathEntry[] entries = project.getRawClasspath(); - for (int i = 0; i < entries.length; i++) { - IClasspathEntry entry = entries[i]; - if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { - IPath containerPath = entry.getPath(); - if (containerPath.segmentCount() == 2 && FlexotaskClasspathInitializer.CONTAINER_ID.equals(containerPath.segment(0))) { - return true; - } - } - } - return false; - } - - /** * Interact with the user depending on the current state of the project. If the project is already fully converted, just inform the user * of that fact and do nothing. * @param haveNature true iff the project already has the FlexotaskNature * @param haveLibraries true iff the project already has the Flexotask libraries * @param generatedExists true iff the 'generated' folder already exists + * @param projectName * @return true if conversion should proceed with those facilities that are missing, false if conversion should not proceed */ - private boolean shouldProceed(boolean haveNature, boolean haveLibraries, boolean generatedExists) { + private boolean shouldProceed(boolean haveNature, boolean haveLibraries, boolean generatedExists, String projectName) { if (haveNature && haveLibraries && generatedExists) { - MessageDialog.openWarning(Display.getCurrent().getActiveShell(), "Nothing to do", "This project is already a Flexotask project, nothing will be done"); + MessageDialog.openWarning(Display.getCurrent().getActiveShell(), "Skipping project", projectName + " is already a Flexotask project, nothing will be done"); return false; } if (!haveNature && !haveLibraries && !generatedExists) { return true; } /* Mixed cases: let the user decide */ - StringBuilder message = new StringBuilder("Project has some Flexotask facilities already: "); + StringBuilder message = new StringBuilder(projectName + " has some Flexotask facilities already: "); message.append("\n").append(haveNature ? "has" : "does not have").append(" development support"); message.append("\n").append(haveLibraries ? "has" : "does not have").append(" Flexotask libraries"); message.append("\n").append(generatedExists ? "has" : "does not have").append(" generated code directory"); Added: trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/RecomputeClasspaths.java =================================================================== --- trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/RecomputeClasspaths.java (rev 0) +++ trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/RecomputeClasspaths.java 2008-11-21 11:56:10 UTC (rev 113) @@ -0,0 +1,46 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package com.ibm.realtime.flexotask.development.wizards; + +import org.eclipse.core.resources.IProject; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; + +import com.ibm.realtime.flexotask.editor.FlexotaskClasspathInitializer; +import com.ibm.realtime.flexotask.editor.model.GlobalTiming; + +/** + * Action to recompute the classpaths of projects that use the Flexotask Classpath container (if called on other projects + * nothing is done). Used by the user to correct for various anomalies that arise when projects are added and deleted + * etc. + */ +public class RecomputeClasspaths extends CommonProjectAction { + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.development.wizards.CommonProjectAction#processProject(org.eclipse.core.resources.IProject) + */ + void processProject(IProject project) { + IJavaProject javaProject = JavaCore.create(project); + boolean hasClasspath; + try { + hasClasspath = hasFlexotaskClasspath(javaProject); + } catch (JavaModelException e) { + hasClasspath = false; + } + if (hasClasspath) { + GlobalTiming.resetProviders(); + FlexotaskClasspathInitializer.recomputeClasspath(javaProject); + } + } +} Property changes on: trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/RecomputeClasspaths.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/FlexotaskClasspathInitializer.java =================================================================== --- trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/FlexotaskClasspathInitializer.java 2008-11-18 20:29:20 UTC (rev 112) +++ trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/FlexotaskClasspathInitializer.java 2008-11-21 11:56:10 UTC (rev 113) @@ -99,18 +99,17 @@ !CONTAINER_ID.equals(containerPath.segment(0))) { return; } - reInitialize(containerPath, project); + reInitialize(project); IEclipsePreferences preferences = new ProjectScope(project.getProject()).getNode(JavaCore.PLUGIN_ID); - preferences.addPreferenceChangeListener(new ComplianceChangeListener(containerPath, project)); + preferences.addPreferenceChangeListener(new ComplianceChangeListener(project)); } /** - * Working subroutine of initialize(), also called when the compliance preference of the project changes - * @param containerPath the container path to use - * @param project the JavaProject to use + * Working subroutine of initialize(), also called from recomputeClasspath + * @param project the IJavaProject whose Flexotask Libraries Container is being (re) initialized * @throws CoreException if anything goes wrong */ - private void reInitialize(IPath containerPath, IJavaProject project) throws CoreException + private static void reInitialize(IJavaProject project) throws CoreException { List<IClasspathEntry> entryList = new ArrayList<IClasspathEntry>(); String compliance = project.getOption(COMPLIANCE_KEY, true); @@ -121,10 +120,35 @@ addPluginClasspath(entryList, ANALYSIS_PLUGIN); GlobalTiming.addToClasspath(entryList); IClasspathEntry[] entries = entryList.toArray(new IClasspathEntry[0]); - IClasspathContainer container = new FlexotaskClasspath(entries, containerPath); - JavaCore.setClasspathContainer(containerPath, new IJavaProject[]{project}, + IClasspathContainer container = new FlexotaskClasspath(entries, CONTAINER_PATH); + JavaCore.setClasspathContainer(CONTAINER_PATH, new IJavaProject[]{project}, new IClasspathContainer[]{container}, null); } + + /** + * Reinitialize the classpath of a project, displaying any errors that may occur. Callable from the project + * preference change listener and from the external UI (Flexotask Tools pupup menu) + * @param project the IJavaProject whose Flexotask Libraries Container is being recomputed + */ + public static void recomputeClasspath(IJavaProject project) { + try { + reInitialize(project); + } catch (CoreException e) { + IStatus status = e.getStatus(); + if (status == null) { + status = new Status(Status.ERROR, EEditPlugin.ID, e.getMessage(), e); + } + ResourcesPlugin.getPlugin().getLog().log(status); + final IStatus istatus = status; + Display display = PlatformUI.getWorkbench().getDisplay(); + final Shell shell = display.getActiveShell(); + display.syncExec(new Runnable() { + public void run() { + ErrorDialog.openError(shell, "Error updating classpath", istatus.getMessage(), istatus); + } + }); + } + } /** * Utility to add a plugin's contribution to an accumulating classpath @@ -286,22 +310,17 @@ /** * A PreferenceChangeListener to notice when the compliance level of a project changes */ - private final class ComplianceChangeListener implements IPreferenceChangeListener + private final static class ComplianceChangeListener implements IPreferenceChangeListener { - /** The container path to use for reinitialization */ - private IPath containerPath; - /** The project whose changes are being listened for */ private IJavaProject project; /** * Make a new ComplianceChangeListener - * @param containerPath container path to use for reinitialization * @param project project whose changes are being listened for */ - ComplianceChangeListener(IPath containerPath, IJavaProject project) + ComplianceChangeListener(IJavaProject project) { - this.containerPath = containerPath; this.project = project; } @@ -312,23 +331,7 @@ { String key = event.getKey(); if (COMPLIANCE_KEY.equals(key)) { - try { - reInitialize(containerPath, project); - } catch (CoreException e) { - IStatus status = e.getStatus(); - if (status == null) { - status = new Status(Status.ERROR, EEditPlugin.ID, e.getMessage(), e); - } - ResourcesPlugin.getPlugin().getLog().log(status); - final IStatus istatus = status; - Display display = PlatformUI.getWorkbench().getDisplay(); - final Shell shell = display.getActiveShell(); - display.syncExec(new Runnable() { - public void run() { - ErrorDialog.openError(shell, "Error updating classpath", istatus.getMessage(), istatus); - } - }); - } + recomputeClasspath(project); } } } Added: trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/BasicLibraryProvider.java =================================================================== --- trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/BasicLibraryProvider.java (rev 0) +++ trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/BasicLibraryProvider.java 2008-11-21 11:56:10 UTC (rev 113) @@ -0,0 +1,52 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package com.ibm.realtime.flexotask.editor.model; + +/** + * A LibraryProvider that can be instantiated by the system from a known plugin id and description. + * Typically used to attach plugin projects that are library providers before such projects have ever + * been installed as plugins. + */ +final class BasicLibraryProvider extends AbstractLibraryProvider +{ + private String pluginID; + private String description; + + /** + * Create a BasicLibraryProvider + * @param pluginID the plugin ID + * @param description the description + */ + BasicLibraryProvider(String pluginID, String description) + { + this.pluginID = pluginID; + this.description = description; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.AbstractLibraryProvider#getPluginID() + */ + public String getPluginID() + { + return pluginID; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.LibraryProvider#getDescription() + */ + public String getDescription() + { + return description; + } +} Property changes on: trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/BasicLibraryProvider.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/GlobalTiming.java =================================================================== --- trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/GlobalTiming.java 2008-11-18 20:29:20 UTC (rev 112) +++ trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/GlobalTiming.java 2008-11-21 11:56:10 UTC (rev 113) @@ -14,7 +14,9 @@ package com.ibm.realtime.flexotask.editor.model; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; @@ -22,6 +24,10 @@ import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.Platform; import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.pde.core.plugin.IPluginBase; +import org.eclipse.pde.core.plugin.IPluginExtension; +import org.eclipse.pde.core.plugin.IPluginModelBase; +import org.eclipse.pde.core.plugin.PluginRegistry; import com.ibm.realtime.flexotask.timing.FlexotaskGlobalTimingData; import com.ibm.realtime.flexotask.timing.FlexotaskTimingDataParser; @@ -102,13 +108,18 @@ } /** - * Collect all the library providers in the system, including grammar providers + * Collect all the library providers in the system, including grammar providers and projects that propose to be library providers but + * are not yet installed * @return all library providers as an array */ public static LibraryProvider[] getAllProviders() { if (libraries == null) { + /* First get library providers that are installed as plugins. These can provide their own + * tailored LibraryProvider implementations + */ List<LibraryProvider> providers = new ArrayList<LibraryProvider>(); + Set<String> providingPlugins = new HashSet<String>(); IExtensionRegistry registry = Platform.getExtensionRegistry(); IExtensionPoint extensionPoint = registry.getExtensionPoint(LIBRARY_EXTENSION); if (extensionPoint != null) { @@ -119,14 +130,39 @@ try { lp = (LibraryProvider) point.createExecutableExtension("class"); providers.add(lp); + providingPlugins.add(point.getContributor().getName()); } catch (CoreException e) { } } } - TimingGrammarProvider[] timingProviders = getGrammars(); - for (int i = 0; i < timingProviders.length; i++) { - providers.add(timingProviders[i]); - } + /* Add the grammar providers. We assume these must be installed as plugins because there is no way they can do their job + * them if they don't provide tailored TimingGrammarProvider implementations + */ + getGrammars(providers, providingPlugins); + /* Now add open PDE projects that extend LIBRARY_EXTENSION or GRAMMAR_EXTENSION + * but don't overlap with any plugin so far identified. These get BasicLibraryProvider implementations + * based on their plugin id and description, which just adds the project to the classpath. Note that this + * degrades projects that intended to be grammar providers to be only library providers. This is the best + * we can do since grammar providers really have to be installed. + */ + IPluginModelBase[] models = PluginRegistry.getWorkspaceModels(); + for (int i = 0; i < models.length; i++) { + if (models[i].isEnabled()) { + IPluginBase base = models[i].getPluginBase(); + String id = base.getId(); + if (providingPlugins.contains(id)) { + continue; + } + IPluginExtension[] extensions = base.getExtensions(); + for (int j = 0; j < extensions.length; j++) { + String point = extensions[j].getPoint(); + if (LIBRARY_EXTENSION.equals(point) || GRAMMAR_EXTENSION.equals(point)) { + String desc = "Contents of project " + base.getModel().getUnderlyingResource().getProject().getName(); + providers.add(new BasicLibraryProvider(id, desc)); + } + } + } + } libraries = providers.toArray(new LibraryProvider[0]); } return libraries; @@ -136,30 +172,38 @@ * Get the set of grammars in the workspace, initializing from the extension registry the * first time around. */ - public static TimingGrammarProvider[] getGrammars() - { + public static TimingGrammarProvider[] getGrammars() { if (grammars == null) { - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint extensionPoint = registry.getExtensionPoint(GRAMMAR_EXTENSION); - if (extensionPoint == null) { - grammars = new TimingGrammarProvider[0]; - } else { - IConfigurationElement points[] = extensionPoint.getConfigurationElements(); - List<TimingGrammarProvider> grammarList = new ArrayList<TimingGrammarProvider>(); - for (int i = 0; i < points.length; i++) { - IConfigurationElement point = points[i]; - TimingGrammarProvider tgp; - try { - tgp = (TimingGrammarProvider) point.createExecutableExtension("class"); - grammarList.add(tgp); - } catch (CoreException e) { - } - } - grammars = (TimingGrammarProvider[]) grammarList.toArray(new TimingGrammarProvider[0]); - } + List<LibraryProvider> grammarList = new ArrayList<LibraryProvider>(); + getGrammars(grammarList, new HashSet<String>()); + grammars = grammarList.toArray(new TimingGrammarProvider[grammarList.size()]); } return grammars; } + + /** + * Get the set of grammars in the workspace from the extension registry and computing the set of + * contributing plugins + * @param grammarList the list to which instantiated grammar providers should be added + * @param contributers the Set to which contributing plugins should be added + */ + private static void getGrammars(List<LibraryProvider> grammarList, Set<String> contributers) { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint extensionPoint = registry.getExtensionPoint(GRAMMAR_EXTENSION); + if (extensionPoint != null) { + IConfigurationElement points[] = extensionPoint.getConfigurationElements(); + for (int i = 0; i < points.length; i++) { + IConfigurationElement point = points[i]; + TimingGrammarProvider tgp; + try { + tgp = (TimingGrammarProvider) point.createExecutableExtension("class"); + grammarList.add(tgp); + contributers.add(point.getContributor().getName()); + } catch (CoreException e) { + } + } + } + } /** * Get the FlexotaskTimingDataParsers of all the supported timing grammars @@ -174,4 +218,12 @@ } return ans; } + + /** + * Force recalculation of the set of library providers to include a possibly changed repertoire of + * projects. + */ + public static void resetProviders() { + libraries = null; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |