From 6340ae683dc27564cf0610c92d7a5459d41c87a4 Mon Sep 17 00:00:00 2001 From: Mikhail Sennikovsky Date: Mon, 23 Apr 2007 13:36:18 +0000 Subject: [PATCH] Core functionality fix for [Bug 182820] [Exclusion/Inclusion] Included source FILE appears as source FOLDER --- .../managedbuilder/core/IResourceInfo.java | 2 + .../internal/core/Configuration.java | 30 ++++- .../internal/core/FolderInfo.java | 4 + .../internal/core/ResourceConfiguration.java | 4 + .../internal/core/ResourceInfo.java | 12 +- .../ui/tests/util/TestFolderInfo.java | 5 + .../settings/model/ICResourceDescription.java | 2 + .../core/settings/model/util/CDataUtil.java | 115 ++++++++++++++++-- .../model/CConfigurationDescription.java | 33 +++-- .../core/settings/model/CFileDescription.java | 6 +- .../settings/model/CFileDescriptionCache.java | 4 + .../settings/model/CFolderDescription.java | 8 +- .../model/CFolderDescriptionCache.java | 4 + 13 files changed, 203 insertions(+), 26 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceInfo.java index c0c0440be95..d3d4553a867 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceInfo.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IResourceInfo.java @@ -31,6 +31,8 @@ public interface IResourceInfo extends IBuildObject { void setExclude(boolean excluded); + boolean canExclude(boolean exclude); + boolean isDirty(); boolean needsRebuild(); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java index c80f2b4e030..5faa5505860 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java @@ -2952,18 +2952,38 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild return CDataUtil.isExcluded(path, entries); } - void setExcluded(IPath path, boolean excluded){ + void setExcluded(IPath path, boolean isFolder, boolean excluded){ // if(path.segmentCount() == 0) // return; if(excludeList == null) { - ICSourceEntry[] entries = getSourceEntries(); - ICSourceEntry[] newEntries = CDataUtil.setExcluded(path, excluded, entries); - setSourceEntries(newEntries, false); + ICSourceEntry[] newEntries = getUpdatedEntries(path, isFolder, excluded); + if(newEntries != null) + setSourceEntries(newEntries, false); } else{ if(excluded) excludeList.add(path); } - + } + + private ICSourceEntry[] getUpdatedEntries(IPath path, boolean isFolder, boolean excluded){ + try { + ICSourceEntry[] entries = getSourceEntries(); + return CDataUtil.setExcluded(path, isFolder, excluded, entries, false); + } catch (CoreException e) { + ManagedBuilderCorePlugin.log(e); + } + return null; + } + + boolean canExclude(IPath path, boolean isFolder, boolean excluded){ + if(excludeList == null) { + ICSourceEntry[] newEntries = getUpdatedEntries(path, isFolder, excluded); + return newEntries != null; + } else{ + if(excluded) + excludeList.add(path); + return true; + } } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/FolderInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/FolderInfo.java index 9e4599c7eac..adcc5ced36f 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/FolderInfo.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/FolderInfo.java @@ -1369,4 +1369,8 @@ public class FolderInfo extends ResourceInfo implements IFolderInfo { public void setContainsDiscoveredScannerInfo(boolean contains){ containsDiscoveredScannerInfo = contains; } + + public boolean isFolderInfo() { + return true; + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java index 84a52cba9ca..00616cd644a 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceConfiguration.java @@ -1064,4 +1064,8 @@ public class ResourceConfiguration extends ResourceInfo implements IFileInfo { toolList = newToolList; } + + public boolean isFolderInfo() { + return false; + } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceInfo.java index bdb77d47f41..d303c3dbdb2 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceInfo.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceInfo.java @@ -165,7 +165,7 @@ public abstract class ResourceInfo extends BuildObject implements IResourceInfo // exclude String excludeStr = element.getAttribute(EXCLUDE); if (excludeStr != null){ - config.setExcluded(getPath(), ("true".equals(excludeStr))); //$NON-NLS-1$ + config.setExcluded(getPath(), isFolderInfo(), ("true".equals(excludeStr))); //$NON-NLS-1$ } } @@ -197,7 +197,7 @@ public abstract class ResourceInfo extends BuildObject implements IResourceInfo if (element.getAttribute(EXCLUDE) != null) { String excludeStr = element.getAttribute(EXCLUDE); if (excludeStr != null){ - config.setExcluded(getPath(), ("true".equals(excludeStr))); //$NON-NLS-1$ + config.setExcluded(getPath(), isFolderInfo(), ("true".equals(excludeStr))); //$NON-NLS-1$ } } @@ -247,12 +247,18 @@ public abstract class ResourceInfo extends BuildObject implements IResourceInfo if(isExcluded() == excluded) return; - config.setExcluded(getPath(), excluded); + config.setExcluded(getPath(), isFolderInfo(), excluded); setDirty(true); setRebuildState(true); } + public boolean canExclude(boolean exclude) { + return config.canExclude(getPath(), isFolderInfo(), exclude); + } + + public abstract boolean isFolderInfo(); + // private boolean internalSetExclude(boolean excluded){ //// if(excluded/* && isRoot()*/) //// return isExcluded; diff --git a/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/util/TestFolderInfo.java b/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/util/TestFolderInfo.java index 76d737fcca1..ea1f4e8bc3a 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/util/TestFolderInfo.java +++ b/build/org.eclipse.cdt.managedbuilder.ui.tests/src/org/eclipse/cdt/managedbuilder/ui/tests/util/TestFolderInfo.java @@ -221,4 +221,9 @@ public class TestFolderInfo implements IFolderInfo { } + public boolean canExclude(boolean exclude) { + // TODO Auto-generated method stub + return false; + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICResourceDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICResourceDescription.java index 689e40a66c0..0489487b51d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICResourceDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICResourceDescription.java @@ -24,4 +24,6 @@ public interface ICResourceDescription extends ICSettingContainer, ICSettingObje void setPath(IPath path) throws WriteAccessException ; ICFolderDescription getParentFolderDescription(); + + boolean canExclude(boolean exclude); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CDataUtil.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CDataUtil.java index 0fc48e59ca6..7650b7b9d60 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CDataUtil.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CDataUtil.java @@ -54,8 +54,10 @@ import org.eclipse.cdt.core.settings.model.extension.CResourceData; import org.eclipse.cdt.core.settings.model.extension.CTargetPlatformData; import org.eclipse.cdt.core.settings.model.extension.impl.CDataFacroty; import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultLanguageData; +import org.eclipse.cdt.internal.core.settings.model.ExceptionFactory; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; @@ -557,8 +559,46 @@ public class CDataUtil { char[][] exclusions = entry.fullExclusionPatternChars(); return CoreModelUtil.isExcluded(path, exclusions); } - - public static ICSourceEntry[] setExcluded(IPath path, boolean excluded, ICSourceEntry[] entries){ + + public static boolean isOnSourceEntry(IPath path, ICSourceEntry entry){ + IPath entryPath = new Path(entry.getName()); + + if(path.equals(entryPath)) + return true; + + if(!entryPath.isPrefixOf(path)) + return false; + + if(path.segmentCount() == 0) + return true; + char[][] exclusions = entry.fullExclusionPatternChars(); + return !CoreModelUtil.isExcluded(path, exclusions); + } + + public static boolean canExclude(IPath path, boolean isFolder, boolean excluded, ICSourceEntry[] entries){ + try { + return setExcluded(path, isFolder, excluded, entries, false) != null; + } catch (CoreException e) { + } + return false; + } + + public static ICSourceEntry[] setExcluded(IPath path, boolean isFolder, boolean excluded, ICSourceEntry[] entries) throws CoreException { + return setExcluded(path, isFolder, excluded, entries, true); + } + + public static ICSourceEntry[] setExcludedIfPossible(IPath path, boolean isFolder, boolean excluded, ICSourceEntry[] entries) { + try { + ICSourceEntry[] newEntries = setExcluded(path, isFolder, excluded, entries, false); + if(newEntries == null) + newEntries = entries; + return newEntries; + } catch (CoreException e) { + } + return entries; + } + + public static ICSourceEntry[] setExcluded(IPath path, boolean isFolder, boolean excluded, ICSourceEntry[] entries, boolean throwExceptionOnErr) throws CoreException { if(isExcluded(path, entries) == excluded) return entries; @@ -567,7 +607,7 @@ public class CDataUtil { List includeList = new ArrayList(entries.length); List excludeList = new ArrayList(entries.length); - sortEntries(path, entries, includeList, excludeList); + sortEntries(path, false, entries, includeList, excludeList); for(int i = 0; i < includeList.size(); i++){ ICSourceEntry oldEntry = (ICSourceEntry)includeList.get(i); @@ -580,13 +620,72 @@ public class CDataUtil { newEntries = (ICSourceEntry[])excludeList.toArray(new ICSourceEntry[excludeList.size()]); } else { - newEntries = new ICSourceEntry[entries.length + 1]; - System.arraycopy(entries, 0, newEntries, 0, entries.length); - newEntries[entries.length] = new CSourceEntry(path, null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED); + List includeList = new ArrayList(entries.length + 1); + List excludeList = new ArrayList(entries.length); + + sortIncludingExcludingEntries(path, entries, includeList, excludeList); + boolean included = false; + if(includeList.size() != 0){ + if(includeExclusion(path, includeList) >= 0) + included = true; + } + + if(!included){ + if(isFolder){ + includeList.add(new CSourceEntry(path, null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED)); + } else { + if(throwExceptionOnErr) + throw ExceptionFactory.createCoreException("can not create a source entry for individual file"); + return null; + } + } + + includeList.addAll(excludeList); + newEntries = (ICSourceEntry[])includeList.toArray(new ICSourceEntry[includeList.size()]); } return newEntries; } + + private static int includeExclusion(IPath path, List entries){ + for(int i = 0; i < entries.size(); i++){ + ICSourceEntry entry = (ICSourceEntry)entries.get(i); + entry = include(path, entry); + if(entry != null) + entries.set(i, entry); + return i; + } + return -1; + } + + private static ICSourceEntry include(IPath path, ICSourceEntry entry){ + IPath[] exclusions = entry.getExclusionPatterns(); + IPath entryPath = new Path(entry.getName()); + IPath relPath = path.removeFirstSegments(entryPath.segmentCount()).makeRelative(); + for(int k = 0; k < exclusions.length; k++){ + if(exclusions[k].equals(relPath)){ + IPath updatedExclusions[] = new IPath[exclusions.length - 1]; + System.arraycopy(exclusions, 0, updatedExclusions, 0, k); + System.arraycopy(exclusions, k + 1, updatedExclusions, k, updatedExclusions.length - k); + ICSourceEntry updatedEntry = new CSourceEntry(entry.getName(), updatedExclusions, entry.getFlags()); + if(isOnSourceEntry(path, updatedEntry)) + return updatedEntry; + exclusions = updatedExclusions; + entry = updatedEntry; + } + } + return null; + } + + private static void sortIncludingExcludingEntries(IPath path, ICSourceEntry[] entries, List including, List excluding){ + for(int i = 0; i < entries.length; i++){ + IPath entryPath = new Path(entries[i].getName()); + if(entryPath.isPrefixOf(path)) + including.add(entries[i]); + else + excluding.add(entries[i]); + } + } public static ICSourceEntry[] adjustEntries(ICSourceEntry entries[]){ return adjustEntries(entries, false, null); @@ -734,9 +833,9 @@ public class CDataUtil { return new CSourceEntry(entry.getName(), newExclusions, entry.getFlags()); } - private static void sortEntries(IPath path, ICSourceEntry[] entries, List included, List excluded){ + private static void sortEntries(IPath path, boolean byExclude, ICSourceEntry[] entries, List included, List excluded){ for(int i = 0; i < entries.length; i++){ - if(isExcluded(path, entries[i])){ + if(byExclude ? isExcluded(path, entries[i]) : !isOnSourceEntry(path, entries[i])){ if(excluded != null) excluded.add(entries[i]); } else { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java index e7739ae8943..6c3aebd82a4 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CConfigurationDescription.java @@ -753,12 +753,32 @@ public class CConfigurationDescription extends CDataProxyContainer implements IC return CDataUtil.isExcluded(path, entries); } - void setExcluded(IPath path, boolean exclude){ + void setExcluded(IPath path, boolean isFolder, boolean exclude){ // if(path.segmentCount() == 0) // return; if(isExcluded(path) == exclude) return; + ICSourceEntry[] newEntries = getUpdatedSourceEntries(path, isFolder, exclude); + if(newEntries != null) { + try { + setSourceEntries(newEntries); + } catch (CoreException e) { + CCorePlugin.log(e); + } + } + } + + boolean canExclude(IPath path, boolean isFolder, boolean exclude){ + if(isExcluded(path) == exclude) + return true; + + return getUpdatedSourceEntries(path, isFolder, exclude) != null; + } + + private ICSourceEntry[] getUpdatedSourceEntries(IPath path, boolean isFolder, boolean exclude){ +// if(path.segmentCount() == 0) +// return; IProject project = fIsPreference ? null : getProjectDescription().getProject(); if(project != null) path = project.getFullPath().append(path); @@ -782,14 +802,13 @@ public class CConfigurationDescription extends CDataProxyContainer implements IC } if(newEntries == null){ - newEntries = CDataUtil.setExcluded(path, exclude, getResolvedSourceEntries()); + try { + newEntries = CDataUtil.setExcluded(path, isFolder, exclude, getResolvedSourceEntries(), false); + } catch (CoreException e) { + } } - try { - setSourceEntries(newEntries); - } catch (CoreException e) { - CCorePlugin.log(e); - } + return newEntries; } public String[] getExternalSettingsProviderIds() { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CFileDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CFileDescription.java index 072fd04addf..d68716c7c4b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CFileDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CFileDescription.java @@ -43,7 +43,7 @@ public class CFileDescription extends CDataProxyContainer implements public void setExcluded(boolean excluded) { CConfigurationDescription cfg = (CConfigurationDescription)getConfiguration(); - cfg.setExcluded(getPath(), excluded); + cfg.setExcluded(getPath(), false, excluded); } public void setPath(IPath path) { @@ -128,4 +128,8 @@ public class CFileDescription extends CDataProxyContainer implements return fCache; } + public boolean canExclude(boolean exclude) { + CConfigurationDescription cfg = (CConfigurationDescription)getConfiguration(); + return cfg.canExclude(getPath(), false, exclude); + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CFileDescriptionCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CFileDescriptionCache.java index 0992e9cf667..33b605ee209 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CFileDescriptionCache.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CFileDescriptionCache.java @@ -42,6 +42,10 @@ public class CFileDescriptionCache extends CDefaultFileData implements public void setExcluded(boolean excluded) throws WriteAccessException { throw ExceptionFactory.createIsReadOnlyException(); } + + public boolean canExclude(boolean exclude) { + return exclude == isExcluded(); + } public void setName(String name) throws WriteAccessException{ throw ExceptionFactory.createIsReadOnlyException(); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CFolderDescription.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CFolderDescription.java index 11b4b6a7070..41e02b783bb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CFolderDescription.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CFolderDescription.java @@ -45,7 +45,7 @@ public class CFolderDescription extends CDataProxyContainer implements public void setExcluded(boolean excluded) { CConfigurationDescription cfg = (CConfigurationDescription)getConfiguration(); - cfg.setExcluded(getPath(), excluded); + cfg.setExcluded(getPath(), true, excluded); } public void setPath(IPath path) { @@ -188,8 +188,12 @@ public class CFolderDescription extends CDataProxyContainer implements return (ICLanguageSetting)proxy; } - public boolean isRoot() { return getPath().segmentCount() == 0; } + + public boolean canExclude(boolean exclude) { + CConfigurationDescription cfg = (CConfigurationDescription)getConfiguration(); + return cfg.canExclude(getPath(), true, exclude); + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CFolderDescriptionCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CFolderDescriptionCache.java index 338645d911f..b59baac8424 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CFolderDescriptionCache.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CFolderDescriptionCache.java @@ -75,6 +75,10 @@ public class CFolderDescriptionCache extends CDefaultFolderData implements throw ExceptionFactory.createIsReadOnlyException(); } + public boolean canExclude(boolean exclude) { + return exclude == isExcluded(); + } + public void setPath(IPath path) throws WriteAccessException { throw ExceptionFactory.createIsReadOnlyException(); }