Search in sources :

Example 1 with ResourceException

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();
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IResource(org.eclipse.core.resources.IResource) MultiStatus(org.eclipse.core.runtime.MultiStatus) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ResourceException(org.eclipse.core.internal.resources.ResourceException)

Example 2 with ResourceException

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();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) ResourceException(org.eclipse.core.internal.resources.ResourceException) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) JarFile(java.util.jar.JarFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) Display(org.eclipse.swt.widgets.Display)

Example 3 with ResourceException

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();
    }
}
Also used : ResourceException(org.eclipse.core.internal.resources.ResourceException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 4 with ResourceException

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);
    }
}
Also used : ResourceException(org.eclipse.core.internal.resources.ResourceException)

Example 5 with ResourceException

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);
            }
        }
    }
}
Also used : ResourceException(org.eclipse.core.internal.resources.ResourceException)

Aggregations

ResourceException (org.eclipse.core.internal.resources.ResourceException)12 IResourceStatus (org.eclipse.core.resources.IResourceStatus)4 IProject (org.eclipse.core.resources.IProject)3 CoreException (org.eclipse.core.runtime.CoreException)3 File (java.io.File)2 ResourceStatus (org.eclipse.core.internal.resources.ResourceStatus)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)1 IOException (java.io.IOException)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 IFile (org.eclipse.core.resources.IFile)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 IPath (org.eclipse.core.runtime.IPath)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Path (org.eclipse.core.runtime.Path)1