author | dadubrow |
Wed, 10 Feb 2010 13:34:53 -0600 | |
changeset 133 | 996f2f4e33c7 |
parent 52 | 42077b7eab6e |
permissions | -rw-r--r-- |
37 | 1 |
/******************************************************************************* |
2 |
* Copyright (c) 2007, 2009 Intel 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 |
* Intel Corporation - Initial API and implementation |
|
10 |
* Markus Schorn (Wind River Systems) |
|
11 |
* IBM Corporation |
|
12 |
* James Blackburn (Broadcom Corp.) |
|
13 |
* Alex Blewitt Bug 132511 - nature order not preserved |
|
14 |
*******************************************************************************/ |
|
15 |
package org.eclipse.cdt.internal.core.settings.model; |
|
16 |
||
17 |
import java.io.ByteArrayOutputStream; |
|
18 |
import java.io.File; |
|
19 |
import java.io.FileInputStream; |
|
20 |
import java.io.FileNotFoundException; |
|
21 |
import java.io.FileOutputStream; |
|
22 |
import java.io.IOException; |
|
23 |
import java.io.InputStream; |
|
24 |
import java.io.UnsupportedEncodingException; |
|
25 |
import java.net.URI; |
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.Arrays; |
|
28 |
import java.util.Collection; |
|
29 |
import java.util.Collections; |
|
30 |
import java.util.HashMap; |
|
31 |
import java.util.HashSet; |
|
32 |
import java.util.Iterator; |
|
33 |
import java.util.LinkedHashMap; |
|
34 |
import java.util.LinkedHashSet; |
|
35 |
import java.util.List; |
|
36 |
import java.util.Map; |
|
37 |
import java.util.Set; |
|
38 |
import java.util.concurrent.CopyOnWriteArraySet; |
|
39 |
||
40 |
import javax.xml.parsers.DocumentBuilder; |
|
41 |
import javax.xml.parsers.DocumentBuilderFactory; |
|
42 |
import javax.xml.parsers.FactoryConfigurationError; |
|
43 |
import javax.xml.parsers.ParserConfigurationException; |
|
44 |
import javax.xml.transform.OutputKeys; |
|
45 |
import javax.xml.transform.Transformer; |
|
46 |
import javax.xml.transform.TransformerConfigurationException; |
|
47 |
import javax.xml.transform.TransformerException; |
|
48 |
import javax.xml.transform.TransformerFactory; |
|
49 |
import javax.xml.transform.dom.DOMSource; |
|
50 |
import javax.xml.transform.stream.StreamResult; |
|
51 |
||
52 |
import org.eclipse.cdt.core.CCorePlugin; |
|
53 |
import org.eclipse.cdt.core.model.CModelException; |
|
54 |
import org.eclipse.cdt.core.model.ICElement; |
|
55 |
import org.eclipse.cdt.core.model.ICElementDelta; |
|
56 |
import org.eclipse.cdt.core.model.ICProject; |
|
57 |
import org.eclipse.cdt.core.settings.model.CExternalSetting; |
|
58 |
import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent; |
|
59 |
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; |
|
60 |
import org.eclipse.cdt.core.settings.model.ICDescriptionDelta; |
|
61 |
import org.eclipse.cdt.core.settings.model.ICFileDescription; |
|
62 |
import org.eclipse.cdt.core.settings.model.ICFolderDescription; |
|
63 |
import org.eclipse.cdt.core.settings.model.ICLanguageSetting; |
|
64 |
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; |
|
65 |
import org.eclipse.cdt.core.settings.model.ICProjectDescription; |
|
66 |
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener; |
|
67 |
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; |
|
68 |
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionWorkspacePreferences; |
|
69 |
import org.eclipse.cdt.core.settings.model.ICResourceDescription; |
|
70 |
import org.eclipse.cdt.core.settings.model.ICSettingBase; |
|
71 |
import org.eclipse.cdt.core.settings.model.ICSettingEntry; |
|
72 |
import org.eclipse.cdt.core.settings.model.ICSettingObject; |
|
73 |
import org.eclipse.cdt.core.settings.model.ICSettingsStorage; |
|
74 |
import org.eclipse.cdt.core.settings.model.ICSourceEntry; |
|
75 |
import org.eclipse.cdt.core.settings.model.ICStorageElement; |
|
76 |
import org.eclipse.cdt.core.settings.model.ICTargetPlatformSetting; |
|
77 |
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; |
|
78 |
import org.eclipse.cdt.core.settings.model.extension.CConfigurationDataProvider; |
|
79 |
import org.eclipse.cdt.core.settings.model.extension.CFileData; |
|
80 |
import org.eclipse.cdt.core.settings.model.extension.CFolderData; |
|
81 |
import org.eclipse.cdt.core.settings.model.extension.CLanguageData; |
|
82 |
import org.eclipse.cdt.core.settings.model.extension.CResourceData; |
|
83 |
import org.eclipse.cdt.core.settings.model.extension.ICProjectConverter; |
|
84 |
import org.eclipse.cdt.core.settings.model.extension.impl.CDataFactory; |
|
85 |
import org.eclipse.cdt.core.settings.model.util.CDataUtil; |
|
86 |
import org.eclipse.cdt.core.settings.model.util.CSettingEntryFactory; |
|
87 |
import org.eclipse.cdt.core.settings.model.util.KindBasedStore; |
|
88 |
import org.eclipse.cdt.core.settings.model.util.ListComparator; |
|
89 |
import org.eclipse.cdt.core.settings.model.util.PathSettingsContainer; |
|
90 |
import org.eclipse.cdt.core.settings.model.util.PatternNameMap; |
|
91 |
import org.eclipse.cdt.internal.core.CConfigBasedDescriptorManager; |
|
92 |
import org.eclipse.cdt.internal.core.model.CElementDelta; |
|
93 |
import org.eclipse.cdt.internal.core.settings.model.CExternalSettinsDeltaCalculator.ExtSettingsDelta; |
|
94 |
import org.eclipse.cdt.internal.core.settings.model.xml.InternalXmlStorageElement; |
|
95 |
import org.eclipse.cdt.internal.core.settings.model.xml.XmlStorage; |
|
96 |
import org.eclipse.core.filesystem.EFS; |
|
97 |
import org.eclipse.core.filesystem.IFileStore; |
|
98 |
import org.eclipse.core.resources.IProject; |
|
99 |
import org.eclipse.core.resources.IProjectDescription; |
|
100 |
import org.eclipse.core.resources.IResource; |
|
101 |
import org.eclipse.core.resources.IResourceChangeEvent; |
|
102 |
import org.eclipse.core.resources.ISavedState; |
|
103 |
import org.eclipse.core.resources.IWorkspace; |
|
104 |
import org.eclipse.core.resources.IWorkspaceRoot; |
|
105 |
import org.eclipse.core.resources.IWorkspaceRunnable; |
|
106 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
107 |
import org.eclipse.core.runtime.CoreException; |
|
108 |
import org.eclipse.core.runtime.IExtension; |
|
109 |
import org.eclipse.core.runtime.IExtensionPoint; |
|
110 |
import org.eclipse.core.runtime.IPath; |
|
111 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
112 |
import org.eclipse.core.runtime.IStatus; |
|
113 |
import org.eclipse.core.runtime.NullProgressMonitor; |
|
114 |
import org.eclipse.core.runtime.Platform; |
|
115 |
import org.eclipse.core.runtime.QualifiedName; |
|
116 |
import org.eclipse.core.runtime.Status; |
|
117 |
import org.eclipse.core.runtime.SubProgressMonitor; |
|
118 |
import org.eclipse.core.runtime.content.IContentType; |
|
119 |
import org.eclipse.core.runtime.content.IContentTypeManager; |
|
120 |
import org.eclipse.core.runtime.jobs.IJobManager; |
|
121 |
import org.eclipse.core.runtime.jobs.ISchedulingRule; |
|
122 |
import org.eclipse.core.runtime.jobs.Job; |
|
123 |
import org.osgi.framework.Version; |
|
124 |
import org.w3c.dom.Document; |
|
125 |
import org.w3c.dom.Element; |
|
126 |
import org.w3c.dom.Node; |
|
127 |
import org.w3c.dom.NodeList; |
|
128 |
import org.w3c.dom.ProcessingInstruction; |
|
129 |
import org.xml.sax.SAXException; |
|
130 |
||
131 |
import com.ibm.icu.text.MessageFormat; |
|
132 |
||
133 |
/** |
|
134 |
* The CProjectDescriptionManager is to marshall the loading and storing |
|
135 |
* of CDT Project Descriptions. |
|
136 |
* |
|
137 |
* This class delegates loading and store of the project model to the appropriate |
|
138 |
* AbstractCProjectDescriptionStorage for the Project Description. [ Discovered at Project load |
|
139 |
* time.] |
|
140 |
* |
|
141 |
* Users should not synchronize on the singleton instance of this class. It is the job of |
|
142 |
* the AbstractCProjectDescriptionStorage to ensure thread safe access to the backing store |
|
143 |
* as described in that interface. |
|
144 |
* |
|
145 |
* Previously this class created and persisted |
|
146 |
* @see ICProjectDescriptionManager |
|
147 |
*/ |
|
148 |
public class CProjectDescriptionManager implements ICProjectDescriptionManager { |
|
149 |
public static final int INTERNAL_GET_IGNORE_CLOSE = 1 << 31 ; |
|
150 |
||
151 |
private static final String VERSION_ELEMENT_NAME = "fileVersion"; //$NON-NLS-1$ |
|
152 |
/** Preference Version 4.0 & 5.0 are equivalent for us. Version was inadvertently bumped |
|
153 |
* when during project description storage work. |
|
154 |
* This is the minimum preference version we support loading.*/ |
|
155 |
public static final Version MIN_DESCRIPTION_VERSION = new Version("4.0"); //$NON-NLS-1$ |
|
156 |
/** Current preference file storage version */ |
|
157 |
public static final Version DESCRIPTION_VERSION = new Version("5.0"); //$NON-NLS-1$ |
|
158 |
public final static String MODULE_ID = "org.eclipse.cdt.core.settings"; //$NON-NLS-1$ |
|
159 |
static final String CONFIGURATION = "cconfiguration"; //$NON-NLS-1$ |
|
160 |
private static final ICLanguageSettingEntry[] EMPTY_LANGUAGE_SETTINGS_ENTRIES_ARRAY = new ICLanguageSettingEntry[0]; |
|
161 |
private static final ICElementDelta[] EMPTY_CELEMENT_DELTA = new ICElementDelta[0]; |
|
162 |
private static final ICLanguageSetting[] EMPTY_LANGUAGE_SETTINGS_ARRAY = new ICLanguageSetting[0]; |
|
163 |
private static final String PREFERENCES_STORAGE = "preferences"; //$NON-NLS-1$ |
|
164 |
private static final String PREFERENCE_BUILD_SYSTEM_ELEMENT = "buildSystem"; //$NON-NLS-1$ |
|
165 |
private static final String PREFERENCES_ELEMENT = "preferences"; //$NON-NLS-1$ |
|
166 |
private static final String ID = "id"; //$NON-NLS-1$ |
|
167 |
private static final String PREFERENCE_CFG_ID_PREFIX = "preference."; //$NON-NLS-1$ |
|
168 |
private static final String PREFERENCE_CFG_NAME = SettingsModelMessages.getString("CProjectDescriptionManager.15"); //$NON-NLS-1$ |
|
169 |
private static final String ROOT_PREFERENCE_ELEMENT = "preferences"; //$NON-NLS-1$ |
|
170 |
private static final String DEFAULT_CFG_ID_PREFIX = CCorePlugin.PLUGIN_ID + ".default.config"; //$NON-NLS-1$ |
|
171 |
private static final String DEFAULT_CFG_NAME = "Configuration"; //$NON-NLS-1$ |
|
172 |
||
173 |
private static final QualifiedName SCANNER_INFO_PROVIDER_PROPERTY = new QualifiedName(CCorePlugin.PLUGIN_ID, "scannerInfoProvider"); //$NON-NLS-1$ |
|
174 |
||
175 |
static class CompositeWorkspaceRunnable implements IWorkspaceRunnable { |
|
176 |
private List<IWorkspaceRunnable> fRunnables = new ArrayList<IWorkspaceRunnable>(); |
|
177 |
private String fName; |
|
178 |
private boolean fStopOnErr; |
|
179 |
||
180 |
CompositeWorkspaceRunnable(String name){ |
|
181 |
if(name == null) |
|
182 |
name = ""; //$NON-NLS-1$ |
|
183 |
fName = name; |
|
184 |
} |
|
185 |
||
186 |
public void add(IWorkspaceRunnable runnable){ |
|
187 |
fRunnables.add(runnable); |
|
188 |
} |
|
189 |
||
190 |
public void run(IProgressMonitor monitor) throws CoreException { |
|
191 |
try { |
|
192 |
monitor.beginTask(fName, fRunnables.size()); |
|
193 |
||
194 |
for(Iterator<IWorkspaceRunnable> iter = fRunnables.iterator(); iter.hasNext();){ |
|
195 |
IWorkspaceRunnable r = iter.next(); |
|
196 |
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1); |
|
197 |
try { |
|
198 |
r.run(subMonitor); |
|
199 |
} catch (CoreException e){ |
|
200 |
if(fStopOnErr) |
|
201 |
throw e; |
|
202 |
} catch (RuntimeException e) { |
|
203 |
if(fStopOnErr) |
|
204 |
throw e; |
|
205 |
} finally { |
|
206 |
subMonitor.done(); |
|
207 |
} |
|
208 |
} |
|
209 |
} finally { |
|
210 |
monitor.done(); |
|
211 |
} |
|
212 |
} |
|
213 |
||
214 |
public boolean isEmpty(){ |
|
215 |
return fRunnables.isEmpty(); |
|
216 |
} |
|
217 |
} |
|
218 |
||
219 |
/** |
|
220 |
* Container class for ICProjectDescription change listeners |
|
221 |
*/ |
|
222 |
private static class ListenerDescriptor{ |
|
223 |
final ICProjectDescriptionListener fListener; |
|
224 |
final int fEventTypes; |
|
225 |
||
226 |
public ListenerDescriptor(ICProjectDescriptionListener listener, int eventTypes) { |
|
227 |
fListener = listener; |
|
228 |
fEventTypes = eventTypes; |
|
229 |
} |
|
230 |
||
231 |
public boolean handlesEvent(int eventType){ |
|
232 |
return (eventType & fEventTypes) != 0; |
|
233 |
} |
|
133
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
234 |
|
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
235 |
// Can't use these due to implementation of CopyOnWriteArraySet.remove() |
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
236 |
// @Override |
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
237 |
// public int hashCode() { |
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
238 |
// return fListener.hashCode(); |
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
239 |
// } |
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
240 |
// @Override |
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
241 |
// public boolean equals(Object obj) { |
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
242 |
// return fListener.equals(obj); |
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
243 |
// } |
37 | 244 |
} |
245 |
||
246 |
private volatile Map<String, CConfigurationDataProviderDescriptor> fProviderMap; |
|
247 |
private volatile CProjectConverterDesciptor fConverters[]; |
|
248 |
/** Set of Listeners listening for Project Description Deltas */ |
|
249 |
private Set<ListenerDescriptor> fListeners = new CopyOnWriteArraySet<ListenerDescriptor>(); |
|
250 |
private Map<String, CConfigurationDescriptionCache> fPreferenceMap = new HashMap<String, CConfigurationDescriptionCache>(); |
|
251 |
private CConfigBasedDescriptorManager fDescriptorManager; |
|
252 |
private ResourceChangeHandler fRcChangeHandler; |
|
253 |
private CProjectDescriptionWorkspacePreferences fPreferences; |
|
254 |
private boolean fAllowEmptyCreatingDescription = true; // allowed by default |
|
255 |
||
256 |
private ICDataProxyContainer fPrefUpdater = new ICDataProxyContainer(){ |
|
257 |
||
258 |
public void updateChild(CDataProxy child, boolean write) { |
|
259 |
if(write){ |
|
260 |
try { |
|
261 |
((CConfigurationDescription)child).doWritable(); |
|
262 |
} catch (CoreException e) { |
|
263 |
CCorePlugin.log(e); |
|
264 |
} |
|
265 |
} |
|
266 |
} |
|
267 |
||
268 |
public ICSettingObject[] getChildSettings() { |
|
269 |
return fPreferenceMap.values().toArray(new CConfigurationDescriptionCache[fPreferenceMap.size()]); |
|
270 |
} |
|
271 |
}; |
|
272 |
||
273 |
/** The CProjectDescriptionManager instance */ |
|
274 |
private static volatile CProjectDescriptionManager fInstance; |
|
275 |
||
276 |
private CProjectDescriptionManager(){} |
|
277 |
||
278 |
public static CProjectDescriptionManager getInstance(){ |
|
279 |
if(fInstance == null) |
|
280 |
synchronized(CProjectDescriptionManager.class) { |
|
281 |
if (fInstance == null) |
|
282 |
fInstance = new CProjectDescriptionManager(); |
|
283 |
} |
|
284 |
return fInstance; |
|
285 |
} |
|
286 |
||
287 |
public void projectClosedRemove(IProject project) { |
|
288 |
CProjectDescriptionStorageManager.getInstance().projectClosedRemove(project); |
|
289 |
} |
|
290 |
||
291 |
public void projectMove(IProject from, IProject to) { |
|
292 |
CProjectDescriptionStorageManager.getInstance().projectMove(from, to); |
|
293 |
} |
|
294 |
||
295 |
||
296 |
public Job startup(){ |
|
297 |
if(fRcChangeHandler == null){ |
|
298 |
fRcChangeHandler = new ResourceChangeHandler(); |
|
299 |
||
300 |
ResourcesPlugin.getWorkspace().addResourceChangeListener( |
|
301 |
fRcChangeHandler, |
|
302 |
IResourceChangeEvent.POST_CHANGE |
|
303 |
| IResourceChangeEvent.PRE_DELETE |
|
304 |
| IResourceChangeEvent.PRE_CLOSE |
|
305 |
/*| IResourceChangeEvent.POST_BUILD*/); |
|
306 |
||
307 |
if(fDescriptorManager == null){ |
|
308 |
fDescriptorManager = CConfigBasedDescriptorManager.getInstance(); |
|
309 |
fDescriptorManager.startup(); |
|
310 |
} |
|
311 |
||
312 |
CExternalSettingsManager.getInstance().startup(); |
|
313 |
} |
|
314 |
return createPostStartupJob(); |
|
315 |
} |
|
316 |
||
317 |
private Job createPostStartupJob() { |
|
318 |
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); |
|
319 |
Job rcJob = new Job(SettingsModelMessages.getString("CProjectDescriptionManager.0")){ //$NON-NLS-1$ |
|
320 |
@Override |
|
321 |
protected IStatus run(IProgressMonitor monitor) { |
|
322 |
try{ |
|
323 |
startSaveParticipant(); |
|
324 |
} catch (CoreException e){ |
|
325 |
CCorePlugin.log(e); |
|
326 |
return e.getStatus(); |
|
327 |
} |
|
328 |
return new Status( |
|
329 |
IStatus.OK, |
|
330 |
CCorePlugin.PLUGIN_ID, |
|
331 |
IStatus.OK, |
|
332 |
"", //$NON-NLS-1$ |
|
333 |
null); |
|
334 |
} |
|
335 |
}; |
|
336 |
||
337 |
rcJob.setRule(root); |
|
338 |
rcJob.setPriority(Job.INTERACTIVE); |
|
339 |
rcJob.setSystem(true); |
|
340 |
return rcJob; |
|
341 |
} |
|
342 |
||
343 |
/* |
|
344 |
* This method adds a save participant and resource change listener |
|
345 |
* Throws CoreException if the methods fails to add a save participant. |
|
346 |
* The resource change listener in not added in this case either. |
|
347 |
*/ |
|
348 |
private void startSaveParticipant() throws CoreException{ |
|
349 |
// Set up a listener for resource change events |
|
350 |
ISavedState lastState = |
|
351 |
ResourcesPlugin.getWorkspace().addSaveParticipant(CCorePlugin.getDefault(), fRcChangeHandler); |
|
352 |
||
353 |
if (lastState != null) { |
|
354 |
lastState.processResourceChangeEvents(fRcChangeHandler); |
|
355 |
} |
|
356 |
} |
|
357 |
||
358 |
public void shutdown(){ |
|
359 |
CExternalSettingsManager.getInstance().shutdown(); |
|
360 |
||
361 |
if(fDescriptorManager != null) { |
|
362 |
fDescriptorManager.shutdown(); |
|
363 |
fDescriptorManager = null; |
|
364 |
} |
|
365 |
||
366 |
if(fRcChangeHandler != null) { |
|
367 |
ResourcesPlugin.getWorkspace().removeResourceChangeListener(fRcChangeHandler); |
|
368 |
fRcChangeHandler = null; |
|
369 |
} |
|
370 |
||
371 |
CProjectDescriptionStorageManager.getInstance().shutdown(); |
|
372 |
} |
|
373 |
||
374 |
public ICProjectDescription getProjectDescription(IProject project, boolean write) { |
|
375 |
return getProjectDescription(project, true, write); |
|
376 |
} |
|
377 |
||
378 |
public ICProjectDescription getProjectDescription(IProject project, boolean load, boolean write) { |
|
379 |
int flags = load ? 0 : GET_IF_LOADDED; |
|
380 |
flags |= write ? GET_WRITABLE : 0; |
|
381 |
||
382 |
return getProjectDescription(project, flags); |
|
383 |
} |
|
384 |
||
385 |
public ICProjectDescription getProjectDescription(IProject project, int flags) { |
|
386 |
AbstractCProjectDescriptionStorage storage = getProjectDescriptionStorage(project); |
|
387 |
if (storage != null) { |
|
388 |
try { |
|
389 |
return storage.getProjectDescription(flags, new NullProgressMonitor()); |
|
390 |
} catch (CoreException e) { |
|
391 |
// FIXME Currently the resource change handler ResourceChangeHandler.getProjectDescription(...) |
|
392 |
// Does this when the project is closed. Don't log an error or the tests will fail |
|
393 |
// CCorePlugin.log(e); |
|
394 |
} |
|
395 |
} |
|
396 |
return null; |
|
397 |
} |
|
398 |
||
399 |
/** |
|
400 |
* Run the workspace modification in the current thread using the workspace scheduling rule |
|
401 |
* Equivalent to: <code>runWspModification(IWorkspaceRunnable, ResourcecPlugin.getWorkspace().getRoot(), IProgressMonitor)</code> |
|
402 |
*<br/><br/> |
|
403 |
* Note that if the workspace is locked, or the current job / thread doesn't contain the workspace |
|
404 |
* scheduling rule, then we schedule a job to run the {@link IWorkspaceRunnable} |
|
405 |
*<br/><br/> |
|
406 |
* The scheduled job is returned, or null if the operation was run immediately. |
|
407 |
* |
|
408 |
* @param runnable the IWorkspaceRunnable to run |
|
409 |
* @param monitor |
|
410 |
* @return scheduled job or null if the operation was run immediately |
|
411 |
*/ |
|
412 |
public static Job runWspModification(final IWorkspaceRunnable runnable, IProgressMonitor monitor) { |
|
413 |
return runWspModification(runnable, ResourcesPlugin.getWorkspace().getRoot(), monitor); |
|
414 |
} |
|
415 |
||
416 |
/** |
|
417 |
* Either runs the modification in the current thread (if the workspace is not locked) |
|
418 |
* or schedules a runnable to perform the operation |
|
419 |
* @param runnable |
|
420 |
* @param monitor |
|
421 |
* @return scheduled job or null if the operation was run immediately |
|
422 |
*/ |
|
423 |
public static Job runWspModification(final IWorkspaceRunnable runnable, final ISchedulingRule rule, IProgressMonitor monitor){ |
|
424 |
if(monitor == null) |
|
425 |
monitor = new NullProgressMonitor(); |
|
426 |
||
427 |
// Should the rule be scheduled, or run immediately |
|
428 |
boolean scheduleRule = ResourcesPlugin.getWorkspace().isTreeLocked(); |
|
429 |
||
430 |
// Check whether current job contains rule 'rule' |
|
431 |
// If not, we must schedule another job to execute the runnable |
|
432 |
if (!scheduleRule) { |
|
433 |
Job currentJob = Job.getJobManager().currentJob(); |
|
434 |
if (currentJob != null && currentJob.getRule() != null && !currentJob.getRule().contains(rule)) |
|
435 |
scheduleRule = true; |
|
436 |
} |
|
437 |
||
438 |
if(!scheduleRule) { |
|
439 |
// Run immediately |
|
440 |
IJobManager mngr = Job.getJobManager(); |
|
441 |
try{ |
|
442 |
mngr.beginRule(rule, monitor); |
|
443 |
runAtomic(runnable, rule, monitor); |
|
444 |
} catch (Exception e) { |
|
445 |
CCorePlugin.log(e); |
|
446 |
} finally { |
|
447 |
if(!scheduleRule) |
|
448 |
monitor.done(); |
|
449 |
mngr.endRule(rule); |
|
450 |
} |
|
451 |
} else { |
|
452 |
// schedule a job for it |
|
453 |
Job job = new Job(SettingsModelMessages.getString("CProjectDescriptionManager.12")){ //$NON-NLS-1$ |
|
454 |
@Override |
|
455 |
protected IStatus run(IProgressMonitor monitor) { |
|
456 |
try { |
|
457 |
runAtomic(runnable, rule, monitor); |
|
458 |
} catch (CoreException e) { |
|
459 |
CCorePlugin.log(e); |
|
460 |
return e.getStatus(); |
|
461 |
} finally { |
|
462 |
monitor.done(); |
|
463 |
} |
|
464 |
return Status.OK_STATUS; |
|
465 |
} |
|
466 |
}; |
|
467 |
||
468 |
job.setRule(rule); |
|
469 |
job.setSystem(true); |
|
470 |
job.schedule(); |
|
471 |
return job; |
|
472 |
} |
|
473 |
return null; |
|
474 |
} |
|
475 |
||
476 |
private static void runAtomic(final IWorkspaceRunnable r, ISchedulingRule rule, IProgressMonitor monitor) throws CoreException{ |
|
477 |
IWorkspace wsp = ResourcesPlugin.getWorkspace(); |
|
478 |
wsp.run(new IWorkspaceRunnable(){ |
|
479 |
public void run(IProgressMonitor monitor) throws CoreException { |
|
480 |
try { |
|
481 |
r.run(monitor); |
|
482 |
} catch (Exception e){ |
|
483 |
CCorePlugin.log(e); |
|
484 |
throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, e.getMessage(), e)); |
|
485 |
} |
|
486 |
} |
|
487 |
}, rule, IWorkspace.AVOID_UPDATE, monitor); |
|
488 |
} |
|
489 |
||
490 |
public void updateProjectDescriptions(IProject[] projects, IProgressMonitor monitor) throws CoreException{ |
|
491 |
if(monitor == null) |
|
492 |
monitor = new NullProgressMonitor(); |
|
493 |
||
494 |
try { |
|
495 |
IWorkspace wsp = ResourcesPlugin.getWorkspace(); |
|
496 |
if(projects == null) |
|
497 |
projects = wsp.getRoot().getProjects(); |
|
498 |
final ICProjectDescription dess[] = new ICProjectDescription[projects.length]; |
|
499 |
int num = 0; |
|
500 |
for(int i = 0; i < projects.length; i++){ |
|
501 |
ICProjectDescription des = getProjectDescription(projects[i], false, true); |
|
502 |
if(des != null) |
|
503 |
dess[num++] = des; |
|
504 |
} |
|
505 |
||
506 |
if(num != 0){ |
|
507 |
final int[] fi = new int[1]; |
|
508 |
fi[0] = num; |
|
509 |
runWspModification(new IWorkspaceRunnable(){ |
|
510 |
||
511 |
public void run(IProgressMonitor monitor) throws CoreException { |
|
512 |
monitor.beginTask(SettingsModelMessages.getString("CProjectDescriptionManager.13"), fi[0]); //$NON-NLS-1$ |
|
513 |
||
514 |
for(int i = 0; i < dess.length; i++){ |
|
515 |
ICProjectDescription des = dess[i]; |
|
516 |
if(des == null) |
|
517 |
break; |
|
518 |
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1); |
|
519 |
try { |
|
520 |
setProjectDescription(des.getProject(), des, true, subMonitor); |
|
521 |
} catch (CoreException e){ |
|
522 |
CCorePlugin.log(e); |
|
523 |
} finally { |
|
524 |
subMonitor.done(); |
|
525 |
} |
|
526 |
} |
|
527 |
} |
|
528 |
}, monitor); |
|
529 |
||
530 |
} |
|
531 |
} finally { |
|
532 |
monitor.done(); |
|
533 |
} |
|
534 |
||
535 |
} |
|
536 |
||
537 |
public ICProjectConverter getConverter(IProject project, String oldOwnerId, ICProjectDescription des){ |
|
538 |
CProjectConverterDesciptor[] converterDess = getConverterDescriptors(); |
|
539 |
ICProjectConverter converter = null; |
|
540 |
for(int i = 0; i < converterDess.length; i++){ |
|
541 |
if(converterDess[i].canConvertProject(project, oldOwnerId, des)){ |
|
542 |
try { |
|
543 |
converter = converterDess[i].getConverter(); |
|
544 |
} catch (CoreException e) { |
|
545 |
} |
|
546 |
if(converter != null) |
|
547 |
break; |
|
548 |
} |
|
549 |
} |
|
550 |
return converter; |
|
551 |
} |
|
552 |
||
553 |
private CProjectConverterDesciptor[] getConverterDescriptors(){ |
|
554 |
if(fConverters == null){ |
|
555 |
initConverterInfoSynch(); |
|
556 |
} |
|
557 |
return fConverters; |
|
558 |
} |
|
559 |
||
560 |
private synchronized void initConverterInfoSynch(){ |
|
561 |
if(fConverters != null) |
|
562 |
return; |
|
563 |
||
564 |
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CProjectConverterDesciptor.PROJECT_CONVERTER_EXTPOINT_ID); |
|
565 |
IExtension exts[] = extensionPoint.getExtensions(); |
|
566 |
CProjectConverterDesciptor[] dess = new CProjectConverterDesciptor[exts.length]; |
|
567 |
||
568 |
for(int i = 0; i < exts.length; i++){ |
|
569 |
dess[i] = new CProjectConverterDesciptor(exts[i]); |
|
570 |
} |
|
571 |
||
572 |
fConverters = dess; |
|
573 |
} |
|
574 |
||
575 |
public ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists) throws CoreException{ |
|
576 |
return createProjectDescription(project, loadIfExists, false); |
|
577 |
} |
|
578 |
||
579 |
public ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists, boolean creating) throws CoreException{ |
|
580 |
int flags = ICProjectDescriptionManager.GET_WRITABLE | ICProjectDescriptionManager.GET_CREATE_DESCRIPTION; |
|
581 |
flags |= loadIfExists ? 0 : ICProjectDescriptionManager.GET_EMPTY_PROJECT_DESCRIPTION; |
|
582 |
flags |= creating ? ICProjectDescriptionManager.PROJECT_CREATING : 0; |
|
583 |
||
584 |
return getProjectDescription(project, flags); |
|
585 |
} |
|
586 |
||
587 |
public ScannerInfoProviderProxy getScannerInfoProviderProxy(IProject project){ |
|
588 |
ICProjectDescription des = getProjectDescription(project, false); |
|
589 |
if(des == null){ |
|
590 |
return new ScannerInfoProviderProxy(project); |
|
591 |
} |
|
592 |
||
593 |
ScannerInfoProviderProxy provider = (ScannerInfoProviderProxy)des.getSessionProperty(SCANNER_INFO_PROVIDER_PROPERTY); |
|
594 |
if(provider == null){ |
|
595 |
provider = new ScannerInfoProviderProxy(project); |
|
596 |
des.setSessionProperty(SCANNER_INFO_PROVIDER_PROPERTY, provider); |
|
597 |
} else { |
|
598 |
provider.updateProject(project); |
|
599 |
} |
|
600 |
||
601 |
return provider; |
|
602 |
} |
|
603 |
||
604 |
public ICProjectDescription getProjectDescription(IProject project){ |
|
605 |
return getProjectDescription(project, true); |
|
606 |
} |
|
607 |
||
608 |
/* |
|
609 |
* returns true if the project description was modified false - otherwise |
|
610 |
*/ |
|
611 |
public boolean checkHandleActiveCfgChange(CProjectDescription newDes, ICProjectDescription oldDes, IProjectDescription eDes, IProgressMonitor monitor){ |
|
612 |
if(newDes == null) |
|
613 |
return false; |
|
614 |
ICConfigurationDescription newCfg = newDes.getActiveConfiguration(); |
|
615 |
if(newCfg == null) |
|
616 |
return false; |
|
617 |
||
618 |
ICConfigurationDescription oldCfg = oldDes != null ? oldDes.getActiveConfiguration() : null; |
|
619 |
||
620 |
checkActiveCfgChange(newDes, oldDes); |
|
621 |
checkSettingCfgChange(newDes, oldDes); |
|
622 |
||
623 |
boolean modified = false; |
|
624 |
||
625 |
try { |
|
626 |
if(checkBuildSystemChange(eDes, newCfg, oldCfg, monitor)) |
|
627 |
modified = true; |
|
628 |
} catch (CoreException e) { |
|
629 |
CCorePlugin.log(e); |
|
630 |
} |
|
631 |
||
632 |
try { |
|
633 |
if(checkProjectRefChange(eDes, newCfg, oldCfg, monitor)) |
|
634 |
modified = true; |
|
635 |
} catch (CoreException e) { |
|
636 |
CCorePlugin.log(e); |
|
637 |
} |
|
638 |
||
639 |
return modified; |
|
640 |
} |
|
641 |
||
642 |
// String loadActiveCfgId(ICProjectDescription des){ |
|
643 |
// try { |
|
644 |
// return des.getProject().getPersistentProperty(ACTIVE_CFG_PROPERTY); |
|
645 |
// } catch (CoreException e) { |
|
646 |
// CCorePlugin.log(e); |
|
647 |
// } |
|
648 |
// return null; |
|
649 |
// } |
|
650 |
||
651 |
private Collection<IProject> projSetFromProjNameSet(Collection<String> projNames){ |
|
652 |
if(projNames.size() == 0) |
|
653 |
return new HashSet<IProject>(0); |
|
654 |
||
655 |
Set<IProject> set = new HashSet<IProject>(); |
|
656 |
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); |
|
657 |
||
658 |
for (String sproj : projNames) |
|
659 |
set.add(root.getProject(sproj)); |
|
660 |
||
661 |
return set; |
|
662 |
} |
|
663 |
||
664 |
private boolean checkProjectRefChange(IProjectDescription des, ICConfigurationDescription newCfg, ICConfigurationDescription oldCfg, IProgressMonitor monitor) throws CoreException{ |
|
665 |
if(newCfg == null) |
|
666 |
return false; |
|
667 |
||
668 |
Map<String, String> oldMap = oldCfg != null ? oldCfg.getReferenceInfo() : null; |
|
669 |
Map<String, String> newMap = newCfg.getReferenceInfo(); |
|
670 |
Collection<IProject> oldProjSet = oldMap != null ? projSetFromProjNameSet(oldMap.keySet()) : new HashSet<IProject>(0); |
|
671 |
Collection<IProject> newProjSet = newMap != null ? projSetFromProjNameSet(newMap.keySet()) : new HashSet<IProject>(0); |
|
672 |
||
673 |
Set<IProject> tmp = new HashSet<IProject>(newProjSet); |
|
674 |
newProjSet.removeAll(oldProjSet); |
|
675 |
oldProjSet.removeAll(tmp); |
|
676 |
if(oldProjSet.size() != 0 || newProjSet.size() != 0){ |
|
677 |
IProject[] refs = des.getReferencedProjects(); |
|
678 |
Set<IProject> set = new HashSet<IProject>(Arrays.asList(refs)); |
|
679 |
set.removeAll(oldProjSet); |
|
680 |
set.addAll(newProjSet); |
|
681 |
des.setReferencedProjects(set.toArray(new IProject[set.size()])); |
|
682 |
return true; |
|
683 |
} |
|
684 |
return false; |
|
685 |
} |
|
686 |
||
687 |
||
688 |
// private void checkBuildSystemChange(IProject project, String newBsId, String oldBsId, IProgressMonitor monitor) throws CoreException{ |
|
689 |
// checkBuildSystemChange(project, null, newBsId, oldBsId, monitor); |
|
690 |
// } |
|
691 |
||
692 |
private boolean checkActiveCfgChange(CProjectDescription des, |
|
693 |
ICProjectDescription oldDes |
|
694 |
// ICConfigurationDescription newCfg, |
|
695 |
// ICConfigurationDescription oldCfg |
|
696 |
){ |
|
697 |
ICConfigurationDescription oldCfg = oldDes != null ? oldDes.getActiveConfiguration() : null; |
|
698 |
// String newId = newCfg.getId(); |
|
699 |
String oldId = oldCfg != null ? oldCfg.getId() : null; |
|
700 |
||
701 |
||
702 |
return des.checkPersistActiveCfg(oldId, false); |
|
703 |
} |
|
704 |
||
705 |
private boolean checkSettingCfgChange(CProjectDescription des, |
|
706 |
ICProjectDescription oldDes |
|
707 |
// ICConfigurationDescription newCfg, |
|
708 |
// ICConfigurationDescription oldCfg |
|
709 |
){ |
|
710 |
ICConfigurationDescription oldCfg = oldDes != null ? oldDes.getDefaultSettingConfiguration() : null; |
|
711 |
// String newId = newCfg.getId(); |
|
712 |
String oldId = oldCfg != null ? oldCfg.getId() : null; |
|
713 |
||
714 |
||
715 |
return des.checkPersistSettingCfg(oldId, false); |
|
716 |
} |
|
717 |
||
718 |
private boolean checkBuildSystemChange(IProjectDescription des, |
|
719 |
ICConfigurationDescription newCfg, |
|
720 |
ICConfigurationDescription oldCfg, |
|
721 |
IProgressMonitor monitor) throws CoreException{ |
|
722 |
String newBsId = newCfg != null ? newCfg.getBuildSystemId() : null; |
|
723 |
String oldBsId = oldCfg != null ? oldCfg.getBuildSystemId() : null; |
|
724 |
||
725 |
CConfigurationDataProviderDescriptor newDr = newBsId != null ? getCfgProviderDescriptor(newBsId) : null; |
|
726 |
CConfigurationDataProviderDescriptor oldDr = oldBsId != null ? getCfgProviderDescriptor(oldBsId) : null; |
|
727 |
||
728 |
List<String> newNatures, oldNatures, conflictingNatures; |
|
729 |
newNatures = oldNatures = conflictingNatures = Collections.emptyList(); |
|
730 |
if (oldDr != null) |
|
731 |
oldNatures = Arrays.asList(oldDr.getNatureIds()); |
|
732 |
if (newDr != null) { |
|
733 |
newNatures = Arrays.asList(newDr.getNatureIds()); |
|
734 |
conflictingNatures = Arrays.asList(newDr.getConflictingNatureIds()); |
|
735 |
} |
|
736 |
||
737 |
// List of existing natureIds |
|
738 |
final String[] natureIds = des.getNatureIds(); |
|
739 |
||
740 |
// Get the set of items to remove ({oldNatures} - {newNatures}) + conflictingNatures |
|
741 |
Set<String> toRemove = new HashSet<String>(oldNatures); |
|
742 |
toRemove.removeAll(newNatures); // Don't remove items we're re-adding |
|
743 |
toRemove.addAll(conflictingNatures); // Add conflicting natures for removal |
|
744 |
// Modify an ordered set of the existing natures with the changes |
|
745 |
final LinkedHashSet<String> cur = new LinkedHashSet<String>(Arrays.asList(natureIds)); |
|
746 |
cur.addAll(newNatures); |
|
747 |
cur.removeAll(toRemove); |
|
748 |
||
749 |
final String[] newNatureIds = cur.toArray(new String[cur.size()]); |
|
750 |
if (!Arrays.equals(newNatureIds, natureIds)) { |
|
751 |
des.setNatureIds(newNatureIds); |
|
752 |
return true; |
|
753 |
} |
|
754 |
||
755 |
return false; |
|
756 |
} |
|
757 |
||
758 |
public void setProjectDescription(IProject project, ICProjectDescription des) throws CoreException { |
|
759 |
setProjectDescription(project, des, false, null); |
|
760 |
} |
|
761 |
||
762 |
public void setProjectDescription(IProject project, ICProjectDescription des, boolean force, IProgressMonitor monitor) throws CoreException { |
|
763 |
int flags = force ? SET_FORCE : 0; |
|
764 |
setProjectDescription(project, des, flags, monitor); |
|
765 |
} |
|
766 |
||
767 |
static boolean checkFlags(int flags, int check){ |
|
768 |
return (flags & check) == check; |
|
769 |
} |
|
770 |
||
771 |
/** ThreadLocal flag to let CDescriptor know whether already in a setProjectDescription */ |
|
772 |
ThreadLocal<Boolean> settingProjectDescription = new ThreadLocal<Boolean>(){@Override protected Boolean initialValue() {return false;}}; |
|
773 |
public void setProjectDescription(IProject project, ICProjectDescription des, int flags, IProgressMonitor monitor) throws CoreException { |
|
774 |
try { |
|
775 |
settingProjectDescription.set(true); |
|
776 |
if(des != null){ |
|
777 |
if (!project.isAccessible()) |
|
778 |
throw ExceptionFactory.createCoreException(MessageFormat.format(CCorePlugin.getResourceString("ProjectDescription.ProjectNotAccessible"), new Object[] {project.getName()})); //$NON-NLS-1$ |
|
779 |
||
780 |
if(!des.isValid() && (!fAllowEmptyCreatingDescription || !des.isCdtProjectCreating())) |
|
781 |
throw ExceptionFactory.createCoreException(SettingsModelMessages.getString("CProjectDescriptionManager.17") + project.getName()); //$NON-NLS-1$ |
|
782 |
||
783 |
if(!checkFlags(flags, SET_FORCE) && !des.isModified()) |
|
784 |
return; |
|
785 |
||
786 |
if(((CProjectDescription)des).isLoading()){ |
|
787 |
throw ExceptionFactory.createCoreException("description is being loadded"); //$NON-NLS-1$ |
|
788 |
} |
|
789 |
||
790 |
if(((CProjectDescription)des).isApplying()){ |
|
791 |
throw ExceptionFactory.createCoreException("description is being applied"); //$NON-NLS-1$ |
|
792 |
} |
|
793 |
} |
|
794 |
CProjectDescriptionStorageManager.getInstance().setProjectDescription(project, des, flags, monitor); |
|
795 |
} finally { |
|
796 |
settingProjectDescription.set(false); |
|
797 |
} |
|
798 |
} |
|
799 |
||
800 |
/** |
|
801 |
* Indicates that a setProjectDescription is currently in progress to prevent recursive setProjectDescription |
|
802 |
* @return boolean |
|
803 |
*/ |
|
804 |
public boolean isCurrentThreadSetProjectDescription() { |
|
805 |
return settingProjectDescription.get(); |
|
806 |
} |
|
807 |
||
808 |
private AbstractCProjectDescriptionStorage getProjectDescriptionStorage(IProject project) { |
|
809 |
return CProjectDescriptionStorageManager.getInstance().getProjectDescriptionStorage(project); |
|
810 |
} |
|
811 |
||
812 |
/** |
|
813 |
* Return an ICSettingsStorage based on the provided ICStorageElement |
|
814 |
* in the given IProject |
|
815 |
* @param project |
|
816 |
* @return ICSettingsStorages |
|
817 |
*/ |
|
818 |
public ICSettingsStorage getStorageForElement(IProject project, ICStorageElement element) throws CoreException { |
|
819 |
if (project != null) |
|
820 |
return getProjectDescriptionStorage(project).getStorageForElement(element); |
|
821 |
// project is null means it's a preference element, uses XmlStorages |
|
822 |
return new XmlStorage((InternalXmlStorageElement)element); |
|
823 |
} |
|
824 |
||
825 |
private void serializePreference(String key, InternalXmlStorageElement element) throws CoreException{ |
|
826 |
Document doc = element.fElement.getOwnerDocument(); |
|
827 |
||
828 |
// Transform the document to something we can save in a file |
|
829 |
ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
|
830 |
FileOutputStream fileStream = null; |
|
831 |
try { |
|
832 |
Transformer transformer = TransformerFactory.newInstance().newTransformer(); |
|
833 |
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ |
|
834 |
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$ |
|
835 |
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ |
|
836 |
DOMSource source = new DOMSource(doc); |
|
837 |
StreamResult result = new StreamResult(stream); |
|
838 |
transformer.transform(source, result); |
|
839 |
||
840 |
// Save the document |
|
841 |
File file = getPreferenceFile(key); |
|
842 |
String utfString = stream.toString("UTF-8"); //$NON-NLS-1$ |
|
843 |
||
844 |
if (file.exists()) { |
|
845 |
// if (projectFile.isReadOnly()) { |
|
846 |
// |
|
847 |
// // Inform Eclipse that we are intending to modify this file |
|
848 |
// // This will provide the user the opportunity, via UI prompts, to fetch the file from source code control |
|
849 |
// // reset a read-only file protection to write etc. |
|
850 |
// // If there is no shell, i.e. shell is null, then there will be no user UI interaction |
|
851 |
// |
|
852 |
// //TODO |
|
853 |
// //IStatus status = projectFile.getWorkspace().validateEdit(new IFile[]{projectFile}, shell); |
|
854 |
// |
|
855 |
// // If the file is still read-only, then we should not attempt the write, since it will |
|
856 |
// // just fail - just throw an exception, to be caught below, and inform the user |
|
857 |
// // For other non-successful status, we take our chances, attempt the write, and pass |
|
858 |
// // along any exception thrown |
|
859 |
// |
|
860 |
// //if (!status.isOK()) { |
|
861 |
// // if (status.getCode() == IResourceStatus.READ_ONLY_LOCAL) { |
|
862 |
// // stream.close(); |
|
863 |
// // throw new CoreException(status); |
|
864 |
// //} |
|
865 |
// //} |
|
866 |
// } |
|
867 |
// projectFile.setContents(new ByteArrayInputStream(utfString.getBytes("UTF-8")), IResource.FORCE, new NullProgressMonitor()); //$NON-NLS-1$ |
|
868 |
} else { |
|
869 |
file.createNewFile(); |
|
870 |
} |
|
871 |
fileStream = new FileOutputStream(file); |
|
872 |
byte[] bytes; |
|
873 |
try { |
|
874 |
bytes = utfString.getBytes("UTF-8"); //$NON-NLS-1$ |
|
875 |
} catch (UnsupportedEncodingException e){ |
|
876 |
bytes = utfString.getBytes(); |
|
877 |
} |
|
878 |
fileStream.write(bytes); |
|
879 |
fileStream.close(); |
|
880 |
// Close the streams |
|
881 |
stream.close(); |
|
882 |
} catch (TransformerConfigurationException e){ |
|
883 |
throw ExceptionFactory.createCoreException(e); |
|
884 |
} catch (TransformerException e) { |
|
885 |
throw ExceptionFactory.createCoreException(e); |
|
886 |
} catch (IOException e) { |
|
887 |
throw ExceptionFactory.createCoreException(e); |
|
888 |
} |
|
889 |
} |
|
890 |
||
891 |
ICLanguageSetting findLanguagSettingForFile(String fileName, IProject project, ICLanguageSetting settings[]){ |
|
892 |
// if(cType != null){ |
|
893 |
// setting = findLanguageSettingForContentTypeId(cType.getId(), settings, true); |
|
894 |
// if(setting == null) |
|
895 |
// setting = findLanguageSettingForContentTypeId(cType.getId(), settings, false); |
|
896 |
// } |
|
897 |
ICLanguageSetting setting = null; |
|
898 |
int index = fileName.lastIndexOf('.'); |
|
899 |
if(index > 0){ |
|
900 |
String ext = fileName.substring(index + 1).trim(); |
|
901 |
if(ext.length() > 0){ |
|
902 |
setting = findLanguageSettingForExtension(ext, settings); |
|
903 |
} |
|
904 |
} |
|
905 |
return setting; |
|
906 |
} |
|
907 |
||
908 |
public ICLanguageSetting findLanguageSettingForContentTypeId(String id, ICLanguageSetting settings[]/*, boolean src*/){ |
|
909 |
for(int i = 0; i < settings.length; i++){ |
|
910 |
String ids[] = settings[i].getSourceContentTypeIds(); |
|
911 |
if(ListComparator.indexOf(id, ids) != -1) |
|
912 |
return settings[i]; |
|
913 |
} |
|
914 |
return null; |
|
915 |
} |
|
916 |
||
917 |
public ICLanguageSetting[] findCompatibleSettingsForContentTypeId(String id, ICLanguageSetting[] settings/*, boolean src*/){ |
|
918 |
IContentTypeManager manager = Platform.getContentTypeManager(); |
|
919 |
IContentType cType = manager.getContentType(id); |
|
920 |
if(cType != null){ |
|
921 |
String [] exts = cType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC); |
|
922 |
if(exts != null && exts.length != 0){ |
|
923 |
List<ICLanguageSetting> list = new ArrayList<ICLanguageSetting>(); |
|
924 |
ICLanguageSetting setting; |
|
925 |
for(int i = 0; i < exts.length; i++){ |
|
926 |
setting = findLanguageSettingForExtension(exts[i], settings/*, src*/); |
|
927 |
if(setting != null) |
|
928 |
list.add(setting); |
|
929 |
} |
|
930 |
return list.toArray(new ICLanguageSetting[list.size()]); |
|
931 |
} |
|
932 |
} |
|
933 |
return EMPTY_LANGUAGE_SETTINGS_ARRAY; |
|
934 |
} |
|
935 |
||
936 |
public ICLanguageSetting findLanguageSettingForExtension(String ext, ICLanguageSetting settings[]/*, boolean src*/){ |
|
937 |
ICLanguageSetting setting; |
|
938 |
for(int i = 0; i < settings.length; i++){ |
|
939 |
setting = settings[i]; |
|
940 |
String exts[] = setting.getSourceExtensions(); |
|
941 |
/* if(src){ |
|
942 |
if(setting.getSourceContentType() == null){ |
|
943 |
exts = setting.getSourceExtensions(); |
|
944 |
} |
|
945 |
} else { |
|
946 |
if(setting.getHeaderContentType() == null){ |
|
947 |
exts = setting.getHeaderExtensions(); |
|
948 |
} |
|
949 |
} |
|
950 |
*/ |
|
951 |
if(exts != null && exts.length != 0){ |
|
952 |
for(int j = 0; j < exts.length; j++){ |
|
953 |
if(ext.equals(exts[j])) |
|
954 |
return setting; |
|
955 |
} |
|
956 |
} |
|
957 |
} |
|
958 |
return null; |
|
959 |
} |
|
960 |
||
961 |
/** |
|
962 |
* Returns a map of configurations elements as discovered from the supplied project |
|
963 |
* description |
|
964 |
* @param des |
|
965 |
* @return Map String -> ICStorageElement: configuration name -> configuration ICStorageElement |
|
966 |
* @throws CoreException |
|
967 |
*/ |
|
968 |
Map<String, ICStorageElement> createCfgStorages(ICProjectDescription des) throws CoreException{ |
|
969 |
LinkedHashMap<String, ICStorageElement> map = new LinkedHashMap<String, ICStorageElement>(); |
|
970 |
ICStorageElement rootElement = des.getStorage(MODULE_ID, false); |
|
971 |
if(rootElement != null){ |
|
972 |
ICStorageElement children[] = rootElement.getChildren(); |
|
973 |
||
974 |
for(int i = 0; i < children.length; i++){ |
|
975 |
ICStorageElement el = children[i]; |
|
976 |
if(CONFIGURATION.equals(el.getName())){ |
|
977 |
String id = el.getAttribute(CConfigurationSpecSettings.ID); |
|
978 |
if(id != null) |
|
979 |
map.put(id, el); |
|
980 |
} |
|
981 |
} |
|
982 |
} |
|
983 |
return map; |
|
984 |
} |
|
985 |
||
986 |
/** |
|
987 |
* Create the configuration storage cfgId in the project description |
|
988 |
* @param storage the root settingsStorage of the project |
|
989 |
* @param cfgId the configuration Id desire |
|
990 |
* @return the cfgId as discovered in the project description or a new ICStorageElement with that Id |
|
991 |
* @throws CoreException on failure to create storage |
|
992 |
*/ |
|
993 |
ICStorageElement createStorage(ICSettingsStorage storage, String cfgId) throws CoreException { |
|
994 |
ICStorageElement rootElement = storage.getStorage(MODULE_ID, true); // throws CoreException |
|
995 |
ICStorageElement children[] = rootElement.getChildren(); |
|
996 |
ICStorageElement element = null; |
|
997 |
||
998 |
for(int i = 0; i < children.length; i++){ |
|
999 |
if(CONFIGURATION.equals(children[i].getName()) |
|
1000 |
&& cfgId.equals(children[i].getAttribute(CConfigurationSpecSettings.ID))){ |
|
1001 |
element = children[i]; |
|
1002 |
break; |
|
1003 |
} |
|
1004 |
} |
|
1005 |
||
1006 |
if(element == null){ |
|
1007 |
element = rootElement.createChild(CONFIGURATION); |
|
1008 |
element.setAttribute(CConfigurationSpecSettings.ID, cfgId); |
|
1009 |
} |
|
1010 |
||
1011 |
return element; |
|
1012 |
} |
|
1013 |
||
1014 |
/** |
|
1015 |
* Creates a new configuration storage based on an existing 'base' storage. |
|
1016 |
* If a configuration with the new ID already exists in the passed in project storage |
|
1017 |
* a CoreException is thrown. |
|
1018 |
* @param storage the setting storage of the current project description |
|
1019 |
* @param cfgId configID of the new configuration - must be unique in |
|
1020 |
* @param base the base (spec settings) storage element from which settings should be copied. |
|
1021 |
* @return ICStorageElement representing the new configuration |
|
1022 |
* @throws CoreException on failure |
|
1023 |
*/ |
|
1024 |
ICStorageElement createStorage(ICSettingsStorage storage, String cfgId, ICStorageElement base) throws CoreException{ |
|
1025 |
ICStorageElement rootElement = storage.getStorage(MODULE_ID, true); |
|
1026 |
ICStorageElement children[] = rootElement.getChildren(); |
|
1027 |
for (ICStorageElement child : children) { |
|
1028 |
if(CONFIGURATION.equals(child.getName()) |
|
1029 |
&& cfgId.equals(child.getAttribute(CConfigurationSpecSettings.ID))) |
|
1030 |
throw ExceptionFactory.createCoreException(MessageFormat |
|
1031 |
.format(SettingsModelMessages.getString("CProjectDescriptionManager.cfgIDAlreadyExists"), //$NON-NLS-1$ |
|
1032 |
new Object[] {cfgId})); |
|
1033 |
} |
|
1034 |
ICStorageElement config = rootElement.importChild(base); |
|
1035 |
config.setAttribute(CConfigurationSpecSettings.ID, cfgId); |
|
1036 |
return config; |
|
1037 |
} |
|
1038 |
||
1039 |
/** |
|
1040 |
* Remove the storage with the supplied configuration Id from the project |
|
1041 |
* @param storage The root settingsStorage of the project |
|
1042 |
* @param cfgId the configuration ID which would be |
|
1043 |
* @throws CoreException |
|
1044 |
*/ |
|
1045 |
void removeStorage(ICSettingsStorage storage, String cfgId) throws CoreException{ |
|
1046 |
ICStorageElement rootElement = storage.getStorage(MODULE_ID, false); |
|
1047 |
if(rootElement != null){ |
|
1048 |
ICStorageElement children[] = rootElement.getChildren(); |
|
1049 |
||
1050 |
for(int i = 0; i < children.length; i++){ |
|
1051 |
if(CONFIGURATION.equals(children[i].getName()) |
|
1052 |
&& cfgId.equals(children[i].getAttribute(CConfigurationSpecSettings.ID))){ |
|
1053 |
rootElement.removeChild(children[i]); |
|
1054 |
break; |
|
1055 |
} |
|
1056 |
} |
|
1057 |
} |
|
1058 |
} |
|
1059 |
||
1060 |
CConfigurationData loadData(ICConfigurationDescription des, IProgressMonitor monitor) throws CoreException{ |
|
1061 |
if(monitor == null) |
|
1062 |
monitor = new NullProgressMonitor(); |
|
1063 |
||
1064 |
CConfigurationDataProvider provider = getProvider(des); |
|
1065 |
return provider.loadConfiguration(des, monitor); |
|
1066 |
} |
|
1067 |
||
1068 |
CConfigurationData applyData(CConfigurationDescriptionCache des, ICConfigurationDescription baseDescription, CConfigurationData base, SettingsContext context, IProgressMonitor monitor) throws CoreException { |
|
1069 |
if(monitor == null) |
|
1070 |
monitor = new NullProgressMonitor(); |
|
1071 |
||
1072 |
CConfigurationDataProvider provider = getProvider(des); |
|
1073 |
context.init(des); |
|
1074 |
return provider.applyConfiguration(des, baseDescription, base, context, monitor); |
|
1075 |
} |
|
1076 |
||
1077 |
void notifyCached(ICConfigurationDescription des, CConfigurationData data, IProgressMonitor monitor) { |
|
1078 |
if(monitor == null) |
|
1079 |
monitor = new NullProgressMonitor(); |
|
1080 |
||
1081 |
try { |
|
1082 |
CConfigurationDataProvider provider = getProvider(des); |
|
1083 |
provider.dataCached(des, data, monitor); |
|
1084 |
} catch (CoreException e){ |
|
1085 |
CCorePlugin.log(e); |
|
1086 |
} |
|
1087 |
} |
|
1088 |
||
1089 |
void removeData(ICConfigurationDescription des, CConfigurationData data, IProgressMonitor monitor) throws CoreException{ |
|
1090 |
if(monitor == null) |
|
1091 |
monitor = new NullProgressMonitor(); |
|
1092 |
||
1093 |
CConfigurationDataProvider provider = getProvider(des); |
|
1094 |
provider.removeConfiguration(des, data, monitor); |
|
1095 |
} |
|
1096 |
||
1097 |
CConfigurationData createData(ICConfigurationDescription des, ICConfigurationDescription baseDescription, CConfigurationData base, boolean clone, IProgressMonitor monitor) throws CoreException{ |
|
1098 |
if(monitor == null) |
|
1099 |
monitor = new NullProgressMonitor(); |
|
1100 |
||
1101 |
CConfigurationDataProvider provider = getProvider(des); |
|
1102 |
return provider.createConfiguration(des, baseDescription, base, clone, monitor); |
|
1103 |
} |
|
1104 |
||
1105 |
private CConfigurationDataProvider getProvider(ICConfigurationDescription des) throws CoreException{ |
|
1106 |
CConfigurationDataProviderDescriptor providerDes = getCfgProviderDescriptor(des); |
|
1107 |
if(providerDes == null) |
|
1108 |
throw ExceptionFactory.createCoreException(SettingsModelMessages.getString("CProjectDescriptionManager.1")); //$NON-NLS-1$ |
|
1109 |
||
1110 |
return providerDes.getProvider(); |
|
1111 |
} |
|
1112 |
||
1113 |
private CConfigurationDataProviderDescriptor getCfgProviderDescriptor(ICConfigurationDescription des){ |
|
1114 |
return getCfgProviderDescriptor(des.getBuildSystemId()); |
|
1115 |
} |
|
1116 |
||
1117 |
private CConfigurationDataProviderDescriptor getCfgProviderDescriptor(String id){ |
|
1118 |
initProviderInfo(); |
|
1119 |
return fProviderMap.get(id); |
|
1120 |
} |
|
1121 |
||
1122 |
private void initProviderInfo(){ |
|
1123 |
if(fProviderMap != null) |
|
1124 |
return; |
|
1125 |
||
1126 |
synchronized (this) { |
|
1127 |
if(fProviderMap != null) |
|
1128 |
return; |
|
1129 |
||
1130 |
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CConfigurationDataProviderDescriptor.DATA_PROVIDER_EXTPOINT_ID); |
|
1131 |
IExtension exts[] = extensionPoint.getExtensions(); |
|
1132 |
fProviderMap = new HashMap<String, CConfigurationDataProviderDescriptor>(exts.length); |
|
1133 |
||
1134 |
for(int i = 0; i < exts.length; i++){ |
|
1135 |
CConfigurationDataProviderDescriptor des = new CConfigurationDataProviderDescriptor(exts[i]); |
|
1136 |
fProviderMap.put(des.getId(), des); |
|
1137 |
} |
|
1138 |
} |
|
1139 |
} |
|
1140 |
||
1141 |
/* CConfigurationSpecSettings createConfigurationSpecSettings(ICConfigurationDescription cfg) throws CoreException{ |
|
1142 |
CConfigurationSpecSettings settings = null; |
|
1143 |
if(cfg instanceof CConfigurationDescriptionCache){ |
|
1144 |
settings = new CConfigurationSpecSettings(cfg, createStorage(cfg.getProjectDescription(), cfg.getId())); |
|
1145 |
} else { |
|
1146 |
ICProjectDescription des = getProjecDescription(cfg.getProjectDescription().getProject(), false); |
|
1147 |
CConfigurationDescriptionCache cache = (CConfigurationDescriptionCache)des.getConfigurationById(cfg.getId()); |
|
1148 |
if(cache != null){ |
|
1149 |
settings = new CConfigurationSpecSettings(cfg, cache.getSpecSettings()); |
|
1150 |
} else { |
|
1151 |
settings = new CConfigurationSpecSettings(cfg, createStorage(cfg.getProjectDescription(), cfg.getId())); |
|
1152 |
} |
|
1153 |
} |
|
1154 |
return settings; |
|
1155 |
} |
|
1156 |
*/ |
|
1157 |
||
1158 |
public ICStorageElement createPreferenceStorage(String key, boolean createEmptyIfNotFound, boolean readOnly) throws CoreException{ |
|
1159 |
try { |
|
1160 |
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
|
1161 |
Document doc = null; |
|
1162 |
Element element = null; |
|
1163 |
InputStream stream = null; |
|
1164 |
||
1165 |
try{ |
|
1166 |
stream = getPreferenceProperty(key); |
|
1167 |
if(stream != null){ |
|
1168 |
doc = builder.parse(stream); |
|
1169 |
||
1170 |
// Get the first element in the project file |
|
1171 |
Node rootElement = doc.getFirstChild(); |
|
1172 |
||
1173 |
if (rootElement.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE) { |
|
1174 |
throw ExceptionFactory.createCoreException(SettingsModelMessages.getString("CProjectDescriptionManager.2")); //$NON-NLS-1$ |
|
1175 |
} else { |
|
1176 |
String fileVersion = rootElement.getNodeValue(); |
|
1177 |
Version version = new Version(fileVersion); |
|
1178 |
// Make sure that the version is compatible with the manager |
|
1179 |
// Version must between min version and current version inclusive |
|
1180 |
if (MIN_DESCRIPTION_VERSION.compareTo(version) > 0 || DESCRIPTION_VERSION.compareTo(version) < 0) { |
|
1181 |
throw ExceptionFactory.createCoreException(SettingsModelMessages.getString("CProjectDescriptionManager.3")); //$NON-NLS-1$ |
|
1182 |
} |
|
1183 |
} |
|
1184 |
||
1185 |
// Now get the project root element (there should be only one) |
|
1186 |
NodeList nodes = doc.getElementsByTagName(ROOT_PREFERENCE_ELEMENT); |
|
1187 |
if (nodes.getLength() == 0) |
|
1188 |
throw ExceptionFactory.createCoreException(SettingsModelMessages.getString("CProjectDescriptionManager.4")); //$NON-NLS-1$ |
|
1189 |
Node node = nodes.item(0); |
|
1190 |
if(node.getNodeType() != Node.ELEMENT_NODE) |
|
1191 |
throw ExceptionFactory.createCoreException(SettingsModelMessages.getString("CProjectDescriptionManager.5")); //$NON-NLS-1$ |
|
1192 |
element = (Element)node; |
|
1193 |
} else if(!createEmptyIfNotFound){ |
|
1194 |
throw ExceptionFactory.createCoreException(SettingsModelMessages.getString("CProjectDescriptionManager.6")); //$NON-NLS-1$ |
|
1195 |
} |
|
1196 |
} catch (FactoryConfigurationError e) { |
|
1197 |
if(!createEmptyIfNotFound) |
|
1198 |
throw ExceptionFactory.createCoreException(e.getLocalizedMessage()); |
|
1199 |
} catch (SAXException e) { |
|
1200 |
if(!createEmptyIfNotFound) |
|
1201 |
throw ExceptionFactory.createCoreException(e); |
|
1202 |
} catch (IOException e) { |
|
1203 |
if(!createEmptyIfNotFound) |
|
1204 |
throw ExceptionFactory.createCoreException(e); |
|
1205 |
} finally { |
|
1206 |
if(stream != null){ |
|
1207 |
try { |
|
1208 |
stream.close(); |
|
1209 |
} catch (IOException e) { |
|
1210 |
} |
|
1211 |
} |
|
1212 |
} |
|
1213 |
||
1214 |
if(element == null) { |
|
1215 |
doc = builder.newDocument(); |
|
1216 |
ProcessingInstruction instruction = doc.createProcessingInstruction(VERSION_ELEMENT_NAME, DESCRIPTION_VERSION.toString()); |
|
1217 |
doc.appendChild(instruction); |
|
1218 |
element = doc.createElement(ROOT_PREFERENCE_ELEMENT); |
|
1219 |
doc.appendChild(element); |
|
1220 |
} |
|
1221 |
return new InternalXmlStorageElement(element, null, false, readOnly); |
|
1222 |
} catch (ParserConfigurationException e) { |
|
1223 |
throw ExceptionFactory.createCoreException(e); |
|
1224 |
} |
|
1225 |
} |
|
1226 |
||
1227 |
private InputStream getPreferenceProperty(String key) { |
|
1228 |
InputStream stream = null; |
|
1229 |
File file = getPreferenceFile(key); |
|
1230 |
if (file.exists()) { |
|
1231 |
try { |
|
1232 |
stream = new FileInputStream(file); |
|
1233 |
} catch (FileNotFoundException e) { |
|
1234 |
CCorePlugin.log(e); |
|
1235 |
} |
|
1236 |
} |
|
1237 |
return stream; |
|
1238 |
} |
|
1239 |
||
1240 |
private File getPreferenceFile(String key){ |
|
1241 |
IPath path = CCorePlugin.getDefault().getStateLocation(); |
|
1242 |
path = path.append(key); |
|
1243 |
return path.toFile(); |
|
1244 |
} |
|
1245 |
||
1246 |
public static File toLocalFile(URI uri, IProgressMonitor monitor) throws CoreException { |
|
1247 |
IFileStore fileStore = EFS.getStore(uri); |
|
1248 |
File localFile = fileStore.toLocalFile(EFS.NONE, monitor); |
|
1249 |
if (localFile ==null) |
|
1250 |
// non local file system |
|
1251 |
localFile= fileStore.toLocalFile(EFS.CACHE, monitor); |
|
1252 |
return localFile; |
|
1253 |
} |
|
1254 |
||
1255 |
ICDescriptionDelta createDelta(ICProjectDescription newDescription, ICProjectDescription oldDescription){ |
|
1256 |
CProjectDescriptionDelta delta = new CProjectDescriptionDelta(newDescription, oldDescription); |
|
1257 |
||
1258 |
if(delta.getDeltaKind() == ICDescriptionDelta.CHANGED){ |
|
1259 |
ICConfigurationDescription[] cfgs = newDescription.getConfigurations(); |
|
1260 |
for(int i = 0; i < cfgs.length; i++){ |
|
1261 |
ICConfigurationDescription oldCfg = oldDescription.getConfigurationById(cfgs[i].getId()); |
|
1262 |
CProjectDescriptionDelta cfgDelta = createDelta(cfgs[i], oldCfg); |
|
1263 |
if(cfgDelta != null){ |
|
1264 |
delta.addChild(cfgDelta); |
|
1265 |
} |
|
1266 |
} |
|
1267 |
||
1268 |
cfgs = oldDescription.getConfigurations(); |
|
1269 |
for(int i = 0; i < cfgs.length; i++){ |
|
1270 |
ICConfigurationDescription newCfg = newDescription.getConfigurationById(cfgs[i].getId()); |
|
1271 |
if(newCfg == null) |
|
1272 |
delta.addChild(createDelta(null, cfgs[i])); |
|
1273 |
} |
|
1274 |
||
1275 |
if(checkCfgChange(newDescription, oldDescription, true)) |
|
1276 |
delta.addChangeFlags(ICDescriptionDelta.ACTIVE_CFG); |
|
1277 |
||
1278 |
if(checkCfgChange(newDescription, oldDescription, false)) |
|
1279 |
delta.addChangeFlags(ICDescriptionDelta.INDEX_CFG); |
|
1280 |
||
1281 |
if(oldDescription.isCdtProjectCreating() && !newDescription.isCdtProjectCreating()) |
|
1282 |
delta.addChangeFlags(ICDescriptionDelta.PROJECT_CREAION_COMPLETED); |
|
1283 |
} |
|
1284 |
return delta.isEmpty() ? null : delta; |
|
1285 |
} |
|
1286 |
||
1287 |
private boolean checkCfgChange(ICProjectDescription newDes, ICProjectDescription oldDes, boolean active){ |
|
1288 |
ICConfigurationDescription newCfg, oldCfg; |
|
1289 |
||
1290 |
if(active){ |
|
1291 |
newCfg = newDes.getActiveConfiguration(); |
|
1292 |
oldCfg = oldDes.getActiveConfiguration(); |
|
1293 |
} else { |
|
1294 |
newCfg = newDes.getDefaultSettingConfiguration(); |
|
1295 |
oldCfg = oldDes.getDefaultSettingConfiguration(); |
|
1296 |
} |
|
1297 |
||
1298 |
if(newCfg == null){ |
|
1299 |
return oldCfg != null; |
|
1300 |
} else if (oldCfg == null){ |
|
1301 |
return true; |
|
1302 |
} |
|
1303 |
return !newCfg.getId().equals(oldCfg.getId()); |
|
1304 |
} |
|
1305 |
||
1306 |
/* void postProcessNewDescriptionCache(CProjectDescription des, ICProjectDescriptionDelta delta){ |
|
1307 |
if(delta == null && delta.getDeltaKind() != ICProjectDescriptionDelta.CHANGED) |
|
1308 |
return; |
|
1309 |
||
1310 |
ICConfigurationDescription indexCfg = des.getIndexConfiguration(); |
|
1311 |
ICConfigurationDescription activeCfg = des.getActiveConfiguration(); |
|
1312 |
ICProjectDescriptionDelta activeCfgDelta = findDelta(activeCfg.getId(), delta); |
|
1313 |
if(indexCfg != activeCfg){ |
|
1314 |
switch(activeCfgDelta.getDeltaKind()){ |
|
1315 |
case ICProjectDescriptionDelta.CHANGED: |
|
1316 |
des.setIndexConfiguration(activeCfg); |
|
1317 |
} |
|
1318 |
} |
|
1319 |
||
1320 |
||
1321 |
} |
|
1322 |
*/ |
|
1323 |
private ICDescriptionDelta findDelta(String id, ICDescriptionDelta delta){ |
|
1324 |
ICDescriptionDelta children[] = delta.getChildren(); |
|
1325 |
ICSettingObject obj; |
|
1326 |
for(int i = 0; i < children.length; i++){ |
|
1327 |
obj = children[i].getSetting(); |
|
1328 |
if(obj.getId().equals(id)) |
|
1329 |
return children[i]; |
|
1330 |
} |
|
1331 |
return null; |
|
1332 |
} |
|
1333 |
||
1334 |
public int calculateDescriptorFlags(ICConfigurationDescription newCfg, ICConfigurationDescription oldCfg){ |
|
1335 |
try { |
|
1336 |
int flags = 0; |
|
1337 |
CConfigurationSpecSettings newSettings = ((IInternalCCfgInfo)newCfg).getSpecSettings(); |
|
1338 |
CConfigurationSpecSettings oldSettings = ((IInternalCCfgInfo)oldCfg).getSpecSettings(); |
|
1339 |
String newId = newSettings.getCOwnerId(); |
|
1340 |
String oldId = oldSettings.getCOwnerId(); |
|
1341 |
if(!CDataUtil.objectsEqual(newId, oldId)) |
|
1342 |
flags |= ICDescriptionDelta.OWNER; |
|
1343 |
||
1344 |
Map<String, CConfigExtensionReference[]> newMap = newSettings.getExtensionMapCopy(); |
|
1345 |
Map<String, CConfigExtensionReference[]> oldMap = oldSettings.getExtensionMapCopy(); |
|
1346 |
||
1347 |
for(Iterator<Map.Entry<String, CConfigExtensionReference[]>> iter = newMap.entrySet().iterator(); iter.hasNext();){ |
|
1348 |
Map.Entry entry = iter.next(); |
|
1349 |
iter.remove(); |
|
1350 |
CConfigExtensionReference[] oldRefs = oldMap.remove(entry.getKey()); |
|
1351 |
if(oldRefs == null){ |
|
1352 |
flags |= ICDescriptionDelta.EXT_REF; |
|
1353 |
break; |
|
1354 |
} |
|
1355 |
||
1356 |
CConfigExtensionReference[] newRefs = (CConfigExtensionReference[])entry.getValue(); |
|
1357 |
if(newRefs.length != oldRefs.length){ |
|
1358 |
flags |= ICDescriptionDelta.EXT_REF; |
|
1359 |
break; |
|
1360 |
} |
|
1361 |
||
1362 |
Set<CConfigExtensionReference> newSet = new HashSet<CConfigExtensionReference>(Arrays.asList(newRefs)); |
|
1363 |
Set<CConfigExtensionReference> oldSet = new HashSet<CConfigExtensionReference>(Arrays.asList(oldRefs)); |
|
1364 |
if(newSet.size() != oldSet.size()){ |
|
1365 |
flags |= ICDescriptionDelta.EXT_REF; |
|
1366 |
break; |
|
1367 |
} |
|
1368 |
||
1369 |
newSet.removeAll(oldSet); |
|
1370 |
if(newSet.size() != 0){ |
|
1371 |
flags |= ICDescriptionDelta.EXT_REF; |
|
1372 |
break; |
|
1373 |
} |
|
1374 |
} |
|
1375 |
||
1376 |
return flags; |
|
1377 |
} catch (CoreException e) { |
|
1378 |
CCorePlugin.log(e); |
|
1379 |
} |
|
1380 |
return 0; |
|
1381 |
} |
|
1382 |
||
1383 |
public CProjectDescriptionDelta createDelta(ICConfigurationDescription newCfg, ICConfigurationDescription oldCfg){ |
|
1384 |
CProjectDescriptionDelta delta = new CProjectDescriptionDelta(newCfg, oldCfg); |
|
1385 |
IInternalCCfgInfo newInfo = (IInternalCCfgInfo)newCfg; |
|
1386 |
IInternalCCfgInfo oldInfo = (IInternalCCfgInfo)oldCfg; |
|
1387 |
if(delta.getDeltaKind() == ICDescriptionDelta.CHANGED){ |
|
1388 |
ICFolderDescription[] foDess = newCfg.getFolderDescriptions(); |
|
1389 |
for(int i = 0; i < foDess.length; i++){ |
|
1390 |
ICResourceDescription oldDes = oldCfg.getResourceDescription(foDess[i].getPath(), true); |
|
1391 |
if(oldDes != null && oldDes.getType() == ICSettingBase.SETTING_FOLDER){ |
|
1392 |
CProjectDescriptionDelta foDelta = createDelta(foDess[i], (ICFolderDescription)oldDes); |
|
1393 |
if(foDelta != null) |
|
1394 |
delta.addChild(foDelta); |
|
1395 |
} else { |
|
1396 |
delta.addChild(createDelta(foDess[i], null)); |
|
1397 |
} |
|
1398 |
} |
|
1399 |
||
1400 |
foDess = oldCfg.getFolderDescriptions(); |
|
1401 |
for(int i = 0; i < foDess.length; i++){ |
|
1402 |
ICResourceDescription newDes = newCfg.getResourceDescription(foDess[i].getPath(), true); |
|
1403 |
if(newDes == null || newDes.getType() != ICSettingBase.SETTING_FOLDER){ |
|
1404 |
delta.addChild(createDelta(null, foDess[i])); |
|
1405 |
} |
|
1406 |
} |
|
1407 |
||
1408 |
ICFileDescription[] fiDess = newCfg.getFileDescriptions(); |
|
1409 |
for(int i = 0; i < fiDess.length; i++){ |
|
1410 |
ICResourceDescription oldDes = oldCfg.getResourceDescription(fiDess[i].getPath(), true); |
|
1411 |
if(oldDes != null && oldDes.getType() == ICSettingBase.SETTING_FILE){ |
|
1412 |
CProjectDescriptionDelta fiDelta = createDelta(fiDess[i], (ICFileDescription)oldDes); |
|
1413 |
if(fiDelta != null) |
|
1414 |
delta.addChild(fiDelta); |
|
1415 |
} else { |
|
1416 |
delta.addChild(createDelta(fiDess[i], null)); |
|
1417 |
} |
|
1418 |
} |
|
1419 |
||
1420 |
fiDess = oldCfg.getFileDescriptions(); |
|
1421 |
for(int i = 0; i < fiDess.length; i++){ |
|
1422 |
ICResourceDescription newDes = newCfg.getResourceDescription(fiDess[i].getPath(), true); |
|
1423 |
if(newDes == null || newDes.getType() != ICSettingBase.SETTING_FILE){ |
|
1424 |
delta.addChild(createDelta(null, fiDess[i])); |
|
1425 |
} |
|
1426 |
} |
|
1427 |
||
1428 |
CProjectDescriptionDelta tpsDelta = createDelta(newCfg.getTargetPlatformSetting(), oldCfg.getTargetPlatformSetting()); |
|
1429 |
if(tpsDelta != null) |
|
1430 |
delta.addChild(tpsDelta); |
|
1431 |
||
1432 |
if(!newCfg.getName().equals(oldCfg.getName())){ |
|
1433 |
delta.addChangeFlags(ICDescriptionDelta.NAME); |
|
1434 |
} |
|
1435 |
||
1436 |
ICSourceEntry newEntries[] = newCfg.getSourceEntries(); |
|
1437 |
ICSourceEntry oldEntries[] = oldCfg.getSourceEntries(); |
|
1438 |
||
1439 |
if(newEntries.length > oldEntries.length){ |
|
1440 |
delta.addChangeFlags(ICDescriptionDelta.SOURCE_ADDED); |
|
1441 |
} else { |
|
1442 |
ICSourceEntry newEntry; |
|
1443 |
for(int i = 0; i < newEntries.length; i++){ |
|
1444 |
boolean found = false; |
|
1445 |
newEntry = newEntries[i]; |
|
1446 |
for(int j = 0; j < oldEntries.length; j++){ |
|
1447 |
if(newEntry.equals(oldEntries[j])){ |
|
1448 |
found = true; |
|
1449 |
break; |
|
1450 |
} |
|
1451 |
} |
|
1452 |
||
1453 |
if(!found){ |
|
1454 |
delta.addChangeFlags(ICDescriptionDelta.SOURCE_ADDED); |
|
1455 |
break; |
|
1456 |
} |
|
1457 |
} |
|
1458 |
} |
|
1459 |
||
1460 |
if(oldEntries.length > newEntries.length){ |
|
1461 |
delta.addChangeFlags(ICDescriptionDelta.SOURCE_REMOVED); |
|
1462 |
} else { |
|
1463 |
ICSourceEntry oldEntry; |
|
1464 |
for(int i = 0; i < oldEntries.length; i++){ |
|
1465 |
boolean found = false; |
|
1466 |
oldEntry = oldEntries[i]; |
|
1467 |
for(int j = 0; j < newEntries.length; j++){ |
|
1468 |
if(oldEntry.equals(newEntries[j])){ |
|
1469 |
found = true; |
|
1470 |
break; |
|
1471 |
} |
|
1472 |
} |
|
1473 |
||
1474 |
if(!found){ |
|
1475 |
delta.addChangeFlags(ICDescriptionDelta.SOURCE_REMOVED); |
|
1476 |
break; |
|
1477 |
} |
|
1478 |
} |
|
1479 |
} |
|
1480 |
||
1481 |
try { |
|
1482 |
CConfigurationSpecSettings newSettings = newInfo.getSpecSettings(); |
|
1483 |
CConfigurationSpecSettings oldSettings = oldInfo.getSpecSettings(); |
|
1484 |
if(!newSettings.extRefSettingsEqual(oldSettings)) |
|
1485 |
delta.addChangeFlags(ICDescriptionDelta.EXT_REF); |
|
1486 |
} catch (CoreException e){ |
|
1487 |
CCorePlugin.log(e); |
|
1488 |
} |
|
1489 |
||
1490 |
||
1491 |
calculateCfgExtSettingsDelta(delta); |
|
1492 |
||
1493 |
int drFlags = calculateDescriptorFlags(newCfg, oldCfg); |
|
1494 |
if(drFlags != 0) |
|
1495 |
delta.addChangeFlags(drFlags); |
|
1496 |
} |
|
1497 |
||
1498 |
return delta.isEmpty() ? null : delta; |
|
1499 |
} |
|
1500 |
||
1501 |
private void calculateCfgExtSettingsDelta(CProjectDescriptionDelta delta){ |
|
1502 |
ICConfigurationDescription newDes = (ICConfigurationDescription)delta.getNewSetting(); |
|
1503 |
ICConfigurationDescription oldDes = (ICConfigurationDescription)delta.getOldSetting(); |
|
1504 |
ExtSettingsDelta[] deltas = getSettingChange(newDes, oldDes); |
|
1505 |
int flags = 0; |
|
1506 |
int addedRemoved = ICDescriptionDelta.EXTERNAL_SETTINGS_ADDED | ICDescriptionDelta.EXTERNAL_SETTINGS_REMOVED; |
|
1507 |
if(deltas != null ){ |
|
1508 |
for(int i = 0; i < deltas.length; i++){ |
|
1509 |
ICSettingEntry[][] d = deltas[i].getEntriesDelta(); |
|
1510 |
if(d[0] != null) |
|
1511 |
flags |= ICDescriptionDelta.EXTERNAL_SETTINGS_ADDED; |
|
1512 |
if(d[1] != null) |
|
1513 |
flags |= ICDescriptionDelta.EXTERNAL_SETTINGS_REMOVED; |
|
1514 |
||
1515 |
if((flags & (addedRemoved)) == addedRemoved) |
|
1516 |
break; |
|
1517 |
} |
|
1518 |
// delta.setExtSettingsDeltas(deltas); |
|
1519 |
if(flags != 0) |
|
1520 |
delta.addChangeFlags(flags); |
|
1521 |
} |
|
1522 |
||
1523 |
int cfgRefFlags = calcRefChangeFlags(newDes, oldDes); |
|
1524 |
if(cfgRefFlags != 0) |
|
1525 |
delta.addChangeFlags(cfgRefFlags); |
|
1526 |
} |
|
1527 |
||
1528 |
private int calcRefChangeFlags(ICConfigurationDescription newDes, ICConfigurationDescription oldDes){ |
|
1529 |
Map<String, String> newMap = newDes != null ? newDes.getReferenceInfo() : null; |
|
1530 |
Map<String, String> oldMap = oldDes != null ? oldDes.getReferenceInfo() : null; |
|
1531 |
||
1532 |
int flags = 0; |
|
1533 |
if(newMap == null || newMap.size() == 0){ |
|
1534 |
if(oldMap != null && oldMap.size() != 0){ |
|
1535 |
flags = ICDescriptionDelta.CFG_REF_REMOVED; |
|
1536 |
} |
|
1537 |
} else { |
|
1538 |
if(oldMap == null || oldMap.size() == 0){ |
|
1539 |
flags = ICDescriptionDelta.CFG_REF_ADDED; |
|
1540 |
} else { |
|
1541 |
boolean stop = false; |
|
1542 |
for(Iterator iter = newMap.entrySet().iterator(); iter.hasNext();){ |
|
1543 |
Map.Entry newEntry = (Map.Entry)iter.next(); |
|
1544 |
Object newProj = newEntry.getKey(); |
|
1545 |
Object newCfg = newEntry.getValue(); |
|
1546 |
Object oldCfg = oldMap.remove(newProj); |
|
1547 |
if(!newCfg.equals(oldCfg)){ |
|
1548 |
flags |= ICDescriptionDelta.CFG_REF_ADDED; |
|
1549 |
if(oldCfg != null){ |
|
1550 |
flags |= ICDescriptionDelta.CFG_REF_REMOVED; |
|
1551 |
stop = true; |
|
1552 |
} |
|
1553 |
if(stop) |
|
1554 |
break; |
|
1555 |
} |
|
1556 |
} |
|
1557 |
||
1558 |
if(!oldMap.isEmpty()) |
|
1559 |
flags |= ICDescriptionDelta.CFG_REF_REMOVED; |
|
1560 |
} |
|
1561 |
} |
|
1562 |
||
1563 |
return flags; |
|
1564 |
} |
|
1565 |
||
1566 |
||
1567 |
private ExtSettingsDelta[] getSettingChange(ICConfigurationDescription newDes, ICConfigurationDescription oldDes){ |
|
1568 |
CExternalSetting[] newSettings = newDes != null ? (CExternalSetting[])newDes.getExternalSettings() : null; |
|
1569 |
CExternalSetting[] oldSettings = oldDes != null ? (CExternalSetting[])oldDes.getExternalSettings() : null; |
|
1570 |
return CExternalSettinsDeltaCalculator.getInstance().getSettingChange(newSettings, oldSettings); |
|
1571 |
} |
|
1572 |
||
1573 |
private CProjectDescriptionDelta createDelta(ICFolderDescription newFo, ICFolderDescription oldFo){ |
|
1574 |
CProjectDescriptionDelta delta = new CProjectDescriptionDelta(newFo, oldFo); |
|
1575 |
||
1576 |
if(delta.getDeltaKind() == ICDescriptionDelta.CHANGED){ |
|
1577 |
ICLanguageSetting newLss[] = newFo.getLanguageSettings(); |
|
1578 |
ICLanguageSetting oldLss[] = oldFo.getLanguageSettings(); |
|
1579 |
List<ICLanguageSetting> newList = new ArrayList<ICLanguageSetting>(Arrays.asList(newLss)); |
|
1580 |
List<ICLanguageSetting> oldList = new ArrayList<ICLanguageSetting>(Arrays.asList(oldLss)); |
|
1581 |
List<ICLanguageSetting[]> matched = sortSettings(newList, oldList); |
|
1582 |
||
1583 |
for(Iterator<ICLanguageSetting[]> iter = matched.iterator(); iter.hasNext();){ |
|
1584 |
ICLanguageSetting[] match = iter.next(); |
|
1585 |
CProjectDescriptionDelta lsDelta = createDelta(match[0], match[1]); |
|
1586 |
if(lsDelta != null) |
|
1587 |
delta.addChild(lsDelta); |
|
1588 |
} |
|
1589 |
||
1590 |
for(Iterator<ICLanguageSetting> iter = newList.iterator(); iter.hasNext();){ |
|
1591 |
ICLanguageSetting added = iter.next(); |
|
1592 |
delta.addChild(createDelta(added, null)); |
|
1593 |
} |
|
1594 |
||
1595 |
for(Iterator<ICLanguageSetting> iter = oldList.iterator(); iter.hasNext();){ |
|
1596 |
ICLanguageSetting removed = iter.next(); |
|
1597 |
delta.addChild(createDelta(null, removed)); |
|
1598 |
} |
|
1599 |
||
1600 |
// HashMap oldMap = new HashMap(); |
|
1601 |
// for(int i = 0; i < oldLss.length; i++){ |
|
1602 |
// oldMap.put(oldLss[i].getId(), oldLss[i]); |
|
1603 |
// } |
|
1604 |
||
1605 |
// for(int i = 0; i < newLss.length; i++){ |
|
1606 |
// ICLanguageSetting oldLs = (ICLanguageSetting)oldMap.remove(newLss[i].getId()); |
|
1607 |
// CProjectDescriptionDelta lsDelta = createDelta(newLss[i], oldLs); |
|
1608 |
// if(lsDelta != null) |
|
1609 |
// delta.addChild(lsDelta); |
|
1610 |
// } |
|
1611 |
||
1612 |
// if(!oldMap.isEmpty()){ |
|
1613 |
// for(Iterator iter = oldMap.values().iterator(); iter.hasNext();){ |
|
1614 |
// delta.addChild(createDelta(null, (ICLanguageSetting)iter.next())); |
|
1615 |
// } |
|
1616 |
// } |
|
1617 |
||
1618 |
// if(!newFo.getPath().equals(oldFo.getPath())) |
|
1619 |
// delta.addChangeFlags(ICProjectDescriptionDelta.PATH); |
|
1620 |
||
1621 |
if(newFo.isExcluded() != oldFo.isExcluded()) |
|
1622 |
delta.addChangeFlags(ICDescriptionDelta.EXCLUDE); |
|
1623 |
} |
|
1624 |
||
1625 |
return delta.isEmpty() ? null : delta; |
|
1626 |
} |
|
1627 |
||
1628 |
private List<ICLanguageSetting[]> sortSettings(List<ICLanguageSetting> settings1, |
|
1629 |
List<ICLanguageSetting> settings2){ |
|
1630 |
ICLanguageSetting setting1; |
|
1631 |
ICLanguageSetting setting2; |
|
1632 |
List<ICLanguageSetting[]> result = new ArrayList<ICLanguageSetting[]>(); |
|
1633 |
for(Iterator<ICLanguageSetting> iter1 = settings1.iterator(); iter1.hasNext();){ |
|
1634 |
setting1 = iter1.next(); |
|
1635 |
for(Iterator<ICLanguageSetting> iter2 = settings2.iterator(); iter2.hasNext();){ |
|
1636 |
setting2 = iter2.next(); |
|
1637 |
||
1638 |
if(setting2.getId().equals(setting1.getId())){ |
|
1639 |
iter1.remove(); |
|
1640 |
iter2.remove(); |
|
1641 |
ICLanguageSetting [] match = new ICLanguageSetting[2]; |
|
1642 |
match[0] = setting1; |
|
1643 |
match[1] = setting2; |
|
1644 |
result.add(match); |
|
1645 |
break; |
|
1646 |
} |
|
1647 |
} |
|
1648 |
} |
|
1649 |
||
1650 |
for(Iterator<ICLanguageSetting> iter1 = settings1.iterator(); iter1.hasNext();){ |
|
1651 |
setting1 = iter1.next(); |
|
1652 |
String lId = setting1.getLanguageId(); |
|
1653 |
if(lId != null){ |
|
1654 |
for(Iterator<ICLanguageSetting> iter2 = settings2.iterator(); iter2.hasNext();){ |
|
1655 |
setting2 = iter2.next(); |
|
1656 |
||
1657 |
if(lId.equals(setting2.getLanguageId())){ |
|
1658 |
iter1.remove(); |
|
1659 |
iter2.remove(); |
|
1660 |
ICLanguageSetting [] match = new ICLanguageSetting[2]; |
|
1661 |
match[0] = setting1; |
|
1662 |
match[1] = setting2; |
|
1663 |
result.add(match); |
|
1664 |
break; |
|
1665 |
} |
|
1666 |
} |
|
1667 |
} |
|
1668 |
} |
|
1669 |
||
1670 |
for(Iterator<ICLanguageSetting> iter1 = settings1.iterator(); iter1.hasNext();){ |
|
1671 |
setting1 = iter1.next(); |
|
1672 |
String cTypeIds1[] = setting1.getSourceContentTypeIds(); |
|
1673 |
if(cTypeIds1.length != 0){ |
|
1674 |
for(Iterator<ICLanguageSetting> iter2 = settings2.iterator(); iter2.hasNext();){ |
|
1675 |
setting2 = iter2.next(); |
|
1676 |
if(Arrays.equals(cTypeIds1, setting2.getSourceContentTypeIds())){ |
|
1677 |
iter1.remove(); |
|
1678 |
iter2.remove(); |
|
1679 |
ICLanguageSetting [] match = new ICLanguageSetting[2]; |
|
1680 |
match[0] = setting1; |
|
1681 |
match[1] = setting2; |
|
1682 |
result.add(match); |
|
1683 |
break; |
|
1684 |
} |
|
1685 |
} |
|
1686 |
} |
|
1687 |
} |
|
1688 |
||
1689 |
for(Iterator<ICLanguageSetting> iter1 = settings1.iterator(); iter1.hasNext();){ |
|
1690 |
setting1 = iter1.next(); |
|
1691 |
if(setting1.getSourceContentTypeIds().length == 0){ |
|
1692 |
String srcExts[] = setting1.getSourceExtensions(); |
|
1693 |
if(srcExts.length != 0){ |
|
1694 |
for(Iterator<ICLanguageSetting> iter2 = settings2.iterator(); iter2.hasNext();){ |
|
1695 |
setting2 = iter2.next(); |
|
1696 |
if(setting2.getSourceContentTypeIds().length == 0){ |
|
1697 |
if(Arrays.equals(srcExts, setting2.getSourceExtensions())){ |
|
1698 |
iter1.remove(); |
|
1699 |
iter2.remove(); |
|
1700 |
ICLanguageSetting [] match = new ICLanguageSetting[2]; |
|
1701 |
match[0] = setting1; |
|
1702 |
match[1] = setting2; |
|
1703 |
result.add(match); |
|
1704 |
break; |
|
1705 |
} |
|
1706 |
} |
|
1707 |
} |
|
1708 |
} |
|
1709 |
} |
|
1710 |
} |
|
1711 |
return result; |
|
1712 |
} |
|
1713 |
||
1714 |
private CProjectDescriptionDelta createDelta(ICFileDescription newFi, ICFileDescription oldFi){ |
|
1715 |
CProjectDescriptionDelta delta = new CProjectDescriptionDelta(newFi, oldFi); |
|
1716 |
||
1717 |
if(delta.getDeltaKind() == ICDescriptionDelta.CHANGED){ |
|
1718 |
CProjectDescriptionDelta lsDelta = createDelta(newFi.getLanguageSetting(), oldFi.getLanguageSetting()); |
|
1719 |
if(lsDelta != null) |
|
1720 |
delta.addChild(lsDelta); |
|
1721 |
||
1722 |
// if(!newFi.getPath().equals(oldFi.getPath())) |
|
1723 |
// delta.addChangeFlags(ICProjectDescriptionDelta.PATH); |
|
1724 |
||
1725 |
if(newFi.isExcluded() != oldFi.isExcluded()) |
|
1726 |
delta.addChangeFlags(ICDescriptionDelta.EXCLUDE); |
|
1727 |
} |
|
1728 |
||
1729 |
return delta.isEmpty() ? null : delta; |
|
1730 |
} |
|
1731 |
||
1732 |
private CProjectDescriptionDelta createDelta(ICLanguageSetting newLs, ICLanguageSetting oldLs){ |
|
1733 |
CProjectDescriptionDelta delta = new CProjectDescriptionDelta(newLs, oldLs); |
|
1734 |
||
1735 |
if(delta.getDeltaKind() == ICDescriptionDelta.CHANGED){ |
|
1736 |
int kinds[] = KindBasedStore.getLanguageEntryKinds(); |
|
1737 |
int kind; |
|
1738 |
int addedKinds = 0; |
|
1739 |
int removedKinds = 0; |
|
1740 |
int reorderedKinds = 0; |
|
1741 |
for(int i = 0; i < kinds.length; i++){ |
|
1742 |
kind = kinds[i]; |
|
1743 |
ICLanguageSettingEntry newEntries[] = newLs.getSettingEntries(kind); |
|
1744 |
ICLanguageSettingEntry oldEntries[] = oldLs.getSettingEntries(kind); |
|
1745 |
boolean[] change = calculateSettingsChanges(newEntries, oldEntries); |
|
1746 |
||
1747 |
if(change[0]) |
|
1748 |
addedKinds |= kind; |
|
1749 |
if(change[1]) |
|
1750 |
removedKinds |= kind; |
|
1751 |
if(change[2]) |
|
1752 |
reorderedKinds |= kind; |
|
1753 |
} |
|
1754 |
delta.setAddedLanguageEntriesKinds(addedKinds); |
|
1755 |
delta.setRemovedLanguageEntriesKinds(removedKinds); |
|
1756 |
delta.setReorderedLanguageEntriesKinds(reorderedKinds); |
|
1757 |
||
1758 |
String[] newCtIds = newLs.getSourceContentTypeIds(); |
|
1759 |
String[] oldCtIds = oldLs.getSourceContentTypeIds(); |
|
1760 |
||
1761 |
if(!Arrays.equals(newCtIds, oldCtIds)) |
|
1762 |
delta.addChangeFlags(ICDescriptionDelta.SOURCE_CONTENT_TYPE); |
|
1763 |
||
1764 |
||
1765 |
String[] newExts = newLs.getSourceExtensions(); |
|
1766 |
String[] oldExts = oldLs.getSourceExtensions(); |
|
1767 |
if(!Arrays.equals(newExts, oldExts)) |
|
1768 |
delta.addChangeFlags(ICDescriptionDelta.SOURCE_ENTENSIONS); |
|
1769 |
||
1770 |
||
1771 |
// newCt = newLs.getHeaderContentType(); |
|
1772 |
// oldCt = oldLs.getHeaderContentType(); |
|
1773 |
||
1774 |
// if(!compare(newCt, oldCt)) |
|
1775 |
// delta.addChangeFlags(ICDescriptionDelta.HEADER_CONTENT_TYPE); |
|
1776 |
||
1777 |
// newExts = newLs.getHeaderExtensions(); |
|
1778 |
// oldExts = oldLs.getHeaderExtensions(); |
|
1779 |
// if(!Arrays.equals(newExts, oldExts)) |
|
1780 |
// delta.addChangeFlags(ICDescriptionDelta.HEADER_ENTENSIONS); |
|
1781 |
} |
|
1782 |
||
1783 |
return delta.isEmpty() ? null : delta; |
|
1784 |
} |
|
1785 |
||
1786 |
private boolean[] calculateSettingsChanges(ICLanguageSettingEntry newEntries[], ICLanguageSettingEntry oldEntries[]) { |
|
1787 |
boolean result[] = new boolean[3]; |
|
1788 |
||
1789 |
// if nothing was known before do not generate any deltas. |
|
1790 |
if (oldEntries == null) { |
|
1791 |
return result; |
|
1792 |
} |
|
1793 |
// Sanity checks |
|
1794 |
if (newEntries == null) { |
|
1795 |
newEntries = EMPTY_LANGUAGE_SETTINGS_ENTRIES_ARRAY; |
|
1796 |
} |
|
1797 |
||
52
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1798 |
Set<ICLanguageSettingEntry> newEntrySet = new HashSet<ICLanguageSettingEntry>(Arrays.asList(newEntries)); |
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1799 |
Set<ICLanguageSettingEntry> oldEntrySet = new HashSet<ICLanguageSettingEntry>(Arrays.asList(oldEntries)); |
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1800 |
|
37 | 1801 |
// Check the removed entries. |
52
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1802 |
for (ICLanguageSettingEntry oldEntry : oldEntries) { |
37 | 1803 |
boolean found = false; |
52
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1804 |
if (newEntrySet.contains(oldEntry)) { |
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1805 |
found = true; |
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1806 |
break; |
37 | 1807 |
} |
1808 |
if(!found){ |
|
1809 |
result[1] = true; |
|
1810 |
break; |
|
1811 |
} |
|
1812 |
} |
|
1813 |
||
1814 |
// Check the new entries. |
|
52
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1815 |
for (ICLanguageSettingEntry newEntry : newEntries) { |
37 | 1816 |
boolean found = false; |
52
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1817 |
if (oldEntrySet.contains(newEntry)) { |
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1818 |
found = true; |
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1819 |
break; |
37 | 1820 |
} |
1821 |
if(!found){ |
|
1822 |
result[0] = true; |
|
1823 |
break; |
|
1824 |
} |
|
1825 |
} |
|
1826 |
||
1827 |
// Check for reorder |
|
1828 |
if (!result[0] && !result[1] && oldEntries.length == newEntries.length) { |
|
1829 |
for (int i = 0; i < newEntries.length; i++) { |
|
1830 |
if (!newEntries[i].equals(oldEntries[i])) { |
|
1831 |
result[2] = true; |
|
1832 |
break; |
|
1833 |
} |
|
1834 |
} |
|
1835 |
} |
|
1836 |
// They may have remove some duplications, catch here .. consider it as reordering. |
|
1837 |
if (!result[0] && !result[1] && oldEntries.length != newEntries.length) { |
|
1838 |
result[2] = true; |
|
1839 |
} |
|
1840 |
||
1841 |
return result; |
|
1842 |
} |
|
1843 |
||
1844 |
/* public boolean entriesEqual(ICLanguageSettingEntry entries1[], ICLanguageSettingEntry entries2[]){ |
|
1845 |
if(entries1.length != entries2.length) |
|
1846 |
return false; |
|
1847 |
||
1848 |
for(int i = 0; i < entries1.length; i++){ |
|
1849 |
if(!entries1[i].equals(entries2[i])) |
|
1850 |
return false; |
|
1851 |
} |
|
1852 |
||
1853 |
return true; |
|
1854 |
} |
|
1855 |
*/ |
|
1856 |
private CProjectDescriptionDelta createDelta(ICTargetPlatformSetting newTPS, ICTargetPlatformSetting oldTPS){ |
|
1857 |
CProjectDescriptionDelta delta = new CProjectDescriptionDelta(newTPS, oldTPS); |
|
1858 |
if(!Arrays.equals(newTPS.getBinaryParserIds(), oldTPS.getBinaryParserIds())) |
|
1859 |
delta.addChangeFlags(ICDescriptionDelta.BINARY_PARSER_IDS); |
|
1860 |
||
1861 |
return delta.isEmpty() ? null : delta; |
|
1862 |
} |
|
1863 |
||
1864 |
ICElementDelta[] generateCElementDeltas(ICProject cProject, ICDescriptionDelta projDesDelta){ |
|
1865 |
if(projDesDelta == null) |
|
1866 |
return EMPTY_CELEMENT_DELTA; |
|
1867 |
||
1868 |
int kind = projDesDelta.getDeltaKind(); |
|
1869 |
switch(kind){ |
|
1870 |
case ICDescriptionDelta.CHANGED: |
|
1871 |
ICProjectDescription newDes = (ICProjectDescription)projDesDelta.getNewSetting(); |
|
1872 |
ICProjectDescription oldDes = (ICProjectDescription)projDesDelta.getOldSetting(); |
|
1873 |
// int flags = projDesDelta.getChangeFlags(); |
|
1874 |
// ICConfigurationDescription activeCfg = newDes.getActiveConfiguration(); |
|
1875 |
ICConfigurationDescription indexCfg = newDes.getDefaultSettingConfiguration(); |
|
1876 |
// if(indexCfg != activeCfg){ |
|
1877 |
// ICDescriptionDelta delta = findDelta(activeCfg.getId(), projDesDelta); |
|
1878 |
// if(delta != null && delta.getDeltaKind() == ICDescriptionDelta.CHANGED){ |
|
1879 |
// indexCfg = activeCfg; |
|
1880 |
// newDes.setIndexConfiguration(activeCfg); |
|
1881 |
// } |
|
1882 |
// } |
|
1883 |
ICConfigurationDescription oldIndexCfg = oldDes.getDefaultSettingConfiguration(); |
|
1884 |
ICDescriptionDelta indexDelta; |
|
1885 |
if(oldIndexCfg != null && oldIndexCfg.getId().equals(indexCfg.getId())){ |
|
1886 |
indexDelta = findDelta(indexCfg.getId(), projDesDelta); |
|
1887 |
} else { |
|
1888 |
indexDelta = createDelta(indexCfg, oldIndexCfg); |
|
1889 |
} |
|
1890 |
if(indexDelta != null){ |
|
1891 |
List<CElementDelta> list = new ArrayList<CElementDelta>(); |
|
1892 |
generateCElementDeltasFromCfgDelta(cProject, indexDelta, list); |
|
1893 |
return list.toArray(new ICElementDelta[list.size()]); |
|
1894 |
} |
|
1895 |
return EMPTY_CELEMENT_DELTA; |
|
1896 |
case ICDescriptionDelta.ADDED: |
|
1897 |
case ICDescriptionDelta.REMOVED: |
|
1898 |
break; |
|
1899 |
} |
|
1900 |
return EMPTY_CELEMENT_DELTA; |
|
1901 |
} |
|
1902 |
||
1903 |
private List<CElementDelta> generateCElementDeltasFromCfgDelta(ICProject cProject, ICDescriptionDelta cfgDelta, List<CElementDelta> list){ |
|
1904 |
int kind = cfgDelta.getDeltaKind(); |
|
1905 |
switch(kind){ |
|
1906 |
case ICDescriptionDelta.CHANGED: |
|
1907 |
int descriptionFlags = cfgDelta.getChangeFlags(); |
|
1908 |
int celementFlags = 0; |
|
1909 |
if((descriptionFlags & ICDescriptionDelta.SOURCE_ADDED) != 0) |
|
1910 |
celementFlags |= ICElementDelta.F_ADDED_PATHENTRY_SOURCE; |
|
1911 |
if((descriptionFlags & ICDescriptionDelta.SOURCE_REMOVED) != 0) |
|
1912 |
celementFlags |= ICElementDelta.F_REMOVED_PATHENTRY_SOURCE; |
|
1913 |
||
1914 |
if(celementFlags != 0){ |
|
1915 |
CElementDelta cElDelta = new CElementDelta(cProject.getCModel()); |
|
1916 |
cElDelta.changed(cProject, celementFlags); |
|
1917 |
list.add(cElDelta); |
|
1918 |
} |
|
1919 |
||
1920 |
ICDescriptionDelta children[] = cfgDelta.getChildren(); |
|
1921 |
ICDescriptionDelta child; |
|
1922 |
int type; |
|
1923 |
for(int i = 0; i < children.length; i++){ |
|
1924 |
child = children[i]; |
|
1925 |
type = child.getSettingType(); |
|
1926 |
if(type == ICSettingBase.SETTING_FILE || type == ICSettingBase.SETTING_FOLDER){ |
|
1927 |
generateCElementDeltasFromResourceDelta(cProject, child, list); |
|
1928 |
} |
|
1929 |
} |
|
1930 |
case ICDescriptionDelta.ADDED: |
|
1931 |
case ICDescriptionDelta.REMOVED: |
|
1932 |
break; |
|
1933 |
} |
|
1934 |
return list; |
|
1935 |
} |
|
1936 |
||
1937 |
private List<CElementDelta> generateCElementDeltasFromResourceDelta(ICProject cProject, ICDescriptionDelta delta, List<CElementDelta> list){ |
|
1938 |
int kind = delta.getDeltaKind(); |
|
1939 |
ICDescriptionDelta parentDelta = delta.getParent(); |
|
1940 |
ICElement el; |
|
1941 |
// IProject project = cProject.getProject(); |
|
1942 |
IResource rc = null; |
|
1943 |
||
1944 |
ICResourceDescription oldRcDes; |
|
1945 |
ICResourceDescription newRcDes; |
|
1946 |
IPath path; |
|
1947 |
switch(kind){ |
|
1948 |
case ICDescriptionDelta.REMOVED: |
|
1949 |
oldRcDes = (ICResourceDescription)delta.getOldSetting(); |
|
1950 |
path = oldRcDes.getPath(); |
|
1951 |
newRcDes = ((ICConfigurationDescription)parentDelta.getNewSetting()).getResourceDescription(path, false); |
|
1952 |
break; |
|
1953 |
case ICDescriptionDelta.CHANGED: |
|
1954 |
// if((delta.getChangeFlags() & ICProjectDescriptionDelta.PATH) == 0){ |
|
1955 |
newRcDes = (ICResourceDescription)delta.getNewSetting(); |
|
1956 |
path = newRcDes.getPath(); |
|
1957 |
oldRcDes = (ICResourceDescription)delta.getOldSetting(); |
|
1958 |
break; |
|
1959 |
// } |
|
1960 |
//if path changed treat as added |
|
1961 |
case ICDescriptionDelta.ADDED: |
|
1962 |
default: |
|
1963 |
newRcDes = (ICResourceDescription)delta.getNewSetting(); |
|
1964 |
path = newRcDes.getPath(); |
|
1965 |
oldRcDes = ((ICConfigurationDescription)parentDelta.getOldSetting()).getResourceDescription(path, false); |
|
1966 |
break; |
|
1967 |
} |
|
1968 |
path = path.makeRelative(); |
|
1969 |
el = null; |
|
1970 |
try { |
|
1971 |
el = cProject.findElement(path); |
|
1972 |
rc = el.getResource(); |
|
1973 |
} catch (CModelException e) { |
|
1974 |
// int i = 0; |
|
1975 |
} |
|
1976 |
// rc = ResourcesPlugin.getWorkspace().getRoot().findMember(project.getFullPath().append(path)); |
|
1977 |
if(rc != null){ |
|
1978 |
if(rc.getType() == IResource.FILE){ |
|
1979 |
String fileName = path.lastSegment(); |
|
1980 |
ICLanguageSetting newLS = getLanguageSetting(newRcDes, fileName); |
|
1981 |
ICLanguageSetting oldLS = getLanguageSetting(oldRcDes, fileName); |
|
1982 |
ICDescriptionDelta ld = createDelta(newLS, oldLS); |
|
1983 |
generateCElementDeltasFromLanguageDelta(el, ld, list); |
|
1984 |
} else { |
|
1985 |
if(newRcDes.getType() == ICSettingBase.SETTING_FOLDER){ |
|
1986 |
ICFolderDescription oldFoDes = null; |
|
1987 |
if (oldRcDes != null) { |
|
1988 |
if (oldRcDes.getType() == ICSettingBase.SETTING_FOLDER) |
|
1989 |
oldFoDes = (ICFolderDescription)oldRcDes; |
|
1990 |
} |
|
1991 |
ICDescriptionDelta folderDelta = createDelta((ICFolderDescription)newRcDes, oldFoDes); |
|
1992 |
if(folderDelta != null){ |
|
1993 |
ICDescriptionDelta children[] = folderDelta.getChildren(); |
|
1994 |
ICDescriptionDelta child; |
|
1995 |
for(int i = 0; i < children.length; i++){ |
|
1996 |
child = children[i]; |
|
1997 |
if(child.getSettingType() == ICSettingBase.SETTING_LANGUAGE){ |
|
1998 |
generateCElementDeltasFromLanguageDelta(el, child, list); |
|
1999 |
} |
|
2000 |
} |
|
2001 |
} |
|
2002 |
} else { |
|
2003 |
//ERROR? |
|
2004 |
} |
|
2005 |
||
2006 |
} |
|
2007 |
} |
|
2008 |
return list; |
|
2009 |
} |
|
2010 |
||
2011 |
private ICLanguageSetting getLanguageSetting(ICResourceDescription rcDes, String fileName){ |
|
2012 |
if(rcDes.getType() == ICSettingBase.SETTING_FILE){ |
|
2013 |
return ((ICFileDescription)rcDes).getLanguageSetting(); |
|
2014 |
} |
|
2015 |
return ((ICFolderDescription)rcDes).getLanguageSettingForFile(fileName); |
|
2016 |
} |
|
2017 |
||
2018 |
private List<CElementDelta> generateCElementDeltasFromLanguageDelta(ICElement el, ICDescriptionDelta delta, List<CElementDelta> list){ |
|
2019 |
if(delta == null) |
|
2020 |
return list; |
|
2021 |
||
2022 |
int flags = 0; |
|
2023 |
flags |= calculateEntriesFlags(delta.getAddedEntriesKinds(), true); |
|
2024 |
flags |= calculateEntriesFlags(delta.getRemovedEntriesKinds(), false); |
|
2025 |
flags |= calculateEntriesFlags(delta.getReorderedEntriesKinds(), true); |
|
2026 |
if(flags != 0){ |
|
2027 |
CElementDelta cElDelta = new CElementDelta(el.getCModel()); |
|
2028 |
cElDelta.changed(el, flags); |
|
2029 |
list.add(cElDelta); |
|
2030 |
} |
|
2031 |
return list; |
|
2032 |
} |
|
2033 |
||
2034 |
private int calculateEntriesFlags(int languageDeltaKinds, boolean added){ |
|
2035 |
int flags = 0; |
|
2036 |
int kindsArray[] = kindsToArray(languageDeltaKinds); |
|
2037 |
||
2038 |
for(int i = 0; i < kindsArray.length; i++){ |
|
2039 |
switch(kindsArray[i]){ |
|
2040 |
case ICLanguageSettingEntry.INCLUDE_PATH: |
|
2041 |
flags |= ICElementDelta.F_CHANGED_PATHENTRY_INCLUDE; |
|
2042 |
break; |
|
2043 |
case ICLanguageSettingEntry.INCLUDE_FILE: |
|
2044 |
flags |= ICElementDelta.F_CHANGED_PATHENTRY_INCLUDE; |
|
2045 |
break; |
|
2046 |
case ICLanguageSettingEntry.MACRO: |
|
2047 |
flags |= ICElementDelta.F_CHANGED_PATHENTRY_MACRO; |
|
2048 |
break; |
|
2049 |
case ICLanguageSettingEntry.MACRO_FILE: |
|
2050 |
flags |= ICElementDelta.F_CHANGED_PATHENTRY_MACRO; |
|
2051 |
break; |
|
2052 |
case ICLanguageSettingEntry.LIBRARY_PATH: |
|
2053 |
flags |= added ? ICElementDelta.F_ADDED_PATHENTRY_LIBRARY |
|
2054 |
: ICElementDelta.F_REMOVED_PATHENTRY_LIBRARY; |
|
2055 |
break; |
|
2056 |
case ICLanguageSettingEntry.LIBRARY_FILE: |
|
2057 |
flags |= added ? ICElementDelta.F_ADDED_PATHENTRY_LIBRARY |
|
2058 |
: ICElementDelta.F_REMOVED_PATHENTRY_LIBRARY; |
|
2059 |
break; |
|
2060 |
} |
|
2061 |
} |
|
2062 |
return flags; |
|
2063 |
} |
|
2064 |
||
2065 |
int[] kindsToArray(int kinds){ |
|
2066 |
int allKinds[] = KindBasedStore.getLanguageEntryKinds(); |
|
2067 |
int kindsArray[] = new int[allKinds.length]; |
|
2068 |
int num = 0; |
|
2069 |
for(int i = 0; i < allKinds.length; i++){ |
|
2070 |
if((allKinds[i] & kinds) != 0){ |
|
2071 |
kindsArray[num++] = allKinds[i]; |
|
2072 |
} |
|
2073 |
} |
|
2074 |
||
2075 |
if(num < allKinds.length){ |
|
2076 |
int tmp[] = new int[num]; |
|
2077 |
if(num > 0) |
|
2078 |
System.arraycopy(kindsArray, 0, tmp, 0, num); |
|
2079 |
kindsArray = tmp; |
|
2080 |
} |
|
2081 |
return kindsArray; |
|
2082 |
} |
|
2083 |
||
2084 |
/* |
|
2085 |
* Methods for manipulating the set of project description listeners |
|
2086 |
*/ |
|
2087 |
||
2088 |
public void addCProjectDescriptionListener(ICProjectDescriptionListener listener, int eventTypes) { |
|
2089 |
fListeners.add(new ListenerDescriptor(listener, eventTypes)); |
|
2090 |
} |
|
2091 |
||
2092 |
public void removeCProjectDescriptionListener(ICProjectDescriptionListener listener) { |
|
133
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
2093 |
// fListeners.remove(listener); |
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
2094 |
// Note: can't use remove directly due to the implementation of CopyOnWriteArraySet.remove() |
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
2095 |
for (ListenerDescriptor listenerDescriptor : fListeners) { |
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
2096 |
if (listenerDescriptor.fListener.equals(listener)) { |
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
2097 |
fListeners.remove(listenerDescriptor); |
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
2098 |
break; |
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
2099 |
} |
996f2f4e33c7
fix bug where project descriptor listeners could not be removed
dadubrow
parents:
52
diff
changeset
|
2100 |
} |
37 | 2101 |
} |
2102 |
||
2103 |
public void notifyListeners(CProjectDescriptionEvent event){ |
|
2104 |
int eventType = event.getEventType(); |
|
2105 |
for (ListenerDescriptor listener : fListeners) { |
|
2106 |
if (listener.handlesEvent(eventType)) |
|
2107 |
listener.fListener.handleEvent(event); |
|
2108 |
} |
|
2109 |
} |
|
2110 |
||
2111 |
void checkRemovedConfigurations(ICDescriptionDelta delta){ |
|
2112 |
if(delta == null) |
|
2113 |
return; |
|
2114 |
||
2115 |
ICDescriptionDelta cfgDeltas[] = delta.getChildren(); |
|
2116 |
for(int i = 0; i < cfgDeltas.length; i++){ |
|
2117 |
if(cfgDeltas[i].getDeltaKind() == ICDescriptionDelta.REMOVED){ |
|
2118 |
CConfigurationDescriptionCache des = (CConfigurationDescriptionCache)cfgDeltas[i].getOldSetting(); |
|
2119 |
CConfigurationData data = des.getConfigurationData(); |
|
2120 |
try { |
|
2121 |
removeData(des, data, null); |
|
2122 |
} catch (CoreException e) { |
|
2123 |
} |
|
2124 |
} |
|
2125 |
} |
|
2126 |
} |
|
2127 |
||
2128 |
public ICConfigurationDescription getPreferenceConfiguration(String buildSystemId) throws CoreException { |
|
2129 |
return getPreferenceConfiguration(buildSystemId, true); |
|
2130 |
} |
|
2131 |
||
2132 |
private void runContextOperations(SettingsContext context, IProgressMonitor monitor){ |
|
2133 |
IWorkspaceRunnable toRun = context.createOperationRunnable(); |
|
2134 |
if(toRun != null){ |
|
2135 |
runWspModification(toRun, monitor); |
|
2136 |
} else if (monitor != null){ |
|
2137 |
monitor.done(); |
|
2138 |
} |
|
2139 |
} |
|
2140 |
||
2141 |
public ICConfigurationDescription getPreferenceConfiguration(String buildSystemId, boolean write) throws CoreException { |
|
2142 |
ICConfigurationDescription des = getLoaddedPreference(buildSystemId); |
|
2143 |
if(des == null){ |
|
2144 |
try { |
|
2145 |
des = loadPreference(buildSystemId); |
|
2146 |
} catch (CoreException e) { |
|
2147 |
// CCorePlugin.log(e); |
|
2148 |
} |
|
2149 |
||
2150 |
if(des == null){ |
|
2151 |
try { |
|
2152 |
des = createNewPreference(buildSystemId); |
|
2153 |
} catch (CoreException e) { |
|
2154 |
CCorePlugin.log(e); |
|
2155 |
} |
|
2156 |
} |
|
2157 |
||
2158 |
setLoaddedPreference(buildSystemId, (CConfigurationDescriptionCache)des); |
|
2159 |
} |
|
2160 |
if(des != null && write){ |
|
2161 |
try { |
|
2162 |
des = createWritablePreference((CConfigurationDescriptionCache)des); |
|
2163 |
} catch (CoreException e) { |
|
2164 |
CCorePlugin.log(e); |
|
2165 |
} |
|
2166 |
} |
|
2167 |
return des; |
|
2168 |
} |
|
2169 |
||
2170 |
public void setPreferenceConfiguration(String buildSystemId, ICConfigurationDescription des) throws CoreException{ |
|
2171 |
if(!needSavePreference(buildSystemId, des)) |
|
2172 |
return; |
|
2173 |
||
2174 |
CConfigurationDescriptionCache cache = createPreferenceCache(des); |
|
2175 |
||
2176 |
savePreferenceConfiguration(buildSystemId, cache); |
|
2177 |
||
2178 |
setLoaddedPreference(buildSystemId, cache); |
|
2179 |
} |
|
2180 |
||
2181 |
private void savePreferenceConfiguration(String buildStystemId, CConfigurationDescriptionCache cache) throws CoreException{ |
|
2182 |
ICStorageElement el = cache.getSpecSettings().getRootStorageElement(); |
|
2183 |
saveBuildSystemConfigPreferenceStorage(buildStystemId, el); |
|
2184 |
} |
|
2185 |
||
2186 |
private void saveBuildSystemConfigPreferenceStorage(String buildSystemId, ICStorageElement el) throws CoreException{ |
|
2187 |
ICStorageElement cur = getBuildSystemConfigPreferenceStorage(buildSystemId); |
|
2188 |
ICStorageElement parent = cur.getParent(); |
|
2189 |
parent.removeChild(cur); |
|
2190 |
parent.importChild(el); |
|
2191 |
savePreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, parent); |
|
2192 |
} |
|
2193 |
||
2194 |
private boolean needSavePreference(String buildSystemId, ICConfigurationDescription des){ |
|
2195 |
if(des.isModified() |
|
2196 |
|| !des.isPreferenceConfiguration() |
|
2197 |
|| !des.getBuildSystemId().equals(buildSystemId)) |
|
2198 |
return true; |
|
2199 |
||
2200 |
return false; |
|
2201 |
} |
|
2202 |
||
2203 |
private ICConfigurationDescription createWritablePreference(CConfigurationDescriptionCache cache) throws CoreException{ |
|
2204 |
return new CConfigurationDescription(cache, fPrefUpdater); |
|
2205 |
} |
|
2206 |
||
2207 |
private CConfigurationDescriptionCache createPreferenceCache(ICConfigurationDescription des) throws CoreException{ |
|
2208 |
IInternalCCfgInfo cfgDes = (IInternalCCfgInfo)des; |
|
2209 |
CConfigurationData baseData = cfgDes.getConfigurationData(false); |
|
2210 |
CConfigurationDescriptionCache baseCache = null; |
|
2211 |
if(baseData instanceof CConfigurationDescriptionCache){ |
|
2212 |
baseCache = (CConfigurationDescriptionCache)baseData; |
|
2213 |
baseData = baseCache.getConfigurationData(); |
|
2214 |
} |
|
2215 |
CConfigurationSpecSettings settings = cfgDes.getSpecSettings(); |
|
2216 |
ICStorageElement rootEl = getBuildSystemConfigPreferenceStorage(des.getBuildSystemId(), true, false); |
|
2217 |
ICStorageElement rootParent = rootEl.getParent(); |
|
2218 |
rootParent.removeChild(rootEl); |
|
2219 |
ICStorageElement baseRootEl = settings.getRootStorageElement(); |
|
2220 |
rootEl = rootParent.importChild(baseRootEl); |
|
2221 |
CConfigurationDescriptionCache cache = new CConfigurationDescriptionCache(des, baseData, baseCache, cfgDes.getSpecSettings(), null, rootEl); |
|
2222 |
CSettingEntryFactory factory = new CSettingEntryFactory(); |
|
2223 |
SettingsContext context = new SettingsContext(null); |
|
2224 |
cache.applyData(factory, context); |
|
2225 |
cache.doneInitialization(); |
|
2226 |
factory.clear(); |
|
2227 |
runContextOperations(context, null); |
|
2228 |
return cache; |
|
2229 |
} |
|
2230 |
||
2231 |
private ICConfigurationDescription createNewPreference(String buildSystemId) throws CoreException { |
|
2232 |
ICStorageElement cfgEl = getBuildSystemConfigPreferenceStorage(buildSystemId, true, false); |
|
2233 |
||
2234 |
String id = PREFERENCE_CFG_ID_PREFIX + buildSystemId; |
|
2235 |
CConfigurationDescription des = new CConfigurationDescription(id, PREFERENCE_CFG_NAME, buildSystemId, cfgEl, fPrefUpdater); |
|
2236 |
||
2237 |
return createPreferenceCache(des); |
|
2238 |
} |
|
2239 |
||
2240 |
// private XmlStorage createBuildSystemCfgPrefStore() throws CoreException{ |
|
2241 |
// ICStorageElement el = getPreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, true, false); |
|
2242 |
// |
|
2243 |
// XmlStorage store = new XmlStorage((InternalXmlStorageElement)el); |
|
2244 |
// |
|
2245 |
// return store; |
|
2246 |
// } |
|
2247 |
// |
|
2248 |
// ICSettingsStorage getBuildSystemCfgPrefStore() throws CoreException{ |
|
2249 |
// if(fPrefCfgStorage == null){ |
|
2250 |
// fPrefCfgStorage = createBuildSystemCfgPrefStore(); |
|
2251 |
// } |
|
2252 |
// |
|
2253 |
// return copyStorage(fPrefCfgStorage, false); |
|
2254 |
// } |
|
2255 |
||
2256 |
ICStorageElement getBuildSystemConfigPreferenceStorage(String buildSystemId) throws CoreException{ |
|
2257 |
return getBuildSystemConfigPreferenceStorage(buildSystemId, true, false); |
|
2258 |
} |
|
2259 |
||
2260 |
private ICStorageElement getBuildSystemConfigPreferenceStorage(String buildSystemId, boolean createIfNotDound, boolean readOnly) throws CoreException{ |
|
2261 |
ICStorageElement el = getPreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, createIfNotDound, readOnly); |
|
2262 |
ICStorageElement cfgEl = null; |
|
2263 |
||
2264 |
if(el != null){ |
|
2265 |
ICStorageElement children[] = el.getChildren(); |
|
2266 |
for(int i = 0; i < children.length; i++){ |
|
2267 |
ICStorageElement child = children[i]; |
|
2268 |
if(PREFERENCE_BUILD_SYSTEM_ELEMENT.equals(child.getName())){ |
|
2269 |
if(buildSystemId.equals(child.getAttribute(ID))){ |
|
2270 |
cfgEl = child; |
|
2271 |
break; |
|
2272 |
} |
|
2273 |
} |
|
2274 |
||
2275 |
} |
|
2276 |
||
2277 |
if(cfgEl == null){ |
|
2278 |
cfgEl = el.createChild(PREFERENCE_BUILD_SYSTEM_ELEMENT); |
|
2279 |
cfgEl.setAttribute(ID, buildSystemId); |
|
2280 |
} |
|
2281 |
||
2282 |
} |
|
2283 |
||
2284 |
return cfgEl; |
|
2285 |
} |
|
2286 |
||
2287 |
private ICConfigurationDescription loadPreference(String buildSystemId) throws CoreException{ |
|
2288 |
ICStorageElement el = getPreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, false, false); |
|
2289 |
||
2290 |
ICStorageElement children[] = el.getChildren(); |
|
2291 |
ICStorageElement cfgEl = null; |
|
2292 |
for(int i = 0; i < children.length; i++){ |
|
2293 |
ICStorageElement child = children[i]; |
|
2294 |
if(PREFERENCE_BUILD_SYSTEM_ELEMENT.equals(child.getName())){ |
|
2295 |
if(buildSystemId.equals(child.getAttribute(ID))){ |
|
2296 |
cfgEl = child; |
|
2297 |
break; |
|
2298 |
} |
|
2299 |
} |
|
2300 |
||
2301 |
} |
|
2302 |
CConfigurationDescriptionCache cache = new CConfigurationDescriptionCache(cfgEl, null); |
|
2303 |
CSettingEntryFactory factory = new CSettingEntryFactory(); |
|
2304 |
cache.loadData(factory); |
|
2305 |
cache.doneInitialization(); |
|
2306 |
factory.clear(); |
|
2307 |
return cache; |
|
2308 |
} |
|
2309 |
||
2310 |
public ICStorageElement getPreferenceStorage(String prefKey, String storageId, boolean createIfNotDound, boolean readOnly) throws CoreException{ |
|
2311 |
XmlStorage store = getPreferenceStore(prefKey, createIfNotDound, readOnly); |
|
2312 |
||
2313 |
return store.getStorage(storageId, createIfNotDound); |
|
2314 |
} |
|
2315 |
||
2316 |
private XmlStorage getPreferenceStore(String prefKey, boolean createIfNotDound, boolean readOnly) throws CoreException{ |
|
2317 |
ICStorageElement el = createPreferenceStorage(prefKey, createIfNotDound, readOnly); |
|
2318 |
||
2319 |
XmlStorage store = new XmlStorage((InternalXmlStorageElement)el); |
|
2320 |
||
2321 |
return store; |
|
2322 |
} |
|
2323 |
||
2324 |
public void savePreferenceStorage(String prefKey, String storageId, ICStorageElement el) throws CoreException{ |
|
2325 |
XmlStorage store = getPreferenceStore(prefKey, true, false); |
|
2326 |
store.importStorage(storageId, el); |
|
2327 |
||
2328 |
InternalXmlStorageElement rootEl = new InternalXmlStorageElement(store.fElement, store.isReadOnly()); |
|
2329 |
serializePreference(prefKey, rootEl); |
|
2330 |
} |
|
2331 |
||
2332 |
private CConfigurationDescriptionCache getLoaddedPreference(String buildSystemId){ |
|
2333 |
return fPreferenceMap.get(buildSystemId); |
|
2334 |
} |
|
2335 |
||
2336 |
private void setLoaddedPreference(String buildSystemId, CConfigurationDescriptionCache des){ |
|
2337 |
fPreferenceMap.put(buildSystemId, des); |
|
2338 |
} |
|
2339 |
||
2340 |
public CConfigBasedDescriptorManager getDescriptorManager(){ |
|
2341 |
return fDescriptorManager; |
|
2342 |
} |
|
2343 |
||
2344 |
public CConfigurationData createDefaultConfigData(IProject project, CDataFactory factory) throws CoreException{ |
|
2345 |
return createDefaultConfigData(project, CDataUtil.genId(DEFAULT_CFG_ID_PREFIX), DEFAULT_CFG_NAME, factory); |
|
2346 |
} |
|
2347 |
||
2348 |
public CConfigurationData createDefaultConfigData(IProject project, String id, String name, CDataFactory factory) throws CoreException{ |
|
2349 |
if(factory == null) |
|
2350 |
factory = new CDataFactory(); |
|
2351 |
||
2352 |
CConfigurationData data = CDataUtil.createEmptyData(id, name, factory, true); |
|
2353 |
// CDataUtil. |
|
2354 |
//// data.initEmptyData(); |
|
2355 |
// |
|
2356 |
// CDataUtil.adjustConfig(data, factory); |
|
2357 |
||
2358 |
factory.setModified(data, false); |
|
2359 |
return data; |
|
2360 |
} |
|
2361 |
||
2362 |
public boolean isNewStyleIndexCfg(IProject project){ |
|
2363 |
ICProjectDescription des = getProjectDescription(project, false); |
|
2364 |
if(des != null) |
|
2365 |
return isNewStyleIndexCfg(des); |
|
2366 |
return false; |
|
2367 |
} |
|
2368 |
||
2369 |
public boolean isNewStyleIndexCfg(ICProjectDescription des){ |
|
2370 |
ICConfigurationDescription cfgDes = des.getDefaultSettingConfiguration(); |
|
2371 |
if(cfgDes != null) |
|
2372 |
return isNewStyleCfg(cfgDes); |
|
2373 |
return false; |
|
2374 |
} |
|
2375 |
||
2376 |
public boolean isNewStyleProject(IProject project){ |
|
2377 |
return isNewStyleProject(getProjectDescription(project, false)); |
|
2378 |
} |
|
2379 |
||
2380 |
public boolean isNewStyleProject(ICProjectDescription des){ |
|
2381 |
if(des == null) |
|
2382 |
return false; |
|
2383 |
||
2384 |
return isNewStyleIndexCfg(des); |
|
2385 |
} |
|
2386 |
||
2387 |
public boolean isNewStyleCfg(ICConfigurationDescription cfgDes){ |
|
2388 |
if(cfgDes == null) |
|
2389 |
return false; |
|
2390 |
||
2391 |
CConfigurationData data = ((IInternalCCfgInfo)cfgDes).getConfigurationData(false); |
|
2392 |
if(data instanceof CConfigurationDescriptionCache){ |
|
2393 |
data = ((CConfigurationDescriptionCache)data).getConfigurationData(); |
|
2394 |
} |
|
2395 |
||
2396 |
return data != null && !PathEntryConfigurationDataProvider.isPathEntryData(data); |
|
2397 |
} |
|
2398 |
||
2399 |
// public String[] getContentTypeFileSpecs (IProject project, IContentType type) { |
|
2400 |
// String[] globalSpecs = type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC); |
|
2401 |
// IContentTypeSettings settings = null; |
|
2402 |
// if (project != null) { |
|
2403 |
// IScopeContext projectScope = new ProjectScope(project); |
|
2404 |
// try { |
|
2405 |
// settings = type.getSettings(projectScope); |
|
2406 |
// } catch (Exception e) {} |
|
2407 |
// if (settings != null) { |
|
2408 |
// String[] specs = settings.getFileSpecs(IContentType.FILE_EXTENSION_SPEC); |
|
2409 |
// if (specs.length > 0) { |
|
2410 |
// int total = globalSpecs.length + specs.length; |
|
2411 |
// String[] projSpecs = new String[total]; |
|
2412 |
// int i=0; |
|
2413 |
// for (int j=0; j<specs.length; j++) { |
|
2414 |
// projSpecs[i] = specs[j]; |
|
2415 |
// i++; |
|
2416 |
// } |
|
2417 |
// for (int j=0; j<globalSpecs.length; j++) { |
|
2418 |
// projSpecs[i] = globalSpecs[j]; |
|
2419 |
// i++; |
|
2420 |
// } |
|
2421 |
// return projSpecs; |
|
2422 |
// } |
|
2423 |
// } |
|
2424 |
// } |
|
2425 |
// return globalSpecs; |
|
2426 |
// } |
|
2427 |
||
2428 |
// public String[] getExtensionsFromContentTypes(IProject project, String[] typeIds){ |
|
2429 |
// return CDataUtil.getExtensionsFromContentTypes(project, typeIds); |
|
2430 |
// } |
|
2431 |
||
2432 |
static ICLanguageSetting getLanguageSettingForFile(ICConfigurationDescription cfgDes, IPath path, boolean ignoreExcludeStatus){ |
|
2433 |
int segCount = path.segmentCount(); |
|
2434 |
if(segCount == 0) |
|
2435 |
return null; |
|
2436 |
||
2437 |
ICResourceDescription rcDes = cfgDes.getResourceDescription(path, false); |
|
2438 |
if(rcDes == null || (!ignoreExcludeStatus && rcDes.isExcluded())) |
|
2439 |
return null; |
|
2440 |
||
2441 |
if(rcDes.getType() == ICSettingBase.SETTING_FOLDER){ |
|
2442 |
return ((ICFolderDescription)rcDes).getLanguageSettingForFile(path.lastSegment()); |
|
2443 |
} |
|
2444 |
return ((ICFileDescription)rcDes).getLanguageSetting(); |
|
2445 |
} |
|
2446 |
||
2447 |
static private HashMap<HashSet<String>, CLanguageData> createExtSetToLDataMap(IProject project, CLanguageData[] lDatas){ |
|
2448 |
HashMap<HashSet<String>, CLanguageData> map = new HashMap<HashSet<String>, CLanguageData>(); |
|
2449 |
||
2450 |
for(int i = 0; i < lDatas.length; i++){ |
|
2451 |
CLanguageData lData = lDatas[i]; |
|
2452 |
String[] exts = CDataUtil.getSourceExtensions(project, lData); |
|
2453 |
HashSet<String> set = new HashSet<String>(Arrays.asList(exts)); |
|
2454 |
map.put(set, lData); |
|
2455 |
} |
|
2456 |
||
2457 |
return map; |
|
2458 |
} |
|
2459 |
||
2460 |
static boolean removeNonCustomSettings(IProject project, CConfigurationData data){ |
|
2461 |
PathSettingsContainer cr = CDataUtil.createRcDataHolder(data); |
|
2462 |
PathSettingsContainer[] crs = cr.getChildren(false); |
|
2463 |
PathSettingsContainer child, parent; |
|
2464 |
CResourceData childRcData; |
|
2465 |
boolean modified = false; |
|
2466 |
for(int i = 0; i < crs.length; i++){ |
|
2467 |
child = crs[i]; |
|
2468 |
childRcData = (CResourceData)child.getValue(); |
|
2469 |
if(childRcData.getType() == ICSettingBase.SETTING_FOLDER){ |
|
2470 |
CResourceData parentRcData = null; |
|
2471 |
for(parent = child.getParentContainer(); |
|
2472 |
(parentRcData = (CResourceData)parent.getValue()).getType() != ICSettingBase.SETTING_FOLDER; |
|
2473 |
parent = parent.getParentContainer()); |
|
2474 |
if(!settingsCustomized(project, (CFolderData)parentRcData, (CFolderData)childRcData)){ |
|
2475 |
try { |
|
2476 |
data.removeResourceData(childRcData); |
|
2477 |
child.remove(); |
|
2478 |
modified = true; |
|
2479 |
} catch (CoreException e) { |
|
2480 |
CCorePlugin.log(e); |
|
2481 |
} |
|
2482 |
} |
|
2483 |
} else { |
|
2484 |
parent = child.getParentContainer(); |
|
2485 |
if(!settingsCustomized(project, (CResourceData)parent.getValue(), (CFileData)childRcData)){ |
|
2486 |
try { |
|
2487 |
data.removeResourceData(childRcData); |
|
2488 |
child.remove(); |
|
2489 |
modified = true; |
|
2490 |
} catch (CoreException e) { |
|
2491 |
CCorePlugin.log(e); |
|
2492 |
} |
|
2493 |
} |
|
2494 |
} |
|
2495 |
||
2496 |
} |
|
2497 |
return modified; |
|
2498 |
} |
|
2499 |
||
2500 |
static boolean settingsCustomized(IProject project, CFolderData parent, CFolderData child){ |
|
2501 |
if(baseSettingsCustomized(parent, child)) |
|
2502 |
return true; |
|
2503 |
||
2504 |
CLanguageData[] childLDatas = child.getLanguageDatas(); |
|
2505 |
CLanguageData[] parentLDatas = parent.getLanguageDatas(); |
|
2506 |
||
2507 |
if(childLDatas.length != parentLDatas.length) |
|
2508 |
return true; |
|
2509 |
||
2510 |
if(childLDatas.length != 0){ |
|
2511 |
HashMap<HashSet<String>, CLanguageData> parentMap = createExtSetToLDataMap(project, parentLDatas); |
|
2512 |
HashMap<HashSet<String>, CLanguageData> childMap = createExtSetToLDataMap(project, childLDatas); |
|
2513 |
CLanguageData parentLData, childLData; |
|
2514 |
for(Iterator iter = parentMap.entrySet().iterator(); iter.hasNext();){ |
|
2515 |
Map.Entry entry = (Map.Entry)iter.next(); |
|
2516 |
childLData = childMap.get(entry.getKey()); |
|
2517 |
if(childLData == null) |
|
2518 |
return true; |
|
2519 |
||
2520 |
parentLData = (CLanguageData)entry.getValue(); |
|
2521 |
if(!langDatasEqual(parentLData, childLData)) |
|
2522 |
return true; |
|
2523 |
} |
|
2524 |
} |
|
2525 |
||
2526 |
return false; |
|
2527 |
} |
|
2528 |
||
2529 |
static boolean settingsCustomized(IProject project, CResourceData parent, CFileData child){ |
|
2530 |
if(baseSettingsCustomized(parent, child)) |
|
2531 |
return true; |
|
2532 |
||
2533 |
CLanguageData lData = child.getLanguageData(); |
|
2534 |
||
2535 |
if(parent.getType() == ICSettingBase.SETTING_FOLDER){ |
|
2536 |
CFolderData foParent = (CFolderData)parent; |
|
2537 |
||
2538 |
IPath childPath = child.getPath(); |
|
2539 |
String fileName = childPath.lastSegment(); |
|
2540 |
if(PatternNameMap.isPatternName(fileName)) |
|
2541 |
return true; |
|
2542 |
||
2543 |
CLanguageData parentLangData = CDataUtil.findLanguagDataForFile(fileName, project, foParent); |
|
2544 |
||
2545 |
return !langDatasEqual(lData, parentLangData); |
|
2546 |
} |
|
2547 |
||
2548 |
CFileData fiParent = (CFileData)parent; |
|
2549 |
CLanguageData parentLangData = fiParent.getLanguageData(); |
|
2550 |
return !langDatasEqual(lData, parentLangData); |
|
2551 |
} |
|
2552 |
||
2553 |
static boolean langDatasEqual(CLanguageData lData1, CLanguageData lData2){ |
|
2554 |
if(lData1 == null) |
|
2555 |
return lData2 == null; |
|
2556 |
||
2557 |
if(lData2 == null) |
|
2558 |
return false; |
|
2559 |
||
2560 |
int kinds[] = KindBasedStore.getLanguageEntryKinds(); |
|
2561 |
int kind; |
|
2562 |
for(int i = 0; i < kinds.length; i++){ |
|
2563 |
kind = kinds[i]; |
|
2564 |
ICLanguageSettingEntry entries1[] = lData1.getEntries(kind); |
|
2565 |
ICLanguageSettingEntry entries2[] = lData2.getEntries(kind); |
|
2566 |
if(!Arrays.equals(entries1, entries2)) |
|
2567 |
return false; |
|
2568 |
} |
|
2569 |
||
2570 |
return true; |
|
2571 |
} |
|
2572 |
||
2573 |
private static boolean baseSettingsCustomized(CResourceData parent, CResourceData child){ |
|
2574 |
// if(parent.isExcluded() != child.isExcluded()) |
|
2575 |
// return true; |
|
2576 |
||
2577 |
if(child.hasCustomSettings()) |
|
2578 |
return true; |
|
2579 |
||
2580 |
return false; |
|
2581 |
} |
|
2582 |
||
2583 |
||
2584 |
public ICProjectDescriptionWorkspacePreferences getProjectDescriptionWorkspacePreferences( |
|
2585 |
boolean write) { |
|
2586 |
if(fPreferences == null){ |
|
2587 |
try { |
|
2588 |
fPreferences = loadPreferences(); |
|
2589 |
} catch (CoreException e) { |
|
2590 |
} |
|
2591 |
if(fPreferences == null) |
|
2592 |
fPreferences = new CProjectDescriptionWorkspacePreferences((ICStorageElement)null, null, true); |
|
2593 |
} |
|
2594 |
||
2595 |
CProjectDescriptionWorkspacePreferences prefs = fPreferences; |
|
2596 |
||
2597 |
if(write) |
|
2598 |
prefs = new CProjectDescriptionWorkspacePreferences(prefs, false); |
|
2599 |
||
2600 |
return prefs; |
|
2601 |
} |
|
2602 |
||
2603 |
public boolean setProjectDescriptionWorkspacePreferences(ICProjectDescriptionWorkspacePreferences prefs, |
|
2604 |
boolean updateProjects, |
|
2605 |
IProgressMonitor monitor) { |
|
2606 |
if(monitor == null) |
|
2607 |
monitor = new NullProgressMonitor(); |
|
2608 |
boolean changed = false; |
|
2609 |
ICProjectDescriptionWorkspacePreferences oldPrefs = getProjectDescriptionWorkspacePreferences(false); |
|
2610 |
try { |
|
2611 |
do { |
|
2612 |
if(oldPrefs != prefs){ |
|
2613 |
if(prefs.getConfigurationRelations() != oldPrefs.getConfigurationRelations()){ |
|
2614 |
changed = true; |
|
2615 |
break; |
|
2616 |
} |
|
2617 |
} |
|
2618 |
} while(false); |
|
2619 |
||
2620 |
if(changed){ |
|
2621 |
CProjectDescriptionWorkspacePreferences basePrefs; |
|
2622 |
if(prefs instanceof CProjectDescriptionWorkspacePreferences) |
|
2623 |
basePrefs = (CProjectDescriptionWorkspacePreferences)prefs; |
|
2624 |
else |
|
2625 |
throw new IllegalArgumentException(); |
|
2626 |
||
2627 |
fPreferences = new CProjectDescriptionWorkspacePreferences(basePrefs, null, true); |
|
2628 |
||
2629 |
storePreferences(fPreferences); |
|
2630 |
||
2631 |
if(updateProjects) |
|
2632 |
updateProjectDescriptions(null, monitor); |
|
2633 |
} |
|
2634 |
} catch (CoreException e) { |
|
2635 |
CCorePlugin.log(e); |
|
2636 |
} finally { |
|
2637 |
monitor.done(); |
|
2638 |
} |
|
2639 |
||
2640 |
return changed; |
|
2641 |
} |
|
2642 |
||
2643 |
private void storePreferences(CProjectDescriptionWorkspacePreferences prefs) throws CoreException { |
|
2644 |
ICStorageElement el = getCProjectDescriptionPreferencesElement(true, false); |
|
2645 |
prefs.serialize(el); |
|
2646 |
saveCProjectDescriptionPreferencesElement(el); |
|
2647 |
} |
|
2648 |
||
2649 |
private void saveCProjectDescriptionPreferencesElement(ICStorageElement el) throws CoreException{ |
|
2650 |
ICStorageElement cur = getCProjectDescriptionPreferencesElement(true, false); |
|
2651 |
ICStorageElement parent = cur.getParent(); |
|
2652 |
parent.removeChild(cur); |
|
2653 |
parent.importChild(el); |
|
2654 |
savePreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, parent); |
|
2655 |
} |
|
2656 |
||
2657 |
private CProjectDescriptionWorkspacePreferences loadPreferences() throws CoreException{ |
|
2658 |
ICStorageElement el = getCProjectDescriptionPreferencesElement(false, true); |
|
2659 |
return new CProjectDescriptionWorkspacePreferences(el, null, true); |
|
2660 |
} |
|
2661 |
||
2662 |
private ICStorageElement getCProjectDescriptionPreferencesElement(boolean createIfNotFound, boolean readOnly) throws CoreException{ |
|
2663 |
ICStorageElement el = getPreferenceStorage(PREFERENCES_STORAGE, MODULE_ID, createIfNotFound, readOnly); |
|
2664 |
ICStorageElement[] children = el.getChildren(); |
|
2665 |
for(int i = 0; i < children.length; i++){ |
|
2666 |
if(PREFERENCES_ELEMENT.equals(children[i].getName())) |
|
2667 |
return children[i]; |
|
2668 |
} |
|
2669 |
if(createIfNotFound) |
|
2670 |
return el.createChild(PREFERENCES_ELEMENT); |
|
2671 |
throw ExceptionFactory.createCoreException(SettingsModelMessages.getString("CProjectDescriptionManager.14")); //$NON-NLS-1$ |
|
2672 |
} |
|
2673 |
||
2674 |
public void updateExternalSettingsProviders(String[] ids, IProgressMonitor monitor){ |
|
2675 |
ExtensionContainerFactory.updateReferencedProviderIds(ids, monitor); |
|
2676 |
} |
|
2677 |
||
2678 |
boolean isEmptyCreatingDescriptionAllowed(){ |
|
2679 |
return fAllowEmptyCreatingDescription; |
|
2680 |
} |
|
2681 |
||
2682 |
void setEmptyCreatingDescriptionAllowed(boolean allow){ |
|
2683 |
fAllowEmptyCreatingDescription = allow; |
|
2684 |
} |
|
2685 |
||
2686 |
} |