mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Bug 193843 - Fix up handling of folders and binaries not in a source root but in an output entry.
This commit is contained in:
parent
edf59d635c
commit
b5ad1a939e
5 changed files with 129 additions and 152 deletions
|
@ -227,14 +227,11 @@ public class CContainer extends Openable implements ICContainer {
|
|||
protected ICElement computeChild(IResource res, ICProject cproject) throws CModelException {
|
||||
ICElement celement = null;
|
||||
ISourceRoot sroot = getSourceRoot();
|
||||
if (sroot == null) {
|
||||
return null;
|
||||
}
|
||||
switch (res.getType()) {
|
||||
case IResource.FILE: {
|
||||
IFile file = (IFile) res;
|
||||
boolean checkBinary = true;
|
||||
if (sroot.isOnSourceEntry(res)) {
|
||||
if (sroot != null && sroot.isOnSourceEntry(res)) {
|
||||
// Check for Valid C Element only.
|
||||
String id = CoreModel.getRegistedContentTypeId(file.getProject(), file.getName());
|
||||
if (id != null) {
|
||||
|
@ -263,7 +260,7 @@ public class CContainer extends Openable implements ICContainer {
|
|||
break;
|
||||
}
|
||||
case IResource.FOLDER:
|
||||
if (sroot.isOnSourceEntry(res) || cproject.isOnOutputEntry(res)) {
|
||||
if (sroot != null && sroot.isOnSourceEntry(res) || cproject.isOnOutputEntry(res)) {
|
||||
celement = new CContainer(this, res);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -249,10 +249,6 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
return cModel.getCProject(project);
|
||||
}
|
||||
|
||||
private boolean isInContainerOnOutputPath(ICContainer root, IResource resource) {
|
||||
return (root.getPath().isPrefixOf(resource.getFullPath()));
|
||||
}
|
||||
|
||||
public ICContainer create(IFolder folder, ICProject cproject) {
|
||||
if (folder == null) {
|
||||
return null;
|
||||
|
@ -260,33 +256,41 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
if (cproject == null) {
|
||||
cproject = create(folder.getProject());
|
||||
}
|
||||
ICContainer celement = null;
|
||||
IPath resourcePath = folder.getFullPath();
|
||||
try {
|
||||
ICElement[] children = cproject.getChildren();
|
||||
for (int i = 0; i < children.length; ++i) {
|
||||
if (children[i] instanceof ICContainer) {
|
||||
ICContainer root = (ICContainer) children[i];
|
||||
IPath rootPath = root.getPath();
|
||||
if (rootPath.equals(resourcePath)) {
|
||||
celement = root;
|
||||
break; // We are done.
|
||||
} else if (root instanceof ISourceRoot && ((ISourceRoot)root).isOnSourceEntry(folder) || isInContainerOnOutputPath(root, folder)) {
|
||||
IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount());
|
||||
if (children[i] instanceof ISourceRoot) {
|
||||
ISourceRoot root = (ISourceRoot)children[i];
|
||||
if (root.isOnSourceEntry(folder)) {
|
||||
// Get the container
|
||||
IPath path = folder.getFullPath();
|
||||
path = path.removeFirstSegments(root.getPath().segmentCount());
|
||||
String[] segments = path.segments();
|
||||
ICContainer cfolder = root;
|
||||
for (int j = 0; j < segments.length; j++) {
|
||||
for (int j = 0; j < segments.length; ++j) {
|
||||
cfolder = cfolder.getCContainer(segments[j]);
|
||||
}
|
||||
celement = cfolder;
|
||||
break;
|
||||
return cfolder;
|
||||
}
|
||||
} else if (children[i] instanceof ICContainer) {
|
||||
ICContainer root = (ICContainer)children[i];
|
||||
IPath rootPath = root.getPath();
|
||||
IPath path = folder.getFullPath();
|
||||
if (rootPath.isPrefixOf(path) && cproject.isOnOutputEntry(folder)) {
|
||||
path = path.removeFirstSegments(root.getPath().segmentCount());
|
||||
String[] segments = path.segments();
|
||||
ICContainer cfolder = root;
|
||||
for (int j = 0; j < segments.length; ++j) {
|
||||
cfolder = cfolder.getCContainer(segments[j]);
|
||||
}
|
||||
return cfolder;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (CModelException e) {
|
||||
//
|
||||
}
|
||||
return celement;
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICElement create(IFile file, ICProject cproject) {
|
||||
|
@ -298,41 +302,37 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
}
|
||||
ICElement celement = null;
|
||||
try {
|
||||
ICElement[] children = cproject.getChildren();
|
||||
for (int i = 0; i < children.length; ++i) {
|
||||
if (children[i] instanceof ICContainer) {
|
||||
ICContainer root = (ICContainer) children[i];
|
||||
if (root instanceof ISourceRoot && ((ISourceRoot)root).isOnSourceEntry(file) || isInContainerOnOutputPath(root, file)) {
|
||||
IPath rootPath = root.getPath();
|
||||
IPath resourcePath = file.getFullPath();
|
||||
IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount());
|
||||
String fileName = path.lastSegment();
|
||||
path = path.removeLastSegments(1);
|
||||
String[] segments = path.segments();
|
||||
ICContainer cfolder = root;
|
||||
for (int j = 0; j < segments.length; j++) {
|
||||
cfolder = cfolder.getCContainer(segments[j]);
|
||||
}
|
||||
if (CoreModel.isValidTranslationUnitName(cproject.getProject(), fileName)) {
|
||||
celement = cfolder.getTranslationUnit(fileName);
|
||||
} else if (cproject.isOnOutputEntry(file)) {
|
||||
IBinaryFile bin = createBinaryFile(file);
|
||||
if (bin != null) {
|
||||
if (bin.getType() == IBinaryFile.ARCHIVE) {
|
||||
celement = new Archive(cfolder, file, (IBinaryArchive) bin);
|
||||
ArchiveContainer vlib = (ArchiveContainer) cproject.getArchiveContainer();
|
||||
vlib.addChild(celement);
|
||||
} else {
|
||||
celement = new Binary(cfolder, file, (IBinaryObject) bin);
|
||||
BinaryContainer vbin = (BinaryContainer) cproject.getBinaryContainer();
|
||||
vbin.addChild(celement);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
// First look for TU's
|
||||
IPath resourcePath = file.getFullPath();
|
||||
ISourceRoot[] roots = cproject.getSourceRoots();
|
||||
for (int i = 0; i < roots.length; ++i) {
|
||||
ISourceRoot root = roots[i];
|
||||
if (root.isOnSourceEntry(file)) {
|
||||
IPath rootPath = root.getPath();
|
||||
IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount());
|
||||
String fileName = path.lastSegment();
|
||||
path = path.removeLastSegments(1);
|
||||
String[] segments = path.segments();
|
||||
ICContainer cfolder = root;
|
||||
for (int j = 0; j < segments.length; j++) {
|
||||
cfolder = cfolder.getCContainer(segments[j]);
|
||||
}
|
||||
if (CoreModel.isValidTranslationUnitName(cproject.getProject(), fileName)) {
|
||||
celement = cfolder.getTranslationUnit(fileName);
|
||||
} else {
|
||||
IBinaryFile bin = createBinaryFile(file);
|
||||
if (bin != null)
|
||||
celement = create(file, bin, cproject);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (celement == null && cproject.isOnOutputEntry(file)) {
|
||||
IBinaryFile bin = createBinaryFile(file);
|
||||
if (bin != null)
|
||||
celement = create(file, bin, cproject);
|
||||
}
|
||||
} catch (CModelException e) {
|
||||
//
|
||||
}
|
||||
|
@ -354,6 +354,12 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
if (cproject.isOnOutputEntry(file)) {
|
||||
IPath resourcePath = file.getParent().getFullPath();
|
||||
ICElement cfolder = cproject.findElement(resourcePath);
|
||||
|
||||
// Check if folder is a source root and use that instead
|
||||
ISourceRoot sourceRoot = cproject.findSourceRoot(resourcePath);
|
||||
if (sourceRoot != null)
|
||||
cfolder = sourceRoot;
|
||||
|
||||
if (bin.getType() == IBinaryFile.ARCHIVE) {
|
||||
ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer();
|
||||
celement = new Archive(cfolder, file, (IBinaryArchive)bin);
|
||||
|
|
|
@ -620,39 +620,36 @@ public class CProject extends Openable implements ICProject {
|
|||
return new ArrayList(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add any output paths which don't overlay paths already in the list.
|
||||
*/
|
||||
private List addOutputOnlyRoots(List sourceRoots) {
|
||||
IResource[] resources;
|
||||
ArrayList result = new ArrayList(sourceRoots.size());
|
||||
protected boolean computeChildren(OpenableInfo info, IResource res) throws CModelException {
|
||||
List sourceRoots = computeSourceRoots();
|
||||
List children = new ArrayList(sourceRoots.size());
|
||||
children.addAll(sourceRoots);
|
||||
|
||||
// Now look for output folders
|
||||
try {
|
||||
resources = getProject().members();
|
||||
IResource[] resources = getProject().members();
|
||||
for (int i = 0; i < resources.length; i++) {
|
||||
if (resources[i].getType() == IResource.FOLDER) {
|
||||
IResource child = resources[i];
|
||||
if (child.getType() == IResource.FOLDER) {
|
||||
boolean found = false;
|
||||
for (int j = 0; j < sourceRoots.size(); j++) {
|
||||
if (((ICElement) sourceRoots.get(j)).getResource().getProjectRelativePath().isPrefixOf(resources[i].getProjectRelativePath())) {
|
||||
for (Iterator iter = sourceRoots.iterator(); iter.hasNext();) {
|
||||
ISourceRoot sourceRoot = (ISourceRoot)iter.next();
|
||||
if (sourceRoot.isOnSourceEntry(child)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
result.add(new CContainer(this, resources[i]));
|
||||
}
|
||||
|
||||
// Not in source folder, check if it's a container on output entry
|
||||
if (!found && isOnOutputEntry(child))
|
||||
children.add(new CContainer(this, child));
|
||||
}
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
// ignore
|
||||
}
|
||||
result.addAll(sourceRoots);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected boolean computeChildren(OpenableInfo info, IResource res) throws CModelException {
|
||||
List list = computeSourceRoots();
|
||||
list = addOutputOnlyRoots(list);
|
||||
info.setChildren(list);
|
||||
|
||||
info.setChildren(children);
|
||||
if (info instanceof CProjectInfo) {
|
||||
CProjectInfo pinfo = (CProjectInfo)info;
|
||||
pinfo.setNonCResources(null);
|
||||
|
|
|
@ -12,10 +12,10 @@
|
|||
package org.eclipse.cdt.internal.core.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.CoreModelUtil;
|
||||
import org.eclipse.cdt.core.model.IArchiveContainer;
|
||||
import org.eclipse.cdt.core.model.IBinaryContainer;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
|
@ -23,16 +23,10 @@ import org.eclipse.cdt.core.model.IIncludeReference;
|
|||
import org.eclipse.cdt.core.model.ILibraryReference;
|
||||
import org.eclipse.cdt.core.model.IOutputEntry;
|
||||
import org.eclipse.cdt.core.model.ISourceRoot;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
/**
|
||||
* Info for ICProject.
|
||||
|
@ -78,72 +72,58 @@ class CProjectInfo extends OpenableInfo {
|
|||
if (nonCResources != null)
|
||||
return nonCResources;
|
||||
|
||||
// determine if src == project
|
||||
boolean srcIsProject = false;
|
||||
ICSourceEntry[] entries = null;
|
||||
ICProject cproject = getElement().getCProject();
|
||||
IProject project = cproject.getProject();
|
||||
IPath projectPath = project.getFullPath();
|
||||
char[][] exclusionPatterns = null;
|
||||
ICProjectDescription des = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
if (des != null) {
|
||||
ICConfigurationDescription cfg = des.getDefaultSettingConfiguration();
|
||||
if (cfg != null) {
|
||||
entries = cfg.getResolvedSourceEntries();
|
||||
}
|
||||
}
|
||||
|
||||
if (entries != null) {
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
ICSourceEntry entry = entries[i];
|
||||
if (projectPath.equals(entry.getFullPath())) {
|
||||
srcIsProject = true;
|
||||
exclusionPatterns = entry.fullExclusionPatternChars();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList notChildren = new ArrayList();
|
||||
List notChildren = new ArrayList();
|
||||
try {
|
||||
IResource[] resources = null;
|
||||
if (res instanceof IContainer) {
|
||||
IContainer container = (IContainer)res;
|
||||
resources = container.members(false);
|
||||
}
|
||||
|
||||
if (resources != null) {
|
||||
for (int i = 0; i < resources.length; i++) {
|
||||
IResource member = resources[i];
|
||||
switch(member.getType()) {
|
||||
case IResource.FILE: {
|
||||
String filename = member.getName();
|
||||
if (srcIsProject) {
|
||||
if (CoreModel.isValidTranslationUnitName(cproject.getProject(), filename)
|
||||
&& !CoreModelUtil.isExcluded(member, exclusionPatterns)) {
|
||||
continue;
|
||||
} else if (!CoreModelUtil.isExcluded(member, exclusionPatterns)) {
|
||||
if (cproject.isOnOutputEntry(member) && CModelManager.getDefault().createBinaryFile((IFile)member) != null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
ICProject cproject = getElement().getCProject();
|
||||
ISourceRoot[] sourceRoots = cproject.getSourceRoots();
|
||||
IResource[] resources = ((IContainer)res).members();
|
||||
|
||||
for (int i = 0; i < resources.length; ++i) {
|
||||
IResource child = resources[i];
|
||||
|
||||
// Check if under source root
|
||||
boolean found = false;
|
||||
for (int j = 0; j < sourceRoots.length; ++j)
|
||||
if (sourceRoots[j].isOnSourceEntry(child)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
case IResource.FOLDER: {
|
||||
if (srcIsProject && !CoreModelUtil.isExcluded(member, exclusionPatterns)) {
|
||||
|
||||
if (found) {
|
||||
switch (child.getType()) {
|
||||
case IResource.FILE:
|
||||
// Must be a translation unit or binary
|
||||
if (CoreModel.isValidTranslationUnitName(cproject.getProject(), child.getName())
|
||||
|| CModelManager.getDefault().createBinaryFile((IFile)child) != null)
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case IResource.FOLDER:
|
||||
// All folders are good
|
||||
continue;
|
||||
}
|
||||
} else if (cproject.isOnOutputEntry(child)) {
|
||||
switch (child.getType()) {
|
||||
case IResource.FILE:
|
||||
if (CModelManager.getDefault().createBinaryFile((IFile)child) != null)
|
||||
continue;
|
||||
break;
|
||||
case IResource.FOLDER:
|
||||
// All folders are good here too
|
||||
continue;
|
||||
}
|
||||
}
|
||||
notChildren.add(member);
|
||||
|
||||
// It's a non C resource
|
||||
notChildren.add(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (CModelException e) {
|
||||
// this can't be good.
|
||||
} catch (CoreException e) {
|
||||
//System.out.println (e);
|
||||
//CPlugin.log (e);
|
||||
//e.printStackTrace();
|
||||
// this neither
|
||||
}
|
||||
|
||||
setNonCResources(notChildren.toArray());
|
||||
return nonCResources;
|
||||
}
|
||||
|
|
|
@ -329,19 +329,16 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
|
|||
return NO_CHILDREN;
|
||||
|
||||
List list= new ArrayList();
|
||||
ISourceRoot[] roots = cproject.getSourceRoots();
|
||||
// filter out source roots that correspond to projects and
|
||||
// replace them with the package fragments directly
|
||||
for (int i= 0; i < roots.length; i++) {
|
||||
ISourceRoot root= roots[i];
|
||||
if (isProjectSourceRoot(root)) {
|
||||
Object[] children= root.getChildren();
|
||||
for (int k= 0; k < children.length; k++) {
|
||||
list.add(children[k]);
|
||||
}
|
||||
} else {
|
||||
list.add(root);
|
||||
}
|
||||
ICElement[] children = cproject.getChildren();
|
||||
for (int i= 0; i < children.length; i++) {
|
||||
ICElement child = children[i];
|
||||
if (child instanceof ISourceRoot && child.getResource().getType() == IResource.PROJECT) {
|
||||
// Was a source root at the project, get the children of this element
|
||||
ICElement[] c2 = ((ISourceRoot)child).getChildren();
|
||||
for (int k = 0; k < c2.length; ++k)
|
||||
list.add(c2[k]);
|
||||
} else
|
||||
list.add(child);
|
||||
}
|
||||
|
||||
Object[] objects = list.toArray();
|
||||
|
|
Loading…
Add table
Reference in a new issue