use of org.eclipse.core.runtime.CoreException in project che by eclipse.
the class FileStoreTextFileBuffer method commitFileBufferContent.
/*
* @see org.eclipse.core.internal.filebuffers.FileBuffer#commitFileBufferContent(org.eclipse.core.runtime.IProgressMonitor, boolean)
*/
protected void commitFileBufferContent(IProgressMonitor monitor, boolean overwrite) throws CoreException {
// if (!isSynchronized() && !overwrite)
// throw new CoreException(new Status(IStatus.WARNING, FileBuffersPlugin.PLUGIN_ID, IResourceStatus.OUT_OF_SYNC_LOCAL, FileBuffersMessages.FileBuffer_error_outOfSync, null));
String encoding = computeEncoding();
Charset charset;
try {
charset = Charset.forName(encoding);
} catch (UnsupportedCharsetException ex) {
String message = NLSUtility.format(FileBuffersMessages.ResourceTextFileBuffer_error_unsupported_encoding_message_arg, encoding);
IStatus s = new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, ex);
throw new CoreException(s);
} catch (IllegalCharsetNameException ex) {
String message = NLSUtility.format(FileBuffersMessages.ResourceTextFileBuffer_error_illegal_encoding_message_arg, encoding);
IStatus s = new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, ex);
throw new CoreException(s);
}
CharsetEncoder encoder = charset.newEncoder();
encoder.onMalformedInput(CodingErrorAction.REPLACE);
encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
byte[] bytes;
int bytesLength;
try {
ByteBuffer byteBuffer = encoder.encode(CharBuffer.wrap(fDocument.get()));
bytesLength = byteBuffer.limit();
if (byteBuffer.hasArray())
bytes = byteBuffer.array();
else {
bytes = new byte[bytesLength];
byteBuffer.get(bytes);
}
} catch (CharacterCodingException ex) {
Assert.isTrue(ex instanceof UnmappableCharacterException);
String message = NLSUtility.format(FileBuffersMessages.ResourceTextFileBuffer_error_charset_mapping_failed_message_arg, encoding);
IStatus s = new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IFileBufferStatusCodes.CHARSET_MAPPING_FAILED, message, null);
throw new CoreException(s);
}
IFileInfo fileInfo = fFileStore.fetchInfo();
if (fileInfo != null && fileInfo.exists()) {
if (!overwrite)
checkSynchronizationState();
InputStream stream = new ByteArrayInputStream(bytes, 0, bytesLength);
/*
* XXX:
* This is a workaround for a corresponding bug in Java readers and writer,
* see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
*/
if (fHasBOM && CHARSET_UTF_8.equals(encoding))
stream = new SequenceInputStream(new ByteArrayInputStream(IContentDescription.BOM_UTF_8), stream);
// here the file synchronizer should actually be removed and afterwards added again. However,
// we are already inside an operation, so the delta is sent AFTER we have added the listener
setFileContents(stream, monitor);
// set synchronization stamp to know whether the file synchronizer must become active
fSynchronizationStamp = fFileStore.fetchInfo().getLastModified();
// if (fAnnotationModel instanceof IPersistableAnnotationModel) {
// IPersistableAnnotationModel persistableModel= (IPersistableAnnotationModel) fAnnotationModel;
// persistableModel.commit(fDocument);
// }
} else {
fFileStore.getParent().mkdir(EFS.NONE, null);
OutputStream out = fFileStore.openOutputStream(EFS.NONE, null);
try {
/*
* XXX:
* This is a workaround for a corresponding bug in Java readers and writer,
* see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
*/
if (fHasBOM && CHARSET_UTF_8.equals(encoding))
out.write(IContentDescription.BOM_UTF_8);
out.write(bytes, 0, bytesLength);
out.flush();
out.close();
} catch (IOException x) {
IStatus s = new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, x.getLocalizedMessage(), x);
throw new CoreException(s);
} finally {
try {
out.close();
} catch (IOException x) {
}
}
// set synchronization stamp to know whether the file synchronizer must become active
fSynchronizationStamp = fFileStore.fetchInfo().getLastModified();
}
}
use of org.eclipse.core.runtime.CoreException in project che by eclipse.
the class Launching method writeInstallInfo.
/**
* Writes out the mappings of SDK install time stamps to disk. See
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=266651 for more information.
*/
private static void writeInstallInfo() {
if (fgInstallTimeMap != null) {
OutputStream stream = null;
try {
Document doc = newDocument();
//$NON-NLS-1$
Element root = doc.createElement("dirs");
doc.appendChild(root);
Map.Entry<String, Long> entry = null;
Element e = null;
String key = null;
for (Iterator<Map.Entry<String, Long>> i = fgInstallTimeMap.entrySet().iterator(); i.hasNext(); ) {
entry = i.next();
key = entry.getKey();
if (fgLibraryInfoMap == null || fgLibraryInfoMap.containsKey(key)) {
//only persist the info if the library map also has info OR is null - prevent persisting deleted JRE information
//$NON-NLS-1$
e = doc.createElement("entry");
root.appendChild(e);
//$NON-NLS-1$
e.setAttribute("loc", key);
//$NON-NLS-1$
e.setAttribute("stamp", entry.getValue().toString());
}
}
String xml = serializeDocument(doc);
IPath libPath = getDefault().getStateLocation();
//$NON-NLS-1$
libPath = libPath.append(".install.xml");
File file = libPath.toFile();
if (!file.exists()) {
file.createNewFile();
}
stream = new BufferedOutputStream(new FileOutputStream(file));
//$NON-NLS-1$
stream.write(xml.getBytes("UTF8"));
} catch (IOException e) {
log(e);
} catch (CoreException e) {
log(e);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e1) {
}
}
}
}
}
use of org.eclipse.core.runtime.CoreException in project che by eclipse.
the class Workspace method delete.
@Override
public IStatus delete(IResource[] resources, int updateFlags, IProgressMonitor monitor) throws CoreException {
monitor = Policy.monitorFor(monitor);
try {
int opWork = Math.max(resources.length, 1);
int totalWork = Policy.totalWork * opWork / Policy.opWork;
String message = Messages.resources_deleting_0;
monitor.beginTask(message, totalWork);
message = Messages.resources_deleteProblem;
MultiStatus result = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IResourceStatus.INTERNAL_ERROR, message, null);
if (resources.length == 0)
return result;
// to avoid concurrent changes to this array
resources = resources.clone();
try {
prepareOperation(getRoot(), monitor);
beginOperation(true);
for (int i = 0; i < resources.length; i++) {
Policy.checkCanceled(monitor);
Resource resource = (Resource) resources[i];
if (resource == null) {
monitor.worked(1);
continue;
}
try {
resource.delete(updateFlags, Policy.subMonitorFor(monitor, 1));
} catch (CoreException e) {
// Don't really care about the exception unless the resource is still around.
ResourceInfo info = resource.getResourceInfo(false, false);
if (resource.exists(resource.getFlags(info), false)) {
message = NLS.bind(Messages.resources_couldnotDelete, resource.getFullPath());
result.merge(new org.eclipse.core.internal.resources.ResourceStatus(IResourceStatus.FAILED_DELETE_LOCAL, resource.getFullPath(), message));
result.merge(e.getStatus());
}
}
}
if (result.matches(IStatus.ERROR))
throw new ResourceException(result);
return result;
} catch (OperationCanceledException e) {
getWorkManager().operationCanceled();
throw e;
} finally {
endOperation(getRoot(), true, Policy.subMonitorFor(monitor, totalWork - opWork));
}
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.CoreException in project che by eclipse.
the class Workspace method createResource.
public void createResource(IResource resource, int updateFlags) throws CoreException {
try {
IPath path = resource.getFullPath();
switch(resource.getType()) {
case IResource.FILE:
String newName = path.lastSegment();
VirtualFileEntry child = getProjectsRoot().getChild(path.removeLastSegments(1).toOSString());
if (child == null) {
throw new NotFoundException("Can't find parent folder: " + path.removeLastSegments(1).toOSString());
}
FolderEntry entry = (FolderEntry) child;
entry.createFile(newName, new byte[0]);
break;
case IResource.FOLDER:
getProjectsRoot().createFolder(path.toOSString());
break;
case IResource.PROJECT:
ProjectConfigImpl projectConfig = new ProjectConfigImpl();
projectConfig.setPath(resource.getName());
projectConfig.setName(resource.getName());
projectConfig.setType(BaseProjectType.ID);
projectManager.get().createProject(projectConfig, new HashMap<>());
break;
default:
throw new UnsupportedOperationException();
}
} catch (ForbiddenException | ConflictException | ServerException | NotFoundException e) {
throw new CoreException(new Status(0, ResourcesPlugin.getPluginId(), e.getMessage(), e));
}
}
use of org.eclipse.core.runtime.CoreException in project che by eclipse.
the class TextFileBufferManager method connect.
/*
* @see org.eclipse.core.filebuffers.IFileBufferManager#connect(org.eclipse.core.runtime.IPath, org.eclipse.core.filebuffers.IFileBufferManager.LocationKind, org.eclipse.core.runtime.IProgressMonitor)
* @since 3.3
*/
public void connect(IPath location, LocationKind locationKind, IProgressMonitor monitor) throws CoreException {
Assert.isNotNull(location);
if (locationKind == LocationKind.NORMALIZE)
location = normalizeLocation(location);
AbstractFileBuffer fileBuffer = null;
synchronized (fFilesBuffers) {
fileBuffer = internalGetFileBuffer(location);
if (fileBuffer != null) {
fileBuffer.connect();
return;
}
}
fileBuffer = createFileBuffer(location, locationKind);
if (fileBuffer == null)
throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IFileBufferStatusCodes.CREATION_FAILED, FileBuffersMessages.FileBufferManager_error_canNotCreateFilebuffer, null));
fileBuffer.create(location, monitor);
synchronized (fFilesBuffers) {
AbstractFileBuffer oldFileBuffer = internalGetFileBuffer(location);
if (oldFileBuffer != null) {
fileBuffer.disconnect();
fileBuffer.dispose();
oldFileBuffer.connect();
return;
}
fileBuffer.connect();
fFilesBuffers.put(location, fileBuffer);
}
// Do notification outside synchronized block
fireBufferCreated(fileBuffer);
}
Aggregations