Search in sources :

Example 6 with ResourceException

use of org.eclipse.core.internal.resources.ResourceException in project che by eclipse.

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);
                }
                try {
                    if (bytesRead == -1) {
                        // Bug 332543 - ensure we don't ignore failures on close()
                        destination.close();
                        break;
                    }
                    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 : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ResourceException(org.eclipse.core.internal.resources.ResourceException) IOException(java.io.IOException)

Example 7 with ResourceException

use of org.eclipse.core.internal.resources.ResourceException in project che by eclipse.

the class Resource method unprotectedMove.

/**
     * Calls the move/delete hook to perform the move.  Since this method calls
     * client code, it is run "unprotected", so the workspace lock is not held.
     * Returns true if resources were actually moved, and false otherwise.
     */
private boolean unprotectedMove(final IResource destination, int updateFlags, IProgressMonitor monitor) throws CoreException, ResourceException {
    //        IMoveDeleteHook hook = workspace.getMoveDeleteHook();
    switch(getType()) {
        case IResource.FILE:
            //                if (!hook.moveFile(tree, (IFile) this, (IFile) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
            workspace.standardMoveFile((IFile) this, (IFile) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
            break;
        case IResource.FOLDER:
            //                if (!hook.moveFolder(tree, (IFolder) this, (IFolder) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
            workspace.standardMoveFolder((IFolder) this, (IFolder) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
            break;
        case IResource.PROJECT:
            IProject project = (IProject) this;
            // if there is no change in name, there is nothing to do so return.
            if (getName().equals(destination.getName()))
                return false;
            IProjectDescription description = project.getDescription();
            description.setName(destination.getName());
            //                if (!hook.moveProject(tree, project, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
            workspace.standardMoveProject(project, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
            break;
        case IResource.ROOT:
            String msg = Messages.resources_moveRoot;
            throw new ResourceException(new ResourceStatus(IResourceStatus.INVALID_VALUE, getFullPath(), msg));
    }
    return true;
}
Also used : IProjectDescription(org.eclipse.core.resources.IProjectDescription) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ResourceException(org.eclipse.core.internal.resources.ResourceException) IProject(org.eclipse.core.resources.IProject)

Example 8 with ResourceException

use of org.eclipse.core.internal.resources.ResourceException in project liferay-ide by liferay.

the class NewLiferayPluginProjectPortletNameOpTests method removePluginsSDK.

@AfterClass
public static void removePluginsSDK() throws CoreException {
    IProject[] projects = CoreUtil.getAllProjects();
    for (IProject project : projects) {
        if (project != null && project.isAccessible() && project.exists()) {
            try {
                project.close(new NullProgressMonitor());
                project.delete(true, new NullProgressMonitor());
            } catch (ResourceException re) {
                project.close(new NullProgressMonitor());
                project.delete(true, new NullProgressMonitor());
            }
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ResourceException(org.eclipse.core.internal.resources.ResourceException) IProject(org.eclipse.core.resources.IProject) AfterClass(org.junit.AfterClass)

Example 9 with ResourceException

use of org.eclipse.core.internal.resources.ResourceException in project polymap4-core by Polymap4.

the class Bucket method load.

/**
 * Loads the contents from a file under the given directory. If <code>force</code> is
 * <code>false</code>, if this bucket already contains the contents from the current location,
 * avoids reloading.
 */
public void load(String newProjectName, File baseLocation, boolean force) throws CoreException {
    try {
        // avoid reloading
        if (!force && this.location != null && baseLocation.equals(this.location.getParentFile()) && (projectName == null ? (newProjectName == null) : projectName.equals(newProjectName))) {
            this.projectName = newProjectName;
            return;
        }
        // previously loaded bucket may not have been saved... save before loading new one
        save();
        this.projectName = newProjectName;
        this.location = new File(baseLocation, getIndexFileName());
        this.entries.clear();
        if (!this.location.isFile())
            return;
        DataInputStream source = new DataInputStream(new BufferedInputStream(new FileInputStream(location), 8192));
        try {
            int version = source.readByte();
            if (version != getVersion()) {
                // unknown version
                String message = NLS.bind(Messages.resources_readMetaWrongVersion, location.getAbsolutePath(), Integer.toString(version));
                ResourceStatus status = new ResourceStatus(IResourceStatus.FAILED_READ_METADATA, message);
                throw new ResourceException(status);
            }
            int entryCount = source.readInt();
            for (int i = 0; i < entryCount; i++) this.entries.put(readEntryKey(source), readEntryValue(source));
        } finally {
            source.close();
        }
    } catch (IOException ioe) {
        String message = NLS.bind(Messages.resources_readMeta, location.getAbsolutePath());
        ResourceStatus status = new ResourceStatus(IResourceStatus.FAILED_READ_METADATA, null, message, ioe);
        throw new ResourceException(status);
    }
}
Also used : ResourceStatus(org.eclipse.core.internal.resources.ResourceStatus) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ResourceException(org.eclipse.core.internal.resources.ResourceException)

Example 10 with ResourceException

use of org.eclipse.core.internal.resources.ResourceException in project polymap4-core by Polymap4.

the class Bucket method save.

/**
 * Saves this bucket's contents back to its location.
 */
public void save() throws CoreException {
    if (!needSaving)
        return;
    try {
        if (entries.isEmpty()) {
            needSaving = false;
            cleanUp(location);
            return;
        }
        // ensure the parent location exists
        File parent = location.getParentFile();
        if (parent == null)
            // caught and rethrown below
            throw new IOException();
        parent.mkdirs();
        DataOutputStream destination = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(location), 8192));
        try {
            destination.write(getVersion());
            destination.writeInt(entries.size());
            for (Iterator i = entries.entrySet().iterator(); i.hasNext(); ) {
                Map.Entry entry = (Map.Entry) i.next();
                writeEntryKey(destination, (String) entry.getKey());
                writeEntryValue(destination, entry.getValue());
            }
        } finally {
            destination.close();
        }
        needSaving = false;
    } catch (IOException ioe) {
        String message = NLS.bind(Messages.resources_writeMeta, location.getAbsolutePath());
        ResourceStatus status = new ResourceStatus(IResourceStatus.FAILED_WRITE_METADATA, null, message, ioe);
        throw new ResourceException(status);
    }
}
Also used : ResourceStatus(org.eclipse.core.internal.resources.ResourceStatus) IResourceStatus(org.eclipse.core.resources.IResourceStatus) 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