Search in sources :

Example 26 with IFileInfo

use of org.eclipse.core.filesystem.IFileInfo in project che by eclipse.

the class RefactoringHistoryManager method readRefactoringDescriptorProxies.

/**
	 * Reads refactoring descriptor proxies.
	 *
	 * @param store
	 *            the file store to read
	 * @param project
	 *            the name of the project, or <code>null</code> for the
	 *            workspace
	 * @param collection
	 *            the collection of proxies to fill in
	 * @param start
	 *            the start time stamp, inclusive
	 * @param end
	 *            the end time stamp, inclusive
	 * @param monitor
	 *            the progress monitor to use
	 * @param task
	 *            the task label to use
	 * @throws CoreException
	 *             if an error occurs
	 */
private static void readRefactoringDescriptorProxies(final IFileStore store, final String project, final Collection collection, final long start, final long end, final IProgressMonitor monitor, final String task) throws CoreException {
    try {
        monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_retrieving_history, 22);
        final IFileInfo info = store.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 2, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
        if (!info.isDirectory() && info.exists() && store.getName().equalsIgnoreCase(RefactoringHistoryService.NAME_INDEX_FILE)) {
            InputStream stream = null;
            try {
                stream = store.openInputStream(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
                final RefactoringDescriptorProxy[] proxies = readRefactoringDescriptorProxies(stream, project, start, end);
                for (int index = 0; index < proxies.length; index++) collection.add(proxies[index]);
                monitor.worked(1);
            } catch (IOException exception) {
                throw createCoreException(exception);
            } finally {
                monitor.worked(1);
                if (stream != null) {
                    try {
                        stream.close();
                    } catch (IOException exception) {
                    // Do nothing
                    }
                }
                monitor.worked(1);
            }
        } else
            monitor.worked(4);
        if (monitor.isCanceled())
            throw new OperationCanceledException();
        final IFileStore[] stores = store.childStores(EFS.NONE, new SubProgressMonitor(monitor, 2, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
        final IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 12);
        try {
            subMonitor.beginTask(task, stores.length);
            for (int index = 0; index < stores.length; index++) readRefactoringDescriptorProxies(stores[index], project, collection, start, end, new SubProgressMonitor(subMonitor, 1), task);
        } finally {
            subMonitor.done();
        }
    } finally {
        monitor.done();
    }
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RefactoringDescriptorProxy(org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 27 with IFileInfo

use of org.eclipse.core.filesystem.IFileInfo in project che by eclipse.

the class FileStoreFileBuffer method create.

public void create(IFileStore fileStore, IProgressMonitor monitor) throws CoreException {
    IFileInfo info = fileStore.fetchInfo();
    fFileStore = fileStore;
    if (fLocation == null)
        fLocation = URIUtil.toPath(fileStore.toURI());
    initializeFileBufferContent(monitor);
    if (info.exists())
        fSynchronizationStamp = info.getLastModified();
    addFileBufferContentListeners();
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo)

Example 28 with IFileInfo

use of org.eclipse.core.filesystem.IFileInfo in project che by eclipse.

the class FileStore method copy.

/**
	 * The default implementation of {@link IFileStore#copy(IFileStore, int, IProgressMonitor)}.
	 * This implementation performs a copy by using other primitive methods. 
	 * Subclasses may override this method.
	 */
public void copy(IFileStore destination, int options, IProgressMonitor monitor) throws CoreException {
    monitor = Policy.monitorFor(monitor);
    Policy.checkCanceled(monitor);
    final IFileInfo sourceInfo = fetchInfo(EFS.NONE, null);
    if (sourceInfo.isDirectory())
        copyDirectory(sourceInfo, destination, options, monitor);
    else
        copyFile(sourceInfo, destination, options, monitor);
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo)

Example 29 with IFileInfo

use of org.eclipse.core.filesystem.IFileInfo in project che by eclipse.

the class LocalFile method fetchInfo.

public IFileInfo fetchInfo(int options, IProgressMonitor monitor) {
    //		if (LocalFileNativesManager.isUsingNatives()) {
    //			FileInfo info = LocalFileNativesManager.fetchFileInfo(filePath);
    //			//natives don't set the file name on all platforms
    //			if (info.getName().length() == 0) {
    //				String name = file.getName();
    //				//Bug 294429: make sure that substring baggage is removed
    //				info.setName(new String(name.toCharArray()));
    //			}
    //			return info;
    //		}
    //in-lined non-native implementation
    FileInfo info = new FileInfo(file.getName());
    final long lastModified = file.lastModified();
    if (lastModified <= 0) {
        //if the file doesn't exist, all other attributes should be default values
        info.setExists(false);
        return info;
    }
    info.setLastModified(lastModified);
    info.setExists(true);
    info.setLength(file.length());
    info.setDirectory(file.isDirectory());
    info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, file.exists() && !file.canWrite());
    info.setAttribute(EFS.ATTRIBUTE_HIDDEN, file.isHidden());
    return info;
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) FileInfo(org.eclipse.core.filesystem.provider.FileInfo)

Example 30 with IFileInfo

use of org.eclipse.core.filesystem.IFileInfo in project eclipse.platform.text by eclipse.

the class FileBuffersForFilesInLinkedFolders method modifyUnderlyingFile.

@Override
protected boolean modifyUnderlyingFile() throws Exception {
    IFileStore fileStore = FileBuffers.getFileStoreAtLocation(getPath());
    assertTrue(fileStore.fetchInfo().exists());
    OutputStream out = fileStore.openOutputStream(EFS.NONE, null);
    try {
        out.write("Changed content of file in linked folder".getBytes());
        out.flush();
    } catch (IOException x) {
        fail();
    } finally {
        out.close();
    }
    IFileInfo fileInfo = fileStore.fetchInfo();
    fileInfo.setLastModified(1000);
    fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null);
    IFile iFile = FileBuffers.getWorkspaceFileAtLocation(getPath());
    iFile.refreshLocal(IResource.DEPTH_INFINITE, null);
    return true;
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFile(org.eclipse.core.resources.IFile) OutputStream(java.io.OutputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException)

Aggregations

IFileInfo (org.eclipse.core.filesystem.IFileInfo)49 IFileStore (org.eclipse.core.filesystem.IFileStore)32 CoreException (org.eclipse.core.runtime.CoreException)22 IOException (java.io.IOException)13 URI (java.net.URI)13 IFile (org.eclipse.core.resources.IFile)11 IPath (org.eclipse.core.runtime.IPath)11 Test (org.junit.Test)8 URISyntaxException (java.net.URISyntaxException)7 OutputStream (java.io.OutputStream)6 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)6 BufferedReader (java.io.BufferedReader)5 InputStreamReader (java.io.InputStreamReader)5 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)5 IStatus (org.eclipse.core.runtime.IStatus)5 IDocument (org.eclipse.jface.text.IDocument)5 InputStream (java.io.InputStream)4 Path (org.eclipse.core.runtime.Path)4 Status (org.eclipse.core.runtime.Status)4 Reader (java.io.Reader)3