mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-09 17:25:38 +02:00
[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.
This commit is contained in:
parent
b929b9ccc6
commit
651edc45f3
12 changed files with 939 additions and 829 deletions
|
@ -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
|
|
@ -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@
|
|
@ -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
|
|
@ -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/
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 4.5 KiB |
|
@ -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,13 +12,14 @@
|
|||
*
|
||||
* 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 org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.rse.core.RSECorePlugin;
|
||||
import org.eclipse.rse.ui.RSEUIPlugin;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
|
@ -42,8 +43,10 @@ public class Activator extends AbstractUIPlugin {
|
|||
*/
|
||||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
RSECorePlugin.getDefault();
|
||||
RSEUIPlugin.getDefault();
|
||||
////We must not activate RSE plugins prematurely, since we are being
|
||||
////activated VERY early while the Resources plugin is not yet fully up
|
||||
//RSECorePlugin.getDefault();
|
||||
//RSEUIPlugin.getDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,14 +66,4 @@ public class Activator extends AbstractUIPlugin {
|
|||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image descriptor for the image file at the given
|
||||
* plug-in relative path.
|
||||
*
|
||||
* @param path the path
|
||||
* @return the image descriptor
|
||||
*/
|
||||
public static ImageDescriptor getImageDescriptor(String path) {
|
||||
return AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.rse.internal.eclipse.filesystem", path); //$NON-NLS-1$
|
||||
}
|
||||
}
|
|
@ -1,154 +0,0 @@
|
|||
/********************************************************************************
|
||||
* Copyright (c) 2007 IBM Corporation. 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:
|
||||
* Kushal Munir (IBM) - moved to internal package
|
||||
********************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.eclipse.filesystem;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
|
||||
|
||||
public class RSEFileCache {
|
||||
|
||||
private static RSEFileCache instance;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
private RSEFileCache() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the singleton instance.
|
||||
* @return the singleton instance.
|
||||
*/
|
||||
public static RSEFileCache getInstance() {
|
||||
|
||||
if (instance == null) {
|
||||
instance = new RSEFileCache();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the remote file exists in the cache. Returns <code>true</code> if the file exists in the cache, <code>false</code> otherwise.
|
||||
* @param remoteFile the remote file.
|
||||
* @return <code>true</code> if the file exists in the cache, <code>false</code> 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 <code>null</code> 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 <code>null</code> 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();
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
* <p>
|
||||
* Moved implementation to separate class in order to defer class loading
|
||||
* until resources plugin is up.
|
||||
* </p>
|
||||
* @return the RSEFileStoreImpl implementation.
|
||||
*/
|
||||
/*package*/ RSEFileStoreImpl getImpl() throws CoreException {
|
||||
//FIXME Workaround for Platform bug 181998 - activation problems on early startup:
|
||||
//Resources plugin opens the workspace in its start() method, triggers the
|
||||
//save manager and this in turn would activate org.eclipse.rse.ui which depends
|
||||
//on resources... this activation circle does not work, therefore throw an
|
||||
//exception if resources are not yet up.
|
||||
if (_impl==null) {
|
||||
if (!isResourcesPluginUp()) {
|
||||
throw new CoreException(new Status(IStatus.WARNING,
|
||||
Activator.getDefault().getBundle().getSymbolicName(),
|
||||
"Cannot access file: Resources not loaded yet"));
|
||||
}
|
||||
_impl = new RSEFileStoreImpl(this);
|
||||
}
|
||||
return _impl;
|
||||
}
|
||||
|
||||
public OutputStream openOutputStream(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.createFile(_remoteFile);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Could not create file", e)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
if (_remoteFile.isFile()) {
|
||||
|
||||
try {
|
||||
return new RSEFileStoreOutputStream(_subSystem.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)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
if (_remoteFile.isDirectory()) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "This is a directory")); //$NON-NLS-1$
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IFileStore getChild(String name) {
|
||||
return new RSEFileStore(this, _subSystem, _absolutePath, name);
|
||||
}
|
||||
|
||||
public void delete(int options, IProgressMonitor monitor) throws CoreException
|
||||
private static Bundle resourcesBundle = null;
|
||||
private static boolean isResourcesPluginUp()
|
||||
{
|
||||
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()) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
|
||||
try {
|
||||
boolean success = _subSystem.delete(_remoteFile, monitor);
|
||||
|
||||
if (!success) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Could not delete file")); //$NON-NLS-1$
|
||||
if (resourcesBundle==null) {
|
||||
BundleContext ctx = Activator.getDefault().getBundle().getBundleContext();
|
||||
Bundle[] bundles = ctx.getBundles();
|
||||
for (int i=0; i<bundles.length; i++) {
|
||||
if ("org.eclipse.core.resources".equals(bundles[i].getSymbolicName())) { //$NON-NLS-1$
|
||||
if (resourcesBundle==null || bundles[i].getState()==Bundle.ACTIVE) {
|
||||
resourcesBundle = bundles[i];
|
||||
}
|
||||
//System.out.println(resourcesBundle);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "Could not delete file", e)); //$NON-NLS-1$
|
||||
}
|
||||
return resourcesBundle.getState()==Bundle.ACTIVE;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.core.filesystem.provider.FileStore#childNames(int, org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public String[] childNames(int options, IProgressMonitor monitor) throws CoreException {
|
||||
return getImpl().childNames(options, monitor);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.core.filesystem.provider.FileStore#childInfos(int, org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public IFileInfo[] childInfos(int options, IProgressMonitor monitor) throws CoreException {
|
||||
return getImpl().childInfos(options, monitor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch information for this file store.
|
||||
* <p>
|
||||
* FIXME This is a HACK to fix early startup problems until
|
||||
* Platform bug 182006 is resolved! Returns an info
|
||||
* object indicating a non-existing file while the Eclipse resources
|
||||
* plugin is not fully activated. This is in order to avoid problems
|
||||
* of activating too much of RSE while Eclipse is not yet ready.
|
||||
* </p>
|
||||
* @return a file info object for this file store.
|
||||
*/
|
||||
public IFileInfo fetchInfo() {
|
||||
try {
|
||||
return fetchInfo(EFS.NONE, null);
|
||||
} catch (CoreException e) {
|
||||
if (!isResourcesPluginUp()) {
|
||||
//FIXME HACK workaround for platform bug 182006:
|
||||
//Claim that files do not exist while resources
|
||||
//plugin is not yet fully up.
|
||||
return new FileInfo(getName());
|
||||
}
|
||||
//Whoa! Bad bad... wrapping a checked exception in an unchecked one...
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.core.filesystem.provider.FileStore#fetchInfo(int, org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException {
|
||||
return getImpl().fetchInfo(options, monitor);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.core.filesystem.provider.FileStore#openInputStream(int, org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException
|
||||
{
|
||||
return getImpl().openInputStream(options, monitor);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.core.filesystem.provider.FileStore#toURI()
|
||||
*/
|
||||
public URI toURI() {
|
||||
return RSEFileSystem.getURIFor(getHost(), getAbsolutePath());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.core.filesystem.provider.FileStore#mkdir(int, org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public IFileStore mkdir(int options, IProgressMonitor monitor) throws CoreException
|
||||
{
|
||||
return getImpl().mkdir(options, monitor);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.core.filesystem.provider.FileStore#openOutputStream(int, org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException
|
||||
{
|
||||
return getImpl().openOutputStream(options, monitor);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.core.filesystem.provider.FileStore#delete(int, org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public void delete(int options, IProgressMonitor monitor) throws CoreException
|
||||
{
|
||||
getImpl().delete(options, monitor);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,631 @@
|
|||
/********************************************************************************
|
||||
* 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
|
||||
*
|
||||
* Initial Contributors:
|
||||
* The following IBM employees contributed to the Remote System Explorer
|
||||
* component that contains this file: David McKnight, Kushal Munir,
|
||||
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
|
||||
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
||||
*
|
||||
* 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.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.core.filesystem.EFS;
|
||||
import org.eclipse.core.filesystem.IFileInfo;
|
||||
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.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.rse.core.model.IHost;
|
||||
import org.eclipse.rse.core.model.ISystemRegistry;
|
||||
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.model.RemoteFileUtility;
|
||||
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.rse.ui.RSEUIPlugin;
|
||||
|
||||
/**
|
||||
* Implementation of IFileStore for RSE.
|
||||
*
|
||||
* The RSEFileStore delegates to this impl class in order to defer class
|
||||
* loading until file contents are really needed.
|
||||
*/
|
||||
public class RSEFileStoreImpl extends FileStore
|
||||
{
|
||||
private RSEFileStore _parent;
|
||||
|
||||
//cached IRemoteFile object: an Object to avoid early class loading
|
||||
private transient IRemoteFile _remoteFile;
|
||||
|
||||
/**
|
||||
* Constructor to use if the parent file store is known.
|
||||
* @param parent the parent file store.
|
||||
*/
|
||||
public RSEFileStoreImpl(RSEFileStore parent) {
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.core.filesystem.IFileStore#getChild(java.lang.String)
|
||||
*/
|
||||
public IFileStore getChild(String name) {
|
||||
return _parent.getChild(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.core.filesystem.IFileStore#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return _parent.getName();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.core.filesystem.IFileStore#getParent()
|
||||
*/
|
||||
public IFileStore getParent() {
|
||||
return _parent.getParent();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.core.filesystem.IFileStore#toURI()
|
||||
*/
|
||||
public URI toURI() {
|
||||
return _parent.toURI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the best RSE connection object matching the given host name.
|
||||
*
|
||||
* @param hostNameOrAddr IP address of requested host.
|
||||
* @return RSE connection object matching the given host name, or
|
||||
* <code>null</code> 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()<endTime);
|
||||
//System.out.println("Time: "+ (System.currentTimeMillis()-startTime)+", Iterations: "+iterations);
|
||||
//System.out.println("Dbg Breakpoint");
|
||||
}
|
||||
|
||||
IHost unconnected = null;
|
||||
|
||||
for (int i = 0; i < connections.length; i++) {
|
||||
|
||||
IHost con = connections[i];
|
||||
|
||||
//TODO use more elaborate methods of checking whether two
|
||||
//host names/IP addresses are the same; or, use the host alias
|
||||
if (hostNameOrAddr.equalsIgnoreCase(con.getHostName())) {
|
||||
IRemoteFileSubSystem fss = getRemoteFileSubSystem(con);
|
||||
if (fss!=null && fss.isConnected()) {
|
||||
return con;
|
||||
} else {
|
||||
unconnected = con;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return unconnected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the best available remote file subsystem for a connection.
|
||||
* Criteria are:
|
||||
* <ol>
|
||||
* <li>A connected FileServiceSubsystem</li>
|
||||
* <li>A connected IRemoteFileSubSystem</li>
|
||||
* <li>An unconnected FileServiceSubsystem</li>
|
||||
* <li>An unconnected IRemoteFileSubSystem</li>
|
||||
* </ol>
|
||||
* @param host
|
||||
* @return an IRemoteFileSubSystem for the given connection, or
|
||||
* <code>null</code> 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; i<subSys.length; i++) {
|
||||
if (subSys[i] instanceof FileServiceSubSystem) {
|
||||
if (subSys[i].isConnected()) {
|
||||
//best candidate: service and connected
|
||||
return subSys[i];
|
||||
} else if (serviceCandidate==null) {
|
||||
serviceCandidate = (FileServiceSubSystem)subSys[i];
|
||||
}
|
||||
} else if(candidate==null) {
|
||||
candidate=subSys[i];
|
||||
} else if(subSys[i].isConnected() && !candidate.isConnected()) {
|
||||
candidate=subSys[i];
|
||||
}
|
||||
}
|
||||
//Now find the best candidate
|
||||
if (candidate!=null && candidate.isConnected()) {
|
||||
return candidate;
|
||||
} else if (serviceCandidate!=null) {
|
||||
return serviceCandidate;
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the best connected file subsystem for this file store.
|
||||
* Never returns <code>null</code>.
|
||||
* @param hostNameOrAddr host name or IP address
|
||||
* @param monitor progress monitor
|
||||
* @return The best connected file subsystem for this file store.
|
||||
* @throws CoreException if no file subsystem could be found or connected.
|
||||
*/
|
||||
public static IRemoteFileSubSystem getConnectedFileSubSystem(String hostNameOrAddr, IProgressMonitor monitor) throws CoreException
|
||||
{
|
||||
IHost con = RSEFileStoreImpl.getConnectionFor(hostNameOrAddr, monitor);
|
||||
if (con == null) {
|
||||
throw new CoreException(new Status(IStatus.ERROR,
|
||||
Activator.getDefault().getBundle().getSymbolicName(),
|
||||
"Connection not found for host: "+hostNameOrAddr));
|
||||
}
|
||||
IRemoteFileSubSystem subSys = RSEFileStoreImpl.getRemoteFileSubSystem(con);
|
||||
if (subSys == null) {
|
||||
throw new CoreException(new Status(IStatus.ERROR,
|
||||
Activator.getDefault().getBundle().getSymbolicName(),
|
||||
"No file subsystem found on host: "+hostNameOrAddr+" connection "+con.getAliasName()));
|
||||
}
|
||||
if (!subSys.isConnected()) {
|
||||
try {
|
||||
if (monitor==null) monitor=new NullProgressMonitor();
|
||||
subSys.connect(monitor, false);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR,
|
||||
Activator.getDefault().getBundle().getSymbolicName(),
|
||||
"Could not connect to host: "+hostNameOrAddr+" subsystem "+subSys.getConfigurationId(), e));
|
||||
}
|
||||
}
|
||||
return subSys;
|
||||
}
|
||||
|
||||
private IRemoteFile getCachedRemoteFile() {
|
||||
return _remoteFile;
|
||||
}
|
||||
|
||||
private void cacheRemoteFile(IRemoteFile remoteFile) {
|
||||
//if (_remoteFile != remoteFile) _remoteFile = remoteFile;
|
||||
_remoteFile = remoteFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an IRemoteFile for this file store.
|
||||
* Requires that the file subsystem is connected.
|
||||
* @param monitor progress monitor
|
||||
* @param forceExists if <code>true</code>, 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue