mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-20 23:45:23 +02:00
Core functionality fix for [Bug 182820] [Exclusion/Inclusion] Included source FILE appears as source FOLDER
This commit is contained in:
parent
325c59736a
commit
6340ae683d
13 changed files with 203 additions and 26 deletions
|
@ -31,6 +31,8 @@ public interface IResourceInfo extends IBuildObject {
|
|||
|
||||
void setExclude(boolean excluded);
|
||||
|
||||
boolean canExclude(boolean exclude);
|
||||
|
||||
boolean isDirty();
|
||||
|
||||
boolean needsRebuild();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1369,4 +1369,8 @@ public class FolderInfo extends ResourceInfo implements IFolderInfo {
|
|||
public void setContainsDiscoveredScannerInfo(boolean contains){
|
||||
containsDiscoveredScannerInfo = contains;
|
||||
}
|
||||
|
||||
public boolean isFolderInfo() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1064,4 +1064,8 @@ public class ResourceConfiguration extends ResourceInfo implements IFileInfo {
|
|||
|
||||
toolList = newToolList;
|
||||
}
|
||||
|
||||
public boolean isFolderInfo() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -221,4 +221,9 @@ public class TestFolderInfo implements IFolderInfo {
|
|||
|
||||
}
|
||||
|
||||
public boolean canExclude(boolean exclude) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,4 +24,6 @@ public interface ICResourceDescription extends ICSettingContainer, ICSettingObje
|
|||
void setPath(IPath path) throws WriteAccessException ;
|
||||
|
||||
ICFolderDescription getParentFolderDescription();
|
||||
|
||||
boolean canExclude(boolean exclude);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue