From 651edc45f326fdb57011852b98dc262a2284382b Mon Sep 17 00:00:00 2001
From: Martin Oberhuber < martin.oberhuber@windriver.com>
Date: Wed, 11 Apr 2007 19:27:10 +0000
Subject: [PATCH] [181917] EFS Improvements: Avoid unclosed Streams, - Fix
early startup issues by deferring FileStore evaluation and classloading, -
Improve performance by RSEFileStore instance factory and caching IRemoteFile.
- Also remove unnecessary class RSEFileCache and obsolete branding files.
---
.../about.ini | 27 -
.../about.mappings | 6 -
.../about.properties | 29 -
.../build.properties | 10 +-
.../eclipse32.png | Bin 4594 -> 0 bytes
.../eclipse/filesystem/Activator.java | 25 +-
.../eclipse/filesystem/RSEFileCache.java | 154 ----
.../eclipse/filesystem/RSEFileStore.java | 736 ++++++------------
.../eclipse/filesystem/RSEFileStoreImpl.java | 631 +++++++++++++++
.../eclipse/filesystem/RSEFileSystem.java | 127 ++-
.../filesystem/RSEFileSystemContributor.java | 10 +-
.../CreateRemoteProjectActionDelegate.java | 13 +-
12 files changed, 939 insertions(+), 829 deletions(-)
delete mode 100644 rse/plugins/org.eclipse.rse.eclipse.filesystem/about.ini
delete mode 100644 rse/plugins/org.eclipse.rse.eclipse.filesystem/about.mappings
delete mode 100644 rse/plugins/org.eclipse.rse.eclipse.filesystem/about.properties
delete mode 100644 rse/plugins/org.eclipse.rse.eclipse.filesystem/eclipse32.png
delete mode 100644 rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileCache.java
create mode 100644 rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileStoreImpl.java
diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/about.ini b/rse/plugins/org.eclipse.rse.eclipse.filesystem/about.ini
deleted file mode 100644
index fdd61ff0dd8..00000000000
--- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/about.ini
+++ /dev/null
@@ -1,27 +0,0 @@
-# about.ini
-# contains information about a feature
-# java.io.Properties file (ISO 8859-1 with "\" escapes)
-# "%key" are externalized strings defined in about.properties
-# This file does not need to be translated.
-
-# Property "aboutText" contains blurb for "About" dialog (translated)
-aboutText=%blurb
-
-# Property "windowImage" contains path to window icon (16x16)
-# needed for primary features only
-
-# Property "featureImage" contains path to feature image (32x32)
-featureImage=eclipse32.png
-
-# Property "aboutImage" contains path to product image (500x330 or 115x164)
-# needed for primary features only
-
-# Property "appName" contains name of the application (not translated)
-# needed for primary features only
-
-# Property "welcomePage" contains path to welcome page (special XML-based format)
-# optional
-
-# Property "welcomePerspective" contains the id of the perspective in which the
-# welcome page is to be opened.
-# optional
\ No newline at end of file
diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/about.mappings b/rse/plugins/org.eclipse.rse.eclipse.filesystem/about.mappings
deleted file mode 100644
index bddaab43109..00000000000
--- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/about.mappings
+++ /dev/null
@@ -1,6 +0,0 @@
-# about.mappings
-# contains fill-ins for about.properties
-# java.io.Properties file (ISO 8859-1 with "\" escapes)
-# This file does not need to be translated.
-
-0=@build@
\ No newline at end of file
diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/about.properties b/rse/plugins/org.eclipse.rse.eclipse.filesystem/about.properties
deleted file mode 100644
index c9a7fcae02f..00000000000
--- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/about.properties
+++ /dev/null
@@ -1,29 +0,0 @@
-###############################################################################
-# Copyright (c) 2000, 2007 IBM Corporation and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-#
-# Contributors:
-# IBM Corporation - initial API and implementation
-###############################################################################
-
-# NLS_MESSAGEFORMAT_NONE
-# NLS_ENCODING=UTF-8
-
-# about.properties
-# contains externalized strings for about.ini
-# java.io.Properties file (ISO 8859-1 with "\" escapes)
-# fill-ins are supplied by about.mappings
-# This file should be translated.
-#
-# Do not translate any values surrounded by {}
-
-blurb=Remote System Explorer Experimental Eclipse Filesystem (EFS) Provider\n\
-\n\
-Version: {featureVersion}\n\
-Build id: {0}\n\
-\n\
-(c) Copyright IBM Corporation and others 2006, 2007. All rights reserved.\n\
-Visit http://www.eclipse.org/dsdp/tm
\ No newline at end of file
diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/build.properties b/rse/plugins/org.eclipse.rse.eclipse.filesystem/build.properties
index 4eeb1202be5..d66d9b4024e 100644
--- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/build.properties
+++ b/rse/plugins/org.eclipse.rse.eclipse.filesystem/build.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2001, 2006 IBM Corporation and others.
+# Copyright (c) 2001, 2007 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -7,14 +7,14 @@
#
# Contributors:
# IBM Corporation - initial API and implementation
+# Martin Oberhuber (Wind River) - [181917] EFS Improvements: Avoid unclosed Streams,
+# - Fix early startup issues by deferring FileStore evaluation and classloading,
+# - Improve performance by RSEFileStore instance factory and caching IRemoteFile.
+# - Also remove unnecessary class RSEFileCache and obsolete branding files.
###############################################################################
bin.includes = META-INF/,\
plugin.xml,\
about.html,\
- about.ini,\
- about.mappings,\
- about.properties,\
- eclipse32.png,\
plugin.properties,\
.
source.. = src/
diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/eclipse32.png b/rse/plugins/org.eclipse.rse.eclipse.filesystem/eclipse32.png
deleted file mode 100644
index 568fac1d05f4d05a2470f02033e92c77ce49a660..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 4594
zcmV
+ * Moved implementation to separate class in order to defer class loading
+ * until resources plugin is up.
+ * false
otherwise.
- * @param remoteFile the remote file.
- * @return true
if the file exists in the cache, false
otherwise.
- */
- public boolean isExistsInCache(IRemoteFile remoteFile) {
- File file = getFromCache(remoteFile);
-
- if (file != null) {
- return true;
- }
- else {
- return false;
- }
- }
-
- /**
- * Writes to the cache. If this is a directory, it simply creates the folder.
- * @param remoteFile the remote file.
- * @param inputStream the input stream with the contents of the remote file, or null
if this is a directory.
- * @return the file in the cache.
- */
- public File writeToCache(IRemoteFile remoteFile, InputStream inputStream) {
-
- String path = getCachePath(remoteFile.getParentRemoteFileSubSystem().getHost().getHostName(), remoteFile.getAbsolutePath());
- File file = new File(path);
-
- if (remoteFile.isDirectory()) {
-
- if (!file.exists()) {
- boolean success = file.mkdirs();
-
- if (success) {
- return file;
- }
- else {
- return null;
- }
- }
- else {
- return file;
- }
- }
- else {
- File parent = file.getParentFile();
-
- if (!parent.exists()) {
- parent.mkdirs();
- }
- }
-
- FileOutputStream outputStream = null;
- BufferedOutputStream bufOutputStream = null;
-
- try {
- outputStream = new FileOutputStream(file);
- bufOutputStream = new BufferedOutputStream(outputStream);
-
- byte[] buffer = new byte[4096];
-
- int readCount;
-
- while((readCount = inputStream.read(buffer)) > 0) {
- bufOutputStream.write(buffer, 0, readCount);
- }
-
- bufOutputStream.flush();
- inputStream.close();
- bufOutputStream.close();
- }
- catch (Exception e) {
- return null;
- }
-
- return file;
- }
-
- /**
- * Gets the cached file for the remote file from the cache if any.
- * @param remoteFile the remote file.
- * @return the cached file, or null
if none.
- */
- public File getFromCache(IRemoteFile remoteFile) {
- String path = getCachePath(remoteFile.getParentRemoteFileSubSystem().getHost().getHostName(), remoteFile.getAbsolutePath());
- File file = new File(path);
-
- if (file.exists()) {
- return file;
- }
- else {
- return null;
- }
- }
-
- /**
- * Gets the cache path.
- * @param hostname the hostname.
- * @param remotePath the remote path.
- * @return the cache path.
- */
- private String getCachePath(String hostname, String remotePath) {
- IPath path = Platform.getStateLocation(Activator.getDefault().getBundle());
- path = path.makeAbsolute();
- path = path.addTrailingSeparator();
- path = path.append(hostname);
- path = path.addTrailingSeparator();
- path = path.append(remotePath);
- return path.toOSString();
- }
-}
\ No newline at end of file
diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileStore.java b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileStore.java
index 3842b5feddb..9a8b03d3580 100644
--- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileStore.java
+++ b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileStore.java
@@ -1,5 +1,5 @@
/********************************************************************************
- * Copyright (c) 2006, 2007 IBM Corporation. All rights reserved.
+ * Copyright (c) 2006, 2007 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@@ -12,17 +12,18 @@
*
* Contributors:
* Kushal Munir (IBM) - moved to internal package
+ * Martin Oberhuber (Wind River) - [181917] EFS Improvements: Avoid unclosed Streams,
+ * - Fix early startup issues by deferring FileStore evaluation and classloading,
+ * - Improve performance by RSEFileStore instance factory and caching IRemoteFile.
+ * - Also remove unnecessary class RSEFileCache and obsolete branding files.
********************************************************************************/
package org.eclipse.rse.internal.eclipse.filesystem;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
-import java.net.URISyntaxException;
+import java.util.HashMap;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo;
@@ -30,545 +31,274 @@ import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.filesystem.provider.FileInfo;
import org.eclipse.core.filesystem.provider.FileStore;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
-import org.eclipse.rse.core.subsystems.RemoteChildrenContentsType;
-import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
-import org.eclipse.rse.services.files.IHostFile;
-import org.eclipse.rse.subsystems.files.core.model.RemoteFileFilterString;
-import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem;
-import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
-import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
-import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
-import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystemConfiguration;
-import org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileContext;
-import org.eclipse.swt.widgets.Display;
-
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+/**
+ * Implementation of IFileStore for RSE.
+ *
+ * An RSEFileStore is an immutable object. Once created, it always
+ * references the same remote item. Therefore, instances can be
+ * shared.
+ *
+ * @since RSE 2.0
+ */
public class RSEFileStore extends FileStore implements IFileStore
{
- private IFileStore _parent;
- private IRemoteFileSubSystem _subSystem;
- private String _absolutePath;
+ private RSEFileStore _parent;
+ private String _host;
private String _name;
- private IRemoteFile _remoteFile;
+ private IPath _absolutePath;
+
+ //cached IRemoteFile object: an Object to avoid early class loading
+ private transient RSEFileStoreImpl _impl = null;
+ private static HashMap instanceMap = new HashMap();
+
+ /**
+ * Constructor to use if the parent file store is known.
+ * @param parent the parent file store.
+ * @param name the name of the file store.
+ */
+ private RSEFileStore(RSEFileStore parent, String name) {
+ _parent = parent;
+ _host = parent.getHost();
+ _name = name;
+ _absolutePath = parent._absolutePath.append(name);
+ }
/**
* Constructor to use if the file store is a handle.
- * @param parent the parent.
- * @param name the name of the file store.
+ * @param host the connection name for the file store.
+ * @param absolutePath an absolute path to the file, valid on the remote file system.
*/
- public RSEFileStore(RSEFileStore parent, IRemoteFileSubSystem subSystem, String parentAbsolutePath, String name) {
- _parent = parent;
- _subSystem = subSystem;
-
- if (!parentAbsolutePath.endsWith(_subSystem.getSeparator())) {
- _absolutePath = parentAbsolutePath + _subSystem.getSeparator() + name;
- }
- else {
- _absolutePath = parentAbsolutePath + name;
- }
-
- _name = name;
- }
-
- // an input stream that wraps another input stream and closes the wrappered input stream in a runnable that is always run with the user interface thread
- private class RSEFileStoreInputStream extends BufferedInputStream {
-
- /**
- * Creates a BufferedInputStream and saves its argument, the input stream, for later use. An internal buffer array is created.
- * @param in the underlying input stream.
- */
- public RSEFileStoreInputStream(InputStream in) {
- super(in);
- }
-
- /**
- * Creates a BufferedInputStream and saves its argument, the input stream, for later use. An internal buffer array of the given size is created.
- * @param in the underlying input stream.
- * @param size the buffer size.
- */
- public RSEFileStoreInputStream(InputStream in, int size) {
- super(in, size);
- }
-
- /**
- * @see java.io.BufferedInputStream#close()
- */
- public void close() throws IOException {
-
- Display current = Display.getCurrent();
-
- if (current != null) {
- super.close();
- }
- }
- }
-
- private class RSEFileStoreOutputStream extends BufferedOutputStream {
-
- /**
- * Creates a new buffered output stream to write data to the specified underlying output stream with a default 512-byte buffer size.
- * @param out the underlying output stream.
- */
- public RSEFileStoreOutputStream(OutputStream out) {
- super(out);
- }
-
- /**
- * Creates a new buffered output stream to write data to the specified underlying output stream with the specified buffer size.
- * @param out the underlying output stream.
- * @param size the buffer size.
- */
- public RSEFileStoreOutputStream(OutputStream out, int size) {
- super(out, size);
- }
-
- /**
- * @see java.io.BufferedOutputStream#close()
- */
- public void close() throws IOException {
-
- Display current = Display.getCurrent();
-
- if (current != null) {
- super.close();
- }
- }
- }
-
- public String[] childNames(int options, IProgressMonitor monitor) throws CoreException {
-
- String[] names;
-
- if (!_subSystem.isConnected()) {
-
- try {
- _subSystem.connect(monitor);
- }
- catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Could not connect to subsystem", e)); //$NON-NLS-1$
- }
- }
-
- // at this point get the live remote file because we want to fetch the info about this file
- try {
- _remoteFile = _subSystem.getRemoteFileObject(_absolutePath);
- }
- catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Could not get remote file", e)); //$NON-NLS-1$
- }
-
- if (_remoteFile == null || !_remoteFile.exists()) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "The file store does not exist")); //$NON-NLS-1$
- }
-
- if (!_remoteFile.isStale() && _remoteFile.hasContents(RemoteChildrenContentsType.getInstance()) && !(_subSystem instanceof IFileServiceSubSystem))
- {
- Object[] children = _remoteFile.getContents(RemoteChildrenContentsType.getInstance());
- names = new String[children.length];
-
- for (int i = 0; i < children.length; i++)
- {
- names[i] = ((IRemoteFile)children[i]).getName();
- }
- }
- else
- {
- try {
-
- IRemoteFile[] children = null;
-
- if (_subSystem instanceof FileServiceSubSystem) {
- FileServiceSubSystem fileServiceSubSystem = ((FileServiceSubSystem)_subSystem);
- IHostFile[] results = fileServiceSubSystem.getFileService().getFilesAndFolders(monitor, _remoteFile.getAbsolutePath(), "*"); //$NON-NLS-1$
- IRemoteFileSubSystemConfiguration config = _subSystem.getParentRemoteFileSubSystemConfiguration();
- RemoteFileFilterString filterString = new RemoteFileFilterString(config, _remoteFile.getAbsolutePath(), "*"); //$NON-NLS-1$
- filterString.setShowFiles(true);
- filterString.setShowSubDirs(true);
- RemoteFileContext context = new RemoteFileContext(_subSystem, _remoteFile, filterString);
- children = fileServiceSubSystem.getHostFileToRemoteFileAdapter().convertToRemoteFiles(fileServiceSubSystem, context, _remoteFile, results);
- }
- else {
- children = _subSystem.listFoldersAndFiles(_remoteFile, "*", monitor); //$NON-NLS-1$
- }
-
- names = new String[children.length];
-
- for (int i = 0; i < children.length; i++) {
- names[i] = (children[i]).getName();
- }
- }
- catch (SystemMessageException e) {
- names = new String[0];
- }
- }
-
- return names;
+ private RSEFileStore(String host, String absolutePath) {
+ _parent = null;
+ _host = host;
+ _absolutePath = new Path(absolutePath);
+ _name = _absolutePath.lastSegment();
}
/**
- * @see org.eclipse.core.filesystem.provider.FileStore#childInfos(int, org.eclipse.core.runtime.IProgressMonitor)
+ * Public factory method for obtaining RSEFileStore instances.
+ * @param uri URI to get a fileStore for
+ * @return an RSEFileStore instance for the URI.
*/
- public IFileInfo[] childInfos(int options, IProgressMonitor monitor) throws CoreException {
-
- FileInfo[] infos;
-
- if (!_subSystem.isConnected()) {
-
- try {
- _subSystem.connect(monitor);
- }
- catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Could not connect to subsystem", e)); //$NON-NLS-1$
+ public static RSEFileStore getInstance(URI uri) {
+ synchronized(instanceMap) {
+ RSEFileStore store = (RSEFileStore)instanceMap.get(uri);
+ if (store==null) {
+ String path = uri.getPath();
+ String hostName = uri.getHost();
+ store = new RSEFileStore(hostName, path);
+ instanceMap.put(uri, store);
}
+ return store;
}
-
- // at this point get the live remote file because we want to fetch the info about this file
- try {
- _remoteFile = _subSystem.getRemoteFileObject(_absolutePath);
- }
- catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Could not get remote file", e)); //$NON-NLS-1$
- }
-
- if (_remoteFile == null || !_remoteFile.exists()) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "The file store does not exist")); //$NON-NLS-1$
- }
-
- if (!_remoteFile.isStale() && _remoteFile.hasContents(RemoteChildrenContentsType.getInstance()) && !(_subSystem instanceof IFileServiceSubSystem))
- {
- Object[] children = _remoteFile.getContents(RemoteChildrenContentsType.getInstance());
-
- infos = new FileInfo[children.length];
-
- for (int i = 0; i < children.length; i++)
- {
- IRemoteFile file = (IRemoteFile)(children[i]);
- FileInfo info = new FileInfo(file.getName());
-
- if (!file.exists()) {
- info.setExists(false);
- }
- else {
- info.setExists(true);
- info.setLastModified(file.getLastModified());
- boolean isDir = file.isDirectory();
- info.setDirectory(isDir);
- info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, !file.canWrite());
- info.setAttribute(EFS.ATTRIBUTE_EXECUTABLE, file.isExecutable());
- info.setAttribute(EFS.ATTRIBUTE_ARCHIVE, file.isArchive());
- info.setAttribute(EFS.ATTRIBUTE_HIDDEN, file.isHidden());
-
- if (!isDir) {
- info.setLength(file.getLength());
- }
- }
-
- infos[i] = info;
- }
- }
- else
- {
- try {
-
- IRemoteFile[] children = null;
-
- if (_subSystem instanceof FileServiceSubSystem) {
- FileServiceSubSystem fileServiceSubSystem = ((FileServiceSubSystem)_subSystem);
- IHostFile[] results = fileServiceSubSystem.getFileService().getFilesAndFolders(monitor, _remoteFile.getAbsolutePath(), "*"); //$NON-NLS-1$
- IRemoteFileSubSystemConfiguration config = _subSystem.getParentRemoteFileSubSystemConfiguration();
- RemoteFileFilterString filterString = new RemoteFileFilterString(config, _remoteFile.getAbsolutePath(), "*"); //$NON-NLS-1$
- filterString.setShowFiles(true);
- filterString.setShowSubDirs(true);
- RemoteFileContext context = new RemoteFileContext(_subSystem, _remoteFile, filterString);
- children = fileServiceSubSystem.getHostFileToRemoteFileAdapter().convertToRemoteFiles(fileServiceSubSystem, context, _remoteFile, results);
- }
- else {
- children = _subSystem.listFoldersAndFiles(_remoteFile, "*", monitor); //$NON-NLS-1$
- }
-
- infos = new FileInfo[children.length];
-
- for (int i = 0; i < children.length; i++)
- {
- IRemoteFile file = children[i];
- FileInfo info = new FileInfo(file.getName());
-
- if (!file.exists()) {
- info.setExists(false);
- }
- else {
- info.setExists(true);
- info.setLastModified(file.getLastModified());
- boolean isDir = file.isDirectory();
- info.setDirectory(isDir);
- info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, !file.canWrite());
- info.setAttribute(EFS.ATTRIBUTE_EXECUTABLE, file.isExecutable());
- info.setAttribute(EFS.ATTRIBUTE_ARCHIVE, file.isArchive());
- info.setAttribute(EFS.ATTRIBUTE_HIDDEN, file.isHidden());
- //TODO Add symbolic link attribute
-
- if (!isDir) {
- info.setLength(file.getLength());
- }
- }
-
- infos[i] = info;
- }
- }
- catch (SystemMessageException e) {
- //TODO check whether we should not throw an exception ourselves
- infos = new FileInfo[0];
- }
- }
-
- return infos;
}
- public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException {
-
- // connect if needed
- if (!_subSystem.isConnected()) {
-
- try {
- _subSystem.connect(monitor);
- }
- catch (Exception e) {
- // throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Could not connect to subsystem", e)); //$NON-NLS-1$
- FileInfo info = new FileInfo(getName());
- info.setExists(false);
- return info;
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.filesystem.provider.FileStore#getChild(java.lang.String)
+ */
+ public IFileStore getChild(String name) {
+ RSEFileStore tmpChild = new RSEFileStore(this, name);
+ URI uri = tmpChild.toURI();
+ synchronized(instanceMap) {
+ RSEFileStore storedChild = (RSEFileStore)instanceMap.get(uri);
+ if (storedChild==null) {
+ instanceMap.put(uri, tmpChild);
+ } else {
+ tmpChild = storedChild;
}
}
-
- // at this point get the live remote file because we want to fetch the info about this file
- try {
- _remoteFile = _subSystem.getRemoteFileObject(_absolutePath);
- }
- catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Could not get remote file", e)); //$NON-NLS-1$
- }
-
- FileInfo info = new FileInfo(getName());
-
- if (_remoteFile == null || !_remoteFile.exists()) {
- info.setExists(false);
- return info;
- }
-
- info.setExists(true);
- info.setLastModified(_remoteFile.getLastModified());
- boolean isDir = _remoteFile.isDirectory();
- info.setDirectory(isDir);
- info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, !_remoteFile.canWrite());
- info.setAttribute(EFS.ATTRIBUTE_EXECUTABLE, _remoteFile.isExecutable());
- info.setAttribute(EFS.ATTRIBUTE_ARCHIVE, _remoteFile.isArchive());
- info.setAttribute(EFS.ATTRIBUTE_HIDDEN, _remoteFile.isHidden());
+ return tmpChild;
+ }
- if (!isDir) {
- info.setLength(_remoteFile.getLength());
- }
-
- return info;
+ /**
+ * Returns the host name or address for this file store.
+ * @return the host name or address for this file store.
+ */
+ /*package*/ String getHost() {
+ //TODO consider computing this instead of storing it
+ return _host;
}
+ /**
+ * Returns an absolute path for this file store.
+ *
+ * The absolute path is in normalized form, as it can use in URIs
+ * (with separator '/').
+ *
+ * @return an absolute path for this file store in normalized form.
+ */
+ /*package*/ String getAbsolutePath() {
+ //TODO consider computing this instead of storing it
+ return _absolutePath.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.filesystem.provider.FileStore#getName()
+ */
public String getName() {
return _name;
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.filesystem.provider.FileStore#getParent()
+ */
public IFileStore getParent() {
return _parent;
}
-
- public synchronized InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException
- {
- if (!_subSystem.isConnected()) {
-
- try {
- _subSystem.connect(monitor);
- }
- catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Could not connect to subsystem", e)); //$NON-NLS-1$
- }
- }
-
- // at this point get the live remote file
- try {
- _remoteFile = _subSystem.getRemoteFileObject(_absolutePath);
- }
- catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Could not get remote file", e)); //$NON-NLS-1$
- }
-
- if (_remoteFile == null || !_remoteFile.exists()) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "The file store does not exist")); //$NON-NLS-1$
- }
-
- if (_remoteFile.isDirectory()) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "The file store represents a directory")); //$NON-NLS-1$
- }
-
- if (_remoteFile.isFile()) {
-
- try {
- return new RSEFileStoreInputStream(_subSystem.getInputStream(_remoteFile.getParentPath(), _remoteFile.getName(), true, monitor));
- }
- catch (SystemMessageException e) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Could not get input stream", e)); //$NON-NLS-1$
- }
- }
-
- return null;
- }
-
- public URI toURI() {
-
- try {
- String path = _absolutePath;
-
- if (path.charAt(0) != '/') {
- path = "/" + path.replace('\\', '/'); //$NON-NLS-1$
- }
-
- return new URI("rse", _subSystem.getHost().getHostName(), path, null); //$NON-NLS-1$
- }
- catch (URISyntaxException e) {
- throw new RuntimeException(e);
- }
+
+ /**
+ * Returns the parent file store as an RSEFileStore.
+ * @return the parent file store as an RSEFileStore.
+ */
+ /*package*/ RSEFileStore getParentStore() {
+ return _parent;
}
- public IFileStore mkdir(int options, IProgressMonitor monitor) throws CoreException
- {
- if (!_subSystem.isConnected()) {
-
- try {
- _subSystem.connect(monitor);
- }
- catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Could not connect to subsystem", e)); //$NON-NLS-1$
- }
- }
-
- // at this point get the live remote file
- try {
- _remoteFile = _subSystem.getRemoteFileObject(_absolutePath);
- }
- catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Could not get remote file", e)); //$NON-NLS-1$
- }
-
- if (!_remoteFile.exists()) {
- try {
- _remoteFile = _subSystem.createFolder(_remoteFile);
- }
- catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "The directory could not be created", e)); //$NON-NLS-1$
- }
-
- return this;
- }
- else {
-
- if (_remoteFile.isFile()) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "A file of that name already exists")); //$NON-NLS-1$
- }
- else {
- return this;
+ /**
+ * Get FileStore implementation.
+ *
null
if no matching connection object was found.
+ */
+ public static IHost getConnectionFor(String hostNameOrAddr, IProgressMonitor monitor) {
+ if (hostNameOrAddr==null) {
+ return null;
+ }
+ ISystemRegistry sr = RSEUIPlugin.getTheSystemRegistry();
+ IHost[] connections = sr.getHosts();
+
+ //FIXME HACK workaround until we get an API method to know when persistent data is fully restored
+ //Without this hack, the first time a directory is expanded RSEUIPlugin is activated and it
+ //is too slow reading persistent data. We wait up to 5 seconds for RSE to initialize.
+ if (connections.length==0) {
+ long startTime = System.currentTimeMillis();
+ long endTime = startTime+5000;
+ //int iterations=0;
+ do {
+ try {
+ Thread.sleep(500);
+ //iterations++;
+ } catch(InterruptedException e) {
+ break;
+ }
+ if (monitor!=null) {
+ monitor.worked(1);
+ if (monitor.isCanceled()) {
+ break;
+ }
+ }
+ connections = sr.getHosts();
+ } while((connections.length==0 || getConnectionFor(hostNameOrAddr, monitor)==null)
+ && System.currentTimeMillis()null
if no IRemoteFileSubSystem is configured.
+ */
+ public static IRemoteFileSubSystem getRemoteFileSubSystem(IHost host) {
+ IRemoteFileSubSystem candidate = null;
+ FileServiceSubSystem serviceCandidate = null;
+ IRemoteFileSubSystem[] subSys = RemoteFileUtility.getFileSubSystems(host);
+ for (int i=0; itrue
, throw an exception if the remote file does not exist
+ * @return an IRemoteFile for this file store
+ * @throws CoreException if connecting is not possible.
+ */
+ private synchronized IRemoteFile getRemoteFileObject(IProgressMonitor monitor, boolean forceExists) throws CoreException {
+ IRemoteFile remoteFile = getCachedRemoteFile();
+ if (remoteFile!=null) {
+ if (remoteFile.getParentRemoteFileSubSystem().isConnected()) {
+ return remoteFile;
+ } else {
+ //need to re-initialize cache
+ remoteFile=null;
+ cacheRemoteFile(null);
+ }
+ }
+
+ RSEFileStore parentStore = _parent.getParentStore();
+ if (parentStore!=null) {
+ //Handle was created naming a parent file store
+ IRemoteFile parent = parentStore.getImpl().getRemoteFileObject(monitor, forceExists);
+ if (parent==null) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ Activator.getDefault().getBundle().getSymbolicName(),
+ "Could not get remote file"));
+ }
+ try {
+ remoteFile = parent.getParentRemoteFileSubSystem().getRemoteFileObject(parent, _parent.getName());
+ } catch(Exception e) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ Activator.getDefault().getBundle().getSymbolicName(),
+ "Could not get remote file", e));
+ }
+ } else {
+ //Handle was created with an absolute name
+ IRemoteFileSubSystem subSys = RSEFileStoreImpl.getConnectedFileSubSystem(_parent.getHost(), monitor);
+ try {
+ //TODO method missing a progressmonitor!
+ remoteFile = subSys.getRemoteFileObject(_parent.getAbsolutePath());
+ }
+ catch (Exception e) {
+ throw new CoreException(new Status(
+ IStatus.ERROR,
+ Activator.getDefault().getBundle().getSymbolicName(),
+ "Could not get remote file", e));
+ }
+ }
+
+ cacheRemoteFile(remoteFile);
+ if (forceExists && (remoteFile == null || !remoteFile.exists())) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ Activator.getDefault().getBundle().getSymbolicName(),
+ "The file store does not exist"));
+ }
+ return remoteFile;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.filesystem.IFileStore#childNames(int, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public String[] childNames(int options, IProgressMonitor monitor) throws CoreException {
+
+ String[] names;
+ IRemoteFile remoteFile = getRemoteFileObject(monitor, true);
+ IRemoteFileSubSystem subSys = remoteFile.getParentRemoteFileSubSystem();
+ if (!remoteFile.isStale() && remoteFile.hasContents(RemoteChildrenContentsType.getInstance()) && !(subSys instanceof IFileServiceSubSystem))
+ {
+ Object[] children = remoteFile.getContents(RemoteChildrenContentsType.getInstance());
+ names = new String[children.length];
+
+ for (int i = 0; i < children.length; i++)
+ {
+ names[i] = ((IRemoteFile)children[i]).getName();
+ }
+ }
+ else
+ {
+ try {
+ IRemoteFile[] children = null;
+
+ if (subSys instanceof FileServiceSubSystem) {
+ FileServiceSubSystem fileServiceSubSystem = ((FileServiceSubSystem)subSys);
+ IHostFile[] results = fileServiceSubSystem.getFileService().getFilesAndFolders(monitor, remoteFile.getAbsolutePath(), "*"); //$NON-NLS-1$
+ IRemoteFileSubSystemConfiguration config = subSys.getParentRemoteFileSubSystemConfiguration();
+ RemoteFileFilterString filterString = new RemoteFileFilterString(config, remoteFile.getAbsolutePath(), "*"); //$NON-NLS-1$
+ filterString.setShowFiles(true);
+ filterString.setShowSubDirs(true);
+ RemoteFileContext context = new RemoteFileContext(subSys, remoteFile, filterString);
+ children = fileServiceSubSystem.getHostFileToRemoteFileAdapter().convertToRemoteFiles(fileServiceSubSystem, context, remoteFile, results);
+ }
+ else {
+ children = subSys.listFoldersAndFiles(remoteFile, "*", monitor); //$NON-NLS-1$
+ }
+
+ names = new String[children.length];
+
+ for (int i = 0; i < children.length; i++) {
+ names[i] = (children[i]).getName();
+ }
+ }
+ catch (SystemMessageException e) {
+ names = new String[0];
+ }
+ }
+
+ return names;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.filesystem.IFileStore#childInfos(int, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public IFileInfo[] childInfos(int options, IProgressMonitor monitor) throws CoreException {
+
+ FileInfo[] infos;
+ IRemoteFile remoteFile = getRemoteFileObject(monitor, true);
+ IRemoteFileSubSystem subSys = remoteFile.getParentRemoteFileSubSystem();
+ if (!remoteFile.isStale() && remoteFile.hasContents(RemoteChildrenContentsType.getInstance()) && !(subSys instanceof IFileServiceSubSystem))
+ {
+ Object[] children = remoteFile.getContents(RemoteChildrenContentsType.getInstance());
+
+ infos = new FileInfo[children.length];
+
+ for (int i = 0; i < children.length; i++)
+ {
+ IRemoteFile file = (IRemoteFile)(children[i]);
+ FileInfo info = new FileInfo(file.getName());
+
+ if (!file.exists()) {
+ info.setExists(false);
+ }
+ else {
+ info.setExists(true);
+ info.setLastModified(file.getLastModified());
+ boolean isDir = file.isDirectory();
+ info.setDirectory(isDir);
+ info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, !file.canWrite());
+ info.setAttribute(EFS.ATTRIBUTE_EXECUTABLE, file.isExecutable());
+ info.setAttribute(EFS.ATTRIBUTE_ARCHIVE, file.isArchive());
+ info.setAttribute(EFS.ATTRIBUTE_HIDDEN, file.isHidden());
+
+ if (!isDir) {
+ info.setLength(file.getLength());
+ }
+ }
+
+ infos[i] = info;
+ }
+ }
+ else
+ {
+ try {
+
+ IRemoteFile[] children = null;
+
+ if (subSys instanceof FileServiceSubSystem) {
+ FileServiceSubSystem fileServiceSubSystem = ((FileServiceSubSystem)subSys);
+ IHostFile[] results = fileServiceSubSystem.getFileService().getFilesAndFolders(monitor, remoteFile.getAbsolutePath(), "*"); //$NON-NLS-1$
+ IRemoteFileSubSystemConfiguration config = subSys.getParentRemoteFileSubSystemConfiguration();
+ RemoteFileFilterString filterString = new RemoteFileFilterString(config, remoteFile.getAbsolutePath(), "*"); //$NON-NLS-1$
+ filterString.setShowFiles(true);
+ filterString.setShowSubDirs(true);
+ RemoteFileContext context = new RemoteFileContext(subSys, remoteFile, filterString);
+ children = fileServiceSubSystem.getHostFileToRemoteFileAdapter().convertToRemoteFiles(fileServiceSubSystem, context, remoteFile, results);
+ }
+ else {
+ children = subSys.listFoldersAndFiles(remoteFile, "*", monitor); //$NON-NLS-1$
+ }
+
+ infos = new FileInfo[children.length];
+
+ for (int i = 0; i < children.length; i++)
+ {
+ IRemoteFile file = children[i];
+ FileInfo info = new FileInfo(file.getName());
+
+ if (!file.exists()) {
+ info.setExists(false);
+ }
+ else {
+ info.setExists(true);
+ info.setLastModified(file.getLastModified());
+ boolean isDir = file.isDirectory();
+ info.setDirectory(isDir);
+ info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, !file.canWrite());
+ info.setAttribute(EFS.ATTRIBUTE_EXECUTABLE, file.isExecutable());
+ info.setAttribute(EFS.ATTRIBUTE_ARCHIVE, file.isArchive());
+ info.setAttribute(EFS.ATTRIBUTE_HIDDEN, file.isHidden());
+ //TODO Add symbolic link attribute
+
+ if (!isDir) {
+ info.setLength(file.getLength());
+ }
+ }
+
+ infos[i] = info;
+ }
+ }
+ catch (SystemMessageException e) {
+ //TODO check whether we should not throw an exception ourselves
+ infos = new FileInfo[0];
+ }
+ }
+
+ return infos;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.filesystem.IFileStore#fetchInfo(int, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException {
+
+ // connect if needed. Will throw exception if not successful.
+ IRemoteFile remoteFile = getRemoteFileObject(monitor, false);
+
+ FileInfo info = new FileInfo(_parent.getName());
+ if (remoteFile == null || !remoteFile.exists()) {
+ info.setExists(false);
+ return info;
+ }
+
+ info.setExists(true);
+ info.setLastModified(remoteFile.getLastModified());
+ boolean isDir = remoteFile.isDirectory();
+ info.setDirectory(isDir);
+ info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, !remoteFile.canWrite());
+ info.setAttribute(EFS.ATTRIBUTE_EXECUTABLE, remoteFile.isExecutable());
+ info.setAttribute(EFS.ATTRIBUTE_ARCHIVE, remoteFile.isArchive());
+ info.setAttribute(EFS.ATTRIBUTE_HIDDEN, remoteFile.isHidden());
+
+ if (!isDir) {
+ info.setLength(remoteFile.getLength());
+ }
+
+ return info;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.filesystem.IFileStore#openInputStream(int, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException
+ {
+ IRemoteFile remoteFile = getRemoteFileObject(monitor, true);
+ IRemoteFileSubSystem subSys = remoteFile.getParentRemoteFileSubSystem();
+
+ if (remoteFile.isDirectory()) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ Activator.getDefault().getBundle().getSymbolicName(),
+ "The file store represents a directory"));
+ }
+
+ if (remoteFile.isFile()) {
+
+ try {
+ return subSys.getInputStream(remoteFile.getParentPath(), remoteFile.getName(), true, monitor);
+ }
+ catch (SystemMessageException e) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ Activator.getDefault().getBundle().getSymbolicName(),
+ "Could not get input stream", e));
+ }
+ }
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.filesystem.IFileStore#mkdir(int, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public IFileStore mkdir(int options, IProgressMonitor monitor) throws CoreException
+ {
+ IRemoteFile remoteFile = getRemoteFileObject(monitor, false);
+ if (remoteFile==null) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ Activator.getDefault().getBundle().getSymbolicName(),
+ "Could not get remote file"));
+ }
+ IRemoteFileSubSystem subSys = remoteFile.getParentRemoteFileSubSystem();
+ if (!remoteFile.exists()) {
+ try {
+ remoteFile = subSys.createFolder(remoteFile);
+ }
+ catch (Exception e) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ Activator.getDefault().getBundle().getSymbolicName(),
+ "The directory could not be created", e));
+ }
+ return _parent;
+ }
+ else if (remoteFile.isFile()) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ Activator.getDefault().getBundle().getSymbolicName(),
+ "A file of that name already exists"));
+ }
+ else {
+ return _parent;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.filesystem.IFileStore#openOutputStream(int, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException {
+
+ IRemoteFile remoteFile = getRemoteFileObject(monitor, false);
+ if (remoteFile==null) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ Activator.getDefault().getBundle().getSymbolicName(),
+ "Could not get remote file"));
+ }
+ IRemoteFileSubSystem subSys = remoteFile.getParentRemoteFileSubSystem();
+ if (!remoteFile.exists()) {
+ try {
+ remoteFile = subSys.createFile(remoteFile);
+ }
+ catch (Exception e) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ Activator.getDefault().getBundle().getSymbolicName(),
+ "Could not create file", e));
+ }
+ }
+
+ if (remoteFile.isFile()) {
+
+ try {
+ return subSys.getOutputStream(remoteFile.getParentPath(), remoteFile.getName(), true, monitor);
+ }
+ catch (SystemMessageException e) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ Activator.getDefault().getBundle().getSymbolicName(),
+ "Could not get output stream", e));
+ }
+ }
+ else if (remoteFile.isDirectory()) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ Activator.getDefault().getBundle().getSymbolicName(),
+ "This is a directory"));
+ }
+ else {
+ //TODO check what to do for symbolic links and other strange stuff
+ return null;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.filesystem.IFileStore#delete(int, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void delete(int options, IProgressMonitor monitor) throws CoreException
+ {
+ IRemoteFile remoteFile = getRemoteFileObject(monitor, false);
+ if (remoteFile==null || !remoteFile.exists()) {
+ return;
+ }
+ else {
+ IRemoteFileSubSystem subSys = remoteFile.getParentRemoteFileSubSystem();
+ try {
+ boolean success = subSys.delete(remoteFile, monitor);
+ if (!success) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ Activator.getDefault().getBundle().getSymbolicName(),
+ "Could not delete file"));
+ }
+ }
+ catch (Exception e) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ Activator.getDefault().getBundle().getSymbolicName(),
+ "Could not delete file", e));
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileSystem.java b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileSystem.java
index a34f86b4a9e..766700d39e6 100644
--- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileSystem.java
+++ b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileSystem.java
@@ -1,5 +1,5 @@
/********************************************************************************
- * Copyright (c) 2006, 2007 IBM Corporation. All rights reserved.
+ * Copyright (c) 2006, 2007 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@@ -13,6 +13,10 @@
* Contributors:
* David Dykstal (IBM) - 168977: refactoring IConnectorService and ServerLauncher hierarchies
* Kushal Munir (IBM) - moved to internal package
+ * Martin Oberhuber (Wind River) - [181917] EFS Improvements: Avoid unclosed Streams,
+ * - Fix early startup issues by deferring FileStore evaluation and classloading,
+ * - Improve performance by RSEFileStore instance factory and caching IRemoteFile.
+ * - Also remove unnecessary class RSEFileCache and obsolete branding files.
********************************************************************************/
package org.eclipse.rse.internal.eclipse.filesystem;
@@ -23,114 +27,73 @@ import java.net.URISyntaxException;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.filesystem.provider.FileSystem;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.rse.core.model.IHost;
-import org.eclipse.rse.core.model.ISystemRegistry;
-import org.eclipse.rse.core.subsystems.IConnectorService;
-import org.eclipse.rse.subsystems.files.core.model.RemoteFileUtility;
-import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
-import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
-import org.eclipse.rse.ui.RSEUIPlugin;
public class RSEFileSystem extends FileSystem
{
private static RSEFileSystem _instance = new RSEFileSystem();
-
+
+ /**
+ * Default constructor.
+ */
public RSEFileSystem() {
super();
}
+ /**
+ * Return the singleton instance of this file system.
+ * @return the singleton instance of this file system.
+ */
public static RSEFileSystem getInstance() {
return _instance;
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.filesystem.provider.FileSystem#canDelete()
+ */
public boolean canDelete() {
return true;
}
-
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.filesystem.provider.FileSystem#canWrite()
+ */
public boolean canWrite() {
return true;
}
- public static IHost getConnectionFor(String hostName) {
-
- ISystemRegistry sr = RSEUIPlugin.getTheSystemRegistry();
- IHost[] connections = sr.getHosts();
- IHost unconnected = null;
-
- for (int i = 0; i < connections.length; i++) {
-
- IHost con = connections[i];
-
- if (con.getHostName().equalsIgnoreCase(hostName)) {
-
- boolean isConnected = false;
- IConnectorService[] connectorServices = con.getConnectorServices();
-
- for (int c = 0; c < connectorServices.length && !isConnected; c++)
- {
- IConnectorService serv = connectorServices[c];
- isConnected = serv.isConnected();
- }
-
- if (isConnected) {
- return con;
- }
- else {
- unconnected = con;
- }
- }
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.filesystem.provider.FileSystem#getStore(java.net.URI)
+ */
+ public IFileStore getStore(URI uri) {
+ try {
+ return RSEFileStore.getInstance(uri);
+ }
+ catch (Exception e) {
+ //Could be an URI format exception
+ return EFS.getNullFileSystem().getStore(uri);
}
-
- return unconnected;
}
-
- public static IRemoteFileSubSystem getRemoteFileSubSystem(IHost host) {
- return RemoteFileUtility.getFileSubSystem(host);
- }
-
- public URI getURIFor(IRemoteFile file) {
- String path = file.getAbsolutePath();
-
- if (path.charAt(0) != '/') {
- path = "/" + path.replace('\\', '/'); //$NON-NLS-1$
+
+ /**
+ * Return an URI uniquely naming an RSE remote resource.
+ * @param hostNameOrAddr host name or IP address of remote system
+ * @param absolutePath absolute path to resource as valid on the remote system
+ * @return an URI uniquely naming the remote resource.
+ */
+ public static URI getURIFor(String hostNameOrAddr, String absolutePath) {
+ //FIXME backslashes are valid in UNIX file names. This is not correctly handled yet.
+ if (absolutePath.charAt(0) != '/') {
+ absolutePath = "/" + absolutePath.replace('\\', '/'); //$NON-NLS-1$
}
-
try {
- return new URI("rse", file.getParentRemoteFileSubSystem().getHost().getHostName(), path, null); //$NON-NLS-1$
+ return new URI("rse", hostNameOrAddr, absolutePath, null); //$NON-NLS-1$
}
catch (URISyntaxException e)
{
throw new RuntimeException(e);
}
}
-
- public IFileStore getStore(URI uri) {
-
- try {
-
- String path = uri.getPath();
- String hostName = uri.getHost();
- IHost con = getConnectionFor(hostName);
-
- if (con != null) {
-
- IRemoteFileSubSystem fs = getRemoteFileSubSystem(con);
-
- if (fs != null) {
- Path absPath = new Path(path);
- return new RSEFileStore(null, fs, absPath.removeLastSegments(1).toString(), absPath.lastSegment());
- }
- else {
- return EFS.getNullFileSystem().getStore(uri);
- }
- }
- else {
- return EFS.getNullFileSystem().getStore(uri);
- }
- }
- catch (Exception e) {
- return EFS.getNullFileSystem().getStore(uri);
- }
- }
}
\ No newline at end of file
diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileSystemContributor.java b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileSystemContributor.java
index 2061a76177c..7ae07af0236 100644
--- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileSystemContributor.java
+++ b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileSystemContributor.java
@@ -1,5 +1,5 @@
/********************************************************************************
- * Copyright (c) 2002, 2006 IBM Corporation. All rights reserved.
+ * Copyright (c) 2002, 2007 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@@ -12,6 +12,10 @@
*
* Contributors:
* Kushal Munir (IBM) - moved to internal package.
+ * Martin Oberhuber (Wind River) - [181917] EFS Improvements: Avoid unclosed Streams,
+ * - Fix early startup issues by deferring FileStore evaluation and classloading,
+ * - Improve performance by RSEFileStore instance factory and caching IRemoteFile.
+ * - Also remove unnecessary class RSEFileCache and obsolete branding files.
********************************************************************************/
@@ -41,8 +45,8 @@ public class RSEFileSystemContributor extends FileSystemContributor {
try {
URI uri = new URI(initialPath);
- IHost host = RSEFileSystem.getConnectionFor(uri.getHost());
- IRemoteFileSubSystem fs = RSEFileSystem.getRemoteFileSubSystem(host);
+ IHost host = RSEFileStoreImpl.getConnectionFor(uri.getHost(), null);
+ IRemoteFileSubSystem fs = RSEFileStoreImpl.getRemoteFileSubSystem(host);
dlg.setInputObject(fs.getRemoteFileObject(uri.getPath()));
}
catch (Exception e) {
diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/ui/actions/CreateRemoteProjectActionDelegate.java b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/ui/actions/CreateRemoteProjectActionDelegate.java
index 309304791b6..17623e5c529 100644
--- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/ui/actions/CreateRemoteProjectActionDelegate.java
+++ b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/ui/actions/CreateRemoteProjectActionDelegate.java
@@ -1,5 +1,5 @@
/********************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others. All rights reserved.
+ * Copyright (c) 2000, 2007 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@@ -14,7 +14,11 @@
* IBM Corporation - initial API and implementation
* Kushal Munir (IBM) - moved to internal package
* Martin Oberhuber (Wind River) - added progress dialog
- * - (adapted from org.eclipse.ui.actions.CopyProjectAction, copyright IBM)
+ * - (adapted from org.eclipse.ui.actions.CopyProjectAction, copyright IBM)
+ * Martin Oberhuber (Wind River) - [181917] EFS Improvements: Avoid unclosed Streams,
+ * - Fix early startup issues by deferring FileStore evaluation and classloading,
+ * - Improve performance by RSEFileStore instance factory and caching IRemoteFile.
+ * - Also remove unnecessary class RSEFileCache and obsolete branding files.
********************************************************************************/
package org.eclipse.rse.internal.eclipse.filesystem.ui.actions;
@@ -166,7 +170,6 @@ public class CreateRemoteProjectActionDelegate implements IActionDelegate {
// (Copyright 2000, 2006 IBM Corporation and others)
//----------------------------------------------------------------------------
-
private IProject createRemoteProject(IRemoteFile directory, IProgressMonitor monitor)
{
IWorkspaceRoot root = SystemBasePlugin.getWorkspaceRoot();
@@ -185,7 +188,9 @@ public class CreateRemoteProjectActionDelegate implements IActionDelegate {
try
{
IProjectDescription description = root.getWorkspace().newProjectDescription(directory.getName());
- URI location = RSEFileSystem.getInstance().getURIFor(directory);
+ String hostNameOrAddr = directory.getParentRemoteFileSubSystem().getHost().getHostName();
+ String absolutePath = directory.getAbsolutePath();
+ URI location = RSEFileSystem.getURIFor(hostNameOrAddr, absolutePath);
description.setLocationURI(location);
editProject.create(description, monitor);