use of org.eclipse.core.runtime.Status in project che by eclipse.
the class ChePreferences method write.
/*
* Helper method to persist a Properties object to the filesystem. We use this
* helper so we can remove the date/timestamp that Properties#store always
* puts in the file.
*/
protected static void write(Properties properties, String location) throws BackingStoreException {
// create the parent directories if they don't exist
// File parentFile = new File(location);
// if (parentFile == null)
// return;
// parentFile.mkdirs();
OutputStream output = null;
try {
File file = new File(location);
if (!file.exists()) {
File parentFile = file.getParentFile();
if (!parentFile.exists()) {
parentFile.mkdirs();
}
file.createNewFile();
}
output = new SafeFileOutputStream(file);
//$NON-NLS-1$
output.write(removeTimestampFromTable(properties).getBytes("UTF-8"));
output.flush();
} catch (IOException e) {
// String message = NLS.bind(PrefsMessages.preferences_saveException, location);
ResourcesPlugin.log(new Status(IStatus.ERROR, PrefsMessages.OWNER_NAME, IStatus.ERROR, "preferences_saveException", e));
throw new BackingStoreException("preferences_saveException");
} finally {
if (output != null)
try {
output.close();
} catch (IOException e) {
// ignore
}
}
}
use of org.eclipse.core.runtime.Status 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.Status in project che by eclipse.
the class Project method getDescription.
@Override
public IProjectDescription getDescription() throws CoreException {
return new IProjectDescription() {
@Override
public IBuildConfiguration[] getBuildConfigReferences(String s) {
return new IBuildConfiguration[0];
}
@Override
public ICommand[] getBuildSpec() {
return new ICommand[0];
}
@Override
public String getComment() {
return null;
}
@Override
public IProject[] getDynamicReferences() {
return new IProject[0];
}
@Override
public IPath getLocation() {
return null;
}
@Override
public URI getLocationURI() {
return null;
}
@Override
public String getName() {
return null;
}
@Override
public String[] getNatureIds() {
RegisteredProject project = workspace.getProjectRegistry().getProject(path.toString());
if (project == null) {
ResourcesPlugin.log(new Status(IStatus.ERROR, "resource", "Can't find project: " + path.toOSString()));
return new String[0];
}
Map<String, List<String>> attributes = project.getAttributes();
String language = "";
if (attributes.containsKey("language")) {
language = attributes.get("language").get(0);
}
return "java".equals(language) ? new String[] { "org.eclipse.jdt.core.javanature" } : new String[] { language };
}
@Override
public IProject[] getReferencedProjects() {
return new IProject[0];
}
@Override
public boolean hasNature(String s) {
String[] natureIds = getNatureIds();
for (String id : natureIds) {
if (s.equals(id)) {
return true;
}
}
return false;
}
@Override
public ICommand newCommand() {
return null;
}
@Override
public void setActiveBuildConfig(String s) {
}
@Override
public void setBuildConfigs(String[] strings) {
}
@Override
public void setBuildConfigReferences(String s, IBuildConfiguration[] iBuildConfigurations) {
}
@Override
public void setBuildSpec(ICommand[] iCommands) {
}
@Override
public void setComment(String s) {
}
@Override
public void setDynamicReferences(IProject[] iProjects) {
}
@Override
public void setLocation(IPath iPath) {
}
@Override
public void setLocationURI(URI uri) {
}
@Override
public void setName(String s) {
}
@Override
public void setNatureIds(String[] strings) {
}
@Override
public void setReferencedProjects(IProject[] iProjects) {
}
};
}
use of org.eclipse.core.runtime.Status 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.Status 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