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 186431 Details for
Bug 333903
Need to update JS include path after module core nature installed
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]
Fix Patch
333903_class_path.txt (text/plain), 18.03 KB, created by
Ian Tewksbury
on 2011-01-10 16:23:53 EST
(
hide
)
Description:
Fix Patch
Filename:
MIME Type:
Creator:
Ian Tewksbury
Created:
2011-01-10 16:23:53 EST
Size:
18.03 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.wst.jsdt.web.core >Index: src/org/eclipse/wst/jsdt/web/core/internal/JSPCorePluginResources.properties >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/JSPCorePluginResources.properties,v >retrieving revision 1.5 >diff -u -r1.5 JSPCorePluginResources.properties >--- src/org/eclipse/wst/jsdt/web/core/internal/JSPCorePluginResources.properties 30 Apr 2008 19:06:22 -0000 1.5 >+++ src/org/eclipse/wst/jsdt/web/core/internal/JSPCorePluginResources.properties 10 Jan 2011 21:22:51 -0000 >@@ -22,3 +22,6 @@ > JSPDirectiveValidator_2=The prefix {0} is used more than once > JSPDirectiveValidator_3=A {0} value is required in this directive > JSPBatchValidator_0=Gathering files in {0} >+ >+JSWebResourceEventManager=JavaScript Web Resource Event Manager >+JsCorePlugin_Initializing_JS_Web_Tools=Initializing JavaScript Web Tools >Index: src/org/eclipse/wst/jsdt/web/core/internal/JSWebResourceEventManager.java >=================================================================== >RCS file: src/org/eclipse/wst/jsdt/web/core/internal/JSWebResourceEventManager.java >diff -N src/org/eclipse/wst/jsdt/web/core/internal/JSWebResourceEventManager.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/jsdt/web/core/internal/JSWebResourceEventManager.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,169 @@ >+/******************************************************************************* >+ * Copyright (c) 2011 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ * >+ *******************************************************************************/ >+package org.eclipse.wst.jsdt.web.core.internal; >+ >+import java.io.File; >+import java.util.ArrayList; >+import java.util.List; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.wst.common.componentcore.ModuleCoreNature; >+import org.eclipse.wst.jsdt.core.IIncludePathAttribute; >+import org.eclipse.wst.jsdt.core.IIncludePathEntry; >+import org.eclipse.wst.jsdt.core.JavaScriptCore; >+import org.eclipse.wst.jsdt.internal.core.JavaProject; >+import org.eclipse.wst.jsdt.web.core.internal.project.ModuleSourcePathProvider; >+import org.eclipse.wst.sse.core.indexing.AbstractIndexManager; >+ >+/** >+ * <p>This is an implementation of the {@link AbstractIndexManager} for the JavaScript Web core plugin.</p> >+ * >+ * <p>Current Uses: >+ * <ul> >+ * <li>listen for .project changes so that JavaScript class paths can be updated >+ * if the module core nature is added to a project</li> >+ * </ul></p> >+ * >+ * <p><b>NOTE:</b> If any other file resource change listening needs to take place in the future in this plugin >+ * it should be done here.</p> >+ */ >+public class JSWebResourceEventManager extends AbstractIndexManager { >+ /** the singleton instance of the {@link JSWebResourceEventManager} */ >+ private static JSWebResourceEventManager INSTANCE; >+ >+ /** the name of the ".project" file where natures are stored */ >+ private static final String DOT_PROJECT_FILE_NAME = ".project"; //$NON-NLS-1$ >+ >+ /** the location to store state */ >+ private IPath fWorkingLocation; >+ >+ /** >+ * <p>Private constructor for the resource event manager</p> >+ */ >+ private JSWebResourceEventManager() { >+ super(JsCoreMessages.JSWebResourceEventManager); >+ } >+ >+ /** >+ * @return the singleton instance of the {@link JSWebResourceEventManager} >+ */ >+ public static JSWebResourceEventManager getDefault() { >+ return INSTANCE != null ? INSTANCE : (INSTANCE = new JSWebResourceEventManager()); >+ } >+ >+ /** >+ * @see org.eclipse.wst.sse.core.indexing.AbstractIndexManager#isResourceToIndex(int, org.eclipse.core.runtime.IPath) >+ */ >+ protected boolean isResourceToIndex(int type, IPath path) { >+ String name = path.lastSegment(); >+ return >+ type == IResource.ROOT || >+ type == IResource.PROJECT || >+ (type == IResource.FILE && name.equals(DOT_PROJECT_FILE_NAME)); >+ } >+ >+ /** >+ * @see org.eclipse.wst.sse.core.indexing.AbstractIndexManager#performAction(byte, byte, org.eclipse.core.resources.IResource, org.eclipse.core.runtime.IPath) >+ */ >+ protected void performAction(byte source, byte action, IResource resource, >+ IPath movePath) { >+ >+ switch(action) { >+ case(AbstractIndexManager.ACTION_ADD): { >+ if(resource.getName().equals(DOT_PROJECT_FILE_NAME)) { >+ updateClassPathEntires(resource.getProject()); >+ } >+ break; >+ } >+ } >+ >+ } >+ >+ /** >+ * @see org.eclipse.wst.sse.core.indexing.AbstractIndexManager#getWorkingLocation() >+ */ >+ protected IPath getWorkingLocation() { >+ if(this.fWorkingLocation == null) { >+ //create path to working area >+ IPath workingLocation = >+ JsCorePlugin.getDefault().getStateLocation().append("JSWebResourceEventManager"); //$NON-NLS-1$ >+ >+ // ensure that it exists on disk >+ File folder = new File(workingLocation.toOSString()); >+ if (!folder.isDirectory()) { >+ try { >+ folder.mkdir(); >+ } >+ catch (SecurityException e) { >+ Logger.logException(this.getName() + >+ ": Error while creating state location: " + folder + //$NON-NLS-1$ >+ " This renders the index manager irrevocably broken for this workspace session", //$NON-NLS-1$ >+ e); >+ } >+ } >+ >+ this.fWorkingLocation = workingLocation; >+ } >+ >+ return this.fWorkingLocation; >+ } >+ >+ /** >+ * <p>Updates the JavaScript class path entries for the given project if >+ * both the Module core and JavaScript natures are installed on that project.</p> >+ * >+ * @param project {@link IProject} to update the JavaScript class path entires for >+ */ >+ private static void updateClassPathEntires(IProject project) { >+ try { >+ //if a JS project with Module core check if class path needs to be updated >+ if (project.hasNature(JavaScriptCore.NATURE_ID) && >+ ModuleCoreNature.isFlexibleProject(project)) { >+ >+ JavaProject jsProject = (JavaProject) JavaScriptCore.create(project); >+ >+ IIncludePathEntry[] oldEntries = jsProject.getRawIncludepath(); >+ List existingEntries = new ArrayList(); >+ boolean foundDefault = false; >+ >+ for(int e = 0; e < oldEntries.length; ++e) { >+ IIncludePathAttribute[] attrs = oldEntries[e].getExtraAttributes(); >+ >+ for(int a = 0; a < attrs.length; ++a) { >+ if(attrs[a].getName().equals(ModuleSourcePathProvider.PROVIDER_ATTRIBUTE_KEY_NAME) && >+ attrs[a].getValue().equals(ModuleSourcePathProvider.PROVIDER_ATTRIBUTE_KEY_VALUE)) { >+ foundDefault = true; >+ } else { >+ existingEntries.add(oldEntries[e]); >+ } >+ } >+ >+ } >+ >+ //if found that a default path was added, replace with module core determined path >+ if(foundDefault) { >+ IIncludePathEntry[] newEntries = new ModuleSourcePathProvider().getDefaultSourcePaths(project); >+ IIncludePathEntry[] combinedEntries = new IIncludePathEntry[existingEntries.size() + newEntries.length]; >+ System.arraycopy(newEntries, 0, combinedEntries, 0, newEntries.length); >+ System.arraycopy(existingEntries.toArray(), 0, combinedEntries, newEntries.length, existingEntries.size()); >+ >+ jsProject.setRawIncludepath(combinedEntries, project.getLocation(), null); >+ } >+ } >+ } catch(CoreException e) { >+ Logger.logException("Error while updating JavaScript classpath.", e); //$NON-NLS-1$ >+ } >+ } >+} >\ No newline at end of file >Index: src/org/eclipse/wst/jsdt/web/core/internal/JsCoreMessages.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/JsCoreMessages.java,v >retrieving revision 1.3 >diff -u -r1.3 JsCoreMessages.java >--- src/org/eclipse/wst/jsdt/web/core/internal/JsCoreMessages.java 30 Apr 2008 19:06:22 -0000 1.3 >+++ src/org/eclipse/wst/jsdt/web/core/internal/JsCoreMessages.java 10 Jan 2011 21:22:52 -0000 >@@ -33,6 +33,10 @@ > public static String JSPFContentPropertiesManager_Updating; > public static String JSPIndexManager_0; > public static String JSPIndexManager_2; >+ >+ public static String JSWebResourceEventManager; >+ public static String JsCorePlugin_Initializing_JS_Web_Tools; >+ > /** > * @deprecated > */ >Index: src/org/eclipse/wst/jsdt/web/core/internal/JsCorePlugin.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/JsCorePlugin.java,v >retrieving revision 1.5 >diff -u -r1.5 JsCorePlugin.java >--- src/org/eclipse/wst/jsdt/web/core/internal/JsCorePlugin.java 30 Apr 2008 19:06:22 -0000 1.5 >+++ src/org/eclipse/wst/jsdt/web/core/internal/JsCorePlugin.java 10 Jan 2011 21:22:52 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2004, 2008 IBM Corporation and others. >+ * Copyright (c) 2004, 2011 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 >@@ -10,7 +10,20 @@ > *******************************************************************************/ > package org.eclipse.wst.jsdt.web.core.internal; > >+import org.eclipse.core.resources.IResourceChangeEvent; >+import org.eclipse.core.resources.IResourceChangeListener; >+import org.eclipse.core.resources.ISaveContext; >+import org.eclipse.core.resources.ISaveParticipant; >+import org.eclipse.core.resources.ISavedState; >+import org.eclipse.core.resources.IWorkspace; >+import org.eclipse.core.resources.IWorkspaceRunnable; >+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.Plugin; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.core.runtime.jobs.Job; > import org.eclipse.wst.jsdt.web.core.javascript.search.JsIndexManager; > import org.osgi.framework.BundleContext; > >@@ -27,12 +40,14 @@ > public static final String PLUGIN_ID = "org.eclipse.wst.jsdt.web.core"; //$NON-NLS-1$ > > /** >+ * <p>Job used to finish tasks needed to start up the plugin but that did not have >+ * to block the plugin start up process.</p> >+ */ >+ private Job fPluginInitializerJob; >+ >+ /** > * Returns the shared instance. >- * >- * @deprecated - will be removed. Currently used to get "model preferences", >- * but there are other, better ways. > */ >- > public static JsCorePlugin getDefault() { > return JsCorePlugin.plugin; > } >@@ -43,6 +58,7 @@ > public JsCorePlugin() { > super(); > JsCorePlugin.plugin = this; >+ this.fPluginInitializerJob = new PluginInitializerJob(); > } > > /* >@@ -58,6 +74,10 @@ > // listen for classpath changes > JsIndexManager.getInstance().initialize(); > // listen for resource changes to update content properties keys >+ >+ //schedule delayed initialization >+ this.fPluginInitializerJob.schedule(2000); >+ > } > > /* >@@ -71,6 +91,123 @@ > // keys > // stop any indexing > JsIndexManager.getInstance().shutdown(); >+ >+ //Stop the resource event manager >+ JSWebResourceEventManager.getDefault().stop(); >+ > super.stop(context); > } >+ >+ /** >+ * <p>A {@link Job} used to perform delayed initialization for the plugin</p> >+ */ >+ private static class PluginInitializerJob extends Job { >+ /** >+ * <p>Default constructor to set up this {@link Job} as a >+ * long running system {@link Job}</p> >+ */ >+ protected PluginInitializerJob() { >+ super(JsCoreMessages.JsCorePlugin_Initializing_JS_Web_Tools); >+ >+ this.setUser(false); >+ this.setSystem(true); >+ this.setPriority(Job.LONG); >+ } >+ >+ /** >+ * <p>Perform delayed initialization for the plugin</p> >+ * >+ * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ protected IStatus run(IProgressMonitor monitor) { >+ IStatus status = Status.OK_STATUS; >+ final IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ try { >+ /* >+ * Restore save state and process any events that happened before >+ * plug-in loaded. Don't do it immediately since adding the save >+ * participant requires a lock on the workspace to compute the >+ * accumulated deltas, and if the tree is not already locked it >+ * becomes a blocking call. >+ */ >+ workspace.run(new IWorkspaceRunnable() { >+ public void run(final IProgressMonitor worspaceMonitor) throws CoreException { >+ ISavedState savedState = null; >+ >+ try { >+ //add the save participant for this bundle >+ savedState = ResourcesPlugin.getWorkspace().addSaveParticipant( >+ JsCorePlugin.plugin.getBundle().getSymbolicName(), new SaveParticipant()); >+ } catch (CoreException e) { >+ Logger.logException("JSP Core Plugin failed at loading previously saved state." + //$NON-NLS-1$ >+ " All componenets dependent on this state will start as if first workspace load.", e); //$NON-NLS-1$ >+ } >+ >+ //if there is a saved state start up using that, else start up cold >+ if(savedState != null) { >+ try { >+ Thread.currentThread().setPriority(Thread.MIN_PRIORITY); >+ } finally { >+ savedState.processResourceChangeEvents(new IResourceChangeListener() { >+ /** >+ * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent) >+ */ >+ public void resourceChanged(IResourceChangeEvent event) { >+ JSWebResourceEventManager.getDefault().start(event.getDelta(), worspaceMonitor); >+ } >+ }); >+ } >+ } else { >+ JSWebResourceEventManager.getDefault().start(null, worspaceMonitor); >+ } >+ } >+ }, monitor); >+ } catch(CoreException e) { >+ status = e.getStatus(); >+ } >+ >+ return status; >+ } >+ >+ } >+ >+ /** >+ * Used so that all of the IResourceChangeEvents that occurred before >+ * this plugin loaded can be processed. >+ */ >+ private static class SaveParticipant implements ISaveParticipant { >+ /** >+ * <p>Default constructor</p> >+ */ >+ protected SaveParticipant() { >+ } >+ >+ /** >+ * @see org.eclipse.core.resources.ISaveParticipant#doneSaving(org.eclipse.core.resources.ISaveContext) >+ */ >+ public void doneSaving(ISaveContext context) { >+ //ignore >+ } >+ >+ /** >+ * @see org.eclipse.core.resources.ISaveParticipant#prepareToSave(org.eclipse.core.resources.ISaveContext) >+ */ >+ public void prepareToSave(ISaveContext context) throws CoreException { >+ //ignore >+ } >+ >+ /** >+ * @see org.eclipse.core.resources.ISaveParticipant#rollback(org.eclipse.core.resources.ISaveContext) >+ */ >+ public void rollback(ISaveContext context) { >+ //ignore >+ } >+ >+ /** >+ * @see org.eclipse.core.resources.ISaveParticipant#saving(org.eclipse.core.resources.ISaveContext) >+ */ >+ public void saving(ISaveContext context) throws CoreException { >+ context.needDelta(); >+ } >+ } > } >Index: src/org/eclipse/wst/jsdt/web/core/internal/project/ModuleSourcePathProvider.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.jsdt.web.core/src/org/eclipse/wst/jsdt/web/core/internal/project/ModuleSourcePathProvider.java,v >retrieving revision 1.2 >diff -u -r1.2 ModuleSourcePathProvider.java >--- src/org/eclipse/wst/jsdt/web/core/internal/project/ModuleSourcePathProvider.java 28 Sep 2010 01:57:54 -0000 1.2 >+++ src/org/eclipse/wst/jsdt/web/core/internal/project/ModuleSourcePathProvider.java 10 Jan 2011 21:22:52 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2010 IBM Corporation and others. >+ * Copyright (c) 2010, 2011 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 >@@ -21,13 +21,17 @@ > import org.eclipse.wst.jsdt.core.IIncludePathAttribute; > import org.eclipse.wst.jsdt.core.IIncludePathEntry; > import org.eclipse.wst.jsdt.core.JavaScriptCore; >+import org.eclipse.wst.jsdt.internal.core.ClasspathEntry; > import org.eclipse.wst.jsdt.internal.core.util.DefaultSourcePathProvider; > > public class ModuleSourcePathProvider extends DefaultSourcePathProvider { > >+ public static final String PROVIDER_ATTRIBUTE_KEY_NAME = "provider"; //$NON-NLS-1$ >+ public static final String PROVIDER_ATTRIBUTE_KEY_VALUE = ModuleSourcePathProvider.class.getName(); //$NON-NLS-1$ >+ > static final IPath VIRTUAL_CONTAINER_PATH = new Path("org.eclipse.wst.jsdt.launching.WebProject"); //$NON-NLS-1$ > static final IIncludePathEntry VIRTUAL_SCOPE_ENTRY = JavaScriptCore.newContainerEntry(VIRTUAL_CONTAINER_PATH, new IAccessRule[0], new IIncludePathAttribute[]{IIncludePathAttribute.HIDE}, false); >- >+ > public ModuleSourcePathProvider() { > } > >@@ -53,6 +57,9 @@ > } > } > } >- return super.getDefaultSourcePaths(p); >+ >+ return new IIncludePathEntry[]{JavaScriptCore.newSourceEntry(p.getFullPath(), >+ ClasspathEntry.INCLUDE_ALL,ClasspathEntry.EXCLUDE_NONE,null, >+ new IIncludePathAttribute[]{JavaScriptCore.newIncludepathAttribute(PROVIDER_ATTRIBUTE_KEY_NAME, PROVIDER_ATTRIBUTE_KEY_VALUE)})}; > } > }
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 333903
:
186431
|
187232