1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-21 07:55:24 +02:00

Core functionality fix for [Bug 182820] [Exclusion/Inclusion] Included source FILE appears as source FOLDER

This commit is contained in:
Mikhail Sennikovsky 2007-04-23 13:36:18 +00:00
parent 325c59736a
commit 6340ae683d
13 changed files with 203 additions and 26 deletions

View file

@ -31,6 +31,8 @@ public interface IResourceInfo extends IBuildObject {
void setExclude(boolean excluded); void setExclude(boolean excluded);
boolean canExclude(boolean exclude);
boolean isDirty(); boolean isDirty();
boolean needsRebuild(); boolean needsRebuild();

View file

@ -2952,18 +2952,38 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild
return CDataUtil.isExcluded(path, entries); return CDataUtil.isExcluded(path, entries);
} }
void setExcluded(IPath path, boolean excluded){ void setExcluded(IPath path, boolean isFolder, boolean excluded){
// if(path.segmentCount() == 0) // if(path.segmentCount() == 0)
// return; // return;
if(excludeList == null) { if(excludeList == null) {
ICSourceEntry[] entries = getSourceEntries(); ICSourceEntry[] newEntries = getUpdatedEntries(path, isFolder, excluded);
ICSourceEntry[] newEntries = CDataUtil.setExcluded(path, excluded, entries); if(newEntries != null)
setSourceEntries(newEntries, false); setSourceEntries(newEntries, false);
} else{ } else{
if(excluded) if(excluded)
excludeList.add(path); 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;
}
} }
} }

View file

@ -1369,4 +1369,8 @@ public class FolderInfo extends ResourceInfo implements IFolderInfo {
public void setContainsDiscoveredScannerInfo(boolean contains){ public void setContainsDiscoveredScannerInfo(boolean contains){
containsDiscoveredScannerInfo = contains; containsDiscoveredScannerInfo = contains;
} }
public boolean isFolderInfo() {
return true;
}
} }

View file

@ -1064,4 +1064,8 @@ public class ResourceConfiguration extends ResourceInfo implements IFileInfo {
toolList = newToolList; toolList = newToolList;
} }
public boolean isFolderInfo() {
return false;
}
} }

View file

@ -165,7 +165,7 @@ public abstract class ResourceInfo extends BuildObject implements IResourceInfo
// exclude // exclude
String excludeStr = element.getAttribute(EXCLUDE); String excludeStr = element.getAttribute(EXCLUDE);
if (excludeStr != null){ 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) { if (element.getAttribute(EXCLUDE) != null) {
String excludeStr = element.getAttribute(EXCLUDE); String excludeStr = element.getAttribute(EXCLUDE);
if (excludeStr != null){ 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) if(isExcluded() == excluded)
return; return;
config.setExcluded(getPath(), excluded); config.setExcluded(getPath(), isFolderInfo(), excluded);
setDirty(true); setDirty(true);
setRebuildState(true); setRebuildState(true);
} }
public boolean canExclude(boolean exclude) {
return config.canExclude(getPath(), isFolderInfo(), exclude);
}
public abstract boolean isFolderInfo();
// private boolean internalSetExclude(boolean excluded){ // private boolean internalSetExclude(boolean excluded){
//// if(excluded/* && isRoot()*/) //// if(excluded/* && isRoot()*/)
//// return isExcluded; //// return isExcluded;

View file

@ -221,4 +221,9 @@ public class TestFolderInfo implements IFolderInfo {
} }
public boolean canExclude(boolean exclude) {
// TODO Auto-generated method stub
return false;
}
} }

View file

@ -24,4 +24,6 @@ public interface ICResourceDescription extends ICSettingContainer, ICSettingObje
void setPath(IPath path) throws WriteAccessException ; void setPath(IPath path) throws WriteAccessException ;
ICFolderDescription getParentFolderDescription(); ICFolderDescription getParentFolderDescription();
boolean canExclude(boolean exclude);
} }

View file

