use of org.eclipse.core.internal.resources.ResourceException 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.internal.resources.ResourceException in project mdw-designer by CenturyLinkCloud.
the class PluginUtil method unzipProjectResource.
/**
* Unzips an archive file into a project.
*
* @param project
* holds the archive file and the destination folder
* @param file
* the archive file to unzip
* @param filesToIgnore
* filenames to exclude
* @param destFolder
* directory to unzip into
* @param a
* progress monitor (uses 10 ticks)
*/
public static void unzipProjectResource(IProject project, IFile file, List<String> filesToIgnore, IFolder destFolder, IProgressMonitor monitor) throws IOException, CoreException {
monitor.subTask("Unzipping: " + file.getName());
JarFile jar = null;
try {
jar = new JarFile(new File(file.getLocationURI()));
if (!destFolder.exists())
project.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 1));
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 10);
Enumeration<JarEntry> entries = jar.entries();
subMonitor.beginTask("", jar.size());
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
String entryName = entry.getName();
if (filesToIgnore != null && filesToIgnore.contains(entryName.substring(entryName.lastIndexOf("/") + 1)))
continue;
// write the file into the project
String outpath = destFolder.getProjectRelativePath() + "/" + entryName;
IFile outfile = project.getFile(outpath);
if (!outfile.exists()) {
if (entry.isDirectory())
PluginUtil.createFoldersAsNeeded(project, project.getFolder(outpath), subMonitor);
else {
try {
outfile.create(jar.getInputStream(entry), IFile.FORCE, subMonitor);
} catch (ResourceException ex) {
PluginMessages.log(ex);
final Display display = MdwPlugin.getDisplay();
if (display != null) {
final String msg = ex.getMessage();
display.syncExec(new Runnable() {
public void run() {
MessageDialog.openError(display.getActiveShell(), "Resource Error", msg);
}
});
}
}
}
} else {
if (!entry.isDirectory())
outfile.setContents(jar.getInputStream(entry), IFile.FORCE, subMonitor);
}
subMonitor.worked(1);
}
} finally {
if (jar != null)
jar.close();
}
}
use of org.eclipse.core.internal.resources.ResourceException in project polymap4-core by Polymap4.
the class AutoBuildJob method doBuild.
private void doBuild(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
monitor = Policy.monitorFor(monitor);
try {
// $NON-NLS-1$
monitor.beginTask("", Policy.opWork);
final ISchedulingRule rule = workspace.getRuleFactory().buildRule();
try {
workspace.prepareOperation(rule, monitor);
workspace.beginOperation(true);
final int trigger = IncrementalProjectBuilder.AUTO_BUILD;
workspace.broadcastBuildEvent(workspace, IResourceChangeEvent.PRE_BUILD, trigger);
IStatus result = Status.OK_STATUS;
try {
if (shouldBuild())
result = workspace.getBuildManager().build(trigger, Policy.subMonitorFor(monitor, Policy.opWork));
} finally {
// always send POST_BUILD if there has been a PRE_BUILD
workspace.broadcastBuildEvent(workspace, IResourceChangeEvent.POST_BUILD, trigger);
}
if (!result.isOK())
throw new ResourceException(result);
buildNeeded = false;
} finally {
// operation so open it
if (workspace.getElementTree().isImmutable())
workspace.newWorkingTree();
workspace.endOperation(rule, false, Policy.subMonitorFor(monitor, Policy.endOpWork));
}
} finally {
monitor.done();
}
}
use of org.eclipse.core.internal.resources.ResourceException in project polymap4-core by Polymap4.
the class FileUtil method transferStreams.
public static final void transferStreams(InputStream source, OutputStream destination, String path, IProgressMonitor monitor) throws CoreException {
monitor = Policy.monitorFor(monitor);
try {
/*
* Note: although synchronizing on the buffer is thread-safe,
* it may result in slower performance in the future if we want
* to allow concurrent writes.
*/
synchronized (buffer) {
while (true) {
int bytesRead = -1;
try {
bytesRead = source.read(buffer);
} catch (IOException e) {
String msg = NLS.bind(Messages.localstore_failedReadDuringWrite, path);
throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, new Path(path), msg, e);
}
if (bytesRead == -1)
break;
try {
destination.write(buffer, 0, bytesRead);
} catch (IOException e) {
String msg = NLS.bind(Messages.localstore_couldNotWrite, path);
throw new ResourceException(IResourceStatus.FAILED_WRITE_LOCAL, new Path(path), msg, e);
}
monitor.worked(1);
}
}
} finally {
safeClose(source);
safeClose(destination);
}
}
use of org.eclipse.core.internal.resources.ResourceException in project polymap4-core by Polymap4.
the class BucketTree method saveVersion.
/**
* Writes the version tag to a file on disk.
*/
private void saveVersion() throws CoreException {
File versionFile = getVersionFile();
if (!versionFile.getParentFile().exists())
versionFile.getParentFile().mkdirs();
FileOutputStream stream = null;
boolean failed = false;
try {
stream = new FileOutputStream(versionFile);
stream.write(current.getVersion());
} catch (IOException e) {
failed = true;
String message = NLS.bind(Messages.resources_writeWorkspaceMeta, versionFile.getAbsolutePath());
throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, null, message, e);
} finally {
try {
if (stream != null)
stream.close();
} catch (IOException e) {
if (!failed) {
String message = NLS.bind(Messages.resources_writeWorkspaceMeta, versionFile.getAbsolutePath());
throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, null, message, e);
}
}
}
}
Aggregations