log(new Status(IStatus.WARNING, ResourcesPlugin.PI_RESOURCES, IStatus.WARNING, message, null));
}
}
}
};
ISchedulingRule rule = factory.deleteRule(fileInWorkspace);
try {
ResourcesPlugin.getWorkspace().run(operation, rule, IResource.NONE, null);
} catch (OperationCanceledException e) {
throw new BackingStoreException(Messages.preferences_operationCanceled);
}
return;
}
table.put(VERSION_KEY, VERSION_VALUE);
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
table.store(output, null);
} catch (IOException e) {
String message = NLS.bind(Messages.preferences_saveProblems, absolutePath());
log(new Status(IStatus.ERROR, Platform.PI_RUNTIME, IStatus.ERROR, message, e));
throw new BackingStoreException(message);
} finally {
try {
output.close();
} catch (IOException e) {
// ignore
}
}
final InputStream input = new BufferedInputStream(new ByteArrayInputStream(output.toByteArray()));
IWorkspaceRunnable operation = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
if (fileInWorkspace.exists()) {
if (Policy.DEBUG_PREFERENCES)
Policy.debug("Setting preference file contents for: " + fileInWorkspace.getFullPath()); //$NON-NLS-1$
if (fileInWorkspace.isReadOnly()) {
IStatus status = fileInWorkspace.getWorkspace().validateEdit(new IFile[] {fileInWorkspace}, IWorkspace.VALIDATE_PROMPT);
if (!status.isOK())
throw new CoreException(status);
}
// set the contents
fileInWorkspace.setContents(input, IResource.KEEP_HISTORY, null);
} else {
// create the file
IFolder folder = (IFolder) fileInWorkspace.getParent();
if (!folder.exists()) {
if (Policy.DEBUG_PREFERENCES)
Policy.debug("Creating parent preference directory: " + folder.getFullPath()); //$NON-NLS-1$
folder.create(IResource.NONE, true, null);
}
if (Policy.DEBUG_PREFERENCES)
Policy.debug("Creating preference file: " + fileInWorkspace.getLocation()); //$NON-NLS-1$
fileInWorkspace.create(input, IResource.NONE, null);
}
}
};
//don't bother with scheduling rules if we are already inside an operation
try {
if (((Workspace) workspace).getWorkManager().isLockAlreadyAcquired()) {
operation.run(null);
} else {
// we might: create the .settings folder, create the file, or modify the file.
ISchedulingRule rule = MultiRule.combine(factory.createRule(fileInWorkspace.getParent()), factory.modifyRule(fileInWorkspace));
workspace.run(operation, rule, IResource.NONE, null);
}
} catch (OperationCanceledException e) {
throw new BackingStoreException(Messages.preferences_operationCanceled);
}