diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java
index 625337923e1..b2f73e5c74f 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java
@@ -821,10 +821,24 @@ public class CoreModel {
* the entries location are compatible, otherwise a status
* object indicating what is wrong with them
*/
- //private static ICModelStatus validatePathEntry(ICProject cProject, IPathEntry[] entries) {
- //pathEntryManager.validatePathEntry(cproject, entries)
- // return null;
- //}
+ public static ICModelStatus validatePathEntry(ICProject cProject, IPathEntry[] entries) {
+ return pathEntryManager.validatePathEntry(cProject, entries);
+ }
+
+ /**
+ * Returns a C model status describing the problem related to this entry if any,
+ * a status object with code IStatus.OK
if the entry is fine (that is, if the
+ * given entry denotes a valid element).
+ *
+ * @param cProject the given C project
+ * @param entry the given entry
+ * @param checkSourceAttachment a flag to determine if source attachement should be checked
+ * @param recurseInContainers flag indicating whether validation should be applied to container entries recursively
+ * @return a c model status describing the problem related to this entry if any, a status object with code IStatus.OK
if the entry is fine
+ */
+ public static ICModelStatus validatePathEntry(ICProject cProject, IPathEntry entry, boolean checkSourceAttachment, boolean recurseInContainers){
+ return pathEntryManager.validatePathEntry(cProject, entry, checkSourceAttachment, recurseInContainers);
+ }
public static IPathEntryStore getPathEntryStore(IProject project) throws CoreException {
return CCorePlugin.getDefault().getPathEntryStore(project);
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelMarker.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelMarker.java
index 9013059705a..69cebc37624 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelMarker.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelMarker.java
@@ -41,6 +41,22 @@ public interface ICModelMarker {
public static final String TASK_MARKER = CCorePlugin.PLUGIN_ID + ".task"; //$NON-NLS-1$
public static final String INDEXER_MARKER = CCorePlugin.PLUGIN_ID + ".indexermarker"; //$NON-NLS-1$
+
+ /**
+ * PatheEtnry problem marker type (value "org.eclipse.cdt.core.pathentry_problem"
).
+ * This can be used to recognize those markers in the workspace that flag problems
+ * detected by the C tooling during pathEntry setting.
+ */
+ public static final String PATHENTRY_PROBLEM_MARKER = CCorePlugin.PLUGIN_ID + ".pathentry_problem"; //$NON-NLS-1$
+
+ /**
+ * PathEntry file format marker attribute (value "PathEntryFileFormat"
).
+ * Used only on pathentry store problem markers.
+ * The value of this attribute is either "true" or "false".
+ *
+ */
+ public static final String PATHENTRY_FILE_FORMAT = "pathEntryFileFormat"; //$NON-NLS-1$
+
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelStatusConstants.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelStatusConstants.java
index 21fe3c6a202..9475bad5234 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelStatusConstants.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelStatusConstants.java
@@ -17,6 +17,11 @@ package org.eclipse.cdt.core.model;
*/
public interface ICModelStatusConstants {
+ /**
+ * Status constant indicating that a pathentry was invalid
+ */
+ public static final int INVALID_PATHENTRY = 964;
+
/**
* Status constant indicating that a variable path was not resolvable
* indicating either the referred variable is undefined, unbound or the resolved
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java
index 880155cacd7..13b863f71f5 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java
@@ -118,4 +118,14 @@ public abstract class APathEntry extends PathEntry {
return super.equals(obj);
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(super.toString());
+ sb.append(" base-path:").append(basePath.toString()); //$NON-NLS-1$
+ sb.append(" base-ref:").append(baseRef.toString()); //$NON-NLS-1$
+ return sb.toString();
+ }
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java
index 5f8a002ada6..c951955aacf 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java
@@ -97,4 +97,14 @@ public class IncludeEntry extends APathEntry implements IIncludeEntry {
return p;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(super.toString());
+ sb.append(" isSystemInclude:").append(isSystemInclude); //$NON-NLS-1$
+ sb.append(" includePath:").append(includePath); //$NON-NLS-1
+ return sb.toString();
+ }
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java
index 772fa650150..4f69b8516db 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java
@@ -156,4 +156,13 @@ public class LibraryEntry extends APathEntry implements ILibraryEntry {
public IPath getLibraryPath() {
return libraryPath;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(super.toString());
+ sb.append(" librarypath:").append(libraryPath.toString()); //$NON-NLS-1$
+ return sb.toString();
+ }
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java
index 52779e5240e..a8918be56b1 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java
@@ -74,4 +74,14 @@ public class MacroEntry extends APathEntry implements IMacroEntry {
return super.equals(obj);
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(super.toString());
+ sb.append(" name:").append(macroName); //$NON-NLS-1$
+ sb.append(" value:").append(macroValue); //$NON-NLS-1$
+ return sb.toString();
+ }
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
index 9dfe42c69d7..cf28df127c9 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
@@ -12,6 +12,7 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.model;
+import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
@@ -19,9 +20,12 @@ import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
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.ElementChangedEvent;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICElementDelta;
+import org.eclipse.cdt.core.model.ICModelMarker;
+import org.eclipse.cdt.core.model.ICModelStatus;
import org.eclipse.cdt.core.model.ICModelStatusConstants;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IContainerEntry;
@@ -38,8 +42,11 @@ import org.eclipse.cdt.core.model.PathEntryContainerInitializer;
import org.eclipse.cdt.core.resources.IPathEntryStore;
import org.eclipse.cdt.core.resources.IPathEntryStoreListener;
import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
@@ -95,8 +102,14 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
public IPathEntry[] getResolvedPathEntries(ICProject cproject) throws CModelException {
+ boolean markers = cproject.getProject().getWorkspace().isTreeLocked();
+ return getResolvedPathEntries(cproject, !markers);
+ }
+
+ public IPathEntry[] getResolvedPathEntries(ICProject cproject, boolean generateMarkers) throws CModelException {
IPathEntry[] entries = (IPathEntry[])resolvedMap.get(cproject);
if (entries == null) {
+ IPath projectPath = cproject.getPath();
entries = getRawPathEntries(cproject);
ArrayList list = new ArrayList();
for (int i = 0; i < entries.length; i++) {
@@ -109,13 +122,14 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
IPathEntry[] containerEntries = container.getPathEntries();
if (containerEntries != null) {
for (int j = 0; j < containerEntries.length; j++) {
- IPathEntry newEntry = cloneEntry(cproject.getPath(), containerEntries[j]);
+ IPathEntry newEntry = cloneEntry(projectPath, containerEntries[j]);
list.add(newEntry);
}
}
}
} else {
- IPathEntry e = getExpandedPathEntry(entry, cproject);
+ IPathEntry clone = cloneEntry(projectPath, entry);
+ IPathEntry e = getExpandedPathEntry(clone, cproject);
if (e != null) {
list.add(e);
}
@@ -123,6 +137,20 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
entries = new IPathEntry[list.size()];
list.toArray(entries);
+ if (generateMarkers) {
+ IProject project = cproject.getProject();
+ flushPathEntryProblemMarkers(project);
+ ICModelStatus status = validatePathEntry(cproject, entries);
+ if (!status.isOK()) {
+ createPathEntryProblemMarker(project, status);
+ }
+ for (int j = 0; j < entries.length; j++) {
+ status = validatePathEntry(cproject, entries[j], true, false);
+ if (!status.isOK()) {
+ createPathEntryProblemMarker(project, status);
+ }
+ }
+ }
resolvedMap.put(cproject, entries);
}
return entries;
@@ -536,8 +564,92 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return NO_PREREQUISITES;
}
- public void saveRawPathEntries(ICProject cproject, IPathEntry[] newRawEntries) throws CModelException {
+ public void saveRawPathEntries(ICProject cproject, IPathEntry[] entries) throws CModelException {
+ ArrayList list = new ArrayList(entries.length);
+ IPath projectPath = cproject.getPath();
+ for (int i = 0; i < entries.length; i++) {
+ IPathEntry entry;
+
+ int kind = entries[i].getEntryKind();
+
+ // translate the project prefix.
+ IPath resourcePath = entries[i].getPath();
+ if (resourcePath == null) {
+ resourcePath = Path.EMPTY;
+ }
+
+ // Do not do this for container, the path is the ID.
+ if (kind != IPathEntry.CDT_CONTAINER) {
+ // translate to project relative from absolute (unless a device path)
+ if (resourcePath.isAbsolute()) {
+ if (projectPath != null && projectPath.isPrefixOf(resourcePath)) {
+ if (resourcePath.segment(0).equals(projectPath.segment(0))) {
+ resourcePath = resourcePath.removeFirstSegments(1);
+ resourcePath = resourcePath.makeRelative();
+ } else {
+ resourcePath = resourcePath.makeAbsolute();
+ }
+ }
+ }
+ }
+
+ // Specifics to the entries
+ switch(kind) {
+ case IPathEntry.CDT_INCLUDE: {
+ IIncludeEntry include = (IIncludeEntry)entries[i];
+ entry = CoreModel.newIncludeEntry(resourcePath, include.getBasePath(), include.getIncludePath(),
+ include.isSystemInclude(), include.getExclusionPatterns(), include.isExported());
+ break;
+ }
+ case IPathEntry.CDT_LIBRARY: {
+ ILibraryEntry library = (ILibraryEntry)entries[i];
+ IPath sourcePath = library.getSourceAttachmentPath();
+ if (sourcePath != null) {
+ // translate to project relative from absolute
+ if (projectPath != null && projectPath.isPrefixOf(sourcePath)) {
+ if (sourcePath.segment(0).equals(projectPath.segment(0))) {
+ sourcePath = sourcePath.removeFirstSegments(1);
+ sourcePath = sourcePath.makeRelative();
+ }
+ }
+ }
+ entry = CoreModel.newLibraryEntry(resourcePath, library.getBasePath(),
+ library.getLibraryPath(), sourcePath, library.getSourceAttachmentRootPath(),
+ library.getSourceAttachmentPrefixMapping(), library.isExported());
+ break;
+ }
+ case IPathEntry.CDT_MACRO: {
+ IMacroEntry macro = (IMacroEntry)entries[i];
+ entry = CoreModel.newMacroEntry(resourcePath, macro.getMacroName(), macro.getMacroValue(),
+ macro.getExclusionPatterns(), macro.isExported());
+ break;
+ }
+ case IPathEntry.CDT_OUTPUT: {
+ IOutputEntry out = (IOutputEntry)entries[i];
+ entry = CoreModel.newOutputEntry(resourcePath, out.getExclusionPatterns());
+ break;
+ }
+ case IPathEntry.CDT_PROJECT: {
+ IProjectEntry projEntry = (IProjectEntry)entries[i];
+ entry = CoreModel.newProjectEntry(projEntry.getPath(), projEntry.isExported());
+ break;
+ }
+ case IPathEntry.CDT_SOURCE: {
+ ISourceEntry source = (ISourceEntry)entries[i];
+ entry = CoreModel.newSourceEntry(resourcePath, source.getExclusionPatterns());
+ break;
+ }
+ case IPathEntry.CDT_CONTAINER:
+ entry = CoreModel.newContainerEntry(entries[i].getPath(), entries[i].isExported());
+ break;
+ default:
+ entry = entries[i];
+ }
+ list.add(entry);
+ }
try {
+ IPathEntry[] newRawEntries = new IPathEntry[list.size()];
+ list.toArray(newRawEntries);
IProject project = cproject.getProject();
IPathEntryStore store = getPathEntryStore(project, true);
store.setRawPathEntries(newRawEntries);
@@ -801,8 +913,14 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
protected IPathEntry cloneEntry(IPath rpath, IPathEntry entry) {
- IPath entryPath = entry.getPath();
- IPath resourcePath = (entryPath == null || entryPath.isEmpty()) ? rpath : entryPath;
+
+ // get the path
+ IPath entryPath = entry.getPath();
+ if (entryPath == null) {
+ entryPath = Path.EMPTY;
+ }
+ IPath resourcePath = (entryPath.isAbsolute()) ? entryPath : rpath.append(entryPath);
+
switch(entry.getEntryKind()) {
case IPathEntry.CDT_INCLUDE: {
IIncludeEntry include = (IIncludeEntry)entry;
@@ -822,7 +940,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
case IPathEntry.CDT_OUTPUT: {
IOutputEntry out = (IOutputEntry)entry;
- return CoreModel.newOutputEntry(out.getPath(), out.getExclusionPatterns());
+ return CoreModel.newOutputEntry(resourcePath, out.getExclusionPatterns());
}
case IPathEntry.CDT_PROJECT: {
IProjectEntry projEntry = (IProjectEntry)entry;
@@ -830,12 +948,248 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
case IPathEntry.CDT_SOURCE: {
ISourceEntry source = (ISourceEntry)entry;
- return CoreModel.newSourceEntry(source.getPath(), source.getExclusionPatterns());
+ return CoreModel.newSourceEntry(resourcePath, source.getExclusionPatterns());
}
case IPathEntry.CDT_CONTAINER:
- default:
return CoreModel.newContainerEntry(entry.getPath(), entry.isExported());
}
+ return entry;
+ }
+
+ public ICModelStatus validatePathEntry(ICProject cProject, IPathEntry[] entries) {
+
+ // Check duplication.
+ for (int i = 0; i < entries.length; i++) {
+ IPathEntry entry = entries[i];
+ if (entry == null) {
+ continue;
+ }
+ for (int j = 0; j < entries.length; j++) {
+ IPathEntry otherEntry = entries[j];
+ if (otherEntry == null) {
+ continue;
+ }
+ if (entry != otherEntry && otherEntry.equals(entry)) {
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, "Duplication:" + entry.toString()); //$NON-NLS-1$
+ }
+ }
+ }
+
+ // allow nesting source entries in each other as long as the outer entry excludes the inner one
+ for (int i = 0; i < entries.length; i++) {
+ IPathEntry entry = entries[i];
+ if (entry == null) {
+ continue;
+ }
+ IPath entryPath = entry.getPath();
+ int kind = entry.getEntryKind();
+ if (kind == IPathEntry.CDT_SOURCE){
+ for (int j = 0; j < entries.length; j++){
+ IPathEntry otherEntry = entries[j];
+ if (otherEntry == null) {
+ continue;
+ }
+ int otherKind = otherEntry.getEntryKind();
+ IPath otherPath = otherEntry.getPath();
+ if (entry != otherEntry && (otherKind == IPathEntry.CDT_SOURCE)) {
+ char[][] exclusionPatterns = ((ISourceEntry)otherEntry).fullExclusionPatternChars();
+ if (otherPath.isPrefixOf(entryPath) && !otherPath.equals(entryPath)
+ && !CoreModelUtil.isExcluded(entryPath.append("*"), exclusionPatterns)) { //$NON-NLS-1$
+
+ String exclusionPattern = entryPath.removeFirstSegments(otherPath.segmentCount()).segment(0);
+ if (CoreModelUtil.isExcluded(entryPath, exclusionPatterns)) {
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, "Nested:" + entry.toString()); //$NON-NLS-1$
+ } else {
+ if (otherKind == IPathEntry.CDT_SOURCE) {
+ exclusionPattern += '/';
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, "Nested:" + entry.toString()); //$NON-NLS-1$
+ } else {
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, "Nested:" + entry.toString()); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return CModelStatus.VERIFIED_OK;
+ }
+
+ public ICModelStatus validatePathEntry(ICProject cProject, IPathEntry entry, boolean checkSourceAttachment, boolean recurseInContainers){
+ IProject project = cProject.getProject();
+ IPath projectPath = cProject.getPath();
+ String entryMesg = projectPath.toString() + ": " + entry.toString(); //$NON-NLS-1$
+ switch(entry.getEntryKind()) {
+ case IPathEntry.CDT_INCLUDE: {
+ IIncludeEntry include = (IIncludeEntry)entry;
+ IPath path = include.getPath();
+ if (!isValidWorkspacePath(project, path)) {
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$
+ }
+ IPath includePath = include.getFullIncludePath();
+ if (!isValidExternalPath(includePath)) {
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$
+ }
+ break;
+ }
+ case IPathEntry.CDT_LIBRARY: {
+ ILibraryEntry library = (ILibraryEntry)entry;
+ IPath path = library.getPath();
+ if (!isValidWorkspacePath(project, path)) {
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$
+ }
+ if (checkSourceAttachment) {
+ IPath sourceAttach = library.getSourceAttachmentPath();
+ if (sourceAttach != null) {
+ if(!sourceAttach.isAbsolute()) {
+ if (!isValidWorkspacePath(project, sourceAttach)) {
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg);
+ }
+ } else if (!isValidExternalPath(sourceAttach)) {
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg);
+ }
+ }
+ }
+ IPath libraryPath = library.getFullLibraryPath();
+ if (!isValidExternalPath(libraryPath)) {
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$
+ }
+ break;
+ }
+ case IPathEntry.CDT_MACRO: {
+ IMacroEntry macro = (IMacroEntry)entry;
+ IPath path = macro.getPath();
+ if (!isValidWorkspacePath(project, path)) {
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$
+ }
+ break;
+ }
+ case IPathEntry.CDT_OUTPUT: {
+ IOutputEntry out = (IOutputEntry)entry;
+ IPath path = out.getPath();
+ if (!isValidWorkspacePath(project, path)) {
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$
+ }
+ break;
+ }
+ case IPathEntry.CDT_PROJECT: {
+ IProjectEntry projEntry = (IProjectEntry)entry;
+ IPath path = projEntry.getPath();
+ if (path != null && path.isAbsolute() && !path.isEmpty()) {
+ IProject reqProject = project.getWorkspace().getRoot().getProject(path.segment(0));
+ if (!reqProject.exists() || !(CoreModel.hasCCNature(reqProject) || CoreModel.hasCCNature(reqProject))) {
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$
+ }
+ if (!reqProject.isOpen()){
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$
+ }
+ } else {
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$
+ }
+ break;
+ }
+ case IPathEntry.CDT_SOURCE: {
+ ISourceEntry source = (ISourceEntry)entry;
+ IPath path = source.getPath();
+ if (!isValidWorkspacePath(project, path)) {
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$
+ }
+ break;
+ }
+ case IPathEntry.CDT_CONTAINER:
+ break;
+ }
+ return CModelStatus.VERIFIED_OK;
+ }
+
+ private boolean isValidWorkspacePath(IProject project, IPath path) {
+ if (path == null) {
+ return false;
+ }
+ IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot();
+ // We accept empy path as the project
+ IResource res = null;
+ if (path.isAbsolute()) {
+ res = workspaceRoot.findMember(path);
+ } else {
+ res = project.findMember(path);
+ }
+ return (res != null && res.isAccessible());
+ }
+
+ private boolean isValidExternalPath(IPath path) {
+ if (path != null) {
+ File file = path.toFile();
+ if (file != null) {
+ return file.exists();
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Record a new marker denoting a classpath problem
+ */
+ void createPathEntryProblemMarker(IProject project, ICModelStatus status) {
+
+ IMarker marker = null;
+ int severity;
+ switch (status.getCode()) {
+ case ICModelStatusConstants.INVALID_PATHENTRY :
+ severity = IMarker.SEVERITY_WARNING;
+ break;
+
+ case ICModelStatusConstants.INVALID_PATH:
+ severity = IMarker.SEVERITY_WARNING;
+ break;
+
+ default:
+ severity = IMarker.SEVERITY_ERROR;
+ break;
+ }
+
+ try {
+ marker = project.createMarker(ICModelMarker.PATHENTRY_PROBLEM_MARKER);
+ marker.setAttributes(
+ new String[] {
+ IMarker.MESSAGE,
+ IMarker.SEVERITY,
+ IMarker.LOCATION,
+ ICModelMarker.PATHENTRY_FILE_FORMAT,
+ },
+ new Object[] {
+ status.getString(),
+ new Integer(severity),
+ "pathentry",//$NON-NLS-1$
+ "false",//$NON-NLS-1$
+ }
+ );
+ } catch (CoreException e) {
+ // could not create marker: cannot do much
+ e.printStackTrace();
+ }
}
+ /**
+ * Remove all markers denoting classpath problems
+ */
+ protected void flushPathEntryProblemMarkers(IProject project) {
+ IWorkspace workspace = project.getWorkspace();
+
+ try {
+ if (project.isAccessible()) {
+ IMarker[] markers = project.findMarkers(ICModelMarker.PATHENTRY_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
+ if (markers != null) {
+ workspace.deleteMarkers(markers);
+ }
+ }
+ } catch (CoreException e) {
+ // could not flush markers: not much we can do
+ e.printStackTrace();
+ }
+ }
+
+
+
}
diff --git a/core/org.eclipse.cdt.core/plugin.properties b/core/org.eclipse.cdt.core/plugin.properties
index 30a20dd8391..76a73c37f56 100644
--- a/core/org.eclipse.cdt.core/plugin.properties
+++ b/core/org.eclipse.cdt.core/plugin.properties
@@ -4,7 +4,7 @@ providerName=Eclipse.org
cnature.name=C Nature
ccnature.name=C++ Nature
CProblemMarker.name=C Problem
-
+PathEntryProblemMarker.name=Path Entry Problem
CBuildCommand.name=C Builder Command
CBuildConsole.name=C Builder Console
CProject.name=C Project
diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml
index bcfb98cd29c..5dd357fea56 100644
--- a/core/org.eclipse.cdt.core/plugin.xml
+++ b/core/org.eclipse.cdt.core/plugin.xml
@@ -371,5 +371,19 @@
type="org.eclipse.core.resources.textmarker">
+
+
+
+
+
+
+
+
+