mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-13 19:25:38 +02:00
Bug 280262 NPE in editors in closed projects => user friendly error message
createProjectDescription throws a CoreException as defined by the API rather than returning null when the project is inaccessible.
This commit is contained in:
parent
e1c516fe2c
commit
25b266f275
4 changed files with 59 additions and 15 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007 Intel Corporation and others.
|
* Copyright (c) 2007, 2010 Intel Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -127,6 +127,28 @@ public class CProjectDescriptionBasicTests extends BaseTestCase{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCreateProjectDescriptionInvalidProject() throws Exception {
|
||||||
|
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("someProject");
|
||||||
|
assertTrue(!project.isAccessible());
|
||||||
|
|
||||||
|
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
|
||||||
|
boolean exception = false;
|
||||||
|
try {
|
||||||
|
mngr.createProjectDescription(null, false, true);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
exception = true;
|
||||||
|
}
|
||||||
|
assertTrue(exception);
|
||||||
|
|
||||||
|
exception = false;
|
||||||
|
try {
|
||||||
|
mngr.createProjectDescription(project, false, true);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
exception = true;
|
||||||
|
}
|
||||||
|
assertTrue(exception);
|
||||||
|
}
|
||||||
|
|
||||||
public void testSetInvalidCreatingDescription() throws Exception {
|
public void testSetInvalidCreatingDescription() throws Exception {
|
||||||
IWorkspace wsp = ResourcesPlugin.getWorkspace();
|
IWorkspace wsp = ResourcesPlugin.getWorkspace();
|
||||||
IWorkspaceRoot root = wsp.getRoot();
|
IWorkspaceRoot root = wsp.getRoot();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007, 2008 Intel Corporation and others.
|
* Copyright (c) 2007, 2010 Intel Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -73,6 +73,7 @@ public interface ICProjectDescriptionManager {
|
||||||
* and returns a writable project description which is either empty or a copy of the previous configuration description
|
* and returns a writable project description which is either empty or a copy of the previous configuration description
|
||||||
* if loadIfExists == true.
|
* if loadIfExists == true.
|
||||||
* @see #createProjectDescription(IProject, boolean, boolean)
|
* @see #createProjectDescription(IProject, boolean, boolean)
|
||||||
|
* @throws CoreException if the Project doesn't exist, or the storage couldn't be found
|
||||||
*/
|
*/
|
||||||
ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists) throws CoreException;
|
ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists) throws CoreException;
|
||||||
|
|
||||||
|
@ -89,7 +90,7 @@ public interface ICProjectDescriptionManager {
|
||||||
*
|
*
|
||||||
* NOTE: changes made to the returned project description will not be applied until the {@link #setProjectDescription(IProject, ICProjectDescription)} is called
|
* NOTE: changes made to the returned project description will not be applied until the {@link #setProjectDescription(IProject, ICProjectDescription)} is called
|
||||||
* @return {@link ICProjectDescription}
|
* @return {@link ICProjectDescription}
|
||||||
* @throws CoreException
|
* @throws CoreException if the Project doesn't exist, or the storage couldn't be found
|
||||||
*/
|
*/
|
||||||
ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists, boolean creating) throws CoreException;
|
ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists, boolean creating) throws CoreException;
|
||||||
|
|
||||||
|
|
|
@ -390,19 +390,28 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICProjectDescription getProjectDescription(IProject project, int flags) {
|
public ICProjectDescription getProjectDescription(IProject project, int flags) {
|
||||||
AbstractCProjectDescriptionStorage storage = getProjectDescriptionStorage(project);
|
try {
|
||||||
if (storage != null) {
|
return getProjectDescriptionInternal(project, flags);
|
||||||
try {
|
} catch (CoreException e) {
|
||||||
return storage.getProjectDescription(flags, new NullProgressMonitor());
|
// FIXME Currently the resource change handler ResourceChangeHandler.getProjectDescription(...)
|
||||||
} catch (CoreException e) {
|
// Does this when the project is closed. Don't log an error or the tests will fail
|
||||||
// FIXME Currently the resource change handler ResourceChangeHandler.getProjectDescription(...)
|
|
||||||
// Does this when the project is closed. Don't log an error or the tests will fail
|
|
||||||
// CCorePlugin.log(e);
|
// CCorePlugin.log(e);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base method for getting a Project's Description
|
||||||
|
* @param project
|
||||||
|
* @param flags
|
||||||
|
* @return ICProjectDescription
|
||||||
|
* @throws CoreException if project description isn't available
|
||||||
|
*/
|
||||||
|
private ICProjectDescription getProjectDescriptionInternal(IProject project, int flags) throws CoreException {
|
||||||
|
AbstractCProjectDescriptionStorage storage = getProjectDescriptionStorage(project);
|
||||||
|
return storage.getProjectDescription(flags, new NullProgressMonitor());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the workspace modification in the current thread using the workspace scheduling rule
|
* Run the workspace modification in the current thread using the workspace scheduling rule
|
||||||
* Equivalent to: <code>runWspModification(IWorkspaceRunnable, ResourcecPlugin.getWorkspace().getRoot(), IProgressMonitor)</code>
|
* Equivalent to: <code>runWspModification(IWorkspaceRunnable, ResourcecPlugin.getWorkspace().getRoot(), IProgressMonitor)</code>
|
||||||
|
@ -587,7 +596,7 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
|
||||||
flags |= loadIfExists ? 0 : ICProjectDescriptionManager.GET_EMPTY_PROJECT_DESCRIPTION;
|
flags |= loadIfExists ? 0 : ICProjectDescriptionManager.GET_EMPTY_PROJECT_DESCRIPTION;
|
||||||
flags |= creating ? ICProjectDescriptionManager.PROJECT_CREATING : 0;
|
flags |= creating ? ICProjectDescriptionManager.PROJECT_CREATING : 0;
|
||||||
|
|
||||||
return getProjectDescription(project, flags);
|
return getProjectDescriptionInternal(project, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScannerInfoProviderProxy getScannerInfoProviderProxy(IProject project){
|
public ScannerInfoProviderProxy getScannerInfoProviderProxy(IProject project){
|
||||||
|
@ -816,8 +825,19 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
|
||||||
return settingProjectDescription.get();
|
return settingProjectDescription.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private AbstractCProjectDescriptionStorage getProjectDescriptionStorage(IProject project) {
|
/**
|
||||||
return CProjectDescriptionStorageManager.getInstance().getProjectDescriptionStorage(project);
|
* Base for getting a project desc's storage. project must be accessible.
|
||||||
|
* @param project
|
||||||
|
* @return ProjectDescription storage
|
||||||
|
* @throws CoreException if Project isn't accessible
|
||||||
|
*/
|
||||||
|
private AbstractCProjectDescriptionStorage getProjectDescriptionStorage(IProject project) throws CoreException {
|
||||||
|
if (project == null || !project.isAccessible())
|
||||||
|
throw ExceptionFactory.createCoreException(MessageFormat.format(CCorePlugin.getResourceString("ProjectDescription.ProjectNotAccessible"), new Object[] {project != null ? project.getName() : "<null>"})); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
AbstractCProjectDescriptionStorage storage = CProjectDescriptionStorageManager.getInstance().getProjectDescriptionStorage(project);
|
||||||
|
if (storage == null)
|
||||||
|
throw ExceptionFactory.createCoreException(SettingsModelMessages.getString("CProjectDescriptionManager.FailedToGetStorage") + project.getName()); //$NON-NLS-1$
|
||||||
|
return storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,13 +31,14 @@ CProjectDescriptionManager.9=invalid project file format
|
||||||
CProjectDescriptionManager.0=Initiating resource change handling..
|
CProjectDescriptionManager.0=Initiating resource change handling..
|
||||||
CProjectDescriptionManager.10=invalid project file format
|
CProjectDescriptionManager.10=invalid project file format
|
||||||
CProjectDescriptionManager.11=storage file not found
|
CProjectDescriptionManager.11=storage file not found
|
||||||
CProjectDescriptionManager.12=Serialing CDT Project settings..
|
CProjectDescriptionManager.12=Serializing CDT Project settings..
|
||||||
CProjectDescriptionManager.13=Refreshing the project settings
|
CProjectDescriptionManager.13=Refreshing the project settings
|
||||||
CProjectDescriptionManager.14=workspace info element does not exist
|
CProjectDescriptionManager.14=workspace info element does not exist
|
||||||
CProjectDescriptionManager.15=Preference Configuration
|
CProjectDescriptionManager.15=Preference Configuration
|
||||||
CProjectDescriptionManager.16=attempt to set description for the non-openned project
|
CProjectDescriptionManager.16=attempt to set description for the non-openned project
|
||||||
CProjectDescriptionManager.17=unable to apply the invalid project description for project
|
CProjectDescriptionManager.17=unable to apply the invalid project description for project
|
||||||
CProjectDescriptionManager.cfgIDAlreadyExists=Configuration with ID: {0} already exists in passed in settings storage
|
CProjectDescriptionManager.cfgIDAlreadyExists=Configuration with ID: {0} already exists in passed in settings storage
|
||||||
|
CProjectDescriptionManager.FailedToGetStorage=Failed to get storage for project:
|
||||||
CProjectDescriptionManager.illegalDeltaKind=Illegal delta kind
|
CProjectDescriptionManager.illegalDeltaKind=Illegal delta kind
|
||||||
CProjectDescriptionManager.wrongTypeOfResourceDescription=Wrong type of resource description:
|
CProjectDescriptionManager.wrongTypeOfResourceDescription=Wrong type of resource description:
|
||||||
CFolderDescription.0=data was not created
|
CFolderDescription.0=data was not created
|
||||||
|
|
Loading…
Add table
Reference in a new issue