From 8bde9f14de74c48865dd69555dbabf33f243707b Mon Sep 17 00:00:00 2001 From: Kushal Munir < kmunir@ca.ibm.com> Date: Fri, 30 Mar 2007 22:30:01 +0000 Subject: [PATCH] [170916] [efs] Check in changes to EFS so that we do not use cached files since we always want live information in EFS. Also refactor classes to internal package. --- .../META-INF/MANIFEST.MF | 4 +- .../plugin.xml | 8 +- .../eclipse/filesystem/Activator.java | 8 +- .../FileStoreConversionUtility.java | 8 +- .../eclipse/filesystem/RSEFileCache.java | 4 +- .../eclipse/filesystem/RSEFileStore.java | 386 ++++++++++++++++++ .../RSEFileStoreRemoteFileWrapper.java | 220 +--------- .../eclipse/filesystem/RSEFileSystem.java | 99 +++-- .../filesystem/RSEFileSystemContributor.java | 73 ++-- .../CreateRemoteProjectActionDelegate.java | 5 +- 10 files changed, 496 insertions(+), 319 deletions(-) rename rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/{ => internal}/eclipse/filesystem/Activator.java (89%) rename rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/{ => internal}/eclipse/filesystem/FileStoreConversionUtility.java (82%) rename rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/{ => internal}/eclipse/filesystem/RSEFileCache.java (97%) create mode 100644 rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileStore.java rename rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/{ => internal}/eclipse/filesystem/RSEFileStoreRemoteFileWrapper.java (67%) rename rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/{ => internal}/eclipse/filesystem/RSEFileSystem.java (77%) rename rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/{ => internal}/eclipse/filesystem/RSEFileSystemContributor.java (64%) rename rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/{ => internal}/eclipse/filesystem/ui/actions/CreateRemoteProjectActionDelegate.java (96%) diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.eclipse.filesystem/META-INF/MANIFEST.MF index 7413da25f7e..79052c075a5 100644 --- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/META-INF/MANIFEST.MF +++ b/rse/plugins/org.eclipse.rse.eclipse.filesystem/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.rse.eclipse.filesystem; singleton:=true Bundle-Version: 2.0.0.qualifier -Bundle-Activator: org.eclipse.rse.eclipse.filesystem.Activator +Bundle-Activator: org.eclipse.rse.internal.eclipse.filesystem.Activator Bundle-Localization: plugin Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, @@ -18,3 +18,5 @@ Require-Bundle: org.eclipse.ui, Eclipse-LazyStart: true Bundle-Vendor: %providerName Bundle-RequiredExecutionEnvironment: J2SE-1.4 +Export-Package: org.eclipse.rse.internal.eclipse.filesystem;x-internal:=true, + org.eclipse.rse.internal.eclipse.filesystem.ui.actions;x-internal:=true diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/plugin.xml b/rse/plugins/org.eclipse.rse.eclipse.filesystem/plugin.xml index d654957fa42..ce5f95e1ca1 100644 --- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/plugin.xml +++ b/rse/plugins/org.eclipse.rse.eclipse.filesystem/plugin.xml @@ -12,7 +12,7 @@ Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. Contributors: -{Name} (company) - description of contribution. +Kushal Munir (IBM) - Changed paths to reflect internal packages --> @@ -20,7 +20,7 @@ Contributors: id="org.eclipse.rse.eclipse.filesystem" point="org.eclipse.core.filesystem.filesystems"> - + @@ -43,7 +43,7 @@ Contributors: diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/Activator.java b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/Activator.java similarity index 89% rename from rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/Activator.java rename to rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/Activator.java index 0b62f1adcbe..b95707bf1f7 100644 --- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/Activator.java +++ b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/Activator.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2006 IBM Corporation. All rights reserved. + * Copyright (c) 2006, 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 @@ -11,10 +11,10 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * Kushal Munir (IBM) - moved to internal package ********************************************************************************/ -package org.eclipse.rse.eclipse.filesystem; +package org.eclipse.rse.internal.eclipse.filesystem; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.rse.core.RSECorePlugin; @@ -71,6 +71,6 @@ public class Activator extends AbstractUIPlugin { * @return the image descriptor */ public static ImageDescriptor getImageDescriptor(String path) { - return AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.rse.eclipse.filesystem", path); //$NON-NLS-1$ + return AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.rse.internal.eclipse.filesystem", path); //$NON-NLS-1$ } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/FileStoreConversionUtility.java b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/FileStoreConversionUtility.java similarity index 82% rename from rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/FileStoreConversionUtility.java rename to rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/FileStoreConversionUtility.java index c70d66d7233..c2629052f0f 100644 --- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/FileStoreConversionUtility.java +++ b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/FileStoreConversionUtility.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2006 IBM Corporation. All rights reserved. + * Copyright (c) 2006, 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 @@ -12,9 +12,10 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Kushal Munir (IBM) - moved to internal package ********************************************************************************/ -package org.eclipse.rse.eclipse.filesystem; +package org.eclipse.rse.internal.eclipse.filesystem; @@ -26,7 +27,8 @@ public class FileStoreConversionUtility { public static IFileStore convert(IFileStore parent, IRemoteFile remoteFile) { - return new RSEFileStoreRemoteFileWrapper(parent, remoteFile); + // return new RSEFileStoreRemoteFileWrapper(parent, remoteFile); + return new RSEFileStore(parent, remoteFile); } public static IFileStore[] convert(IFileStore parent, IRemoteFile[] remoteFiles) diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/RSEFileCache.java b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileCache.java similarity index 97% rename from rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/RSEFileCache.java rename to rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileCache.java index e754409b45d..f7847e0b540 100644 --- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/RSEFileCache.java +++ b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileCache.java @@ -5,10 +5,10 @@ * available at http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * {Kushal Munir} (IBM) - initial implementation. + * Kushal Munir (IBM) - moved to internal package ********************************************************************************/ -package org.eclipse.rse.eclipse.filesystem; +package org.eclipse.rse.internal.eclipse.filesystem; import java.io.BufferedOutputStream; import java.io.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 new file mode 100644 index 00000000000..cb29c71c11d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileStore.java @@ -0,0 +1,386 @@ +/******************************************************************************** + * Copyright (c) 2006, 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 + * + * 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 + ********************************************************************************/ + +package org.eclipse.rse.internal.eclipse.filesystem; + +import java.io.File; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URI; +import java.net.URISyntaxException; + +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.internal.filesystem.Policy; +import org.eclipse.core.resources.IResource; +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.Status; +import org.eclipse.core.runtime.jobs.Job; +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; + + +public class RSEFileStore extends FileStore implements IFileStore +{ + private IRemoteFile _remoteFile; + private IRemoteFileSubSystem _subSystem; + private IFileStore _parent; + + public RSEFileStore(IFileStore parent, IRemoteFile remoteFile) { + _remoteFile = remoteFile; + _parent = parent; + _subSystem = _remoteFile.getParentRemoteFileSubSystem(); + } + + public IRemoteFileSubSystem getRemoteFileSubSystem() { + return _subSystem; + } + + public String[] childNames(int options, IProgressMonitor monitor) { + + String[] names; + + 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, true); + } + 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; + } + + public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException + { + if (_remoteFile.isStale()) + { + try + { + _remoteFile = _subSystem.getRemoteFileObject(_remoteFile.getAbsolutePath()); + } + catch (Exception e) + { + } + } + + FileInfo info = new FileInfo(getName()); + boolean exists = _remoteFile.exists(); + + info.setExists(exists); + + if (exists) + { + 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()); + } + } + + info.setName(getName()); + return info; + } + + public String getName() + { + return _remoteFile.getName(); + } + + public IFileStore getParent() + { + if (_parent == null) + { + _parent = new RSEFileStore(null, _remoteFile.getParentRemoteFile()); + } + return _parent; + } + + public boolean isParentOf(IFileStore other) + { + if (other instanceof RSEFileStore) + { + RSEFileStore otherWrapper = (RSEFileStore)other; + RSEFileStore parent = (RSEFileStore)otherWrapper.getParent(); + return _remoteFile == parent._remoteFile; + } + else + { + return false; + } + } + + public synchronized InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException + { + if (_remoteFile.exists()) + { + if (_remoteFile.isFile() && _subSystem.isConnected() && _subSystem instanceof IFileServiceSubSystem) + { + IFileServiceSubSystem fileSubSystem = (IFileServiceSubSystem)_subSystem; + + try { + return fileSubSystem.getFileService().getInputStream(monitor, _remoteFile.getParentPath(), _remoteFile.getName(), true); + } + catch (SystemMessageException e) { + return null; + } + } + + if (_remoteFile.isDirectory()) { + throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "This is a directory")); //$NON-NLS-1$ + } + } + return null; + } + + public class RefreshJob extends Job + { + private IResource _resource; + private int _depth; + public RefreshJob(IResource resource, int depth) + { + super("Refresh"); //$NON-NLS-1$ + _resource = resource; + _depth = depth; + } + + public IStatus run(IProgressMonitor monitor) + { + try + { + _resource.refreshLocal(_depth, monitor); + } + catch (Exception e) + { + e.printStackTrace(); + } + return Status.OK_STATUS; + } + } + + public URI toURI() + { + try + { + String path = _remoteFile.getAbsolutePath(); + 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); + } + } + + public IFileStore mkdir(int options, IProgressMonitor monitor) throws CoreException + { + if (!_remoteFile.exists()) + { + try + { + _subSystem.createFolder(_remoteFile); + _remoteFile = _subSystem.getRemoteFileObject(_remoteFile.getAbsolutePath()); + } + catch (Exception e) + { + } + } + return this; + } + + public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException { + monitor = Policy.monitorFor(monitor); + + try { + if (!_remoteFile.exists()) + { + _subSystem.createFile(_remoteFile); + _remoteFile = _subSystem.getRemoteFileObject(_remoteFile.getAbsolutePath()); + } + } + catch (Exception e) { + return null; + } + + if (_remoteFile.isFile() && _subSystem instanceof FileServiceSubSystem) { + IFileServiceSubSystem fileSubSystem = (IFileServiceSubSystem)_subSystem; + + try { + return fileSubSystem.getFileService().getOutputStream(monitor, _remoteFile.getParentPath(), _remoteFile.getName(), true); + } + catch (SystemMessageException e) { + return null; + } + } + 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(IPath path) + { + IFileStore result = this; + for (int i = 0, imax = path.segmentCount(); i < imax; i++) + { + String segment = path.segment(i); + result = result.getChild(segment); + } + + return result; + } + + public IFileStore getChild(String name) + { + if (!_remoteFile.isStale() && _remoteFile.hasContents(RemoteChildrenContentsType.getInstance(), name)) + { + Object[] children = _remoteFile.getContents(RemoteChildrenContentsType.getInstance(), name); + if (children != null && children.length > 0) + { + return FileStoreConversionUtility.convert(_parent, (IRemoteFile)children[0]); + } + else + { + // need empty one + try + { + IRemoteFile child = _subSystem.getRemoteFileObject(_remoteFile, name); + return FileStoreConversionUtility.convert(_parent, child); + } + catch (Exception e) + { + + } + } + } + else if (_remoteFile.isDirectory()) + { + try + { + IRemoteFile child = _subSystem.getRemoteFileObject(_remoteFile, name); + return FileStoreConversionUtility.convert(_parent, child); + } + catch (Exception e) + { + + } + + } + return null; + } + + public File toLocalFile(int options, IProgressMonitor monitor) throws CoreException + { + if (options == EFS.CACHE) { + return super.toLocalFile(options, monitor); + } + else { + if (_remoteFile.exists() && _subSystem instanceof IFileServiceSubSystem) + { + RSEFileCache cache = RSEFileCache.getInstance(); + IFileServiceSubSystem fileServiceSubSystem = (IFileServiceSubSystem)_subSystem; + InputStream inputStream = null; + + try { + + if (_remoteFile.isFile()) { + inputStream = fileServiceSubSystem.getFileService().getInputStream(monitor, _remoteFile.getParentRemoteFileSubSystem().getHost().getHostName(), _remoteFile.getName(), true); + } + + return cache.writeToCache(_remoteFile, inputStream); + } + catch (SystemMessageException e) { + return null; + } + } + else { + return null; + } + } + } + + public void delete(int options, IProgressMonitor monitor) throws CoreException + { + try { + _subSystem.delete(_remoteFile, monitor); + } + catch (Exception e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/RSEFileStoreRemoteFileWrapper.java b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileStoreRemoteFileWrapper.java similarity index 67% rename from rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/RSEFileStoreRemoteFileWrapper.java rename to rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileStoreRemoteFileWrapper.java index 4c2c519084c..b6ee0037833 100644 --- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/RSEFileStoreRemoteFileWrapper.java +++ b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileStoreRemoteFileWrapper.java @@ -11,15 +11,12 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * Kushal Munir (IBM) - moved to internal package ********************************************************************************/ -package org.eclipse.rse.eclipse.filesystem; +package org.eclipse.rse.internal.eclipse.filesystem; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URI; @@ -31,9 +28,6 @@ import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.filesystem.provider.FileInfo; import org.eclipse.core.filesystem.provider.FileStore; import org.eclipse.core.internal.filesystem.Policy; -import org.eclipse.core.internal.resources.ModelObjectWriter; -import org.eclipse.core.internal.resources.ProjectDescription; -import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -57,25 +51,23 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto private IRemoteFile _remoteFile; private IRemoteFileSubSystem _subSystem; private IFileStore _parent; - public RSEFileStoreRemoteFileWrapper(IFileStore parent, IRemoteFile remoteFile) - { + + public RSEFileStoreRemoteFileWrapper(IFileStore parent, IRemoteFile remoteFile) { _remoteFile = remoteFile; _parent = parent; _subSystem = _remoteFile.getParentRemoteFileSubSystem(); } - public IRemoteFileSubSystem getRemoteFileSubSystem() - { + public IRemoteFileSubSystem getRemoteFileSubSystem() { return _subSystem; } - public String[] childNames(int options, IProgressMonitor monitor) - { + public String[] childNames(int options, IProgressMonitor monitor) { IPreferenceStore prefStore = RSEUIPlugin.getDefault().getPreferenceStore(); - //boolean origShowHidden = prefStore.getBoolean(ISystemPreferencesConstants.SHOWHIDDEN); prefStore.setValue(ISystemFilePreferencesConstants.SHOWHIDDEN, true); String[] names; + if (!_remoteFile.isStale() && _remoteFile.hasContents(RemoteChildrenContentsType.getInstance())) { Object[] children = _remoteFile.getContents(RemoteChildrenContentsType.getInstance()); @@ -120,16 +112,9 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto } FileInfo info = new FileInfo(getName()); boolean exists = _remoteFile.exists(); - /* - if (_remoteFile.getName().equals(".project") && _remoteFile.getLength() == 0) - { - info.setExists(false); - } - else - */ - { - info.setExists(exists); - } + + info.setExists(exists); + if (exists) { info.setLastModified(_remoteFile.getLastModified()); @@ -154,6 +139,7 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto { return _remoteFile.getName(); } + public IFileStore getParent() { if (_parent == null) @@ -181,7 +167,6 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto { if (_remoteFile.exists()) { - // IFile file = null; if (_remoteFile.isFile() && _subSystem.isConnected() && _subSystem instanceof IFileServiceSubSystem) { IFileServiceSubSystem fileSubSystem = (IFileServiceSubSystem)_subSystem; @@ -197,96 +182,6 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto if (_remoteFile.isDirectory()) { throw new CoreException(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), "This is a directory")); //$NON-NLS-1$ } - -/* if (_remoteFile.getName().equals(".project") && _remoteFile.getLength() == 0) //$NON-NLS-1$ - { - System.out.println("reading empty .project"); //$NON-NLS-1$ - InputStream stream = getDummyProjectFileStream(); - try - { - int size = stream.available(); - _subSystem.upload(stream, size, _remoteFile, "utf8", monitor); //$NON-NLS-1$ - _remoteFile = _subSystem.getRemoteFileObject(_remoteFile.getAbsolutePath()); - - } - catch (Exception e) - { - } - //return stream; - - try - { - // only temp file has contents - file = (IFile)UniversalFileTransferUtility.getTempFileFor(_remoteFile); - if (file == null || !file.exists()) - { - file.create(null, true, monitor); - } - } - catch (Exception e) - { - e.printStackTrace(); - } - - } - - { - file = (IFile)UniversalFileTransferUtility.copyRemoteResourceToWorkspace(_remoteFile, monitor); - - if (file != null && !file.isSynchronized(IResource.DEPTH_ZERO)) - { - RefreshJob refresh = new RefreshJob(file, IResource.DEPTH_ZERO); - refresh.schedule(); - try - { - refresh.join(); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - } - } - else - { - file = (IFile)UniversalFileTransferUtility.getTempFileFor(_remoteFile); - } - if (file != null && !file.isSynchronized(IResource.DEPTH_ZERO) && !_remoteFile.getName().equals(".project")) //$NON-NLS-1$ - { - RefreshJob refresh = new RefreshJob(file, IResource.DEPTH_ZERO); - refresh.schedule(); - try - { - refresh.join(); - } - catch (Exception e) - { - e.printStackTrace(); - } - - - } - if (file != null) - { - if (file.isSynchronized(IResource.DEPTH_ZERO)) - { - return file.getContents(); - } - else - { - File osFile = file.getLocation().toFile(); - try - { - FileInputStream instream = new FileInputStream(osFile); - return instream; - } - catch (Exception e) - { - - } - } - }*/ } return null; } @@ -297,7 +192,7 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto private int _depth; public RefreshJob(IResource resource, int depth) { - super("Refresh"); + super("Refresh"); //$NON-NLS-1$ _resource = resource; _depth = depth; } @@ -316,25 +211,6 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto } } - private InputStream getDummyProjectFileStream() - { - - IProjectDescription description = new ProjectDescription(); -// write the model to a byte array - ByteArrayOutputStream out = new ByteArrayOutputStream(); - try { - new ModelObjectWriter().write(description, out); - } catch (IOException e) { - - } - byte[] newContents = out.toByteArray(); - - ByteArrayInputStream in = new ByteArrayInputStream(newContents); - - return in; - } - - public URI toURI() { try @@ -370,9 +246,6 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException { monitor = Policy.monitorFor(monitor); - // File file = null; - // try { - // create temp file first try { if (!_remoteFile.exists()) @@ -404,36 +277,6 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto return null; } } - -/* SystemEditableRemoteFile editable = new SystemEditableRemoteFile(_remoteFile); - editable.download(monitor); - IFile localFile = editable.getLocalResource(); - file = localFile.getLocation().toFile(); - - monitor.beginTask(null, 1); - - return new FileOutputStream(file, (options & EFS.APPEND) != 0); - } - catch (FileNotFoundException e) - { - //checkReadOnlyParent(file, e); - String message; - String path = _remoteFile.getAbsolutePath(); - if (file != null && file.isDirectory()) - message = NLS.bind(Messages.notAFile, path); - else - message = NLS.bind(Messages.couldNotWrite, path); - Policy.error(EFS.ERROR_WRITE, message, e); - return null; - } - catch (Exception e) - { - e.printStackTrace(); - } - finally { - monitor.done(); - } - return null;*/ } public IFileStore getChild(IPath path) @@ -515,49 +358,14 @@ public class RSEFileStoreRemoteFileWrapper extends FileStore implements IFileSto return null; } } - - - /*if (_remoteFile.isFile() && _subSystem.isConnected()) - { - file = (IResource)UniversalFileTransferUtility.copyRemoteResourceToWorkspace(_remoteFile, monitor); - } - else - { - file = UniversalFileTransferUtility.getTempFileFor(_remoteFile); - } - // if (!file.isSynchronized(IFile.DEPTH_ZERO)) - // file.refreshLocal(IFile.DEPTH_ZERO, monitor); - return file.getLocation().toFile(); - } - else - { - if (_remoteFile.getName().equals(".project")) //$NON-NLS-1$ - { - file = UniversalFileTransferUtility.getTempFileFor(_remoteFile); - return file.getLocation().toFile(); - } - else if (_remoteFile instanceof RemoteFileEmpty) - { - try - { - return File.createTempFile(_remoteFile.getName(), "empty"); //$NON-NLS-1$ - } - catch (Exception e) - { - - } - } - }*/ } public void delete(int options, IProgressMonitor monitor) throws CoreException { - try - { + try { _subSystem.delete(_remoteFile, monitor); } - catch (Exception e) - { + catch (Exception e) { e.printStackTrace(); } } diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/RSEFileSystem.java b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileSystem.java similarity index 77% rename from rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/RSEFileSystem.java rename to rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileSystem.java index 151e1e76456..4d101b766ee 100644 --- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/RSEFileSystem.java +++ b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileSystem.java @@ -12,9 +12,10 @@ * * Contributors: * David Dykstal (IBM) - 168977: refactoring IConnectorService and ServerLauncher hierarchies + * Kushal Munir (IBM) - moved to internal package ********************************************************************************/ -package org.eclipse.rse.eclipse.filesystem; +package org.eclipse.rse.internal.eclipse.filesystem; import java.net.URI; import java.util.HashMap; @@ -36,122 +37,118 @@ public class RSEFileSystem extends FileSystem private static RSEFileSystem _instance = new RSEFileSystem(); private HashMap _fileStoreMap; - public RSEFileSystem() - { + public RSEFileSystem() { + super(); _fileStoreMap = new HashMap(); } - public static RSEFileSystem getInstance() - { + public static RSEFileSystem getInstance() { return _instance; } - public boolean canDelete() - { + public boolean canDelete() { return true; } - public boolean canWrite() - { + public boolean canWrite() { return true; } - public static IHost getConnectionFor(String hostName) - { + 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++) - { + + for (int i = 0; i < connections.length; i++) { + IHost con = connections[i]; - if (con.getHostName().equalsIgnoreCase(hostName)) - { + + 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) + + if (isConnected) { return con; - else + } + else { unconnected = con; + } } } + return unconnected; } - public static IRemoteFileSubSystem getRemoteFileSubSystem(IHost host) - { + public static IRemoteFileSubSystem getRemoteFileSubSystem(IHost host) { return RemoteFileUtility.getFileSubSystem(host); } - public URI getURIFor(IRemoteFile file) - { + public URI getURIFor(IRemoteFile file) { IFileStore fstore = FileStoreConversionUtility.convert(null, file); return fstore.toURI(); } - public IFileStore getStore(URI uri) - { + public IFileStore getStore(URI uri) { + Object obj = _fileStoreMap.get(uri); - if (obj != null) - { - RSEFileStoreRemoteFileWrapper store = (RSEFileStoreRemoteFileWrapper)obj; + + if (obj != null) { + + // RSEFileStoreRemoteFileWrapper store = (RSEFileStoreRemoteFileWrapper)obj; + RSEFileStore store = (RSEFileStore)obj; + IRemoteFileSubSystem ss = store.getRemoteFileSubSystem(); - if (!ss.isConnected()) - { + + if (!ss.isConnected()) { - try - { + try { ss.connect(); } - catch (Exception e) - { + catch (Exception e) { return null; } } return store; } - try - { + + try { + String path = uri.getPath(); String hostName = uri.getHost(); IHost con = getConnectionFor(hostName); - if (con != null) - { + + if (con != null) { + IRemoteFileSubSystem fs = getRemoteFileSubSystem(con); - if (fs != null) - { - - if (!fs.isConnected()) - { - + + if (fs != null) { + if (!fs.isConnected()) { fs.getConnectorService().acquireCredentials(false); fs.getConnectorService().connect(new NullProgressMonitor()); - //fs.connect(shell); } - if (fs.isConnected()) - { + + if (fs.isConnected()) { IFileStore fstore = FileStoreConversionUtility.convert(null, fs.getRemoteFileObject(path)); _fileStoreMap.put(uri, fstore); return fstore; } - } } } - catch (Exception e) - { + catch (Exception e) { e.printStackTrace(); return EFS.getNullFileSystem().getStore(uri); - - //return FileStoreConversionUtility.convert(null, new RemoteFileEmpty()); } return null; } - } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/RSEFileSystemContributor.java b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileSystemContributor.java similarity index 64% rename from rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/RSEFileSystemContributor.java rename to rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileSystemContributor.java index 77c09484fc0..2061a76177c 100644 --- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/RSEFileSystemContributor.java +++ b/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/RSEFileSystemContributor.java @@ -11,11 +11,11 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * Kushal Munir (IBM) - moved to internal package. ********************************************************************************/ -package org.eclipse.rse.eclipse.filesystem; +package org.eclipse.rse.internal.eclipse.filesystem; import java.net.URI; @@ -29,69 +29,51 @@ import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.ide.fileSystem.FileSystemContributor; -import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils; public class RSEFileSystemContributor extends FileSystemContributor { - public URI browseFileSystem(String initialPath, Shell shell) - { - SystemRemoteFolderDialog dlg = new SystemRemoteFolderDialog(shell, "Select Folder"); + public URI browseFileSystem(String initialPath, Shell shell) { + SystemRemoteFolderDialog dlg = new SystemRemoteFolderDialog(shell, "Select Folder"); //$NON-NLS-1$ - //SystemSelectRemoteFileOrFolderDialog dlg = new SystemSelectRemoteFileOrFolderDialog(shell, "Select File", false); - /* - DirectoryDialog dialog = new DirectoryDialog(shell); - dialog - .setMessage(IDEWorkbenchMessages.ProjectLocationSelectionDialog_directoryLabel); - */ - if (!initialPath.equals(IDEResourceInfoUtils.EMPTY_STRING)) - { - try - { - URI uri = new URI(initialPath); - IHost host = RSEFileSystem.getConnectionFor(uri.getHost()); - IRemoteFileSubSystem fs = RSEFileSystem.getRemoteFileSubSystem(host); - dlg.setInputObject(fs.getRemoteFileObject(uri.getPath())); + if (!initialPath.equals("")) { //$NON-NLS-1$ + + try { + URI uri = new URI(initialPath); + IHost host = RSEFileSystem.getConnectionFor(uri.getHost()); + IRemoteFileSubSystem fs = RSEFileSystem.getRemoteFileSubSystem(host); + dlg.setInputObject(fs.getRemoteFileObject(uri.getPath())); } - catch (Exception e) - { - + catch (Exception e) { } } dlg.setNeedsProgressMonitor(true); - /* - String selectedDirectory = dialog.open(); - if (selectedDirectory == null) { - return null; - } - return new File(selectedDirectory).toURI(); - */ - if (dlg.open() == Window.OK) - { + if (dlg.open() == Window.OK) { + Object selected = dlg.getSelectedObject(); - if (selected instanceof ISystemFilterReference) - { + + if (selected instanceof ISystemFilterReference) { + ISubSystem targetSubSystem = ((ISystemFilterReference)selected).getSubSystem(); ISubSystemConfiguration factory = targetSubSystem.getSubSystemConfiguration(); - if (factory.supportsDropInFilters()) - { + + if (factory.supportsDropInFilters()) { selected = targetSubSystem.getTargetForFilter((ISystemFilterReference)selected); } } + IRemoteFile file = (IRemoteFile)selected; String path = file.getAbsolutePath(); IHost host = dlg.getSelectedConnection(); String hostName = host.getHostName(); - try - { + + try { return new URI("rse", hostName, path, null); //$NON-NLS-1$ } - catch (Exception e) - { - + catch (Exception e) { } } return null; @@ -99,13 +81,12 @@ public class RSEFileSystemContributor extends FileSystemContributor { } public URI getURI(String string){ - try - { + + try { return new URI(string); } - catch (Exception e) - { + catch (Exception e) { } return null; } -} +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/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 similarity index 96% rename from rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/eclipse/filesystem/ui/actions/CreateRemoteProjectActionDelegate.java rename to rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/internal/eclipse/filesystem/ui/actions/CreateRemoteProjectActionDelegate.java index a1206ffc86d..63a570f3b2b 100644 --- a/rse/plugins/org.eclipse.rse.eclipse.filesystem/src/org/eclipse/rse/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 @@ -12,9 +12,10 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Kushal Munir (IBM) - moved to internal package ********************************************************************************/ -package org.eclipse.rse.eclipse.filesystem.ui.actions; +package org.eclipse.rse.internal.eclipse.filesystem.ui.actions; import java.net.URI; import java.util.Iterator; @@ -32,7 +33,7 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.rse.core.SystemBasePlugin; -import org.eclipse.rse.eclipse.filesystem.RSEFileSystem; +import org.eclipse.rse.internal.eclipse.filesystem.RSEFileSystem; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell;