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; package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModelStatus; 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 { public class CModelStatus extends Status implements ICModelStatus, ICModelStatusConstants, IResourceStatus {
/** /**
* The elements related to the failure, or <code>null</code> * The elements related to the failure, or <code>null</code> if no
* if no elements are involved. * elements are involved.
*/ */
protected ICElement[] fElements; protected ICElement[] fElements;
protected final static ICElement[] EmptyElement = new ICElement[] {};
protected final static ICElement[] EmptyElement = new ICElement[]{};
/** /**
* The path related to the failure, or <code>null</code> * The path related to the failure, or <code>null</code> if no path is
* if no path is involved. * involved.
*/ */
protected IPath fPath; protected IPath fPath;
/** /**
@ -49,9 +49,9 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
/** /**
* Empty children * Empty children
*/ */
protected final static IStatus[] fgEmptyChildren = new IStatus[] {}; protected final static IStatus[] fgEmptyChildren = new IStatus[]{};
protected IStatus[] fChildren= fgEmptyChildren; protected IStatus[] fChildren = fgEmptyChildren;
protected final static String DEFAULT_STRING= "CModelStatus"; //$NON-NLS-1$; protected final static String DEFAULT_STRING = "CModelStatus"; //$NON-NLS-1$;
/** /**
* Singleton OK object * Singleton OK object
@ -74,13 +74,12 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
} }
/** /**
* Constructs an C model status with the given corresponding * Constructs an C model status with the given corresponding elements.
* elements.
*/ */
public CModelStatus(int code, ICElement[] elements) { public CModelStatus(int code, ICElement[] elements) {
super(ERROR, CCorePlugin.PLUGIN_ID, code, DEFAULT_STRING, null); super(ERROR, CCorePlugin.PLUGIN_ID, code, DEFAULT_STRING, null);
fElements = elements; fElements = elements;
fPath= Path.EMPTY; fPath = Path.EMPTY;
} }
/** /**
@ -93,7 +92,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
public CModelStatus(int severity, int code, String string) { public CModelStatus(int severity, int code, String string) {
super(severity, CCorePlugin.PLUGIN_ID, code, DEFAULT_STRING, null); super(severity, CCorePlugin.PLUGIN_ID, code, DEFAULT_STRING, null);
fElements = CElement.NO_ELEMENTS; fElements = CElement.NO_ELEMENTS;
fPath= Path.EMPTY; fPath = Path.EMPTY;
fString = string; fString = string;
} }
@ -103,24 +102,23 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
public CModelStatus(int code, IPath path) { public CModelStatus(int code, IPath path) {
super(ERROR, CCorePlugin.PLUGIN_ID, code, DEFAULT_STRING, null); super(ERROR, CCorePlugin.PLUGIN_ID, code, DEFAULT_STRING, null);
fElements = CElement.NO_ELEMENTS; fElements = CElement.NO_ELEMENTS;
fPath= path; fPath = path;
} }
/** /**
* Constructs an C model status with the given corresponding * Constructs an C model status with the given corresponding element.
* element.
*/ */
public CModelStatus(int code, ICElement element) { public CModelStatus(int code, ICElement element) {
this(code, new ICElement[]{element}); this(code, new ICElement[]{element});
} }
/** /**
* Constructs an C model status with the given corresponding * Constructs an C model status with the given corresponding element and
* element and string * string
*/ */
public CModelStatus(int code, ICElement element, String string) { public CModelStatus(int code, ICElement element, String string) {
this(code, new ICElement[]{element}); this(code, new ICElement[]{element});
fString= string; fString = string;
} }
public CModelStatus(int code, ICElement element, IPath path) { public CModelStatus(int code, ICElement element, IPath path) {
@ -146,7 +144,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
protected int getBits() { protected int getBits() {
int severity = 1 << (getCode() % 100 / 33); int severity = 1 << (getCode() % 100 / 33);
int category = 1 << ((getCode() / 100) + 3); int category = 1 << ( (getCode() / 100) + 3);
return severity | category; return severity | category;
} }
@ -184,66 +182,66 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
case CORE_EXCEPTION : case CORE_EXCEPTION :
return CoreModelMessages.getFormattedString("status.coreException"); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.coreException"); //$NON-NLS-1$
case DEVICE_PATH :
case DEVICE_PATH:
return CoreModelMessages.getFormattedString("status.cannotUseDeviceOnPath", getPath().toString()); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.cannotUseDeviceOnPath", getPath().toString()); //$NON-NLS-1$
case PARSER_EXCEPTION: case PARSER_EXCEPTION :
return CoreModelMessages.getFormattedString("status.ParserError"); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.ParserError"); //$NON-NLS-1$
case ELEMENT_DOES_NOT_EXIST: case ELEMENT_DOES_NOT_EXIST :
return CoreModelMessages.getFormattedString("element.doesNotExist", getFirstElementName()); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("element.doesNotExist", getFirstElementName()); //$NON-NLS-1$
case EVALUATION_ERROR: case EVALUATION_ERROR :
return CoreModelMessages.getFormattedString("status.evaluationError", getString()); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.evaluationError", getString()); //$NON-NLS-1$
case INDEX_OUT_OF_BOUNDS: case INDEX_OUT_OF_BOUNDS :
return CoreModelMessages.getFormattedString("status.indexOutOfBounds"); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.indexOutOfBounds"); //$NON-NLS-1$
case INVALID_CONTENTS: case INVALID_CONTENTS :
return CoreModelMessages.getFormattedString("status.invalidContents"); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.invalidContents"); //$NON-NLS-1$
case INVALID_DESTINATION: case INVALID_DESTINATION :
return CoreModelMessages.getFormattedString("status.invalidDestination", getFirstElementName()); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.invalidDestination", getFirstElementName()); //$NON-NLS-1$
case INVALID_ELEMENT_TYPES: case INVALID_ELEMENT_TYPES :
StringBuffer buff= new StringBuffer(CoreModelMessages.getFormattedString("operation.notSupported")); //$NON-NLS-1$ StringBuffer buff = new StringBuffer(CoreModelMessages.getFormattedString("operation.notSupported")); //$NON-NLS-1$
for (int i = 0; i < fElements.length; i++) { for (int i = 0; i < fElements.length; i++) {
if (i > 0) { if (i > 0) {
buff.append(", "); //$NON-NLS-1$ buff.append(", "); //$NON-NLS-1$
} }
buff.append((fElements[i]).toString()); buff.append( (fElements[i]).toString());
} }
return buff.toString(); return buff.toString();
case INVALID_NAME: case INVALID_NAME :
return CoreModelMessages.getFormattedString("status.invalidName", getString()); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.invalidName", getString()); //$NON-NLS-1$
case INVALID_PATH: case INVALID_PATH :
if (fString != null) { String path = getPath() == null ? "null" : getPath().toString(); //$NON-NLS-1$
return fString; return CoreModelMessages.getFormattedString("status.invalidPath", new Object[]{path, getString()}); //$NON-NLS-1$
}
return CoreModelMessages.getFormattedString("status.invalidPath", getPath() == null ? "null" : getPath().toString()); //$NON-NLS-1$ //$NON-NLS-2$
case INVALID_PROJECT: case INVALID_PATHENTRY :
return CoreModelMessages.getFormattedString("status.invalidPathEntry", getString()); //$NON-NLS-1$
case INVALID_PROJECT :
return CoreModelMessages.getFormattedString("status.invalidProject", getString()); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.invalidProject", getString()); //$NON-NLS-1$
case INVALID_RESOURCE: case INVALID_RESOURCE :
return CoreModelMessages.getFormattedString("status.invalidResource", getString()); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.invalidResource", getString()); //$NON-NLS-1$
case INVALID_RESOURCE_TYPE: case INVALID_RESOURCE_TYPE :
return CoreModelMessages.getFormattedString("status.invalidResourceType", getString()); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.invalidResourceType", getString()); //$NON-NLS-1$
case INVALID_SIBLING: case INVALID_SIBLING :
if (fString != null) { if (fString != null) {
return CoreModelMessages.getFormattedString("status.invalidSibling", getString()); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.invalidSibling", getString()); //$NON-NLS-1$
} }
return CoreModelMessages.getFormattedString("status.invalidSibling", getFirstElementName()); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.invalidSibling", getFirstElementName()); //$NON-NLS-1$
case IO_EXCEPTION: case IO_EXCEPTION :
return CoreModelMessages.getFormattedString("status.IOException"); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.IOException"); //$NON-NLS-1$
case NAME_COLLISION: case NAME_COLLISION :
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
if (fElements != null && fElements.length > 0) { if (fElements != null && fElements.length > 0) {
ICElement element = fElements[0]; ICElement element = fElements[0];
@ -254,46 +252,44 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
} }
return CoreModelMessages.getFormattedString("status.nameCollision", sb.toString()); //$NON-NLS-1$ //$NON-NLS-2$ return CoreModelMessages.getFormattedString("status.nameCollision", sb.toString()); //$NON-NLS-1$ //$NON-NLS-2$
case NO_ELEMENTS_TO_PROCESS: case NO_ELEMENTS_TO_PROCESS :
return CoreModelMessages.getFormattedString("operation.needElements"); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("operation.needElements"); //$NON-NLS-1$
case NULL_NAME: case NULL_NAME :
return CoreModelMessages.getFormattedString("operation.needName"); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("operation.needName"); //$NON-NLS-1$
case NULL_PATH: case NULL_PATH :
return CoreModelMessages.getFormattedString("operation.needPath"); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("operation.needPath"); //$NON-NLS-1$
case NULL_STRING: case NULL_STRING :
return CoreModelMessages.getFormattedString("operation.needString"); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("operation.needString"); //$NON-NLS-1$
case PATH_OUTSIDE_PROJECT: 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: case READ_ONLY :
return CoreModelMessages.getFormattedString("status.readOnly", getFirstElementName()); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.readOnly", getFirstElementName()); //$NON-NLS-1$
case RELATIVE_PATH: case RELATIVE_PATH :
return CoreModelMessages.getFormattedString("operation.needAbsolutePath", getPath().toString()); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("operation.needAbsolutePath", getPath().toString()); //$NON-NLS-1$
case UPDATE_CONFLICT: case UPDATE_CONFLICT :
return CoreModelMessages.getFormattedString("status.updateConflict"); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.updateConflict"); //$NON-NLS-1$
case NO_LOCAL_CONTENTS : case NO_LOCAL_CONTENTS :
return CoreModelMessages.getFormattedString("status.noLocalContents", getPath().toString()); //$NON-NLS-1$ return CoreModelMessages.getFormattedString("status.noLocalContents", getPath().toString()); //$NON-NLS-1$
case INVALID_CONTAINER_ENTRY: 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: case VARIABLE_PATH_UNBOUND :
return CoreModelMessages.getFormattedString("pathentry.unboundVariablePath", return CoreModelMessages.getFormattedString("pathentry.unboundVariablePath", //$NON-NLS-1$
new String[] {getPath().makeRelative().toString(), getFirstElementName()}); //$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:
case PATHENTRY_CYCLE :
return CoreModelMessages.getFormattedString("pathentry.cycle", getFirstElementName()); //$NON-NLS-1$
} }
return getString(); return getString();
} }
@ -318,7 +314,8 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
* @see IStatus * @see IStatus
*/ */
public int getSeverity() { public int getSeverity() {
if (fChildren == fgEmptyChildren) return super.getSeverity(); if (fChildren == fgEmptyChildren)
return super.getSeverity();
int severity = -1; int severity = -1;
for (int i = 0, max = fChildren.length; i < max; i++) { for (int i = 0, max = fChildren.length; i < max; i++) {
int childrenSeverity = fChildren[i].getSeverity(); int childrenSeverity = fChildren[i].getSeverity();
@ -362,7 +359,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
/** /**
* @see ICModelStatus * @see ICModelStatus
*/ */
public boolean isOK() { public boolean isOK() {
return getCode() == OK; return getCode() == OK;
} }
@ -371,11 +368,11 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
* @see IStatus#matches * @see IStatus#matches
*/ */
public boolean matches(int mask) { public boolean matches(int mask) {
if (! isMultiStatus()) { if (!isMultiStatus()) {
return matches(this, mask); return matches(this, mask);
} }
for (int i = 0, max = fChildren.length; i < max; i++) { for (int i = 0, max = fChildren.length; i < max; i++) {
if (matches((CModelStatus) fChildren[i], mask)) if (matches((CModelStatus)fChildren[i], mask))
return true; return true;
} }
return false; return false;
@ -388,12 +385,12 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
int severityMask = mask & 0x7; int severityMask = mask & 0x7;
int categoryMask = mask & ~0x7; int categoryMask = mask & ~0x7;
int bits = status.getBits(); int bits = status.getBits();
return ((severityMask == 0) || (bits & severityMask) != 0) && ((categoryMask == 0) || (bits & categoryMask) != 0); return ( (severityMask == 0) || (bits & severityMask) != 0) && ( (categoryMask == 0) || (bits & categoryMask) != 0);
} }
/** /**
* Creates and returns a new <code>ICModelStatus</code> that is a * Creates and returns a new <code>ICModelStatus</code> that is a a
* a multi-status status. * multi-status status.
* *
* @see IStatus#.isMultiStatus() * @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 * Creates and returns a new <code>ICModelStatus</code> that is a a
* a multi-status status. * multi-status status.
* *
* @see IStatus#.isMultiStatus() * @see IStatus#.isMultiStatus()
*/ */
@ -420,7 +417,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus
* purposes. * purposes.
*/ */
public String toString() { public String toString() {
if (this == VERIFIED_OK){ if (this == VERIFIED_OK) {
return "CModelStatus[OK]"; //$NON-NLS-1$ return "CModelStatus[OK]"; //$NON-NLS-1$
} }
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();

View file

@ -58,6 +58,7 @@ status.invalidName = Invalid name specified: {0}.
status.invalidPackage = Invalid package: {0}. status.invalidPackage = Invalid package: {0}.
status.invalidPath = Invalid path: ''{0}''. status.invalidPath = Invalid path: ''{0}''.
status.invalidProject = Invalid project: {0}. status.invalidProject = Invalid project: {0}.
status.invalidPathEntry = Invalid project path: {0}.
status.invalidResource = Invalid resource: {0}. status.invalidResource = Invalid resource: {0}.
status.invalidResourceType = Invalid resource type for {0}. status.invalidResourceType = Invalid resource type for {0}.
status.invalidSibling = Invalid sibling: {0}. status.invalidSibling = Invalid sibling: {0}.
@ -68,3 +69,11 @@ status.readOnly = {0} is read-only.
status.targetException = Target exception. status.targetException = Target exception.
status.updateConflict = Update conflict. 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. * Copyright (c) 2000, 2004 QNX Software Systems and others. All rights
* All rights reserved. This program and the accompanying materials * reserved. This program and the accompanying materials are made available
* are made available under the terms of the Common Public License v1.0 * under the terms of the Common Public License v1.0 which accompanies this
* which accompanies this distribution, and is available at * distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html
* http://www.eclipse.org/legal/cpl-v10.html
* *
* Contributors: * Contributors: QNX Software Systems - Initial API and implementation
* QNX Software Systems - Initial API and implementation ******************************************************************************/
*******************************************************************************/
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.core.model.IPathEntry;
@ -26,21 +24,27 @@ public class PathEntry implements IPathEntry {
this.isExported = isExported; this.isExported = isExported;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.IPathEntry#getEntryKind() * @see org.eclipse.cdt.core.IPathEntry#getEntryKind()
*/ */
public IPath getPath() { public IPath getPath() {
return path; return path;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.IPathEntry#getEntryKind() * @see org.eclipse.cdt.core.IPathEntry#getEntryKind()
*/ */
public int getEntryKind() { public int getEntryKind() {
return entryKind; return entryKind;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.IPathEntry#isExported() * @see org.eclipse.cdt.core.IPathEntry#isExported()
*/ */
public boolean isExported() { public boolean isExported() {
@ -106,7 +110,7 @@ public class PathEntry implements IPathEntry {
return "mac"; //$NON-NLS-1$ return "mac"; //$NON-NLS-1$
case IPathEntry.CDT_CONTAINER : case IPathEntry.CDT_CONTAINER :
return "con"; //$NON-NLS-1$ return "con"; //$NON-NLS-1$
case IPathEntry.CDT_OUTPUT: case IPathEntry.CDT_OUTPUT :
return "out"; //$NON-NLS-1$ return "out"; //$NON-NLS-1$
default : default :
return "unknown"; //$NON-NLS-1$ return "unknown"; //$NON-NLS-1$
@ -122,31 +126,28 @@ public class PathEntry implements IPathEntry {
buffer.append(path.toString()).append(' '); buffer.append(path.toString()).append(' ');
} }
buffer.append('['); buffer.append('[');
switch (getEntryKind()) { buffer.append(getKindString());
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(']'); buffer.append(']');
return buffer.toString(); 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.Hashtable;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICExtensionReference; 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.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtension;
@ -76,25 +78,26 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
static String CONTAINER_INITIALIZER_EXTPOINT_ID = "PathEntryContainerInitializer"; //$NON-NLS-1$ 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]; static final String[] NO_PREREQUISITES = new String[0];
/** /**
* pathentry containers pool * pathentry containers pool accessing the Container is done synch with the
* accessing the Container is done synch with the class * class
*/ */
private static HashMap Containers = new HashMap(5); private static HashMap Containers = new HashMap(5);
static final IPathEntry[] NO_PATHENTRIES = new IPathEntry[0]; static final IPathEntry[] NO_PATHENTRIES = new IPathEntry[0];
// Synchronized the access of the cache entries. // 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 // Accessing the map is synch with the class
private Map storeMap = new HashMap(); private Map storeMap = new HashMap();
private static PathEntryManager pathEntryManager; private static PathEntryManager pathEntryManager;
private PathEntryManager() { private PathEntryManager() {
} }
private class PathEntryContainerLock implements IPathEntryContainer { private class PathEntryContainerLock implements IPathEntryContainer {
@ -109,21 +112,27 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
runInitializer = init; runInitializer = init;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.model.IPathEntryContainer#getPathEntries() * @see org.eclipse.cdt.core.model.IPathEntryContainer#getPathEntries()
*/ */
public IPathEntry[] getPathEntries() { public IPathEntry[] getPathEntries() {
return NO_PATHENTRIES; return NO_PATHENTRIES;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.model.IPathEntryContainer#getDescription() * @see org.eclipse.cdt.core.model.IPathEntryContainer#getDescription()
*/ */
public String getDescription() { public String getDescription() {
return new String("Lock container"); //$NON-NLS-1$ return new String("Lock container"); //$NON-NLS-1$
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.model.IPathEntryContainer#getPath() * @see org.eclipse.cdt.core.model.IPathEntryContainer#getPath()
*/ */
public IPath getPath() { public IPath getPath() {
@ -157,7 +166,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
IPathEntry entry = rawEntries[i]; IPathEntry entry = rawEntries[i];
// Expand the containers. // Expand the containers.
if (entry.getEntryKind() == IPathEntry.CDT_CONTAINER) { if (entry.getEntryKind() == IPathEntry.CDT_CONTAINER) {
IContainerEntry centry = (IContainerEntry) entry; IContainerEntry centry = (IContainerEntry)entry;
IPathEntryContainer container = getPathEntryContainer(centry, cproject); IPathEntryContainer container = getPathEntryContainer(centry, cproject);
if (container != null) { if (container != null) {
IPathEntry[] containerEntries = container.getPathEntries(); IPathEntry[] containerEntries = container.getPathEntries();
@ -201,8 +210,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
private IPathEntry getExpandedPathEntry(IPathEntry entry, ICProject cproject) throws CModelException { private IPathEntry getExpandedPathEntry(IPathEntry entry, ICProject cproject) throws CModelException {
switch(entry.getEntryKind()) { switch (entry.getEntryKind()) {
case IPathEntry.CDT_INCLUDE: { case IPathEntry.CDT_INCLUDE : {
IIncludeEntry includeEntry = (IIncludeEntry)entry; IIncludeEntry includeEntry = (IIncludeEntry)entry;
IPath refPath = includeEntry.getBaseReference(); IPath refPath = includeEntry.getBaseReference();
if (refPath != null && !refPath.isEmpty()) { if (refPath != null && !refPath.isEmpty()) {
@ -220,14 +229,18 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
IIncludeEntry refEntry = (IIncludeEntry)entries[i]; IIncludeEntry refEntry = (IIncludeEntry)entries[i];
if (refEntry.getIncludePath().equals(includePath)) { if (refEntry.getIncludePath().equals(includePath)) {
IPath newBasePath = refEntry.getBasePath(); 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()) { if (!newBasePath.isAbsolute() && !includePath.isAbsolute()) {
IResource refRes; IResource refRes;
if (!newBasePath.isEmpty()) { if (!newBasePath.isEmpty()) {
refRes = cproject.getCModel().getWorkspace().getRoot().findMember(newBasePath); refRes = cproject.getCModel().getWorkspace().getRoot().findMember(
newBasePath);
} else { } else {
IPath refResPath = refEntry.getPath(); IPath refResPath = refEntry.getPath();
refRes = cproject.getCModel().getWorkspace().getRoot().findMember(refResPath); refRes = cproject.getCModel().getWorkspace().getRoot().findMember(
refResPath);
} }
if (refRes != null) { if (refRes != null) {
if (refRes.getType() == IResource.FILE) { if (refRes.getType() == IResource.FILE) {
@ -236,8 +249,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
newBasePath = refRes.getLocation().append(newBasePath); newBasePath = refRes.getLocation().append(newBasePath);
} }
} }
return CoreModel.newIncludeEntry(includeEntry.getPath(), return CoreModel.newIncludeEntry(includeEntry.getPath(), newBasePath, includePath);
newBasePath, includePath);
} }
} }
} }
@ -263,7 +275,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
break; break;
} }
case IPathEntry.CDT_MACRO: { case IPathEntry.CDT_MACRO : {
IMacroEntry macroEntry = (IMacroEntry)entry; IMacroEntry macroEntry = (IMacroEntry)entry;
IPath refPath = macroEntry.getBaseReference(); IPath refPath = macroEntry.getBaseReference();
if (refPath != null && !refPath.isEmpty()) { if (refPath != null && !refPath.isEmpty()) {
@ -307,7 +319,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
break; break;
} }
case IPathEntry.CDT_LIBRARY: { case IPathEntry.CDT_LIBRARY : {
ILibraryEntry libEntry = (ILibraryEntry)entry; ILibraryEntry libEntry = (ILibraryEntry)entry;
IPath refPath = libEntry.getBaseReference(); IPath refPath = libEntry.getBaseReference();
if (refPath != null && !refPath.isEmpty()) { if (refPath != null && !refPath.isEmpty()) {
@ -325,14 +337,18 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
ILibraryEntry refEntry = (ILibraryEntry)entries[i]; ILibraryEntry refEntry = (ILibraryEntry)entries[i];
if (refEntry.getLibraryPath().equals(libraryPath)) { if (refEntry.getLibraryPath().equals(libraryPath)) {
IPath newBasePath = refEntry.getBasePath(); 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()) { if (!newBasePath.isAbsolute() && !libraryPath.isAbsolute()) {
IResource refRes; IResource refRes;
if (!newBasePath.isEmpty()) { if (!newBasePath.isEmpty()) {
refRes = cproject.getCModel().getWorkspace().getRoot().findMember(newBasePath); refRes = cproject.getCModel().getWorkspace().getRoot().findMember(
newBasePath);
} else { } else {
IPath refResPath = refEntry.getPath(); IPath refResPath = refEntry.getPath();
refRes = cproject.getCModel().getWorkspace().getRoot().findMember(refResPath); refRes = cproject.getCModel().getWorkspace().getRoot().findMember(
refResPath);
} }
if (refRes != null) { if (refRes != null) {
if (refRes.getType() == IResource.FILE) { if (refRes.getType() == IResource.FILE) {
@ -394,7 +410,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
public IPathEntry[] getRawPathEntries(ICProject cproject) throws CModelException { public IPathEntry[] getRawPathEntries(ICProject cproject) throws CModelException {
IProject project = cproject.getProject(); IProject project = cproject.getProject();
// Check if the Project is accesible. // Check if the Project is accesible.
if (!(CoreModel.hasCNature(project) || CoreModel.hasCCNature(project))) { if (! (CoreModel.hasCNature(project) || CoreModel.hasCCNature(project))) {
throw new CModelException(new CModelStatus(ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST)); throw new CModelException(new CModelStatus(ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST));
} }
IPathEntry[] pathEntries; IPathEntry[] pathEntries;
@ -457,7 +473,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
for (int j = 0, cpLength = rawPath.length; j < cpLength; j++) { for (int j = 0, cpLength = rawPath.length; j < cpLength; j++) {
IPathEntry entry = rawPath[j]; IPathEntry entry = rawPath[j];
if (entry.getEntryKind() == IPathEntry.CDT_CONTAINER) { if (entry.getEntryKind() == IPathEntry.CDT_CONTAINER) {
IContainerEntry cont = (IContainerEntry) entry; IContainerEntry cont = (IContainerEntry)entry;
if (cont.getPath().equals(containerPath)) { if (cont.getPath().equals(containerPath)) {
found = true; found = true;
break; break;
@ -465,7 +481,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
} }
if (!found) { 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; modifiedProjects[i] = null;
// Still add it to the cache // Still add it to the cache
containerPut(affectedProject, containerPath, newContainer); containerPut(affectedProject, containerPath, newContainer);
@ -478,9 +495,9 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
continue; continue;
} }
remaining++; remaining++;
ArrayList listEntries = (ArrayList) resolvedMap.remove(affectedProject); ArrayList listEntries = (ArrayList)resolvedMap.remove(affectedProject);
if (listEntries != null) { if (listEntries != null) {
oldResolvedEntries[i] = (IPathEntry[]) listEntries.toArray(NO_PATHENTRIES); oldResolvedEntries[i] = (IPathEntry[])listEntries.toArray(NO_PATHENTRIES);
} else { } else {
oldResolvedEntries[i] = null; oldResolvedEntries[i] = null;
} }
@ -492,8 +509,10 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
// trigger model refresh // trigger model refresh
try { try {
//final boolean canChangeResources = !ResourcesPlugin.getWorkspace().isTreeLocked(); //final boolean canChangeResources =
// !ResourcesPlugin.getWorkspace().isTreeLocked();
CoreModel.run(new IWorkspaceRunnable() { CoreModel.run(new IWorkspaceRunnable() {
public void run(IProgressMonitor progressMonitor) throws CoreException { public void run(IProgressMonitor progressMonitor) throws CoreException {
boolean shouldFire = false; boolean shouldFire = false;
@ -524,7 +543,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
} }
}, monitor); }, monitor);
} catch (CoreException e ) { } catch (CoreException e) {
// //
} }
} }
@ -539,13 +558,13 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
if (container instanceof PathEntryContainerLock) { if (container instanceof PathEntryContainerLock) {
boolean runInitializer = false; boolean runInitializer = false;
PathEntryContainerLock lock = (PathEntryContainerLock)container; PathEntryContainerLock lock = (PathEntryContainerLock)container;
synchronized(lock) { synchronized (lock) {
if (!lock.isContainerInitialize()) { if (!lock.isContainerInitialize()) {
runInitializer = true; runInitializer = true;
lock.setContainerInitialize(runInitializer); lock.setContainerInitialize(runInitializer);
} else { } else {
// Wait for the inialization to finish. // Wait for the inialization to finish.
while(containerGet(project, containerPath, true) instanceof PathEntryContainerLock) { while (containerGet(project, containerPath, true) instanceof PathEntryContainerLock) {
try { try {
lock.wait(); lock.wait();
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -566,7 +585,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
public void handleException(Throwable exception) { public void handleException(Throwable exception) {
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR, IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR,
"Exception occurred in container initializer: "+initializer, exception); //$NON-NLS-1$ "Exception occurred in container initializer: " + initializer, exception); //$NON-NLS-1$
CCorePlugin.log(status); CCorePlugin.log(status);
} }
@ -577,7 +596,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}); });
} }
if (!ok[0]) { if (!ok[0]) {
containerPut(project, containerPath, null); // flush and notify containerPut(project, containerPath, null); // flush and
// notify
} }
} }
// retrieve new value // 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 * Helper method finding the container initializer registered for a given
* while iterating over the contributions to extension point to the extension point * 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". * "org.eclipse.cdt.core.PathEntryContainerInitializer".
* <p> * <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> * <p>
* *
* @param containerID - * @param containerID -
* a containerID identifying a registered initializer * 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) { public PathEntryContainerInitializer getPathEntryContainerInitializer(String containerID) {
Plugin core = CCorePlugin.getDefault(); Plugin core = CCorePlugin.getDefault();
if (core == null) { if (core == null) {
return 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) { if (extension != null) {
IExtension[] extensions = extension.getExtensions(); IExtension[] extensions = extension.getExtensions();
for (int i = 0; i < extensions.length; i++) { for (int i = 0; i < extensions.length; i++) {
@ -614,7 +638,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
try { try {
Object execExt = configElements[j].createExecutableExtension("class"); //$NON-NLS-1$ Object execExt = configElements[j].createExecutableExtension("class"); //$NON-NLS-1$
if (execExt instanceof PathEntryContainerInitializer) { if (execExt instanceof PathEntryContainerInitializer) {
return (PathEntryContainerInitializer) execExt; return (PathEntryContainerInitializer)execExt;
} }
} catch (CoreException e) { } catch (CoreException e) {
// executable extension could not be created: // executable extension could not be created:
@ -629,14 +653,14 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
private synchronized IPathEntryContainer containerGet(ICProject cproject, IPath containerPath, boolean bCreateLock) { private synchronized IPathEntryContainer containerGet(ICProject cproject, IPath containerPath, boolean bCreateLock) {
Map projectContainers = (Map) Containers.get(cproject); Map projectContainers = (Map)Containers.get(cproject);
if (projectContainers == null) { if (projectContainers == null) {
projectContainers = new HashMap(); projectContainers = new HashMap();
Containers.put(cproject, projectContainers); Containers.put(cproject, projectContainers);
} }
IPathEntryContainer container = (IPathEntryContainer) projectContainers.get(containerPath); IPathEntryContainer container = (IPathEntryContainer)projectContainers.get(containerPath);
// Initialize the first time with a lock // Initialize the first time with a lock
if (bCreateLock && container == null ) { if (bCreateLock && container == null) {
container = new PathEntryContainerLock(); container = new PathEntryContainerLock();
projectContainers.put(containerPath, container); projectContainers.put(containerPath, container);
} }
@ -644,16 +668,16 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
private synchronized void containerPut(ICProject cproject, IPath containerPath, IPathEntryContainer container) { private synchronized void containerPut(ICProject cproject, IPath containerPath, IPathEntryContainer container) {
Map projectContainers = (Map) Containers.get(cproject); Map projectContainers = (Map)Containers.get(cproject);
if (projectContainers == null) { if (projectContainers == null) {
projectContainers = new HashMap(); projectContainers = new HashMap();
Containers.put(cproject, projectContainers); Containers.put(cproject, projectContainers);
} }
IPathEntryContainer oldContainer; IPathEntryContainer oldContainer;
if (container == null) { if (container == null) {
oldContainer = (IPathEntryContainer)projectContainers.remove(containerPath); oldContainer = (IPathEntryContainer)projectContainers.remove(containerPath);
} else { } else {
oldContainer = (IPathEntryContainer)projectContainers.put(containerPath, container); oldContainer = (IPathEntryContainer)projectContainers.put(containerPath, container);
} }
if (oldContainer instanceof PathEntryContainerLock) { if (oldContainer instanceof PathEntryContainerLock) {
synchronized (oldContainer) { synchronized (oldContainer) {
@ -671,7 +695,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
ArrayList prerequisites = new ArrayList(); ArrayList prerequisites = new ArrayList();
for (int i = 0, length = entries.length; i < length; i++) { for (int i = 0, length = entries.length; i < length; i++) {
if (entries[i].getEntryKind() == IPathEntry.CDT_PROJECT) { if (entries[i].getEntryKind() == IPathEntry.CDT_PROJECT) {
IProjectEntry entry = (IProjectEntry) entries[i]; IProjectEntry entry = (IProjectEntry)entries[i];
prerequisites.add(entry.getPath().lastSegment()); prerequisites.add(entry.getPath().lastSegment());
} }
} }
@ -706,7 +730,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
// Do not do this for container, the path is the ID. // Do not do this for container, the path is the ID.
if (kind != IPathEntry.CDT_CONTAINER) { 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 (resourcePath.isAbsolute()) {
if (projectPath != null && projectPath.isPrefixOf(resourcePath)) { if (projectPath != null && projectPath.isPrefixOf(resourcePath)) {
if (resourcePath.segment(0).equals(projectPath.segment(0))) { if (resourcePath.segment(0).equals(projectPath.segment(0))) {
@ -720,19 +745,19 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
// Specifics to the entries // Specifics to the entries
switch(kind) { switch (kind) {
case IPathEntry.CDT_INCLUDE: { case IPathEntry.CDT_INCLUDE : {
IIncludeEntry include = (IIncludeEntry)entries[i]; IIncludeEntry include = (IIncludeEntry)entries[i];
IPath baseRef = include.getBaseReference(); IPath baseRef = include.getBaseReference();
if (baseRef == null || baseRef.isEmpty()) { if (baseRef == null || baseRef.isEmpty()) {
entry = CoreModel.newIncludeEntry(resourcePath, include.getBasePath(), include.getIncludePath(), entry = CoreModel.newIncludeEntry(resourcePath, include.getBasePath(), include.getIncludePath(),
include.isSystemInclude(), include.getExclusionPatterns(), include.isExported()); include.isSystemInclude(), include.getExclusionPatterns(), include.isExported());
} else { } else {
entry = CoreModel.newIncludeRefEntry(resourcePath, baseRef, include.getIncludePath()); entry = CoreModel.newIncludeRefEntry(resourcePath, baseRef, include.getIncludePath());
} }
break; break;
} }
case IPathEntry.CDT_LIBRARY: { case IPathEntry.CDT_LIBRARY : {
ILibraryEntry library = (ILibraryEntry)entries[i]; ILibraryEntry library = (ILibraryEntry)entries[i];
IPath sourcePath = library.getSourceAttachmentPath(); IPath sourcePath = library.getSourceAttachmentPath();
if (sourcePath != null) { if (sourcePath != null) {
@ -746,15 +771,15 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
IPath baseRef = library.getBaseReference(); IPath baseRef = library.getBaseReference();
if (baseRef == null || baseRef.isEmpty()) { if (baseRef == null || baseRef.isEmpty()) {
entry = CoreModel.newLibraryEntry(resourcePath, library.getBasePath(), entry = CoreModel.newLibraryEntry(resourcePath, library.getBasePath(), library.getLibraryPath(),
library.getLibraryPath(), sourcePath, library.getSourceAttachmentRootPath(), sourcePath, library.getSourceAttachmentRootPath(), library.getSourceAttachmentPrefixMapping(),
library.getSourceAttachmentPrefixMapping(), library.isExported()); library.isExported());
} else { } else {
entry = CoreModel.newLibraryRefEntry(resourcePath, baseRef, library.getLibraryPath()); entry = CoreModel.newLibraryRefEntry(resourcePath, baseRef, library.getLibraryPath());
} }
break; break;
} }
case IPathEntry.CDT_MACRO: { case IPathEntry.CDT_MACRO : {
IMacroEntry macro = (IMacroEntry)entries[i]; IMacroEntry macro = (IMacroEntry)entries[i];
IPath baseRef = macro.getBaseReference(); IPath baseRef = macro.getBaseReference();
if (baseRef == null || baseRef.isEmpty()) { if (baseRef == null || baseRef.isEmpty()) {
@ -765,25 +790,25 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
break; break;
} }
case IPathEntry.CDT_OUTPUT: { case IPathEntry.CDT_OUTPUT : {
IOutputEntry out = (IOutputEntry)entries[i]; IOutputEntry out = (IOutputEntry)entries[i];
entry = CoreModel.newOutputEntry(resourcePath, out.getExclusionPatterns()); entry = CoreModel.newOutputEntry(resourcePath, out.getExclusionPatterns());
break; break;
} }
case IPathEntry.CDT_PROJECT: { case IPathEntry.CDT_PROJECT : {
IProjectEntry projEntry = (IProjectEntry)entries[i]; IProjectEntry projEntry = (IProjectEntry)entries[i];
entry = CoreModel.newProjectEntry(projEntry.getPath(), projEntry.isExported()); entry = CoreModel.newProjectEntry(projEntry.getPath(), projEntry.isExported());
break; break;
} }
case IPathEntry.CDT_SOURCE: { case IPathEntry.CDT_SOURCE : {
ISourceEntry source = (ISourceEntry)entries[i]; ISourceEntry source = (ISourceEntry)entries[i];
entry = CoreModel.newSourceEntry(resourcePath, source.getExclusionPatterns()); entry = CoreModel.newSourceEntry(resourcePath, source.getExclusionPatterns());
break; break;
} }
case IPathEntry.CDT_CONTAINER: case IPathEntry.CDT_CONTAINER :
entry = CoreModel.newContainerEntry(entries[i].getPath(), entries[i].isExported()); entry = CoreModel.newContainerEntry(entries[i].getPath(), entries[i].isExported());
break; break;
default: default :
entry = entries[i]; entry = entries[i];
} }
list.add(entry); list.add(entry);
@ -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$ 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) * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/ */
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
IProject project = finalCProject.getProject(); IProject project = cProject.getProject();
flushPathEntryProblemMarkers(project); 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);
if (!status.isOK()) { if (!status.isOK()) {
createPathEntryProblemMarker(project, status); createPathEntryProblemMarker(project, status);
} }
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; return Status.OK_STATUS;
} }
}; };
markerTask.setRule(CCorePlugin.getWorkspace().getRoot());
markerTask.schedule(); markerTask.schedule();
} }
@ -899,39 +966,39 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} else { } else {
int kind = entry.getEntryKind(); int kind = entry.getEntryKind();
switch (kind) { switch (kind) {
case IPathEntry.CDT_SOURCE: { case IPathEntry.CDT_SOURCE : {
ISourceEntry source = (ISourceEntry) entry; ISourceEntry source = (ISourceEntry)entry;
IPath path = source.getPath(); IPath path = source.getPath();
celement = CoreModel.getDefault().create(path); celement = CoreModel.getDefault().create(path);
flag = (removed) ? ICElementDelta.F_REMOVED_PATHENTRY_SOURCE : ICElementDelta.F_ADDED_PATHENTRY_SOURCE; flag = (removed) ? ICElementDelta.F_REMOVED_PATHENTRY_SOURCE : ICElementDelta.F_ADDED_PATHENTRY_SOURCE;
break; break;
} }
case IPathEntry.CDT_LIBRARY: { case IPathEntry.CDT_LIBRARY : {
celement = cproject; celement = cproject;
flag = (removed) ? ICElementDelta.F_REMOVED_PATHENTRY_LIBRARY : ICElementDelta.F_ADDED_PATHENTRY_LIBRARY; flag = (removed) ? ICElementDelta.F_REMOVED_PATHENTRY_LIBRARY : ICElementDelta.F_ADDED_PATHENTRY_LIBRARY;
break; break;
} }
case IPathEntry.CDT_PROJECT: { case IPathEntry.CDT_PROJECT : {
//IProjectEntry pentry = (IProjectEntry) entry; //IProjectEntry pentry = (IProjectEntry) entry;
celement = cproject; celement = cproject;
flag = ICElementDelta.F_CHANGED_PATHENTRY_PROJECT; flag = ICElementDelta.F_CHANGED_PATHENTRY_PROJECT;
break; break;
} }
case IPathEntry.CDT_INCLUDE: { case IPathEntry.CDT_INCLUDE : {
IIncludeEntry include = (IIncludeEntry) entry; IIncludeEntry include = (IIncludeEntry)entry;
IPath path = include.getPath(); IPath path = include.getPath();
celement = CoreModel.getDefault().create(path); celement = CoreModel.getDefault().create(path);
flag = ICElementDelta.F_CHANGED_PATHENTRY_INCLUDE; flag = ICElementDelta.F_CHANGED_PATHENTRY_INCLUDE;
break; break;
} }
case IPathEntry.CDT_MACRO: { case IPathEntry.CDT_MACRO : {
IMacroEntry macro = (IMacroEntry) entry; IMacroEntry macro = (IMacroEntry)entry;
IPath path = macro.getPath(); IPath path = macro.getPath();
celement = CoreModel.getDefault().create(path); celement = CoreModel.getDefault().create(path);
flag = ICElementDelta.F_CHANGED_PATHENTRY_MACRO; flag = ICElementDelta.F_CHANGED_PATHENTRY_MACRO;
break; break;
} }
case IPathEntry.CDT_CONTAINER: { case IPathEntry.CDT_CONTAINER : {
//IContainerEntry container = (IContainerEntry) entry; //IContainerEntry container = (IContainerEntry) entry;
//celement = cproject; //celement = cproject;
//SHOULD NOT BE HERE Container are resolved. //SHOULD NOT BE HERE Container are resolved.
@ -953,7 +1020,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return null; return null;
} }
ArrayList containerIDList = new ArrayList(5); 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) { if (extension != null) {
IExtension[] extensions = extension.getExtensions(); IExtension[] extensions = extension.getExtensions();
for (int i = 0; i < extensions.length; i++) { for (int i = 0; i < extensions.length; i++) {
@ -972,7 +1040,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
public void setPathEntryStore(IProject project, IPathEntryStore newStore) { public void setPathEntryStore(IProject project, IPathEntryStore newStore) {
IPathEntryStore oldStore = null; IPathEntryStore oldStore = null;
synchronized(this) { synchronized (this) {
oldStore = (IPathEntryStore)storeMap.remove(project); oldStore = (IPathEntryStore)storeMap.remove(project);
if (newStore != null) { if (newStore != null) {
storeMap.put(project, newStore); storeMap.put(project, newStore);
@ -1005,7 +1073,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
if (cextensions.length > 0) { if (cextensions.length > 0) {
for (int i = 0; i < cextensions.length; i++) { for (int i = 0; i < cextensions.length; i++) {
try { try {
store = (IPathEntryStore) cextensions[i].createExtension(); store = (IPathEntryStore)cextensions[i].createExtension();
break; break;
} catch (ClassCastException e) { } catch (ClassCastException e) {
// //
@ -1024,7 +1092,9 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return store; return store;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.resources.IPathEntryStoreListener#pathEntryStoreChanged(org.eclipse.cdt.core.resources.PathEntryChangedEvent) * @see org.eclipse.cdt.core.resources.IPathEntryStoreListener#pathEntryStoreChanged(org.eclipse.cdt.core.resources.PathEntryChangedEvent)
*/ */
public void pathEntryStoreChanged(PathEntryStoreChangedEvent event) { public void pathEntryStoreChanged(PathEntryStoreChangedEvent event) {
@ -1045,7 +1115,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
try { try {
// Clear the old cache entries. // Clear the old cache entries.
IPathEntry[] oldResolvedEntries = null; IPathEntry[] oldResolvedEntries = null;
ArrayList listEntries = (ArrayList) resolvedMap.remove(cproject); ArrayList listEntries = (ArrayList)resolvedMap.remove(cproject);
if (listEntries != null) { if (listEntries != null) {
oldResolvedEntries = (IPathEntry[])listEntries.toArray(NO_PATHENTRIES); oldResolvedEntries = (IPathEntry[])listEntries.toArray(NO_PATHENTRIES);
} }
@ -1067,60 +1137,60 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.model.IElementChangedListener#elementChanged(org.eclipse.cdt.core.model.ElementChangedEvent) * @see org.eclipse.cdt.core.model.IElementChangedListener#elementChanged(org.eclipse.cdt.core.model.ElementChangedEvent)
*/ */
public void elementChanged(ElementChangedEvent event) { public void elementChanged(ElementChangedEvent event) {
try { try {
processDelta(event.getDelta()); if (processDelta(event.getDelta()) == true) {
} catch(CModelException e) { 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 kind = delta.getKind();
int flags= delta.getFlags(); ICElement element = delta.getElement();
ICElement element= delta.getElement(); int type = element.getElementType();
//System.out.println("Processing " + element); // handle open, closing and removing of projects
if ( type == ICElement.C_PROJECT) {
// handle closing and removing of projects ICProject cproject = (ICProject)element;
if (((flags & ICElementDelta.F_CLOSED) != 0) || (kind == ICElementDelta.REMOVED)) { if ((kind == ICElementDelta.REMOVED || kind == ICElementDelta.ADDED)) {
if (element.getElementType() == ICElement.C_PROJECT) { if (kind == ICElementDelta.REMOVED) {
ICProject cproject = (ICProject)element; IProject project = cproject.getProject();
IProject project = cproject.getProject(); IPathEntryStore store = null;
IPathEntryStore store = null; try {
try { store = getPathEntryStore(project, false);
store = getPathEntryStore(project, false); if (store != null) {
if (store != null) { store.close();
store.close(); }
} } catch (CoreException e) {
} catch (CoreException e) { throw new CModelException(e);
throw new CModelException(e); } finally {
} finally { if (store == null) {
if (store == null) { resolvedMap.remove(cproject);
resolvedMap.remove(cproject); containerRemove(cproject);
containerRemove(cproject); }
} }
} }
return; return true;
} }
} else if (kind == ICElementDelta.CHANGED) { // project change, traverse children.
// We should update the pathentry markers if the project change. } else if (kind == ICElementDelta.ADDED || kind == ICElementDelta.REMOVED) {
if (element.getElementType() == ICElement.C_PROJECT) { return true; // add/remove we validate all paths
ICProject cproject = (ICProject)element; }
ArrayList resolvedList = (ArrayList)resolvedMap.get(cproject); ICElementDelta[] affectedChildren = delta.getAffectedChildren();
if (resolvedList != null) { for (int i = 0; i < affectedChildren.length; i++) {
IPathEntry[] entries = (IPathEntry[]) resolvedList.toArray(new IPathEntry[resolvedList.size()]); if (processDelta(affectedChildren[i]) == true) {
generateMarkers(cproject, entries); return true;
}
return;
} }
} }
ICElementDelta[] affectedChildren= delta.getAffectedChildren(); return false;
for (int i= 0; i < affectedChildren.length; i++) {
processDelta(affectedChildren[i]);
}
} }
protected IPathEntry cloneEntry(IPath rpath, IPathEntry entry) { protected IPathEntry cloneEntry(IPath rpath, IPathEntry entry) {
@ -1132,36 +1202,36 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
IPath resourcePath = (entryPath.isAbsolute()) ? entryPath : rpath.append(entryPath); 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;
return CoreModel.newIncludeEntry(resourcePath, include.getBasePath(), include.getIncludePath(), return CoreModel.newIncludeEntry(resourcePath, include.getBasePath(), include.getIncludePath(),
include.isSystemInclude(), include.getExclusionPatterns(), include.isExported()); include.isSystemInclude(), include.getExclusionPatterns(), include.isExported());
} }
case IPathEntry.CDT_LIBRARY: { case IPathEntry.CDT_LIBRARY : {
ILibraryEntry library = (ILibraryEntry)entry; ILibraryEntry library = (ILibraryEntry)entry;
return CoreModel.newLibraryEntry(resourcePath, library.getBasePath(), library.getLibraryPath(), return CoreModel.newLibraryEntry(resourcePath, library.getBasePath(), library.getLibraryPath(),
library.getSourceAttachmentPath(), library.getSourceAttachmentRootPath(), library.getSourceAttachmentPath(), library.getSourceAttachmentRootPath(),
library.getSourceAttachmentPrefixMapping(), library.isExported()); library.getSourceAttachmentPrefixMapping(), library.isExported());
} }
case IPathEntry.CDT_MACRO: { case IPathEntry.CDT_MACRO : {
IMacroEntry macro = (IMacroEntry)entry; IMacroEntry macro = (IMacroEntry)entry;
return CoreModel.newMacroEntry(resourcePath, macro.getMacroName(), macro.getMacroValue(), return CoreModel.newMacroEntry(resourcePath, macro.getMacroName(), macro.getMacroValue(),
macro.getExclusionPatterns(), macro.isExported()); macro.getExclusionPatterns(), macro.isExported());
} }
case IPathEntry.CDT_OUTPUT: { case IPathEntry.CDT_OUTPUT : {
IOutputEntry out = (IOutputEntry)entry; IOutputEntry out = (IOutputEntry)entry;
return CoreModel.newOutputEntry(resourcePath, out.getExclusionPatterns()); return CoreModel.newOutputEntry(resourcePath, out.getExclusionPatterns());
} }
case IPathEntry.CDT_PROJECT: { case IPathEntry.CDT_PROJECT : {
IProjectEntry projEntry = (IProjectEntry)entry; IProjectEntry projEntry = (IProjectEntry)entry;
return CoreModel.newProjectEntry(projEntry.getPath(), projEntry.isExported()); return CoreModel.newProjectEntry(projEntry.getPath(), projEntry.isExported());
} }
case IPathEntry.CDT_SOURCE: { case IPathEntry.CDT_SOURCE : {
ISourceEntry source = (ISourceEntry)entry; ISourceEntry source = (ISourceEntry)entry;
return CoreModel.newSourceEntry(resourcePath, source.getExclusionPatterns()); return CoreModel.newSourceEntry(resourcePath, source.getExclusionPatterns());
} }
case IPathEntry.CDT_CONTAINER: case IPathEntry.CDT_CONTAINER :
return CoreModel.newContainerEntry(entry.getPath(), entry.isExported()); return CoreModel.newContainerEntry(entry.getPath(), entry.isExported());
} }
return entry; return entry;
@ -1182,7 +1252,6 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
if (entry != otherEntry && otherEntry.equals(entry)) { if (entry != otherEntry && otherEntry.equals(entry)) {
StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.DuplicateEntry")); //$NON-NLS-1$ 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()); return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString());
} }
} }
@ -1194,7 +1263,6 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
ICModelStatus[] cmodelStatus = new ICModelStatus[dups.size()]; ICModelStatus[] cmodelStatus = new ICModelStatus[dups.size()];
for (int i = 0; i < dups.size(); ++i) { for (int i = 0; i < dups.size(); ++i) {
StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.DuplicateEntry")); //$NON-NLS-1$ 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()); cmodelStatus[i] = new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString());
} }
return CModelStatus.newMultiStatus(ICModelStatusConstants.INVALID_PATHENTRY, cmodelStatus); return CModelStatus.newMultiStatus(ICModelStatusConstants.INVALID_PATHENTRY, cmodelStatus);
@ -1206,13 +1274,13 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
ICModelStatus[] cmodelStatus = new ICModelStatus[dups.size()]; ICModelStatus[] cmodelStatus = new ICModelStatus[dups.size()];
for (int i = 0; i < dups.size(); ++i) { for (int i = 0; i < dups.size(); ++i) {
StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.DuplicateEntry")); //$NON-NLS-1$ 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()); cmodelStatus[i] = new CModelStatus(ICModelStatusConstants.NAME_COLLISION, errMesg.toString());
} }
return CModelStatus.newMultiStatus(ICModelStatusConstants.INVALID_PATHENTRY, cmodelStatus); 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++) { for (int i = 0; i < entries.length; i++) {
IPathEntry entry = entries[i]; IPathEntry entry = entries[i];
if (entry == null) { if (entry == null) {
@ -1220,8 +1288,8 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
IPath entryPath = entry.getPath(); IPath entryPath = entry.getPath();
int kind = entry.getEntryKind(); int kind = entry.getEntryKind();
if (kind == IPathEntry.CDT_SOURCE){ if (kind == IPathEntry.CDT_SOURCE) {
for (int j = 0; j < entries.length; j++){ for (int j = 0; j < entries.length; j++) {
IPathEntry otherEntry = entries[j]; IPathEntry otherEntry = entries[j];
if (otherEntry == null) { if (otherEntry == null) {
continue; continue;
@ -1235,17 +1303,17 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
String exclusionPattern = entryPath.removeFirstSegments(otherPath.segmentCount()).segment(0); String exclusionPattern = entryPath.removeFirstSegments(otherPath.segmentCount()).segment(0);
if (CoreModelUtil.isExcluded(entryPath, exclusionPatterns)) { if (CoreModelUtil.isExcluded(entryPath, exclusionPatterns)) {
StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$ StringBuffer errMesg = new StringBuffer(
errMesg.append(':').append(entry.toString()); CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString()); return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString());
} else if (otherKind == IPathEntry.CDT_SOURCE) { } else if (otherKind == IPathEntry.CDT_SOURCE) {
exclusionPattern += '/'; exclusionPattern += '/';
StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$ StringBuffer errMesg = new StringBuffer(
errMesg.append(':').append(entry.toString()); CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString()); return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString());
} else { } else {
StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$ StringBuffer errMesg = new StringBuffer(
errMesg.append(':').append(entry.toString()); CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString()); //$NON-NLS-1$ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString()); //$NON-NLS-1$
} }
} }
@ -1257,90 +1325,71 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return CModelStatus.VERIFIED_OK; 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(); IProject project = cProject.getProject();
StringBuffer sb = new StringBuffer(); IPath path = entry.getPath();
sb.append(CCorePlugin.getResourceString("CoreModel.PathEntry.InvalidPathEntry")); //$NON-NLS-1$ if (entry.getEntryKind() != IPathEntry.CDT_PROJECT) {
sb.append(':').append(entry.toString()); if (!isValidWorkspacePath(project, path)) {
String entryMesg = sb.toString(); return new CModelStatus(
switch(entry.getEntryKind()) { ICModelStatusConstants.INVALID_PATHENTRY,
case IPathEntry.CDT_INCLUDE: { 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; 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(); IPath includePath = include.getFullIncludePath();
if (!isValidExternalPath(includePath)) { 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; break;
} }
case IPathEntry.CDT_LIBRARY: { case IPathEntry.CDT_LIBRARY : {
ILibraryEntry library = (ILibraryEntry)entry; ILibraryEntry library = (ILibraryEntry)entry;
IPath path = library.getPath();
if (!isValidWorkspacePath(project, path)) {
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$
}
if (checkSourceAttachment) { if (checkSourceAttachment) {
IPath sourceAttach = library.getSourceAttachmentPath(); IPath sourceAttach = library.getSourceAttachmentPath();
if (sourceAttach != null) { if (sourceAttach != null) {
if(!sourceAttach.isAbsolute()) { if (!sourceAttach.isAbsolute()) {
if (!isValidWorkspacePath(project, sourceAttach)) { if (!isValidWorkspacePath(project, sourceAttach) || !isValidExternalPath(sourceAttach)) {
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); 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(); IPath libraryPath = library.getFullLibraryPath();
if (!isValidExternalPath(libraryPath)) { 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$
}
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; break;
} }
case IPathEntry.CDT_MACRO: { case IPathEntry.CDT_PROJECT : {
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; IProjectEntry projEntry = (IProjectEntry)entry;
IPath path = projEntry.getPath(); path = projEntry.getPath();
if (path != null && path.isAbsolute() && !path.isEmpty()) { IProject reqProject = project.getWorkspace().getRoot().getProject(path.segment(0));
IProject reqProject = project.getWorkspace().getRoot().getProject(path.segment(0)); if (!reqProject.isAccessible()) {
if (!reqProject.exists() || !(CoreModel.hasCNature(reqProject) || CoreModel.hasCCNature(reqProject))) { return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY,
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$ CoreModelMessages.getString("PathEntryManager.5")); //$NON-NLS-1$
} }
if (!reqProject.isOpen()){ if (! (CoreModel.hasCNature(reqProject) || CoreModel.hasCCNature(reqProject))) {
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY,
} CoreModelMessages.getString("PathEntryManager.6")); //$NON-NLS-1$
} else {
return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$
} }
break; break;
} }
case IPathEntry.CDT_SOURCE: { case IPathEntry.CDT_CONTAINER :
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:
if (recurseInContainers) { if (recurseInContainers) {
try { try {
IPathEntryContainer cont = getPathEntryContainer((IContainerEntry)entry, cProject); IPathEntryContainer cont = getPathEntryContainer((IContainerEntry)entry, cProject);
@ -1385,6 +1434,16 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return false; 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) { private List checkForDuplication(List pathEntries, int type) {
List duplicate = new ArrayList(pathEntries.size()); List duplicate = new ArrayList(pathEntries.size());
for (int i = 0; i < pathEntries.size(); ++i) { for (int i = 0; i < pathEntries.size(); ++i) {
@ -1416,35 +1475,25 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
IMarker marker = null; IMarker marker = null;
int severity; int severity;
switch (status.getCode()) { switch (status.getCode()) {
case ICModelStatusConstants.INVALID_PATHENTRY : case ICModelStatusConstants.INVALID_PATHENTRY :
severity = IMarker.SEVERITY_WARNING; severity = IMarker.SEVERITY_WARNING;
break; break;
case ICModelStatusConstants.INVALID_PATH: case ICModelStatusConstants.INVALID_PATH :
severity = IMarker.SEVERITY_WARNING; severity = IMarker.SEVERITY_WARNING;
break; break;
default: default :
severity = IMarker.SEVERITY_ERROR; severity = IMarker.SEVERITY_ERROR;
break; break;
} }
try { try {
marker = project.createMarker(ICModelMarker.PATHENTRY_PROBLEM_MARKER); marker = project.createMarker(ICModelMarker.PATHENTRY_PROBLEM_MARKER);
marker.setAttributes( marker.setAttributes(new String[]{IMarker.MESSAGE, IMarker.SEVERITY, IMarker.LOCATION,
new String[] { ICModelMarker.PATHENTRY_FILE_FORMAT,}, new Object[]{status.getMessage(), new Integer(severity), "pathentry",//$NON-NLS-1$
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$ "false",//$NON-NLS-1$
} });
);
} catch (CoreException e) { } catch (CoreException e) {
// could not create marker: cannot do much // could not create marker: cannot do much
//e.printStackTrace(); //e.printStackTrace();
@ -1470,6 +1519,4 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
} }
} }