1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

- improved path marker messages to be more informative

- improved validation method.
This commit is contained in:
David Inglis 2004-08-26 18:54:05 +00:00
parent 91bf21d039
commit 6eff3a3a90
4 changed files with 422 additions and 368 deletions

View file

@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModelStatus;
@ -29,14 +28,15 @@ import org.eclipse.core.runtime.Status;
public class CModelStatus extends Status implements ICModelStatus, ICModelStatusConstants, IResourceStatus {
/**
* The elements related to the failure, or <code>null</code>
* if no elements are involved.
* The elements related to the failure, or <code>null</code> if no
* elements are involved.
*/
protected ICElement[] fElements;
protected final static ICElement[] EmptyElement = new ICElement[]{};
/**
* The path related to the failure, or <code>null</code>
* if no path is involved.
* The path related to the failure, or <code>null</code> if no path is
* involved.
*/
protected IPath fPath;
/**
@ -74,8 +74,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
}
/**
* Constructs an C model status with the given corresponding
* elements.
* Constructs an C model status with the given corresponding elements.
*/
public CModelStatus(int code, ICElement[] elements) {
super(ERROR, CCorePlugin.PLUGIN_ID, code, DEFAULT_STRING, null);
@ -107,16 +106,15 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
}
/**
* Constructs an C model status with the given corresponding
* element.
* Constructs an C model status with the given corresponding element.
*/
public CModelStatus(int code, ICElement element) {
this(code, new ICElement[]{element});
}
/**
* Constructs an C model status with the given corresponding
* element and string
* Constructs an C model status with the given corresponding element and
* string
*/
public CModelStatus(int code, ICElement element, String string) {
this(code, new ICElement[]{element});
@ -184,7 +182,6 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
case CORE_EXCEPTION :
return CoreModelMessages.getFormattedString("status.coreException"); //$NON-NLS-1$
case DEVICE_PATH :
return CoreModelMessages.getFormattedString("status.cannotUseDeviceOnPath", getPath().toString()); //$NON-NLS-1$
@ -220,10 +217,11 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
return CoreModelMessages.getFormattedString("status.invalidName", getString()); //$NON-NLS-1$
case INVALID_PATH :
if (fString != null) {
return fString;
}
return CoreModelMessages.getFormattedString("status.invalidPath", getPath() == null ? "null" : getPath().toString()); //$NON-NLS-1$ //$NON-NLS-2$
String path = getPath() == null ? "null" : getPath().toString(); //$NON-NLS-1$
return CoreModelMessages.getFormattedString("status.invalidPath", new Object[]{path, getString()}); //$NON-NLS-1$
case INVALID_PATHENTRY :
return CoreModelMessages.getFormattedString("status.invalidPathEntry", getString()); //$NON-NLS-1$
case INVALID_PROJECT :
return CoreModelMessages.getFormattedString("status.invalidProject", getString()); //$NON-NLS-1$
@ -267,7 +265,8 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
return CoreModelMessages.getFormattedString("operation.needString"); //$NON-NLS-1$
case PATH_OUTSIDE_PROJECT :
return CoreModelMessages.getFormattedString("operation.pathOutsideProject", new String[]{getString(), getFirstElementName()}); //$NON-NLS-1$
return CoreModelMessages.getFormattedString(
"operation.pathOutsideProject", new String[]{getString(), getFirstElementName()}); //$NON-NLS-1$
case READ_ONLY :
return CoreModelMessages.getFormattedString("status.readOnly", getFirstElementName()); //$NON-NLS-1$
@ -282,18 +281,15 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
return CoreModelMessages.getFormattedString("status.noLocalContents", getPath().toString()); //$NON-NLS-1$
case INVALID_CONTAINER_ENTRY :
return CoreModelMessages.getFormattedString("pathentry.invalidContainer", new String[] {getString(), getFirstElementName()}); //$NON-NLS-1$
return CoreModelMessages.getFormattedString(
"pathentry.invalidContainer", new String[]{getString(), getFirstElementName()}); //$NON-NLS-1$
case VARIABLE_PATH_UNBOUND :
return CoreModelMessages.getFormattedString("pathentry.unboundVariablePath",
new String[] {getPath().makeRelative().toString(), getFirstElementName()}); //$NON-NLS-1$
return CoreModelMessages.getFormattedString("pathentry.unboundVariablePath", //$NON-NLS-1$
new String[]{getPath().makeRelative().toString(), getFirstElementName()});
case PATHENTRY_CYCLE :
return CoreModelMessages.getFormattedString("pathentry.cycle", getFirstElementName()); //$NON-NLS-1$
//case DISABLED_CP_EXCLUSION_PATTERNS:
//case DISABLED_CP_MULTIPLE_OUTPUT_LOCATIONS:
}
return getString();
}
@ -318,7 +314,8 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
* @see IStatus
*/
public int getSeverity() {
if (fChildren == fgEmptyChildren) return super.getSeverity();
if (fChildren == fgEmptyChildren)
return super.getSeverity();
int severity = -1;
for (int i = 0, max = fChildren.length; i < max; i++) {
int childrenSeverity = fChildren[i].getSeverity();
@ -392,8 +389,8 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
}
/**
* Creates and returns a new <code>ICModelStatus</code> that is a
* a multi-status status.
* Creates and returns a new <code>ICModelStatus</code> that is a a
* multi-status status.
*
* @see IStatus#.isMultiStatus()
*/
@ -404,8 +401,8 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
}
/**
* Creates and returns a new <code>ICModelStatus</code> that is a
* a multi-status status.
* Creates and returns a new <code>ICModelStatus</code> that is a a
* multi-status status.
*
* @see IStatus#.isMultiStatus()
*/

