Search in sources :

Example 21 with Status

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
            }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SafeFileOutputStream(org.eclipse.core.internal.preferences.SafeFileOutputStream) OutputStream(java.io.OutputStream) BackingStoreException(org.osgi.service.prefs.BackingStoreException) IOException(java.io.IOException) SafeFileOutputStream(org.eclipse.core.internal.preferences.SafeFileOutputStream) File(java.io.File)

Example 22 with Status

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();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Charset(java.nio.charset.Charset) CharacterCodingException(java.nio.charset.CharacterCodingException) IOException(java.io.IOException) CharsetEncoder(java.nio.charset.CharsetEncoder) ByteBuffer(java.nio.ByteBuffer) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) IFileInfo(org.eclipse.core.filesystem.IFileInfo) CoreException(org.eclipse.core.runtime.CoreException) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) UnmappableCharacterException(java.nio.charset.UnmappableCharacterException)

Example 23 with Status

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) {
        }
    };
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) ICommand(org.eclipse.core.resources.ICommand) IProjectDescription(org.eclipse.core.resources.IProjectDescription) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) List(java.util.List) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) IBuildConfiguration(org.eclipse.core.resources.IBuildConfiguration)

Example 24 with Status

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));
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) IPath(org.eclipse.core.runtime.IPath) ConflictException(org.eclipse.che.api.core.ConflictException) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) NotFoundException(org.eclipse.che.api.core.NotFoundException) CoreException(org.eclipse.core.runtime.CoreException) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)

Example 25 with Status

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);
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

Status (org.eclipse.core.runtime.Status)305 IStatus (org.eclipse.core.runtime.IStatus)282 CoreException (org.eclipse.core.runtime.CoreException)132 IOException (java.io.IOException)66 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)64 InvocationTargetException (java.lang.reflect.InvocationTargetException)40 File (java.io.File)38 ArrayList (java.util.ArrayList)37 IFile (org.eclipse.core.resources.IFile)37 MultiStatus (org.eclipse.core.runtime.MultiStatus)30 IResource (org.eclipse.core.resources.IResource)27 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)26 IProject (org.eclipse.core.resources.IProject)24 IPath (org.eclipse.core.runtime.IPath)24 ITask (com.cubrid.common.core.task.ITask)23 PartInitException (org.eclipse.ui.PartInitException)23 InputStream (java.io.InputStream)18 GridData (org.eclipse.swt.layout.GridData)17 GridLayout (org.eclipse.swt.layout.GridLayout)17 Composite (org.eclipse.swt.widgets.Composite)16