Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 333903 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/wst/jsdt/web/core/internal/JSPCorePluginResources.properties (+3 lines)
Lines 22-24 Link Here
22
JSPDirectiveValidator_2=The prefix {0} is used more than once
22
JSPDirectiveValidator_2=The prefix {0} is used more than once
23
JSPDirectiveValidator_3=A {0} value is required in this directive
23
JSPDirectiveValidator_3=A {0} value is required in this directive
24
JSPBatchValidator_0=Gathering files in {0}
24
JSPBatchValidator_0=Gathering files in {0}
25
26
JSWebResourceEventManager=JavaScript Web Resource Event Manager
27
JsCorePlugin_Initializing_JS_Web_Tools=Initializing JavaScript Web Tools
(-)src/org/eclipse/wst/jsdt/web/core/internal/JSWebResourceEventManager.java (+169 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     
11
 *******************************************************************************/
12
package org.eclipse.wst.jsdt.web.core.internal;
13
14
import java.io.File;
15
import java.util.ArrayList;
16
import java.util.List;
17
18
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.wst.common.componentcore.ModuleCoreNature;
23
import org.eclipse.wst.jsdt.core.IIncludePathAttribute;
24
import org.eclipse.wst.jsdt.core.IIncludePathEntry;
25
import org.eclipse.wst.jsdt.core.JavaScriptCore;
26
import org.eclipse.wst.jsdt.internal.core.JavaProject;
27
import org.eclipse.wst.jsdt.web.core.internal.project.ModuleSourcePathProvider;
28
import org.eclipse.wst.sse.core.indexing.AbstractIndexManager;
29
30
/**
31
 * <p>This is an implementation of the {@link AbstractIndexManager} for the JavaScript Web core plugin.</p>
32
 * 
33
 * <p>Current Uses:
34
 * <ul>
35
 * <li>listen for .project changes so that JavaScript class paths can be updated
36
 * if the module core nature is added to a project</li>
37
 * </ul></p>
38
 * 
39
 * <p><b>NOTE:</b> If any other file resource change listening needs to take place in the future in this plugin
40
 * it should be done here.</p>
41
 */
42
public class JSWebResourceEventManager extends AbstractIndexManager {
43
	/** the singleton instance of the {@link JSWebResourceEventManager} */
44
	private static JSWebResourceEventManager INSTANCE;
45
	
46
	/** the name of the ".project" file where natures are stored */
47
	private static final String DOT_PROJECT_FILE_NAME = ".project"; //$NON-NLS-1$
48
	
49
	/** the location to store state */
50
	private IPath fWorkingLocation;
51
	
52
	/**
53
	 * <p>Private constructor for the resource event manager</p>
54
	 */
55
	private JSWebResourceEventManager() {
56
		super(JsCoreMessages.JSWebResourceEventManager);
57
	}
58
	
59
	/**
60
	 * @return the singleton instance of the {@link JSWebResourceEventManager}
61
	 */
62
	public static JSWebResourceEventManager getDefault() {
63
		return INSTANCE != null ? INSTANCE : (INSTANCE = new JSWebResourceEventManager());
64
	}
65
66
	/**
67
	 * @see org.eclipse.wst.sse.core.indexing.AbstractIndexManager#isResourceToIndex(int, org.eclipse.core.runtime.IPath)
68
	 */
69
	protected boolean isResourceToIndex(int type, IPath path) {
70
		String name = path.lastSegment();
71
		return 
72
			type == IResource.ROOT ||
73
			type == IResource.PROJECT || 
74
			(type == IResource.FILE && name.equals(DOT_PROJECT_FILE_NAME));
75
	}
76
77
	/**
78
	 * @see org.eclipse.wst.sse.core.indexing.AbstractIndexManager#performAction(byte, byte, org.eclipse.core.resources.IResource, org.eclipse.core.runtime.IPath)
79
	 */
80
	protected void performAction(byte source, byte action, IResource resource,
81
			IPath movePath) {
82
		
83
		switch(action) {
84
			case(AbstractIndexManager.ACTION_ADD): {
85
				if(resource.getName().equals(DOT_PROJECT_FILE_NAME)) {
86
					updateClassPathEntires(resource.getProject());
87
				}
88
				break;
89
			}
90
		}
91
92
	}
93
94
	/**
95
	 * @see org.eclipse.wst.sse.core.indexing.AbstractIndexManager#getWorkingLocation()
96
	 */
97
	protected IPath getWorkingLocation() {
98
		if(this.fWorkingLocation == null) {
99
			//create path to working area
100
    		IPath workingLocation =
101
    			JsCorePlugin.getDefault().getStateLocation().append("JSWebResourceEventManager"); //$NON-NLS-1$
102
103
            // ensure that it exists on disk
104
            File folder = new File(workingLocation.toOSString());
105
    		if (!folder.isDirectory()) {
106
    			try {
107
    				folder.mkdir();
108
    			}
109
    			catch (SecurityException e) {
110
    				Logger.logException(this.getName() +
111
    						": Error while creating state location: " + folder + //$NON-NLS-1$
112
    						" This renders the index manager irrevocably broken for this workspace session", //$NON-NLS-1$
113
    						e);
114
    			}
115
    		}
116
    		
117
    		this.fWorkingLocation = workingLocation;
118
    	}
119
    	
120
        return this.fWorkingLocation;
121
	}
122
	
123
	/**
124
	 * <p>Updates the JavaScript class path entries for the given project if
125
	 * both the Module core and JavaScript natures are installed on that project.</p>
126
	 *
127
	 * @param project {@link IProject} to update the JavaScript class path entires for
128
	 */
129
	private static void updateClassPathEntires(IProject project) {
130
		try {
131
			//if a JS project with Module core check if class path needs to be updated
132
			if (project.hasNature(JavaScriptCore.NATURE_ID) &&
133
					ModuleCoreNature.isFlexibleProject(project)) {
134
				
135
				JavaProject jsProject = (JavaProject) JavaScriptCore.create(project);
136
				
137
				IIncludePathEntry[] oldEntries = jsProject.getRawIncludepath();
138
				List existingEntries = new ArrayList();
139
				boolean foundDefault = false;
140
				
141
				for(int e = 0; e < oldEntries.length; ++e) {
142
					IIncludePathAttribute[] attrs = oldEntries[e].getExtraAttributes();
143
					
144
					for(int a = 0; a < attrs.length; ++a) {
145
						if(attrs[a].getName().equals(ModuleSourcePathProvider.PROVIDER_ATTRIBUTE_KEY_NAME) && 
146
								attrs[a].getValue().equals(ModuleSourcePathProvider.PROVIDER_ATTRIBUTE_KEY_VALUE)) {
147
							foundDefault = true;
148
						} else {
149
							existingEntries.add(oldEntries[e]);
150
						}
151
					}
152
					
153
				}
154
				
155
				//if found that a default path was added, replace with module core determined path
156
				if(foundDefault) {
157
					IIncludePathEntry[] newEntries = new ModuleSourcePathProvider().getDefaultSourcePaths(project);
158
					IIncludePathEntry[] combinedEntries = new IIncludePathEntry[existingEntries.size() + newEntries.length];
159
					System.arraycopy(newEntries, 0, combinedEntries, 0, newEntries.length);
160
					System.arraycopy(existingEntries.toArray(), 0, combinedEntries, newEntries.length, existingEntries.size());
161
					
162
					jsProject.setRawIncludepath(combinedEntries, project.getLocation(), null);
163
				}
164
			}
165
		} catch(CoreException e) {
166
			Logger.logException("Error while updating JavaScript classpath.", e); //$NON-NLS-1$
167
		}
168
	}
169
}
(-)src/org/eclipse/wst/jsdt/web/core/internal/JsCoreMessages.java (+4 lines)
Lines 33-38 Link Here
33
	public static String JSPFContentPropertiesManager_Updating;
33
	public static String JSPFContentPropertiesManager_Updating;
34
	public static String JSPIndexManager_0;
34
	public static String JSPIndexManager_0;
35
	public static String JSPIndexManager_2;
35
	public static String JSPIndexManager_2;
36
	
37
	public static String JSWebResourceEventManager;
38
	public static String JsCorePlugin_Initializing_JS_Web_Tools;
39
	
36
	/**
40
	/**
37
	 * @deprecated
41
	 * @deprecated
38
	 */
42
	 */
(-)src/org/eclipse/wst/jsdt/web/core/internal/JsCorePlugin.java (-5 / +142 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2008 IBM Corporation and others.
2
 * Copyright (c) 2004, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.wst.jsdt.web.core.internal;
11
package org.eclipse.wst.jsdt.web.core.internal;
12
12
13
import org.eclipse.core.resources.IResourceChangeEvent;
14
import org.eclipse.core.resources.IResourceChangeListener;
15
import org.eclipse.core.resources.ISaveContext;
16
import org.eclipse.core.resources.ISaveParticipant;
17
import org.eclipse.core.resources.ISavedState;
18
import org.eclipse.core.resources.IWorkspace;
19
import org.eclipse.core.resources.IWorkspaceRunnable;
20
import org.eclipse.core.resources.ResourcesPlugin;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.IStatus;
13
import org.eclipse.core.runtime.Plugin;
24
import org.eclipse.core.runtime.Plugin;
25
import org.eclipse.core.runtime.Status;
26
import org.eclipse.core.runtime.jobs.Job;
14
import org.eclipse.wst.jsdt.web.core.javascript.search.JsIndexManager;
27
import org.eclipse.wst.jsdt.web.core.javascript.search.JsIndexManager;
15
import org.osgi.framework.BundleContext;
28
import org.osgi.framework.BundleContext;
16
29
Lines 27-38 Link Here
27
	public static final String PLUGIN_ID = "org.eclipse.wst.jsdt.web.core"; //$NON-NLS-1$
40
	public static final String PLUGIN_ID = "org.eclipse.wst.jsdt.web.core"; //$NON-NLS-1$
28
	
41
	
29
	/**
42
	/**
43
	 * <p>Job used to finish tasks needed to start up the plugin but that did not have
44
	 * to block the plugin start up process.</p>
45
	 */
46
	private Job fPluginInitializerJob;
47
	
48
	/**
30
	 * Returns the shared instance.
49
	 * Returns the shared instance.
31
	 * 
32
	 * @deprecated - will be removed. Currently used to get "model preferences",
33
	 *             but there are other, better ways.
34
	 */
50
	 */
35
36
	public static JsCorePlugin getDefault() {
51
	public static JsCorePlugin getDefault() {
37
		return JsCorePlugin.plugin;
52
		return JsCorePlugin.plugin;
38
	}
53
	}
Lines 43-48 Link Here
43
	public JsCorePlugin() {
58
	public JsCorePlugin() {
44
		super();
59
		super();
45
		JsCorePlugin.plugin = this;
60
		JsCorePlugin.plugin = this;
61
		this.fPluginInitializerJob = new PluginInitializerJob();
46
	}
62
	}
47
	
63
	
48
	/*
64
	/*
Lines 58-63 Link Here
58
		// listen for classpath changes
74
		// listen for classpath changes
59
		JsIndexManager.getInstance().initialize();
75
		JsIndexManager.getInstance().initialize();
60
		// listen for resource changes to update content properties keys
76
		// listen for resource changes to update content properties keys
77
		
78
		//schedule delayed initialization
79
		this.fPluginInitializerJob.schedule(2000);
80
61
	}
81
	}
62
	
82
	
63
	/*
83
	/*
Lines 71-76 Link Here
71
		// keys
91
		// keys
72
		// stop any indexing
92
		// stop any indexing
73
		JsIndexManager.getInstance().shutdown();
93
		JsIndexManager.getInstance().shutdown();
94
		
95
		//Stop the resource event manager
96
		JSWebResourceEventManager.getDefault().stop();
97
		
74
		super.stop(context);
98
		super.stop(context);
75
	}
99
	}
100
	
101
	/**
102
	 * <p>A {@link Job} used to perform delayed initialization for the plugin</p>
103
	 */
104
	private static class PluginInitializerJob extends Job {
105
		/**
106
		 * <p>Default constructor to set up this {@link Job} as a
107
		 * long running system {@link Job}</p>
108
		 */
109
		protected PluginInitializerJob() {
110
			super(JsCoreMessages.JsCorePlugin_Initializing_JS_Web_Tools);
111
			
112
			this.setUser(false);
113
			this.setSystem(true);
114
			this.setPriority(Job.LONG);
115
		}
116
		
117
		/**
118
		 * <p>Perform delayed initialization for the plugin</p>
119
		 * 
120
		 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
121
		 */
122
		protected IStatus run(IProgressMonitor monitor) {
123
			IStatus status = Status.OK_STATUS;
124
			final IWorkspace workspace = ResourcesPlugin.getWorkspace();
125
			try {
126
				/*
127
				 * Restore save state and process any events that happened before
128
				 * plug-in loaded. Don't do it immediately since adding the save
129
				 * participant requires a lock on the workspace to compute the
130
				 * accumulated deltas, and if the tree is not already locked it
131
				 * becomes a blocking call.
132
				 */
133
				workspace.run(new IWorkspaceRunnable() {
134
					public void run(final IProgressMonitor worspaceMonitor) throws CoreException {
135
						ISavedState savedState = null;
136
						
137
						try {
138
							//add the save participant for this bundle
139
							savedState = ResourcesPlugin.getWorkspace().addSaveParticipant(
140
									JsCorePlugin.plugin.getBundle().getSymbolicName(), new SaveParticipant());
141
						} catch (CoreException e) {
142
							Logger.logException("JSP Core Plugin failed at loading previously saved state." + //$NON-NLS-1$
143
									" All componenets dependent on this state will start as if first workspace load.", e); //$NON-NLS-1$
144
						}
145
						
146
						//if there is a saved state start up using that, else start up cold
147
						if(savedState != null) {
148
							try {
149
								Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
150
							} finally {
151
								savedState.processResourceChangeEvents(new IResourceChangeListener() {
152
									/**
153
									 * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
154
									 */
155
									public void resourceChanged(IResourceChangeEvent event) {
156
										JSWebResourceEventManager.getDefault().start(event.getDelta(), worspaceMonitor);
157
									}
158
								});
159
							}
160
						} else {
161
							JSWebResourceEventManager.getDefault().start(null, worspaceMonitor);
162
						}
163
					}
164
				}, monitor);
165
			} catch(CoreException e) {
166
				status = e.getStatus();
167
			}
168
			
169
			return status;
170
		}
171
		
172
	}
173
	
174
	/**
175
	 * Used so that all of the IResourceChangeEvents that occurred before
176
	 * this plugin loaded can be processed.
177
	 */
178
	private static class SaveParticipant implements ISaveParticipant {
179
		/**
180
		 * <p>Default constructor</p>
181
		 */
182
		protected SaveParticipant() {
183
		}
184
		
185
		/**
186
		 * @see org.eclipse.core.resources.ISaveParticipant#doneSaving(org.eclipse.core.resources.ISaveContext)
187
		 */
188
		public void doneSaving(ISaveContext context) {
189
			//ignore
190
		}
191
	
192
		/**
193
		 * @see org.eclipse.core.resources.ISaveParticipant#prepareToSave(org.eclipse.core.resources.ISaveContext)
194
		 */
195
		public void prepareToSave(ISaveContext context) throws CoreException {
196
			//ignore
197
		}
198
	
199
		/**
200
		 * @see org.eclipse.core.resources.ISaveParticipant#rollback(org.eclipse.core.resources.ISaveContext)
201
		 */
202
		public void rollback(ISaveContext context) {
203
			//ignore
204
		}
205
	
206
		/**
207
		 * @see org.eclipse.core.resources.ISaveParticipant#saving(org.eclipse.core.resources.ISaveContext)
208
		 */
209
		public void saving(ISaveContext context) throws CoreException {
210
			context.needDelta();
211
		}
212
	}
76
}
213
}
(-)src/org/eclipse/wst/jsdt/web/core/internal/project/ModuleSourcePathProvider.java (-3 / +10 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
2
 * Copyright (c) 2010, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 21-33 Link Here
21
import org.eclipse.wst.jsdt.core.IIncludePathAttribute;
21
import org.eclipse.wst.jsdt.core.IIncludePathAttribute;
22
import org.eclipse.wst.jsdt.core.IIncludePathEntry;
22
import org.eclipse.wst.jsdt.core.IIncludePathEntry;
23
import org.eclipse.wst.jsdt.core.JavaScriptCore;
23
import org.eclipse.wst.jsdt.core.JavaScriptCore;
24
import org.eclipse.wst.jsdt.internal.core.ClasspathEntry;
24
import org.eclipse.wst.jsdt.internal.core.util.DefaultSourcePathProvider;
25
import org.eclipse.wst.jsdt.internal.core.util.DefaultSourcePathProvider;
25
26
26
public class ModuleSourcePathProvider extends DefaultSourcePathProvider {
27
public class ModuleSourcePathProvider extends DefaultSourcePathProvider {
27
28
29
	public static final String PROVIDER_ATTRIBUTE_KEY_NAME = "provider"; //$NON-NLS-1$
30
	public static final String PROVIDER_ATTRIBUTE_KEY_VALUE = ModuleSourcePathProvider.class.getName(); //$NON-NLS-1$
31
	
28
	static final IPath VIRTUAL_CONTAINER_PATH = new Path("org.eclipse.wst.jsdt.launching.WebProject"); //$NON-NLS-1$
32
	static final IPath VIRTUAL_CONTAINER_PATH = new Path("org.eclipse.wst.jsdt.launching.WebProject"); //$NON-NLS-1$
29
	static final IIncludePathEntry VIRTUAL_SCOPE_ENTRY = JavaScriptCore.newContainerEntry(VIRTUAL_CONTAINER_PATH, new IAccessRule[0], new IIncludePathAttribute[]{IIncludePathAttribute.HIDE}, false);
33
	static final IIncludePathEntry VIRTUAL_SCOPE_ENTRY = JavaScriptCore.newContainerEntry(VIRTUAL_CONTAINER_PATH, new IAccessRule[0], new IIncludePathAttribute[]{IIncludePathAttribute.HIDE}, false);
30
34
	
31
	public ModuleSourcePathProvider() {
35
	public ModuleSourcePathProvider() {
32
	}
36
	}
33
37
Lines 53-58 Link Here
53
				}
57
				}
54
			}
58
			}
55
		}
59
		}
56
		return super.getDefaultSourcePaths(p);
60
		
61
		return new IIncludePathEntry[]{JavaScriptCore.newSourceEntry(p.getFullPath(),
62
				ClasspathEntry.INCLUDE_ALL,ClasspathEntry.EXCLUDE_NONE,null,
63
				new IIncludePathAttribute[]{JavaScriptCore.newIncludepathAttribute(PROVIDER_ATTRIBUTE_KEY_NAME, PROVIDER_ATTRIBUTE_KEY_VALUE)})};
57
	}
64
	}
58
}
65
}

Return to bug 333903