1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

bug 367253: Source folders are reshuffled when build settings are

edited.
This commit is contained in:
Andrew Gvozdev 2011-12-28 00:20:15 -05:00
parent bb1c0a023f
commit d78e6aeffb

View file

@ -14,6 +14,7 @@ import java.lang.reflect.Array;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -71,7 +72,7 @@ import org.eclipse.core.runtime.preferences.IScopeContext;
public class CDataUtil { public class CDataUtil {
private static final String EMPTY = ""; //$NON-NLS-1$ private static final String EMPTY = ""; //$NON-NLS-1$
private static final String DELIM = " "; //$NON-NLS-1$ private static final String DELIM = " "; //$NON-NLS-1$
private static Random randomNumber; private static Random randomNumber;
public static final String[] EMPTY_STRING_ARRAY = new String[0]; public static final String[] EMPTY_STRING_ARRAY = new String[0];
@ -87,14 +88,14 @@ public class CDataUtil {
} }
return i; return i;
} }
public static String genId(String baseId){ public static String genId(String baseId){
String suffix = new Integer(genRandomNumber()).toString(); String suffix = new Integer(genRandomNumber()).toString();
return baseId != null ? return baseId != null ?
new StringBuffer(baseId).append(".").append(suffix).toString() //$NON-NLS-1$ new StringBuffer(baseId).append(".").append(suffix).toString() //$NON-NLS-1$
: suffix; : suffix;
} }
public static boolean objectsEqual(Object o1, Object o2){ public static boolean objectsEqual(Object o1, Object o2){
if(o1 == null) if(o1 == null)
return o2 == null; return o2 == null;
@ -117,7 +118,7 @@ public class CDataUtil {
for(int i = 1; i < array.length; i++){ for(int i = 1; i < array.length; i++){
buf.append(separator).append(array[i]); buf.append(separator).append(array[i]);
} }
return buf.toString(); return buf.toString();
} }
@ -137,7 +138,7 @@ public class CDataUtil {
public static ICSettingEntry[] resolveEntries(ICSettingEntry entries[], ICConfigurationDescription cfgDes){ public static ICSettingEntry[] resolveEntries(ICSettingEntry entries[], ICConfigurationDescription cfgDes){
if(entries.length == 0) if(entries.length == 0)
return entries; return entries;
ArrayList<ICSettingEntry> out = new ArrayList<ICSettingEntry>(entries.length); ArrayList<ICSettingEntry> out = new ArrayList<ICSettingEntry>(entries.length);
ICdtVariableManager mngr = CCorePlugin.getDefault().getCdtVariableManager(); ICdtVariableManager mngr = CCorePlugin.getDefault().getCdtVariableManager();
@ -181,14 +182,14 @@ public class CDataUtil {
private static ICSettingEntry[] createResolvedEntry(ICSettingEntry entry, ICConfigurationDescription cfg, ICdtVariableManager mngr){ private static ICSettingEntry[] createResolvedEntry(ICSettingEntry entry, ICConfigurationDescription cfg, ICdtVariableManager mngr){
if(entry.isResolved()) if(entry.isResolved())
return new ICSettingEntry[] { entry }; return new ICSettingEntry[] { entry };
String name = entry.getName(); String name = entry.getName();
String[] names = new String[] { name }; // default value String[] names = new String[] { name }; // default value
try { try {
if ((entry.getKind() != ICSettingEntry.MACRO) && if ((entry.getKind() != ICSettingEntry.MACRO) &&
mngr.isStringListValue(name, cfg)) { mngr.isStringListValue(name, cfg)) {
names = mngr.resolveStringListValue(name, EMPTY, DELIM, cfg); names = mngr.resolveStringListValue(name, EMPTY, DELIM, cfg);
} else { } else {
names[0] = mngr.resolveValue(name, EMPTY, DELIM, cfg); names[0] = mngr.resolveValue(name, EMPTY, DELIM, cfg);
} }
@ -197,7 +198,7 @@ public class CDataUtil {
} }
ICSettingEntry[] result = new ICSettingEntry[names.length]; ICSettingEntry[] result = new ICSettingEntry[names.length];
for (int k=0; k<names.length; k++) { for (int k=0; k<names.length; k++) {
String value = null; String value = null;
IPath[] exclusionFilters = null; IPath[] exclusionFilters = null;
@ -244,11 +245,11 @@ public class CDataUtil {
} }
return result; return result;
} }
private static IPath resolvePath(ICdtVariableManager mngr, ICConfigurationDescription cfg, IPath path){ private static IPath resolvePath(ICdtVariableManager mngr, ICConfigurationDescription cfg, IPath path){
if(path == null) if(path == null)
return null; return null;
try { try {
String unresolved = path.toString(); String unresolved = path.toString();
String resolved = mngr.resolveValue(unresolved, EMPTY, DELIM, cfg); String resolved = mngr.resolveValue(unresolved, EMPTY, DELIM, cfg);
@ -257,7 +258,7 @@ public class CDataUtil {
} catch (CdtVariableException e) { } catch (CdtVariableException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} }
return path; return path;
} }
@ -284,10 +285,10 @@ public class CDataUtil {
break; break;
case ICLanguageSettingEntry.LIBRARY_FILE: case ICLanguageSettingEntry.LIBRARY_FILE:
ICLibraryFileEntry libFile = (ICLibraryFileEntry)entry; ICLibraryFileEntry libFile = (ICLibraryFileEntry)entry;
entry = new CLibraryFileEntry(entry.getName(), entry = new CLibraryFileEntry(entry.getName(),
flags, flags,
libFile.getSourceAttachmentPath(), libFile.getSourceAttachmentPath(),
libFile.getSourceAttachmentRootPath(), libFile.getSourceAttachmentRootPath(),
libFile.getSourceAttachmentPrefixMapping() libFile.getSourceAttachmentPrefixMapping()
); );
break; break;
@ -299,7 +300,7 @@ public class CDataUtil {
return createEntry(kind, name, value, exclusionPatterns, flags, null, null, null); return createEntry(kind, name, value, exclusionPatterns, flags, null, null, null);
} }
public static ICSettingEntry createEntry(int kind, String name, String value, IPath[] exclusionPatterns, int flags, IPath srcPath, IPath srcRootPath, IPath srcPrefixMapping){ public static ICSettingEntry createEntry(int kind, String name, String value, IPath[] exclusionPatterns, int flags, IPath srcPath, IPath srcRootPath, IPath srcPrefixMapping){
switch (kind){ switch (kind){
case ICLanguageSettingEntry.INCLUDE_PATH: case ICLanguageSettingEntry.INCLUDE_PATH:
@ -334,7 +335,7 @@ public class CDataUtil {
else else
exts = CDefaultLanguageData.EMPTY_STRING_ARRAY; exts = CDefaultLanguageData.EMPTY_STRING_ARRAY;
} }
if(exts == null) if(exts == null)
exts = CDefaultLanguageData.EMPTY_STRING_ARRAY; exts = CDefaultLanguageData.EMPTY_STRING_ARRAY;
return exts; return exts;
@ -360,14 +361,14 @@ public class CDataUtil {
exts = list.toArray(new String[list.size()]); exts = list.toArray(new String[list.size()]);
} }
} }
if(exts == null) if(exts == null)
exts = CDefaultLanguageData.EMPTY_STRING_ARRAY; exts = CDefaultLanguageData.EMPTY_STRING_ARRAY;
return exts; return exts;
} }
public static String[] getContentTypeFileSpecs (IProject project, IContentType type) { public static String[] getContentTypeFileSpecs (IProject project, IContentType type) {
String[] globalSpecs = type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC); String[] globalSpecs = type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
IContentTypeSettings settings = null; IContentTypeSettings settings = null;
if (project != null) { if (project != null) {
IScopeContext projectScope = new ProjectScope(project); IScopeContext projectScope = new ProjectScope(project);
@ -383,16 +384,16 @@ public class CDataUtil {
for (int j=0; j<specs.length; j++) { for (int j=0; j<specs.length; j++) {
projSpecs[i] = specs[j]; projSpecs[i] = specs[j];
i++; i++;
} }
for (int j=0; j<globalSpecs.length; j++) { for (int j=0; j<globalSpecs.length; j++) {
projSpecs[i] = globalSpecs[j]; projSpecs[i] = globalSpecs[j];
i++; i++;
} }
return projSpecs; return projSpecs;
} }
} }
} }
return globalSpecs; return globalSpecs;
} }
public static CLanguageData findLanguagDataForFile(String fileName, IProject project, CFolderData fData){ public static CLanguageData findLanguagDataForFile(String fileName, IProject project, CFolderData fData){
@ -415,11 +416,11 @@ public class CDataUtil {
} }
return data; return data;
} }
public static CLanguageData findLanguageDataForExtension(String ext, CLanguageData datas[]/*, boolean src*/){ public static CLanguageData findLanguageDataForExtension(String ext, CLanguageData datas[]/*, boolean src*/){
CLanguageData data; CLanguageData data;
for(int i = 0; i < datas.length; i++){ for(int i = 0; i < datas.length; i++){
data = datas[i]; data = datas[i];
String exts[] = data.getSourceExtensions(); String exts[] = data.getSourceExtensions();
/* if(src){ /* if(src){
if(setting.getSourceContentType() == null){ if(setting.getSourceContentType() == null){
@ -430,7 +431,7 @@ public class CDataUtil {
exts = setting.getHeaderExtensions(); exts = setting.getHeaderExtensions();
} }
} }
*/ */
if(exts != null && exts.length != 0){ if(exts != null && exts.length != 0){
for(int j = 0; j < exts.length; j++){ for(int j = 0; j < exts.length; j++){
if(ext.equals(exts[j])) if(ext.equals(exts[j]))
@ -454,7 +455,7 @@ public class CDataUtil {
public static PathSettingsContainer createRcDataHolder(CConfigurationData data){ public static PathSettingsContainer createRcDataHolder(CConfigurationData data){
PathSettingsContainer h = PathSettingsContainer.createRootContainer(); PathSettingsContainer h = PathSettingsContainer.createRootContainer();
h.setValue(data.getRootFolderData()); h.setValue(data.getRootFolderData());
CResourceData[] rcDatas = data.getResourceDatas(); CResourceData[] rcDatas = data.getResourceDatas();
CResourceData rcData; CResourceData rcData;
@ -466,22 +467,22 @@ public class CDataUtil {
} }
return h; return h;
} }
public static CConfigurationData createEmptyData(String id, String name, CDataFactory factory, boolean performLangAdjustment){ public static CConfigurationData createEmptyData(String id, String name, CDataFactory factory, boolean performLangAdjustment){
if(id == null) if(id == null)
id = genId(null); id = genId(null);
CConfigurationData data = factory.createConfigurationdata(id, name, null, false); CConfigurationData data = factory.createConfigurationdata(id, name, null, false);
if(data.getRootFolderData() == null){ if(data.getRootFolderData() == null){
CFolderData foData = factory.createFolderData(data, null, genId(data.getId()), false, Path.EMPTY); CFolderData foData = factory.createFolderData(data, null, genId(data.getId()), false, Path.EMPTY);
factory.link(data, foData); factory.link(data, foData);
} }
if(data.getBuildData() == null){ if(data.getBuildData() == null){
CBuildData bData = factory.createBuildData(data, null, genId(data.getId()), null, false); CBuildData bData = factory.createBuildData(data, null, genId(data.getId()), null, false);
factory.link(data, bData); factory.link(data, bData);
} }
if(data.getTargetPlatformData() == null){ if(data.getTargetPlatformData() == null){
CTargetPlatformData tpData = factory.createTargetPlatformData(data, null, genId(data.getId()), null, false); CTargetPlatformData tpData = factory.createTargetPlatformData(data, null, genId(data.getId()), null, false);
factory.link(data, tpData); factory.link(data, tpData);
@ -489,7 +490,7 @@ public class CDataUtil {
if(performLangAdjustment) if(performLangAdjustment)
adjustConfig(data, factory); adjustConfig(data, factory);
return data; return data;
} }
@ -497,18 +498,18 @@ public class CDataUtil {
LanguageManager mngr = LanguageManager.getInstance(); LanguageManager mngr = LanguageManager.getInstance();
ILanguageDescriptor dess[] = mngr.getLanguageDescriptors(); ILanguageDescriptor dess[] = mngr.getLanguageDescriptors();
Map<String, ILanguageDescriptor[]> map = mngr.getContentTypeIdToLanguageDescriptionsMap(); Map<String, ILanguageDescriptor[]> map = mngr.getContentTypeIdToLanguageDescriptionsMap();
CResourceData[] rcDatas = cfg.getResourceDatas(); CResourceData[] rcDatas = cfg.getResourceDatas();
for(int i = 0; i < rcDatas.length; i++){ for(int i = 0; i < rcDatas.length; i++){
if(rcDatas[i].getType() == ICSettingBase.SETTING_FOLDER){ if(rcDatas[i].getType() == ICSettingBase.SETTING_FOLDER){
adjustFolderData(cfg, (CFolderData)rcDatas[i], factory, dess, new HashMap<String, ILanguageDescriptor[]>(map)); adjustFolderData(cfg, (CFolderData)rcDatas[i], factory, dess, new HashMap<String, ILanguageDescriptor[]>(map));
} }
} }
return cfg; return cfg;
} }
private static void adjustFolderData(CConfigurationData cfgData, CFolderData data, CDataFactory factory, ILanguageDescriptor dess[], HashMap<String, ILanguageDescriptor[]> map){ private static void adjustFolderData(CConfigurationData cfgData, CFolderData data, CDataFactory factory, ILanguageDescriptor dess[], HashMap<String, ILanguageDescriptor[]> map){
Map<String, ILanguageDescriptor> langMap = new HashMap<String, ILanguageDescriptor>(); Map<String, ILanguageDescriptor> langMap = new HashMap<String, ILanguageDescriptor>();
for(int i = 0; i < dess.length; i++){ for(int i = 0; i < dess.length; i++){
@ -531,38 +532,38 @@ public class CDataUtil {
for(int q = 0; q < langs.length; q++){ for(int q = 0; q < langs.length; q++){
langMap.remove(langs[q].getId()); langMap.remove(langs[q].getId());
} }
adjustLanguageData(data, lData, langs[0]); adjustLanguageData(data, lData, langs[0]);
} }
} }
} }
} }
if(!langMap.isEmpty()){ if(!langMap.isEmpty()){
addLangs(cfgData, data, factory, langMap, map); addLangs(cfgData, data, factory, langMap, map);
} }
} }
private static CLanguageData adjustLanguageData(CFolderData data, CLanguageData lData, ILanguageDescriptor des){ private static CLanguageData adjustLanguageData(CFolderData data, CLanguageData lData, ILanguageDescriptor des){
String [] cTypeIds = des.getContentTypeIds(); String [] cTypeIds = des.getContentTypeIds();
String srcIds[] = lData.getSourceContentTypeIds(); String srcIds[] = lData.getSourceContentTypeIds();
Set<String> landTypes = new HashSet<String>(Arrays.asList(cTypeIds)); Set<String> landTypes = new HashSet<String>(Arrays.asList(cTypeIds));
landTypes.removeAll(Arrays.asList(srcIds)); landTypes.removeAll(Arrays.asList(srcIds));
if(landTypes.size() != 0){ if(landTypes.size() != 0){
List<String> srcList = new ArrayList<String>(); List<String> srcList = new ArrayList<String>();
srcList.addAll(landTypes); srcList.addAll(landTypes);
lData.setSourceContentTypeIds(srcList.toArray(new String[srcList.size()])); lData.setSourceContentTypeIds(srcList.toArray(new String[srcList.size()]));
} }
if(!des.getId().equals(lData.getLanguageId())){ if(!des.getId().equals(lData.getLanguageId())){
lData.setLanguageId(des.getId()); lData.setLanguageId(des.getId());
} }
return lData; return lData;
} }
private static void addLangs(CConfigurationData cfgData, CFolderData data, CDataFactory factory, Map<String, ILanguageDescriptor> langMap, Map<String, ILanguageDescriptor[]> cTypeToLangMap){ private static void addLangs(CConfigurationData cfgData, CFolderData data, CDataFactory factory, Map<String, ILanguageDescriptor> langMap, Map<String, ILanguageDescriptor[]> cTypeToLangMap){
List<ILanguageDescriptor> list = new ArrayList<ILanguageDescriptor>(langMap.values()); List<ILanguageDescriptor> list = new ArrayList<ILanguageDescriptor>(langMap.values());
ILanguageDescriptor des; ILanguageDescriptor des;
@ -579,10 +580,10 @@ public class CDataUtil {
} }
} }
} }
if(addLang){ if(addLang){
CLanguageData lData = factory.createLanguageData(cfgData, data, genId(data.getId()), des.getName(), des.getId(), CLanguageData lData = factory.createLanguageData(cfgData, data, genId(data.getId()), des.getName(), des.getId(),
ICLanguageSettingEntry.INCLUDE_FILE ICLanguageSettingEntry.INCLUDE_FILE
| ICLanguageSettingEntry.INCLUDE_PATH | ICLanguageSettingEntry.INCLUDE_PATH
| ICLanguageSettingEntry.MACRO | ICLanguageSettingEntry.MACRO
| ICLanguageSettingEntry.MACRO_FILE, | ICLanguageSettingEntry.MACRO_FILE,
@ -591,7 +592,7 @@ public class CDataUtil {
} }
} }
} }
public static boolean isExcluded(IPath path, ICSourceEntry[] entries){ public static boolean isExcluded(IPath path, ICSourceEntry[] entries){
for(int i = 0; i < entries.length; i++){ for(int i = 0; i < entries.length; i++){
if(!isExcluded(path, entries[i])) if(!isExcluded(path, entries[i]))
@ -599,16 +600,16 @@ public class CDataUtil {
} }
return true; return true;
} }
public static boolean isExcluded(IPath path, ICSourceEntry entry){ public static boolean isExcluded(IPath path, ICSourceEntry entry){
IPath entryPath = new Path(entry.getName()); IPath entryPath = new Path(entry.getName());
if(path.isPrefixOf(entryPath)) if(path.isPrefixOf(entryPath))
return false; return false;
if(!entryPath.isPrefixOf(path)) if(!entryPath.isPrefixOf(path))
return true; return true;
if(path.segmentCount() == 0) if(path.segmentCount() == 0)
return false; return false;
char[][] exclusions = entry.fullExclusionPatternChars(); char[][] exclusions = entry.fullExclusionPatternChars();
@ -617,13 +618,13 @@ public class CDataUtil {
public static boolean isOnSourceEntry(IPath path, ICSourceEntry entry){ public static boolean isOnSourceEntry(IPath path, ICSourceEntry entry){
IPath entryPath = new Path(entry.getName()); IPath entryPath = new Path(entry.getName());
if(path.equals(entryPath)) if(path.equals(entryPath))
return true; return true;
if(!entryPath.isPrefixOf(path)) if(!entryPath.isPrefixOf(path))
return false; return false;
if(path.segmentCount() == 0) if(path.segmentCount() == 0)
return true; return true;
char[][] exclusions = entry.fullExclusionPatternChars(); char[][] exclusions = entry.fullExclusionPatternChars();
@ -639,10 +640,10 @@ public class CDataUtil {
} }
/** /**
* *
* @param ein - initial source entries * @param ein - initial source entries
* @param aus - resulting source entries * @param aus - resulting source entries
* @return - true if they are equal * @return - true if they are equal
*/ */
public static boolean isEqual(ICSourceEntry[] ein, ICSourceEntry[] aus) { public static boolean isEqual(ICSourceEntry[] ein, ICSourceEntry[] aus) {
if (ein == null || aus == null) return (ein == null && aus == null); if (ein == null || aus == null) return (ein == null && aus == null);
@ -656,14 +657,14 @@ public class CDataUtil {
found = true; found = true;
break; break;
} }
return false; // contents is changed ! return false; // contents is changed !
} }
if (!found) if (!found)
return false; // name is not found ! return false; // name is not found !
} }
return true; // all entries are equal by name and contents return true; // all entries are equal by name and contents
} }
public static ICSourceEntry[] setExcluded(IPath path, boolean isFolder, boolean excluded, ICSourceEntry[] entries) throws CoreException { public static ICSourceEntry[] setExcluded(IPath path, boolean isFolder, boolean excluded, ICSourceEntry[] entries) throws CoreException {
return setExcluded(path, isFolder, excluded, entries, true); return setExcluded(path, isFolder, excluded, entries, true);
} }
@ -682,14 +683,14 @@ public class CDataUtil {
public static ICSourceEntry[] setExcluded(IPath path, boolean isFolder, boolean excluded, ICSourceEntry[] entries, boolean throwExceptionOnErr) throws CoreException { public static ICSourceEntry[] setExcluded(IPath path, boolean isFolder, boolean excluded, ICSourceEntry[] entries, boolean throwExceptionOnErr) throws CoreException {
if(isExcluded(path, entries) == excluded) if(isExcluded(path, entries) == excluded)
return entries; return entries;
ICSourceEntry[] newEntries; ICSourceEntry[] newEntries;
if(excluded){ if(excluded){
List<ICSourceEntry> includeList = new ArrayList<ICSourceEntry>(entries.length); List<ICSourceEntry> includeList = new ArrayList<ICSourceEntry>(entries.length);
List<ICSourceEntry> excludeList = new ArrayList<ICSourceEntry>(entries.length); List<ICSourceEntry> excludeList = new ArrayList<ICSourceEntry>(entries.length);
sortEntries(path, false, entries, includeList, excludeList); sortEntries(path, false, entries, includeList, excludeList);
for(int i = 0; i < includeList.size(); i++){ for(int i = 0; i < includeList.size(); i++){
ICSourceEntry oldEntry = includeList.get(i); ICSourceEntry oldEntry = includeList.get(i);
List<IPath> tmp = new ArrayList<IPath>(1); List<IPath> tmp = new ArrayList<IPath>(1);
@ -698,7 +699,7 @@ public class CDataUtil {
if(newEntry != null) if(newEntry != null)
excludeList.add(newEntry); excludeList.add(newEntry);
} }
newEntries = excludeList.toArray(new ICSourceEntry[excludeList.size()]); newEntries = excludeList.toArray(new ICSourceEntry[excludeList.size()]);
} else { } else {
List<ICSourceEntry> includeList = new ArrayList<ICSourceEntry>(entries.length + 1); List<ICSourceEntry> includeList = new ArrayList<ICSourceEntry>(entries.length + 1);
@ -710,7 +711,7 @@ public class CDataUtil {
if(includeExclusion(path, includeList) >= 0) if(includeExclusion(path, includeList) >= 0)
included = true; included = true;
} }
if(!included){ if(!included){
if(isFolder){ if(isFolder){
includeList.add(new CSourceEntry(path, null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED)); includeList.add(new CSourceEntry(path, null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED));
@ -720,14 +721,14 @@ public class CDataUtil {
return null; return null;
} }
} }
includeList.addAll(excludeList); includeList.addAll(excludeList);
newEntries = includeList.toArray(new ICSourceEntry[includeList.size()]); newEntries = includeList.toArray(new ICSourceEntry[includeList.size()]);
} }
return newEntries; return newEntries;
} }
private static int includeExclusion(IPath path, List<ICSourceEntry> entries){ private static int includeExclusion(IPath path, List<ICSourceEntry> entries){
for(int i = 0; i < entries.size(); i++){ for(int i = 0; i < entries.size(); i++){
ICSourceEntry entry = entries.get(i); ICSourceEntry entry = entries.get(i);
@ -739,7 +740,7 @@ public class CDataUtil {
} }
return -1; return -1;
} }
private static ICSourceEntry include(IPath path, ICSourceEntry entry){ private static ICSourceEntry include(IPath path, ICSourceEntry entry){
IPath[] exclusions = entry.getExclusionPatterns(); IPath[] exclusions = entry.getExclusionPatterns();
IPath entryPath = new Path(entry.getName()); IPath entryPath = new Path(entry.getName());
@ -758,7 +759,7 @@ public class CDataUtil {
} }
return null; return null;
} }
private static void sortIncludingExcludingEntries(IPath path, ICSourceEntry[] entries, List<ICSourceEntry> including, List<ICSourceEntry> excluding){ private static void sortIncludingExcludingEntries(IPath path, ICSourceEntry[] entries, List<ICSourceEntry> including, List<ICSourceEntry> excluding){
for(int i = 0; i < entries.length; i++){ for(int i = 0; i < entries.length; i++){
IPath entryPath = new Path(entries[i].getName()); IPath entryPath = new Path(entries[i].getName());
@ -785,7 +786,7 @@ public class CDataUtil {
} }
return new ICSourceEntry[]{entry}; return new ICSourceEntry[]{entry};
} }
private static ICOutputEntry[] getDefaultOutputEntries(boolean absolute, IProject project){ private static ICOutputEntry[] getDefaultOutputEntries(boolean absolute, IProject project){
ICOutputEntry entry; ICOutputEntry entry;
if(absolute){ if(absolute){
@ -802,14 +803,14 @@ public class CDataUtil {
public static ICOutputEntry[] adjustEntries(ICOutputEntry entries[], boolean makeAbsolute, IProject project){ public static ICOutputEntry[] adjustEntries(ICOutputEntry entries[], boolean makeAbsolute, IProject project){
if(entries == null || entries.length == 0) if(entries == null || entries.length == 0)
return getDefaultOutputEntries(makeAbsolute, project); return getDefaultOutputEntries(makeAbsolute, project);
return makeAbsolute ? makeAbsolute(project, entries) : makeRelative(project, entries); return makeAbsolute ? makeAbsolute(project, entries) : makeRelative(project, entries);
} }
public static ICSourceEntry[] adjustEntries(ICSourceEntry entries[], boolean makeAbsolute, IProject project){ public static ICSourceEntry[] adjustEntries(ICSourceEntry entries[], boolean makeAbsolute, IProject project){
if(entries == null || entries.length == 0) if(entries == null || entries.length == 0)
return getDefaultSourceEntries(makeAbsolute, project); return getDefaultSourceEntries(makeAbsolute, project);
ICSourceEntry ei, ej; ICSourceEntry ei, ej;
LinkedHashMap<ICSourceEntry, List<IPath>> map = new LinkedHashMap<ICSourceEntry, List<IPath>>(); LinkedHashMap<ICSourceEntry, List<IPath>> map = new LinkedHashMap<ICSourceEntry, List<IPath>>();
for(int i = 0; i < entries.length; i++){ for(int i = 0; i < entries.length; i++){
@ -819,7 +820,7 @@ public class CDataUtil {
ej = entries[j]; ej = entries[j];
if(ei == ej) if(ei == ej)
continue; continue;
IPath ejPath = new Path(ej.getName()); IPath ejPath = new Path(ej.getName());
if(!isExcluded(ejPath, ei)){ if(!isExcluded(ejPath, ei)){
if(list == null) if(list == null)
@ -827,7 +828,7 @@ public class CDataUtil {
list.add(ejPath); list.add(ejPath);
} }
} }
map.put(ei, list); map.put(ei, list);
} }
List<ICSourceEntry> resultList = new ArrayList<ICSourceEntry>(entries.length); List<ICSourceEntry> resultList = new ArrayList<ICSourceEntry>(entries.length);
@ -843,19 +844,28 @@ public class CDataUtil {
resultList.add(se); resultList.add(se);
} }
} }
if(makeAbsolute){ if(makeAbsolute){
if(project != null) if(project != null)
resultList = makeAbsolute(project, resultList); resultList = makeAbsolute(project, resultList);
} else { } else {
resultList = makeRelative(project, resultList); resultList = makeRelative(project, resultList);
} }
return resultList.toArray(new ICSourceEntry[resultList.size()]);
ICSourceEntry[] resultArray = resultList.toArray(new ICSourceEntry[resultList.size()]);
Arrays.sort(resultArray, new Comparator<ICSourceEntry>() {
@Override
public int compare(ICSourceEntry o1, ICSourceEntry o2) {
return o1.getFullPath().toString().compareTo(o2.getFullPath().toString());
}
});
return resultArray;
} }
private static List<ICSourceEntry> makeRelative(IProject project, List<ICSourceEntry> list){ private static List<ICSourceEntry> makeRelative(IProject project, List<ICSourceEntry> list){
int size = list.size(); int size = list.size();
for(int i = 0; i < size; i++){ for(int i = 0; i < size; i++){
list.set(i, makeRelative(project, list.get(i))); list.set(i, makeRelative(project, list.get(i)));
} }
@ -864,7 +874,7 @@ public class CDataUtil {
private static List<ICSourceEntry> makeAbsolute(IProject project, List<ICSourceEntry> list){ private static List<ICSourceEntry> makeAbsolute(IProject project, List<ICSourceEntry> list){
int size = list.size(); int size = list.size();
for(int i = 0; i < size; i++){ for(int i = 0; i < size; i++){
list.set(i, makeAbsolute(project, list.get(i))); list.set(i, makeAbsolute(project, list.get(i)));
} }
@ -919,26 +929,26 @@ public class CDataUtil {
public static ICSourceEntry addExcludePaths(ICSourceEntry entry, Collection<IPath> paths, boolean removePrefix){ public static ICSourceEntry addExcludePaths(ICSourceEntry entry, Collection<IPath> paths, boolean removePrefix){
IPath entryPath = new Path(entry.getName()); IPath entryPath = new Path(entry.getName());
IPath[] oldExclusions = entry.getExclusionPatterns(); IPath[] oldExclusions = entry.getExclusionPatterns();
// List newExList = new ArrayList(oldExclusions.length + paths.size()); // List newExList = new ArrayList(oldExclusions.length + paths.size());
LinkedHashSet<IPath> newSet = new LinkedHashSet<IPath>(); LinkedHashSet<IPath> newSet = new LinkedHashSet<IPath>();
if(removePrefix){ if(removePrefix){
removePrefix(entryPath, paths, newSet); removePrefix(entryPath, paths, newSet);
} else { } else {
newSet.addAll(paths); newSet.addAll(paths);
} }
for(Iterator<IPath> iter = newSet.iterator(); iter.hasNext();){ for(Iterator<IPath> iter = newSet.iterator(); iter.hasNext();){
IPath path = iter.next(); IPath path = iter.next();
if(path.segmentCount() == 0) if(path.segmentCount() == 0)
return null; return null;
} }
newSet.addAll(Arrays.asList(oldExclusions)); newSet.addAll(Arrays.asList(oldExclusions));
IPath[] newExclusions = newSet.toArray(new IPath[newSet.size()]); IPath[] newExclusions = newSet.toArray(new IPath[newSet.size()]);
return new CSourceEntry(entry.getName(), newExclusions, entry.getFlags()); return new CSourceEntry(entry.getName(), newExclusions, entry.getFlags());
} }
private static void sortEntries(IPath path, boolean byExclude, ICSourceEntry[] entries, List<ICSourceEntry> included, List<ICSourceEntry> excluded){ private static void sortEntries(IPath path, boolean byExclude, ICSourceEntry[] entries, List<ICSourceEntry> included, List<ICSourceEntry> excluded){
for(int i = 0; i < entries.length; i++){ for(int i = 0; i < entries.length; i++){
if(byExclude ? isExcluded(path, entries[i]) : !isOnSourceEntry(path, entries[i])){ if(byExclude ? isExcluded(path, entries[i]) : !isOnSourceEntry(path, entries[i])){
@ -950,11 +960,11 @@ public class CDataUtil {
} }
} }
} }
public static Map<EntryNameKey, ICSettingEntry> fillEntriesMapByNameKey(Map<EntryNameKey, ICSettingEntry> map, ICSettingEntry[] entries){ public static Map<EntryNameKey, ICSettingEntry> fillEntriesMapByNameKey(Map<EntryNameKey, ICSettingEntry> map, ICSettingEntry[] entries){
if(map == null) if(map == null)
map = new LinkedHashMap<EntryNameKey, ICSettingEntry>(); map = new LinkedHashMap<EntryNameKey, ICSettingEntry>();
for(int i = 0; i < entries.length; i++){ for(int i = 0; i < entries.length; i++){
ICSettingEntry entry = entries[i]; ICSettingEntry entry = entries[i];
map.put(new EntryNameKey(entry), entry); map.put(new EntryNameKey(entry), entry);
@ -965,14 +975,14 @@ public class CDataUtil {
public static Map<EntryContentsKey, ICSettingEntry> fillEntriesMapByContentsKey(Map<EntryContentsKey, ICSettingEntry> map, ICSettingEntry[] entries){ public static Map<EntryContentsKey, ICSettingEntry> fillEntriesMapByContentsKey(Map<EntryContentsKey, ICSettingEntry> map, ICSettingEntry[] entries){
if(map == null) if(map == null)
map = new LinkedHashMap<EntryContentsKey, ICSettingEntry>(); map = new LinkedHashMap<EntryContentsKey, ICSettingEntry>();
for(int i = 0; i < entries.length; i++){ for(int i = 0; i < entries.length; i++){
ICSettingEntry entry = entries[i]; ICSettingEntry entry = entries[i];
map.put(new EntryContentsKey(entry), entry); map.put(new EntryContentsKey(entry), entry);
} }
return map; return map;
} }
public static boolean getBoolean(ICStorageElement el, String attr, boolean defaultValue){ public static boolean getBoolean(ICStorageElement el, String attr, boolean defaultValue){
if(el != null){ if(el != null){
String tmp = el.getAttribute(attr); String tmp = el.getAttribute(attr);
@ -1003,14 +1013,14 @@ public class CDataUtil {
public static void setInteger(ICStorageElement el, String attr, int value){ public static void setInteger(ICStorageElement el, String attr, int value){
el.setAttribute(attr, new Integer(value).toString()); el.setAttribute(attr, new Integer(value).toString());
} }
public static ICExclusionPatternPathEntry addRemoveExclusionsToEntry(ICExclusionPatternPathEntry entry, IPath[] paths, boolean add) throws IllegalArgumentException{ public static ICExclusionPatternPathEntry addRemoveExclusionsToEntry(ICExclusionPatternPathEntry entry, IPath[] paths, boolean add) throws IllegalArgumentException{
if(paths == null || paths.length == 0) if(paths == null || paths.length == 0)
return entry; return entry;
Set<IPath> set = mergeRemovingDups(entry.getExclusionPatterns(), paths, add); Set<IPath> set = mergeRemovingDups(entry.getExclusionPatterns(), paths, add);
IPath exclusions[] = set.toArray(new IPath[set.size()]); IPath exclusions[] = set.toArray(new IPath[set.size()]);
return (ICExclusionPatternPathEntry)createEntry(entry.getKind(), entry.getName(), null, exclusions, entry.getFlags()); return (ICExclusionPatternPathEntry)createEntry(entry.getKind(), entry.getName(), null, exclusions, entry.getFlags());
} }
@ -1023,7 +1033,7 @@ public class CDataUtil {
set.removeAll(Arrays.asList(o2)); set.removeAll(Arrays.asList(o2));
return set; return set;
} }
public static ICExclusionPatternPathEntry makeAbsolute(IProject project, ICExclusionPatternPathEntry entry, boolean force){ public static ICExclusionPatternPathEntry makeAbsolute(IProject project, ICExclusionPatternPathEntry entry, boolean force){
if(!entry.isValueWorkspacePath() && !force) if(!entry.isValueWorkspacePath() && !force)
return entry; return entry;
@ -1036,14 +1046,14 @@ public class CDataUtil {
} }
return entry; return entry;
} }
public static ICExclusionPatternPathEntry makeRelative(IProject project, ICExclusionPatternPathEntry entry, boolean force){ public static ICExclusionPatternPathEntry makeRelative(IProject project, ICExclusionPatternPathEntry entry, boolean force){
if(!entry.isValueWorkspacePath() && !force) if(!entry.isValueWorkspacePath() && !force)
return entry; return entry;
IPath path = new Path(entry.getName()); IPath path = new Path(entry.getName());
IPath projPath = project.getFullPath(); IPath projPath = project.getFullPath();
if(path.isAbsolute()){ if(path.isAbsolute()){
if(projPath.isPrefixOf(path)) if(projPath.isPrefixOf(path))
path = path.removeFirstSegments(projPath.segmentCount()).makeRelative(); path = path.removeFirstSegments(projPath.segmentCount()).makeRelative();
@ -1053,22 +1063,22 @@ public class CDataUtil {
} }
return entry; return entry;
} }
public static ICExclusionPatternPathEntry[] makeRelative(IProject project, ICExclusionPatternPathEntry[] entries, boolean force){ public static ICExclusionPatternPathEntry[] makeRelative(IProject project, ICExclusionPatternPathEntry[] entries, boolean force){
if(entries == null) if(entries == null)
return null; return null;
ICExclusionPatternPathEntry[] relEntries = (ICExclusionPatternPathEntry[])Array.newInstance(entries.getClass().getComponentType(), entries.length); ICExclusionPatternPathEntry[] relEntries = (ICExclusionPatternPathEntry[])Array.newInstance(entries.getClass().getComponentType(), entries.length);
for(int i = 0; i < entries.length; i++){ for(int i = 0; i < entries.length; i++){
relEntries[i] = makeRelative(project, entries[i], force); relEntries[i] = makeRelative(project, entries[i], force);
} }
return relEntries; return relEntries;
} }
public static ICExclusionPatternPathEntry[] makeAbsolute(IProject project, ICExclusionPatternPathEntry[] entries, boolean force){ public static ICExclusionPatternPathEntry[] makeAbsolute(IProject project, ICExclusionPatternPathEntry[] entries, boolean force){
if(entries == null) if(entries == null)
return null; return null;
ICExclusionPatternPathEntry[] relEntries = (ICExclusionPatternPathEntry[])Array.newInstance(entries.getClass().getComponentType(), entries.length); ICExclusionPatternPathEntry[] relEntries = (ICExclusionPatternPathEntry[])Array.newInstance(entries.getClass().getComponentType(), entries.length);
for(int i = 0; i < entries.length; i++){ for(int i = 0; i < entries.length; i++){
relEntries[i] = makeAbsolute(project, entries[i], force); relEntries[i] = makeAbsolute(project, entries[i], force);