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