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