mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Provide error markers for the pathentry ... Work in Progress.
This commit is contained in:
parent
c3ff06502c
commit
ad08ad2679
10 changed files with 455 additions and 13 deletions
|
@ -821,10 +821,24 @@ public class CoreModel {
|
||||||
* the entries location are compatible, otherwise a status
|
* the entries location are compatible, otherwise a status
|
||||||
* object indicating what is wrong with them
|
* object indicating what is wrong with them
|
||||||
*/
|
*/
|
||||||
//private static ICModelStatus validatePathEntry(ICProject cProject, IPathEntry[] entries) {
|
public static ICModelStatus validatePathEntry(ICProject cProject, IPathEntry[] entries) {
|
||||||
//pathEntryManager.validatePathEntry(cproject, entries)
|
return pathEntryManager.validatePathEntry(cProject, entries);
|
||||||
// return null;
|
}
|
||||||
//}
|
|
||||||
|
/**
|
||||||
|
* Returns a C model status describing the problem related to this entry if any,
|
||||||
|
* a status object with code <code>IStatus.OK</code> 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 <code>IStatus.OK</code> 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 {
|
public static IPathEntryStore getPathEntryStore(IProject project) throws CoreException {
|
||||||
return CCorePlugin.getDefault().getPathEntryStore(project);
|
return CCorePlugin.getDefault().getPathEntryStore(project);
|
||||||
|
|
|
@ -41,6 +41,22 @@ public interface ICModelMarker {
|
||||||
public static final String TASK_MARKER = CCorePlugin.PLUGIN_ID + ".task"; //$NON-NLS-1$
|
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$
|
public static final String INDEXER_MARKER = CCorePlugin.PLUGIN_ID + ".indexermarker"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PatheEtnry problem marker type (value <code>"org.eclipse.cdt.core.pathentry_problem"</code>).
|
||||||
|
* 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 <code>"PathEntryFileFormat"</code>).
|
||||||
|
* 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$
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,11 @@ package org.eclipse.cdt.core.model;
|
||||||
*/
|
*/
|
||||||
public interface ICModelStatusConstants {
|
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
|
* Status constant indicating that a variable path was not resolvable
|
||||||
* indicating either the referred variable is undefined, unbound or the resolved
|
* indicating either the referred variable is undefined, unbound or the resolved
|
||||||
|
|
|
@ -118,4 +118,14 @@ public abstract class APathEntry extends PathEntry {
|
||||||
return super.equals(obj);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,4 +97,14 @@ public class IncludeEntry extends APathEntry implements IIncludeEntry {
|
||||||
return p;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,4 +156,13 @@ public class LibraryEntry extends APathEntry implements ILibraryEntry {
|
||||||
public IPath getLibraryPath() {
|
public IPath getLibraryPath() {
|
||||||
return libraryPath;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,4 +74,14 @@ public class MacroEntry extends APathEntry implements IMacroEntry {
|
||||||
return super.equals(obj);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.model;
|
package org.eclipse.cdt.internal.core.model;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
@ -19,9 +20,12 @@ import java.util.Map;
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
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.ElementChangedEvent;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICElementDelta;
|
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.ICModelStatusConstants;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.IContainerEntry;
|
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.IPathEntryStore;
|
||||||
import org.eclipse.cdt.core.resources.IPathEntryStoreListener;
|
import org.eclipse.cdt.core.resources.IPathEntryStoreListener;
|
||||||
import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent;
|
import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent;
|
||||||
|
import org.eclipse.core.resources.IMarker;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
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.resources.IWorkspaceRunnable;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
|
@ -95,8 +102,14 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPathEntry[] getResolvedPathEntries(ICProject cproject) throws CModelException {
|
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);
|
IPathEntry[] entries = (IPathEntry[])resolvedMap.get(cproject);
|
||||||
if (entries == null) {
|
if (entries == null) {
|
||||||
|
IPath projectPath = cproject.getPath();
|
||||||
entries = getRawPathEntries(cproject);
|
entries = getRawPathEntries(cproject);
|
||||||
ArrayList list = new ArrayList();
|
ArrayList list = new ArrayList();
|
||||||
for (int i = 0; i < entries.length; i++) {
|
for (int i = 0; i < entries.length; i++) {
|
||||||
|
@ -109,13 +122,14 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
IPathEntry[] containerEntries = container.getPathEntries();
|
IPathEntry[] containerEntries = container.getPathEntries();
|
||||||
if (containerEntries != null) {
|
if (containerEntries != null) {
|
||||||
for (int j = 0; j < containerEntries.length; j++) {
|
for (int j = 0; j < containerEntries.length; j++) {
|
||||||
IPathEntry newEntry = cloneEntry(cproject.getPath(), containerEntries[j]);
|
IPathEntry newEntry = cloneEntry(projectPath, containerEntries[j]);
|
||||||
list.add(newEntry);
|
list.add(newEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
IPathEntry e = getExpandedPathEntry(entry, cproject);
|
IPathEntry clone = cloneEntry(projectPath, entry);
|
||||||
|
IPathEntry e = getExpandedPathEntry(clone, cproject);
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
list.add(e);
|
list.add(e);
|
||||||
}
|
}
|
||||||
|
@ -123,6 +137,20 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
}
|
}
|
||||||
entries = new IPathEntry[list.size()];
|
entries = new IPathEntry[list.size()];
|
||||||
list.toArray(entries);
|
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);
|
resolvedMap.put(cproject, entries);
|
||||||
}
|
}
|
||||||
return entries;
|
return entries;
|
||||||
|
@ -536,8 +564,92 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
return NO_PREREQUISITES;
|
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 {
|
try {
|
||||||
|
IPathEntry[] newRawEntries = new IPathEntry[list.size()];
|
||||||
|
list.toArray(newRawEntries);
|
||||||
IProject project = cproject.getProject();
|
IProject project = cproject.getProject();
|
||||||
IPathEntryStore store = getPathEntryStore(project, true);
|
IPathEntryStore store = getPathEntryStore(project, true);
|
||||||
store.setRawPathEntries(newRawEntries);
|
store.setRawPathEntries(newRawEntries);
|
||||||
|
@ -801,8 +913,14 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IPathEntry cloneEntry(IPath rpath, IPathEntry entry) {
|
protected IPathEntry cloneEntry(IPath rpath, IPathEntry entry) {
|
||||||
|
|
||||||
|
// get the path
|
||||||
IPath entryPath = entry.getPath();
|
IPath entryPath = entry.getPath();
|
||||||
IPath resourcePath = (entryPath == null || entryPath.isEmpty()) ? rpath : entryPath;
|
if (entryPath == null) {
|
||||||
|
entryPath = Path.EMPTY;
|
||||||
|
}
|
||||||
|
IPath resourcePath = (entryPath.isAbsolute()) ? entryPath : rpath.append(entryPath);
|
||||||
|
|
||||||
switch(entry.getEntryKind()) {
|
switch(entry.getEntryKind()) {
|
||||||
case IPathEntry.CDT_INCLUDE: {
|
case IPathEntry.CDT_INCLUDE: {
|
||||||
IIncludeEntry include = (IIncludeEntry)entry;
|
IIncludeEntry include = (IIncludeEntry)entry;
|
||||||
|
@ -822,7 +940,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
}
|
}
|
||||||
case IPathEntry.CDT_OUTPUT: {
|
case IPathEntry.CDT_OUTPUT: {
|
||||||
IOutputEntry out = (IOutputEntry)entry;
|
IOutputEntry out = (IOutputEntry)entry;
|
||||||
return CoreModel.newOutputEntry(out.getPath(), out.getExclusionPatterns());
|
return CoreModel.newOutputEntry(resourcePath, out.getExclusionPatterns());
|
||||||
}
|
}
|
||||||
case IPathEntry.CDT_PROJECT: {
|
case IPathEntry.CDT_PROJECT: {
|
||||||
IProjectEntry projEntry = (IProjectEntry)entry;
|
IProjectEntry projEntry = (IProjectEntry)entry;
|
||||||
|
@ -830,12 +948,248 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
}
|
}
|
||||||
case IPathEntry.CDT_SOURCE: {
|
case IPathEntry.CDT_SOURCE: {
|
||||||
ISourceEntry source = (ISourceEntry)entry;
|
ISourceEntry source = (ISourceEntry)entry;
|
||||||
return CoreModel.newSourceEntry(source.getPath(), source.getExclusionPatterns());
|
return CoreModel.newSourceEntry(resourcePath, source.getExclusionPatterns());
|
||||||
}
|
}
|
||||||
case IPathEntry.CDT_CONTAINER:
|
case IPathEntry.CDT_CONTAINER:
|
||||||
default:
|
|
||||||
return CoreModel.newContainerEntry(entry.getPath(), entry.isExported());
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ providerName=Eclipse.org
|
||||||
cnature.name=C Nature
|
cnature.name=C Nature
|
||||||
ccnature.name=C++ Nature
|
ccnature.name=C++ Nature
|
||||||
CProblemMarker.name=C Problem
|
CProblemMarker.name=C Problem
|
||||||
|
PathEntryProblemMarker.name=Path Entry Problem
|
||||||
CBuildCommand.name=C Builder Command
|
CBuildCommand.name=C Builder Command
|
||||||
CBuildConsole.name=C Builder Console
|
CBuildConsole.name=C Builder Console
|
||||||
CProject.name=C Project
|
CProject.name=C Project
|
||||||
|
|
|
@ -371,5 +371,19 @@
|
||||||
type="org.eclipse.core.resources.textmarker">
|
type="org.eclipse.core.resources.textmarker">
|
||||||
</super>
|
</super>
|
||||||
</extension>
|
</extension>
|
||||||
|
<!-- =================================================================================== -->
|
||||||
|
<!-- Marker for problems in the PathEntrie -->
|
||||||
|
<!-- =================================================================================== -->
|
||||||
|
<extension
|
||||||
|
id="pathentry_problem"
|
||||||
|
name="%PathEntryProblemMarker.name"
|
||||||
|
point="org.eclipse.core.resources.markers">
|
||||||
|
<super
|
||||||
|
type="org.eclipse.core.resources.problemmarker">
|
||||||
|
</super>
|
||||||
|
<persistent
|
||||||
|
value="true">
|
||||||
|
</persistent>
|
||||||
|
</extension>
|
||||||
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
Loading…
Add table
Reference in a new issue