From df11a294b8a2e86abfd4ae3e3fbde8a381c5fd3d Mon Sep 17 00:00:00 2001 From: John Camelon Date: Wed, 13 Aug 2003 17:45:38 +0000 Subject: Patch for Sean Evoy In order to work through CExtensionPoint mechanism, I have to change the existing extension point entries for the Managed and Standard builders to the following (all future builders will have to conform to this as well): As well, the ManagedBuildManager and StandardBuildManager must extend AbstractCExtension. The new project wizards for managed and standard projects have to be modified to register the right class as the scanner info providers for the project. The example below shows the managed project wizard code, but the standard project wizard is similar. try { ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(project); desc.remove(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID); desc.create(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID, ManagedBuildManager.INTERFACE_IDENTITY); } Clients use a new method defined in CCorePlugin public IScannerInfoProvider getScannerInfoProvider(IProject project) { IScannerInfoProvider provider = null; if (project != null) { try { ICDescriptor desc = (ICDescriptor) getCProjectDescription(project); ICExtensionReference[] extensions = desc.get(BUILD_SCANNER_INFO_UNIQ_ID); if (extensions.length > 0) provider = (IScannerInfoProvider) extensions[0].createExtension(); } catch (CoreException e) { } } return provider; } to get the information provider as shown in the updated JUnit test code below: // Find the first IScannerInfoProvider that supplies build info for the project IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project); assertNotNull(provider); As is the case now, clients implement the IScannerInfoChangeListener interface and pass themselves to the provider in a subscription message. There is also a new method on the IScannerInfoProvider interface that allows the client to get information immediately as shown below: IScannerInfo currentSettings = provider.getScannerInformation(project); The ManagedBuildManager::getScannerInfo(IResource) method will be deprecated, then removed before the end of this release cycle. --- .../core/build/managed/ManagedBuildManager.java | 58 ++++++---------------- .../core/build/standard/StandardBuildManager.java | 44 +++++++--------- 2 files changed, 32 insertions(+), 70 deletions(-) (limited to 'core/org.eclipse.cdt.core/build') diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java index 727b30681ca..89f72cddd68 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/managed/ManagedBuildManager.java @@ -28,6 +28,7 @@ import org.apache.xml.serialize.Method; import org.apache.xml.serialize.OutputFormat; import org.apache.xml.serialize.Serializer; import org.apache.xml.serialize.SerializerFactory; +import org.eclipse.cdt.core.AbstractCExtension; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.parser.*; import org.eclipse.cdt.internal.core.build.managed.ManagedBuildInfo; @@ -48,13 +49,13 @@ import org.w3c.dom.Node; * This is the main entry point for getting at the build information * for the managed build system. */ -public class ManagedBuildManager implements IScannerInfoProvider { +public class ManagedBuildManager extends AbstractCExtension implements IScannerInfoProvider { - private static final QualifiedName buildInfoProperty - = new QualifiedName(CCorePlugin.PLUGIN_ID, "managedBuildInfo"); + private static final QualifiedName buildInfoProperty = new QualifiedName(CCorePlugin.PLUGIN_ID, "managedBuildInfo"); private static final String ROOT_ELEM_NAME = "ManagedProjectBuildInfo"; private static final String FILE_NAME = ".cdtbuild"; private static final ITarget[] emptyTargets = new ITarget[0]; + public static final String INTERFACE_IDENTITY = CCorePlugin.PLUGIN_ID + "." + "ManagedBuildManager"; // Targets defined by extensions (i.e., not associated with a resource) private static boolean extensionTargetsLoaded = false; @@ -450,10 +451,9 @@ public class ManagedBuildManager implements IScannerInfoProvider { * Answers with an interface to the parse information that has been * associated with the resource specified in the argument. * - * NOTE: This method is not part of the registration interface. It has - * been made public as a short-term workaround for the clients of the - * scanner information until the redesign of the build information management - * occurs. + * @deprecated This method is not part of the registration interface. + * Clients of build information should now use getScannerInformation(IResource) + * for one-time information requests. * * @param resource * @return @@ -462,6 +462,13 @@ public class ManagedBuildManager implements IScannerInfoProvider { return (IScannerInfo) getBuildInfo(resource, false); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.IScannerInfoProvider#getScannerInformation(org.eclipse.core.resources.IResource) + */ + public IScannerInfo getScannerInformation(IResource resource) { + return (IScannerInfo) getBuildInfo(resource, false); + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.IScannerInfoProvider#subscribe(org.eclipse.cdt.core.parser.IScannerInfoChangeListener) */ @@ -488,41 +495,6 @@ public class ManagedBuildManager implements IScannerInfoProvider { } } - // TODO Remove all of the IScannerInfoProvider interface methods when - // the discovery mechanism is solidified - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IScannerInfoProvider#managesResource(org.eclipse.core.resources.IResource) - */ - public boolean managesResource(IResource resource) { - // The managed build manager manages build information for the - // resource IFF it it is a project and has a build file with the proper - // root element - IProject project = null; - if (resource instanceof IProject){ - project = (IProject)resource; - } else if (resource instanceof IFile) { - project = ((IFile)resource).getProject(); - } else { - return false; - } - IFile file = project.getFile(FILE_NAME); - if (file.exists()) { - try { - InputStream stream = file.getContents(); - DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document document = parser.parse(stream); - Node rootElement = document.getFirstChild(); - if (rootElement.getNodeName().equals(ROOT_ELEM_NAME)) { - return true; - } - } catch (Exception e) { - return false; - } - } - return false; - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.IScannerInfoProvider#unsubscribe(org.eclipse.cdt.core.parser.IScannerInfoChangeListener) */ @@ -544,6 +516,4 @@ public class ManagedBuildManager implements IScannerInfoProvider { map.put(project, list); } } - - } diff --git a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/standard/StandardBuildManager.java b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/standard/StandardBuildManager.java index 0c8f1d4745e..dbe6f336387 100644 --- a/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/standard/StandardBuildManager.java +++ b/core/org.eclipse.cdt.core/build/org/eclipse/cdt/core/build/standard/StandardBuildManager.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.ListIterator; import java.util.Map; +import org.eclipse.cdt.core.AbstractCExtension; import org.eclipse.cdt.core.BuildInfoFactory; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ICDescriptor; @@ -21,7 +22,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.QualifiedName; import org.w3c.dom.Element; import org.w3c.dom.Node; -import org.w3c.dom.NodeList; /********************************************************************** * Copyright (c) 2002,2003 Rational Software Corporation and others. @@ -34,11 +34,13 @@ import org.w3c.dom.NodeList; * IBM Rational Software - Initial API and implementation ***********************************************************************/ -public class StandardBuildManager implements IScannerInfoProvider { +public class StandardBuildManager extends AbstractCExtension implements IScannerInfoProvider { // Name we will use to store build property with the project private static final QualifiedName buildInfoProperty = new QualifiedName(CCorePlugin.PLUGIN_ID, "standardBuildInfo"); private static final String ID = CCorePlugin.PLUGIN_ID + ".standardBuildInfo"; + // This is the id of the IScannerInfoProvider extension point entry + public static final String INTERFACE_IDENTITY = CCorePlugin.PLUGIN_ID + "." + "StandardBuildManager"; // Listeners interested in build model changes private static Map buildModelListeners; @@ -91,30 +93,6 @@ public class StandardBuildManager implements IScannerInfoProvider { return buildModelListeners; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IScannerInfoProvider#managesResource(org.eclipse.core.resources.IResource) - */ - public boolean managesResource(IResource resource) throws CoreException { - /* - * Answers true if this project has a build info associated with it - */ - - IProject project = null; - if (resource instanceof IProject) { - project = (IProject)resource; - } else if (resource instanceof IFile) { - project = ((IFile)resource).getProject(); - } else { - return false; - } - - // Look for (but do not create) the build information - IStandardBuildInfo info = getBuildInfo(project); - - // If there's info, I manage the resource - return info == null ? false : true; - } - public static void setPreprocessorSymbols(IProject project, String[] symbols) throws CoreException { @@ -162,6 +140,19 @@ public class StandardBuildManager implements IScannerInfoProvider { } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.IScannerInfoProvider#getScannerInformation(org.eclipse.core.resources.IResource) + */ + public IScannerInfo getScannerInformation(IResource resource) { + IStandardBuildInfo info; + try { + info = getBuildInfo((IProject)resource); + } catch (CoreException e) { + return null; + } + return (IScannerInfo)info; + } + /* * Loads the build file and parses the nodes for build information. The * information is then associated with the resource for the duration of @@ -266,4 +257,5 @@ public class StandardBuildManager implements IScannerInfoProvider { map.put(project, list); } } + } -- cgit v1.2.3