@ -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.CTargetPlatformData;
import org.eclipse.cdt.core.settings.model.extension.impl.CDataFacroty; import org.eclipse.cdt.core.settings.model.extension.impl.CDataFacroty;
import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultLanguageData; 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.IProject;
import org.eclipse.core.resources.ProjectScope; import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
@ -558,7 +560,45 @@ public class CDataUtil {
return CoreModelUtil.isExcluded(path, exclusions); 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) if(isExcluded(path, entries) == excluded)
return entries; return entries;
@ -567,7 +607,7 @@ public class CDataUtil {
List includeList = new ArrayList(entries.length); List includeList = new ArrayList(entries.length);
List excludeList = 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++){ for(int i = 0; i < includeList.size(); i++){
ICSourceEntry oldEntry = (ICSourceEntry)includeList.get(i); ICSourceEntry oldEntry = (ICSourceEntry)includeList.get(i);
@ -580,14 +620,73 @@ public class CDataUtil {
newEntries = (ICSourceEntry[])excludeList.toArray(new ICSourceEntry[excludeList.size()]); newEntries = (ICSourceEntry[])excludeList.toArray(new ICSourceEntry[excludeList.size()]);
} else { } else {
newEntries = new ICSourceEntry[entries.length + 1]; List includeList = new ArrayList(entries.length + 1);
System.arraycopy(entries, 0, newEntries, 0, entries.length); List excludeList = new ArrayList(entries.length);
newEntries[entries.length] = new CSourceEntry(path, null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED);
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; 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[]){ public static ICSourceEntry[] adjustEntries(ICSourceEntry entries[]){
return adjustEntries(entries, false, null); return adjustEntries(entries, false, null);
} }
@ -734,9 +833,9 @@ public class CDataUtil {
return new CSourceEntry(entry.getName(), newExclusions, entry.getFlags()); 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++){ 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) if(excluded != null)
excluded.add(entries[i]); excluded.add(entries[i]);
} else { } else {

View file

@ -753,12 +753,32 @@ public class CConfigurationDescription extends CDataProxyContainer implements IC
return CDataUtil.isExcluded(path, entries); return CDataUtil.isExcluded(path, entries);
} }
void setExcluded(IPath path, boolean exclude){ void setExcluded(IPath path, boolean isFolder, boolean exclude){
// if(path.segmentCount() == 0) // if(path.segmentCount() == 0)
// return; // return;
if(isExcluded(path) == exclude) if(isExcluded(path) == exclude)
return; 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(); IProject project = fIsPreference ? null : getProjectDescription().getProject();
if(project != null) if(project != null)
path = project.getFullPath().append(path); path = project.getFullPath().append(path);
@ -782,14 +802,13 @@ public class CConfigurationDescription extends CDataProxyContainer implements IC
} }
if(newEntries == null){ if(newEntries == null){
newEntries = CDataUtil.setExcluded(path, exclude, getResolvedSourceEntries()); try {
newEntries = CDataUtil.setExcluded(path, isFolder, exclude, getResolvedSourceEntries(), false);
} catch (CoreException e) {
}
} }
try { return newEntries;
setSourceEntries(newEntries);
} catch (CoreException e) {
CCorePlugin.log(e);
}
} }
public String[] getExternalSettingsProviderIds() { public String[] getExternalSettingsProviderIds() {

View file

@ -43,7 +43,7 @@ public class CFileDescription extends CDataProxyContainer implements
public void setExcluded(boolean excluded) { public void setExcluded(boolean excluded) {
CConfigurationDescription cfg = (CConfigurationDescription)getConfiguration(); CConfigurationDescription cfg = (CConfigurationDescription)getConfiguration();
cfg.setExcluded(getPath(), excluded); cfg.setExcluded(getPath(), false, excluded);
} }
public void setPath(IPath path) { public void setPath(IPath path) {
@ -128,4 +128,8 @@ public class CFileDescription extends CDataProxyContainer implements
return fCache; return fCache;
} }
public boolean canExclude(boolean exclude) {
CConfigurationDescription cfg = (CConfigurationDescription)getConfiguration();
return cfg.canExclude(getPath(), false, exclude);
}
} }

View file

@ -43,6 +43,10 @@ public class CFileDescriptionCache extends CDefaultFileData implements
throw ExceptionFactory.createIsReadOnlyException(); throw ExceptionFactory.createIsReadOnlyException();
} }
public boolean canExclude(boolean exclude) {
return exclude == isExcluded();
}
public void setName(String name) throws WriteAccessException{ public void setName(String name) throws WriteAccessException{
throw ExceptionFactory.createIsReadOnlyException(); throw ExceptionFactory.createIsReadOnlyException();
} }

View file

@ -45,7 +45,7 @@ public class CFolderDescription extends CDataProxyContainer implements
public void setExcluded(boolean excluded) { public void setExcluded(boolean excluded) {
CConfigurationDescription cfg = (CConfigurationDescription)getConfiguration(); CConfigurationDescription cfg = (CConfigurationDescription)getConfiguration();
cfg.setExcluded(getPath(), excluded); cfg.setExcluded(getPath(), true, excluded);
} }
public void setPath(IPath path) { public void setPath(IPath path) {
@ -188,8 +188,12 @@ public class CFolderDescription extends CDataProxyContainer implements
return (ICLanguageSetting)proxy; return (ICLanguageSetting)proxy;
} }
public boolean isRoot() { public boolean isRoot() {
return getPath().segmentCount() == 0; return getPath().segmentCount() == 0;
} }
public boolean canExclude(boolean exclude) {
CConfigurationDescription cfg = (CConfigurationDescription)getConfiguration();
return cfg.canExclude(getPath(), true, exclude);
}
} }

View file

@ -75,6 +75,10 @@ public class CFolderDescriptionCache extends CDefaultFolderData implements
throw ExceptionFactory.createIsReadOnlyException(); throw ExceptionFactory.createIsReadOnlyException();
} }
public boolean canExclude(boolean exclude) {
return exclude == isExcluded();
}
public void setPath(IPath path) throws WriteAccessException { public void setPath(IPath path) throws WriteAccessException {
throw ExceptionFactory.createIsReadOnlyException(); throw ExceptionFactory.createIsReadOnlyException();
} }