View file

@ -58,6 +58,7 @@ status.invalidName = Invalid name specified: {0}.
status.invalidPackage = Invalid package: {0}.
status.invalidPath = Invalid path: ''{0}''.
status.invalidProject = Invalid project: {0}.
status.invalidPathEntry = Invalid project path: {0}.
status.invalidResource = Invalid resource: {0}.
status.invalidResourceType = Invalid resource type for {0}.
status.invalidSibling = Invalid sibling: {0}.
@ -68,3 +69,11 @@ status.readOnly = {0} is read-only.
status.targetException = Target exception.
status.updateConflict = Update conflict.
PathEntryManager.0=Missing project folder or file:
PathEntryManager.2=Include path not found
PathEntryManager.3=Source attachment not found
PathEntryManager.4=Library not found
PathEntryManager.5=Referenced project is not accessible
PathEntryManager.6=Referenced project is not a C/C++ project
PathEntryManager.1=Workspace include path in accessible
PathEntryManager.7=Workspace library path in accessible

View file

@ -1,13 +1,11 @@
/*******************************************************************************
* Copyright (c) 2000, 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
* Copyright (c) 2000, 2004 QNX Software Systems and others. All rights
* reserved. This program and the accompanying materials are made available
* under the terms of the Common Public License v1.0 which accompanies this
* distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
* Contributors: QNX Software Systems - Initial API and implementation
******************************************************************************/
package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.IPathEntry;
@ -26,21 +24,27 @@ public class PathEntry implements IPathEntry {
this.isExported = isExported;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.IPathEntry#getEntryKind()
*/
public IPath getPath() {
return path;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.IPathEntry#getEntryKind()
*/
public int getEntryKind() {
return entryKind;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.IPathEntry#isExported()
*/
public boolean isExported() {
@ -122,31 +126,28 @@ public class PathEntry implements IPathEntry {
buffer.append(path.toString()).append(' ');
}
buffer.append('[');
switch (getEntryKind()) {
case IPathEntry.CDT_LIBRARY :
buffer.append("CDT_LIBRARY"); //$NON-NLS-1$
break;
case IPathEntry.CDT_PROJECT :
buffer.append("CDT_PROJECT"); //$NON-NLS-1$
break;
case IPathEntry.CDT_SOURCE :
buffer.append("CDT_SOURCE"); //$NON-NLS-1$
break;
case IPathEntry.CDT_OUTPUT :
buffer.append("CDT_OUTPUT"); //$NON-NLS-1$
break;
case IPathEntry.CDT_INCLUDE :
buffer.append("CDT_INCLUDE"); //$NON-NLS-1$
break;
case IPathEntry.CDT_MACRO :
buffer.append("CDT_MACRO"); //$NON-NLS-1$
break;
case IPathEntry.CDT_CONTAINER :
buffer.append("CDT_CONTAINER"); //$NON-NLS-1$
break;
}
buffer.append(getKindString());
buffer.append(']');
return buffer.toString();
}
String getKindString() {
switch (getEntryKind()) {
case IPathEntry.CDT_LIBRARY :
return ("Library path"); //$NON-NLS-1$
case IPathEntry.CDT_PROJECT :
return ("Project path"); //$NON-NLS-1$
case IPathEntry.CDT_SOURCE :
return ("Source path"); //$NON-NLS-1$
case IPathEntry.CDT_OUTPUT :
return ("Output path"); //$NON-NLS-1$
case IPathEntry.CDT_INCLUDE :
return ("Include path"); //$NON-NLS-1$
case IPathEntry.CDT_MACRO :
return ("Symbol definition"); //$NON-NLS-1$
case IPathEntry.CDT_CONTAINER :
return ("Contributed paths"); //$NON-NLS-1$
}
return ("Unknown"); //$NON-NLS-1$
}
}

View file

@ -17,6 +17,7 @@ import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICExtensionReference;
@ -50,6 +51,7 @@ 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.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
@ -76,19 +78,20 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
static String CONTAINER_INITIALIZER_EXTPOINT_ID = "PathEntryContainerInitializer"; //$NON-NLS-1$
/**
* An empty array of strings indicating that a project doesn't have any prerequesite projects.
* An empty array of strings indicating that a project doesn't have any
* prerequesite projects.
*/
static final String[] NO_PREREQUISITES = new String[0];
/**
* pathentry containers pool
* accessing the Container is done synch with the class
* pathentry containers pool accessing the Container is done synch with the
* class
*/
private static HashMap Containers = new HashMap(5);
static final IPathEntry[] NO_PATHENTRIES = new IPathEntry[0];
// Synchronized the access of the cache entries.
private Map resolvedMap = new Hashtable();
protected Map resolvedMap = new Hashtable();
// Accessing the map is synch with the class
private Map storeMap = new HashMap();
@ -109,21 +112,27 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
runInitializer = init;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.model.IPathEntryContainer#getPathEntries()
*/
public IPathEntry[] getPathEntries() {
return NO_PATHENTRIES;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.model.IPathEntryContainer#getDescription()
*/
public String getDescription() {
return new String("Lock container"); //$NON-NLS-1$
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.model.IPathEntryContainer#getPath()
*/
public IPath getPath() {
@ -220,14 +229,18 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
IIncludeEntry refEntry = (IIncludeEntry)entries[i];
if (refEntry.getIncludePath().equals(includePath)) {
IPath newBasePath = refEntry.getBasePath();
// If the includePath is relative give a new basepath if none
// If the includePath is
// relative give a new basepath
// if none
if (!newBasePath.isAbsolute() && !includePath.isAbsolute()) {
IResource refRes;
if (!newBasePath.isEmpty()) {
refRes = cproject.getCModel().getWorkspace().getRoot().findMember(newBasePath);
refRes = cproject.getCModel().getWorkspace().getRoot().findMember(
newBasePath);
} else {
IPath refResPath = refEntry.getPath();
refRes = cproject.getCModel().getWorkspace().getRoot().findMember(refResPath);
refRes = cproject.getCModel().getWorkspace().getRoot().findMember(
refResPath);
}
if (refRes != null) {
if (refRes.getType() == IResource.FILE) {
@ -236,8 +249,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
newBasePath = refRes.getLocation().append(newBasePath);
}
}
return CoreModel.newIncludeEntry(includeEntry.getPath(),
newBasePath, includePath);
return CoreModel.newIncludeEntry(includeEntry.getPath(), newBasePath, includePath);
}
}
}
@ -325,14 +337,18 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
ILibraryEntry refEntry = (ILibraryEntry)entries[i];
if (refEntry.getLibraryPath().equals(libraryPath)) {
IPath newBasePath = refEntry.getBasePath();
// If the libraryPath is relative give a new basepath if none
// If the libraryPath is
// relative give a new basepath
// if none
if (!newBasePath.isAbsolute() && !libraryPath.isAbsolute()) {
IResource refRes;
if (!newBasePath.isEmpty()) {
refRes = cproject.getCModel().getWorkspace().getRoot().findMember(newBasePath);
refRes = cproject.getCModel().getWorkspace().getRoot().findMember(
newBasePath);
} else {
IPath refResPath = refEntry.getPath();
refRes = cproject.getCModel().getWorkspace().getRoot().findMember(refResPath);
refRes = cproject.getCModel().getWorkspace().getRoot().findMember(
refResPath);
}
if (refRes != null) {
if (refRes.getType() == IResource.FILE) {
@ -465,7 +481,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
}
if (!found) {
// filter out this project - does not reference the container path
// filter out this project - does not reference the container
// path
modifiedProjects[i] = null;
// Still add it to the cache
containerPut(affectedProject, containerPath, newContainer);
@ -492,8 +509,10 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
// trigger model refresh
try {
//final boolean canChangeResources = !ResourcesPlugin.getWorkspace().isTreeLocked();
//final boolean canChangeResources =
// !ResourcesPlugin.getWorkspace().isTreeLocked();
CoreModel.run(new IWorkspaceRunnable() {
public void run(IProgressMonitor progressMonitor) throws CoreException {
boolean shouldFire = false;
@ -577,7 +596,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
});
}
if (!ok[0]) {
containerPut(project, containerPath, null); // flush and notify
containerPut(project, containerPath, null); // flush and
// notify
}
}
// retrieve new value
@ -587,23 +607,27 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
/**
* Helper method finding the container initializer registered for a given container ID or <code>null</code> if none was found
* while iterating over the contributions to extension point to the extension point
* Helper method finding the container initializer registered for a given
* container ID or <code>null</code> if none was found while iterating
* over the contributions to extension point to the extension point
* "org.eclipse.cdt.core.PathEntryContainerInitializer".
* <p>
* A containerID is the first segment of any container path, used to identify the registered container initializer.
* A containerID is the first segment of any container path, used to
* identify the registered container initializer.
* <p>
*
* @param containerID -
* a containerID identifying a registered initializer
* @return PathEntryContainerInitializer - the registered container initializer or <code>null</code> if none was found.
* @return PathEntryContainerInitializer - the registered container
* initializer or <code>null</code> if none was found.
*/
public PathEntryContainerInitializer getPathEntryContainerInitializer(String containerID) {
Plugin core = CCorePlugin.getDefault();
if (core == null) {
return null;
}
IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, CONTAINER_INITIALIZER_EXTPOINT_ID);
IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID,
CONTAINER_INITIALIZER_EXTPOINT_ID);
if (extension != null) {
IExtension[] extensions = extension.getExtensions();
for (int i = 0; i < extensions.length; i++) {
@ -706,7 +730,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
// 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)
// 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))) {
@ -746,9 +771,9 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
IPath baseRef = library.getBaseReference();
if (baseRef == null || baseRef.isEmpty()) {
entry = CoreModel.newLibraryEntry(resourcePath, library.getBasePath(),
library.getLibraryPath(), sourcePath, library.getSourceAttachmentRootPath(),
library.getSourceAttachmentPrefixMapping(), library.isExported());
entry = CoreModel.newLibraryEntry(resourcePath, library.getBasePath(), library.getLibraryPath(),
sourcePath, library.getSourceAttachmentRootPath(), library.getSourceAttachmentPrefixMapping(),
library.isExported());
} else {
entry = CoreModel.newLibraryRefEntry(resourcePath, baseRef, library.getLibraryPath());
}
@ -799,27 +824,69 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
}
public void generateMarkers(final ICProject finalCProject, final IPathEntry[] finalEntries) {
public void generateMarkers(final ICProject cProject, final IPathEntry[] entries) {
Job markerTask = new Job("PathEntry Marker Job") { //$NON-NLS-1$
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
protected IStatus run(IProgressMonitor monitor) {
IProject project = finalCProject.getProject();
IProject project = cProject.getProject();
flushPathEntryProblemMarkers(project);
ICModelStatus status = validatePathEntry(finalCProject, finalEntries);
ICModelStatus status = validatePathEntry(cProject, entries);
if (!status.isOK()) {
createPathEntryProblemMarker(project, status);
}
for (int j = 0; j < finalEntries.length; j++) {
status = validatePathEntry(finalCProject, finalEntries[j], true, false);
for (int j = 0; j < entries.length; j++) {
status = validatePathEntry(cProject, entries[j], true, false);
if (!status.isOK()) {
createPathEntryProblemMarker(project, status);
}
}
return Status.OK_STATUS;
}
};
markerTask.setRule(CCorePlugin.getWorkspace().getRoot());
markerTask.schedule();
}
public void updateMarkers(final ICProject[] cProjects) {
Job markerTask = new Job("PathEntry Marker Job") { //$NON-NLS-1$
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
protected IStatus run(IProgressMonitor monitor) {
for(int i = 0; i < cProjects.length; i++) {
ArrayList resolvedList = (ArrayList)resolvedMap.get(cProjects[i]);
if (resolvedList != null) {
IPathEntry[] entries = (IPathEntry[])resolvedList.toArray(new IPathEntry[resolvedList.size()]);
IProject project = cProjects[i].getProject();
flushPathEntryProblemMarkers(project);
ICModelStatus status = validatePathEntry(cProjects[i], entries);
if (!status.isOK()) {
createPathEntryProblemMarker(project, status);
}
for (int j = 0; j < entries.length; j++) {
status = validatePathEntry(cProjects[i], entries[j], true, false);
if (!status.isOK()) {
createPathEntryProblemMarker(project, status);
}
}
}
}
return Status.OK_STATUS;
}
};
markerTask.setRule(CCorePlugin.getWorkspace().getRoot());
markerTask.schedule();
}
@ -953,7 +1020,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return null;
}
ArrayList containerIDList = new ArrayList(5);
IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, CONTAINER_INITIALIZER_EXTPOINT_ID);
IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID,
CONTAINER_INITIALIZER_EXTPOINT_ID);
if (extension != null) {
IExtension[] extensions = extension.getExtensions();
for (int i = 0; i < extensions.length; i++) {
@ -1024,7 +1092,9 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return store;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.resources.IPathEntryStoreListener#pathEntryStoreChanged(org.eclipse.cdt.core.resources.PathEntryChangedEvent)
*/
public void pathEntryStoreChanged(PathEntryStoreChangedEvent event) {
@ -1067,27 +1137,31 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.model.IElementChangedListener#elementChanged(org.eclipse.cdt.core.model.ElementChangedEvent)
*/
public void elementChanged(ElementChangedEvent event) {
try {
processDelta(event.getDelta());
if (processDelta(event.getDelta()) == true) {
ICProject[] projects = (ICProject [])resolvedMap.keySet().toArray(new ICProject[0]);
updateMarkers(projects);
}
} catch (CModelException e) {
}
}
protected void processDelta(ICElementDelta delta) throws CModelException {
protected boolean processDelta(ICElementDelta delta) throws CModelException {
int kind = delta.getKind();
int flags= delta.getFlags();
ICElement element = delta.getElement();
int type = element.getElementType();
//System.out.println("Processing " + element);
// handle closing and removing of projects
if (((flags & ICElementDelta.F_CLOSED) != 0) || (kind == ICElementDelta.REMOVED)) {
if (element.getElementType() == ICElement.C_PROJECT) {
// handle open, closing and removing of projects
if ( type == ICElement.C_PROJECT) {
ICProject cproject = (ICProject)element;
if ((kind == ICElementDelta.REMOVED || kind == ICElementDelta.ADDED)) {
if (kind == ICElementDelta.REMOVED) {
IProject project = cproject.getProject();
IPathEntryStore store = null;
try {
@ -1103,25 +1177,21 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
containerRemove(cproject);
}
}
return;
}
} else if (kind == ICElementDelta.CHANGED) {
// We should update the pathentry markers if the project change.
if (element.getElementType() == ICElement.C_PROJECT) {
ICProject cproject = (ICProject)element;
ArrayList resolvedList = (ArrayList)resolvedMap.get(cproject);
if (resolvedList != null) {
IPathEntry[] entries = (IPathEntry[]) resolvedList.toArray(new IPathEntry[resolvedList.size()]);
generateMarkers(cproject, entries);
}
return;
return true;
}
// project change, traverse children.
} else if (kind == ICElementDelta.ADDED || kind == ICElementDelta.REMOVED) {
return true; // add/remove we validate all paths
}
ICElementDelta[] affectedChildren = delta.getAffectedChildren();
for (int i = 0; i < affectedChildren.length; i++) {
processDelta(affectedChildren[i]);
if (processDelta(affectedChildren[i]) == true) {
return true;
}
}
return false;
}
protected IPathEntry cloneEntry(IPath rpath, IPathEntry entry) {
@ -1182,7 +1252,6 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
if (entry != otherEntry && otherEntry.equals(entry)) {
StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.DuplicateEntry")); //$NON-NLS-1$
errMesg.append(':').append(entry.toString());
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString());
}
}
@ -1194,7 +1263,6 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
ICModelStatus[] cmodelStatus = new ICModelStatus[dups.size()];
for (int i = 0; i < dups.size(); ++i) {
StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.DuplicateEntry")); //$NON-NLS-1$
errMesg.append(':').append(dups.get(i).toString());
cmodelStatus[i] = new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString());
}
return CModelStatus.newMultiStatus(ICModelStatusConstants.INVALID_PATHENTRY, cmodelStatus);
@ -1206,13 +1274,13 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
ICModelStatus[] cmodelStatus = new ICModelStatus[dups.size()];
for (int i = 0; i < dups.size(); ++i) {
StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.DuplicateEntry")); //$NON-NLS-1$
errMesg.append(':').append(dups.get(i).toString());
cmodelStatus[i] = new CModelStatus(ICModelStatusConstants.NAME_COLLISION, errMesg.toString());
}
return CModelStatus.newMultiStatus(ICModelStatusConstants.INVALID_PATHENTRY, cmodelStatus);
}
// allow nesting source entries in each other as long as the outer entry excludes the inner one
// 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) {
@ -1235,17 +1303,17 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
String exclusionPattern = entryPath.removeFirstSegments(otherPath.segmentCount()).segment(0);
if (CoreModelUtil.isExcluded(entryPath, exclusionPatterns)) {
StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$
errMesg.append(':').append(entry.toString());
StringBuffer errMesg = new StringBuffer(
CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString());
} else if (otherKind == IPathEntry.CDT_SOURCE) {
exclusionPattern += '/';
StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$
errMesg.append(':').append(entry.toString());
StringBuffer errMesg = new StringBuffer(
CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString());
} else {
StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$
errMesg.append(':').append(entry.toString());
StringBuffer errMesg = new StringBuffer(
CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString()); //$NON-NLS-1$
}
}
@ -1257,86 +1325,67 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return CModelStatus.VERIFIED_OK;
}
public ICModelStatus validatePathEntry(ICProject cProject, IPathEntry entry, boolean checkSourceAttachment, boolean recurseInContainers){
public ICModelStatus validatePathEntry(ICProject cProject, IPathEntry entry, boolean checkSourceAttachment,
boolean recurseInContainers) {
IProject project = cProject.getProject();
StringBuffer sb = new StringBuffer();
sb.append(CCorePlugin.getResourceString("CoreModel.PathEntry.InvalidPathEntry")); //$NON-NLS-1$
sb.append(':').append(entry.toString());
String entryMesg = sb.toString();
IPath path = entry.getPath();
if (entry.getEntryKind() != IPathEntry.CDT_PROJECT) {
if (!isValidWorkspacePath(project, path)) {
return new CModelStatus(
ICModelStatusConstants.INVALID_PATHENTRY,
CoreModelMessages.getString("PathEntryManager.0") + path.toOSString() + " for " + ((PathEntry)entry).getKindString()); //$NON-NLS-1$ //$NON-NLS-2$
}
}
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$
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY,
CoreModelMessages.getString("PathEntryManager.2") + " (" + includePath.toOSString() + ")"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
}
if (!isValidBasePath(include.getBasePath())) {
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY,
CoreModelMessages.getString("PathEntryManager.1") + " (" + includePath.toOSString() + ")"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
}
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);
if (!isValidWorkspacePath(project, sourceAttach) || !isValidExternalPath(sourceAttach)) {
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY,
CoreModelMessages.getString("PathEntryManager.3") + " (" + sourceAttach.toOSString() + ")"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
}
} 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$
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY,
CoreModelMessages.getString("PathEntryManager.4") + " (" + libraryPath.toOSString() + ")"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
}
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$
if (!isValidBasePath(library.getBasePath())) {
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY,
CoreModelMessages.getString("PathEntryManager.7") + " (" + libraryPath.toOSString() + ")"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
}
break;
}
case IPathEntry.CDT_PROJECT : {
IProjectEntry projEntry = (IProjectEntry)entry;
IPath path = projEntry.getPath();
if (path != null && path.isAbsolute() && !path.isEmpty()) {
path = projEntry.getPath();
IProject reqProject = project.getWorkspace().getRoot().getProject(path.segment(0));
if (!reqProject.exists() || !(CoreModel.hasCNature(reqProject) || CoreModel.hasCCNature(reqProject))) {
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$
if (!reqProject.isAccessible()) {
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY,
CoreModelMessages.getString("PathEntryManager.5")); //$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$
if (! (CoreModel.hasCNature(reqProject) || CoreModel.hasCCNature(reqProject))) {
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY,
CoreModelMessages.getString("PathEntryManager.6")); //$NON-NLS-1$
}
break;
}
@ -1385,6 +1434,16 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return false;
}
private boolean isValidBasePath(IPath path) {
if (!path.isEmpty() && !path.isAbsolute()) {
IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
if (res == null || !res.isAccessible()) {
return false;
}
}
return true;
}
private List checkForDuplication(List pathEntries, int type) {
List duplicate = new ArrayList(pathEntries.size());
for (int i = 0; i < pathEntries.size(); ++i) {
@ -1431,20 +1490,10 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
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.getMessage(),
new Integer(severity),
"pathentry",//$NON-NLS-1$
marker.setAttributes(new String[]{IMarker.MESSAGE, IMarker.SEVERITY, IMarker.LOCATION,
ICModelMarker.PATHENTRY_FILE_FORMAT,}, new Object[]{status.getMessage(), new Integer(severity), "pathentry",//$NON-NLS-1$
"false",//$NON-NLS-1$
}
);
});
} catch (CoreException e) {
// could not create marker: cannot do much
//e.printStackTrace();
@ -1470,6 +1519,4 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
}
}