From 76eaebbe4164dfb55af04faec54eb60fed177df7 Mon Sep 17 00:00:00 2001 From: David Dykstal Date: Mon, 10 Apr 2006 21:04:06 +0000 Subject: [PATCH] initial population --- .../.classpath | 8 + .../.cvsignore | 1 + .../org.eclipse.rse.services.dstore/.project | 28 + .../META-INF/MANIFEST.MF | 29 + .../about.html | 22 + .../about.properties | 25 + .../build.properties | 16 + .../exportDstore.jardesc | 14 + .../exportDstoreMiners.jardesc | 14 + .../exportclientserver.jardesc | 14 + .../universal/miners/ICancellableHandler.java | 29 + .../miners/IUniversalDataStoreConstants.java | 103 + .../dstore/universal/miners/ServerLogger.java | 180 + .../miners/UniversalServerUtilities.java | 102 + .../miners/command/CommandMiner.java | 267 ++ .../miners/command/CommandMinerThread.java | 1218 +++++++ .../miners/command/OutputHandler.java | 398 +++ .../miners/command/ProcessTracker.java | 441 +++ .../miners/command/QueryPathThread.java | 148 + .../command/patterns/CommandPattern.java | 77 + .../command/patterns/OutputPattern.java | 106 + .../miners/command/patterns/ParsedOutput.java | 40 + .../miners/command/patterns/Patterns.java | 314 ++ .../miners/environment/EnvironmentMiner.java | 232 ++ .../miners/filesystem/ClassFileParser.java | 155 + .../miners/filesystem/FileClassifier.java | 1036 ++++++ .../UniversalByteStreamHandler.java | 348 ++ .../filesystem/UniversalDownloadHandler.java | 267 ++ .../filesystem/UniversalFileSystemFilter.java | 124 + .../filesystem/UniversalFileSystemMiner.java | 3120 +++++++++++++++++ .../filesystem/UniversalSearchHandler.java | 382 ++ .../IUniversalProcessDataStoreConstants.java | 41 + .../miners/processes/ProcessDEComparator.java | 57 + .../processes/UniversalProcessMiner.java | 397 +++ .../plugin.properties | 12 + .../serverruntime/.cvsignore | 1 + .../serverruntime/auth.pl | 57 + .../serverruntime/daemon.linux | 44 + .../serverruntime/daemon.unix | 42 + .../serverruntime/daemon.win.bat | 2 + .../serverruntime/minerFile.dat | 4 + .../serverruntime/patterns.dat | 269 ++ .../serverruntime/rsecomm.properties | 25 + .../serverruntime/run.win.bat | 27 + .../serverruntime/server.aix | 7 + .../serverruntime/server.linux | 41 + .../serverruntime/server.unix | 5 + .../serverruntime/server.zseries | 11 + .../serverruntime/setup.env.zseries | 14 + .../serverruntime/win.env.bat | 8 + .../dstore/shell/DStoreShellOutputReader.java | 156 + .../dstore/shell/DStoreShellThread.java | 264 ++ .../dstore/AbstractDStoreService.java | 304 ++ .../rse/services/dstore/Activator.java | 70 + .../rse/services/dstore/IDStoreService.java | 22 + .../rse/services/dstore/ServiceResources.java | 42 + .../dstore/ServiceResources.properties | 30 + .../dstore/files/DStoreFileService.java | 1166 ++++++ .../services/dstore/files/DStoreHostFile.java | 276 ++ .../dstore/files/DStoreVirtualHostFile.java | 78 + .../dstore/processes/DStoreHostProcess.java | 519 +++ .../processes/DStoreProcessService.java | 338 ++ .../DStoreRemoteServiceService.java | 42 + .../DStoreSearchResultConfiguration.java | 51 + .../dstore/search/DStoreSearchService.java | 144 + .../dstore/shells/DStoreHostShell.java | 72 + .../dstore/shells/DStoreShellService.java | 201 ++ .../DStoreFileTransferStatusListener.java | 122 + .../dstore/util/DStoreStatusMonitor.java | 399 +++ .../dstore/util/DownloadListener.java | 335 ++ .../dstore/util/FileSystemMessageUtil.java | 37 + .../dstore/util/StatusChangeListener.java | 330 ++ .../.classpath | 7 + .../.cvsignore | 1 + .../.project | 28 + .../META-INF/MANIFEST.MF | 14 + .../about.html | 22 + .../about.properties | 25 + .../build.properties | 12 + .../plugin.properties | 12 + .../rse/services/files/ftp/Activator.java | 70 + .../services/files/ftp/FTPClientService.java | 37 + .../rse/services/files/ftp/FTPHostFile.java | 135 + .../ftp/FTPLinuxDirectoryListingParser.java | 80 + .../rse/services/files/ftp/FTPService.java | 396 +++ .../files/ftp/FTPServiceResources.java | 32 + .../files/ftp/FTPServiceResources.properties | 18 + .../files/ftp/IFTPDirectoryListingParser.java | 36 + .../rse/services/files/ftp/IFTPService.java | 22 + .../org.eclipse.rse.services.local/.classpath | 7 + .../org.eclipse.rse.services.local/.cvsignore | 1 + .../org.eclipse.rse.services.local/.project | 28 + .../META-INF/MANIFEST.MF | 20 + .../org.eclipse.rse.services.local/about.html | 22 + .../about.properties | 25 + .../build.properties | 12 + .../patterns.dat | 269 ++ .../plugin.properties | 12 + .../local/search/LocalSearchResult.java | 29 + .../services/local/shells/CommandPattern.java | 60 + .../local/shells/LocalShellOutputReader.java | 136 + .../local/shells/LocalShellThread.java | 493 +++ .../services/local/shells/OutputPattern.java | 98 + .../services/local/shells/ParsedOutput.java | 38 + .../services/local/shells/Patterns.java | 216 ++ .../eclipse/rse/services/local/Activator.java | 70 + .../rse/services/local/ILocalService.java | 22 + .../local/files/LocalFileService.java | 1167 ++++++ .../services/local/files/LocalHostFile.java | 120 + .../local/files/LocalServiceResources.java | 37 + .../files/LocalServiceResources.properties | 23 + .../local/files/LocalVirtualHostFile.java | 91 + .../local/processes/LocalProcessService.java | 151 + .../local/search/LocalSearchHandler.java | 504 +++ .../local/search/LocalSearchService.java | 39 + .../rse/services/local/shells/Activator.java | 70 + .../services/local/shells/LocalHostShell.java | 81 + .../local/shells/LocalShellService.java | 144 + .../org.eclipse.rse.shells.ui/.classpath | 7 + .../org.eclipse.rse.shells.ui/.cvsignore | 1 + .../org.eclipse.rse.shells.ui/.project | 28 + .../META-INF/MANIFEST.MF | 29 + .../org.eclipse.rse.shells.ui/about.html | 22 + .../build.properties | 14 + .../icons/full/cview16/commands_view.gif | Bin 0 -> 347 bytes .../icons/full/cview16/errorlist_view.gif | Bin 0 -> 604 bytes .../icons/full/eview16/commands_view.gif | Bin 0 -> 347 bytes .../icons/full/eview16/errorlist_view.gif | Bin 0 -> 604 bytes .../icons/full/obj16/exportshellhistory.gif | Bin 0 -> 592 bytes .../icons/full/obj16/exportshelloutput.gif | Bin 0 -> 613 bytes .../icons/full/obj16/systemcommands_obj.gif | Bin 0 -> 578 bytes .../full/obj16/systemcommandslive_obj.gif | Bin 0 -> 589 bytes .../icons/full/obj16/systemshell.gif | Bin 0 -> 357 bytes .../icons/full/obj16/systemshelllive.gif | Bin 0 -> 366 bytes .../icons/full/view16/commands_view.gif | Bin 0 -> 347 bytes .../icons/full/view16/errorlist_view.gif | Bin 0 -> 604 bytes .../plugin.properties | 30 + .../org.eclipse.rse.shells.ui/plugin.xml | 91 + .../org/eclipse/rse/shells/ui/Activator.java | 93 + .../rse/shells/ui/RemoteCommandHelpers.java | 186 + .../eclipse/rse/shells/ui/ShellResources.java | 88 + .../rse/shells/ui/ShellResources.properties | 80 + .../ui/SystemRemoteCommandEntryForm.java | 285 ++ .../ui/actions/LaunchShellActionDelegate.java | 53 + .../ui/actions/SystemBaseShellAction.java | 85 + .../ui/actions/SystemCommandAction.java | 569 +++ .../SystemExportShellHistoryAction.java | 88 + .../SystemExportShellOutputAction.java | 94 + .../actions/SystemShowInShellViewAction.java | 57 + .../SystemTerminateRemoveShellAction.java | 61 + .../actions/SystemTerminateShellAction.java | 93 + .../EnvironmentVariablesPropertyPage.java | 150 + .../ShellServicesPropertyPage.java | 109 + .../SystemShellPropertyPage.java | 142 + .../CommandEntryContentAssistProcessor.java | 635 ++++ .../view/CommandEntryViewerConfiguration.java | 87 + .../rse/shells/ui/view/CommandsViewPage.java | 654 ++++ .../shells/ui/view/CommandsViewWorkbook.java | 249 ++ .../rse/shells/ui/view/EncodingForm.java | 174 + .../ISystemCommandTextModifyListener.java | 35 + .../ShellServiceSubSystemFactoryAdapter.java | 138 + ...ServiceSubsystemFactoryAdapterFactory.java | 60 + .../shells/ui/view/SystemBuildErrorView.java | 177 + .../ui/view/SystemBuildErrorViewPart.java | 487 +++ .../ui/view/SystemBuildErrorViewProvider.java | 124 + .../shells/ui/view/SystemCommandEditor.java | 490 +++ .../rse/shells/ui/view/SystemCommandsUI.java | 100 + .../shells/ui/view/SystemCommandsView.java | 359 ++ .../ui/view/SystemCommandsViewPart.java | 878 +++++ .../ui/view/SystemCommandsViewProvider.java | 37 + .../view/SystemViewOutputAdapterFactory.java | 84 + .../ui/view/SystemViewRemoteErrorAdapter.java | 121 + .../view/SystemViewRemoteOutputAdapter.java | 1157 ++++++ .../rse/shells/ui/view/TabFolderLayout.java | 61 + .../.classpath | 7 + .../.cvsignore | 1 + .../.project | 28 + .../META-INF/MANIFEST.MF | 21 + .../about.html | 22 + .../build.properties | 10 + .../plugin.properties | 12 + .../core/AbstractJavaLanguageUtility.java | 34 + .../files/core/AbstractLanguageUtility.java | 72 + .../core/AbstractLanguageUtilityFactory.java | 59 + .../files/core/IJavaLanguageUtility.java | 32 + .../files/core/ILanguageUtility.java | 55 + .../files/core/ILanguageUtilityFactory.java | 44 + .../files/core/SystemFileAPIProviderImpl.java | 185 + .../SystemFileSubSystemAPIProviderImpl.java | 109 + ...emFileSubSystemFactoryAPIProviderImpl.java | 132 + .../core/SystemRemoteDirectoryMatcher.java | 61 + .../rse/subsystems/files/core/Activator.java | 70 + .../files/core/SystemFileResources.java | 185 + .../files/core/SystemFileResources.properties | 218 ++ .../files/core/model/IRemotePath.java | 90 + .../core/model/ISystemFileAPIProvider.java | 41 + .../core/model/ISystemFileRemoteTypes.java | 66 + .../model/ISystemFileTransferModeMapping.java | 62 + .../ISystemFileTransferModeRegistry.java | 99 + .../core/model/ISystemRemoteCommand.java | 34 + .../model/ISystemRemoteCommandMessage.java | 26 + .../core/model/RemoteFileFilterString.java | 402 +++ .../files/core/model/RemoteFileUtility.java | 80 + .../files/core/model/RemotePath.java | 244 ++ .../files/core/model/RemotePathUtil.java | 135 + .../model/SystemFileTransferModeMapping.java | 144 + .../model/SystemFileTransferModeRegistry.java | 592 ++++ .../servicesubsystem/AbstractRemoteFile.java | 203 ++ .../FileServiceSubSystem.java | 786 +++++ .../FileServiceSubSystemConfiguration.java | 82 + .../IFileServiceSubSystem.java | 44 + .../IFileServiceSubSystemConfiguration.java | 43 + .../core/servicesubsystem/OutputRefresh.java | 51 + .../core/servicesubsystem/SearchJob.java | 56 + .../IHostFileToRemoteFileAdapter.java | 28 + .../files/core/subsystems/IRemoteFile.java | 289 ++ .../core/subsystems/IRemoteFileContext.java | 68 + .../subsystems/IRemoteFileExceptionCodes.java | 27 + .../IRemoteFileExceptionMessages.java | 37 + .../core/subsystems/IRemoteFileFactory.java | 42 + .../core/subsystems/IRemoteFileSubSystem.java | 717 ++++ .../IRemoteFileSubSystemConfiguration.java | 111 + .../core/subsystems/IRemoteFileWrapper.java | 23 + .../subsystems/IRemoteSearchConstants.java | 40 + .../core/subsystems/IRemoteSearchResult.java | 78 + .../core/subsystems/IVirtualRemoteFile.java | 29 + .../files/core/subsystems/RemoteFile.java | 1052 ++++++ .../RemoteFileCancelledException.java | 40 + .../RemoteFileChildrenContentsType.java | 50 + .../subsystems/RemoteFileCodeException.java | 99 + .../core/subsystems/RemoteFileContext.java | 149 + .../core/subsystems/RemoteFileEmpty.java | 202 ++ .../core/subsystems/RemoteFileException.java | 116 + .../subsystems/RemoteFileIOException.java | 42 + .../files/core/subsystems/RemoteFileRoot.java | 178 + .../subsystems/RemoteFileSchedulingRule.java | 75 + .../RemoteFileSecurityException.java | 40 + .../core/subsystems/RemoteFileSubSystem.java | 1699 +++++++++ .../RemoteFileSubSystemConfiguration.java | 491 +++ .../RemoteFolderChildrenContentsType.java | 50 + .../RemoteFolderNotEmptyException.java | 41 + .../core/subsystems/RemoteSearchResult.java | 248 ++ .../RemoteSearchResultConfiguration.java | 210 ++ .../RemoteSearchResultsContentsType.java | 50 + .../core/util/SystemRemoteFileMatcher.java | 93 + .../core/util/ValidatorFileFilterString.java | 210 ++ .../core/util/ValidatorFileUniqueName.java | 157 + .../.classpath | 7 + .../.cvsignore | 1 + .../.project | 28 + .../META-INF/MANIFEST.MF | 23 + .../about.html | 22 + .../build.properties | 14 + .../icons/full/obj16/systemfiles_obj.gif | Bin 0 -> 157 bytes .../icons/full/obj16/systemfileslive_obj.gif | Bin 0 -> 224 bytes .../plugin.properties | 20 + .../plugin.xml | 47 + .../subsystems/files/dstore/Activator.java | 69 + .../files/dstore/model/DStoreFile.java | 65 + .../files/dstore/model/DStoreFileAdapter.java | 125 + .../dstore/model/DStoreSearchResult.java | 77 + .../files/dstore/model/DStoreVirtualFile.java | 76 + .../files/dstore/old/DownloadListener.java | 369 ++ .../old/FileTransferStatusListener.java | 124 + .../old/SearchResultsChangeListener.java | 400 +++ .../dstore/old/StatusChangeListener.java | 482 +++ ...ersalSearchResultConfigurationFactory.java | 58 + ...niversalSearchResultConfigurationImpl.java | 63 + .../DStoreFileSubSystemConfiguration.java | 164 + ...ileSubSystemSearchResultConfiguration.java | 143 + .../subsystem/DStoreJavaLanguageUtility.java | 79 + .../DStoreLanguageUtilityFactory.java | 79 + ...toreWindowsFileSubSystemConfiguration.java | 74 + .../RemoteFilePropertyChangeListener.java | 281 ++ .../.classpath | 7 + .../.cvsignore | 1 + .../.project | 28 + .../META-INF/MANIFEST.MF | 20 + .../about.html | 22 + .../build.properties | 14 + .../icons/full/obj16/systemfiles_obj.gif | Bin 0 -> 157 bytes .../icons/full/obj16/systemfileslive_obj.gif | Bin 0 -> 224 bytes .../plugin.properties | 20 + .../plugin.xml | 37 + .../rse/subsystems/files/ftp/Activator.java | 73 + .../ftp/FTPFileSubSystemConfiguration.java | 155 + .../connectorservice/FTPConnectorService.java | 87 + .../FTPConnectorServiceManager.java | 110 + .../ftp/connectorservice/IFTPSubSystem.java | 21 + .../files/ftp/model/FTPFileAdapter.java | 70 + .../files/ftp/model/FTPRemoteFile.java | 67 + .../.classpath | 7 + .../.cvsignore | 1 + .../.project | 28 + .../META-INF/MANIFEST.MF | 20 + .../about.html | 22 + .../build.properties | 14 + .../icons/full/obj16/systemfiles_obj.gif | Bin 0 -> 157 bytes .../icons/full/obj16/systemfileslive_obj.gif | Bin 0 -> 224 bytes .../plugin.properties | 20 + .../plugin.xml | 37 + .../rse/subsystems/files/local/Activator.java | 73 + .../LocalFileSubSystemConfiguration.java | 238 ++ .../files/local/LocalJavaLanguageUtility.java | 63 + .../local/LocalLanguageUtilityFactory.java | 78 + .../local/LocalSearchResultConfiguration.java | 121 + .../files/local/model/LocalFile.java | 74 + .../files/local/model/LocalFileAdapter.java | 79 + .../files/local/model/LocalVirtualFile.java | 188 + .../.classpath | 7 + .../.cvsignore | 1 + .../.project | 28 + .../META-INF/MANIFEST.MF | 20 + .../about.html | 22 + .../build.properties | 10 + .../plugin.properties | 12 + .../subsystems/processes/core/Activator.java | 68 + .../IHostProcessToRemoteProcessAdapter.java | 47 + .../core/subsystem/IRemoteProcess.java | 96 + .../core/subsystem/IRemoteProcessContext.java | 76 + .../IRemoteProcessSubSystemConfiguration.java | 28 + .../subsystem/RemoteProcessSubSystem.java | 108 + .../SystemProcessesCoreResources.java | 34 + .../SystemProcessesCoreResources.properties | 19 + .../subsystem/impl/RemoteProcessContext.java | 157 + .../subsystem/impl/RemoteProcessImpl.java | 287 ++ .../RemoteProcessSubSystemConfiguration.java | 212 ++ .../impl/RemoteProcessSubSystemImpl.java | 199 ++ .../IProcessServiceSubSystem.java | 26 + ...IProcessServiceSubSystemConfiguration.java | 51 + .../ProcessServiceSubSystem.java | 201 ++ .../ProcessServiceSubSystemConfiguration.java | 81 + .../.classpath | 7 + .../.cvsignore | 1 + .../.project | 28 + .../META-INF/MANIFEST.MF | 20 + .../about.html | 22 + .../build.properties | 14 + .../icons/full/obj16/activeprocess.gif | Bin 0 -> 962 bytes .../icons/full/obj16/processsubsystem_obj.gif | Bin 0 -> 574 bytes .../full/obj16/processsubsystemlive_obj.gif | Bin 0 -> 594 bytes .../plugin.properties | 20 + .../plugin.xml | 40 + .../processes/dstore/Activator.java | 72 + .../dstore/DStoreProcessAdapter.java | 86 + .../DStoreProcessSubSystemConfiguration.java | 126 + .../.classpath | 7 + .../.cvsignore | 1 + .../.project | 28 + .../META-INF/MANIFEST.MF | 19 + .../about.html | 22 + .../build.properties | 14 + .../icons/full/obj16/activeprocess.gif | Bin 0 -> 962 bytes .../icons/full/obj16/processsubsystem_obj.gif | Bin 0 -> 574 bytes .../full/obj16/processsubsystemlive_obj.gif | Bin 0 -> 594 bytes .../plugin.properties | 19 + .../plugin.xml | 40 + .../subsystems/processes/local/Activator.java | 72 + .../processes/local/LocalProcessAdapter.java | 69 + .../LocalProcessSubSystemConfiguration.java | 126 + .../.classpath | 7 + .../.cvsignore | 1 + .../.project | 28 + .../META-INF/MANIFEST.MF | 22 + .../about.html | 22 + .../build.properties | 10 + .../plugin.properties | 12 + .../servicesubsystem/OutputRefreshJob.java | 77 + .../shells/subsystems/CandidateCommand.java | 110 + .../shells/subsystems/RemoteCmdSubSystem.java | 1233 +++++++ .../RemoteCmdSubSystemConfiguration.java | 200 ++ .../shells/subsystems/RemoteCommandShell.java | 305 ++ .../shells/subsystems/RemoteError.java | 39 + .../shells/subsystems/RemoteOutput.java | 208 ++ .../shells/subsystems/RemoteSystemEnvVar.java | 163 + .../subsystems/SystemRemoteCommand.java | 154 + .../SystemRemoteCommandMessage.java | 45 + .../rse/subsystems/shells/core/Activator.java | 70 + .../subsystems/shells/core/ShellStrings.java | 39 + .../shells/core/ShellStrings.properties | 24 + .../core/model/ISystemOutputRemoteTypes.java | 101 + .../core/model/RemoteCommandFilterString.java | 166 + .../model/RemoteCommandShellOperation.java | 353 ++ .../RemoteCommandShellOperationManager.java | 75 + .../core/model/SimpleCommandOperation.java | 130 + .../core/subsystems/ICandidateCommand.java | 60 + .../core/subsystems/IRemoteCmdSubSystem.java | 220 ++ .../IRemoteCmdSubSystemConfiguration.java | 43 + .../core/subsystems/IRemoteCommandShell.java | 143 + .../shells/core/subsystems/IRemoteError.java | 23 + .../shells/core/subsystems/IRemoteOutput.java | 52 + .../IServiceCommandShell.java | 28 + .../IShellServiceSubSystem.java | 29 + .../IShellServiceSubSystemConfiguration.java | 37 + .../servicesubsystem/ServiceCommandShell.java | 109 + .../ShellServiceSubSystem.java | 247 ++ .../ShellServiceSubSystemConfiguration.java | 73 + .../.classpath | 7 + .../.cvsignore | 1 + .../.project | 28 + .../META-INF/MANIFEST.MF | 23 + .../about.html | 22 + .../build.properties | 14 + .../icons/full/obj16/systemcommands_obj.gif | Bin 0 -> 230 bytes .../full/obj16/systemcommandslive_obj.gif | Bin 0 -> 246 bytes .../plugin.properties | 20 + .../plugin.xml | 40 + .../subsystems/shells/dstore/Activator.java | 74 + .../DStoreShellSubSystemConfiguration.java | 111 + .../model/DStoreServiceCommandShell.java | 79 + .../.classpath | 7 + .../.cvsignore | 1 + .../.project | 28 + .../META-INF/MANIFEST.MF | 20 + .../about.html | 22 + .../build.properties | 14 + .../icons/full/obj16/systemcommands_obj.gif | Bin 0 -> 230 bytes .../full/obj16/systemcommandslive_obj.gif | Bin 0 -> 246 bytes .../plugin.properties | 20 + .../plugin.xml | 40 + .../subsystems/shells/local/Activator.java | 74 + .../LocalShellSubSystemConfiguration.java | 124 + .../local/model/LocalServiceCommandShell.java | 123 + 423 files changed, 53110 insertions(+) create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/.classpath create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/.cvsignore create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/.project create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/META-INF/MANIFEST.MF create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/about.html create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/about.properties create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/build.properties create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/exportDstore.jardesc create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/exportDstoreMiners.jardesc create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/exportclientserver.jardesc create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/ICancellableHandler.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/IUniversalDataStoreConstants.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/ServerLogger.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/UniversalServerUtilities.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/CommandMiner.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/CommandMinerThread.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/OutputHandler.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/ProcessTracker.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/QueryPathThread.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/patterns/CommandPattern.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/patterns/OutputPattern.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/patterns/ParsedOutput.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/patterns/Patterns.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/environment/EnvironmentMiner.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/ClassFileParser.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/FileClassifier.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalByteStreamHandler.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalDownloadHandler.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalFileSystemFilter.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalFileSystemMiner.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalSearchHandler.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/processes/IUniversalProcessDataStoreConstants.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/processes/ProcessDEComparator.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/processes/UniversalProcessMiner.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/plugin.properties create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/serverruntime/.cvsignore create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/serverruntime/auth.pl create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/serverruntime/daemon.linux create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/serverruntime/daemon.unix create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/serverruntime/daemon.win.bat create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/serverruntime/minerFile.dat create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/serverruntime/patterns.dat create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/serverruntime/rsecomm.properties create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/serverruntime/run.win.bat create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/serverruntime/server.aix create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/serverruntime/server.linux create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/serverruntime/server.unix create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/serverruntime/server.zseries create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/serverruntime/setup.env.zseries create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/serverruntime/win.env.bat create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/internal/services/dstore/shell/DStoreShellOutputReader.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/internal/services/dstore/shell/DStoreShellThread.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/AbstractDStoreService.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/Activator.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/IDStoreService.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/ServiceResources.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/ServiceResources.properties create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/files/DStoreFileService.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/files/DStoreHostFile.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/files/DStoreVirtualHostFile.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/processes/DStoreHostProcess.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/processes/DStoreProcessService.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/rmtservice/DStoreRemoteServiceService.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/search/DStoreSearchResultConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/search/DStoreSearchService.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/shells/DStoreHostShell.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/shells/DStoreShellService.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/DStoreFileTransferStatusListener.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/DStoreStatusMonitor.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/DownloadListener.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/FileSystemMessageUtil.java create mode 100644 rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/StatusChangeListener.java create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/.classpath create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/.cvsignore create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/.project create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/META-INF/MANIFEST.MF create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/about.html create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/about.properties create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/build.properties create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/plugin.properties create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/Activator.java create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPClientService.java create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPHostFile.java create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPLinuxDirectoryListingParser.java create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPService.java create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPServiceResources.java create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPServiceResources.properties create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/IFTPDirectoryListingParser.java create mode 100644 rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/IFTPService.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/.classpath create mode 100644 rse/plugins/org.eclipse.rse.services.local/.cvsignore create mode 100644 rse/plugins/org.eclipse.rse.services.local/.project create mode 100644 rse/plugins/org.eclipse.rse.services.local/META-INF/MANIFEST.MF create mode 100644 rse/plugins/org.eclipse.rse.services.local/about.html create mode 100644 rse/plugins/org.eclipse.rse.services.local/about.properties create mode 100644 rse/plugins/org.eclipse.rse.services.local/build.properties create mode 100644 rse/plugins/org.eclipse.rse.services.local/patterns.dat create mode 100644 rse/plugins/org.eclipse.rse.services.local/plugin.properties create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/search/LocalSearchResult.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/CommandPattern.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/LocalShellOutputReader.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/LocalShellThread.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/OutputPattern.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/ParsedOutput.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/Patterns.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/Activator.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/ILocalService.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalFileService.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalHostFile.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalServiceResources.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalServiceResources.properties create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalVirtualHostFile.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/processes/LocalProcessService.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/search/LocalSearchHandler.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/search/LocalSearchService.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/shells/Activator.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/shells/LocalHostShell.java create mode 100644 rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/shells/LocalShellService.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/.classpath create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/.cvsignore create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/.project create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/META-INF/MANIFEST.MF create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/about.html create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/build.properties create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/icons/full/cview16/commands_view.gif create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/icons/full/cview16/errorlist_view.gif create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/icons/full/eview16/commands_view.gif create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/icons/full/eview16/errorlist_view.gif create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/icons/full/obj16/exportshellhistory.gif create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/icons/full/obj16/exportshelloutput.gif create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/icons/full/obj16/systemcommands_obj.gif create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/icons/full/obj16/systemcommandslive_obj.gif create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/icons/full/obj16/systemshell.gif create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/icons/full/obj16/systemshelllive.gif create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/icons/full/view16/commands_view.gif create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/icons/full/view16/errorlist_view.gif create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/plugin.properties create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/plugin.xml create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/Activator.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/RemoteCommandHelpers.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/ShellResources.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/ShellResources.properties create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/SystemRemoteCommandEntryForm.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/LaunchShellActionDelegate.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemBaseShellAction.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemCommandAction.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemExportShellHistoryAction.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemExportShellOutputAction.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemShowInShellViewAction.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemTerminateRemoveShellAction.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemTerminateShellAction.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/propertypages/EnvironmentVariablesPropertyPage.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/propertypages/ShellServicesPropertyPage.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/propertypages/SystemShellPropertyPage.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/CommandEntryContentAssistProcessor.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/CommandEntryViewerConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/CommandsViewPage.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/CommandsViewWorkbook.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/EncodingForm.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/ISystemCommandTextModifyListener.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/ShellServiceSubSystemFactoryAdapter.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/ShellServiceSubsystemFactoryAdapterFactory.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemBuildErrorView.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemBuildErrorViewPart.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemBuildErrorViewProvider.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandEditor.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandsUI.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandsView.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandsViewPart.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandsViewProvider.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemViewOutputAdapterFactory.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemViewRemoteErrorAdapter.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemViewRemoteOutputAdapter.java create mode 100644 rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/TabFolderLayout.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/.classpath create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/.cvsignore create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/.project create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/META-INF/MANIFEST.MF create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/about.html create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/build.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/plugin.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/AbstractJavaLanguageUtility.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/AbstractLanguageUtility.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/AbstractLanguageUtilityFactory.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/IJavaLanguageUtility.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/ILanguageUtility.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/ILanguageUtilityFactory.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/SystemFileAPIProviderImpl.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/SystemFileSubSystemAPIProviderImpl.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/SystemFileSubSystemFactoryAPIProviderImpl.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/SystemRemoteDirectoryMatcher.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/Activator.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/SystemFileResources.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/SystemFileResources.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/IRemotePath.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileAPIProvider.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileRemoteTypes.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileTransferModeMapping.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileTransferModeRegistry.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemRemoteCommand.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemRemoteCommandMessage.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/RemoteFileFilterString.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/RemoteFileUtility.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/RemotePath.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/RemotePathUtil.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/SystemFileTransferModeMapping.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/SystemFileTransferModeRegistry.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/AbstractRemoteFile.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystem.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/IFileServiceSubSystem.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/IFileServiceSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/OutputRefresh.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/SearchJob.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IHostFileToRemoteFileAdapter.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFile.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileContext.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileExceptionCodes.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileExceptionMessages.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileFactory.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileSubSystem.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileWrapper.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteSearchConstants.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteSearchResult.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IVirtualRemoteFile.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFile.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileCancelledException.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileChildrenContentsType.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileCodeException.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileContext.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileEmpty.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileException.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileIOException.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileRoot.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSchedulingRule.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSecurityException.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSubSystem.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFolderChildrenContentsType.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFolderNotEmptyException.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteSearchResult.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteSearchResultConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteSearchResultsContentsType.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/util/SystemRemoteFileMatcher.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/util/ValidatorFileFilterString.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/util/ValidatorFileUniqueName.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/.classpath create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/.cvsignore create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/.project create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/META-INF/MANIFEST.MF create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/about.html create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/build.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/icons/full/obj16/systemfiles_obj.gif create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/icons/full/obj16/systemfileslive_obj.gif create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/plugin.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/plugin.xml create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/Activator.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/model/DStoreFile.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/model/DStoreFileAdapter.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/model/DStoreSearchResult.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/model/DStoreVirtualFile.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/DownloadListener.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/FileTransferStatusListener.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/SearchResultsChangeListener.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/StatusChangeListener.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/UniversalSearchResultConfigurationFactory.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/UniversalSearchResultConfigurationImpl.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreFileSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreFileSubSystemSearchResultConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreJavaLanguageUtility.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreLanguageUtilityFactory.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreWindowsFileSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/RemoteFilePropertyChangeListener.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/.classpath create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/.cvsignore create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/.project create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/META-INF/MANIFEST.MF create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/about.html create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/build.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/icons/full/obj16/systemfiles_obj.gif create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/icons/full/obj16/systemfileslive_obj.gif create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/plugin.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/plugin.xml create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/Activator.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/FTPFileSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/connectorservice/FTPConnectorService.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/connectorservice/FTPConnectorServiceManager.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/connectorservice/IFTPSubSystem.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/model/FTPFileAdapter.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/model/FTPRemoteFile.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/.classpath create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/.cvsignore create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/.project create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/META-INF/MANIFEST.MF create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/about.html create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/build.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/icons/full/obj16/systemfiles_obj.gif create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/icons/full/obj16/systemfileslive_obj.gif create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/plugin.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/plugin.xml create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/Activator.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/LocalFileSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/LocalJavaLanguageUtility.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/LocalLanguageUtilityFactory.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/LocalSearchResultConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/model/LocalFile.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/model/LocalFileAdapter.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/model/LocalVirtualFile.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/.classpath create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/.cvsignore create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/.project create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/META-INF/MANIFEST.MF create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/about.html create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/build.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/plugin.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/Activator.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/IHostProcessToRemoteProcessAdapter.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/IRemoteProcess.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/IRemoteProcessContext.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/IRemoteProcessSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/RemoteProcessSubSystem.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/SystemProcessesCoreResources.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/SystemProcessesCoreResources.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/impl/RemoteProcessContext.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/impl/RemoteProcessImpl.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/impl/RemoteProcessSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/impl/RemoteProcessSubSystemImpl.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/servicesubsystem/IProcessServiceSubSystem.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/servicesubsystem/IProcessServiceSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/servicesubsystem/ProcessServiceSubSystem.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/servicesubsystem/ProcessServiceSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.dstore/.classpath create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.dstore/.cvsignore create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.dstore/.project create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.dstore/META-INF/MANIFEST.MF create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.dstore/about.html create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.dstore/build.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.dstore/icons/full/obj16/activeprocess.gif create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.dstore/icons/full/obj16/processsubsystem_obj.gif create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.dstore/icons/full/obj16/processsubsystemlive_obj.gif create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.dstore/plugin.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.dstore/plugin.xml create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.dstore/src/org/eclipse/rse/subsystems/processes/dstore/Activator.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.dstore/src/org/eclipse/rse/subsystems/processes/dstore/DStoreProcessAdapter.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.dstore/src/org/eclipse/rse/subsystems/processes/dstore/DStoreProcessSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.local/.classpath create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.local/.cvsignore create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.local/.project create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.local/META-INF/MANIFEST.MF create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.local/about.html create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.local/build.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.local/icons/full/obj16/activeprocess.gif create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.local/icons/full/obj16/processsubsystem_obj.gif create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.local/icons/full/obj16/processsubsystemlive_obj.gif create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.local/plugin.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.local/plugin.xml create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.local/src/org/eclipse/rse/subsystems/processes/local/Activator.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.local/src/org/eclipse/rse/subsystems/processes/local/LocalProcessAdapter.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.processes.local/src/org/eclipse/rse/subsystems/processes/local/LocalProcessSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/.classpath create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/.cvsignore create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/.project create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/META-INF/MANIFEST.MF create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/about.html create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/build.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/plugin.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/servicesubsystem/OutputRefreshJob.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/CandidateCommand.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteCmdSubSystem.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteCmdSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteCommandShell.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteError.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteOutput.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteSystemEnvVar.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/SystemRemoteCommand.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/SystemRemoteCommandMessage.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/Activator.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/ShellStrings.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/ShellStrings.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/ISystemOutputRemoteTypes.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/RemoteCommandFilterString.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/RemoteCommandShellOperation.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/RemoteCommandShellOperationManager.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/SimpleCommandOperation.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/ICandidateCommand.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteCmdSubSystem.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteCmdSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteCommandShell.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteError.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteOutput.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/IServiceCommandShell.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/IShellServiceSubSystem.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/IShellServiceSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/ServiceCommandShell.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/ShellServiceSubSystem.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/ShellServiceSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.dstore/.classpath create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.dstore/.cvsignore create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.dstore/.project create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.dstore/META-INF/MANIFEST.MF create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.dstore/about.html create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.dstore/build.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.dstore/icons/full/obj16/systemcommands_obj.gif create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.dstore/icons/full/obj16/systemcommandslive_obj.gif create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.dstore/plugin.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.dstore/plugin.xml create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.dstore/src/org/eclipse/rse/subsystems/shells/dstore/Activator.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.dstore/src/org/eclipse/rse/subsystems/shells/dstore/DStoreShellSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.dstore/src/org/eclipse/rse/subsystems/shells/dstore/model/DStoreServiceCommandShell.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.local/.classpath create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.local/.cvsignore create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.local/.project create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.local/META-INF/MANIFEST.MF create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.local/about.html create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.local/build.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.local/icons/full/obj16/systemcommands_obj.gif create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.local/icons/full/obj16/systemcommandslive_obj.gif create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.local/plugin.properties create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.local/plugin.xml create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.local/src/org/eclipse/rse/subsystems/shells/local/Activator.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.local/src/org/eclipse/rse/subsystems/shells/local/LocalShellSubSystemConfiguration.java create mode 100644 rse/plugins/org.eclipse.rse.subsystems.shells.local/src/org/eclipse/rse/subsystems/shells/local/model/LocalServiceCommandShell.java diff --git a/rse/plugins/org.eclipse.rse.services.dstore/.classpath b/rse/plugins/org.eclipse.rse.services.dstore/.classpath new file mode 100644 index 00000000000..41dca535336 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/rse/plugins/org.eclipse.rse.services.dstore/.cvsignore b/rse/plugins/org.eclipse.rse.services.dstore/.cvsignore new file mode 100644 index 00000000000..ba077a4031a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/rse/plugins/org.eclipse.rse.services.dstore/.project b/rse/plugins/org.eclipse.rse.services.dstore/.project new file mode 100644 index 00000000000..637caefd568 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/.project @@ -0,0 +1,28 @@ + + + org.eclipse.rse.services.dstore + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/rse/plugins/org.eclipse.rse.services.dstore/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.services.dstore/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..bbc3e20f7dc --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/META-INF/MANIFEST.MF @@ -0,0 +1,29 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin.name +Bundle-SymbolicName: org.eclipse.rse.services.dstore +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.rse.services.dstore.Activator +Bundle-Localization: plugin +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.rse.services, + org.eclipse.dstore.core, + org.eclipse.dstore.extra, + org.eclipse.ui +Eclipse-LazyStart: true +Export-Package: org.eclipse.rse.dstore.universal.miners, + org.eclipse.rse.dstore.universal.miners.command, + org.eclipse.rse.dstore.universal.miners.command.patterns, + org.eclipse.rse.dstore.universal.miners.environment, + org.eclipse.rse.dstore.universal.miners.filesystem, + org.eclipse.rse.dstore.universal.miners.processes, + org.eclipse.rse.internal.services.dstore.shell, + org.eclipse.rse.services.dstore, + org.eclipse.rse.services.dstore.files, + org.eclipse.rse.services.dstore.processes, + org.eclipse.rse.services.dstore.search, + org.eclipse.rse.services.dstore.shells, + org.eclipse.rse.services.dstore.util +Bundle-Vendor: Eclipse.org +Bundle-ClassPath: dstore_services.jar, + dstore_miners.jar diff --git a/rse/plugins/org.eclipse.rse.services.dstore/about.html b/rse/plugins/org.eclipse.rse.services.dstore/about.html new file mode 100644 index 00000000000..6f6b96c4c87 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/about.html @@ -0,0 +1,22 @@ + + + +About + + + +

About This Content

+ +

February 24, 2005

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content.

+ + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/about.properties b/rse/plugins/org.eclipse.rse.services.dstore/about.properties new file mode 100644 index 00000000000..8eec86572ff --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/about.properties @@ -0,0 +1,25 @@ +############################################################################### +# Copyright (c) 2000, 2006 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 +############################################################################### +# 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 dstore services\n\ +\n\ +Version: {featureVersion}\n\ +Build id: {0}\n\ +\n\ +(c) Copyright Eclipse contributors and others 2000, 2006. All rights reserved.\n\ +Visit http://www.eclipse.org/dsdp/tm/ diff --git a/rse/plugins/org.eclipse.rse.services.dstore/build.properties b/rse/plugins/org.eclipse.rse.services.dstore/build.properties new file mode 100644 index 00000000000..f4285cc26ff --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/build.properties @@ -0,0 +1,16 @@ +bin.includes = META-INF/,\ + about.html,\ + about.properties,\ + plugin.properties,\ + dstore_services.jar,\ + dstore_miners.jar +src.includes = META-INF/,\ + about.html,\ + about.properties,\ + plugin.properties +source.dstore_services.jar = src/ +output.dstore_services.jar = bin/ +jars.compile.order = dstore_miners.jar,\ + dstore_services.jar +source.dstore_miners.jar = miners/ +output.dstore_miners.jar = bin/ diff --git a/rse/plugins/org.eclipse.rse.services.dstore/exportDstore.jardesc b/rse/plugins/org.eclipse.rse.services.dstore/exportDstore.jardesc new file mode 100644 index 00000000000..99808fdaf40 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/exportDstore.jardesc @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/rse/plugins/org.eclipse.rse.services.dstore/exportDstoreMiners.jardesc b/rse/plugins/org.eclipse.rse.services.dstore/exportDstoreMiners.jardesc new file mode 100644 index 00000000000..d6cafaa7bb0 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/exportDstoreMiners.jardesc @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/rse/plugins/org.eclipse.rse.services.dstore/exportclientserver.jardesc b/rse/plugins/org.eclipse.rse.services.dstore/exportclientserver.jardesc new file mode 100644 index 00000000000..1c52fb77f33 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/exportclientserver.jardesc @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/ICancellableHandler.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/ICancellableHandler.java new file mode 100644 index 00000000000..6e7a35f6463 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/ICancellableHandler.java @@ -0,0 +1,29 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners; + + + +public interface ICancellableHandler +{ + + public boolean isDone(); + public boolean isCancelled(); + + public void cancel(); +} + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/IUniversalDataStoreConstants.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/IUniversalDataStoreConstants.java new file mode 100644 index 00000000000..b7fa5251b6c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/IUniversalDataStoreConstants.java @@ -0,0 +1,103 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners; + +import org.eclipse.rse.services.clientserver.IServiceConstants; + +public interface IUniversalDataStoreConstants extends IServiceConstants +{ + + + + /* + * Miner names, used for logging + */ + public static final String UNIVERSAL_FILESYSTEM_MINER = "UniversalFileSystemMiner"; + + // + // Universal File descriptors for DataStore DataElements + // + public static final String MESSAGE_DESCRIPTOR = "universal.message"; + + public static final String UNIVERSAL_NODE_DESCRIPTOR = "universal.node"; + public static final String UNIVERSAL_TEMP_DESCRIPTOR = "universal.temp"; + public static final String UNIVERSAL_FILTER_DESCRIPTOR = "universal.FilterObject"; + public static final String UNIVERSAL_FILE_DESCRIPTOR = "universal.FileObject"; + public static final String UNIVERSAL_FOLDER_DESCRIPTOR = "universal.FolderObject"; + + public static final String UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR = "universal.ArchiveFileObject"; + public static final String UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR = "universal.VirtualFileObject"; + public static final String UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR = "universal.VirtualFolderObject"; + + + // + // Universal File Miner Commands + // + + public static final String C_QUERY_ROOTS = "C_QUERY_ROOTS"; + public static final String C_QUERY_VIEW_ALL = "C_QUERY_VIEW_ALL"; + public static final String C_QUERY_VIEW_FILES = "C_QUERY_VIEW_FILES"; + public static final String C_QUERY_VIEW_FOLDERS = "C_QUERY_VIEW_FOLDERS"; + public static final String C_CREATE_FILE = "C_CREATE_FILE"; + public static final String C_CREATE_FOLDER = "C_CREATE_FOLDER"; + public static final String C_QUERY_GET_REMOTE_OBJECT="C_QUERY_GET_REMOTE_OBJECT"; + + public static final String C_DELETE = "C_DELETE"; + public static final String C_DELETE_BATCH = "C_DELETE_BATCH"; + public static final String C_RENAME = "C_RENAME"; + public static final String C_COPY = "C_COPY"; + public static final String C_COPY_BATCH = "C_COPY_BATCH"; + + // Download file command + public static final String C_DOWNLOAD_FILE = "C_DOWNLOAD_FILE"; + + // Query system encoding command + public static final String C_SYSTEM_ENCODING = "C_SYSTEM_ENCODING"; + + // Query unused port + public static final String C_QUERY_UNUSED_PORT = "C_QUERY_UNUSED_PORT"; + + // Qualified class name command and return type + public static final String C_QUERY_QUALIFIED_CLASSNAME = "C_QUERY_QUALIFIED_CLASSNAME"; + public static final String TYPE_QUALIFIED_CLASSNAME = "fullClassName"; + + + + // Mode of transfer: text or binary + public static final int TEXT_MODE = -1; + public static final int BINARY_MODE = -2; + + + // Download result types and download messages + public static final String DOWNLOAD_RESULT_SUCCESS_TYPE = "universal.download.success"; + public static final String DOWNLOAD_RESULT_SUCCESS_MESSAGE = "successful"; + public static final String DOWNLOAD_RESULT_FILE_NOT_FOUND_EXCEPTION = "FileNotFoundException"; + public static final String DOWNLOAD_RESULT_UNSUPPORTED_ENCODING_EXCEPTION = "UnsupportedEncodingException"; + public static final String DOWNLOAD_RESULT_IO_EXCEPTION = "IOException"; + public static final String DOWNLOAD_RESULT_EXCEPTION = "Exception"; + public static final String DOWNLOAD_RESULT_UNEXPECTED_ERROR = "UnexpectedError"; + + + // Number of bytes in a kilobyte + public static final int KB_IN_BYTES = 1024; + + // Number of kilobytes we want + public static final int NUM_OF_KB = 40; + + // The size of file segments to read and send across connection (in bytes) + public static final int BUFFER_SIZE = NUM_OF_KB * KB_IN_BYTES; +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/ServerLogger.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/ServerLogger.java new file mode 100644 index 00000000000..6e1e280b8a1 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/ServerLogger.java @@ -0,0 +1,180 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Date; +import java.util.ResourceBundle; + + +public class ServerLogger { + + + // Constants for logging - for use in rsecomm.properties + private static final String DEBUG_LEVEL = "debug_level"; + private static final String LOG_LOCATION = "log_location"; + + private static final int LOG_WARNING = 1; + private static final int LOG_INFO = 2; + private static final int LOG_DEBUG = 3; + + private static final String LOG_TO_STDOUT = "Log_To_StdOut"; + + private static Object writeLock = new Object(); + private static PrintWriter _logFileStream = null; + + public static final boolean DEBUG = false; + private static int log_level = 0; + + /** + * + */ + public ServerLogger(String logPathName) { + if (_logFileStream == null) { + // Read .properties file to configure + boolean logToFile = true; + + try { + ResourceBundle properties = ResourceBundle.getBundle("rsecomm"); + String debug_level = properties.getString(DEBUG_LEVEL).trim(); + log_level = Integer.parseInt(debug_level); + String log_location = properties.getString(LOG_LOCATION).trim(); + if (log_location.equalsIgnoreCase(LOG_TO_STDOUT)) { + logToFile = false; + _logFileStream = new PrintWriter(System.out); + } + } catch (Exception e) { + // Just use logging defaults: log_level = 0, log to file + //e.printStackTrace(); + } + + if (logToFile) { + try { + File _logFile = new File(logPathName, "rsecomm.log"); + + if (!_logFile.exists()) { + _logFile.createNewFile(); + } + + _logFileStream = new PrintWriter(new FileOutputStream(_logFile)); + + } catch (IOException e) { + System.out.println("Error opening log file " + logPathName + "rsecomm.log"); + } + } + } + } + + + /** + * logInfo + * + * @param minerName + * + * @param message Message text to be logged. + */ + public static void logInfo(String minerName, String message) { + if (log_level >= LOG_INFO) { + if (_logFileStream != null) { + synchronized(writeLock) { + try { + _logFileStream.println(new Date()); + _logFileStream.println("INFO " + minerName + ": " + message); + _logFileStream.println("---------------------------------------------------------------"); + _logFileStream.flush(); + }catch (Exception e) {} + } + } + } + } + + + /** + * logWarning + * + * @param minerName + * + * @param message Message text to be logged. + */ + public static void logWarning(String minerName, String message) { + if (log_level >= LOG_WARNING) { + if (_logFileStream != null) { + synchronized(writeLock) { + try { + _logFileStream.println(new Date()); + _logFileStream.println("WARNING " + minerName + ": " + message); + _logFileStream.println("---------------------------------------------------------------"); + _logFileStream.flush(); + }catch (Exception e) {} + } + } + } + } + + + /** + * logError + * + * @param minerName + * + * @param message Message text to be logged. + * + * @param exception Exception that generated the error. Used to print a stack trace. + */ + public static void logError(String minerName, String message, Throwable exception) { + if (_logFileStream != null) { + synchronized(writeLock) { + try { + _logFileStream.println(new Date()); + _logFileStream.println("ERROR " + minerName + ": " + message); + if (exception != null) { + exception.printStackTrace(_logFileStream); + } + _logFileStream.println("---------------------------------------------------------------"); + _logFileStream.flush(); + }catch (Exception e) {} + } + } + } + + + /** + * logDebugMessage + * + * @param minerName + * + * @param message Message text to be logged. + */ + public synchronized static void logDebugMessage(String minerName, String message) { + if (DEBUG && log_level == LOG_DEBUG) { + if (_logFileStream != null) { + synchronized(writeLock) { + try { + _logFileStream.println(new Date()); + _logFileStream.println("DEBUG " + minerName + ": " + message); + _logFileStream.println("---------------------------------------------------------------"); + _logFileStream.flush(); + }catch (Exception e) {} + } + } + } + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/UniversalServerUtilities.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/UniversalServerUtilities.java new file mode 100644 index 00000000000..d1792f74807 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/UniversalServerUtilities.java @@ -0,0 +1,102 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners; + +import java.io.File; + +public class UniversalServerUtilities { + + + private static String _userPreferencesDirectory = null; + private static ServerLogger log = new ServerLogger(getUserPreferencesDirectory()); + + + /** + * getUserPreferencesDirectory() - returns directory on IFS where to store user settings + */ + public static String getUserPreferencesDirectory() + { + if (_userPreferencesDirectory == null) { + + _userPreferencesDirectory = System.getProperty("user.home"); + String userID = System.getProperty("user.name"); + + // append a '/' if not there + if ( _userPreferencesDirectory.length() == 0 || + _userPreferencesDirectory.charAt( _userPreferencesDirectory.length() -1 ) != File.separatorChar ) { + + _userPreferencesDirectory = _userPreferencesDirectory + File.separator; + } + + _userPreferencesDirectory = _userPreferencesDirectory + ".eclipse" + File.separator + + "RSE" + File.separator + userID + File.separator; + File dirFile = new File(_userPreferencesDirectory); + if (!dirFile.exists()) { + dirFile.mkdirs(); + } + } + + return _userPreferencesDirectory; + } + + /** + * logInfo + * + * @param minerName + * + * @param message Message text to be logged. + */ + public static void logInfo(String minerName, String message) { + ServerLogger.logInfo(minerName, message); + } + + /** + * logWarning + * + * @param minerName + * + * @param message Message text to be logged. + */ + public static void logWarning(String minerName, String message) { + ServerLogger.logWarning(minerName, message); + } + + /** + * logError + * + * @param minerName + * + * @param message Message text to be logged. + * + * @param exception Exception that generated the error. Used to print a stack trace. + */ + public static void logError(String minerName, String message, Throwable exception) { + ServerLogger.logError(minerName, message, exception); + } + + /** + * logDebugMessage + * + * @param minerName + * + * @param message Message text to be logged. + */ + public static void logDebugMessage(String minerName, String message) { + ServerLogger.logDebugMessage(minerName, message); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/CommandMiner.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/CommandMiner.java new file mode 100644 index 00000000000..dbbda403ccc --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/CommandMiner.java @@ -0,0 +1,267 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.command; + + + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; + +import org.eclipse.dstore.core.miners.miner.Miner; +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStoreAttributes; +import org.eclipse.dstore.core.model.DataStoreResources; +import org.eclipse.rse.dstore.universal.miners.command.patterns.Patterns; +import org.eclipse.rse.dstore.universal.miners.environment.EnvironmentMiner; + + + +/** + * The CommandMiner provides the ability to run remote interactive shell + * commands via the DataStore. + */ +public class CommandMiner extends Miner +{ + public static final String MINER_ID = CommandMiner.class.getName();//"org.eclipse.rse.dstore.universal.miners.command.CommandMiner"; + + public class CommandMinerDescriptors + { + public DataElement _stdout; + public DataElement _stderr; + public DataElement _prompt; + public DataElement _grep; + public DataElement _pathenvvar; + public DataElement _envvar; + public DataElement _libenvvar; + public DataElement _error; + public DataElement _warning; + public DataElement _informational; + public DataElement _process; + + public DataElement getDescriptorFor(String type) + { + DataElement descriptor = null; + if (type.equals("stdout")) + { + descriptor = _stdout; + } + else if (type.equals("pathenvvar")) + { + descriptor = _pathenvvar; + } + else if (type.equals("envvar")) + { + descriptor = _envvar; + } + else if (type.equals("libenvvar")) + { + descriptor = _libenvvar; + } + else if (type.equals("error")) + { + descriptor = _error; + } + else if (type.equals("warning")) + { + descriptor = _warning; + } + else if (type.equals("informational")) + { + descriptor = _informational; + } + else if (type.equals("process")) + { + descriptor = _process; + } + else if (type.equals("grep")) + { + descriptor = _grep; + } + else if (type.equals("stderr")) + { + descriptor = _stderr; + } + return descriptor; + } + } + + private HashMap _threads = new HashMap(); + private Patterns _patterns; + private CommandMinerDescriptors _descriptors; + + + public Patterns getPatterns() + { + if (_patterns == null) + { + _patterns = new Patterns(_dataStore); + } + return _patterns; + } + + protected ArrayList getDependencies() + { + ArrayList dependencies = new ArrayList(); + dependencies.add(EnvironmentMiner.MINER_ID); + return dependencies; + } + + public void extendSchema(DataElement schemaRoot) + { + //DataElement fsD = _dataStore.findObjectDescriptor("Filesystem Objects"); + DataElement fsD= _dataStore.findObjectDescriptor(DataStoreResources.model_directory); + DataElement cancellable = _dataStore.findObjectDescriptor(DataStoreResources.model_Cancellable); + + DataElement cmdD = createCommandDescriptor(fsD, "Command", "C_COMMAND", false); + _dataStore.createReference(cancellable, cmdD, "abstracts", "abstracted by"); + + DataElement shellD = createCommandDescriptor(fsD, "Shell", "C_SHELL", false); + _dataStore.createReference(cancellable, shellD, "abstracts", "abstracted by"); + + DataElement inputD = _dataStore.createObject(cmdD, "input", "Enter command"); + DataElement outputD = _dataStore.createObject(cmdD, "output", "Command Output"); + + _descriptors = new CommandMinerDescriptors(); + _descriptors._stdout = _dataStore.createObjectDescriptor(schemaRoot, "stdout"); + _descriptors._stderr = _dataStore.createObjectDescriptor(schemaRoot, "stderr"); + _descriptors._prompt = _dataStore.createObjectDescriptor(schemaRoot, "prompt"); + _descriptors._grep = _dataStore.createObjectDescriptor(schemaRoot, "grep"); + _descriptors._pathenvvar = _dataStore.createObjectDescriptor(schemaRoot, "pathenvvar"); + _descriptors._envvar = _dataStore.createObjectDescriptor(schemaRoot, "envvar"); + _descriptors._libenvvar = _dataStore.createObjectDescriptor(schemaRoot, "libenvvar"); + _descriptors._error = _dataStore.createObjectDescriptor(schemaRoot, "error"); + _descriptors._warning = _dataStore.createObjectDescriptor(schemaRoot, "warning"); + _descriptors._informational = _dataStore.createObjectDescriptor(schemaRoot, "informational"); + _descriptors._process =_dataStore.createObjectDescriptor(schemaRoot, "process"); + + + DataElement getPossibleCmds = createCommandDescriptor(fsD, "Get Commands", "C_GET_POSSIBLE_COMMANDS", false); + _dataStore.refresh(schemaRoot); + } + + public DataElement handleCommand(DataElement theElement) + { + String name = getCommandName(theElement); + DataElement status = getCommandStatus(theElement); + DataElement subject = getCommandArgument(theElement, 0); + + if (name.equals("C_COMMAND")) + { + DataElement invArg = getCommandArgument(theElement, 1); + if (invArg != null) + { + String invocation = invArg.getName(); + //Remove All extra whitespace from the command + if (invocation.trim().length() > 0) + { + if (invocation.equals("?") || invocation.equals("help")) + invocation = "cat " + theElement.getDataStore().getAttribute(DataStoreAttributes.A_PLUGIN_PATH) + "/org.eclipse.rse.services.dstore/patterns.dat"; + launchCommand(subject, invocation, status); + } + return status; + } + else + { + status.setAttribute(DE.A_NAME, "done"); + } + } + else if (name.equals("C_SHELL")) + { + String invocation = ">"; + launchCommand(subject, invocation, status); + } + else if (name.equals("C_SEND_INPUT")) + { + DataElement input = getCommandArgument(theElement, 1); + DataElement de = (DataElement) subject.dereference().get(1); + sendInputToCommand(input.getName(), getCommandStatus(subject)); + } + else if (name.equals("C_CANCEL")) + { + DataElement de = (DataElement) subject.dereference().get(1); + DataElement cancelStatus = getCommandStatus(subject); + cancelCommand(de.getName().trim(), cancelStatus); + return status; + } + else if (name.equals("C_GET_POSSIBLE_COMMANDS")) + { + getPossibleCommands(status); + return status; + } + + return status; + } + + public void getPossibleCommands(DataElement status) + { + QueryPathThread qpt = new QueryPathThread(status); + qpt.start(); + } + + public void launchCommand(DataElement subject, String invocation, DataElement status) + { + //First Check to make sure that there are no "zombie" threads + Iterator iter = _threads.keySet().iterator(); + while (iter.hasNext()) + { + String threadName = (String) iter.next(); + CommandMinerThread theThread = (CommandMinerThread) _threads.get(threadName); + if ((theThread == null) || (!theThread.isAlive())) + { + _threads.remove(threadName); + } + } + CommandMinerThread newCommand = new CommandMinerThread(subject, invocation, status, getPatterns(), _descriptors); + _threads.put(status.getAttribute(DE.A_ID), newCommand); + newCommand.start(); + } + + private void sendInputToCommand(String input, DataElement status) + { + CommandMinerThread theThread = (CommandMinerThread) _threads.get(status.getAttribute(DE.A_ID)); + if (theThread != null) + { + theThread.sendInput(input); + } + } + + private void cancelCommand(String theCommand, DataElement status) + { + CommandMinerThread theThread = (CommandMinerThread) _threads.get(status.getAttribute(DE.A_ID)); + if (theThread != null) + { + theThread.stopThread(); + theThread.sendExit(); + + boolean done = false; + long stopIn = System.currentTimeMillis() + 3000; + while (!done) + if ((!theThread.isAlive()) || (stopIn < System.currentTimeMillis())) + done = true; + _dataStore.createObject(status, "stdout", "Command Cancelled by User Request"); + _dataStore.refresh(status); + } + } + + public String getVersion() + { + return "6.4.0"; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/CommandMinerThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/CommandMinerThread.java new file mode 100644 index 00000000000..9350136cf6e --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/CommandMinerThread.java @@ -0,0 +1,1218 @@ +/******************************************************************************** + * Copyright (c) 2003, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.command; + + + +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.List; + +import org.eclipse.dstore.core.miners.miner.MinerThread; +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.core.model.DataStoreAttributes; +import org.eclipse.rse.dstore.universal.miners.command.patterns.ParsedOutput; +import org.eclipse.rse.dstore.universal.miners.command.patterns.Patterns; +import org.eclipse.rse.dstore.universal.miners.environment.EnvironmentMiner; + + + +/** + * CommandMinerThread is used for running and handling io for shell commands + * in a thread. + */ +public class CommandMinerThread extends MinerThread +{ + + + private DataElement _status; + private DataStore _dataStore; + private String _invocation; + + private DataInputStream _stdInput; + private DataInputStream _stdError; + + + private BufferedWriter _stdOutput; + + private Patterns _patterns; + + private Process _theProcess; + private ProcessTracker _processTracker; + + private DataElement _subject; + private String _cwdStr; + private OutputHandler _stdOutputHandler; + private OutputHandler _stdErrorHandler; + private boolean _isShell; + private boolean _isDone; + private boolean _isWindows; + private boolean _isTTY; + private boolean _isOS400 = false; + private boolean _didInitialCWDQuery = false; + + private CommandMiner.CommandMinerDescriptors _descriptors; + + // default + private String PSEUDO_TERMINAL; + + private DataElement _lastPrompt; + + public CommandMinerThread(DataElement theElement, String invocation, DataElement status, Patterns thePatterns, CommandMiner.CommandMinerDescriptors descriptors) + { + _isShell = false; + _isDone = false; + _status = status; + _dataStore = theElement.getDataStore(); + _descriptors = descriptors; + + _subject = theElement; + String theOS = System.getProperty("os.name"); + + _invocation = invocation.trim(); + _patterns = thePatterns; + _patterns.refresh(_invocation); + + + + + if (theOS.toLowerCase().startsWith("os/400")) + { + _isOS400 = true; + } + + if (theOS.toLowerCase().startsWith("z")) + { + System.setProperty("dstore.stdin.encoding","Cp037"); + } + + _isWindows = theOS.toLowerCase().startsWith("win"); + if (!_isWindows) + { + PSEUDO_TERMINAL = _dataStore.getAttribute(DataStoreAttributes.A_PLUGIN_PATH) + File.separatorChar + "rseterm" + File.separatorChar + "rseterm"; + } + + try + { + + _cwdStr = theElement.getSource(); + if (_cwdStr == null || _cwdStr.length() == 0) + { + _cwdStr = System.getProperty("user.home"); + } + + File theDirectory = new File(_cwdStr); + if (!theDirectory.isDirectory()) + theDirectory = theDirectory.getParentFile(); + _cwdStr = theDirectory.getAbsolutePath(); + + String theShell = null; + if (!_isWindows) + { + File psuedoTerminal = new File(PSEUDO_TERMINAL); + if (psuedoTerminal.exists()) + { + _isTTY = true; + PSEUDO_TERMINAL = psuedoTerminal.getAbsolutePath(); + } + else + { + _isTTY = false; + } + _patterns.setIsTerminal(_isTTY && !_isOS400); + + String property = "SHELL="; + + String[] env = getEnvironment(_subject); + for (int i = 0; i < env.length; i++) + { + String var = env[i]; + if (var.startsWith(property)) + { + theShell = var.substring(property.length(), var.length()); + if (theShell.endsWith("bash")) + { + theShell = "sh"; + } + } + if (_isOS400) + { + theShell = "/QOpenSys/usr/bin/sh";//var.substring(property.length(), var.length()); + } + } + + + if (theShell == null) + { + if (_invocation.equals(">")) + { + _invocation = "sh"; + _isShell = true; + } + if (_isTTY) + { + String args[] = new String[2]; + args[0] = PSEUDO_TERMINAL; + args[1] = _invocation; + _theProcess = Runtime.getRuntime().exec(args, env, theDirectory); + } + else + { + _theProcess = Runtime.getRuntime().exec(_invocation, env, theDirectory); + } + } + else + { + if (_invocation.equals(">")) + { + _invocation = theShell; + + _isShell = true; + + + if (_isTTY) + { + String args[] = null; + if (_isOS400) + { + args = new String[4]; + args[0] = PSEUDO_TERMINAL; + args[1] = "/QOpenSys/usr/bin/sh"; + args[2] = "-c"; + args[3] = "export TERMINAL_TYPE=REMOTE;export QIBM_JAVA_STDIO_CONVERT=Y;export QIBM_USE_DESCRIPTOR_STDIO=I;" + theShell; + } + else + { + args = new String[4]; + args[0] = PSEUDO_TERMINAL; + args[1] = "-w"; + args[2] = "256"; + args[3] = _invocation; + } + + + _theProcess = Runtime.getRuntime().exec(args, env, theDirectory); + } + else + { + _theProcess = Runtime.getRuntime().exec(_invocation, env, theDirectory); + } + } + else + { + _isTTY = false; + + + + //String[] inv = parseArgs(_invocation); + if (_isTTY) + { + String args[] = new String[4]; + args[0] = PSEUDO_TERMINAL; + args[1] = theShell; + args[2] = "-c"; + args[3] = _invocation; + /* + for (int i = 0; i < inv.length; i++) + { + args[3 + i] = inv[i]; + } + */ + + _theProcess = Runtime.getRuntime().exec(args, env, theDirectory); + } + else + { + + String args[] = new String[3]; + args[0] = theShell; + args[1] = "-c"; + args[2] = _invocation; + /* + for (int i = 0; i < inv.length; i++) + { + args[2 + i] = inv[i]; + } + */ + + _theProcess = Runtime.getRuntime().exec(args, env, theDirectory); + } + } + } + } + else + { + if ((theOS.indexOf("95") >= 0) || (theOS.indexOf("98") >= 0) || (theOS.indexOf("ME") >= 0)) + { + theShell = "start"; + } + else + { + theShell = "cmd"; + } + if (_invocation.equals(">")) + { + _invocation = theShell; + _isShell = true; + } + + + String args[] = new String[3]; + args[0]= theShell; + if (theShell.equals("start")) + { + args[1] = "/B "; + } + else + { + args[1] = "/C "; + } + args[2] = _invocation; + _theProcess = Runtime.getRuntime().exec(args, getEnvironment(_subject), theDirectory); + } + + + + OutputStream output = _theProcess.getOutputStream(); + _stdInput = new DataInputStream(_theProcess.getInputStream()); + _stdError = new DataInputStream(_theProcess.getErrorStream()); + + + String specialEncoding = System.getProperty("dstore.stdin.encoding"); + + if (specialEncoding != null) + { + /* + _stdInput = new BufferedReader(new InputStreamReader(_theProcess.getInputStream(), specialEncoding)); + _stdError = new BufferedReader(new InputStreamReader(_theProcess.getErrorStream(), specialEncoding)); + */ + try + { + _stdOutput = new BufferedWriter(new OutputStreamWriter(output, specialEncoding)); + } + catch (UnsupportedEncodingException e) + { + _stdOutput = new BufferedWriter(new OutputStreamWriter(output)); + } + } + else + { + //_stdInput = new BufferedReader(new InputStreamReader(_theProcess.getInputStream())); + //_stdError = new BufferedReader(new InputStreamReader(_theProcess.getErrorStream())); + _stdOutput = new BufferedWriter(new OutputStreamWriter(output)); + } + + } + catch (IOException e) + { + _theProcess = null; + e.printStackTrace(); + createObject("command", e.getMessage()); + status.setAttribute(DE.A_NAME, "done"); + return; + } + + createObject("command", _invocation); + createObject("stdout", ""); + + + + if (_isShell && !_isWindows && !_isTTY) + { + createPrompt(_cwdStr +">", _cwdStr); + //createObject("prompt", _cwdStr + ">"); + } + + status.setAttribute(DE.A_NAME, "progress"); + _dataStore.update(status); + _stdOutputHandler = new OutputHandler(_stdInput, null, _isWindows || _isTTY, false, _isShell, this); + _stdOutputHandler.setWaitTime(10); + _stdOutputHandler.start(); + _stdErrorHandler = new OutputHandler(_stdError, null, _isWindows || _isTTY, true, _isShell, this); + _stdErrorHandler.setWaitTime(10); + _stdErrorHandler.start(); + + if (_isOS400) + { + /* + //DKM - this isn't working properly from merge environments + // so I'm keeping these exports for now + try + { + _stdOutput.write("export QIBM_JAVA_STDIO_CONVERT=Y"); + _stdOutput.write("export QIBM_USE_DESCRIPTOR_STDIO=I"); + _stdOutput.write("\r"); + _stdOutput.flush(); + } + catch (IOException e) + { + + } + + sendInput("export PASE_STDIO_ISATTY=N"); + + sendInput("export QPTY_ISATTY=Y"); + sendInput("export STDIO_ISATTY=Y"); + sendInput("export TERMINAL_TYPE=REMOTE"); + + sendInput("export QIBM_PASE_DESCRIPTOR_STDIO=T"); + sendInput("export QIBM_DESCRIPTOR_STDIN=CRLN=Y"); + */ + } + + + getCurrentProccesses(); + queryCWD(); + } + + + private String[] parseArgs(String full) + { + StringBuffer result = new StringBuffer(); + char[] chars = full.toCharArray(); + boolean inQuotes = false; + boolean escaping = false; + for (int i = 0; i < chars.length; i++) + { + char c = chars[i]; + if (c == '\"') + { + inQuotes = !inQuotes; + } + else + { + if (c == '\\') + { + escaping = true; + } + else + { + if (c == ' ') + { + if (!inQuotes && !escaping) + { + c = ','; + } + escaping = false; + } + } + result.append(c); + } + + } + return result.toString().split(","); + } + + public Process getProcess() + { + return _theProcess; + } + + public String getCWD() + { + return _cwdStr; + } + + public void queryCWD() + { + BufferedWriter writer = _stdOutput; + try + { + // hidden command + writer.write("echo '<'PWD=$PWD"); + writer.newLine(); + writer.flush(); + } + catch (Exception e) + { + } + _didInitialCWDQuery = true; + + } + + private void getCurrentProccesses() + { + if (!_isWindows) + { + /* + if (_processTracker == null) + { + _processTracker = new ProcessTracker(); + _processTracker.start(); + } + _processTracker.doUpdate(); + */ + } + } + + public void sendBreak() + { + if (!_isWindows) + { + if (_processTracker != null) + { + _processTracker.killLastest(); + } + } + } + + public void sendInput(String input) + { + if (!_isDone) + { + + byte[] intoout = input.getBytes(); + + try + { + BufferedWriter writer = _stdOutput; + // pty executable handles the break now + if (input.equals("#break") && !_isTTY) + { + sendBreak(); + return; + } + else if (input.equals("#enter")) + { + if (_isOS400) + { + writer.write("\r"); + } + else + { + writer.newLine(); + } + writer.flush(); + return; + } + + if (_isShell) + { + if (_lastPrompt != null) + { + if (!_isTTY) + { + String promptText = _lastPrompt.getName(); + if (promptText.endsWith(">")) + { + _lastPrompt.setAttribute(DE.A_NAME, promptText + input); + _dataStore.refresh(_lastPrompt); + } + + else + { + String cwd = getCWD(); + String line = cwd + ">" + input; + //createObject("prompt", line); + //createPrompt(line, cwd); + } + } + } + + _patterns.update(input); + } + + if (!_isWindows && !_isTTY) + { + createObject("input", input); + } + + writer.write(input); + + if (_isOS400) + { + writer.write("\r"); + } + else + { + writer.newLine(); + } + writer.flush(); + + + if (input.startsWith("cd ") || input.equals("cd")) + { + queryCWD(); + } + else if (!_didInitialCWDQuery) + { + queryCWD(); + } + if (!_isWindows && !_isTTY) + { + // special case for pattern interpretting + // if cwd is not set, then files aren't resolved + // create mock prompt to ensure that they do get resolved + if (input.startsWith("cd ") || input.equals("cd")) + { + writer.write("echo $PWD'>'"); + writer.newLine(); + writer.flush(); + + // sleep to allow reader to interpret before going on + try + { + Thread.sleep(100); + } + catch (InterruptedException e) + { + } + } + } + + _stdOutputHandler.newCommand(); + } + catch (IOException e) + { + cleanupThread(); + System.out.println(e); + } + } + } + private String[] getEnvironment(DataElement theSubject) + { + //Grab the system environment: + DataElement envMiner = _dataStore.findMinerInformation(EnvironmentMiner.MINER_ID); + DataElement systemEnv = _dataStore.find(envMiner, DE.A_NAME, "System Environment", 1); + //Walk up until we find an element with an inhabits relationship. + DataElement theProject = theSubject; + List projectEnvReference = null; + while (theProject != null && !theProject.getValue().equals("Data")) + { + projectEnvReference = theProject.getAssociated("inhabits"); + if (projectEnvReference.size() > 0) + break; + theProject = theProject.getParent(); + } + DataElement projectEnv = null; + if (projectEnvReference != null && (projectEnvReference.size() > 0)) + projectEnv = (DataElement) projectEnvReference.get(0); + String[] theEnv = mergeEnvironments(systemEnv, projectEnv); + return theEnv; + } + + private String[] mergeEnvironments(DataElement systemEnv, DataElement projectEnv) + { + List prjVars = null; + List sysVars = null; + //Fill the ArrayLists with the environment variables + if (systemEnv != null) + sysVars = systemEnv.getNestedData(); + if (projectEnv != null) + prjVars = projectEnv.getNestedData(); + //If one or both of the ArrayLists are null, exit early: + if ((sysVars == null) || (sysVars.size() == 0)) + return listToArray(prjVars); + if ((prjVars == null) || (prjVars.size() == 0)) + return listToArray(sysVars); + //If we get here, then we have both system and project variables...to make merging the 2 lists easier, we'll + //use a Hashtable (Variable Names are the keys, Variables Values are the values): + Hashtable varTable = new Hashtable(); + //First fill the varTable with the sysVars + varTable.putAll(mapVars(sysVars)); + //Now for every project variable, check to see if it already exists, and if the value contains other variables: + for (int i = 0; i < prjVars.size(); i++) + { + DataElement envElement = (DataElement) prjVars.get(i); + if (!envElement.getType().equals("Environment Variable")) + continue; + String theVariable = envElement.getValue(); + String theKey = getKey(theVariable); + String theValue = getValue(theVariable); + theValue = calculateValue(theValue, varTable); + varTable.put(theKey, theValue); + } + + + if (_isTTY) + { + varTable.put("PS1","$PWD/>"); + varTable.put("COLUMNS","256"); + } + /* DKM: for some reason this isn't getting applied properly here + * but it works via export + * */ + String theOS = System.getProperty("os.name"); + if (theOS.toLowerCase().startsWith("os")) + { + varTable.put("QIBM_JAVA_STDIO_CONVERT","Y"); + varTable.put("QIBM_USE_DESCRIPTOR_STDIO","I"); + varTable.put("PASE_STDIO_ISATTY","N"); + varTable.put("TERMINAL_TYPE","REMOTE"); + varTable.put("STDIO_ISATTY","Y"); + } + + + + return tableToArray(varTable); + } //This method is responsible for replacing variable references with their values. + //We support 3 methods of referencing a variable (assume we are referencing a variable called FOO): + // 1. $FOO - common to most shells (must be followed by a non-alphanumeric or nothing...in other words, we + // always construct the longest name after the $) + // 2. ${FOO} - used when you want do something like ${FOO}bar, since $FOObar means a variable named FOObar not + // the value of FOO followed by "bar". + // 3. %FOO% - Windows command interpreter + private String calculateValue(String value, Hashtable theTable) + { + value = value.replaceAll("}","\n}"); + StringBuffer theValue = new StringBuffer(value); + try + { + int index = 0; + char c; + while (index < theValue.length()) + { + c = theValue.charAt(index); + if (c == '{') + { + index++; + c = theValue.charAt(index); + // skip everything til end quote + while (index < theValue.length() && c != '}') + { + index++; + c = theValue.charAt(index); + } + } + //If the current char is a $, then look for a { or just match alphanumerics + else if (c == '$') + { + int nextIndex = index + 1; + if (nextIndex < theValue.length()) + { + c = theValue.charAt(nextIndex); + //If there is a { then we just look for the closing }, and replace the span with the variable value + if (c == '{') + { + int next = theValue.toString().indexOf("}", nextIndex); + if (next > 0) + { + String replacementValue = findValue(theValue.substring(nextIndex + 1, next), theTable, true); + theValue.replace(index, next + 1, replacementValue); + index += replacementValue.length() - 1; + } + } //If there is no { then we just keep matching alphanumerics to construct the longest possible variable name + else + { + if (Character.isJavaIdentifierStart(c)) + { + while ((nextIndex < theValue.length()) && (Character.isJavaIdentifierPart(c))) + c = theValue.charAt(++nextIndex); + String replacementValue = findValue(theValue.substring(index + 1, nextIndex), theTable, true); + theValue.replace(index, nextIndex, replacementValue); + index += replacementValue.length() - 1; + } + } + } + } //If the current char is a %, then simply look for a matching % + else if (c == '%') + { + int next = theValue.toString().indexOf("%", index + 1); + if (next > 0) + { + String replacementValue = findValue(theValue.substring(index + 1, next), theTable, false); + theValue.replace(index, next + 1, replacementValue); + index += replacementValue.length() - 1; + } + } + else if (c == '"') + { + index++; + c = theValue.charAt(index); + // skip everything til end quote + while (index < theValue.length() && c != '"') + { + index++; + c = theValue.charAt(index); + } + + } + + index++; + } + } + catch (Throwable e) + { + e.printStackTrace(); + } + return theValue.toString(); + } + private String findValue(String key, Hashtable theTable, boolean caseSensitive) + { + Object theValue = null; + if (caseSensitive) + theValue = theTable.get(key); + else + { + String matchString = key.toUpperCase(); + for (Enumeration e = theTable.keys(); e.hasMoreElements();) + { + String theKey = (String) e.nextElement(); + if (matchString.equals(theKey.toUpperCase())) + theValue = (String) theTable.get(theKey); + } + } + if (theValue == null) + return ""; + return (String) theValue; + } + private String getKey(String var) + { + int index = var.indexOf("="); + if (index < 0) + return var; + return var.substring(0, index); + } + private String getValue(String var) + { + var = var.replaceAll("}","\n}"); + int index = var.indexOf("=") + 1; + int varLength = var.length(); + if ((index < 1) || (index == var.length())) + return ""; + return var.substring(index, varLength); + } + private Hashtable mapVars(List theVars) + { + Hashtable theTable = new Hashtable(); + int theSize = theVars.size(); + for (int i = 0; i < theSize; i++) + { + String theVar = ((DataElement) theVars.get(i)).getValue(); + theTable.put(getKey(theVar), getValue(theVar)); + } + return theTable; + } + private String[] listToArray(List theList) + { + if (theList == null) + theList = new ArrayList(); + int theSize = theList.size(); + String theArray[] = new String[theSize]; + for (int i = 0; i < theSize; i++) + theArray[i] = ((DataElement) theList.get(i)).getValue(); + return theArray; + } + private String[] tableToArray(Hashtable theTable) + { + if (theTable == null) + theTable = new Hashtable(); + int theSize = theTable.size(); + String theArray[] = new String[theSize]; + int i = 0; + for (Enumeration e = theTable.keys(); e.hasMoreElements();) + { + String theKey = (String) e.nextElement(); + String theValue = (String) theTable.get(theKey); + theArray[i++] = theKey + "=" + theValue; + } + return theArray; + } + public boolean doThreadedWork() + { + + if (((_stdOutputHandler == null) || _stdOutputHandler.isFinished()) && ((_stdErrorHandler == null) || _stdErrorHandler.isFinished())) + { + return false; + } + else + { + return true; + } + } + public void initializeThread() + { + } + + public void sendExit() + { + if (_isShell) + { + sendInput("exit"); + } + } + + public void cleanupThread() + { + /* + if (_isShell) + { + sendInput("#exit"); + }*/ + + _isDone = true; + try + { + _status.setAttribute(DE.A_NAME, "done"); + _dataStore.refresh(_status, true); + _stdOutputHandler.finish(); + _stdErrorHandler.finish(); + _stdInput.close(); + _stdError.close(); + if (_theProcess != null) + { + int exitcode; + try + { + if (_isCancelled) + { + _theProcess.destroy(); + } + else + { + exitcode = _theProcess.exitValue(); + createObject("prompt", "> Shell Completed (exit code = " + exitcode + ")"); + } + } + catch (IllegalThreadStateException e) + { //e.printStackTrace(); + exitcode = -1; + _theProcess.destroy(); + } + _theProcess = null; + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + public void interpretLine(String line, boolean stdError) + { + // for prompting + if (line.startsWith(" 0) + { + // ignore this line + return; + } + + ParsedOutput parsedMsg = null; + + try + { + parsedMsg = _patterns.matchLine(removeWhitespace(line)); + } + catch (Throwable e) + { + e.printStackTrace(); + } + + if (parsedMsg == null) + { + + if (stdError) + { + + createObject(_descriptors._stderr, line); + } + else + { + createObject(_descriptors._stdout, line); + } + } + else + { + try + { + String fileName = parsedMsg.file; + DataElement object = null; + if (parsedMsg.type.equals("prompt")) + { + File promptFile = new File(fileName); + if (promptFile.exists()) + { + createPrompt(line, fileName); + } + else + { + createObject(_descriptors._stdout, line); + } + } + else if (parsedMsg.type.equals("file")) + { + object = createObject(parsedMsg.type, line, fileName, null); + } + else + { + object = createObject(parsedMsg.type, line, fileName, new Integer(parsedMsg.line)); + } + + } + catch (NumberFormatException e) + { + e.printStackTrace(); + } + } + + _dataStore.refresh(_status); + } + + public void createPrompt(String line, String fileName) + { + // prevent duplicate prompts + DataElement object = null; + int size = _status.getNestedSize(); + if (size > 0) + { + DataElement lastObject = _status.get(size - 1); + if (!lastObject.getType().equals("prompt")) + { + line = line.replaceAll("//", "/"); + fileName = fileName.replaceAll("//", "/"); + object = createObject("prompt", line, fileName, null); + + _lastPrompt = object; + _cwdStr = object.getSource(); + } + } + } + + public String removeWhitespace(String theLine) + { + StringBuffer strippedLine = new StringBuffer(); + boolean inWhitespace = true; + char curChar; + for (int i = 0; i < theLine.length(); i++) + { + curChar = theLine.charAt(i); + if (curChar == '\t') + { + if (!inWhitespace) + { + strippedLine.append(' '); + inWhitespace = true; + } + } + else if (curChar == ' ') + { + if (!inWhitespace) + { + strippedLine.append(' '); + inWhitespace = true; + } + } + else + { + strippedLine.append(curChar); + inWhitespace = false; + } + } + return strippedLine.toString(); + } + + /************************************************************************************************ + private void createObject (String,String) + Create a simple object with no source information + *************************************************************************************************/ + public DataElement createObject(String type, String text) + { + DataElement newObj = null; + DataElement descriptorType = _descriptors.getDescriptorFor(type); + if (descriptorType != null) + { + newObj = _dataStore.createObject(_status, descriptorType, text, ""); + } + else + { + newObj = _dataStore.createObject(_status, type, text, ""); + } + return newObj; + } + + public DataElement createObject(DataElement type, String text) + { + return _dataStore.createObject(_status, type, text, ""); + } + + /************************************************************************************************ + private void createObject (String,String,String,Integer,Integer) + + Create an object that can contain file information as well as line an column. + Note: currently our editors do not support jumping to a column, so neither + do we here. + *************************************************************************************************/ + private DataElement createObject(String type, String text, String file, Integer line) + { + DataElement descriptorType = null; + if (file != null && file.length() > 0) + { + boolean foundFile = false; + String expectedPath = null; + File aFile = new File(file); + if (type.equals("prompt")) + { + descriptorType = _descriptors._prompt; + expectedPath = file; + _cwdStr = file.replaceAll("//", "/"); + } + else if (aFile != null && aFile.exists()) + { + expectedPath = aFile.getAbsolutePath(); + file = expectedPath; + if (aFile.isDirectory() && type.equals("file")) + { + type = "directory"; + } + foundFile = true; + } + else if (_cwdStr.endsWith("/")) + { + if (file.equals("/")) + { + expectedPath = _cwdStr; + } + else + { + expectedPath = _cwdStr + file; + } + } + else + { + expectedPath = _cwdStr + "/" + file; + } + + if (!foundFile) + { + + File qfile = new File(expectedPath); + if (!qfile.exists()) + { + expectedPath = file; + qfile = new File(expectedPath); + if (qfile.exists()) + { + if (qfile.isDirectory() && type.equals("file")) + { + type = "directory"; + } + } + else + { + File cwdFile = new File(_cwdStr); + String cwdParent = cwdFile.getAbsolutePath(); + if (cwdFile.getParent() != null) + { + cwdParent = cwdFile.getParentFile().getAbsolutePath(); + } + + if (cwdParent.endsWith("/")) + { + expectedPath = cwdParent + file; + } + else + { + expectedPath = cwdParent + "/" + file; + } + + qfile = new File(expectedPath); + if (qfile.exists()) + { + if (qfile.isDirectory() && type.equals("file")) + { + type = "directory"; + } + file = expectedPath; + } + else + { + // no match, so can't be a file + if (type.equals("file")) + { + type = "stdout"; + descriptorType = _descriptors._stdout; + } + else if (type.equals("error")) + { + type = "stderr"; + descriptorType = _descriptors._stderr; + } + else + { + type = "stdout"; + descriptorType = _descriptors._stdout; + } + } + } + } + else + { + if (qfile.isDirectory() && type.equals("file")) + { + type = "directory"; + expectedPath = expectedPath.replaceAll("//", "/"); + } + file = expectedPath; + } + } + + + DataElement obj = null; + if (line == null || (line.intValue() == 1)) + { + if (descriptorType != null) + { + obj = _dataStore.createObject(_status, descriptorType, text, file); + } + else + { + obj = _dataStore.createObject(_status, type, text, file); + } + } + else + { + if (descriptorType != null) + { + obj = _dataStore.createObject(_status, descriptorType, text, file); + } + else + { + obj = _dataStore.createObject(_status, type, text, file); + } + obj.setAttribute(DE.A_SOURCE, obj.getSource() + ':' + line.toString()); + } + _dataStore.refresh(_status); + return obj; + } + else + { + + return createObject(type, text); + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/OutputHandler.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/OutputHandler.java new file mode 100644 index 00000000000..ac3b938b77f --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/OutputHandler.java @@ -0,0 +1,398 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.command; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +import org.eclipse.dstore.core.model.Handler; + +/** + * The OutputHandler class is used to listen to a particular output or error stream, + * interpret that information and create DataElements for it for use on the client. + */ +public class OutputHandler extends Handler +{ + + private DataInputStream _reader; + private boolean _isStdError; + private boolean _isTerminal; + + private CommandMinerThread _commandThread; + private boolean _isShell; + private static int MAX_OFFSET = 10000; + private boolean _endOfStream = false; + + + private List _encodings; + + + public OutputHandler(DataInputStream reader, String qualifier, boolean isTerminal, boolean isStdError, boolean isShell, CommandMinerThread commandThread) + { + _reader = reader; + _isStdError = isStdError; + _isTerminal = isTerminal; + _commandThread = commandThread; + _isShell = isShell; + _encodings = new ArrayList(); + String system = System.getProperty("os.name").toLowerCase(); + + if (system.startsWith("z")) + { + _encodings.add("IBM-1047"); + /* + _encodings.add("Cp1047"); + _encodings.add("Cp037"); + _encodings.add("UTF8"); + */ + } + else + { + String specialEncoding = System.getProperty("dstore.stdin.encoding"); + if (specialEncoding != null) + { + _encodings.add(specialEncoding); + } + _encodings.add(System.getProperty("file.encoding")); + } + + } + + public void newCommand() + { + } + + public void handle() + { + String[] lines = readLines(); + if (lines != null) + { + + /* + if (lines.length == 0) + { + _reader. + } + + // don't do anything unless we require output + if (_newCommand && !_isTerminal) + { + doPrompt(); + } + } + else + */ + for (int i = 0; i < lines.length; i++) + { + String line = lines[i]; + _commandThread.interpretLine(line, _isStdError); + } + if (!_isTerminal) + doPrompt(); + } + else + { + finish(); + } + } + + private void doPrompt() + { + try + { + if ((_reader.available() == 0) && !_isStdError && _isShell) + { + if (!_isTerminal) + { + try + { + Thread.sleep(500); + if (_reader.available() == 0) + { + // create fake prompt + _commandThread.createPrompt(_commandThread.getCWD() + '>', _commandThread.getCWD()); + } + } + catch (Exception e) + { + } + } + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + public synchronized void waitForInput() + { + try + { + Thread.sleep(100); + } + catch (Exception e) + { + + } + } + + + private String[] readLines() + { + if (_endOfStream) + { + return null; + } + String[] output = null; + + try + { + + // find out how many bytes are available to be read + int available = _reader.available(); + int lookahead = 0; + + // if there's none, wait a bit and return true to continue + if (available <= 0) + { + sleep(100); + available = _reader.available(); + + if (available == 0) + { + lookahead = _reader.read(); + if (lookahead == -1) + { + return null; + } + else + { + available = _reader.available() + 1; + } + } + } + + byte[] readBytes = new byte[available]; + + // read the available bytes + int numRead = 0; + if (lookahead > 0) + { + readBytes[0] = (byte)lookahead; + numRead = _reader.read(readBytes, 1, available - 1) + 1; + } + else + { + numRead = _reader.read(readBytes, 0, available); + } + + // if we've reached end of stream, quit + if (numRead == -1) + { + return null; + } + + + if (readBytes[numRead - 1]== -1) + { + _endOfStream = true; + } + + // use various encodings as a precaution + // note that the first encoding will be the encoding that we were given + int encodingIndex = 0; + + while (encodingIndex < _encodings.size()) + { + String encoding = (String)(_encodings.get(encodingIndex)); + + // get the output using the encoding + try + { + String fullOutput = new String(readBytes, 0, numRead, encoding); + + // if output is not null, we assume the encoding was correct and process the output + if (fullOutput != null /*&& fullOutput.length() == numRead*/) + { + // tokenize the output so that we can get each line of output + // the delimiters are therefore set to "\n\r" + StringTokenizer tokenizer = new StringTokenizer(fullOutput, "\n\r"); + int numTokens = tokenizer.countTokens(); + output = new String[numTokens]; + int index = 0; + while (tokenizer.hasMoreTokens()) + { + output[index] = tokenizer.nextToken(); + index++; + } + + + return output; + } + } + catch (Exception e) + { + } + } + } + catch (Exception e) + { + + } + return output; + } +/* + private String readLine() + { + + + int ch; + boolean done = false; + int byteArrayOffset = 0; + while (!done && !isFinished() && (byteArrayOffset < MAX_OFFSET)) + { + try + { + //synchronized (_reader) + { + + if (byteArrayOffset > 0 && (_reader.available() == 0)) + { + try + { + Thread.sleep(_waitIncrement); + } + catch (InterruptedException e) + { + } + if (_reader.available() == 0) + { + _isWaiting = true; + done = true; + //System.out.println("return nothiong"); + //return ""; + } + + } + + ch = _reader.read(); + + _isWaiting = false; + switch (ch) + { + case -1 : + case 65535 : + if (byteArrayOffset == 0) //End of Reader + { + return null; + } + done = true; + break; + + case 10 : // new line + case 13 : // carriage return + done = true; //Newline + break; + + case 27: + break; + + case 9 : + + + // DKM - test - can we preserve tabs? + _byteArray[byteArrayOffset++] = (byte)ch; + + //theLine.append(" "); //Tab + break; + + default : + char tch = (char) ch; + if (!Character.isISOControl(tch)) + { + //System.out.println("char="+tch); + _byteArray[byteArrayOffset++] = (byte)ch; + } + else + { + //System.out.println("ignoring:"+ch); + // ignore next char too + if (_reader.available() > 0) + _reader.read(); + } + break; + } + + + //Check to see if the BufferedReader is still ready which means there are more characters + //in the Buffer...If not, then we assume it is waiting for input. + if (_reader.available() == 0) + { + //wait to make sure + try + { + Thread.sleep(_waitIncrement); + } + catch (InterruptedException e) + { + } + if (_reader.available() == 0) + { + _isWaiting = true; + done = true; + } + } + } + } + catch (IOException e) + { + return null; + } + } + + String lineObject = null; + if (byteArrayOffset > 0) + { + + int encodingIndex = 0; + //printEncodedLines(_byteArray, 0, byteArrayOffset); + + + while (lineObject == null && encodingIndex < _encodings.size()) + { + lineObject = getEncodedLine(_byteArray, 0, byteArrayOffset, (String) _encodings.get(encodingIndex)); + encodingIndex++; + } + + if (lineObject == null) + { + lineObject = new String(_byteArray, 0, byteArrayOffset); + } + } + else + { + lineObject =""; + } + + + return lineObject; + } + */ +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/ProcessTracker.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/ProcessTracker.java new file mode 100644 index 00000000000..c922d3aeb02 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/ProcessTracker.java @@ -0,0 +1,441 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.command; + + +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +import org.eclipse.dstore.core.model.Handler; + + +public class ProcessTracker extends Handler +{ + + private class ProcessDescriptor + { + private String _pid; + private String _cmd; + + public ProcessDescriptor(String pid, String cmd) + { + _pid = pid; + _cmd = cmd; + } + + public String getPID() + { + return _pid; + } + + public String getCMD() + { + return _cmd; + } + + public String toString() + { + String result = getPID() + " " + getCMD(); + if (ProcessDescriptor.this == _newestProcess) + { + result += " *"; + } + return result; + } + + public boolean hasCMD(String cmdname) + { + StringTokenizer tokenizer = new StringTokenizer(_cmd, "/"); + + while (tokenizer.hasMoreTokens()) + { + String token = tokenizer.nextToken(); + if (!tokenizer.hasMoreElements()) + { + if (token.equals(cmdname)) + { + return true; + } + } + } + return false; + } + + public boolean equals(Object obj) + { + if (obj instanceof ProcessDescriptor) + { + ProcessDescriptor des = (ProcessDescriptor) obj; + if (des.getPID().equals(_pid)) + { + return true; + } + } + + return false; + } + } + + private Process _psShell; + + private BufferedReader _psReader; + private BufferedWriter _psWriter; + + private boolean _updateFlag; + private ProcessDescriptor _newestProcess; + private String _psCommand; + private boolean _isEnabled; + + private List _currentProcesses = new ArrayList(); + + public ProcessTracker() + { + super(); + init(); + } + + private String getFormatOptions(String theOS) + { + String formatOptions = ""; + if (theOS.startsWith("z")) + { + formatOptions = "-o pid,comm"; + } + else if (theOS.startsWith("linux")) + { + formatOptions = "--format pid,ucomm"; + } + else if (theOS.startsWith("aix")) + { + formatOptions = "-F pid,ucomm"; + } + return formatOptions; + } + + private void init() + { + String userID = System.getProperty("user.name"); + String userOptions = "-u " + userID; + + String theOS = System.getProperty("os.name").toLowerCase(); + String formatOptions = getFormatOptions(theOS); + if (formatOptions.length() == 0) + { + _isEnabled = false; + } + else + { + _isEnabled = true; + } + if (_isEnabled) + { + + _psCommand = "ps " + userOptions + " " + formatOptions; + try + { + + if (_psShell == null) + { + _psShell = Runtime.getRuntime().exec("sh"); + + String specialEncoding = System.getProperty("dstore.stdin.encoding"); + if (specialEncoding != null) + { + _psReader = new BufferedReader(new InputStreamReader(_psShell.getInputStream(), specialEncoding)); + try + { + _psWriter = new BufferedWriter(new OutputStreamWriter(_psShell.getOutputStream(), specialEncoding)); + } + catch (UnsupportedEncodingException e) + { + _psWriter = new BufferedWriter(new OutputStreamWriter(_psShell.getOutputStream())); + } + } + else + { + _psReader = new BufferedReader(new InputStreamReader(_psShell.getInputStream())); + _psWriter = new BufferedWriter(new OutputStreamWriter(_psShell.getOutputStream())); + } + } + } + catch (Exception e) + { + } + } + } + + private static String readLine(BufferedReader reader) + { + StringBuffer theLine = new StringBuffer(); + int ch; + boolean done = false; + while (!done) + { + try + { + synchronized (reader) + { + if (!reader.ready()) + { + return theLine.toString(); + } + ch = reader.read(); + switch (ch) + { + case -1 : + if (theLine.length() == 0) //End of Reader + return null; + done = true; + break; + case 65535 : + if (theLine.length() == 0) + return null; + done = true; + break; + case 10 : + done = true; //Newline + break; + case 13 : + done = true; + break; //Carriage Return + default : + char tch = (char) ch; + if (!Character.isISOControl(tch)) + { + theLine.append(tch); //Any other character + } + else + { + // ignore next char too + if (reader.ready()) + reader.read(); + } + break; + //Any other character + } + //Check to see if the BufferedReader is still ready which means there are more characters + //in the Buffer...If not, then we assume it is waiting for input. + if (!reader.ready()) + { + done = true; + } + } + } + catch (IOException e) + { + return null; + } + } + return theLine.toString(); + } + + private void getCurrentProcesses() + { + try + { + _psWriter.write(_psCommand); + _psWriter.write("\n"); + _psWriter.flush(); + + // skip first line + String line = _psReader.readLine(); + ArrayList newPIDs = new ArrayList(); + line = readLine(_psReader); + while (line != null && line.length() > 0) + { + line = line.trim(); + int firstBlank = line.indexOf(' '); + if (firstBlank != -1) + { + String pid = line.substring(0, firstBlank); + String cmd = line.substring(firstBlank + 1, line.length()); + ProcessDescriptor descriptor = new ProcessDescriptor(pid, cmd); + if (!descriptor.hasCMD("ps")) + { + newPIDs.add(descriptor); + } + } + + line = readLine(_psReader); + } + updateProcesses(newPIDs); + } + catch (Exception e) + { + e.printStackTrace(); + } + //listProcesses(); + } + + public void finish() + { + _updateFlag = false; + if (_isEnabled) + { + endTrackerProcess(); + } + super.finish(); + } + + private void updateProcesses(ArrayList newPIDs) + { + boolean firstRun = _currentProcesses.size() == 0; + // remove finished pids + for (int c = _currentProcesses.size() - 1; c >= 0; c--) + { + ProcessDescriptor p = (ProcessDescriptor) _currentProcesses.get(c); + if (newPIDs.contains(p)) + { + newPIDs.remove(p); + } + else + { + _currentProcesses.remove(p); + } + } + + // add new pids + for (int i = 0; i < newPIDs.size(); i++) + { + ProcessDescriptor p = (ProcessDescriptor) newPIDs.get(i); + _currentProcesses.add(p); + if (!firstRun) + { + _newestProcess = p; + } + } + } + + public void endTrackerProcess() + { + if (_isEnabled) + { + try + { + _psWriter.write("exit"); + _psWriter.write("\n"); + _psWriter.flush(); + + _psReader.close(); + _psWriter.close(); + _psShell.waitFor(); + } + catch (Exception e) + { + } + } + } + + public ProcessDescriptor getNewestProcess() + { + return _newestProcess; + } + + private ProcessDescriptor findLast(String cmd) + { + if (_newestProcess != null && _newestProcess.hasCMD(cmd)) + { + return _newestProcess; + } + for (int i = _currentProcesses.size() - 1; i > 0; i--) + { + ProcessDescriptor descriptor = (ProcessDescriptor) _currentProcesses.get(i); + if (descriptor.hasCMD(cmd)) + { + return descriptor; + } + } + return null; + } + + public void killCommand(String cmd) + { + ProcessDescriptor descriptor = findLast(cmd); + if (descriptor != null) + { + kill(descriptor); + } + } + + public void killLastest() + { + if (_newestProcess != null) + { + kill(_newestProcess); + } + } + + private void kill(ProcessDescriptor descriptor) + { + if (_isEnabled) + { + try + { + _psWriter.write("kill " + descriptor.getPID()); + _psWriter.write("\n"); + _psWriter.flush(); + _psReader.reset(); + } + catch (Exception e) + { + } + doUpdate(); + } + } + + public void handle() + { + if (!_isEnabled) + { + finish(); + } + if (_updateFlag) + { + try + { + Thread.sleep(100); + } + catch (Exception e) + { + } + getCurrentProcesses(); + _updateFlag = false; + } + } + + public void doUpdate() + { + if (_isEnabled) + _updateFlag = true; + else + _updateFlag = false; + } + + public synchronized void waitForInput() + { + try + { + Thread.sleep(100); + } + catch (Exception e) + { + + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/QueryPathThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/QueryPathThread.java new file mode 100644 index 00000000000..f68e96c88ba --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/QueryPathThread.java @@ -0,0 +1,148 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.command; + + + + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.rse.dstore.universal.miners.environment.EnvironmentMiner; + +/** + * QueryPathThread is used to determine available command completions + */ +public class QueryPathThread extends Thread +{ + + private DataStore _dataStore; + private DataElement _status; + + public QueryPathThread(DataElement status) + { + super(); + _status = status; + _dataStore = status.getDataStore(); + } + + public void run() + { + getPossibleCommands(_status); + + } + + public List getPathEnvironment() + { + DataElement envMinerData = _dataStore.findMinerInformation(EnvironmentMiner.MINER_ID); + if (envMinerData != null) + { + DataElement systemEnvironment = _dataStore.find(envMinerData, DE.A_NAME, "System Environment", 1); + if (systemEnvironment != null) + { + // d54675 + // for Windows, ignore the case sensitiveness of PATH variable + boolean isIgnoreCase = System.getProperty("os.name").toLowerCase().startsWith("win"); + ArrayList vars = _dataStore.searchForPattern(systemEnvironment, DE.A_NAME, "PATH=*", isIgnoreCase); + + if (vars == null || vars.size() == 0) { + return new ArrayList(); + } + + DataElement pathVariable = (DataElement) vars.get(0); + if (pathVariable != null) + { + String varStr = pathVariable.getValue(); + int separatorIndex = varStr.indexOf("="); + if (separatorIndex > 0) + { + varStr = varStr.substring(separatorIndex + 1, varStr.length()); + } + + return parsePathEnvironmentVariable(varStr); + } + } + } + return null; + } + + protected List parsePathEnvironmentVariable(String path) + { + ArrayList addedPaths = new ArrayList(); + ArrayList addedFolders = new ArrayList(); + + boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("win"); + char separator = isWindows ? ';' : ':'; + StringTokenizer tokenizer = new StringTokenizer(path, separator + ""); + while (tokenizer.hasMoreTokens()) + { + String token = tokenizer.nextToken(); + if (!addedPaths.contains(token)) + { + addedPaths.add(token); + + File folder = new File(token); + if (folder.exists() && folder.isDirectory()) + { + addedFolders.add(folder); + } + } + } + return addedFolders; + } + + public void getPossibleCommands(DataElement status) + { + List resolvedPaths = new ArrayList(); + List paths = getPathEnvironment(); + for (int i = 0; i < paths.size(); i++) + { + File folder = (File) paths.get(i); + String abspath = folder.getAbsolutePath().toLowerCase(); + if (!resolvedPaths.contains(abspath)) + { + resolveCommandsInPath(folder, status); + resolvedPaths.add(abspath); + } + } + status.setAttribute(DE.A_NAME, "done"); + _dataStore.refresh(status); + } + + private void resolveCommandsInPath(File file, DataElement status) + { + if (file.isDirectory()) + { + File[] files = file.listFiles(); + for (int i = 0; i < files.length; i++) + { + File afile = files[i]; + if (afile.isFile() && !afile.isHidden()) + { + String name = afile.getName(); + DataElement fileObj = _dataStore.createObject(status, "file", name); + fileObj.setAttribute(DE.A_SOURCE, afile.getAbsolutePath()); + } + } + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/patterns/CommandPattern.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/patterns/CommandPattern.java new file mode 100644 index 00000000000..6c226a19a50 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/patterns/CommandPattern.java @@ -0,0 +1,77 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.command.patterns; + +import java.util.ArrayList; +import java.util.regex.Pattern; + +/** + * This class represents a command pattern. It contains a list of + * output patterns representing the types of output expected from + * running a command. CommandPattern is used to produce ParsedOutput, + * enabling output interpretation. + */ +public class CommandPattern +{ + + + private Pattern _pattern; + private ArrayList _outputPatterns; + + public CommandPattern(Pattern theCommandPattern) + { + _pattern = theCommandPattern; + _outputPatterns = new ArrayList(); + } + + public String getPattern() + { + return _pattern.pattern(); + } + + public void addOutputPattern(OutputPattern op) + { + _outputPatterns.add(op); + } + + public boolean matchCommand(String theLine) + { + return _pattern.matcher(theLine).matches(); + } + + public ParsedOutput matchLine(String theLine) + { + + int patterns = _outputPatterns.size(); + ParsedOutput matchedOutput; + OutputPattern curPattern; + for (int i = 0; i < patterns; i++) + { + curPattern = (OutputPattern) _outputPatterns.get(i); + + + matchedOutput = curPattern.matchLine(theLine); + + if (matchedOutput != null) + return matchedOutput; + } + + + return null; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/patterns/OutputPattern.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/patterns/OutputPattern.java new file mode 100644 index 00000000000..ea41cf21d83 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/patterns/OutputPattern.java @@ -0,0 +1,106 @@ +/******************************************************************************** + * Copyright (c) 2001, 2006 IBM Corporation and International Business Machines 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.command.patterns; + +import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + + +public class OutputPattern +{ + + + private Pattern _pattern; + private String _objType; + private ArrayList _matchOrder; + + public OutputPattern(String objType, String matchOrder, Pattern thePattern) + { + _objType = objType; + _pattern = thePattern; + + _matchOrder = new ArrayList(); + //Here we add a dummy first element to the ArrayList, to mimick how the PatternMatcher stores it's + //matches (starting with group 1). + _matchOrder.add(null); + + int index = 0; + int nextSpace = 0; + //Walk the matchOrder string parsing out words and adding them to _matchOrder...Could use StringTokenizer + //but this seem much simpler. + while ((nextSpace = matchOrder.indexOf(" ", index)) > 0) + { + _matchOrder.add(matchOrder.substring(index, nextSpace).toLowerCase()); + index = nextSpace; + while ((index < matchOrder.length()) && (matchOrder.charAt(index) == ' ')) + index++; + } + _matchOrder.add(matchOrder.substring(index, matchOrder.length()).toLowerCase()); + + } + + public ParsedOutput matchLine(String theLine) + { + Matcher matcher = null; + try + { + matcher = _pattern.matcher(theLine); + if (!matcher.matches()) + return null; + } + catch (StringIndexOutOfBoundsException e) + { + e.printStackTrace(); + //Getting an exception here, when theLine is an empty line for some patterns..should probably investigate, + //but for now we'll just handle it... + return null; + } + + String fileString = ""; + String lineString = ""; + + //Groups start at 1 (group 0 is the entire match). + for (int i = 1; i < _matchOrder.size(); i++) + { + String mStr = (String)_matchOrder.get(i); + if (mStr.equals("file")) + { + fileString = matcher.group(i); + } + else if (mStr.equals("line")) + { + lineString = matcher.group(i); + } + } + int line = 1; + if (lineString.length() > 0) + { + try + { + line = Integer.parseInt(lineString); + } + catch (NumberFormatException e) + { + e.printStackTrace(); + } + } + + return new ParsedOutput(_objType, theLine, fileString, line, 1); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/patterns/ParsedOutput.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/patterns/ParsedOutput.java new file mode 100644 index 00000000000..315e6130b7f --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/patterns/ParsedOutput.java @@ -0,0 +1,40 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.command.patterns; + +/* + * This is a convenience object for storing information parsed out of a line of output. + */ +public class ParsedOutput +{ + + + public String type; + public String text; + public String file; + public int line; + public int col; + + public ParsedOutput(String theType, String theText, String theFile, int theLine, int theColumn) + { + type = theType; + text = theText; + file = theFile; + line = theLine; + col = theColumn; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/patterns/Patterns.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/patterns/Patterns.java new file mode 100644 index 00000000000..f494c0f94c2 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/patterns/Patterns.java @@ -0,0 +1,314 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.command.patterns; + + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.core.model.DataStoreAttributes; + +/** + * This class is used for interpretting standard error and standard output. + */ +public class Patterns +{ + + private ArrayList _theCommands; + private DataStore _dataStore; + + private String _currentCommand = null; + private List _currentCommandPatterns = null; + + //private String _previousCommand = null; + private long _timeStamp = 0; + private File _thePatternsFile; + private boolean _isTerminal = false; + private String _pluginPath; + + private static String MINERS_PACKAGE = "org.eclipse.rse.services.dstore"; + private static String PATTERNS_FILE = "patterns.dat"; + + // HACK - too late in cycle to deal with version properly - for now this has to be fixed + private String _version = "8.0.0"; + + public Patterns(DataStore ds) + { + _dataStore = ds; + _theCommands = new ArrayList(); + _currentCommandPatterns = new ArrayList(); + _pluginPath = ds.getAttribute(DataStoreAttributes.A_ROOT_PATH); + parsePatternsFile(); + } + + public Patterns(DataStore ds, String pluginsPath) + { + _dataStore = ds; + _theCommands = new ArrayList(); + _currentCommandPatterns = new ArrayList(); + _pluginPath = pluginsPath; + parsePatternsFile(); + } + + public void setIsTerminal(boolean isTerminal) + { + _isTerminal = isTerminal; + } + + private String cleanCmdString(String theCommand) + { + String result = theCommand; + + // for multi commands + int semiIndex = result.indexOf(";"); + if (semiIndex > 0) + { + result = result.substring(0, semiIndex); + } + + // for qualified commands + int spaceIndex = result.indexOf(" "); + if (spaceIndex > -1) + { + int slashIndex = result.lastIndexOf("/", spaceIndex); + if ((slashIndex > 0)) + { + result = result.substring(slashIndex + 1, result.length()); + } + } + else + { + int slashIndex = result.lastIndexOf("/"); + if ((slashIndex > 0)) + { + result = result.substring(slashIndex + 1, result.length()); + } + } + + return result; + } + + public void refresh(String theCommand) + { + // _previousCommand = _currentCommand; + _currentCommand = cleanCmdString(theCommand); + _currentCommandPatterns.clear(); + parsePatternsFile(); + } + + public void update(String theCommand) + { + // _previousCommand = _currentCommand; + _currentCommand = cleanCmdString(theCommand); + _currentCommandPatterns.clear(); + + // don't reparse patterns file + } + + private File getPatternsFile() + { + if (_thePatternsFile == null) + { + + File thePatternsFile = new File(_pluginPath + "/" + MINERS_PACKAGE + "/" + PATTERNS_FILE); + if (!thePatternsFile.exists()) + { + thePatternsFile = new File(_pluginPath + "/" + PATTERNS_FILE); + if (!thePatternsFile.exists()) + { + thePatternsFile = new File(_pluginPath + "/" + MINERS_PACKAGE + "_" + _version + "/" + PATTERNS_FILE); + + if (!thePatternsFile.exists()) + { + File parentFile = new File(_pluginPath); + if (parentFile.exists()) + { + // now we're really desparate! + // search for a file that looks like it + File[] files = parentFile.listFiles(); + for (int i = 0; i < files.length && !thePatternsFile.exists(); i++) + { + File c = files[i]; + + if (c.getName().startsWith(MINERS_PACKAGE)) + { + thePatternsFile = c; + } + } + } + } + } + } + _thePatternsFile = thePatternsFile; + } + return _thePatternsFile; + } + + private void parsePatternsFile() + { + if (_dataStore == null) + return; + + //Check the timestamp of the patterns.dat file to make sure we need to read it. + File thePatternsFile = getPatternsFile(); + + long newTimeStamp = 0; + if (!thePatternsFile.exists() || ((newTimeStamp = thePatternsFile.lastModified()) == _timeStamp)) + return; + + _timeStamp = newTimeStamp; + + //If we get here, we are actually going to read\parse the file. + try + { + readPatternsFile(thePatternsFile, DE.ENCODING_UTF_8); + } + catch (Exception e) + { + _dataStore.trace(e); + _dataStore.trace("failed to load patterns.dat with UTF-8. Trying with native encoding"); + + try + { + readPatternsFile(thePatternsFile, null); + } + catch (Exception ex) + { + _dataStore.trace(ex); + } + } + } + + private void readPatternsFile(File thePatternsFile, String encoding) throws Exception + { + FileInputStream fileStream = new FileInputStream(thePatternsFile); + InputStreamReader inReader = null; + if (encoding == null) + { + inReader = new InputStreamReader(fileStream); + } + else + { + inReader = new InputStreamReader(fileStream, encoding); + } + BufferedReader reader = new BufferedReader(inReader); + + _theCommands.clear(); + + String curLine; + CommandPattern curCommand = null; + + //Main Loop that reads each line. + while ((curLine = reader.readLine()) != null) + { + curLine = curLine.trim(); + //Skip the current line if it is empty or starts with a # + if ((curLine.length() == 0) || (curLine.charAt(0) == '#')) + continue; + + //Check if this line is the start of a new command section + if (curLine.startsWith("command")) + { + int colon = curLine.indexOf(":"); + //Check that there is something after the colon + if (colon == (curLine.length() - 1)) + continue; + String cmdStr = curLine.substring(colon + 1, curLine.length()).trim(); + + Pattern thePattern = Pattern.compile(cmdStr); + curCommand = new CommandPattern(thePattern); + _theCommands.add(curCommand); + } + + //If we get here, the line must be an output pattern + else + { + int firstSpace = curLine.indexOf(" "); + int patternWord = curLine.indexOf("pattern"); + int firstEquals = curLine.indexOf("="); + if ((firstEquals == -1) || (firstEquals == (curLine.length() - 1))) + continue; + String objType = curLine.substring(0, firstSpace); + String matchOrder = curLine.substring(firstSpace + 1, patternWord).trim(); + String patternString = curLine.substring(firstEquals + 1, curLine.length()); + Pattern thePattern = Pattern.compile(patternString.trim()); + + if (curCommand != null) + curCommand.addOutputPattern(new OutputPattern(objType, matchOrder, thePattern)); + } + } + } + + private List getCurrentCommandPatterns() + { + + if (_currentCommandPatterns.size() == 0) + { + int commands = _theCommands.size(); + + for (int i = 0; i < commands; i++) + { + CommandPattern curCommand = (CommandPattern) _theCommands.get(i); + + if (curCommand.matchCommand(_currentCommand)) + { + _currentCommandPatterns.add(curCommand); + } + } + } + return _currentCommandPatterns; + } + + + public ParsedOutput matchLine(String theLine) + { + + CommandPattern curCommand; + ParsedOutput matchedOutput = null; + + List cmdPatterns = getCurrentCommandPatterns(); + for (int i = 0; i < cmdPatterns.size(); i++) + { + curCommand = (CommandPattern) cmdPatterns.get(i); + + if (curCommand.matchCommand(_currentCommand)) + { + if (_currentCommand.equals("ls") && _isTerminal && !curCommand.getPattern().equals(".*")) + { + } + else + { + matchedOutput = curCommand.matchLine(theLine); + } + } + + if (matchedOutput != null) + { + return matchedOutput; + } + } + + return null; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/environment/EnvironmentMiner.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/environment/EnvironmentMiner.java new file mode 100644 index 00000000000..4596b6cf029 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/environment/EnvironmentMiner.java @@ -0,0 +1,232 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.environment; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.dstore.core.miners.miner.Miner; +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; + +public class EnvironmentMiner extends Miner +{ + public static final String MINER_ID = EnvironmentMiner.class.getName();//"org.eclipse.rse.dstore.universal.miners.environment.EnvironmentMiner"; + + private DataElement _system; + + + public void load() + { + getSystemNode(); + } + + protected ArrayList getDependencies() + { + ArrayList dependencies = new ArrayList(); + return dependencies; + } + + private DataElement getSystemNode() + { + if (_system == null) + { + _system = _dataStore.createObject(_minerData, "Environment Variable", "System Environment"); + _dataStore.refresh(_minerData); + } + return _system; + } + + public void extendSchema(DataElement schemaRoot) + { + DataElement envVar = _dataStore.createObjectDescriptor(schemaRoot, "Environment Variable"); + _dataStore.createReference(envVar, _dataStore.createRelationDescriptor(schemaRoot,"Parent Environment")); + DataElement containerObjectD = _dataStore.findObjectDescriptor("Container Object"); + _dataStore.createReference(containerObjectD, envVar, "abstracts", "abstracted by"); + + createCommandDescriptor(containerObjectD, "Set Environment Variables", "C_SET_ENVIRONMENT_VARIABLES", false); + createCommandDescriptor(containerObjectD, "Set Environment Variables", "C_SET_ENVIRONMENT_VARIABLES_NO_SYSTEM", false); + + DataElement fsObj = _dataStore.findObjectDescriptor("Filesystem Objects"); + DataElement inhabits = _dataStore.createRelationDescriptor(schemaRoot, "inhabits"); + DataElement sustains = _dataStore.createRelationDescriptor(schemaRoot, "sustains"); + + _dataStore.createReference(envVar, sustains); + _dataStore.createReference(fsObj, inhabits); + + + /* + * DY: Retreive environment values required by user define actions + * - temp directory (user.temp) + * - user's home directory (user.home) + */ + DataElement systemInfo = _dataStore.createObject(_minerData, "dstore.structureNode", "systemInfo"); + + _dataStore.createObject(systemInfo, "system.property", "user.home", System.getProperty("user.home")); + _dataStore.createObject(systemInfo, "system.property", "temp.dir", System.getProperty("java.io.tmpdir")); + + _dataStore.createObject(systemInfo, "system.property", "os.name", System.getProperty("os.name")); + _dataStore.createObject(systemInfo, "system.property", "os.version", System.getProperty("os.version")); + + getSystemNode(); + _dataStore.refresh(_minerData); + getSystemEnvironment(); + } + + public DataElement handleCommand (DataElement theElement) + { + String name = getCommandName(theElement); + DataElement status = getCommandStatus(theElement); + DataElement subject = getCommandArgument(theElement, 0); + DataElement env = getCommandArgument(theElement, 1); + + + if (name.equals("C_SET_ENVIRONMENT_VARIABLES")) + { + if (_system.getNestedSize() == 0) + { + getSystemEnvironment(); + } + handleSetEnvironment(subject, env); + } + else if (name.equals("C_SET_ENVIRONMENT_VARIABLES_NO_SYSTEM")) + { + handleSetEnvironment(subject, env); + } + + status.setAttribute(DE.A_NAME, "done"); + return status; + } + + public void handleSetEnvironment(DataElement theElement, DataElement environment) + { + String envName = theElement.getValue() + ".env"; + + //First check to see if we already have an Environment for theElement..and get rid of it if we do. + DataElement envRoot = _dataStore.find(_minerData, DE.A_NAME, envName, 1); + if (envRoot != null) + { + _dataStore.deleteObject(_minerData, envRoot); + _dataStore.refresh(_minerData); + List theReferences = theElement.getAssociated("inhabits"); + if (theReferences.size() > 0) + { + _dataStore.deleteObject(theElement, (DataElement)theReferences.get(0)); + _dataStore.refresh(theElement); + } + } + + environment.setAttribute(DE.A_NAME, envName); + environment.setAttribute(DE.A_VALUE, envName); + + _minerData.addNestedData(environment, false); + environment.setParent(_minerData); + _dataStore.refresh(_minerData); + _dataStore.createReference(theElement, environment, "inhabits", "sustains"); + _dataStore.refresh(environment); + _dataStore.refresh(theElement); + } + + //This sucks, but the best way to get the current list of environment variables is to run the "env" (or "set" on + //windows), and grab the output. Can't use System.properties since this list only includes environment variables + //that you passed in as parameters when you started the VM. + private void getSystemEnvironment() + { + + String envCommand = "sh -c env"; + + String theOS = System.getProperty("os.name").toLowerCase(); + //If we're on windows, change the envCommand. + if (theOS.startsWith("win")) + envCommand = "cmd /c set"; + + if (theOS.startsWith("os/400")) + { + envCommand = "/QOpenSys/usr/bin/sh -c env"; + } + + String specialEncoding= System.getProperty("dstore.stdin.encoding"); + try + { + Process _process = Runtime.getRuntime().exec(envCommand); + + BufferedReader _output = null; + if (specialEncoding != null) + { + _output = new BufferedReader(new InputStreamReader(_process.getInputStream(), specialEncoding)); + } + else + { + _output = new BufferedReader(new InputStreamReader(_process.getInputStream())); + } + + String curLine; + while ( (curLine = _output.readLine()) != null) + { + int eqIndex = curLine.indexOf("="); + if (eqIndex > 0) + { + if (curLine.indexOf("=()") > 0) + { + String multiLine =new String(curLine); + + if (!curLine.endsWith("}")) + { + boolean complete = false; + String subLine = null; + while (!complete && (subLine = _output.readLine()) != null) + { + multiLine += subLine; + if (subLine.indexOf('}') > -1) + { + complete = true; + } + } + } + + //String name = curLine.substring(0, eqIndex); + DataElement var = _dataStore.createObject(_system, "Environment Variable", curLine, multiLine); + var.setAttribute(DE.A_VALUE, multiLine); + } + else + { + if (curLine.startsWith("PATH=")) + { + curLine += ":."; + } + _dataStore.createObject(_system, "Environment Variable", curLine, curLine); + } + + } + } + _dataStore.refresh(_system); + + } + catch (IOException e) + { + System.err.println("Error getting System Environment Variables\n" + e.getMessage()); + } + } + + public String getVersion() + { + return "6.4.0"; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/ClassFileParser.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/ClassFileParser.java new file mode 100644 index 00000000000..ec94e264690 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/ClassFileParser.java @@ -0,0 +1,155 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.filesystem; + +import java.io.DataInputStream; +import java.io.InputStream; +import java.util.ArrayList; + +public class ClassFileParser { + + + private static final int CONSTANT_Class = 7; + private static final int CONSTANT_Fieldref = 9; + private static final int CONSTANT_Methodref = 10; + private static final int CONSTANT_InterfaceMethodref = 11; + private static final int CONSTANT_String = 8; + private static final int CONSTANT_Integer = 3; + private static final int CONSTANT_Float = 4; + private static final int CONSTANT_Long = 5; + private static final int CONSTANT_Double = 6; + private static final int CONSTANT_NameAndType = 12; + private static final int CONSTANT_Utf8 = 1; + + private DataInputStream in; + + private ArrayList classes = new ArrayList(); + private ArrayList utf8s = new ArrayList(); + + private class _Class { + public int pool_index; + public int name_index; + + public _Class(int pIndx, int nIndx) { + pool_index = pIndx; + name_index = nIndx; + } + } + + private class _Utf8 { + public int pool_index; + public byte[] bytes; + + public _Utf8(int pIndx, byte[] bytes) { + pool_index = pIndx; + this.bytes = bytes; + } + } + + + public ClassFileParser(InputStream stream) + { + in = new DataInputStream(stream); + } + + public String getPackageName() + { + String packageName = null; + try { + // Skip magic / miner / major + in.skipBytes(8); + + int constPoolCount = in.readUnsignedShort(); + + // Read in the constant_pool storing Class and Utf8 entries + int tag; + int index; + int len; + byte[] data; + for (int loop = 1; loop < constPoolCount; loop++) { + tag = in.readUnsignedByte(); + switch (tag) { + case CONSTANT_Class: + index = in.readUnsignedShort(); + classes.add(new _Class(loop, index)); + break; + + case CONSTANT_Utf8: + len = in.readUnsignedShort(); + data = new byte[len]; + in.read(data, 0, len); + utf8s.add(new _Utf8(loop, data)); + break; + + case CONSTANT_Fieldref: + case CONSTANT_Methodref: + case CONSTANT_InterfaceMethodref: + case CONSTANT_Integer: + case CONSTANT_Float: + case CONSTANT_NameAndType: + in.skipBytes(4); + break; + + case CONSTANT_String: + in.skipBytes(2); + break; + + case CONSTANT_Long: + case CONSTANT_Double: + in.skipBytes(8); + // these take two entries in constant pool + loop++; + break; + + default: + break; + } + } + + // Skip access flags + in.skipBytes(2); + int classNameIndex = in.readUnsignedShort(); + + boolean found = false; + int utf8Index = -1; + for(int loop = 0; loop < classes.size() && !found; loop++) { + if (((_Class)classes.get(loop)).pool_index == classNameIndex) { + found = true; + utf8Index = ((_Class)classes.get(loop)).name_index; + } + } + + found = false; + for (int loop = 0; loop < utf8s.size() && !found; loop++) { + if (((_Utf8)utf8s.get(loop)).pool_index == utf8Index) { + packageName = new String(((_Utf8)utf8s.get(loop)).bytes); + packageName = packageName.replace('/', '.'); + found = true; + } + } + + in.close(); + + + } catch (Exception e) { + e.printStackTrace(); + } + + return packageName; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/FileClassifier.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/FileClassifier.java new file mode 100644 index 00000000000..9d849f88f28 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/FileClassifier.java @@ -0,0 +1,1036 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.filesystem; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.services.clientserver.IServiceConstants; +import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; +import org.eclipse.rse.services.clientserver.java.BasicClassFileParser; + + +/* + * This utility class is for determing file types + */ +public class FileClassifier extends Thread +{ + protected class Pair + { + private String _fileName; + + private String _canonicalName; + + private DataElement _element; + + public Pair(String fileName, DataElement element) + { + _fileName = fileName; + _element = element; + } + + public DataElement getElement() + { + return _element; + } + + public String getFileName() + { + return _fileName; + } + + public String getCanonicalName() + { + return _canonicalName; + } + + public void setCanonicalName(String canonicalName) + { + _canonicalName = canonicalName; + } + } + + public static final String symbolicLinkStr = "symbolic link to"; + + public static final String fileSep = System.getProperty("file.separator"); + public static final String defaultType = "file"; + + public static final String STR_SYMBOLIC_LINK = "symbolic link"; + public static final String STR_SHARED_OBJECT="shared object"; + public static final String STR_OBJECT_MODULE="object module"; + public static final String STR_MODULE="module"; + public static final String STR_ARCHIVE="archive"; + public static final String STR_EXECUTABLE="executable"; + public static final String STR_SCRIPT="script"; + public static final String STR_EXECUTABLE_SCRIPT="executable(script)"; + public static final String STR_EXECUTABLE_BINARY="executable(binary)"; + public static final String STR_DOT_A=".a"; + public static final String STR_DOT_SO=".so"; + public static final String STR_DOT_SO_DOT=".so."; + public static final String STR_DIRECTORY="diectory"; + + + private DataElement _subject; + + private DataStore _dataStore; + + private String _specialEncoding = null; + + protected String _systemShell = null; + + private List _fileMap; + + private boolean _classifyChildren = true; + + private boolean _canResolveLinks = false; + + private boolean _classifyVirtual = false; + + private boolean _systemSupportsClassify = true; + + private boolean _systemSupportsClassFilesOnly = false; + + private List _lines; + + public FileClassifier(DataElement subject) + { + _lines = new ArrayList(); + // special encoding passed in when starting server + _specialEncoding = System.getProperty("dstore.stdin.encoding"); + + _subject = subject; + _dataStore = subject.getDataStore(); + _fileMap = new ArrayList(); + + // we can resolve links on Linux + String osName = System.getProperty("os.name").toLowerCase(); + if (osName.startsWith("win")) + { + _systemSupportsClassify = false; + } + else if (osName.equals("z/OS")) { + _systemSupportsClassFilesOnly = true; + } + + _systemShell = "sh"; + _canResolveLinks = osName.startsWith("linux"); + + init(); + } + + private void init() + { + String objType = _subject.getType(); + + // determine if we are classifying virtual files + // we are if the subject is an archive, virtual folder or a virtual file + if (objType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) || objType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR) + || objType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) + { + _classifyVirtual = true; + } + else + { + _classifyVirtual = false; + } + + // if the subject is a file or a virtual file (i.e. not a directory or + // an archive), then + // we do not classify children (since there are no children) + if (objType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) || objType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) + { + _classifyChildren = false; + } + // otherwise, put children in hashmap + else + { + // store all datalements in hashmap + for (int i = 0; i < _subject.getNestedSize(); i++) + { + DataElement child = _subject.get(i); + + if (child.getType().equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) + || child.getType().equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) + || child.getType().equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR)) + { + String name = child.getName(); + String properties = child.getSource(); + + // if this file has already been classified + // ignore it + String[] tokens = properties.split("\\" + IServiceConstants.TOKEN_SEPARATOR); + + if (tokens.length < 12) + { + putElement(name, child); + } + /* + * StringTokenizer tokenizer = new + * StringTokenizer(properties, + * IUniversalDataStoreConstants.TOKEN_SEPARATOR); if + * (tokenizer.countTokens() < 12) { putElement(name, child); } + */ + } + } + + _classifyChildren = true; + } + } + + private void putElement(String name, DataElement child) + { + _fileMap.add(new Pair(name, child)); + } + + /** + * Gets the data element for the given name from the name to data element + * mapping. + * + * @param name + * the name. + * @return the data element corresponding to that name. + */ + private List getElementsFor(String fileName) + { + boolean matchedCanonical = false; + ArrayList results = new ArrayList(); + for (int i = 0; i < _fileMap.size(); i++) + { + Pair apair = (Pair) _fileMap.get(i); + String canonicalName = apair.getCanonicalName(); + if (canonicalName != null) + { + if (canonicalName.equals(fileName)) + { + + if (!matchedCanonical) + { + results.clear(); + matchedCanonical = true; + } + results.add(apair); + } + } + else if (apair.getFileName().equals(fileName) && !matchedCanonical) + { + results.add(apair); + } + } + return results; + } + + public void run() + { + if (!_systemSupportsClassify) + return; + + // get full path + StringBuffer fPathBuf = new StringBuffer(_subject.getValue()); + fPathBuf.append(File.separatorChar); + fPathBuf.append(_subject.getName()); + String filePath = fPathBuf.toString(); + + // if we have to classify children + if (_classifyChildren) + { + + + // if it's not a classification of virtual files + if (!_classifyVirtual) + { + File parentFile = new File(filePath); + + // if parent file is a directory, classify all its children, and + // do not + // resolve links by default + if (parentFile.isDirectory() && parentFile.list().length > 0) + { + classifyChildren(parentFile, "*", false); + } + } + else + { + classifyVirtualChildren(filePath); + } + + _dataStore.refresh(_subject); + } + else + { + File theFile = new File(filePath); + + if (theFile.exists()) + { + try + { + String type = classifyFile(theFile.getCanonicalFile()); + StringBuffer classifiedProperties = new StringBuffer(_subject.getSource()); + classifiedProperties.append('('); + classifiedProperties.append(type); + classifiedProperties.append(')'); + _subject.setAttribute(DE.A_SOURCE, classifiedProperties.toString()); + _dataStore.refresh(_subject); + } + catch (Exception e) + { + } + } + } + } + + /** + * Classifies from the given line of classification output. + * + * @param parentFile + * the parent file. + * @param line + * the line of output to parse. + * @param specialEncoding + * a special encoding, if there is one. + * @param resolveLink + * resolve link. + * @return the classification. + */ + protected String classify(File parentFile, String line, String specialEncoding, boolean resolveLink) + { + // this string should be contained in an output line that indicates a + // symbolic link + + + // default type + String type = defaultType; + + int colon = line.indexOf(':'); + + // name appears before colon + String name = line.substring(0, colon); + + // the full type appears after the colon + String fulltype = line.substring(colon + 1, line.length()).trim(); + + // if it's a *.class file, then we look for main method and qulaified + // class name + // as part of the classification + if (name.endsWith(".class")) + { + // get parent path + String parentPath = parentFile.getAbsolutePath(); + + // get file separator + + + // if parent path does not end with separator, then add it + if (!parentPath.endsWith(fileSep)) + { + parentPath = parentPath + fileSep; + } + + // add name to parent path to get file path + String filePath = parentPath + name; + + // input stream to file + FileInputStream stream = null; + + // class file parser + BasicClassFileParser parser = null; + + boolean isExecutable = false; + + try + { + stream = new FileInputStream(filePath); + + // use class file parser to parse the class file + parser = new BasicClassFileParser(stream); + parser.parse(); + + // query if it is executable, i.e. whether it has main method + isExecutable = parser.isExecutable(); + } + catch (IOException e) + { + // TODO: log it + + // we assume not executable + isExecutable = false; + } + + // if it is executable, then also get qualified class name + if (isExecutable) + { + type = "executable(java"; + + String qualifiedClassName = parser.getQualifiedClassName(); + + if (qualifiedClassName != null) + { + type = type + ":" + qualifiedClassName; + } + + type = type + ")"; + } + return type; + } + + // if the system supports only classifying *.class files, then return generic type "file". + if (_systemSupportsClassFilesOnly) { + return type; + } + + boolean matchesLib = (fulltype.indexOf(STR_SHARED_OBJECT) > -1) || (fulltype.indexOf(STR_OBJECT_MODULE) > -1) || (fulltype.indexOf(STR_ARCHIVE) > -1); + + boolean matchesExe = (fulltype.indexOf(STR_EXECUTABLE) > -1); + boolean matchesScript = (fulltype.indexOf(STR_SCRIPT) > -1); + // shared + if (matchesLib && (name.endsWith(STR_DOT_A) || name.endsWith(STR_DOT_SO) || name.indexOf(STR_DOT_SO_DOT) > 0)) + { + type = STR_MODULE; + } + else if (matchesScript) + { + if (matchesExe) + { + type = STR_EXECUTABLE_SCRIPT; + } + else + { + type = STR_SCRIPT; + } + } + // if the fullType contains "executable", then it is either a script + // executable or a binary + // executable + else if (matchesExe) + { + type = STR_EXECUTABLE_BINARY; + } + else if (fulltype.indexOf(STR_DIRECTORY) > -1) + { + type = STR_DIRECTORY; + } + // finally, if the full type contains the symbolic link string, then we + // know + // we have a symbolic link + else if (fulltype.startsWith(symbolicLinkStr)) + { + type = resolveSymbolicLink(parentFile, name, fulltype, symbolicLinkStr, resolveLink, specialEncoding); + } + + return type; + } + + protected String resolveSymbolicLink(File parentFile, String originalName, String fulltype, String symbolicLinkStr, boolean resolveLink, String specialEncoding) + { + // type is "link" + StringBuffer type = new StringBuffer(STR_SYMBOLIC_LINK); + + // find the target (i.e. referenced) file + String referencedFile = fulltype.substring(symbolicLinkStr.length()).trim(); + File refFile = new File(referencedFile); + if (refFile.isDirectory()) + { + type.append("(directory)"); + return type.toString(); + } + + try + { + // if we are supposed to resolve link, then do so by running "sh -c + // file " + // with being the reference file name + if (resolveLink) + { + + String args[] = new String[3]; + args[0] = _systemShell; + args[1] = "-c"; + args[2] = "file " + referencedFile; + + Process childProcess = Runtime.getRuntime().exec(args, null, parentFile); + BufferedReader childReader = null; + + if (specialEncoding != null && specialEncoding.length() > 0) + { + childReader = new BufferedReader(new InputStreamReader(childProcess.getInputStream(), specialEncoding)); + } + else + { + childReader = new BufferedReader(new InputStreamReader(childProcess.getInputStream())); + } + + String childLine = childReader.readLine().trim(); + + type.append('('); + type.append(classify(parentFile, childLine, specialEncoding, resolveLink)); + type.append(')'); + + childReader.close(); + + } + } + catch (Exception e) + { + } + return type.toString(); + } + + /** + * Classify a file. It classifies the file by running "sh -c file + * ". + * + * @param aFile + * the file to classify. + * @return the classification. + */ + public String classifyFile(File aFile) + { + String type = defaultType; + + try + { + String referencedFile = aFile.getCanonicalPath(); + + String specialEncoding = System.getProperty("dstore.stdin.encoding"); + /* + if (specialEncoding == null) + { + specialEncoding = System.getProperty("file.encoding"); + } +*/ + specialEncoding = null; + String args[] = new String[3]; + args[0] = "sh"; + args[1] = "-c"; + args[2] = "file " + referencedFile; + + Process childProcess = Runtime.getRuntime().exec(args); + + BufferedReader childReader = null; + + if (specialEncoding != null && specialEncoding.length() > 0) + { + childReader = new BufferedReader(new InputStreamReader(childProcess.getInputStream(), specialEncoding)); + } + else + { + childReader = new BufferedReader(new InputStreamReader(childProcess.getInputStream())); + } + + String childLine = null; + try + { + childLine = childReader.readLine().trim(); + } + catch (Exception e) + { + + } + + type = classify(aFile.getParentFile(), childLine, specialEncoding, true); + + childReader.close(); + } + catch (Exception e) + { + } + + return type; + } + + protected List readLines(DataInputStream stream, String encoding) throws Exception + { + + if (encoding == null) + { + encoding = System.getProperty("file.encoding"); + } + + + try + { + + // find out how many bytes are available to be read + int available = stream.available(); + while (available > -1) + { + // if there's none, wait a bit and return true to continue + if (available == 0) + { + sleep(100); + available = stream.available(); + if (available == 0) + return _lines; + } + + byte[] readBytes = new byte[available]; + + // read the available bytes + int numRead = stream.read(readBytes, 0, available); + + // if we've reached end of stream, quit + if (numRead == -1) + { + return null; + } + + + // get the output using the encoding + try + { + + String fullOutput = new String(readBytes, 0, numRead, encoding); + + // if output is not null, we assume the encoding was correct and + // process the output + if (fullOutput != null /* && fullOutput.length() == numRead */) + { + // tokenize the output so that we can get each line of + // output + // the delimiters are therefore set to "\n\r" + String[] tokens = fullOutput.split("\n"); + if (tokens.length > 0) + { + if (_lines.size() > 0) + { + String lastLine = (String)_lines.remove(_lines.size() -1); + tokens[0] = lastLine + tokens[0]; + } + + for (int i = 0; i< tokens.length; i++) + { + _lines.add(tokens[i]); + } + } + } + } + catch (Exception e) + { + } + available = stream.available(); + } + + } + catch (Exception e) + { + + } + + return _lines; + + } + + protected String readLine(DataInputStream stream, String encoding) throws Exception + { + if (_lines.size() == 0) + { + _lines = readLines(stream, encoding); + } + if (_lines == null) + { + return null; + } + if (_lines.size() > 0) + { + return (String)_lines.remove(0); + } + return null; + } + + /** + * Classifies the children of a given file. + * + * @param parentFile + * the parent file. + * @param files + * the files to classify. Specify "*" to classify all files. + * @param resolveLinks + * resolve links if possible. + */ + protected void classifyChildren(File parentFile, String files, boolean resolveLinks) + { + + try + { + boolean hasLinks = false; + + String[] args = new String[3]; + args[0] = "sh"; + + args[1] = "-c"; + + // if we are asked to resolve children, and it is possible to do so + // then use "file -L". This is slower than if we run without the + // "-L". + if (resolveLinks && _canResolveLinks) + { + args[2] = "file -L " + files; + } + // otherwise, don't use "-L" + else + { + args[2] = "file " + files; + + } + + // run command with the working directory being the parent file + Process theProcess = Runtime.getRuntime().exec(args, null, parentFile); + + BufferedReader reader = null; + DataInputStream stream = null; + + if (_specialEncoding != null) + { + stream = new DataInputStream(theProcess.getInputStream()); + reader = new BufferedReader(new InputStreamReader(stream, _specialEncoding)); + } + else + { + stream = new DataInputStream(theProcess.getInputStream()); + } + + // a list of files to be queried after + List deferredQueries = new ArrayList(); + + String line = null; + try + { + if (reader != null) + line = reader.readLine(); + else + line = readLine(stream, _specialEncoding);//reader.readLine(); + } + catch (Exception e) + { + } + + // read each line of output + while (line != null) + { + if (line.length() > 0) + { + line = line.trim(); + if (line.indexOf("cannot open ") > 0) + { + + } + else + { + int colon = line.indexOf(':'); + + // sometimes we get two lines of output for each file + // so ignore second line + if (colon != -1) + { + + // name of classified file + String name = line.substring(0, colon); + + // get classification from line, and do not resolve + // link + String type = classify(parentFile, line, _specialEncoding, false); + + // get data elements- may be more than one (in case + // of link) + List pairs = getElementsFor(name); + for (int d = 0; d < pairs.size(); d++) + { + Pair pair = (Pair) pairs.get(d); + + DataElement element = pair.getElement(); + + // if the element was in our list of mappings + if (element != null) + { + + // referencing file + StringBuffer path = new StringBuffer(element.getValue()); + path.append(File.separatorChar); + path.append(element.getName()); + File refFile = new File(path.toString()); + + // canonical file path + + String canonicalPath = null; + + // if the file is a link resolve it + // if it's a link and we're already trying + // to resolve links, ignore it + if (type.equals(STR_SYMBOLIC_LINK) && !resolveLinks) + { + + // get canonical file path + canonicalPath = refFile.getCanonicalPath(); + + // if we can't resolve links, then get + // the canonical file using Java + if (!_canResolveLinks) + { + // get canonical file + File canFile = refFile.getCanonicalFile(); + + // put canonical file in our list of + // mappings with + // the current element (so the + // canonical file name + // corresponds to this element + // subsequently) + pair.setCanonicalName(canonicalPath); + + // get parent of canonical file + File cP = canFile.getParentFile(); + + // add canonical file parent to + // deferred query list + if (!deferredQueries.contains(cP)) + { + deferredQueries.add(cP); + } + } + + // we can resolve links, so indicate it + // with a flag + hasLinks = true; + } + else + { + // remove from list + _fileMap.remove(pair); + + if (type.equals(STR_SYMBOLIC_LINK)) + { + canonicalPath = refFile.getCanonicalPath(); + } + } + + // set current properties + StringBuffer currentProperties = new StringBuffer(element.getAttribute(DE.A_SOURCE)); + + // determine text to write + StringBuffer textToWrite = new StringBuffer(type); + + // if type is "link", we write a string of + // form "link:canonicalPath" + if (type.equals(STR_SYMBOLIC_LINK)) + { + if (type.indexOf(":") == -1) + { + textToWrite.append(':'); + textToWrite.append(canonicalPath); + } + } + + // determine text to check for + String textToCheck = STR_SYMBOLIC_LINK; + + int linkIndex = currentProperties.lastIndexOf(textToCheck); + + if (linkIndex != -1) + { + int cutOffIndex = linkIndex + textToCheck.length(); + + StringBuffer typeBuf = new StringBuffer(); + typeBuf.append('('); + typeBuf.append(type); + typeBuf.append(')'); + currentProperties.insert(cutOffIndex, typeBuf.toString()); + element.setAttribute(DE.A_SOURCE, currentProperties.toString()); + } + else + { + currentProperties.append('|'); + currentProperties.append(textToWrite); + element.setAttribute(DE.A_SOURCE, currentProperties.toString()); + } + } + } + } + } + } + + try + { + if (reader != null) + line = reader.readLine(); + else + line = readLine(stream, _specialEncoding); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + if (reader != null) + reader.close(); + else + stream.close(); + // we have found links + if (hasLinks) + { + // if we were told not to resolve them, but we are capable of + // doing so, then + // let's try again + if (!resolveLinks && _canResolveLinks) + { + // we pass true to indicate we want to resolve links this + // time + classifyChildren(parentFile, "*", true); + } + // otherwise, run deferred queries on parents of target files + // and try to resolve link + else + { + // run deferred queries on canonical file parents + for (int i = 0; i < deferredQueries.size(); i++) + { + File aFile = (File) deferredQueries.get(i); + + // we pass true to indicate we want to resolve links + // this time + StringBuffer newPathBuf = new StringBuffer(aFile.getAbsolutePath()); + newPathBuf.append(File.separatorChar); + newPathBuf.append('*'); + classifyChildren(parentFile, newPathBuf.toString(), true); + } + } + } + } + catch (Exception e) + { + e.printStackTrace(); + } + + } + + /** + * Classify virtual children. + * + * @param fullPath + * the full path of the parent file. The path could represent an + * archive or a virtual folder. + */ + protected void classifyVirtualChildren(String parentPath) + { + ArchiveHandlerManager mgr = ArchiveHandlerManager.getInstance(); + + // clean up path + // DKM - this strips leading / so I'm putting it back + parentPath = '/' + ArchiveHandlerManager.cleanUpVirtualPath(parentPath); + + // check if parent is an archive + boolean isArchive = mgr.isRegisteredArchive(parentPath); + + // check if parent is virtual + boolean isVirtual = ArchiveHandlerManager.isVirtual(parentPath); + + VirtualChild[] children = null; + + try + { + + File archiveFile = null; + String virtualPath = null; + + // if the parent is an archive and not a virtual + if (isArchive && !isVirtual) + { + + // archive file is simply the path passed in + archiveFile = new File(parentPath); + + // virtual path is "" to indicate we want the top level entries + // in the archive + virtualPath = ""; + } + // otherwise, if the parent is a virtual folder + else + { + AbsoluteVirtualPath avp = new AbsoluteVirtualPath(parentPath); + + // get the path of the containing archive + String archivePath = avp.getContainingArchiveString(); + + // get the virtual part of the file path + virtualPath = avp.getVirtualPart(); + + // get archive file + archiveFile = new File(archivePath); + } + + // get the contents of the virtual path within the archive + children = mgr.getContents(archiveFile, virtualPath); + + // go through each virtual child, and set the classification type + for (int i = 0; i < children.length; i++) + { + VirtualChild child = children[i]; + + String type = defaultType; + + // only classify if the virtual child is not a directory + if (!child.isDirectory) + { + + // name of virtual child + String name = child.name; + + // get classification + type = mgr.getClassification(archiveFile, child.fullName); + + // get data element + List matches = getElementsFor(name); + for (int c = 0; c < matches.size(); c++) + { + Pair pair = (Pair) matches.get(c); + DataElement element = pair.getElement(); + + // if element is in our list of mappings + if (element != null) + { + + // remove element from list of mappings + _fileMap.remove(pair); + + // add type to current properties + StringBuffer currentProperties = new StringBuffer(element.getAttribute(DE.A_SOURCE)); + currentProperties.append('|'); + currentProperties.append(type); + + element.setAttribute(DE.A_SOURCE, currentProperties.toString()); + } + } + } + } + } + catch (IOException e) + { + // TODO: log error + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalByteStreamHandler.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalByteStreamHandler.java new file mode 100644 index 00000000000..32afbb6b035 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalByteStreamHandler.java @@ -0,0 +1,348 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.filesystem; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; + +import org.eclipse.dstore.core.model.ByteStreamHandler; +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.rse.services.clientserver.IClientServerConstants; +import org.eclipse.rse.services.clientserver.IServiceConstants; +import org.eclipse.rse.services.clientserver.SystemEncodingUtil; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; +import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; + + + +/** + * This class overrides ByteStreamHandler to handle cases where + * virtual files are being transfered to the host + */ +public class UniversalByteStreamHandler extends ByteStreamHandler +{ + + public UniversalByteStreamHandler(DataStore dataStore, DataElement log) + { + super(dataStore, log); + } + + + + /** + * Save a file in the specified location. This method is called by the + * DataStore when the communication layer receives a file transfer + * + * @param remotePath the path where to save the file + * @param buffer the bytes to insert in the file + * @param size the number of bytes to insert + * @param binary indicates whether to save the bytes as binary or text + */ + public void receiveBytes(String remotePath, byte[] buffer, int size, boolean binary) + { + boolean isVirtual = ArchiveHandlerManager.isVirtual(remotePath); + + if (!isVirtual) + { + super.receiveBytes(remotePath, buffer, size, binary); + return; + } + + remotePath = ArchiveHandlerManager.cleanUpVirtualPath(remotePath); + DataElement status = findStatusFor(remotePath); + String fileName = _dataStore.mapToLocalPath(remotePath); + + if (fileName != null) + { + String virtualFileName = fileName; + + ArchiveHandlerManager mgr = ArchiveHandlerManager.getInstance(); + VirtualChild child = mgr.getVirtualObject(virtualFileName); + ISystemArchiveHandler handler = child.getHandler(); + + try + { + File file = child.getExtractedFile(); + fileName = file.getAbsolutePath(); + + if (!file.exists()) + { + File parent = new File(file.getParent()); + parent.mkdirs(); + } + else + { + } + + File newFile = new File(fileName); + FileOutputStream fileStream = new FileOutputStream(newFile); + + if (binary) + { + fileStream.write(buffer, 0, size); + } + else + { + String bufferString = new String(buffer, 0, size, SystemEncodingUtil.ENCODING_UTF_8); + + // hack for zOS + String theOS = System.getProperty("os.name"); + if (theOS.toLowerCase().startsWith("z")) + { + bufferString = bufferString.replace('\r', ' '); + } + + OutputStreamWriter writer = new OutputStreamWriter(fileStream); + writer.write(bufferString, 0, size); + writer.flush(); + } + + fileStream.close(); + + // write the temp file to the archive + if (handler == null) + { + int virtualIndex = virtualFileName.indexOf(ArchiveHandlerManager.VIRTUAL_SEPARATOR); + String filePath = virtualFileName.substring(0, virtualIndex); + handler = mgr.getRegisteredHandler(new File(filePath)); + } + boolean success = handler != null && handler.add(newFile, child.path, child.name); + if (!success) + { + if (status == null) return; + status.setAttribute(DE.A_VALUE, IClientServerConstants.FILEMSG_REMOTE_SAVE_FAILED); + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + _dataStore.refresh(status.getParent()); + } + else + { + if (status == null) return; + status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); + _dataStore.refresh(status.getParent()); + } + } + catch (IOException e) + { + _dataStore.trace(e); + if (status == null) return; + status.setAttribute(DE.A_VALUE, IClientServerConstants.FILEMSG_REMOTE_SAVE_FAILED); + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + _dataStore.refresh(status.getParent()); + } + catch (Exception e) + { + _dataStore.trace(e); + if (status == null) return; + status.setAttribute(DE.A_VALUE, IClientServerConstants.FILEMSG_REMOTE_SAVE_FAILED); + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + _dataStore.refresh(status.getParent()); + } + } + } + + /** + * Append a bytes to a file at a specified location. This method is called by the + * DataStore when the communication layer receives a file transfer append. + * + * @param remotePath the path where to save the file + * @param buffer the bytes to append in the file + * @param size the number of bytes to append in the file + * @param binary indicates whether to save the bytes as binary or text + */ + public void receiveAppendedBytes(String remotePath, byte[] buffer, int size, boolean binary) + { + + boolean isVirtual = ArchiveHandlerManager.isVirtual(remotePath); + if (!isVirtual) + { + super.receiveAppendedBytes(remotePath, buffer, size, binary); + return; + } + + remotePath = ArchiveHandlerManager.cleanUpVirtualPath(remotePath); + DataElement status = findStatusFor(remotePath); + String fileName = _dataStore.mapToLocalPath(remotePath); + + if (fileName != null) + { + String virtualFileName = fileName; + + ArchiveHandlerManager mgr = ArchiveHandlerManager.getInstance(); + VirtualChild child = mgr.getVirtualObject(virtualFileName); + if (!child.exists()) + { + System.out.println(virtualFileName + " does not exist."); + return; + } + ISystemArchiveHandler handler = child.getHandler(); + + try + { + boolean success; + + File file = child.getExtractedFile(); + fileName = file.getAbsolutePath(); + + if (!file.exists()) + { + File parent = new File(file.getParent()); + parent.mkdirs(); + + File newFile = new File(fileName); + FileOutputStream fileStream = new FileOutputStream(newFile); + + //boolean binary = false; + if (binary) + { + fileStream.write(buffer, 0, size); + } + else + { + String bufferString = new String(buffer, 0, size, SystemEncodingUtil.ENCODING_UTF_8); + + // hack for zOS + String theOS = System.getProperty("os.name"); + if (theOS.toLowerCase().startsWith("z")) + { + bufferString = bufferString.replace('\r', ' '); + } + + OutputStreamWriter writer = new OutputStreamWriter(fileStream); + writer.write(bufferString, 0, size); + writer.flush(); + } + + fileStream.close(); + // write the temp file to the archive + if (handler == null) + { + int virtualIndex = virtualFileName.indexOf(ArchiveHandlerManager.VIRTUAL_SEPARATOR); + String filePath = virtualFileName.substring(0, virtualIndex); + handler = mgr.getRegisteredHandler(new File(filePath)); + } + success = handler != null && handler.add(newFile, child.path, child.name); + + } + else + { + // need to reorganize this so that we don't use up all the memory + // divide appendedBuffer into chunks + // at > 50M this kills Eclipse + File oldFile = new File(fileName); + File newFile = new File(fileName + ".new"); + newFile.createNewFile(); + + FileInputStream oldFileStream = new FileInputStream(oldFile); + FileOutputStream newFileStream = new FileOutputStream(newFile); + + // write old file to new file + int maxSize = 5000000; + int written = 0; + int oldSize = (int) oldFile.length(); + int bufferSize = (oldSize > maxSize) ? maxSize : oldSize; + byte[] subBuffer = new byte[bufferSize]; + + while (written < oldSize) + { + int subWritten = 0; + + while (written < oldSize && subWritten < bufferSize) + { + int available = oldFileStream.available(); + available = (bufferSize > available) ? available : bufferSize; + int read = oldFileStream.read(subBuffer, subWritten, available); + subWritten += read; + written += subWritten; + } + + newFileStream.write(subBuffer, 0, subWritten); + } + + oldFileStream.close(); + + // write new buffer to new file + if (binary) + { + newFileStream.write(buffer, 0, size); + } + else + { + String bufferString = new String(buffer, 0, size, SystemEncodingUtil.ENCODING_UTF_8); + + // hack for zOS + String theOS = System.getProperty("os.name"); + if (theOS.toLowerCase().startsWith("z")) + { + bufferString = bufferString.replace('\r', ' '); + } + + OutputStreamWriter writer = new OutputStreamWriter(newFileStream); + writer.write(bufferString, 0, size); + writer.flush(); + } + + newFileStream.close(); + + // remote old file + oldFile.delete(); + + // rename new file + newFile.renameTo(oldFile); + + // write the temp file to the archive + if (handler == null) + { + int virtualIndex = virtualFileName.indexOf(ArchiveHandlerManager.VIRTUAL_SEPARATOR); + String filePath = virtualFileName.substring(0, virtualIndex); + handler = mgr.getRegisteredHandler(new File(filePath)); + } + success = handler != null && handler.add(newFile, child.path, child.name); + + } + + if (!success) + { + if (status == null) return; + status.setAttribute(DE.A_VALUE, IClientServerConstants.FILEMSG_REMOTE_SAVE_FAILED); + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + _dataStore.refresh(status.getParent()); + } + else + { + if (status == null) return; + status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); + _dataStore.refresh(status.getParent()); + } + } + catch (IOException e) + { + _dataStore.trace(e); + if (status == null) return; + status.setAttribute(DE.A_VALUE, IClientServerConstants.FILEMSG_REMOTE_SAVE_FAILED); + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + _dataStore.refresh(status.getParent()); + } + } + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalDownloadHandler.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalDownloadHandler.java new file mode 100644 index 00000000000..62e78379176 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalDownloadHandler.java @@ -0,0 +1,267 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.filesystem; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.UnsupportedEncodingException; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.core.model.IByteConverter; +import org.eclipse.rse.dstore.universal.miners.ICancellableHandler; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.dstore.universal.miners.UniversalServerUtilities; +import org.eclipse.rse.services.clientserver.IServiceConstants; +import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath; +import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; +import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; + + +public class UniversalDownloadHandler extends Thread implements ICancellableHandler +{ + + private boolean _isDone = false; + private DataStore _dataStore; + private UniversalFileSystemMiner _miner; + private DataElement _status; + private DataElement _cmdElement; + private boolean _isCancelled= false; + + public UniversalDownloadHandler(DataStore dataStore, UniversalFileSystemMiner miner, DataElement cmdElement, DataElement status) + { + _miner = miner; + _dataStore = dataStore; + _status = status; + _cmdElement = cmdElement; + } + + public void run() + { + handleDownload(_cmdElement, _status); + _isDone = true; + } + + public boolean isDone() + { + return _isDone; + } + + public boolean isCancelled() + { + return _isCancelled; + } + + public void cancel() + { + _dataStore.trace("cancelling download"); + _isCancelled = true; + } + + + protected DataElement handleDownload(DataElement theElement, DataElement status) + { + DataElement arg1 = _miner.getCommandArgument(theElement, 1); + String elementType = arg1.getType(); + String remotePath = arg1.getName(); + + int buffer_size = IUniversalDataStoreConstants.BUFFER_SIZE; + DataElement bufferSizeElement = _dataStore.find(theElement, DE.A_TYPE, "buffer_size", 1); + if (bufferSizeElement != null) + { + try + { + buffer_size = Integer.parseInt(bufferSizeElement.getName()); + } + catch (Exception e) + { + } + } + + String resultType = null; + String resultMessage = null; + + + FileInputStream inputStream = null; + BufferedInputStream bufInputStream = null; + + + try + { + if (elementType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) || elementType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) || elementType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) + { + + _dataStore.trace("download:" + remotePath + "," + elementType); + + File file = new File(remotePath); + + + if (elementType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) + { + AbsoluteVirtualPath vpath = _miner.getAbsoluteVirtualPath(remotePath); + + ISystemArchiveHandler handler = _miner.getArchiveHandlerFor(vpath.getContainingArchiveString()); + if (handler == null) + { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + resultType = IUniversalDataStoreConstants.DOWNLOAD_RESULT_IO_EXCEPTION; + resultMessage = "Corrupted archive."; + _isDone = true; + _dataStore.createObject(arg1, resultType, resultMessage); + _dataStore.refresh(arg1); + return _miner.statusDone(status); + } + VirtualChild vChild = handler.getVirtualFile(vpath.getVirtualPart()); + file = vChild.getExtractedFile(); + + } + + DataElement arg2 = _miner.getCommandArgument(theElement, 2); + DataElement arg3 = _miner.getCommandArgument(theElement, 3); + + int mode = (Integer.valueOf(arg1.getSource())).intValue(); + String localPath = arg2.getName(); + + boolean isText = (mode == IUniversalDataStoreConstants.TEXT_MODE); + + String clientEncoding = null; + + if (isText) + { + clientEncoding = arg2.getSource(); + } + + // Read in the file + inputStream = new FileInputStream(file); + bufInputStream = new BufferedInputStream(inputStream, buffer_size); + + int totalBytes = (int)file.length(); + int totalWritten = 0; + + boolean first = true; + byte[] buffer = new byte[buffer_size]; + byte[] convBytes; + int numToRead = 0; + + IByteConverter byteConverter = _dataStore.getByteConverter(); + byteConverter.setContext(file); + + int available = bufInputStream.available(); + + while (available > 0 && !_isCancelled) + { + numToRead = (available < buffer_size) ? available : buffer_size; + + int bytesRead = bufInputStream.read(buffer, 0, numToRead); + + if (bytesRead == -1) + break; + if (isText) + { + convBytes = byteConverter.convertHostBytesToClientBytes(buffer, 0, bytesRead); + + if (first) + { // send first set of bytes + first = false; + _dataStore.updateFile(localPath, convBytes, convBytes.length, true); + } + else + { // append subsequent segments + _dataStore.updateAppendFile(localPath, convBytes, convBytes.length, true); + } + totalWritten += convBytes.length; + } + else + { + + if (first) + { // send first set of bytes + first = false; + _dataStore.updateFile(localPath, buffer, bytesRead, true); + } + else + { // append subsequent segments + _dataStore.updateAppendFile(localPath, buffer, bytesRead, true); + } + totalWritten +=bytesRead; + } + + status.setAttribute(DE.A_SOURCE, "sent "+totalWritten + " of "+totalBytes); + _dataStore.refresh(status); + available = bufInputStream.available(); + } + + resultType = IUniversalDataStoreConstants.DOWNLOAD_RESULT_SUCCESS_TYPE; + resultMessage = IUniversalDataStoreConstants.DOWNLOAD_RESULT_SUCCESS_MESSAGE; + + } + } + catch (FileNotFoundException e) + { + UniversalServerUtilities.logError(UniversalFileSystemMiner.CLASSNAME, "handleDownload: error reading file " + remotePath, e); + resultType = IUniversalDataStoreConstants.DOWNLOAD_RESULT_FILE_NOT_FOUND_EXCEPTION; + resultMessage = e.getLocalizedMessage(); + } + catch (UnsupportedEncodingException e) + { + UniversalServerUtilities.logError(UniversalFileSystemMiner.CLASSNAME, "handleDownload: error reading file " + remotePath, e); + resultType = IUniversalDataStoreConstants.DOWNLOAD_RESULT_UNSUPPORTED_ENCODING_EXCEPTION; + resultMessage = e.getLocalizedMessage(); + } + catch (IOException e) + { + UniversalServerUtilities.logError(UniversalFileSystemMiner.CLASSNAME, "handleDownload: error reading file " + remotePath, e); + resultType = IUniversalDataStoreConstants.DOWNLOAD_RESULT_IO_EXCEPTION; + resultMessage = e.getLocalizedMessage(); + } + catch (Exception e) + { + UniversalServerUtilities.logError(UniversalFileSystemMiner.CLASSNAME, "handleDownload: error reading file " + remotePath, e); + resultType = IUniversalDataStoreConstants.DOWNLOAD_RESULT_EXCEPTION; + resultMessage = e.getLocalizedMessage(); + } + finally + { + + try + { + + if (bufInputStream != null) + bufInputStream.close(); + + } + catch (IOException e) + { + UniversalServerUtilities.logError(UniversalFileSystemMiner.CLASSNAME, "handleDownload: error closing reader on " + remotePath, e); + resultType = IUniversalDataStoreConstants.DOWNLOAD_RESULT_IO_EXCEPTION; + resultMessage = e.getMessage(); + } + } + _isDone = true; + + _dataStore.createObject(arg1, resultType, resultMessage); + _dataStore.refresh(arg1); + + return _miner.statusDone(status); + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalFileSystemFilter.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalFileSystemFilter.java new file mode 100644 index 00000000000..f36f03cc963 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalFileSystemFilter.java @@ -0,0 +1,124 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.filesystem; + +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.services.clientserver.FileTypeMatcher; +import org.eclipse.rse.services.clientserver.IClientServerConstants; +import org.eclipse.rse.services.clientserver.IMatcher; +import org.eclipse.rse.services.clientserver.NamePatternMatcher; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; + + +public class UniversalFileSystemFilter implements java.io.FilenameFilter, IUniversalDataStoreConstants, IClientServerConstants{ + + + protected String filter; + protected boolean allowDirs; + protected boolean allowFiles; + protected boolean caseSensitive = true; + protected IMatcher matcher = null; + protected NamePatternMatcher folderNameMatcher = null; + protected int includeFilesOrFolders; + + /** + * Insert the method's description here. + * Creation date: (2/22/01 1:15:54 PM) + * @param filter java.lang.String + */ + public UniversalFileSystemFilter(String fString, boolean files, boolean folders, boolean caseSensitive) { + this.filter = fString; + this.allowFiles = files; + this.allowDirs = folders; + this.caseSensitive = caseSensitive; + } + + /** + * Tests if a specified file should be included in a file list. + * + * @param dir the directory in which the file was found. + * @param name the name of the file. + * @return true if and only if the name should be + * included in the file list; false otherwise. + */ + public boolean accept(java.io.File dir, String nameFilter) { + + boolean match = true; + java.io.File file = new java.io.File(dir, nameFilter); + if (!allowDirs && file.isDirectory()) + return false; + + if (allowDirs && (file.isDirectory() || ArchiveHandlerManager.getInstance().isArchive(file))) + return true; + + if (!allowFiles && file.isFile()) + return false; + + if (allowDirs && allowFiles) + setListValues(INCLUDE_ALL, filter); + else if (allowDirs) + setListValues(INCLUDE_FOLDERS_ONLY, filter); + else if (allowFiles) + setListValues(INCLUDE_FILES_ONLY, filter); + else + return false; + + if ((matcher == null) && (folderNameMatcher == null)) + return true; + if (includeFilesOrFolders != INCLUDE_ALL) + match = matcher.matches(nameFilter); + else { + if (file.isFile()) { + if (matcher!=null) + match = matcher.matches(nameFilter); + } else { + if (folderNameMatcher!=null) + match = folderNameMatcher.matches(nameFilter); + } + } + return match; + } + + protected void setListValues(int includeFilesOrFolders, String nameFilter) + { + this.includeFilesOrFolders = includeFilesOrFolders; + if ((nameFilter!=null) && !nameFilter.equals("*")) + { + if (nameFilter.endsWith(",")) + matcher = new FileTypeMatcher(FileTypeMatcher.parseTypes(nameFilter), true); + else + matcher = new NamePatternMatcher(nameFilter, true, caseSensitive); + } + else + matcher = null; + folderNameMatcher = null; + } + /** + * Overloaded method to set variables to affect the folder content subsetting, + * when there is separate filters for both folder names and filter names. + * @param includeFilesOrFolders A constant from {IFileConstants} + * @param folderNameFilter The pattern to filter the folder names by. Can be null to include all folders + * @param nameFilter The pattern to filter the file names by. Can be null to include all files + */ + protected void setListValues(int includeFilesOrFolders, String folderNameFilter, String fileNameFilter) + { + setListValues(includeFilesOrFolders, fileNameFilter); + if ((folderNameFilter!=null) && !folderNameFilter.equals("*")) + folderNameMatcher = new NamePatternMatcher(folderNameFilter, true, caseSensitive); + } + + } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalFileSystemMiner.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalFileSystemMiner.java new file mode 100644 index 00000000000..63743255b20 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalFileSystemMiner.java @@ -0,0 +1,3120 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.filesystem; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.net.ServerSocket; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.IdentityHashMap; +import java.util.List; + +import org.eclipse.dstore.core.miners.miner.Miner; +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.core.model.DataStoreResources; +import org.eclipse.dstore.core.util.StringCompare; +import org.eclipse.rse.dstore.universal.miners.ICancellableHandler; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.dstore.universal.miners.UniversalServerUtilities; +import org.eclipse.rse.services.clientserver.IClientServerConstants; +import org.eclipse.rse.services.clientserver.SystemFileClassifier; +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; +import org.eclipse.rse.services.clientserver.archiveutils.SystemJarHandler; +import org.eclipse.rse.services.clientserver.archiveutils.SystemTarHandler; +import org.eclipse.rse.services.clientserver.archiveutils.SystemZipHandler; +import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; +import org.eclipse.rse.services.clientserver.java.ClassFileUtil; + +public class UniversalFileSystemMiner extends Miner implements + IUniversalDataStoreConstants, IClientServerConstants { + + + public static final String MINER_ID = UniversalFileSystemMiner.class.getName(); + + + private DataElement deUFSfilters; + + private DataElement deUFSnode; + + private DataElement deUFStemp; + + private DataElement deUFSuploadlog; + + private DataElement dePropertyQuery; + + private DataElement deFileClassificationQuery; + + private DataElement deFolderClassificationQuery; + + private DataElement deUniversalFileObject; + private DataElement deUniversalFolderObject; + private DataElement deUniversalVirtualFileObject; + private DataElement deUniversalVirtualFolderObject; + private DataElement deUniversalArchiveFileObject; + + + protected String filterString = "*"; + + protected ArchiveHandlerManager _archiveHandlerManager; + + protected boolean showHidden = false; + + + public static final String CLASSNAME = "UniversalFileSystemMiner"; + + protected HashMap _cancellableThreads; + + private boolean _isWindows = false; + + public UniversalFileSystemMiner() { + _cancellableThreads = new HashMap(); + _isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows"); + _archiveHandlerManager = ArchiveHandlerManager.getInstance(); + _archiveHandlerManager.setRegisteredHandler("zip", SystemZipHandler.class); + _archiveHandlerManager.setRegisteredHandler("jar", SystemJarHandler.class); + _archiveHandlerManager.setRegisteredHandler("tar", SystemTarHandler.class); + } + + protected FileClassifier getFileClassifier(DataElement subject) + { + return new FileClassifier(subject); + } + + /** + * @see Miner#handleCommand(DataElement) + */ + public DataElement handleCommand(DataElement theElement) { + String name = getCommandName(theElement); + + + + + DataElement status = getCommandStatus(theElement); + DataElement subject = getCommandArgument(theElement, 0); + + UniversalServerUtilities.logInfo(getName(), name + ":" + subject); + + String queryType = (String) subject.getElementProperty(DE.P_TYPE); + boolean caseSensitive = !_isWindows; + // TODO: test on WINDOWS! + + if ("C_QUERY_VIEW_ALL".equals(name)) { + if (subject != null) + { + DataElement attributes = getCommandArgument(theElement, 1); + if (attributes != null && attributes.getType().equals("attributes")) + { + return handleQueryAll(subject, attributes, status, queryType, + caseSensitive); + } + else + { + return handleQueryAll(subject, null, status, queryType, + caseSensitive); + } + } + else + UniversalServerUtilities.logError(CLASSNAME, + "C_QUERY_VIEW_ALL - subject is null", null); + } else if ("C_QUERY_VIEW_FILES".equals(name)) { + if (subject != null) + { + DataElement attributes = getCommandArgument(theElement, 1); + if (attributes != null && attributes.getType().equals("attributes")) + { + return handleQueryFiles(subject, attributes, status, queryType, + caseSensitive); + } + else + { + return handleQueryFiles(subject, null, status, queryType, + caseSensitive); + } + } + else + UniversalServerUtilities.logError(CLASSNAME, + "C_QUERY_VIEW_FILES - subject is null", null); + } else if ("C_QUERY_VIEW_FOLDERS".equals(name)) { + if (subject != null) + { + DataElement attributes = getCommandArgument(theElement, 1); + if (attributes != null && attributes.getType().equals("attributes")) + { + return handleQueryFolders(subject, attributes, status, queryType, + caseSensitive); + } + else + { + return handleQueryFolders(subject, null, status, queryType, + caseSensitive); + } + } + else + UniversalServerUtilities.logError(CLASSNAME, + "C_QUERY_VIEW_FOLDERS - subject is null", null); + } else if ("C_QUERY_ROOTS".equals(name)) { + if (subject != null) + return handleQueryRoots(subject, status); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_QUERY_ROOTS - subject is null", null); + } else if ("C_SEARCH".equals(name)) { + if (subject != null) + return handleSearch(theElement, status, queryType, + caseSensitive); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_SEARCH - subject is null", null); + } else if ("C_CANCEL".equals(name)) { + if (subject != null) { + String commandToCancel = subject.getName(); + return handleCancel(subject, status); + } else + UniversalServerUtilities.logError(CLASSNAME, + "C_CANCEL - subject is null", null); + } else if ("C_RENAME".equals(name)) { + if (subject != null) + return handleRename(subject, status); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_RENAME - subject is null", null); + } else if ("C_DELETE".equals(name)) { + if (subject != null) + return handleDelete(subject, status, true); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_DELETE - subject is null", null); + } else if ("C_DELETE_BATCH".equals(name)) { + if (subject != null) + return handleDeleteBatch(theElement, status); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_DELETE_BATCH - subject is null", null); + } else if ("C_COPY".equals(name)) { + if (subject != null) + return handleCopy(subject, getCommandArgument(theElement, 1), + getCommandArgument(theElement, 2), status); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_COPY - subject is null", null); + } else if ("C_COPY_BATCH".equals(name)) { + if (subject != null) + return handleCopyBatch(subject, theElement, status); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_COPY_BATCH - subject is null", null); + } else if ("C_CREATE_FILE".equals(name)) { + if (subject != null) + return handleCreateFile(subject, status, queryType); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_CREATE_FILE - subject is null", null); + } else if ("C_CREATE_FOLDER".equals(name)) { + if (subject != null) + return handleCreateFolder(subject, status, queryType); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_CREATE_FOLDERS - subject is null", null); + } else if ("C_SET_READONLY".equals(name)) { + if (subject != null) + return handleSetReadOnly(subject, status); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_SET_READONLY - subject is null", null); + } else if ("C_SET_LASTMODIFIED".equals(name)) { + if (subject != null) + return handleSetLastModified(subject, status); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_SET_LASTMODIFIED - subject is null", null); + } else if ("C_QUERY_BASIC_PROPERTY".equals(name)) { + if (subject != null) + return handleQueryBasicProperty(subject, status); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_QUERY_BASIC_PROPERTY - subject is null", null); + } else if ("C_QUERY_CAN_WRITE_PROPERTY".equals(name)) { + if (subject != null) + return handleQuerycanWriteProperty(subject, status); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_QUERY_CAN_WRITE_PROPERTY - subject is null", null); + } else if ("C_QUERY_ADVANCE_PROPERTY".equals(name)) { + if (subject != null) + return handleQueryAdvanceProperty(subject, status); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_QUERY_ADVANCE_PROPERTY - subject is null", null); + } else if ("C_QUERY_FILE_CLASSIFICATIONS".equals(name)) { + if (subject != null) + return handleQueryFileClassification(subject, status); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_QUERY_FILE_CLASSIFICATION - subject is null", null); + } else if ("C_QUERY_FILE_CLASSIFICATION".equals(name)) { + if (subject != null) + return handleQueryFileClassification(subject, status); + else + UniversalServerUtilities + .logError( + CLASSNAME, + "C_QUERY_FOLDER_CLASSIFICATION - subject is null", + null); + } else if ("C_QUERY_EXISTS".equals(name)) { + if (subject != null) + return handleQueryExists(subject, status, queryType); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_QUERY_EXISTS - subject is null", null); + } else if ("C_QUERY_GET_REMOTE_OBJECT".equals(name)) { + if (subject != null) + return handleQueryGetRemoteObject(subject, status, queryType); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_QUERY_GET_REMOTE_OBJECT- subject is null", null); + } else if ("C_GET_OSTYPE".equals(name)) { + if (subject != null) + return handleGetOSType(subject, status); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_GET_OSTYPE - subject is null", null); + } else if (C_DOWNLOAD_FILE.equals(name)) { + if (subject != null) + return handleDownload(theElement, status); + else + UniversalServerUtilities.logError(CLASSNAME, C_DOWNLOAD_FILE + + " - subject is null", null); + } else if (C_SYSTEM_ENCODING.equals(name)) { + if (subject != null) + return handleQueryEncoding(subject, status); + else + UniversalServerUtilities.logError(CLASSNAME, C_SYSTEM_ENCODING + + " - subject is null", null); + } else if (C_QUERY_UNUSED_PORT.equals(name)) { + if (subject != null) + return handleQueryUnusedPort(subject, status); + else + UniversalServerUtilities.logError(CLASSNAME, C_QUERY_UNUSED_PORT + + " - subject is null", null); + } else if ("C_QUERY_CLASSNAME".equals(name)) { + if (subject != null) + return handleQueryClassName(subject, status); + else + UniversalServerUtilities.logError(CLASSNAME, + "C_QUERY_CLASSNAME- subject is null", null); + } else if (C_QUERY_QUALIFIED_CLASSNAME.equals(name)) { + if (subject != null) + return handleQueryQualifiedClassName(subject, status); + else + UniversalServerUtilities.logError(CLASSNAME, + C_QUERY_QUALIFIED_CLASSNAME + " - subject is null", + null); + } else { + UniversalServerUtilities.logError(CLASSNAME, + "Invalid query to handlecommand", null); + } + return statusDone(status); + } + + private DataElement handleCopyBatch(DataElement targetFolder, DataElement theElement, DataElement status) + { + String targetType = targetFolder.getType(); + File tgtFolder = getFileFor(targetFolder); + int numOfSources = theElement.getNestedSize() - 2; + + if (targetType.equals(UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) || targetType.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) + { + // if target is virtual or an archive, insert into an archive + AbsoluteVirtualPath vpath = getAbsoluteVirtualPath(targetFolder); + ISystemArchiveHandler handler = getArchiveHandlerFor(vpath.getContainingArchiveString()); + + if (handler == null) + { + status.setAttribute(DE.A_SOURCE, FAILED); + return statusDone(status); + } + + File[] srcFiles = new File[numOfSources]; + String[] names = new String[numOfSources]; + + for (int i = 0; i < numOfSources; i++) + { + DataElement sourceFile = getCommandArgument(theElement, i+1); + String srcType = sourceFile.getType(); + names[i] = sourceFile.getName(); + + if (srcType.equals(UNIVERSAL_FILE_DESCRIPTOR) || srcType.equals(UNIVERSAL_FOLDER_DESCRIPTOR) + || srcType.equals(UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) + { + srcFiles[i] = getFileFor(sourceFile); + } + else if (srcType.equals(UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) + { + AbsoluteVirtualPath svpath = getAbsoluteVirtualPath(sourceFile); + ISystemArchiveHandler shandler = getArchiveHandlerFor(svpath.getContainingArchiveString()); + + if (shandler == null) + { + status.setAttribute(DE.A_SOURCE, FAILED); + return statusDone(status); + } + + VirtualChild child = shandler.getVirtualFile(svpath.getVirtualPart()); + srcFiles[i] = child.getExtractedFile(); + } + } + String virtualContainer = ""; + + if (targetType.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) + { + virtualContainer = vpath.getVirtualPart(); + } + + boolean result = handler.add(srcFiles, virtualContainer, names); + + if (result) { + status.setAttribute(DE.A_SOURCE, SUCCESS); + } + else { + status.setAttribute(DE.A_SOURCE, FAILED); + } + return statusDone(status); + } + else // target is a regular folder + { + boolean folderCopy = false; + String source = ""; + String tgt = tgtFolder.getAbsolutePath(); + StringBuffer tgtBuf = new StringBuffer(tgt); + handleSpecialChars(tgtBuf); + tgt = "\"" + tgtBuf.toString() + "\""; + + int numOfNonVirtualSources = 0; + for (int i = 0; i < numOfSources; i++) + { + DataElement sourceFile = getCommandArgument(theElement, i+1); + String srcType = sourceFile.getType(); + + if (srcType.equals(UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) + { + // extract from an archive to folder + AbsoluteVirtualPath svpath = getAbsoluteVirtualPath(sourceFile); + ISystemArchiveHandler shandler = getArchiveHandlerFor(svpath.getContainingArchiveString()); + + if (shandler == null) + { + status.setAttribute(DE.A_SOURCE, FAILED); + return statusDone(status); + } + + VirtualChild child = shandler.getVirtualFile(svpath.getVirtualPart()); + + File parentDir = getFileFor(targetFolder); + File destination = new File(parentDir, sourceFile.getName()); + + if (child.isDirectory) + { + shandler.extractVirtualDirectory(svpath.getVirtualPart(), parentDir, destination); + } + else + { + shandler.extractVirtualFile(svpath.getVirtualPart(), destination); + } + } + else // source is regular file or folder + { + File srcFile = getFileFor(sourceFile); + folderCopy = folderCopy || srcFile.isDirectory(); + String src = srcFile.getAbsolutePath(); + + // handle special characters in source and target strings + StringBuffer srcBuf = new StringBuffer(src); + handleSpecialChars(srcBuf); + src = "\"" + srcBuf.toString() + "\""; + + if (numOfNonVirtualSources == 0) + { + source += src; + } + else + { + source = source + " " + src; + } + numOfNonVirtualSources++; + } + } // end for loop iterating through sources + + if (numOfNonVirtualSources > 0) + { + doCopyCommand(source, tgt, folderCopy, status); + } + } // end if/then/else (target is regular folder) + return statusDone(status); + } + + protected void doCopyCommand(String source, String tgt, boolean folderCopy, DataElement status) + { + String command = null; + if (_isWindows) { + + if (folderCopy) { + command = "xcopy " + source + " " + tgt + + " /S /E /K /O /Q /H /I"; + } + else { + command = "copy " + source + " " + tgt; + } + } + else { + if (folderCopy) { + command = "cp -r " + source + " " + tgt; + } + else { + command = "cp " + source + " " + tgt; + } + } + + // run copy command + try + { + Runtime runtime = Runtime.getRuntime(); + Process p = null; + + if (_isWindows) + { + String theShell = "cmd /C "; + p = runtime.exec(theShell + command); + } + else + { + String theShell = "sh"; + String args[] = new String[3]; + args[0] = theShell; + args[1] = "-c"; + args[2] = command; + + p = runtime.exec(args); + } + + // ensure there is a process + if (p != null) { + + // wait for process to finish + p.waitFor(); + + // get the exit value of the process + int result = p.exitValue(); + + // if the exit value is not 0, then the process did not terminate normally + if (result != 0) { + + // get the error stream + InputStream errStream = p.getErrorStream(); + + // error buffer + StringBuffer errBuf = new StringBuffer(); + + byte[] bytes = null; + + int numOfBytesRead = 0; + + int available = errStream.available(); + + // read error stream and store in error buffer + while (available > 0) { + + bytes = new byte[available]; + + numOfBytesRead = errStream.read(bytes); + + if (numOfBytesRead > -1) { + errBuf.append(new String(bytes, 0, numOfBytesRead)); + } + else { + break; + } + + available = errStream.available(); + } + + String err = errBuf.toString(); + + // omit new line if there is one at the end because datastore does not + // handle new line in the attributes + // TODO: what to do if newline occurs in the middle of the string? + String newLine = System.getProperty("line.separator"); + + if (newLine != null && err.endsWith(newLine)) { + err = err.substring(0, err.length() - newLine.length()); + } + + // if there is something in error buffer + // there was something in the error stream of the process + if (err.length() > 0) { + status.setAttribute(DE.A_SOURCE, FAILED); + status.setAttribute(DE.A_VALUE, err); + } + // otherwise, nothing in the error stream + // but we know process did not exit normally, so we indicate an unexpected error + else { + status.setAttribute(DE.A_SOURCE, FAILED); + status.setAttribute(DE.A_VALUE, UNEXPECTED_ERROR); + } + } + // otherwise if exit value is 0, process terminated normally + else { + status.setAttribute(DE.A_SOURCE, SUCCESS); + } + } + // no process, so something is wrong + else { + status.setAttribute(DE.A_SOURCE, FAILED); + status.setAttribute(DE.A_VALUE, UNEXPECTED_ERROR); + } + } + catch (Exception e) + { + UniversalServerUtilities.logError(CLASSNAME, "Exception is handleCopy", e); + status.setAttribute(DE.A_SOURCE, FAILED); + status.setAttribute(DE.A_VALUE, e.getMessage()); + } + } + + /** + * Delete directory and its children. + * + */ + public void deleteDir(File fileObj, DataElement status) { + try { + File list[] = fileObj.listFiles(); + for (int i = 0; i < list.length; ++i) { + if (list[i].isFile()) { + if (!(list[i].delete())) { + status.setAttribute(DE.A_SOURCE, FAILED); + UniversalServerUtilities.logWarning(CLASSNAME, + "Deletion of dir failed"); + } + } else { + deleteDir(list[i], status); + if (!(list[i].delete())) { + status.setAttribute(DE.A_SOURCE, FAILED); + UniversalServerUtilities.logWarning(CLASSNAME, + "Deletion of dir failed"); + } + } + } + } catch (Exception e) { + status.setAttribute(DE.A_SOURCE, FAILED_WITH_EXCEPTION); + status.setAttribute(DE.A_VALUE, e.getLocalizedMessage()); + UniversalServerUtilities.logError(CLASSNAME, + "Deletion of dir failed", e); + } + } + + /** + * Method to do a search. + */ + public DataElement handleSearch(DataElement theElement, DataElement status, + String queryType, boolean fileNamesCaseSensitive) { + File fileobj = null; + + DataElement subject = getCommandArgument(theElement, 0); + + // if the query type is against a folder, archive or a virtual folder, + // we know to handle it + if (queryType.equals(UNIVERSAL_FOLDER_DESCRIPTOR) + || queryType.equals(UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) + || queryType.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + + fileobj = new File(subject.getAttribute(DE.A_VALUE) + + File.separatorChar + subject.getName()); + } + // otherwise log error, and return as done + else { + UniversalServerUtilities.logError(CLASSNAME, "Invalid query type to handleSearch", null); + return statusDone(status); + } + + if (fileobj.exists()) { + DataElement arg1 = getCommandArgument(theElement, 1); + DataElement arg2 = getCommandArgument(theElement, 2); + DataElement arg3 = getCommandArgument(theElement, 3); + + String textString = arg1.getType(); + boolean isCaseSensitive = Boolean.valueOf(arg1.getName()).booleanValue(); + boolean isTextRegex = Boolean.valueOf(arg1.getSource()).booleanValue(); + + String fileNamesString = arg2.getType(); + + boolean isFileNamesRegex = Boolean.valueOf(arg2.getName()).booleanValue(); + String classification = arg2.getSource(); + + boolean isIncludeArchives = Boolean.valueOf(arg3.getType()).booleanValue(); + boolean isIncludeSubfolders = Boolean.valueOf(arg3.getName()).booleanValue(); + boolean showHidden = Boolean.valueOf(arg3.getSource()).booleanValue(); + + SystemSearchString searchString = new SystemSearchString( + textString, isCaseSensitive, isTextRegex, fileNamesString, + isFileNamesRegex, isIncludeArchives, isIncludeSubfolders, classification); + + UniversalSearchHandler searchThread = new UniversalSearchHandler( + _dataStore, this, searchString, !_isWindows, fileobj, + status); + + searchThread.start(); + + // save search thread in hashmap for retrieval during cancel + _cancellableThreads.put(status.getParent(), searchThread); + return status; + } + + return statusDone(status); + } + + public DataElement handleCancel(DataElement subject, DataElement status) { + ICancellableHandler thread = (ICancellableHandler) _cancellableThreads + .get(subject); + + if (thread != null) { + if (!thread.isDone()) { + thread.cancel(); + } + } + + // indicate status cancelled before indicating we are done + statusCancelled(status); + + // indicate status done + return statusDone(status); + } + + /** + * Method to list the files and folders for a given filter. + */ + public DataElement handleQueryAll(DataElement subject, DataElement attributes, DataElement status, + String queryType, boolean caseSensitive) + { + if (queryType.equals(UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) + || queryType.equals(UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) + || queryType.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + return handleQueryAllArchive(subject, attributes, status, caseSensitive, false); + } + + File fileobj = null; + + + String filter = null; + if (attributes != null) + { + filter = getFilterString(attributes.getAttribute(DE.A_SOURCE)); + showHidden = getShowHiddenFlag(attributes.getAttribute(DE.A_SOURCE)); + } + else + { + filter = getFilterString(subject.getAttribute(DE.A_SOURCE)); + showHidden = getShowHiddenFlag(subject.getAttribute(DE.A_SOURCE)); + } + + if (queryType.equals(UNIVERSAL_FILTER_DESCRIPTOR)) + fileobj = new File(subject.getName()); + else if (queryType.equals(UNIVERSAL_FOLDER_DESCRIPTOR)) + fileobj = new File(subject.getAttribute(DE.A_VALUE) + + File.separatorChar + subject.getName()); + else + { + UniversalServerUtilities.logError(CLASSNAME, + "Invalid query type to handleQueryAll", null); + } + + if (fileobj != null) + // query all files and folders for the filter + internalQueryAll(subject, fileobj, queryType, filter, + caseSensitive, INCLUDE_ALL); + + // refresh datastore + _dataStore.refresh(subject); + + + return statusDone(status); + } + + protected void internalQueryAll(DataElement subject, File fileobj, + String queryType, String filter, boolean caseSensitive, + int inclusion) { + if (fileobj.exists()) + { + + + boolean filterFiles = (inclusion == INCLUDE_ALL) || (inclusion == INCLUDE_FILES_ONLY); + boolean filterFolders = (inclusion == INCLUDE_ALL) || (inclusion == INCLUDE_FOLDERS_ONLY); + + UniversalFileSystemFilter filefilter = new UniversalFileSystemFilter(filter,filterFiles, filterFolders, caseSensitive); + String theOS = System.getProperty("os.name"); + File[] list = null; + if (theOS.equals("z/OS")) + { + // filters not supported with z/OS jvm + File[] tempList = fileobj.listFiles(); + List acceptedList = new ArrayList(tempList.length); + + for (int i = 0; i < tempList.length; i++) { + File afile = tempList[i]; + if (filefilter.accept(fileobj, afile.getName())) { + acceptedList.add(afile); + } + } + list = new File[acceptedList.size()]; + for (int l = 0; l < acceptedList.size(); l++) + list[l] = (File) acceptedList.get(l); + } + else + { + list = fileobj.listFiles(filefilter); + } + + if (list != null) + { + createDataElement(_dataStore, subject, list, queryType, filter,inclusion); + String folderProperties = setProperties(fileobj); + subject.setAttribute(DE.A_SOURCE, folderProperties); + + FileClassifier clsfy = getFileClassifier(subject); + clsfy.start(); + } + } + else { + /* + UniversalServerUtilities + .logError( + CLASSNAME, + "The path specified in handleQueryAll does not exist", + null); + status.setAttribute(DE.A_SOURCE, FAILED_WITH_EXIST); + */ + } + + } +/* + private void internalLSQueryAll(DataElement subject, File fileobj, + String queryType, String filter, boolean caseSensitive, int include) { + + BufferedReader reader = null; // use 'ls -l' command + String cmd = "ls -l"; + try { + String rootSource = fileobj.getAbsolutePath(); + + Process theProcess = Runtime.getRuntime().exec(cmd, null, + new File(rootSource)); + String specialEncoding = System + .getProperty("dstore.stdin.encoding"); + if (specialEncoding != null) { + reader = new BufferedReader(new InputStreamReader(theProcess + .getInputStream(), specialEncoding)); + } else { + reader = new BufferedReader(new InputStreamReader(theProcess + .getInputStream())); + } + + String line = null; + while ((line = reader.readLine()) != null) { + createDataElementFromLSString(subject, rootSource, line, + include); + } + } catch (Exception e) { + } + if (reader != null) { + try { + reader.close(); + } catch (Exception e) { + } + } + _dataStore.refresh(subject); + } + +private DataElement createDataElementFromLSString(DataElement subject, + String rootSource, String line, int include) +{ + boolean isFolder = false; + + boolean isExecutable = false; + String name = line; + int length =line.length(); + + if (line.charAt(length - 1) == '/') + { + isFolder = true; name =line.substring(0, length - 1); + } + else if (line.charAt(length - 1) == '*') + { + isExecutable = true; name = line.substring(0, length - 1); + } + else if (line.charAt(length - 1) == '@') { name = line.substring(0, length - 1); + { + String filePath = rootSource + File.separatorChar + name; + DataElement deObj = null; + if (include == INCLUDE_ALL) + { + if (isFolder) + { + deObj = _dataStore.createObject(subject, UNIVERSAL_FOLDER_DESCRIPTOR, name); + } + else // file + { + //if (ArchiveHandlerManager.getInstance().isArchive(list[i])) + //{ + // deObj = ds.createObject(subject, UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR, name); + // } + // else + // { + deObj = _dataStore.createObject(subject, UNIVERSAL_FILE_DESCRIPTOR, name); + // } + } + } + return deObj; + } + return null; + } + + + else if (include == INCLUDE_FILES_ONLY) + { + if (!isFolder) + { + if (ArchiveHandlerManager.getInstance().isArchive(list[i])) + { + deObj = ds.createObject(subject, UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR, name); + } + else + { + deObj = _dataStore.createObject(subject, + UNIVERSAL_FILE_DESCRIPTOR, name); + } + } + } + else if (include == INCLUDE_FOLDERS_ONLY) + { + if (isFolder) + { + deObj = _dataStore.createObject(subject, UNIVERSAL_FOLDER_DESCRIPTOR, name); + } + } + else + { + } + */ + + + +// if (deObj != null) + // { + // deObj.setAttribute(DE.A_VALUE, rootSource + File.separatorChar); + + //_dataStore.command(dePropertyQuery, deObj); //File fobj = new + // File(rootSource + File.separatorChar + name); + //deObj.setAttribute(DE.A_SOURCE, setProperties(fobj, isExecutable)); } + + //classifyExecutable(newObject, false); return deObj; } + // } + + /** + * Method to list the files for a given filter. + */ + public DataElement handleQueryFiles(DataElement subject, DataElement attributes, + DataElement status, String queryType, boolean caseSensitive) { + + File fileobj = null; + + String filter = null; + if (attributes != null) + { + filter = getFilterString(attributes.getAttribute(DE.A_SOURCE)); + showHidden = getShowHiddenFlag(attributes.getAttribute(DE.A_SOURCE)); + } + else + { + filter = getFilterString(subject.getAttribute(DE.A_SOURCE)); + showHidden = getShowHiddenFlag(subject.getAttribute(DE.A_SOURCE)); + } + + if (queryType.equals(UNIVERSAL_FILTER_DESCRIPTOR)) + fileobj = new File(subject.getName()); + else if (queryType.equals(UNIVERSAL_FOLDER_DESCRIPTOR)) + fileobj = new File(subject.getAttribute(DE.A_VALUE) + + File.separatorChar + subject.getName()); + else + UniversalServerUtilities.logError(CLASSNAME, + "Invalid query type to handleQueryFiles", null); + + + internalQueryAll(subject, fileobj, queryType, filter, caseSensitive, INCLUDE_FILES_ONLY); + + _dataStore.refresh(subject); + return statusDone(status); + } + + /** + * Method to list the folders for a given filter. + */ + public DataElement handleQueryFolders(DataElement subject, DataElement attributes, + DataElement status, String queryType, boolean caseSensitive) { + if (queryType.equals(UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) + || queryType.equals(UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) + || queryType.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + return handleQueryAllArchive(subject, attributes, status, caseSensitive, true); + } + + File fileobj = null; + String filter = null; + + if (attributes != null) + { + filter = getFilterString(attributes.getAttribute(DE.A_SOURCE)); + showHidden = getShowHiddenFlag(attributes.getAttribute(DE.A_SOURCE)); + } + else + { + filter = getFilterString(subject.getAttribute(DE.A_SOURCE)); + showHidden = getShowHiddenFlag(subject.getAttribute(DE.A_SOURCE)); + } + + if (queryType.equals(UNIVERSAL_FILTER_DESCRIPTOR)) + fileobj = new File(subject.getName()); + else if (queryType.equals(UNIVERSAL_FOLDER_DESCRIPTOR)) + fileobj = new File(subject.getAttribute(DE.A_VALUE) + + File.separatorChar + subject.getName()); + else + UniversalServerUtilities.logError(CLASSNAME, + "Invalid query type to handleQueryFolders", null); + + internalQueryAll(subject, fileobj, queryType, filter, caseSensitive, INCLUDE_FOLDERS_ONLY); + + _dataStore.refresh(subject); + return statusDone(status); + } + + /** + * Method to list the roots. + */ + public DataElement handleQueryRoots(DataElement subject, DataElement status) { + File fileobj = new File(subject.getName()); + DataElement deObj = null; + + if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { + String[] ALLDRIVES = { "c:\\", "d:\\", "e:\\", "f:\\", "g:\\", + "h:\\", "i:\\", "j:\\", "k:\\", "l:\\", "m:\\", "n:\\", + "o:\\", "p:\\", "q:\\", "r:\\", "s:\\", "t:\\", "u:\\", + "v:\\", "w:\\", "x:\\", "y:\\", "z:\\" }; + for (int idx = 0; idx < ALLDRIVES.length; idx++) { + File drive = new File(ALLDRIVES[idx]); + if (drive.exists()) { + try { + String path = drive.getCanonicalPath(); + deObj = _dataStore.createObject(subject, + UNIVERSAL_FOLDER_DESCRIPTOR, path); + deObj.setAttribute(DE.A_SOURCE, setProperties(drive)); + deObj.setAttribute(DE.A_NAME, ""); + deObj.setAttribute(DE.A_VALUE, path); + } catch (IOException e) { + return statusDone(status); + } + } + } + } else { // not windows + File[] list = File.listRoots(); + + for (int i = 0; i < list.length; ++i) { + deObj = _dataStore.createObject(subject, + UNIVERSAL_FOLDER_DESCRIPTOR, list[i].getAbsolutePath()); + deObj.setAttribute(DE.A_SOURCE, setProperties(list[i])); + deObj.setAttribute(DE.A_NAME, ""); + deObj.setAttribute(DE.A_VALUE, list[i].getAbsolutePath()); + } + } + _dataStore.refresh(subject); + return statusDone(status); + } + + /** + * Method to Delete a file or folder. + */ + public DataElement handleDelete(DataElement subject, DataElement status, boolean refreshDataStore) { + String type = subject.getType(); + if (type.equals(UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) + || type.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + return handleDeleteFromArchive(subject, status); + } + + File deleteObj = new File(subject.getAttribute(DE.A_VALUE) + + File.separatorChar + subject.getName()); + DataElement deObj = null; + if (!deleteObj.exists()) { + status.setAttribute(DE.A_SOURCE, FAILED_WITH_DOES_NOT_EXIST + "|" + deleteObj.getAbsolutePath()); + UniversalServerUtilities.logError(CLASSNAME, + "The object to delete does not exist", null); + } else { + try { + if (deleteObj.isFile()) { + if (deleteObj.delete() == false) { + status.setAttribute(DE.A_SOURCE, FAILED + "|" + deleteObj.getAbsolutePath()); + } else { + // delete was successful and delete the object from the + // datastore + deObj = _dataStore.find(subject, DE.A_NAME, subject + .getName(), 1); + _dataStore.deleteObject(subject, deObj); + status.setAttribute(DE.A_SOURCE, SUCCESS + "|" + deleteObj.getAbsolutePath()); + } + _dataStore.refresh(subject); + } else if (deleteObj.isDirectory()) { // it is directory and + // need to delete the + // entire directory + + // children + deleteDir(deleteObj, status); + if (deleteObj.delete() == false) { + status.setAttribute(DE.A_SOURCE, FAILED + "|" + deleteObj.getAbsolutePath()); + UniversalServerUtilities.logError(CLASSNAME, + "Deletion of dir fialed", null); + } else { + _dataStore.deleteObjects(subject); + DataElement parent = subject.getParent(); + _dataStore.deleteObject(parent, subject); + _dataStore.refresh(parent); + } + } else { + UniversalServerUtilities + .logError( + CLASSNAME, + "The object to delete is neither a File or Folder! in handleDelete", + null); + } + } catch (Exception e) { + status.setAttribute(DE.A_SOURCE, FAILED_WITH_EXCEPTION + "|" + deleteObj.getAbsolutePath()); + status.setAttribute(DE.A_VALUE, e.getLocalizedMessage()); + UniversalServerUtilities.logError(CLASSNAME, + "Delete of the object failed", e); + } + } + _dataStore.refresh(subject); + return statusDone(status); + } + + private DataElement handleDeleteBatch(DataElement theElement, DataElement status) + { + int numOfSources = theElement.getNestedSize() - 2; + for (int i = 0; i < numOfSources; i++) + { + DataElement subject = getCommandArgument(theElement, i+1); + handleDelete(subject, status, false); + if (!status.getSource().startsWith(SUCCESS)) return statusDone(status); + } + return statusDone(status); + } + + /** + * Method to Rename a file or folder. + */ + public DataElement handleRename(DataElement subject, DataElement status) { + File fileoldname = new File(subject.getAttribute(DE.A_VALUE) + + File.separatorChar + subject.getName()); + File filerename = new File(subject.getAttribute(DE.A_VALUE) + + File.separatorChar + subject.getAttribute(DE.A_SOURCE)); + + System.out.println(ArchiveHandlerManager.isVirtual(fileoldname + .getAbsolutePath())); + if (ArchiveHandlerManager.isVirtual(fileoldname.getAbsolutePath())) { + AbsoluteVirtualPath oldAbsPath = new AbsoluteVirtualPath( + fileoldname.getAbsolutePath()); + AbsoluteVirtualPath newAbsPath = new AbsoluteVirtualPath(filerename + .getAbsolutePath()); + ISystemArchiveHandler handler = _archiveHandlerManager + .getRegisteredHandler(new File(oldAbsPath + .getContainingArchiveString())); + boolean success = !(handler == null) + && handler.fullRename(oldAbsPath.getVirtualPart(), + newAbsPath.getVirtualPart()); + if (success) { + subject.setAttribute(DE.A_NAME, filerename.getName()); + subject.setAttribute(DE.A_SOURCE, setProperties(handler + .getVirtualFile(newAbsPath.getVirtualPart()))); + status.setAttribute(DE.A_SOURCE, SUCCESS); + _dataStore.update(subject); + } else { + status.setAttribute(DE.A_SOURCE, FAILED); + } + _dataStore.refresh(subject); + return statusDone(status); + } + if (filerename.exists()) + status.setAttribute(DE.A_SOURCE, FAILED_WITH_EXIST); + else { + try { + boolean done = fileoldname.renameTo(filerename); + if (done) { + subject.setAttribute(DE.A_NAME, filerename.getName()); + subject + .setAttribute(DE.A_SOURCE, + setProperties(filerename)); + status.setAttribute(DE.A_SOURCE, SUCCESS); + + if (filerename.isDirectory()) { + // update children's properties + updateChildProperties(subject, filerename); + } + _dataStore.update(subject); + } else + status.setAttribute(DE.A_SOURCE, FAILED); + } catch (Exception e) { + status.setAttribute(DE.A_SOURCE, FAILED); + UniversalServerUtilities.logError(CLASSNAME, + "handleRename failed", e); + } + } + _dataStore.refresh(subject); + return statusDone(status); + } + + // DKM: during folder rename we need to recursively update all the parent + // paths + private void updateChildProperties(DataElement subject, File filerename) { + + int nestedSize = subject.getNestedSize(); + for (int i = 0; i < nestedSize; i++) { + DataElement child = subject.get(i); + child.setAttribute(DE.A_VALUE, filerename.getAbsolutePath()); + + if (child.getNestedSize() > 0) { + File childFile = new File(filerename, child.getName()); + updateChildProperties(child, childFile); + } + } + } + + /** + * Method to create a new file. + */ + public DataElement handleCreateFile(DataElement subject, + DataElement status, String queryType) { + boolean wasFilter = queryType.equals(UNIVERSAL_FILTER_DESCRIPTOR); + if (queryType.equals(UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) { + return handleCreateVirtualFile(subject, status, queryType); + } + + File filename = null; + if (queryType.equals(UNIVERSAL_FILTER_DESCRIPTOR)) { + if (subject.getName().indexOf( + ArchiveHandlerManager.VIRTUAL_SEPARATOR) > 0) { + subject.setAttribute(DE.A_TYPE, + UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR); + return handleCreateVirtualFile(subject, status, queryType); + } else { + filename = new File(subject.getValue()); + subject.setAttribute(DE.A_TYPE, UNIVERSAL_FILE_DESCRIPTOR); + subject.setAttribute(DE.A_SOURCE, setProperties(filename)); + } + } else if (queryType.equals(UNIVERSAL_FILE_DESCRIPTOR)) + filename = new File(subject.getAttribute(DE.A_VALUE) + + File.separatorChar + subject.getName()); + else + UniversalServerUtilities.logError(CLASSNAME, + "Invalid query type to handleCreateFile", null); + + if (filename.exists()) + status.setAttribute(DE.A_SOURCE, FAILED_WITH_EXIST); + else { + try { + boolean done = filename.createNewFile(); + if (ArchiveHandlerManager.getInstance().isArchive(filename)) { + done = ArchiveHandlerManager.getInstance() + .createEmptyArchive(filename); + if (done) + subject.setAttribute(DE.A_TYPE, + UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR); + } else { + if (done) + { + subject.setAttribute(DE.A_TYPE, + UNIVERSAL_FILE_DESCRIPTOR); + } + } + subject.setAttribute(DE.A_SOURCE, setProperties(filename)); + if (done) { + status.setAttribute(DE.A_SOURCE, SUCCESS); + if (wasFilter) { + String fullName = subject.getValue(); + String name = fullName.substring(fullName + .lastIndexOf(File.separatorChar) + 1, fullName + .length()); + String path = fullName.substring(0, fullName + .lastIndexOf(File.separatorChar)); + subject.setAttribute(DE.A_NAME, name); + subject.setAttribute(DE.A_VALUE, path); + } + } else + status.setAttribute(DE.A_SOURCE, FAILED); + } catch (Exception e) { + UniversalServerUtilities.logError(CLASSNAME, + "handleCreateFile failed", e); + status.setAttribute(DE.A_SOURCE, FAILED); + } + } + _dataStore.refresh(subject); + return statusDone(status); + } + + /** + * Method to create a new folder. + */ + public DataElement handleCreateFolder(DataElement subject, + DataElement status, String queryType) { + if (queryType.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + return handleCreateVirtualFolder(subject, status, queryType); + } + + File filename = null; + if (queryType.equals(UNIVERSAL_FILTER_DESCRIPTOR)) + { + if (subject.getName().indexOf( + ArchiveHandlerManager.VIRTUAL_SEPARATOR) > 0) + { + subject.setAttribute(DE.A_TYPE, + UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR); + return handleCreateVirtualFolder(subject, status, queryType); + } + else + { + filename = new File(subject.getValue()); + subject.setAttribute(DE.A_TYPE, UNIVERSAL_FOLDER_DESCRIPTOR); + subject.setAttribute(DE.A_SOURCE, setProperties(filename)); + } + } + else if (queryType.equals(UNIVERSAL_FOLDER_DESCRIPTOR)) + { + filename = new File(subject.getValue()); + } + else + UniversalServerUtilities.logError(CLASSNAME, + "Invalid query type to handleCreateFolder", null); + + if (filename.exists()) + status.setAttribute(DE.A_SOURCE, FAILED_WITH_EXIST); + else + { + try { + boolean done = filename.mkdirs(); + if (done) + { + status.setAttribute(DE.A_SOURCE, SUCCESS); + subject.setAttribute(DE.A_SOURCE, setProperties(filename)); + subject.setAttribute(DE.A_TYPE,UNIVERSAL_FOLDER_DESCRIPTOR); + subject.setAttribute(DE.A_NAME, filename.getName()); + subject.setAttribute(DE.A_VALUE, filename.getParentFile().getAbsolutePath()); + } + else + { + status.setAttribute(DE.A_SOURCE, FAILED); + } + + } catch (Exception e) { + UniversalServerUtilities.logError(CLASSNAME, + "handleCreateFolder failed", e); + status.setAttribute(DE.A_SOURCE, FAILED); + } + } + _dataStore.refresh(subject); + return statusDone(status); + } + + /** + * Method to set ReadOnly to a file or folder. + */ + public DataElement handleSetReadOnly(DataElement subject, DataElement status) { + + File filename = new File(subject.getAttribute(DE.A_VALUE) + + File.separatorChar + subject.getName()); + if (!filename.exists()) + status.setAttribute(DE.A_SOURCE, FAILED_WITH_DOES_NOT_EXIST); + else { + try { + boolean done = filename.setReadOnly(); + if (done) { + status.setAttribute(DE.A_SOURCE, SUCCESS); + subject.setAttribute(DE.A_SOURCE, setProperties(filename)); + _dataStore.refresh(subject); + } else { + status.setAttribute(DE.A_SOURCE, FAILED); + } + } catch (Exception e) { + UniversalServerUtilities.logError(CLASSNAME, + "handleSetreadOnly", e); + } + } + _dataStore.refresh(subject); + return statusDone(status); + } + + /** + * Method to set LastModified to a file or folder. + */ + public DataElement handleSetLastModified(DataElement subject, + DataElement status) { + + File filename = new File(subject.getAttribute(DE.A_VALUE)); + if (!filename.exists()) + status.setAttribute(DE.A_SOURCE, FAILED_WITH_DOES_NOT_EXIST); + else { + try { + String str = subject.getAttribute(DE.A_SOURCE); + + long date = Long.parseLong(str); + boolean done = filename.setLastModified(date); + + filename = new File(subject.getAttribute(DE.A_VALUE)); + if (done) { + status.setAttribute(DE.A_SOURCE, SUCCESS); + subject.setAttribute(DE.A_SOURCE, setProperties(filename)); + _dataStore.refresh(subject); + } else + status.setAttribute(DE.A_SOURCE, FAILED); + } catch (Exception e) { + UniversalServerUtilities.logError(CLASSNAME, + "handleSetLastModified", e); + } + } + _dataStore.refresh(subject); + return statusDone(status); + } + + /** + * Method to Retrieve properties of the file or folder. + */ + protected DataElement handleQueryBasicProperty(DataElement subject, + DataElement status) { + File fileobj = new File(subject.getAttribute(DE.A_VALUE) + + File.separatorChar + subject.getName()); + subject.setAttribute(DE.A_SOURCE, setProperties(fileobj)); + _dataStore.refresh(subject); + return statusDone(status); + } + + /** + * Method to Retrieve canWrite property of the file or folder. + */ + protected DataElement handleQuerycanWriteProperty(DataElement subject, + DataElement status) { + File fileObj = new File(subject.getAttribute(DE.A_VALUE) + + File.separatorChar + subject.getName()); + + String version = VERSION_1; + StringBuffer buffer = new StringBuffer(50); + boolean canWrite = fileObj.canWrite(); + + buffer.append(version).append(TOKEN_SEPARATOR).append(canWrite); + subject.setAttribute(DE.A_SOURCE, buffer.toString()); + _dataStore.refresh(subject); + return statusDone(status); + } + + /** + * Method to query advance properties. + */ + + protected DataElement handleQueryAdvanceProperty(DataElement subject, + DataElement status) { + // log error currently there are no advance properties for Universal + // Files + return statusDone(status); + } + + protected DataElement handleQueryFileClassification(DataElement subject, DataElement status) { + + FileClassifier classifier = getFileClassifier(subject); + classifier.start(); + statusDone(status); + + return status; + } + + /** + * Method to query existence of the file or folder. + */ + protected DataElement handleQueryExists(DataElement subject, + DataElement status, String queryType) { + + File fileobj = null; + if (queryType.equals(UNIVERSAL_FILTER_DESCRIPTOR)) { + if (subject.getName().indexOf( + ArchiveHandlerManager.VIRTUAL_SEPARATOR) > 0) { + VirtualChild child = _archiveHandlerManager + .getVirtualObject(subject.getName()); + if (child.exists()) { + status.setAttribute(DE.A_SOURCE, "true"); + return statusDone(status); + } else { + status.setAttribute(DE.A_SOURCE, "false"); + return statusDone(status); + } + } else { + fileobj = new File(subject.getName()); + } + } else if (queryType.equals(UNIVERSAL_FILE_DESCRIPTOR) + || queryType.equals(UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) + fileobj = new File(subject.getAttribute(DE.A_VALUE) + + File.separatorChar + subject.getName()); + else if (queryType.equals(UNIVERSAL_FOLDER_DESCRIPTOR)) + fileobj = new File(subject.getAttribute(DE.A_VALUE)); + else if (queryType.equals(UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) + || queryType.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + AbsoluteVirtualPath vpath = getAbsoluteVirtualPath(subject); + ISystemArchiveHandler handler = _archiveHandlerManager + .getRegisteredHandler(new File(vpath + .getContainingArchiveString())); + if (handler == null) { + status.setAttribute(DE.A_SOURCE, "false"); + return statusDone(status); + } + VirtualChild child = handler.getVirtualFile(vpath.getVirtualPart()); + if (child.exists()) { + status.setAttribute(DE.A_SOURCE, "true"); + return statusDone(status); + } + + } + + if (fileobj.exists()) + status.setAttribute(DE.A_SOURCE, "true"); + else + status.setAttribute(DE.A_SOURCE, "false"); + return statusDone(status); + } + + /** + * Method to get remote object + */ + public DataElement handleQueryGetRemoteObject(DataElement subject, + DataElement status, String queryType) { + File fileobj = null; + boolean isVirtual = false; + String fullName = subject.getValue(); + if (queryType.equals(UNIVERSAL_FILTER_DESCRIPTOR)) { + isVirtual = ArchiveHandlerManager.isVirtual(fullName); + String filterValue = subject.getValue(); + // . translates to home dir + if (filterValue.equals(".")) + { + filterValue = System.getProperty("user.home"); + subject.setAttribute(DE.A_VALUE, filterValue); + } + if (!isVirtual) + fileobj = new File(filterValue); + } else { + UniversalServerUtilities.logError(CLASSNAME, + "Invalid query type to handleQueryGetRemoteObject", null); + return statusDone(status); + } + + if (!isVirtual && fileobj.exists()) { + + // Get the canonical path name so that we preserve case for Windows + // systems. + // Even though Windows is case insensitive, we still want to + // preserve case + // when we show the path as a property to the user + try { + fullName = fileobj.getCanonicalPath(); + + } catch (IOException e) { + return statusDone(status); + } + + if (fileobj.isFile()) + { + if (_archiveHandlerManager.isArchive(fileobj)) { + subject.setAttribute(DE.A_TYPE,UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR); + } else { + subject.setAttribute(DE.A_TYPE, UNIVERSAL_FILE_DESCRIPTOR); + } + String name = fullName + .substring( + fullName.lastIndexOf(File.separatorChar) + 1, + fullName.length()); + String path = fullName.substring(0, fullName + .lastIndexOf(File.separatorChar)); + subject.setAttribute(DE.A_NAME, name); + subject.setAttribute(DE.A_VALUE, path); + } + else { // directory + subject.setAttribute(DE.A_TYPE, UNIVERSAL_FOLDER_DESCRIPTOR); + subject.setAttribute(DE.A_NAME, ""); + subject.setAttribute(DE.A_VALUE, fullName); + } + + // DKM - do basic property stuff here + subject.setAttribute(DE.A_SOURCE, setProperties(fileobj)); + + /* + // classify the file too + if (fileobj.isFile()) { + subject.setAttribute(DE.A_SOURCE, subject + .getAttribute(DE.A_SOURCE) + + "|" + FileClassifier.classifyFile(fileobj)); + } + */ + + status.setAttribute(DE.A_SOURCE, SUCCESS); + } else if (isVirtual) { + try { + String goodFullName = ArchiveHandlerManager + .cleanUpVirtualPath(fullName); + AbsoluteVirtualPath avp = new AbsoluteVirtualPath(goodFullName); + VirtualChild child = _archiveHandlerManager + .getVirtualObject(goodFullName); + if (child.exists()) { + + if (child.isDirectory) { + subject.setAttribute(DE.A_TYPE, + UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR); + subject.setAttribute(DE.A_NAME, child.name); + if (child.path.equals("")) { + subject.setAttribute(DE.A_VALUE, avp + .getContainingArchiveString()); + } else { + subject.setAttribute(DE.A_VALUE, avp + .getContainingArchiveString() + + ArchiveHandlerManager.VIRTUAL_SEPARATOR + + child.path); + } + + } else { + subject.setAttribute(DE.A_TYPE, + UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR); + String name = child.name; + String path = avp.getContainingArchiveString(); + if (!child.path.equals("")) { + path = path + + ArchiveHandlerManager.VIRTUAL_SEPARATOR + + child.path; + } + + subject.setAttribute(DE.A_NAME, name); + subject.setAttribute(DE.A_VALUE, path); + } + + subject.setAttribute(DE.A_SOURCE, setProperties(child)); + status.setAttribute(DE.A_SOURCE, SUCCESS); + } else { + UniversalServerUtilities.logWarning(CLASSNAME, + "object does not exist"); + subject.setAttribute(DE.A_SOURCE, setProperties(child)); + status + .setAttribute(DE.A_SOURCE, + FAILED_WITH_DOES_NOT_EXIST); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } else { + subject.setAttribute(DE.A_SOURCE, setProperties(fileobj)); + status.setAttribute(DE.A_SOURCE, FAILED_WITH_DOES_NOT_EXIST); + } + + _dataStore.refresh(subject); + return statusDone(status); + } + + protected DataElement getFileElement(DataElement subject, File file) { + String fileName = file.getName(); + + for (int i = 0; i < subject.getNestedSize(); i++) { + DataElement child = subject.get(i); + if (child.getName().equals(fileName)) { + String type = subject.getType(); + boolean isfile = file.isFile(); + + if (isfile) { + return child; + } else if (type.equals(UNIVERSAL_FOLDER_DESCRIPTOR)) { + return child; + } + } + } + + return null; + } + + protected void createDataElement(DataStore ds, DataElement subject, + File[] list, String queryType, String filter, int include) + { + createDataElement(ds, subject, list, queryType, filter, include, null); + } + /** + * Method to create the DataElement object in the datastore. + */ + + protected void createDataElement(DataStore ds, DataElement subject, + File[] list, String queryType, String filter, int include, String types[]) + { + + IdentityHashMap foundMap = new IdentityHashMap(list.length); + List children = subject.getNestedData(); + if (children != null) + { + ArrayList filteredChildren = new ArrayList(); + for (int f = 0; f < children.size(); f++) + { + DataElement child = (DataElement)children.get(f); + String type = child.getType(); + if (type.equals(UNIVERSAL_FILE_DESCRIPTOR) || type.equals(UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) + { + if (StringCompare.compare(filter, child.getName(), false)) + { + filteredChildren.add(child); + } + } + else + { + filteredChildren.add(child); + } + } + + + if (filteredChildren.size() != 0) + { + boolean found; + Object[] currentObjList = filteredChildren.toArray(); + + // Check if the current Objects in the DataStore are valid... exist + // on the remote host + try { + for (int i = 0; i < currentObjList.length; ++i) + { + found = false; + DataElement previousElement = (DataElement) currentObjList[i]; + for (int j = 0; j < list.length && !found; ++j) + { + + if (previousElement.getName().equals(list[j].getName()) && !previousElement.isDeleted()) + { + // Type have to be equal as well + String type = ((DataElement) currentObjList[i]).getType(); + boolean isfile = list[j].isFile(); + if (((type.equals(UNIVERSAL_FILE_DESCRIPTOR) || type.equals(UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) && isfile) + || + (type.equals(UNIVERSAL_FOLDER_DESCRIPTOR) && !isfile)) + { + if (types !=null) + { + String attributes = previousElement.getAttribute(DE.A_SOURCE); + String thisType = types[j]; + if (attributes.indexOf(thisType) != -1) + { + foundMap.put(list[j], currentObjList[i]); // already exists so don't recreate the element + found = true; + } + } + else + { + foundMap.put(list[j], currentObjList[i]); // already exists so don't recreate the element + found = true; + } + } + } + } // end for j + + // Object in DataStore no longer exists in the host. Remove + // it from DataStore. + if (found == false) + { + //DataElement deObj = ds.find(subject, DE.A_NAME,((DataElement) currentObjList[i]).getName(), 1); + ds.deleteObject(subject, previousElement); + } + } // end for i + } catch (Exception e) { + e.printStackTrace(); + UniversalServerUtilities.logError(CLASSNAME, + "createDataElement failed with exception - isFile ", e); + } + } // end currentObj not 0 + } + + // Now query the other way. If the object queried, exists on the host, + // then check if + // it is already in datastore. If so do not recreate it. + + if (list != null) + { + + /* + * DKM: I've commented out this as we shouldn't need it any more + * with the above code working + * + * if (subject.getNestedData().size() != 0) { + * _dataStore.deleteObjects(subject); // subject.removeNestedData(); + * //System.out.println("removing nested data"); } + */ + + + // DKM - test - dummy object + //ds.createObject(subject,UNIVERSAL_FILE_DESCRIPTOR,"I'm not really here!"); + + for (int i = 0; i < list.length; i++) + { + DataElement deObj = null; + File file = list[i]; + + try + { + String fileName = file.getName(); + boolean isHidden = file.isHidden() || fileName.charAt(0) == '.'; + + if (!isHidden || showHidden) + { + // check for duplicates + Object obj = foundMap.get(file); + if (obj != null && obj instanceof DataElement) + { + deObj = (DataElement)obj; + } + //deObj = getFileElement(subject, list[i]); + + if (deObj == null) + { + if (include == INCLUDE_ALL) + { + if (file.isDirectory()) + { + deObj = ds.createObject(subject,deUniversalFolderObject,fileName); + } + else + // file + { + if (ArchiveHandlerManager.getInstance().isArchive(file)) + { + deObj = ds + .createObject( + subject, + deUniversalArchiveFileObject, + fileName); + } + else + { + deObj = ds.createObject(subject, + deUniversalFileObject, + fileName); + } + } + } + else if (include == INCLUDE_FOLDERS_ONLY) + { + if (ArchiveHandlerManager.getInstance().isArchive(file)) + { + deObj = ds.createObject(subject, + deUniversalArchiveFileObject, + fileName); + } + else + { + deObj = ds.createObject(subject, + deUniversalFolderObject, + fileName); + } + } + else if (include == INCLUDE_FILES_ONLY) + { + if (ArchiveHandlerManager.getInstance().isArchive(file)) + { + deObj = ds.createObject(subject, + deUniversalArchiveFileObject, + fileName); + } + else + { + deObj = ds + .createObject(subject, + deUniversalFileObject, + fileName); + } + } + + if (queryType.equals(UNIVERSAL_FILTER_DESCRIPTOR)) + { + deObj.setAttribute(DE.A_VALUE, subject.getAttribute(DE.A_VALUE)); + } + else + { + + if (subject.getName().length() > 0) + { + String valueStr = subject.getAttribute(DE.A_VALUE); + //String valueStr = list[i].getParentFile().getAbsolutePath(); + StringBuffer valueBuffer = new StringBuffer(valueStr); + if ((_isWindows && valueStr.endsWith("\\"))|| valueStr.endsWith("/") || subject.getName().startsWith("/")) + { + valueBuffer.append(subject.getName()); + deObj.setAttribute(DE.A_VALUE,valueBuffer.toString()); + } + else + { + valueBuffer.append(File.separatorChar); + valueBuffer.append(subject.getName()); + deObj.setAttribute(DE.A_VALUE,valueBuffer.toString()); + } + } + else + { + String valueStr = list[i].getParentFile().getAbsolutePath(); + deObj.setAttribute(DE.A_VALUE, valueStr); + } + } + } + // DKM - do basic property stuff here + String properties = setProperties(file); + + if (types != null) + { + /* + String oldClassification = getClassificationString(deObj.getAttribute(DE.A_SOURCE)); + if (oldClassification != null && !oldClassification.equals(types[i])) + { + deObj.setAttribute(DE.A_SOURCE, properties + "|" + oldClassification + " " + types[i]); + } + else + */ + { + deObj.setAttribute(DE.A_SOURCE, properties + "|" + types[i]); + } + } + else + { + deObj.setAttribute(DE.A_SOURCE, properties); + } + + } + } catch (Exception e) + { + UniversalServerUtilities + .logError( + CLASSNAME, + "createDataElement failed with exception - isHidden ", + e); + } + } // end for + } // if list !=null + //*/ + + } + + /** + * Method to create the DataElement object in the datastore out of a list of + * VirtualChildren + */ + + protected void createDataElement(DataStore ds, DataElement subject, + VirtualChild[] list, String filter, String rootPath, + String virtualPath) + { + + IdentityHashMap foundMap = null; + List children = subject.getNestedData(); + if (children != null) + { + ArrayList filteredChildren = new ArrayList(); + + for (int f = 0; f < children.size(); f++) + { + DataElement child = (DataElement)children.get(f); + String type = child.getType(); + if (type.equals(UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || + type.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) + { + if (StringCompare.compare(filter, child.getName(), false)) + { + filteredChildren.add(child); + } + } + else + { + filteredChildren.add(child); + } + } + + foundMap = new IdentityHashMap(list.length); + + if (filteredChildren.size() != 0) + { + boolean found; + Object[] currentObjList = filteredChildren.toArray(); + + // Check if the current Objects in the DataStore are valid... exist + // on the remote host + try { + for (int i = 0; i < currentObjList.length; ++i) { + found = false; + DataElement previousElement = (DataElement) currentObjList[i]; + for (int j = 0; j < list.length && !found; ++j) + { + + if (!previousElement.isDeleted() + && previousElement.getName().equals(list[j].name)) + { + // Type have to be equal as well + String type = previousElement.getType(); + boolean isfile = !list[j].isDirectory; + if (type.equals(UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) + || (type.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR) && !isfile) + ) + { + foundMap.put(list[j], previousElement); + found = true; + } + } + } // end for j + + // Object in DataStore no longer exists in the host. Remove + // it from DataStore. + if (found == false) + { + ds.deleteObject(subject, previousElement); + } + } // end for i + } catch (Exception e) { + e.printStackTrace(); + UniversalServerUtilities.logError(CLASSNAME, + "createDataElement failed with exception - isFile ", e); + } + } // end currentObj not 0 + } + + + // Now query the other way. If the object queried, exists on the host, + // then check if + // it is already in datastore. If so do not recreate it. + + if (list != null) + { + for (int i = 0; i < list.length; i++) + { + DataElement deObj = null; + VirtualChild child = list[i]; + Object obj = null; + if (foundMap != null) + { + obj = foundMap.get(child); + } + if (obj != null && obj instanceof DataElement) + { + deObj = (DataElement)obj; + } + + if (deObj == null) + { + if (child.isDirectory) + { + deObj = _dataStore.createObject(subject, UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR,child.name); + } + else // file + { + deObj = _dataStore.createObject(subject,UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR, child.name); + } + + } + deObj.setAttribute(DE.A_VALUE, rootPath + ArchiveHandlerManager.VIRTUAL_SEPARATOR + virtualPath); + deObj.setAttribute(DE.A_SOURCE, setProperties(child)); + } + } + + //*/ + } + + public String setProperties(File fileObj) { + return setProperties(fileObj, false); + } + + /** + * Method to obtain the properties of file or folder. + */ + public String setProperties(File fileObj, boolean doArchiveProperties) { + String version = VERSION_1; + StringBuffer buffer = new StringBuffer(500); + long date = fileObj.lastModified(); + long size = fileObj.length(); + boolean hidden = fileObj.isHidden(); + boolean canWrite = fileObj.canWrite() ; + boolean canRead = fileObj.canRead(); + + // These extra properties here might cause problems for older clients, + // ie: a IndexOutOfBounds in UniversalFileImpl. + + // DKM: defer this until later as it is bad for performacnes.. + // I think we're doing the full query on an archive by instantiating a + // handler + boolean isArchive = false;//ArchiveHandlerManager.getInstance().isArchive(fileObj); + + String comment; + if (isArchive) + comment = ArchiveHandlerManager.getInstance().getComment(fileObj); + else + comment = " "; + + long compressedSize = size; + String compressionMethod = " "; + double compressionRatio = 0; + + long expandedSize; + if (isArchive) + expandedSize = ArchiveHandlerManager.getInstance().getExpandedSize( + fileObj); + else + expandedSize = size; + + buffer.append(version).append(TOKEN_SEPARATOR).append(date).append( + TOKEN_SEPARATOR).append(size).append(TOKEN_SEPARATOR); + buffer.append(hidden).append(TOKEN_SEPARATOR).append(canWrite).append( + TOKEN_SEPARATOR).append(canRead); + + // values might not be used but we set them here just so that there are right number + // of properties + buffer.append(TOKEN_SEPARATOR); + buffer.append(comment).append(TOKEN_SEPARATOR).append(compressedSize) + .append(TOKEN_SEPARATOR).append(compressionMethod).append( + TOKEN_SEPARATOR); + buffer.append(compressionRatio).append(TOKEN_SEPARATOR).append( + expandedSize); + + + String buf = buffer.toString(); + return buf; + } + + public String setProperties(VirtualChild fileObj) { + String version = VERSION_1; + StringBuffer buffer = new StringBuffer(500); + long date = fileObj.getTimeStamp(); + long size = fileObj.getSize(); + boolean hidden = false; + boolean canWrite = fileObj.getContainingArchive().canWrite(); + boolean canRead = fileObj.getContainingArchive().canRead(); + + // These extra properties here might cause problems for older clients, + // ie: a IndexOutOfBounds in UniversalFileImpl. + String comment = fileObj.getComment(); + if (comment.equals("")) + comment = " "; // make sure this is still a + // token + long compressedSize = fileObj.getCompressedSize(); + String compressionMethod = fileObj.getCompressionMethod(); + if (compressionMethod.equals("")) + compressionMethod = " "; + double compressionRatio = fileObj.getCompressionRatio(); + long expandedSize = size; + + buffer.append(version).append(TOKEN_SEPARATOR).append(date).append( + TOKEN_SEPARATOR).append(size).append(TOKEN_SEPARATOR); + buffer.append(hidden).append(TOKEN_SEPARATOR).append(canWrite).append( + TOKEN_SEPARATOR).append(canRead); + + buffer.append(TOKEN_SEPARATOR); + buffer.append(comment).append(TOKEN_SEPARATOR).append(compressedSize) + .append(TOKEN_SEPARATOR).append(compressionMethod).append( + TOKEN_SEPARATOR); + buffer.append(compressionRatio).append(TOKEN_SEPARATOR).append( + expandedSize); + + return buffer.toString(); + } + + /** + * Method to obtain the classificatoin string of file or folder. + */ + protected String getClassificationString(String s) { + + //StringTokenizer tokenizer = new StringTokenizer(s, TOKEN_SEPARATOR); + String[] str = s.split("\\"+TOKEN_SEPARATOR); + int tokens = str.length; + if (tokens < 10) + return null; + /* + int tokens = tokenizer.countTokens(); + if (tokens < 10) + return null; + + String[] str = new String[tokens]; + + for (int i = 0; i < tokens; ++i) { + str[i] = tokenizer.nextToken(); + } +*/ + + return (str[10]); + } + /** + * Method to obtain the filter string of file or folder. + */ + protected String getFilterString(String s) { + + //StringTokenizer tokenizer = new StringTokenizer(s, TOKEN_SEPARATOR); + String[] str = s.split("\\"+TOKEN_SEPARATOR); + int tokens = str.length; + + /* + int tokens = tokenizer.countTokens(); + String[] str = new String[tokens]; + + for (int i = 0; i < tokens; ++i) { + str[i] = tokenizer.nextToken(); + } + */ + if (tokens > 1) + { + return (str[1]); + } + else + { + System.out.println("problem with properties:"+s); + return "*"; + } + } + + /** + * Method to obtain the show Hidden flag for file or folder. + */ + protected boolean getShowHiddenFlag(String s) { + + //StringTokenizer tokenizer = new StringTokenizer(s, TOKEN_SEPARATOR); + String[] str = s.split("\\"+TOKEN_SEPARATOR); + int tokens = str.length; + /* + int tokens = tokenizer.countTokens(); + String[] str = new String[tokens]; + + for (int i = 0; i < tokens; ++i) { + str[i] = tokenizer.nextToken(); + } + */ + if (tokens > 2) + { + return ((new Boolean(str[2])).booleanValue()); + } + else + { + System.out.println("show hidden flag problem:"+s); + return true; + } + } + + /** + * Method to obtain the depth for a search + */ + protected int getDepth(String s) + { + String[] str = s.split("\\"+TOKEN_SEPARATOR); + int tokens = str.length; + /* + StringTokenizer tokenizer = new StringTokenizer(s, TOKEN_SEPARATOR); + + int tokens = tokenizer.countTokens(); + */ + if (tokens < 4) { + return 1; + } +/* + String[] str = new String[tokens]; + + for (int i = 0; i < tokens; ++i) { + str[i] = tokenizer.nextToken(); + } +*/ + return ((new Integer(str[3])).intValue()); + } + + /** + * Method to download a file. + */ + protected DataElement handleDownload(DataElement theElement, + DataElement status) { + + UniversalDownloadHandler downloadThread = new UniversalDownloadHandler( + _dataStore, this, theElement, status); + downloadThread.start(); + + // save find thread in hashmap for retrieval during cancel + _cancellableThreads.put(status.getParent(), downloadThread); + return status; + + /* + * DataElement arg1 = getCommandArgument(theElement, 1); String + * elementType = arg1.getType(); String remotePath = arg1.getName(); + * + * String resultType = null; String resultMessage = null; + * + * FileInputStream inputStream = null; BufferedInputStream + * bufInputStream = null; + * + * try { + * + * if (elementType.equals(UNIVERSAL_FILE_DESCRIPTOR) || + * elementType.equals(UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) || + * elementType.equals(UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) { + * _dataStore.trace("download:" + remotePath + "," + elementType); + * + * File file = new File(remotePath); + * + * + * if (elementType.equals(UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) { + * AbsoluteVirtualPath vpath = getAbsoluteVirtualPath(remotePath); + * + * ISystemArchiveHandler handler = + * _archiveHandlerManager.getRegisteredHandler(new + * File(vpath.getContainingArchiveString())); VirtualChild vChild = + * handler.getVirtualFile(vpath.getVirtualPart()); file = + * vChild.getExtractedFile(); } + * + * DataElement arg2 = getCommandArgument(theElement, 2); DataElement + * arg3 = getCommandArgument(theElement, 3); + * + * int mode = (Integer.valueOf(arg1.getSource())).intValue(); String + * localPath = arg2.getName(); + * + * boolean isText = (mode == TEXT_MODE); + * + * String clientEncoding = null; + * + * if (isText) { clientEncoding = arg2.getSource(); } // Read in the + * file inputStream = new FileInputStream(file); bufInputStream = new + * BufferedInputStream(inputStream, BUFFER_SIZE); + * + * boolean first = true; byte[] buffer = new byte[BUFFER_SIZE]; byte[] + * convBytes; int numToRead = 0; + * + * int available = bufInputStream.available(); + * + * while (available > 0) { numToRead = (available < BUFFER_SIZE) ? + * available : BUFFER_SIZE; + * + * int bytesRead = bufInputStream.read(buffer, 0, numToRead); + * + * if (bytesRead == -1) break; + * + * if (isText) { convBytes = (new String(buffer, 0, + * bytesRead)).getBytes(clientEncoding); + * + * if (first) { // send first set of bytes first = false; + * _dataStore.updateFile(localPath, convBytes, convBytes.length, true); } + * else { // append subsequent segments + * _dataStore.updateAppendFile(localPath, convBytes, convBytes.length, + * true); } } else { + * + * if (first) { // send first set of bytes first = false; + * _dataStore.updateFile(localPath, buffer, bytesRead, true); } else { // + * append subsequent segments _dataStore.updateAppendFile(localPath, + * buffer, bytesRead, true); } } + * + * available = bufInputStream.available(); } + * + * resultType = DOWNLOAD_RESULT_SUCCESS_TYPE; resultMessage = + * DOWNLOAD_RESULT_SUCCESS_MESSAGE; } } catch (FileNotFoundException e) { + * UniversalServerUtilities.logError(CLASSNAME, "handleDownload: error + * reading file " + remotePath, e); resultType = + * DOWNLOAD_RESULT_FILE_NOT_FOUND_EXCEPTION; resultMessage = + * e.getLocalizedMessage(); } catch (UnsupportedEncodingException e) { + * UniversalServerUtilities.logError(CLASSNAME, "handleDownload: error + * reading file " + remotePath, e); resultType = + * DOWNLOAD_RESULT_UNSUPPORTED_ENCODING_EXCEPTION; resultMessage = + * e.getLocalizedMessage(); } catch (IOException e) { + * UniversalServerUtilities.logError(CLASSNAME, "handleDownload: error + * reading file " + remotePath, e); resultType = + * DOWNLOAD_RESULT_IO_EXCEPTION; resultMessage = + * e.getLocalizedMessage(); } catch (Exception e) { e.printStackTrace(); } + * finally { + * + * try { + * + * if (bufInputStream != null) bufInputStream.close(); } catch + * (IOException e) { UniversalServerUtilities.logError(CLASSNAME, + * "handleDownload: error closing reader on " + remotePath, e); + * resultType = DOWNLOAD_RESULT_IO_EXCEPTION; resultMessage = + * e.getMessage(); } } + * + * _dataStore.createObject(arg1, resultType, resultMessage); + * _dataStore.refresh(arg1); return statusDone(status); + */ + } + + /** + * Get the system encoding + */ + protected DataElement handleQueryEncoding(DataElement subject, DataElement status) { + + String encoding = System.getProperty("file.encoding"); + + subject.setAttribute(DE.A_VALUE, encoding); + _dataStore.refresh(subject); + + return statusDone(status); + } + + /** + * Get an unused port number. + */ + protected DataElement handleQueryUnusedPort(DataElement subject, DataElement status) { + + int port = -1; + + // create a server socket with port 0 (i.e. use any free port) + try { + ServerSocket socket = new ServerSocket(0); + port = socket.getLocalPort(); + socket.close(); + } + catch (IOException e) { + UniversalServerUtilities.logError(CLASSNAME, "Can not get unused port", e); + port = -1; + } + + String portNum = String.valueOf(port); + subject.setAttribute(DE.A_VALUE, portNum); + _dataStore.refresh(subject); + + return statusDone(status); + } + + /** + * Complete status. + */ + public DataElement statusDone(DataElement status) { + status.setAttribute(DE.A_NAME, DataStoreResources.model_done); + _dataStore.refresh(status); + return status; + } + + /** + * Cancel status. + */ + public DataElement statusCancelled(DataElement status) { + status.setAttribute(DE.A_NAME, "cancelled"); + _dataStore.refresh(status); + return status; + } + + /** + * @see Miner#load() + */ + public void load() { + // Create datastore tree structure for UniversalFileSystemMiner + deUFSnode = _dataStore.createObject(_minerData, + UNIVERSAL_NODE_DESCRIPTOR, "universal.node"); + deUFStemp = _dataStore.createObject(deUFSnode, + UNIVERSAL_NODE_DESCRIPTOR, "universal.temp"); + deUFSfilters = _dataStore.createObject(deUFSnode, + UNIVERSAL_NODE_DESCRIPTOR, "universal.filters"); + deUFSuploadlog = _dataStore.createObject(deUFSnode, + UNIVERSAL_NODE_DESCRIPTOR, "universal.uploadlog"); + + UniversalByteStreamHandler universalHandler = new UniversalByteStreamHandler(_dataStore, deUFSuploadlog); + + //_dataStore.setByteStreamHandler(new UniversalByteStreamHandler(_dataStore, deUFSuploadlog)); + _dataStore.registerByteStreamHandler(universalHandler); + + _dataStore.refresh(_minerData); + _dataStore.refresh(deUFSuploadlog); + } + + public void finish() { + //_archiveHandlerManager.dispose(); + super.finish(); + } + + /** + * Retrieve the fully qualified class name (including package) for the + * specified .class file. This information is required by the distributed + * debugger. + */ + protected DataElement handleQueryClassName(DataElement subject, + DataElement status) { + String filename = subject.getAttribute(DE.A_VALUE) + File.separatorChar + + subject.getName(); + + try { + ClassFileParser parser = new ClassFileParser( + getInputStreamForFile(filename)); + String name = parser.getPackageName(); + if (name != null) { + _dataStore.createObject(status, "qualifiedClassName", name); + } else { + _dataStore.createObject(status, "qualifiedClassName", "null"); + } + } catch (java.io.IOException e) { + _dataStore.createObject(status, "qualifiedClassName", "null"); + } + + return statusDone(status); + } + + /** + * Retrieve the fully qualified class name (including package) for a class + * file. + */ + protected DataElement handleQueryQualifiedClassName(DataElement subject, DataElement status) { + + // first get parent path + String parentPath = subject.getAttribute(DE.A_VALUE); + + // get system separator + String sep = File.separator; + + boolean isParentArchive = ArchiveHandlerManager.getInstance().isRegisteredArchive(parentPath); + + boolean isParentVirtual = ArchiveHandlerManager.isVirtual(parentPath); + + // parent is virtual folder, so make separator "/" + if (isParentVirtual) { + sep = "/"; + } + + // file path + String filePath = null; + + // parent is not a virtual archive + if (!isParentArchive) { + + // if parent path does not end with separator, then add it + if (!parentPath.endsWith(sep)) { + parentPath = parentPath + sep; + } + + // add file name to get the file path + filePath = parentPath + subject.getName(); + } + // parent is an archive, so add virtual file separator, then the file name + else { + filePath = parentPath + ArchiveHandlerManager.VIRTUAL_SEPARATOR + subject.getName(); + } + + try { + + String className = null; + + // if parent is not an archive or a virtual folder, then file must be + // a file + if (!(isParentArchive || isParentVirtual)) { + className = ClassFileUtil.getInstance().getQualifiedClassName(filePath); + } + // otherwise, file is a virtual file + else { + String classification = SystemFileClassifier.getInstance().classifyFile(filePath); + String execJava = "executable(java:"; + + int idx = classification.indexOf(execJava); + + if (idx != -1) { + idx = idx + execJava.length(); + int jdx = classification.indexOf(")", idx); + + if (jdx != -1) { + + if (jdx > idx) { + className = classification.substring(idx, jdx); + } + else if (jdx == idx) { + className = ""; + } + } + } + } + + if (className != null) { + _dataStore.createObject(status, TYPE_QUALIFIED_CLASSNAME, className); + } else { + _dataStore.createObject(status, TYPE_QUALIFIED_CLASSNAME, "null"); + } + } catch (IOException e) { + UniversalServerUtilities.logError(CLASSNAME, + "I/O error occured trying to read class file " + filePath, + null); + + _dataStore.createObject(status, TYPE_QUALIFIED_CLASSNAME, "null"); + } + + return statusDone(status); + } + + /** + * Method to retrieve the OS that the miner is running. + */ + public DataElement handleGetOSType(DataElement subject, DataElement status) { + String osType = System.getProperty("os.name").toLowerCase(); + status.setAttribute(DE.A_SOURCE, osType); + _dataStore.refresh(subject); + return statusDone(status); + } + + protected java.io.InputStream getInputStreamForFile(String filename) + throws java.io.IOException { + File file = new File(filename); + return file.toURL().openStream(); + } + + /** + * @see Miner#extendSchema(DataElement) + */ + public void extendSchema(DataElement schemaRoot) { + DataElement root = _dataStore.find(schemaRoot, DE.A_NAME, + DataStoreResources.model_root, 1); + DataElement snode = createObjectDescriptor(schemaRoot, + UNIVERSAL_NODE_DESCRIPTOR); + + DataElement tempnode = createObjectDescriptor(schemaRoot, + UNIVERSAL_TEMP_DESCRIPTOR); + + // Define filesystem descriptors + DataElement UniversalFilter = createObjectDescriptor(schemaRoot, + UNIVERSAL_FILTER_DESCRIPTOR); + deUniversalFileObject = createObjectDescriptor(schemaRoot, + UNIVERSAL_FILE_DESCRIPTOR); + deUniversalFolderObject = createObjectDescriptor(schemaRoot, + UNIVERSAL_FOLDER_DESCRIPTOR); + deUniversalArchiveFileObject = createObjectDescriptor( + schemaRoot, UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR); + deUniversalVirtualFileObject = createObjectDescriptor( + schemaRoot, UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR); + deUniversalVirtualFolderObject = createObjectDescriptor( + schemaRoot, UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR); + + _dataStore.refresh(schemaRoot); + + // Define command descriptors + createCommandDescriptor(UniversalFilter, "Filter", "C_QUERY_VIEW_ALL"); + createCommandDescriptor(UniversalFilter, "Filter", "C_QUERY_VIEW_FILES"); + createCommandDescriptor(UniversalFilter, "Filter", + "C_QUERY_VIEW_FOLDERS"); + createCommandDescriptor(UniversalFilter, "Filter", "C_QUERY_ROOTS"); + + createCommandDescriptor(UniversalFilter, "GetOSType", "C_GET_OSTYPE"); + createCommandDescriptor(UniversalFilter, "Exists", "C_QUERY_EXISTS"); + createCommandDescriptor(UniversalFilter, "GetRemoteObject", + "C_QUERY_GET_REMOTE_OBJECT"); + createCommandDescriptor(UniversalFilter, "CreateNewFile", + "C_CREATE_FILE"); + createCommandDescriptor(UniversalFilter, "CreateNewFolder", + "C_CREATE_FOLDER"); + createCommandDescriptor(deUniversalFolderObject, "Filter", + "C_QUERY_VIEW_ALL"); + createCommandDescriptor(deUniversalFolderObject, "Filter", + "C_QUERY_VIEW_FILES"); + createCommandDescriptor(deUniversalFolderObject, "Filter", + "C_QUERY_VIEW_FOLDERS"); + createCommandDescriptor(deUniversalArchiveFileObject, "Filter", + "C_QUERY_VIEW_ALL"); + createCommandDescriptor(deUniversalArchiveFileObject, "Filter", + "C_QUERY_VIEW_FILES"); + createCommandDescriptor(deUniversalArchiveFileObject, "Filter", + "C_QUERY_VIEW_FOLDERS"); + + _dataStore.createReference(deUniversalFileObject, + deUniversalArchiveFileObject, "abstracts", "abstracted by"); + _dataStore.createReference(deUniversalFolderObject, + deUniversalArchiveFileObject, "abstracts", "abstracted by"); + _dataStore.createReference(deUniversalFileObject, + deUniversalVirtualFileObject, "abstracts", "abstracted by"); + _dataStore.createReference(deUniversalFolderObject, + deUniversalVirtualFolderObject, "abstracts", "abstracted by"); + + // create the search descriptor and make it cacnellable + DataElement searchDescriptor = createCommandDescriptor( + deUniversalFolderObject, "Search", "C_SEARCH"); + DataElement cancellable = _dataStore.find(schemaRoot, DE.A_NAME, + DataStoreResources.model_Cancellable, 1); + _dataStore.createReference(cancellable, searchDescriptor, "abstracts", + "abstracted by"); + + createCommandDescriptor(deUniversalFolderObject, "GetAdvanceProperty", + "C_QUERY_ADVANCE_PROPERTY"); + createCommandDescriptor(tempnode, "Filter", "C_CREATE_TEMP"); + createCommandDescriptor(deUniversalFileObject, "Delete", "C_DELETE"); + createCommandDescriptor(deUniversalFileObject, "DeleteBatch", "C_DELETE_BATCH"); + createCommandDescriptor(deUniversalFileObject, "CreateNewFile", + "C_CREATE_FILE"); + createCommandDescriptor(deUniversalFileObject, "CreateNewFolder", + "C_CREATE_FOLDER"); + createCommandDescriptor(deUniversalFileObject, "Rename", "C_RENAME"); + createCommandDescriptor(deUniversalFileObject, "SetReadOnly", + "C_SET_READONLY"); + createCommandDescriptor(deUniversalFileObject, "SetLastModified", + "C_SET_LASTMODIFIED"); + createCommandDescriptor(deUniversalFileObject, "GetAdvanceProperty", + "C_QUERY_ADVANCE_PROPERTY"); + dePropertyQuery = createCommandDescriptor(deUniversalFileObject, + "GetBasicProperty", "C_QUERY_BASIC_PROPERTY"); + + createCommandDescriptor(deUniversalFileObject, "GetcanWriteProperty", + "C_QUERY_CAN_WRITE_PROPERTY"); + createCommandDescriptor(deUniversalFileObject, "Exists", "C_QUERY_EXISTS"); + + createCommandDescriptor(deUniversalFolderObject, "Delete", "C_DELETE"); + createCommandDescriptor(deUniversalFolderObject, "DeleteBatch", "C_DELETE_BATCH"); + createCommandDescriptor(deUniversalFolderObject, "Rename", "C_RENAME"); + createCommandDescriptor(deUniversalFolderObject, "Copy", "C_COPY"); + createCommandDescriptor(deUniversalFolderObject, "CopyBatch", "C_COPY_BATCH"); + createCommandDescriptor(deUniversalFolderObject, "CreateNewFolder", + "C_CREATE_FOLDER"); + createCommandDescriptor(deUniversalFolderObject, "SetReadOnly", + "C_SET_READONLY"); + createCommandDescriptor(deUniversalFolderObject, "SetLastModified", + "C_SET_LASTMODIFIED"); + createCommandDescriptor(deUniversalFolderObject, "GetBasicProperty", + "C_QUERY_BASIC_PROPERTY"); + createCommandDescriptor(deUniversalFolderObject, "GetcanWriteProperty", + "C_QUERY_CAN_WRITE_PROPERTY"); + + deFileClassificationQuery = createCommandDescriptor( + deUniversalFileObject, "GetFileClassifications", + "C_QUERY_FILE_CLASSIFICATIONS"); + deFolderClassificationQuery = createCommandDescriptor( + deUniversalFolderObject, "GetFolderClassifications", + "C_QUERY_FILE_CLASSIFICATION"); + createCommandDescriptor(deUniversalFolderObject, "Exists", + "C_QUERY_EXISTS"); + createCommandDescriptor(deUniversalFolderObject, "CreateNewFile", + "C_CREATE_FILE"); + createCommandDescriptor(deUniversalFolderObject, "CreateNewFolder", + "C_CREATE_FOLDER"); + createCommandDescriptor(deUniversalFolderObject, "GetOSType", + "C_GET_OSTYPE"); + createCommandDescriptor(deUniversalFileObject, "GetOSType", + "C_GET_OSTYPE"); + + // create a download command descriptor and make it cancellable + DataElement downloadDescriptor = createCommandDescriptor( + deUniversalFileObject, "DownloadFile", C_DOWNLOAD_FILE); + _dataStore.createReference(cancellable, downloadDescriptor, + "abstracts", "abstracted by"); + _dataStore.createReference(cancellable, downloadDescriptor, + "abstracts", "abstracted by"); + + DataElement adownloadDescriptor = createCommandDescriptor( + deUniversalArchiveFileObject, "DownloadFile", C_DOWNLOAD_FILE); + _dataStore.createReference(cancellable, adownloadDescriptor, + "abstracts", "abstracted by"); + _dataStore.createReference(cancellable, adownloadDescriptor, + "abstracts", "abstracted by"); + + createCommandDescriptor(tempnode, "SystemEncoding", C_SYSTEM_ENCODING); + + createCommandDescriptor(tempnode, "UnusedPort", C_QUERY_UNUSED_PORT); + + // command descriptor to retrieve package name for a class file + createCommandDescriptor(deUniversalFileObject, "GetQualifiedClassName", + "C_QUERY_CLASSNAME"); + + // command descriptor to retrieve qualified class name for class file + createCommandDescriptor(deUniversalFileObject, "GetFullClassName", + C_QUERY_QUALIFIED_CLASSNAME); + } + + private AbsoluteVirtualPath getAbsoluteVirtualPath(DataElement subject) { + StringBuffer path = new StringBuffer(subject.getAttribute(DE.A_VALUE)); + if (ArchiveHandlerManager.getInstance().isArchive( + new File(path.toString()))) { + path.append(ArchiveHandlerManager.VIRTUAL_SEPARATOR); + } else { + path.append('/'); + } + path.append(subject.getName()); + return getAbsoluteVirtualPath(path.toString()); + } + + public AbsoluteVirtualPath getAbsoluteVirtualPath(String path) { + AbsoluteVirtualPath vp = new AbsoluteVirtualPath(path); + return vp; + } + + public DataElement handleDeleteFromArchive(DataElement subject, + DataElement status) { + String type = subject.getType(); + DataElement deObj = null; + + AbsoluteVirtualPath vpath = getAbsoluteVirtualPath(subject); + if (vpath != null) { + ISystemArchiveHandler handler = _archiveHandlerManager + .getRegisteredHandler(new File(vpath + .getContainingArchiveString())); + if (handler == null || !handler.delete(vpath.getVirtualPart())) { + status.setAttribute(DE.A_SOURCE, FAILED); + _dataStore.refresh(subject); + return statusDone(status); + } + + if (type.equals(UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) { + deObj = _dataStore.find(subject, DE.A_NAME, subject.getName(), + 1); + _dataStore.deleteObject(subject, deObj); + status.setAttribute(DE.A_SOURCE, SUCCESS); + } else if (type.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + _dataStore.deleteObjects(subject); + DataElement parent = subject.getParent(); + _dataStore.deleteObject(parent, subject); + _dataStore.refresh(parent); + } + } + + _dataStore.refresh(subject); + return statusDone(status); + } + + public DataElement handleQueryAllArchive(DataElement subject, DataElement attributes, + DataElement status, boolean caseSensitive, boolean foldersOnly) { + File fileobj = null; + try { + ArchiveHandlerManager mgr = ArchiveHandlerManager.getInstance(); + char separatorChar = File.separatorChar; + if (ArchiveHandlerManager.isVirtual(subject + .getAttribute(DE.A_VALUE))) { + separatorChar = '/'; + } + + String path = subject.getAttribute(DE.A_VALUE) + separatorChar + + subject.getName(); + String rootPath = path; + String virtualPath = ""; + + VirtualChild[] children = null; + + if (subject.getType().equals(UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) { + // it's an archive file (i.e. file.zip) + fileobj = new File(rootPath); + subject.setAttribute(DE.A_SOURCE, setProperties(fileobj, true)); + + if (foldersOnly) { + children = mgr.getFolderContents(fileobj, ""); + } else { + children = mgr.getContents(fileobj, ""); + } + + } else if (subject.getType().equals( + UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + // it's a virtual folder (i.e. a folder within zip) + // need to determine the associate File object + AbsoluteVirtualPath avp = new AbsoluteVirtualPath(path); + rootPath = avp.getContainingArchiveString(); + virtualPath = avp.getVirtualPart(); + fileobj = new File(rootPath); + + if (fileobj.exists()) { + + if (foldersOnly) { + children = mgr.getFolderContents(fileobj, virtualPath); + } else { + children = mgr.getContents(fileobj, virtualPath); + } + + subject.setAttribute(DE.A_SOURCE, setProperties(mgr.getVirtualObject(virtualPath))); + if (children == null || children.length == 0) { + _dataStore.trace("problem with virtual:" + virtualPath); + } + } else { + _dataStore.trace("problem with File:" + rootPath); + } + } + createDataElement(_dataStore, subject, children, "*", rootPath, virtualPath); + + _dataStore.refresh(subject); + + FileClassifier clsfy = getFileClassifier(subject); + clsfy.start(); + + return statusDone(status); + } catch (Exception e) { + if (!(fileobj == null)) { + try { + (new FileReader(fileobj)).read(); + } catch (IOException ex) { + status.setAttribute(DE.A_VALUE, FILEMSG_NO_PERMISSION); + status.setAttribute(DE.A_SOURCE, FAILED); + _dataStore.refresh(subject); + return statusDone(status); + } + } + status.setAttribute(DE.A_VALUE, FILEMSG_ARCHIVE_CORRUPTED); + status.setAttribute(DE.A_SOURCE, FAILED); + return statusDone(status); + } + } + + private DataElement findExistingVirtual(DataElement subject, + VirtualChild vchild) { + String name = vchild.name; + for (int i = 0; i < subject.getNestedSize(); i++) { + DataElement child = subject.get(i); + String deName = child.getName(); + if (name.equals(deName)) { + if (vchild.isDirectory) { + if (child.getType().equals( + UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + return child; + } + } else { + if (child.getType().equals( + UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) { + return child; + } + } + } + } + return null; + } + + public ISystemArchiveHandler getArchiveHandlerFor(String archivePath) { + File file = new File(archivePath); + return _archiveHandlerManager.getRegisteredHandler(file); + } + + public DataElement handleCreateVirtualFile(DataElement subject, + DataElement status, String type) { + + AbsoluteVirtualPath vpath = null; + if (type.equals(UNIVERSAL_FILTER_DESCRIPTOR)) { + vpath = getAbsoluteVirtualPath(subject.getValue()); + } else { + vpath = getAbsoluteVirtualPath(subject); + } + ISystemArchiveHandler handler = getArchiveHandlerFor(vpath + .getContainingArchiveString()); + if (handler == null) { + status.setAttribute(DE.A_SOURCE, FAILED); + return statusDone(status); + } + VirtualChild child = handler.getVirtualFile(vpath.getVirtualPart()); + handler.createFile(vpath.getVirtualPart()); + + status.setAttribute(DE.A_SOURCE, SUCCESS); + if (type.equals(UNIVERSAL_FILTER_DESCRIPTOR)) { + String fullName = subject.getValue(); + String name = fullName.substring(fullName + .lastIndexOf(File.separatorChar) + 1, fullName.length()); + String path = fullName.substring(0, fullName + .lastIndexOf(File.separatorChar)); + subject.setAttribute(DE.A_NAME, name); + subject.setAttribute(DE.A_VALUE, path); + subject.setAttribute(DE.A_TYPE, UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR); + } + _dataStore.refresh(subject); + return statusDone(status); + } + + public DataElement handleCreateVirtualFolder(DataElement subject, + DataElement status, String type) { + + AbsoluteVirtualPath vpath = null; + if (type.equals(UNIVERSAL_FILTER_DESCRIPTOR)) { + vpath = getAbsoluteVirtualPath(subject.getValue()); + } else { + vpath = getAbsoluteVirtualPath(subject); + } + ISystemArchiveHandler handler = getArchiveHandlerFor(vpath + .getContainingArchiveString()); + if (handler == null) { + status.setAttribute(DE.A_SOURCE, FAILED); + return statusDone(status); + } + VirtualChild child = handler.getVirtualFile(vpath.getVirtualPart()); + handler.createFolder(vpath.getVirtualPart()); + + status.setAttribute(DE.A_SOURCE, SUCCESS); + if (type.equals(UNIVERSAL_FILTER_DESCRIPTOR)) { + String fullName = subject.getValue(); + String name = fullName.substring(fullName + .lastIndexOf(File.separatorChar) + 1, fullName.length()); + String path = fullName.substring(0, fullName + .lastIndexOf(File.separatorChar)); + subject.setAttribute(DE.A_NAME, name); + subject.setAttribute(DE.A_VALUE, path); + subject + .setAttribute(DE.A_TYPE, + UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR); + } + _dataStore.refresh(subject); + return statusDone(status); + } + + private File getFileFor(DataElement element) { + File result = null; + String type = element.getType(); + if (type.equals(UNIVERSAL_FILTER_DESCRIPTOR)) { + result = new File(element.getName()); + } else if (type.equals(UNIVERSAL_FILE_DESCRIPTOR) + || type.equals(UNIVERSAL_FOLDER_DESCRIPTOR) + || type.equals(UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) { + StringBuffer buf = new StringBuffer(element + .getAttribute(DE.A_VALUE)); + buf.append(File.separatorChar); + buf.append(element.getName()); + result = new File(buf.toString()); + } + + return result; + } + + public DataElement handleCopy(DataElement targetFolder, DataElement sourceFile, DataElement nameObj, DataElement status) { + + String newName = nameObj.getName(); + String targetType = targetFolder.getType(); + String srcType = sourceFile.getType(); + + if (targetType.equals(UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) || targetType.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + + // insert into an archive + AbsoluteVirtualPath vpath = getAbsoluteVirtualPath(targetFolder); + ISystemArchiveHandler handler = getArchiveHandlerFor(vpath.getContainingArchiveString()); + + if (handler == null) { + status.setAttribute(DE.A_SOURCE, FAILED); + return statusDone(status); + } + + File srcFile = null; + + if (srcType.equals(UNIVERSAL_FILE_DESCRIPTOR) || srcType.equals(UNIVERSAL_FOLDER_DESCRIPTOR) + || srcType.equals(UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) { + + srcFile = getFileFor(sourceFile); + } + else if (srcType.equals(UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + + AbsoluteVirtualPath svpath = getAbsoluteVirtualPath(sourceFile); + ISystemArchiveHandler shandler = getArchiveHandlerFor(svpath.getContainingArchiveString()); + + if (shandler == null) { + status.setAttribute(DE.A_SOURCE, FAILED); + return statusDone(status); + } + + VirtualChild child = shandler.getVirtualFile(svpath.getVirtualPart()); + srcFile = child.getExtractedFile(); + } + + String virtualContainer = ""; + + if (targetType.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + virtualContainer = vpath.getVirtualPart(); + } + + boolean result = handler.add(srcFile, virtualContainer, newName); + + if (result) { + status.setAttribute(DE.A_SOURCE, SUCCESS); + } + else { + status.setAttribute(DE.A_SOURCE, FAILED); + } + } + else if (srcType.equals(UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { + + // extract from an archive to folder + AbsoluteVirtualPath svpath = getAbsoluteVirtualPath(sourceFile); + ISystemArchiveHandler shandler = getArchiveHandlerFor(svpath.getContainingArchiveString()); + + if (shandler == null) { + status.setAttribute(DE.A_SOURCE, FAILED); + return statusDone(status); + } + + VirtualChild child = shandler.getVirtualFile(svpath.getVirtualPart()); + + File parentDir = getFileFor(targetFolder); + File destination = new File(parentDir, newName); + + if (child.isDirectory) { + shandler.extractVirtualDirectory(svpath.getVirtualPart(), parentDir, destination); + } + else { + shandler.extractVirtualFile(svpath.getVirtualPart(), destination); + } + } + else { + File tgtFolder = getFileFor(targetFolder); + File srcFile = getFileFor(sourceFile); + + // regular copy + boolean folderCopy = srcFile.isDirectory(); + String src = srcFile.getAbsolutePath(); + String tgt = tgtFolder.getAbsolutePath() + File.separatorChar + newName; + File tgtFile = new File(tgt); + + if (tgtFile.exists() && tgtFile.isDirectory() && newName.equals(srcFile.getName())) + { + tgt = tgtFolder.getAbsolutePath(); + } + + // handle special characters in source and target strings + StringBuffer srcBuf = new StringBuffer(src); + StringBuffer tgtBuf = new StringBuffer(tgt); + handleSpecialChars(srcBuf); + handleSpecialChars(tgtBuf); + + src = "\"" + srcBuf.toString() + "\""; + tgt = "\"" + tgtBuf.toString() + "\""; + + doCopyCommand(src, tgt, folderCopy, status); + } + + return statusDone(status); + } + + protected void handleSpecialChars(StringBuffer buf) + { + for (int i = 0; i < buf.length(); i++) + { + char c = buf.charAt(i); + + boolean isSpecialChar = isSpecialChar(c); + + if (isSpecialChar) + { + buf.insert(i, "\\"); + i++; + } + } + } + + /** + * Checks whether the given character is a special character in the shell. A special character is + * '$', '`', '"' and '\'. + * @param c the character to check. + * @return true if the character is a special character, false otherwise. + */ + protected boolean isSpecialChar(char c) { + + if ((c == '$') || (c == '`') || (c == '"') || (c == '\\')) { + return true; + } + else { + return false; + } + } + + public String getVersion() + { + return "7.0.0"; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalSearchHandler.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalSearchHandler.java new file mode 100644 index 00000000000..cb6ef126d42 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/filesystem/UniversalSearchHandler.java @@ -0,0 +1,382 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.filesystem; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashSet; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.core.util.StringCompare; +import org.eclipse.rse.dstore.universal.miners.ICancellableHandler; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.dstore.universal.miners.UniversalServerUtilities; +import org.eclipse.rse.services.clientserver.SystemFileClassifier; +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; +import org.eclipse.rse.services.clientserver.search.SystemSearchFileNameMatcher; +import org.eclipse.rse.services.clientserver.search.SystemSearchLineMatch; +import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatchLocator; +import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher; + +public class UniversalSearchHandler extends Thread implements ICancellableHandler +{ + protected HashSet _alreadySearched; + + private File _rootFile; + + protected boolean _isCancelled; + protected boolean _isDone; + protected int _depth = -1; + + protected DataStore _dataStore; + protected UniversalFileSystemMiner _miner; + protected DataElement _status; + + protected SystemSearchString _searchString; + protected SystemSearchStringMatcher _stringMatcher; + protected boolean _isFileSearch; + protected SystemSearchFileNameMatcher _fileNameMatcher; + protected String _classificationString; + + protected DataElement _deGrep; + protected DataElement _deFile; + protected DataElement _deFolder; + protected DataElement _deArchiveFile; + protected DataElement _deVirtualFile; + + protected boolean _fsCaseSensitive; + + public UniversalSearchHandler(DataStore dataStore, UniversalFileSystemMiner miner, SystemSearchString searchString, boolean fsCaseSensitive, File theFile, DataElement status) { + _dataStore = dataStore; + _miner = miner; + _searchString = searchString; + _fsCaseSensitive = fsCaseSensitive; + _alreadySearched = new HashSet(); + + _deGrep = _dataStore.findObjectDescriptor("grep"); + _deFile = _dataStore.findObjectDescriptor(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR); + _deFolder = _dataStore.findObjectDescriptor(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR); + _deArchiveFile = _dataStore.findObjectDescriptor(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR); + _deVirtualFile = _dataStore.findObjectDescriptor(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR); + boolean includeSubfolders = searchString.isIncludeSubfolders(); + + if (includeSubfolders) { + _depth = -1; + } + else { + _depth = 1; + } + + _rootFile = theFile; + _status = status; + + _isCancelled = false; + _isDone = false; + + _stringMatcher = new SystemSearchStringMatcher(_searchString.getTextString(), _searchString.isCaseSensitive(), _searchString.isTextStringRegex()); + + // if the search string is empty or if it is an asterisk, then we are doing a file search + // i.e. we do not want to look inside files + _isFileSearch = _stringMatcher.isSearchStringEmpty() || _stringMatcher.isSearchStringAsterisk(); + + _fileNameMatcher = new SystemSearchFileNameMatcher(_searchString.getFileNamesString(), fsCaseSensitive, _searchString.isFileNamesRegex()); + + // classification of files to restrict the search to + _classificationString = _searchString.getClassificationString(); + } + + public void run() { + + try { + internalSearch(_rootFile, _depth); + } + catch (Exception e) { + UniversalServerUtilities.logError(_miner.getName(), "Error occured when calling internal search", e); + } + + _isDone = true; + + if (_isCancelled) { + _miner.statusCancelled(_status); + } + else { + // NOTE: do not call miner statusDone() method since we want to + // update the status immediately. + // Otherwise we don't get an event on the client corresponding + // to status refresh. As a result client thinks + // search isn't finished. + // _miner.statusDone(_status); + _status.setAttribute(DE.A_NAME, "done"); + _dataStore.refresh(_status, true); // true indicates refresh immediately + } + } + + public boolean isCancelled() { + return _isCancelled; + } + + public boolean isDone() { + return _isDone; + } + + public void cancel() { + _isCancelled = true; + } + + protected boolean hasSearchedDirectory(File file) { + return _alreadySearched.contains(file); + } + + protected void internalSearch(File theFile, int depth) { + + // is it a directory? + boolean isDirectory = theFile.isDirectory(); + + // is it an archive? + boolean isArchive = ArchiveHandlerManager.getInstance().isArchive(theFile); + + String absPath = theFile.getAbsolutePath(); + String compareStr = theFile.getName(); + + // is it a virtual file? + boolean isVirtual = ArchiveHandlerManager.isVirtual(absPath); + + // is it a virtual directory? + boolean isVirtualDirectory = false; + + // if it is a virtual object, then get a reference to it + if (isVirtual) { + VirtualChild vc = ArchiveHandlerManager.getInstance().getVirtualObject(absPath); + isVirtualDirectory = isVirtual && vc.isDirectory; + } + + // base case for the recursive method call + // if the file is not a directory, an archive or a virtual directory, + // and we get a match with the file name, then we can search for match within the file + if (!isDirectory && + (!isArchive || _isFileSearch) && + !isVirtualDirectory && + doesFilePatternMatch(compareStr) && + doesClassificationMatch(absPath)) + { + DataElement deObj = null; + + // if the file is a virtual file, then get matches from the archive handler + if (ArchiveHandlerManager.isVirtual(absPath)) { + VirtualChild vc = ArchiveHandlerManager.getInstance().getVirtualObject(absPath); + + if (!vc.isDirectory) { + deObj = _dataStore.createObject(null, _deVirtualFile, compareStr); + + // if parent of virtual child is archive, then create it this way + if (vc.path.equals("")) { + deObj.setAttribute(DE.A_VALUE, vc.getContainingArchive().getAbsolutePath()); + } + else { + deObj.setAttribute(DE.A_VALUE, vc.getContainingArchive().getAbsolutePath() + + ArchiveHandlerManager.VIRTUAL_SEPARATOR + vc.path); + } + + deObj.setAttribute(DE.A_SOURCE, _miner.setProperties(vc)); + + SystemSearchLineMatch[] results = null; + + // if it's not a file search, call the handler method to search + if (!_isFileSearch) { + results = vc.getHandler().search(vc.fullName, _stringMatcher); + + // if at least one match found, then send back the remote file with matches + if (results != null && results.length > 0) { + convert(deObj, absPath, results); + deObj.setParent(_status); + _status.addNestedData(deObj, false); + } + } + // otherwise if it is a file search, return the remote file back with no children + else { + deObj.setParent(_status); + _status.addNestedData(deObj, false); + } + } + } + // otherwise, search the file + else { + + if (!isArchive) { + deObj = _dataStore.createObject(null, _deFile, compareStr); + } + else { + deObj = _dataStore.createObject(null, _deArchiveFile, compareStr); + } + + deObj.setAttribute(DE.A_VALUE, theFile.getParentFile().getAbsolutePath()); + deObj.setAttribute(DE.A_SOURCE, _miner.setProperties(theFile)); + + // if it is a file search, we send the remote file back + // otherwise search within the file and see if there is at least one match + if (_isFileSearch || internalSearchWithinFile(deObj, absPath, theFile)) { + deObj.setParent(_status); + _status.addNestedData(deObj, false); + } + } + + // do a refresh + _dataStore.refresh(_status, true); + } + + // if the depth is not 0, then we need to recursively search + if (depth != 0) { + + // if it is a directory, or an archive, or a virtual directory, then we need to get the + // children and search those + if (isDirectory || ((isArchive || isVirtualDirectory) && _searchString.isIncludeArchives())) + { + + if (!hasSearchedDirectory(theFile)) { + + _alreadySearched.add(theFile); + + File[] children = null; + + // if the file is an archive or a virtual directory, then get the children from + // the archive handler + if (isArchive || isVirtualDirectory) { + + AbsoluteVirtualPath avp = new AbsoluteVirtualPath(absPath); + File archive = new File(avp.getContainingArchiveString()); + String virtualPath = avp.getVirtualPart(); + + VirtualChild[] virtualchildren = null; + + try { + virtualchildren = ArchiveHandlerManager.getInstance().getContents(archive, virtualPath); + } + catch (IOException e) { + UniversalServerUtilities.logError(_miner.getName(), "Error occured trying to get the canonical file", e); + } + + if (virtualchildren != null) { + + children = new File[virtualchildren.length]; + + for (int i = 0; i < virtualchildren.length; i++) { + AbsoluteVirtualPath newAvp = new AbsoluteVirtualPath(absPath); + newAvp.setVirtualPart(virtualchildren[i].fullName); + children[i] = new File(newAvp.toString()); + } + + if (virtualchildren.length == 0) { + children = null; + } + } + } + // otherwise, get the list of children + else { + children = theFile.listFiles(); + } + + if (children != null) { + + for (int i = 0; i < children.length && !_isCancelled; i++) { + + File child = children[i]; + internalSearch(child, depth - 1); + } + } + } + } + } + } + + protected boolean internalSearchWithinFile(DataElement remoteFile, String absPath, File theFile) { + + // if search string is empty, no need to look for matches within file + if (_isFileSearch) { + return true; + } + + FileInputStream inputStream = null; + + try { + inputStream = new FileInputStream(theFile); + InputStreamReader reader = new InputStreamReader(inputStream); + BufferedReader bufReader = new BufferedReader(reader); + + SystemSearchStringMatchLocator locator = new SystemSearchStringMatchLocator(bufReader, _stringMatcher); + + SystemSearchLineMatch[] matches = locator.locateMatches(); + + boolean foundMatches = ((matches != null) && (matches.length > 0)); + + if (foundMatches) { + convert(remoteFile, absPath, matches); + } + + return foundMatches; + } + catch (Exception e) { + UniversalServerUtilities.logError(_miner.getName(), "Error occured when trying to locate matches", e); + remoteFile.setAttribute(DE.A_VALUE, e.getMessage()); + return false; + } + } + + protected boolean doesFilePatternMatch(String compareStr) { + return _fileNameMatcher.matches(compareStr); + } + + /** + * Returns whether classification matches. + * @param absolutePath the absolute path of the file for which we want to check classification. + * @return true if the classification matches, false otherwise. + */ + protected boolean doesClassificationMatch(String absolutePath) { + + if (_classificationString == null || _classificationString.equals("")) { + return true; + } + else { + String classification = SystemFileClassifier.getInstance().classifyFile(absolutePath); + return StringCompare.compare(_classificationString, classification, true); + } + } + + /** + * Converts from system line matches to data elements that will be sent back. + * @param deObj the element representing the file for which matches have been found. + * @param absPath the absolute path of the file. + * @param lineMatches an array of line matches, or empty if no matches. + */ + protected void convert(DataElement deObj, String absPath, SystemSearchLineMatch[] lineMatches) { + + SystemSearchLineMatch match = null; + + for (int i = 0; i < lineMatches.length; i++) { + match = lineMatches[i]; + DataElement obj = _dataStore.createObject(deObj, _deGrep, match.getLine(), absPath); + obj.setAttribute(DE.A_SOURCE, obj.getSource() + ':'+ match.getLineNumber()); + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/processes/IUniversalProcessDataStoreConstants.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/processes/IUniversalProcessDataStoreConstants.java new file mode 100644 index 00000000000..ca1821a5faf --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/processes/IUniversalProcessDataStoreConstants.java @@ -0,0 +1,41 @@ +/******************************************************************************** + * Copyright (c) 2005, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.processes; + +public interface IUniversalProcessDataStoreConstants +{ + + /* + * Miner name, used for logging + */ + public static final String UNIVERSAL_PROCESS_MINER = "UniversalProcessMiner"; + + // + // Universal Process descriptors for DataStore DataElements + // + public static final String UNIVERSAL_PROCESS_ROOT = "universal.process.root"; + public static final String UNIVERSAL_PROCESS_FILTER = "universal.process.filter"; + public static final String UNIVERSAL_PROCESS_DESCRIPTOR = "universal.process.descriptor"; + + // + // Universal Process Miner Commands + // + public static final String C_PROCESS_FILTER_QUERY_ALL = "C_PROCESS_FILTER_QUERY_ALL"; + public static final String C_PROCESS_KILL = "C_PROCESS_KILL"; + public static final String C_PROCESS_QUERY_ALL_PROPERTIES = "C_PROCESS_QUERY_ALL_PROPERTIES"; + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/processes/ProcessDEComparator.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/processes/ProcessDEComparator.java new file mode 100644 index 00000000000..1049033316c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/processes/ProcessDEComparator.java @@ -0,0 +1,57 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.processes; + +import java.util.Comparator; + +import org.eclipse.dstore.core.model.DataElement; + +/** + * Compares two DataElements representing processes by extracting + * their PID's and comparing numerically based on the PID's. + * @author mjberger + * + */ +public class ProcessDEComparator implements Comparator +{ + public ProcessDEComparator() + { + } + + public int compare(Object obj1, Object obj2) + { + DataElement de1 = (DataElement) obj1; + DataElement de2 = (DataElement) obj2; + long pid1 = 0; + long pid2 = 0; + try + { + pid1 = Long.parseLong(de1.getName()); + pid2 = Long.parseLong(de2.getName()); + } + catch (NumberFormatException e) + { + return de1.toString().compareTo(de2.toString()); + } + return (int) (pid1 - pid2); + } + + public boolean equals(Object obj) + { + return this.equals(obj); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/processes/UniversalProcessMiner.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/processes/UniversalProcessMiner.java new file mode 100644 index 00000000000..51d9a8cd93f --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/processes/UniversalProcessMiner.java @@ -0,0 +1,397 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.dstore.universal.miners.processes; + + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.eclipse.dstore.core.miners.miner.Miner; +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.dstore.universal.miners.UniversalServerUtilities; +import org.eclipse.rse.services.clientserver.processes.HostProcessFilterImpl; +import org.eclipse.rse.services.clientserver.processes.IHostProcess; +import org.eclipse.rse.services.clientserver.processes.ISystemProcessRemoteConstants; +import org.eclipse.rse.services.clientserver.processes.handlers.IRemoteServerProcess; +import org.eclipse.rse.services.clientserver.processes.handlers.ProcessComparator; +import org.eclipse.rse.services.clientserver.processes.handlers.ProcessHandler; +import org.eclipse.rse.services.clientserver.processes.handlers.ProcessHandlerManager; +import org.eclipse.rse.services.clientserver.processes.handlers.UniversalServerProcessImpl; + +/** + * Miner for getting process information from a remote system. + * @author mjberger + */ +public class UniversalProcessMiner extends Miner implements IUniversalProcessDataStoreConstants, IUniversalDataStoreConstants, ISystemProcessRemoteConstants +{ + + public static final String MINER_ID = UniversalProcessMiner.class.getName(); + + private ProcessHandler handler; + + private static final String _minerVersion = "7.0.0"; + + private DataElement deUniversalProcessObject, deUniversalProcessFilter, deKillInfoNode; + private ProcessDEComparator _processDEcomparator; + + public UniversalProcessMiner() + { + handler = ProcessHandlerManager.getInstance().getNewProcessHandler(); + } + + private ProcessDEComparator getProcessDEComparator() + { + if (_processDEcomparator == null) + { + try + { + _processDEcomparator = new ProcessDEComparator(); + } + catch (Exception e) + { + e.printStackTrace(); + } + catch (Error err) + { + err.printStackTrace(); + } + + } + return _processDEcomparator; + } + + public DataElement handleCommand(DataElement theCommand) + { + String name = getCommandName(theCommand); + DataElement status = getCommandStatus(theCommand); + DataElement subject = getCommandArgument(theCommand, 0); + + //UniversalServerUtilities.logInfo(getMinerName(), name + ":" + subject); + + if (subject == null) { + + UniversalServerUtilities.logError(UNIVERSAL_PROCESS_MINER, "Subject for UniversalProcessMiner command " + name + " is null", null); + status.setAttribute(DE.A_NAME, "done"); + return status; + } + + String subjectType = (String) subject.getElementProperty(DE.P_TYPE); + + if (subjectType.equals(UNIVERSAL_PROCESS_FILTER)) + { + if (name.equals(C_PROCESS_FILTER_QUERY_ALL)) + { + status = handleQuery(subject, status); + } + else + { + UniversalServerUtilities.logError(UNIVERSAL_PROCESS_MINER, "Unknown filter command: " + name, null); + status.setAttribute(DE.A_NAME, "done"); + } + } + else if (subjectType.equals(UNIVERSAL_PROCESS_DESCRIPTOR)) + { + if (name.equals(C_PROCESS_QUERY_ALL_PROPERTIES)) + { + handleQueryJobAllProperties(subject, status); + } + else if (name.equals(C_PROCESS_KILL)) + { + status = handleKill(subject, status); + } + else + { + UniversalServerUtilities.logError(UNIVERSAL_PROCESS_MINER, "Unsupported process command: " + name, null); + status.setAttribute(DE.A_NAME, "done"); + } + } + else + { + UniversalServerUtilities.logError(UNIVERSAL_PROCESS_MINER, "Unsupported subject for command: " + subject, null); + status.setAttribute(DE.A_NAME, "done"); + } + + return status; + } + + public void extendSchema(DataElement schemaRoot) + { + + // define process descriptors + deUniversalProcessFilter = createObjectDescriptor(schemaRoot, + UNIVERSAL_PROCESS_FILTER); + deUniversalProcessObject = createObjectDescriptor(schemaRoot, + UNIVERSAL_PROCESS_DESCRIPTOR); + + // define command descriptors + createCommandDescriptor(deUniversalProcessFilter, "Filter", C_PROCESS_FILTER_QUERY_ALL); + createCommandDescriptor(deUniversalProcessObject, "Kill", C_PROCESS_KILL); + createCommandDescriptor(deUniversalProcessObject, "ProcessQueryAllProperties", C_PROCESS_QUERY_ALL_PROPERTIES); + + _dataStore.refresh(schemaRoot); + } + + public void load() + { + deKillInfoNode = _dataStore.createObject(_minerData, UNIVERSAL_NODE_DESCRIPTOR, "universal.killinfo"); + deKillInfoNode.setAttribute(DE.A_VALUE, getSignalTypes()); + _dataStore.refresh(_minerData); + + } + + /** + * @return a String with a list of signal types that can be sent to processes on this + * system, separated by newline characters. + */ + protected String getSignalTypes() + { + try + { + Process kill = Runtime.getRuntime().exec("kill -l"); + InputStreamReader isr = new InputStreamReader(kill.getInputStream()); + if (isr == null) return ""; + BufferedReader reader = new BufferedReader(isr); + if (reader == null) return ""; + String nextLine = reader.readLine(); + String output = ""; + while (nextLine != null) + { + output = output + nextLine + "\n"; + nextLine = reader.readLine(); + } + reader.close(); + isr.close(); + return output; + } + catch (Exception e) + { + return ""; + } + } + + /** + * Handle process queries + */ + private DataElement handleQuery(DataElement subject, DataElement status) + { + try + { + HostProcessFilterImpl pfs = new HostProcessFilterImpl(subject.getSource()); + lookupProcesses(pfs, subject); + } catch (Exception e) { + e.printStackTrace(); + UniversalServerUtilities.logError("UniversalProcessMiner", "handleQuery()", e); + status.setAttribute(DE.A_VALUE, e.getMessage()); + status.setAttribute(DE.A_NAME, "done"); + _dataStore.refresh(status); + return status; + } + + _dataStore.refresh(subject); + status.setAttribute(DE.A_NAME, "done"); + status.setAttribute(DE.A_VALUE, PROCESS_MINER_SUCCESS); + + return status; + } + + private void lookupProcesses(HostProcessFilterImpl fsObj, DataElement subject) throws Exception + { + // we need to synchronize the list of data elements with the fresh + // results coming back from the query + if (handler == null) throw new Exception(PROCESS_MINER_ERROR_NO_HANDLER); + SortedSet processes = handler.lookupProcesses(fsObj); + SortedSet sortedDEs = null; + // sort the data elements + List nested = subject.getNestedData(); + if (nested != null) + { + Object[] oldDEs = nested.toArray(); + if (oldDEs != null && oldDEs.length > 0) + { + sortedDEs = new TreeSet(getProcessDEComparator()); + for (int i = 0; i < oldDEs.length; i++) + { + if (fsObj.allows(((DataElement)oldDEs[i]).getValue())) + sortedDEs.add(oldDEs[i]); + } + } + } + + // take care of the special cases where one of the lists has no + // elements + if (processes == null || processes.size() == 0) + { + deleteDataElements(fsObj, subject); + return; + } + if (sortedDEs == null || sortedDEs.size() == 0) + { + createDataElements(processes.toArray(), subject); + return; + } + + // now we merge the lists + Iterator pIter = processes.iterator(); + Iterator deIter = sortedDEs.iterator(); + + DataElement nextDE = null; + IRemoteServerProcess nextP = null; + IRemoteServerProcess nextDEP = null; + try + { + // pop the first two elements off the lists + ProcessComparator comparator = new ProcessComparator(); + nextDE = (DataElement) deIter.next(); + nextDEP = new UniversalServerProcessImpl(nextDE.getValue()); + nextP = (IRemoteServerProcess) pIter.next(); + do + { + // compare the pid's of the elements + int comparison = comparator.compare(nextDEP, nextP); + + // data element exists in datastore but no longer returned in query, + // so delete it, and pop it off the list + if (comparison < 0) + { + _dataStore.deleteObject(subject, nextDE); + deIter.remove(); + nextDE = (DataElement) deIter.next(); + nextDEP = new UniversalServerProcessImpl(nextDE.getValue()); + + } + + // data element exists in both the query and datastore, so refresh its properties + // and then pop both top items off their lists + if (comparison == 0) + { + nextDE.setAttribute(DE.A_VALUE, nextP.getAllProperties()); + deIter.remove(); + pIter.remove(); + nextDE = (DataElement) deIter.next(); + nextDEP = new UniversalServerProcessImpl(nextDE.getValue()); + nextP = (IRemoteServerProcess) pIter.next(); + } + + // data element does not exist in the data store, so create it + if (comparison > 0) + { + createDataElement(nextP, subject); + pIter.remove(); + nextP = (IRemoteServerProcess) pIter.next(); + } + } + while(true); + } + catch (NoSuchElementException e) // we have reached the tail of one of the lists, add or delete the rest + { + if (!pIter.hasNext() && !deIter.hasNext()) return; + if (deIter.hasNext()) deleteRemainingElements(deIter, subject); + else createDataElements(processes.toArray(), subject); + } + } + + private void deleteRemainingElements(Iterator iter, DataElement subject) + { + while (iter.hasNext()) + { + DataElement next = (DataElement) iter.next(); + _dataStore.deleteObject(subject, next); + } + } + + private void deleteDataElements(HostProcessFilterImpl fsObj, DataElement subject) + { + List nested = subject.getNestedData(); + if (nested != null) + { + Object[] oldDEs = nested.toArray(); + if (oldDEs == null || oldDEs.length == 0) return; + for (int i = 0; i < oldDEs.length; i++) + { + DataElement currentDE = (DataElement) oldDEs[i]; + if (fsObj.allows(currentDE.getValue())) + _dataStore.deleteObject(subject, currentDE); + } + } + } + + private void createDataElements(Object[] processes, DataElement subject) + { + if (processes == null || processes.length == 0) return; + for (int i = 0; i < processes.length; i++) + { + createDataElement((IRemoteServerProcess)processes[i], subject); + } + } + + private void createDataElement(IRemoteServerProcess process, DataElement subject) + { + DataElement dsObj = null; + dsObj = _dataStore.createObject(subject, deUniversalProcessObject, "" + process.getPid()); + dsObj.setAttribute(DE.A_VALUE, process.getAllProperties()); + } + /** + * Query all properties of the process. + */ + private void handleQueryJobAllProperties(DataElement subject, DataElement status) + { + } + + /** + * Kill a process. + */ + private DataElement handleKill(DataElement subject, DataElement status) + { + try + { + String statusLine = subject.getValue(); + UniversalServerProcessImpl usp = new UniversalServerProcessImpl(statusLine); + if (handler == null) throw new Exception(PROCESS_MINER_ERROR_NO_HANDLER); + IHostProcess result = handler.kill(usp, subject.getSource()); + + if (result == null) _dataStore.deleteObject(subject.getParent(), subject); + else + { + subject.setAttribute(DE.A_SOURCE, ""); + subject.setAttribute(DE.A_VALUE, result.getAllProperties()); + } + } catch (Exception e) { + UniversalServerUtilities.logError("UniversalProcessMiner", "handleQuery()", e); + status.setAttribute(DE.A_VALUE, e.getMessage()); + status.setAttribute(DE.A_NAME, "done"); + _dataStore.refresh(status); + return status; + } + + _dataStore.refresh(subject.getParent()); + status.setAttribute(DE.A_NAME, "done"); + status.setAttribute(DE.A_VALUE, PROCESS_MINER_SUCCESS); + return status; + } + + public String getVersion() + { + return _minerVersion; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/plugin.properties b/rse/plugins/org.eclipse.rse.services.dstore/plugin.properties new file mode 100644 index 00000000000..ff0b04b8e05 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/plugin.properties @@ -0,0 +1,12 @@ +############################################################################### +# Copyright (c) 2000, 2006 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 +############################################################################### + +plugin.name = RSE Dstore Services \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/.cvsignore b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/.cvsignore new file mode 100644 index 00000000000..30b512fb73c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/.cvsignore @@ -0,0 +1 @@ +rseserver.jar diff --git a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/auth.pl b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/auth.pl new file mode 100644 index 00000000000..77eb0955449 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/auth.pl @@ -0,0 +1,57 @@ +#!/usr/bin/perl -w + +use Shell; + +if (!defined($ARGV[0]) || !defined($ARGV[1]) || !defined($ARGV[2]) || !defined($ARGV[3]) || !defined($ARGV[4])) +{ + print("command usage:\n"); + print("auth.pl USER, PATH, PORT, TIMEOUT, TICKET\n"); +} +else +{ + $userIN = $ARGV[0]; + $pathIN = $ARGV[1]; + $portIN = $ARGV[2]; + $timeoutIN = $ARGV[3]; + $ticketIN = $ARGV[4]; + + $pwdIN = ; + chomp($pwdIN); + + + @passwdStruct = getpwnam($userIN); + + if (@passwdStruct == 0) + { + print("invalid user name\n"); + 0; + } + else + { + $passwd=$passwdStruct[1]; + $encryptedPWD = crypt($pwdIN, $passwd); + $classpath=$ENV{CLASSPATH}; + $suOptions="-lp"; + + if ($passwd eq $encryptedPWD) + { + print("success\n"); + + $os = uname(); + chomp($os); + + if (lc($os) eq "aix") + { + $suOptions="-"; + } + + system("su $suOptions $userIN -c 'java -cp $classpath -DA_PLUGIN_PATH=$pathIN com.ibm.etools.systems.dstore.core.server.Server $portIN $timeoutIN $ticketIN'"); + 1; + } + else + { + print("incorrect password\n"); + 0; + } + } +} diff --git a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/daemon.linux b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/daemon.linux new file mode 100644 index 00000000000..5f23205ad3b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/daemon.linux @@ -0,0 +1,44 @@ +#!/usr/bin/perl -w + + +$port = "4800"; +$helpFlag = "-h"; + +if (defined($ARGV[0])) +{ + $port = $ARGV[0]; +} + + +$isHelp = $helpFlag cmp $port; +if ($isHelp == 0) +{ + print("command usage:\n"); + print("daemon.linux [ | -]\n"); + 0; +} +else +{ + $trace = $ENV{DSTORE_TRACING_ON}; + $user=`whoami`; chomp($user); + $match = $user cmp "root"; + + if ($match != 0) + { + print("To run the server daemon, you must be root\n"); + 0; + } + else + { + $dir= $ENV{PWD}; + $plugins_dir=$dir; + + $ENV{A_PLUGIN_PATH}="$plugins_dir/"; + + $oldClasspath = $ENV{CLASSPATH}; + + $ENV{"CLASSPATH"}="$plugins_dir:$plugins_dir/dstore_extra_server.jar:$plugins_dir/dstore_core.jar:$plugins_dir/dstore_miners.jar:$plugins_dir/clientserver.jar:$oldClasspath"; + + system("java -DA_PLUGIN_PATH=\$A_PLUGIN_PATH -DDSTORE_TRACING_ON=$trace org.eclipse.dstore.core.server.ServerLauncher $port"); + } +} diff --git a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/daemon.unix b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/daemon.unix new file mode 100644 index 00000000000..cc3efd9c10d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/daemon.unix @@ -0,0 +1,42 @@ +#!/usr/bin/perl + + + +if (defined($ARGV[0])) +{ + $port = $ARGV[0]; +} +else +{ + $port = "4035"; +} + +#$user = $ENV{USER}; + +$trace = $ENV{DSTORE_TRACING_ON}; +$user=`whoami`; chomp($user); +$match = $user cmp "root"; + +if ($match != 0) +{ + print("To run the server daemon, you must be root\n"); + 0; +} +else +{ + $dir= $ENV{PWD}; + + $plugins_dir=$dir; + + $ENV{A_PLUGIN_PATH}="$plugins_dir/"; + + $oldClasspath = $ENV{CLASSPATH}; + + $ENV{"CLASSPATH"}="$plugins_dir:$plugins_dir/dstore_extra_server.jar:$plugins_dir/dstore_core.jar:$plugins_dir/dstore_miners.jar:$plugins_dir/universalminers.jar:$plugins_dir/clientserver.jar:$oldClasspath"; + + + + system("java -DA_PLUGIN_PATH=\$A_PLUGIN_PATH -DDSTORE_TRACING_ON=$trace com.ibm.etools.systems.dstore.core.server.ServerLauncher $port"); + $ENV{CLASSPATH}=$oldClasspath; + +} diff --git a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/daemon.win.bat b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/daemon.win.bat new file mode 100644 index 00000000000..f2a3584097a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/daemon.win.bat @@ -0,0 +1,2 @@ +java -DA_PLUGIN_PATH=%A_PLUGIN_PATH% com.ibm.etools.systems.dstore.core.server.ServerLauncher + diff --git a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/minerFile.dat b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/minerFile.dat new file mode 100644 index 00000000000..3fc1668ea2b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/minerFile.dat @@ -0,0 +1,4 @@ +org.eclipse.rse.dstore.universal.miners.command.CommandMiner +org.eclipse.rse.dstore.universal.miners.filesystem.UniversalFileSystemMiner +org.eclipse.rse.dstore.universal.miners.environment.EnvironmentMiner +org.eclipse.rse.dstore.universal.miners.processes.UniversalProcessMiner diff --git a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/patterns.dat b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/patterns.dat new file mode 100644 index 00000000000..a6cda3b70ae --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/patterns.dat @@ -0,0 +1,269 @@ +# +# parse command line output. +# +# CLICK THIS LINE TO EDIT THIS FILE (PATTERNS.DAT). (When viewing from the Output view) + +command: grep -n.* + grep file line pattern =([\w,.,/,(,),\\,\-,\+,\d]*):(\d*):.* + +command: grep -.*n.* + grep file line pattern =([\w,.,/,(,),\\,\-,\+,\d]*):(\d*):.* + +command: grep .* + grep file pattern =([\w,.,/,(,)\\,\-,\+,\d]*):.* + + +command: pwd + directory file pattern=([\w,.,/,(,),\\,\-,\+,\d,:]*) + +command: nmake.* + error pattern=NMAKE : .* + error file line pattern =([\w,.,\-,\+,(,),\\,:]*)\((\d*):(\d*)\) : error EDC.* + error file pattern =[\w,.,\-,\+,(,),\\,:]*\(([\w,.,/,\\]*)\) : error LNK.* + error file line pattern=([\w,.,/,\-,\+,(,),\\]*):(\d*):\d*\) : error .* + warning file line pattern=([\w,.,/,\-,\+,(,),\\]*)\((\d*):\d*\) : warning .* + informational file line pattern=([\w,.,/,\-,\+,(,),\\]*)\((\d*):\d*\) : informational .* + +command: make.* + error file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(S\).* + error file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\",, line (\d*)\.\d*: \d*-\d* \(E\).* + warning file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(W\).* + informational file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(I\).* + warning file line pattern =([\w,.,/,(,),\-,\+,\\]*):(\d*): warning: .* + warning file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*):\d*: warning: .* + error file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*):.* + informational file pattern =([\w,.,/,\\,\-,\+,(,)]*):.* + informational file line pattern =In file included from ([\w,.,/,\\,\-,\+,(,)]*):(\d*): + #iseries c compiler + error file line pattern=[\w,.,/,\\]* Line \d* \"([\w,.,/,\\]*)\", line (\d*)\.\d*: .* + error file line pattern=([\w,.,/,\\]*) Line (\d*)\s.* + #makefile errors + error file line pattern=\"([\w,\.,/,(,),\-,\+,\\]*)\", line (\d*): make:.* + #xlc Options warnings + warning pattern=\(W\) Option .* + #c89 errors + error file line pattern=ERROR CBC\d* ([\w,.,/,\\,\-,\+,(,)]*):(\d*) .* + warning file line pattern=WARNING CBC\d* ([\w,.,/,\\,\-,\+,(,)]*):(\d*) .* + informational pattern=CBC\d*\(I\) .* + +command: gmake.* + error file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(S\).* + warning file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(W\).* + informational file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(I\).* + warning file line pattern =([\w,.,/,(,),\-,\+,\\]*):(\d*): warning: .* + warning file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*):\d*: warning: .* + informational file line pattern =In file included from ([\w,.,/,\\,\-,\+,(,)]*):(\d*): + # ixlc compiler + error file line pattern=[\w,.,/,\\]* Line \d* \"([\w,.,/,\\]*)\", line (\d*)\.\d*: .* + error file line pattern=([\w,.,/,\\]*) Line (\d*)\s.* + # icc compiler + error file line pattern =([\w,.,/,\\,\-,\+,(,)]*),\s(\d*)\.\d*:\s.* + error file line pattern =\"([\w,.,/,\\,\-,\+,(,)]*)\",\sline\s(\d*)\.\d*:\s.* + #generic + error file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*):.* + +command: gcc\s.* + error file line pattern=\"([\w,.,/,\\,\-,\+,(,)]*)\", line (\d*)\.\d*: \d*-\d* \(S\).* + warning file line pattern=\"([\w,.,/,\\,\-,\+,(,)]*)\", line (\d*)\.\d*: \d*-\d* \(W\).* + informational file line pattern=\"([\w,.,/,\\,\-,\+,(,)]*)\", line (\d*)\.\d*: \d*-\d* \(I\).* + warning file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*): warning: .* + warning file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*):\d*: warning: .* + error file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*):.* + informational file pattern =([\w,.,/,\\,\-,\+,(,)]*):.* + informational file line pattern =In file included from ([\w,.,/,\\,\-,\+,(,)]*):(\d*): + +command: cc\s.* + error file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*):.* + +command: CC\s.* + error file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*):.* + +command: c89.* + error file line pattern=ERROR CBC\d* ([\w,.,/,\\,\-,\+,(,)]*):(\d*) .* + warning file line pattern=WARNING CBC\d* ([\w,.,/,\\,\-,\+,(,)]*):(\d*) .* + informational pattern=CBC\d*\(I\) .* + +command: icc.* + error file line pattern =([\w,.,/,\\,\-,\+,(,)]*),\s(\d*)\.\d*:\s.* + error file line pattern =\"([\w,.,/,\\,\-,\+,(,)]*)\",\sline\s(\d*)\.\d*:\s.* + +command: javac.* + warning file line pattern=([\w,.,/,\\,\-,\+,(,),:]*):(\d*): warning.* + error file line pattern=([\w,.,/,\\,\-,\+,(,),:]*):(\d*):.* + +command: .*bat\s.* + error file line pattern=\[javac\]\s([\w,.,/,\\,:]*):(\d*):.* + error file line pattern=file:([\w,.,/,\\,:]*):(\d*):.* + +command: dir.* + directory file pattern=\d{2}/\d{2}/\d*\s\d{2}:\d{2}[a,p,AM,PM,\s].*\s*\s*([\w,.,/,\\,\s,\-,\+\+,\d]*).* + file file pattern=\d{2}/\d{2}/\d*\s\d{2}:\d{2}[a,p,AM,PM,\s].*\s*[\d,,]* ([\w,.,/,\\,\s,\-,\+\+,\d]*).* + directory file pattern=[\d,/,\\,.,-]+.\s*\d{2}[:,.]\d{2}.\s*\s*([\w,.,/,\\,\s,\-,\+\+,\d]*) + file file pattern=[\d,/,\\,.,-]+.\s*\d{2}[:,.]\d{2}.\s*[\d,,,.]*\s*([\w,.,/,\\,\s,\-,\+\+,\d]*) + +command: ls -l.* + file file pattern=-[-,r,w,x]+\s.*\s[\d{4},\d{2}:\d{2}]+,\s([\w,.,/,(,),\\,\-,\+\s,\d]*) + file file pattern=l[-,r,w,x]+\s.*\s[\d{4},\d{2}:\d{2}]+,\s([\w,.,/,(,),\\,\-,\+\s,\d]*)\s->\s[\w,.,/,(,),\\,\-,\+\s,\d]* + file file pattern=-.*\d{2}:\d{2} ([\w,.,/,(,),\\,\-,\+,\s,\d]*) + file file pattern=-.* \d{4} ([\w,.,/,(,),\\,\-,\+,\s,\d]*) + file file pattern=l.*\d{2}:\d{2} ([\w,.,/,(,),\\,\-,\+,\s,\d]*)\s->\s[\w,.,/,(,),\\,\-,\+\s,\d]* + file file pattern=l.* \d{4} ([\w,.,/,(,),\\,\-,\+,\s,\d]*)\s->\s[\w,.,/,(,),\\,\-,\+\s,\d]* + directory file pattern=d.*\d{2}:\d{2} ([\w,.,/,(,),\\,\-,\+\s,\d]*) + directory file pattern=d.*\d{4} ([\w,.,/,(,),\\,\-,\+,\s,\d]*) + +command: ls -a.* + file file pattern=-.*\d{2}:\d{2} ([\w,.,/,(,),\\,\-,\+\s,\d]*) + file file pattern=-.* \d{4} ([\w,.,/,(,),\\,\-,\+\s,\d]*) + directory file pattern=d.*\d{2}:\d{2} ([\w,.,/,(,),\\,\-,\+\s,\d]*) + directory file pattern=d.*\d{4} ([\w,.,/,(,),\\,\-,\+\s,\d]*) + +command: ls + file file pattern=([\w,\d,.,(,),\-,\+\s]+) + +command: ls\s.* + file file pattern=([\w,\d,.,(,),\-,\+\s]+) + +command: .* + prompt file pattern=([\w,.,/,(,),\\,\-,\+,\d,:,\s]*)>.* + +command: find .* + file file pattern=([\w,.,/,\\,(,),\-]+) + +command: env + pathenvvar file pattern=PATH\=(.*) + libpathenvvar file pattern=LIBPATH\=(.*) + libpathenvvar file pattern=LIB\=(.*) + envvar pattern=[\w\d]+\=.* + +command: ps + process pattern=[\s]*[\d]+\s.* + +command: ps .* + process pattern=[\s]*[\d]+\s.* + +command: xl[C,c].* + error file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\",, line (\d*)\.\d*: \d*-\d* \(S\).* + error file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(E\).* + warning file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(W\).* + informational file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(I\).* + +command: ixlc.* + error file line pattern=([\w,.,/,\\]*) Line (\d*)\s.* + error file line pattern=[\w,.,/,\\]* Line \d* \"([\w,.,/,\\]*)\", line (\d*)\.\d*: .* + +command: cat.*patterns.* + warning file pattern=# .*(PATTERNS.DAT).* + Output pattern=command: .* + #statement pattern=#.* + statement pattern=.* pattern.*=.* + +# special for autoconf +command: ./bootstrap.sc.* + error file line pattern=aclocal: ([\w,.,/,\\]*): (\d*):.* + warning file line pattern=([\w,.,/,\\]*):(\d*):.* + +command: ./configure.* + error file line pattern=./(configure): line (\d*): .* + +# How Patterns Work +# ----------------- +# +# Patterns are used by the Output View to allow lines that contain file names and +# perhaps line numbers to be clicked to cause the file location to be opened in an Editor. +# A line in this file can be 1 of 3 things: +# 1. An empty line or a comment line (denoted by a # in column 1) +# 2. The start of a command description (denoted by a 'command:' at the beginning of the line) +# 3. A pattern description. +# A formal description of the syntax of this file is included at the bottom of this file. +# +# +# Command Descriptions +# -------------------- +# +# A Command Description consists of 2 things: A regular expression that describes the +# command invocation, and a list of Pattern Descriptions. The regular expression +# is used to determine what set of Pattern Descriptons to use when parsing command output. +# For example, if you type the command 'gmake clean', the Command Descriptions are checked and +# .*make.* would match that command. Therefore the Pattern Descriptions for .*make.* would +# be used to parse the output of the 'gmake clean'. +# Note: The first Command Description that is found to match the command is used, so make +# sure you put the most specific patterns first. For example, if the nmake.* Command +# Description appeared after .*make.*, then 'nmake install' would be matched by the .*make.* +# Command Descripton, which is probably not what was intended. +# +# +# Pattern Descriptions +# -------------------- +# +# A Pattern Description has the following form: +# "pattern=" +# +# where: +# : The type of object that will be created in the Output View if +# a line of output matches this pattern. If you have put an +# icon called ".gif" in the com.ibm.etools.systems.dstore.core/icons +# directory, then the icon will be displayed in the view. +# +# : This is some combination of the words "file" and "line" or nothing +# at all. This is used to define how the backreferences in the +# regular expression are to be interpreted. So "file line" means +# that the first back-reference is a file, and the second is a +# line number. This may seem unnecessary, but we added this capability +# in the event that future releases support other types of information +# that may be useful, such as column info (once we support it). +# +# : A regular expression that describes a line of output. Backreferences +# are used to store (instead of just match) the filename and line +# number. To store a filename use the backreference ([\w,.,/,\\]*), and +# to store a line number, use (\d*) +# +# +# Note: The patterns are checked against command output and only exact matches are dealt with +# So as an example, if you forget the .* (match everything) at the end of a pattern, +# the match will fail if there are trailing characters in the output not accounted for by +# the pattern +# +# +# Pattern File Syntax +# ------------------- +# +# The pattern file syntax should be easy to grasp by looking at the ones +# above, but for those of you who like formal grammars, here it is: +# +# patterns-file: +# commands +# +# commands: +# command +# commands new-line command +# +# command: +# "command:" reg-ex new-line patterns +# +# patterns: +# pattern +# patterns new-line pattern +# +# pattern: +# command-name match-list "pattern=" reg-ex +# +# command-name: +# String that denotes what type of object will be created if some output matches this pattern +# +# match-list: +# file-or-line +# match-list space file-or-line +# +# file-or-line: +# "file" | "line" +# +# reg-ex: +# A regular expression +# +# new-line: +# The new-line character \n +# +# space: +# The space character + + diff --git a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/rsecomm.properties b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/rsecomm.properties new file mode 100644 index 00000000000..8abced9e119 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/rsecomm.properties @@ -0,0 +1,25 @@ +# +# +# + +# +# server.version - DO NOT MODIFY! +# +server.version=5.0.0 + +# +# Logging level +# 0 - Log error messages +# 1 - Log error and warning messages +# 2 - Log error, warning and info messages +# 3 - Log error, warning, info and debug messages +# +debug_level=0 + +# +# Log location +# Log_To_StdOut +# Log_To_File +# +log_location=Log_To_File + diff --git a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/run.win.bat b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/run.win.bat new file mode 100644 index 00000000000..53eff1790ba --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/run.win.bat @@ -0,0 +1,27 @@ +echo off + +setlocal + +set PORT=%1 +set TIMEOUT=%2 +set TICKET=%3 + +if xxx%1 == xxx set PORT=4033 +if xxx%2 == xxx set TIMEOUT=120000 +if xxx%3 == xxx goto runNoTicket + +@echo on + +java -DA_PLUGIN_PATH=%A_PLUGIN_PATH% com.ibm.etools.systems.dstore.core.server.Server %PORT% %TIMEOUT% %TICKET% +goto done + +:runNoTicket +@echo on +java -DA_PLUGIN_PATH=%A_PLUGIN_PATH% com.ibm.etools.systems.dstore.core.server.Server %PORT% %TIMEOUT% +goto done + +:usage +@echo Usage: run.win ^ ^ + +:done +endlocal \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/server.aix b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/server.aix new file mode 100644 index 00000000000..b826194cceb --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/server.aix @@ -0,0 +1,7 @@ +# Shell script to starat RSE communications server +# This script will start the datastore listening on an available socket + +export serverpath=.; +export PATH=/usr/java131/jre/bin:$PATH +export CLASSPATH=/usr/java131/jre/lib/rt.jar:/usr/jdk_base/lib/classes.zip:$CLASSPATH +export CLASSPATH=.:dstore_extra_server.jar:dstore_core.jar:dstore_miners.jar:universalminers.jar:clientserver.jar:$CLASSPATH;java -DA_PLUGIN_PATH=$serverpath -DDSTORE_TRACING_ON=false com.ibm.etools.systems.dstore.core.server.Server 0 60000 & \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/server.linux b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/server.linux new file mode 100644 index 00000000000..6248deadd0d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/server.linux @@ -0,0 +1,41 @@ +#!/usr/bin/perl + +$port = $ARGV[0]; +$timeout = $ARGV[1]; +$packaged_as = $ARGV[2]; + + +$dir= $ENV{PWD}; +#print("path $dir"); + +#$plugins_dir=substr($dir,0,rindex($dir,"/")); +$plugins_dir=$dir; + +$ENV{A_PLUGIN_PATH}="$plugins_dir/"; + +$oldClasspath = $ENV{CLASSPATH}; + + +if ($packaged_as == "jar") +{ + $ENV{"CLASSPATH"}="$plugins_dir:$plugins_dir/dstore_extra_server.jar:$plugins_dir/dstore_core.jar:$plugins_dir/dstore_miners.jar:$plugins_dir/universalminers.jar:$plugins_dir/clientserver.jar:$oldClasspath"; +} +if ($packaged_as == "src") +{ + $ENV{"CLASSPATH"}="$plugins_dir:$oldClasspath"; +} +if (!defined($packaged_as)) +{ + $ENV{"CLASSPATH"}="$plugins_dir:$plugins_dir/dstore_extra_server.jar:$plugins_dir/dstore_core.jar:$plugins_dir/dstore_miners.jar:$plugins_dir/universalminers.jar:$plugins_dir/clientserver.jar:$oldClasspath"; +} + +if (!defined($timeout)) +{ + system("java -DA_PLUGIN_PATH=\$A_PLUGIN_PATH com.ibm.etools.systems.dstore.core.server.Server $port"); +} +else +{ + system("java -DA_PLUGIN_PATH=\$A_PLUGIN_PATH com.ibm.etools.systems.dstore.core.server.Server $port $timeout"); +} + +$ENV{CLASSPATH}=$oldClasspath; \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/server.unix b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/server.unix new file mode 100644 index 00000000000..8e485ee43b7 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/server.unix @@ -0,0 +1,5 @@ +# Shell script to starat RSE communications server +# This script will start the datastore listening on an available socket +export serverpath=.; +export CLASSPATH=.:dstore_extra_server.jar:dstore_core.jar:dstore_miners.jar:universalminers.jar:clientserver.jar:$CLASSPATH; +java -DA_PLUGIN_PATH=$serverpath -DDSTORE_TRACING_ON=false com.ibm.etools.systems.dstore.core.server.Server 0 60000 & diff --git a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/server.zseries b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/server.zseries new file mode 100644 index 00000000000..f616b86a4af --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/server.zseries @@ -0,0 +1,11 @@ +# +# Shell script to start RSE communications server +# This script will start the datastore listening on any socket +# that's available. +# +. setup.env.zseries +export serverpath=.; + +export CLASSPATH=.:dstore_extra_server.jar:dstore_core.jar:dstore_miners.jar:universalminers.jar:clientserver.jar:$CLASSPATH; + +java -DA_PLUGIN_PATH=$serverpath com.ibm.etools.systems.dstore.core.server.Server 0 60000 & diff --git a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/setup.env.zseries b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/setup.env.zseries new file mode 100644 index 00000000000..9e8c12b01ce --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/setup.env.zseries @@ -0,0 +1,14 @@ +# +# QShell script to start RSE communications server +# Usage: runServer portNumber socketTimeOut +# + +export JAVA_HOME=/sysroot/usr/lpp/java/IBM/J1.3 +SHELL=/bin/sh +TZ=EST5EDT +LANG=C +export PATH=$PATH:/bin:.:/usr/sbin:/sysroot/usr/lpp/internet/bin:/sysroot/usr/lpp/internet/sbin:$JAVA_HOME/bin:$JAVA_HOME/bin/ + +export _CEE_RUNOPTS="ALL31(ON) HEAP(32M,32K,ANYWHERE,KEEP)" + + diff --git a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/win.env.bat b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/win.env.bat new file mode 100644 index 00000000000..758e7699bc0 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/win.env.bat @@ -0,0 +1,8 @@ +set ECLIPSEDIR=. +set CORE=%ECLIPSEDIR%\dstore_core.jar +set MINERS=%ECLIPSEDIR%\dstore_miners.jar +set EXTRA=%ECLIPSEDIR%\dstore_extra_server.jar +set UNIVERSALJAR=%ECLIPSEDIR%\universalminers.jar +set CLIENTSERVER=%ECLIPSEDIR%\clientserver.jar +set A_PLUGIN_PATH=%ECLIPSEDIR% +set CLASSPATH=%CORE%;%MINERS%;%UNIVERSAL%;%UNIVERSALJAR%;%CLIENTSERVER%;%EXTRA%;%CLASSPATH% diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/internal/services/dstore/shell/DStoreShellOutputReader.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/internal/services/dstore/shell/DStoreShellOutputReader.java new file mode 100644 index 00000000000..d0d89450bbd --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/internal/services/dstore/shell/DStoreShellOutputReader.java @@ -0,0 +1,156 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.services.dstore.shell; + +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.extra.internal.extra.DomainEvent; +import org.eclipse.dstore.extra.internal.extra.IDomainListener; +import org.eclipse.rse.services.shells.AbstractHostShellOutputReader; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IHostShellOutputReader; + +public class DStoreShellOutputReader extends AbstractHostShellOutputReader implements IHostShellOutputReader, IDomainListener +{ + protected DataElement _status; + protected int _statusOffset = 0; + + public DStoreShellOutputReader(IHostShell hostShell, DataElement status, boolean isErrorReader) + { + super(hostShell, isErrorReader); + _status = status; + if (status != null) + { + _status.getDataStore().getDomainNotifier().addDomainListener(this); + } + } + + public String getWorkingDirectory() + { + String pwd = _status.getSource(); + return pwd; + } + + protected Object internalReadLine() + { + if (_status != null) + { + int newSize = _status.getNestedSize(); + while (newSize > _statusOffset) + { + DataElement line = _status.get(_statusOffset++); + + + + String type = line.getType(); + boolean isError = type.equals("error") || type.equals("stderr"); + if (_isErrorReader && isError) + { + return line; + } + else if (!_isErrorReader && !isError) + { + return line; + } + } + + + try + { + waitForResponse(); + return internalReadLine(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + return ""; + } + + public boolean listeningTo(DomainEvent e) + { + return e.getParent() == _status; + } + + public void domainChanged(DomainEvent event) + { + if (_status.getValue().equals("done")) + { + + if (_status == event.getParent()) + { + finish(); + } + } + else + { + // for now, this is pulled via internalReadLine() + notifyResponse(); + } + + } + + /** + * Causes the current thread to wait until this class request has been + * fulfilled. + */ + public synchronized void waitForResponse() + { + try + { + wait(); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } + + /** + * Causes all threads waiting for this class request to be filled + * to wake up. + */ + public synchronized void notifyResponse() + { + try + { + notifyAll(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + /* + private void handleInput() + { + // append new results to existing results + ArrayList results = _status.getNestedData(); + int totalSize = results.size(); + int currentSize = _linesOfOutput.size(); + + for (int loop = currentSize; loop < totalSize; loop++) + { + DataElement result = (DataElement) results.get(loop); + addLine(result.getName()); + } + } + */ + +} + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/internal/services/dstore/shell/DStoreShellThread.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/internal/services/dstore/shell/DStoreShellThread.java new file mode 100644 index 00000000000..e62152986d6 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/internal/services/dstore/shell/DStoreShellThread.java @@ -0,0 +1,264 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.services.dstore.shell; + +import java.io.File; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.core.model.DataStoreSchema; +import org.eclipse.rse.dstore.universal.miners.command.CommandMiner; +import org.eclipse.rse.dstore.universal.miners.environment.EnvironmentMiner; + + + +public class DStoreShellThread +{ + protected DataElement _runCmdDescriptor; + protected DataElement _runShellDescriptor; + protected DataElement _setEnvironmentDescriptor; + protected DataElement _sendInputDescriptor; + protected DataElement _cmdMinerElement; + protected DataElement _envMinerElement; + + private String _encoding; + private String _cwd; + private String[] _envVars; + private DataStore _dataStore; + private DataElement _status; + + /** + * @param cwd initial working directory + * @param invocation launch shell command + * @param encoding + * @param patterns patterns file for output interpretation + * @param envVars user and system environment variables to launch shell with + */ + public DStoreShellThread(DataStore dataStore, String cwd, String invocation, String encoding, String[] envVars) + { + super(); + _dataStore = dataStore; + _encoding = encoding; + _cwd = cwd; + _envVars = envVars; + init(); + } + + protected void init() + { + // make this subsystem a communications listener + DataElement contextDir = _dataStore.createObject(null, "directory", (new File(_cwd)).getName(), _cwd); + _dataStore.setObject(contextDir); + setRemoteEnvironment(contextDir); + + sendShellToMiner(contextDir); + } + + public DataElement getStatus() + { + return _status; + } + + protected void sendShellToMiner(DataElement contextDir) + { + DataElement cmdD = getRunShellDescriptor(contextDir); + + if (cmdD != null) + { + String encoding = _encoding; + if (encoding != null && encoding.length() > 0) + { + DataElement arg = _dataStore.createObject(null, "shell.encoding", encoding); + _status = _dataStore.command(cmdD, arg, contextDir); + } + else + { + _status = _dataStore.command(cmdD, contextDir); + } + } + } + + /** + * Set the environment variables for this connection. For universal this sets them in the + * DataStore tree. When a new shell is launched the environment variables are passed to the + * shell. + */ + public void setRemoteEnvironment(DataElement theObject) + { + + if (_envVars != null && _envVars.length > 0) + { + DataElement theEnvironment = _dataStore.createObject(null, "Environment Variable", theObject.getName()); + for (int i = 0; i < _envVars.length; i++) + { + String var = _envVars[i]; + _dataStore.createObject(theEnvironment, "Environment Variable", var, var); + } + + theEnvironment.setAttribute(DE.A_NAME, theObject.getId()); + DataElement contObj = _dataStore.findObjectDescriptor("Container Object"); + DataElement setD = getSetEnvironmentDescriptor(contObj); + if (setD != null) + { + _dataStore.command(setD, theEnvironment, theObject, false); + } + } + } + + + protected DataElement getRunCommandDescriptor(DataElement remoteObject) + { + if (_runCmdDescriptor == null || _dataStore != remoteObject.getDataStore()) + { + _runCmdDescriptor = _dataStore.localDescriptorQuery(remoteObject.getDescriptor(), getRunCommandId()); + } + return _runCmdDescriptor; + } + + protected DataElement getRunShellDescriptor(DataElement remoteObject) + { + if (_runShellDescriptor == null || _dataStore != remoteObject.getDataStore()) + { + _runShellDescriptor = _dataStore.localDescriptorQuery(remoteObject.getDescriptor(), getRunShellId(), 2); + } + return _runShellDescriptor; + } + + protected DataElement getSetEnvironmentDescriptor(DataElement remoteObject) + { + if (_setEnvironmentDescriptor == null || _dataStore != remoteObject.getDataStore()) + { + _setEnvironmentDescriptor = _dataStore.localDescriptorQuery(remoteObject.getDescriptor(), getSetEnvironmentId(), 2); + } + return _setEnvironmentDescriptor; + } + + + protected DataElement getSendInputDescriptor(DataElement remoteObject) + { + if (_sendInputDescriptor == null || _dataStore != remoteObject.getDataStore()) + { + _sendInputDescriptor = _dataStore.findCommandDescriptor(DataStoreSchema.C_SEND_INPUT); + } + + return _sendInputDescriptor; + } + + + protected DataElement getCmdSystemMinerElement() + { + + if (_cmdMinerElement == null || _cmdMinerElement.getDataStore() != _dataStore) + { + _cmdMinerElement = _dataStore.findMinerInformation(getCmdSystemMinerId()); + if (_cmdMinerElement == null) + { + _cmdMinerElement = _dataStore.findMinerInformation(getOldCmdSystemMinerId()); + } + } + return _cmdMinerElement; + } + + protected DataElement getEnvSystemMinerElement() + { + + if (_envMinerElement == null || _envMinerElement.getDataStore() != _dataStore) + { + _envMinerElement = _dataStore.findMinerInformation(getEnvSystemMinerId()); + + if (_envMinerElement == null) + { + _envMinerElement = _dataStore.findMinerInformation(getOldEnvSystemMinerId()); + } + } + return _envMinerElement; + } + + + protected String getCmdSystemMinerId() + { + return CommandMiner.MINER_ID; + } + + protected String getOldCmdSystemMinerId() + { + return "com.ibm.etools.systems.dstore.miners.command.CommandMiner"; + } + + protected String getEnvSystemMinerId() + { + return EnvironmentMiner.MINER_ID; + } + + protected String getRunShellId() + { + return "C_SHELL"; + } + + protected String getRunCommandId() + { + return "C_COMMAND"; + } + + protected String getSetEnvironmentId() + { + return "C_SET_ENVIRONMENT_VARIABLES"; + } + + protected String getOldEnvSystemMinerId() + { + return "com.ibm.etools.systems.dstore.miners.environment.EnvironmentMiner"; + } + + public void writeToShell(String command) + { + DataElement commandElement = _status.getParent(); + DataStore dataStore = commandElement.getDataStore(); + + if (command.equals("") || command.equals("#break")) + { + String cmd = command; + if (cmd.equals("")) + cmd = "#enter"; + DataElement commandDescriptor = getSendInputDescriptor(commandElement); + if (commandDescriptor != null) + { + DataElement in = dataStore.createObject(null, "input", cmd); + dataStore.command(commandDescriptor, in, commandElement); + } + } + else + { + String[] tokens = command.split("\n\r"); + for (int i = 0; i = 8) + { + String minerId = getMinerId(); + String message = SystemMessage.sub(ServiceResources.DStore_Service_ProgMon_Initializing_Message, "&1", minerId); + monitor.beginTask(message, IProgressMonitor.UNKNOWN); + DataStore ds = getDataStore(); + if (_minerElement == null || _minerElement.getDataStore() != ds) + { + if (ds != null) + { + _initializeStatus = ds.activateMiner(minerId); + /* + DStoreStatusMonitor smon = getStatusMonitor(ds); + try + { + smon.waitForUpdate(status, monitor, 50); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + + getMinerElement(); + */ + } + } + } + } + monitor.done(); + } + + protected abstract String getMinerId(); + + /** + * For now just a dummy method + * @param messageID + * @return + */ + public SystemMessage getMessage(String messageID) + { + return null; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/Activator.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/Activator.java new file mode 100644 index 00000000000..05d946aa179 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/Activator.java @@ -0,0 +1,70 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class Activator extends AbstractUIPlugin { + + //The shared instance. + private static Activator plugin; + + /** + * The constructor. + */ + public Activator() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static Activator getDefault() { + 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.services.files.dstore", path); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/IDStoreService.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/IDStoreService.java new file mode 100644 index 00000000000..b40706d26f6 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/IDStoreService.java @@ -0,0 +1,22 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore; + +public interface IDStoreService +{ + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/ServiceResources.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/ServiceResources.java new file mode 100644 index 00000000000..f8d2317400c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/ServiceResources.java @@ -0,0 +1,42 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore; + +import org.eclipse.osgi.util.NLS; + +public class ServiceResources extends NLS +{ + private static String BUNDLE_NAME = "org.eclipse.rse.services.dstore.ServiceResources";//$NON-NLS-1$ + + public static String DStore_Shell_Service_Label; + public static String DStore_Search_Service_Label; + public static String DStore_File_Service_Label; + public static String DStore_Process_Service_Label; + + public static String DStore_Shell_Service_Description; + public static String DStore_Search_Service_Description; + public static String DStore_File_Service_Description; + public static String DStore_Process_Service_Description; + + public static String DStore_Service_ProgMon_Initializing_Message; + public static String DStore_Service_Percent_Complete_Message; + + static { + // load message values from bundle file + NLS.initializeMessages(BUNDLE_NAME, ServiceResources.class); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/ServiceResources.properties b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/ServiceResources.properties new file mode 100644 index 00000000000..bcf29684cd9 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/ServiceResources.properties @@ -0,0 +1,30 @@ +################################################################################ +# Copyright (c) 2006 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: +# {Name} (company) - description of contribution. +################################################################################ + + + +DStore_Shell_Service_Label=DStore Shell Service +DStore_Search_Service_Label=DStore Search Service +DStore_File_Service_Label=DStore File Service +DStore_Process_Service_Label=DStore Process Service + +DStore_Service_ProgMon_Initializing_Message=Initializing &1... +DStore_Service_Percent_Complete_Message=&0 of &1 complete (&2) + +DStore_Shell_Service_Description=The DStore Shell Service uses the RSE DataStore to provide service for the Shells subsystem. It requires a DataStore server or daemon to be running on the host machine. +DStore_Search_Service_Description=The DStore Search Service uses the RSE DataStore to provide service for remote searches. It requires a DataStore server or daemon to be running on the host machine. +DStore_File_Service_Description=The DStore File Service uses the RSE DataStore to provide service for the Files subsystem. It requires a DataStore server or daemon to be running on the host machine. +DStore_Process_Service_Description=The DStore Process Service uses the RSE DataStore to provide service for the Processes subsystem. It requires a DataStore server or daemon to be running on the host machine. \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/files/DStoreFileService.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/files/DStoreFileService.java new file mode 100644 index 00000000000..17ee7559d71 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/files/DStoreFileService.java @@ -0,0 +1,1166 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore.files; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.core.model.DataStoreAttributes; +import org.eclipse.dstore.core.model.DataStoreResources; +import org.eclipse.dstore.core.model.IDataStoreProvider; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.dstore.universal.miners.filesystem.UniversalByteStreamHandler; +import org.eclipse.rse.dstore.universal.miners.filesystem.UniversalFileSystemMiner; +import org.eclipse.rse.services.clientserver.IServiceConstants; +import org.eclipse.rse.services.clientserver.ISystemFileTypes; +import org.eclipse.rse.services.clientserver.PathUtility; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.dstore.AbstractDStoreService; +import org.eclipse.rse.services.dstore.ServiceResources; +import org.eclipse.rse.services.dstore.util.DownloadListener; +import org.eclipse.rse.services.dstore.util.FileSystemMessageUtil; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.files.IHostFile; +import org.eclipse.swt.widgets.Display; + + + + +public class DStoreFileService extends AbstractDStoreService implements IFileService, IUniversalDataStoreConstants +{ + + protected org.eclipse.dstore.core.model.DataElement _uploadLogElement = null; + protected Map _fileElementMap; + private int _bufferUploadSize = IUniversalDataStoreConstants.BUFFER_SIZE; + private int _bufferDownloadSize = IUniversalDataStoreConstants.BUFFER_SIZE; + protected ISystemFileTypes _fileTypeRegistry; + + private static String[] _filterAttributes = { + "attributes", + "filter", + "filter.id", + "doc", + "", + "", + DataStoreResources.FALSE, + "2"}; + + public DStoreFileService(IDataStoreProvider dataStoreProvider, ISystemFileTypes fileTypeRegistry) + { + super(dataStoreProvider); + _fileElementMap = new HashMap(); + _fileTypeRegistry = fileTypeRegistry; + } + + public String getName() + { + return ServiceResources.DStore_File_Service_Label; + } + + public String getDescription() + { + return ServiceResources.DStore_File_Service_Description; + } + + public void setBufferUploadSize(int size) + { + _bufferUploadSize = size; + } + + public void setBufferDownloadSize(int size) + { + _bufferDownloadSize = size; + } + + protected int getBufferUploadSize() + { + return _bufferUploadSize; + } + + protected int getBufferDownloadSize() + { + return _bufferDownloadSize; + } + + protected String getMinerId() + { + return UniversalFileSystemMiner.MINER_ID; + } + + protected String getByteStreamHandlerId() + { + return UniversalByteStreamHandler.class.getName(); + } + + protected String getDataStoreRoot() + { + return getDataStore().getAttribute(DataStoreAttributes.A_LOCAL_PATH); + } + + + protected String prepareForDownload(String localPath) + { + int index = localPath.lastIndexOf(File.separator); + String parentDir = localPath.substring(0, index + 1); + + // change local root for datastore so that the file is downloaded + // at the specified location + setDataStoreRoot(parentDir); + + String dataStoreLocalPath = localPath.substring(index + 1); + + if (!dataStoreLocalPath.startsWith("/")) + dataStoreLocalPath = "/" + dataStoreLocalPath; + + return dataStoreLocalPath; + } + + protected void setDataStoreRoot(String root) + { + getDataStore().setAttribute(DataStoreAttributes.A_LOCAL_PATH, root); + } + + protected DataElement findUploadLog() + { + DataElement minerInfo = getMinerElement(); + if (_uploadLogElement == null || _uploadLogElement.getDataStore() != getDataStore()) + { + _uploadLogElement = getDataStore().find(minerInfo, DE.A_NAME, "universal.uploadlog", 2); + } + return _uploadLogElement; + } + + protected DataElement getAttributes(String fileNameFilter, boolean showHidden) + { + DataElement attributes = getDataStore().createTransientObject(_filterAttributes); + String version = VERSION_1; + StringBuffer buffer = new StringBuffer(); + String filter = ((fileNameFilter == null) ? "*" : fileNameFilter); + buffer.append(version).append(TOKEN_SEPARATOR).append(filter).append(TOKEN_SEPARATOR).append(showHidden); + attributes.setAttribute(DE.A_SOURCE, buffer.toString()); + return attributes; + } + + + + public boolean upload(IProgressMonitor monitor, InputStream inputStream, String remoteParent, String remoteFile, + boolean isBinary, String hostEncoding) + { + BufferedInputStream bufInputStream = null; + + + boolean isCancelled = false; + Display display = Display.getCurrent(); + + + try + { + + DataElement uploadLog = findUploadLog(); +// listener = new FileTransferStatusListener(remotePath, shell, monitor, getConnectorService(), ds, uploadLog); + // ds.getDomainNotifier().addDomainListener(listener); + + int buffer_size = getBufferUploadSize(); + + // read in the file + bufInputStream = new BufferedInputStream(inputStream, buffer_size); + + boolean first = true; + byte[] buffer = new byte[buffer_size]; + byte[] convBytes; + int numToRead = 0; + + int available = bufInputStream.available(); + + long totalSent = 0; + + // upload bytes while available + while (available > 0 && !isCancelled) + { + if (display != null && !display.isDisposed()) + { + while (display.readAndDispatch()) {} + } + + numToRead = (available < buffer_size) ? available : buffer_size; + + int bytesRead = bufInputStream.read(buffer, 0, numToRead); + + if (bytesRead == -1) + break; + + totalSent += bytesRead; + + String byteStreamHandlerId = getByteStreamHandlerId(); + String remotePath = remoteParent + getSeparator(remoteParent) + remoteFile; + + if (!isBinary) + { + String tempStr = new String(buffer, 0, bytesRead); + + // hack for zOS - \r causes problems for compilers +// if (osName != null && (osName.startsWith("z") || osName.equalsIgnoreCase("aix"))) +// { +// tempStr = tempStr.replace('\r', ' '); +// } + + convBytes = tempStr.getBytes(hostEncoding); + + if (first) + { // send first set of bytes + first = false; + getDataStore().replaceFile(remotePath, convBytes, convBytes.length, true, byteStreamHandlerId); + } + else + { // append subsequent segments + getDataStore().replaceAppendFile(remotePath, convBytes, convBytes.length, true, byteStreamHandlerId); + } + } + else // binary + { + if (first) + { // send first set of bytes + first = false; + getDataStore().replaceFile(remotePath, buffer, bytesRead, true, byteStreamHandlerId); + } + else + { // append subsequent segments + getDataStore().replaceAppendFile(remotePath, buffer, bytesRead, true, byteStreamHandlerId); + } + } + + + if (display != null && monitor != null) + { + + isCancelled = monitor.isCanceled(); + if (isCancelled) + { + while (display.readAndDispatch()) + { + } + } + } + + available = bufInputStream.available(); + } +// if (listener.uploadHasFailed()) +// { +// showUploadFailedMessage(listener, source); +// } +// else + { + // transferSuccessful = true; + } + } + + catch (FileNotFoundException e) + { +// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error writing file " + remotePath, e); +// throw new RemoteFileIOException(e); + return false; + } + catch (UnsupportedEncodingException e) + { +// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error writing file " + remotePath, e); +// throw new RemoteFileIOException(e); + return false; + } + catch (IOException e) + { +// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error writing file " + remotePath, e); +// throw new RemoteFileIOException(e); + return false; + } + catch (Exception e) + { +// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error writing file " + remotePath, e); +// throw new RemoteFileIOException(e); + return false; + } + finally + { + + try + { + + if (bufInputStream != null) + bufInputStream.close(); + + if (isCancelled) + { + return false; + //throw new RemoteFileCancelledException(); + } + } + catch (IOException e) + { +// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error writing file " + remotePath, e); +// throw new RemoteFileIOException(e); + return false; + } + + } + + if (display != null && monitor != null) + { + // monitor.done(); + while (display.readAndDispatch()) { + } + } + return true; + } + + public boolean upload(IProgressMonitor monitor, File file, String remoteParent, String remoteFile, + boolean isBinary, String srcEncoding, String hostEncoding) + { + FileInputStream inputStream = null; + BufferedInputStream bufInputStream = null; + + + boolean isCancelled = false; + boolean transferSuccessful = false; + Display display = Display.getCurrent(); + + long totalBytes = file.length(); + + try + { + // if the file is empty, create new empty file on host + if (totalBytes == 0) + { + IHostFile created = createFile(monitor, remoteParent, remoteFile); + return created.exists(); + } + + DataElement uploadLog = findUploadLog(); +// listener = new FileTransferStatusListener(remotePath, shell, monitor, getConnectorService(), ds, uploadLog); + // ds.getDomainNotifier().addDomainListener(listener); + + int buffer_size = getBufferUploadSize(); + + // read in the file + inputStream = new FileInputStream(file); + bufInputStream = new BufferedInputStream(inputStream, buffer_size); + + boolean first = true; + byte[] buffer = new byte[buffer_size]; + byte[] convBytes; + int numToRead = 0; + + int available = bufInputStream.available(); + + long totalSent = 0; + + // upload bytes while available + while (available > 0 && !isCancelled) + { + if (display != null && !display.isDisposed()) + { + while (display.readAndDispatch()) {} + } + + numToRead = (available < buffer_size) ? available : buffer_size; + + int bytesRead = bufInputStream.read(buffer, 0, numToRead); + + if (bytesRead == -1) + break; + + totalSent += bytesRead; + + String byteStreamHandlerId = getByteStreamHandlerId(); + String remotePath = remoteParent + getSeparator(remoteParent) + remoteFile; + + if (!isBinary) + { + String tempStr = new String(buffer, 0, bytesRead, srcEncoding); + + // hack for zOS - \r causes problems for compilers +// if (osName != null && (osName.startsWith("z") || osName.equalsIgnoreCase("aix"))) +// { +// tempStr = tempStr.replace('\r', ' '); +// } + + convBytes = tempStr.getBytes(hostEncoding); + + if (first) + { // send first set of bytes + first = false; + getDataStore().replaceFile(remotePath, convBytes, convBytes.length, true, byteStreamHandlerId); + } + else + { // append subsequent segments + getDataStore().replaceAppendFile(remotePath, convBytes, convBytes.length, true, byteStreamHandlerId); + } + } + else // binary + { + if (first) + { // send first set of bytes + first = false; + getDataStore().replaceFile(remotePath, buffer, bytesRead, true, byteStreamHandlerId); + } + else + { // append subsequent segments + getDataStore().replaceAppendFile(remotePath, buffer, bytesRead, true, byteStreamHandlerId); + } + } + + + if (display != null && monitor != null) + { + long percent = (totalSent * 100) / totalBytes; + + + StringBuffer totalSentBuf = new StringBuffer(); + totalSentBuf.append((totalSent / KB_IN_BYTES)); + totalSentBuf.append(" KB"); + + StringBuffer totalBuf = new StringBuffer(); + totalBuf.append(totalBytes / KB_IN_BYTES); + totalBuf.append(" KB"); + + StringBuffer percentBuf = new StringBuffer(); + percentBuf.append(percent); + percentBuf.append("%"); + + monitor.worked(bytesRead); + /* + progressMsg.makeSubstitution(totalSentBuf.toString(), totalBuf, percentBuf); + monitor.subTask(progressMsg.getLevelOneText()); + */ + while (display.readAndDispatch()) + { + } + + isCancelled = monitor.isCanceled(); + if (isCancelled) + { + while (display.readAndDispatch()) + { + } + } + } + + available = bufInputStream.available(); + } +// if (listener.uploadHasFailed()) +// { +// showUploadFailedMessage(listener, source); +// } +// else + { + transferSuccessful = true; + } + } + + catch (FileNotFoundException e) + { +// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error writing file " + remotePath, e); +// throw new RemoteFileIOException(e); + return false; + } + catch (UnsupportedEncodingException e) + { +// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error writing file " + remotePath, e); +// throw new RemoteFileIOException(e); + return false; + } + catch (IOException e) + { +// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error writing file " + remotePath, e); +// throw new RemoteFileIOException(e); + return false; + } + catch (Exception e) + { +// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error writing file " + remotePath, e); +// throw new RemoteFileIOException(e); + return false; + } + finally + { + + try + { + + if (bufInputStream != null) + bufInputStream.close(); + + if (isCancelled) + { + return false; + //throw new RemoteFileCancelledException(); + } + } + catch (IOException e) + { +// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error writing file " + remotePath, e); +// throw new RemoteFileIOException(e); + return false; + } + + if (totalBytes > 0) + { + if (transferSuccessful) + { + + +// try +// { +// listener.waitForUpdate(null, 2); +// +// } +// catch (InterruptedException e) +// { +// UniversalSystemPlugin.logError(CLASSNAME + " InterruptedException while waiting for command", e); +// } + + } + + //ds.getDomainNotifier().removeDomainListener(listener); + +// if (listener.uploadHasFailed()) +// { +// showUploadFailedMessage(listener, source); +// } + } + } + + if (display != null && monitor != null) + { + // monitor.done(); + while (display.readAndDispatch()) { + } + } + return true; + } + + + public boolean download(IProgressMonitor monitor, String remoteParent, String remoteFile, File localFile, + boolean isBinary, String encoding) + { + DataElement universaltemp = getMinerElement(); + + if (!localFile.exists()) + { + File parentDir = localFile.getParentFile(); + parentDir.mkdirs(); + } + + try + { + if (localFile.exists()) + localFile.delete(); + localFile.createNewFile(); + } + catch (IOException e) + { +// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error creating local file " + destination, e); +// throw new RemoteFileIOException(e); + return false; + } + + int mode; + + if (isBinary) + { + mode = BINARY_MODE; + } + else + { + mode = TEXT_MODE; + } + + DataStore ds = getDataStore(); + String remotePath = remoteParent + getSeparator(remoteParent) + remoteFile; + + DataElement de = getElementFor(remotePath); + long fileLength = DStoreHostFile.getFileLength(de.getSource()); + + + DataElement remoteElement = ds.createObject(universaltemp, de.getType(), remotePath, String.valueOf(mode)); + + String tempRoot = getDataStoreRoot(); + + String dataStoreLocalPath = prepareForDownload(localFile.getAbsolutePath()); + + DataElement localElement = ds.createObject(universaltemp, de.getType(), dataStoreLocalPath, encoding); + + DataElement bufferSizeElement = ds.createObject(universaltemp, "buffer_size", "" + getBufferDownloadSize(), ""); + DataElement queryCmd = getCommandDescriptor(de,C_DOWNLOAD_FILE); + + ArrayList argList = new ArrayList(); + argList.add(remoteElement); + argList.add(localElement); + argList.add(bufferSizeElement); + + DataElement subject = ds.createObject(universaltemp, de.getType(), remotePath, String.valueOf(mode)); + + DataElement status = ds.command(queryCmd, argList, subject); + if (status == null) + { + System.out.println("no download descriptor for "+remoteElement); + } + try + { + DownloadListener dlistener = new DownloadListener(monitor, status, localFile, remotePath, (long) fileLength); + try + { + dlistener.waitForUpdate(); + } + catch (InterruptedException e) + { + } + + //getStatusMonitor(ds).waitForUpdate(status, monitor); + } + catch (Exception e) + { + return false; + } + + // now wait till we have all the bytes local + long localBytes = localFile.length(); + while (localBytes < fileLength && !monitor.isCanceled()) + { + try + { + Thread.sleep(100); + localBytes = localFile.length(); + } + catch (Exception e) + { + } + } + +// DownloadListener dlistener = new DownloadListener(shell, monitor, getConnectorService(), status, localFile, remotePath, (long) universalFile.getLength()); +// try +// { +// dlistener.waitForUpdate(); +// } +// catch (InterruptedException e) +// { +// UniversalSystemPlugin.logError(CLASSNAME + " InterruptedException while waiting for command", e); +// } + +// if (!dlistener.isCancelled()) +// { +// +// setDataStoreRoot(tempRoot); +// +// ArrayList resultList = remoteElement.getNestedData(); +// DataElement resultChild = null; +// +// for (int i = 0; i < resultList.size(); i++) +// { +// +// resultChild = (DataElement) resultList.get(i); +// +// if (resultChild.getType().equals(DOWNLOAD_RESULT_SUCCESS_TYPE)) +// { +// return; +// } +// else if (resultChild.getType().equals(DOWNLOAD_RESULT_FILE_NOT_FOUND_EXCEPTION)) +// { +// FileNotFoundException e = new FileNotFoundException(resultChild.getName()); +// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error reading file " + remotePath, e); +// throw new RemoteFileIOException(e); +// } +// else if (resultChild.getType().equals(DOWNLOAD_RESULT_UNSUPPORTED_ENCODING_EXCEPTION)) +// { +// UnsupportedEncodingException e = new UnsupportedEncodingException(resultChild.getName()); +// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error reading file " + remotePath, e); +// throw new RemoteFileIOException(e); +// } +// else if (resultChild.getType().equals(DOWNLOAD_RESULT_IO_EXCEPTION)) +// { +// IOException e = new IOException(resultChild.getName()); +// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error reading file " + remotePath, e); +// throw new RemoteFileIOException(e); +// } +// } +// } +// else +// { +// throw new RemoteFileCancelledException(); +// } + if (monitor != null) + { + //monitor.done(); + } + return true; + } + + public IHostFile getFile(IProgressMonitor monitor, String remoteParent, String name) + { + DataElement de = null; + if (name.equals(".") && name.equals(remoteParent)) + { + de = getElementFor(name); + } + else + { + de = getElementFor(remoteParent + getSeparator(remoteParent) + name); + } + dsQueryCommand(monitor, de, C_QUERY_GET_REMOTE_OBJECT); + return new DStoreHostFile(de); + } + + /** + * Returns what the next part of the path should be, given the current + * path as parentPath. Returns different separators based on whether the path + * appears to be a windows, linux, or virtual path. + * Pass in null to just get the default separator. + */ + protected String getSeparator(String parentPath) + { + if (parentPath == null || parentPath.length() < 2) return "/"; + if (parentPath.endsWith(ArchiveHandlerManager.VIRTUAL_SEPARATOR)) + return ""; + if (parentPath.endsWith(ArchiveHandlerManager.VIRTUAL_CANONICAL_SEPARATOR)) + return "/"; + if (parentPath.charAt(1) == ':') //Windows path + if (parentPath.indexOf(ArchiveHandlerManager.VIRTUAL_CANONICAL_SEPARATOR) != -1) + if (parentPath.endsWith("/")) + return ""; //already ends in separator + else return "/"; + else if (ArchiveHandlerManager.getInstance().isArchive(new File(parentPath))) + return ArchiveHandlerManager.VIRTUAL_SEPARATOR; + else + if (parentPath.endsWith("\\")) + return ""; //already ends in separator + else return "\\"; + else if (parentPath.charAt(0) == '/') //UNIX path + if (ArchiveHandlerManager.getInstance().isArchive(new File(parentPath))) + return ArchiveHandlerManager.VIRTUAL_SEPARATOR; + else + if (parentPath.endsWith("/")) + return ""; //already ends in separator + else return "/"; + else return "/"; //unrecognized path + } + + protected IHostFile convertToHostFile(DataElement element) + { + String type = element.getType(); + IHostFile file = null; + if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || + type.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) + { + file = new DStoreVirtualHostFile(element); + } + else + { + file = new DStoreHostFile(element); + } + String path = file.getAbsolutePath(); + _fileElementMap.put(path, element); + return file; + } + + protected IHostFile[] convertToHostFiles(DataElement[] elements) + { + ArrayList results = new ArrayList(); + for (int i = 0; i < elements.length; i++) + { + if (!elements[i].isDeleted()) + results.add(convertToHostFile(elements[i])); + } + return (IHostFile[]) results.toArray(new IHostFile[results.size()]); + } + + public IHostFile getUserHome() + { + return getFile(null, ".","."); + } + + public IHostFile createFile(IProgressMonitor monitor, String remoteParent, String fileName) + { + String remotePath = remoteParent + getSeparator(remoteParent) + fileName; + DataElement de = getElementFor(remotePath); + dsQueryCommand(monitor, de, C_CREATE_FILE); + return new DStoreHostFile(de); + } + + public IHostFile createFolder(IProgressMonitor monitor, String remoteParent, String folderName) + { + String remotePath = remoteParent + getSeparator(remoteParent) + folderName; + DataElement de = getElementFor(remotePath); + dsQueryCommand(monitor, de, C_CREATE_FOLDER); + return new DStoreHostFile(de); + } + + public boolean delete(IProgressMonitor monitor, String remoteParent, String fileName) throws SystemMessageException + { + String remotePath = remoteParent + getSeparator(remoteParent) + fileName; + DataElement de = getElementFor(remotePath); + DataElement status = dsStatusCommand(monitor, de, C_DELETE); + if (status == null) return false; + if (FileSystemMessageUtil.getSourceMessage(status).equals(IServiceConstants.SUCCESS)) return true; + else throw new SystemMessageException(getMessage("RSEF1300").makeSubstitution(FileSystemMessageUtil.getSourceLocation(status))); + + } + + public boolean deleteBatch(IProgressMonitor monitor, String[] remoteParents, String[] fileNames) throws SystemMessageException + { + if (remoteParents.length == 1) return delete(monitor, remoteParents[0], fileNames[0]); + + ArrayList dataElements = new ArrayList(remoteParents.length); + for (int i = 0; i < remoteParents.length; i++) + { + String remotePath = remoteParents[i] + getSeparator(remoteParents[i]) + fileNames[i]; + DataElement de = getElementFor(remotePath); + if (de != null) dataElements.add(de); + } + DataElement status = dsStatusCommand(monitor, (DataElement) dataElements.get(0), dataElements, C_DELETE_BATCH); + if (status == null) return false; + if (FileSystemMessageUtil.getSourceMessage(status).equals(IServiceConstants.SUCCESS)) return true; + else throw new SystemMessageException(getMessage("RSEF1300").makeSubstitution(FileSystemMessageUtil.getSourceLocation(status))); + } + + public boolean rename(IProgressMonitor monitor, String remoteParent, String oldName, String newName) + { + String remotePath = remoteParent + getSeparator(remoteParent) + oldName; + DataElement de = getElementFor(remotePath); + de.setAttribute(DE.A_SOURCE, newName); + dsQueryCommand(monitor, de, C_RENAME); + return true; + } + + public boolean rename(IProgressMonitor monitor, String remoteParent, String oldName, String newName, IHostFile oldFile) + { + boolean retVal = rename(monitor, remoteParent, oldName, newName); + String newPath = remoteParent + getSeparator(remoteParent) + newName; + oldFile.renameTo(newPath); + return retVal; + } + + public boolean move(IProgressMonitor monitor, String srcParent, String srcName, String tgtParent, String tgtName) + { + String src = srcParent + getSeparator(srcParent) + srcName; + String tgt = tgtParent + getSeparator(tgtParent) + tgtName; + boolean isVirtual = ArchiveHandlerManager.isVirtual(src) || ArchiveHandlerManager.isVirtual(tgt); + //if (isVirtual || isArchive) + { + if (copy(monitor, srcParent, srcName, tgtParent, tgtName)) + { + try + { + delete(monitor, srcParent, srcName); + } + catch (Exception e) + { + return false; + } + return true; + } + return false; + } + +/* + // handle special characters in source and target strings + StringBuffer srcBuf = new StringBuffer(src); + StringBuffer tgtBuf = new StringBuffer(tgt); + + for (int i = 0; i < srcBuf.length(); i++) + { + char c = srcBuf.charAt(i); + + boolean isSpecialChar = isSpecialChar(c); + + if (isSpecialChar) + { + srcBuf.insert(i, "\\"); + i++; + } + } + + for (int i = 0; i < tgtBuf.length(); i++) + { + char c = tgtBuf.charAt(i); + + boolean isSpecialChar = isSpecialChar(c); + + if (isSpecialChar) + { + tgtBuf.insert(i, "\\"); + i++; + } + } + + src = "\"" + srcBuf.toString() + "\""; + tgt = "\"" + tgtBuf.toString() + "\""; + + if (systemType.equals(SYSTEMTYPE_WINDOWS)) + { + if (sourceFolderOrFile.isDirectory() && sourceFolderOrFile.getAbsolutePath().charAt(0) != targetFolder.getAbsolutePath().charAt(0)) + { + // special case - move across drives + command = "xcopy " + src + " " + tgt + " /S /E /K /O /Q /H /I && rmdir /S /Q " + src; + } + else + { + command = "move " + src + " " + tgt; + } + } + else + { + command = "mv " + src + " " + tgt; + } + + UniversalCmdSubSystemImpl cmdSubSystem = getUniversalCmdSubSystem(); + IRemoteFile runFile = sourceFolderOrFile; + + if (cmdSubSystem != null) + { + try + { + done = cmdSubSystem.runRemoteCommand(runFile, command); + runFile.getParentRemoteFile().markStale(true); + runFile.markStale(true); + + } + catch (InterruptedException e) + { + done = false; + } + } + else + SystemPlugin.logWarning(CLASSNAME + " cmdSubSystem is null in move"); + + return done; + */ + + } + + /** + * Checks whether the given character is a special character in the shell. A special character is + * '$', '`', '"' and '\'. + * @param c the character to check. + * @return true if the character is a special character, false otherwise. + */ + protected boolean isSpecialChar(char c) { + + if ((c == '$') || (c == '`') || (c == '"') || (c == '\\')) { + return true; + } + else { + return false; + } + } + + public boolean copy(IProgressMonitor monitor, String srcParent, String srcName, String tgtParent, String tgtName) + { + DataStore ds = getDataStore(); + String srcRemotePath = srcParent + getSeparator(srcParent) + srcName; + DataElement srcDE = getElementFor(srcRemotePath); + + DataElement tgtDE = getElementFor(tgtParent); + + DataElement cpCmd = getCommandDescriptor(tgtDE, C_COPY); + + if (cpCmd != null) + { + ArrayList args = new ArrayList(); + args.add(srcDE); + DataElement nameObj = ds.createObject(null, "name", tgtName); + args.add(nameObj); + DataElement status = ds.command(cpCmd, args, tgtDE, true); + + + try + { + getStatusMonitor(ds).waitForUpdate(status, monitor); + + if (status.getAttribute(DE.A_SOURCE).equals(FAILED)) { + + String errMsg = status.getAttribute(DE.A_VALUE); + + /* + // for an unexpected error, we don't have an error message from the server + if (errMsg.equals(UNEXPECTED_ERROR)) { + msg = SystemPlugin.getPluginMessage(MSG_ERROR_UNEXPECTED).getLevelOneText(); + } + else { + msg = errMsg; + } + + + throw new RemoteFileIOException(new Exception(msg)); + */ + return false; + } + } + catch (InterruptedException e) + { +// UniversalSystemPlugin.logError(CLASSNAME + " InterruptedException while waiting for command", e); + } + return true; + } + return false; + } + + public boolean copyBatch(IProgressMonitor monitor, String[] srcParents, String[] srcNames, String tgtParent) + { + DataStore ds = getDataStore(); + + DataElement tgtDE = getElementFor(tgtParent); + DataElement cpCmd = getCommandDescriptor(tgtDE, C_COPY_BATCH); + + if (cpCmd != null) + { + ArrayList args = new ArrayList(); + for (int i = 0; i < srcParents.length; i++) + { + String srcRemotePath = srcParents[i] + getSeparator(srcParents[i]) + srcNames[i]; + DataElement srcDE = getElementFor(srcRemotePath); + args.add(srcDE); + } + DataElement status = ds.command(cpCmd, args, tgtDE, true); + + try + { + getStatusMonitor(ds).waitForUpdate(status, monitor); + + if (status.getAttribute(DE.A_SOURCE).equals(FAILED)) { + + String errMsg = status.getAttribute(DE.A_VALUE); + + /* + // for an unexpected error, we don't have an error message from the server + if (errMsg.equals(UNEXPECTED_ERROR)) { + msg = SystemPlugin.getPluginMessage(MSG_ERROR_UNEXPECTED).getLevelOneText(); + } + else { + msg = errMsg; + } + + + throw new RemoteFileIOException(new Exception(msg)); + */ + return false; + } + } + catch (InterruptedException e) + { +// UniversalSystemPlugin.logError(CLASSNAME + " InterruptedException while waiting for command", e); + } + return true; + } + return false; + } + + + + + + public IHostFile[] getRoots(IProgressMonitor monitor) + { + if (!isInitialized()) + { + waitForInitialize(null); + } + DataStore ds = getDataStore(); + DataElement universaltemp = getMinerElement(); + + // create filter descriptor + DataElement deObj = ds.createObject(universaltemp, UNIVERSAL_FILTER_DESCRIPTOR, "", "", "", false); + DataElement[] results = dsQueryCommand(monitor, deObj, C_QUERY_ROOTS); + + return convertToHostFiles(results); + } + + + + + public IHostFile[] getFolders(IProgressMonitor monitor, String remoteParent, String fileFilter) + { + return fetch(monitor, remoteParent, fileFilter, C_QUERY_VIEW_FOLDERS); + } + + public IHostFile[] getFiles(IProgressMonitor monitor, String remoteParent, String fileFilter) + { + return fetch(monitor, remoteParent, fileFilter, C_QUERY_VIEW_FILES); + } + + public IHostFile[] getFilesAndFolders(IProgressMonitor monitor, String remoteParent, String fileFilter) + { + return fetch(monitor, remoteParent, fileFilter, C_QUERY_VIEW_ALL); + } + + protected DataElement getElementFor(String path) + { + if (!isInitialized()) + { + waitForInitialize(null); + } + + + String normalizedPath = PathUtility.normalizeUnknown(path); + DataElement element = (DataElement)_fileElementMap.get(normalizedPath); + if (element == null || element.isDeleted()) + { + DataElement universaltemp = getMinerElement(); + element = getDataStore().createObject(universaltemp, UNIVERSAL_FILTER_DESCRIPTOR, normalizedPath, normalizedPath, "", false); + } + return element; + } + + protected IHostFile[] fetch(IProgressMonitor monitor, String remoteParent, String fileFilter, String queryType) + { + DataStore ds = getDataStore(); + + + // create filter descriptor + DataElement deObj = getElementFor(remoteParent); + if (deObj == null) + { + DataElement universaltemp = getMinerElement(); + ds.createObject(universaltemp, UNIVERSAL_FILTER_DESCRIPTOR, remoteParent, remoteParent, "", false); + } + + DataElement attributes = getAttributes(fileFilter, true); + ArrayList args = new ArrayList(1); + args.add(attributes); + + DataElement[] results = dsQueryCommand(monitor, deObj, args, queryType); + return convertToHostFiles(results); + } + + public boolean isCaseSensitive() + { + return true; + } + + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/files/DStoreHostFile.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/files/DStoreHostFile.java new file mode 100644 index 00000000000..9a9029cb502 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/files/DStoreHostFile.java @@ -0,0 +1,276 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore.files; + +import java.io.File; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.services.clientserver.IServiceConstants; +import org.eclipse.rse.services.clientserver.PathUtility; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.files.IHostFile; + +public class DStoreHostFile implements IHostFile +{ + public static final int ATTRIBUTE_MODIFIED_DATE=1; + public static final int ATTRIBUTE_SIZE = 2; + public static final int ATTRIBUTE_CLASSIFICATION =11; + + + protected DataElement _element; + protected boolean _isArchive; + + public DStoreHostFile(DataElement element) + { + _element = element; + _isArchive = internalIsArchive(); + } + + public DataElement getDataElement() + { + return _element; + } + + public static String getNameFromPath(String path) + { + int lastSlash = path.lastIndexOf('/'); + if (lastSlash > 0 && lastSlash != path.length() - 1) + { + return path.substring(lastSlash); + } + return path; + } + + public static String getParentPathFromPath(String path) + { + int lastSlash = path.lastIndexOf('/'); + if (lastSlash > 0 && lastSlash != path.length() - 1) + { + return path.substring(0, lastSlash); + } + return path; + } + + public String getName() + { + String type = _element.getType(); + if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) + { + // filter doesn't separate path from name + String path = _element.getName(); + return getNameFromPath(path); + } + else + { + String name = _element.getName(); + String parentPath = getParentPath(); + if (name.length() == 0 && + (parentPath.equals("/") || parentPath.endsWith(":\\"))) + { + return getParentPath(); + } + return name; + } + } + + public String getParentPath() + { + String type = _element.getType(); + if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) + { + // filter doesn't separate path from name + String path = _element.getName(); + return getParentPathFromPath(path); + } + else + { + return _element.getValue(); + } + } + + public boolean isHidden() + { + String name = getName(); + if (name == null || name.length() == 0) + { + return false; + } + else + { + + return name.charAt(0) == '.'; + } + } + + public boolean isDirectory() + { + String type = _element.getType(); + if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR) + || type.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) + { + return true; + } + return false; + + } + + public boolean isRoot() + { + String parentPath = getParentPath(); + String name = _element.getName(); + if (parentPath == null || parentPath.length() == 0 || + (name.length() == 0 && (parentPath.equals("/") || parentPath.endsWith(":\\"))) + ) + + { + return true; + } + else + { + return false; + } + } + + public boolean isFile() + { + String type = _element.getType(); + if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) + || type.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) + || type.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) + { + return true; + } + return false; + } + + public boolean exists() + { + String type = _element.getType(); + if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) || + type.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR) || + type.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || + type.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR) || + type.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) + { + return true; + } + else + { + return false; + } + } + + + public String getAbsolutePath() + { + String parentPath = getParentPath(); + String name = _element.getName(); + + String type = _element.getType(); + if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) + { + return parentPath; + } + + if (name.length() == 0) + { + return PathUtility.normalizeUnknown(parentPath); + } + else + { + return PathUtility.normalizeUnknown(parentPath + "/" + name); + } + } + + public long getSize() + { + return getFileLength(_element.getSource()); + } + + public long getModifiedDate() + { + return getModifiedDate(_element.getSource()); + + } + + public String getClassification() + { + String classification = getClassification(_element.getSource()); + if (classification == null) + { + if (isFile()) + { + classification = "file"; + } + else + { + classification = "directory"; + } + } + return classification; + } + + protected static String getClassification(String attributes) + { + return getAttribute(attributes, ATTRIBUTE_CLASSIFICATION); + } + + protected static long getFileLength(String attributes) + { + String str = getAttribute(attributes, ATTRIBUTE_SIZE); + return Long.parseLong(str); + } + + protected static long getModifiedDate(String attributes) + { + String str = getAttribute(attributes, ATTRIBUTE_MODIFIED_DATE); + return Long.parseLong(str); + } + + protected static String getAttribute(String attributes, int index) + { + String[] str = attributes.split("\\"+IServiceConstants.TOKEN_SEPARATOR); + if (str.length > index) + { + return str[index]; + } + else + { + return null; + } + } + + public void renameTo(String newAbsolutePath) + { + _element.setAttribute(DE.A_NAME, newAbsolutePath); + _isArchive = internalIsArchive(); + } + + protected boolean internalIsArchive() + { + String path = getAbsolutePath(); + return ArchiveHandlerManager.getInstance().isArchive(new File(path)) + && !ArchiveHandlerManager.isVirtual(path); + } + + public boolean isArchive() + { + return _isArchive; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/files/DStoreVirtualHostFile.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/files/DStoreVirtualHostFile.java new file mode 100644 index 00000000000..deac515631a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/files/DStoreVirtualHostFile.java @@ -0,0 +1,78 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore.files; + +import org.eclipse.dstore.core.model.DataElement; + +public class DStoreVirtualHostFile extends DStoreHostFile +{ + + public static final int ATTRIBUTE_COMMENT = 6; + public static final int ATTRIBUTE_COMPRESSEDSIZE = 7; + public static final int ATTRIBUTE_COMPRESSIONMETHOD = 8; + public static final int ATTRIBUTE_COMPRESSIONRATIO = 9; + public static final int ATTRIBUTE_EXPANDEDSIZE = 10; + + public DStoreVirtualHostFile(DataElement element) + { + super(element); + } + + protected static long getCompressedSize(String attributes) + { + String str = getAttribute(attributes, ATTRIBUTE_COMPRESSEDSIZE); + return Long.parseLong(str); + } + + protected static long getExpandedSize(String attributes) + { + String str = getAttribute(attributes, ATTRIBUTE_EXPANDEDSIZE); + return Long.parseLong(str); + } + + protected static double getCompressionRatio(String attributes) + { + String str = getAttribute(attributes, ATTRIBUTE_COMPRESSIONRATIO); + return Double.parseDouble(str); + } + + public String getComment() + { + return getAttribute(_element.getSource(), ATTRIBUTE_COMMENT); + } + + public long getCompressedSize() + { + return getCompressedSize(_element.getSource()); + } + + public String getCompressionMethod() + { + return getAttribute(_element.getSource(), ATTRIBUTE_COMPRESSIONMETHOD); + } + + public double getCompressionRatio() + { + return getCompressionRatio(_element.getSource()); + } + + public long getExpandedSize() + { + return getExpandedSize(_element.getSource()); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/processes/DStoreHostProcess.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/processes/DStoreHostProcess.java new file mode 100644 index 00000000000..e681893c6a5 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/processes/DStoreHostProcess.java @@ -0,0 +1,519 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore.processes; + + +import java.util.HashMap; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.Platform; +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.rse.services.clientserver.processes.IHostProcess; + +/** + * This class implements the IRemoteClientProcess interface by wrappering a DataElement + * and returning process attribute information from the underlying DataElement. + * It also contains client-specific methods for getting contextual information about + * the process such as the associated subsystem and connection. + * @author mjberger + * + */ +public class DStoreHostProcess implements IHostProcess, org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants, IAdaptable, org.eclipse.rse.services.clientserver.processes.ISystemProcessRemoteConstants +{ + public static final boolean ROOT_TRUE = true; + public static final boolean ROOT_FALSE = false; + + protected String _name, _username; + protected long _pid = -1; + protected long _ppid = -1; + protected long _tgid = -1; + protected long _tracerPid = -1; + protected long _uid = -1; + protected long _gid = -1; + + protected String _label = null; + protected String _fullyQualifiedProcess; + + protected boolean _isRoot = false; + + protected Object _remoteObj; + + // master hash map + protected HashMap _contents = new HashMap(); + + /* container properties */ + protected boolean _isStale = false; + + // properties + protected HashMap _properties = new HashMap(); + protected HashMap _propertyStates = new HashMap(); + + /** + * Constructor that takes a dataElement object containing the process information, and + * a parent process. + */ + public DStoreHostProcess(DataElement dataElementObj) + { + init(dataElementObj); + } + + protected void init(DataElement dataElementObj) + { + setProcess(dataElementObj); + String name = dataElementObj.getName(); + _fullyQualifiedProcess = "/proc/" + name; + + // if we already have retrieved file properties + // set them now + String s = dataElementObj.getAttribute(DE.A_VALUE); + if (s != null && s.length() > 0) + { + getAttributes(null); + } + } + + /** + * The Properties of the process are returned from the miner in a string that can be parsed using + * the String.split method, with delimiter "|". + * You can also set all attributes at once with your own string passed as a parameter, as long + * as the string is in the same format as outlined below (pass in null to use the DataElement's string): + *

The string contains properties of the object in the following order + *

    + *
  • Process Id (pid) - long + *
  • Executable name - String + *
  • Status - char + *
  • Tgid - long + *
  • Process Parent id (ppid) - long + *
  • Tracer pid - long + *
  • User id (uid) - int + *
  • Username - String + *
  • Group id (gid) - int + *
  • VM Size - long + *
  • VM RSS - long + *
+ */ + protected String getAttributes(String newAttributes) + { + DataElement deObj = (DataElement) this.getObject(); + + String s = null; + + if (newAttributes == null) s = deObj.getAttribute(DE.A_VALUE); + else s = newAttributes; + + if (s != null && s.length() > 0) + { + String[] str = s.split("\\"+TOKEN_SEPARATOR); + int tokens = str.length; + if (tokens > 1) + { + try + { + setPid(str[PROCESS_ATTRIBUTES_INDEX_PID]); + + setName(str[PROCESS_ATTRIBUTES_INDEX_EXENAME]); + + setTgid(str[PROCESS_ATTRIBUTES_INDEX_TGID]); + + setPPid(str[PROCESS_ATTRIBUTES_INDEX_PPID]); + + if (_ppid == 0) _isRoot = true; + + setTracerPid(str[PROCESS_ATTRIBUTES_INDEX_TRACERPID]); + + setUid(str[PROCESS_ATTRIBUTES_INDEX_UID]); + + setUsername(str[PROCESS_ATTRIBUTES_INDEX_USERNAME]); + + setGid(str[PROCESS_ATTRIBUTES_INDEX_GID]); + + setLabel(str[PROCESS_ATTRIBUTES_INDEX_EXENAME]); + } + catch (ArrayIndexOutOfBoundsException e) + { + // SystemPlugin.logError("Error in UniversalProcessImpl.getAttributes(). Attributes = " + s); + } + } + } + return s; + } + + /** + * Set the DataElement for this object + */ + public void setProcess(Object dataElementObj) + { + _remoteObj = (DataElement) dataElementObj; + } + + /** + * Returns the DataElement for this object + */ + public Object getObject() + { + return _remoteObj; + } + + public String getAbsolutePath() + { + return _fullyQualifiedProcess; + } + + public String getLabel() + { + return _label; + } + + public long getPid() + { + return _pid; + } + + public String getName() + { + return _name; + } + + public String getState() + { + String state = getSubAttribute(PROCESS_ATTRIBUTES_INDEX_STATUS); + if (state == null) + { + //SystemPlugin.logError("Error in UniversalProcessImpl.getAttributes(): status of process " + getPid() + " is not given."); + return " "; + } + else return state; + } + + public long getTgid() + { + return _tgid; + } + + public long getTracerPid() + { + return _tracerPid; + } + + public long getUid() + { + return _uid; + } + + public String getUsername() + { + return _username; + } + + public long getGid() + { + return _gid; + } + + protected void setAbsolutePath(String path) + { + _fullyQualifiedProcess = path; + } + + protected void setGid(long gid) + { + _gid = gid; + } + + protected void setGid(String newGid) + { + try + { + _gid = Long.parseLong(newGid); + } + catch (NumberFormatException e) + { + //SystemPlugin.logError("Error in UniversalProcessImpl.setGid: Could not parse gid into integer."); + _gid = -1; + } + } + + public void setLabel(String newLabel) + { + _label = newLabel; + } + + protected void setName(String exeName) + { + _name = exeName; + } + + protected void setPid(long newPid) + { + _pid = newPid; + } + + protected void setPid(String newPid) + { + try + { + _pid = Long.parseLong(newPid); + } + catch (NumberFormatException e) + { + // SystemPlugin.logError("Error in UniversalProcessImpl.setPid: Could not parse pid into integer."); + _pid = -1; + } + } + + protected void setState(String newState) + { + setSubAttribute(PROCESS_ATTRIBUTES_INDEX_STATUS, newState); + } + + protected void setTgid(long tgid) + { + _tgid = tgid; + } + + protected void setTgid(String newTgid) + { + try + { + _tgid = Long.parseLong(newTgid); + } + catch (NumberFormatException e) + { + // SystemPlugin.logError("Error in UniversalProcessImpl.setTgid: Could not parse tgid into integer."); + _tgid = -1; + } + } + + protected void setTracerPid(long tracerPid) + { + _tracerPid = tracerPid; + } + + protected void setTracerPid(String newTracerPid) + { + try + { + _tracerPid = Long.parseLong(newTracerPid); + } + catch (NumberFormatException e) + { + // SystemPlugin.logError("Error in UniversalProcessImpl.setTracerPid: Could not parse tracerpid into integer."); + _tracerPid = -1; + } + } + + protected void setUid(long uid) + { + _uid = uid; + } + + protected void setUid(String newUid) + { + try + { + _uid = Long.parseLong(newUid); + } + catch (NumberFormatException e) + { + // SystemPlugin.logError("Error in UniversalProcessImpl.setUid: Could not parse uid into integer."); + _uid = -1; + } + } + + protected void setUsername(String username) + { + _username = username; + } + + public Object getAdapter(Class adapterType) + { + return Platform.getAdapterManager().getAdapter(this, adapterType); + } + + public long getPPid() + { + return _ppid; + } + + protected void setPPid(long newPPid) + { + _ppid = newPPid; + } + + protected void setPPid(String newPPid) + { + try + { + _ppid = Long.parseLong(newPPid); + } + catch (NumberFormatException e) + { + // SystemPlugin.logError("Error in UniversalProcessImpl.setPPid: Could not parse ppid into integer."); + _ppid = -1; + } + } + + public boolean isRoot() + { + return _isRoot; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.processes.IHostProcess#getAllProperties() + */ + public String getAllProperties() + { + return getAttributes(null); + } + + /** + * @param allProperties + */ + protected void setAllProperties(String allProperties) + { + getAttributes(allProperties); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.processes.IHostProcess#getVmSizeInKB() + */ + public long getVmSizeInKB() + { + String sizeStr = getSubAttribute(PROCESS_ATTRIBUTES_INDEX_VMSIZE); + if (sizeStr == null) return 0; + long vmsize = 0; + try + { + vmsize = Long.parseLong(sizeStr); + } + catch (NumberFormatException e) + { + // SystemPlugin.logError("Error in UniversalProcessImpl.getVMSizeInKB: Could not parse VM Size into integer."); + return 0; + } + return vmsize; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.processes.IHostProcess#getVmRSSInKB() + */ + public long getVmRSSInKB() + { + String sizeStr = getSubAttribute(PROCESS_ATTRIBUTES_INDEX_VMRSS); + if (sizeStr == null) return 0; + long vmrss = 0; + try + { + vmrss = Long.parseLong(sizeStr); + } + catch (NumberFormatException e) + { + // SystemPlugin.logError("Error in UniversalProcessImpl.getVMRSSInKB: Could not parse VM RSS into integer."); + return 0; + } + return vmrss; + } + + + /** + * @param size the size to set + */ + protected void setVmSizeInKB(long size) + { + String sizeStr = ""; + sizeStr = sizeStr + size; + setSubAttribute(PROCESS_ATTRIBUTES_INDEX_VMSIZE, sizeStr); + } + + /** + * @param size the size to set + */ + protected void setVmRSSInKB(long size) + { + String sizeStr = ""; + sizeStr = sizeStr + size; + setSubAttribute(PROCESS_ATTRIBUTES_INDEX_VMRSS, sizeStr); + } + + /** + * Returns a subattribute of the A_VALUE of this process's associated + * data element. + * @param attIndex the index of the desired subattribute + * @return a string containing that attribute, or null if that attribute + * is not specified, if the dataelement does not exist, or if the attIndex + * is out of bounds. + */ + protected String getSubAttribute(int attIndex) + { + DataElement deObj = (DataElement) this.getObject(); + if (deObj == null) return null; + + String s = deObj.getAttribute(DE.A_VALUE); + + if (s != null && s.length() > 0) + { + String[] str = s.split("\\"+TOKEN_SEPARATOR); + if (attIndex >= str.length) return null; + if (str[attIndex] == null || str[attIndex].equals("")) return null; + else return str[attIndex]; + } + else return null; + } + + /** + * Helper method for setting any attributes of the underlying DataElement. + * @param attIndex + * @param newSubAttribute + */ + protected void setSubAttribute(int attIndex, String newSubAttribute) + { + DataElement deObj = (DataElement) this.getObject(); + if (deObj == null) + { + // SystemPlugin.logError("Error in UniversalProcessImpl.setSubAttribute: Could not access dataelement."); + return; + } + String s = deObj.getAttribute(DE.A_VALUE); + + if (s != null && s.length() > 0) + { + String[] str = s.split("\\"+TOKEN_SEPARATOR); + if (attIndex >= str.length) + { + // SystemPlugin.logError("Error in UniversalProcessImpl.setSubAttribute: Attribute index out of bounds."); + return; + } + s = ""; + str[attIndex] = newSubAttribute; + for (int i = 0; i < str.length; i++) + { + if (i == str.length - 1) s = s + str[i]; + else s = s + str[i] + TOKEN_SEPARATOR; + } + deObj.setAttribute(DE.A_VALUE, s); + DataStore ds = deObj.getDataStore(); + ds.refresh(deObj); + } + else + { + // SystemPlugin.logError("Error in UniversalProcessImpl.setSubAttribute: Dataelement did not contain an attribute string."); + return; + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/processes/DStoreProcessService.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/processes/DStoreProcessService.java new file mode 100644 index 00000000000..02b046dece0 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/processes/DStoreProcessService.java @@ -0,0 +1,338 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore.processes; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.core.model.IDataStoreProvider; +import org.eclipse.rse.dstore.universal.miners.processes.IUniversalProcessDataStoreConstants; +import org.eclipse.rse.dstore.universal.miners.processes.UniversalProcessMiner; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.clientserver.processes.IHostProcess; +import org.eclipse.rse.services.clientserver.processes.IHostProcessFilter; +import org.eclipse.rse.services.clientserver.processes.ISystemProcessRemoteConstants; +import org.eclipse.rse.services.dstore.ServiceResources; +import org.eclipse.rse.services.dstore.util.DStoreStatusMonitor; +import org.eclipse.rse.services.processes.AbstractProcessService; +import org.eclipse.rse.services.processes.IProcessService; + + +public class DStoreProcessService extends AbstractProcessService implements IProcessService, IUniversalProcessDataStoreConstants, ISystemProcessRemoteConstants +{ + protected IDataStoreProvider _provider; + protected DataElement _minerElement = null; + protected DStoreStatusMonitor _statusMonitor; + protected DataElement _procMinerStatus; + protected String[] _statusTypes; + + public DStoreProcessService(IDataStoreProvider provider) + { + _provider = provider; + } + + public String getName() + { + return ServiceResources.DStore_Process_Service_Label; + } + + public String getDescription() + { + return ServiceResources.DStore_Process_Service_Description; + } + + public IHostProcess[] listAllProcesses(IProgressMonitor monitor, IHostProcessFilter filter) throws SystemMessageException + { + if (!isInitialized()) + { + waitForInitialize(monitor); + } + IHostProcess[] processes = null; + + DataStore ds = getDataStore(); + DataElement universaltemp = getMinerElement(); + + // create filter descriptor + DataElement deObj; + deObj = ds.find(universaltemp, DE.A_NAME, UNIVERSAL_PROCESS_ROOT, 1); + if (deObj == null) deObj = ds.createObject(universaltemp, UNIVERSAL_PROCESS_FILTER, UNIVERSAL_PROCESS_ROOT, "", "", false); + deObj.setAttribute(DE.A_SOURCE, filter.toString()); + + // query + DataElement queryCmd = ds.localDescriptorQuery(deObj.getDescriptor(), C_PROCESS_FILTER_QUERY_ALL); + + if (queryCmd != null) + { + DataElement status = ds.command(queryCmd, deObj, true); + + DStoreStatusMonitor smon = getStatusMonitor(getDataStore()); + try + { + smon.waitForUpdate(status); + } + catch (InterruptedException e) + { + throw new SystemMessageException(getMessage("RSEG1067")); + } + // get results + List nested = deObj.getNestedData(); + if (nested != null) + { + Object[] results = nested.toArray(); + + String message = status.getAttribute(DE.A_VALUE); + if (!message.equals(PROCESS_MINER_SUCCESS)) + { + throw new SystemMessageException(getMessage("RSEPG1301")); + } + + // convert objects to remote files + processes = convertObjsToHostProcesses(filter, results); + } + } + else + { + //SystemPlugin.logWarning(CLASSNAME + " queryCmd is null in listRoots"); + } + + return processes; + } + + /** + * Helper method to convert DataElement objects to IRemoteClientProcess objects. + */ + protected IHostProcess[] convertObjsToHostProcesses(IHostProcessFilter processFilter, Object[] objs) + { + if (objs == null) + return null; + + ArrayList list = new ArrayList(objs.length); + + for (int idx = 0; idx < objs.length; idx++) + { + DataElement de = (DataElement) objs[idx]; + if (!de.isDeleted()) + { + if (processFilter == null || processFilter.allows(de.getValue())) + { + DStoreHostProcess newProcess = new DStoreHostProcess(de); + list.add(newProcess); + } + } + } + + IHostProcess[] processes = new IHostProcess[list.size()]; + + for (int idx = 0; idx < list.size(); idx++) + { + processes[idx] = (IHostProcess) list.get(idx); + } + + return processes; + } + + /** + * Helper method to return the DataStore object needed by comm layer. + */ + protected DataStore getDataStore() + { + return _provider.getDataStore(); + } + + protected DataElement getMinerElement() + { + + if (_minerElement == null || _minerElement.getDataStore() != getDataStore()) + { + _minerElement = getDataStore() + .findMinerInformation( + "org.eclipse.rse.dstore.universal.miners.processes.UniversalProcessMiner"); + } + return _minerElement; + } + + public DStoreStatusMonitor getStatusMonitor(DataStore dataStore) + { + if (_statusMonitor == null || _statusMonitor.getDataStore() != dataStore) + { + _statusMonitor = new DStoreStatusMonitor(dataStore); + } + return _statusMonitor; + } + + public boolean kill(IProgressMonitor monitor, long PID, String signal) throws SystemMessageException + { + try + { + DataStore ds = getDataStore(); + + // run kill command on host + DStoreHostProcess process = (DStoreHostProcess) getProcess(monitor, PID); + DataElement deObj = (DataElement) process.getObject(); + DataElement killCmd = ds.localDescriptorQuery(deObj.getDescriptor(), C_PROCESS_KILL); + deObj.setAttribute(DE.A_SOURCE, signal); + + if (killCmd != null) + { + DataElement status = ds.command(killCmd, deObj, true); + + DStoreStatusMonitor smon = getStatusMonitor(getDataStore()); + smon.waitForUpdate(status); + + // get results + String message = status.getAttribute(DE.A_VALUE); + if (message.equals(PROCESS_MINER_SUCCESS)) return true; + else + { + SystemMessage msg = getMessage("RSEPG1300"); + msg.makeSubstitution(process.getName() + " (" + process.getPid() + ")", message); + throw new SystemMessageException(msg); + } + } + else + { + // SystemPlugin.logWarning(CLASSNAME + " queryCmd is null in listRoots"); + } + } + catch (InterruptedException e) + { + throw new SystemMessageException(getMessage("RSEG1067")); + } + return false; + } + + public String[] getSignalTypes() + { + if (_statusTypes != null) + { + return _statusTypes; + } + else + { + _statusTypes = internalGetSignalTypes(); + } + return _statusTypes; + } + + /** + * Returns a list of the types of signals that can be sent to + * a process on the remote system. + * @return the signal types, or null if there are none, or they cannot be found. + */ + private String[] internalGetSignalTypes() + { + try + { + DataElement sigTypesElement = getSignalTypesMinerElement(); + String sigTypesOutput = sigTypesElement.getValue(); + String[] lines = sigTypesOutput.trim().split("\\s+"); + if (lines == null) throw new Exception(); + return lines; + } + catch (Exception e) + { + // SystemPlugin.logError("UniversalProcessSubSystemImpl.getSignalTypes() 'kill -l' command failed.", e); + return null; + } + } + + protected DataElement getSignalTypesMinerElement() + { + return getDataStore().find(_minerElement, DE.A_NAME, "universal.killinfo"); + } + + public void initService(IProgressMonitor monitor) + { + initMiner(monitor); + } + + public boolean isInitialized() + { + if (_procMinerStatus != null) + { + DStoreStatusMonitor smon = getStatusMonitor(getDataStore()); + return smon.determineStatusDone(_procMinerStatus); + } + return false; + } + + protected void waitForInitialize(IProgressMonitor monitor) + { + if (_procMinerStatus!= null) + { + DStoreStatusMonitor smon = getStatusMonitor(getDataStore()); + try + { + smon.waitForUpdate(_procMinerStatus, monitor); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + getMinerElement(); + } + } + + protected void initMiner(IProgressMonitor monitor) + { + DataElement fsElement = getMinerElement(); + if (fsElement == null) + { + if (getServerVersion() >= 8) + { + String minerId = getMinerId(); + String message = SystemMessage.sub(ServiceResources.DStore_Service_ProgMon_Initializing_Message, "&1", minerId); + monitor.beginTask(message, IProgressMonitor.UNKNOWN); + DataStore ds = getDataStore(); + if (_minerElement == null || _minerElement.getDataStore() != ds) + { + if (ds != null) + { + _procMinerStatus = ds.activateMiner(minerId); + + } + } + } + } + monitor.done(); + } + + protected String getMinerId() + { + return UniversalProcessMiner.MINER_ID; + } + + public int getServerVersion() + { + return getDataStore().getServerVersion(); + } + + public int getServerMinor() + { + return getDataStore().getServerMinor(); + } + + protected String getProcessMinerId() + { + return UniversalProcessMiner.MINER_ID; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/rmtservice/DStoreRemoteServiceService.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/rmtservice/DStoreRemoteServiceService.java new file mode 100644 index 00000000000..8d55dcd7b48 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/rmtservice/DStoreRemoteServiceService.java @@ -0,0 +1,42 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore.rmtservice; + +import org.eclipse.dstore.core.java.IRemoteClassInstance; +import org.eclipse.dstore.core.model.IDataStoreProvider; +import org.eclipse.rse.services.dstore.AbstractDStoreService; + +public class DStoreRemoteServiceService extends AbstractDStoreService +{ + + public DStoreRemoteServiceService(IDataStoreProvider dataStoreProvider) + { + super(dataStoreProvider); + } + + protected String getMinerId() + { + // TODO Auto-generated method stub + return null; + } + + public void runRemoteService(IRemoteClassInstance serviceClass) + { + getDataStore().runRemoteClassInstance(serviceClass); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/search/DStoreSearchResultConfiguration.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/search/DStoreSearchResultConfiguration.java new file mode 100644 index 00000000000..92c91573bf6 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/search/DStoreSearchResultConfiguration.java @@ -0,0 +1,51 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore.search; + +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.extra.internal.extra.DomainEvent; +import org.eclipse.dstore.extra.internal.extra.IDomainListener; +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.search.AbstractSearchResultConfiguration; +import org.eclipse.rse.services.search.IHostSearchResultSet; +import org.eclipse.rse.services.search.ISearchService; + +public abstract class DStoreSearchResultConfiguration extends AbstractSearchResultConfiguration implements IDomainListener +{ + protected DataElement _status; + public DStoreSearchResultConfiguration(IHostSearchResultSet set, Object searchObject, SystemSearchString searchString, ISearchService searchService) + { + super(set, searchObject, searchString, searchService); + } + + public void setStatusObject(DataElement status) + { + _status = status; + // don't need this anymore + //_status.getDataStore().getDomainNotifier().addDomainListener(this); + } + + public DataElement getStatusObject() + { + return _status; + } + + public boolean listeningTo(DomainEvent e) + { + return e.getParent() == _status; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/search/DStoreSearchService.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/search/DStoreSearchService.java new file mode 100644 index 00000000000..d6c57bdf33f --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/search/DStoreSearchService.java @@ -0,0 +1,144 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore.search; + +import java.util.ArrayList; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.core.model.IDataStoreProvider; +import org.eclipse.rse.dstore.universal.miners.filesystem.UniversalFileSystemMiner; +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.dstore.AbstractDStoreService; +import org.eclipse.rse.services.dstore.ServiceResources; +import org.eclipse.rse.services.dstore.files.DStoreHostFile; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.search.IHostSearchConstants; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.services.search.ISearchService; + + + +public class DStoreSearchService extends AbstractDStoreService implements ISearchService +{ + public DStoreSearchService(IDataStoreProvider provider) + { + super(provider); + } + + public String getName() + { + return ServiceResources.DStore_Search_Service_Label; + } + + protected String getMinerId() + { + return UniversalFileSystemMiner.MINER_ID; + } + + public void search(IProgressMonitor monitor, IHostSearchResultConfiguration searchConfig, IFileService fileService) + { + DStoreHostFile searchTarget = (DStoreHostFile) searchConfig.getSearchTarget(); + + SystemSearchString searchString = searchConfig.getSearchString(); + String textString = searchString.getTextString(); + boolean isCaseSensitive = searchString.isCaseSensitive(); + boolean isTextRegex = searchString.isTextStringRegex(); + String fileNamesString = searchString.getFileNamesString(); + boolean isFileNamesRegex = searchString.isFileNamesRegex(); + boolean includeArchives = searchString.isIncludeArchives(); + boolean includeSubfolders = searchString.isIncludeSubfolders(); + String classificationString = searchString.getClassificationString(); + + + DataElement deObj = searchTarget.getDataElement(); + DataStore ds = getDataStore(); + + DataElement queryCmd = ds.localDescriptorQuery(deObj.getDescriptor(), "C_SEARCH"); + + if (queryCmd != null) + { + ArrayList argList = setSearchAttributes(textString, isCaseSensitive, isTextRegex, fileNamesString, isFileNamesRegex, includeArchives, includeSubfolders, classificationString, true); + + DataElement status = ds.command(queryCmd, argList, deObj); + DStoreSearchResultConfiguration config = (DStoreSearchResultConfiguration) searchConfig; + config.setStatusObject(status); + + try + { + getStatusMonitor(ds).waitForUpdate(status, monitor); + config.setStatus(IHostSearchConstants.FINISHED); + } + catch (Exception e) + { + config.setStatus(IHostSearchConstants.CANCELLED); + } + } + } + + private ArrayList setSearchAttributes( + String textString, + boolean isCaseSensitive, + boolean isTextRegex, + String fileNamesString, + boolean isFileNamesRegex, + boolean includeArchives, + boolean includeSubfolders, + String classificationString, + boolean showHidden) + { + + DataStore ds = getDataStore(); + DataElement universaltemp = getMinerElement(); + + // create the argument data elements + DataElement arg1 = ds.createObject(universaltemp, textString, String.valueOf(isCaseSensitive), String.valueOf(isTextRegex)); + DataElement arg2 = ds.createObject(universaltemp, fileNamesString, String.valueOf(isFileNamesRegex), classificationString); + DataElement arg3 = ds.createObject(universaltemp, String.valueOf(includeArchives), String.valueOf(includeSubfolders), String.valueOf(showHidden)); + + // add the arguments to the argument list + ArrayList argList = new ArrayList(); + argList.add(arg1); + argList.add(arg2); + argList.add(arg3); + + return argList; + } + + public void cancelSearch(IProgressMonitor monitor, IHostSearchResultConfiguration searchConfig) + { + DStoreSearchResultConfiguration config = (DStoreSearchResultConfiguration) searchConfig; + DataElement status = config.getStatusObject(); + + if (status != null) + { + DataElement command = status.getParent(); + DataStore dataStore = command.getDataStore(); + DataElement cmdDescriptor = command.getDescriptor(); + DataElement cancelDescriptor = dataStore.localDescriptorQuery(cmdDescriptor, "C_CANCEL"); + + if (cancelDescriptor != null) + { + dataStore.command(cancelDescriptor, command); + } + } + } + + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/shells/DStoreHostShell.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/shells/DStoreHostShell.java new file mode 100644 index 00000000000..78c68431f58 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/shells/DStoreHostShell.java @@ -0,0 +1,72 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore.shells; + +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.rse.internal.services.dstore.shell.DStoreShellOutputReader; +import org.eclipse.rse.internal.services.dstore.shell.DStoreShellThread; +import org.eclipse.rse.services.dstore.util.DStoreStatusMonitor; +import org.eclipse.rse.services.shells.AbstractHostShell; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IHostShellOutputReader; + + +public class DStoreHostShell extends AbstractHostShell implements IHostShell +{ + private DStoreShellThread _shellThread; + private IHostShellOutputReader _stdoutHandler; + private IHostShellOutputReader _stderrHandler; + private DataElement _status; + private DStoreStatusMonitor _statusMonitor; + + public DStoreHostShell(DStoreStatusMonitor statusMonitor, DataStore dataStore, String initialWorkingDirectory, String invocation, String encoding, String[] environment) + { + _shellThread = new DStoreShellThread(dataStore, initialWorkingDirectory, invocation, encoding, environment); + _status = _shellThread.getStatus(); + _stdoutHandler = new DStoreShellOutputReader(this, _status, false); + _stderrHandler = new DStoreShellOutputReader(this, _status,true); + _statusMonitor = statusMonitor; + } + + public boolean isActive() + { + return !_statusMonitor.determineStatusDone(_status); + } + + public void writeToShell(String command) + { + _shellThread.writeToShell(command); + } + + public IHostShellOutputReader getStandardOutputReader() + { + return _stdoutHandler; + } + + public IHostShellOutputReader getStandardErrorReader() + { + return _stderrHandler; + } + + public void exit() + { + writeToShell("exit"); + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/shells/DStoreShellService.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/shells/DStoreShellService.java new file mode 100644 index 00000000000..6724b4e8000 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/shells/DStoreShellService.java @@ -0,0 +1,201 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore.shells; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.core.model.IDataStoreProvider; +import org.eclipse.rse.dstore.universal.miners.command.CommandMiner; +import org.eclipse.rse.dstore.universal.miners.environment.EnvironmentMiner; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.services.dstore.AbstractDStoreService; +import org.eclipse.rse.services.dstore.ServiceResources; +import org.eclipse.rse.services.dstore.util.DStoreStatusMonitor; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IShellService; + + +public class DStoreShellService extends AbstractDStoreService implements IShellService +{ + protected String[] _envVars; + protected DataElement _envMinerElement; + protected DataElement _envMinerStatus; + + public DStoreShellService(IDataStoreProvider dataStoreProvider) + { + super(dataStoreProvider); + } + + + public String getName() + { + return ServiceResources.DStore_Shell_Service_Label; + } + + public String getDescription() + { + return ServiceResources.DStore_Shell_Service_Description; + } + + + public IHostShell launchShell(IProgressMonitor monitor, String initialWorkingDirectory, String[] environment) + { + if (!isInitialized()) + { + waitForInitialize(null); + } + return launchShell(monitor, initialWorkingDirectory, null, environment); + } + + public IHostShell launchShell(IProgressMonitor monitor, String initialWorkingDirectory, String encoding, String[] environment) + { + if (!isInitialized()) + { + waitForInitialize(null); + } + return new DStoreHostShell(getStatusMonitor(getDataStore()), getDataStore(), initialWorkingDirectory, ">", encoding, environment); + } + + public IHostShell runCommand(IProgressMonitor monitor, String initialWorkingDirectory, String command, + String[] environment) + { + if (!isInitialized()) + { + waitForInitialize(null); + } + return runCommand(monitor, initialWorkingDirectory, command, null, environment); + } + + public IHostShell runCommand(IProgressMonitor monitor, String initialWorkingDirectory, String command, + String encoding, String[] environment) + { + if (!isInitialized()) + { + waitForInitialize(null); + } + return new DStoreHostShell(getStatusMonitor(getDataStore()), getDataStore(), initialWorkingDirectory, command, encoding, environment); + } + + public String[] getHostEnvironment() + { + if (_envVars == null || _envVars.length == 0) + { + List envVars = new ArrayList(); + DataStore ds = getDataStore(); + DataElement envMinerData = ds.findMinerInformation(getEnvSystemMinerId()); + if (envMinerData != null) + { + DataElement systemEnvironment = ds.find(envMinerData, DE.A_NAME, "System Environment", 1); + if (systemEnvironment != null && systemEnvironment.getNestedSize() > 0) + { + for (int i = 0; i < systemEnvironment.getNestedSize(); i++) + { + DataElement var = systemEnvironment.get(i); + envVars.add(var.getValue()); + } + } + } + _envVars = (String[])envVars.toArray(new String[envVars.size()]); + } + return _envVars; + } + + protected String getMinerId() + { + return CommandMiner.MINER_ID; + } + + protected String getEnvSystemMinerId() + { + return EnvironmentMiner.MINER_ID; + } + + protected String getOldEnvSystemMinerId() + { + return "com.ibm.etools.systems.dstore.miners.environment.EnvironmentMiner"; + } + + public boolean isInitialized() + { + if (_initializeStatus != null) + { + DStoreStatusMonitor smon = getStatusMonitor(getDataStore()); + return smon.determineStatusDone(_initializeStatus); + } + return false; + } + + protected void waitForInitialize(IProgressMonitor monitor) + { + if (_envMinerStatus!= null) + { + DStoreStatusMonitor smon = getStatusMonitor(getDataStore()); + try + { + smon.waitForUpdate(_envMinerStatus, monitor); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + getMinerElement(getEnvSystemMinerId()); + } + super.waitForInitialize(monitor); + } + + protected void initMiner(IProgressMonitor monitor) + { + // init env miner first + + if (getServerVersion() >= 8) + { + String minerId = getEnvSystemMinerId(); + String message = SystemMessage.sub(ServiceResources.DStore_Service_ProgMon_Initializing_Message, "&1", minerId); + monitor.beginTask(message, IProgressMonitor.UNKNOWN); + DataStore ds = getDataStore(); + if (_envMinerElement == null || _envMinerElement.getDataStore() != ds) + { + if (ds != null) + { + _envMinerStatus = ds.activateMiner(minerId); + /* + DStoreStatusMonitor smon = getStatusMonitor(ds); + try + { + smon.waitForUpdate(status, monitor, 50); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + + getMinerElement(getEnvSystemMinerId()); + */ + + + } + } + super.initMiner(monitor); + } + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/DStoreFileTransferStatusListener.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/DStoreFileTransferStatusListener.java new file mode 100644 index 00000000000..bae8db531c8 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/DStoreFileTransferStatusListener.java @@ -0,0 +1,122 @@ +/******************************************************************************** + * Copyright (c) 2004, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore.util; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.services.clientserver.IServiceConstants; +import org.eclipse.swt.widgets.Shell; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.core.model.DataStoreSchema; + +/** + * @author mjberger + * + * copyright 2003 IBM Corp. + */ +public class DStoreFileTransferStatusListener extends StatusChangeListener +{ + + protected String _remotePath; + protected DataElement _log; + protected DataElement _statusElement; + + public DStoreFileTransferStatusListener(String remotePath, Shell shell, IProgressMonitor monitor, DataStore ds, DataElement uploadLog) throws Exception + { + super(shell, monitor); + _remotePath = remotePath.replace('\\', '/'); + + _log = uploadLog; + if (_log == null) + { + throw new Exception("Could not find log in DataStore."); + } + setStatus(findOrCreateUploadStatus(ds)); + } + + protected DataElement findOrCreateUploadStatus(DataStore ds) + { + DataElement result = ds.find(_log, DE.A_NAME, _remotePath,1); + + // first upload, this will always ben null + // but also need to handle case where it's been uploaded before in the sessoin (i.e. for reseting values) + if (result == null) + { + result = _log.getDataStore().createObject(_log, "uploadstatus", _remotePath); + result.setAttribute(DE.A_SOURCE, "running"); + result.setAttribute(DE.A_VALUE, ""); + + DataElement cmd = ds.findCommandDescriptor(DataStoreSchema.C_SET); + + DataElement setstatus = ds.command(cmd, _log, true); + /* + try + { + StatusMonitorFactory.getInstance().getStatusMonitorFor(system, ds).waitForUpdate(setstatus); + } + catch (Exception e) + { + } + */ + // DKM: no need for this - turns out the problem was that we need to send the LOG not the result - + // since the server needs to know the parent! + //ds.waitUntil(setstatus, "done"); + + } + else + { + + result.setAttribute(DE.A_SOURCE, "running"); + result.setAttribute(DE.A_VALUE, ""); + } + _statusElement = result; + return result; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.services.dstore.util.StatusChangeListener#determineStatusDone() + */ + protected boolean determineStatusDone() + { + return getStatus().getAttribute(DE.A_SOURCE).equals(IServiceConstants.SUCCESS) || getStatus().getAttribute(DE.A_SOURCE).equals(IServiceConstants.FAILED); + + } + + public boolean uploadHasFailed() + { + return getStatus().getAttribute(DE.A_SOURCE).equals(IServiceConstants.FAILED); + } + + public String getErrorMessage() + { + return getStatus().getAttribute(DE.A_VALUE); + } + + public String getRemotePath() + { + return _remotePath; + } + + public void setRemotePath(String remotePath) + { + _remotePath = remotePath; + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/DStoreStatusMonitor.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/DStoreStatusMonitor.java new file mode 100644 index 00000000000..fccc4148a38 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/DStoreStatusMonitor.java @@ -0,0 +1,399 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore.util; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.extra.internal.extra.DomainEvent; +import org.eclipse.dstore.extra.internal.extra.IDomainListener; +import org.eclipse.dstore.extra.internal.extra.IDomainNotifier; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + + +/* + * This utility class can be used to monitor the status of one more more status DataElements. + * Only one instanceof of this class is required per DataStore for use in monitoring statuses. + * This is intended to be used in place of StatusChangeListeners + * + * *

+ * The following is one example of the use of the StatusMonitor. The code: + *

+ *    		DataElement status = dataStore.command(dsCmd, args, deObj);
+ *
+ *			StatusMonitor smon = StatusMonitorFactory.getInstance().getStatusMonitorFor(getSystem(), ds);
+ *			smon.waitForUpdate(status, monitor);
+ * 
+ */ +public class DStoreStatusMonitor implements IDomainListener +{ + + protected Shell _shell; + + protected boolean _networkDown = false; + + protected List _workingStatuses; + protected List _cancelledStatuses; + protected List _doneStatuses; + + protected DataStore _dataStore; + + protected class FindShell implements Runnable + { + private Shell shell; + + /** + * @see Runnable#run() + */ + public void run() + { + Display display = Display.getCurrent(); + if (display != null) + { + try { + Shell[] shells = Display.getCurrent().getShells(); + for (int loop = 0; loop < shells.length && shell == null; loop++) { + if (shells[loop].isEnabled()) { + shell = shells[loop]; + } + } + } catch (Exception e) { + } + } + } + } + + /** + * Construct a StatusChangeListener + * + * @param dataStore the dataStore associated with this monitor + */ + public DStoreStatusMonitor(DataStore dataStore) + { + _dataStore = dataStore; + reInit(); + } + + + + public void reInit() + { + _networkDown = false; + _workingStatuses = new ArrayList(); + _doneStatuses = new ArrayList(); + _cancelledStatuses = new ArrayList(); + IDomainNotifier notifier = _dataStore.getDomainNotifier(); + if (notifier != null) + { + notifier.addDomainListener(this); + } + } + + public DataStore getDataStore() + { + return _dataStore; + } + + public void dispose() + { + _workingStatuses.clear(); + _doneStatuses.clear(); + _cancelledStatuses.clear(); + _dataStore.getDomainNotifier().removeDomainListener(this); + } + + /** + * @see IDomainListener#listeningTo(DomainEvent) + */ + public boolean listeningTo(DomainEvent event) + { + if (_workingStatuses.size() == 0) + { + return true; + } + + DataElement parent = (DataElement)event.getParent(); + if (_workingStatuses.contains(parent)) + { + return determineStatusDone(parent); + } + + return false; + } + + + + /** + * @see IDomainListener#domainChanged(DomainEvent) + */ + public void domainChanged(DomainEvent event) + { + if (_workingStatuses.size() == 0) + { + return; + } + + DataElement parent = (DataElement)event.getParent(); + if (_workingStatuses.contains(parent)) + { + boolean isStatusDone = determineStatusDone(parent); + if (isStatusDone) + { + setDone(parent); + notifyUpdate(); + } + } + } + + + /** + * Determines whether the status is done. + * @return true if status done, false otherwise. + */ + public boolean determineStatusDone(DataElement status) + { + return status.getAttribute(DE.A_VALUE).equals("done") || status.getAttribute(DE.A_NAME).equals("done"); + } + + /** + * @return true if the the monitor is passive. In this case it is false. + */ + public boolean isPassiveCommunicationsListener() + { + return false; + } + + /** + * setDone(boolean) + */ + public synchronized void setDone(DataElement status) + { + _workingStatuses.remove(status); + _doneStatuses.add(status); + } + + + public synchronized void setCancelled(DataElement status) + { + _workingStatuses.remove(status); + _cancelledStatuses.add(status); + } + + public synchronized void setWorking(DataElement status) + { + _workingStatuses.add(status); + } + + + public boolean wasCancelled(DataElement status) + { + if (_cancelledStatuses.contains(status)) + { + return true; + } + return false; + } + + /** + * @see IDomainListener#getShell() + */ + public Shell getShell() + { + // dy: DomainNotifier (which calls this method) requires the shell not be disposed + //if (shell == null) { + if (_shell == null || _shell.isDisposed()) + { + FindShell findShell = new FindShell(); + Display.getDefault().syncExec(findShell); + _shell = findShell.shell; + } + return _shell; + } + + + + /** + * Test if the StatusChangeListener returned because the network connection to the + * remote system was broken. + */ + public boolean isNetworkDown() + { + return _networkDown; + } + + public DataElement waitForUpdate(DataElement status) throws InterruptedException + { + return waitForUpdate(status, null, 0); + } + + public DataElement waitForUpdate(DataElement status, IProgressMonitor monitor) throws InterruptedException + { + return waitForUpdate(status, monitor, 0); + } + + public DataElement waitForUpdate(DataElement status, int wait) throws InterruptedException + { + return waitForUpdate(status, null, wait); + } + + public synchronized DataElement waitForUpdate(DataElement status, IProgressMonitor monitor, int wait) throws InterruptedException + { + if (_networkDown && status.getDataStore().isConnected()) + { + reInit(); + } + if (determineStatusDone(status)) + { + setDone(status); + return status; + } + + setWorking(status); + + Display display = Display.getCurrent(); + + + // Prevent infinite looping by introducing a threshold for wait + int WaitThreshold = 600; //default. sleep(100ms) for 600 times + if ( wait > 0 ) + WaitThreshold = wait*10; // 1 second means 10 sleep(100ms) + else if ( wait == -1 ) // force a diagnostic + WaitThreshold = -1; + + + if (display != null) + { + // Current thread is UI thread + while (_workingStatuses.contains(status)) + { + // Process everything on event queue + while (display.readAndDispatch()) {} + + if ((monitor != null) && (monitor.isCanceled())) + { + setCancelled(status); + throw new InterruptedException(); + } + + boolean statusDone = determineStatusDone(status); + + if (statusDone) + { + setDone(status); + } + else + { + waitForUpdate(); + //Thread.sleep(100); + + if (WaitThreshold > 0) // update timer count if + // threshold not reached + --WaitThreshold; // decrement the timer count + + if (WaitThreshold == 0) + { + // no diagnostic factory but there is a timeout + return status; // returning the undone status object + } + else if (_networkDown) + { + dispose(); + throw new InterruptedException(); + } + } + } + + } + else + { + // Current thread is not UI thread + while (_workingStatuses.contains(status)) + { + + if ((monitor != null) && (monitor.isCanceled())) + { + setCancelled(status); + throw new InterruptedException(); + } + + boolean statusDone = determineStatusDone(status); + + if (statusDone) + { + setDone(status); + } + else + { + waitForUpdate(); + //Thread.sleep(200); + + if (WaitThreshold > 0) // update timer count if + // threshold not reached + --WaitThreshold; // decrement the timer count + + if (WaitThreshold == 0) + { + // no diagnostic factory but there is a timeout + return status; // returning the undone status object + } + else if (_networkDown) + { + dispose(); + throw new InterruptedException(); + } + } + } + } + + + return status; + } + + + /** + * Causes the current thread to wait until this class request has been + * fulfilled. + */ + public synchronized void waitForUpdate() + { + try + { + wait(200); + } + catch (InterruptedException e) + { + e.printStackTrace(); + return; + } + } + + /** + * Causes all threads waiting for this class request to be filled + * to wake up. + */ + public synchronized void notifyUpdate() + { + notifyAll(); + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/DownloadListener.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/DownloadListener.java new file mode 100644 index 00000000000..1cc689acf3b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/DownloadListener.java @@ -0,0 +1,335 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore.util; + + + +import java.io.File; +import java.text.MessageFormat; + +import org.eclipse.core.runtime.IProgressMonitor; + +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.services.dstore.ServiceResources; +import org.eclipse.swt.widgets.Display; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.extra.internal.extra.DomainEvent; +import org.eclipse.dstore.extra.internal.extra.IDomainListener; + +public class DownloadListener implements IDomainListener,IUniversalDataStoreConstants +{ + + private DataElement _status; + private IProgressMonitor _monitor; + private DataStore _dataStore; + private File _localFile; + private Display _display; + + private boolean _networkDown = false; + private boolean _isDone = false; + private boolean _isCancelled = false; + private long _totalBytesNotified = 0; + private long _totalLength; + + private static String _percentMsg = SystemMessage.sub(SystemMessage.sub(SystemMessage.sub(ServiceResources.DStore_Service_Percent_Complete_Message, "&0", "{0}"), "&1", "{1}"), "&2", "{2}"); + + public DownloadListener(IProgressMonitor monitor, DataElement status, File localFile, String remotePath, long totalLength) + { + _monitor = monitor; + _status = status; + _totalLength = totalLength; + _display = Display.getCurrent(); + + if (_status == null) + { + System.out.println("Status is null!"); + } + + _dataStore = _status.getDataStore(); + _dataStore.getDomainNotifier().addDomainListener(this); + + _localFile = localFile; + + if (monitor != null) + { + if (_display != null) + { + while (_display.readAndDispatch()) + { + } + } + + } + if (_status.getValue().equals("done")) + { + updateDownloadState(); + setDone(true); + } + + } + public boolean isCancelled() + { + return _isCancelled; + } + + public DataElement getStatus() + { + return _status; + } + + /** + * @see IDomainListener#listeningTo(DomainEvent) + */ + public boolean listeningTo(DomainEvent event) + { + if (_status == null) + { + return false; + } + + if (_status == event.getParent()) + { + return true; + } + + return false; + } + + /** + * @see IDomainListener#domainChanged(DomainEvent) + */ + public void domainChanged(DomainEvent event) + { + if (_status.getValue().equals("done")) + { + + if (_status == event.getParent()) + { + setDone(true); + } + } + else + { + updateDownloadState(); + } + } + + private void updateDownloadState() + { + + if (_monitor != null) + { + long currentLength = _localFile.length(); + long delta = currentLength - _totalBytesNotified; + if (delta > 0) + { + //System.out.println(_status.getAttribute(DE.A_SOURCE)); + _monitor.worked((int)delta); + + try + { + long percent = (currentLength * 100) / _totalLength; + + + StringBuffer current = new StringBuffer(); + current.append(currentLength /KB_IN_BYTES); + current.append(" KB"); + + StringBuffer total = new StringBuffer(); + total.append(_totalLength / KB_IN_BYTES); + total.append(" KB"); + + StringBuffer percentBuf = new StringBuffer(); + percentBuf.append(percent); + percentBuf.append("%"); + + String str = MessageFormat.format(_percentMsg, new Object[] {current, total, percentBuf}); + + _monitor.subTask(str); + + if (_display != null) + { + while (_display.readAndDispatch()) + { + } + } + } + catch (Exception e) + { + } + _totalBytesNotified = currentLength; + } + } + + if (!_status.getDataStore().getStatus().getName().equals("okay")) + { + _networkDown = true; + } + } + + /** + * setDone(boolean) + */ + public void setDone(boolean done) + { + this._isDone = done; + if (done) + { + updateDownloadState(); + _status.getDataStore().getDomainNotifier().removeDomainListener(this); + + } + } + + + + /** + * + */ + public boolean wasCancelled() + { + return _isCancelled; + } + + + + /** + * Wait for the the status DataElement to be refreshed + * + * @param + * ICommunicationsDiagnosticFactory factory : for creating system specific diagnostic class instance + * Int wait : threshold for starting diagnostic. Default is 60 seconds; a zero means to use the default. + * -1 means to force a timeout; mainly for testing purpose. + * + * @return The status DataElement after it has been updated, or the user + * has pressed cancel + * + * @throws InterruptedException if the thread was interrupted. + */ + public DataElement waitForUpdate() throws InterruptedException + { + return waitForUpdate(0); //No diagnostic + } + + + public DataElement waitForUpdate(int wait) throws InterruptedException + { + Display display = _display; + + if (wait > 0) + { + } + else if (wait == -1) + { + } + + + + if (display != null) + { + + // Current thread is UI thread + while (!_isDone && !_isCancelled && !_networkDown) + { + // Process everything on event queue + while (display.readAndDispatch()) + { + } + + if ((_monitor != null) && (_monitor.isCanceled())) + { + // cancel remote request + cancelDownload(); + _isCancelled = true; + setDone(true); + } + else if (_networkDown) + { + _isCancelled = true; + setDone(true); + throw new InterruptedException(); + } + + if (getStatus().getAttribute(DE.A_NAME).equals("done")) + { + setDone(true); + } + else + { + Thread.sleep(100); + updateDownloadState(); + } + } + + } + else + { + // Current thread is not UI thread + while (!_isDone && !_isCancelled && !_networkDown) + { + if ((_monitor != null) && (_monitor.isCanceled())) + { + cancelDownload(); + _isCancelled = true; + setDone(true); + } + else if (_networkDown) + { + _isCancelled = true; + setDone(true); + throw new InterruptedException(); + } + + if (getStatus().getAttribute(DE.A_NAME).equals("done")) + { + setDone(true); + } + else + { + Thread.sleep(100); + updateDownloadState(); + } + } + } + return _status; + } + + public void cancelDownload() + { + DataElement status = _status; + if (status != null) + { + DataElement command = status.getParent(); + DataStore dataStore = command.getDataStore(); + DataElement cmdDescriptor = command.getDescriptor(); + DataElement cancelDescriptor = dataStore.localDescriptorQuery(cmdDescriptor, "C_CANCEL"); + if (cancelDescriptor != null) + { + dataStore.command(cancelDescriptor, command); + } + _localFile.delete(); + } + if (_monitor != null) + { + _monitor.done(); + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/FileSystemMessageUtil.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/FileSystemMessageUtil.java new file mode 100644 index 00000000000..96dc92a9b02 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/FileSystemMessageUtil.java @@ -0,0 +1,37 @@ +package org.eclipse.rse.services.dstore.util; + +import org.eclipse.dstore.core.model.DataElement; + +public class FileSystemMessageUtil +{ + + /** + * Returns the source message (first part of the source attribute) for this element. + * + * @return the source message + */ + public static String getSourceMessage(DataElement element) + { + String source = element.getSource(); + if (source == null) return null; + if (source.equals("")) return ""; + int sepIndex = source.indexOf("|"); + if (sepIndex == -1) return source; + else return source.substring(0, sepIndex); + } + + /** + * Returns the source location (second part of the source attribute) for this element. + * + * @return the source location + */ + public static String getSourceLocation(DataElement element) + { + String source = element.getSource(); + if (source == null) return null; + if (source.equals("")) return ""; + int sepIndex = source.indexOf("|"); + if (sepIndex == -1) return ""; + else return source.substring(sepIndex+1); + } +} diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/StatusChangeListener.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/StatusChangeListener.java new file mode 100644 index 00000000000..bc61d9c5711 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/services/dstore/util/StatusChangeListener.java @@ -0,0 +1,330 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.dstore.util; + + +import java.util.Vector; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.extra.internal.extra.DomainEvent; +import org.eclipse.dstore.extra.internal.extra.IDomainListener; + +/* + * Utility class for determining when a DataStore command is complete via the status. + */ +public class StatusChangeListener implements IDomainListener +{ + + protected DataElement target; + protected Shell shell; + protected IProgressMonitor monitor; + + protected boolean _networkDown = false; + protected boolean done = false; + protected boolean cancelled = false; + + protected Vector historyOfTargets; + + protected class FindShell implements Runnable { + private Shell shell; + + /** + * @see Runnable#run() + */ + public void run() { + try { + Shell[] shells = Display.getCurrent().getShells(); + for (int loop = 0; loop < shells.length && shell == null; loop++) { + if (shells[loop].isEnabled()) { + shell = shells[loop]; + } + } + } catch (Exception e) { + } + } + } + + + /** + * Construct a StatusChangeListener + * + * @param shell A valid Shell object + * + * @param monitor A progress monitor if you want this object to check if + * the user presses cancel while waiting for the status object + * to be updated + * + * @param target The status DataElement for which you wish to wait for an update + */ + public StatusChangeListener(Shell shell, IProgressMonitor monitor, DataElement target) { + this.shell = shell; + this.monitor = monitor; + this.target = target; + historyOfTargets = new Vector(); + } + + + public StatusChangeListener(Shell shell, IProgressMonitor monitor) { + this(shell, monitor, null); + } + + +// public StatusChangeListener(Shell shell, DataElement target) { +// this(shell, null, target); +// } + + + /** + * + */ + public void setStatus(DataElement p_target) + { + this.target = p_target; + + for (int i = 0; i < historyOfTargets.size(); i++) + { + if (target == historyOfTargets.elementAt(i)) + { + setDone( true ); + historyOfTargets.clear(); + return; + } + } + + historyOfTargets.clear(); + } + + /** + * + */ + public DataElement getStatus() + { + return target; + } + + /** + * @see IDomainListener#listeningTo(DomainEvent) + */ + public boolean listeningTo(DomainEvent event) { + if (target == null) + { + return true; + } + + if (target == event.getParent()) { + return true; + } + + return false; + } + + + /** + * @see IDomainListener#domainChanged(DomainEvent) + */ + public void domainChanged(DomainEvent event) { + if (target == null) + { + if (historyOfTargets.size() < 1000) + { + historyOfTargets.addElement(event.getParent()); + } + } + + if (target == event.getParent()) + { + boolean isStatusDone = determineStatusDone(); + + if (isStatusDone) + { + setDone( true ); + } + } + } + + + /** + * setDone(boolean) + */ + public void setDone(boolean done) + { + this.done = done; + } + + /** + * @see IDomainListener#getShell() + */ + public Shell getShell() { + // dy: DomainNotifier (which calls this method) requires the shell not be disposed + //if (shell == null) { + if (shell == null || shell.isDisposed()) + { + FindShell findShell = new FindShell(); + Display.getDefault().syncExec(findShell); + shell = findShell.shell; + } + return shell; + } + + /** + * + */ + public boolean wasCancelled() { + return cancelled; + } + + + + + /** + * Wait for the the status DataElement to be refreshed + * + * @param + * ICommunicationsDiagnosticFactory factory : for creating system specific diagnostic class instance + * Int wait : threshold for starting diagnostic. Default is 60 seconds; a zero means to use the default. + * -1 means to force a timeout; mainly for testing purpose. + * + * @return The status DataElement after it has been updated, or the user + * has pressed cancel + * + * @throws InterruptedException if the thread was interrupted. + */ + public DataElement waitForUpdate() throws InterruptedException + { + return waitForUpdate( 0); //No diagnostic + } + + + public DataElement waitForUpdate(int wait) throws InterruptedException + { + boolean statusDone = determineStatusDone(); + if (statusDone) + { + setDone(true); + } + else + { + Display display = Display.getCurrent(); + + if ( wait > 0 ) + { + } + else if ( wait == -1 ) + { + } + + + if (display != null) { + if (shell == null || shell.isDisposed()) { + shell = Display.getDefault().getActiveShell(); + } + // Current thread is UI thread + while (!done && !cancelled) { + // Process everything on event queue + while (display.readAndDispatch()) { + } + + if ((monitor != null) && (monitor.isCanceled())) { + cancelled = true; + target.getDataStore().getDomainNotifier().removeDomainListener(this); + throw new InterruptedException(); + } + + statusDone = determineStatusDone(); + + if (statusDone) + { + setDone(true); + } + else + { + Thread.sleep(100); + if (_networkDown) + { + target.getDataStore().getDomainNotifier().removeDomainListener(this); + throw new InterruptedException(); + } + } + } + + } else { + // Current thread is not UI thread + while (!done && !cancelled) + { + + if ((monitor != null) && (monitor.isCanceled())) + { + cancelled = true; + target.getDataStore().getDomainNotifier().removeDomainListener(this); + throw new InterruptedException(); + } + + statusDone = determineStatusDone(); + + if (statusDone) + { + setDone(true); + } + else { + Thread.sleep(100); + + if (_networkDown) + { + target.getDataStore().getDomainNotifier().removeDomainListener(this); + throw new InterruptedException(); + } + } + } + } + } + + // Reset done so we can detect the next event if waitForUpdate + // is called again + done = false; + + return target; + } + + /** + * Determines whether the status is done. + * @return true if status done, false otherwise. + */ + protected boolean determineStatusDone() { + return getStatus().getAttribute(DE.A_VALUE).equals("done") || getStatus().getAttribute(DE.A_NAME).equals("done"); + } + + /** + * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#isPassiveCommunicationsListener() + */ + public boolean isPassiveCommunicationsListener() { + return false; + } + + + /** + * Test if the StatusChangeListener returned because the network connection to the + * remote system was broken. + */ + public boolean isNetworkDown() { + return _networkDown; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/.classpath b/rse/plugins/org.eclipse.rse.services.files.ftp/.classpath new file mode 100644 index 00000000000..751c8f2e504 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/.cvsignore b/rse/plugins/org.eclipse.rse.services.files.ftp/.cvsignore new file mode 100644 index 00000000000..ba077a4031a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/.project b/rse/plugins/org.eclipse.rse.services.files.ftp/.project new file mode 100644 index 00000000000..88dc1254cc4 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/.project @@ -0,0 +1,28 @@ + + + org.eclipse.rse.services.files.ftp + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.services.files.ftp/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..220bd0772b9 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin.name +Bundle-SymbolicName: org.eclipse.rse.services.files.ftp +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.rse.services.files.ftp.Activator +Bundle-Vendor: Eclipse.org +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.rse.services +Eclipse-LazyStart: true +Export-Package: org.eclipse.rse.services.files.ftp +Bundle-ClassPath: ftpfiles.jar diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/about.html b/rse/plugins/org.eclipse.rse.services.files.ftp/about.html new file mode 100644 index 00000000000..6f6b96c4c87 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/about.html @@ -0,0 +1,22 @@ + + + +About + + + +

About This Content

+ +

February 24, 2005

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content.

+ + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/about.properties b/rse/plugins/org.eclipse.rse.services.files.ftp/about.properties new file mode 100644 index 00000000000..a5c11a0586c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/about.properties @@ -0,0 +1,25 @@ +############################################################################### +# Copyright (c) 2000, 2006 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 +############################################################################### +# 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 FTP services\n\ +\n\ +Version: {featureVersion}\n\ +Build id: {0}\n\ +\n\ +(c) Copyright Eclipse contributors and others 2000, 2006. All rights reserved.\n\ +Visit http://www.eclipse.org/dsdp/tm/ diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/build.properties b/rse/plugins/org.eclipse.rse.services.files.ftp/build.properties new file mode 100644 index 00000000000..14606becee6 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/build.properties @@ -0,0 +1,12 @@ +bin.includes = META-INF/,\ + about.html,\ + about.properties,\ + plugin.properties,\ + ftpfiles.jar +src.includes = META-INF/,\ + about.html,\ + about.properties,\ + plugin.properties +source.ftpfiles.jar = src/ +jars.compile.order = ftpfiles.jar +output.ftpfiles.jar = bin/ diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/plugin.properties b/rse/plugins/org.eclipse.rse.services.files.ftp/plugin.properties new file mode 100644 index 00000000000..b928cbf8445 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/plugin.properties @@ -0,0 +1,12 @@ +############################################################################### +# Copyright (c) 2000, 2006 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 +############################################################################### + +plugin.name = RSE FTP services \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/Activator.java b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/Activator.java new file mode 100644 index 00000000000..e1ce504a063 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/Activator.java @@ -0,0 +1,70 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.files.ftp; + +import org.eclipse.ui.plugin.*; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class Activator extends AbstractUIPlugin { + + //The shared instance. + private static Activator plugin; + + /** + * The constructor. + */ + public Activator() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static Activator getDefault() { + 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("com.ibm.rse.universal.services.ftp", path); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPClientService.java b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPClientService.java new file mode 100644 index 00000000000..5a89d819eda --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPClientService.java @@ -0,0 +1,37 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.files.ftp; + +import java.io.IOException; + +import sun.net.ftp.FtpClient; + +public class FTPClientService extends FtpClient +{ + public int sendCommand(String command) + { + try + { + return issueCommand(command); + } + catch (IOException e) + { + e.printStackTrace(); + return -1; + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPHostFile.java b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPHostFile.java new file mode 100644 index 00000000000..bb513a395c7 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPHostFile.java @@ -0,0 +1,135 @@ +/******************************************************************************** + * Copyright (c) 2005, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.files.ftp; + +import java.io.File; + +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.files.IHostFile; + +public class FTPHostFile implements IHostFile +{ + private String _name; + private String _parentPath; + private boolean _isDirectory = false; + private boolean _isRoot = false; + private boolean _isArchive = false; + private long _lastModified = 0; + private long _size = 0; + + public FTPHostFile(String parentPath, String name, boolean isDirectory, boolean isRoot, long lastModified, long size) + { + _parentPath = parentPath; + _name = name; + _isDirectory = isDirectory; + _isRoot = isRoot; + _lastModified = lastModified; + _size = size; + _isArchive = internalIsArchive(); + } + + public String getName() + { + return _name; + } + + public boolean isHidden() + { + String name = getName(); + return name.charAt(0) == '.'; + + } + + public String getParentPath() + { + return _parentPath; + } + + public boolean isDirectory() + { + return _isDirectory; + } + + public boolean isFile() + { + return !(_isDirectory || _isRoot); + } + + public boolean isRoot() + { + return _isRoot; + } + + public boolean exists() + { + return true; + } + + public String getAbsolutePath() + { + + StringBuffer path = new StringBuffer(getParentPath()); + if (!_parentPath.endsWith("/")) + { + path.append('/'); + } + path.append(getName()); + + + return path.toString(); + } + + public long getSize() + { + return _size; + } + + public long getModifiedDate() + { + return _lastModified; + } + + public void renameTo(String newAbsolutePath) + { + int i = newAbsolutePath.lastIndexOf("/"); + if (i == -1) + { + _name = newAbsolutePath; + } + else + { + _parentPath = newAbsolutePath.substring(0, i); + _name = newAbsolutePath.substring(i+1); + } + + _isArchive = internalIsArchive(); + + + } + + protected boolean internalIsArchive() + { + return ArchiveHandlerManager.getInstance().isArchive(new File(getAbsolutePath())) + && !ArchiveHandlerManager.isVirtual(getAbsolutePath()); + } + + public boolean isArchive() + { + return _isArchive; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPLinuxDirectoryListingParser.java b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPLinuxDirectoryListingParser.java new file mode 100644 index 00000000000..6cd4ff8f5d2 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPLinuxDirectoryListingParser.java @@ -0,0 +1,80 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.files.ftp; + +import java.text.DateFormat; +import java.util.Calendar; +import java.util.Locale; + +public class FTPLinuxDirectoryListingParser implements IFTPDirectoryListingParser +{ + + public FTPHostFile getFTPHostFile(String line, String parentPath) + { + // Note this assumes that text is always formatted the same way + if (line == null) return null; + String[] tokens = line.split("\\s+", 9); + if (tokens.length < 9) return null; + String name = tokens[8]; + boolean isDirectory = line.charAt(0) == 'd'; + long length = 0; + long lastMod = 0; + if (tokens.length > 4) + { + try + { + length = Long.parseLong(tokens[tokens.length - 5]); + } + catch (NumberFormatException e) {} + + try + { + int i = tokens.length - 4; + int j = tokens.length - 3; + int k = tokens.length - 2; + String time = ""; + String year = ""; + if (tokens[k].indexOf(":") == -1) + { + time = "11:59 PM"; + year = tokens[k]; + } + else + { + String[] parts = tokens[k].split(":"); + int hours = Integer.parseInt(parts[0]); + boolean morning = hours < 12; // assumes midnight is 00:00 + if (morning) + { + if (hours == 0) + { + hours = 12; + } + } + time = hours + ":" + parts[1] + (morning? " AM" : " PM"); + year = "" + (Calendar.getInstance().get(Calendar.YEAR)); + } + + String date = tokens[i] + " " + tokens[j] + ", " + year + " " + time; + lastMod = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, new Locale("EN", "US")).parse(date).getTime(); + } + catch (Exception e) {} + } + return new FTPHostFile(parentPath, name, isDirectory, false, lastMod, length); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPService.java b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPService.java new file mode 100644 index 00000000000..6fa5eecae65 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPService.java @@ -0,0 +1,396 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.files.ftp; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.services.clientserver.NamePatternMatcher; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.files.AbstractFileService; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.files.IHostFile; + + +import sun.net.TelnetInputStream; +import sun.net.ftp.FtpClient; + + + +public class FTPService extends AbstractFileService implements IFileService, IFTPService +{ + private FTPClientService _ftpClient; + private String _userHome; + private IFTPDirectoryListingParser _ftpPropertiesUtil; + + + + private transient String _hostname; + private transient String _userId; + private transient String _password; + + public FTPService() + { + } + + public String getName() + { + return FTPServiceResources.FTP_File_Service_Name; + } + + public String getDescription() + { + return FTPServiceResources.FTP_File_Service_Description; + } + + public void setHostName(String hostname) + { + _hostname = hostname; + } + + public void setUserId(String userId) + { + _userId = userId; + } + + public void setPassword(String password) + { + _password = password; + } + + + public void connect() throws Exception + { + FtpClient ftp = getFTPClient(); + ftp.openServer(_hostname); + ftp.login(_userId, _password); + + _userHome = ftp.pwd(); + } + + protected void reconnect() + { + try + { + connect(); + } + catch (Exception e) + { + } + } + + public void disconnect() + { + try + { + getFTPClient().closeServer(); + _ftpClient = null; + } + catch (Exception e) + { + // e.printStackTrace(); + _ftpClient = null; + } + } + + public IFTPDirectoryListingParser getDirListingParser() + { + if (_ftpPropertiesUtil == null) + { + _ftpPropertiesUtil = new FTPLinuxDirectoryListingParser(); + } + return _ftpPropertiesUtil; + } + + public FTPClientService getFTPClient() + { + if (_ftpClient == null) + { + _ftpClient = new FTPClientService(); + } + return _ftpClient; + } + + public IHostFile getFile(IProgressMonitor monitor, String remoteParent, String fileName) + { + IHostFile[] matches = internalFetch(monitor, remoteParent, fileName, FILE_TYPE_FILES_AND_FOLDERS); + if (matches != null && matches.length > 0) + { + return matches[0]; + } + return null; + } + public boolean isConnected() + { + return getFTPClient().serverIsOpen(); + } + + + + + protected IHostFile[] internalFetch(IProgressMonitor monitor, String parentPath, String fileFilter, int fileType) + { + if (fileFilter == null) + { + fileFilter = "*"; + } + NamePatternMatcher filematcher = new NamePatternMatcher(fileFilter, true, true); + List results = new ArrayList(); + try + { + FtpClient ftp = getFTPClient(); + try + { + ftp.noop(); + } + catch (Exception e) + { + //e.printStackTrace(); + disconnect(); + + // probably timed out + reconnect(); + ftp = getFTPClient(); + } + + ftp.cd(parentPath); + TelnetInputStream stream = ftp.list(); + BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); + String line = reader.readLine(); + while (line != null) + { + FTPHostFile node = getDirListingParser().getFTPHostFile(line, parentPath); + if (node != null && filematcher.matches(node.getName())) + { + if (isRightType(fileType, node)) + { + results.add(node); + } + } + line = reader.readLine(); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + return (IHostFile[])results.toArray(new IHostFile[results.size()]); + } + + public String getSeparator() + { + return "/"; + } + + + public boolean upload(IProgressMonitor monitor, File localFile, String remoteParent, String remoteFile, boolean isBinary, String srcEncoding, String hostEncoding) + { + FtpClient ftp = getFTPClient(); + try + { + ftp.cd(remoteParent); + if (isBinary) + ftp.binary(); + else + ftp.ascii(); + ftp.put(localFile.getAbsolutePath()); + } + catch (Exception e) + { + e.printStackTrace(); + } + return true; + } + + public boolean upload(IProgressMonitor monitor, InputStream stream, String remoteParent, String remoteFile, boolean isBinary, String hostEncoding) + { + // hack for now + try + { + BufferedInputStream bis = new BufferedInputStream(stream); + File tempFile = File.createTempFile("ftp", "temp"); + FileOutputStream os = new FileOutputStream(tempFile); + BufferedOutputStream bos = new BufferedOutputStream(os); + + byte[] buffer = new byte[1024]; + int readCount; + while( (readCount = bis.read(buffer)) > 0) + { + bos.write(buffer, 0, readCount); + } + bos.close(); + + FtpClient ftp = getFTPClient(); + try + { + ftp.cd(remoteParent); + if (isBinary) + ftp.binary(); + else + ftp.ascii(); + ftp.put(tempFile.getAbsolutePath()); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + return true; + } + + public boolean download(IProgressMonitor monitor, String remoteParent, String remoteFile, File localFile, boolean isBinary, String hostEncoding) + { + FtpClient ftp = getFTPClient(); + try + { + ftp.cd(remoteParent); + /* + if (isBinary) + ftp.binary(); + else + ftp.ascii(); + */ + // for now only binary seems to work + ftp.binary(); + + InputStream is = ftp.get(remoteFile); + BufferedInputStream bis = new BufferedInputStream(is); + + if (!localFile.exists()) + { + File localParentFile = localFile.getParentFile(); + if (!localParentFile.exists()) + { + localParentFile.mkdirs(); + } + localFile.createNewFile(); + } + OutputStream os = new FileOutputStream(localFile); + BufferedOutputStream bos = new BufferedOutputStream(os); + + byte[] buffer = new byte[1024]; + int totalWrote = 0; + int readCount; + while( (readCount = bis.read(buffer)) > 0) + { + bos.write(buffer, 0, readCount); + totalWrote += readCount; + } + bos.close(); + + } + catch (Exception e) + { + e.printStackTrace(); + } + return true; + } + + public IHostFile getUserHome() + { + int lastSlash = _userHome.lastIndexOf('/'); + String name = _userHome.substring(lastSlash + 1); + String parent = _userHome.substring(0, lastSlash); + return getFile(null, parent, name); + } + + public IHostFile[] getRoots(IProgressMonitor monitor) + { + IHostFile root = new FTPHostFile("/", "/", true, true, 0, 0); + return new IHostFile[] { root }; + } + + + // TODO + /******************************************************** + * + * The following APIs need to be implemented + * + ********************************************************/ + + public IHostFile createFile(IProgressMonitor monitor, String remoteParent, String fileName) + { + // TODO Auto-generated method stub + return null; + } + + public IHostFile createFolder(IProgressMonitor monitor, String remoteParent, String folderName) { + // TODO Auto-generated method stub + return null; + } + + public boolean delete(IProgressMonitor monitor, String remoteParent, String fileName) { + // TODO Auto-generated method stub + return false; + } + + public boolean rename(IProgressMonitor monitor, String remoteParent, String oldName, String newName) { + // TODO Auto-generated method stub + return false; + } + + public boolean rename(IProgressMonitor monitor, String remoteParent, String oldName, String newName, IHostFile oldFile) { + // TODO Auto-generated method stub + return false; + } + + public boolean move(IProgressMonitor monitor, String srcParent, String srcName, String tgtParent, String tgtName) { + // TODO Auto-generated method stub + return false; + } + + public boolean copy(IProgressMonitor monitor, String srcParent, String srcName, String tgtParent, String tgtName) { + // TODO Auto-generated method stub + return false; + } + + public boolean copyBatch(IProgressMonitor monitor, String[] srcParents, String[] srcNames, String tgtParent) throws SystemMessageException + { + boolean ok = true; + for (int i = 0; i < srcParents.length; i++) + { + ok = ok && copy(monitor, srcParents[i], srcNames[i], tgtParent, srcNames[i]); + } + return ok; + } + + public void initService(IProgressMonitor monitor) + { + + } + + public boolean isCaseSensitive() + { + return true; + } + + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPServiceResources.java b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPServiceResources.java new file mode 100644 index 00000000000..905e0497bb2 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPServiceResources.java @@ -0,0 +1,32 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.files.ftp; + +import org.eclipse.osgi.util.NLS; + +public class FTPServiceResources extends NLS +{ + private static String BUNDLE_NAME = "org.eclipse.rse.services.files.ftp.FTPServiceResources";//$NON-NLS-1$ + + public static String FTP_File_Service_Name; + public static String FTP_File_Service_Description; + + static { + // load message values from bundle file + NLS.initializeMessages(BUNDLE_NAME, FTPServiceResources.class); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPServiceResources.properties b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPServiceResources.properties new file mode 100644 index 00000000000..5ceabfa9ca2 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/FTPServiceResources.properties @@ -0,0 +1,18 @@ +################################################################################ +# Copyright (c) 2006 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: +# {Name} (company) - description of contribution. +################################################################################ + +FTP_File_Service_Name=FTP File Service +FTP_File_Service_Description=The FTP File Service uses the FTP protocol to provide service for the Files subsystem. It requires an FTP daemon to be running on the host machine. \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/IFTPDirectoryListingParser.java b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/IFTPDirectoryListingParser.java new file mode 100644 index 00000000000..29ba5db3a0a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/IFTPDirectoryListingParser.java @@ -0,0 +1,36 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.files.ftp; + +/** + * Implementers of this interface provide a way to get + * information about file properties from an FTP directory + * listing in a way + * that might be specific to a certain system type. + * @author mjberger + * + */ +public interface IFTPDirectoryListingParser +{ + /** + * Return an FTPHostFile representing a line from an FTP directory listing + * @param line The line of text from the directory listing + * @param parentPath The directory that this is a listing of + * @return null if the line is not well formed + */ + public FTPHostFile getFTPHostFile(String line, String parentPath); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/IFTPService.java b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/IFTPService.java new file mode 100644 index 00000000000..bf566160b5d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/services/files/ftp/IFTPService.java @@ -0,0 +1,22 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.files.ftp; + +public interface IFTPService +{ + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/.classpath b/rse/plugins/org.eclipse.rse.services.local/.classpath new file mode 100644 index 00000000000..751c8f2e504 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/rse/plugins/org.eclipse.rse.services.local/.cvsignore b/rse/plugins/org.eclipse.rse.services.local/.cvsignore new file mode 100644 index 00000000000..ba077a4031a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/rse/plugins/org.eclipse.rse.services.local/.project b/rse/plugins/org.eclipse.rse.services.local/.project new file mode 100644 index 00000000000..edd4638bbf1 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/.project @@ -0,0 +1,28 @@ + + + org.eclipse.rse.services.local + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/rse/plugins/org.eclipse.rse.services.local/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.services.local/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..3e013b18b16 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin.name +Bundle-SymbolicName: org.eclipse.rse.services.local;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.rse.services.local.Activator +Bundle-Vendor: Eclipse.org +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.rse.services +Eclipse-LazyStart: true +Export-Package: org.eclipse.rse.internal.services.local.search, + org.eclipse.rse.internal.services.local.shells, + org.eclipse.rse.services.local, + org.eclipse.rse.services.local.files, + org.eclipse.rse.services.local.processes, + org.eclipse.rse.services.local.search, + org.eclipse.rse.services.local.shells +Bundle-ClassPath: localfiles.jar diff --git a/rse/plugins/org.eclipse.rse.services.local/about.html b/rse/plugins/org.eclipse.rse.services.local/about.html new file mode 100644 index 00000000000..6f6b96c4c87 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/about.html @@ -0,0 +1,22 @@ + + + +About + + + +

About This Content

+ +

February 24, 2005

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content.

+ + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/about.properties b/rse/plugins/org.eclipse.rse.services.local/about.properties new file mode 100644 index 00000000000..4f875867775 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/about.properties @@ -0,0 +1,25 @@ +############################################################################### +# Copyright (c) 2000, 2006 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 +############################################################################### +# 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 local services\n\ +\n\ +Version: {featureVersion}\n\ +Build id: {0}\n\ +\n\ +(c) Copyright Eclipse contributors and others 2000, 2006. All rights reserved.\n\ +Visit http://www.eclipse.org/dsdp/tm/ diff --git a/rse/plugins/org.eclipse.rse.services.local/build.properties b/rse/plugins/org.eclipse.rse.services.local/build.properties new file mode 100644 index 00000000000..ef02c081dfe --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/build.properties @@ -0,0 +1,12 @@ +bin.includes = META-INF/,\ + about.html,\ + about.properties,\ + plugin.properties,\ + localfiles.jar +src.includes = META-INF/,\ + about.html,\ + about.properties,\ + plugin.properties +source.localfiles.jar = src/ +jars.compile.order = localfiles.jar +output.localfiles.jar = bin/ diff --git a/rse/plugins/org.eclipse.rse.services.local/patterns.dat b/rse/plugins/org.eclipse.rse.services.local/patterns.dat new file mode 100644 index 00000000000..a6cda3b70ae --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/patterns.dat @@ -0,0 +1,269 @@ +# +# parse command line output. +# +# CLICK THIS LINE TO EDIT THIS FILE (PATTERNS.DAT). (When viewing from the Output view) + +command: grep -n.* + grep file line pattern =([\w,.,/,(,),\\,\-,\+,\d]*):(\d*):.* + +command: grep -.*n.* + grep file line pattern =([\w,.,/,(,),\\,\-,\+,\d]*):(\d*):.* + +command: grep .* + grep file pattern =([\w,.,/,(,)\\,\-,\+,\d]*):.* + + +command: pwd + directory file pattern=([\w,.,/,(,),\\,\-,\+,\d,:]*) + +command: nmake.* + error pattern=NMAKE : .* + error file line pattern =([\w,.,\-,\+,(,),\\,:]*)\((\d*):(\d*)\) : error EDC.* + error file pattern =[\w,.,\-,\+,(,),\\,:]*\(([\w,.,/,\\]*)\) : error LNK.* + error file line pattern=([\w,.,/,\-,\+,(,),\\]*):(\d*):\d*\) : error .* + warning file line pattern=([\w,.,/,\-,\+,(,),\\]*)\((\d*):\d*\) : warning .* + informational file line pattern=([\w,.,/,\-,\+,(,),\\]*)\((\d*):\d*\) : informational .* + +command: make.* + error file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(S\).* + error file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\",, line (\d*)\.\d*: \d*-\d* \(E\).* + warning file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(W\).* + informational file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(I\).* + warning file line pattern =([\w,.,/,(,),\-,\+,\\]*):(\d*): warning: .* + warning file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*):\d*: warning: .* + error file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*):.* + informational file pattern =([\w,.,/,\\,\-,\+,(,)]*):.* + informational file line pattern =In file included from ([\w,.,/,\\,\-,\+,(,)]*):(\d*): + #iseries c compiler + error file line pattern=[\w,.,/,\\]* Line \d* \"([\w,.,/,\\]*)\", line (\d*)\.\d*: .* + error file line pattern=([\w,.,/,\\]*) Line (\d*)\s.* + #makefile errors + error file line pattern=\"([\w,\.,/,(,),\-,\+,\\]*)\", line (\d*): make:.* + #xlc Options warnings + warning pattern=\(W\) Option .* + #c89 errors + error file line pattern=ERROR CBC\d* ([\w,.,/,\\,\-,\+,(,)]*):(\d*) .* + warning file line pattern=WARNING CBC\d* ([\w,.,/,\\,\-,\+,(,)]*):(\d*) .* + informational pattern=CBC\d*\(I\) .* + +command: gmake.* + error file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(S\).* + warning file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(W\).* + informational file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(I\).* + warning file line pattern =([\w,.,/,(,),\-,\+,\\]*):(\d*): warning: .* + warning file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*):\d*: warning: .* + informational file line pattern =In file included from ([\w,.,/,\\,\-,\+,(,)]*):(\d*): + # ixlc compiler + error file line pattern=[\w,.,/,\\]* Line \d* \"([\w,.,/,\\]*)\", line (\d*)\.\d*: .* + error file line pattern=([\w,.,/,\\]*) Line (\d*)\s.* + # icc compiler + error file line pattern =([\w,.,/,\\,\-,\+,(,)]*),\s(\d*)\.\d*:\s.* + error file line pattern =\"([\w,.,/,\\,\-,\+,(,)]*)\",\sline\s(\d*)\.\d*:\s.* + #generic + error file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*):.* + +command: gcc\s.* + error file line pattern=\"([\w,.,/,\\,\-,\+,(,)]*)\", line (\d*)\.\d*: \d*-\d* \(S\).* + warning file line pattern=\"([\w,.,/,\\,\-,\+,(,)]*)\", line (\d*)\.\d*: \d*-\d* \(W\).* + informational file line pattern=\"([\w,.,/,\\,\-,\+,(,)]*)\", line (\d*)\.\d*: \d*-\d* \(I\).* + warning file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*): warning: .* + warning file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*):\d*: warning: .* + error file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*):.* + informational file pattern =([\w,.,/,\\,\-,\+,(,)]*):.* + informational file line pattern =In file included from ([\w,.,/,\\,\-,\+,(,)]*):(\d*): + +command: cc\s.* + error file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*):.* + +command: CC\s.* + error file line pattern =([\w,.,/,\\,\-,\+,(,)]*):(\d*):.* + +command: c89.* + error file line pattern=ERROR CBC\d* ([\w,.,/,\\,\-,\+,(,)]*):(\d*) .* + warning file line pattern=WARNING CBC\d* ([\w,.,/,\\,\-,\+,(,)]*):(\d*) .* + informational pattern=CBC\d*\(I\) .* + +command: icc.* + error file line pattern =([\w,.,/,\\,\-,\+,(,)]*),\s(\d*)\.\d*:\s.* + error file line pattern =\"([\w,.,/,\\,\-,\+,(,)]*)\",\sline\s(\d*)\.\d*:\s.* + +command: javac.* + warning file line pattern=([\w,.,/,\\,\-,\+,(,),:]*):(\d*): warning.* + error file line pattern=([\w,.,/,\\,\-,\+,(,),:]*):(\d*):.* + +command: .*bat\s.* + error file line pattern=\[javac\]\s([\w,.,/,\\,:]*):(\d*):.* + error file line pattern=file:([\w,.,/,\\,:]*):(\d*):.* + +command: dir.* + directory file pattern=\d{2}/\d{2}/\d*\s\d{2}:\d{2}[a,p,AM,PM,\s].*\s*\s*([\w,.,/,\\,\s,\-,\+\+,\d]*).* + file file pattern=\d{2}/\d{2}/\d*\s\d{2}:\d{2}[a,p,AM,PM,\s].*\s*[\d,,]* ([\w,.,/,\\,\s,\-,\+\+,\d]*).* + directory file pattern=[\d,/,\\,.,-]+.\s*\d{2}[:,.]\d{2}.\s*\s*([\w,.,/,\\,\s,\-,\+\+,\d]*) + file file pattern=[\d,/,\\,.,-]+.\s*\d{2}[:,.]\d{2}.\s*[\d,,,.]*\s*([\w,.,/,\\,\s,\-,\+\+,\d]*) + +command: ls -l.* + file file pattern=-[-,r,w,x]+\s.*\s[\d{4},\d{2}:\d{2}]+,\s([\w,.,/,(,),\\,\-,\+\s,\d]*) + file file pattern=l[-,r,w,x]+\s.*\s[\d{4},\d{2}:\d{2}]+,\s([\w,.,/,(,),\\,\-,\+\s,\d]*)\s->\s[\w,.,/,(,),\\,\-,\+\s,\d]* + file file pattern=-.*\d{2}:\d{2} ([\w,.,/,(,),\\,\-,\+,\s,\d]*) + file file pattern=-.* \d{4} ([\w,.,/,(,),\\,\-,\+,\s,\d]*) + file file pattern=l.*\d{2}:\d{2} ([\w,.,/,(,),\\,\-,\+,\s,\d]*)\s->\s[\w,.,/,(,),\\,\-,\+\s,\d]* + file file pattern=l.* \d{4} ([\w,.,/,(,),\\,\-,\+,\s,\d]*)\s->\s[\w,.,/,(,),\\,\-,\+\s,\d]* + directory file pattern=d.*\d{2}:\d{2} ([\w,.,/,(,),\\,\-,\+\s,\d]*) + directory file pattern=d.*\d{4} ([\w,.,/,(,),\\,\-,\+,\s,\d]*) + +command: ls -a.* + file file pattern=-.*\d{2}:\d{2} ([\w,.,/,(,),\\,\-,\+\s,\d]*) + file file pattern=-.* \d{4} ([\w,.,/,(,),\\,\-,\+\s,\d]*) + directory file pattern=d.*\d{2}:\d{2} ([\w,.,/,(,),\\,\-,\+\s,\d]*) + directory file pattern=d.*\d{4} ([\w,.,/,(,),\\,\-,\+\s,\d]*) + +command: ls + file file pattern=([\w,\d,.,(,),\-,\+\s]+) + +command: ls\s.* + file file pattern=([\w,\d,.,(,),\-,\+\s]+) + +command: .* + prompt file pattern=([\w,.,/,(,),\\,\-,\+,\d,:,\s]*)>.* + +command: find .* + file file pattern=([\w,.,/,\\,(,),\-]+) + +command: env + pathenvvar file pattern=PATH\=(.*) + libpathenvvar file pattern=LIBPATH\=(.*) + libpathenvvar file pattern=LIB\=(.*) + envvar pattern=[\w\d]+\=.* + +command: ps + process pattern=[\s]*[\d]+\s.* + +command: ps .* + process pattern=[\s]*[\d]+\s.* + +command: xl[C,c].* + error file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\",, line (\d*)\.\d*: \d*-\d* \(S\).* + error file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(E\).* + warning file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(W\).* + informational file line pattern=\"([\w,.,/,(,),\-,\+,\\]*)\", line (\d*)\.\d*: \d*-\d* \(I\).* + +command: ixlc.* + error file line pattern=([\w,.,/,\\]*) Line (\d*)\s.* + error file line pattern=[\w,.,/,\\]* Line \d* \"([\w,.,/,\\]*)\", line (\d*)\.\d*: .* + +command: cat.*patterns.* + warning file pattern=# .*(PATTERNS.DAT).* + Output pattern=command: .* + #statement pattern=#.* + statement pattern=.* pattern.*=.* + +# special for autoconf +command: ./bootstrap.sc.* + error file line pattern=aclocal: ([\w,.,/,\\]*): (\d*):.* + warning file line pattern=([\w,.,/,\\]*):(\d*):.* + +command: ./configure.* + error file line pattern=./(configure): line (\d*): .* + +# How Patterns Work +# ----------------- +# +# Patterns are used by the Output View to allow lines that contain file names and +# perhaps line numbers to be clicked to cause the file location to be opened in an Editor. +# A line in this file can be 1 of 3 things: +# 1. An empty line or a comment line (denoted by a # in column 1) +# 2. The start of a command description (denoted by a 'command:' at the beginning of the line) +# 3. A pattern description. +# A formal description of the syntax of this file is included at the bottom of this file. +# +# +# Command Descriptions +# -------------------- +# +# A Command Description consists of 2 things: A regular expression that describes the +# command invocation, and a list of Pattern Descriptions. The regular expression +# is used to determine what set of Pattern Descriptons to use when parsing command output. +# For example, if you type the command 'gmake clean', the Command Descriptions are checked and +# .*make.* would match that command. Therefore the Pattern Descriptions for .*make.* would +# be used to parse the output of the 'gmake clean'. +# Note: The first Command Description that is found to match the command is used, so make +# sure you put the most specific patterns first. For example, if the nmake.* Command +# Description appeared after .*make.*, then 'nmake install' would be matched by the .*make.* +# Command Descripton, which is probably not what was intended. +# +# +# Pattern Descriptions +# -------------------- +# +# A Pattern Description has the following form: +# "pattern=" +# +# where: +# : The type of object that will be created in the Output View if +# a line of output matches this pattern. If you have put an +# icon called ".gif" in the com.ibm.etools.systems.dstore.core/icons +# directory, then the icon will be displayed in the view. +# +# : This is some combination of the words "file" and "line" or nothing +# at all. This is used to define how the backreferences in the +# regular expression are to be interpreted. So "file line" means +# that the first back-reference is a file, and the second is a +# line number. This may seem unnecessary, but we added this capability +# in the event that future releases support other types of information +# that may be useful, such as column info (once we support it). +# +# : A regular expression that describes a line of output. Backreferences +# are used to store (instead of just match) the filename and line +# number. To store a filename use the backreference ([\w,.,/,\\]*), and +# to store a line number, use (\d*) +# +# +# Note: The patterns are checked against command output and only exact matches are dealt with +# So as an example, if you forget the .* (match everything) at the end of a pattern, +# the match will fail if there are trailing characters in the output not accounted for by +# the pattern +# +# +# Pattern File Syntax +# ------------------- +# +# The pattern file syntax should be easy to grasp by looking at the ones +# above, but for those of you who like formal grammars, here it is: +# +# patterns-file: +# commands +# +# commands: +# command +# commands new-line command +# +# command: +# "command:" reg-ex new-line patterns +# +# patterns: +# pattern +# patterns new-line pattern +# +# pattern: +# command-name match-list "pattern=" reg-ex +# +# command-name: +# String that denotes what type of object will be created if some output matches this pattern +# +# match-list: +# file-or-line +# match-list space file-or-line +# +# file-or-line: +# "file" | "line" +# +# reg-ex: +# A regular expression +# +# new-line: +# The new-line character \n +# +# space: +# The space character + + diff --git a/rse/plugins/org.eclipse.rse.services.local/plugin.properties b/rse/plugins/org.eclipse.rse.services.local/plugin.properties new file mode 100644 index 00000000000..6b0e52b6cba --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/plugin.properties @@ -0,0 +1,12 @@ +############################################################################### +# Copyright (c) 2000, 2006 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 +############################################################################### + +plugin.name = RSE Local Services \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/search/LocalSearchResult.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/search/LocalSearchResult.java new file mode 100644 index 00000000000..866229f5285 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/search/LocalSearchResult.java @@ -0,0 +1,29 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.services.local.search; + +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.search.AbstractSearchResult; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; + +public class LocalSearchResult extends AbstractSearchResult +{ + public LocalSearchResult(IHostSearchResultConfiguration configuration, Object parent, SystemSearchString searchString) + { + super(configuration, parent, searchString); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/CommandPattern.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/CommandPattern.java new file mode 100644 index 00000000000..b07f6b3e60f --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/CommandPattern.java @@ -0,0 +1,60 @@ +/******************************************************************************** + * Copyright (c) 2001, 2006 IBM Corporation and International Business Machines 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.services.local.shells; + +import java.util.ArrayList; +import java.util.regex.Pattern; + +public class CommandPattern +{ + + + private Pattern _pattern; + private ArrayList _outputPatterns; + + public CommandPattern(Pattern theCommandPattern) + { + _pattern = theCommandPattern; + _outputPatterns = new ArrayList(); + } + + public void addOutputPattern(OutputPattern op) + { + _outputPatterns.add(op); + } + + public boolean matchCommand(String theLine) + { + return _pattern.matcher(theLine).matches(); + } + + public ParsedOutput matchLine(String theLine) + { + int patterns = _outputPatterns.size(); + ParsedOutput matchedOutput; + OutputPattern curPattern; + for (int i = 0; i < patterns; i++) + { + curPattern = (OutputPattern) _outputPatterns.get(i); + matchedOutput = curPattern.matchLine(theLine); + if (matchedOutput != null) + return matchedOutput; + } + return null; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/LocalShellOutputReader.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/LocalShellOutputReader.java new file mode 100644 index 00000000000..643be932389 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/LocalShellOutputReader.java @@ -0,0 +1,136 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.services.local.shells; + +import java.io.BufferedReader; +import java.io.IOException; + + +import org.eclipse.rse.services.shells.AbstractHostShellOutputReader; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IHostShellOutputReader; + +/** + * Listener to shell output. As io streams through, refresh events are sent out + * for the OutputChangeListener to respond to. + */ +public class LocalShellOutputReader extends AbstractHostShellOutputReader implements IHostShellOutputReader +{ + protected BufferedReader _reader; + + public LocalShellOutputReader(IHostShell hostShell, BufferedReader reader, boolean isErrorReader) + { + super(hostShell, isErrorReader); + _reader = reader; + } + + protected Object internalReadLine() + { + StringBuffer theLine = new StringBuffer(); + int ch; + int lastch = 0; + boolean done = false; + while (!done && !isFinished()) + { + try + { + + ch = _reader.read(); + switch (ch) + { + case -1: + if (theLine.length() == 0) // End of Reader + return null; + done = true; + break; + case 65535: + if (theLine.length() == 0) // Check why I keep getting + // this!!! + return null; + done = true; + break; + case 10: + done = true; // Newline + + break; + case 9: + theLine.append(" "); // Tab + break; + case 13: + break; // Carriage Return + default: + char tch = (char) ch; + if (!Character.isISOControl(tch)) + { + theLine.append(tch); // Any other character + } + else + { + // ignore next char too + _reader.read(); + } + } + + boolean ready = _reader.ready(); + if (ch == 10 && lastch == 13) + { + return theLine.toString(); + } + lastch = ch; + + // Check to see if the BufferedReader is still ready which means + // there are more characters + // in the Buffer...If not, then we assume it is waiting for + // input. + if (!ready) + { + // wait to make sure + try + { + //_reader.wait(_waitIncrement); + Thread.sleep(_waitIncrement); + } + catch (InterruptedException e) + { + } + if (!_reader.ready()) + { + if (done) + { + return theLine.toString().trim(); + } + else + { + done = true; + } + + } + } + + } + catch (IOException e) + { + return null; + } + } + + return theLine.toString(); + } + + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/LocalShellThread.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/LocalShellThread.java new file mode 100644 index 00000000000..dee78000885 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/LocalShellThread.java @@ -0,0 +1,493 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.services.local.shells; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.URL; + +import org.eclipse.core.runtime.Platform; + +/** + * The LocalCommandThread class is used for running and interacting with a + * local command shell. + */ +public class LocalShellThread extends Thread +{ + + private volatile Thread _commandThread; + protected boolean _isCancelled; + + private String _cwd; + private String _invocation; + private String[] _envVars; + private String PSEUDO_TERMINAL; + + + private boolean _isShell; + private boolean _isDone; + + private Process _theProcess; + + + private boolean _isTTY = false; + + private boolean _isWindows; + private String _encoding; + + private BufferedReader _stdInput; + private BufferedReader _stdError; + + /** + * consturtor for local command shell monitor + * @param fileSubSystem associated local file subsystem + * @param cwd initial working directory + * @param invocation launch shell command + * @param encoding + * @param patterns patterns file for output interpretation + * @param envVars user and system environment variables to launch shell with + */ + public LocalShellThread(String cwd, String invocation, String encoding, String[] envVars) + { + super(); + _encoding = encoding; + _isCancelled = false; + _cwd = cwd; + _invocation = invocation; + + // if pty exists for this client + // then the rse.pty property will have been set + // by the contributor of the pty exectuable + // on linux client this is a likely scenario + PSEUDO_TERMINAL = System.getProperty("rse.pty"); + //PSEUDO_TERMINAL ="platform:/base/plugins/com.ibm.etools.power.universal.server/server.components/intellinux/pty/pty"; + try + { + PSEUDO_TERMINAL = Platform.resolve(new URL(PSEUDO_TERMINAL)).getPath(); + } + catch (Exception e) + { + } + + _envVars = envVars; + init(); + } + + + public boolean isShell() + { + return _isShell; + } + + public boolean isWindows() + { + return _isWindows; + } + + public boolean isDone() + { + return _isDone || _isCancelled; + } + + public String getInvocation() + { + return _invocation; + } + + public String getCWD() + { + return _cwd; + } + + public void setCWD(String cwd) + { + _cwd = cwd; + } + + private void init() + { + try + { + File theDirectory = new File(_cwd); + if (!theDirectory.isDirectory()) + theDirectory = theDirectory.getParentFile(); + String theOS = System.getProperty("os.name"); + _isWindows = theOS.toLowerCase().startsWith("win"); + _isTTY = PSEUDO_TERMINAL != null && (new File(PSEUDO_TERMINAL).exists()); + + String theShell = null; + + if (!_isWindows) + { + String[] envVars = getEnvironmentVariables(false); + if (theShell == null) + { + if (_isTTY) + { + if (_invocation.equals(">")) + { + _invocation = "sh"; + _isShell = true; + } + + String args[] = new String[2]; + args[0] = PSEUDO_TERMINAL; + args[1] = _invocation; + + _theProcess = Runtime.getRuntime().exec(args, envVars, theDirectory); + } + else + { + if (_invocation.equals(">")) + { + _invocation = "sh"; + _isShell = true; + } + String args[] = new String[1]; + args[0] = _invocation; + + _theProcess = Runtime.getRuntime().exec(args[0], envVars, theDirectory); + } + } + else + { + if (_isTTY) + { + if (_invocation.equals(">")) + { + _invocation = theShell; + _isShell = true; + } + + String args[] = new String[4]; + args[0] = PSEUDO_TERMINAL; + args[1] = theShell; + args[2] = "-c"; + args[3] = _invocation; + + _theProcess = Runtime.getRuntime().exec(args, envVars, theDirectory); + } + else + { + if (_invocation.equals(">")) + { + _invocation = theShell; + _isShell = true; + } + + String args[] = new String[3]; + args[0] = theShell; + args[1] = "-c"; + args[2] = _invocation; + + _theProcess = Runtime.getRuntime().exec(args, envVars, theDirectory); + } + + } + } + else + { + String[] envVars = getEnvironmentVariables(true); + if ((theOS.indexOf("95") >= 0) || (theOS.indexOf("98") >= 0) || (theOS.indexOf("ME") >= 0)) + { + theShell = "start"; + } + else + { + theShell = "cmd"; + } + + if (_invocation.equals(">")) + { + _invocation = theShell; + _isShell = true; + } + + if (theShell.equals("start")) + { + theShell += " /B "; + } + else + { + theShell += " /C "; + } + + _theProcess = Runtime.getRuntime().exec(theShell + _invocation, envVars, theDirectory); + } + + // determine the windows encoding + if (_encoding == null || _encoding.length() == 0) + { + try + { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + OutputStreamWriter osw = new OutputStreamWriter(os); + _encoding = osw.getEncoding(); + osw.close(); + os.close(); + } + catch (Exception x) + { + } + if (_encoding == null) + { + if (_encoding == null || _encoding.length() == 0) + { + _encoding = System.getProperty("file.encoding"); + } + } + } + + if (_encoding.equals("Cp1252") && !theOS.startsWith("Windows XP")) + { + _stdInput = new BufferedReader(new InputStreamReader(_theProcess.getInputStream(), "Cp850")); + _stdError = new BufferedReader(new InputStreamReader(_theProcess.getErrorStream(), "Cp850")); + } + else + { + _stdInput = new BufferedReader(new InputStreamReader(_theProcess.getInputStream())); + _stdError = new BufferedReader(new InputStreamReader(_theProcess.getErrorStream())); + } + + } + catch (IOException e) + { + _theProcess = null; + e.printStackTrace(); + return; + } + + + } + + public BufferedReader getOutputStream() + { + return _stdInput; + } + + public BufferedReader getErrorStream() + { + return _stdError; + } + + + + public synchronized void stopThread() + { + if (_commandThread != null) + { + _isCancelled = true; + + try + { + _commandThread = null; + } + catch (Exception e) + { + System.out.println(e); + } + + } + notify(); + } + + public void sendInput(String input) + { + if (!_isDone) + { + byte[] intoout = input.getBytes(); + OutputStream output = _theProcess.getOutputStream(); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output)); + + try + { + + writer.write(input); + writer.write('\n'); + writer.flush(); + + if (!_isWindows && !_isTTY) + { + // special case for pattern interpretting + // if cwd is not set, then files aren't resolved + // create mock prompt to ensure that they do get resolved + if (input.startsWith("cd ") || input.equals("cd")) + { + writer.write("echo $PWD'>'"); + writer.write('\n'); + writer.flush(); + + // sleep to allow reader to interpret before going on + try + { + Thread.sleep(100); + } + catch (InterruptedException e) + { + } + } + } + } + catch (IOException e) + { + System.out.println(e); + } + + } + } + + public void run() + { + Thread thisThread = Thread.currentThread(); + _commandThread = thisThread; + + + while (_commandThread != null && _commandThread == thisThread && _commandThread.isAlive() && !_isCancelled) + { + try + { + Thread.sleep(200); + } + catch (InterruptedException e) + { + System.out.println(e); + } + + //This function is where the Threads do real work, and return false when finished + if (!doThreadedWork()) + { + try + { + _commandThread = null; + } + catch (Exception e) + { + System.out.println(e); + } + } + else + { + } + } + + //This function lets derived classes cleanup or whatever + cleanupThread(); + } + + public boolean doThreadedWork() + { + if (_stdInput == null) + { + return false; + } + else + { + return true; + } + } + + public void cleanupThread() + { + if (_isShell) + { + sendInput("exit"); + } + + _isDone = true; + try + { + _stdInput.close(); + _stdError.close(); + + if (_theProcess != null) + { + int exitcode; + try + { + if (_isCancelled) + { + _theProcess.destroy(); + } + else + { + exitcode = _theProcess.exitValue(); + } + } + catch (IllegalThreadStateException e) + { + //e.printStackTrace(); + exitcode = -1; + _theProcess.destroy(); + } + _theProcess = null; + } + } + catch (IOException e) + { + e.printStackTrace(); + } + + } + + + public String getPathEnvironmentVariable() + { + String[] vars = _envVars; + if (vars != null) + { + + for (int i = 0; i < vars.length; i++) + { + String var = vars[i].toUpperCase(); + if (var.startsWith("PATH=")) + { + return var; + } + } + + } + return null; + } + + /** + * Retrieve the system environment variables and append the user defined + * environment variables to create the String array that can be passed to + * Runtime.exec(). We need to retrieve the system env vars because the + * env vars passed to Runtime.exec() prevent the system ones from being + * inherited. + */ + private String[] getEnvironmentVariables(boolean windows) + { + if (_isTTY) + { + String[] newEnv = new String[_envVars.length + 1]; + for (int i = 0; i < _envVars.length; i++) + newEnv[i] = _envVars[i]; + newEnv[_envVars.length] = "PS1=$PWD/>"; + _envVars = newEnv; + } + return _envVars; + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/OutputPattern.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/OutputPattern.java new file mode 100644 index 00000000000..d81bf728937 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/OutputPattern.java @@ -0,0 +1,98 @@ +/******************************************************************************** + * Copyright (c) 2001, 2006 IBM Corporation and International Business Machines 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.services.local.shells; + +import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class OutputPattern +{ + + + private Pattern _pattern; + private String _objType; + private ArrayList _matchOrder; + + public OutputPattern(String objType, String matchOrder, Pattern thePattern) + { + _objType = objType; + _pattern = thePattern; + + _matchOrder = new ArrayList(); + //Here we add a dummy first element to the ArrayList, to mimick how the PatternMatcher stores it's + //matches (starting with group 1). + _matchOrder.add(null); + + int index = 0; + int nextSpace = 0; + //Walk the matchOrder string parsing out words and adding them to _matchOrder...Could use StringTokenizer + //but this seem much simpler. + while ((nextSpace = matchOrder.indexOf(" ", index)) > 0) + { + _matchOrder.add(matchOrder.substring(index, nextSpace).toLowerCase()); + index = nextSpace; + while ((index < matchOrder.length()) && (matchOrder.charAt(index) == ' ')) + index++; + } + _matchOrder.add(matchOrder.substring(index, matchOrder.length()).toLowerCase()); + + } + + public ParsedOutput matchLine(String theLine) + { + Matcher matcher = null; + try + { + matcher = _pattern.matcher(theLine); + if (!matcher.matches()) + return null; + } + catch (StringIndexOutOfBoundsException e) + { + //Getting an exception here, when theLine is an empty line for some patterns..should probably investigate, + //but for now we'll just handle it... + return null; + } + + String fileString = ""; + String lineString = ""; + //Groups start at 1 (group 0 is the entire match). + for (int i = 1; i < _matchOrder.size(); i++) + { + String mStr = (String)_matchOrder.get(i); + if (mStr.equals("file")) + fileString = matcher.group(i); + else if (mStr.equals("line")) + lineString = matcher.group(i); + } + int line = 1; + if (lineString.length() > 0) + { + try + { + line = Integer.parseInt(lineString); + } + catch (NumberFormatException e) + { + } + } + + return new ParsedOutput(_objType, theLine, fileString, line, 1); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/ParsedOutput.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/ParsedOutput.java new file mode 100644 index 00000000000..70b06325512 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/ParsedOutput.java @@ -0,0 +1,38 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.services.local.shells; + +//This is just a convenience object for storing information parsed out of a line of output. +public class ParsedOutput +{ + + + public String type; + public String text; + public String file; + public int line; + public int col; + + public ParsedOutput (String theType, String theText, String theFile, int theLine, int theColumn) + { + type = theType; + text = theText; + file = theFile; + line = theLine; + col = theColumn; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/Patterns.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/Patterns.java new file mode 100644 index 00000000000..8d9c43305e3 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/shells/Patterns.java @@ -0,0 +1,216 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.services.local.shells; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.regex.Pattern; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.PluginVersionIdentifier; +import org.eclipse.rse.services.local.Activator; +import org.osgi.framework.Bundle; + +public class Patterns +{ + + private ArrayList _theCommands; + private String _currentCommand; + private String _pluginsPath; + private String _version; + private long _timeStamp = 0; + private File _thePatternsFile; + private static String PATTERNS_PACKAGE = "org.eclipse.rse.services.local"; + private static String PATTERNS_FILE = "patterns.dat"; + + public Patterns() + { + _theCommands = new ArrayList(); + parsePatternsFile(); + } + + protected String getPatternsFilePath(Bundle bundle) + { + URL pluginsURL = bundle.getEntry("/"); + String path = null; + try + { + path = Platform.resolve(pluginsURL).getPath(); + File systemsPluginDir = new File(path); + path = systemsPluginDir.getParentFile().getAbsolutePath(); + } + catch (IOException e) + { + } + return path; + } + + private String getPatternsFilePath() + { + if (_pluginsPath == null) + { + Bundle bundle = Activator.getDefault().getBundle(); + _pluginsPath = getPatternsFilePath(bundle); + String version = (String)(bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION)); + _version = (new PluginVersionIdentifier(version)).toString(); + } + return _pluginsPath; + } + + public void refresh(String theCommand) + { + _currentCommand = theCommand; + parsePatternsFile(); + } + + public void update(String theCommand) + { + _currentCommand = theCommand; + } + + private File getPatternsFile() + { + if (_thePatternsFile == null) + { + String pluginDir = getPatternsFilePath(); + + + File thePatternsFile = new File(pluginDir + "/" + PATTERNS_PACKAGE + "/" + PATTERNS_FILE); + if (!thePatternsFile.exists()) + { + thePatternsFile = new File(pluginDir + "/" + PATTERNS_PACKAGE + "_" + _version + "/" + PATTERNS_FILE); + + if (!thePatternsFile.exists()) + { + File parentFile = new File(pluginDir); + if (parentFile.exists()) + { + // now we're really desparate! + // search for a file that looks like it + File[] files = parentFile.listFiles(); + for (int i = 0; i < files.length && !thePatternsFile.exists(); i++) + { + File c = files[i]; + if (c.getName().startsWith(PATTERNS_PACKAGE)) + { + thePatternsFile = c; + } + } + + } + } + } + _thePatternsFile = thePatternsFile; + } + return _thePatternsFile; + } + private void parsePatternsFile() + { + File thePatternsFile = getPatternsFile(); + + long newTimeStamp = 0; + if (!thePatternsFile.exists() || ((newTimeStamp = thePatternsFile.lastModified()) == _timeStamp)) + return; + + _timeStamp = newTimeStamp; + + //If we get here, we are actually going to read\parse the file. + BufferedReader reader = null; + try + { + reader = new BufferedReader(new FileReader(thePatternsFile)); + _theCommands.clear(); + + String curLine; + CommandPattern curCommand = null; + + //Main Loop that reads each line. + while ((curLine = reader.readLine()) != null) + { + curLine = curLine.trim(); + //Skip the current line if it is empty or starts with a # + if ((curLine.length() == 0) || (curLine.charAt(0) == '#')) + continue; + + //Check if this line is the start of a new command section + if (curLine.startsWith("command")) + { + int colon = curLine.indexOf(":"); + //Check that there is something after the colon + if (colon == (curLine.length() - 1)) + continue; + + Pattern thePattern = Pattern.compile(curLine.substring(colon + 1, curLine.length()).trim()); + curCommand = new CommandPattern(thePattern); + _theCommands.add(curCommand); + } + + //If we get here, the line must be an output pattern + else + { + int firstSpace = curLine.indexOf(" "); + int patternWord = curLine.indexOf("pattern"); + int firstEquals = curLine.indexOf("="); + if ((firstEquals == -1) || (firstEquals == (curLine.length() - 1))) + continue; + String objType = curLine.substring(0, firstSpace); + String matchOrder = curLine.substring(firstSpace + 1, patternWord).trim(); + String patternString = curLine.substring(firstEquals + 1, curLine.length()); + Pattern thePattern = Pattern.compile(patternString.trim()); + + if (curCommand != null) + curCommand.addOutputPattern(new OutputPattern(objType, matchOrder, thePattern)); + } + } + } + catch (FileNotFoundException e) + { + System.out.println(e.getMessage()); + return; + } + catch (IOException e) + { + System.out.println(e.getMessage()); + return; + } + } + + public ParsedOutput matchLine(String theLine) + { + CommandPattern curCommand; + ParsedOutput matchedOutput = null; + int commands = _theCommands.size(); + + if (_currentCommand != null) + { + for (int i = 0; i < commands; i++) + { + curCommand = (CommandPattern) _theCommands.get(i); + if (curCommand.matchCommand(_currentCommand)) + matchedOutput = curCommand.matchLine(theLine); + if (matchedOutput != null) + return matchedOutput; + } + } + return null; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/Activator.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/Activator.java new file mode 100644 index 00000000000..7fd2516d61c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/Activator.java @@ -0,0 +1,70 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.local; + +import org.eclipse.ui.plugin.*; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class Activator extends AbstractUIPlugin { + + //The shared instance. + private static Activator plugin; + + /** + * The constructor. + */ + public Activator() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static Activator getDefault() { + 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("com.ibm.rse.services.files.local", path); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/ILocalService.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/ILocalService.java new file mode 100644 index 00000000000..6f440b7b91d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/ILocalService.java @@ -0,0 +1,22 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.local; + +public interface ILocalService +{ + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalFileService.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalFileService.java new file mode 100644 index 00000000000..ea54e1056f7 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalFileService.java @@ -0,0 +1,1167 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.local.files; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.services.clientserver.ISystemFileTypes; +import org.eclipse.rse.services.clientserver.NamePatternMatcher; +import org.eclipse.rse.services.clientserver.SystemEncodingUtil; +import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; +import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.files.AbstractFileService; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.files.IHostFile; +import org.eclipse.rse.services.local.ILocalService; + +public class LocalFileService extends AbstractFileService implements IFileService, ILocalService +{ + private static final String[] ALLDRIVES = + { + "c:\\", + "d:\\", + "e:\\", + "f:\\", + "g:\\", + "h:\\", + "i:\\", + "j:\\", + "k:\\", + "l:\\", + "m:\\", + "n:\\", + "o:\\", + "p:\\", + "q:\\", + "r:\\", + "s:\\", + "t:\\", + "u:\\", + "v:\\", + "w:\\", + "x:\\", + "y:\\", + "z:\\" }; + + private boolean _checkedOS = false; + private boolean _isWindows = false; + private boolean _isWin95 = false; + private boolean _isWinNT = false; + private String _osCmdShell = null; + protected ISystemFileTypes _fileTypeRegistry; + + public LocalFileService(ISystemFileTypes fileTypeRegistry) + { + + + _fileTypeRegistry = fileTypeRegistry; + } + + public String getName() + { + return LocalServiceResources.Local_File_Service_Name; + } + + public String getDescription() + { + return LocalServiceResources.Local_File_Service_Description; + } + + public boolean isWindows() + { + if (!_checkedOS) + { + String osName = System.getProperty("os.name").toLowerCase(); + _isWindows = osName.startsWith("win"); + _isWin95 = _isWindows && ((osName.indexOf("95") >= 0) || (osName.indexOf("98") >= 0) || (osName.indexOf("me") >= 0)); + _isWinNT = _isWindows && ((osName.indexOf("nt") >= 0) || (osName.indexOf("2000") >= 0) || (osName.indexOf("xp") >= 0)); + + if (_isWinNT) + { + _osCmdShell = "cmd /C "; + } + else if (_isWin95) + { + _osCmdShell = "start /B "; + } + _checkedOS = true; + } + return _isWindows; + } + + public class LocalFileNameFilter implements FilenameFilter + { + private NamePatternMatcher _matcher; + public LocalFileNameFilter(String filter) + { + _matcher = new NamePatternMatcher(filter); + } + public boolean accept(File dir, String name) + { + return _matcher.matches(name); + } + public boolean isGeneric() + { + return _matcher.isGeneric(); + } + + } + + public boolean upload(IProgressMonitor monitor, InputStream stream, String remoteParent, String remoteFile, boolean isBinary, String hostEncoding) throws SystemMessageException + { + boolean isCancelled = false; + FileInputStream inputStream = null; + BufferedInputStream bufInputStream = null; + FileOutputStream outputStream = null; + BufferedOutputStream bufOutputStream = null; + OutputStreamWriter outputWriter = null; + BufferedWriter bufWriter = null; + + try + { + File destinationFile = new File(remoteParent, remoteFile); + if (ArchiveHandlerManager.isVirtual(destinationFile.getAbsolutePath())) + { + VirtualChild child = ArchiveHandlerManager.getInstance().getVirtualObject(destinationFile.getAbsolutePath()); + ISystemArchiveHandler handler = child.getHandler(); + if (handler == null) + throwCorruptArchiveException(this.getClass() + ".upload()"); + return handler.add(stream, child.path, remoteFile, SystemEncodingUtil.ENCODING_UTF_8, hostEncoding, !isBinary); + } + if (ArchiveHandlerManager.getInstance().isArchive(destinationFile)) + { + ISystemArchiveHandler handler = ArchiveHandlerManager.getInstance().getRegisteredHandler(destinationFile); + if (handler == null) + throwCorruptArchiveException(this.getClass() + ".copyToArchive()"); + return handler.add(stream, "", remoteFile, SystemEncodingUtil.ENCODING_UTF_8, hostEncoding, !isBinary); + } + + File destinationParent = destinationFile.getParentFile(); + if (!destinationParent.exists()) + { + destinationParent.mkdirs(); + } + + bufInputStream = new BufferedInputStream(inputStream); + outputStream = new FileOutputStream(destinationFile); + + // if encoding conversion required, then we need a writer + boolean isEncodingConversionRequired = !isBinary; + if (isEncodingConversionRequired) + { + outputWriter = new OutputStreamWriter(outputStream, hostEncoding); + bufWriter = new BufferedWriter(outputWriter); + } + else + { + bufOutputStream = new BufferedOutputStream(outputStream); + } + + byte[] buffer = new byte[512000]; + int readCount = 0; + while( (readCount = bufInputStream.read(buffer)) > 0 && !isCancelled) + { + if (isEncodingConversionRequired) + { + String s = new String(buffer, 0, readCount, hostEncoding); + bufWriter.write(s); + } + else + { + bufOutputStream.write(buffer, 0,readCount); + } + if (monitor != null) + { + monitor.worked(readCount); + isCancelled = monitor.isCanceled(); + } + } + + } + catch (FileNotFoundException e) + { + } + catch (UnsupportedEncodingException e) + { + } + catch (IOException e) + { + } + finally + { + + try + { + if (bufWriter != null) + bufWriter.close(); + + if (bufInputStream != null) + bufInputStream.close(); + + if (bufOutputStream != null) + bufOutputStream.close(); + + if (isCancelled) + { + // throw new RemoteFileCancelledException(); + return false; + } + } + catch (IOException e) + { + } + } + return true; + } + + + + public boolean download(IProgressMonitor monitor, String remoteParent, String remoteFile, File destinationFile, boolean isBinary, String hostEncoding) throws SystemMessageException + { + File file = new File(remoteParent, remoteFile); + FileInputStream inputStream = null; + BufferedInputStream bufInputStream = null; + FileOutputStream outputStream = null; + BufferedOutputStream bufOutputStream = null; + OutputStreamWriter outputWriter = null; + BufferedWriter bufWriter = null; + boolean isCancelled = false; + + boolean sourceIsVirtual = ArchiveHandlerManager.isVirtual(file.getAbsolutePath()); + boolean targetIsVirtual = ArchiveHandlerManager.isVirtual(destinationFile.getParent()); + boolean targetIsArchive = ArchiveHandlerManager.getInstance().isArchive(destinationFile.getParentFile()); + if (sourceIsVirtual) + { + return copyFromArchive(file, destinationFile.getParentFile(), destinationFile.getName(), monitor, hostEncoding, SystemEncodingUtil.ENCODING_UTF_8, !isBinary); + } + if (targetIsVirtual || targetIsArchive) + { + return copyToArchive(file, destinationFile.getParentFile(), destinationFile.getName(), monitor, hostEncoding, SystemEncodingUtil.ENCODING_UTF_8, !isBinary); + } + + try + { + + + if (!destinationFile.exists()) + { + File parentDir = destinationFile.getParentFile(); + parentDir.mkdirs(); + } + + + + // encoding conversion required if it a text file but not an xml file + boolean isEncodingConversionRequired = !isBinary; + + inputStream = new FileInputStream(file); + bufInputStream = new BufferedInputStream(inputStream); + outputStream = new FileOutputStream(destinationFile); + + if (isEncodingConversionRequired) + { + outputWriter = new OutputStreamWriter(outputStream, hostEncoding); + bufWriter = new BufferedWriter(outputWriter); + } + else + { + bufOutputStream = new BufferedOutputStream(outputStream); + } + + + byte[] buffer = new byte[512000]; + long totalSize = file.length(); + int totalRead = 0; + + while (totalRead < totalSize && !isCancelled) + { + + int available = bufInputStream.available(); + available = (available < 512000) ? available : 512000; + + int bytesRead = bufInputStream.read(buffer, 0, available); + + if (bytesRead == -1) { + break; + } + + // need to convert encoding, i.e. text file, but not xml + // ensure we read in file using the encoding for the file system + // which can be specified by user as text file encoding in preferences + if (isEncodingConversionRequired) + { + String s = new String(buffer, 0, bytesRead, hostEncoding); + bufWriter.write(s); + } + else + { + bufOutputStream.write(buffer, 0, bytesRead); + } + + totalRead += bytesRead; + + if (monitor != null) + { + monitor.worked(bytesRead); + isCancelled = monitor.isCanceled(); + } + } + } + catch (FileNotFoundException e) + { +// SystemPlugin.logError("Local copy: " + file.getAbsolutePath(), e); +// throw new RemoteFileIOException(e); + return false; + } + catch (UnsupportedEncodingException e) + { +// SystemPlugin.logError("Local copy: " + file.getAbsolutePath(), e); +// throw new RemoteFileIOException(e); + return false; + } + catch (IOException e) + { + // SystemPlugin.logError("Local copy: " + file.getAbsolutePath(), e); + // throw new RemoteFileIOException(e); + return false; + } + finally + { + + try + { + if (bufWriter != null) + bufWriter.close(); + + if (bufInputStream != null) + bufInputStream.close(); + + if (bufOutputStream != null) + bufOutputStream.close(); + + if (isCancelled) + { + // throw new RemoteFileCancelledException(); + return false; + } + } + catch (IOException e) + { + // SystemPlugin.logError("Closing streams: " + file.getAbsolutePath(), e); + // throw new RemoteFileIOException(e); + } + } + return true; + } + + private boolean copyToArchive(File file, File destination, String newName, IProgressMonitor monitor, String sourceEncoding, String targetEncoding, boolean isText) throws SystemMessageException + { + boolean ok = false; + if (ArchiveHandlerManager.isVirtual(destination.getAbsolutePath())) + { + VirtualChild virtualChild = ArchiveHandlerManager.getInstance().getVirtualObject(destination.getAbsolutePath()); + String path = virtualChild.fullName; + if (!virtualChild.isDirectory) + { + path = virtualChild.path; + } + ISystemArchiveHandler handler = virtualChild.getHandler(); + if (handler == null) + throwCorruptArchiveException(this.getClass() + ".copyToArchive()"); + if (file.isDirectory()) + { + ok = handler.add(file, path, newName, sourceEncoding, targetEncoding, _fileTypeRegistry); + } + else + { + ok = handler.add(file, path, newName, sourceEncoding, targetEncoding, isText); + } + } + else if (ArchiveHandlerManager.getInstance().isArchive(destination)) + { + ISystemArchiveHandler handler = ArchiveHandlerManager.getInstance().getRegisteredHandler(destination); + if (handler == null) + throwCorruptArchiveException(this.getClass() + ".copyToArchive()"); + if (file.isDirectory()) + { + ok = handler.add(file, "", newName, sourceEncoding, targetEncoding, _fileTypeRegistry); + } + else + { + ok = handler.add(file, "", newName, sourceEncoding, targetEncoding, isText); + } + } + if (!ok) + { + // SystemPlugin.logError("LocalFileSubSystemImpl.copyToArchive(): Handler's add() method returned false."); + SystemMessage msg = getMessage("RSEF5006"); + msg.makeSubstitution(destination.getName(), "localhost"); + throw new SystemMessageException(msg); + } + else + return true; + } + + public boolean upload(IProgressMonitor monitor, File localFile, String remoteParent, String remoteFile, boolean isBinary, String srcEncoding, String hostEncoding) throws SystemMessageException + { + boolean isCancelled = false; + FileInputStream inputStream = null; + BufferedInputStream bufInputStream = null; + FileOutputStream outputStream = null; + BufferedOutputStream bufOutputStream = null; + OutputStreamWriter outputWriter = null; + BufferedWriter bufWriter = null; + + File target = new File(remoteParent, remoteFile); + boolean sourceIsVirtual = ArchiveHandlerManager.isVirtual(localFile.getAbsolutePath()); + boolean targetIsVirtual = ArchiveHandlerManager.isVirtual(target.getAbsolutePath()); + boolean targetIsArchive = ArchiveHandlerManager.getInstance().isArchive(target); + if (sourceIsVirtual) + { + return copyFromArchive(localFile, target, remoteFile, monitor, srcEncoding, hostEncoding, !isBinary); + } + if (targetIsVirtual || targetIsArchive) + { + return copyToArchive(localFile, target, remoteFile, monitor, srcEncoding, hostEncoding, !isBinary); + } + + try + { + File destinationFile = new File(remoteParent, remoteFile); + int totalSize = (int) localFile.length(); + + File destinationParent = destinationFile.getParentFile(); + if (!destinationParent.exists()) + { + destinationParent.mkdirs(); + } + + inputStream = new FileInputStream(localFile); + bufInputStream = new BufferedInputStream(inputStream); + outputStream = new FileOutputStream(destinationFile); + + // if encoding conversion required, then we need a writer + boolean isEncodingConversionRequired = !isBinary && !srcEncoding.equals(hostEncoding); + if (isEncodingConversionRequired) + { + outputWriter = new OutputStreamWriter(outputStream, hostEncoding); + bufWriter = new BufferedWriter(outputWriter); + } + else + { + bufOutputStream = new BufferedOutputStream(outputStream); + } + + byte[] buffer = new byte[512000]; + int totalRead = 0; + + while (totalRead < totalSize && !isCancelled) { + + int available = bufInputStream.available(); + available = (available < 512000) ? available : 512000; + + int bytesRead = bufInputStream.read(buffer, 0, available); + + if (bytesRead == -1) { + break; + } + + if (isEncodingConversionRequired) { + String s = new String(buffer, 0, bytesRead, srcEncoding); + bufWriter.write(s); + } + else { + bufOutputStream.write(buffer, 0, bytesRead); + } + + totalRead += bytesRead; + + if (monitor != null) { + monitor.worked(bytesRead); + isCancelled = monitor.isCanceled(); + } + } + } + catch (FileNotFoundException e) + { + } + catch (UnsupportedEncodingException e) + { + } + catch (IOException e) + { + } + finally + { + + try + { + if (bufWriter != null) + bufWriter.close(); + + if (bufInputStream != null) + bufInputStream.close(); + + if (bufOutputStream != null) + bufOutputStream.close(); + + if (isCancelled) + { + // throw new RemoteFileCancelledException(); + return false; + } + } + catch (IOException e) + { + } + } + return true; + } + + protected IHostFile[] internalFetch(IProgressMonitor monitor, String remoteParent, String fileFilter, int type) + { + LocalFileNameFilter fFilter = new LocalFileNameFilter(fileFilter); + + File localParent = new File(remoteParent); + + if (remoteParent.endsWith(ArchiveHandlerManager.VIRTUAL_SEPARATOR)) + { + remoteParent = remoteParent.substring(0, remoteParent.length() - ArchiveHandlerManager.VIRTUAL_SEPARATOR.length()); + } + boolean isVirtual = ArchiveHandlerManager.isVirtual(remoteParent); + boolean isArchive = ArchiveHandlerManager.getInstance().isArchive(localParent); + if (isVirtual || isArchive) + { + try + { + VirtualChild[] contents = null; + + File theFile = getContainingArchive(localParent); + + if (isArchive) + { + contents = ArchiveHandlerManager.getInstance().getContents(localParent, ""); + } + else if (isVirtual) + { + AbsoluteVirtualPath avp = new AbsoluteVirtualPath(remoteParent); + contents = ArchiveHandlerManager.getInstance().getContents(theFile, avp.getVirtualPart()); + } + + if (contents == null) + { + return null; + } + + IHostFile[] results = new LocalVirtualHostFile[contents.length]; + + for (int i = 0; i < contents.length; i++) + { + results[i] = new LocalVirtualHostFile(contents[i]); + } + return results; + } + catch (IOException e) + { + // FIXME: Do something! + return null; + } + } + else + { + if (!fFilter.isGeneric()) + { + File file = new File(localParent, fileFilter); + return convertToHostFiles(new File[] { file }, type); + } + if (localParent.exists()) + { + File[] files = localParent.listFiles(fFilter); + return convertToHostFiles(files, type); + } + else + { + return new IHostFile[0]; + } + } + } + + protected IHostFile[] convertToHostFiles(File[] files, int type) + { + List results = new ArrayList(); + if (files != null) + { + for (int i = 0; i < files.length; i++) + { + File file = files[i]; + if (file.isDirectory()) + { + if (type == FILE_TYPE_FILES_AND_FOLDERS || + type == FILE_TYPE_FOLDERS) + { + results.add(new LocalHostFile(file)); + } + } + else if (file.isFile()) + { + if (type == FILE_TYPE_FILES_AND_FOLDERS || + type == FILE_TYPE_FILES) + { + results.add(new LocalHostFile(file)); + } + } + else if (!file.exists()) + { + results.add(new LocalHostFile(file)); + } + } + } + return (IHostFile[])results.toArray(new IHostFile[results.size()]); + } + + public IHostFile getUserHome() + { + String userHome =System.getProperty("user.home"); + File userHomeFile = new File(userHome); + return new LocalHostFile(userHomeFile); + } + + + + public IHostFile[] getRoots(IProgressMonitor monitor) + { + List v = new ArrayList(); + if (isWindows()) + { + for (int idx = 0; idx < ALLDRIVES.length; idx++) + { + File drive = new File(ALLDRIVES[idx]); + if (drive.exists()) + + try + { + v.add(drive.getAbsoluteFile()); + //v.addElement(drive.getCanonicalFile()); + } + catch (Exception e) + { + } + } + } + else + { + v.add(new File("/")); + } + + IHostFile[] fileObjs = new LocalHostFile[v.size()]; + for (int idx = 0; idx < v.size(); idx++) + { + fileObjs[idx] = new LocalHostFile((File) v.get(idx), true); + } + + return fileObjs; + } + + + + public IHostFile getFile(IProgressMonitor monitor, String remoteParent, String name) + { + if (name.endsWith(ArchiveHandlerManager.VIRTUAL_SEPARATOR)) + { + name = name.substring(0, name.length() - ArchiveHandlerManager.VIRTUAL_SEPARATOR.length()); + } + boolean isVirtualParent = ArchiveHandlerManager.isVirtual(remoteParent); + boolean isArchiveParent = ArchiveHandlerManager.getInstance().isArchive(new File(remoteParent)); + if (!isVirtualParent && !isArchiveParent) + { + File file = null; + if (remoteParent == null) + { + file = new File(name); + } + else + { + file = new File(remoteParent, name); + } + File parent = file.getParentFile(); + return new LocalHostFile(file); + } + else + { + String fullpath = remoteParent; + if (isArchiveParent) + { + fullpath = fullpath + ArchiveHandlerManager.VIRTUAL_SEPARATOR; + } + else + { + fullpath = fullpath + "/"; + } + LocalVirtualHostFile results; + VirtualChild vc = ArchiveHandlerManager.getInstance().getVirtualObject(fullpath + name); + results = new LocalVirtualHostFile(vc); + return results; + } + } + + + + public IHostFile createFile(IProgressMonitor monitor, String remoteParent, String fileName) throws SystemMessageException + { + File parentFile = new File(remoteParent); + File fileToCreate = new File(parentFile, fileName); + if (!fileToCreate.exists()) + { + if (ArchiveHandlerManager.isVirtual(fileToCreate.getAbsolutePath())) + { + return createFileInArchive(fileToCreate); + } + else if (!parentFile.exists()) + { + parentFile.mkdirs(); + } + else + { + try + { + fileToCreate.createNewFile(); + if (ArchiveHandlerManager.getInstance().isArchive(fileToCreate)) + { + if (!ArchiveHandlerManager.getInstance().createEmptyArchive(fileToCreate)) + { + // SystemPlugin.logError("LocalFileSubSystemImpl.createFile(): HandlerManager's createEmptyArchive() method returned false."); + throw new SystemMessageException(getMessage("RSEG1122")); + } + } + } + catch (Exception e) + { + } + } + } + return new LocalHostFile(fileToCreate); + } + + protected LocalVirtualHostFile createFileInArchive(File newFile) throws SystemMessageException + { + VirtualChild child = ArchiveHandlerManager.getInstance().getVirtualObject(newFile.getAbsolutePath()); + ISystemArchiveHandler handler = child.getHandler(); + if (handler == null) + throwCorruptArchiveException(this.getClass() + ".createFileInArchive()"); + if (!handler.createFile(child.fullName)) + { + //SystemPlugin.logError("LocalFileSubSystemImpl.createFileInArchive(): Archive Handler's createFile method returned false. Couldn't create virtual object."); + throw new SystemMessageException(getMessage("RSEG1124").makeSubstitution(newFile)); + } + return new LocalVirtualHostFile(child); + } + + private void throwCorruptArchiveException(String classAndMethod) throws SystemMessageException + { + // SystemPlugin.logError(classAndMethod + ": Couldn't instantiate archive handler. Archive could be corrupted."); + throw new SystemMessageException(getMessage("RSEG1122")); + } + + protected File getContainingArchive(File file) + { + String absPath = file.getAbsolutePath(); + AbsoluteVirtualPath avp = new AbsoluteVirtualPath(absPath); + return new File(avp.getContainingArchiveString()); + } + + protected String getVirtualPart(String absPath) + { + AbsoluteVirtualPath avp = new AbsoluteVirtualPath(absPath); + return avp.getVirtualPart(); + } + + public IHostFile createFolder(IProgressMonitor monitor, String remoteParent, String folderName) throws SystemMessageException + { + File folderToCreate = new File(remoteParent, folderName); + if (!folderToCreate.exists()) + { + if (ArchiveHandlerManager.isVirtual(folderToCreate.getAbsolutePath())) + { + return createFolderInArchive(folderToCreate); + } + else + { + folderToCreate.mkdirs(); + } + } + return new LocalHostFile(folderToCreate); + } + + protected LocalVirtualHostFile createFolderInArchive(File newFolder) throws SystemMessageException + { + VirtualChild child = ArchiveHandlerManager.getInstance().getVirtualObject(newFolder.getAbsolutePath()); + ISystemArchiveHandler handler = child.getHandler(); + if (handler == null) + throwCorruptArchiveException(this.getClass() + ".createFolderInArchive()"); + if (!handler.createFolder(child.fullName)) + { + // SystemPlugin.logError("LocalFileSubSystemImpl.createFolderInArchive(): Archive Handler's createFolder method returned false. Couldn't create virtual object."); + throw new SystemMessageException(getMessage("RSEG1124").makeSubstitution(newFolder)); + } + return new LocalVirtualHostFile(child); + } + + public boolean delete(IProgressMonitor monitor, String remoteParent, String fileName) throws SystemMessageException + { + if (fileName.endsWith(ArchiveHandlerManager.VIRTUAL_SEPARATOR)) + { + fileName = fileName.substring(0, fileName.length() - ArchiveHandlerManager.VIRTUAL_SEPARATOR.length()); + } + File fileToDelete = new File(remoteParent, fileName); + if (ArchiveHandlerManager.isVirtual(fileToDelete.getAbsolutePath())) + { + return deleteFromArchive(fileToDelete); + } + else if (ArchiveHandlerManager.getInstance().isArchive(fileToDelete)) + { + return deleteArchive(fileToDelete); + } + if (fileToDelete.isDirectory()) + { + return deleteContents(monitor, fileToDelete); + } + else + { + return fileToDelete.delete(); + } + } + + private boolean deleteContents(IProgressMonitor monitor, File folder) + { + boolean result = true; + File[] files = folder.listFiles(); + for (int i = 0; i < files.length && result; i++) + { + File file = files[i]; + if (file.isDirectory()) + { + result = deleteContents(monitor, file); + } + else + { + result = file.delete(); + } + } + if (result) + { + result = folder.delete(); + } + return result; + } + + /** + * Deletes a virtual file from its archive. + * + * @param destination virtual file to delete from archive + */ + protected boolean deleteFromArchive(File destination) throws SystemMessageException + { + VirtualChild child = ArchiveHandlerManager.getInstance().getVirtualObject(destination.getAbsolutePath()); + ISystemArchiveHandler handler = child.getHandler(); + if (handler == null) + throwCorruptArchiveException(this.getClass() + ".deleteFromArchive()"); + if (!handler.delete(child.fullName)) + { + // SystemPlugin.logError("LocalFileSubSystemImpl.deleteFromArchive(): Archive Handler's delete method returned false. Couldn't delete virtual object."); + throw new SystemMessageException(getMessage("RSEG1125").makeSubstitution(destination)); + } + return true; + } + + protected boolean deleteArchive(File file) + { + ArchiveHandlerManager.getInstance().disposeOfRegisteredHandlerFor(file); + return file.delete(); + } + + public boolean rename(IProgressMonitor monitor, String remoteParent, String oldName, String newName) throws SystemMessageException + { + File fileToRename = new File(remoteParent, oldName); + if (ArchiveHandlerManager.isVirtual(fileToRename.getAbsolutePath())) + { + return renameVirtualFile(fileToRename, newName); + } + File newFile = new File(remoteParent, newName); + return fileToRename.renameTo(newFile); + } + + public boolean rename(IProgressMonitor monitor, String remoteParent, String oldName, String newName, IHostFile oldFile) throws SystemMessageException + { + boolean retVal = rename(monitor, remoteParent, oldName, newName); + File newFile = new File(remoteParent, newName); + oldFile.renameTo(newFile.getAbsolutePath()); + return retVal; + } + + /** + * Renames a virtual file + * + * @param destination virtual file to rename + * @param newName the new name of the virtual file + * @return + */ + protected boolean renameVirtualFile(File destination, String newName) throws SystemMessageException + { + VirtualChild child = ArchiveHandlerManager.getInstance().getVirtualObject(destination.getAbsolutePath()); + ISystemArchiveHandler handler = child.getHandler(); + if (handler == null) + throwCorruptArchiveException(this.getClass() + ".renameVirtualFile()"); + boolean retval = handler.rename(child.fullName, newName); + if (!retval) + { + // SystemPlugin.logError("LocalFileSubSystemImpl.renameVirtualFile(): Archive Handler's rename method returned false. Couldn't rename virtual object."); + throw new SystemMessageException(getMessage("RSEG1127").makeSubstitution(child.fullName)); + } + else return retval; + } + + public boolean move(IProgressMonitor monitor, String srcParent, String srcName, String tgtParent, String tgtName) throws SystemMessageException + { + File sourceFolderOrFile = new File(srcParent, srcName); + File targetFolder = new File(tgtParent, tgtName); + boolean sourceIsVirtual = ArchiveHandlerManager.isVirtual(sourceFolderOrFile.getAbsolutePath()); + boolean targetIsVirtual = ArchiveHandlerManager.isVirtual(targetFolder.getAbsolutePath()); + boolean targetIsArchive = ArchiveHandlerManager.getInstance().isArchive(targetFolder); + if (sourceIsVirtual || targetIsVirtual || targetIsArchive) + /* DKM + * we shouldn't be moving archives like virtuals + *|| ArchiveHandlerManager.getInstance().isRegisteredArchive(newName) + * + */ + { + if (copy(monitor, srcParent, srcName, tgtParent, tgtName)) + { + return delete(monitor, srcParent, srcName); + } + else return false; + } + else + { + File fileToMove = new File(srcParent, srcName); + File newFile = new File(tgtParent, tgtName); + return fileToMove.renameTo(newFile); + } + } + + + + public boolean copy(IProgressMonitor monitor, String srcParent, String srcName, String tgtParent, String tgtName) throws SystemMessageException + { + File srcFile = new File(srcParent, srcName); + File tgtFile = new File(tgtParent, tgtName); + + String command = null; + boolean folderCopy = srcFile.isDirectory(); + String src = srcFile.getAbsolutePath(); + + + String target = tgtFile.getAbsolutePath(); + + boolean sourceIsVirtual = ArchiveHandlerManager.isVirtual(src); + boolean targetIsVirtual = ArchiveHandlerManager.isVirtual(target); + boolean targetIsArchive = ArchiveHandlerManager.getInstance().isArchive(new File(tgtParent)); + if (sourceIsVirtual) + { + return copyFromArchive(srcFile, new File(tgtParent), tgtName, monitor, SystemEncodingUtil.ENCODING_UTF_8, SystemEncodingUtil.ENCODING_UTF_8, false); + } + if (targetIsVirtual || targetIsArchive) + { + return copyToArchive(srcFile, new File(tgtParent), tgtName, monitor, SystemEncodingUtil.ENCODING_UTF_8, SystemEncodingUtil.ENCODING_UTF_8, false); + } + + // handle imbedded blanks of from or to name... + if (src.indexOf(' ') >= 0) + src = "\"" + src + "\""; + if (target.indexOf(' ') >= 0) + target = "\"" + target + "\""; + if (System.getProperty("os.name").toLowerCase().startsWith("win")) + { + if (folderCopy) + { + command = "xcopy " + src + " " + target + " /S /E /K /Q /H /I"; + } + else + command = _osCmdShell + "copy " + src + " " + target; + } + else + { + if (folderCopy) + { + command = "cp -r " + src + " " + target; + } + else // it is a file + { + command = "cp " + src + " " + target; + } + } + int rc = -1; + try + { + Process p = Runtime.getRuntime().exec(command); + rc = p.waitFor(); + //rc = p.exitValue(); + } + catch (Exception e) + { + + } + return (rc == 0); + } + + /** + * Copy a file or folder to a new target parent folder, but if + * copying from an archive, extract the file in the encoding specified + * + * @param sourceFolderOrFile The file or folder to copy + * @param targetFolder The folder to copy to. No guarantee it is on the same system, so be sure to check getSystemConnection()! + * @param newName The new name for the copied file or folder + * @param encoding The encoding for the file once it is extracted from the archive + * @return true iff the copy succeeded + */ + public boolean copyFromArchive(File sourceFolderOrFile, File targetFolder, String newName, IProgressMonitor monitor, String sourceEncoding, String targetEncoding, boolean isText) throws SystemMessageException + { + if (sourceEncoding == null) sourceEncoding = SystemEncodingUtil.ENCODING_UTF_8; + if (sourceEncoding == null) isText = _fileTypeRegistry.isText(sourceFolderOrFile); + if (!(ArchiveHandlerManager.isVirtual(sourceFolderOrFile.getAbsolutePath()))) return false; + String command = null; + boolean folderCopy = sourceFolderOrFile.isDirectory(); + String src = sourceFolderOrFile.getAbsolutePath(); + VirtualChild child = ArchiveHandlerManager.getInstance().getVirtualObject(sourceFolderOrFile.getAbsolutePath()); + if (!(ArchiveHandlerManager.isVirtual(targetFolder.getAbsolutePath())) && !ArchiveHandlerManager.getInstance().isArchive(targetFolder)) + { + // this is an optimization to speed up extractions from large zips. Instead of + // extracting to a temp location and then copying the temp files to the target location + // we simply instruct the handler to extract to the target location. + return child.getExtractedFile(new File(targetFolder, child.name), sourceEncoding, isText); + } + + src = child.getExtractedFile(sourceEncoding, isText).getAbsolutePath(); + + if (child.isDirectory) + { + File tempSource = null; + try + { + tempSource = File.createTempFile(child.name, "virtual"); + tempSource.deleteOnExit(); + } + catch (IOException e) + { + // SystemPlugin.logError("LocalFileSubSystemImpl.copy(): Could not create temp file.", e); + throw new SystemMessageException(getMessage("Copy failed")); + } + tempSource.delete(); + if (!tempSource.mkdir()) + { + // SystemPlugin.logError("LocalFileSubSystemImpl.copy(): Couldn't create temp dir."); + throw new SystemMessageException(getMessage("RSEG1306").makeSubstitution(sourceFolderOrFile)); + } + ISystemArchiveHandler handler = child.getHandler(); + if (handler == null) + throwCorruptArchiveException(this.getClass() + ".copy()"); + handler.extractVirtualDirectory(child.fullName, tempSource, sourceEncoding, isText); + src = tempSource.getAbsolutePath() + File.separatorChar + child.name; + } + if (ArchiveHandlerManager.isVirtual(targetFolder.getAbsolutePath()) || ArchiveHandlerManager.getInstance().isArchive(targetFolder)) + { + File source = new File(src); + return copyToArchive(source, targetFolder, newName, monitor, SystemEncodingUtil.ENCODING_UTF_8, targetEncoding, isText); + } + + String target = targetFolder.getAbsolutePath() + java.io.File.separator + newName; + // handle embedded blanks of from or to name... + if (src.indexOf(' ') >= 0) + src = "\"" + src + "\""; + if (target.indexOf(' ') >= 0) + target = "\"" + target + "\""; + if (System.getProperty("os.name").toLowerCase().startsWith("win")) + { + if (folderCopy) + { + command = "xcopy " + src + " " + target + " /S /E /K /Q /H /I"; + } + else + command = _osCmdShell + "copy " + src + " " + target; + } + else + { + if (folderCopy) + { + command = "cp -r " + src + " " + target; + } + else // it is a file + { + command = "cp " + src + " " + target; + } + } + int rc = -1; + try + { + Process p = Runtime.getRuntime().exec(command); + rc = p.exitValue(); + } + catch (Exception e) + { + + } + return (rc == 0); + } + + public void initService(IProgressMonitor monitor) + { + + } + + public boolean isCaseSensitive() + { + return true; + } + + public boolean copyBatch(IProgressMonitor monitor, String[] srcParents, String[] srcNames, String tgtParent) throws SystemMessageException + { + boolean ok = true; + for (int i = 0; i < srcParents.length; i++) + { + ok = ok && copy(monitor, srcParents[i], srcNames[i], tgtParent, srcNames[i]); + } + return ok; + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalHostFile.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalHostFile.java new file mode 100644 index 00000000000..17cb1232d42 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalHostFile.java @@ -0,0 +1,120 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.local.files; + +import java.io.File; + +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.files.IHostFile; + + +public class LocalHostFile implements IHostFile +{ + private File _file; + private boolean _isRoot = false; + private boolean _isArchive = false; + + public LocalHostFile(File file) + { + _file = file; + _isArchive = ArchiveHandlerManager.getInstance().isArchive(_file); + } + + public LocalHostFile(File file, boolean isRoot) + { + _file = file; + _isRoot = isRoot; + _isArchive = ArchiveHandlerManager.getInstance().isArchive(_file); + + } + + public String getName() + { + if (_isRoot) + { + return _file.getPath(); + } + else + { + return _file.getName(); + } + } + + public boolean isHidden() + { + String name = getName(); + return name.charAt(0) == '.'; + + } + + public String getParentPath() + { + return _file.getParent(); + } + + public boolean isDirectory() + { + return _file.isDirectory(); + } + + public boolean isRoot() + { + return _isRoot; + } + + public boolean isFile() + { + return _file.isFile(); + } + + public File getFile() + { + return _file; + } + + public boolean exists() + { + return _file.exists(); + } + + public String getAbsolutePath() + { + return _file.getAbsolutePath(); + } + + public long getSize() + { + return _file.length(); + } + + public long getModifiedDate() + { + return _file.lastModified(); + } + + public void renameTo(String newAbsolutePath) + { + _file = new File(newAbsolutePath); + _isArchive = ArchiveHandlerManager.getInstance().isArchive(_file); + } + + public boolean isArchive() + { + return _isArchive; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalServiceResources.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalServiceResources.java new file mode 100644 index 00000000000..eb24392f89f --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalServiceResources.java @@ -0,0 +1,37 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.local.files; + +import org.eclipse.osgi.util.NLS; + +public class LocalServiceResources extends NLS +{ + private static String BUNDLE_NAME = "org.eclipse.rse.services.local.files.LocalServiceResources";//$NON-NLS-1$ + + public static String Local_File_Service_Name; + public static String Local_Process_Service_Name; + public static String Local_Shell_Service_Name; + + public static String Local_File_Service_Description; + public static String Local_Process_Service_Description; + public static String Local_Shell_Service_Description; + + static { + // load message values from bundle file + NLS.initializeMessages(BUNDLE_NAME, LocalServiceResources.class); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalServiceResources.properties b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalServiceResources.properties new file mode 100644 index 00000000000..5819739b20a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalServiceResources.properties @@ -0,0 +1,23 @@ +################################################################################ +# Copyright (c) 2006 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: +# {Name} (company) - description of contribution. +################################################################################ + +Local_File_Service_Name=Local File Service +Local_Process_Service_Name=Local Process Service +Local_Shell_Service_Name=Local Shell Service + +Local_File_Service_Description=The Local File Service uses Java API to provide service to the Files subsystem on the local machine. +Local_Process_Service_Description=The Local File Service uses Java API to provide service to the Processes subsystem on the local machine. +Local_Shell_Service_Description=The Local File Service uses Java API to provide service to the Shells subsystem on the local machine. \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalVirtualHostFile.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalVirtualHostFile.java new file mode 100644 index 00000000000..3b0e7a7073d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/files/LocalVirtualHostFile.java @@ -0,0 +1,91 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.local.files; + +import java.io.File; + +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; + +public class LocalVirtualHostFile extends LocalHostFile +{ + protected File _parentArchive; + protected VirtualChild _child; + + public LocalVirtualHostFile(VirtualChild child) + { + super(child.getContainingArchive()); + _child = child; + _parentArchive = _child.getContainingArchive(); + } + + public String getName() + { + return _child.name; + } + + public String getParentPath() + { + return _parentArchive.getAbsolutePath() + ArchiveHandlerManager.VIRTUAL_SEPARATOR + _child.path; + } + + public boolean isDirectory() + { + return _child.isDirectory; + } + + public boolean isRoot() + { + return false; + } + + public boolean isFile() + { + return !_child.isDirectory; + } + + public File getFile() + { + return _parentArchive; + } + + public boolean exists() + { + return _child.exists(); + } + + public String getAbsolutePath() + { + return _child.getContainingArchive().getAbsolutePath() + ArchiveHandlerManager.VIRTUAL_SEPARATOR + _child.fullName; + } + + public VirtualChild getChild() + { + return _child; + } + + public boolean isHidden() + { + return false; + } + + public boolean isArchive() + { + return false; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/processes/LocalProcessService.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/processes/LocalProcessService.java new file mode 100644 index 00000000000..bf8bb224426 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/processes/LocalProcessService.java @@ -0,0 +1,151 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.local.processes; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.SortedSet; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.services.clientserver.processes.IHostProcess; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.clientserver.processes.IHostProcessFilter; +import org.eclipse.rse.services.clientserver.processes.handlers.ProcessHandler; +import org.eclipse.rse.services.clientserver.processes.handlers.ProcessHandlerManager; +import org.eclipse.rse.services.local.ILocalService; +import org.eclipse.rse.services.local.files.LocalServiceResources; +import org.eclipse.rse.services.processes.AbstractProcessService; +import org.eclipse.rse.services.processes.IProcessService; + +public class LocalProcessService extends AbstractProcessService implements ILocalService, IProcessService +{ + protected String[] _statusTypes; + protected ProcessHandler handler; + + public LocalProcessService() + { + handler = ProcessHandlerManager.getInstance().getNewProcessHandler(); + } + + public String getName() + { + return LocalServiceResources.Local_Process_Service_Name; + } + + public String getDescription() + { + return LocalServiceResources.Local_Process_Service_Description; + } + + public IHostProcess[] listAllProcesses(IProgressMonitor monitor, IHostProcessFilter filter) throws SystemMessageException + { + IHostProcess[] processes = null; + + if (handler == null) return null; + try + { + SortedSet results = handler.lookupProcesses(filter); + processes = (IHostProcess[]) results.toArray(new IHostProcess[results.size()]); + } + catch (Exception e) + { + throw new SystemMessageException(getMessage("RSEPG1301")); + } + return processes; + } + + public boolean kill(IProgressMonitor monitor, long PID, String signal) throws SystemMessageException + { + IHostProcess process = null; + try + { + process = getProcess(monitor, PID); + handler.kill(process, signal); + return true; + } + catch (InterruptedException e) + { + throw new SystemMessageException(getMessage("RSEG1067")); + } + catch (Exception e) + { + String name = ""; + if (process != null) name += process.getName(); + String pid = ""; + if (process != null) pid += process.getPid(); + + SystemMessage msg = getMessage("RSEPG1300"); + msg.makeSubstitution(name + " (" + pid + ")", e.getMessage()); + throw new SystemMessageException(msg); + } + } + + public String[] getSignalTypes() + { + if (_statusTypes != null) + { + return _statusTypes; + } + else + { + _statusTypes = internalGetSignalTypes(); + } + return _statusTypes; + } + + /** + * Returns a list of the signal types supported by the 'kill' command on this system + * @return a list of the signal types or null if there are none or there is an error in + * executing the kill command. + */ + protected String[] internalGetSignalTypes() + { + try + { + // use the kill command to find out the signal types + Process kill = Runtime.getRuntime().exec("kill -l"); + InputStreamReader isr = new InputStreamReader(kill.getInputStream()); + if (isr == null) return null; + BufferedReader reader = new BufferedReader(isr); + if (reader == null) return null; + String nextLine = reader.readLine(); + String output = ""; + while (nextLine != null) + { + output = output + nextLine + "\n"; + nextLine = reader.readLine(); + } + reader.close(); + isr.close(); + if (output.equals("")) throw new Exception(); + String[] lines = output.trim().split("\\s+"); + if (lines == null) throw new Exception(); + return lines; + } + catch (Exception e) + { + //SystemPlugin.logError("LocalProcessSubSystemImpl.getSignalTypes() 'kill -l' command failed.", e); + return null; + } + } + + public void initService(IProgressMonitor monitor) + { + + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/search/LocalSearchHandler.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/search/LocalSearchHandler.java new file mode 100644 index 00000000000..484a8b7601a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/search/LocalSearchHandler.java @@ -0,0 +1,504 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.local.search; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashSet; +import java.util.Iterator; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.internal.services.local.search.LocalSearchResult; +import org.eclipse.rse.services.clientserver.StringCompare; +import org.eclipse.rse.services.clientserver.SystemFileClassifier; +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; +import org.eclipse.rse.services.clientserver.search.SystemSearchFileNameMatcher; +import org.eclipse.rse.services.clientserver.search.SystemSearchLineMatch; +import org.eclipse.rse.services.clientserver.search.SystemSearchMatch; +import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatchLocator; +import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.files.IHostFile; +import org.eclipse.rse.services.local.files.LocalHostFile; +import org.eclipse.rse.services.local.files.LocalVirtualHostFile; +import org.eclipse.rse.services.search.IHostSearchConstants; +import org.eclipse.rse.services.search.IHostSearchResult; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.services.search.ISearchHandler; + +/** + * Class used to collect local search results. + */ +public class LocalSearchHandler implements ISearchHandler +{ + + protected HashSet _alreadySearched; + + protected IHostSearchResultConfiguration _searchConfig; + + protected File _theFile; + + protected int _depth = -1; + + protected IFileService _fs; + + protected boolean _isDone; + + protected boolean _isCancelled; + + protected LocalHostFile _theRmtFile; + + protected SystemSearchString _searchString; + + protected SystemSearchStringMatcher _stringMatcher; + + protected boolean _isFileSearch; + + protected SystemSearchFileNameMatcher _fileNameMatcher; + + protected String _classificationString; + + /** + * Constructor for local search handler. + * + * @param shell + * a shell. + * @param searchConfig + * a search configuration. + */ + public LocalSearchHandler(IHostSearchResultConfiguration searchConfig, IFileService fileService) + { + + _searchConfig = searchConfig; + + _theRmtFile = (LocalHostFile) (searchConfig.getSearchTarget()); + + // if the remote file is not virtual, then simply get the file + if (!(_theRmtFile instanceof LocalVirtualHostFile)) + { + _theFile = (File) (_theRmtFile.getFile()); + } + // for virtual file, fake it with a non-existent file representing the + // actual path (note this file won't actually exist on the filesystem) + else + { + String absPath = _theRmtFile.getAbsolutePath(); + AbsoluteVirtualPath avp = new AbsoluteVirtualPath(absPath); + _theFile = new File(avp.toString()); + } + + _fs = fileService; + + _searchString = searchConfig.getSearchString(); + + boolean includeSubfolders = _searchString.isIncludeSubfolders(); + + if (includeSubfolders) + { + _depth = -1; + } + else + { + _depth = 1; + } + + _isCancelled = false; + _isDone = false; + _alreadySearched = new HashSet(); + + _stringMatcher = new SystemSearchStringMatcher(_searchString.getTextString(), _searchString.isCaseSensitive(), + _searchString.isTextStringRegex()); + + // if the search string is empty or if it is an asterisk, then we are + // doing a file search + // i.e. we do not want to look inside files + _isFileSearch = _stringMatcher.isSearchStringEmpty() || _stringMatcher.isSearchStringAsterisk(); + + boolean fsCaseSensitive = _fs.isCaseSensitive(); + _fileNameMatcher = new SystemSearchFileNameMatcher(_searchString.getFileNamesString(), fsCaseSensitive, + _searchString.isFileNamesRegex()); + + // classification of files to restrict the search to + _classificationString = _searchString.getClassificationString(); + } + + public void search(IProgressMonitor monitor) + { + + // start search + // pass in the context of the target file + internalSearch(_theFile, _depth, _theRmtFile); + + _isDone = true; + + if (!_isCancelled) + { + _searchConfig.setStatus(IHostSearchConstants.FINISHED); + } + else + { + _searchConfig.setStatus(IHostSearchConstants.CANCELLED); + } + } + + public boolean isDone() + { + return _isDone; + } + + public void cancel(IProgressMonitor monitor) + { + _isCancelled = true; + } + + private boolean hasSearchedDirectory(File file) + { + return _alreadySearched.contains(file); + } + + private boolean internalSearch(File theFile, int depth, IHostFile context) + { + + boolean foundFile = false; + + // is it a directory? (note that for virtual the file won't exist, so it + // will + // return false, which is what we want!) + boolean isDirectory = theFile.isDirectory(); + + // is it an archive? + boolean isArchive = ArchiveHandlerManager.getInstance().isArchive(theFile); + + String absPath = theFile.getAbsolutePath(); + String compareStr = theFile.getName(); + + // is it a virtual file? + boolean isVirtual = ArchiveHandlerManager.isVirtual(absPath); + + // is it a virtual directory? + boolean isVirtualDirectory = false; + + VirtualChild vc = null; + + // if it is a virtual object, then get a reference to it + if (isVirtual) + { + vc = ArchiveHandlerManager.getInstance().getVirtualObject(absPath); + isVirtualDirectory = isVirtual && vc.isDirectory; + } + + // base case for the recursive method call + // if the file is not a directory, an archive or a virtual directory, + // and we get a match with the file name, then we can search for match + // within the file + if (!isDirectory && !isArchive && !isVirtualDirectory && doesFilePatternMatch(compareStr) + && doesClassificationMatch(absPath)) + { + + LocalHostFile file; + + // if the file is a virtual file, then get matches from the archive + // handler + if (isVirtual) + { + file = new LocalVirtualHostFile(vc); + + SystemSearchLineMatch[] matches = null; + + // if it is not a file search, then call the handler search + // method + if (!_isFileSearch) + { + matches = vc.getHandler().search(vc.fullName, _stringMatcher); + IHostSearchResult[] results = convert(file, matches); + + /** TODO - how to store search results related to files + // if there is at least one match, then add the file to the + // search results + if (results != null && results.length > 0) + { + file.setContents(IHostSearchResultsContentsType.getInstance(), _searchString.toString(), + results); + _searchConfig.addResult(file); + } + + **/ + _searchConfig.addResults(file, results); + } + // otherwise add the file to the search results + else + { + _searchConfig.addResult(file); + } + } + // otherwise, search the file + else + { + + // note that the file can not be root + file = new LocalHostFile(theFile, false); + + /* TODO + if (!isArchive) + { + file.setIsContainer(false); + } + else + { + file.setIsContainer(true); + } + */ + + // if file search, add the file to the results + // otherwise, search within the file and if there is at least + // one text match, then add it + if (_isFileSearch || internalSearchWithinFile(file, theFile)) + { + _searchConfig.addResult(file); + } + else + { + _searchConfig.addResult(file); + } + } + + // indicate that we have found a file + foundFile = true; + + if (foundFile) + { + // TODO refresh(_isDone); + foundFile = false; + } + } + + // if the depth is not 0, then we need to recursively search + if (depth != 0) + { + + // if it is a directory, or an archive, or a virtual directory, then + // we need to get the + // children and search those + if (isDirectory || isArchive || isVirtualDirectory) + { + + if (!hasSearchedDirectory(theFile)) + { + + _alreadySearched.add(theFile); + + File[] children = null; + + // if the file is an archive or a virtual directory, then + // get the children from + // the archive handler + if (isArchive || isVirtualDirectory) + { + + AbsoluteVirtualPath avp = new AbsoluteVirtualPath(absPath); + File archive = new File(avp.getContainingArchiveString()); + String virtualPath = avp.getVirtualPart(); + + VirtualChild[] virtualchildren = null; + + try + { + virtualchildren = ArchiveHandlerManager.getInstance().getContents(archive, virtualPath); + } + catch (IOException e) + { + //SystemPlugin.logError("An erorr occured trying to retrieve virtual file " + virtualPath + // + " for " + archive.getAbsolutePath(), e); + } + + if (virtualchildren != null) + { + children = new File[virtualchildren.length]; + + for (int i = 0; i < virtualchildren.length; i++) + { + AbsoluteVirtualPath newAvp = new AbsoluteVirtualPath(absPath); + newAvp.setVirtualPart(virtualchildren[i].fullName); + children[i] = new File(newAvp.toString()); + } + + if (virtualchildren.length == 0) + { + children = null; + } + } + } + else + { + children = theFile.listFiles(); + } + + if (children != null) + { + + LocalHostFile fileImpl = null; + + // create local file for archive or directory which is + // not virtual + if (!isVirtualDirectory) + { + + // if the context's parent file (which is + // essentially the parent file of + // the given file) is null, then it means the given + // file is root + boolean isRoot = false; //TODO + + fileImpl = new LocalHostFile(theFile, isRoot); + } + // create local file differently for virtual directory + else + { + fileImpl = new LocalVirtualHostFile(vc); + } + + for (int i = 0; i < children.length && !_isCancelled; i++) + { + + File child = children[i]; + + if (internalSearch(child, depth - 1, fileImpl)) + { + foundFile = true; + } + } + } + } + } + } + + return foundFile; + } + + + private boolean internalSearchWithinFile(IHostFile remoteFile, File theFile) + { + + // if file search, no need to look for matches within file + if (_isFileSearch) + { + return true; + } + + FileInputStream inputStream = null; + + try + { + inputStream = new FileInputStream(theFile); + InputStreamReader reader = new InputStreamReader(inputStream); + BufferedReader bufReader = new BufferedReader(reader); + + SystemSearchStringMatchLocator locator = new SystemSearchStringMatchLocator(bufReader, _stringMatcher); + + SystemSearchLineMatch[] matches = locator.locateMatches(); + + if (matches == null || matches.length == 0) + { + return false; + } + + IHostSearchResult[] results = convert(remoteFile, matches); + _searchConfig.addResults(remoteFile, results); + + // TODO - how to store results related to files + //remoteFile.setContents(IHostSearchResultsContentsType.getInstance(), _searchString.toString(), results); + + return true; + } + catch (IOException e) + { + //SystemPlugin.logError("Error occured when trying to locate matches", e); + return false; + } + } + + protected boolean doesFilePatternMatch(String compareStr) + { + return _fileNameMatcher.matches(compareStr); + } + + /** + * Returns whether classification matches. + * + * @param absolutePath + * the absolute path of the file for which we want to check + * classification. + * @return true if the classification matches, + * false otherwise. + */ + protected boolean doesClassificationMatch(String absolutePath) + { + + if (_classificationString == null || _classificationString.equals("")) + { + return true; + } + else + { + String classification = SystemFileClassifier.getInstance().classifyFile(absolutePath); + return StringCompare.compare(_classificationString, classification, true); + } + } + + /** + * Converts from system line matches to remote search results that will show + * up in the remote search view. + * + * @param remoteFile + * the remote file for which line matches have been found. + * @param lineMatches + * an array of line matches, or empty if no matches. + * @return an array of remote search results, or empty if no matches. + */ + private IHostSearchResult[] convert(IHostFile remoteFile, SystemSearchLineMatch[] lineMatches) + { + + LocalSearchResult[] results = new LocalSearchResult[lineMatches.length]; + + for (int i = 0; i < lineMatches.length; i++) + { + results[i] = new LocalSearchResult(_searchConfig, remoteFile, _searchString); + results[i].setText(lineMatches[i].getLine()); + results[i].setLine(lineMatches[i].getLineNumber()); + results[i].setIndex(i); + + Iterator iter = lineMatches[i].getMatches(); + + // add matches within the line + while (iter.hasNext()) + { + SystemSearchMatch match = (SystemSearchMatch) iter.next(); + int startOffset = match.getStartOffset(); + int endOffset = match.getEndOffset(); + results[i].addMatch(startOffset, endOffset); + } + } + + return results; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/search/LocalSearchService.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/search/LocalSearchService.java new file mode 100644 index 00000000000..dc84fcc53d3 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/search/LocalSearchService.java @@ -0,0 +1,39 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.local.search; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.search.AbstractSearchService; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.services.search.ISearchHandler; + + + + +public class LocalSearchService extends AbstractSearchService +{ + + public ISearchHandler internalSearch(IProgressMonitor monitor, IHostSearchResultConfiguration searchConfig, IFileService fileService) + { + LocalSearchHandler handler = new LocalSearchHandler(searchConfig, fileService); + searchConfig.setSearchHandler(handler); + handler.search(monitor); + return handler; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/shells/Activator.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/shells/Activator.java new file mode 100644 index 00000000000..2c0e87d3bdb --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/shells/Activator.java @@ -0,0 +1,70 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.local.shells; + +import org.eclipse.ui.plugin.*; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class Activator extends AbstractUIPlugin { + + //The shared instance. + private static Activator plugin; + + /** + * The constructor. + */ + public Activator() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static Activator getDefault() { + 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.services.shells.local", path); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/shells/LocalHostShell.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/shells/LocalHostShell.java new file mode 100644 index 00000000000..c18bb81d65b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/shells/LocalHostShell.java @@ -0,0 +1,81 @@ +/******************************************************************************** + * Copyright (c) 2005, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.local.shells; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.internal.services.local.shells.LocalShellOutputReader; +import org.eclipse.rse.internal.services.local.shells.LocalShellThread; +import org.eclipse.rse.services.shells.AbstractHostShell; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IHostShellOutputReader; + +/** + * @author dmcknigh + * + */ +public class LocalHostShell extends AbstractHostShell implements IHostShell +{ + private LocalShellThread _shellThread; + private LocalShellOutputReader _stdoutHandler; + private LocalShellOutputReader _stderrHandler; + + public LocalHostShell(String initialWorkingDirectory, String invocation, String encoding, String[] environment) + { + _shellThread = new LocalShellThread(initialWorkingDirectory, invocation, encoding, environment); + _stdoutHandler = new LocalShellOutputReader(this, _shellThread.getOutputStream(), false); + _stderrHandler = new LocalShellOutputReader(this, _shellThread.getErrorStream(),true); + } + + protected void run(IProgressMonitor monitor) + { + _shellThread.start(); + } + + + /* (non-Javadoc) + * @see org.eclipse.rse.services.shells.IHostShell#isActive() + */ + public boolean isActive() + { + return _shellThread.isAlive(); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.services.shells.IHostShell#writeToStdin(java.lang.String) + */ + public void writeToShell(String command) + { + _shellThread.sendInput(command); + } + + public IHostShellOutputReader getStandardOutputReader() + { + return _stdoutHandler; + } + + public IHostShellOutputReader getStandardErrorReader() + { + return _stderrHandler; + } + + public void exit() + { + writeToShell("exit"); + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/shells/LocalShellService.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/shells/LocalShellService.java new file mode 100644 index 00000000000..3e7a68a66fc --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/services/local/shells/LocalShellService.java @@ -0,0 +1,144 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.services.local.shells; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.services.local.ILocalService; +import org.eclipse.rse.services.local.files.LocalServiceResources; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IShellService; + +public class LocalShellService implements IShellService, ILocalService +{ + private static final String SHELL_INVOCATION = ">"; + private String[] _envVars; + + public LocalShellService() + { + } + + public String getName() + { + return LocalServiceResources.Local_Shell_Service_Name; + } + + public String getDescription() + { + return LocalServiceResources.Local_Shell_Service_Description; + } + + public IHostShell launchShell(IProgressMonitor monitor, String initialWorkingDirectory, String[] environment) + { + String defaultEncoding = System.getProperty("file.encoding"); + return launchShell(monitor, initialWorkingDirectory, defaultEncoding, environment); + } + + public IHostShell launchShell(IProgressMonitor monitor, String initialWorkingDirectory, String encoding, String[] environment) + { + LocalHostShell hostShell = new LocalHostShell(initialWorkingDirectory,SHELL_INVOCATION, encoding, environment); + hostShell.run(monitor); + return hostShell; + } + + public IHostShell runCommand(IProgressMonitor monitor, String initialWorkingDirectory, String command, String[] environment) + { + String defaultEncoding = System.getProperty("file.encoding"); + return runCommand(monitor, initialWorkingDirectory, command, defaultEncoding, environment); + } + + public IHostShell runCommand(IProgressMonitor monitor, String initialWorkingDirectory, String command, String encoding, String[] environment) + { + LocalHostShell hostShell = new LocalHostShell(initialWorkingDirectory,command, encoding, environment); + hostShell.run(monitor); + return hostShell; + } + + public String[] getHostEnvironment() + { + if (_envVars == null) + { + List envVars = new ArrayList(); + + String[] envCommand = new String[3]; + //If we're on windows, change the envCommand. + if (System.getProperty("os.name").toLowerCase().startsWith("win")) + { + envCommand[0] = "cmd"; + envCommand[1] = "/c"; + envCommand[2] = "set"; + } + else + { + envCommand[0] = "sh"; + envCommand[1] = "-c"; + envCommand[2] = "env"; + } + + BufferedReader reader = null; + try + { + Process process = Runtime.getRuntime().exec(envCommand); + InputStream stdout = process.getInputStream(); + InputStreamReader ireader = new InputStreamReader(stdout); + + reader = new BufferedReader(ireader); + String curLine = null; + while ((curLine = reader.readLine()) != null) + { + if (curLine.indexOf("=") > 0) + { + envVars.add(curLine); + } + } + reader.close(); + process.exitValue(); + } + catch (Exception e) + { + if (reader != null) + { + try + { + reader.close(); + } + catch (Exception ex) + { + } + } + } + _envVars = (String[])envVars.toArray(new String[envVars.size()]); + } + return _envVars; + } + + public void initService(IProgressMonitor monitor) + { + + } + + public SystemMessage getMessage(String messageID) + { + return null; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/.classpath b/rse/plugins/org.eclipse.rse.shells.ui/.classpath new file mode 100644 index 00000000000..751c8f2e504 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/rse/plugins/org.eclipse.rse.shells.ui/.cvsignore b/rse/plugins/org.eclipse.rse.shells.ui/.cvsignore new file mode 100644 index 00000000000..ba077a4031a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/rse/plugins/org.eclipse.rse.shells.ui/.project b/rse/plugins/org.eclipse.rse.shells.ui/.project new file mode 100644 index 00000000000..9ab0849b088 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/.project @@ -0,0 +1,28 @@ + + + org.eclipse.rse.shells.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/rse/plugins/org.eclipse.rse.shells.ui/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.shells.ui/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..d43737041e2 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/META-INF/MANIFEST.MF @@ -0,0 +1,29 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin.name +Bundle-SymbolicName: org.eclipse.rse.shells.ui;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.rse.shells.ui.Activator +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.rse.services, + org.eclipse.core.resources, + org.eclipse.ui.views, + org.eclipse.jface.text, + org.eclipse.ui.workbench.texteditor, + org.eclipse.ui.editors, + org.eclipse.ui.forms, + org.eclipse.ui.ide, + org.eclipse.debug.core, + org.eclipse.rse.files.ui, + org.eclipse.rse.subsystems.shells.core, + org.eclipse.rse.subsystems.files.core, + org.eclipse.rse.ui +Eclipse-LazyStart: true +Export-Package: org.eclipse.rse.shells.ui, + org.eclipse.rse.shells.ui.actions, + org.eclipse.rse.shells.ui.propertypages, + org.eclipse.rse.shells.ui.view +Bundle-Vendor: Eclipse.org +Bundle-ClassPath: shells_ui.jar diff --git a/rse/plugins/org.eclipse.rse.shells.ui/about.html b/rse/plugins/org.eclipse.rse.shells.ui/about.html new file mode 100644 index 00000000000..6f6b96c4c87 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/about.html @@ -0,0 +1,22 @@ + + + +About + + + +

About This Content

+ +

February 24, 2005

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content.

+ + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/build.properties b/rse/plugins/org.eclipse.rse.shells.ui/build.properties new file mode 100644 index 00000000000..356b100dff5 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/build.properties @@ -0,0 +1,14 @@ +bin.includes = META-INF/,\ + plugin.xml,\ + about.html,\ + icons/,\ + plugin.properties,\ + shells_ui.jar +src.includes = META-INF/,\ + about.html,\ + icons/,\ + plugin.properties,\ + plugin.xml +source.shells_ui.jar = src/ +jars.compile.order = shells_ui.jar +output.shells_ui.jar = bin/ diff --git a/rse/plugins/org.eclipse.rse.shells.ui/icons/full/cview16/commands_view.gif b/rse/plugins/org.eclipse.rse.shells.ui/icons/full/cview16/commands_view.gif new file mode 100644 index 0000000000000000000000000000000000000000..093c6bad04348793bb198ed35e4273841b7b854a GIT binary patch literal 347 zcmZ?wbhEHb6krfwxXQqA_{8Oys#O!09zS~Ol1}6l&HN*pxd*lK4rt}<)ymqTnZ8Lc zcehsZYMs>8dYK!wBBy9aOw^8;pdHq$o3r)z-~WyK-gX^+H|^BNr5C?!x%K1Fqu&=^ z{r&#u|L5QT-~al5_4EJNKmWh`_5bD1|8IW%fB*ac=Rf~{|NH;z-~Y4c&t@msbr%~q z=b2V#S`?>Pr^VPOMmkQb)SpylFsaP2r`V_^&$K4f;{X5u47h>fPZmZ71~Ud7kP?ue z7}zQtX8ST#8i;VVEL6zh;uby4I{9MG48MgcP8k+z-OOg(zh|76j|h|a-Eptr=B;H# z?C;*+ob!#5m4#7RS-V(AUap)`QN^@aS6)?>aiXk7r=O<0j7(=|gP)$fnh2wax(M@h eU;Q-^f78}2yEi#9SOWlu>Xowq literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.shells.ui/icons/full/cview16/errorlist_view.gif b/rse/plugins/org.eclipse.rse.shells.ui/icons/full/cview16/errorlist_view.gif new file mode 100644 index 0000000000000000000000000000000000000000..cc87d38aa0a1b26e02c85a621d6ce447e9dbf97c GIT binary patch literal 604 zcmZ?wbhEHb6krfwc*ekRP*ifisKkH&p#KTU|H~_`ib-D)lfEOR@ZUfDe{j@C|Iq)T zQ6GcDKZQpAk4^laSNzh{?tg6B|E$8lfB)q*uPf=?bn4QhZ$JM0{`2qWuRlM2{;ulZ z);i}%$D9N2KmTf&w!3TLi3!V3Pg{GjZ_$y7OOMapbZzO*+h?vmxpeFK(>Fh!zx%o7 z;KR+wpY_gI`Rc>Z2d{oSdj0*)r(a*b|9<@D`}6ldKYsiD{ny{0zyHpfIbrVX-UV~J zmoDg>J+uGz&GY*Yt0?n7Kj(jL?*FAr|F2l_9}E}<2T=UU!pOi7#GnIm4k%6-*mpJrH3fNj`gnOb zcXc~A`}q5M`}+t>PMg*n)F0^YKWEBxNtYl2UcY&B{Fns9L`9@rgBS%lI06H=3NlKF z@3jkJ=jL4D&&kccR>a6{3D>;2bGQV|O|RNFvGE58@dfa+s!Okvb7*GeVP@fBH8Xto z&b@gFJA;6Rto$PpJ;zVBCR!OBG8zT#Hj0`a6C^GwwmP?4J$c$-$lT^Cq3BT1FwuG5 e6fu3LeFBCY?EL*f5o-(rnUm1RU=08!bm#>D literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.shells.ui/icons/full/eview16/commands_view.gif b/rse/plugins/org.eclipse.rse.shells.ui/icons/full/eview16/commands_view.gif new file mode 100644 index 0000000000000000000000000000000000000000..093c6bad04348793bb198ed35e4273841b7b854a GIT binary patch literal 347 zcmZ?wbhEHb6krfwxXQqA_{8Oys#O!09zS~Ol1}6l&HN*pxd*lK4rt}<)ymqTnZ8Lc zcehsZYMs>8dYK!wBBy9aOw^8;pdHq$o3r)z-~WyK-gX^+H|^BNr5C?!x%K1Fqu&=^ z{r&#u|L5QT-~al5_4EJNKmWh`_5bD1|8IW%fB*ac=Rf~{|NH;z-~Y4c&t@msbr%~q z=b2V#S`?>Pr^VPOMmkQb)SpylFsaP2r`V_^&$K4f;{X5u47h>fPZmZ71~Ud7kP?ue z7}zQtX8ST#8i;VVEL6zh;uby4I{9MG48MgcP8k+z-OOg(zh|76j|h|a-Eptr=B;H# z?C;*+ob!#5m4#7RS-V(AUap)`QN^@aS6)?>aiXk7r=O<0j7(=|gP)$fnh2wax(M@h eU;Q-^f78}2yEi#9SOWlu>Xowq literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.shells.ui/icons/full/eview16/errorlist_view.gif b/rse/plugins/org.eclipse.rse.shells.ui/icons/full/eview16/errorlist_view.gif new file mode 100644 index 0000000000000000000000000000000000000000..cc87d38aa0a1b26e02c85a621d6ce447e9dbf97c GIT binary patch literal 604 zcmZ?wbhEHb6krfwc*ekRP*ifisKkH&p#KTU|H~_`ib-D)lfEOR@ZUfDe{j@C|Iq)T zQ6GcDKZQpAk4^laSNzh{?tg6B|E$8lfB)q*uPf=?bn4QhZ$JM0{`2qWuRlM2{;ulZ z);i}%$D9N2KmTf&w!3TLi3!V3Pg{GjZ_$y7OOMapbZzO*+h?vmxpeFK(>Fh!zx%o7 z;KR+wpY_gI`Rc>Z2d{oSdj0*)r(a*b|9<@D`}6ldKYsiD{ny{0zyHpfIbrVX-UV~J zmoDg>J+uGz&GY*Yt0?n7Kj(jL?*FAr|F2l_9}E}<2T=UU!pOi7#GnIm4k%6-*mpJrH3fNj`gnOb zcXc~A`}q5M`}+t>PMg*n)F0^YKWEBxNtYl2UcY&B{Fns9L`9@rgBS%lI06H=3NlKF z@3jkJ=jL4D&&kccR>a6{3D>;2bGQV|O|RNFvGE58@dfa+s!Okvb7*GeVP@fBH8Xto z&b@gFJA;6Rto$PpJ;zVBCR!OBG8zT#Hj0`a6C^GwwmP?4J$c$-$lT^Cq3BT1FwuG5 e6fu3LeFBCY?EL*f5o-(rnUm1RU=08!bm#>D literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.shells.ui/icons/full/obj16/exportshellhistory.gif b/rse/plugins/org.eclipse.rse.shells.ui/icons/full/obj16/exportshellhistory.gif new file mode 100644 index 0000000000000000000000000000000000000000..f4ec50b5d9ed1bf0f8fb3bf15e14bd5c2adf4429 GIT binary patch literal 592 zcmZ?wbhEHb6krfwc*el+{rjJmzC{tmi(2{@we&6AapdOXmtR`?7e<#Yh$&x?R5fqa zo@)orKRtfs`L1I(p1uG3;Mx1c>UsOmKizfw=83D%FWi3h_QRL-`Z*i-ojVTVzP$P9 z?SmJe((30tc>X@8d3H|otdr+1KY#P_){CzN?XwEoXWoAKwSVfYcVB+qdinMC%P*x} zGy0~^di&+)yDvXJ{`z0pJN?4P|5bg{o_zoR?(2{G3De$w{qgb3*ZK)lKmPf@e$W1l z%9_SWQ&(==aqaHyIddn@nLA@{xhU-acJS9h~h=RxpI^BB>g|Uw8~2?%4r0H&`RHw0{hXZU*(c9k ze*Wg;truSl+h^W>`SsnGpQT+h-hTP{;oGlwUw$0FaHXnm+Pkkm>L*Nl`}N1iFJJ2? zOkKZce@10ZGF>sc|U#>{PG_X^#o@u6Ir?0E8Z*1(qWIEGO#x8tEP*CWey`k}X8e%PW4#8e0 zPDaOTsVl3i%Ld2AdS1I060fPGrpC)F73{&rDJbA^nqN|pmx1wetox@=QSp2{61*a! z(!p+ALUt7fLF*5+vhuF;XmoG!nAjG%Z;C=g!+{27_GLUX86F*;q!wXh*`)5mF9X(Ss|A=PpLCw5_S~+{QviE3aZP&`$p_#r(3y4zIXeF=K zN?fWHw?HdqmR95xZ6J!6s2wpuJFNHj-~WIA{oj4}*RdymFTDKMxbJQI!T0^gKFmD* zdC8@(>#u*m@$UbRKmULI{r~;X|Ifew|NQ&^&%gigfBnDu`Ty&m|KI)k|Ksofmp}i% z`St(vpa0+g{{Qy(|F3`lbop8aYI7$zQ*RgjgybIAK1IOInS&*)1o-VIxWT_G175brT(OH!|o#EoOs*+|Nk=# zR-pKkg^_{5hd~GAKv0}8u+MMsX=-k1ZEJ587UbvS<>BUFXJKM&VU(1TmXVbc6PJ*m z+AJ(2z|hCV$;QgOsL4ZpblChx{8Jl4)%toicQ|?N=gb^s)m-<78X{9O>XKU42dBf2N$#V eOPI6CMxF@p;E^}XsBl&}F_WiDf|Zqt!5RQ(vci7= literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.shells.ui/icons/full/obj16/systemcommandslive_obj.gif b/rse/plugins/org.eclipse.rse.shells.ui/icons/full/obj16/systemcommandslive_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..8710ab849f21c8af7995c1916f7a22e957ec400b GIT binary patch literal 589 zcmZ?wbhEHb6krfwc*ek>9X<2z^DmnDM>NwnX#r8n8m;8jT8T@w;udJd%+iXSq76h5 z6SX5IXovOQeg66P-~WIA{oj4}SL437?FZlYANw%#^yej)zOKLi{oC*VKmPpx_4ohx zKmR}f{{Qpu|3Cl!zyJ0B>gWHjfBt{>>;I3x|6l(6|K`{K&wu`Z|NH;j-~Ye<{g-d? zJ9O{-@duY}r=_^e$_!gpQM|cduEx11oPNXN5B*S~#vZ(61Pq;kXV zBIBHR+yDRnGYm4I_>+Z^fx(|a2jnhLoG`GjYVdDrZfP=V?PxJ-Z{p+O;^bgwV`en& zcIsgg77-N_mk^S4bXe+O?a#-{%`l0Th2Pl3XnB*j;*On)%6p7fH2Em19zJrUr^)xw z5zRAayjolo)s&RfG_u`%E(Bm z$ZMMwTv<_=+`2$nQ9&a_FwvDy)-vpfM9Y#zM-{az))X}AT~x@?vFTC~;b5=^0BjJ_ A1poj5 literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.shells.ui/icons/full/obj16/systemshell.gif b/rse/plugins/org.eclipse.rse.shells.ui/icons/full/obj16/systemshell.gif new file mode 100644 index 0000000000000000000000000000000000000000..15e83364423ab4c33ef8d7e1db5791434f4a9d77 GIT binary patch literal 357 zcmZ?wbhEHb6krfwxXQo~ozYU>Ftw?F*}|1O)a}#kf=a@&d#23am{T`P(J@cgyVO3a zA$QU~|JwCI4I9InHb=E?iEZB&+p#UNduL+Tj+EY=slB_>`}bt@@6MjMH+S+rm$FrE z<*VH)R(n*g@vdGQ)Ue^)qtBP0emQpkQ`DR@D=)s;eC_?-+aL0_Ju2P#xNh&$_CwDn zAAdRb%J z_l@@zzkM=-1vt#Pnwp!;oJ_b`SYXAU*m?QuI literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.shells.ui/icons/full/obj16/systemshelllive.gif b/rse/plugins/org.eclipse.rse.shells.ui/icons/full/obj16/systemshelllive.gif new file mode 100644 index 0000000000000000000000000000000000000000..a3f79194a8aa9ec22f14c3fe44e6f30d8000a370 GIT binary patch literal 366 zcmZ?wbhEHb6krfwxXQo~ozYU>Ftw?F*}|1O)a}#kf=a@&d#23am{T`P(J@cgyVO3a z;qIfC{bLz-~MN9XO|`!4+4($tvO z)0(w#V#2K6l*ygx+vkR@n-RTyO6=xY5&yw}0WVPe$->CMV9KBaQU&r816%ijSp^;< zle#>VUd~XNHcjiTu8dYK!wBBy9aOw^8;pdHq$o3r)z-~WyK-gX^+H|^BNr5C?!x%K1Fqu&=^ z{r&#u|L5QT-~al5_4EJNKmWh`_5bD1|8IW%fB*ac=Rf~{|NH;z-~Y4c&t@msbr%~q z=b2V#S`?>Pr^VPOMmkQb)SpylFsaP2r`V_^&$K4f;{X5u47h>fPZmZ71~Ud7kP?ue z7}zQtX8ST#8i;VVEL6zh;uby4I{9MG48MgcP8k+z-OOg(zh|76j|h|a-Eptr=B;H# z?C;*+ob!#5m4#7RS-V(AUap)`QN^@aS6)?>aiXk7r=O<0j7(=|gP)$fnh2wax(M@h eU;Q-^f78}2yEi#9SOWlu>Xowq literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.shells.ui/icons/full/view16/errorlist_view.gif b/rse/plugins/org.eclipse.rse.shells.ui/icons/full/view16/errorlist_view.gif new file mode 100644 index 0000000000000000000000000000000000000000..cc87d38aa0a1b26e02c85a621d6ce447e9dbf97c GIT binary patch literal 604 zcmZ?wbhEHb6krfwc*ekRP*ifisKkH&p#KTU|H~_`ib-D)lfEOR@ZUfDe{j@C|Iq)T zQ6GcDKZQpAk4^laSNzh{?tg6B|E$8lfB)q*uPf=?bn4QhZ$JM0{`2qWuRlM2{;ulZ z);i}%$D9N2KmTf&w!3TLi3!V3Pg{GjZ_$y7OOMapbZzO*+h?vmxpeFK(>Fh!zx%o7 z;KR+wpY_gI`Rc>Z2d{oSdj0*)r(a*b|9<@D`}6ldKYsiD{ny{0zyHpfIbrVX-UV~J zmoDg>J+uGz&GY*Yt0?n7Kj(jL?*FAr|F2l_9}E}<2T=UU!pOi7#GnIm4k%6-*mpJrH3fNj`gnOb zcXc~A`}q5M`}+t>PMg*n)F0^YKWEBxNtYl2UcY&B{Fns9L`9@rgBS%lI06H=3NlKF z@3jkJ=jL4D&&kccR>a6{3D>;2bGQV|O|RNFvGE58@dfa+s!Okvb7*GeVP@fBH8Xto z&b@gFJA;6Rto$PpJ;zVBCR!OBG8zT#Hj0`a6C^GwwmP?4J$c$-$lT^Cq3BT1FwuG5 e6fu3LeFBCY?EL*f5o-(rnUm1RU=08!bm#>D literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.shells.ui/plugin.properties b/rse/plugins/org.eclipse.rse.shells.ui/plugin.properties new file mode 100644 index 00000000000..a6ed7adb298 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/plugin.properties @@ -0,0 +1,30 @@ +################################################################################ +# Copyright (c) 2006 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: +# {Name} (company) - description of contribution. +################################################################################ + +plugin.name = RSE Shells UI + +View.Commands = Commands +View.RemoteCommands = Remote Shell + +PropertyPage.ShellSettings = Shell Settings + +PropertyPage.ServerLauncherSettings = Server Launcher Settings +PropertyPage.ServerConnectionSecurity = Server Connection Security +PropertyPage.Service = Service +PropertyPage.EnvVariables = Environment Variables + +Launch_Shell=Launch Shell +Launch_Shell_Tooltip=Launch a command shell from the selected directory \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/plugin.xml b/rse/plugins/org.eclipse.rse.shells.ui/plugin.xml new file mode 100644 index 00000000000..1eb773ee97d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/plugin.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/Activator.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/Activator.java new file mode 100644 index 00000000000..7cac312a411 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/Activator.java @@ -0,0 +1,93 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui; + +import org.eclipse.core.runtime.IAdapterManager; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.rse.shells.ui.view.ShellServiceSubsystemFactoryAdapterFactory; +import org.eclipse.rse.shells.ui.view.SystemViewOutputAdapterFactory; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + + +/** + * The main plugin class to be used in the desktop. + */ +public class Activator extends AbstractUIPlugin { + + //The shared instance. + private static Activator plugin; + SystemViewOutputAdapterFactory _svoaf; + + /** + * The constructor. + */ + public Activator() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception + { + super.start(context); + + IAdapterManager manager = Platform.getAdapterManager(); + + _svoaf = new SystemViewOutputAdapterFactory(); + _svoaf.registerWithManager(manager); + + ShellServiceSubsystemFactoryAdapterFactory fac = new ShellServiceSubsystemFactoryAdapterFactory(); + fac.registerWithManager(manager); + } + + /** + * For pathpath access to our adapters for viewable remote output objects. Exploits the knowledge we use singleton adapters. + */ + public SystemViewOutputAdapterFactory getSystemViewOutputAdapterFactory() + { + return _svoaf; + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static Activator getDefault() { + 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.shells.ui", path); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/RemoteCommandHelpers.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/RemoteCommandHelpers.java new file mode 100644 index 00000000000..9094b96394a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/RemoteCommandHelpers.java @@ -0,0 +1,186 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteCmdSubSystem; +import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteCommandShell; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.model.ISystemRegistry; +import org.eclipse.rse.shells.ui.view.SystemCommandsUI; +import org.eclipse.rse.shells.ui.view.SystemCommandsViewPart; +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.IRemoteFileSubSystemConfiguration; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.ui.messages.SystemMessageDialog; +import org.eclipse.swt.widgets.Shell; + + +/** + * Static helpers to simplify the act of running a universal command against + * a local or remote Unix, Windows or Linux command shell. + */ +public class RemoteCommandHelpers +{ + + /** + * Constructor for RemoteCommandHelpers. + */ + public RemoteCommandHelpers() + { + super(); + } + + /** + * Helper method to return the path to change-directory to, given a selected remote file object + */ + public static String getWorkingDirectory(IRemoteFile selectedFile) + { + String path = null; + if (selectedFile.isDirectory()) + path = selectedFile.getAbsolutePath(); + else + path = selectedFile.getParentPath(); + return path; + } + + + public static IRemoteCmdSubSystem getCmdSubSystem(IHost connection) + { + ISystemRegistry sr = SystemPlugin.getTheSystemRegistry(); + ISubSystem[] sses = sr.getSubSystems(connection); + for (int i = 0; i < sses.length; i++) + { + if (sses[i] instanceof IRemoteCmdSubSystem) + { + IRemoteCmdSubSystem cmdSubSystem = (RemoteCmdSubSystem)sses[i]; + return cmdSubSystem; + } + } + return null; + } + + public static IRemoteCmdSubSystem[] getCmdSubSystems(IHost connection) + { + List results = new ArrayList(); + ISystemRegistry sr = SystemPlugin.getTheSystemRegistry(); + ISubSystem[] sses = sr.getSubSystems(connection); + for (int i = 0; i < sses.length; i++) + { + if (sses[i] instanceof IRemoteCmdSubSystem) + { + IRemoteCmdSubSystem cmdSubSystem = (RemoteCmdSubSystem)sses[i]; + results.add(cmdSubSystem); + } + } + return (IRemoteCmdSubSystem[])results.toArray(new IRemoteCmdSubSystem[results.size()]); + } + + public static boolean runUniversalCommand(Shell shell, String cmdString, String path, + IRemoteCmdSubSystem cmdSubSystem) + { + return runUniversalCommand(shell, cmdString, path, cmdSubSystem, false); + } + + /** + * Encapsulation of code needed to run a universal subsystem command. A universal + * command is a command that runs in a Unix or Linux or Windows command shell, as + * opposed to something unique like an OS/400 or z/OS command. + * This: + *
    + *
  • Sets the current directory to the given path + *
  • Runs the given command remotely + *
  • Logs the command and its output in the command view + *
+ * + * @param shell - the shell to use if need to prompt for password or show msg dialog + * @param cmdString - the resolved command + * @param path - the path to run the command against + * @param cmdSubSystem - this connection's command subsystem, which will run the command + * @return true if we should continue, false if something went wrong + */ + public static boolean runUniversalCommand(Shell shell, String cmdString, String path, + IRemoteCmdSubSystem cmdSubSystem, boolean isCompile) + { + boolean ok = false; + if (cmdSubSystem != null) + { + ok = true; + try + { + + IRemoteCommandShell defaultShell= cmdSubSystem.getDefaultShell(shell); + + + showInView(defaultShell, isCompile, cmdString); + + IRemoteFileSubSystemConfiguration fileSSF = RemoteFileUtility.getFileSubSystemFactory(cmdSubSystem.getHost().getSystemType()); + IRemoteFile pwd = ((RemoteCommandShell)defaultShell).getWorkingDirectory(); + if (pwd == null || !pwd.getAbsolutePath().equals(path)) + { + if (path.indexOf(' ') > 0) + { + path = "\"" + path + "\""; + } + + String cdCmd = "cd " + path; + if (!fileSSF.isUnixStyle()) + { + if (path.endsWith(":")) + { + path += "\\"; + } + cdCmd = "cd /d " + path; + } + + cmdSubSystem.sendCommandToShell(cdCmd, shell, defaultShell); + } + cmdSubSystem.sendCommandToShell(cmdString, shell, defaultShell); + + + } + catch (Exception e) + { + SystemBasePlugin.logError("Run Remote Command failed", e); + SystemMessageDialog.displayExceptionMessage(shell, e); + ok = false; + } + } // end if + return ok; + } // end method + + + + + public static void showInView(IRemoteCommandShell cmd, boolean isCompile, String cmdString) { + SystemCommandsViewPart cmdsPart = SystemCommandsUI.getInstance().activateCommandsView(); + cmdsPart.updateOutput(cmd); + /* DKM - no longer show this for compile commands + if (isCompile) { + SystemBuildErrorViewPart errorPart = SystemCommandsUI.getInstance().activateBuildErrorView(); + errorPart.setInput((IAdaptable)cmd, cmdString); + } + */ + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/ShellResources.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/ShellResources.java new file mode 100644 index 00000000000..7d1f07527e8 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/ShellResources.java @@ -0,0 +1,88 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui; + +import org.eclipse.osgi.util.NLS; + +public class ShellResources extends NLS +{ + private static String BUNDLE_NAME = "org.eclipse.rse.shells.ui.ShellResources"; + + public static String RESID_SHELL_PROPERTYPAGE_TITLE; + public static String RESID_SHELL_PROPERTYPAGE_DESCRIPTION; + public static String RESID_SHELL_PROPERTYPAGE_ENCODING; + public static String RESID_SHELL_PROPERTYPAGE_DEFAULT_ENCODING; + public static String RESID_SHELL_PROPERTYPAGE_HOST_ENCODING; + public static String RESID_SHELL_PROPERTYPAGE_OTHER_ENCODING; + public static String RESID_UNSUPPORTED_ENCODING; + + + public static String RESID_SHELLS_RUN_IN_NEW_SHELL_LABEL; + public static String RESID_SHELLS_RUN_IN_NEW_SHELL_TOOLTIP; + public static String RESID_SHELLS_RUN_COMMAND_LABEL; + public static String RESID_SHELLS_COMMAND_LABEL; + public static String RESID_SHELLS_COMMAND_TOOLTIP; + public static String RESID_SHELLS_COMMAND_SHELL_LABEL; + + // COMMANDS VIEW + public static String RESID_COMMANDSVIEW_RUN_LABEL; + public static String RESID_COMMANDSVIEW_RUN_TOOLTIP; + public static String RESID_COMMANDSVIEW_CMDCOMBO_TOOLTIP; + public static String RESID_COMMANDSVIEW_SUBSYSCOMBO_TOOLTIP; + public static String RESID_PREF_COMMANDSVIEW_BRINGTOFRONT_LABEL; + public static String RESID_PREF_COMMANDSVIEW_BRINGTOFRONT_TOOLTIP; + + // UNIVERSAL COMMMANDS VIEW + public static String RESID_COMMANDSVIEW_COMMAND_LABEL; + public static String RESID_COMMANDSVIEW_COMMAND_TOOLTIP; + public static String RESID_COMMANDSVIEW_PREVIOUS_TOOLTIP; + + // ACTIONS + public static String ACTION_RUN_COMMAND_LABEL; + public static String ACTION_RUN_COMMAND_TOOLTIP; + + public static String ACTION_RUN_SHELL_LABEL; + public static String ACTION_RUN_SHELL_TOOLTIP; + + public static String ACTION_LAUNCH_LABEL; + public static String ACTION_LAUNCH_TOOLTIP; + + public static String ACTION_SHOW_SHELL_LABEL; + public static String ACTION_SHOW_SHELL_TOOLTIP; + + public static String ACTION_CANCEL_SHELL_LABEL; + public static String ACTION_CANCEL_SHELL_TOOLTIP; + + public static String ACTION_CANCEL_REMOVE_SHELL_LABEL; + public static String ACTION_CANCEL_REMOVE_SHELL_TOOLTIP; + + public static String ACTION_EXPORT_SHELL_OUTPUT_LABEL; + public static String ACTION_EXPORT_SHELL_OUTPUT_TOOLTIP; + + public static String ACTION_EXPORT_SHELL_HISTORY_LABEL; + public static String ACTION_EXPORT_SHELL_HISTORY_TOOLTIP; + + public static String ACTION_OPEN_OUTPUT_LABEL; + public static String ACTION_OPEN_OUTPUT_TOOLTIP; + + static + { + // load message values from bundle file + NLS.initializeMessages(BUNDLE_NAME, ShellResources.class); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/ShellResources.properties b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/ShellResources.properties new file mode 100644 index 00000000000..74b88504007 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/ShellResources.properties @@ -0,0 +1,80 @@ +################################################################################ +# Copyright (c) 2006 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: +# {Name} (company) - description of contribution. +################################################################################ + +################################################################################### +############################ Universal Commands ############################ +################################################################################### +RESID_SHELL_PROPERTYPAGE_TITLE=Shell Settings +RESID_SHELL_PROPERTYPAGE_DESCRIPTION=Configure settings for shells +RESID_SHELL_PROPERTYPAGE_ENCODING=Shell Encoding +RESID_SHELL_PROPERTYPAGE_DEFAULT_ENCODING=Default +RESID_SHELL_PROPERTYPAGE_HOST_ENCODING=Host encoding +RESID_SHELL_PROPERTYPAGE_OTHER_ENCODING=Select or enter an encoding +RESID_UNSUPPORTED_ENCODING=This is not a supported encoding + +RESID_SHELLS_RUN_IN_NEW_SHELL_LABEL = Run in new shell +RESID_SHELLS_RUN_IN_NEW_SHELL_TOOLTIP = Indicate whether the command is to be launched in a new shell or the system default shell +RESID_SHELLS_RUN_COMMAND_LABEL = Run Command +RESID_SHELLS_COMMAND_LABEL = Command +RESID_SHELLS_COMMAND_TOOLTIP = Enter the command to invoke +RESID_SHELLS_COMMAND_SHELL_LABEL = Command Shell + +#============================================================= +# Commands View +#============================================================= +RESID_COMMANDSVIEW_RUN_LABEL=Run +RESID_COMMANDSVIEW_RUN_TOOLTIP=Run the specified command on the selected subsystem and connection +RESID_COMMANDSVIEW_CMDCOMBO_TOOLTIP=Specify the command to run +RESID_COMMANDSVIEW_SUBSYSCOMBO_TOOLTIP=Select the subsystem on which to run a command +RESID_PREF_COMMANDSVIEW_BRINGTOFRONT_LABEL=Show Commands view when command is run +RESID_PREF_COMMANDSVIEW_BRINGTOFRONT_TOOLTIP=Force the Commands view to the foreground when a remote system command is run + +#============================================================= +# Commands View +#============================================================= +RESID_COMMANDSVIEW_COMMAND_LABEL=Command +RESID_COMMANDSVIEW_COMMAND_TOOLTIP=Specify a command to run +RESID_COMMANDSVIEW_PREVIOUS_TOOLTIP=Specify a previously run command + +#============================================================= +# Actions +#============================================================= +ACTION_RUN_COMMAND_LABEL=Run Command... +ACTION_RUN_COMMAND_TOOLTIP=Issue a command from the selected resource + +ACTION_RUN_SHELL_LABEL=Launch Shell +ACTION_RUN_SHELL_TOOLTIP=Launch a new shell on the selected system + +ACTION_LAUNCH_LABEL=Launch +ACTION_LAUNCH_TOOLTIP=Launch a new shell on the selected system + +ACTION_SHOW_SHELL_LABEL=Show in Remote Shell View +ACTION_SHOW_SHELL_TOOLTIP=Show the selected shell in the Remote Shell view + +ACTION_CANCEL_SHELL_LABEL=Cancel Shell +ACTION_CANCEL_SHELL_TOOLTIP=Terminate the selected shell + +ACTION_CANCEL_REMOVE_SHELL_LABEL=Remove Shell +ACTION_CANCEL_REMOVE_SHELL_TOOLTIP=Terminate the selected shell and remove it from the Remote Shell view + +ACTION_EXPORT_SHELL_OUTPUT_LABEL=Export Shell Output... +ACTION_EXPORT_SHELL_OUTPUT_TOOLTIP=Export the output of the selected shell to a file + +ACTION_EXPORT_SHELL_HISTORY_LABEL=Export Shell History... +ACTION_EXPORT_SHELL_HISTORY_TOOLTIP=Export the command history for the selected shell to a file + +ACTION_OPEN_OUTPUT_LABEL= Goto +ACTION_OPEN_OUTPUT_TOOLTIP= Open the selected output object in an editor or view \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/SystemRemoteCommandEntryForm.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/SystemRemoteCommandEntryForm.java new file mode 100644 index 00000000000..ceb7c1bc2be --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/SystemRemoteCommandEntryForm.java @@ -0,0 +1,285 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui; +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.model.ISubSystemFactoryCategories; +import org.eclipse.rse.model.ISystemResourceChangeEvent; +import org.eclipse.rse.model.ISystemResourceChangeEvents; +import org.eclipse.rse.subsystems.files.core.model.ISystemRemoteCommand; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.ui.SystemWidgetHelpers; +import org.eclipse.rse.ui.widgets.SystemHostCombo; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; + + +/** + * A composite encapsulating the GUI widgets for a command console. Used in the CommandView view + * but can also be instantiated and used anywhere. + */ +public class SystemRemoteCommandEntryForm extends Composite + implements org.eclipse.rse.model.ISystemResourceChangeListener +{ + private SystemHostCombo sysConnCombo; + private IRemoteCmdSubSystem[] subSystems = null; + private int subSystemIndex = -1; + + private Combo cmdCombo; + private Combo subSysCombo; + private Button runButton; + + public SystemRemoteCommandEntryForm( Composite parent, int style ) + { + super(parent, style); + + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 4; + setLayout(gridLayout); + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = false; + setLayoutData(gridData); + + sysConnCombo = new SystemHostCombo(this, SWT.NULL, null, false, ISubSystemFactoryCategories.SUBSYSTEM_CATEGORY_CMDS, false); + sysConnCombo.setWidthHint(100); + sysConnCombo.addSelectionListener( new SelectionAdapter() + { + public void widgetSelected(SelectionEvent event) + { + sysConnChanged(); + }; + }); + sysConnCombo.listenToConnectionEvents(true); + + subSysCombo = SystemWidgetHelpers.createReadonlyCombo(this, new Listener() { + public void handleEvent(Event e) { + subSysChanged(); + } + }, ShellResources.RESID_COMMANDSVIEW_SUBSYSCOMBO_TOOLTIP); + ((GridData)subSysCombo.getLayoutData()).widthHint = 100; + + cmdCombo = SystemWidgetHelpers.createCombo(this, new Listener() { + public void handleEvent(Event e) { + commandChanged(); + } + }, ShellResources.RESID_COMMANDSVIEW_CMDCOMBO_TOOLTIP); + cmdCombo.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + checkRunButtonEnablement(); + } + } + ); + ((GridData)cmdCombo.getLayoutData()).widthHint = 250; + cmdCombo.addSelectionListener(new SelectionAdapter() { + public void widgetDefaultSelected( SelectionEvent e ) + { + handleCmdComboEnter(); + } + } ); + + runButton = SystemWidgetHelpers.createPushButton(this, new Listener() { + public void handleEvent(Event e) { + runCommand(); + } + }, ShellResources.RESID_COMMANDSVIEW_RUN_LABEL, ShellResources.RESID_COMMANDSVIEW_RUN_TOOLTIP); + //((GridData)runButton.getLayoutData()).widthHint = 30; + + pack(); + + populateSubSysCombo(); + populateCommandCombo(); + checkRunButtonEnablement(); + + cmdCombo.setFocus(); + + // ---------------------------------------- + // register with system registry for events + // ---------------------------------------- + SystemPlugin.getTheSystemRegistry().addSystemResourceChangeListener(this); + } + + private void runCommand() + { + String cmd = cmdCombo.getText(); + if ( cmd.length() > 0 ) + { + IHost sysConn = sysConnCombo.getHost(); + if ( sysConn != null ) + { + //SubSystem[] cmdSubSystems = SystemPlugin.getDefault().getSystemRegistry().getSubSystemsBySubSystemFactoryCategory(ISubSystemFactoryCategories.SUBSYSTEM_CATEGORY_CMDS, sysConn); + IRemoteCmdSubSystem[] cmdSubSystems = RemoteCommandHelpers.getCmdSubSystems(sysConn); + IRemoteCmdSubSystem currSubSystem = null; + String subSystemName = subSysCombo.getText(); + for (int i = 0; i < cmdSubSystems.length && currSubSystem == null; i++) + { + if ( subSystemName.equals(cmdSubSystems[i].getName() ) ) + currSubSystem = cmdSubSystems[i]; + } + + if ( currSubSystem != null ) + { + try + { + currSubSystem.runCommand(cmd, getShell(), null); + } + catch ( Exception e ) + { + SystemBasePlugin.logInfo("Exception invoking command "+cmd+" on " + sysConn.getAliasName() ); + } + } + } + } + } + + /** + * Handle a change in the command combo + */ + private void commandChanged() + { + checkRunButtonEnablement(); + } + + + /** + * Handle a change in the subsystem combo + */ + private void subSysChanged() + { + subSystemIndex = subSysCombo.getSelectionIndex(); + populateCommandCombo(); + checkRunButtonEnablement(); + } + + /** + * Handle a change in the system connection combo + */ + private void sysConnChanged() + { + populateSubSysCombo(); + populateCommandCombo(); + checkRunButtonEnablement(); + } + + /** + * Determine if the Run button should be enabled + */ + private void checkRunButtonEnablement() + { + if ( sysConnCombo.getText().length() > 0 && subSysCombo.getText().length() > 0 && cmdCombo.getText().trim().length() > 0 ) + runButton.setEnabled(true); + else + runButton.setEnabled(false); + } + + /** + * Populate the list command subsystems for the selected connection + */ + private void populateSubSysCombo() + { + subSysCombo.removeAll(); + IHost sysConn = sysConnCombo.getHost(); + if ( sysConn != null ) + { + //subSystems = SystemPlugin.getDefault().getSystemRegistry().getSubSystemsBySubSystemFactoryCategory(ISubSystemFactoryCategories.SUBSYSTEM_CATEGORY_CMDS, sysConn); + subSystems = RemoteCommandHelpers.getCmdSubSystems(sysConn); + for (int i = 0; i < subSystems.length; i++) + { + if ( i == 0 ) + subSystemIndex = 0; + subSysCombo.add(subSystems[i].getName()); + } + subSysCombo.select(0); + } + } + + /** + * Populate the command combo with the history of executed commands on that subsystemlist command subsystems for the selected connection + */ + private void populateCommandCombo() + { + cmdCombo.removeAll(); + if ( subSystemIndex >= 0 ) + { + String[] cmds = subSystems[subSystemIndex].getExecutedCommands(); + if ( cmds != null ) + cmdCombo.setItems( cmds ); + } + } + + /** + * This is the method in your class that will be called when a + * system resource changes. Listen for run commands. + * @see ISystemResourceChangeEvent + */ + public void systemResourceChanged(ISystemResourceChangeEvent event) + { + int type = event.getType(); + Object src = event.getSource(); + Object parent = event.getParent(); + switch ( type ) + { + case ISystemResourceChangeEvents.EVENT_COMMAND_RUN: + if ( src instanceof ISystemRemoteCommand ) + { + if ( subSystemIndex >= 0 && subSystems[subSystemIndex] == ((ISystemRemoteCommand)src).getSubSystem() ) + { + // use asyncExec to avoid invalid Thread exceptions + Display.getDefault().asyncExec(new Runnable() { + public void run() + { + populateCommandCombo(); + } + } + ); + } + } + break; + case ISystemResourceChangeEvents.EVENT_COMMAND_MESSAGE: + break; + case ISystemResourceChangeEvents.EVENT_COMMAND_HISTORY_UPDATE: + // use asyncExec to avoid invalid Thread exceptions + Display.getDefault().asyncExec(new Runnable() { + public void run() + { + populateCommandCombo(); + } + } + ); + break; + } + } + + private void handleCmdComboEnter() + { + if ( runButton.isEnabled() ) + runCommand(); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/LaunchShellActionDelegate.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/LaunchShellActionDelegate.java new file mode 100644 index 00000000000..e55875db300 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/LaunchShellActionDelegate.java @@ -0,0 +1,53 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.actions; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.ui.IActionDelegate; +import org.eclipse.ui.actions.ActionDelegate; + +public class LaunchShellActionDelegate extends ActionDelegate implements IActionDelegate +{ + private SystemCommandAction _launchAction; + private ISelection _selection; + public LaunchShellActionDelegate() + { + super(); + } + + public void run(IAction action) + { + if (_launchAction == null) + { + _launchAction = new SystemCommandAction(SystemBasePlugin.getActiveWorkbenchShell(), true); + } + _launchAction.updateSelection((IStructuredSelection)_selection); + _launchAction.run(); + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) + */ + public void selectionChanged(IAction action, ISelection selection) + { + _selection = selection; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemBaseShellAction.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemBaseShellAction.java new file mode 100644 index 00000000000..a8515451d3c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemBaseShellAction.java @@ -0,0 +1,85 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + + +package org.eclipse.rse.shells.ui.actions; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.ui.actions.SystemBaseAction; +import org.eclipse.swt.widgets.Shell; + + + +public abstract class SystemBaseShellAction extends SystemBaseAction +{ + protected List _selected; + + public SystemBaseShellAction(String name, String tooltip, ImageDescriptor image, Shell parent) + { + super(name, + tooltip, + image, + parent); + setAvailableOffline(true); + allowOnMultipleSelection(true); + _selected = new ArrayList(); + } + + /** + * Called when the selection changes. The selection is checked to + * make sure this action can be performed on the selected object. + */ + public boolean updateSelection(IStructuredSelection selection) + { + boolean enable = false; + Iterator e = ((IStructuredSelection) selection).iterator(); + _selected.clear(); + while (e.hasNext()) + { + Object selected = e.next(); + if (selected instanceof IRemoteCommandShell) + { + if (isApplicable((IRemoteCommandShell)selected)) + { + _selected.add(selected); + enable = true; + } + else + { + return false; + } + } + else + { + return false; + } + } + + + return enable; + } + + protected boolean isApplicable(IRemoteCommandShell cmdShell) + { + return true; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemCommandAction.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemCommandAction.java new file mode 100644 index 00000000000..695df1fa082 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemCommandAction.java @@ -0,0 +1,569 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.actions; + +import java.util.Iterator; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.window.Window; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.filters.ISystemFilterReference; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.shells.ui.RemoteCommandHelpers; +import org.eclipse.rse.shells.ui.ShellResources; +import org.eclipse.rse.shells.ui.view.SystemCommandsUI; +import org.eclipse.rse.shells.ui.view.SystemCommandsViewPart; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.ui.ISystemIconConstants; +import org.eclipse.rse.ui.ISystemMessages; +import org.eclipse.rse.ui.actions.SystemBaseAction; +import org.eclipse.rse.ui.dialogs.SystemPromptDialog; +import org.eclipse.rse.ui.view.ISystemViewElementAdapter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + + +/** + * Launches a shell and/or runs a shell command, displaying the output + * in the Remote Systems Commands view. + */ +public class SystemCommandAction extends SystemBaseAction +{ + private IRemoteFile _selected; + private ISystemFilterReference _selectedFilterRef; + + + private boolean _isShell; + private IRemoteCmdSubSystem _cmdSubSystem; + + + /** + * The command dialog used when running a command. + */ + public class CommandDialog extends SystemPromptDialog implements ISystemMessages + { + private Combo _cmdText; + private Button _launchNewShellButton; + private SystemMessage _errorMessage; + + private String _cmdStr; + private boolean _launchNewShell; + + /** + * Constructor for the CommandDialog + * @param shell the parent of the dialog + */ + public CommandDialog(Shell shell) + { + super(shell, ShellResources.RESID_SHELLS_RUN_COMMAND_LABEL); + //pack(); + } + + /** + * @return the user-specified command invocation + */ + public String getCmdStr() + { + return _cmdStr; + } + + /** + * @return whether the specified command is to be launched in a new shell or not + */ + public boolean launchNewShell() + { + return _launchNewShell; + } + + protected void buttonPressed(int buttonId) + { + setReturnCode(buttonId); + _cmdStr = _cmdText.getText(); + _launchNewShell = _launchNewShellButton.getSelection(); + close(); + } + + /** + * Constructs the dialog + * @param parent the parent of the dialog + */ + public Control createInner(Composite parent) + { + Composite c = new Composite(parent, SWT.NONE); + + GridLayout layout = new GridLayout(); + c.setLayout(layout); + c.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Label aLabel = new Label(c, SWT.NONE); + aLabel.setText(ShellResources.RESID_SHELLS_COMMAND_LABEL); + + _cmdText = new Combo(c, SWT.SINGLE | SWT.BORDER); + GridData textData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); + _cmdText.setLayoutData(textData); + _cmdText.setText(""); + _cmdText.setToolTipText(ShellResources.RESID_SHELLS_COMMAND_TOOLTIP); + + // add keystroke listeners... + _cmdText.addModifyListener(new ModifyListener() + { + public void modifyText(ModifyEvent e) + { + validateInvocation(); + } + }); + + IRemoteCmdSubSystem cmdSubSystem = getCommandSubSystem(); + if (cmdSubSystem != null) + { + String[] cmds = cmdSubSystem.getExecutedCommands(); + if (cmds != null) + _cmdText.setItems(cmds); + } + + + _launchNewShellButton = new Button(c, SWT.CHECK); + _launchNewShellButton.setText(ShellResources.RESID_SHELLS_RUN_IN_NEW_SHELL_LABEL); + _launchNewShellButton.setToolTipText(ShellResources.RESID_SHELLS_RUN_IN_NEW_SHELL_TOOLTIP); + + setHelp(); + + enableOkButton(false); + return c; + } + + + /** + * returns the initial focus control + */ + protected Control getInitialFocusControl() + { + enableOkButton(false); + return _cmdText; + } + + private void setHelp() + { + setHelp(SystemPlugin.HELPPREFIX + "cmdi0000"); + } + + /** + * validate the invocation + * @return a SystemMessage if the invocation is invalid. + */ + protected SystemMessage validateInvocation() + { + _errorMessage = null; + String theNewName = _cmdText.getText(); + + if (theNewName.length() == 0) + { + _errorMessage = SystemPlugin.getPluginMessage(MSG_UCMD_INVOCATION_EMPTY); + } + + if (_errorMessage != null) + { + setErrorMessage(_errorMessage); + enableOkButton(false); + } + else + { + clearErrorMessage(); + enableOkButton(true); + } + + return _errorMessage; + } + } + + /** + * Constructor for SystemCommandAction + * @param parent + */ + public SystemCommandAction(Shell parent) + { + this(parent, false); + } + + /** + * Constructor for SystemCommandAction + * @param parent + * @param isShell indication of whether this action launches a shell or runs a command + */ + public SystemCommandAction(Shell parent, boolean isShell) + { + this(parent, isShell, null); + } + + /** + * Constructor for SystemCommandAction + * @param parent + * @param isShell indication of whether this action launches a shell or runs a command + * @param cmdSubSystem the command subsystem to use if launching a shell + */ + public SystemCommandAction(Shell parent, boolean isShell, IRemoteCmdSubSystem cmdSubSystem) + { + this( + isShell ? ShellResources.ACTION_RUN_SHELL_LABEL : ShellResources.ACTION_RUN_COMMAND_LABEL, + isShell ? ShellResources.ACTION_RUN_SHELL_TOOLTIP : ShellResources.ACTION_RUN_COMMAND_TOOLTIP, + parent, + isShell, + cmdSubSystem); + } + + /** + * Constructor for SystemCommandAction + * @param title the title of the action + * @param parent + * @param isShell indication of whether this action launches a shell or runs a command + * @param cmdSubSystem the command subsystem to use if launching a shell + */ + public SystemCommandAction(String title, Shell parent, boolean isShell, IRemoteCmdSubSystem cmdSubSystem) + { + this(title, null, parent, isShell, cmdSubSystem); + } + + + /** + * Constructor for SystemCommandAction + * @param title the title of the action + * @param tooltip the tooltip for the action + * @param parent + * @param isShell indication of whether this action launches a shell or runs a command + * @param cmdSubSystem the command subsystem to use if launching a shell + */ + public SystemCommandAction(String title, String tooltip, Shell parent, boolean isShell, IRemoteCmdSubSystem cmdSubSystem) + { + this( + title, + tooltip, + isShell ? SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_SHELL_ID) : SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_RUN_ID), + parent, + isShell, + cmdSubSystem); + } + + + /** + * Constructor for SystemCommandAction + * @param title the title of the action + * @param tooltip the tooltip for the action + * @param descriptor the image descriptor for the action + * @param parent + * @param isShell indication of whether this action launches a shell or runs a command + * @param cmdSubSystem the command subsystem to use if launching a shell + */ + public SystemCommandAction(String title, String tooltip, ImageDescriptor descriptor, Shell parent, boolean isShell, IRemoteCmdSubSystem cmdSubSystem) + { + super(title, tooltip, descriptor, parent); + _isShell = isShell; + _cmdSubSystem = cmdSubSystem; + if (_isShell) + setHelp(SystemPlugin.HELPPREFIX+"actn0113"); + else + setHelp(SystemPlugin.HELPPREFIX+"actn0114"); + } + + public void setSubSystem(IRemoteCmdSubSystem ss) + { + _cmdSubSystem = ss; + } + + /** + * Runs the command action. If the action is for launching a shell, the shell is launched + * and the commands view shows it's output. If the action is for running a command, a + * dialog pops up prompting for the invocation. + */ + public void run() + { + if (_isShell) + { + runShell(); + } + else + { + CommandDialog cmdDialog = new CommandDialog(getShell()); + if (cmdDialog.open() == Window.OK) + { + String cmdStr = cmdDialog.getCmdStr(); + if (cmdStr != null) + { + // run the command + runCommand(cmdStr, cmdDialog.launchNewShell()); + } + } + } + } + + private IRemoteCmdSubSystem getCommandSubSystem() + { + if (_selectedFilterRef != null) + { + ISystemViewElementAdapter adapter = (ISystemViewElementAdapter)((IAdaptable)_selectedFilterRef).getAdapter(ISystemViewElementAdapter.class); + if (adapter != null) + { + ISubSystem ss = adapter.getSubSystem(_selectedFilterRef); + if (ss != null) + { + return RemoteCommandHelpers.getCmdSubSystem(ss.getHost()); + } + } + } + + IRemoteFile selectedFile = _selected; + if (_selected == null) + { + return _cmdSubSystem; + } + + IHost sysConn = selectedFile.getSystemConnection(); + if (sysConn != null) + { + ISubSystem currSubSystem = selectedFile.getParentRemoteFileSubSystem(); + if (currSubSystem != null) + { + try + { + Shell shell = getShell(); + IRemoteCmdSubSystem cmdSubSystem = RemoteCommandHelpers.getCmdSubSystem(currSubSystem.getHost()); + return cmdSubSystem; + } + catch (Exception e) + { + } + } + } + + return null; + } + + /** + * runs the command + */ + private void runCommand(String cmd, boolean launchNewShell) + { + if (cmd.length() > 0) + { + + try + { + Shell shell = getShell(); + + if (_selectedFilterRef != null) + { + ISystemViewElementAdapter adapter = (ISystemViewElementAdapter)((IAdaptable)_selectedFilterRef).getAdapter(ISystemViewElementAdapter.class); + if (adapter != null) + { + ISubSystem ss = adapter.getSubSystem(_selectedFilterRef); + if (ss != null) + { + Object target = ss.getTargetForFilter(_selectedFilterRef); + if (target != null && target instanceof IRemoteFile) + { + _selected = (IRemoteFile)target; + } + } + } + } + + if (_selected != null) + { + IRemoteCmdSubSystem cmdSubSystem = getCommandSubSystem(); + String path = _selected.getAbsolutePath(); + + if (launchNewShell) + { + Object[] results = cmdSubSystem.runCommand(cmd, shell, _selected); + Object cmdObject = results[0]; + if (cmdObject instanceof IRemoteCommandShell) + { + showInView((IRemoteCommandShell) cmdObject); + } + } + else + { + // run command in shell + IRemoteCommandShell defaultShell = cmdSubSystem.getDefaultShell(shell); + if (defaultShell != null) + { + showInView(defaultShell); + } + + String cdCmd = "cd " + path; + if ((cmdSubSystem.getHost().getSystemType().equals("Local") && System.getProperty("os.name").toLowerCase().startsWith("win")) + || cmdSubSystem.getHost().getSystemType().equals("Windows")) + { + cdCmd = "cd /d " + path; + } + cmdSubSystem.sendCommandToShell(cdCmd, shell, defaultShell); + cmdSubSystem.sendCommandToShell(cmd, shell, defaultShell); + } + } + else + { + IRemoteCmdSubSystem cmdSubSystem = getCommandSubSystem(); + if (cmdSubSystem != null) + { + Object[] results = cmdSubSystem.runCommand(cmd, shell, _selected); + Object cmdObject = results[0]; + if (cmdObject instanceof IRemoteCommandShell) + { + showInView((IRemoteCommandShell) cmdObject); + } + } + } + + } + catch (Exception e) + { + e.printStackTrace(); + } + + } + } + + /** + * launches a new shell + */ + private void runShell() + { + try + { + Shell shell = getShell(); + if (_selectedFilterRef != null) + { + ISystemViewElementAdapter adapter = (ISystemViewElementAdapter)((IAdaptable)_selectedFilterRef).getAdapter(ISystemViewElementAdapter.class); + if (adapter != null) + { + ISubSystem ss = adapter.getSubSystem(_selectedFilterRef); + if (ss != null) + { + Object target = ss.getTargetForFilter(_selectedFilterRef); + if (target != null && target instanceof IRemoteFile) + { + _selected = (IRemoteFile)target; + } + } + } + } + + IRemoteCmdSubSystem cmdSubSystem = getCommandSubSystem(); + if (cmdSubSystem != null) + { + if (cmdSubSystem.isConnected()) + { + SystemCommandsUI commandsUI = SystemCommandsUI.getInstance(); + SystemCommandsViewPart cmdsPart = commandsUI.activateCommandsView(); + IRemoteCommandShell cmd = cmdSubSystem.runShell(shell, _selected); + cmdsPart.updateOutput(cmd); + } + else + { + cmdSubSystem.connect(shell); + SystemCommandsUI commandsUI = SystemCommandsUI.getInstance(); + SystemCommandsViewPart cmdsPart = commandsUI.activateCommandsView(); + IRemoteCommandShell cmd = cmdSubSystem.runShell(shell, _selected); + cmdsPart.updateOutput(cmd); + //showInView(cmd); + } + } + + } + catch (Exception e) + { + e.printStackTrace(); + // SystemPlugin.getDefault().logInfo("Exception invoking command " + cmd + " on " + sysConn.getAliasName()); + } + + } + + /** + * shows the command in the commands view + */ + private void showInView(IRemoteCommandShell cmd) + { + SystemCommandsUI commandsUI = SystemCommandsUI.getInstance(); + SystemCommandsViewPart cmdsPart = commandsUI.activateCommandsView(); + cmdsPart.updateOutput(cmd); + } + + /** + * Called when the selection changes in the systems view. This determines + * the input object for the command and whether to enable or disable + * the action. + * + * @param selection the current seleciton + * @return whether to enable or disable the action + */ + public boolean updateSelection(IStructuredSelection selection) + { + boolean enable = false; + + Iterator e = ((IStructuredSelection) selection).iterator(); + Object selected = e.next(); + + if (selected != null) + { + if (selected instanceof ISystemFilterReference) + { + _selectedFilterRef = (ISystemFilterReference)selected; + _selected = null; + enable = true; + } + if (selected instanceof IRemoteFile) + { + _selected = (IRemoteFile) selected; + _selectedFilterRef = null; + if (!_selected.isFile()) + { + enable = checkObjectType(_selected); + } + } + } + + if (enable) + { + IRemoteCmdSubSystem cmdSubSystem = getCommandSubSystem(); + if (_cmdSubSystem != cmdSubSystem) + { + _cmdSubSystem = cmdSubSystem; + enable = _cmdSubSystem.canRunCommand(); + } + } + else if (_cmdSubSystem != null) + { + enable = _cmdSubSystem.canRunShell(); + } + + return enable; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemExportShellHistoryAction.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemExportShellHistoryAction.java new file mode 100644 index 00000000000..0f5a596efd6 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemExportShellHistoryAction.java @@ -0,0 +1,88 @@ +/******************************************************************************** + * Copyright (c) 2004, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.actions; + +import java.io.FileWriter; + +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.shells.ui.ShellResources; +import org.eclipse.rse.shells.ui.view.SystemCommandsUI; +import org.eclipse.rse.shells.ui.view.SystemCommandsViewPart; +import org.eclipse.rse.subsystems.files.core.SystemFileResources; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.ui.ISystemIconConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; + + + +/** + * @author dmcknigh + */ +public class SystemExportShellHistoryAction extends SystemBaseShellAction +{ + public SystemExportShellHistoryAction(Shell parent) + { + super(ShellResources.ACTION_EXPORT_SHELL_HISTORY_LABEL, + ShellResources.ACTION_EXPORT_SHELL_HISTORY_TOOLTIP, + SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_EXPORT_SHELL_HISTORY_ID), + parent); + allowOnMultipleSelection(false); + } + + + /** + * Called when this action is selected from the popup menu. + */ + public void run() + { + SystemCommandsViewPart viewPart = SystemCommandsUI.getInstance().activateCommandsView(); + for (int i = 0; i < _selected.size(); i++) + { + IRemoteCommandShell cmdShell = (IRemoteCommandShell)_selected.get(i); + + + FileDialog fdlg = new FileDialog(getShell(), SWT.SAVE); + fdlg.setText(SystemFileResources.RESID_ENTER_OR_SELECT_FILE_TITLE); + //fdlg.setText(SystemPlugin.getString("com.ibm.etools.systems.ui.RmtJarExport.selectOrEnterJarDialog.title")); + fdlg.setFileName(cmdShell.getId() + "-history.txt"); + fdlg.setFilterExtensions(new String[] {"*.txt"}); + String fileName = fdlg.open(); + try + { + //FileOutputStream stream = new FileOutputStream(fileName); + //OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8"); + // DKM - file writer writes to local encoding + FileWriter writer= new FileWriter(fileName); + String[] cmds = cmdShell.getHistory(); + for (int o = 0; o < cmds.length; o++) + { + String cmd = cmds[o]; + writer.write(cmd); + writer.write("\r\n"); + + } + writer.close(); + } + catch (Exception e) + { + } + } + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemExportShellOutputAction.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemExportShellOutputAction.java new file mode 100644 index 00000000000..0f472698271 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemExportShellOutputAction.java @@ -0,0 +1,94 @@ +/******************************************************************************** + * Copyright (c) 2004, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.actions; + +import java.io.FileWriter; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.shells.ui.ShellResources; +import org.eclipse.rse.shells.ui.view.SystemCommandsUI; +import org.eclipse.rse.shells.ui.view.SystemCommandsViewPart; +import org.eclipse.rse.subsystems.files.core.SystemFileResources; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.ui.ISystemIconConstants; +import org.eclipse.rse.ui.view.ISystemViewElementAdapter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; + + + +/** + * @author dmcknigh + */ +public class SystemExportShellOutputAction extends SystemBaseShellAction +{ + public SystemExportShellOutputAction(Shell parent) + { + super(ShellResources.ACTION_EXPORT_SHELL_OUTPUT_LABEL, + ShellResources.ACTION_EXPORT_SHELL_OUTPUT_TOOLTIP, + SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_EXPORT_SHELL_OUTPUT_ID), + parent); + allowOnMultipleSelection(false); + } + + + /** + * Called when this action is selected from the popup menu. + */ + public void run() + { + SystemCommandsViewPart viewPart = SystemCommandsUI.getInstance().activateCommandsView(); + for (int i = 0; i < _selected.size(); i++) + { + IRemoteCommandShell cmdShell = (IRemoteCommandShell)_selected.get(i); + + FileDialog fdlg = new FileDialog(getShell(),SWT.SAVE); + fdlg.setText(SystemFileResources.RESID_ENTER_OR_SELECT_FILE_TITLE); + //fdlg.setText(SystemPlugin.getString("com.ibm.etools.systems.ui.RmtJarExport.selectOrEnterJarDialog.title")); + fdlg.setFileName(cmdShell.getId() + "-output.txt"); + fdlg.setFilterExtensions(new String[] {"*.txt"}); + String fileName = fdlg.open(); + try + { + + //FileOutputStream stream = new FileOutputStream(fileName); + //OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8"); + // dkm - using local encoding + FileWriter writer = new FileWriter(fileName); + + Object[] outputs = cmdShell.listOutput(); + for (int o = 0; o < outputs.length; o++) + { + IAdaptable output = (IAdaptable)outputs[o]; + ISystemViewElementAdapter adapter = (ISystemViewElementAdapter)output.getAdapter(ISystemViewElementAdapter.class); + if (adapter != null) + { + writer.write(adapter.getText(output)); + writer.write("\r\n"); + } + } + writer.close(); + } + catch (Exception e) + { + } + } + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemShowInShellViewAction.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemShowInShellViewAction.java new file mode 100644 index 00000000000..a29c0e78fcc --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemShowInShellViewAction.java @@ -0,0 +1,57 @@ +/******************************************************************************** + * Copyright (c) 2004, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.actions; + +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.shells.ui.ShellResources; +import org.eclipse.rse.shells.ui.view.SystemCommandsUI; +import org.eclipse.rse.shells.ui.view.SystemCommandsViewPart; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.ui.ISystemIconConstants; +import org.eclipse.swt.widgets.Shell; + + + +public class SystemShowInShellViewAction extends SystemBaseShellAction +{ + /** + * Constructor. + * @param shell Shell of parent window, used as the parent for the dialog. + * Can be null, but be sure to call setParent before the action is used (ie, run). + */ + public SystemShowInShellViewAction(Shell parent) + { + super(ShellResources.ACTION_SHOW_SHELL_LABEL, + ShellResources.ACTION_SHOW_SHELL_TOOLTIP, + SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_SHOW_SHELL_ID), + parent); + allowOnMultipleSelection(false); + } + + /** + * Called when this action is selected from the popup menu. + */ + public void run() + { + SystemCommandsViewPart viewPart = SystemCommandsUI.getInstance().activateCommandsView(); + for (int i = 0; i < _selected.size(); i++) + { + IRemoteCommandShell cmdShell = (IRemoteCommandShell)_selected.get(i); + viewPart.updateOutput(cmdShell); + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemTerminateRemoveShellAction.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemTerminateRemoveShellAction.java new file mode 100644 index 00000000000..4dfef6d9cd3 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemTerminateRemoveShellAction.java @@ -0,0 +1,61 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + + +package org.eclipse.rse.shells.ui.actions; + +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.shells.ui.ShellResources; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.ui.ISystemIconConstants; +import org.eclipse.swt.widgets.Shell; + + + +public class SystemTerminateRemoveShellAction extends SystemTerminateShellAction +{ + public SystemTerminateRemoveShellAction(Shell parent) + { + super(ShellResources.ACTION_CANCEL_REMOVE_SHELL_LABEL, + ShellResources.ACTION_CANCEL_REMOVE_SHELL_TOOLTIP, + SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_REMOVE_SHELL_ID), + parent); + } + + protected boolean isApplicable(IRemoteCommandShell cmdShell) + { + return true; + } + + + public void cancel(IRemoteCommandShell command) + { + try + { + IRemoteCmdSubSystem cmdSubSystem = command.getCommandSubSystem(); + if (cmdSubSystem != null) + { + cmdSubSystem.removeShell(getShell(), command); + } + } + catch (Exception e) + { + // SystemPlugin.getDefault().logInfo("Exception invoking command " + cmd + " on " + sysConn.getAliasName()); + } + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemTerminateShellAction.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemTerminateShellAction.java new file mode 100644 index 00000000000..c6c190a511a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/actions/SystemTerminateShellAction.java @@ -0,0 +1,93 @@ +/******************************************************************************** + * Copyright (c) 2004, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.actions; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.shells.ui.ShellResources; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.ui.ISystemIconConstants; +import org.eclipse.swt.widgets.Shell; + + + +public class SystemTerminateShellAction extends SystemBaseShellAction +{ + public SystemTerminateShellAction(Shell parent) + { + this(ShellResources.ACTION_CANCEL_SHELL_LABEL, + ShellResources.ACTION_CANCEL_SHELL_TOOLTIP, + SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_CANCEL_ID), + parent); + } + + public SystemTerminateShellAction(String label, + String tooltip, + ImageDescriptor image, + Shell parent) + { + super(label, + tooltip, + image, + parent); + } + + public void run() + { + // DKM - need to deselect in tree + //SystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + //registry.fireEvent(new SystemResourceChangeEvent()) + List selected = new ArrayList(); + selected.addAll(_selected); + for (int i = selected.size() -1; i >= 0; i--) + { + IRemoteCommandShell cmdShell = (IRemoteCommandShell)selected.get(i); + terminateShell(cmdShell); + } + } + + protected boolean isApplicable(IRemoteCommandShell cmdShell) + { + return cmdShell.isActive(); + } + + protected void terminateShell(IRemoteCommandShell command) + { + cancel(command); + } + + public void cancel(IRemoteCommandShell command) + { + try + { + IRemoteCmdSubSystem cmdSubSystem = command.getCommandSubSystem(); + if (cmdSubSystem != null) + { + cmdSubSystem.cancelShell(getShell(), command); + } + } + catch (Exception e) + { + // SystemPlugin.getDefault().logInfo("Exception invoking command " + cmd + " on " + sysConn.getAliasName()); + } + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/propertypages/EnvironmentVariablesPropertyPage.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/propertypages/EnvironmentVariablesPropertyPage.java new file mode 100644 index 00000000000..237ff8371a2 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/propertypages/EnvironmentVariablesPropertyPage.java @@ -0,0 +1,150 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.propertypages; + + + +import java.util.Collection; +import java.util.Iterator; +import java.util.Vector; + +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.subsystems.IRemoteSystemEnvVar; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.shells.ui.RemoteCommandHelpers; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.ui.propertypages.SystemBasePropertyPage; +import org.eclipse.rse.ui.widgets.EnvironmentVariablesForm; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + + +/** + * Property page for editing persistant environment variables for an + * RSE connection. + */ +public class EnvironmentVariablesPropertyPage extends SystemBasePropertyPage +{ + private EnvironmentVariablesForm _form; + + /** + * Constructor for EnvironmentVariablesPropertyPage. + */ + public EnvironmentVariablesPropertyPage() + { + super(); + } + + /** + * @see org.eclipse.rse.ui.propertypages.SystemBasePropertyPage#createContentArea(Composite) + */ + protected Control createContentArea(Composite parent) + { + + IRemoteCmdSubSystem cmdSubSystem = getCmdSubSystem(); + if (cmdSubSystem != null) + { + + // Create property page UI + _form = + new EnvironmentVariablesForm( + getShell(), + getMessageLine(), + getElement(), + cmdSubSystem.getInvalidEnvironmentVariableNameCharacters()); + + // Load existing environment variables + IRemoteSystemEnvVar[] envVars = getCmdSubSystem().getEnvironmentVariableList(); + // Form only works with a simple inner class since it cannot easily instantiate + // RemoteSystemEnvVarImpl classes. We leave this complexity (via MOF) to the + // subsystem. + Vector envVarsVector = new Vector(); + for (int idx = 0; idx < envVars.length; idx++) + { + envVarsVector.add(_form.new EnvironmentVariable(envVars[idx].getName(), envVars[idx].getValue())); + } + _form.setEnvVars(envVarsVector); + + _form.createContents(parent); + + } + else + { + // Create property page UI + _form = + new EnvironmentVariablesForm( + getShell(), + getMessageLine(), + null, + null); + + _form.createContents(parent); + } + return parent; + } + + /** + * @see org.eclipse.rse.ui.propertypages.SystemBasePropertyPage#verifyPageContents() + */ + protected boolean verifyPageContents() + { + return true; + } + + /** + * Return the command subsystem implementation object. + */ + private IRemoteCmdSubSystem getCmdSubSystem() + { + Object subsystem = getElement(); + if (subsystem instanceof ISubSystem) + { + return RemoteCommandHelpers.getCmdSubSystem(((ISubSystem)subsystem).getHost()); + } + else + { + SystemBasePlugin.logError( + "EnvironmentVariablesPropertyPage.getCmdSubSystem: input element for property page is not an instanceof SubSystem: " + + subsystem); + return null; + } + } + + /** + * @see org.eclipse.jface.preference.IPreferencePage#performOk() + */ + public boolean performOk() + { + Collection envVars = _form.getEnvVars(); + String[] names = new String[envVars.size()]; + String[] values = new String[envVars.size()]; + + Iterator i = envVars.iterator(); + EnvironmentVariablesForm.EnvironmentVariable variable; + for (int idx = 0; i.hasNext(); idx++) + { + variable = (EnvironmentVariablesForm.EnvironmentVariable) i.next(); + names[idx] = variable.getName(); + values[idx] = variable.getValue(); + } + + getCmdSubSystem().setEnvironmentVariableList(names, values); + + return true; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/propertypages/ShellServicesPropertyPage.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/propertypages/ShellServicesPropertyPage.java new file mode 100644 index 00000000000..4b004baa89b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/propertypages/ShellServicesPropertyPage.java @@ -0,0 +1,109 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.propertypages; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.servicesubsystem.IServiceSubSystemConfiguration; +import org.eclipse.rse.core.subsystems.ISubSystemConfiguration; +import org.eclipse.rse.model.DummyHost; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.model.ISystemRegistry; +import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.IShellServiceSubSystemConfiguration; +import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.ShellServiceSubSystem; +import org.eclipse.rse.ui.propertypages.ServicesPropertyPage; +import org.eclipse.rse.ui.widgets.services.FactoryServiceElement; +import org.eclipse.rse.ui.widgets.services.ServiceElement; + + +public class ShellServicesPropertyPage extends ServicesPropertyPage +{ + + private IShellServiceSubSystemConfiguration _currentFactory; + + + protected ShellServiceSubSystem getShellServiceSubSystem() + { + return (ShellServiceSubSystem)getElement(); + } + + + protected ServiceElement[] getServiceElements() + { + ShellServiceSubSystem subSystem = getShellServiceSubSystem(); + IShellServiceSubSystemConfiguration[] factories = null; + IHost host = null; + if (subSystem == null || _currentFactory != null) + { + // create dummy host + factories = getShellServiceSubSystemFactories(getSystemType()); + host = new DummyHost(getHostname(), getSystemType()); + } + else + { + host = subSystem.getHost(); + _currentFactory = (IShellServiceSubSystemConfiguration)subSystem.getParentRemoteCmdSubSystemFactory(); + factories = getShellServiceSubSystemFactories(host.getSystemType()); + } + + // create elements for each + ServiceElement[] elements = new ServiceElement[factories.length]; + for (int i = 0; i < factories.length; i++) + { + IShellServiceSubSystemConfiguration factory = factories[i]; + + elements[i] = new FactoryServiceElement(host, factory); + if (factory == _currentFactory) + { + elements[i].setSelected(true); + } + } + return elements; + } + + + protected IShellServiceSubSystemConfiguration[] getShellServiceSubSystemFactories(String systemType) + { + List results = new ArrayList(); + ISystemRegistry sr = SystemPlugin.getTheSystemRegistry(); + ISubSystemConfiguration[] factories = sr.getSubSystemConfigurationsBySystemType(systemType); + + for (int i = 0; i < factories.length; i++) + { + ISubSystemConfiguration factory = factories[i]; + if (factory instanceof IShellServiceSubSystemConfiguration) + { + results.add(factory); + } + } + + return (IShellServiceSubSystemConfiguration[])results.toArray(new IShellServiceSubSystemConfiguration[results.size()]); + } + + + protected IServiceSubSystemConfiguration getCurrentServiceSubSystemFactory() + { + return _currentFactory; + } + + public void setSubSystemFactory(ISubSystemConfiguration factory) + { + _currentFactory = (IShellServiceSubSystemConfiguration)factory; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/propertypages/SystemShellPropertyPage.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/propertypages/SystemShellPropertyPage.java new file mode 100644 index 00000000000..4e0deb5863e --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/propertypages/SystemShellPropertyPage.java @@ -0,0 +1,142 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + + +package org.eclipse.rse.shells.ui.propertypages; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteCmdSubSystem; +import org.eclipse.rse.shells.ui.ShellResources; +import org.eclipse.rse.shells.ui.view.EncodingForm; +import org.eclipse.rse.ui.propertypages.SystemBasePropertyPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; + + + +public class SystemShellPropertyPage extends SystemBasePropertyPage +{ + private EncodingForm _form; + + public SystemShellPropertyPage() + { + super(); + setDescription(ShellResources.RESID_SHELL_PROPERTYPAGE_DESCRIPTION); + } + + public void setShellEncodingDefaults(List encodings) + { + StringBuffer history = new StringBuffer(); + for (int i = 0; i < encodings.size(); i++) + { + String encoding = (String)encodings.get(i); + history.append(encoding); + if (i < encodings.size()) + { + history.append(','); + } + } + + SystemPlugin.getDefault().getPreferenceStore().setValue("shell.encodingDefaults", history.toString()); + } + + public List getShellEncodingDefaults() + { + List result = new ArrayList(); + String attribute = SystemPlugin.getDefault().getPreferenceStore().getString("shell.encodingDefaults"); + if (attribute != null && attribute.length() > 0) + { + String[] list = attribute.split(","); + for (int i = 0; i < list.length; i++) + { + result.add(list[i]); + } + } + else + { + result.add("UTF-8"); + result.add("UTF-16"); + result.add("US-ASCII"); + result.add("ISO-8859-1"); + result.add("Cp1252"); + result.add("Cp1256"); + } + return result; + } + + + /* (non-Javadoc) + * @see com.ibm.etools.systems.core.ui.propertypages.SystemBasePropertyPage#createContentArea(org.eclipse.swt.widgets.Composite) + */ + protected Control createContentArea(Composite parent) + { + Font font = parent.getFont(); + Group group = new Group(parent, SWT.NONE); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + group.setLayoutData(data); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + group.setLayout(layout); + group.setText(ShellResources.RESID_SHELL_PROPERTYPAGE_ENCODING); + group.setFont(font); + + _form = new EncodingForm(getShell(), getMessageLine()); + _form.createContents(group); + + RemoteCmdSubSystem cmdSS = getCmdSubSystem(); + _form.initialize(getShellEncodingDefaults(), cmdSS.getShellEncoding()); + return _form.getDefaultControl(); + } + + public RemoteCmdSubSystem getCmdSubSystem() + { + return (RemoteCmdSubSystem)getElement(); + } + + /* (non-Javadoc) + * @see com.ibm.etools.systems.core.ui.propertypages.SystemBasePropertyPage#verifyPageContents() + */ + protected boolean verifyPageContents() + { + return true; + } + + /** + * @see org.eclipse.jface.preference.IPreferencePage#performOk() + */ + public boolean performOk() + { + String encoding = _form.getEncoding(); + getCmdSubSystem().setShellEncoding(encoding); + + List defaults = getShellEncodingDefaults(); + if (!defaults.contains(encoding)) + { + defaults.add(encoding); + setShellEncodingDefaults(defaults); + } + + return true; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/CommandEntryContentAssistProcessor.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/CommandEntryContentAssistProcessor.java new file mode 100644 index 00000000000..26c20568ea9 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/CommandEntryContentAssistProcessor.java @@ -0,0 +1,635 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.contentassist.CompletionProposal; +import org.eclipse.jface.text.contentassist.ContextInformation; +import org.eclipse.jface.text.contentassist.ICompletionProposal; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.text.contentassist.IContextInformation; +import org.eclipse.jface.text.contentassist.IContextInformationValidator; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.subsystems.RemoteChildrenContentsType; +import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteCmdSubSystem; +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.subsystems.files.core.subsystems.RemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileChildrenContentsType; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteFolderChildrenContentsType; +import org.eclipse.rse.subsystems.shells.core.model.ISystemOutputRemoteTypes; +import org.eclipse.rse.subsystems.shells.core.subsystems.ICandidateCommand; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.ui.ISystemIconConstants; +import org.eclipse.rse.ui.view.ISystemViewElementAdapter; +import org.eclipse.rse.ui.view.SystemTableViewProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; + + +/** + * Class that implements the content assist processor interface for the command line. + */ +public class CommandEntryContentAssistProcessor implements IContentAssistProcessor +{ + + private class CompletionResults + { + private List _nameResults; + private List _proposalResults; + private List _proposalHelpResults; + private List _images; + + public CompletionResults() + { + _nameResults = new ArrayList(); + _proposalResults = new ArrayList(); + _proposalHelpResults = new ArrayList(); + _images = new ArrayList(); + } + + public int size() + { + return _nameResults.size(); + } + + public void addResult(String name, String text, String help, Image image) + { + _nameResults.add(name); + _proposalResults.add(text); + _proposalHelpResults.add(help); + _images.add(image); + } + + public String getNameAt(int i) + { + return (String) _nameResults.get(i); + } + + public String getTextAt(int i) + { + return (String) _proposalResults.get(i); + } + + public String getHelpAt(int i) + { + return (String) _proposalHelpResults.get(i); + } + + public Image getImageAt(int i) + { + return (Image) _images.get(i); + } + } + + private CommandEntryViewerConfiguration _configurator; + private SystemTableViewProvider _provider; + private HashMap _imageMap; + private IRemoteCommandShell _remoteCommand; + private char _fileSeparator; + private char _foreignFileSeparator; + private IRemoteFile _lastFolderContext; + private boolean _isWindows; + private Image _envImage; + + private static int FILES_ONLY = 0; + private static int FOLDERS_ONLY = 1; + private static int FILES_AND_FOLDERS = 2; + + /** + * Constructor + */ + public CommandEntryContentAssistProcessor(CommandEntryViewerConfiguration configurator) + { + _configurator = configurator; + _provider = new SystemTableViewProvider(); + _imageMap = new HashMap(); + } + + public void setRemoteCommand(IRemoteCommandShell cmd) + { + if (cmd != _remoteCommand) + { + + _remoteCommand = cmd; + if (_remoteCommand != null) + { + RemoteCmdSubSystem cmdSubsystem = (RemoteCmdSubSystem) _remoteCommand.getCommandSubSystem(); + String type = cmdSubsystem.getHost().getSystemType(); + if (cmdSubsystem.isWindows()) + { + _isWindows = true; + _fileSeparator = '\\'; + _foreignFileSeparator = '/'; + } + else + { + _isWindows = false; + _fileSeparator = '/'; + _foreignFileSeparator = '\\'; + } + + _remoteCommand.getCandidateCommands(); + } + } + } + + public IRemoteCommandShell getRemoteCommand() + { + return _remoteCommand; + } + + private boolean isDeliminator(char c) + { + if (c == ' ' || c == ';' || c == ':' || c == '&' || c == '|' || c == '=') + return true; + return false; + } + + private String getCurrentText(ITextViewer viewer, int documentOffset) + { + StringBuffer currentText = new StringBuffer(); + String text = viewer.getDocument().get(); + if (documentOffset > -1) + { + boolean noWhiteSpace = true; + int firstChar = documentOffset - 1; + while (firstChar > -1 && noWhiteSpace) + { + char c = text.charAt(firstChar); + if (isDeliminator(c)) + { + noWhiteSpace = false; + } + else + { + currentText.insert(0, c); + } + firstChar--; + } + } + return currentText.toString(); + } + + private boolean isAtFirstToken(IDocument document) + { + String text = document.get(); + if (text.length() > 0) + { + int spaceIndex = text.indexOf(' '); + if (spaceIndex > 0) + { + return false; + } + } + + return true; + } + + private String getFirstToken(IDocument document) + { + StringBuffer buf = new StringBuffer(); + String text = document.get(); + int index = 0; + while (index < text.length()) + { + char c = text.charAt(index); + if (c == ' ') + { + return buf.toString(); + } + else + { + buf.append(c); + } + index++; + } + return buf.toString(); + } + + /** + * @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int) + */ + public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) + { + String text = viewer.getDocument().get(); + boolean atFirstToken = isAtFirstToken(viewer.getDocument()); + String firstToken = getFirstToken(viewer.getDocument()); + String currentText = getCurrentText(viewer, documentOffset); + + CompletionResults completions = getCompletions(firstToken, currentText, atFirstToken); + if (completions != null && completions.size() > 0) + { + ICompletionProposal[] proposalList = new ICompletionProposal[completions.size()]; + + int replacementOffset = documentOffset - currentText.length(); + int replacementLength = 0; + + replacementLength = documentOffset - replacementOffset; + + for (int idx = 0; idx < proposalList.length; idx++) + { + String name = completions.getNameAt(idx); + String proposal = completions.getTextAt(idx); + String help = completions.getHelpAt(idx); + Image image = completions.getImageAt(idx); + + // @param replacementString the actual string to be inserted into the document + // @param replacementOffset the offset of the text to be replaced + // @param replacementLength the length of the text to be replaced + // @param cursorPosition the position of the cursor following the insert relative to replacementOffset + // @param image the image to display for this proposal + // @param displayString the string to be displayed for the proposal + // @param contentInformation the context information associated with this proposal + // @param additionalProposalInfo the additional information associated with this proposal + ContextInformation info = new ContextInformation(proposal, help); + proposalList[idx] = new CompletionProposal(proposal, replacementOffset, replacementLength, documentOffset + proposal.length(), image, name, info, help); + + } + return proposalList; + } + return new ICompletionProposal[0]; + } + + private Image getImageFor(Object object) + { + ImageDescriptor descriptor = null; + Image image = null; + if (object instanceof ICandidateCommand) + { + ICandidateCommand cmd = (ICandidateCommand) object; + descriptor = cmd.getImageDescriptor(); + if (descriptor == null) + { + String type = cmd.getType(); + if (type.equals(ISystemOutputRemoteTypes.TYPE_FILE)) + { + descriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE); + } + else + { + descriptor = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_RUN_ID); + } + } + } + else if (object instanceof IAdaptable) + { + ISystemViewElementAdapter adapter = (ISystemViewElementAdapter) ((IAdaptable) object).getAdapter(ISystemViewElementAdapter.class); + descriptor = adapter.getImageDescriptor(object); + } + + image = (Image) _imageMap.get(descriptor); + if (image == null) + { + image = descriptor.createImage(); + _imageMap.put(descriptor, image); + } + return image; + } + + private Image getEnvironmentVariableImage() + { + if (_envImage == null) + { + _envImage = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_ENVVAR_ID).createImage(); + } + return _envImage; + } + + private CompletionResults getCompletions(String firstToken, String currentText, boolean atFirstToken) + { + CompletionResults results = new CompletionResults(); + if (_remoteCommand != null && _remoteCommand.isActive()) + { + Object context = _remoteCommand.getContext(); + if (context instanceof IRemoteFile) + { + + IRemoteFile workingDirectory = (IRemoteFile)context; + if (workingDirectory != null) + { + int separatorIndex = currentText.lastIndexOf(_fileSeparator); + int foreignseparatorIndex = currentText.lastIndexOf(_foreignFileSeparator); + if (foreignseparatorIndex > separatorIndex) + { + separatorIndex = foreignseparatorIndex; + } + + if (separatorIndex > 0) + { + String previousText = currentText.substring(0, separatorIndex + 1).replace(_foreignFileSeparator, _fileSeparator); + String nextText = ""; + if (separatorIndex < currentText.length()) + { + nextText = currentText.substring(separatorIndex + 1, currentText.length()); + } + + IRemoteFile contextDirectory = null; + String contextPath = null; + if (!_isWindows && currentText.charAt(0) == _fileSeparator) + { + contextPath = previousText; + } + else + { + contextPath = workingDirectory.getAbsolutePath() + _fileSeparator + previousText; + } + + if (_lastFolderContext != null && _lastFolderContext.getAbsolutePath().equals(contextPath)) + { + contextDirectory = _lastFolderContext; + } + else + { + try + { + contextDirectory = RemoteFileUtility.getFileSubSystem(_remoteCommand.getCommandSubSystem().getHost()).getRemoteFileObject(contextPath); + _lastFolderContext = contextDirectory; + } + catch (Exception e) + { + } + } + getFileCompletions(contextDirectory, previousText, nextText, results, FILES_AND_FOLDERS); + + } + else + { + if (atFirstToken) + { + if (!_isWindows && currentText.length() > 0 && currentText.charAt(0) == _fileSeparator) + { + getAbsoluteFileCompletions("", currentText, results, FILES_AND_FOLDERS); + } + else + { + getFileCompletions(workingDirectory, "", currentText, results, FILES_ONLY); + getCommandCompletions(currentText, results); + } + } + else + { + int flag = FILES_AND_FOLDERS; + + if (firstToken.equals("cd")) + { + flag = FOLDERS_ONLY; + } + else + { + if (_isWindows) + { + if (firstToken.equals("set") || currentText.startsWith("%")) + { + getEnvironmentCompletions(currentText, results); + return results; + } + } + else if (firstToken.equals("export") || currentText.startsWith("$")) + { + getEnvironmentCompletions(currentText, results); + return results; + } + } + + getFileCompletions(workingDirectory, "", currentText, results, flag); + } + } + } + } + else + { + getCommandCompletions(currentText, results); + } + } + + return results; + } + + private void getEnvironmentCompletions(String currentText, CompletionResults results) + { + IRemoteCmdSubSystem subsystem = _remoteCommand.getCommandSubSystem(); + if (subsystem instanceof IRemoteCmdSubSystem) + { + IRemoteCmdSubSystem cmdSubsystem = (IRemoteCmdSubSystem) subsystem; + List vars = cmdSubsystem.getHostEnvironmentVariables(); + if (vars != null) + { + for (int i = 0; i < vars.size(); i++) + { + String var = (String) vars.get(i); + int eqSepIndex = var.indexOf('='); + String name = var.substring(0, eqSepIndex); + String value = var.substring(eqSepIndex + 1, var.length()); + boolean hasDollars = currentText.startsWith("$"); + String compareName = name; + if (hasDollars) + { + compareName = "$" + name; + } + boolean hasPercent = currentText.startsWith("%"); + if (hasPercent) + { + compareName = "%" + name + "%"; + } + + if (compareName.toLowerCase().startsWith(currentText.toLowerCase())) + { + + results.addResult(name, compareName, value, getEnvironmentVariableImage()); + } + } + } + } + } + + private void getCommandCompletions(String currentText, CompletionResults results) + { + IRemoteCmdSubSystem subsystem = _remoteCommand.getCommandSubSystem(); + if (subsystem instanceof IRemoteCmdSubSystem) + { + IRemoteCmdSubSystem cmdSubsystem = (IRemoteCmdSubSystem) subsystem; + ICandidateCommand[] cmds = cmdSubsystem.getCandidateCommands(_remoteCommand); + if (cmds != null) + { + for (int i = 0; i < cmds.length; i++) + { + ICandidateCommand cmd = cmds[i]; + String name = cmd.getName(); + if (name.toLowerCase().startsWith(currentText.toLowerCase())) + { + + results.addResult(name, name, cmd.getDescription(), getImageFor(cmd)); + } + } + } + } + } + + private void getAbsoluteFileCompletions(String prefix, String currentText, CompletionResults results, int flag) + { + if (!_isWindows) + { + int lastSlashIndex = currentText.lastIndexOf("/"); + String parentPath = currentText.substring(0, lastSlashIndex); + IRemoteFileSubSystem fs = RemoteFileUtility.getFileSubSystem(_remoteCommand.getCommandSubSystem().getHost()); + try + { + IRemoteFile parent = fs.getRemoteFileObject(parentPath); + + Object[] fileList = null; + + if (parent.hasContents(RemoteChildrenContentsType.getInstance())) + { + fileList = parent.getContents(RemoteChildrenContentsType.getInstance()); + } + else + { + fileList = parent.getParentRemoteFileSubSystem().listFoldersAndFiles(parent, currentText + "*"); + } + + + for (int f1 = 0; f1 < fileList.length; f1++) + { + if (fileList[f1] instanceof IRemoteFile) + { + RemoteFile file = (RemoteFile) fileList[f1]; + if ((flag == FILES_ONLY && file.isFile()) || (flag == FOLDERS_ONLY && file.isDirectory()) || (flag == FILES_AND_FOLDERS)) + { + String name = file.getName(); + String proposal = prefix + name; + + if (name.startsWith(currentText)) + { + results.addResult(name, proposal, file.getAbsolutePath(), getImageFor(file)); + } + else if (_isWindows && name.toLowerCase().startsWith(currentText.toLowerCase())) + { + results.addResult(name, proposal, file.getAbsolutePath(), getImageFor(file)); + } + } + } + } + } + catch (Exception e) + { + } + } + } + + private void getFileCompletions(IRemoteFile workingDirectory, String prefix, String currentText, CompletionResults results, int flag) + { + + Object[] fileList = null; + + if (workingDirectory.hasContents(RemoteChildrenContentsType.getInstance()) && !workingDirectory.isStale()) + { + if (flag == FILES_ONLY) + { + fileList = workingDirectory.getContents(RemoteFileChildrenContentsType.getInstance()); + } + else if (flag == FOLDERS_ONLY) + { + fileList = workingDirectory.getContents(RemoteFolderChildrenContentsType.getInstance()); + } + else + { + fileList = workingDirectory.getContents(RemoteChildrenContentsType.getInstance()); + } + } + else + { + fileList = workingDirectory.getParentRemoteFileSubSystem().listFoldersAndFiles(workingDirectory, currentText + "*"); + } + //_provider.getChildren(workingDirectory); + + if (fileList != null && fileList.length > 0) + { + for (int f1 = 0; f1 < fileList.length; f1++) + { + if (fileList[f1] instanceof IRemoteFile) + { + RemoteFile file = (RemoteFile) fileList[f1]; + if ((flag == FILES_ONLY && file.isFile()) || (flag == FOLDERS_ONLY && file.isDirectory()) || (flag == FILES_AND_FOLDERS)) + { + String name = file.getName(); + String proposal = prefix + name; + + if (name.startsWith(currentText)) + { + results.addResult(name, proposal, file.getAbsolutePath(), getImageFor(file)); + } + else if (_isWindows && name.toLowerCase().startsWith(currentText.toLowerCase())) + { + results.addResult(name, proposal, file.getAbsolutePath(), getImageFor(file)); + } + } + } + } + } + } + + /* + * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int) + */ + public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) + { + return null; + } + + /* + * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters() + */ + public char[] getCompletionProposalAutoActivationCharacters() + { + return _configurator.getCompletionProposalAutoActivationCharacters(); + } + + /* + * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters() + */ + public char[] getContextInformationAutoActivationCharacters() + { + return null; + } + + /* + * @see IContentAssistProcessor#getErrorMessage() + */ + public String getErrorMessage() + { + return null; + } + + /* + * @see IContentAssistProcessor#getContextInformationValidator() + */ + public IContextInformationValidator getContextInformationValidator() + { + return null; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/CommandEntryViewerConfiguration.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/CommandEntryViewerConfiguration.java new file mode 100644 index 00000000000..1f678d02612 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/CommandEntryViewerConfiguration.java @@ -0,0 +1,87 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.contentassist.ContentAssistant; +import org.eclipse.jface.text.contentassist.IContentAssistant; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; + + +/** + * Source viewer configuration class for command line content assist. + * + */ +public class CommandEntryViewerConfiguration extends SourceViewerConfiguration +{ + + private CommandEntryContentAssistProcessor _contentAssistantProcessor; + private ContentAssistant _contentAssistant; + /** + * Constructor + */ + public CommandEntryViewerConfiguration() + { + super(); + _contentAssistantProcessor = new CommandEntryContentAssistProcessor(this); + + } + + public void setRemoteCommand(IRemoteCommandShell cmd) + { + _contentAssistantProcessor.setRemoteCommand(cmd); + } + + public IRemoteCommandShell getRemoteCommand() + { + return _contentAssistantProcessor.getRemoteCommand(); + } + + /** + * Parent override. + * Returns the content assistant ready to be used with the given source viewer. + * + * @param sourceViewer the source viewer to be configured by this configuration + * @return a content assistant or null if content assist should not be supported + */ + public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) + { + if (_contentAssistant == null) + { + _contentAssistant = new ContentAssistant(); + _contentAssistant.setContentAssistProcessor(_contentAssistantProcessor, IDocument.DEFAULT_CONTENT_TYPE); + _contentAssistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY); + //_contentAssistant.enableAutoActivation(true); + _contentAssistant.enableAutoInsert(true); + + _contentAssistant.setInformationControlCreator(getInformationControlCreator(sourceViewer)); + } + return _contentAssistant; + } + + /** + * Return the characters which trigger the auto-display of the list + * substitution variables. We return '$' by default, but this can be + * overridden. + */ + protected char[] getCompletionProposalAutoActivationCharacters() + { + return new char[] { '/', '\\', '$', '%'}; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/CommandsViewPage.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/CommandsViewPage.java new file mode 100644 index 00000000000..fe144b8d2f0 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/CommandsViewPage.java @@ -0,0 +1,654 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.text.ITextOperationTarget; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableLayout; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.model.ISystemRegistry; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.shells.ui.ShellResources; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.ui.ISystemMessages; +import org.eclipse.rse.ui.ISystemThemeConstants; +import org.eclipse.rse.ui.SystemResources; +import org.eclipse.rse.ui.SystemWidgetHelpers; +import org.eclipse.rse.ui.actions.SystemCopyToClipboardAction; +import org.eclipse.rse.ui.actions.SystemPasteFromClipboardAction; +import org.eclipse.rse.ui.view.ISystemViewElementAdapter; +import org.eclipse.rse.ui.view.SystemTableViewProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.CellEditorActionHandler; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; +import org.eclipse.ui.themes.IThemeManager; + + +/** + * Class for a remote shell session on a connection + */ +public class CommandsViewPage implements SelectionListener, ISystemThemeConstants, IPropertyChangeListener, ISelectionChangedListener, +FocusListener +{ + + private Listener _keyListener = new Listener() + { + private boolean checkState(Event event) + { + if (event.character == '\r') + { + _inputEntry.setInCodeAssist(false); + } + + return !_inputEntry.isInCodeAssist(); + } + + public void handleEvent(Event e) + { + if (checkState(e)) + { + + if (e.character == '\r') // "enter" key + { + sendInput(); + } + else if (e.keyCode == 13) + { + sendInput(); + } + else if (e.keyCode == 16777217) // "up" arrow + { + handleUp(); + } + else if (e.keyCode == 16777218) // "down" arrow + { + handleDown(); + } + else if (e.stateMask == 262144) + { + if (((int)e.character) == 3) + { + if (_inputEntry.getSelectedText().length() == 0) + { + sendBreak(); + } + else + { + _inputEntry.doOperation(ITextOperationTarget.COPY); + } + } + } + } + } + }; + + class SelectAllAction extends Action + { + public SelectAllAction() + { + super(SystemResources.ACTION_SELECT_ALL_LABEL, null); + setToolTipText(SystemResources.ACTION_SELECT_ALL_TOOLTIP); + } + + public void checkEnabledState() + { + setEnabled(true); + } + + public void run() + { + SystemCommandsView view = _viewer; + view.getTable().selectAll(); + view.setSelection(view.getSelection()); + } + } + + + private CommandEntryViewerConfiguration _entryViewerConfiguration; + + private SystemCommandsView _viewer; + + private SystemCommandEditor _inputEntry; + + private Button _upButton; + private Button _downButton; + private Composite _inputContainer; + private Group _tabFolderPage; + + private int _commandHistoryOffset; + private SystemCommandsViewPart _viewPart; + + private String _title; + + private SystemCopyToClipboardAction _copyAction; + private SystemPasteFromClipboardAction _pasteAction; + private SelectAllAction _selectAllAction; + private IActionBars _actionBars; + + public CommandsViewPage(SystemCommandsViewPart viewPart) + { + _commandHistoryOffset = 0; + _entryViewerConfiguration = new CommandEntryViewerConfiguration(); + _viewPart = viewPart; + _actionBars = _viewPart.getViewSite().getActionBars(); + } + + public Composite createTabFolderPage(CTabFolder tabFolder, CellEditorActionHandler editorActionHandler) + { + _tabFolderPage = new Group(tabFolder, SWT.NULL); + GridLayout gridLayout = new GridLayout(); + _tabFolderPage.setLayout(gridLayout); + + createControl(_tabFolderPage); + + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + + // global actions + Clipboard clipboard = registry.getSystemClipboard(); + _copyAction = new SystemCopyToClipboardAction(_viewer.getShell(), clipboard); + _copyAction.setEnabled(false); + + _pasteAction = new SystemPasteFromClipboardAction(_viewer.getShell(), clipboard); + _pasteAction.setEnabled(false); + + editorActionHandler.setCopyAction(_copyAction); + editorActionHandler.setPasteAction(_pasteAction); + + _selectAllAction = new SelectAllAction(); + _selectAllAction.setEnabled(false); + editorActionHandler.setSelectAllAction(_selectAllAction); + + + _viewer.addSelectionChangedListener(this); + _viewer.getControl().addFocusListener(this); + _inputEntry.getControl().addFocusListener(this); + + return _tabFolderPage; + } + + public void setFocus() + { + _inputEntry.getTextWidget().setFocus(); + + _viewPart.getSite().setSelectionProvider(_viewer); + } + + public IActionBars getActionBars() + { + return _actionBars; + } + + public void selectionChanged(SelectionChangedEvent e) + { + IStructuredSelection sel = (IStructuredSelection) e.getSelection(); + _copyAction.setEnabled(_copyAction.updateSelection(sel)); + _pasteAction.setEnabled(_pasteAction.updateSelection(sel)); + _selectAllAction.setEnabled(true); + + //setActionHandlers(); + } + + + + + public void setEnabled(boolean flag) + { + if (!flag) + { + _inputEntry.getTextWidget().setEnabled(flag); + _inputEntry.setEditable(flag); + + Table table = _viewer.getTable(); + + Display display = _viewer.getShell().getDisplay(); + Color bgcolour = _tabFolderPage.getBackground(); + + table.setBackground(bgcolour); + _inputEntry.getTextWidget().setBackground(bgcolour); + } + } + + public void createControl(Composite parent) + { + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 1; + parent.setLayout(gridLayout); + + // create table portion + Table table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.HIDE_SELECTION); + _viewer = new SystemCommandsView(table, _viewPart); + _viewer.setWorkbenchPart(_viewPart); + + _viewer.addDoubleClickListener(new IDoubleClickListener() + { + public void doubleClick(DoubleClickEvent event) + { + handleDoubleClick(event); + } + }); + + + SystemWidgetHelpers.setHelp(_viewer.getControl(), SystemPlugin.HELPPREFIX + "ucmd0000"); + + TableLayout layout = new TableLayout(); + table.setLayout(layout); + table.setHeaderVisible(false); + table.setLinesVisible(false); + + GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); + table.setLayoutData(gridData); + + _inputContainer = new Composite(parent, SWT.NONE); + GridLayout ilayout = new GridLayout(); + ilayout.numColumns = 4; + + Label label = new Label(_inputContainer, SWT.NONE); + label.setText(ShellResources.RESID_COMMANDSVIEW_COMMAND_LABEL); + + _inputEntry = new SystemCommandEditor(_viewPart.getViewSite(), _inputContainer, SWT.SINGLE | SWT.BORDER, 50, _entryViewerConfiguration, "", SystemResources.ACTION_CONTENT_ASSIST); + _inputEntry.getTextWidget().setToolTipText(ShellResources.RESID_COMMANDSVIEW_COMMAND_TOOLTIP); + + + _upButton = new Button(_inputContainer, SWT.ARROW | SWT.UP); + _upButton.addSelectionListener(this); + _upButton.setToolTipText(ShellResources.RESID_COMMANDSVIEW_PREVIOUS_TOOLTIP); + + _downButton = new Button(_inputContainer, SWT.ARROW | SWT.DOWN); + _downButton.addSelectionListener(this); + _downButton.setToolTipText(ShellResources.RESID_COMMANDSVIEW_PREVIOUS_TOOLTIP); + + GridData idata = new GridData(GridData.VERTICAL_ALIGN_END | GridData.FILL_VERTICAL | GridData.FILL_HORIZONTAL); + idata.heightHint = 22; + _inputEntry.getTextWidget().setLayoutData(idata); + _inputEntry.getTextWidget().addListener(SWT.KeyUp, _keyListener); + + enableEntry(false); + + GridData gridData1 = new GridData(GridData.FILL_HORIZONTAL); + _inputContainer.setLayout(ilayout); + _inputContainer.setLayoutData(gridData1); + + updateTheme(); + IThemeManager mgr = PlatformUI.getWorkbench().getThemeManager(); + mgr.addPropertyChangeListener(this); + + + + } + + public void propertyChange(PropertyChangeEvent e) + { + updateTheme(); + } + public void updateTheme() + { + Display display = getViewer().getControl().getDisplay(); + IThemeManager mgr = PlatformUI.getWorkbench().getThemeManager(); + Color bg = mgr.getCurrentTheme().getColorRegistry().get(REMOTE_COMMANDS_VIEW_BG_COLOR); + Color fg = mgr.getCurrentTheme().getColorRegistry().get(REMOTE_COMMANDS_VIEW_FG_COLOR); + Font fFont =mgr.getCurrentTheme().getFontRegistry().get(REMOTE_COMMANDS_VIEW_FONT); + + _inputEntry.getControl().setBackground(bg); + _inputEntry.getControl().setForeground(fg); + _inputEntry.getControl().setFont(fFont); + } + + private void handleDoubleClick(DoubleClickEvent event) + { + IStructuredSelection s = (IStructuredSelection) event.getSelection(); + Object element = s.getFirstElement(); + if (element == null) + return; + + ISystemViewElementAdapter adapter = (ISystemViewElementAdapter) ((IAdaptable) element).getAdapter(ISystemViewElementAdapter.class); + boolean alreadyHandled = false; + if (adapter != null) + { + if (adapter.hasChildren(element)) + { + // special case for folders + if (element instanceof IRemoteFile) + { + IRemoteFile folder = (IRemoteFile) element; + if (folder.isDirectory()) + { + String path = folder.getAbsolutePath(); + ISubSystem cmdSubSystem = adapter.getSubSystem(element); + + String cdCmd = "cd " + "\"" + path + "\""; + if (cmdSubSystem.getHost().getSystemType().equals("Local") + && System.getProperty("os.name").toLowerCase().startsWith("win") + || cmdSubSystem.getHost().getSystemType().equals("Windows")) + { + cdCmd = "cd /d " + path; + } + sendInput(cdCmd); + } + } + } + else + { + alreadyHandled = adapter.handleDoubleClick(element); + } + } + } + + public void dispose() + { + IThemeManager mgr = PlatformUI.getWorkbench().getThemeManager(); + mgr.removePropertyChangeListener(this); + + _inputEntry.getTextWidget().removeListener(SWT.KeyUp, _keyListener); + _inputEntry.getTextWidget().dispose(); + _inputContainer.dispose(); + _viewer.dispose(); + _tabFolderPage.dispose(); + } + + private void enableEntry(boolean flag) + { + if (!_inputEntry.getTextWidget().isDisposed()) + _inputEntry.getTextWidget().setEnabled(flag); + } + + public void sendInput() + { + String inputStr = _inputEntry.getTextWidget().getText(); + sendInput(inputStr); + } + + public void sendInput(String inputStr) + { + Object input = _viewer.getInput(); + if (input instanceof IRemoteCommandShell) + { + _commandHistoryOffset = getCommandHistory().length + 1; + IRemoteCommandShell remoteCommand = (IRemoteCommandShell) input; + IRemoteCmdSubSystem commandSubSystem = remoteCommand.getCommandSubSystem(); + try + { + commandSubSystem.sendCommandToShell(inputStr, _viewer.getShell(), remoteCommand); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + _inputEntry.getTextWidget().setText(""); + _inputEntry.getTextWidget().setFocus(); + } + + public void sendBreak() + { + Object input = _viewer.getInput(); + if (input instanceof IRemoteCommandShell) + { + IRemoteCommandShell remoteCommand = (IRemoteCommandShell) input; + IRemoteCmdSubSystem commandSubSystem = remoteCommand.getCommandSubSystem(); + try + { + commandSubSystem.sendCommandToShell("#break", _viewer.getShell(), remoteCommand); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + } + + public Object getInput() + { + return _viewer.getInput(); + } + + public void setInput(IAdaptable object) + { + setInput(object, true); + updateTitle(object); + } + + public void updateTitle(IAdaptable object) + { + if (object instanceof IRemoteCommandShell) + { + IRemoteCommandShell command = (IRemoteCommandShell) object; + String title = command.getType(); + + SystemMessage msg = null; + if (!command.isActive()) + { + msg = SystemPlugin.getPluginMessage(ISystemMessages.MSG_OPERATION_FINISHED); + } + else + { + msg = SystemPlugin.getPluginMessage(ISystemMessages.MSG_OPERATION_RUNNING); + } + + msg.makeSubstitution(title); + _title = msg.getLevelOneText(); + _tabFolderPage.setText(_title); + } + } + + public String getTitle() + { + return _title; + } + + public void setInput(IAdaptable object, boolean updateHistory) + { + if (_viewer != null && object != null) + { + _viewer.setInput(object); + _entryViewerConfiguration.setRemoteCommand((IRemoteCommandShell) object); + //_inputEntry.getTextWidget().setFocus(); + } + } + + public void clearInput() + { + if (_viewer != null) + { + _viewer.setInput(null); + _entryViewerConfiguration.setRemoteCommand(null); + } + } + + public SystemCommandsView getViewer() + { + return _viewer; + } + + public void updateOutput() + { + if (_viewer != null) + { + ((SystemTableViewProvider) _viewer.getContentProvider()).flushCache(); + _viewer.updateChildren(); + _commandHistoryOffset = getCommandHistory().length; + } + } + + public void updateActionStates() + { + Object input = _viewer.getInput(); + if (input != null) + { + if (input instanceof IRemoteCommandShell) + { + IRemoteCommandShell cmdInput = (IRemoteCommandShell) input; + if (cmdInput.isActive()) + { + enableEntry(true); + } + else + { + enableEntry(false); + } + } + else + { + enableEntry(false); + } + } + else + { + enableEntry(false); + } + + } + + public void widgetDefaultSelected(SelectionEvent e) + { + widgetSelected(e); + } + + public void widgetSelected(SelectionEvent e) + { + Widget source = e.widget; + + if (source == _upButton) + { + handleUp(); + } + else if (source == _downButton) + { + handleDown(); + } + } + + private String[] getCommandHistory() + { + Object input = _viewer.getInput(); + if (input != null && input instanceof IRemoteCommandShell) + { + IRemoteCommandShell command = (IRemoteCommandShell) input; + return command.getHistory(); + } + return null; + } + + private void handleUp() + { + String[] history = getCommandHistory(); + _commandHistoryOffset--; + if (_commandHistoryOffset > 0) + { + if (history.length > _commandHistoryOffset) + { + String lastCommand = history[_commandHistoryOffset]; + _inputEntry.getTextWidget().setText(lastCommand); + _inputEntry.getTextWidget().setCaretOffset(_inputEntry.getTextWidget().getCharCount()); + } + } + else + { + _commandHistoryOffset = 0; + + if (history.length > 0) + { + _inputEntry.getTextWidget().setText(history[0]); + _inputEntry.getTextWidget().setCaretOffset(_inputEntry.getTextWidget().getCharCount()); + } + } + } + + private void handleDown() + { + _commandHistoryOffset++; + if (_commandHistoryOffset >= getCommandHistory().length) + { + _commandHistoryOffset = getCommandHistory().length; + _inputEntry.getTextWidget().setText(""); + } + else + { + String[] history = getCommandHistory(); + if (history.length > 0) + { + String lastCommand = history[_commandHistoryOffset]; + _inputEntry.getTextWidget().setText(lastCommand); + _inputEntry.getTextWidget().setCaretOffset(_inputEntry.getTextWidget().getCharCount()); + } + } + } + + + /* (non-Javadoc) + * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent) + */ + public void focusGained(FocusEvent arg0) + { + IActionBars actionBars = getActionBars(); + if (actionBars != null) + { + if (arg0.widget == _viewer.getControl()) + { + actionBars.setGlobalActionHandler(ITextEditorActionConstants.COPY, _copyAction); + actionBars.setGlobalActionHandler(ITextEditorActionConstants.PASTE, _pasteAction); + actionBars.setGlobalActionHandler(ITextEditorActionConstants.SELECT_ALL, _selectAllAction); + actionBars.updateActionBars(); + + } + else if (arg0.widget == _inputEntry.getControl()) + { + _inputEntry.setActionHandlers(); + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent) + */ + public void focusLost(FocusEvent arg0) + { + + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/CommandsViewWorkbook.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/CommandsViewWorkbook.java new file mode 100644 index 00000000000..784a7ad0bb9 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/CommandsViewWorkbook.java @@ -0,0 +1,249 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.ui.view.ISystemViewElementAdapter; +import org.eclipse.rse.ui.view.SystemTableView; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.custom.CTabItem; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; + + + +/** + * This is the desktop view wrapper of the System View viewer. + * ViewPart is from com.ibm.itp.ui.support.parts + */ +public class CommandsViewWorkbook extends Composite +{ + + + private CTabFolder _folder; + private SystemCommandsViewPart _viewPart; + + public CommandsViewWorkbook(Composite parent, SystemCommandsViewPart viewPart) + { + super(parent, SWT.NONE); + + _folder = new CTabFolder(this, SWT.NONE); + _folder.setLayout(new TabFolderLayout()); + _folder.setLayoutData(new GridData(GridData.FILL_BOTH)); + setLayout(new FillLayout()); + _viewPart = viewPart; + } + + public void dispose() + { + if (!_folder.isDisposed()) + { + for (int i = 0; i < _folder.getItemCount(); i++) + { + CTabItem item = _folder.getItem(i); + if (!item.isDisposed()) + { + CommandsViewPage page = (CommandsViewPage) item.getData(); + page.dispose(); + } + } + _folder.dispose(); + } + super.dispose(); + } + + public CTabFolder getFolder() + { + return _folder; + } + + public void remove(Object root) + { + for (int i = 0; i < _folder.getItemCount(); i++) + { + CTabItem item = _folder.getItem(i); + if (!item.isDisposed()) + { + CommandsViewPage page = (CommandsViewPage) item.getData(); + + if (page != null && root == page.getInput()) + { + item.dispose(); + page.dispose(); + + page = null; + item = null; + + _folder.redraw(); + + return; + } + } + } + } + + public CTabItem getSelectedTab() + { + if (_folder.getItemCount() > 0) + { + int index = _folder.getSelectionIndex(); + CTabItem item = _folder.getItem(index); + return item; + } + + return null; + } + + public CommandsViewPage getCurrentTabItem() + { + if (_folder.getItemCount() > 0) + { + int index = _folder.getSelectionIndex(); + CTabItem item = _folder.getItem(index); + return (CommandsViewPage) item.getData(); + } + return null; + } + + public void showCurrentPage() + { + _folder.setFocus(); + } + + public Object getInput() + { + CommandsViewPage page = getCurrentTabItem(); + if (page != null) + { + page.setFocus(); + return page.getInput(); + } + + return null; + } + + public SystemCommandsView getViewer() + { + if (getCurrentTabItem() != null) + { + return getCurrentTabItem().getViewer(); + } + return null; + } + + public void updateOutput(IRemoteCommandShell root, boolean createTab) + { + if (!_folder.isDisposed()) + { + for (int i = 0; i < _folder.getItemCount(); i++) + { + CTabItem item = _folder.getItem(i); + CommandsViewPage page = (CommandsViewPage) item.getData(); + if (page != null && root == page.getInput()) + { + if (!root.isActive()) + { + setTabTitle((IAdaptable) root, item); + page.updateTitle((IAdaptable) root); + page.setEnabled(false); + } + + page.updateOutput(); + + if (_folder.getSelectionIndex() != i) + { + _folder.setSelection(item); + } + updateActionStates(); + //page.setFocus(); + return; + } + } + + if (/*root.isActive() &&*/ createTab) + { + // never shown this, so add it + createTabItem((IAdaptable) root); + } + } + } + + private void createTabItem(IAdaptable root) + { + CommandsViewPage commandsViewPage = new CommandsViewPage(_viewPart); + + CTabItem titem = new CTabItem(_folder, SWT.NULL); + setTabTitle(root, titem); + + titem.setData(commandsViewPage); + titem.setControl(commandsViewPage.createTabFolderPage(_folder, _viewPart.getEditorActionHandler())); + _folder.setSelection(titem ); + + commandsViewPage.setInput(root); + + SystemTableView viewer = commandsViewPage.getViewer(); + _viewPart.getSite().setSelectionProvider(viewer); + _viewPart.getSite().registerContextMenu(viewer.getContextMenuManager(), viewer); + //commandsViewPage.getViewer().addSelectionChangedListener((SystemCommandsViewPart)_viewPart); + + commandsViewPage.setFocus(); + } + + private void setTabTitle(IAdaptable root, CTabItem titem) + { + ISystemViewElementAdapter va = (ISystemViewElementAdapter) root.getAdapter(ISystemViewElementAdapter.class); + if (va != null) + { + titem.setText(va.getName(root)); + titem.setImage(va.getImageDescriptor(root).createImage()); + } + } + + public void setInput(IAdaptable root) + { + for (int i = 0; i < _folder.getItemCount(); i++) + { + CTabItem item = _folder.getItem(i); + CommandsViewPage page = (CommandsViewPage) item.getData(); + if (root == page.getInput()) + { + _folder.setSelection(i); + page.getViewer().updateChildren(); + return; + } + } + } + + public void updateActionStates() + { + for (int i = 0; i < _folder.getItemCount(); i++) + { + CTabItem item = _folder.getItem(i); + if (!item.isDisposed()) + { + CommandsViewPage page = (CommandsViewPage) item.getData(); + if (page != null) + { + page.updateActionStates(); + } + } + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/EncodingForm.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/EncodingForm.java new file mode 100644 index 00000000000..673e50a1ffd --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/EncodingForm.java @@ -0,0 +1,174 @@ +/******************************************************************************** + * Copyright (c) 2005, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; + +import java.io.UnsupportedEncodingException; +import java.util.Collections; +import java.util.List; + +import org.eclipse.rse.shells.ui.ShellResources; +import org.eclipse.rse.ui.SystemBaseForm; +import org.eclipse.rse.ui.messages.ISystemMessageLine; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + + + +public class EncodingForm extends SystemBaseForm +{ + // State for encoding group + private String _encoding; + private String _defaultEncoding; + + private Button _defaultEncodingButton; + private Button _otherEncodingButton; + private Combo _encodingCombo; + + + public EncodingForm(Shell shell, ISystemMessageLine line) + { + super(shell, line); + _defaultEncoding = ShellResources.RESID_SHELL_PROPERTYPAGE_DEFAULT_ENCODING; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.ui.SystemBaseForm#createContents(org.eclipse.swt.widgets.Composite) + */ + public Control createContents(Composite group) + { + + SelectionAdapter buttonListener = new SelectionAdapter() + { + public void widgetSelected(SelectionEvent e) { + updateEncodingState(_defaultEncodingButton.getSelection()); + updateValidState(); + } + }; + + _defaultEncodingButton = new Button(group, SWT.RADIO); + _defaultEncodingButton.setText(ShellResources.RESID_SHELL_PROPERTYPAGE_HOST_ENCODING); + GridData data = new GridData(); + Font font = group.getFont(); + + data.horizontalSpan = 2; + _defaultEncodingButton.setLayoutData(data); + _defaultEncodingButton.addSelectionListener(buttonListener); + _defaultEncodingButton.setFont(font); + + _otherEncodingButton = new Button(group, SWT.RADIO); + _otherEncodingButton.setText(ShellResources.RESID_SHELL_PROPERTYPAGE_OTHER_ENCODING); + _otherEncodingButton.addSelectionListener(buttonListener); + _otherEncodingButton.setFont(font); + + _encodingCombo = new Combo(group, SWT.NONE); + data = new GridData(); + _encodingCombo.setFont(font); + _encodingCombo.setLayoutData(data); + _encodingCombo.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + updateValidState(); + } + }); + + return _encodingCombo; + } + + public void initialize(List defaults, String encoding) + { + _encoding = encoding; + + boolean isDefault = _encoding == null || _encoding.length() == 0 || encoding.equals(_defaultEncoding); + + if (!isDefault && !defaults.contains(_encoding)) + { + defaults.add(_encoding); + } + Collections.sort(defaults); + for (int i = 0; i < defaults.size(); ++i) { + _encodingCombo.add((String) defaults.get(i)); + } + + _encodingCombo.setText(isDefault ? _defaultEncoding : _encoding); + updateEncodingState(isDefault); + } + + public Control getDefaultControl() + { + return _encodingCombo; + } + + public boolean usingDefault() + { + return _defaultEncodingButton.getSelection(); + } + + public String getEncoding() + { + if (usingDefault()) + { + return ""; + } + return _encodingCombo.getText(); + } + + protected void updateValidState() + { + if (!isEncodingValid()) + { + getMessageLine().setErrorMessage(ShellResources.RESID_UNSUPPORTED_ENCODING); + } + else + { + getMessageLine().clearErrorMessage(); + } + } + + private boolean isEncodingValid() + { + return _defaultEncodingButton.getSelection() + || isValidEncoding(_encodingCombo.getText()); + } + + private boolean isValidEncoding(String enc) + { + try { + new String(new byte[0], enc); + return true; + } catch (UnsupportedEncodingException e) { + return false; + } + } + + private void updateEncodingState(boolean useDefault) + { + _defaultEncodingButton.setSelection(useDefault); + _otherEncodingButton.setSelection(!useDefault); + _encodingCombo.setEnabled(!useDefault); + updateValidState(); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/ISystemCommandTextModifyListener.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/ISystemCommandTextModifyListener.java new file mode 100644 index 00000000000..7e3f152fe6f --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/ISystemCommandTextModifyListener.java @@ -0,0 +1,35 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; + +import org.eclipse.rse.services.clientserver.messages.SystemMessage; + +/** + * Interface that is to be implemented by anyone interested in + * listening to modify events on the command widget. + */ +public interface ISystemCommandTextModifyListener +{ + + /** + * Callback from SystemCommandTextField when the user modifies the command. + * @param cmdText - current contents of the field + * @param errorMessage - potential error detected by the default validator + */ + public void commandModified(String cmdText, SystemMessage errorMessage); + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/ShellServiceSubSystemFactoryAdapter.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/ShellServiceSubSystemFactoryAdapter.java new file mode 100644 index 00000000000..f9455b7ac02 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/ShellServiceSubSystemFactoryAdapter.java @@ -0,0 +1,138 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.core.subsystems.ISubSystemConfiguration; +import org.eclipse.rse.shells.ui.RemoteCommandHelpers; +import org.eclipse.rse.shells.ui.actions.SystemCommandAction; +import org.eclipse.rse.shells.ui.actions.SystemExportShellHistoryAction; +import org.eclipse.rse.shells.ui.actions.SystemExportShellOutputAction; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.ui.ISystemIconConstants; +import org.eclipse.rse.ui.view.SubsystemFactoryAdapter; +import org.eclipse.swt.widgets.Shell; + + +public class ShellServiceSubSystemFactoryAdapter extends SubsystemFactoryAdapter +{ + protected IAction _exportShellHistoryAction; + protected IAction _exportShellOutputAction; + protected SystemCommandAction _commandAction; + protected ImageDescriptor _activeShellImageDescriptor; + protected ImageDescriptor _inactiveShellImageDescriptor; + + public IAction[] getSubSystemActions(ISubSystemConfiguration factory, ISubSystem selectedSubSystem, Shell shell) + { + List allActions = new ArrayList(); + IAction[] baseActions = super.getSubSystemActions(factory, selectedSubSystem, shell); + for (int i = 0; i < baseActions.length; i++) + { + allActions.add(baseActions[i]); + } + + //launching shells and finding files + if (selectedSubSystem instanceof IRemoteFileSubSystem) + { + IRemoteFileSubSystem fs = (IRemoteFileSubSystem) selectedSubSystem; + IRemoteCmdSubSystem cmdSubSystem = RemoteCommandHelpers.getCmdSubSystem(fs.getHost()); + if (cmdSubSystem != null) + { + allActions.add(getCommandShellAction(cmdSubSystem, shell)); + } + } + else if (selectedSubSystem instanceof IRemoteCmdSubSystem) + { + allActions.add(getCommandShellAction((IRemoteCmdSubSystem)selectedSubSystem, shell)); + } + + return (IAction[])allActions.toArray(new IAction[allActions.size()]); + } + + + + public IAction getCommandShellAction(IRemoteCmdSubSystem selectedSubSystem, Shell shell) + { + if (_commandAction == null) + { + _commandAction = new SystemCommandAction(shell, true, selectedSubSystem); + } + else + { + _commandAction.setSubSystem(selectedSubSystem); + } + return _commandAction; + } + + /** + * Return the command shell history export action for the subsystem. If there is none, return null + */ + public IAction getCommandShellHistoryExportAction(Shell shell) + { + if (_exportShellHistoryAction == null) + { + _exportShellHistoryAction = new SystemExportShellHistoryAction(shell); + } + return _exportShellHistoryAction; + } + + /** + * Return the command shell output export action for the subsystem. If there is none, return null + */ + public IAction getCommandShellOutputExportAction(Shell shell) + { + if (_exportShellOutputAction == null) + { + _exportShellOutputAction = new SystemExportShellOutputAction(shell); + } + return _exportShellOutputAction; + } + + + /** + * Return the active command shell icon for this subsystem + */ + public ImageDescriptor getActiveCommandShellImageDescriptor() + { + if (_activeShellImageDescriptor == null) + { + _activeShellImageDescriptor = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_SHELLLIVE_ID); + + } + return _activeShellImageDescriptor; + } + + /** + * Return the inactive command shell icon for this subsystem + */ + public ImageDescriptor getInactiveCommandShellImageDescriptor() + { + if (_inactiveShellImageDescriptor == null) + { + _inactiveShellImageDescriptor = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_SHELL_ID); + } + return _inactiveShellImageDescriptor; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/ShellServiceSubsystemFactoryAdapterFactory.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/ShellServiceSubsystemFactoryAdapterFactory.java new file mode 100644 index 00000000000..1f4edbaf657 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/ShellServiceSubsystemFactoryAdapterFactory.java @@ -0,0 +1,60 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; + +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.core.runtime.IAdapterManager; +import org.eclipse.rse.core.subsystems.util.ISubsystemConfigurationAdapter; +import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.IShellServiceSubSystemConfiguration; +import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.ShellServiceSubSystemConfiguration; + + +public class ShellServiceSubsystemFactoryAdapterFactory implements IAdapterFactory +{ + + private ISubsystemConfigurationAdapter ssFactoryAdapter = new ShellServiceSubSystemFactoryAdapter(); + + /** + * @see IAdapterFactory#getAdapterList() + */ + public Class[] getAdapterList() + { + return new Class[] {ISubsystemConfigurationAdapter.class}; + } + /** + * Called by our plugin's startup method to register our adaptable object types + * with the platform. We prefer to do it here to isolate/encapsulate all factory + * logic in this one place. + */ + public void registerWithManager(IAdapterManager manager) + { + manager.registerAdapters(this, IShellServiceSubSystemConfiguration.class); + } + /** + * @see IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class) + */ + public Object getAdapter(Object adaptableObject, Class adapterType) + { + Object adapter = null; + if (adaptableObject instanceof ShellServiceSubSystemConfiguration) + adapter = ssFactoryAdapter; + + return adapter; + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemBuildErrorView.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemBuildErrorView.java new file mode 100644 index 00000000000..664938dba0c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemBuildErrorView.java @@ -0,0 +1,177 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.rse.model.ISystemResourceChangeEvent; +import org.eclipse.rse.model.ISystemResourceChangeEvents; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteError; +import org.eclipse.rse.ui.messages.ISystemMessageLine; +import org.eclipse.rse.ui.view.SystemTableView; +import org.eclipse.rse.ui.view.SystemTableViewProvider; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Item; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.ui.views.properties.IPropertyDescriptor; + + +public class SystemBuildErrorView extends SystemTableView +{ + + private class ErrorViewerFilter extends ViewerFilter + { + public boolean select(Viewer viewer, Object obj1, Object obj2) + { + if (obj2 instanceof IRemoteError) + { + return true; + } + return false; + } + } + + + private Color _errColor; + private Color _outColor; + private Color _infColor; + private Color _warColor; + private Color _prmColor; + + + + public SystemBuildErrorView(Table table, ISystemMessageLine msgLine) + { + super(table, msgLine); + + Display display = getControl().getDisplay(); + + _errColor = new Color(display, 255, 0, 0); + _outColor = new Color(display, 50, 50, 50); + _infColor = new Color(display, 0, 0, 255); + _warColor = new Color(display, 200, 150, 0); + _prmColor = new Color(display, 0, 50, 0); + + _provider = new SystemBuildErrorViewProvider(); + setContentProvider(_provider); + addFilter(new ErrorViewerFilter()); + } + + public void refresh() + { + super.refresh(); + + Table table = getTable(); + if (table != null && table.getItemCount() > 0) + { + TableItem lastItem = table.getItem(table.getItemCount() - 1); + table.showItem(lastItem); + } + } + + public IPropertyDescriptor[] getVisibleDescriptors(Object object) + { + SystemViewRemoteErrorAdapter adpt = new SystemViewRemoteErrorAdapter(); + return adpt.getUniquePropertyDescriptors(); + } + + public IPropertyDescriptor getNameDescriptor(Object object) + { + SystemViewRemoteErrorAdapter adpt = new SystemViewRemoteErrorAdapter(); + return adpt.getPropertyDescriptors()[0]; + } + + public void setOffset(int offset) + { + ((SystemBuildErrorViewProvider)_provider).setOffset(offset); + } + + public synchronized void updateChildren() + { + computeLayout(); + internalRefresh(getInput()); + + } + + + public void clearAllItems() + { + Object input = getInput(); + SystemTableViewProvider provider = (SystemTableViewProvider) getContentProvider(); + Object[] children = provider.getChildren(input); + + ((SystemBuildErrorViewProvider)_provider).moveOffsetToEnd(); + clearFirstItems(children, children.length - 1); + provider.flushCache(); + + } + + private void clearFirstItems(Object[] children, int items) + { + Table table = getTable(); + + table.setRedraw(false); + synchronized (table) + { + int count = table.getItemCount(); + table.remove(0, items); + + } + table.setRedraw(true); + } + + protected Item newItem(Widget parent, int flags, int ix) + { + if (parent instanceof Table) + { + return new TableItem((Table) parent, flags); + } + + return null; + } + + public void systemResourceChanged(ISystemResourceChangeEvent event) + { + Object child = event.getSource(); + + if (event.getType() == ISystemResourceChangeEvents.EVENT_REFRESH) + { + if (child == getInput()) + { + SystemTableViewProvider provider = (SystemTableViewProvider) getContentProvider(); + if (provider != null) + { + provider.flushCache(); + + updateChildren(); + return; + } + } + } + + //super.systemResourceChanged(event); + } + + protected Object getParentForContent(Object element) + { + return getAdapter(element).getParent(element); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemBuildErrorViewPart.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemBuildErrorViewPart.java new file mode 100644 index 00000000000..361ba8fafdc --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemBuildErrorViewPart.java @@ -0,0 +1,487 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IStatusLineManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.subsystems.IRemoteLineReference; +import org.eclipse.rse.model.ISystemRegistry; +import org.eclipse.rse.model.ISystemResourceChangeEvent; +import org.eclipse.rse.model.ISystemResourceChangeEvents; +import org.eclipse.rse.model.ISystemResourceChangeListener; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteOutput; +import org.eclipse.rse.ui.ISystemIconConstants; +import org.eclipse.rse.ui.ISystemMessages; +import org.eclipse.rse.ui.SystemResources; +import org.eclipse.rse.ui.SystemWidgetHelpers; +import org.eclipse.rse.ui.messages.ISystemMessageLine; +import org.eclipse.rse.ui.view.ISystemViewElementAdapter; +import org.eclipse.rse.ui.view.SystemTableViewProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.ISelectionService; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.part.ViewPart; + + + + + +/** + * This is the wrapper class to SystemBuildErrorView. + */ +public class SystemBuildErrorViewPart extends ViewPart implements ISelectionListener, SelectionListener, ISystemResourceChangeListener, ISystemMessageLine +{ + + + class BrowseAction extends Action + { + public BrowseAction(String label, ImageDescriptor des) + { + super(label, des); + + setToolTipText(label); + } + + public void checkEnabledState() + { + if (getViewer().getInput() != null) + { + setEnabled(true); + } + else + { + setEnabled(false); + } + } + + public void run() + { + } + } + + public class ClearAction extends BrowseAction + { + public ClearAction() + { + super(SystemResources.ACTION_CLEAR_LABEL, + // DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_CLEAR)); + SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_CLEAR_ID)); + + ImageDescriptor des = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_CLEAR_ID); + + /* + setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_LCL_CLEAR)); + setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_CLEAR)); + setImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_CLEAR)); + */ + setImageDescriptor(des); + + // TODO DKM - get help for this! + //PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.CLEAR_CONSOLE_ACTION); + } + + public void checkEnabledState() + { + Object input = getViewer().getInput(); + if (input != null) + { + if (input instanceof IRemoteCommandShell) + { + setEnabled(((IRemoteCommandShell) input).isActive()); + return; + } + } + + setEnabled(false); + } + + public void run() + { + clear(); + } + + // clear contents of the current command viewer + private void clear() + { + getViewer().clearAllItems(); + } + } + + + // constants + public static final String ID = "com.ibm.etools.systems.core.ui.view.buildErrorView"; + // matches id in plugin.xml, view tag + + private SystemBuildErrorView _viewer; + private ClearAction _clearAction; + private boolean _enableUpdates = true; + + // for ISystemMessageLine + private String _message, _errorMessage; + private SystemMessage sysErrorMessage; + private IStatusLineManager _statusLine = null; + + public void setFocus() + { + _viewer.getControl().setFocus(); + } + + public SystemBuildErrorView getViewer() + { + return _viewer; + } + + public Shell getShell() + { + return _viewer.getShell(); + } + + public void fillLocalToolBar() + { + boolean firstCall = false; + if (_clearAction == null) + { + firstCall = true; + _clearAction = new ClearAction(); + } + + IActionBars actionBars = getViewSite().getActionBars(); + IToolBarManager toolBarManager = actionBars.getToolBarManager(); + addToolBarItems(toolBarManager); + + if (firstCall) + { + IMenuManager menuManager = actionBars.getMenuManager(); + _statusLine = actionBars.getStatusLineManager(); + //addMenuItems(menuManager); + } + } + + private void addToolBarItems(IToolBarManager toolBarManager) + { + toolBarManager.removeAll(); + + toolBarManager.add(_clearAction); + } + + public void createPartControl(Composite parent) + { + // create table portion + Table table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.HIDE_SELECTION); + _viewer = new SystemBuildErrorView(table, this); + table.setLinesVisible(true); + + ISelectionService selectionService = getSite().getWorkbenchWindow().getSelectionService(); + selectionService.addSelectionListener(this); + + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + + registry.addSystemResourceChangeListener(this); + + _viewer.addDoubleClickListener(new IDoubleClickListener() + { + public void doubleClick(DoubleClickEvent event) + { + handleDoubleClick(event); + } + }); + SystemWidgetHelpers.setHelp(_viewer.getControl(), SystemPlugin.HELPPREFIX + "uerr0000"); + fillLocalToolBar(); + } + + private void handleDoubleClick(DoubleClickEvent event) + { + IStructuredSelection s = (IStructuredSelection) event.getSelection(); + Object element = s.getFirstElement(); + if (element == null) + return; + + ISystemViewElementAdapter adapter = (ISystemViewElementAdapter) ((IAdaptable) element).getAdapter(ISystemViewElementAdapter.class); + boolean alreadyHandled = false; + if (adapter != null) + { + if (!adapter.hasChildren(element)) + { + alreadyHandled = adapter.handleDoubleClick(element); + } + } + } + + public void selectionChanged(IWorkbenchPart part, ISelection sel) + { + } + + public void dispose() + { + ISelectionService selectionService = getSite().getWorkbenchWindow().getSelectionService(); + selectionService.removeSelectionListener(this); + _viewer.dispose(); + + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + registry.removeSystemResourceChangeListener(this); + super.dispose(); + } + + + + + + public void selectionChanged(SelectionChangedEvent e) + { + } + + public void resetOffset() + { + SystemBuildErrorViewProvider provider = (SystemBuildErrorViewProvider)_viewer.getContentProvider(); + int size = ((IRemoteCommandShell)_viewer.getInput()).getSize(); + provider.setOffset(size - 1); + } + + public void setInput(IAdaptable object, String cmdString) + { + setInput(object, true, cmdString); + } + + public void setInput(IAdaptable object, boolean updateHistory, String cmdString) + { + _viewer.getTable().removeAll(); + setEnableUpdates(true); + + if (object instanceof IRemoteCommandShell) + { + _viewer.setInput(object); + } + else + { + if (object instanceof IRemoteOutput) + { + IRemoteOutput output = (IRemoteOutput)object; + if (output != null) + { + _viewer.setInput(output.getParent()); + SystemBuildErrorViewProvider provider = (SystemBuildErrorViewProvider)_viewer.getContentProvider(); + provider.setOffset(output.getIndex() - 1); + } + } + else if (object instanceof IRemoteLineReference) + { + + _viewer.setInput(((IRemoteLineReference)object).getParent()); + } + + } + + SystemMessage msg = SystemPlugin.getPluginMessage(ISystemMessages.MSG_ERROR_LIST_TITLE); + msg.makeSubstitution(cmdString); + setPartName(msg.getLevelOneText()); + } + + public void updateOutput() + { + if (_viewer != null) + { + ((SystemTableViewProvider) _viewer.getContentProvider()).flushCache(); + _viewer.updateChildren(); + } + } + + + private void updateOutput(IRemoteCommandShell root) + { + if (root != null && _enableUpdates) + { + if (_viewer.getInput() != root) + { + _viewer.clearAllItems(); + _viewer.setInput(root); + } + updateOutput(); + } + } + + /* + * Lock view from updates since the compile has ended + */ + public void setEnableUpdates(boolean enable) + { + if (!enable) + { + // do one last refresh to make sure + // last compile got shown + updateOutput(); + } + _enableUpdates= enable; + } + + public void systemResourceChanged(ISystemResourceChangeEvent event) + { + if (event.getType() == ISystemResourceChangeEvents.EVENT_COMMAND_SHELL_FINISHED) + { + Object source = event.getSource(); + if (source instanceof IRemoteCmdSubSystem) + { + Shell shell = SystemPlugin.getTheSystemRegistry().getShell(); + //shell.getDisplay().asyncExec(new CommandSubSystemDisconnectedRunnable((RemoteCmdSubSystem) source)); + } + else + if (source instanceof IRemoteCommandShell) + { + // find out if we're listening to this + updateOutput((IRemoteCommandShell) source); + } + } + else + if (event.getType() == ISystemResourceChangeEvents.EVENT_REFRESH) + { + + Object parent = event.getParent(); + if (parent instanceof IRemoteCommandShell) + { + updateOutput((IRemoteCommandShell) parent); + } + } + } + + public void widgetDefaultSelected(SelectionEvent e) + { + widgetSelected(e); + } + + public void widgetSelected(SelectionEvent e) + { + + + } + + + +// ------------------------------- + // ISystemMessageLine interface... + // ------------------------------- + /** + * Clears the currently displayed error message and redisplayes + * the message which was active before the error message was set. + */ + public void clearErrorMessage() + { + _errorMessage = null; + sysErrorMessage = null; + if (_statusLine != null) + _statusLine.setErrorMessage(_errorMessage); + } + /** + * Clears the currently displayed message. + */ + public void clearMessage() + { + _message = null; + if (_statusLine != null) + _statusLine.setMessage(_message); + } + /** + * Get the currently displayed error text. + * @return The error message. If no error message is displayed null is returned. + */ + public String getErrorMessage() + { + return _errorMessage; + } + /** + * Get the currently displayed message. + * @return The message. If no message is displayed null is returned. + */ + public String getMessage() + { + return _message; + } + /** + * Display the given error message. A currently displayed message + * is saved and will be redisplayed when the error message is cleared. + */ + public void setErrorMessage(String message) + { + this._errorMessage = message; + if (_statusLine != null) + _statusLine.setErrorMessage(message); + } + /** + * Get the currently displayed error text. + * @return The error message. If no error message is displayed null is returned. + */ + public SystemMessage getSystemErrorMessage() + { + return sysErrorMessage; + } + + /** + * Display the given error message. A currently displayed message + * is saved and will be redisplayed when the error message is cleared. + */ + public void setErrorMessage(SystemMessage message) + { + sysErrorMessage = message; + setErrorMessage(message.getLevelOneText()); + } + /** + * Display the given error message. A currently displayed message + * is saved and will be redisplayed when the error message is cleared. + */ + public void setErrorMessage(Throwable exc) + { + setErrorMessage(exc.getMessage()); + } + + /** + * Set the message text. If the message line currently displays an error, + * the message is stored and will be shown after a call to clearErrorMessage + */ + public void setMessage(String message) + { + this._message = message; + if (_statusLine != null) + _statusLine.setMessage(message); + } + /** + *If the message line currently displays an error, + * the message is stored and will be shown after a call to clearErrorMessage + */ + public void setMessage(SystemMessage message) + { + setMessage(message.getLevelOneText()); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemBuildErrorViewProvider.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemBuildErrorViewProvider.java new file mode 100644 index 00000000000..86ae7778a1b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemBuildErrorViewProvider.java @@ -0,0 +1,124 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; + +import java.util.ArrayList; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.rse.core.subsystems.IRemoteLineReference; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteError; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteOutput; +import org.eclipse.rse.ui.view.ISystemViewElementAdapter; +import org.eclipse.rse.ui.view.SystemTableViewProvider; + + + +/** + * This is the content and label provider for the SystemTableView. + * This class is used both to populate the SystemTableView but also + * to resolve the icon and labels for the cells in the table. + * + */ +public class SystemBuildErrorViewProvider extends SystemTableViewProvider +{ + + private int _offset = 0; + private Object[] _unfilteredResults = null; + + public SystemBuildErrorViewProvider() + { + super(); + } + + + public void inputChanged(Viewer visualPart, Object oldInput, Object newInput) + { + if (newInput instanceof IRemoteCommandShell) + { + IRemoteCommandShell cmd = (IRemoteCommandShell)newInput; + Object[] output = cmd.listOutput(); + if (_offset == 0) + setOffset(output.length); + } + else if (newInput instanceof IRemoteOutput) + { + IRemoteOutput output = (IRemoteOutput)newInput; + IRemoteCommandShell cmd = (IRemoteCommandShell)output.getParent(); + setOffset(output.getIndex()); + } + else if (newInput instanceof IRemoteLineReference) + { + IRemoteLineReference output = (IRemoteLineReference)newInput; + IRemoteCommandShell cmd = (IRemoteCommandShell)output.getParent(); + //setOffset(output.getIndex()); + } + } + + + public void setOffset(int offset) + { + _offset = offset; + } + + public void moveOffsetToEnd() + { + if (_unfilteredResults != null) + { + _offset = _unfilteredResults.length; + } + } + + public Object[] getElements(Object object) + { + Object[] results = null; + if (object == _lastObject && _lastResults != null) + { + return _lastResults; + } + else + if (object instanceof IAdaptable) + { + ISystemViewElementAdapter adapter = getAdapterFor(object); + if (adapter != null) + { + results = adapter.getChildren(object); + + ArrayList filterredResults = new ArrayList(); + for (int i = _offset+ 1; i 0); // defect 46369 + SystemMessage errorMessage = validateCommand(); + fireModifyEvents(cmdText, errorMessage); + } + }); + getTextWidget().addKeyListener(new KeyAdapter() + { + public void keyReleased(KeyEvent e) + { + + if (!e.doit) + return; + + if (e.stateMask == SWT.CTRL) + { + // DKM - using this now since SWT isn't providing statemask with verify key events + switch (e.character) + { + case ' ' : + setInCodeAssist(true); + doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); + //e.doit = false; + break; + // CTRL-Z + case (int) 'z' - (int) 'a' + 1 : + doOperation(ITextOperationTarget.UNDO); + //e.doit = false; + break; + } + } + + } + }); + prependVerifyKeyListener(new VerifyKeyListener() + { + public void verifyKey(VerifyEvent event) + { + handleVerifyKeyPressed(event); + } + }); + initializeActions(); + } + public String getCommandText() + { + return getDocument().get().trim(); + } + + public String getSelectedText() + { + return getTextWidget().getSelectionText(); + } + /** + * Add a modify listener + */ + public void addModifyListener(ISystemCommandTextModifyListener listener) + { + listeners.add(listener); + } + /** + * Remove a modify listener + */ + public void removeModifyListener(ISystemCommandTextModifyListener listener) + { + listeners.remove(listener); + } + /** + * Fire an event to listeners + */ + private void fireModifyEvents(String cmdText, SystemMessage errorMessage) + { + for (int idx = 0; idx < listeners.size(); idx++) + ((ISystemCommandTextModifyListener) listeners.elementAt(idx)).commandModified(cmdText, errorMessage); + } + /** + * Turn on or off event ignoring flag + */ + public void setIgnoreChanges(boolean ignore) + { + ignoreChanges = ignore; + } + /** + * Validate command input + */ + public SystemMessage validateCommand() + { + if (cmdValidator != null) + return cmdValidator.validate(getCommandText()); + else + return null; + } + /** + * Set the command validator to validate contents per keystroke + */ + public void setCommandValidator(ISystemValidator cmdValidator) + { + this.cmdValidator = cmdValidator; + } + private void fillContextMenu(IMenuManager menu) + { + menu.add(new GroupMarker(ITextEditorActionConstants.GROUP_UNDO)); + menu.appendToGroup( + ITextEditorActionConstants.GROUP_UNDO, + (IAction) fGlobalActions.get(ITextEditorActionConstants.UNDO)); + menu.add(new Separator(ITextEditorActionConstants.GROUP_EDIT)); + menu.appendToGroup( + ITextEditorActionConstants.GROUP_EDIT, + (IAction) fGlobalActions.get(ITextEditorActionConstants.CUT)); + menu.appendToGroup( + ITextEditorActionConstants.GROUP_EDIT, + (IAction) fGlobalActions.get(ITextEditorActionConstants.COPY)); + menu.appendToGroup( + ITextEditorActionConstants.GROUP_EDIT, + (IAction) fGlobalActions.get(ITextEditorActionConstants.PASTE)); + menu.appendToGroup( + ITextEditorActionConstants.GROUP_EDIT, + (IAction) fGlobalActions.get(ITextEditorActionConstants.SELECT_ALL)); + menu.add(new Separator("group.generate")); + menu.appendToGroup("group.generate", (IAction) fGlobalActions.get("ContentAssistProposal")); //$NON-NLS-1$ + } + private IActionBars getActionBars() + { + if (_site != null) + { + IActionBars actionBars = _site.getActionBars(); + return actionBars; + } + return null; + } + public void setViewSite(IViewSite site) + { + _site = site; + } + private void initializeActions() + { + _undoAction = new TextViewerAction(this, UNDO); + _undoAction.setText(SystemResources.ACTION_UNDO_LABEL); + fGlobalActions.put(ITextEditorActionConstants.UNDO, _undoAction); + _undoAction.setEnabled(false); // defect 46369 + _cutAction = new TextViewerAction(this, CUT); + _cutAction.setText(SystemResources.ACTION_CUT_LABEL); + fGlobalActions.put(ITextEditorActionConstants.CUT, _cutAction); + _cutAction.setEnabled(false); // defect 46369 + _copyAction = new TextViewerAction(this, COPY); + _copyAction.setText(SystemResources.ACTION_COPY_LABEL); + fGlobalActions.put(ITextEditorActionConstants.COPY, _copyAction); + _copyAction.setEnabled(false); // defect 46369 + _pasteAction = new TextViewerAction(this, PASTE); + _pasteAction.setText(SystemResources.ACTION_PASTE_LABEL); + fGlobalActions.put(ITextEditorActionConstants.PASTE, _pasteAction); + _pasteAction.setEnabled(false); // defect 46369 + if (_pasteAction instanceof IUpdate) + ((IUpdate) _pasteAction).update(); + _selectAllAction = new TextViewerAction(this, SELECT_ALL); + _selectAllAction.setText(SystemResources.ACTION_SELECT_ALL_LABEL); + fGlobalActions.put(ITextEditorActionConstants.SELECT_ALL, _selectAllAction); + _selectAllAction.setEnabled(false); // defect 46369 + _caAction = new TextViewerAction(this, CONTENTASSIST_PROPOSALS); + _caAction.setText(contentAssistText); + _caAction.setEnabled(true); + fGlobalActions.put("ContentAssistProposal", _caAction); //$NON-NLS-1$ + + + setActionHandlers(); + + fSelectionActions.add(ITextEditorActionConstants.CUT); + fSelectionActions.add(ITextEditorActionConstants.COPY); + fSelectionActions.add(ITextEditorActionConstants.PASTE); + // create context menu + MenuManager manager = new MenuManager(); + manager.setRemoveAllWhenShown(true); + manager.addMenuListener(new IMenuListener() + { + public void menuAboutToShow(IMenuManager mgr) + { + fillContextMenu(mgr); + if (!menuListenerAdded) + { + if (mgr instanceof MenuManager) + { + Menu m = ((MenuManager) mgr).getMenu(); + if (m != null) + { + menuListenerAdded = true; + SystemViewMenuListener ml = new SystemViewMenuListener(); + //if (messageLine != null) + // ml.setShowToolTipText(true, messageLine); + m.addMenuListener(ml); + } + } + } + } + }); + StyledText text = this.getTextWidget(); + Menu menu = manager.createContextMenu(text); + text.setMenu(menu); + } + + public void setActionHandlers() + { + IActionBars actionBars = getActionBars(); + if (actionBars != null) + { + actionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, _undoAction); + actionBars.setGlobalActionHandler(ITextEditorActionConstants.CUT, _cutAction); + actionBars.setGlobalActionHandler(ITextEditorActionConstants.COPY, _copyAction); + actionBars.setGlobalActionHandler(ITextEditorActionConstants.PASTE, _pasteAction); + actionBars.setGlobalActionHandler(ITextEditorActionConstants.SELECT_ALL, _selectAllAction); + actionBars.updateActionBars(); + } + } + + protected void updateSelectionDependentActions() + { + Iterator iterator = fSelectionActions.iterator(); + while (iterator.hasNext()) + updateAction((String) iterator.next()); + } + protected void updateUndoAction() + { + Object obj = fGlobalActions.get(ITextEditorActionConstants.UNDO); + if (obj instanceof IAction) + { + IAction action = (IAction) obj; + if (action instanceof IUpdate) + ((IUpdate) action).update(); + } + } + protected void updateAction(String actionId) + { + Object obj = fGlobalActions.get(actionId); + if (obj instanceof IAction) + { + IAction action = (IAction) obj; + if (action instanceof IUpdate) + ((IUpdate) action).update(); + } + } + private void handleVerifyKeyPressed(VerifyEvent event) + { + if (!event.doit) + return; + + // DKM - moved to key press handler since for some reason SWT doesn't provide statemask anymore + /* + if (event.character == 0 && (event.keyCode & SWT.KEYCODE_BIT) == 0) + { + return; + } + switch (event.character) + { + case ' ' : + doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); + event.doit = false; + break; + // CTRL-Z + case (int) 'z' - (int) 'a' + 1 : + doOperation(ITextOperationTarget.UNDO); + event.doit = false; + break; + } + */ + } + + + public void setInCodeAssist(boolean flag) + { + isInCodeAssist = flag; + } + + public boolean requestWidgetToken(IWidgetTokenKeeper requester) + { + boolean result = super.requestWidgetToken(requester); + if (result) + { + setInCodeAssist(true); + } + return result; + } + public void releaseWidgetToken(IWidgetTokenKeeper tokenKeeper) + { + super.releaseWidgetToken(tokenKeeper); + DelayedIsInCodeAssistUntoggler untoggler = new DelayedIsInCodeAssistUntoggler(); + untoggler.start(); + } + public boolean isInCodeAssist() + { + return isInCodeAssist; + } + private class DelayedIsInCodeAssistUntoggler extends Thread + { + public void run() + { + try + { + Thread.sleep(200); + } + catch (InterruptedException e) + { + } + setInCodeAssist(false); + } + } + private static class TextViewerAction extends Action implements IUpdate + { + private int fOperationCode = -1; + private ITextOperationTarget fOperationTarget; + public TextViewerAction(ITextViewer viewer, int operationCode) + { + fOperationCode = operationCode; + fOperationTarget = viewer.getTextOperationTarget(); + update(); + } + /** + * Updates the enabled state of the action. + * Fires a property change if the enabled state changes. + * + * @see Action#firePropertyChange(String, Object, Object) + */ + public void update() + { + boolean wasEnabled = isEnabled(); + boolean isEnabled = (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode)); + setEnabled(isEnabled); + if (wasEnabled != isEnabled) + { + firePropertyChange( + ENABLED, + wasEnabled ? Boolean.TRUE : Boolean.FALSE, + isEnabled ? Boolean.TRUE : Boolean.FALSE); + } + } + /** + * @see Action#run() + */ + public void run() + { + if (fOperationCode != -1 && fOperationTarget != null) + { + fOperationTarget.doOperation(fOperationCode); + } + } + } + + public void doOperation(int operation) + { + if (operation == CONTENTASSIST_PROPOSALS) + { + isInCodeAssist = true; + } + super.doOperation(operation); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandsUI.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandsUI.java new file mode 100644 index 00000000000..88de72112a1 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandsUI.java @@ -0,0 +1,100 @@ +/******************************************************************************** + * Copyright (c) 2003, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; + +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; + + +/** + * A singleton class for dealing with remote commands + */ +public class SystemCommandsUI +{ + + + // singleton instance + private static SystemCommandsUI instance; + private static SystemCommandsViewPart _viewPart; + private static SystemBuildErrorViewPart _errorPart; + + public static final String COMMANDS_VIEW_ID = SystemCommandsViewPart.ID; + public static final String BUILD_ERROR_VIEW_ID = SystemBuildErrorViewPart.ID; + + private SystemCommandsUI() + { + super(); + } + + /** + * Get the singleton instance. + * @return the singleton object of this type + */ + public static SystemCommandsUI getInstance() + { + if (instance == null) + { + instance = new SystemCommandsUI(); + } + + return instance; + } + + public SystemBuildErrorViewPart activateBuildErrorView() + { + try + { + IWorkbenchPage page = SystemBasePlugin.getActiveWorkbenchWindow().getActivePage(); + _errorPart = (SystemBuildErrorViewPart) page.showView(SystemCommandsUI.BUILD_ERROR_VIEW_ID); + page.bringToTop(_errorPart); + } + catch (PartInitException e) + { + SystemBasePlugin.logError("Can not open build error view", e); + } + + return _errorPart; + } + + public SystemCommandsViewPart activateCommandsView() + { + try + { + IWorkbenchPage page = SystemBasePlugin.getActiveWorkbenchWindow().getActivePage(); + _viewPart = (SystemCommandsViewPart) page.showView(SystemCommandsUI.COMMANDS_VIEW_ID); + page.bringToTop(_viewPart); + } + catch (PartInitException e) + { + e.printStackTrace(); + SystemBasePlugin.logError("Can not open commands view", e); + } + + return _viewPart; + } + + public static SystemBuildErrorViewPart getBuildErrorView() + { + return _errorPart; + } + + public static SystemCommandsViewPart getCommandsView() + { + return _viewPart; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandsView.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandsView.java new file mode 100644 index 00000000000..5705891efb4 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandsView.java @@ -0,0 +1,359 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; + +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.rse.model.ISystemResourceChangeEvent; +import org.eclipse.rse.model.ISystemResourceChangeEvents; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteOutput; +import org.eclipse.rse.ui.ISystemThemeConstants; +import org.eclipse.rse.ui.messages.ISystemMessageLine; +import org.eclipse.rse.ui.view.SystemTableView; +import org.eclipse.rse.ui.view.SystemTableViewProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Item; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.themes.IThemeManager; + + +public class SystemCommandsView extends SystemTableView implements ISystemThemeConstants, IPropertyChangeListener +{ + + + public class CommandsViewFilter extends ViewerFilter + { + public boolean select(Viewer viewer, Object parent, Object element) + { + if (element instanceof IRemoteOutput) + { + + IRemoteOutput remoteOutput = (IRemoteOutput)element; + if (remoteOutput.getText().indexOf("BEGIN-END-TAG:") > -1) + { + return false; + } + + } + + return true; + } + } + + private static int MAX_BUFFER = 20000; + private Color _errColor; + private Color _outColor; + private Color _infColor; + private Color _warColor; + private Color _prmColor; + private int _maxCharWidth = 256; + + public SystemCommandsView(Table table, ISystemMessageLine msgLine) + { + super(table, msgLine); + + addFilter(new CommandsViewFilter()); + updateTheme(); + int[] colWidths = new int[1]; + colWidths[0] = 1000; + setLastColumnWidths(colWidths); + + } + + // overridden to produce custom provider + protected SystemTableViewProvider getProvider() + { + if (_provider == null) + { + _provider = new SystemCommandsViewProvider(); + } + return _provider; + } + + public void propertyChange(PropertyChangeEvent e) + { + // for now always update + updateTheme(); + } + + public void updateTheme() + { + Table table = getTable(); + if (table != null) + { + Display display = getControl().getDisplay(); + + + IThemeManager mgr = PlatformUI.getWorkbench().getThemeManager(); + Color bg = mgr.getCurrentTheme().getColorRegistry().get(REMOTE_COMMANDS_VIEW_BG_COLOR); + Color fg = mgr.getCurrentTheme().getColorRegistry().get(REMOTE_COMMANDS_VIEW_FG_COLOR); + Font fFont = mgr.getCurrentTheme().getFontRegistry().get(REMOTE_COMMANDS_VIEW_FONT); + + + table.setBackground(bg); + table.setForeground(fg); + table.setFont(fFont); + + if (_errColor == null) + { + mgr.addPropertyChangeListener(this); + } + _errColor = mgr.getCurrentTheme().getColorRegistry().get(MESSAGE_ERROR_COLOR); + _outColor = mgr.getCurrentTheme().getColorRegistry().get(REMOTE_COMMANDS_VIEW_FG_COLOR); + _infColor = mgr.getCurrentTheme().getColorRegistry().get(MESSAGE_INFORMATION_COLOR); + _warColor = mgr.getCurrentTheme().getColorRegistry().get(MESSAGE_WARNING_COLOR); + _prmColor = mgr.getCurrentTheme().getColorRegistry().get(REMOTE_COMMANDS_VIEW_PROMPT_COLOR); + + } + } + + public void refresh() + { + super.refresh(); + + Table table = getTable(); + if (table != null && table.getItemCount() > 0) + { + TableItem lastItem = table.getItem(table.getItemCount() - 1); + table.showItem(lastItem); + } + } + + public synchronized void updateChildren() + { + // updateTheme(); + + Object input = getInput(); + if (input instanceof IRemoteCommandShell) + { + SystemTableViewProvider provider = (SystemTableViewProvider) getContentProvider(); + Table table = getTable(); + + Object[] children = provider.getChildren(input); + if (children != null && children.length > 0) + { + boolean needsLayout = false; + TableItem[] tableItems = table.getItems(); + if (tableItems == null || tableItems.length == 0) + { + needsLayout = true; + } + else + { + int widest = provider.getMaxCharsInColumnZero(); + if (widest > _maxCharWidth) + { + needsLayout = true; + _maxCharWidth = widest; + } + } + synchronized (children) + { + int index = table.getItemCount(); + if (index > MAX_BUFFER) + { + table.setRedraw(false); + clearFirstItems(children, index - (MAX_BUFFER / 2)); + table.setRedraw(true); + provider.flushCache(); + internalRefresh(input); + } + else + { + + // update previous item + /* + if (index > 0 && (children.length > index - 1)) + { + Object lastObject = children[index - 1]; + + TableItem lastItem = table.getItem(index - 1); + if (lastObject != null && lastItem != null) + { + colorItem(lastItem, lastObject); + updateItem(lastItem, lastObject); + } + }*/ + + for (int i = index; i < children.length; i++) + { + Object child = children[i]; + if (child != null) + { + boolean isVisible = true; + + if (isVisible) + { + TableItem newItem = (TableItem) newItem(table, SWT.NONE, index); + + colorItem(newItem, child); + updateItem(newItem, child); + index++; + } + } + } + + if (index > 0) + { + table.setTopIndex(index - 1); + } + } + } + if (needsLayout) + { + computeLayout(true); + } + } + } + } + + private void colorItem(TableItem newItem, Object child) + { + if (child instanceof IRemoteOutput) + { + IRemoteOutput rmtOutput = (IRemoteOutput) child; + String type = rmtOutput.getType(); + if (type.equals("stderr") || type.equals("error")) + { + newItem.setForeground(_errColor); + } + else + if (type.equals("warning")) + { + newItem.setForeground(_warColor); + } + else + if (type.equals("informational")) + { + newItem.setForeground(_infColor); + } + else + if (type.equals("prompt")) + { + newItem.setForeground(_prmColor); + } + else + { + newItem.setForeground(_outColor); + } + } + } + + public void clearAllItems() + { + Object input = getInput(); + SystemTableViewProvider provider = (SystemTableViewProvider) getContentProvider(); + Object[] children = provider.getChildren(input); + clearFirstItems(children, children.length ); + } + + public void dispose() + { + IThemeManager mgr = PlatformUI.getWorkbench().getThemeManager(); + mgr.removePropertyChangeListener(this); + } + + private void clearFirstItems(Object[] children, int items) + { + Table table = getTable(); + + table.setRedraw(false); + synchronized (table) + { + if (items > 0) + { + int count = table.getItemCount(); + if (count >= items) + { + table.remove(0, items - 1); + + IRemoteCommandShell input = (IRemoteCommandShell) getInput(); + // remove items from command + for (int i = 0; i < items && i < children.length; i++) + { + Object item = children[i]; + input.removeOutput(item); + } + } + } + } + table.setRedraw(true); + } + + protected Item newItem(Widget parent, int flags, int ix) + { + if (parent instanceof Table) + { + return new TableItem((Table) parent, flags); + } + + return null; + } + + public void systemResourceChanged(ISystemResourceChangeEvent event) + { + Object child = event.getSource(); + + if (event.getType() == ISystemResourceChangeEvents.EVENT_REFRESH) + { + if (child == getInput()) + { + SystemTableViewProvider provider = (SystemTableViewProvider) getContentProvider(); + if (provider != null) + { + provider.flushCache(); + + updateChildren(); + return; + } + } + } + else if (event.getType() == ISystemResourceChangeEvents.EVENT_ICON_CHANGE) + { + try + { + Widget w = findItem(child); + if (w != null) + { + updateItem(w, child); + } + } + catch (Exception e) + { + + } + } + + + //super.systemResourceChanged(event); + } + + protected Object getParentForContent(Object element) + { + return getAdapter(element).getParent(element); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandsViewPart.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandsViewPart.java new file mode 100644 index 00000000000..06786adb303 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandsViewPart.java @@ -0,0 +1,878 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IContributionItem; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IStatusLineManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.model.ISystemRegistry; +import org.eclipse.rse.model.ISystemResourceChangeEvent; +import org.eclipse.rse.model.ISystemResourceChangeEvents; +import org.eclipse.rse.model.ISystemResourceChangeListener; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.shells.ui.RemoteCommandHelpers; +import org.eclipse.rse.shells.ui.ShellResources; +import org.eclipse.rse.shells.ui.actions.SystemBaseShellAction; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.ui.ISystemIconConstants; +import org.eclipse.rse.ui.SystemResources; +import org.eclipse.rse.ui.SystemWidgetHelpers; +import org.eclipse.rse.ui.actions.SystemBaseDummyAction; +import org.eclipse.rse.ui.actions.SystemTablePrintAction; +import org.eclipse.rse.ui.messages.ISystemMessageLine; +import org.eclipse.rse.ui.view.IRSEViewPart; +import org.eclipse.rse.ui.view.ISystemViewElementAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.ISelectionService; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.part.CellEditorActionHandler; +import org.eclipse.ui.part.ViewPart; + + + +/** + * This is the desktop view wrapper of the System View viewer. + * ViewPart is from com.ibm.itp.ui.support.parts + */ +public class SystemCommandsViewPart + extends ViewPart + implements + ISelectionListener, + SelectionListener, + ISelectionChangedListener, + ISystemResourceChangeListener, + IRSEViewPart, + IMenuListener, + ISystemMessageLine +{ + + + class RestoreStateRunnable implements Runnable + { + public void run() + { + initDefaultCommandShells(); + } + } + + class BrowseAction extends Action + { + public BrowseAction(String label, ImageDescriptor des) + { + super(label, des); + + setToolTipText(label); + } + + public void checkEnabledState() + { + if (_folder != null && _folder.getInput() != null) + { + setEnabled(true); + } + else + { + setEnabled(false); + } + } + + public void run() + { + } + } + + + + + public class ShellAction extends BrowseAction + { + private IRemoteCmdSubSystem _cmdSubSystem; + + public ShellAction(String title, ImageDescriptor image, IRemoteCmdSubSystem cmdSubSystem) + { + super(title, image); + + setToolTipText(ShellResources.ACTION_RUN_SHELL_TOOLTIP); + _cmdSubSystem = cmdSubSystem; + } + + public void checkEnabledState() + { + setEnabled(_cmdSubSystem.canRunShell()); + } + + public void run() + { + try + { + IRemoteCommandShell cmd = _cmdSubSystem.runShell(getShell(), null); + if (cmd != null) + { + showInView(cmd); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + + } + + private void showInView(IRemoteCommandShell cmd) + { + SystemCommandsUI commandsUI = SystemCommandsUI.getInstance(); + SystemCommandsViewPart cmdsPart = commandsUI.activateCommandsView(); + cmdsPart.updateOutput(cmd); + } + } + + public class ClearAction extends BrowseAction + { + public ClearAction() + { + + super(SystemResources.ACTION_CLEAR_LABEL, + SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_CLEAR_ID)); + + ImageDescriptor des = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_CLEAR_ID); + + setImageDescriptor(des); + + setEnabled(false); + // TODO DKM - get help for this! + //PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.CLEAR_CONSOLE_ACTION); + } + + public void checkEnabledState() + { + Object input = _folder.getInput(); + if (input != null) + { + if (input instanceof IRemoteCommandShell) + { + setEnabled(((IRemoteCommandShell) input).isActive()); + return; + } + } + + setEnabled(false); + } + + public void run() + { + if (_folder.getInput() != null) + { + clear(); + } + } + + // clear contents of the current command viewer + private void clear() + { + _folder.getViewer().clearAllItems(); + } + } + + + public class CommandSubSystemDisconnectedRunnable implements Runnable + { + private IRemoteCmdSubSystem _subsystem; + public CommandSubSystemDisconnectedRunnable(IRemoteCmdSubSystem subsystem) + { + _subsystem = subsystem; + } + + public void run() + { + IRemoteCommandShell[] cmds = _subsystem.getShells(); + if (cmds != null) + { + for (int i = 0; i < cmds.length; i++) + { + _folder.remove(cmds[i]); + } + } + } + } + + public class CommandMenuManager extends MenuManager + { + public CommandMenuManager() + { + super(ShellResources.ACTION_LAUNCH_LABEL); + } + } + + public class CommandSubmenuManager extends MenuManager + { + private IRemoteCmdSubSystem[] _subsystems; + public CommandSubmenuManager(IHost connection, IRemoteCmdSubSystem[] subsystems) + { + super(connection.getAliasName()); + _subsystems = subsystems; + } + + public IRemoteCmdSubSystem[] getSubSystems() + { + return _subsystems; + } + } + + private ClearAction _clearAction = null; + + + + private List _shellActions = null; + + private SystemTablePrintAction _printTableAction = null; + private CommandsViewWorkbook _folder = null; + private IRemoteCommandShell _lastSelected = null; + private CellEditorActionHandler _editorActionHandler = null; + + // for ISystemMessageLine + private String _message, _errorMessage; + private SystemMessage sysErrorMessage; + private IStatusLineManager _statusLine = null; + + // constants + public static final String ID = "org.eclipse.rse.shells.ui.view.commandsView"; + // matches id in plugin.xml, view tag + + public void setFocus() + { + _folder.showCurrentPage(); + } + + public Shell getShell() + { + return _folder.getShell(); + } + + public Viewer getRSEViewer() + { + return _folder.getViewer(); + } + + public CellEditorActionHandler getEditorActionHandler() + { + if (_editorActionHandler == null) + { + _editorActionHandler = new CellEditorActionHandler(getViewSite().getActionBars()); + } + return _editorActionHandler; + } + + public void createPartControl(Composite parent) + { + _folder = new CommandsViewWorkbook(parent, this); + _folder.getFolder().addSelectionListener(this); + + ISelectionService selectionService = getSite().getWorkbenchWindow().getSelectionService(); + selectionService.addSelectionListener(this); + + + SystemWidgetHelpers.setHelp(_folder, SystemPlugin.HELPPREFIX + "ucmd0000"); + + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + + + + registry.addSystemResourceChangeListener(this); + + RestoreStateRunnable restore = new RestoreStateRunnable(); + Display.getCurrent().asyncExec(restore); + + fillLocalToolBar(); + } + + public void selectionChanged(IWorkbenchPart part, ISelection sel) + { + } + + public void dispose() + { + ISelectionService selectionService = getSite().getWorkbenchWindow().getSelectionService(); + selectionService.removeSelectionListener(this); + _folder.dispose(); + + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + registry.removeSystemResourceChangeListener(this); + super.dispose(); + } + + public void updateActionStates() + { + if (_shellActions == null) + fillLocalToolBar(); + + if (_folder != null && _folder.getInput() != null) + { + IRemoteCommandShell currentSelected = (IRemoteCommandShell)_folder.getInput(); + if (currentSelected != null) + { + if (currentSelected != _lastSelected) + { + // reset the actions + IActionBars actionBars = getViewSite().getActionBars(); + IToolBarManager toolBarManager = actionBars.getToolBarManager(); + updateShellActions(); + addToolBarItems(toolBarManager); + } + _lastSelected = currentSelected; + + _folder.updateActionStates(); + CommandsViewPage page = _folder.getCurrentTabItem(); + if (page != null) + { + _printTableAction.setTableView(page.getTitle(), page.getViewer()); + } + else + { + _printTableAction.setTableView("", null); + } + + _clearAction.checkEnabledState(); + + StructuredSelection cmdSelection = new StructuredSelection(_folder.getInput()); + for (int i =0; i < _shellActions.size(); i++) + { + Object action = _shellActions.get(i); + if (action instanceof SystemBaseShellAction) + { + SystemBaseShellAction shellAction = (SystemBaseShellAction)action; + shellAction.setEnabled(shellAction.updateSelection(cmdSelection)); + } + } + + _printTableAction.checkEnabledState(); + } + } + + + } + + protected void updateShellActions() + { + if (_folder != null && _folder.getInput() != null) + { + IRemoteCommandShell cmdShell = (IRemoteCommandShell)_folder.getInput(); + SystemViewRemoteOutputAdapter adapter = (SystemViewRemoteOutputAdapter)((IAdaptable)cmdShell).getAdapter(ISystemViewElementAdapter.class); + + _shellActions = adapter.getShellActions(cmdShell.getCommandSubSystem().getParentRemoteCmdSubSystemFactory()); + } + else if (_shellActions != null) + { + _shellActions.clear(); + } + else + { + _shellActions = new ArrayList(); + } + } + + public void fillLocalToolBar() + { + boolean firstCall = false; + if (_folder != null ) + { + firstCall = (_shellActions == null); + + if (firstCall) { + updateShellActions(); + } + + updateActionStates(); + + IActionBars actionBars = getViewSite().getActionBars(); + + if (firstCall) + { + _clearAction = new ClearAction(); + _printTableAction = new SystemTablePrintAction(getTitle(), null); + IMenuManager menuManager = actionBars.getMenuManager(); + addMenuItems(menuManager); + _statusLine = actionBars.getStatusLineManager(); + } + IToolBarManager toolBarManager = actionBars.getToolBarManager(); + addToolBarItems(toolBarManager); + } + } + + private void addToolBarItems(IToolBarManager toolBarManager) + { + toolBarManager.removeAll(); + if (_clearAction != null) + { + toolBarManager.add(_clearAction); + } + if (_shellActions != null) + { + for (int i =0; i < _shellActions.size(); i++) + { + Object shellAction = _shellActions.get(i); + if (shellAction instanceof IContributionItem) + { + toolBarManager.add((IContributionItem)shellAction); + } + else if (shellAction instanceof IAction) + { + toolBarManager.add((IAction)shellAction); + } + } + } + toolBarManager.update(true); + + } + + private void addMenuItems(IMenuManager menuManager) + { + IMenuManager launchMenu = new CommandMenuManager(); + + launchMenu.add(new SystemBaseDummyAction()); + launchMenu.addMenuListener(this); + launchMenu.setRemoveAllWhenShown(true); + menuManager.add(launchMenu); + menuManager.addMenuListener(this); + + menuManager.add(new Separator()); + menuManager.add(_printTableAction); + } + + public void menuAboutToShow(IMenuManager menuManager) + { + if (menuManager instanceof CommandSubmenuManager) + { + IRemoteCmdSubSystem[] cmdSubSystems = ((CommandSubmenuManager)menuManager).getSubSystems(); + for (int c = 0; c < cmdSubSystems.length; c++) + { + IRemoteCmdSubSystem cmdSubSystem = cmdSubSystems[c]; + + if (cmdSubSystem != null && cmdSubSystem.canRunShell()) + { + String name = cmdSubSystem.getName(); + ISystemViewElementAdapter ssva = + (ISystemViewElementAdapter) ((IAdaptable) cmdSubSystem).getAdapter( + ISystemViewElementAdapter.class); + ImageDescriptor icon = ssva.getImageDescriptor(cmdSubSystem); + ShellAction action = + new ShellAction( + name, + icon, + cmdSubSystem); + menuManager.add(action); + } + } + } + else + { + boolean hasItem = false; + + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + IHost[] connections = registry.getHosts(); + + for (int i = 0; i < connections.length; i++) + { + IHost connection = connections[i]; + if (registry.isAnySubSystemConnected(connection) || connection.getSystemType().equals("Local")) + { + IRemoteCmdSubSystem[] cmdSubSystems = RemoteCommandHelpers.getCmdSubSystems(connection); + if (cmdSubSystems.length == 1) + { + IRemoteCmdSubSystem cmdSubSystem = cmdSubSystems[0]; + if (cmdSubSystem != null && cmdSubSystem.canRunShell()) + { + hasItem = true; + + if (menuManager instanceof CommandMenuManager) + { + ISystemViewElementAdapter va = + (ISystemViewElementAdapter) ((IAdaptable) connection).getAdapter( + ISystemViewElementAdapter.class); + + String name = connection.getAliasName(); + ImageDescriptor icon = va.getImageDescriptor(connection); + + + ShellAction action = + new ShellAction( + name, + icon, + cmdSubSystem); + menuManager.add(action); + } + } + } + else if (cmdSubSystems.length > 1) + { + if (menuManager instanceof CommandMenuManager) + { + ISystemViewElementAdapter va = + (ISystemViewElementAdapter) ((IAdaptable) connection).getAdapter( + ISystemViewElementAdapter.class); + + IMenuManager sublaunchMenu = new CommandSubmenuManager(connection, cmdSubSystems); + sublaunchMenu.add(new SystemBaseDummyAction()); + sublaunchMenu.addMenuListener(this); + sublaunchMenu.setRemoveAllWhenShown(true); + + menuManager.add(sublaunchMenu); + menuManager.addMenuListener(this); + } + + + } + } + } + + if (!(menuManager instanceof CommandMenuManager)) + { + if (!hasItem) + { + if (menuManager.getItems().length > 0) + { + MenuManager lmgr = (MenuManager) menuManager.getItems()[0]; + if (lmgr.getMenu() != null) + { + lmgr.getMenu().getParentItem().setEnabled(false); + } + } + } + else + { + if (menuManager.getItems().length > 0) + { + MenuManager lmgr = (MenuManager) menuManager.getItems()[0]; + if (lmgr.getMenu() != null) + { + lmgr.getMenu().getParentItem().setEnabled(true); + } + } + } + } + } + } + + public void selectionChanged(SelectionChangedEvent e) + { + } + + /** + * Update or create a view tab for the specified command + * If there is no tab for the command, create one. + * + * @param root command to view + * + */ + public void updateOutput(IRemoteCommandShell root) + { + updateOutput(root, true); + } + + private void updateOutput(IRemoteCommandShell root, boolean createTab) + { + if (root != null) + { + _folder.updateOutput(root, createTab); + if (createTab) + updateActionStates(); + } + } + + public void setInput(IAdaptable object) + { + setInput(object, true); + } + + public void setInput(IAdaptable object, boolean updateHistory) + { + _folder.setInput(object); + } + + + protected void initDefaultCommandShells() + { + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + IHost[] connections = registry.getHosts(); + CommandsViewPage curpage = _folder.getCurrentTabItem(); + + for (int i = 0; i < connections.length; i++) + { + IHost connection = connections[i]; + if (registry.isAnySubSystemConnected(connection) || connection.getSystemType().equals("Local")) + { + IRemoteCmdSubSystem[] cmdSubSystems = RemoteCommandHelpers.getCmdSubSystems(connection); + if (cmdSubSystems.length > 0) + { + for (int c= 0; c < cmdSubSystems.length; c++) + { + IRemoteCmdSubSystem cmdSubSystem = cmdSubSystems[c]; + + if (cmdSubSystem != null && cmdSubSystem.canRunShell()) + { + restoreCommandShells(cmdSubSystem); + } + } + } + } + } + + if (curpage != null) + { + updateOutput((IRemoteCommandShell)curpage.getInput()); + //curpage.setFocus(); + } + + } + + protected void restoreCommandShells(IRemoteCmdSubSystem cmdSS) + { + + try + { + IRemoteCommandShell[] cmds = cmdSS.getShells(); + if (cmds == null || cmds.length == 0) + { + cmds = cmdSS.restoreShellState(getShell()); + for (int i = 0; i < cmds.length; i++) + { + updateOutput(cmds[i]); + } + } + } + catch (Exception e) + { + } + + + } + + + public void systemResourceChanged(ISystemResourceChangeEvent event) + { + if (event.getType() == ISystemResourceChangeEvents.EVENT_COMMAND_SHELL_FINISHED) + { + Object source = event.getSource(); + if (source instanceof IRemoteCmdSubSystem) + { + Shell shell = SystemPlugin.getTheSystemRegistry().getShell(); + shell.getDisplay().asyncExec(new CommandSubSystemDisconnectedRunnable((IRemoteCmdSubSystem) source)); + } + else if (source instanceof IRemoteCommandShell) + { + // find out if we're listening to this + + updateOutput((IRemoteCommandShell) source, false); + updateActionStates(); + } + } + + if (event.getType() == ISystemResourceChangeEvents.EVENT_COMMAND_SHELL_REMOVED) + { + Object source = event.getSource(); + if (source instanceof IRemoteCommandShell) + { + updateOutput((IRemoteCommandShell) source, false); + _folder.remove((IRemoteCommandShell)source); + updateActionStates(); + } + } + else if (event.getType() == ISystemResourceChangeEvents.EVENT_REFRESH) + { + Object parent = event.getParent(); + if (parent instanceof IRemoteCommandShell) + { + updateOutput((IRemoteCommandShell) parent, false); + } + } + else if (event.getType() == ISystemResourceChangeEvents.EVENT_PROPERTY_CHANGE) + { + IRemoteCmdSubSystem cmdSS = null; + Object parent = event.getSource(); + + if (parent instanceof IRemoteFileSubSystem) + { + IRemoteFileSubSystem ss = (IRemoteFileSubSystem)parent; + cmdSS = RemoteCommandHelpers.getCmdSubSystem(ss.getHost()); + } + else if (parent instanceof IRemoteCmdSubSystem) + { + cmdSS = (IRemoteCmdSubSystem)parent; + } + else if (parent instanceof ISubSystem) + { + // DKM - for now assuming only 1 cmd subsystem + //SystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + //registry.getCmdSubSystems() + cmdSS = RemoteCommandHelpers.getCmdSubSystem(((ISubSystem)parent).getHost()); + } + if (cmdSS != null) + { + if (cmdSS.isConnected()) + restoreCommandShells(cmdSS); + } + } + else if (event.getType() == ISystemResourceChangeEvents.EVENT_MUST_COLLAPSE) + { + Object source = event.getSource(); + if (source instanceof IRemoteCmdSubSystem) + { + Shell shell = SystemPlugin.getTheSystemRegistry().getShell(); + shell.getDisplay().asyncExec(new CommandSubSystemDisconnectedRunnable((IRemoteCmdSubSystem) source)); + } + } + } + + public void widgetDefaultSelected(SelectionEvent e) + { + widgetSelected(e); + } + + public void widgetSelected(SelectionEvent e) + { + Widget source = e.widget; + + if (source == _folder.getFolder()) + { + updateActionStates(); + } + } + + +// ------------------------------- + // ISystemMessageLine interface... + // ------------------------------- + /** + * Clears the currently displayed error message and redisplayes + * the message which was active before the error message was set. + */ + public void clearErrorMessage() + { + _errorMessage = null; + sysErrorMessage = null; + if (_statusLine != null) + _statusLine.setErrorMessage(_errorMessage); + } + /** + * Clears the currently displayed message. + */ + public void clearMessage() + { + _message = null; + if (_statusLine != null) + _statusLine.setMessage(_message); + } + /** + * Get the currently displayed error text. + * @return The error message. If no error message is displayed null is returned. + */ + public String getErrorMessage() + { + return _errorMessage; + } + /** + * Get the currently displayed message. + * @return The message. If no message is displayed null is returned. + */ + public String getMessage() + { + return _message; + } + /** + * Display the given error message. A currently displayed message + * is saved and will be redisplayed when the error message is cleared. + */ + public void setErrorMessage(String message) + { + this._errorMessage = message; + if (_statusLine != null) + _statusLine.setErrorMessage(message); + } + /** + * Get the currently displayed error text. + * @return The error message. If no error message is displayed null is returned. + */ + public SystemMessage getSystemErrorMessage() + { + return sysErrorMessage; + } + + /** + * Display the given error message. A currently displayed message + * is saved and will be redisplayed when the error message is cleared. + */ + public void setErrorMessage(SystemMessage message) + { + sysErrorMessage = message; + setErrorMessage(message.getLevelOneText()); + } + /** + * Display the given error message. A currently displayed message + * is saved and will be redisplayed when the error message is cleared. + */ + public void setErrorMessage(Throwable exc) + { + setErrorMessage(exc.getMessage()); + } + + /** + * Set the message text. If the message line currently displays an error, + * the message is stored and will be shown after a call to clearErrorMessage + */ + public void setMessage(String message) + { + this._message = message; + if (_statusLine != null) + _statusLine.setMessage(message); + } + /** + *If the message line currently displays an error, + * the message is stored and will be shown after a call to clearErrorMessage + */ + public void setMessage(SystemMessage message) + { + setMessage(message.getLevelOneText()); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandsViewProvider.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandsViewProvider.java new file mode 100644 index 00000000000..5c05a035a4c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemCommandsViewProvider.java @@ -0,0 +1,37 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; + +import org.eclipse.rse.ui.view.SystemTableViewProvider; + +public class SystemCommandsViewProvider extends SystemTableViewProvider +{ + /** + * Overridden to provide alternate text for special views of + * model objects + */ + public String getText(Object object) + { + String result = getAdapterFor(object).getAlternateText(object); + int len = result.length(); + if (len > _maxCharsInColumnZero) + { + _maxCharsInColumnZero = len; + } + return result; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemViewOutputAdapterFactory.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemViewOutputAdapterFactory.java new file mode 100644 index 00000000000..6ae2f1564a9 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemViewOutputAdapterFactory.java @@ -0,0 +1,84 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.core.runtime.IAdapterManager; +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteError; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteOutput; +import org.eclipse.rse.ui.view.ISystemDragDropAdapter; +import org.eclipse.rse.ui.view.ISystemRemoteElementAdapter; +import org.eclipse.rse.ui.view.ISystemViewElementAdapter; +import org.eclipse.ui.IActionFilter; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.ui.views.properties.IPropertySource; + + +/** + * This factory maps requests for an adapter object from a given + * element object. This is for the universal command subsystem. + */ +public class SystemViewOutputAdapterFactory implements IAdapterFactory +{ + private SystemViewRemoteOutputAdapter outputAdapter = new SystemViewRemoteOutputAdapter(); + private SystemViewRemoteErrorAdapter errorAdapter = new SystemViewRemoteErrorAdapter(); + + /** + * @see IAdapterFactory#getAdapterList() + */ + public Class[] getAdapterList() + { + return new Class[] {ISystemViewElementAdapter.class, ISystemDragDropAdapter.class, ISystemRemoteElementAdapter.class, IPropertySource.class, IWorkbenchAdapter.class, IActionFilter.class}; + } + /** + * Called by our plugin's startup method to register our adaptable object types + * with the platform. We prefer to do it here to isolate/encapsulate all factory + * logic in this one place. + */ + public void registerWithManager(IAdapterManager manager) + { + manager.registerAdapters(this, IRemoteError.class); + manager.registerAdapters(this, IRemoteOutput.class); + manager.registerAdapters(this, IRemoteCommandShell.class); + } + /** + * @see IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class) + */ + public Object getAdapter(Object adaptableObject, Class adapterType) + { + Object adapter = null; + if (adaptableObject instanceof IRemoteError) + adapter = errorAdapter; + else if (adaptableObject instanceof IRemoteOutput) + adapter = outputAdapter; + else if (adaptableObject instanceof IRemoteCommandShell) + adapter = outputAdapter; + + if ((adapter != null) && (adapterType == IPropertySource.class)) + { + ((ISystemViewElementAdapter)adapter).setPropertySourceInput(adaptableObject); + } + else if (adapter == null) + { + SystemBasePlugin.logWarning("No adapter found for object of type: " + adaptableObject.getClass().getName()); + } + return adapter; + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemViewRemoteErrorAdapter.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemViewRemoteErrorAdapter.java new file mode 100644 index 00000000000..5f69d03c23a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemViewRemoteErrorAdapter.java @@ -0,0 +1,121 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteError; +import org.eclipse.rse.ui.SystemMenuManager; +import org.eclipse.rse.ui.view.SystemViewResources; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.views.properties.IPropertyDescriptor; +import org.eclipse.ui.views.properties.PropertyDescriptor; + + +/** + * Comment goes here + */ +public class SystemViewRemoteErrorAdapter extends SystemViewRemoteOutputAdapter +{ + + protected IPropertyDescriptor[] _uniquePropertyDescriptorArray; + /** + * Used to add context menu actions for the given remote output + */ + public void addActions(SystemMenuManager menu, IStructuredSelection selection, Shell shell, String menuGroup) + { + super.addActions(menu, selection, shell, menuGroup); + + } + + public IPropertyDescriptor[] getUniquePropertyDescriptors() + { + if (_uniquePropertyDescriptorArray == null) + { + int nbrOfProperties = 2; + + _uniquePropertyDescriptorArray = new PropertyDescriptor[nbrOfProperties]; + //PropertyDescriptor[] defaultProperties = (PropertyDescriptor[]) getDefaultDescriptors(); + + int i = -1; + + // add our unique property descriptors... + SystemPlugin plugin = SystemPlugin.getDefault(); + + // path + _uniquePropertyDescriptorArray[++i] = createSimplePropertyDescriptor(P_ERROR_FILENAME, SystemViewResources.RESID_PROPERTY_ERROR_FILENAME_LABEL, SystemViewResources.RESID_PROPERTY_ERROR_FILENAME_TOOLTIP); + + // line + _uniquePropertyDescriptorArray[++i] = createSimplePropertyDescriptor(P_ERROR_LINENO, SystemViewResources.RESID_PROPERTY_ERROR_LINENO_LABEL, SystemViewResources.RESID_PROPERTY_ERROR_LINENO_TOOLTIP); + } + + return _uniquePropertyDescriptorArray; + + } + + /** + * Return our unique property descriptors + */ + protected IPropertyDescriptor[] internalGetPropertyDescriptors() + { + if (_propertyDescriptors == null) + { + // unique ones + IPropertyDescriptor[] unique = getUniquePropertyDescriptors(); + // our additional + _propertyDescriptors = new PropertyDescriptor[1+ unique.length]; + int idx = -1; + + // path + _propertyDescriptors[++idx] = createSimplePropertyDescriptor(P_FILE_PATH, SystemViewResources.RESID_PROPERTY_FILE_PATH_LABEL, SystemViewResources.RESID_PROPERTY_FILE_PATH_TOOLTIP); + // append... + for (int i = 0; i < unique.length; i++) + { + _propertyDescriptors[++idx] = unique[i]; + } + } + return _propertyDescriptors; + } + + /** + * Returns the current collection of property descriptors. + * @return an array containing all descriptors. + */ + protected Object internalGetPropertyValue(Object key) + { + String name = (String) key; + if (propertySourceInput instanceof IRemoteError) + { + IRemoteError output = (IRemoteError) propertySourceInput; + + if (name.equals(P_FILE_PATH)) + { + return output.getAbsolutePath(); + } + else if (name.equals(P_ERROR_FILENAME)) + { + return output.getAbsolutePath(); + } + else if (name.equals(P_ERROR_LINENO)) + { + return new Integer(output.getLine()); + } + } + return null; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemViewRemoteOutputAdapter.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemViewRemoteOutputAdapter.java new file mode 100644 index 00000000000..33e3152e2eb --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/SystemViewRemoteOutputAdapter.java @@ -0,0 +1,1157 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; +import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.subsystems.IRemoteLineReference; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.core.subsystems.util.ISubsystemConfigurationAdapter; +import org.eclipse.rse.files.ui.actions.SystemRemoteFileLineOpenWithMenu; +import org.eclipse.rse.files.ui.resources.RemoteSourceLookupDirector; +import org.eclipse.rse.files.ui.resources.SystemEditableRemoteFile; +import org.eclipse.rse.shells.ui.ShellResources; +import org.eclipse.rse.shells.ui.actions.SystemShowInShellViewAction; +import org.eclipse.rse.shells.ui.actions.SystemTerminateRemoveShellAction; +import org.eclipse.rse.shells.ui.actions.SystemTerminateShellAction; +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.subsystems.shells.core.model.ISystemOutputRemoteTypes; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystemConfiguration; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteError; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteOutput; +import org.eclipse.rse.ui.ISystemContextMenuConstants; +import org.eclipse.rse.ui.ISystemIconConstants; +import org.eclipse.rse.ui.SystemMenuManager; +import org.eclipse.rse.ui.actions.SystemCopyToClipboardAction; +import org.eclipse.rse.ui.actions.SystemPasteFromClipboardAction; +import org.eclipse.rse.ui.view.AbstractSystemViewAdapter; +import org.eclipse.rse.ui.view.ISystemDragDropAdapter; +import org.eclipse.rse.ui.view.ISystemEditableRemoteObject; +import org.eclipse.rse.ui.view.ISystemPropertyConstants; +import org.eclipse.rse.ui.view.ISystemRemoteElementAdapter; +import org.eclipse.rse.ui.view.ISystemViewElementAdapter; +import org.eclipse.rse.ui.view.SystemView; +import org.eclipse.rse.ui.view.SystemViewResources; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorDescriptor; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorRegistry; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.part.FileEditorInput; +import org.eclipse.ui.views.properties.IPropertyDescriptor; + + +/** + * This is the adapter for smart output from remote commands, such that they can support right click actions and such. + */ +public class SystemViewRemoteOutputAdapter extends AbstractSystemViewAdapter +implements ISystemViewElementAdapter, ISystemRemoteElementAdapter, ISystemOutputRemoteTypes +{ + + + protected IPropertyDescriptor[] _propertyDescriptors; + + private SystemCopyToClipboardAction _copyOutputAction = null; + private SystemPasteFromClipboardAction _pasteToPromptAction = null; + + private SystemShowInShellViewAction _showInShellView = null; + private SystemTerminateShellAction _terminateShellAction = null; + private SystemTerminateRemoveShellAction _terminateRemoveShellAction = null; + private IAction _exportShellHistoryAction = null; + private IAction _exportShellOutputAction = null; + private List _shellActions = null; + + private IPropertyDescriptor _shellPropertyDescriptors[]; + private IPropertyDescriptor _outputPropertyDescriptors[]; + + public SystemViewRemoteOutputAdapter() + { + _shellActions = new ArrayList(); + } + + /** + * Used to add context menu actions for the given remote output + */ + public void addActions(SystemMenuManager menu, IStructuredSelection selection, Shell shell, String menuGroup) + { + Object firstSelection = selection.getFirstElement(); + + if (firstSelection != null) + { + if (firstSelection instanceof IRemoteOutput) + { + if (_copyOutputAction == null) + { + _copyOutputAction = new SystemCopyToClipboardAction(shell, SystemPlugin.getTheSystemRegistry().getSystemClipboard()); + } + + menu.add(menuGroup, _copyOutputAction); + + if (selection.size() == 1) + { + if (firstSelection instanceof IRemoteLineReference) + { + IRemoteOutput result = (IRemoteOutput) firstSelection; + if (result.getType().equals("prompt")) + { + if (_pasteToPromptAction == null) + { + _pasteToPromptAction = new SystemPasteFromClipboardAction(shell, SystemPlugin.getTheSystemRegistry().getSystemClipboard()); + } + + menu.add(menuGroup, _pasteToPromptAction); + } + else + { + IRemoteOutput output = (IRemoteOutput)firstSelection; + if (output.getAbsolutePath() != null) + { + //SystemCreateEditLineActions createActions = new SystemCreateEditLineActions(); + //createActions.create(menu, selection, shell, menuGroup); + // open with -> + MenuManager submenu = + new MenuManager(org.eclipse.ui.internal.views.navigator.ResourceNavigatorMessages.ResourceNavigator_openWith, + ISystemContextMenuConstants.GROUP_OPENWITH); + + SystemRemoteFileLineOpenWithMenu openWithMenu = new SystemRemoteFileLineOpenWithMenu(); + openWithMenu.updateSelection(selection); + submenu.add(openWithMenu); + menu.getMenuManager().appendToGroup(ISystemContextMenuConstants.GROUP_OPENWITH, submenu); + + } + } + } + + + + } + } + else if (firstSelection instanceof IRemoteCommandShell) + { + IRemoteCommandShell cmdShell = (IRemoteCommandShell)firstSelection; + if (_showInShellView == null) + { + _showInShellView = new SystemShowInShellViewAction(shell); + + } + menu.add(ISystemContextMenuConstants.GROUP_OPEN,_showInShellView); + + getShellActions(cmdShell.getCommandSubSystem().getParentRemoteCmdSubSystemFactory()); + + menu.add(ISystemContextMenuConstants.GROUP_CHANGE, _terminateShellAction); + menu.add(ISystemContextMenuConstants.GROUP_CHANGE, _terminateRemoveShellAction); + menu.add(ISystemContextMenuConstants.GROUP_IMPORTEXPORT, _exportShellOutputAction); + menu.add(ISystemContextMenuConstants.GROUP_IMPORTEXPORT, _exportShellHistoryAction); + } + } + else + { + return; + } + } + + public List getShellActions(IRemoteCmdSubSystemConfiguration factory) + { + getShell(); + _shellActions.clear(); + if (_shellActions.size()== 0) + { + if (_terminateShellAction == null) + { + _terminateShellAction = new SystemTerminateShellAction(shell); + } + _shellActions.add(_terminateShellAction); + if (_terminateRemoveShellAction == null) + { + _terminateRemoveShellAction = new SystemTerminateRemoveShellAction(shell); + } + _shellActions.add(_terminateRemoveShellAction); + + _shellActions.add(new Separator()); + + ShellServiceSubSystemFactoryAdapter factoryAdapter = (ShellServiceSubSystemFactoryAdapter)factory.getAdapter(ISubsystemConfigurationAdapter.class); + + _exportShellOutputAction = factoryAdapter.getCommandShellOutputExportAction(shell); + _shellActions.add(_exportShellOutputAction); + _exportShellHistoryAction = factoryAdapter.getCommandShellHistoryExportAction(shell); + _shellActions.add(_exportShellHistoryAction); + + } + return _shellActions; + } + + /** + * Returns the parent command object for a line of output + */ + public Object getParent(Object element) + { + if (element instanceof IRemoteOutput) + { + IRemoteOutput output = (IRemoteOutput) element; + return output.getParent(); + } + return null; + } + + /** + * Returns the text to display in a view for this element. + */ + public String getText(Object element) + { + if (element instanceof IRemoteOutput) + { + IRemoteOutput output = (IRemoteOutput) element; + String text = output.getText(); + + if (text.indexOf('\t') > 0) + { + text = translateTabs(text); + } + + int tagIndex = text.indexOf("BEGIN-END-TAG"); + if (tagIndex == 0) + { + return ""; + } + else if (tagIndex > 0) + { + //return text.substring(0, tagIndex - 6); + return text.substring(0, tagIndex); + } + + return text; + } + else if (element instanceof IRemoteCommandShell) + { + IRemoteCommandShell outputRoot = (IRemoteCommandShell) element; + return outputRoot.getId(); + } + return null; + } + + + protected String translateTabs(String tabbedString) + { + int columnWidth = 8; + + int currentOffset = 0; + StringBuffer untabbedBuf = new StringBuffer(); + for (int i = 0; i < tabbedString.length();i++) + { + char p = '\0'; + char c = tabbedString.charAt(i); + char n = '\0'; + if (i+1 -1) + { + p = tabbedString.charAt(i - 1); + } + if (c == '\t') + { + untabbedBuf.append(' '); + currentOffset++; + while ((currentOffset % columnWidth) >0) + { + untabbedBuf.append(' '); + currentOffset++; + } + } + else if (c == ' ') + { + untabbedBuf.append(' '); + currentOffset++; + } + else + { + untabbedBuf.append(c); + currentOffset++; + } + } + + return untabbedBuf.toString(); + } + /** + * Returns the type attribute of a line of output or command. + */ + public String getType(Object element) + { + if (element instanceof IRemoteOutput) + { + IRemoteOutput output = (IRemoteOutput) element; + return output.getType(); + } + else if (element instanceof IRemoteCommandShell) + { + IRemoteCommandShell root = (IRemoteCommandShell) element; + return root.getType(); + } + return null; + } + + /** + * Returns the children of a remote command if the element is a remote command + */ + public Object[] getChildren(Object element) + { + + if (element instanceof IRemoteCommandShell) + { + IRemoteCommandShell output = (IRemoteCommandShell) element; + return output.listOutput(); + } + + return null; + } + + /** + * Returns true if the element is a remote command and false if it is a remote output. + */ + public boolean hasChildren(Object element) + { + if (element instanceof IRemoteCommandShell) + { + if (!(getViewer() instanceof SystemView)) + { + return true; + } + return false; + } + else + { + return false; + } + } + + /** + * Returns the associated IRemoteFile for this line of remote output if one exists + * @param output the line of remote output + * @return the associated remote file + */ + public static IRemoteFile outputToFile(IRemoteOutput output) + { + IRemoteFile file = null; + Object parent = output.getParent(); + IRemoteFileSubSystem fs = null; + if (parent instanceof IRemoteCommandShell) + { + IRemoteCommandShell root = (IRemoteCommandShell) output.getParent(); + fs = RemoteFileUtility.getFileSubSystem(root.getCommandSubSystem().getHost()); + } + else if (parent instanceof IRemoteFile) + { + return (IRemoteFile) parent; + } + + if (fs != null) + { + String path = output.getAbsolutePath(); + if (path != null && path.length() > 0) + { + Object obj = null; + try + { + obj = fs.getObjectWithAbsoluteName(path); + } + catch (Exception e) + { + return null; + } + if (obj != null && obj instanceof IRemoteFile) + { + file = (IRemoteFile) obj; + + return file; + } + } + } + + return file; + } + + + + protected IEditorRegistry getEditorRegistry() + { + return SystemPlugin.getDefault().getWorkbench().getEditorRegistry(); + } + + protected IEditorDescriptor getDefaultTextEditor() + { + IEditorRegistry registry = getEditorRegistry(); + return registry.findEditor("org.eclipse.ui.DefaultTextEditor"); + } + + /** + * Open workspace file associated with IRemoteCommandShell. If there is no associated project + * return. + * @param remoteFile + * @param output + * @return + */ + protected boolean openWorkspaceFile(IRemoteFile remoteFile, IRemoteOutput output) + { + IRemoteCommandShell cmd = (IRemoteCommandShell)(output.getParent()); + IProject associatedProject = cmd.getAssociatedProject(); + if (associatedProject != null) + { + ProjectSourceContainer container = new ProjectSourceContainer(associatedProject, false); + ISourceLookupDirector director = new RemoteSourceLookupDirector(); + container.init(director); + try + { + Object[] matches = container.findSourceElements(remoteFile.getName()); + for (int i = 0; i < matches.length; i++) + { + //System.out.println("match="+matches[i]); + } + + if (matches.length == 1) + { + IFile localMatch = (IFile)matches[0]; + + + + IWorkbenchPage activePage = SystemBasePlugin.getActiveWorkbenchWindow().getActivePage(); + + FileEditorInput finput = new FileEditorInput(localMatch); + + + IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(remoteFile.getName()); + if (desc == null) + { + desc = getDefaultTextEditor(); + } + String editorid = desc.getId(); + IEditorPart editor = activePage.openEditor(finput, editorid); + + int line = output.getLine(); + int charStart = output.getCharStart(); + int charEnd = output.getCharEnd(); + + try + { + IMarker marker = null; + + // DKM - should we? this will populate the Problems view..but resources are actually remote + if (output instanceof IRemoteError) + { + IRemoteError error = (IRemoteError)output; + String type = error.getType(); + + marker = localMatch.createMarker(IMarker.TEXT); + + if (type.equals("error")) + { + marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); + } + else if (type.equals("warning")) + { + marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING); + } + else if (type.equals("informational")) + { + marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO); + } + + marker.setAttribute(IMarker.MESSAGE, output.getText()); + marker.setAttribute(IMarker.LINE_NUMBER, line); + marker.setAttribute(IMarker.CHAR_START, charStart); + marker.setAttribute(IMarker.CHAR_END, charEnd); + + } + else + { + marker = localMatch.createMarker(IMarker.TEXT); + marker.setAttribute(IMarker.LINE_NUMBER, line); + marker.setAttribute(IMarker.CHAR_START, charStart); + marker.setAttribute(IMarker.CHAR_END, charEnd); + } + IDE.gotoMarker(editor, marker); + + + } + catch (CoreException e) + { + e.printStackTrace(); + } + return true; + } + } + catch(Exception e) + { + e.printStackTrace(); + } + } + + return false; + } + + /** + * Opens the appropriate editor for a remote output object + */ + public boolean handleDoubleClick(Object element) + { + boolean result = false; + if (element instanceof IRemoteOutput) + { + IRemoteOutput output = (IRemoteOutput) element; + + IRemoteFile file = outputToFile(output); + if (file != null && file.isFile()) + { + if (!openWorkspaceFile(file, output)) + { + ISystemViewElementAdapter adapter = (ISystemViewElementAdapter) ((IAdaptable) file).getAdapter(ISystemViewElementAdapter.class); + result = adapter.handleDoubleClick(file); + int line = output.getLine(); + + if (result) + { + if (line > 0) + { + SystemRemoteFileLineOpenWithMenu.handleGotoLine(file, line, output.getCharStart(), output.getCharEnd()); + } + return true; + } + } + } + } + else if (element instanceof IRemoteCommandShell) + { + IRemoteCommandShell cmdshell = (IRemoteCommandShell) element; + if (cmdshell.getType().equals(ShellResources.RESID_SHELLS_COMMAND_SHELL_LABEL)) + { + SystemCommandsViewPart viewPart = SystemCommandsUI.getInstance().activateCommandsView(); + viewPart.updateOutput(cmdshell); + result = true; + } + } + return result; + } + + /** + * Returns the associated subsystem for this line of remote output or remote command + */ + public ISubSystem getSubSystem(Object element) + { + if (element instanceof IRemoteCommandShell) + { + IRemoteCommandShell cmd = (IRemoteCommandShell) element; + return cmd.getCommandSubSystem(); + } + else if (element instanceof IRemoteOutput) + { + IRemoteOutput output = (IRemoteOutput) element; + Object parent = output.getParent(); + if (parent instanceof IRemoteCommandShell) + { + return getSubSystem(parent); + } + } + + return null; + } + + /** + * Return the fully qualified name of this remote object. + */ + public String getAbsoluteName(Object element) + { + if (element instanceof IRemoteCommandShell) + { + IRemoteCommandShell cmd = (IRemoteCommandShell) element; + return cmd.getId(); + } + else if (element instanceof IRemoteOutput) + { + IRemoteOutput out = (IRemoteOutput) element; + String str = getAbsoluteParentName(element); + return str + ":" + out.getIndex(); + } + return null; + } + + /** + * Return fully qualified name that uniquely identifies this remote object's remote parent within its subsystem + */ + public String getAbsoluteParentName(Object element) + { + return getAbsoluteName(getParent(element)); + } + + /** + * Return the subsystem factory id that owns this remote object + * The value must not be translated, so that property pages registered via xml can subset by it. + */ + public String getSubSystemFactoryId(Object element) + { + return null; + } + + /** + * Return a value for the type category property for this object + * The value must not be translated, so that property pages registered via xml can subset by it. + */ + public String getRemoteTypeCategory(Object element) + { + return null; + } + + /** + * Return a value for the type property for this object + * The value must not be translated, so that property pages registered via xml can subset by it. + */ + public String getRemoteType(Object element) + { + if (element instanceof IRemoteOutput) + { + return ((IRemoteOutput) element).getType(); + } + else if (element instanceof IRemoteCommandShell) + { + return ((IRemoteCommandShell) element).getType(); + } + return null; + } + + /** + * Return a value for the subtype property for this object. + * Not all object types support a subtype, so returning null is ok. + * The value must not be translated, so that property pages registered via xml can subset by it. + */ + public String getRemoteSubType(Object element) + { + return null; + } + + /** + * Return a value for the sub-subtype property for this object. + * Not all object types support a sub-subtype, so returning null is ok. + * The value must not be translated, so that property pages registered via xml can subset by it. + */ + public String getRemoteSubSubType(Object element) + { + return null; + } + /** + * Return the source type of the selected object. Typically, this only makes sense for compilable + * source members. For non-compilable remote objects, this typically just returns null. + */ + public String getRemoteSourceType(Object element) + { + return null; + } + + /** + * Some view has updated the name or properties of this remote object. As a result, the + * remote object's contents need to be refreshed. You are given the old remote object that has + * old data, and you are given the new remote object that has the new data. For example, on a + * rename the old object still has the old name attribute while the new object has the new + * new attribute. + *

+ * This is called by viewers like SystemView in response to rename and property change events. + *

+ * @param oldElement the element that was found in the tree + * @param newElement the updated element that was passed in the REFRESH_REMOTE event + * @return true if you want the viewer that called this to refresh the children of this object, + * such as is needed on a rename of a folder, say. + */ + public boolean refreshRemoteObject(Object oldElement, Object newElement) + { + return false; + } + + /** + * Given a remote object, returns it remote parent object. Eg, given a file, return the folder + * it is contained in. + */ + public Object getRemoteParent(Shell shell, Object element) throws Exception + { + if (element instanceof IRemoteOutput) + { + return ((IRemoteOutput) element).getParent(); + } + return null; + } + + /** + * Given a remote object, return the unqualified names of the objects contained in that parent. This is + * used for testing for uniqueness on a rename operation, for example. Sometimes, it is not + * enough to just enumerate all the objects in the parent for this purpose, because duplicate + * names are allowed if the types are different, such as on iSeries. In this case return only + * the names which should be used to do name-uniqueness validation on a rename operation. + */ + public String[] getRemoteParentNamesInUse(Shell shell, Object element) throws Exception + { + return null; + } + + + /** + * Returns the current collection of property descriptors. + * By default returns descriptors for name and type only. + * Override if desired. + * @return an array containing all descriptors. + */ + protected Object internalGetPropertyValue(Object key) + { + return getPropertyValue(key, true); + } + + /** + * Returns the icon to display for this object + * @param element the remote output object + * @return the associated image descriptor + */ + public ImageDescriptor getImageDescriptor(Object element) + { + if (element instanceof IRemoteOutput) + { + ImageDescriptor imageDescriptor = null; + IRemoteOutput output = (IRemoteOutput) element; + String type = output.getType(); + if (type.equals(TYPE_ERROR)) + { + imageDescriptor = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_ERROR_ID); + } + else if (type.equals(TYPE_WARNING)) + { + imageDescriptor = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_WARNING_ID); + } + else if (type.equals(TYPE_INFORMATIONAL)) + { + imageDescriptor = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_INFO_ID); + } + else if (type.equals(TYPE_DIRECTORY)) + { + imageDescriptor = //PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER); + SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_FOLDER_ID); + } + else if (type.equals(TYPE_FILE)) + { + imageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE); + //SystemPlugin.getDefault().getImageDescriptor(ISystemConstants.ICON_SYSTEM_FILE_ID); + } + else if (type.equals(TYPE_GREP)) + { + imageDescriptor = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_SEARCH_RESULT_ID); + } + else if (type.equals(TYPE_COMMAND)) + { + imageDescriptor = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_SHELL_ID); + } + else if (type.equals(TYPE_PROMPT)) + { + imageDescriptor = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_SHELL_ID); + } + else if (type.equals(TYPE_PROCESS)) + { + imageDescriptor = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_PROCESS_ID); + } + else if (type.equals(TYPE_ENVVAR)) + { + imageDescriptor = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_ENVVAR_ID); + } + else if (type.equals(TYPE_ENVVAR_LIBPATH)) + { + imageDescriptor = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_ENVVAR_LIBPATH_ID); + } + else if (type.equals(TYPE_ENVVAR_PATH)) + { + imageDescriptor = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_ENVVAR_PATH_ID); + } + else + { + imageDescriptor = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_BLANK_ID); + } + + return imageDescriptor; + } + + else if (element instanceof IRemoteCommandShell) + { + IRemoteCommandShell command = (IRemoteCommandShell) element; + IRemoteCmdSubSystemConfiguration factory = command.getCommandSubSystem().getParentRemoteCmdSubSystemFactory(); + ShellServiceSubSystemFactoryAdapter factoryAdapter = (ShellServiceSubSystemFactoryAdapter)factory.getAdapter(ISubsystemConfigurationAdapter.class); + ImageDescriptor imageDescriptor = null; + if (command.isActive()) + { + imageDescriptor = factoryAdapter.getActiveCommandShellImageDescriptor(); + } + else + { + imageDescriptor = factoryAdapter.getInactiveCommandShellImageDescriptor(); + } + return imageDescriptor; + } + + else + { // return some default + ImageDescriptor imageDescriptor = SystemPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_BLANK_ID); + return imageDescriptor; + } + } + + /** + * Return true if we should show the delete action in the popup for the given element. + * If true, then canDelete will be called to decide whether to enable delete or not. + */ + public boolean showDelete(Object element) + { + return false; + } + /** + * Return true if this object is deletable by the user. If so, when selected, + * the Edit->Delete menu item will be enabled. + * By default, returns false. Override if your object is deletable. + */ + public boolean canDelete(Object element) + { + return false; + } + + // ------------------------------------------ + // METHODS TO SUPPORT COMMON REFRESH ACTION... + // ------------------------------------------ + /** + * Return true if we should show the refresh action in the popup for the given element. + */ + public boolean showRefresh(Object element) + { + return false; + } + + // ------------------------------------------------------------ + // METHODS TO SUPPORT COMMON OPEN-IN-NEW-PERSPECTIVE ACTIONS... + // ------------------------------------------------------------ + /** + * Return true if we should show the refresh action in the popup for the given element. + */ + public boolean showOpenViewActions(Object element) + { + return false; + } + + // ------------------------------------------ + // METHODS TO SUPPORT COMMON RENAME ACTION... + // ------------------------------------------ + + /** + * Return true if we should show the rename action in the popup for the given element. + * If true, then canRename will be called to decide whether to enable rename or not. + */ + public boolean showRename(Object element) + { + return false; + } + /** + * Return true if this object is renamable by the user. If so, when selected, + * the Rename popup menu item will be enabled. + * By default, returns false. Override if your object is renamable. + */ + public boolean canRename(Object element) + { + return false; + } + + /** + * Perform the rename action. By default does nothing. Override if your object is renamable. + * Return true if this was successful. Return false if it failed and you issued a msg. + * Throw an exception if it failed and you want to use the generic msg. + */ + public boolean doRename(Shell shell, Object element, String name) throws Exception + { + //com.ibm.etools.systems.core.ui.SystemMessage.displayErrorMessage("INSIDE DORENAME"); + return false; + } + + // Drag and drop + + /** + * Indicates whether the specified object can have another object copied to it + * @param element the object to copy to + * @return whether this object can be copied to or not + */ + public boolean canDrop(Object element) + { + /*DKM -for now disabling - the function doesn't + * make sense for other types of prompts like + * RAD4z + if (element instanceof IRemoteOutput) + { + IRemoteOutput output = (IRemoteOutput) element; + if (output.getType().equals(TYPE_PROMPT)) + { + return true; + } + } + */ + + return false; + } + + /** + * Indicates whether the specified object can be copied + * @param element the object to copy + */ + public boolean canDrag(Object element) + { + if (element instanceof IRemoteOutput) + { + return true; + } + else if (element instanceof IRemoteCommandShell) + { + return true; + } + + return false; + } + + /** + * Copy the specified remote output object. This method returns a string representing + * the text of the remote output; + * + * @param element the output to copy + * @param sameSystemType not applicable for remote output + * @param monitor the progress monitor + */ + public Object doDrag(Object element, boolean sameSystemType, IProgressMonitor monitor) + { + if (element instanceof List) + { + List resultSet = new ArrayList(); + List set = (List)element; + for (int i = 0; i < set.size(); i++) + { + resultSet.add(getText(set.get(i))); + } + return resultSet; + } + else + { + return getText(element); + } + } + + /** + * Return true if it is valid for the src object to be dropped in the target + * @param src the object to drop + * @param target the object which src is dropped in + * @param sameSystem whether this is the same system + * @return whether this is a valid operation + */ + public boolean validateDrop(Object src, Object target, boolean sameSystem) + { + if (target instanceof IRemoteOutput) + { + IRemoteOutput targetOutput = (IRemoteOutput) target; + if (targetOutput.getType().equals(TYPE_PROMPT)) + { + if (src instanceof IRemoteFile) + { + return true; + } + else if (src instanceof IResource) + { + return true; + } + else if (src instanceof String) + { + return true; + } + } + } + return false; + } + + /** + * Perform a copy via drag and drop. + * @param src the object to be copied. If the target and source are not on the same system, then this is a + * temporary object produced by the doDrag. + * @param target the object to be copied to. + * @param sameSystem an indication whether the target and source reside on the same type of system + * @param indicates the type of source + * @param monitor the progress monitor + * @return an indication whether the operation was successful or not. + */ + public Object doDrop(Object src, Object target, boolean sameSystemType, boolean sameSystem, int srcType, IProgressMonitor monitor) + { + IRemoteFile folder = outputToFile((IRemoteOutput) target); + if (folder != null) + { + ISystemDragDropAdapter adapter = (ISystemDragDropAdapter) ((IAdaptable) folder).getAdapter(ISystemDragDropAdapter.class); + return adapter.doDrop(src, folder, sameSystemType, sameSystem, srcType, monitor); + } + return null; + } + + /** + * Determines whether the line of remote output can be edited in an editor + * @param element the remote output object + * @return true if this can be edited in an editor + */ + public boolean canEdit(Object element) + { + if (element instanceof IRemoteOutput) + { + IRemoteOutput output = (IRemoteOutput) element; + IRemoteFile file = outputToFile(output); + if (file != null && file.isFile()) + { + return true; + } + } + return false; + } + + /** + * Returns the associated remote editable object for this line of output + * @param element the remote output object + * @return the associated ediable object if one exists + */ + public ISystemEditableRemoteObject getEditableRemoteObject(Object element) + { + if (element instanceof IRemoteOutput) + { + IRemoteOutput output = (IRemoteOutput) element; + IRemoteFile file = outputToFile(output); + if (file != null && file.isFile()) + { + return new SystemEditableRemoteFile(file); + } + } + return null; + } + + /** + * Return a filter string that corresponds to this object. + * @param object the object to obtain a filter string for + * @return the corresponding filter string if applicable + */ + public String getFilterStringFor(Object object) + { + return null; + } + + protected IPropertyDescriptor[] internalGetPropertyDescriptors() + { + return getUniquePropertyDescriptors(); + } + + public IPropertyDescriptor[] getUniquePropertyDescriptors() + { + if (propertySourceInput instanceof IRemoteCommandShell) + { + if (_shellPropertyDescriptors == null) + { + _shellPropertyDescriptors = new IPropertyDescriptor[2]; + + _shellPropertyDescriptors[0] = createSimplePropertyDescriptor(P_SHELL_STATUS, SystemViewResources.RESID_PROPERTY_SHELL_STATUS_LABEL, SystemViewResources.RESID_PROPERTY_SHELL_STATUS_TOOLTIP); + _shellPropertyDescriptors[1] = createSimplePropertyDescriptor(P_SHELL_CONTEXT, SystemViewResources.RESID_PROPERTY_SHELL_CONTEXT_LABEL, SystemViewResources.RESID_PROPERTY_SHELL_CONTEXT_TOOLTIP); + } + return _shellPropertyDescriptors; + } + else + { + if (_outputPropertyDescriptors == null) + { + _outputPropertyDescriptors = new IPropertyDescriptor[0]; + } + return _outputPropertyDescriptors; + } + } + + /** + * Returns the current value for the named property. + * + * @param property the name or key of the property as named by its property descriptor + * @param formatted indication of whether to return the value in formatted or raw form + * @return the current value of the given property + */ + public Object getPropertyValue(Object property, boolean formatted) + { + String name = (String) property; + if (propertySourceInput instanceof IRemoteCommandShell) + { + IRemoteCommandShell cmdShell = (IRemoteCommandShell) propertySourceInput; + if (name.equals(ISystemPropertyConstants.P_SHELL_STATUS)) + { + if (cmdShell.isActive()) + { + return SystemViewResources.RESID_PROPERTY_SHELL_STATUS_ACTIVE_VALUE; + } + else + { + return SystemViewResources.RESID_PROPERTY_SHELL_STATUS_INACTIVE_VALUE; + } + } + else if (name.equals(ISystemPropertyConstants.P_SHELL_CONTEXT)) + { + Object context = cmdShell.getContext(); + if (context instanceof IRemoteFile) + { + IRemoteFile cwd = (IRemoteFile)context; + if (cwd != null) + { + return cwd.getAbsolutePath(); + } + } + else + { + return context; + } + } + } + return ""; + } + + + /** + * Returns false. + * @see org.eclipse.rse.ui.view.ISystemRemoteElementAdapter#supportsUserDefinedActions(java.lang.Object) + */ + public boolean supportsUserDefinedActions(Object object) { + return false; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/TabFolderLayout.java b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/TabFolderLayout.java new file mode 100644 index 00000000000..65835a85f7c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.shells.ui/src/org/eclipse/rse/shells/ui/view/TabFolderLayout.java @@ -0,0 +1,61 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.shells.ui.view; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Layout; + +public class TabFolderLayout extends Layout { + + + + protected Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache) { + if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) + return new Point(wHint, hHint); + + Control [] children = composite.getChildren (); + int count = children.length; + int maxWidth = 0, maxHeight = 0; + for (int i=0; i + + + + + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/.cvsignore b/rse/plugins/org.eclipse.rse.subsystems.files.core/.cvsignore new file mode 100644 index 00000000000..ba077a4031a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/.project b/rse/plugins/org.eclipse.rse.subsystems.files.core/.project new file mode 100644 index 00000000000..4629439dad0 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/.project @@ -0,0 +1,28 @@ + + + org.eclipse.rse.subsystems.files.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.subsystems.files.core/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..b3eae6deb1f --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin.name +Bundle-SymbolicName: org.eclipse.rse.subsystems.files.core +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.rse.subsystems.files.core.Activator +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.rse.services, + org.eclipse.core.resources, + org.eclipse.rse.ui +Eclipse-LazyStart: true +Export-Package: org.eclipse.rse.internal.subsystems.files.core, + org.eclipse.rse.subsystems.files.core, + org.eclipse.rse.subsystems.files.core.model, + org.eclipse.rse.subsystems.files.core.servicesubsystem, + org.eclipse.rse.subsystems.files.core.subsystems, + org.eclipse.rse.subsystems.files.core.util +Bundle-Vendor: Eclipse.org +Bundle-ClassPath: files_core.jar diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/about.html b/rse/plugins/org.eclipse.rse.subsystems.files.core/about.html new file mode 100644 index 00000000000..6f6b96c4c87 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/about.html @@ -0,0 +1,22 @@ + + + +About + + + +

About This Content

+ +

February 24, 2005

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content.

+ + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/build.properties b/rse/plugins/org.eclipse.rse.subsystems.files.core/build.properties new file mode 100644 index 00000000000..33d4ab4e9d6 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/build.properties @@ -0,0 +1,10 @@ +bin.includes = META-INF/,\ + about.html,\ + plugin.properties,\ + files_core.jar +src.includes = META-INF/,\ + about.html,\ + plugin.properties +jars.compile.order = files_core.jar +source.files_core.jar = src/ +output.files_core.jar = bin/ diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/plugin.properties b/rse/plugins/org.eclipse.rse.subsystems.files.core/plugin.properties new file mode 100644 index 00000000000..7cad38f347a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/plugin.properties @@ -0,0 +1,12 @@ +############################################################################### +# Copyright (c) 2000, 2006 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 +############################################################################### + +plugin.name = RSE Files Core diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/AbstractJavaLanguageUtility.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/AbstractJavaLanguageUtility.java new file mode 100644 index 00000000000..179089670d4 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/AbstractJavaLanguageUtility.java @@ -0,0 +1,34 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.files.core; + +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; + +/** + * This class is a Java language utility. + */ +public abstract class AbstractJavaLanguageUtility extends AbstractLanguageUtility implements IJavaLanguageUtility { + + /** + * Constructor. + * @param subsystem the subsystem with which the utility is associated. + * @param language the language. + */ + public AbstractJavaLanguageUtility(IRemoteFileSubSystem subsystem, String language) { + super(subsystem, language); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/AbstractLanguageUtility.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/AbstractLanguageUtility.java new file mode 100644 index 00000000000..d97b14f40a1 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/AbstractLanguageUtility.java @@ -0,0 +1,72 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.files.core; + +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; + +/** + * Abstract class for language utility. Language utilities are expected to subclass + * it. + */ +public abstract class AbstractLanguageUtility implements ILanguageUtility { + + protected IRemoteFileSubSystem subsystem; + protected String language; + + /** + * Constructor. + * @param subsystem the subsystem with which the utility is associated. + * @param language the language. + */ + protected AbstractLanguageUtility(IRemoteFileSubSystem subsystem, String language) { + super(); + setSubSystem(subsystem); + setLanguage(language); + } + + /** + * Sets the subsystem with which the utility is associated. + * @param the subsystem. + */ + private void setSubSystem(IRemoteFileSubSystem subsystem) { + this.subsystem = subsystem; + } + + /** + * Sets the language to which this utility applies. It could be one of + * LANGUAGE_JAVA, LANGUAGE_C, and LANGUAGE_CPP, or + * another language. + * @return the language. + */ + private void setLanguage(String language) { + this.language = language; + } + + /** + * @see org.eclipse.rse.internal.subsystems.files.core.ILanguageUtility#getSubSystem() + */ + public IRemoteFileSubSystem getSubSystem() { + return subsystem; + } + + /** + * @see org.eclipse.rse.internal.subsystems.files.core.ILanguageUtility#getLanguage() + */ + public String getLanguage() { + return language; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/AbstractLanguageUtilityFactory.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/AbstractLanguageUtilityFactory.java new file mode 100644 index 00000000000..8d015ce9cf7 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/AbstractLanguageUtilityFactory.java @@ -0,0 +1,59 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.files.core; + +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; + +/** + * A language utility factory associated with a subsystem. + */ +public abstract class AbstractLanguageUtilityFactory implements ILanguageUtilityFactory { + + protected IRemoteFileSubSystem subsystem; + + /** + * Constructor. + * @param subsystem the subsystem with which this factory is associated. + */ + protected AbstractLanguageUtilityFactory(IRemoteFileSubSystem subsystem) { + super(); + setSubSystem(subsystem); + } + + /** + * Sets the subsystem with which the factory is associated. + * @param subsystem the subsystem. + */ + private void setSubSystem(IRemoteFileSubSystem subsystem) { + this.subsystem = subsystem; + } + + /** + * @see org.eclipse.rse.internal.subsystems.files.core.ILanguageUtilityFactory#getSubSystem() + */ + public IRemoteFileSubSystem getSubSystem() { + return subsystem; + } + + /** + * For Java, subclasses should return an instance of IJavaLanguageUtility + * @see org.eclipse.rse.internal.subsystems.files.core.ILanguageUtilityFactory#getUtility(java.lang.String) + * + * @see IJavaLanguageUtility + */ + public abstract ILanguageUtility getUtility(String language); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/IJavaLanguageUtility.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/IJavaLanguageUtility.java new file mode 100644 index 00000000000..ce75bd02cf7 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/IJavaLanguageUtility.java @@ -0,0 +1,32 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.files.core; + +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; + +/** + * Interface for Java language utility. + */ +public interface IJavaLanguageUtility extends ILanguageUtility { + + /** + * Returns the qualified class name for the remote file. + * @param remoteFile the remote file. + * @return the qualified class name. + */ + public String getQualifiedClassName(IRemoteFile remoteFile); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/ILanguageUtility.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/ILanguageUtility.java new file mode 100644 index 00000000000..90c72db4ce6 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/ILanguageUtility.java @@ -0,0 +1,55 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.files.core; + +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; + +/** + * Interface for a language utility. Each programming language should have its own utility, + * for example Java, C/C++, etc. + */ +public interface ILanguageUtility { + + /** + * Constant for Java language. + */ + public static final String LANGUAGE_JAVA = "Java"; + + /** + * Constant for C language. + */ + public static final String LANGUAGE_C = "C"; + + /** + * Constant for C++ language. + */ + public static final String LANGUAGE_CPP = "C++"; + + /** + * Returns the subsystem with which the utility is associated. + * @return the subsystem. + */ + public IRemoteFileSubSystem getSubSystem(); + + /** + * Returns the language to which this utility applies. It could be one of + * LANGUAGE_JAVA, LANGUAGE_C, and LANGUAGE_CPP, or + * another language. + * @return the language. + */ + public String getLanguage(); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/ILanguageUtilityFactory.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/ILanguageUtilityFactory.java new file mode 100644 index 00000000000..92d62838772 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/ILanguageUtilityFactory.java @@ -0,0 +1,44 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.files.core; + +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; + +/** + * A factory for creating language specific utility. + */ +public interface ILanguageUtilityFactory { + + /** + * Returns the subsystem with which the factory is associated. + * @return the subsystem. + */ + public IRemoteFileSubSystem getSubSystem(); + + /** + * Returns the language utility for the given language identifier. + * Identifiers for popular languages are available in ILanguageUtility. + * For Java, the identifier is LANGUAGE_JAVA. + * For C, the identifier is LANGUAGE_C. + * For C++, the identifier is LANGUAGE_CPP. + * @param language the language identifier. + * @return the language utility. + * + * @see ILanguageUtility + */ + public ILanguageUtility getUtility(String language); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/SystemFileAPIProviderImpl.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/SystemFileAPIProviderImpl.java new file mode 100644 index 00000000000..4cdfabdd34d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/SystemFileAPIProviderImpl.java @@ -0,0 +1,185 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.files.core; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.model.ISystemRegistry; +import org.eclipse.rse.subsystems.files.core.model.ISystemFileAPIProvider; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.ui.view.SystemAbstractAPIProvider; + + +/** + * Where to start when looking to traverse a remote file system. + */ +public class SystemFileAPIProviderImpl + extends SystemAbstractAPIProvider + implements ISystemFileAPIProvider +{ + + + protected ISystemRegistry sr = null; + protected boolean directoryMode = false; + //protected Object[] emptyList = new Object[0]; + + /** + * Constructor for SystemFileAPIProvider + * @param directoryMode true if you only want to traverse directories, false for both files and directories. + */ + public SystemFileAPIProviderImpl(boolean directoryMode) + { + super(); + this.directoryMode = directoryMode; + sr = SystemPlugin.getTheSystemRegistry(); + } + + /** + * Get the directories-only mode. + */ + public boolean isDirectoriesOnly() + { + return directoryMode; + } + + // ---------------------------------- + // SYSTEMVIEWINPUTPROVIDER METHODS... + // ---------------------------------- + /** + * Return the children objects to consistute the root elements in the system view tree. + * We return all connections containing a remote file subsystem, for all active profiles. + */ + public Object[] getSystemViewRoots() + { + + return getConnections(); + } + /** + * Return true if {@link #getSystemViewRoots()} will return a non-empty list + * We return true if there are any connections containing a remote file subsystem, for any active profile. + */ + public boolean hasSystemViewRoots() + { + return (getConnectionCount()>0); + } + /** + * This method is called by the connection adapter when the user expands + * a connection. This method must return the child objects to show for that + * connection. + */ + public Object[] getConnectionChildren(IHost selectedConnection) + { + return sr.getConnectionChildren(selectedConnection); + } + /** + * This method is called by the connection adapter when deciding to show a plus-sign + * or not beside a connection. Return true if this connection has children to be shown. + */ + public boolean hasConnectionChildren(IHost selectedConnection) + { + return sr.hasConnectionChildren(selectedConnection); + } + + /** + * Return true to show the action bar (ie, toolbar) above the viewer. + * The action bar contains connection actions, predominantly. + */ + public boolean showActionBar() + { + return true; + } + /** + * Return true to show the button bar above the viewer. + * The tool bar contains "Get List" and "Refresh" buttons and is typicall + * shown in dialogs that list only remote system objects. + */ + public boolean showButtonBar() + { + return false; + } + /** + * Return true to show right-click popup actions on objects in the tree. + */ + public boolean showActions() + { + return true; + } + + + // ---------------------------------- + // OUR OWN METHODS... + // ---------------------------------- + + /** + * Return all connections which have at least one subsystem that implements/extends RemoteFileSubSystem + */ + public IHost[] getConnections() + { + int connCount = getConnectionCount(); + IHost[] ourConns = new IHost[connCount]; + IHost[] allConns = sr.getHosts(); + int ourConnsIdx = 0; + if (allConns != null) + { + for (int idx=0; idx full get; do restore from disk if not already + return ((allOurSubSystems!=null) && (allOurSubSystems.length>0)); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/SystemRemoteDirectoryMatcher.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/SystemRemoteDirectoryMatcher.java new file mode 100644 index 00000000000..0436fb3c0bb --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/internal/subsystems/files/core/SystemRemoteDirectoryMatcher.java @@ -0,0 +1,61 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.files.core; +import org.eclipse.rse.core.SystemRemoteObjectMatcher; +import org.eclipse.rse.subsystems.files.core.model.ISystemFileRemoteTypes; + + + +/** + * This class encapsulates all the criteria required to identify a match on a remote + * system directory object. + *

+ * Use the static method {@link #getDirectoryMatcher()} + * to get an default instance that matches on any directory of any name. + *

+ * You only need to instantiate this class if you want to match on a directory of a + * particular name. + * @see org.eclipse.rse.ui.view.ISystemRemoteElementAdapter + */ +public class SystemRemoteDirectoryMatcher extends SystemRemoteObjectMatcher +{ + public static SystemRemoteDirectoryMatcher inst = null; + //public static final String factoryId = com.ibm.etools.systems.as400filesubsys.FileSubSystemFactory.factoryId; + public static final String category = ISystemFileRemoteTypes.TYPECATEGORY; + public static final String type = ISystemFileRemoteTypes.TYPE_FOLDER; + + /** + * Constructor. + * You only need to instantiate yourself if you want to match on a directory + * of a particular name. + * Otherwise, call {@link #getDirectoryMatcher()}. + */ + public SystemRemoteDirectoryMatcher(String nameFilter) + { + super(null, category, nameFilter, type, null, null); + } + + /** + * Return an instance that will match on any directory of any name from any remote system + */ + public static SystemRemoteDirectoryMatcher getDirectoryMatcher() + { + if (inst == null) + inst = new SystemRemoteDirectoryMatcher(null); + return inst; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/Activator.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/Activator.java new file mode 100644 index 00000000000..15ebb0ce911 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/Activator.java @@ -0,0 +1,70 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core; + +import org.eclipse.ui.plugin.*; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class Activator extends AbstractUIPlugin { + + //The shared instance. + private static Activator plugin; + + /** + * The constructor. + */ + public Activator() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static Activator getDefault() { + 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.subsystems.files.core", path); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/SystemFileResources.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/SystemFileResources.java new file mode 100644 index 00000000000..a4010137105 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/SystemFileResources.java @@ -0,0 +1,185 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core; + +import org.eclipse.osgi.util.NLS; + + +public class SystemFileResources extends NLS +{ + private static String BUNDLE_NAME = "org.eclipse.rse.subsystems.files.core.SystemFileResources"; //$NON-NLS-1$ + + // ------------------- + // DEFAULT FILTERS... + // ------------------- + public static String RESID_FILTER_ROOTS; + public static String RESID_FILTER_ROOTFILES; + public static String RESID_FILTER_ROOTFOLDERS; + public static String RESID_FILTER_DRIVES; + public static String RESID_FILTER_HOME; + public static String RESID_FILTER_USERHOME; + public static String RESID_FILTER_MYHOME; + + // ------------------------- + // MISCELLANEOUS... + // ------------------------- + public static String RESID_PROPERTY_FILE_FILTER_VALUE; + + // ------------------------- + // WIZARDS... + // ------------------------- + + // New System File Filter wizard... + public static String RESID_NEWFILEFILTER_PAGE1_TITLE; + public static String RESID_NEWFILEFILTER_PAGE1_DESCRIPTION; + + // New Filter String wizard... + public static String RESID_NEWFILTERSTRING_TITLE; + public static String RESID_NEWFILTERSTRING_PAGE1_TITLE; + public static String RESID_NEWFILTERSTRING_PAGE1_DESCRIPTION; + + // File Filter String Re-Usable form (used in dialog and wizard) + + public static String RESID_FILEFILTERSTRING_FOLDER_LABEL; + public static String RESID_FILEFILTERSTRING_FILE_LABEL; + public static String RESID_FILEFILTERSTRING_INCFOLDERS_LABEL; + public static String RESID_FILEFILTERSTRING_INCFILES_LABEL; + public static String RESID_FILEFILTERSTRING_INCFILESONLY_LABEL; + public static String RESID_FILEFILTERSTRING_BYFILENAME_LABEL; + public static String RESID_FILEFILTERSTRING_BYFILETYPES_LABEL; + public static String RESID_FILEFILTERSTRING_TYPES_LABEL; + public static String RESID_FILEFILTERSTRING_SELECTTYPES_LABEL; + public static String RESID_FILEFILTERSTRING_TEST_LABEL; + + public static String RESID_FILEFILTERSTRING_FOLDER_TOOLTIP; + public static String RESID_FILEFILTERSTRING_FILE_TOOLTIP; + public static String RESID_FILEFILTERSTRING_INCFOLDERS_TOOLTIP; + public static String RESID_FILEFILTERSTRING_INCFILES_TOOLTIP; + public static String RESID_FILEFILTERSTRING_INCFILESONLY_TOOLTIP; + public static String RESID_FILEFILTERSTRING_BYFILENAME_TOOLTIP; + public static String RESID_FILEFILTERSTRING_BYFILETYPES_TOOLTIP; + public static String RESID_FILEFILTERSTRING_TYPES_TOOLTIP; + public static String RESID_FILEFILTERSTRING_SELECTTYPES_TOOLTIP; + public static String RESID_FILEFILTERSTRING_TEST_TOOLTIP; + + // ------------------------- + // DIALOGS... + // ------------------------- + // Change System File Filter dialog... + public static String RESID_CHGFILEFILTER_TITLE; + + // Change System File Filter String dialog... + public static String RESID_CHGFILEFILTERSTRING_TITLE; + + // Select Directory dialog... + public static String RESID_SELECTDIRECTORY_TITLE; + public static String RESID_SELECTDIRECTORY_VERBAGE; + public static String RESID_SELECTDIRECTORY_SELECT_LABEL; + public static String RESID_SELECTDIRECTORY_SELECT_TOOLTIP; + + // Select File dialog... + public static String RESID_SELECTFILE_TITLE; + public static String RESID_SELECTFILE_VERBAGE; + public static String RESID_SELECTFILE_SELECT_LABEL; + public static String RESID_SELECTFILE_SELECT_TOOLTIP; + + // Prompt for home folder dialog... + public static String RESID_HOMEPROMPT_TITLE; + public static String RESID_HOMEPROMPT_VERBAGE; + public static String RESID_HOMEPROMPT_PROMPT_LABEL; + public static String RESID_HOMEPROMPT_PROMPT_TOOLTIP; + + // ------------------------- + // ACTIONS... + // ------------------------- + public static String ACTION_NEWFILTER_LABEL; + public static String ACTION_NEWFILTER_TOOLTIP; + + public static String ACTION_NEWNESTEDFILTER_LABEL; + public static String ACTION_NEWNESTEDFILTER_TOOLTIP; + + + public static String ACTION_NEWFILTERSTRING_LABEL; + public static String ACTION_NEWFILTERSTRING_TOOLTIP; + + public static String ACTION_ADDFILTERSTRING_LABEL; + public static String ACTION_AddFILTERSTRING_TOOLTIP; + + public static String ACTION_UPDATEFILTERSTRING_LABEL; + public static String ACTION_UPDATEFILTERSTRING_TOOLTIP; + + public static String ACTION_SELECTFILETYPES_LABEL; + public static String ACTION_SELECTFILETYPES_TOOLTIP; + + // ------------------------- + // WIDGETS... + // ------------------------- + public static String WIDGET_FOLDER_LABEL; + public static String WIDGET_FOLDER_TOOLTIP; + + public static String WIDGET_BROWSE_LABEL; + public static String WIDGET_BROWSE_TOOLTIP; + + // ------------------------- + // PROPERTY PAGES... + // ------------------------- + public static String RESID_PP_FILE_TITLE; + public static String RESID_PP_FILE_TYPE_LABEL; + public static String RESID_PP_FILE_TYPE_TOOLTIP; + public static String RESID_PP_FILE_TYPE_FILE_VALUE; + public static String RESID_PP_FILE_TYPE_FOLDER_VALUE; + public static String RESID_PP_FILE_TYPE_ROOT_VALUE; + public static String RESID_PP_FILE_NAME_LABEL; + public static String RESID_PP_FILE_PATH_LABEL; + public static String RESID_PP_FILE_SIZE_LABEL; + public static String RESID_PP_FILE_SIZE_VALUE; + public static String RESID_PP_FILE_MODIFIED_LABEL; + public static String RESID_PP_FILE_READONLY_LABEL; + public static String RESID_PP_FILE_WRITABLE_LABEL; + public static String RESID_PP_FILE_HIDDEN_LABEL; + + public static String RESID_PP_FILE_NAME_TOOLTIP; + public static String RESID_PP_FILE_PATH_TOOLTIP; + public static String RESID_PP_FILE_SIZE_TOOLTIP; + public static String RESID_PP_FILE_MODIFIED_TOOLTIP; + public static String RESID_PP_FILE_READONLY_TOOLTIP; + public static String RESID_PP_FILE_READABLE_TOOLTIP; + public static String RESID_PP_FILE_WRITABLE_TOOLTIP; + public static String RESID_PP_FILE_HIDDEN_TOOLTIP; + + // ------------------------------- + // Enter or select file form + // ------------------------------- + public static String RESID_ENTER_OR_SELECT_FILE_TITLE; + public static String RESID_ENTER_OR_SELECT_FILE_VERBAGE_LABEL; + public static String RESID_ENTER_OR_SELECT_FILE_ENTER_LABEL; + public static String RESID_ENTER_OR_SELECT_FILE_ENTER_TOOLTIP; + public static String RESID_ENTER_OR_SELECT_FILE_SELECT_TOOLTIP; + public static String RESID_ENTER_OR_SELECT_FILE_FILE_LABEL; + public static String RESID_ENTER_OR_SELECT_FILE_FILE_TOOLTIP; + + public static String RESID_JOB_SEARCH_NAME; + public static String RESID_JOB_DECORATEFILES_NAME; + + public static String RESID_FTP_CONNECTORSERVICE_NAME; + public static String RESID_FTP_CONNECTORSERVICE_DESCRIPTION; + + static { + // load message values from bundle file + NLS.initializeMessages(BUNDLE_NAME, SystemFileResources.class); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/SystemFileResources.properties b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/SystemFileResources.properties new file mode 100644 index 00000000000..b841ab90b88 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/SystemFileResources.properties @@ -0,0 +1,218 @@ +################################################################################ +# Copyright (c) 2000, 2006 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: +# {Name} (company) - description of contribution. +################################################################################ + +# NLS_MESSAGEFORMAT_NONE + +############################################################## +# Button values. Mnemonics will be assigned automatically, don't set them here. +############################################################## + + +#============================================================= +# FILE SUBSYSTEM ACTIONS... +#============================================================= +ACTION_NEWFILTER_LABEL=Filter... +ACTION_NEWFILTER_TOOLTIP=Create a new file system filter + +ACTION_NEWNESTEDFILTER_LABEL=Nested Filter... +ACTION_NEWNESTEDFILTER_TOOLTIP=Create a new file system filter within the selected filter + + +ACTION_NEWFILTERSTRING_LABEL=Filter String... +ACTION_NEWFILTERSTRING_TOOLTIP=Create a new file filter string + +ACTION_ADDFILTERSTRING_LABEL=Add... +ACTION_AddFILTERSTRING_TOOLTIP=Create a new file filter string + +ACTION_UPDATEFILTERSTRING_LABEL=Change +ACTION_UPDATEFILTERSTRING_TOOLTIP=Edit this filter string + +ACTION_SELECTFILETYPES_LABEL=Select... +ACTION_SELECTFILETYPES_TOOLTIP=Select file types + + +############################################################## +# REMOTE FILE SYSTEM TRANSLATABLE STRINGS +############################################################## +#============================================================= +# DEFAULT FILTERS... +#============================================================= +RESID_FILTER_ROOTS=Roots +RESID_FILTER_ROOTFILES=Root +RESID_FILTER_ROOTFOLDERS=Folders +RESID_FILTER_DRIVES=Drives +RESID_FILTER_HOME=Home +RESID_FILTER_USERHOME=Home +RESID_FILTER_MYHOME=My Home +#============================================================= +# NEW FILE FILTER WIZARD... +#============================================================= +RESID_NEWFILEFILTER_PAGE1_TITLE=File Filter +RESID_NEWFILEFILTER_PAGE1_DESCRIPTION=Create a file filter + +#============================================================= +# NEW FILE FILTER STRING WIZARD... +#============================================================= +RESID_NEWFILTERSTRING_TITLE=New File Filter String +RESID_NEWFILTERSTRING_PAGE1_TITLE=File Filter String +RESID_NEWFILTERSTRING_PAGE1_DESCRIPTION=Create a file name filter string + + +#============================================================= +# CHANGE FILE FILTER DIALOG... +#============================================================= +RESID_CHGFILEFILTER_TITLE=Change File Filter + +#============================================================= +# CHANGE FILE FILTER STRING DIALOG... +#============================================================= +RESID_CHGFILEFILTERSTRING_TITLE=Change File Filter String + +#============================================================= +# SELECT DIRECTORY DIALOG... +#============================================================= +RESID_SELECTDIRECTORY_TITLE=Browse For Folder +RESID_SELECTDIRECTORY_VERBAGE=Select a folder +RESID_SELECTDIRECTORY_SELECT_LABEL=Selected folder: +RESID_SELECTDIRECTORY_SELECT_TOOLTIP=Expand tree and select folder + +#============================================================= +# SELECT FILE DIALOG... +#============================================================= +RESID_SELECTFILE_TITLE=Browse For File +RESID_SELECTFILE_VERBAGE=Select a file +RESID_SELECTFILE_SELECT_LABEL=Selected file: +RESID_SELECTFILE_SELECT_TOOLTIP=Expand tree and select file + +#============================================================= +# PROMPT FOR HOME FOLDER DIALOG... +#============================================================= +RESID_HOMEPROMPT_TITLE=Prompt For Home Folder + +RESID_HOMEPROMPT_VERBAGE=Please enter or select your personal home folder for this remote system +RESID_HOMEPROMPT_PROMPT_LABEL=Home folder +RESID_HOMEPROMPT_PROMPT_TOOLTIP=Enter or select the folder assigned to your user ID + + + +#============================================================= +# REMOTE FILE SYSTEM PROPERTY VALUES +#============================================================= +RESID_PROPERTY_FILE_FILTER_VALUE=File filter + +#============================================================= +# REMOTE FILE PROPERTIES PAGE... +#============================================================= +RESID_PP_FILE_TITLE=Properties for File System Object +RESID_PP_FILE_TYPE_ROOT_VALUE=Root +RESID_PP_FILE_TYPE_FOLDER_VALUE=Folder +RESID_PP_FILE_TYPE_FILE_VALUE=File +RESID_PP_FILE_SIZE_VALUE=&1 bytes + + +#============================================================= +# ENTER OR SELECT FILE DIALOG... +#============================================================= +RESID_ENTER_OR_SELECT_FILE_TITLE= Specify File +RESID_ENTER_OR_SELECT_FILE_VERBAGE_LABEL= Enter or select a file +RESID_ENTER_OR_SELECT_FILE_ENTER_LABEL= Enter parent folder: +RESID_ENTER_OR_SELECT_FILE_ENTER_TOOLTIP= Enter the path of the parent folder +RESID_ENTER_OR_SELECT_FILE_SELECT_TOOLTIP= Expand tree and select file or parent folder +RESID_ENTER_OR_SELECT_FILE_FILE_LABEL= File name: +RESID_ENTER_OR_SELECT_FILE_FILE_TOOLTIP= Enter the name of the file + + +#============================================================= +# NEW FILTER WIZARD... +#============================================================= + + +RESID_FILEFILTERSTRING_FOLDER_LABEL=Folder path +RESID_FILEFILTERSTRING_FOLDER_TOOLTIP=Folder containing the files to list +RESID_FILEFILTERSTRING_FILE_LABEL=File name filter +RESID_FILEFILTERSTRING_FILE_TOOLTIP=File name filter pattern + +RESID_FILEFILTERSTRING_INCFOLDERS_LABEL=Include folders +RESID_FILEFILTERSTRING_INCFOLDERS_TOOLTIP=Select to includes folders in the list + +RESID_FILEFILTERSTRING_INCFILES_LABEL=Include files +RESID_FILEFILTERSTRING_INCFILES_TOOLTIP=Select to includes files in the list + +RESID_FILEFILTERSTRING_INCFILESONLY_LABEL=Show files only +RESID_FILEFILTERSTRING_INCFILESONLY_TOOLTIP=Select to exclude folders from the list + + +RESID_FILEFILTERSTRING_BYFILENAME_LABEL=Subset by file name +RESID_FILEFILTERSTRING_BYFILENAME_TOOLTIP=Select to subset the list by generic file name + +RESID_FILEFILTERSTRING_BYFILETYPES_LABEL=Subset by file types +RESID_FILEFILTERSTRING_BYFILETYPES_TOOLTIP=Select to subset the list by one or more file types + +RESID_FILEFILTERSTRING_TYPES_LABEL=File types filter +RESID_FILEFILTERSTRING_TYPES_TOOLTIP=Select the file types to restrict the list by + + +RESID_FILEFILTERSTRING_SELECTTYPES_LABEL=Select... +RESID_FILEFILTERSTRING_SELECTTYPES_TOOLTIP=Select the file types to subset the list by + + +RESID_FILEFILTERSTRING_TEST_LABEL=Test... +RESID_FILEFILTERSTRING_TEST_TOOLTIP=Display results of running this filter string + + +RESID_PP_FILE_PATH_LABEL=Location: +RESID_PP_FILE_PATH_TOOLTIP=Path of the remote file or folder + +RESID_PP_FILE_NAME_LABEL=Name: +RESID_PP_FILE_NAME_TOOLTIP=Name of the remote file or folder + +RESID_PP_FILE_TYPE_LABEL=Object type: +RESID_PP_FILE_TYPE_TOOLTIP=Type of the remote file or folder + +RESID_PP_FILE_SIZE_LABEL=Size: +RESID_PP_FILE_SIZE_TOOLTIP=Size in bytes of the remote file +RESID_PP_FILE_SIZE_VALUE=&1 bytes + +RESID_PP_FILE_MODIFIED_LABEL=Last modified: +RESID_PP_FILE_MODIFIED_TOOLTIP=Date this file or folder was last modified + +RESID_PP_FILE_READONLY_LABEL=Read-only +RESID_PP_FILE_READONLY_TOOLTIP=Is this file or folder read-only + +RESID_PP_FILE_READABLE_TOOLTIP=Is reading of this file or folder permitted + +RESID_PP_FILE_WRITABLE_LABEL=Writable +RESID_PP_FILE_WRITABLE_TOOLTIP=Is reading of this file or folder permitted + +RESID_PP_FILE_HIDDEN_LABEL=Hidden +RESID_PP_FILE_HIDDEN_TOOLTIP=Is this file or folder typically hidden from lists + + + +#============================================================= +# RE-USABLE COMPOSITE FILE SYSTEM WIDGETS +#============================================================= +WIDGET_FOLDER_LABEL=Folder: +WIDGET_FOLDER_TOOLTIP=Select or specify folder path + +WIDGET_BROWSE_LABEL=Browse... +WIDGET_BROWSE_TOOLTIP=Browse for folder path + +RESID_JOB_SEARCH_NAME=Search +RESID_JOB_DECORATEFILES_NAME=Decorate Files + +RESID_FTP_CONNECTORSERVICE_NAME=FTP Connector Service +RESID_FTP_CONNECTORSERVICE_DESCRIPTION=The FTP Connector Service uses the FTP protocol to connect to a remote host. You must have an FTP daemon running on the host. \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/IRemotePath.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/IRemotePath.java new file mode 100644 index 00000000000..2143d27ac3f --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/IRemotePath.java @@ -0,0 +1,90 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.model; + +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; + +/** + * This interface represents a remote path. + */ +public interface IRemotePath { + + /** + * Returns the profile name. + * @return the profile name. + */ + public String getProfileName(); + + /** + * Returns the connection name. + * @return the connection name. + */ + public String getConnectionName(); + + /** + * Returns the absolute path. + * @return the absolute path. + */ + public String getAbsolutePath(); + + /** + * Returns the fully qualified path. The fully qualified path is the absolute path on the remote machine, + * prefixed by profile name and connection name. It is of the form "profileName.connectionName:absolutePath". + * If the profile name, connection name or absolute path is null, then the fully qualified path + * will also be null. + * @return the fully qualified path. + */ + public String getFullyQualifiedPath(); + + /** + * Returns the file extension for the path. The file extension portion is + * defined as the string following the last period (".") character in the path. + * @return the extension, or null if none. + */ + public String getFileExtension(); + + /** + * Returns a new path with the file extension added to this path. The file extension portion is + * defined as the string following the last period (".") character in the path. If this path ends + * with a separator, i.e. '/' or '\\', then this path is returned. + * The given extension should not include a leading ".". + * @param extension the file extension to append to the path. + * @return the new path. + */ + public IRemotePath addFileExtension(String extension); + + /** + * Returns a new path with the file extension removed from this path. The file extension portion is + * defined as the string following the last period (".") character in the path. If this path ends + * with a separator, i.e. '/' or '\\', or if it does not have an extension, then this path is returned. + * The given extension should not include a leading ".". + * @param the new path. + */ + public IRemotePath removeFileExtension(); + + /** + * Returns whether this path represents a virtual file. + * @return true if the path represents a virtual file, false otherwise. + */ + public boolean isVirtual(); + + /** + * Returns the remote file represented by the remote path. + * @return the remote file. + */ + public IRemoteFile toRemoteFile(); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileAPIProvider.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileAPIProvider.java new file mode 100644 index 00000000000..7dcc4465da1 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileAPIProvider.java @@ -0,0 +1,41 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.model; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.ui.view.ISystemViewInputProvider; + + + +/** + * Where to start when looking to traverse a remote file system + * @see org.eclipse.rse.internal.subsystems.files.core.SystemFileAPIProviderImpl + */ +public interface ISystemFileAPIProvider extends ISystemViewInputProvider +{ + /** + * Get the directories-only mode. + */ + public boolean isDirectoriesOnly(); + /** + * Return all connections which have at least one subsystem that implements/extends RemoteFileSubSystem + */ + public IHost[] getConnections(); + /** + * Return a count of all connections which have at least one subsystem that implements/extends RemoteFileSubSystem + */ + public int getConnectionCount(); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileRemoteTypes.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileRemoteTypes.java new file mode 100644 index 00000000000..d83f3649c5c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileRemoteTypes.java @@ -0,0 +1,66 @@ +/******************************************************************************** + * Copyright (c) 2000, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.model; +/** + * All remote object types we support. + * These can be used when registering property pages against remote universal file system objects. + */ +public interface ISystemFileRemoteTypes +{ + + // ------------------ + // TYPE CATEGORIES... + // ------------------ + + /** + * There is only one type category for remote files. + * It is "files". + */ + public static final String TYPECATEGORY = "files"; + /** + * There is only one type category for remote cmds. + * It is "cmds". + */ + public static final String TYPECMDCATEGORY = "cmds"; + + // ----------- + // TYPES... + // ----------- + + /** + * A folder object + */ + public static final String TYPE_FOLDER = "folder"; + /** + * A file object + */ + public static final String TYPE_FILE = "file"; + + // ----------- + // SUBTYPES... + // ----------- + + /** + * A folder object + */ + public static final String SUBTYPE_SUBFOLDER = "subfolder"; + /** + * A root object + */ + public static final String SUBTYPE_ROOT = "root"; + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileTransferModeMapping.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileTransferModeMapping.java new file mode 100644 index 00000000000..2011e6697f7 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileTransferModeMapping.java @@ -0,0 +1,62 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.model; + +public interface ISystemFileTransferModeMapping { + + + + + /** + * Get the extension + * + * @return the extension for the mapping + */ + public String getExtension(); + + + /** + * Get the label + * + * @return the label for the mapping + */ + public String getLabel(); + + + /** + * Get the name + * + * @return the name for the mapping + */ + public String getName(); + + + /** + * Returns if the mapping is binary + * + * @return true if binary, false if text + */ + public boolean isBinary(); + + + /** + * Returns if the mapping is text + * + * @return true if text, false if binary + */ + public boolean isText(); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileTransferModeRegistry.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileTransferModeRegistry.java new file mode 100644 index 00000000000..1478d110529 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileTransferModeRegistry.java @@ -0,0 +1,99 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.model; + + +import org.eclipse.core.resources.IFile; +import org.eclipse.rse.services.clientserver.ISystemFileTypes; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; + + + +public interface ISystemFileTransferModeRegistry extends ISystemFileTypes +{ + + // Default text file names + public static final String[] DEFAULT_TEXT_FILE_NAMES = {"application.xml", "build.properties", "fragment.xml", + "ibm-application-bnd.xmi", "ibm-application-ext.xmi", + "install.xml", "plugin.xml", "server-cfg.xml", "web.xml"}; + + // Default text file types + public static final String[] DEFAULT_TEXT_FILE_EXTENSIONS = {"conxmi", "css", "dad", "dadx", "dbxmi", "dtd", + "ent", "htm", "html", "html-ss", "jardesc", + "java", "jhtml", "jpage", "jsp", "nst", + "properties", "schxmi", "shtm", "shtml", "tblxmi", + "tld", "txt", "wsdl", "xhtml", "xmi", "xml", + "xsd", "xsl"}; + + // Default text file types that only we recognize through LPEX + public static final String[] DEFAULT_LPEX_TEXT_FILE_EXTENSIONS = {"app", "asm", "c", "c++", "cbl", "cc", "ccs", + "cmd", "cpp", "cpy", "cxx", "f", "f90", "f95", + "h", "h++", "hh", "hla", "hpp", "htm", "html", + "hxx", "inc", "inl", "jav", "java", "jcl", + "jj", "lx", "lxl", "lxu", "mac", "pli", "pro", + "properties", "rc", "rex", "rexx", "s", "sqc", + "sql", "sqlj", "xml", "xsl"}; + + // the following need to match what is in plugin.xml! */ + /* scrubbed by phil 10/16/2002... removed old code/400 extensions not used anymore, and added .cpy for cobol on ifs + public static final String[] DEFAULT_ISERIES_LPEX_TEXT_FILE_EXTENSIONS = {"c", "cbl", "cblle", "cicsc", + "cicscbl", "cicscblle", "cicssqlcbl", + "cl", "cle", "clle", "clp", "cmd", + "cpp", "cpple", "dsp", "dspf", + "dspf400", "icf", "icff", "icff400", + "irp", "lf", "lf4", "lf400", "mnudds", + "pf", "pf4", "pf400", "pnlgrp", "prt", + "prtf", "prtf400", "rpg", "rpg36", + "rpg38", "rpgle", "rpgleinc", "rpt", + "sir", "sqlc", "sqlcbl", "sqlcblle", + "sqlcpple", "sqlrpg", "sqlrpgle", + "srg"}; */ + public static final String[] DEFAULT_ISERIES_LPEX_TEXT_FILE_EXTENSIONS = {"c", "cbl", "cblle", "cicsc", + "cicscbl", "cicscblle", "cicssqlcbl", + "cl", "cle", "clle", "clp", "cmd", + "cob", + "cpp", "cpple", "cpy", "dspf", + "icff", + "lf", "mbr", "mnudds", + "pcml", + "pf", "pnlgrp", + "prtf", "rpg", "rpg36", + "rpg38", "rpgle", "rpgleinc", "rpt", + "sqlc", "sqlcbl", "sqlcblle", + "sqlcpple", "sqlrpg", "sqlrpgle", + }; + /* added by phil 10/16/2002... */ + public static final String[] DEFAULT_UNIX_LPEX_TEXT_FILE_EXTENSIONS = {"csh", "ksh", "mak", "pl", "profile", "py", + }; + + public static final String[] DEFAULT_BINARY_FILE_EXTENSIONS = {"xml", "jar", "zip", "tar", "exe", "gz", "z", + "gif","jpg"}; + + + // Get all file transfer mode mappings + public ISystemFileTransferModeMapping[] getModeMappings(); + + + // Query whether a file should be treated as binary + public boolean isBinary(IFile file); + public boolean isBinary(IRemoteFile remoteFile); + + + // Query whether a file should be treated as text + public boolean isText(IFile file); + public boolean isText(IRemoteFile remoteFile); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemRemoteCommand.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemRemoteCommand.java new file mode 100644 index 00000000000..6ef864f03e1 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemRemoteCommand.java @@ -0,0 +1,34 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.model; + +import org.eclipse.rse.core.subsystems.ISubSystem; + + + +public interface ISystemRemoteCommand { + + + + public String getCommand(); + + public ISubSystem getSubSystem(); + + public ISystemRemoteCommandMessage[] getMessages(); + + public Object getObject(); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemRemoteCommandMessage.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemRemoteCommandMessage.java new file mode 100644 index 00000000000..fe0d4c0c905 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemRemoteCommandMessage.java @@ -0,0 +1,26 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.model; +public interface ISystemRemoteCommandMessage { + + + + + public String getMessageText(); + + public String getMessageHelp(); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/RemoteFileFilterString.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/RemoteFileFilterString.java new file mode 100644 index 00000000000..bcd52e5d87b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/RemoteFileFilterString.java @@ -0,0 +1,402 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.model; +import java.util.StringTokenizer; +import java.util.Vector; + +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystemConfiguration; + + +/** + * A string representing a filter sent to remote file subsystems. + *

+ * Filters can be absolute or relative. Absolute contains a folder path, while relative do not. + *

+ * The files can be filtered by name, or by a list of file types. If by name, it can have + * up to 2 asterisks anywhere in the name for wildcarding. If by types, multiple types can + * by specified. The types are the file extensions without the dot, as in "java" or "class". + *

+ * Examples: + *

    + *
  • Absolute file name filter: d:\mystuff\phil*.abc + *
  • Relative file name filter: phil*.abc + *
  • Absolute file type filter: d:\mystuff\java,class, + *
  • Relative file type filter: java,class, + *

    + * Syntactically, file type filter strings have at least one comma. + * Note that the file name filter string "*.java" is semantically the same + * as a type filter string "java,". Either one can be used and will get + * the same results. However, if you specify "java" you will be in trouble, + * as it will mean look for a file explicitly named "java". + *

    + * It is invalid to have both a comma and an asterisk in the same filter string. + * It is also invalid to have both a comma and a period in the same filter string. + */ +public class RemoteFileFilterString implements Cloneable +{ + protected String path, file; + protected String[] types; + protected boolean subdirs, files, filterByTypes; + //private RemoteFileSubSystemFactory subsysFactory; + protected String PATH_SEP = java.io.File.separator; + public static final char TYPE_SEP = ','; + public static final String TYPE_SEP_STRING = ","; + public static final String SWITCH_NOSUBDIRS = " /ns"; + public static final String SWITCH_NOFILES = " /nf"; + + /** + * Constructor to use for a filter to list roots when used absolutely, or list all contents + * when used relatively. + */ + public RemoteFileFilterString() + { + file = "*"; + subdirs = true; + files = true; + } + /** + * Constructor to use when there is no existing filter string. + *

    + * This constructor is better that the default constructor, because it takes a remote file subsystem + * factory, from which we can query the folder and path separator characters, which are needed + * to parse and re-build filter strings. + * @see #setPath(String) + * @see #setFile(String) + * @see #setTypes(String[]) + */ + public RemoteFileFilterString(IRemoteFileSubSystemConfiguration subsysFactory) + { + PATH_SEP = subsysFactory.getSeparator(); + file = "*"; + subdirs = true; + files = true; + } + /** + * Constructor to use when an absolute filter string already exists. + */ + public RemoteFileFilterString(IRemoteFileSubSystemConfiguration subsysFactory, String input) + { + this(subsysFactory); + parse(null, input); + } + /** + * Constructor to use when you have a path and filename filter or comma-separated file types list. + * In the latter case, the last char must be a TYPE_SEP or comma, even for a single type. + */ + public RemoteFileFilterString(IRemoteFileSubSystemConfiguration subsysFactory, String path, String input) + { + this(subsysFactory); + parse(path, input); + } + + public void setSubSystemFactory(IRemoteFileSubSystemConfiguration subsysFactory) + { + PATH_SEP = subsysFactory.getSeparator(); + } + /** + * Set the file name filter. You either call this or setTypes! + */ + public void setFile(String obj) + { + file = obj; + } + /** + * Set the path to list files and/or folders in + */ + public void setPath(String path) + { + this.path = path; + } + /** + * Set the file types to subset by. These are extensions, without the dot, as + * in java, class, gif, etc. + * You either call this or setFile! + */ + public void setTypes(String[] types) + { + this.types = types; + filterByTypes = (types != null); + } + /** + * Allow files? + */ + public void setShowFiles(boolean set) + { + files = set; + } + /** + * Allow subdirs? + */ + public void setShowSubDirs(boolean set) + { + subdirs = set; + } + + /** + * Get the file name filter + */ + public String getFile() + { + return file; + } + /** + * Return the file part of the filter string, without the path. + * This is either the file name filter or a comma-separated list of types if this + * is a file type filter string. + */ + public String getFileOrTypes() + { + if (!filterByTypes || (types==null)) + return file; + else + { + return getTypesString(types); + } + } + /** + * Concatenate the given file types as a single string, each type comma-separated + */ + public static String getTypesString(String[] typesArray) + { + StringBuffer typesBuffer = new StringBuffer(""); + for (int idx=0; idx= 0) + { + subdirs = false; + input = input.substring(0,idx); + } + else + subdirs = true; + idx = input.indexOf(SWITCH_NOFILES); + if (idx >= 0) + { + files = false; + input = input.substring(0,idx); + } + else + files = true; + if (inputPath != null) + { + path = inputPath; + parseFileOrTypes(input); // file = input; + } + else + { + int pathidx = input.lastIndexOf(PATH_SEP); + if (pathidx == 0) + { + // hmm, we have been given say \*.java -> what does this mean? On Windows, it + // would mean "*.java" in the current drive, whereas on Unix/Linux it would + // mean "*.java" in the root directory. + // For now, we are going with the Unix interpretation, and see if that leads + // to any problems on Windows, which should not allow such a filter anyway, unless + // it is absolute. + //path = null; + path = PATH_SEP; + if (input.length()>1) + //file = input.substring(1); // from the 2nd char on + parseFileOrTypes(input.substring(1)); // from the 2nd char on + else + file = "*"; + } + else if (pathidx>0) + { + path = input.substring(0,pathidx); + if (path.endsWith(":")) // special case: eg, given e: + path = path + PATH_SEP; // need it to be e:\ !! + if (pathidx == (input.length()-1)) + file = "*"; + else + //file = input.substring(pathidx+1); + parseFileOrTypes(input.substring(pathidx+1)); + } + else + { + path = null; + //file = input; + parseFileOrTypes(input); + } + } + ///File fileObj = (path==null)? new File(input) : new File(path, input); + //this.path = fileObj.getParent(); + //if (this.path == null) + //this.path = fileObj.getAbsolutePath(); // happens for root drives + //this.file = fileObj.getName(); + } + /** + * Parse the non-folder part of the filter string. Will either be a + * generic name or comma-separated list of types. + */ + protected void parseFileOrTypes(String filter) + { + filterByTypes = false; + types = null; + if ((filter == null) || (filter.length()==0)) + { + file = "*"; + } + else if (filter.endsWith(TYPE_SEP_STRING)) + { + types = parseTypes(filter); + filterByTypes = true; + } + else + file = filter; + } + /** + * Parse a comma-separated list of strings into an array of strings + */ + public static String[] parseTypes(String typeList) + { + StringTokenizer tokens = new StringTokenizer(typeList,TYPE_SEP_STRING); + Vector v = new Vector(); + while (tokens.hasMoreTokens()) + { + String token = tokens.nextToken().trim(); + if (token.length()>0) + v.addElement(token); + } + String[] types = new String[v.size()]; + for (int idx=0; idx"profileName.connectionName:absolutePath". + * @param fullyQualifiedName the fully qualified name. + */ + public RemotePath(String fullyQualifiedPath) { + + if (fullyQualifiedPath != null) { + + int dotIndex = fullyQualifiedPath.indexOf('.'); + + if ((dotIndex != -1) && (dotIndex != (fullyQualifiedPath.length() - 1))) { + int colonIndex = fullyQualifiedPath.indexOf(':', dotIndex+1); + + if ((colonIndex != -1) && (colonIndex != (fullyQualifiedPath.length() - 1))) { + setProfileName(fullyQualifiedPath.substring(0, dotIndex)); + setConnectionName(fullyQualifiedPath.substring(dotIndex+1, colonIndex)); + setAbsolutePath(fullyQualifiedPath.substring(colonIndex+1)); + } + } + } + } + + /** + * @see org.eclipse.rse.subsystems.files.core.model.IRemotePath#setProfileName(java.lang.String) + */ + protected void setProfileName(String profileName) { + this.profileName = profileName; + } + + /** + * @see org.eclipse.rse.subsystems.files.core.model.IRemotePath#setConnectionName(java.lang.String) + */ + protected void setConnectionName(String connectionName) { + this.connectionName = connectionName; + } + + /** + * @see org.eclipse.rse.subsystems.files.core.model.IRemotePath#setAbsolutePath(java.lang.String) + */ + protected void setAbsolutePath(String absolutePath) { + this.absolutePath = absolutePath; + } + + /** + * @see org.eclipse.rse.subsystems.files.core.model.IRemotePath#getProfileName() + */ + public String getProfileName() { + return profileName; + } + + /** + * @see org.eclipse.rse.subsystems.files.core.model.IRemotePath#getConnectionName() + */ + public String getConnectionName() { + return connectionName; + } + + /** + * @see org.eclipse.rse.subsystems.files.core.model.IRemotePath#getAbsolutePath() + */ + public String getAbsolutePath() { + return absolutePath; + } + + /** + * @see org.eclipse.rse.subsystems.files.core.model.IRemotePath#getFullyQualifiedPath() + */ + public String getFullyQualifiedPath() { + + if ((profileName == null) || (connectionName == null) || (absolutePath == null)) { + return null; + } + else { + return profileName + "." + connectionName + ":" + absolutePath; + } + } + + /** + * @see org.eclipse.rse.subsystems.files.core.model.IRemotePath#getFileExtension() + */ + public String getFileExtension() { + + if (absolutePath == null) { + return null; + } + else { + + int dotIndex = absolutePath.lastIndexOf('.'); + + if (dotIndex != -1) { + + if (dotIndex != (absolutePath.length() - 1)) { + return absolutePath.substring(dotIndex+1); + } + else { + return ""; + } + } + else { + return null; + } + } + } + + /** + * @see org.eclipse.rse.subsystems.files.core.model.IRemotePath#addFileExtension(java.lang.String) + */ + public IRemotePath addFileExtension(String extension) { + + if (absolutePath == null) { + return null; + } + + if (absolutePath.endsWith("/") || absolutePath.endsWith("\\")) { + return this; + } + else { + String newAbsolutePath = absolutePath + "." + extension; + return new RemotePath(profileName, connectionName, newAbsolutePath); + } + } + + /** + * @see org.eclipse.rse.subsystems.files.core.model.IRemotePath#removeFileExtension(java.lang.String) + */ + public IRemotePath removeFileExtension() { + + if (absolutePath == null) { + return null; + } + + if (absolutePath.endsWith("/") || absolutePath.endsWith("\\")) { + return this; + } + else { + int dotIndex = absolutePath.lastIndexOf('.'); + + if (dotIndex == -1) { + return this; + } + else { + String newAbsolutePath = absolutePath.substring(0, dotIndex); + return new RemotePath(profileName, connectionName, newAbsolutePath); + } + } + } + + /** + * @see org.eclipse.rse.subsystems.files.core.model.IRemotePath#isVirtual() + */ + public boolean isVirtual() { + return ArchiveHandlerManager.isVirtual(absolutePath); + } + + /** + * @see org.eclipse.rse.subsystems.files.core.model.IRemotePath#toRemoteFile() + */ + public IRemoteFile toRemoteFile() { + + if ((profileName == null) || (connectionName == null) || (absolutePath == null)) { + return null; + } + + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + ISystemProfile profile = registry.getSystemProfile(profileName); + + if (profile == null) { + return null; + } + + IHost conn = registry.getHost(profile, connectionName); + + if (conn == null) { + return null; + } + + IRemoteFileSubSystem subsys = RemoteFileUtility.getFileSubSystem(conn); + IRemoteFile remoteFile = null; + + try { + remoteFile = subsys.getRemoteFileObject(absolutePath); + } + catch (SystemMessageException e) { + SystemBasePlugin.logError("Error occured trying to get remote file", e); + remoteFile = null; + } + + return remoteFile; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/RemotePathUtil.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/RemotePathUtil.java new file mode 100644 index 00000000000..911bcefc51d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/RemotePathUtil.java @@ -0,0 +1,135 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.model; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +/** + * Singleton utility class for remote paths. + */ +public class RemotePathUtil { + + private static RemotePathUtil instance; + + /** + * Constructor. + */ + private RemotePathUtil() { + super(); + } + + /** + * Returns the singleton instance. + * @return the singleton instance. + */ + public static RemotePathUtil getInstance() { + + if (instance == null) { + instance = new RemotePathUtil(); + } + + return instance; + } + + /** + * Returns the path of the temp location corresponding to the remote path. The remote + * path must represent a file (i.e. can not be a directory). + * The temp path is simply the default temp location on the client system (given by system property + * "java.io.tmpdir"), with the name of the remote file appended (not the path of the + * remote file). + * @param remotePath the remote path. + * @return the path of the temporary file, or null if the default temporary location + * is not available. + */ + public IPath getClientTempLocationForFile(IRemotePath remotePath) { + String tempDirString = System.getProperty("java.io.tmpdir"); + + IPath tempPath = new Path(tempDirString); + + if (tempDirString == null) { + return null; + } + else { + + String absolutePath = remotePath.getAbsolutePath(); + + // try '/' first + String sep = "/"; + + boolean isVirtual = remotePath.isVirtual(); + + IPath newPath = new Path(tempPath.toOSString()); + + newPath = appendRemoteFileNameToPath(newPath, absolutePath, sep); + + if (!newPath.equals(tempPath)) { + return newPath; + } + else { + + // for virtual separator is '/' + if (isVirtual) { + return null; + } + + sep = "\\"; + + newPath = appendRemoteFileNameToPath(newPath, absolutePath, sep); + + if (!newPath.equals(tempPath)) { + return newPath; + } + else { + return null; + } + } + } + } + + /** + * Apnnds a file name to a path given the absolute path of a file. + * The absolute path name of the file must not end with the given separator (we assume + * that a directory will end with a separator). + * @param path the path to which to append. + * @param absolutePath the absolute path from which the name will be obtained. + * @param sep the separator to parse the absolute path, and get the name. + * @return the new path, or the same path if the separator was not found, or + * was found to be the last character in the absolute path. + */ + private IPath appendRemoteFileNameToPath(IPath path, String absolutePath, String sep) { + + int sepIndex = absolutePath.lastIndexOf(sep); + + // found separator + if (sepIndex != -1) { + + // if not the last character in the path, then strip out the last segment + if (sepIndex != (absolutePath.length()-1)) { + return path.append(absolutePath.substring(sepIndex+1)); + } + // separator is last character in path, so it must be a directory + else { + return path; + } + } + // no separator found so simply append the absolute path + else { + return path.append(absolutePath); + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/SystemFileTransferModeMapping.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/SystemFileTransferModeMapping.java new file mode 100644 index 00000000000..75070beaf3c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/SystemFileTransferModeMapping.java @@ -0,0 +1,144 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.model; + + +/** + * An internal class. Clients must not instantiate or subclass it. + */ + +public class SystemFileTransferModeMapping + implements ISystemFileTransferModeMapping, Cloneable { + + + + + private String name; + private String extension; + private boolean isBinary = true; + + + /** + * Constructor for SystemFileTransferModeMapping + */ + public SystemFileTransferModeMapping(String extension) { + this("*", extension); + } + + + /** + * Constructor for SystemFileTransferModeMapping + */ + public SystemFileTransferModeMapping(String name, String extension) { + + if ((name == null) || (name.length() < 1)) { + setName("*"); + } + else { + setName(name); + } + + setExtension(extension); + } + + + + /** + * @see ISystemFileTransferModeMapping#getExtension() + */ + public String getExtension() { + return extension; + } + + + /** + * @see ISystemFileTransferModeMapping#getLabel() + */ + public String getLabel() { + return (name + "." + extension); + } + + + /** + * @see ISystemFileTransferModeMapping#getName() + */ + public String getName() { + return name; + } + + + /** + * @see ISystemFileTransferModeMapping#isBinary() + */ + public boolean isBinary() { + return isBinary; + } + + + /** + * @see ISystemFileTransferModeMapping#isText() + */ + public boolean isText() { + return !isBinary(); + } + + + /** + * Set whether transfer mode is binary + */ + public void setAsBinary() { + isBinary = true; + } + + + /** + * Set whether transfer mode is text + */ + public void setAsText() { + isBinary = false; + } + + + /** + * Set the name + */ + public void setName(String name) { + this.name = name; + } + + + /** + * Set the extension + */ + public void setExtension(String extension) { + this.extension = extension; + } + + + /** + * Clone this object + */ + public Object clone() { + + try { + return ((SystemFileTransferModeMapping)(super.clone())); + } + catch (CloneNotSupportedException e) { + return null; + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/SystemFileTransferModeRegistry.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/SystemFileTransferModeRegistry.java new file mode 100644 index 00000000000..f03e8a96e37 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/SystemFileTransferModeRegistry.java @@ -0,0 +1,592 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.model; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.SystemSorter; +import org.eclipse.rse.services.clientserver.SystemEncodingUtil; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.ui.ISystemPreferencesConstants; +import org.eclipse.ui.IEditorRegistry; +import org.eclipse.ui.IFileEditorMapping; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.IPropertyListener; +import org.eclipse.ui.XMLMemento; + + + +/** + * An internal class. Clients must not instantiate or subclass it. + */ + +public class SystemFileTransferModeRegistry + implements ISystemFileTransferModeRegistry, IPropertyListener { + + + + + private static SystemFileTransferModeRegistry instance; + + private HashMap typeModeMappings; + + private SystemPlugin plugin; + + // Constants for reading from and writing to xml file + private static final String FILENAME = "fileTransferMode.xml"; + private static final String ENCODING = SystemEncodingUtil.ENCODING_UTF_8; + private static final String ROOT_NODE = "mode"; + private static final String INFO_NODE = "info"; + private static final String NAME_ATTRIBUTE = "name"; + private static final String EXTENSION_ATTRIBUTE = "extension"; + private static final String MODE_ATTRIBUTE = "mode"; + private static final String BINARY_VALUE = "binary"; + private static final String TEXT_VALUE = "text"; + + + /** + * Constructor for SystemFileTransferModeRegistry + */ + private SystemFileTransferModeRegistry() { + super(); + this.plugin = SystemPlugin.getDefault(); + initialize(); + } + + + /** + * Get the singleton instance + */ + public static SystemFileTransferModeRegistry getDefault() { + + if (instance == null) { + instance = new SystemFileTransferModeRegistry(); + } + + return instance; + } + + + /** + * Initialize the registry from storage. + */ + private void initialize() { + + // load our current associations (if any) + loadAssociations(); + + // now we need to ensure that our mapping is in sync with the + // editor registry. We can be out of sync because we may not have + // been listening for editor registry changes (e.g. if our plugin wasn't + // started while those changes were made). + IEditorRegistry registry = SystemPlugin.getDefault().getWorkbench().getEditorRegistry(); + syncWithEditorRegistry(registry); + + registry.addPropertyListener(this); + } + + + /** + * Listen for changes to the Editor Registry content. + * Update our registry by changing the hashmap and saving the new + * mappings on disk. + * @see org.eclipse.ui.IPropertyListener#propertyChanged(Object, int) + */ + public void propertyChanged(Object source, int propId) { + + if ((source instanceof IEditorRegistry) && (propId == IEditorRegistry.PROP_CONTENTS)) { + IEditorRegistry registry = (IEditorRegistry)source; + syncWithEditorRegistry(registry); + } + } + + + /** + * Ensures that our registry is in sync with the editor registry, e.g. + * we have exactly the same types as in the editor registry. We can be + * out of sync if changes are made to the registry while we are not listening. + */ + private void syncWithEditorRegistry(IEditorRegistry registry) { + + IFileEditorMapping[] editorMappings = registry.getFileEditorMappings(); + + SystemFileTransferModeMapping[] modeMappings = new SystemFileTransferModeMapping[editorMappings.length]; + + for (int i = 0; i < editorMappings.length; i++) { + modeMappings[i] = getMapping(editorMappings[i]); + } + + setModeMappings(modeMappings); // set new mappings + saveAssociations(); // now save associations + } + + + /** + * @see ISystemFileTransferModeRegistry#getModeMappings() + */ + public ISystemFileTransferModeMapping[] getModeMappings() { + List sortedMappings = sortedTypeModeMappings(); // sort hash table elements + ISystemFileTransferModeMapping[] array = new ISystemFileTransferModeMapping[sortedMappings.size()]; + sortedMappings.toArray(array); + return array; + } + + + /** + * The mappings are kept in a hash map for fast lookup. Sorting is + * typically only needed for certain dialogs/choices etc. + */ + private List sortedTypeModeMappings() { + + Object[] array = new Object[typeModeMappings.size()]; + Iterator iter = typeModeMappings.values().iterator(); + + int j = 0; + + while (iter.hasNext()) { + array[j++] = iter.next(); + } + + SystemSorter s = new SystemSorter() { + + public boolean compare(Object o1, Object o2) { + + String s1 = ((ISystemFileTransferModeMapping)o1).getLabel().toUpperCase(); + String s2 = ((ISystemFileTransferModeMapping)o2).getLabel().toUpperCase(); + return s2.compareTo(s1) > 0; + } + }; + + array = s.sort(array); + + List result = new ArrayList(); + + for (int i = 0; i < array.length; i++) { + result.add(array[i]); + } + + return result; + } + + + /** + * Sets new mode mappings + */ + public void setModeMappings(SystemFileTransferModeMapping[] newMappings) { + typeModeMappings = new HashMap(); + + for (int i = 0; i < newMappings.length; i++) { + SystemFileTransferModeMapping mapping = newMappings[i]; + typeModeMappings.put(getMappingKey(mapping), mapping); + } + } + + + /** + * Return a key given the mapping + */ + private String getMappingKey(ISystemFileTransferModeMapping mapping) { + return mapping.getLabel().toLowerCase(); + } + + + /** + * @see ISystemFileTransferModeRegistry#isBinary(String) + */ + public boolean isBinary(String fileName) { + return getMapping(fileName).isBinary(); + } + + + /** + * @see ISystemFileTransferModeRegistry#isBinary(File) + */ + public boolean isBinary(File file) { + return isBinary(file.getName()); + } + + + /** + * @see ISystemFileTransferModeRegistry#isBinary(IFile) + */ + public boolean isBinary(IFile file) { + return isBinary(file.getName()); + } + + + /** + * @see ISystemFileTransferModeRegistry#isBinary(IRemoteFile) + */ + public boolean isBinary(IRemoteFile remoteFile) { + return isBinary(remoteFile.getName()); + } + + + /** + * @see ISystemFileTransferModeRegistry#isText(String) + */ + public boolean isText(String fileName) { + return getMapping(fileName).isText(); + } + + + /** + * @see ISystemFileTransferModeRegistry#isText(File) + */ + public boolean isText(File file) { + return isText(file.getName()); + } + + + /** + * @see ISystemFileTransferModeRegistry#isText(IFile) + */ + public boolean isText(IFile file) { + return isText(file.getName()); + } + + + /** + * @see ISystemFileTransferModeRegistry#isText(IRemoteFile) + */ + public boolean isText(IRemoteFile remoteFile) { + return isText(remoteFile.getName()); + } + + + /** + * Get a mode mapping given a file editor mapping + */ + public SystemFileTransferModeMapping getMapping(IFileEditorMapping editorMapping) { + return getMapping(editorMapping.getLabel()); + } + + + /** + * Get the mode mapping given a file name + */ + private SystemFileTransferModeMapping getMapping(String fileName) { + SystemFileTransferModeMapping mapping = (SystemFileTransferModeMapping)(typeModeMappings.get(fileName.toLowerCase())); + + if (mapping == null) { + mapping = createMappingFromModeMappings(fileName); + } + + if (mapping == null) { + return getDefaultMapping(fileName); + } + + return mapping; + } + + private SystemFileTransferModeMapping createMappingFromModeMappings(String fileName) + { + // get file extension + //DY int extIndex = fileName.indexOf('.'); + int extIndex = fileName.lastIndexOf('.'); + + + // if there is no extension + if ((extIndex == -1) || (extIndex == (fileName.length() - 1))) { + return null; + } + + + String name = fileName.substring(0, extIndex); + String extension = fileName.substring(extIndex + 1); + + SystemFileTransferModeMapping mapping = (SystemFileTransferModeMapping)(typeModeMappings.get(getMappingKey(new SystemFileTransferModeMapping(extension)))); + + if (mapping == null) + return null; + + + SystemFileTransferModeMapping fileMapping = new SystemFileTransferModeMapping(name, extension); + + if (mapping.isText()) + { + fileMapping.setAsText(); + } + else + { + fileMapping.setAsBinary(); + } + + return fileMapping; + } + + /** + * Return whether to automatically detect, use binary or text during file transfer + * for unspecified file types + */ + public static int getFileTransferModeDefaultPreference() + { + IPreferenceStore store= SystemPlugin.getDefault().getPreferenceStore(); + return store.getInt(ISystemPreferencesConstants.FILETRANSFERMODEDEFAULT); + } + + /** + * Get a default mapping given an extension. Should never return null. + */ + private SystemFileTransferModeMapping getDefaultMapping(String fileName) { + + // now we check if the file has an extension + // DY int extIndex = fileName.indexOf('.'); + int extIndex = fileName.lastIndexOf('.'); + String name, extension; + + // if there is no extension + // DY 04-23-2002 changed from default binary to default text for files that + // a) Have no extension + // b) Ends with a period + // c) Start with a '.' i.e. .bash_history + if ((extIndex == -1) || (extIndex == (fileName.length() - 1)) || (extIndex == 0)) + { + name = fileName; + extension = null; + } + else + { + name = fileName.substring(0, extIndex); + extension = fileName.substring(extIndex + 1); + } + + SystemFileTransferModeMapping mapping = new SystemFileTransferModeMapping(name, extension); + + + // check if it's a default text file name + for (int i = 0; i < DEFAULT_TEXT_FILE_NAMES.length; i++) + { + if (fileName.equalsIgnoreCase(DEFAULT_TEXT_FILE_NAMES[i])) + { + mapping.setAsText(); + return mapping; + } + } + + // DKM + // no longer default to text - instead we default based on preferences + // after the if (extension != null), we pick up preferences for default + /* + if (extension == null) + { + // DY mapping.setAsBinary(); + mapping.setAsText(); + return mapping; + } */ + + + + if (extension != null) + { + // check if it's a default text file extension + for (int i = 0; i < DEFAULT_TEXT_FILE_EXTENSIONS.length; i++) + { + if (extension.equalsIgnoreCase(DEFAULT_TEXT_FILE_EXTENSIONS[i])) + { + mapping.setAsText(); + return mapping; + } + } + + // check if it's a default LPEX text file extension + for (int i = 0; i < DEFAULT_LPEX_TEXT_FILE_EXTENSIONS.length; i++) + { + if (extension.equalsIgnoreCase(DEFAULT_LPEX_TEXT_FILE_EXTENSIONS[i])) + { + mapping.setAsText(); + return mapping; + } + } + + // check if it's a default iSeries LPEX text file extension + for (int i = 0; i < DEFAULT_ISERIES_LPEX_TEXT_FILE_EXTENSIONS.length; i++) + { + if (extension.equalsIgnoreCase(DEFAULT_ISERIES_LPEX_TEXT_FILE_EXTENSIONS[i])) + { + mapping.setAsText(); + return mapping; + } + } + + // check if it's a default Universal LPEX text file extension (Phil 10/16/2002) + for (int i = 0; i < DEFAULT_UNIX_LPEX_TEXT_FILE_EXTENSIONS.length; i++) + { + if (extension.equalsIgnoreCase(DEFAULT_UNIX_LPEX_TEXT_FILE_EXTENSIONS[i])) + { + mapping.setAsText(); + return mapping; + } + } + + // check for known binary types + for (int i = 0; i < DEFAULT_BINARY_FILE_EXTENSIONS.length; i++) + { + if (extension.equalsIgnoreCase(DEFAULT_BINARY_FILE_EXTENSIONS[i])) + { + mapping.setAsBinary(); + return mapping; + } + } + } + + // default + int defaultFileTransferMode = getFileTransferModeDefaultPreference(); + + if (defaultFileTransferMode == ISystemPreferencesConstants.FILETRANSFERMODE_BINARY) + { + mapping.setAsBinary(); + } + else if (defaultFileTransferMode == ISystemPreferencesConstants.FILETRANSFERMODE_TEXT) + { + mapping.setAsText(); + } + + return mapping; + } + + + /** + * Load the saved associations to the registry + * + * @return true if operation successful, false otherwise + */ + public boolean loadAssociations() { + + typeModeMappings = new HashMap(); + + String location = getFileLocation(); + + File file = new File(location); + + if (!file.exists()) + return false; + + FileInputStream stream = null; + InputStreamReader reader = null; + + boolean result = false; + + try { + stream = new FileInputStream(file); + reader = new InputStreamReader(stream, ENCODING); + XMLMemento memento = XMLMemento.createReadRoot(reader); + IMemento[] mementos = memento.getChildren(INFO_NODE); + + for (int i = 0; i < mementos.length; i++) { + String name = mementos[i].getString(NAME_ATTRIBUTE); + String extension = mementos[i].getString(EXTENSION_ATTRIBUTE); + String mode = mementos[i].getString(MODE_ATTRIBUTE); + + SystemFileTransferModeMapping mapping = new SystemFileTransferModeMapping(name, extension); + + if (mode.equals(TEXT_VALUE)) { + mapping.setAsText(); + } + else { + mapping.setAsBinary(); + } + + typeModeMappings.put(getMappingKey(mapping), mapping); + } + + result = true; + } + catch (Exception e) { + SystemBasePlugin.logError("Could not read transfer mode xml file", e); + result = false; + } + finally { + + try { + + if (reader != null) + reader.close(); + } + catch (Exception e) { + SystemBasePlugin.logError("Could not close reader for transfer mode xml file", e); + } + } + + + return result; + } + + + /** + * Save the contents of the registry + */ + public void saveAssociations() { + + String location = getFileLocation(); + + XMLMemento memento = XMLMemento.createWriteRoot(ROOT_NODE); + + Iterator iter = typeModeMappings.values().iterator(); + + while (iter.hasNext()) { + ISystemFileTransferModeMapping mapping = (ISystemFileTransferModeMapping)iter.next(); + IMemento infoMemento = memento.createChild(INFO_NODE); + infoMemento.putString(NAME_ATTRIBUTE, mapping.getName()); + infoMemento.putString(EXTENSION_ATTRIBUTE, mapping.getExtension()); + infoMemento.putString(MODE_ATTRIBUTE, mapping.isBinary() ? BINARY_VALUE : TEXT_VALUE); + } + + FileOutputStream stream = null; + OutputStreamWriter writer = null; + + try { + stream = new FileOutputStream(location); + writer = new OutputStreamWriter(stream, ENCODING); + memento.save(writer); + } + catch (Exception e) { + SystemBasePlugin.logError("Could not write to transfer mode xml file", e); + } + finally { + + try { + + if (writer != null) + writer.close(); + } + catch (Exception e) { + SystemBasePlugin.logError("Could not close writer for transfer mode xml file", e); + } + } + } + + + /** + * Get the file location + */ + private String getFileLocation() { + return plugin.getStateLocation().append(FILENAME).toOSString(); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/AbstractRemoteFile.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/AbstractRemoteFile.java new file mode 100644 index 00000000000..1d7aa3529a7 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/AbstractRemoteFile.java @@ -0,0 +1,203 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.servicesubsystem; + +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.files.IHostFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileContext; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteFile; + + +public abstract class AbstractRemoteFile extends RemoteFile implements IRemoteFile +{ + protected IHostFile _hostFile; + protected FileServiceSubSystem _subSystem; + protected String _classiciation; + + + public AbstractRemoteFile(FileServiceSubSystem subSystem, IRemoteFileContext context, IRemoteFile parent, IHostFile hostFile) + { + super(context); + _subSystem = subSystem; + _hostFile = hostFile; + setParentRemoteFile(parent); + } + + public IRemoteFileSubSystem getParentRemoteFileSubSystem() + { + return _subSystem; + } + + public IHost getSystemConnection() + { + return _subSystem.getHost(); + } + + public String getAbsolutePath() + { + return _hostFile.getAbsolutePath(); + } + + + public String getLabel() + { + return _hostFile.getName(); + } + + public String getName() + { + return _hostFile.getName(); + } + + public String getParentPath() + { + return _hostFile.getParentPath(); + } + + public boolean isRoot() + { + return _hostFile.isRoot(); + } + + public boolean isDirectory() + { + return _hostFile.isDirectory(); + } + + public boolean isFile() + { + return _hostFile.isFile(); + } + + + public boolean exists() + { + return _hostFile.exists(); + } + + public long getLastModified() + { + return _hostFile.getModifiedDate(); + } + + + public long getLength() + { + return _hostFile.getSize(); + } + + public int compareTo(Object other) throws ClassCastException + { + IRemoteFile otherFile = (IRemoteFile)other; + if (otherFile.isFile()) + { + if (isFile()) + { + String otherPath = otherFile.getAbsolutePath(); + String thisPath = getAbsolutePath(); + + return thisPath.compareToIgnoreCase(otherPath); + } + else + { + return -1; + } + } + else // not file + { + if (isDirectory()) + { + String otherPath = otherFile.getAbsolutePath(); + String thisPath = getAbsolutePath(); + + return thisPath.compareToIgnoreCase(otherPath); + } + else + { + return 1; + } + } + } + + public boolean showBriefPropertySet() + { + // TODO Auto-generated method stub + return false; + } + + /** + * @deprecated - shouldn't need apis like this + */ + public String getParentNoRoot() + { + String parentPath = getParentPath(); + return parentPath; + } + + /** + * @deprecated - shouldn't need apis like this + */ + public String getRoot() + { + // TODO Auto-generated method stub + return null; + } + + public String getParentName() + { + // TODO Auto-generated method stub + return null; + } + + public boolean isHidden() + { + // TODO Auto-generated method stub + return false; + } + + public boolean isVirtual() + { + // TODO Auto-generated method stub + return false; + } + + public boolean canRead() + { + // TODO Auto-generated method stub + return true; + } + + public boolean canWrite() + { + // TODO Auto-generated method stub + return true; + } + + public boolean showReadOnlyProperty() + { + // TODO Auto-generated method stub + return false; + } + + public IHostFile getHostFile() + { + return _hostFile; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystem.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystem.java new file mode 100644 index 00000000000..2778d8383be --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystem.java @@ -0,0 +1,786 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.servicesubsystem; + + +import java.io.File; +import java.io.InputStream; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.servicesubsystem.IServiceSubSystemConfiguration; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.core.subsystems.RemoteChildrenContentsType; +import org.eclipse.rse.internal.subsystems.files.core.ILanguageUtilityFactory; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.clientserver.PathUtility; +import org.eclipse.rse.services.clientserver.SystemEncodingUtil; +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.files.IHostFile; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.services.search.IHostSearchResultSet; +import org.eclipse.rse.services.search.ISearchService; +import org.eclipse.rse.subsystems.files.core.model.SystemFileTransferModeRegistry; +import org.eclipse.rse.subsystems.files.core.subsystems.IHostFileToRemoteFileAdapter; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileContext; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileIOException; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSecurityException; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteFolderNotEmptyException; + + + + +public final class FileServiceSubSystem extends RemoteFileSubSystem implements IFileServiceSubSystem +{ + protected ILanguageUtilityFactory _languageUtilityFactory; + protected IFileService _hostFileService; + protected ISearchService _hostSearchService; + protected IHostFileToRemoteFileAdapter _hostFileToRemoteFileAdapter; + + public FileServiceSubSystem(IHost host, IConnectorService connectorService, IFileService hostFileService, IHostFileToRemoteFileAdapter fileAdapter, ISearchService searchService) + { + super(host, connectorService); + _hostFileService = hostFileService; + _hostFileToRemoteFileAdapter = fileAdapter; + _hostSearchService = searchService; + + } + + public IRemoteFileContext getContextFor(IRemoteFile file) + { + return getContext(file); + } + + public IRemoteFileContext getTheDefaultContext() + { + return getDefaultContextNoFilterString(); + } + + public IFileService getFileService() + { + return _hostFileService; + } + + public void setFileService(IFileService service) + { + _hostFileService = service; + } + + public ISearchService getSearchService() + { + return _hostSearchService; + } + + public void setSearchService(ISearchService service) + { + _hostSearchService = service; + } + + public IHostFileToRemoteFileAdapter getHostFileToRemoteFileAdapter() + { + return _hostFileToRemoteFileAdapter; + } + + + + public String getRemoteEncoding() + { + return System.getProperty("file.encoding"); + } + + public void setHostFileToRemoteFileAdapter(IHostFileToRemoteFileAdapter hostFileAdapter) + { + _hostFileToRemoteFileAdapter = hostFileAdapter; + } + + /** + * Constructs an IRemoteFile object given + * an unqualified file or folder name and its parent folder object. + * @param parent Folder containing the folder or file + * @param folderOrFileName Un-qualified folder or file name + * @return an IRemoteFile object for the file. + * @see IRemoteFile + */ + public IRemoteFile getRemoteFileObject(IRemoteFile parent, String folderOrFileName) throws SystemMessageException + { + String fullPath = parent.getAbsolutePath() + getSeparator() + folderOrFileName; + IRemoteFile file = getCachedRemoteFile(fullPath); + if (file != null && !file.isStale()) + { + return file; + } + + IHostFile node = getFile(null, parent.getAbsolutePath(), folderOrFileName); + return getHostFileToRemoteFileAdapter().convertToRemoteFile(this, getDefaultContext(), parent, node); + } + + /** + * Constructs and returns an IRemoteFile object given a fully-qualified + * file or folder name. + * @param folderOrFileName Fully qualified folder or file name + * @return The constructed IRemoteFile + * @see IRemoteFile + */ + public IRemoteFile getRemoteFileObject(String folderOrFileName) throws SystemMessageException + { + String fofName = ArchiveHandlerManager.cleanUpVirtualPath(folderOrFileName); + IRemoteFile file = getCachedRemoteFile(fofName); + if (file != null && !file.isStale()) { + return file; + } + + if (fofName.endsWith(ArchiveHandlerManager.VIRTUAL_SEPARATOR)) + { + fofName = fofName.substring(0, fofName.length() - ArchiveHandlerManager.VIRTUAL_SEPARATOR.length()); + } + + + int j = fofName.indexOf(ArchiveHandlerManager.VIRTUAL_SEPARATOR); + if (j == -1) + { + if (fofName.equals("/")) + { + try + { + return listRoots()[0]; + } + catch (Exception e) + { + + } + } + + if (fofName.equals(".")) { + return getUserHome(); + } + + String sep = PathUtility.getSeparator(folderOrFileName); + if (fofName.endsWith(sep)) + { + fofName = fofName.substring(0, fofName.length() - sep.length()); + } + + if (fofName.endsWith(":")) + { + try + { + IHostFile[] roots = getRoots(null); + for (int i = 0; i < roots.length; i++) + if (roots[i].getAbsolutePath().toLowerCase().startsWith(fofName.toLowerCase())) + return getHostFileToRemoteFileAdapter().convertToRemoteFile(this, getDefaultContext(), null, roots[i]); + } + catch (InterruptedException e) + { + } + return null; + } + + int lastSep = fofName.lastIndexOf(sep); + + if (lastSep > -1) + { + String parentPath = fofName.substring(0, lastSep); + + + if (parentPath.length() == 0) parentPath = "/"; + String name = fofName.substring(lastSep + 1, fofName.length()); + + IHostFile node = getFile(null, parentPath, name); + if (node != null) + { + IRemoteFile parent = null; + if (!node.isRoot()) + { + //parent = getRemoteFileObject(parentPath); + } + return getHostFileToRemoteFileAdapter().convertToRemoteFile(this, getDefaultContext(), parent, node); + } + } + return null; + } + else + { + AbsoluteVirtualPath avp = new AbsoluteVirtualPath(fofName); + IHostFile node = getFile(null, avp.getPath(), avp.getName()); + if (node != null) + { + return getHostFileToRemoteFileAdapter().convertToRemoteFile(this, getDefaultContext(), null, node); + } + else return null; + } + } + + + + + + /** + * @return The IRemoteFile that is the user's home directory on this remote file system. + * The remote file system is assumed to have a concept of a home directory. + */ + protected IRemoteFile getUserHome() + { + IRemoteFile root = getCachedRemoteFile("."); + if (root != null && !root.isStale()) { + return root; + } + IHostFile userHome = getFileService().getUserHome(); + IRemoteFile parent = null; + if (!userHome.getParentPath().equals(".")) + { + try + { + //parent = getRemoteFileObject(userHome.getParentPath()); + } + catch (Exception e) + { + } + } + root = getHostFileToRemoteFileAdapter().convertToRemoteFile(this, getDefaultContext(), parent, userHome); + cacheRemoteFile(root, "."); + return root; + } + + protected IHostFile[] getFolders(IProgressMonitor monitor, String parentPath, String fileNameFilter) throws SystemMessageException + { + return getFileService().getFolders(monitor, parentPath, fileNameFilter); + } + + protected IHostFile[] getFiles(IProgressMonitor monitor, String parentPath, String fileNameFilter) throws SystemMessageException + { + return getFileService().getFiles(monitor, parentPath, fileNameFilter); + } + + protected IHostFile[] getFilesAndFolders(IProgressMonitor monitor, String parentPath, String fileNameFilter) throws SystemMessageException + { + return getFileService().getFilesAndFolders(monitor, parentPath, fileNameFilter); + } + + protected IHostFile getFile(IProgressMonitor monitor, String parentPath, String fileName) throws SystemMessageException + { + return getFileService().getFile(monitor, parentPath, fileName); + } + + protected IHostFile[] getRoots(IProgressMonitor monitor) throws InterruptedException, SystemMessageException + { + return getFileService().getRoots(monitor); + } + + /** + * Return a list of remote folders and files in the given folder. + *

    + * The files part of the list is subsetted by the given file name filter. + * It can be null for no subsetting. + * This version is called by RemoteFileSubSystemImpl's resolveFilterString(s). + * @param parent The parent folder to list folders and files in + * @param fileNameFilter The name pattern to subset the file list by, or null to return all files. + * @param context The holder of state information + */ + public IRemoteFile[] listFoldersAndFiles(IRemoteFile parent, String fileNameFilter, IRemoteFileContext context) + { + String parentPath = null; + if (parent != null) { + parentPath = parent.getAbsolutePath(); + } else { + parentPath = "/"; + } + IHostFile[] results = null; + try + { + results = getFilesAndFolders(null, parentPath, fileNameFilter); + } + catch (SystemMessageException e) + { + + } + IRemoteFile[] farr = getHostFileToRemoteFileAdapter().convertToRemoteFiles(this, context, parent, results); + parent.setContents(RemoteChildrenContentsType.getInstance(), fileNameFilter, farr); + return farr; + } + + /** + * Return the array of IRemoteFile instances, matching the given pattern, + * that are contained in the given folder. + * This version is called by RemoteFileSubSystemImpl's resolveFilterString(s) + * @param parent The parent folder to list files in + * @param fileNameFilter The name pattern to subset the list by, or null to return all files. + * @param context The holder of state information + */ + public IRemoteFile[] listFiles(IRemoteFile parent, String fileNameFilter, IRemoteFileContext context) + { + String parentPath = null; + if (parent != null) { + parentPath = parent.getAbsolutePath(); + } else { + parentPath = "/"; + } + IHostFile[] results = null; + try + { + results = getFiles(null, parentPath, fileNameFilter); + } + catch (SystemMessageException e) + { + + } + IRemoteFile[] farr = getHostFileToRemoteFileAdapter().convertToRemoteFiles(this, context, parent, results); + parent.setContents(RemoteChildrenContentsType.getInstance(), fileNameFilter, farr); + return farr; + } + + /** + * Return a subsetted list of remote folders in the given parent folder on the remote system. + * This version is called by RemoteFileSubSystemImpl's resolveFilterString(s) + * @param parent The parent folder to list folders in + * @param fileNameFilter The name pattern for subsetting the file list when this folder is subsequently expanded + * @param context The holder of state information + */ + public IRemoteFile[] listFolders(IRemoteFile parent, String fileNameFilter, IRemoteFileContext context) + { + String parentPath = null; + if (parent != null) { + parentPath = parent.getAbsolutePath(); + } else { + parentPath = "/"; + } + IHostFile[] results = null; + try + { + results = getFolders(null, parentPath, fileNameFilter); + } + catch (SystemMessageException e) + { + } + IRemoteFile[] farr = getHostFileToRemoteFileAdapter().convertToRemoteFiles(this, context, parent, results); + parent.setContents(RemoteChildrenContentsType.getInstance(), fileNameFilter, farr); + return farr; + } + + public IRemoteFile[] listRoots(IRemoteFileContext context) throws InterruptedException + { + IHostFile[] roots = null; + try + { + roots = getRoots(null); + } + catch (SystemMessageException e) + { + + } + IRemoteFile[] results = getHostFileToRemoteFileAdapter().convertToRemoteFiles(this, context, null, roots); + return results; + } + + + + /** + * Get the remote file and save it locally. The file is saved in the encoding + * specified. + * @param source remote file that represents the file to be obtained + * @param destination the absolute path of the local file + * @param encoding the encoding of the local file + * @param monitor progress monitor + */ + public void download(IRemoteFile file, String localpath, String encoding, IProgressMonitor monitor) + { + String parentPath = file.getParentPath(); + File localFile = new File(localpath); + try + { + getFileService().download(monitor, parentPath, file.getName(), localFile, isBinary(file), encoding); + } + catch (SystemMessageException e) + { + // FIXME: Display message + } + } + + protected boolean isBinary(String localEncoding, String hostEncoding, String remotePath) + { + boolean isText = !hostEncoding.equals(localEncoding) && + SystemFileTransferModeRegistry.getDefault().isText(remotePath) && + !SystemEncodingUtil.getInstance().isXML(remotePath) ; + return !isText; + } + + protected boolean isBinary(IRemoteFile source) + { + // if binary or XML file, transfer in binary mode + if (source.isBinary() || SystemEncodingUtil.getInstance().isXML(source.getAbsolutePath())) + { + return true; + } + else + { + return false; + } + } + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding of the local operating system + * @param source the absolute path of the local copy + * @param srcEncoding The encoding of the local copy + * @param remotePath remote file that represents the file on the server + * @param rmtEncoding The encoding of the remote file. + */ + public void upload(String source, String srcEncoding, String remotePath, String rmtEncoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException { + int slashIndex = remotePath.lastIndexOf(getSeparator()); + if (slashIndex > -1) { + String remoteParentPath = remotePath.substring(0, slashIndex); + String remoteFileName = remotePath.substring(slashIndex + 1, remotePath.length()); + boolean isBinary = isBinary(srcEncoding, rmtEncoding, remotePath); + try + { + getFileService().upload(monitor, new File(source), remoteParentPath, remoteFileName, isBinary, srcEncoding, rmtEncoding); + } + catch (SystemMessageException e) + { + + } + } + } + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding of the local operating system + * @param source the absolute path of the local copy + * @param destination location to copy to + * @param encoding The encoding of the local copy + * @param monitor progress monitor + */ + public void upload(String source, IRemoteFile destination, String encoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + String remoteParentPath = destination.getParentPath(); + String remoteFileName = destination.getName(); + String hostEncoding = getRemoteEncoding(); // default host encoding + boolean isBinary = isBinary(encoding, hostEncoding, destination.getAbsolutePath()); + try + { + getFileService().upload(monitor, new File(source), remoteParentPath, remoteFileName, isBinary, encoding, hostEncoding); + } + catch (SystemMessageException e) + { + + } + } + + public void upload(InputStream stream, long totalBytes, IRemoteFile destination, String encoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + String remoteParentPath = destination.getParentPath(); + String remoteFileName = destination.getName(); + String hostEncoding = getRemoteEncoding(); // default host encoding + boolean isBinary = isBinary(encoding, hostEncoding, destination.getAbsolutePath()); + try + { + getFileService().upload(monitor, stream, remoteParentPath, remoteFileName, isBinary, hostEncoding); + } + catch (SystemMessageException e) + { + + } + } + + + + public boolean copy(IRemoteFile sourceFolderOrFile, IRemoteFile targetFolder, String newName, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + IFileService service = getFileService(); + try + { + return service.copy(monitor, sourceFolderOrFile.getParentPath(), sourceFolderOrFile.getName(), targetFolder.getAbsolutePath(), newName); + } + catch (SystemMessageException e) + { + + } + return false; + } + + public boolean copyBatch(IRemoteFile[] sourceFolderOrFiles, IRemoteFile targetFolder, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + IFileService service = getFileService(); + String[] sourceParents = new String[sourceFolderOrFiles.length]; + String[] sourceNames = new String[sourceFolderOrFiles.length]; + + for (int i = 0; i < sourceFolderOrFiles.length; i++) + { + sourceParents[i] = sourceFolderOrFiles[i].getParentPath(); + sourceNames[i] = sourceFolderOrFiles[i].getName(); + } + try + { + return service.copyBatch(monitor, sourceParents, sourceNames, targetFolder.getAbsolutePath()); + } + catch (SystemMessageException e) + { + + } + return false; + } + + public IRemoteFile getParentFolder(IRemoteFile folderOrFile) + { + try + { + return getRemoteFileObject(folderOrFile.getParentPath()); + } + catch (Exception e) + { + return null; + } + } + + public IRemoteFile createFile(IRemoteFile fileToCreate) throws RemoteFileSecurityException, RemoteFileIOException + { + IFileService service = getFileService(); + String parent = fileToCreate.getParentPath(); + String name = fileToCreate.getName(); + IHostFile newFile = null; + + try + { + newFile = service.createFile(monitor, parent, name); + } + catch (SystemMessageException e) + { + + } + return getHostFileToRemoteFileAdapter().convertToRemoteFile(this, getDefaultContext(), fileToCreate.getParentRemoteFile(), newFile); + } + + public IRemoteFile createFolder(IRemoteFile folderToCreate) throws RemoteFileSecurityException, RemoteFileIOException + { + IFileService service = getFileService(); + String parent = folderToCreate.getParentPath(); + String name = folderToCreate.getName(); + IHostFile newFolder = null; + try + { + newFolder = service.createFolder(monitor, parent, name); + } + catch (SystemMessageException e) + { + + } + return getHostFileToRemoteFileAdapter().convertToRemoteFile(this, getDefaultContext(), folderToCreate.getParentRemoteFile(), newFolder); + } + + public IRemoteFile createFolders(IRemoteFile folderToCreate) throws RemoteFileSecurityException, RemoteFileIOException + { + return createFolder(folderToCreate); + } + + public boolean delete(IRemoteFile folderOrFile, IProgressMonitor monitor) throws RemoteFolderNotEmptyException, RemoteFileSecurityException, RemoteFileIOException + { + boolean result = false; + IFileService service = getFileService(); + String parent = folderOrFile.getParentPath(); + String name = folderOrFile.getName(); + try + { + result = service.delete(monitor, parent, name); + folderOrFile.markStale(true); + } + catch (SystemMessageException e) + { + return false; + } + return result; + } + + public boolean deleteBatch(IRemoteFile[] folderOrFiles, IProgressMonitor monitor) throws RemoteFolderNotEmptyException, RemoteFileSecurityException, RemoteFileIOException + { + boolean result = false; + String[] parents = new String[folderOrFiles.length]; + String[] names = new String[folderOrFiles.length]; + for (int i = 0; i < folderOrFiles.length; i++) + { + parents[i] = folderOrFiles[i].getParentPath(); + names[i] = folderOrFiles[i].getName(); + folderOrFiles[i].markStale(true); + } + IFileService service = getFileService(); + try + { + result = service.deleteBatch(monitor, parents, names); + } + catch (SystemMessageException e) + { + return false; + } + return result; + } + + public boolean rename(IRemoteFile folderOrFile, String newName) throws RemoteFileSecurityException, RemoteFileIOException + { + boolean result = false; + removeCachedRemoteFile(folderOrFile); + IFileService service = getFileService(); + String srcParent = folderOrFile.getParentPath(); + String oldName = folderOrFile.getName(); + String newPath = srcParent + folderOrFile.getSeparator() + newName; + try + { + result = service.rename(monitor, srcParent, oldName, newName); + folderOrFile.getHostFile().renameTo(newPath); + } + catch (SystemMessageException e) + { + + } + return result; + } + + public boolean move(IRemoteFile sourceFolderOrFile, IRemoteFile targetFolder, String newName, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + boolean result = false; + IFileService service = getFileService(); + String srcParent = sourceFolderOrFile.getParentPath(); + String srcName = sourceFolderOrFile.getName(); + String tgtParent = targetFolder.getAbsolutePath(); + try + { + result = service.move(monitor, srcParent, srcName, tgtParent, newName); + sourceFolderOrFile.markStale(true); + targetFolder.markStale(true); + } + catch (SystemMessageException e) + { + + } + return result; + } + + + public boolean setLastModified(IRemoteFile folderOrFile, long newDate) throws RemoteFileSecurityException, RemoteFileIOException + { + // TODO Auto-generated method stub + return false; + } + + public boolean setReadOnly(IRemoteFile folderOrFile) throws RemoteFileSecurityException, RemoteFileIOException + { + // TODO Auto-generated method stub + return false; + } + + public ILanguageUtilityFactory getLanguageUtilityFactory() + { + if (_languageUtilityFactory == null) + { + _languageUtilityFactory = ((IFileServiceSubSystemConfiguration)getParentRemoteFileSubSystemFactory()).getLanguageUtilityFactory(this); + } + return _languageUtilityFactory; + } + + public void setLanguageUtilityFactory(ILanguageUtilityFactory factory) + { + _languageUtilityFactory = factory; + } + + public void search(IHostSearchResultConfiguration searchConfig) + { + ISearchService searchService = getSearchService(); + if (searchService != null) + { + SearchJob job = new SearchJob(searchConfig, searchService, getFileService()); + job.schedule(); + } + } + + public void cancelSearch(IHostSearchResultConfiguration searchConfig) + { + ISearchService searchService = getSearchService(); + if (searchService != null) + { + searchService.cancelSearch(null, searchConfig); + } + } + + public IHostSearchResultConfiguration createSearchConfiguration(IHostSearchResultSet resultSet, Object searchTarget, SystemSearchString searchString) + { + ISearchService searchService = getSearchService(); + if (searchService != null) + { + IFileServiceSubSystemConfiguration factory = (IFileServiceSubSystemConfiguration)getParentRemoteFileSubSystemFactory(); + if (factory != null) + { + return factory.createSearchConfiguration(getHost(), resultSet, searchTarget, searchString); + } + } + return null; + } + + + + /** + * Switch to use another protocol + */ + public void switchServiceFactory(IServiceSubSystemConfiguration fact) + { + if (fact != getSubSystemConfiguration() && fact instanceof IFileServiceSubSystemConfiguration) + { + IFileServiceSubSystemConfiguration factory = (IFileServiceSubSystemConfiguration)fact; + try + { + _cachedRemoteFiles.clear(); + disconnect(SystemBasePlugin.getActiveWorkbenchShell()); + } + catch (Exception e) + { + } + + _languageUtilityFactory = null; + IHost host = getHost(); + setSubSystemConfiguration(factory); + + IConnectorService oldConnectorService = getConnectorService(); + oldConnectorService.deregisterSubSystem(this); + + IConnectorService newConnectorService = factory.getConnectorService(host); + setConnectorService(newConnectorService); + + oldConnectorService.commit(); + newConnectorService.commit(); + + setFileService(factory.getFileService(host)); + setHostFileToRemoteFileAdapter(factory.getHostFileAdapter()); + setSearchService(factory.getSearchService(host)); + + } + } + + public Class getServiceType() + { + return IFileService.class; + } + + public void initializeSubSystem(IProgressMonitor monitor) + { + super.initializeSubSystem(monitor); + getFileService().initService(monitor); + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystemConfiguration.java new file mode 100644 index 00000000000..63ab897d457 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/FileServiceSubSystemConfiguration.java @@ -0,0 +1,82 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.servicesubsystem; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.IService; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.search.ISearchService; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSubSystemConfiguration; + + + +public abstract class FileServiceSubSystemConfiguration extends RemoteFileSubSystemConfiguration implements IFileServiceSubSystemConfiguration +{ + private Map _services; + private Map _searchServices; + + protected FileServiceSubSystemConfiguration() + { + super(); + _services = new HashMap(); + _searchServices = new HashMap(); + } + + public final Class getServiceType() + { + return IFileService.class; + } + + public final IService getService(IHost host) + { + return getFileService(host); + } + + public final IFileService getFileService(IHost host) + { + IFileService service = (IFileService)_services.get(host); + if (service == null) + { + service = createFileService(host); + _services.put(host, service); + } + return service; + } + + public final ISearchService getSearchService(IHost host) + { + ISearchService service = (ISearchService)_searchServices.get(host); + if (service == null) + { + service = createSearchService(host); + _searchServices.put(host, service); + } + return service; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSubSystemConfiguration#supportsServerLaunchProperties(org.eclipse.rse.model.IHost) + */ + public final boolean supportsServerLaunchProperties(IHost host) + { + return getConnectorService(host).supportsServerLaunchProperties(); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/IFileServiceSubSystem.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/IFileServiceSubSystem.java new file mode 100644 index 00000000000..fb04a645bca --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/IFileServiceSubSystem.java @@ -0,0 +1,44 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.servicesubsystem; + + +import org.eclipse.rse.core.servicesubsystem.IServiceSubSystem; +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.services.search.IHostSearchResultSet; +import org.eclipse.rse.subsystems.files.core.subsystems.IHostFileToRemoteFileAdapter; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; + + + +public interface IFileServiceSubSystem extends IRemoteFileSubSystem, IServiceSubSystem +{ + + /** + * Returns the file service used by this subsystem. By wrapping this service + * we can easily share it among connections or subsystems if that is desired. + * @return the file service wrapped by this subsystem. + */ + public IFileService getFileService(); + public IHostFileToRemoteFileAdapter getHostFileToRemoteFileAdapter(); + public IHostSearchResultConfiguration createSearchConfiguration(IHostSearchResultSet resultSet, Object searchTarget, SystemSearchString searchString); + + + +} //DefaultFileSubSystem \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/IFileServiceSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/IFileServiceSubSystemConfiguration.java new file mode 100644 index 00000000000..03356f09447 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/IFileServiceSubSystemConfiguration.java @@ -0,0 +1,43 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.servicesubsystem; + + +import org.eclipse.rse.core.servicesubsystem.IServiceSubSystemConfiguration; +import org.eclipse.rse.internal.subsystems.files.core.ILanguageUtilityFactory; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.services.search.IHostSearchResultSet; +import org.eclipse.rse.services.search.ISearchService; +import org.eclipse.rse.subsystems.files.core.subsystems.IHostFileToRemoteFileAdapter; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystemConfiguration; + + + +public interface IFileServiceSubSystemConfiguration extends IRemoteFileSubSystemConfiguration, IServiceSubSystemConfiguration +{ + public IFileService getFileService(IHost host); + public IFileService createFileService(IHost host); + public IHostFileToRemoteFileAdapter getHostFileAdapter(); + public ISearchService getSearchService(IHost host); + public ISearchService createSearchService(IHost host); + public IHostSearchResultConfiguration createSearchConfiguration(IHost host, IHostSearchResultSet resultSet, Object searchTarget, SystemSearchString searchString); + public ILanguageUtilityFactory getLanguageUtilityFactory(IRemoteFileSubSystem ss); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/OutputRefresh.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/OutputRefresh.java new file mode 100644 index 00000000000..31c5f5ca4f2 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/OutputRefresh.java @@ -0,0 +1,51 @@ +/******************************************************************************** + * Copyright (c) 2004, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.servicesubsystem; + +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.model.ISystemRegistry; +import org.eclipse.rse.model.ISystemResourceChangeEvents; +import org.eclipse.rse.model.SystemResourceChangeEvent; +import org.eclipse.rse.services.search.IHostSearchConstants; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; + + +public class OutputRefresh implements Runnable +{ + private IHostSearchResultConfiguration searchConfig; + private boolean isDone = false; + + public OutputRefresh(IHostSearchResultConfiguration searchConfig) + { + this.searchConfig = searchConfig; + this.isDone = searchConfig.getStatus() == IHostSearchConstants.FINISHED; + } + + public void run() { + + if (searchConfig != null) + { + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + registry.fireEvent(new SystemResourceChangeEvent(searchConfig, ISystemResourceChangeEvents.EVENT_REFRESH, null)); + + if (isDone) + { + registry.fireEvent(new SystemResourceChangeEvent(searchConfig, ISystemResourceChangeEvents.EVENT_SEARCH_FINISHED, null)); + } + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/SearchJob.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/SearchJob.java new file mode 100644 index 00000000000..9bdc97114e7 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/servicesubsystem/SearchJob.java @@ -0,0 +1,56 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.servicesubsystem; + +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.services.files.IFileService; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.services.search.ISearchService; +import org.eclipse.rse.subsystems.files.core.SystemFileResources; +import org.eclipse.swt.widgets.Display; + + +public class SearchJob extends Job +{ + IHostSearchResultConfiguration _searchConfig; + ISearchService _searchService; + IFileService _fileService; + + public SearchJob(IHostSearchResultConfiguration searchConfig, ISearchService searchService, IFileService fileService) + { + super(SystemFileResources.RESID_JOB_SEARCH_NAME); + _searchConfig = searchConfig; + _searchService = searchService; + _fileService = fileService; + } + + protected IStatus run(IProgressMonitor monitor) + { + _searchService.search(monitor, _searchConfig, _fileService); + + OutputRefresh refresh = new OutputRefresh(_searchConfig); + Display.getDefault().asyncExec(refresh); + monitor.done(); + return Status.OK_STATUS; + } + + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IHostFileToRemoteFileAdapter.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IHostFileToRemoteFileAdapter.java new file mode 100644 index 00000000000..edf844d5916 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IHostFileToRemoteFileAdapter.java @@ -0,0 +1,28 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; + +import org.eclipse.rse.services.files.IHostFile; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; + + + +public interface IHostFileToRemoteFileAdapter +{ + public IRemoteFile[] convertToRemoteFiles(FileServiceSubSystem ss, IRemoteFileContext context, IRemoteFile parent, IHostFile[] nodes); + public IRemoteFile convertToRemoteFile(FileServiceSubSystem ss, IRemoteFileContext context, IRemoteFile parent, IHostFile node); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFile.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFile.java new file mode 100644 index 00000000000..b7102d693d0 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFile.java @@ -0,0 +1,289 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; +import java.util.Date; + +import org.eclipse.rse.core.subsystems.IRemoteContainer; +import org.eclipse.rse.core.subsystems.IRemotePropertyHolder; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.files.IHostFile; +import org.eclipse.rse.subsystems.files.core.model.RemoteFileFilterString; + +/** + * This interface represents a handle to a remote file system object, + * which is either a file or a folder. This interface is similar to + * a java.io.File object, but with some significant differences: + *

      + *
    • This is an interface, so there are no static methods + *
    • This represents a "handle" to the remote file or folder. For editing purposes, + * you may want to manage a local copy of the remote file. The support + * for this is captured in the child interface IRemoteEditableFile + *
    • This are no action methods, only read methods. The action methods + * such as delete and rename are found in the file subsystem interface. + * All remote commands/actions are funnelled through subsystems in this + * remote system framework. + *
    • Similarly, the methods for listing objects are in IRemoteFileSubSystem, not here + *
    • Similarly, the methods for return an IRemoteFile object of the parent folder or + * root drive are in IRemoteFileSubSystem, not here. + *
    • Similarly, you do not construct these objects directly. Rather, there are + * factory methods in IRemoteFileSubSystem to create them. + *
    • There is no relative names. All names are fully qualified, and include + * the root, the path and the file name (unless this is a folder). + *
    • There are additional methods for querying the root (ie, c:\) and the + * parent directory (unqualified name of the parent directory). + *
    + *

    + * Note for subsystem providers: this method does not capture the set methods that the + * RemoteFileImpl class defines. For that, cast to IRemoteFileMutable. + */ +public interface IRemoteFile extends IRemoteContainer, IRemotePropertyHolder +{ + public static final char CONNECTION_DELIMITER = ':'; + public static final boolean ISROOT_YES = true; + public static final boolean ISROOT_NO = false; + + /** + * Querying properties for the property sheet can be expensive on some operating systems. + * By default all properties are shown on the property sheet for this object, unless true + * is returned from this query, in which only a couple properties are shown. + */ + public boolean showBriefPropertySet(); + /** + * Get parent subsystem + */ + public IRemoteFileSubSystem getParentRemoteFileSubSystem(); + /** + * Return the separator character for this file system: \ or /. + * Queries it from the subsystem factory. + */ + public char getSeparatorChar(); + /** + * Return the separator character for this file system, as a string: "\" or "/". + * Queries it from the subsystem factory. + */ + public String getSeparator(); + /** + * Return as a string the line separator for this file system + * Queries it from the subsystem factory. + */ + public String getLineSeparator(); + /** + * Return the connection this remote file is from. + */ + public IHost getSystemConnection(); + /** + * Return the parent remote file object expanded to get this object, or null if no such parent + */ + public IRemoteFile getParentRemoteFile(); + /** + * Return the filter string resolved to get this object + */ + public RemoteFileFilterString getFilterString(); + /** + * If this is a folder, it is possible that it is listed as part of a multiple filter string + * filter. In this case, when the folder is expanded, we want to filter the file names to + * show all the files that match any of the filter strings that have the same parent path. + *

    + * This method supports that by returning all the filter strings in the filter which have the + * same parent path as was used to produce this file. + */ + public RemoteFileFilterString[] getAllFilterStrings(); + /** + * Get fully qualified name: root plus path plus name. No connection name. + */ + public String getAbsolutePath(); + /** + * Get fully qualified connection and file name: profile.connection\path\file. + * Note the separator character between the profile name and the connection name is always '.' + * Note the separator character between the connection and qualified-file is always ':' + */ + public String getAbsolutePathPlusConnection(); + + /** + * Get the display name for this file. By default, this should be the same as the name + * If this object represents only a root drive, this is the same as getRoot(). + */ + public String getLabel(); + + /** + * Get unqualified file name. No root and no path. + * If this object represents only a root drive, this is the same as getRoot(). + */ + public String getName(); + /** + * Get fully qualified path and name of folder containing this file or folder. + * Returns the root and path. No file name, and no ending separator. + *

    + * If this object represent only a root drive, this returns null; + *

    + * Example: c:\folder1\folder2\file1.ext results in c:\folder1\folder2 + */ + public String getParentPath(); + /** + * Get fully qualified path and name of folder containing this file or folder, minus the root. + * Returns the path. No root prefix. No file name, and no ending separator. + *

    + * If this object represent only a root drive, this returns null; + *

    + * Example: c:\folder1\folder2\file1.ext results in folder1\folder2 + */ + public String getParentNoRoot(); + /** + * Get the root part of the name. + *

    + *

      + *
    • Example: c:\folder1\folder2\file1.ext results in c:\ + *
    • Example: /folder1/folder2/file1.ext results in / + *
    + */ + public String getRoot(); + /** + * Get the unqualified name of the parent directory containing this file or folder. + * Compare this to getParent() that returns the fully qualified parent directory. + * If this object represents only a root drive, this returns null. + *

    + * Example: c:\folder1\folder2\file1.ext results in folder2 + */ + public String getParentName(); + /** + * Return the extension part of a file name. + * Eg, for abc.java, return "java" + */ + public String getExtension(); + /** + * Returns true if this represents a root folder (eg: c:\\ or /). + */ + public boolean isRoot(); + /** + * Returns true if this represents a folder (eg: c:\\folder) + */ + public boolean isDirectory(); + /** + * Returns true if this represents a file, versus a root or folder + */ + public boolean isFile(); + /** + * Returns true if this represents an archive file, versues a non-archive file + */ + public boolean isArchive(); + + /** + * Returns true if this is a binary file + */ + public boolean isBinary(); + /** + * Returns true if this is a text file + */ + public boolean isText(); + /** + * Returns true if this is a hidden file. + */ + public boolean isHidden(); + /** + * Returns true if the application can read this file. + */ + public boolean canRead(); + /** + * Returns true if the application can write to this file. + */ + public boolean canWrite(); + + /** + * Returns true if this folder or file actually exists. + */ + public boolean exists(); + /** + * Returns the time (in milliseconds since epoch) this file was last modified. + */ + public long getLastModified(); + /** + * Return the last modified time as a Date object. + */ + public Date getLastModifiedDate() ; + /** + * Returns the length, in bytes, of this file. + */ + public long getLength(); + + /** + * Returns true if the ReadOnly Property should be shown in the property page. + */ + public boolean showReadOnlyProperty(); + + // ================================== + // for comparator interface... + // ================================== + /** + * Compare one remote file to another. This enables us to sort the files so they + * are shown folders-first, and in alphabetical order. + */ + public int compareTo(Object other) throws ClassCastException; + + /** + * Get the object. + */ + public Object getFile(); + + /** + * Note: if this remoteFile is the same as the file passed + * as parameter, then this method returns true. + */ + public boolean isAncestorOf(IRemoteFile file); + + /** + * Note: if this remoteFile is the same as the file passed + * as parameter, then this method returns true. + */ + public boolean isDescendantOf(IRemoteFile file); + + /** + * @return Any comments stored with the file in the file system or archive. + */ + public String getComment(); + + /** + * Returns the classification of this file. If the file is + * an executable, then "executable(...)" will be returned. If the + * file is a symbolic link then it will appear as "link(....):resolvedPath". + * The resolvedPath is the path that the link resolves to. + * A symbolic link that resolves to an executable would appear as "link(executable(...)):resolvedPath". + * By default this should just return "file". + * @return the classification. + */ + public String getClassification(); + + /** + * Returns whether the file is executable or not. + * @return true if the file is executable, false otherwise. + */ + public boolean isExecutable(); + + /** + * Returns whether the file is a symbolic link or not. + * @return true if the file is a symbolic link, false otherwise. + */ + public boolean isLink(); + + /** + * Returns the canonical path of the remote file. + * @return the resolved path if the file is a symbolic link, or + */ + public String getCanonicalPath(); + + public IHostFile getHostFile(); + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileContext.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileContext.java new file mode 100644 index 00000000000..2499c135347 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileContext.java @@ -0,0 +1,68 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; +import org.eclipse.rse.subsystems.files.core.model.RemoteFileFilterString; + +/** + * This interface represents a place to hold contextual information stored within + * each remote file object. + *

    + * We store in here information that might be the same for multiple remote file objects, + * in order to save memory. This way, we can merely hold a reference to a single object, + * which itself may have numerous pieces of information helpful when processing actions + * on a particular remote object. + */ +public interface IRemoteFileContext +{ + + /** + * Get parent subsystem + */ + public IRemoteFileSubSystem getParentRemoteFileSubSystem(); + /** + * Return the parent remote file object expanded to get this object, or null if no such parent + */ + public IRemoteFile getParentRemoteFile(); + /** + * Return the filter string used to resolve the list resulting in this remote object. + */ + public RemoteFileFilterString getFilterString(); + /** + * Return all the filter string objects applicable to this folder object. + */ + public RemoteFileFilterString[] getAllFilterStrings(); + + /** + * Set parent subsystem + */ + public void setParentRemoteFileSubSystem(IRemoteFileSubSystem parentSubSystem); + /** + * Set the parent remote file object expanded to get this object, or null if no such parent + */ + public void setParentRemoteFile(IRemoteFile parentFile); + /** + * Set the filter string used to resolve the list resulting in this remote object. + */ + public void setFilterString(RemoteFileFilterString filterString); + /** + * Add an additional filter string. This is called for folders in a multi-filter string + * filter. It is called for each filter string that lists the contents of the same parent + * path, when show subdirs is true. It is needed to support the subsequent expansion of + * this subdirectory, so that it can filter on all the appropriate filter strings. + */ + public void addFilterString(RemoteFileFilterString additionalFilterString); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileExceptionCodes.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileExceptionCodes.java new file mode 100644 index 00000000000..76edf296990 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileExceptionCodes.java @@ -0,0 +1,27 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; + +/** + * Intended as a placeholder for all exception code constants + */ + +public interface IRemoteFileExceptionCodes { + + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileExceptionMessages.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileExceptionMessages.java new file mode 100644 index 00000000000..6ff78c0e2c3 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileExceptionMessages.java @@ -0,0 +1,37 @@ +/******************************************************************************** + * Copyright (c) 2000, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; +/** + * Keys into the core plugin's resource bundle for error messages related + * to exceptions thrown by the remote file system framework. + */ +public interface IRemoteFileExceptionMessages +{ + //public static final String PLUGIN_ID ="org.eclipse.rse.systems"; + //public static final String PLUGIN_ID =ISystemMessages.PLUGIN_ID; + // Message prefix + //public static final String FILEMSG_PREFIX = PLUGIN_ID+".ui.filemsg."; + + // Messages + public static final String FILEMSG_IO_ERROR = "RSEF1001"; + public static final String FILEMSG_SECURITY_ERROR = "RSEF1002"; + + public static final String FILEMSG_FOLDER_NOTEMPTY = "RSEF1003"; + public static final String FILEMSG_FOLDER_NOTFOUND = "RSEF1004"; + + public static final String FILEMSG_FILE_NOTFOUND = "RSEF1005"; +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileFactory.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileFactory.java new file mode 100644 index 00000000000..44427c22573 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileFactory.java @@ -0,0 +1,42 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; + +/** + * This interface represents a handle to a remote file object, + * which is either a universalFileSystem or an ifsFileSystem. + */ + +public interface IRemoteFileFactory +{ + + /** + * Get the RemoteFile object + */ + public IRemoteFile createRemoteFile(IRemoteFileContext context, Object obj, boolean isRoot); + + /** + * Get the RemoteFile object when we know if it is a exists or not + */ + public IRemoteFile createRemoteFile(IRemoteFileContext context, Object obj, boolean isRoot, boolean exists); + + /** + * Get the RemoteFile object when we know if it is a exists or not and whether it is a directory or not + */ + public IRemoteFile createRemoteFile(IRemoteFileContext context, Object obj, boolean isRoot, boolean exists, boolean isDir); + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileSubSystem.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileSubSystem.java new file mode 100644 index 00000000000..b0f1dd2a098 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileSubSystem.java @@ -0,0 +1,717 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; +import java.io.File; +import java.io.InputStream; +import java.net.InetAddress; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.internal.subsystems.files.core.ILanguageUtilityFactory; +import org.eclipse.rse.model.SystemRemoteResourceSet; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.services.search.IHostSearchResultConfigurationFactory; + + +// +/** + * Specialized interface for remote file subsystems. + *

    + * These are unix/windows like file systems, versus native OS/400 or OS/390 + * file subsystems. Rather, it is more like the IFS and HFS systems on + * these operating systems. + *

    + * The idea is to encourage a common API and GUI layer that works + * with any remote unix-like file system on any remote operating system. + */ +/** + * @lastgen interface RemoteFileSubSystem extends SubSystem {} + */ + +public interface IRemoteFileSubSystem extends ISubSystem{ + + // ---------------------- + // HELPER METHODS... + // ---------------------- + + /** + * Return parent subsystem factory, cast to a RemoteFileSubSystemFactory + */ + public IRemoteFileSubSystemConfiguration getParentRemoteFileSubSystemFactory(); + /** + * Return true if file names are case-sensitive. Used when doing name or type filtering + */ + public boolean isCaseSensitive(); + + // -------------------------------- + // FILE SYSTEM ATTRIBUTE METHODS... + // -------------------------------- + /** + * Return in string format the character used to separate folders. Eg, "\" or "/". + *
    + * Shortcut to {@link #getParentRemoteFileSubSystemFactory()}.getSeparator() + */ + public String getSeparator(); + + /** + * Return in character format the character used to separate folders. Eg, "\" or "/" + *
    + * Shortcut to {@link #getParentRemoteFileSubSystemFactory()}.getSeparatorChar() + */ + public char getSeparatorChar(); + + /** + * Return in string format the character used to separate paths. Eg, ";" or ":" + *
    + * Shortcut to {@link #getParentRemoteFileSubSystemFactory()}.getPathSeparator() + */ + public String getPathSeparator(); + + /** + * Return in char format the character used to separate paths. Eg, ";" or ":" + *
    + * Shortcut to {@link #getParentRemoteFileSubSystemFactory()}.getPathSeparatorChar() + */ + public char getPathSeparatorChar(); + + /** + * Return as a string the line separator. + *
    + * Shortcut to {@link #getParentRemoteFileSubSystemFactory()}.getLineSeparator() + */ + public String getLineSeparator(); + + // ---------------------- + // FILE SYSTEM METHODS... + // ---------------------- + + /** + * Return a list of roots/drives on the remote system. + * This version is called directly by users. + */ + public IRemoteFile[] listRoots() throws InterruptedException; + /** + * Return a list of all remote folders in the given parent folder on the remote system + * @param parent The parent folder to list folders in + */ + public IRemoteFile[] listFolders(IRemoteFile parent); + + /** + * Return a full list of remote folders in the given parent folder on the remote system. + * @param parent The parent folder to list folders in + * @param fileNameFilter The name pattern for subsetting the file list when this folder is subsequently expanded + */ + public IRemoteFile[] listFolders(IRemoteFile parent, String fileNameFilter); + + /** + * Return a list of all remote files in the given parent folder on the remote system + * @param parent The parent folder to list files in + */ + public IRemoteFile[] listFiles(IRemoteFile parent); + + /** + * Return a list of remote files in the given folder, which match the given name pattern. + * @param parent The parent folder to list files in + * @param fileNameFilter The name pattern to subset the list by, or null to return all files. + */ + public IRemoteFile[] listFiles(IRemoteFile parent, String fileNameFilter); + + /** + * Return a list of all remote folders and files in the given folder. The list is not subsetted. + * @param parent The parent folder to list folders and files in + */ + public IRemoteFile[] listFoldersAndFiles(IRemoteFile parent); + + /** + * Return a list of remote folders and files in the given folder. Only file names are subsettable + * by the given file name filter. It can be null for no subsetting. + * @param parent The parent folder to list folders and files in + * @param fileNameFilter The name pattern to subset the file list by, or null to return all files. + */ + public IRemoteFile[] listFoldersAndFiles(IRemoteFile parent, String fileNameFilter); + + /** + * Return a list of remote folders and files in the given folder. + *

    + * The files part of the list is subsetted by the given file name filter. + * It can be null for no subsetting. + * This version is called by RemoteFileSubSystemImpl's resolveFilterString(s). + * @param parent The parent folder to list folders and files in + * @param fileNameFilter The name pattern to subset the file list by, or null to return all files. + * @param context The holder of state information + */ + public IRemoteFile[] listFoldersAndFiles(IRemoteFile parent, String fileNameFilter, IRemoteFileContext context); + + /** + * Return a subsetted list of remote folders in the given parent folder on the remote system. + * This version is called by RemoteFileSubSystemImpl's resolveFilterString(s) + * noteThis method should be abstract but MOF doesn't allow abstract impl classes at this point + * @param parent The parent folder to list folders in + * @param fileNameFilter The name pattern for subsetting the file list when this folder is subsequently expanded + * @param context The holder of state information + */ + public IRemoteFile[] listFolders(IRemoteFile parent, String fileNameFilter, IRemoteFileContext context); + + /** + * Return a list of remote files in the given folder, which match the given name pattern. + * This version is called by RemoteFileSubSystemImpl's resolveFilterString(s) + * noteThis method should be abstract but MOF doesn't allow abstract impl classes at this point + * @param parent The parent folder to list files in + * @param fileNameFilter The name pattern to subset the list by, or null to return all files. + * @param context The holder of state information + */ + public IRemoteFile[] listFiles(IRemoteFile parent, String fileNameFilter, IRemoteFileContext context); + /** + * Given a search configuration, searches for its results. + * @param searchConfig a search configuration. + */ + public void search(IHostSearchResultConfiguration searchConfig); + + /** + * Given a search configuration, cancel the search. + * @param searchConfig a search configuration. + */ + public void cancelSearch(IHostSearchResultConfiguration searchConfig); + + + /** + * Given a folder or file, return its parent folder object. + * @param folderOrFile folder or file to return parent of. + */ + public IRemoteFile getParentFolder(IRemoteFile folderOrFile); + + /** + * Given a folder or file, return its parent folder name, fully qualified + * @param folderOrFile folder or file to return parent of. + */ + public String getParentFolderName(IRemoteFile folderOrFile); + + /** + * Get the default encoding of the target system + * @return the encoding + */ + public String getRemoteEncoding(); + + /** + * Given a set of fully qualified file or folder names, return an ISystemResourceSet object for it. + * @param folderOrFileNames Fully qualified folder or file names + */ + public SystemRemoteResourceSet getRemoteFileObjects(List folderOrFileNames) throws SystemMessageException; + + /** + * Given a fully qualified file or folder name, return an IRemoteFile object for it. + * @param folderOrFileName Fully qualified folder or file name + */ + public IRemoteFile getRemoteFileObject(String folderOrFileName) throws SystemMessageException; + + /** + * Given a un-qualified file or folder name, and its parent folder object, + * return an IRemoteFile object for the file. + * @param parent Folder containing the folder or file + * @param folderOrFileName Un-qualified folder or file name + */ + public IRemoteFile getRemoteFileObject(IRemoteFile parent, String folderOrFileName) throws SystemMessageException; + + /** + * Given a key, returns a search result object for it. For the key, see < + * @param key the key that uniquely identifies a search result. + */ + public IRemoteSearchResult getRemoteSearchResultObject(String key) throws SystemMessageException; + + /** + * Create a new file, given its IRemoteFile object (these do not have to represent existing files). + *

    + *

      + *
    • The parent folder must exist for this to succeed. + *
    • If this file already exists, this is a no-op. + *
    • If the given object is a folder, not a file, this is a no-op. + *
    + * + * @see #createFolders(IRemoteFile) + * + * @param fileToCreate The object representing the file to be created. + * @return The same input object returned for convenience. Will throw exception if it fails. + */ + public IRemoteFile createFile(IRemoteFile fileToCreate) throws RemoteFileSecurityException, RemoteFileIOException; + + /** + * Create a new folder, given its IRemoteFile object (these do not have to represent existing folders) + *

    + *

      + *
    • The parent folder must exist for this to succeed. + *
    • If this folder already exists, this is a no-op. + *
    • If the given object is a file, not a folder, this is a no-op. + *
    + * + * @see #createFolders(IRemoteFile) + * + * @param folderToCreate The object representing the folder to be created. + * @return The same input object returned for convenience. Will throw exception if it fails. + */ + public IRemoteFile createFolder(IRemoteFile folderToCreate) throws RemoteFileSecurityException, RemoteFileIOException; + + /** + * Given an IRemoteFile for a folder, this will create that folder and any missing parent folders in its path. + * Use getParentFolder to get the parent object of your file or folder in order to call this method. + *

    + *

      + *
    • If this folder already exists, this is a no-op. + *
    • If the given object is a file, not a folder, this is a no-op. + *
    + * + * @see #getParentFolder(IRemoteFile) + * + * @param folderToCreate The object representing the folder to be created, along with its parents. + * @return The same input object returned for convenience. Will throw exception if it fails. + */ + public IRemoteFile createFolders(IRemoteFile folderToCreate) throws RemoteFileSecurityException, RemoteFileIOException; + + /** + * Delete the given remote file or folder. + *
      + *
    • If the input is a folder, that folder must be empty for this to succeed. + *
    + * + * @param folderOrFile represents the object to be deleted. + * @return false if the given folder/file didn't exist to begin with, else true. Throws an exception if anything fails. + * + * @deprecated use the delete that takes a monitor now + */ + public boolean delete(IRemoteFile folderOrFile) throws RemoteFolderNotEmptyException, RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Delete the given remote file or folder. + *
      + *
    • If the input is a folder, that folder must be empty for this to succeed. + *
    + * + * @param folderOrFile represents the object to be deleted. + * @param monitor progressMonitor + * @return false if the given folder/file didn't exist to begin with, else true. Throws an exception if anything fails. + */ + public boolean delete(IRemoteFile folderOrFile, IProgressMonitor monitor) throws RemoteFolderNotEmptyException, RemoteFileSecurityException, RemoteFileIOException; + + /** + * Delete the given batch of remote file or folder. + *
      + *
    • If any of the inputs are a folder, those folders must be empty for this to succeed. + *
    + * + * @param folderOrFiles represents the objects to be deleted. + * @param monitor progressMonitor + * @return false if any of the given folder/file dont exist to begin with, else true. Throws an exception if anything fails. + */ + public boolean deleteBatch(IRemoteFile[] folderOrFiles, IProgressMonitor monitor) throws RemoteFolderNotEmptyException, RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Rename the given remote file or folder. This renames it in memory and, iff it exists, on disk. + * @param folderOrFile represents the object to be renamed. + * @param newName new name to give it. + * @return false if the given folder/file didn't exist on disk (still renamed in memory), else true. Throws an exception if anything fails. + */ + public boolean rename(IRemoteFile folderOrFile, String newName) throws RemoteFileSecurityException, RemoteFileIOException; + + /** + * Move a file or folder to a new target parent folder. + * + * @param sourceFolderOrFile The file or folder to move + * @param targetFolder The folder to move to. No guarantee it is on the same system, so be sure to check getSystemConnection()! + * @param newName The new name for the moved file or folder + * @return false true iff the move succeeded + */ + public boolean move(IRemoteFile sourceFolderOrFile, IRemoteFile targetFolder, String newName) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Move a file or folder to a new target parent folder. + * + * @param sourceFolderOrFile The file or folder to move + * @param targetFolder The folder to move to. No guarantee it is on the same system, so be sure to check getSystemConnection()! + * @param newName The new name for the moved file or folder + * @param monitor progress monitor + * @return false true iff the move succeeded + */ + public boolean move(IRemoteFile sourceFolderOrFile, IRemoteFile targetFolder, String newName,IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + /** + * Set the last modified date for the given file or folder. Like a Unix "touch" operation. + * Folder or file must exist on disk for this to succeed. + * + * @param folderOrFile represents the object to be renamed. + * @param newDate new date, in milliseconds from epoch, to assign. + * @return false if the given folder/file didn't exist on disk (operation fails), else true. Throws an exception if anything fails. + */ + public boolean setLastModified(IRemoteFile folderOrFile, long newDate) throws RemoteFileSecurityException, RemoteFileIOException; + + /** + * Set a file to readonly. + * Folder or file must exist on disk for this to succeed. + * + * @param folderOrFile represents the object to be renamed. + * @return false if the given folder/file didn't exist on disk (operation fails), else true. Throws an exception if anything fails. + */ + public boolean setReadOnly(IRemoteFile folderOrFile) throws RemoteFileSecurityException, RemoteFileIOException; + + + // ---------------------------- + // METHODS FOR FILE TRANSFER... + // ---------------------------- + + // Beginning of methods for downloading remote files from the server + + /** + * Copy a file or folder to a new target parent folder. + * + * @param sourceFolderOrFile The file or folder to copy + * @param targetFolder The folder to copy to. No guarantee it is on the same system, so be sure to check getSystemConnection()! + * @param newName The new name for the copied file or folder + * @return false true iff the copy succeeded + */ + public boolean copy(IRemoteFile sourceFolderOrFile, IRemoteFile targetFolder, String newName, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + /** + * Copy a set of remote files or folders to a new target parent folder. Precondition: Sources and target must all be on the same system! + * + * @param sourceFolderOrFiles The file or folder to copy + * @param targetFolder The folder to copy to. + * @return false true iff all copies succeeded + */ + public boolean copyBatch(IRemoteFile[] sourceFolderOrFile, IRemoteFile targetFolder, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Get the remote file and save it locally. The file is saved in the encoding + * of the operating system. Two exceptions: if the remote file is binary, encoding does not apply. + * If the remote file is a XML file, then it will be copied to local in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * @param source remote file that represents the file to be obtained + * @param destination the absolute path of the local file + * @param monitor the progress monitor + */ + public void download(IRemoteFile source, String destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Get the remote file and save it locally. The file is saved in the encoding + * specified. Two exceptions: if the remote file is binary, encoding does not apply. + * If the remote file is a XML file, then it will be copied to local in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * @param source remote file that represents the file to be obtained + * @param destination the absolute path of the local file + * @param encoding the encoding of the local file + * @param monitor the progress monitor + */ + public void download(IRemoteFile source, String destination, String encoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Get the remote file and save it locally. The file is saved in UTF-8 encoding. + * Two exceptions: if the remote file is binary, encoding does not apply. + * If the remote file is a XML file, then it will be copied to local in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * This is a recommended method to use for file transfer. + * @param source remote file that represents the file to be obtained + * @param destination the absolute path of the local file + * @param monitor the progress monitor + */ + public void downloadUTF8(IRemoteFile source, String destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Get the remote file and save it locally. The file is saved in the encoding + * of the operating system. Two exceptions: if the remote file is binary, encoding does not apply. + * If the remote file is a XML file, then it will be copied to local in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * @param source remote file that represents the file to be obtained + * @param destination the local file + * @param monitor the progress monitor + */ + public void download(IRemoteFile source, File destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Get the remote file and save it locally. The file is saved in the encoding + * specified. Two exceptions: if the remote file is binary, encoding does not apply. + * If the remote file is a XML file, then it will be copied to local in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * @param source remote file that represents the file to be obtained + * @param destination the local file + * @param encoding the encoding of the local file + * @param monitor the progress monitor + */ + public void download(IRemoteFile source, File destination, String encoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Get the remote file and save it locally. The file is saved in UTF-8 encoding. + * Two exceptions: if the remote file is binary, encoding does not apply. + * If the remote file is a XML file, then it will be copied to local in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * This is a recommended method to use for file transfer. + * @param source remote file that represents the file to be obtained + * @param destination the local file + * @param monitor the progress monitor + */ + public void downloadUTF8(IRemoteFile source, File destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Get the remote file and save it locally. The file is saved in the encoding + * of the operating system. Two exceptions: if the remote file is binary, encoding does not apply. + * If the remote file is a XML file, then it will be copied to local in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * @param source remote file that represents the file to be obtained + * @param destination the local file + * @param monitor the progress monitor + */ + public void download(IRemoteFile source, IFile destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Get the remote file and save it locally. The file is saved in the encoding + * specified. Two exceptions: if the remote file is binary, encoding does not apply. + * If the remote file is a XML file, then it will be copied to local in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * @param source remote file that represents the file to be obtained + * @param destination the local file + * @param encoding the encoding of the local file + * @param monitor the progress monitor + */ + public void download(IRemoteFile source, IFile destination, String encoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Get the remote file and save it locally. The file is saved in UTF-8 encoding. + * Two exceptions: if the remote file is binary, encoding does not apply. + * If the remote file is a XML file, then it will be copied to local in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * This is a recommended method to use for file transfer. + * @param source remote file that represents the file to be obtained + * @param destination the local file + * @param monitor the progress monitor + */ + public void downloadUTF8(IRemoteFile source, IFile destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + // End of methods to download remote files from the server + + + // Beginning of methods to upload local files to the server + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding of the local operating system. + * Two exceptions: if the local file is binary, encoding does not apply. + * If the local file is a XML file, then it will be copied to remote in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * @param source the absolute path of the local copy + * @param destination remote file that represents the file on the server + * @param monitor the progress monitor + */ + public void upload(String source, IRemoteFile destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding specified. + * Two exceptions: if the local file is binary, encoding does not apply. + * If the local file is a XML file, then it will be copied to remote in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * @param source the absolute path of the local copy + * @param destination remote file that represents the file on the server + * @param encoding the encoding of the local copy + * @param monitor the progress monitor + */ + public void upload(String source, IRemoteFile destination, String encoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + /** + * Put local data to a remote location. The local data is assumed to be in the encoding specified. + * @param stream the input stream containing the local data. + * @param totalBytes the total number of bytes in the stream, or -1 if unknown. If -1 is specified, then the progress monitor must be null. + * @param destination remote file that represents the file on the server. + * @param encoding the encoding of the local data, or null to specify binary. + * @param monitor the progress monitor. + * @throws RemoteFileSecurityException + * @throws RemoteFileIOException + */ + public void upload(InputStream stream, long totalBytes, IRemoteFile destination, String encoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding of the local operating system. + * Two exceptions: if the local file is binary, encoding does not apply. + * If the local file is a XML file, then it will be copied to remote in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * @param source the absolute path of the local copy + * @param destination remote file that represents the file on the server + * @param monitor the progress monitor + */ + public void upload(String source, String destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding of the local operating system. + * Two exceptions: if the local file is binary, encoding does not apply. + * If the local file is a XML file, then it will be copied to remote in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * @param source the absolute path of the local copy + * @param srcEncoding the encoding of the local copy + * @param remotePath remote file that represents the file on the server + * @param rmtEncoding the encoding of the remote file. + */ + public void upload(String source, String srcEncoding, String remotePath, String rmtEncoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + /** + * Put the local copy of the remote file back to the remote location. The local file + * must be in UTF-8 encoding. + * Two exceptions: if the local file is binary, encoding does not apply. + * If the local file is a XML file, then it will be copied to remote in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * @param source the absolute path of the local copy + * @param destination remote file that represents the file on the server + * @param monitor the progress monitor + */ + public void uploadUTF8(String source, IRemoteFile destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding of the local operating system. + * Two exceptions: if the local file is binary, encoding does not apply. + * If the local file is a XML file, then it will be copied to remote in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * @param source the local copy + * @param destination remote file that represents the file on the server + * @param monitor the progress monitor + */ + public void upload(File source, IRemoteFile destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding specified. + * Two exceptions: if the local file is binary, encoding does not apply. + * If the local file is a XML file, then it will be copied to remote in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * @param source the local copy + * @param destination remote file that represents the file on the server + * @param encoding the encoding of the local copy + * @param monitor the progress monitor + */ + public void upload(File source, IRemoteFile destination, String encoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Put the local copy of the remote file back to the remote location. The local file + * must be in UTF-8 encoding. + * Two exceptions: if the local file is binary, encoding does not apply. + * If the local file is a XML file, then it will be copied to remote in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * @param source the local copy + * @param destination remote file that represents the file on the server + * @param monitor the progress monitor + */ + public void uploadUTF8(File source, IRemoteFile destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding of the local operating system. + * Two exceptions: if the local file is binary, encoding does not apply. + * If the local file is a XML file, then it will be copied to remote in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * @param source the local copy + * @param destination remote file that represents the file on the server + * @param monitor the progress monitor + */ + public void upload(IFile source, IRemoteFile destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding specified + * @param source the local copy + * @param destination remote file that represents the file on the server + * @param encoding the encoding of the local copy + * @param monitor the progress monitor + */ + public void upload(IFile source, IRemoteFile destination, String encoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * Put the local copy of the remote file back to the remote location. The local file + * must be in UTF-8 encoding. + * Two exceptions: if the local file is binary, encoding does not apply. + * If the local file is a XML file, then it will be copied to remote in the encoding + * specified in the XML declaration, or as determined from the XML specification. + * @param source the local copy + * @param destination remote file that represents the file on the server + * @param monitor the progress monitor + */ + public void uploadUTF8(IFile source, IRemoteFile destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException; + + + /** + * @generated This field/method will be replaced during code generation + * @return The value of the HomeFolder attribute + */ + String getHomeFolder(); + + /** + * @generated This field/method will be replaced during code generation + * @param value The new value of the HomeFolder attribute + */ + void setHomeFolder(String value); + + /** + * Returns a language utility factory associated with this subsystem. + * @return the language utility factory associated with this subsystem. + */ + public ILanguageUtilityFactory getLanguageUtilityFactory(); + + /** + * Returns an unused port number on the remote host that could be used + * by any tool on the host. + * @return an unused port number on the host, or -1 if none could be found. + */ + public int getUnusedPort(); + + + /** + * Return a list of roots/drives on the remote system. + * This version is called by RemoteFileSubSystemImpl's resolveFilterString(s) + * noteThis method should be abstract but MOF doesn't allow abstract impl classes at this point + */ + public IRemoteFile[] listRoots(IRemoteFileContext context) throws InterruptedException; + + /** + * Returns the TCP/IP address for the local system that is accessible from + * the remote server. If the local system has multiple IP addresses (because of multiple + * network cards or VPN), then this will return the address that the remote system + * can use to "call back" to the PC. There must be a network connection between the local + * system and the remote system for this method to work. If no network connection exists, + * then this method returns null. + * + * @return the local TCP/IP address accessible from the remote system, or null if + * no address can be resolved. + */ + public InetAddress getLocalAddress(); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileSubSystemConfiguration.java new file mode 100644 index 00000000000..454ac993fc5 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileSubSystemConfiguration.java @@ -0,0 +1,111 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; +import org.eclipse.rse.core.subsystems.ISubSystemConfiguration; +import org.eclipse.rse.ui.validators.ISystemValidator; +import org.eclipse.rse.ui.validators.ValidatorFileName; +import org.eclipse.rse.ui.validators.ValidatorFolderName; + + +// +/** + * Specialization for file subsystem factories. + */ +/** + * @lastgen interface RemoteFileSubSystemFactory extends SubSystemFactory {} + */ + +public interface IRemoteFileSubSystemConfiguration extends ISubSystemConfiguration +{ + /** + * Return true if subsystems of this factory support the environment variables property. + * Return true to show it, return false to hide it. + */ + public boolean supportsEnvironmentVariablesPropertyPage(); + + /** + * Return true if subsystems for this configuration support search functionality. + * @return true if search is supported + */ + public boolean supportsSearch(); + + /** + * Return true if subsystems for this configuration support archive management. + * @return true if archive management is supported + */ + public boolean supportsArchiveManagement(); + + /** + * Tell us if this is a unix-style file system or a windows-style file system. The + * default is windows. + * Child classes must call this, so we know how to respond to separator and path-separator requests. + */ + public boolean isUnixStyle(); + /** + * Tell us if this file system is case sensitive. The default is isUnixStyle(), and so should + * rarely need to be overridden. + */ + public boolean isCaseSensitive(); + + // -------------------------------- + // VALIDATOR METHODS... + // -------------------------------- + /** + * Return validator used in filter string dialog for the path part of the filter string + */ + public ISystemValidator getPathValidator(); + /** + * Return validator used in filter string dialog for the file part of the filter string + */ + public ISystemValidator getFileFilterStringValidator(); + /** + * Return validator used when creating or renaming files + */ + public ValidatorFileName getFileNameValidator(); + /** + * Return validator used when creating or renaming folders + */ + public ValidatorFolderName getFolderNameValidator(); + // -------------------------------- + // FILE SYSTEM ATTRIBUTE METHODS... + // -------------------------------- + /** + * Return in string format the character used to separate folders. Eg, "\" or "/" + */ + public String getSeparator(); + /** + * Return in character format the character used to separate folders. Eg, "\" or "/" + */ + public char getSeparatorChar(); + /** + * Return in string format the character used to separate paths. Eg, ";" or ":" + */ + public String getPathSeparator(); + /** + * Return in char format the character used to separate paths. Eg, ";" or ":" + */ + public char getPathSeparatorChar(); + /** + * Return as a string the line separator. + */ + public String getLineSeparator(); + /** + * Return the default remote systems editor profile ID for files on this subsystem + */ + public String getEditorProfileID(); + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileWrapper.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileWrapper.java new file mode 100644 index 00000000000..d169156e80e --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteFileWrapper.java @@ -0,0 +1,23 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; +public interface IRemoteFileWrapper +{ + + + IRemoteFile getRemoteFile(); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteSearchConstants.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteSearchConstants.java new file mode 100644 index 00000000000..0131361dc94 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteSearchConstants.java @@ -0,0 +1,40 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; + +public interface IRemoteSearchConstants { + + /** + * Status indicating configuration is still running, 0. + */ + public static final int RUNNING = 0; + + /** + * Status indicating configuration has finished, 1. + */ + public static final int FINISHED = 1; + + /** + * Status indicating configuration has been cancelled, 2. + */ + public static final int CANCELLED = 2; + + /** + * Status indicating configuration has been disconnected, 3. + */ + public static final int DISCONNECTED = 3; +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteSearchResult.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteSearchResult.java new file mode 100644 index 00000000000..5571a78558b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IRemoteSearchResult.java @@ -0,0 +1,78 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; + +import org.eclipse.rse.core.subsystems.IRemoteLineReference; +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.search.IHostSearchResult; + + +/** + * This interface represents a handle to a search result. + */ +public interface IRemoteSearchResult extends IRemoteLineReference, IHostSearchResult +{ + + + + + /** + * Gets the text to display for a search result. + * @return the text. + */ + public String getText(); + + /** + * Gets the index of this search result in the context of its parent. + * @return the index. + */ + public int getIndex(); + + /** + * Gets the search string that this result matches. + * @return the search string. + */ + public SystemSearchString getMatchingSearchString(); + + /** + * Add a match to the result. A match comprises a char start offset and a char end offset, both + * relative to the beginning of the file. The matches are added in order. + * @param startOffset the char start offset, from the beginning of the file. + * @param endOffset the char end offset, from the beginning of the file. + */ + public void addMatch(int startOffset, int endOffset); + + /** + * Gets the number of matches in this line. + * @return the number of matches. + */ + public int numOfMatches(); + + /** + * Gets the char start offset for the given match index. + * @param matchIndex the match index. For example, to get the start offset for the first match, specify 0. + * @return the char start offset. + */ + public int getCharStart(int matchIndex); + + /** + * Gets the char end offset for the given match index. + * @param matchIndex the match index. For example, to get the end offset for the first match, specify 0. + * @return the char end offset. + */ + public int getCharEnd(int matchIndex); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IVirtualRemoteFile.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IVirtualRemoteFile.java new file mode 100644 index 00000000000..da721c093cb --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/IVirtualRemoteFile.java @@ -0,0 +1,29 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; + +public interface IVirtualRemoteFile extends IRemoteFile +{ + public String getVirtualName(); + public boolean isVirtualFolder(); + public boolean isVirtualFile(); + public String getComment(); + public long getCompressedSize(); + public String getCompressionMethod(); + public double getCompressionRatio(); + public long getExpandedSize(); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFile.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFile.java new file mode 100644 index 00000000000..34dd92c743c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFile.java @@ -0,0 +1,1052 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.Platform; +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.subsystems.IRemoteContainer; +import org.eclipse.rse.core.subsystems.RemoteChildrenContentsType; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.model.ISystemContentsType; +import org.eclipse.rse.services.clientserver.StringComparePatternMatcher; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.subsystems.files.core.model.RemoteFileFilterString; +import org.eclipse.rse.subsystems.files.core.model.SystemFileTransferModeRegistry; +import org.eclipse.rse.ui.ISystemPreferencesConstants; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + + +/** + * A remote file represents a named file on a remote file system. This class + * works with remote file names that do not include the preceding "" + * prefix. Such ultimately-qualified names are known as IRemoteFilePath names. + *

    + * Base parent class that supplies all of the + * functionality required by the IRemoteFile interface. + *

    + * This base functionality is possible because this is a + * read-only representation of a remote file ... all actions + * like delete and rename are handled by the subsystem. + *

    + * For all this base functionality to work, the subsystem + * that creates this object must call the setter methods to + * prefill this object with the core required information: + *

      + *
    • {@link #RemoteFileImpl(IRemoteFileContext)} constructor sets the parent subsystem + *
    • {@link #setAbsolutePath(String, String, boolean, boolean)} to set core attributes + *
    • {@link #setExists(boolean)} to set existence attribute + *
    • {@link #setLastModified(long)} to set last-modified date + *
    • {@link #setLength(long)} to set length in bytes + *
    + */ +public abstract class RemoteFile implements IRemoteFile, IAdaptable, Comparable, Cloneable +{ + + + protected IRemoteFileContext _context; + protected String fullyQualifiedName; + + protected String _label; + protected Object remoteObj; + protected IRemoteFile _parentFile; + + /* Archived file properties */ + // DKM - let's get rid of these fields + // - they should now be in IHostfile + protected boolean isContainer = false; + + // master hash map + protected HashMap _contents = new HashMap(); + + /* container properties */ + protected boolean _isStale = false; + + // properties + protected HashMap properties = new HashMap(); + protected HashMap propertyStates = new HashMap(); + + /** + * Constructor that takes a context object containing important information. + * @param context An object holding contextual information about this object + * @see org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileContext + */ + public RemoteFile(IRemoteFileContext context) + { + this._context = context; + if ((context!=null) && (context.getParentRemoteFileSubSystem()!=null) && + !context.getParentRemoteFileSubSystem().isConnected()) + try + { + // deduce active shell from display + Shell shell = Display.getCurrent().getActiveShell(); + context.getParentRemoteFileSubSystem().connect(shell); + } catch (Exception exc) {} + } + + + /** + * Set the filter string resolved to get this object + */ + public void setFilterString(RemoteFileFilterString filterString) + { + _context.setFilterString(filterString); + } + + + public void setLabel(String newLabel) + { + _label = newLabel; + } + + + // ------------------------------------------------------------------------ + // GETTER METHODS. ALL FULLY IMPLEMENTED ASSUMING SETTERS HAVE BEEN CALLED. + // ------------------------------------------------------------------------ + + /** + * Return the context associated with this remote file + */ + public IRemoteFileContext getContext() + { + return _context; + } + + /** + * Return the parent subsystem + */ + public IRemoteFileSubSystem getParentRemoteFileSubSystem() + { + return _context.getParentRemoteFileSubSystem(); + } + /** + * Return the parent subsystem factory + */ + public IRemoteFileSubSystemConfiguration getParentRemoteFileSubSystemFactory() + { + IRemoteFileSubSystem ss = _context.getParentRemoteFileSubSystem(); + if (ss == null) + return null; + else + return ss.getParentRemoteFileSubSystemFactory(); + } + + public void setParentRemoteFile(IRemoteFile parentFile) + { + this._parentFile = parentFile; + } + + /** + * Return the parent remote file object expanded to get this object, or null if no such parent + */ + public IRemoteFile getParentRemoteFile() + { + if (this._parentFile == null) + { + IRemoteFile parentFile = null; + +// _context.getParentRemoteFile(); + + String pathOnly = getParentPath(); + if ((parentFile == null) && (pathOnly != null)) + { + IRemoteFileSubSystem ss = _context.getParentRemoteFileSubSystem(); + if (ss != null) + { + try { + char sep = getSeparatorChar(); + if (pathOnly.length() == 0) + parentFile = ss.getRemoteFileObject(pathOnly); + else if (pathOnly.length() == 1) + parentFile = null; + else if (!(pathOnly.charAt(pathOnly.length()-1)==sep)) + parentFile = ss.getRemoteFileObject(pathOnly+sep); + else + parentFile = ss.getRemoteFileObject(pathOnly); + } catch (SystemMessageException e) { + SystemBasePlugin.logError("RemoteFileImpl.getParentRemoteFile()", e); + } + } + } + else if (parentFile != null) + { + } + else + { + } + this._parentFile = parentFile; + } + return this._parentFile; + } + /** + * Return the filter string resolved to get this object + */ + public RemoteFileFilterString getFilterString() + { + return _context.getFilterString(); + } + /** + * If this is a folder, it is possible that it is listed as part of a multiple filter string + * filter. In this case, when the folder is expanded, we want to filter the file names to + * show all the files that match any of the filter strings that have the same parent path. + *

    + * This method supports that by returning all the filter strings in the filter which have the + * same parent path as was used to produce this file. + */ + public RemoteFileFilterString[] getAllFilterStrings() + { + return _context.getAllFilterStrings(); + } + /** + * Return the separator character for this file system: \ or /. + * Queries it from the subsystem factory. + */ + public char getSeparatorChar() + { + IRemoteFileSubSystemConfiguration ssf = getParentRemoteFileSubSystemFactory(); + if (ssf != null) + return ssf.getSeparatorChar(); + else + return java.io.File.separatorChar; + } + /** + * Return the separator character for this file system, as a string: "\" or "/". + * Queries it from the subsystem factory. + */ + public String getSeparator() + { + IRemoteFileSubSystemConfiguration ssf = getParentRemoteFileSubSystemFactory(); + if (ssf != null) + return ssf.getSeparator(); + else + return java.io.File.separator; + } + /** + * Return as a string the line separator character values + */ + public String getLineSeparator() + { + IRemoteFileSubSystemConfiguration ssf = getParentRemoteFileSubSystemFactory(); + if (ssf != null) + return ssf.getLineSeparator(); + else + return System.getProperty("line.separator"); + } + /** + * Return if this is a file on Unix, versus windows say + * Queries it from the subsystem factory. + */ + public boolean isUnix() + { + IRemoteFileSubSystemConfiguration ssf = getParentRemoteFileSubSystemFactory(); + if (ssf != null) + return ssf.isUnixStyle(); + else + return System.getProperty("os.name").toLowerCase().startsWith("windows"); + } + + public boolean isLink() + { + String classifyString = getClassification(); + + if (classifyString == null) + { + return false; + } + else if (classifyString.indexOf("symbolic link") > -1) + { + return true; + } + return false; + } + + + public boolean isExecutable() + { + String classifyString = getClassification(); + + if (classifyString == null) + { + return false; + } + else if (classifyString.indexOf("executable") > -1) + { + return true; + } + return false; + } + + + public boolean isArchive() + { + File file = new File(getAbsolutePath()); + return ArchiveHandlerManager.getInstance().isArchive(file); + } + + /** + * Return the connection this remote file is from. + */ + public IHost getSystemConnection() + { + IRemoteFileSubSystem ss = _context.getParentRemoteFileSubSystem(); + if (ss == null) + return null; + else + return ss.getHost(); + } + + /** + * @see IRemoteFile#getAbsolutePath() + */ + public String getAbsolutePath() + { + return fullyQualifiedName; + } + /** + * Get fully qualified connection and file name: connection:\path\file + * Note the separator character between the profile name and the connection name is always '.' + * Note the separator character between the connection and qualified-file is always ':' + */ + public String getAbsolutePathPlusConnection() + { + IHost conn = getSystemConnection(); + if (conn == null) + return getAbsolutePath(); + else + return conn.getSystemProfileName()+'.'+conn.getAliasName() + CONNECTION_DELIMITER + getAbsolutePath(); + } + + /** + * @see IRemoteFile#getLabel() + */ + public String getLabel() + { + if (_label != null) + { + return _label; + } + return getName(); + } + + + /** + * @see IRemoteFile#isBinary() + */ + public boolean isBinary() + { + if (isDirectory()) + return false; + else + return SystemFileTransferModeRegistry.getDefault().isBinary(this); + } + + /** + * @see IRemoteFile#isText() + */ + public boolean isText() + { + if (isDirectory()) + return false; + else + return SystemFileTransferModeRegistry.getDefault().isText(this); + } + + + + + /** + * @see IRemoteFile#getLastModifiedDate() + */ + public Date getLastModifiedDate() + { + return new Date(getLastModified()); + } + + + /** + * Return the extension part of a file name. + * Eg, for abc.java, return "java" + */ + public String getExtension() + { + String nameOnly = getName(); + if (nameOnly == null) + return null; + int idx = nameOnly.lastIndexOf('.'); + if (idx >= 0) + return nameOnly.substring(idx+1); + return null; // TODO - why null? + } + + + /** + * Return the cached copy of this remote file. The returned IFile must be used for read-only + * purposes since no locks are acquired on the remote file. + * + * @return IFile The cached copy of this file if it exists AND it is upto date. null is returned if a local + * cached copy of this file is not available or the local cached copy is not upto date (last modified + * timestamp comparison.) + */ +// FIXME - core and ui separate now (editor is ui) +// public IFile getCachedCopy() throws SystemMessageException +// { +// if (SystemRemoteEditManager.getDefault().doesRemoteEditProjectExist()) +// { +// IResource replica = UniversalFileTransferUtility.getTempFileFor(this); +// if (replica != null && replica.exists()) +// { +// return (IFile)replica; +// } +// } +// return null; +// } + + // ----------------------- + // HOUSEKEEPING METHODS... + // ----------------------- + public String toString() + { + return getName(); + } + + /** + * This is the method required by the IAdaptable interface. + * Given an adapter class type, return an object castable to the type, or + * null if this is not possible. + *

    + * By default this returns Platform.getAdapterManager().getAdapter(this, adapterType); + * This in turn results in the default subsystem adapter SystemViewSubSystemAdapter, + * in package com.ibm.etools.systems.core.ui.view. + */ + public Object getAdapter(Class adapterType) + { + return Platform.getAdapterManager().getAdapter(this, adapterType); + } + + // ------------------------------- + // java.util.Comparable methods... + // ------------------------------- + /** + * Compare one remote file to another. This enables us to sort the files so they + * are shown folders-first, and in alphabetical order. + */ + public int compareTo(Object other) throws ClassCastException + { + IRemoteFile otherFile = (IRemoteFile)other; + if (isDirectory() && !otherFile.isDirectory()) + return -1; // we are a folder so we are less than a file + else if (!isDirectory() && otherFile.isDirectory()) + return 1; // we are a file so we are more than a folder + String comp1 = getName(); + + String comp2 = otherFile.getName(); + if (comp2 == null) + comp2 = otherFile.getParentPath(); + return comp1.toLowerCase().compareTo(comp2.toLowerCase()); + } + + // ================================== + // for a proxy mimicing java.io.File + // ================================== + + public void setFile (Object obj) + { + remoteObj = obj; + } + + public Object getFile() + { + return remoteObj; + } + + public boolean isAncestorOf(IRemoteFile file) + { + String separator = this.getSeparator(); + if (this instanceof IVirtualRemoteFile) separator = "/"; + if (this.isArchive()) separator = ArchiveHandlerManager.VIRTUAL_SEPARATOR; + + return file.getAbsolutePathPlusConnection().startsWith(this.getAbsolutePathPlusConnection() + separator); + } + + public boolean isDescendantOf(IRemoteFile file) + { + String separator = file.getSeparator(); + if (this instanceof IVirtualRemoteFile) separator = "/"; + if (file.isArchive()) separator = ArchiveHandlerManager.VIRTUAL_SEPARATOR; + + return this.getAbsolutePathPlusConnection().startsWith(file.getAbsolutePathPlusConnection() + separator); + } + + /** + * @see org.eclipse.rse.core.subsystems.IRemoteContainer#hasContents(java.lang.String) + */ + public boolean hasContents(ISystemContentsType contentsType) + { + boolean result = _contents.containsKey(contentsType); + +// KM: comment out this code to prevent us picking up wrong cache +// KM: defect 45072 +// if (!result) +// { +// if (contentsType == RemoteFileChildrenContentsType.getInstance()) +// { +// return hasContents(RemoteChildrenContentsType.getInstance()); +// } +// else if (contentsType == RemoteFolderChildrenContentsType.getInstance()) +// { +// return hasContents(RemoteChildrenContentsType.getInstance()); +// } +// } + + return result; + } + + /** + * @see org.eclipse.rse.core.subsystems.IRemoteContainer#hasContents(java.lang.String, java.lang.String) + */ + public boolean hasContents(ISystemContentsType contentsType, String filter) { + HashMap filters = (HashMap)(_contents.get(contentsType)); + + if (filters == null) { + return false; + } + + if (filter == null) { + filter = "*"; + } + + boolean result = containsFilterKey(filters, filter); + +// KM: comment out this code to prevent us picking up wrong cache +// KM: defect 45072 +// if (!result) +// { +// if (contentsType == RemoteFileChildrenContentsType.getInstance()) +// { +// return hasContents(RemoteChildrenContentsType.getInstance(), filter); +// } +// else if (contentsType == RemoteFolderChildrenContentsType.getInstance()) +// { +// return hasContents(RemoteChildrenContentsType.getInstance(), filter); +// } +// } + + return result; + } + + protected boolean containsFilterKey(HashMap filters, String filter) + { + if (filters.containsKey(filter)) + { + return true; + } + else + { + + Set keySet = filters.keySet(); + Object[] keyArray = keySet.toArray(); + for (int i = 0; i < keyArray.length; i++) + { + String key = (String)keyArray[i]; + StringComparePatternMatcher matcher = new StringComparePatternMatcher(key); + if (matcher.stringMatches(filter)) + { + return true; + } + /* + StringComparePatternMatcher matcher = new StringComparePatternMatcher(filter); + if (matcher.stringMatches(key)) + { + return true; + } + */ + } + } + return false; + } + + /** + * @see org.eclipse.rse.core.subsystems.IRemoteContainer#getContents(java.lang.String) + */ + public Object[] getContents(ISystemContentsType contentsType) + { + return getContents(contentsType, "*"); + } + + private Object[] combineAndFilterHidden(Object[] set1, Object[] set2) + { + boolean showHidden = SystemPlugin.getDefault().getPreferenceStore().getBoolean(ISystemPreferencesConstants.SHOWHIDDEN); + ArrayList result = new ArrayList(set1.length + set2.length); + for (int i = 0; i < set1.length; i++) + { + if (set1[1] instanceof IRemoteFile) + { + if (showHidden) + { + result.add(set1[i]); + } + else + { + if (!((IRemoteFile)set1[i]).isHidden()) + { + result.add(set1[i]); + } + } + } + else + { + result.add(set1[i]); + } + } + for (int j = 0; j < set2.length; j++) + { + if (set2[j] instanceof IRemoteFile) + { + if (showHidden) + { + result.add(set2[j]); + } + else + { + if (!((IRemoteFile)set2[j]).isHidden()) + { + result.add(set2[j]); + } + } + } + else + { + result.add(set2[j]); + } + } + return result.toArray(new IRemoteFile[result.size()]); + } + + private Object[] filterHidden(Object[] set, boolean checkInstanceOf) + { + boolean showHidden = SystemPlugin.getDefault().getPreferenceStore().getBoolean(ISystemPreferencesConstants.SHOWHIDDEN); + ArrayList result = new ArrayList(set.length); + for (int i = 0; i < set.length; i++) + { + if (set[i] instanceof IRemoteFile) + { + if (showHidden) + { + result.add(set[i]); + } + else + { + if (!checkInstanceOf || set[i] instanceof IRemoteFile) + { + if (!((IRemoteFile)set[i]).isHidden()) + { + result.add(set[i]); + } + } + } + } + + + } + return result.toArray(new IRemoteFile[result.size()]); + } + + private Object[] getFiles(Object[] filesAndFolders) + { + List results = new ArrayList(); + for (int i = 0; i < filesAndFolders.length; i++) + { + IRemoteFile fileOrFolder = (IRemoteFile)filesAndFolders[i]; + boolean supportsArchiveManagement = fileOrFolder.getParentRemoteFileSubSystem().getParentRemoteFileSubSystemFactory().supportsArchiveManagement(); + if (fileOrFolder.isFile() || (fileOrFolder.isArchive() && supportsArchiveManagement)) + { + results.add(fileOrFolder); + } + } + return results.toArray(); + } + + private Object[] getFolders(Object[] filesAndFolders) + { + List results = new ArrayList(); + for (int i = 0; i < filesAndFolders.length; i++) + { + IRemoteFile fileOrFolder = (IRemoteFile)filesAndFolders[i]; + boolean supportsArchiveManagement = fileOrFolder.getParentRemoteFileSubSystem().getParentRemoteFileSubSystemFactory().supportsArchiveManagement(); + if (!fileOrFolder.isFile() || (fileOrFolder.isArchive() && supportsArchiveManagement)) + { + results.add(fileOrFolder); + } + } + return results.toArray(); + } + + + /** + * @see org.eclipse.rse.core.subsystems.IRemoteContainer#getContents(java.lang.String, java.lang.String) + */ + public Object[] getContents(ISystemContentsType contentsType, String filter) + { + HashMap filters = (HashMap)(_contents.get(contentsType)); + + if (filters == null || filters.isEmpty()) + { + if (contentsType == RemoteChildrenContentsType.getInstance()) + { + if (hasContents(RemoteFileChildrenContentsType.getInstance()) && hasContents(RemoteFolderChildrenContentsType.getInstance())) + { + // implies both files and folders + Object[] folders = getContents(RemoteFolderChildrenContentsType.getInstance(), filter); + Object[] files = getContents(RemoteFileChildrenContentsType.getInstance(), filter); + + return combineAndFilterHidden(folders, files); + } + } + else if (contentsType == RemoteFileChildrenContentsType.getInstance()) + { + if (hasContents(RemoteChildrenContentsType.getInstance())) + { + Object[] filesAndFolders = getContents(RemoteChildrenContentsType.getInstance()); + return filterHidden(getFiles(filesAndFolders), false); + } + } + else if (contentsType == RemoteFolderChildrenContentsType.getInstance()) + { + if (hasContents(RemoteChildrenContentsType.getInstance())) + { + Object[] filesAndFolders = getContents(RemoteChildrenContentsType.getInstance()); + return filterHidden(getFolders(filesAndFolders), false); + } + } + return null; + } + + if (filter == null) { + filter = "*"; + } + + if (filters.containsKey(filter)) + { + Object[] filterResults = (Object[])filters.get(filter); + if (contentsType == RemoteChildrenContentsType.getInstance() || + contentsType == RemoteFileChildrenContentsType.getInstance() || + contentsType == RemoteFolderChildrenContentsType.getInstance() + ) + { + return filterHidden(filterResults, true); + } + else + { + return filterResults; + } + } + + ArrayList calculatedResults = new ArrayList(); + + + StringComparePatternMatcher fmatcher = new StringComparePatternMatcher(filter); + + // the filter may be a subset of existing filters + Object[] keySet = filters.keySet().toArray(); + + for (int i = 0; i < keySet.length; i++) { + + String key = (String)keySet[i]; + + // KM: we need to match with the key to ensure that the filter is a subset + StringComparePatternMatcher matcher = new StringComparePatternMatcher(key); + + if (matcher.stringMatches(filter)) + { + // get all children, i.e. the superset + Object[] all = (Object[])filters.get(key); + + if (all != null) { + + for (int s = 0; s < all.length; s++) { + + Object subContent = all[s]; + + if (!calculatedResults.contains(subContent)) + { + if (subContent instanceof IRemoteFile) + { + // match with the filter to take out those that do not match the filter + if (fmatcher.stringMatches(((IRemoteFile)subContent).getName())) + { + calculatedResults.add(subContent); + } + } + else + { + calculatedResults.add(subContent); + } + } + } + } + } + } + + return calculatedResults.toArray(); + } + + + + public void setIsContainer(boolean con) { + isContainer = con; + } + + /* + * Replace occurrences of cached object with new object + */ + public void replaceContent(Object oldObject, Object newObject) + { + HashMap filters = (HashMap)(_contents.get(RemoteChildrenContentsType.getInstance())); + if (filters != null) + { + Collection values = filters.values(); + Object[] valuesArray = values.toArray(); + for (int i = 0; i < valuesArray.length; i++) + { + Object[] children = (Object[])valuesArray[i]; + for (int j = 0; j < children.length; j++) + { + if (children[j]== oldObject) + { + children[j]= newObject; + } + } + } + } + } + + + + /** + * @see org.eclipse.rse.core.subsystems.IRemoteContainer#setContents(java.lang.String, java.lang.String, java.lang.Object[]) + */ + public void setContents(ISystemContentsType contentsType, String filter, Object[] con) { + + if (filter == null) { + filter = "*"; + } + + if (con != null && con.length > 0) + { + isContainer = true; + } + + HashMap filters = (HashMap)(_contents.get(contentsType)); + + if (filters == null) + { + filters = new HashMap(); + } + + if (isContainer) + { + filters.put(filter, con); + _contents.put(contentsType, filters); + } + + // set parent folders + if (isContainer && con != null) + { + for (int i = 0; i < con.length; i++) + { + if (con[i] instanceof RemoteFile) + { + RemoteFile rFile = (RemoteFile)con[i]; + rFile.setParentRemoteFile(this); + } + } + } + } + + /** + * @see org.eclipse.rse.core.subsystems.IRemoteContainer#isStale() + */ + public boolean isStale() + { + return _isStale || !exists(); + } + + + + /** + * @see org.eclipse.rse.core.subsystems.IRemoteContainer#markStale(boolean) + */ + public void markStale(boolean isStale) + { + markStale(isStale, true); + } + + /** + * @see org.eclipse.rse.core.subsystems.IRemoteContainer#markStale(boolean) + */ + public void markStale(boolean isStale, boolean clearCache) + { + _isStale = isStale; + + if (isStale && clearCache) + { + + Iterator iter = _contents.keySet().iterator(); + + while (iter.hasNext()) { + Object contentsType = iter.next(); + if (contentsType instanceof ISystemContentsType) + { + if (!((ISystemContentsType)contentsType).isPersistent()) + { + HashMap filters = (HashMap)(_contents.get(contentsType)); + + if (filters != null) + { + filters.clear(); + } + } + } + } + + IRemoteFile parent = getParentRemoteFile(); + if (parent != null) + { + parent.markStale(isStale, false); + } + } + } + + public void copyContentsTo(IRemoteContainer target) + { + Iterator iter = _contents.keySet().iterator(); + + while (iter.hasNext()) + { + Object contentsType = iter.next(); + if (contentsType instanceof ISystemContentsType) + { + ISystemContentsType ct = (ISystemContentsType)contentsType; + if (ct.isPersistent()) + { + HashMap filters = (HashMap)(_contents.get(ct)); + + Iterator fiter = filters.keySet().iterator(); + + while (fiter.hasNext()) + { + Object filter = fiter.next(); + Object fcontents = filters.get(filter); + if (fcontents != null && fcontents instanceof Object[]) + { + target.setContents(ct, (String)filter, (Object[])fcontents); + } + } + } + } + } + } + + /** + * @see org.eclipse.rse.core.subsystems.IRemotePropertyHolder#getProperties(java.lang.String[]) + */ + public Object[] getProperties(String[] keys) { + + Object[] values = new Object[keys.length]; + + for (int i = 0; i < keys.length; i++) { + values[i] = properties.get(keys[i]); + } + + return values; + } + + /** + * @see org.eclipse.rse.core.subsystems.IRemotePropertyHolder#getProperty(java.lang.String) + */ + public Object getProperty(String key) { + return properties.get(key); + } + + /** + * @see org.eclipse.rse.core.subsystems.IRemotePropertyHolder#isPropertyStale(java.lang.String) + */ + public boolean isPropertyStale(String key) { + + Boolean b = (Boolean)(propertyStates.get(key)); + + if (b == null) { + return false; + } + else { + return b.booleanValue(); + } + } + + /** + * @see org.eclipse.rse.core.subsystems.IRemotePropertyHolder#markAllPropertiesStale() + */ + public void markAllPropertiesStale() { + Iterator iter = propertyStates.keySet().iterator(); + + while (iter.hasNext()) { + String key = (String)(iter.next()); + markPropertyStale(key); + } + } + + /** + * @see org.eclipse.rse.core.subsystems.IRemotePropertyHolder#markPropertyStale(java.lang.String) + */ + public void markPropertyStale(String key) { + propertyStates.put(key, Boolean.FALSE); + } + + /** + * @see org.eclipse.rse.core.subsystems.IRemotePropertyHolder#setProperties(java.lang.String[], java.lang.Object[]) + */ + public void setProperties(String[] keys, Object[] values) { + + for (int i = 0; i < keys.length; i++) { + setProperty(keys[i], values[i]); + } + } + + /** + * @see org.eclipse.rse.core.subsystems.IRemotePropertyHolder#setProperty(java.lang.String, java.lang.Object) + */ + public void setProperty(String key, Object value) { + properties.put(key, value); + propertyStates.put(key, Boolean.TRUE); + } + + public String getComment() + { + return ""; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileCancelledException.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileCancelledException.java new file mode 100644 index 00000000000..482d94e308e --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileCancelledException.java @@ -0,0 +1,40 @@ +/******************************************************************************** + * Copyright (c) 2000, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.ui.ISystemMessages; + + +/** + * Exception thrown when attempting an operation and it fails for IO reasons, such as + * the file is read-only. + *

    + * The original remote system's io message is always embedded and retrievable + * via getRemoteException(). + */ +public class RemoteFileCancelledException extends RemoteFileIOException +{ + + /** + * Constructor + */ + public RemoteFileCancelledException() + { + super(new SystemMessageException(SystemPlugin.getPluginMessage(ISystemMessages.MSG_OPERATION_CANCELLED))); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileChildrenContentsType.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileChildrenContentsType.java new file mode 100644 index 00000000000..dd40e644744 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileChildrenContentsType.java @@ -0,0 +1,50 @@ +/******************************************************************************** + * Copyright (c) 2004, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; + +import org.eclipse.rse.model.ISystemContentsType; + +/** + * Represents contents that are children of a container + */ +public class RemoteFileChildrenContentsType implements ISystemContentsType +{ + public static String CONTENTS_TYPE_CHILDREN = "contents_file_children"; + public static RemoteFileChildrenContentsType _instance = new RemoteFileChildrenContentsType(); + + public static RemoteFileChildrenContentsType getInstance() + { + return _instance; + } + + /* (non-Javadoc) + * @see com.ibm.etools.systems.subsystems.IRemoteContentsType#getType() + */ + public String getType() + { + return CONTENTS_TYPE_CHILDREN; + } + + /* (non-Javadoc) + * @see com.ibm.etools.systems.subsystems.IRemoteContentsType#isPersistent() + */ + public boolean isPersistent() + { + return false; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileCodeException.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileCodeException.java new file mode 100644 index 00000000000..596e30f8d5e --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileCodeException.java @@ -0,0 +1,99 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; + +/** + * This exception class should be used to return exception codes to + * clients. Codes can be either integers or strings, or both may be + * used at the same time for better subclassing of similar errors that + * occur due to slightly different reasons. + */ + +public class RemoteFileCodeException extends Exception { + + + + private int code; + private String codeString; + + + /** + * Constructor for RemoteFileCodeException + */ + public RemoteFileCodeException() { + super(); + } + + + /** + * Constructor for RemoteFileCodeException + */ + public RemoteFileCodeException(int code) { + this.code = code; + } + + + /** + * Constructor for RemoteFileCodeException + */ + public RemoteFileCodeException(String codeString) { + this.codeString = codeString; + } + + + /** + * Constructor for RemoteFileCodeException + */ + public RemoteFileCodeException(int code, String codeString) { + this.code = code; + this.codeString = codeString; + } + + + /** + * Set the error code + * @param the error code + */ + public void setErrorCode(int code) { + this.code = code; + } + + + /** + * Get the error code + * @return the error code that was set + */ + public int getErrorCode() { + return code; + } + + + /** + * Set the error code string + */ + public void setErrorCodeString(String codeString) { + this.codeString = codeString; + } + + + /** + * Get the error code string + */ + public String getErrorCodeString() { + return codeString; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileContext.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileContext.java new file mode 100644 index 00000000000..b4789a9029a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileContext.java @@ -0,0 +1,149 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; +import java.util.Vector; + +import org.eclipse.rse.subsystems.files.core.model.RemoteFileFilterString; + +/** + * This interface represents a place to hold contextual information stored within + * each remote file object. + *

    + * We store in here information that might be the same for multiple remote file objects, + * in order to save memory. This way, we can merely hold a reference to a single object, + * which itself may have numerous pieces of information helpful when processing actions + * on a particular remote object. + */ +public class RemoteFileContext implements IRemoteFileContext +{ + + protected IRemoteFileSubSystem subsystem; + protected IRemoteFile parentFile; + protected RemoteFileFilterString filterString; + protected Vector allFilterStrings; + + /** + * Constructor that takes all inputs. + */ + public RemoteFileContext(IRemoteFileSubSystem subsystem, IRemoteFile parentFileObject, + RemoteFileFilterString filterString) + { + this.subsystem = subsystem; + this.parentFile = parentFileObject; + this.filterString = filterString; + } + /** + * Constructor that takes no inputs. + */ + public RemoteFileContext() + { + } + + // ------------------------------------------------------------------------ + // SETTER METHODS... + // ------------------------------------------------------------------------ + /** + * Set the parent subsystem + */ + public void setParentRemoteFileSubSystem(IRemoteFileSubSystem subsystem) + { + this.subsystem = subsystem; + } + /** + * Set the parent remote file object expanded to get this object + */ + public void setParentRemoteFile(IRemoteFile parentFileObject) + { + this.parentFile = parentFileObject; + } + /** + * Set the filter string object resolved to get this object + */ + public void setFilterString(RemoteFileFilterString filterString) + { + this.filterString = filterString; + allFilterStrings = null; + } + /** + * Add an additional filter string. This is called for folders in a multi-filter string + * filter. It is called for each filter string that lists the contents of the same parent + * path, when show subdirs is true. It is needed to support the subsequent expansion of + * this subdirectory, so that it can filter on all the appropriate filter strings. + */ + public void addFilterString(RemoteFileFilterString additionalFilterString) + { + if (allFilterStrings == null) + { + allFilterStrings = new Vector(); + if (filterString != null) + allFilterStrings.addElement(filterString); + } + // ensure this filter string is not already in the list... + boolean match = false; + String newfs = additionalFilterString.toString(); + for (int idx=0; !match && (idx + * All remote file exceptions are guaranteed to have a translated message retrievable + * via getMessage(), to make it easy to display to the user. + *

    + * All child exceptions potentially contain an imbedded exception that + * is the original exception from the remote system. + *

    + * Use {#link getRemoteException()} to retrieve that wrapped exception, if any. + */ +public class RemoteFileException extends SystemMessageException +{ + private Exception wrappedException = null; + + /** + * Constructor for RemoteFileException with an error message for getMessage() to return. + * @param bundle The ResourceBundle containing the error message + * @param key The key to retrieve the message + */ + public RemoteFileException(ResourceBundle bundle, String key) + { + this(getString(bundle,key), null); + } + /** + * Constructor for RemoteFileException with an error message for getMessage() to return. + * @param msg The fully resolved message + */ + public RemoteFileException(String msg) + { + this(msg, null); + } + /** + * Constructor for RemoteFileException with an error message for getMessage() to return, + * and a wrapped exception to contain. It is accessed via getRemoteException(). + * @param bundle The ResourceBundle containing the error message + * @param key The key to retrieve the message + * @param remoteException The exception to contain within this exception + */ + public RemoteFileException(ResourceBundle bundle, String key, Exception remoteException) + { + this(getString(bundle,key), remoteException); + } + /** + * Constructor for RemoteFileException with an error message for getMessage() to return. + * and a wrapped exception to contain. It is accessed via getRemoteException(). + * @param msg The fully resolved message + * @param remoteException The exception to contain within this exception + */ + public RemoteFileException(String msg, Exception remoteException) + { + super(msg); + wrappedException = remoteException; + } + + /** + * Constructor for RemoteFileException with an error message for getMessage() to return. + * @param msg The fully resolved message + */ + public RemoteFileException(SystemMessage msg) + { + this(msg, null); + } + /** + * Constructor for RemoteFileException with an error message for getMessage() to return. + * and a wrapped exception to contain. It is accessed via getRemoteException(). + * @param msg The fully resolved message + * @param remoteException The exception to contain within this exception + */ + public RemoteFileException(SystemMessage msg, Exception remoteException) + { + super(msg); + wrappedException = remoteException; + } + /** + * Return the wrapped exception + */ + public Exception getRemoteException() + { + return wrappedException; + } + + + private static String getString(ResourceBundle bundle, String key) + { + String msg = null; + try { msg = bundle.getString(key); } catch (Exception exc) {} + if (msg == null) + msg = "Message with key " + key + " not found"; + return msg; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileIOException.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileIOException.java new file mode 100644 index 00000000000..bb3170858b2 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileIOException.java @@ -0,0 +1,42 @@ +/******************************************************************************** + * Copyright (c) 2000, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.ui.ISystemMessages; + + +/** + * Exception thrown when attempting an operation and it fails for IO reasons, such as + * the file is read-only. + *

    + * The original remote system's io message is always embedded and retrievable + * via getRemoteException(). + */ +public class RemoteFileIOException extends RemoteFileException +{ + /** + * Constructor + */ + public RemoteFileIOException(Exception remoteException) + { + super(SystemPlugin.getPluginMessage(ISystemMessages.FILEMSG_IO_ERROR), remoteException); + String secondLevel = remoteException.getMessage(); + if (secondLevel == null) + secondLevel = remoteException.getClass().getName(); + getSystemMessage().makeSubstitution(secondLevel); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileRoot.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileRoot.java new file mode 100644 index 00000000000..009b8633e0b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileRoot.java @@ -0,0 +1,178 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; + +import org.eclipse.rse.services.files.IHostFile; + +/** + * A root node used to drive a CheckboxTreeAndListGroup, or any viewer which + * takes a root which should return a single IRemoteFile object in the initial + * getChildren query. + */ +public class RemoteFileRoot extends RemoteFile +{ + private IRemoteFile rootFile; + private IRemoteFile[] rootFiles; + + /** + * Constructor when root is known + */ + public RemoteFileRoot(IRemoteFile rootFile) + { + super(new RemoteFileContext(null,null,null)); + } + /** + * Constructor when root is not known + */ + public RemoteFileRoot() + { + super(new RemoteFileContext(null,null,null)); + } + + /** + * Return the root file node + */ + public IRemoteFile getRootFile() + { + return rootFile; + } + + /** + * Reset the root file node + */ + public void setRootFile(IRemoteFile rootFile) + { + this.rootFile = rootFile; + rootFiles = new IRemoteFile[1]; + rootFiles[0] = rootFile; + } + + /** + * Return the root file node as an array of 1 + */ + public IRemoteFile[] getRootFiles() + { + return rootFiles; + } + + public String getName() + { + return "dummy"; + } + + public int compareTo(Object o) + { + // TODO Auto-generated method stub + return 0; + } + public boolean isVirtual() + { + // TODO Auto-generated method stub + return false; + } + public boolean showBriefPropertySet() + { + // TODO Auto-generated method stub + return false; + } + public String getParentPath() + { + // TODO Auto-generated method stub + return null; + } + public String getParentNoRoot() + { + // TODO Auto-generated method stub + return null; + } + public String getRoot() + { + // TODO Auto-generated method stub + return null; + } + public String getParentName() + { + // TODO Auto-generated method stub + return null; + } + public boolean isRoot() + { + // TODO Auto-generated method stub + return false; + } + public boolean isDirectory() + { + // TODO Auto-generated method stub + return false; + } + public boolean isFile() + { + // TODO Auto-generated method stub + return false; + } + public boolean isHidden() + { + // TODO Auto-generated method stub + return false; + } + public boolean canRead() + { + // TODO Auto-generated method stub + return false; + } + public boolean canWrite() + { + // TODO Auto-generated method stub + return false; + } + public boolean exists() + { + // TODO Auto-generated method stub + return false; + } + public long getLastModified() + { + // TODO Auto-generated method stub + return 0; + } + public long getLength() + { + // TODO Auto-generated method stub + return 0; + } + public boolean showReadOnlyProperty() + { + // TODO Auto-generated method stub + return false; + } + public String getClassification() + { + // TODO Auto-generated method stub + return null; + } + public String getCanonicalPath() + { + // TODO Auto-generated method stub + return null; + } + public IHostFile getHostFile() + { + // TODO Auto-generated method stub + return null; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSchedulingRule.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSchedulingRule.java new file mode 100644 index 00000000000..696d3488bd9 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSchedulingRule.java @@ -0,0 +1,75 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; + +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.core.runtime.jobs.MultiRule; + + +public class RemoteFileSchedulingRule implements ISchedulingRule +{ + private IRemoteFile _file; + + public RemoteFileSchedulingRule(IRemoteFile file) + { + _file = file; + } + + /* + * (non-Javadoc) + * @see ISchedulingRule#contains(ISchedulingRule) + */ + public boolean contains(ISchedulingRule rule) { + if (this == rule) + return true; + if (rule instanceof MultiRule) { + MultiRule multi = (MultiRule) rule; + ISchedulingRule[] children = multi.getChildren(); + for (int i = 0; i < children.length; i++) + if (!contains(children[i])) + return false; + return true; + } + if (!(rule instanceof RemoteFileSchedulingRule)) + return false; + return getHostName().equals(((RemoteFileSchedulingRule) rule).getHostName()) && + ((RemoteFileSchedulingRule) rule).getAbsolutePath().startsWith(getAbsolutePath()); + } + + /* (non-Javadoc) + * @see ISchedulingRule#isConflicting(ISchedulingRule) + */ + public boolean isConflicting(ISchedulingRule rule) + { + if (!(rule instanceof RemoteFileSchedulingRule)) + return false; + String otherPath = ((RemoteFileSchedulingRule) rule).getAbsolutePath(); + String path = this.getAbsolutePath(); + String otherHost = ((RemoteFileSchedulingRule) rule).getHostName(); + return getHostName().equals(otherHost) && path.startsWith(otherPath) || otherPath.startsWith(path); + } + + public String getAbsolutePath() + { + return _file.getAbsolutePath(); + } + + public String getHostName() + { + return _file.getSystemConnection().getHostName(); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSecurityException.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSecurityException.java new file mode 100644 index 00000000000..b820d3ff14b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSecurityException.java @@ -0,0 +1,40 @@ +/******************************************************************************** + * Copyright (c) 2000, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.ui.ISystemMessages; + + +/** + * Exception thrown when attempting an operation and it fails for security reasons. + * The original remote system's security message is always embedded and retrievable + * via getRemoteException(). + */ +public class RemoteFileSecurityException extends RemoteFileException +{ + /** + * Constructor + */ + public RemoteFileSecurityException(Exception remoteException) + { + super(SystemPlugin.getPluginMessage(ISystemMessages.FILEMSG_SECURITY_ERROR), remoteException); + String secondLevel = remoteException.getMessage(); + if (secondLevel == null) + secondLevel = remoteException.getClass().getName(); + getSystemMessage().makeSubstitution(secondLevel); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSubSystem.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSubSystem.java new file mode 100644 index 00000000000..04266dff2ba --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSubSystem.java @@ -0,0 +1,1699 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; +// copy all the following imports to your child class... +// remote system framework packages... +//import com.ibm.etools.systems.subsystems.impl.*; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Vector; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.subsystems.CommunicationsEvent; +import org.eclipse.rse.core.subsystems.ICommunicationsListener; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.core.subsystems.IRemoteContainer; +import org.eclipse.rse.core.subsystems.ISubSystemConfiguration; +import org.eclipse.rse.core.subsystems.RemoteChildrenContentsType; +import org.eclipse.rse.core.subsystems.SubSystem; +import org.eclipse.rse.filters.ISystemFilterReference; +import org.eclipse.rse.filters.ISystemFilterString; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.model.ISystemMessageObject; +import org.eclipse.rse.model.SystemChildrenContentsType; +import org.eclipse.rse.model.SystemMessageObject; +import org.eclipse.rse.model.SystemRemoteResourceSet; +import org.eclipse.rse.services.clientserver.FileTypeMatcher; +import org.eclipse.rse.services.clientserver.IClientServerConstants; +import org.eclipse.rse.services.clientserver.IMatcher; +import org.eclipse.rse.services.clientserver.NamePatternMatcher; +import org.eclipse.rse.services.clientserver.SystemEncodingUtil; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.search.IHostSearchResult; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.services.search.IHostSearchResultConfigurationFactory; +import org.eclipse.rse.subsystems.files.core.model.RemoteFileFilterString; +import org.eclipse.rse.ui.ISystemMessages; +import org.eclipse.rse.ui.propertypages.SystemSubSystemPropertyPageCore; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.dialogs.PropertyPage; + + +/** + * Specialization for file subsystem factories. + * It is subclassed via use of a Rose model and MOF/EMF, or better yet + * by subclassing {@link org.eclipse.rse.core.servicesubsystem.impl.FileServiceSubSystem}. + *

    + * For your convenience, there is built-in name filtering support. To use it, + * call: + *

      + *
    • {@link #setListValues(int, String)} or {@link #setListValues(int, String, String)} to set the filter criteria + *
    • {@link #accept(String, boolean)} to test a given name for a match + *
    + * + *

    This class returns instances of {@link RemoteFile} objects. + */ + +public abstract class RemoteFileSubSystem extends SubSystem implements IRemoteFileSubSystem, ICommunicationsListener +{ + /** + * The default value of the '{@link #getHomeFolder() Home Folder}' attribute. + * + * + * @see #getHomeFolder() + * @generated + * @ordered + */ + protected static final String HOME_FOLDER_EDEFAULT = null; + + public boolean osVarsSet, osWindows, osWindows95, osWindowsNT; + public String osName, osCmdShell; + // variables to affect the list method for subsetting folder contents + private int includeFilesOrFolders = IClientServerConstants.INCLUDE_ALL; + //private NamePatternMatcher matcher = null; + protected IMatcher matcher = null; + protected NamePatternMatcher folderNameMatcher = null; + protected RemoteFileFilterString currFilterString = null; + protected RemoteFileFilterString FILTERSTRING_LISTROOTS = null; + protected RemoteFileContext DEFAULT_CONTEXT = null; + protected RemoteFileContext DEFAULT_CONTEXT_NOFILTERSTRING = null; + + protected ArrayList _searchHistory; + + // all created IRemoteFiles mapped in cache to quick retreival + protected HashMap _cachedRemoteFiles = new HashMap(); + + protected IProgressMonitor monitor; + + /** + * @generated This field/method will be replaced during code generation. + */ + /** + * @generated This field/method will be replaced during code generation. + */ + protected String homeFolder = HOME_FOLDER_EDEFAULT; + /** + * Default constructor. Do not call directly! Rather, use the mof generated factory method to create. + * After instantiation, be sure to call {@link #setSubSystemConfiguration(ISubSystemConfiguration)}. + */ + public RemoteFileSubSystem(IHost host, IConnectorService connectorService) + { + super(host, connectorService); + _searchHistory = new ArrayList(); + } + /** + * @return true if this subsystem's properties should take precedence over other subsystems that share the same ISystem + */ + public boolean isPrimarySubSystem() + { + return true; + } + + /** + * Return parent subsystem factory, cast to a RemoteFileSubSystemFactory + * Assumes {@link #setSubSystemConfiguration(ISubSystemConfiguration)} has already been called. + */ + public IRemoteFileSubSystemConfiguration getParentRemoteFileSubSystemFactory() + { + return (IRemoteFileSubSystemConfiguration) super.getSubSystemConfiguration(); + } + + /** + * Return true if file names are case-sensitive. Used when doing name or type filtering + * Default is false, but can be overridden. + */ + public boolean isCaseSensitive() + { + return false; + } + + /** + * Long running list processing calls this method to check for a user-cancel event. + * If user did cancel, an exception is thrown. + * @return true if caller wants to cancel + */ + public boolean checkForCancel() + { + if ((monitor != null) && monitor.isCanceled()) + throw new OperationCanceledException(SystemPlugin.getPluginMessage(ISystemMessages.MSG_OPERATION_CANCELLED).getLevelOneText()); + return false; + } + + protected RemoteFileFilterString getCurrentFilterString() + { + RemoteFileFilterString crffs = currFilterString; + currFilterString = null; + return crffs; + } + + protected RemoteFileFilterString getFilterStringListRoots() + { + if (FILTERSTRING_LISTROOTS == null) + FILTERSTRING_LISTROOTS = new RemoteFileFilterString(getParentRemoteFileSubSystemFactory()); + return FILTERSTRING_LISTROOTS; + } + protected RemoteFileContext getDefaultContext() + { + if (DEFAULT_CONTEXT == null) + DEFAULT_CONTEXT = new RemoteFileContext(this, null, getFilterStringListRoots()); + return DEFAULT_CONTEXT; + } + protected RemoteFileContext getDefaultContextNoFilterString() + { + if (DEFAULT_CONTEXT_NOFILTERSTRING == null) + DEFAULT_CONTEXT_NOFILTERSTRING = new RemoteFileContext(this, null, null); + return DEFAULT_CONTEXT_NOFILTERSTRING; + } + protected RemoteFileContext getContext(IRemoteFile parent) + { + return new RemoteFileContext(this, parent, null); + } + protected RemoteFileContext getContext(IRemoteFile parent, RemoteFileFilterString rffs) + { + return new RemoteFileContext(this, parent, rffs); + } + + // -------------------------------- + // FILE SYSTEM ATTRIBUTE METHODS... + // -------------------------------- + /** + * Return in string format the character used to separate folders. Eg, "\" or "/". + *
    + * Shortcut to {@link #getParentRemoteFileSubSystemFactory()}.getSeparator() + */ + public String getSeparator() + { + return getParentRemoteFileSubSystemFactory().getSeparator(); + } + /** + * Return in character format the character used to separate folders. Eg, "\" or "/" + *
    + * Shortcut to {@link #getParentRemoteFileSubSystemFactory()}.getSeparatorChar() + */ + public char getSeparatorChar() + { + return getParentRemoteFileSubSystemFactory().getSeparatorChar(); + } + /** + * Return in string format the character used to separate paths. Eg, ";" or ":" + *
    + * Shortcut to {@link #getParentRemoteFileSubSystemFactory()}.getPathSeparator() + */ + public String getPathSeparator() + { + return getParentRemoteFileSubSystemFactory().getPathSeparator(); + } + /** + * Return in char format the character used to separate paths. Eg, ";" or ":" + *
    + * Shortcut to {@link #getParentRemoteFileSubSystemFactory()}.getPathSeparatorChar() + */ + public char getPathSeparatorChar() + { + return getParentRemoteFileSubSystemFactory().getPathSeparatorChar(); + } + /** + * Return as a string the line separator. + *
    + * Shortcut to {@link #getParentRemoteFileSubSystemFactory()}.getLineSeparator() + */ + public String getLineSeparator() + { + return getParentRemoteFileSubSystemFactory().getLineSeparator(); + } + + + // ------------------------------------- + // GUI methods + // ------------------------------------- + /** + * Return the single property page to show in the tabbed notebook for the + * for SubSystem property of the parent Connection. Return null if no + * page is to be contributed for this. You are limited to a single page, + * so you may have to compress. It is recommended you prompt for the port + * if applicable since the common base subsystem property page is not shown + * To help with this you can use the SubSystemPortPrompt widget. + */ + public PropertyPage getPropertyPage(Composite parent) + { + return new SystemSubSystemPropertyPageCore(); + } + + // ------------------------- + // Filter Testing Methods... + // ------------------------- + + /** + * Return true if the given remote object name will pass the filtering criteria for + * the given filter string. + *

    + * Subclasses need to override this. + * If in doubt, return true. + *

    + * There is a hack here if you want to tell us the absolute name is that of a folder: append " -folder" to the name! + */ + public boolean doesFilterStringMatch(String filterString, String remoteObjectAbsoluteName, boolean caseSensitive) + { + RemoteFileFilterString rffs = new RemoteFileFilterString(getParentRemoteFileSubSystemFactory(), filterString); + // ok, this is a tweak: if the absolute name has " -folder" at the end, that means it is a folder... + if (remoteObjectAbsoluteName.endsWith(" -folder")) + { + if (!rffs.getShowSubDirs()) + return false; + remoteObjectAbsoluteName = remoteObjectAbsoluteName.substring(0, remoteObjectAbsoluteName.indexOf(" -folder")); + } + // problem 1: we don't know if the given remote object name represents a file or folder. We have to assume a file, + // since we don't support filtering by folder names. + if (!rffs.getShowFiles()) + return false; + + // step 1: verify the path of the remote object matches the path of the filter string + String container = rffs.getPath(); + if (container == null) + return false; + + if (container.equals(".")) + { + try + { + container = getRemoteFileObject(container).getAbsolutePath(); + } + catch (Exception e) + { + + } + //return true; + } + + // trick: use filter string code to parse remote absolute name + RemoteFileFilterString rmtName = new RemoteFileFilterString(getParentRemoteFileSubSystemFactory(), remoteObjectAbsoluteName); + boolean pathMatch = false; + if (caseSensitive) + pathMatch = container.equals(rmtName.getPath()); + else + pathMatch = container.equalsIgnoreCase(rmtName.getPath()); + if (!pathMatch) + return false; + + // step 2: test if the given file name matches the filter criteria + String nameFilter = rffs.getFileOrTypes(); + if (nameFilter == null) + return false; + if (!nameFilter.equals("*")) + { + IMatcher matcher = null; + if (nameFilter.endsWith(",")) + matcher = new FileTypeMatcher(FileTypeMatcher.parseTypes(nameFilter), true); + else + matcher = new NamePatternMatcher(nameFilter, true, caseSensitive); + return matcher.matches(rmtName.getFile()); + } + else + return true; + } + /** + * Return true if the given filter string lists the contents of the given remote object. + * For example, if given a folder, return true if the given filter string + * lists the contents of that folder. Used in impact analysis when a remote object is + * created, deleted, renamed, copied or moved, so as to establish which filters need to be + * refreshed or collapsed (if the folder is deleted, say). + *

    + * This should only return true if the filter string directly lists the contents of the given + * object, versus indirectly. + *

    + * Subclasses should override this. + */ + public boolean doesFilterStringListContentsOf(ISystemFilterString filterString, String remoteObjectAbsoluteName) + { + RemoteFileFilterString rffs = new RemoteFileFilterString(getParentRemoteFileSubSystemFactory(), filterString.getString()); + String container = rffs.getPath(); + if (container == null) + return false; + boolean affected = false; + if (filterString.getParentSystemFilter().isStringsCaseSensitive()) + affected = container.equals(remoteObjectAbsoluteName); + else + affected = container.equalsIgnoreCase(remoteObjectAbsoluteName); + + //UniversalSystemPlugin.logDebugMessage( + // "UniversalFileSubSystemImpl::doesFilterStringListContentsOf", + // "Univ Filter String Testing '" + container + "' versus '" + remoteObjectAbsoluteName + "' => " + affected); + return affected; + } + + // ------------------------------- + // SubSystem METHODS ... + // ------------------------------- + + /** + * Resolves filter strings. + * The default implementation of this simply calls {@link #internalResolveFilterString(IProgressMontior, String)}. + * If the result for each filter string is a SystemMessage (e.g. an error), then the messages are returned. + * If the result for any filter string is not a message (i.e. an array of children), then the children are returned, + * and the messages are not. This avoids mixing chuldren as a result of successful resolution of a filter string with + * messages that might result for other filter strings. + * So the returned results are always the successful results, or messages (never a mix of the two). + * @see org.eclipse.rse.core.subsystems.SubSystem#internalResolveFilterStrings(org.eclipse.core.runtime.IProgressMonitor, java.lang.String[]) + * @param monitor the progress monitor we are running under + * @param filterStrings array of filter patterns for objects to return. + * @return Array of objects that are the result of resolving all the filter strings + */ + public Object[] internalResolveFilterStrings(IProgressMonitor monitor, String[] filterStrings) + throws java.lang.reflect.InvocationTargetException, + java.lang.InterruptedException + { + Object[] children = null; + Vector vChildren = new Vector(); + Vector vMessages = new Vector(); + + boolean oneSuccess = false; + boolean success = false; + if (filterStrings == null) + { + System.out.println("filterStrings==null!"); + System.out.println("connection == "+getHostAliasName()); + return null; + } + + for (int idx=0; idx + * Can be used to filter out redundant entries in the concatenated list, if this + * is desired. + */ + protected void addResolvedFilterStringObjects(Vector allChildrenSoFar, Object[] childrenForThisFilterString, String[] allFilterStrings, int currFilterStringIndex) + { + if (currFilterStringIndex == 0) + super.addResolvedFilterStringObjects(allChildrenSoFar, childrenForThisFilterString, allFilterStrings, currFilterStringIndex); + else + { + // for defect 42095, we filter out redundancies... + RemoteFileFilterString currFS = new RemoteFileFilterString(getParentRemoteFileSubSystemFactory(), allFilterStrings[currFilterStringIndex]); + String currPath = currFS.getPath(); + if (currPath == null) + currPath = ""; + boolean matchingPaths = false; + boolean caseSensitive = getParentRemoteFileSubSystemFactory().isCaseSensitive(); + // test if we are listing in the same folder as any previous filter string... + // ... if we are not, we can save time and skip the redundancy checking.. + for (int idx = 0; idx < currFilterStringIndex; idx++) + { + RemoteFileFilterString prevFS = new RemoteFileFilterString(getParentRemoteFileSubSystemFactory(), allFilterStrings[idx]); + String prevPath = prevFS.getPath(); + if (prevPath == null) + prevPath = ""; + + if ((caseSensitive && prevPath.equals(currPath)) || (!caseSensitive && prevPath.equalsIgnoreCase(currPath))) + { + matchingPaths = true; + } + } + + // ok, what through the current resolved list, and if appropriate strip out + // any entries that are already in the list. That is, any entries with the same + // absolute path name... + // ... for performance reasons, we don't want to waste time checking items in our + // our own list, so we do this in two passes, first marking redundant entries by + // nulling them out... + if (matchingPaths) + { + for (int jdx = 0; jdx < childrenForThisFilterString.length; jdx++) + { + if (childrenForThisFilterString[jdx] instanceof IRemoteFile) + { + IRemoteFile child = (IRemoteFile) childrenForThisFilterString[jdx]; + String path1 = child.getAbsolutePath(); + if (path1 == null) + path1 = ""; + IRemoteFile match = null; + for (int idx = 0;(match == null) && (idx < allChildrenSoFar.size()); idx++) + { + Object prevChild = allChildrenSoFar.elementAt(idx); + if (prevChild instanceof IRemoteFile) + { + String path2 = ((IRemoteFile) prevChild).getAbsolutePath(); + if (path2 == null) + path2 = ""; + if (path1.equals(path2)) + match = (IRemoteFile) prevChild; + } + } + if (match != null) + { + childrenForThisFilterString[jdx] = null; // mark as redundant + // if this redundant entry is a folder, that implies there are multiple + // filter strings that would have resulted in seeing this folder. We need + // to record all such filter strings in the folder's context, so that when + // subsequently expanded, all applicable filter strings will be used to get + // the children of this subdirectory... + if (match.isDirectory() && (match instanceof RemoteFile)) + { + IRemoteFileContext context = ((RemoteFile) match).getContext(); + if (context != null) + { + context.addFilterString(currFS); + } + } + } + } + } // end for loop + } + // second pass... + for (int jdx = 0; jdx < childrenForThisFilterString.length; jdx++) + if (childrenForThisFilterString[jdx] != null) + allChildrenSoFar.addElement(childrenForThisFilterString[jdx]); + } + } + + /** + * Actually resolve an absolute filter string. This is called by the + * run(IProgressMonitor monitor) method, which in turn is called by resolveFilterString. + * @see org.eclipse.rse.core.subsystems.SubSystem#internalResolveFilterString(IProgressMonitor,String) + */ + protected Object[] internalResolveFilterString(IProgressMonitor monitor, String filterString) throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException + { + this.monitor = monitor; + boolean debugMode = false; + IRemoteFileSubSystemConfiguration rfssf = getParentRemoteFileSubSystemFactory(); + boolean windows = !rfssf.isUnixStyle(); + if (debugMode) + SystemBasePlugin.logInfo("INTERNALRESOLVEFILTERSTRING: INPUT FILTERSTRING: " + filterString); + if (filterString.startsWith("/") && windows) // request to list root files? + { // convert to request to list drives on Windows + int len = filterString.length(); + if (len == 1) + filterString = "*"; // hmm, should never happen + else + filterString = filterString.substring(1); + if (debugMode) + SystemBasePlugin.logInfo("...FINAL FILTERSTRING: " + filterString); + } + RemoteFileFilterString fs = new RemoteFileFilterString(rfssf, filterString); + currFilterString = fs; + if (debugMode) + SystemBasePlugin.logInfo("...LISTROOTS = " + fs.listRoots()); + if (fs.listRoots()) + return listRoots(new RemoteFileContext(this, null, fs)); + else + { + boolean showDirs = fs.getShowSubDirs(); + boolean showFiles = fs.getShowFiles(); + String path = fs.getPath(); + if (windows && (path != null) && !path.endsWith(rfssf.getSeparator())) + path = path + rfssf.getSeparatorChar(); + String filter = fs.getFileOrTypes(); + if (debugMode) + SystemBasePlugin.logInfo("...path='" + path + "', filter='" + filter + "', showDirs=" + showDirs + ", showFiles=" + showFiles); + + IRemoteFile parent = null; + try + { + parent = getRemoteFileObject(path); + + /* DKM - now filters should get invalidated via SystemRegistry event firing so this should not be needed + * + // DKM: this may be a filter refresh - to be safe I'm marking it stale + if (parent != null) + parent.markStale(true); + */ + + } + catch (SystemMessageException e) + { + SystemBasePlugin.logError("RemoteFileSubSystemImpl.logError()", e); + parent = null; + } + + boolean parentExists = true; + + if (parent != null) { + parentExists = parent.exists(); + } + + Object[] children = null; + + // if parent exists, get its children according to the filter + if (parent != null && parentExists) + { + boolean hasFileContents = !parent.isStale() && parent.hasContents(RemoteFileChildrenContentsType.getInstance(), filter); + boolean hasFolderContents = !parent.isStale() && parent.hasContents(RemoteFolderChildrenContentsType.getInstance(), filter); + boolean hasFileAndFolderContents = !parent.isStale() && parent.hasContents(RemoteChildrenContentsType.getInstance(), filter); + if (showDirs && showFiles) + { + + if (hasFileAndFolderContents) + { + } + else if (hasFileContents) + { + // already have the files, now add the folders + listFolders(parent, filter); + } + else if (hasFolderContents) + { + // already have the folders, now add the files + listFiles(parent, filter); + } + else + { + // don't have anything - query both + listFoldersAndFiles(parent, filter); + } + children = parent.getContents(RemoteChildrenContentsType.getInstance(), filter); + } + else if (showDirs) + { + if (hasFolderContents) + { + children = parent.getContents(RemoteFolderChildrenContentsType.getInstance(), filter); + } + else + { + children = listFolders(parent, filter); + } + } + else + { + if (hasFileContents) + { + children = parent.getContents(RemoteFileChildrenContentsType.getInstance(), filter); + } + else + { + children = listFiles(parent, filter); + } + } + } + // otherwise return message saying parent could not be found + else if (parent != null && !parentExists) { + children = new SystemMessageObject[1]; + SystemMessage msg = SystemPlugin.getPluginMessage(ISystemMessages.FILEMSG_FOLDER_NOTFOUND); + msg.makeSubstitution(parent.getAbsolutePath()); + children[0] = new SystemMessageObject(msg, ISystemMessageObject.MSGTYPE_ERROR, null); + } + + return children; + } + //return null; + } + /** + * Sort the concatenated list of all objects returned by resolving one or more + * filter strings. + * The default implementation does nothing. Child classes can override if they wish + * to show their resulting objects sorted. + */ + public Object[] sortResolvedFilterStringObjects(Object[] children) + { + if ((children != null) && (children.length > 1)) + Arrays.sort(children); + return children; + } + + /** + * Called by parent when we defer getting a filter string until later, where we query it from + * the parent. In this case we need the first filter string for the progress monitor msg. + */ + protected String getFirstParentFilterString(Object parent) + { + RemoteFileFilterString[] allFilterStrings = ((IRemoteFile) parent).getAllFilterStrings(); + if ((allFilterStrings == null) || (allFilterStrings.length == 0)) + return "*"; + else + { + return allFilterStrings[0].getFileOrTypes(); + } + } + /** + * Actually resolve a relative filter string. This is called by the + * run(IProgressMonitor monitor) method, which in turn is called by resolveFilterString. + *

    + * As per IRunnableWithProgress rules: + *

      + *
    • if the user cancels (monitor.isCanceled()), throw new InterruptedException() + *
    • if something else bad happens, throw new java.lang.reflect.InvocationTargetException(exc); + *
    • do not worry about calling monitor.done() ... caller will do that! + *
    + * YOU MUST OVERRIDE THIS IF YOU SUPPORT FILTERS! + */ + protected Object[] internalResolveFilterString(IProgressMonitor monitor, Object parent, String filterString) throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException + { + + this.monitor = monitor; + RemoteFileFilterString fs = null; + //System.out.println("Inside internalResolveFilterString for parent '"+parent+"' for filterstring '" + filterString+"'"); + if (filterString == null) // this will be the case when we want to support merging of filter strings + { + // this is all for defect 42095. Phil + RemoteFileFilterString[] allFilterStrings = ((IRemoteFile) parent).getAllFilterStrings(); + if (allFilterStrings == null) + fs = new RemoteFileFilterString(getParentRemoteFileSubSystemFactory(), "*"); + else + { + boolean onlyOne = (allFilterStrings.length == 1); + Object[] children = null; + Vector vChildren = null; + if (!onlyOne) + vChildren = new Vector(); + String[] allStrings = new String[allFilterStrings.length]; + for (int idx = 0; idx < allFilterStrings.length; idx++) + allStrings[idx] = allFilterStrings[idx].toString(); + for (int idx = 0; idx < allFilterStrings.length; idx++) + { + fs = (RemoteFileFilterString) allFilterStrings[idx].clone(); + fs.setPath(null); + children = internalResolveOneFilterString(monitor, parent, fs, onlyOne); + if (!onlyOne && (children != null)) + { + addResolvedFilterStringObjects(vChildren, children, allStrings, idx); + } + } + if (!onlyOne) + { + children = new Object[vChildren.size()]; + for (int cdx = 0; cdx < children.length; cdx++) + children[cdx] = vChildren.elementAt(cdx); + Arrays.sort(children); + } + else + { + /* + System.out.println("Returning " + children.length + " children " ); + System.out.println(); + for (int idx=0;idx 1)) + Arrays.sort(children); + } + return children; + } + // --------------------------------------- + // RemoteFileSubSystem WRAPPER METHODS ... + // ... we set the filterstring objects + // --------------------------------------- + + // ------------------------------- + // RemoteFileSubSystem METHODS ... + // ------------------------------- + /** + * Return a list of roots/drives on the remote system + */ + public IRemoteFile[] listRoots() throws InterruptedException + { + return listRoots(getDefaultContext()); + } + + + /** + * Return a list of all remote folders in the given parent folder on the remote system + * @param parent The parent folder to list folders in + */ + public IRemoteFile[] listFolders(IRemoteFile parent) + { + return listFolders(parent, null); + } + + /** + * Return a full list of remote folders in the given parent folder on the remote system. + * @param parent The parent folder to list folders in + * @param fileNameFilter The name pattern for subsetting the file list when this folder is subsequently expanded + */ + public IRemoteFile[] listFolders(IRemoteFile parent, String fileNameFilter) + { + RemoteFileFilterString filterString = new RemoteFileFilterString(getParentRemoteFileSubSystemFactory()); + filterString.setPath(parent.getAbsolutePath()); + filterString.setFile((fileNameFilter == null) ? "*" : fileNameFilter); + filterString.setShowFiles(false); + filterString.setShowSubDirs(true); + RemoteFileContext context = new RemoteFileContext(this, parent, filterString); + //return listFolders(parent, fileNameFilter, context); + return listFolders(parent, null, context); + } + + + /** + * Return a list of all remote files in the given parent folder on the remote system + * @param parent The parent folder to list files in + */ + public IRemoteFile[] listFiles(IRemoteFile parent) + { + return listFiles(parent, null); + } + + /** + * Return a list of remote files in the given folder, which match the given name pattern. + * @param parent The parent folder to list files in + * @param fileNameFilter The name pattern to subset the list by, or null to return all files. + */ + public IRemoteFile[] listFiles(IRemoteFile parent, String fileNameFilter) + { + RemoteFileFilterString filterString = new RemoteFileFilterString(getParentRemoteFileSubSystemFactory()); + filterString.setPath(parent.getAbsolutePath()); + filterString.setFile((fileNameFilter == null) ? "*" : fileNameFilter); + filterString.setShowFiles(true); + filterString.setShowSubDirs(false); + RemoteFileContext context = new RemoteFileContext(this, parent, filterString); + return listFiles(parent, fileNameFilter, context); + } + + + /** + * Return a list of all remote folders and files in the given folder. The list is not subsetted. + * @param parent The parent folder to list folders and files in + */ + public IRemoteFile[] listFoldersAndFiles(IRemoteFile parent) + { + return listFoldersAndFiles(parent, (String) null); + } + + /** + * Return a list of remote folders and files in the given folder. + *

    + * The files part of the list is subsetted by the given file name filter. It can be null for no subsetting. + * + * @param parent The parent folder to list folders and files in + * @param fileNameFilter The name pattern to subset the file list by, or null to return all files. + */ + public IRemoteFile[] listFoldersAndFiles(IRemoteFile parent, String fileNameFilter) + { + + + RemoteFileFilterString filterString = new RemoteFileFilterString(getParentRemoteFileSubSystemFactory()); + filterString.setPath(parent.getAbsolutePath()); + if (fileNameFilter == null) + fileNameFilter = "*"; + filterString.setFile(fileNameFilter); + filterString.setShowFiles(true); + filterString.setShowSubDirs(true); + RemoteFileContext context = new RemoteFileContext(this, parent, filterString); + return listFoldersAndFiles(parent, fileNameFilter, context); + } + + + + + /** + * Given a folder or file, return its parent folder name, fully qualified + * @param folderOrFile folder or file to return parent of. + */ + public String getParentFolderName(IRemoteFile folderOrFile) + { + return folderOrFile.getParentPath(); + } + + + /** + * @see org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem#getRemoteSearchResultObject(java.lang.String) + */ + public IRemoteSearchResult getRemoteSearchResultObject(String key) throws SystemMessageException { + + int idx = key.indexOf(IHostSearchResult.SEARCH_RESULT_DELIMITER); + + if (idx != -1) { + String remoteFilePath = key.substring(0, idx); + IRemoteFile remoteFile = getRemoteFileObject(remoteFilePath); + + if (remoteFile != null) { + + int jdx = idx + IHostSearchResult.SEARCH_RESULT_DELIMITER.length() + IHostSearchResult.SEARCH_RESULT_OPEN_DELIMITER.length(); + + int kdx = key.indexOf(IHostSearchResult.SEARCH_RESULT_INDEX_DELIMITER, jdx); + + String searchString = key.substring(jdx, kdx); + + Object[] children = remoteFile.getContents(RemoteSearchResultsContentsType.getInstance(), searchString); + + if (children != null) { + + int ldx = key.indexOf(IHostSearchResult.SEARCH_RESULT_CLOSE_DELIMITER, kdx+1); + + int index = Integer.valueOf(key.substring(kdx+1, ldx)).intValue(); + + if (children.length > index) { + IRemoteSearchResult result = (IRemoteSearchResult)(children[index]); + return result; + } + else { + return null; + } + } + else { + return null; + } + } + else { + return null; + } + } + else { + return null; + } + } + + /** + * Overrideable Override this method to provide optimized implementation + * Given a set of fully qualified file or folder names, return an ISystemResourceSet object for it. + * @param folderOrFileNames Fully qualified folder or file names + */ + public SystemRemoteResourceSet getRemoteFileObjects(List folderOrFileNames) throws SystemMessageException + { + SystemRemoteResourceSet results = new SystemRemoteResourceSet(this); + for (int i = 0; i < folderOrFileNames.size(); i++) + { + String path = (String)folderOrFileNames.get(i); + results.addResource(getRemoteFileObject(path)); + } + return results; + } + + /** + * Given a un-qualified file or folder name, and its parent folder object, + * return an IRemoteFile object for the file. + * noteThis method should be abstract but MOF doesn't allow abstract impl classes at this point + * @param parent Folder containing the folder or file + * @param folderOrFileName Un-qualified folder or file name + */ + public IRemoteFile getRemoteFileObject(IRemoteFile parent, String folderOrFileName) throws SystemMessageException + { + // child subclasses must override + return null; + } + + /** + * Return the object within the subsystem that corresponds to + * the specified unique ID. For remote files, assuming the key + * is the absolute path of a file, this is simply a wrapper to + * getRemoteFileObject(). + */ + public Object getObjectWithAbsoluteName(String key) throws Exception + { + Object filterRef = getFilterReferenceWithAbsoluteName(key); + + if (filterRef != null) { + return filterRef; + } + + // look to see if there is a search result delimiter + // if not, the key must be for a file + if (key.lastIndexOf(IHostSearchResult.SEARCH_RESULT_DELIMITER) == -1) { + + IRemoteFile remoteFile = getRemoteFileObject(key); + + if (remoteFile != null) { + return remoteFile; + } + else { + return null; + } + } + // otherwise, it's a search result + else { + return getRemoteSearchResultObject(key); + } + } + + + + + + + + /** + * Delete the given remote file or folder. + *

      + *
    • If the input is a folder, that folder must be empty for this to succeed. + *
    + * + * noteThis method should be abstract but MOF doesn't allow abstract impl classes at this point + * + * @param folderOrFile represents the object to be deleted. + * @return false if the given folder/file didn't exist to begin with, else true. Throws an exception if anything fails. + * @deprecated + */ + public boolean delete(IRemoteFile folderOrFile) throws RemoteFolderNotEmptyException, RemoteFileSecurityException, RemoteFileIOException + { + // child subclasses must override + return delete(folderOrFile, null); + } + + + + + /** + * Move a file or folder to a new target parent folder. + * + * @param sourceFolderOrFile The file or folder to move + * @param targetFolder The folder to move to. No guarantee it is on the same system, so be sure to check getSystemConnection()! + * @param newName The new name for the moved file or folder + * @return true iff the move succeeded + * @deprecated + */ + public boolean move(IRemoteFile sourceFolderOrFile, IRemoteFile targetFolder, String newName) throws RemoteFileSecurityException, RemoteFileIOException + { + return move(sourceFolderOrFile, targetFolder, newName, null); + } + + + + + + + // ----------------------------------------------------------------- + // CONVENIENCE METHODS FOR CHILD CLASSES FOR DOING NAME FILTERING... + // ----------------------------------------------------------------- + /** + * Method to set variables to affect the folder content subsetting. + * Use this when only listing either files or folders, but not both. + * @param includeFilesOrFolders A constant from {@link org.eclipse.rse.core.subsystems.IFileConstants} + * @param nameFilter The pattern to filter the file or folder names by. Can be null to include all. + */ + protected void setListValues(int includeFilesOrFolders, String nameFilter) + { + this.includeFilesOrFolders = includeFilesOrFolders; + if ((nameFilter != null) && !nameFilter.equals("*")) + { + if (nameFilter.endsWith(",")) + matcher = new FileTypeMatcher(FileTypeMatcher.parseTypes(nameFilter), isCaseSensitive()); + else + matcher = new NamePatternMatcher(nameFilter, true, isCaseSensitive()); + } + else + matcher = null; + folderNameMatcher = null; + } + /** + * Overloaded method to set variables to affect the folder content subsetting, + * when there is separate filters for both folder names and filter names. + * @param includeFilesOrFolders A constant from {@link org.eclipse.rse.core.subsystems.IFileConstants} + * @param folderNameFilter The pattern to filter the folder names by. Can be null to include all folders + * @param nameFilter The pattern to filter the file names by. Can be null to include all files + */ + protected void setListValues(int includeFilesOrFolders, String folderNameFilter, String fileNameFilter) + { + setListValues(includeFilesOrFolders, fileNameFilter); + if ((folderNameFilter != null) && !folderNameFilter.equals("*")) + folderNameMatcher = new NamePatternMatcher(folderNameFilter, true, isCaseSensitive()); + } + + /** + * Method to decide if a given folder or file name matches the present criteria. + * You must have previously called {@link #setListValues(int, String)} or {@link #setListValues(int, String, String)} + * @param name The file or folder name to test + * @param isFile true if this is a file name, false if it is a folder name. + * @return true if the name matches the previously specified criteria + */ + protected boolean accept(String name, boolean isFile) + { + checkForCancel(); + boolean match = true; + if (includeFilesOrFolders == IClientServerConstants.INCLUDE_FILES_ONLY) + { + if (!isFile) + return false; + } + else if (includeFilesOrFolders == IClientServerConstants.INCLUDE_FOLDERS_ONLY) + { + if (isFile) + return false; + } + if ((matcher == null) && (folderNameMatcher == null)) + return true; + if (includeFilesOrFolders != IClientServerConstants.INCLUDE_ALL) + match = matcher.matches(name); + else + { + if (isFile) + { + if (matcher != null) + match = matcher.matches(name); + } + else + { + if (folderNameMatcher != null) + match = folderNameMatcher.matches(name); + } + } + return match; + } + + /** + * Copy a file or folder to a new target parent folder. + * + * @param sourceFolderOrFile The file or folder to copy + * @param targetFolder The folder to copy to. No guarantee it is on the same system, so be sure to check getSystemConnection()! + * @param newName The new name for the copied file or folder + * @return false true iff the copy succeeded + */ +// public boolean copy(IRemoteFile sourceFolderOrFile, IRemoteFile targetFolder, String newName, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException +// { +// return false; +// } + + + + /** + * Get the remote file and save it locally. The file is saved in the encoding + * of the operating system. + * @param source remote file that represents the file to be obtained + * @param destination the absolute path of the local file + * @param monitor the progress monitor + */ + public void download(IRemoteFile source, String destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + download(source, destination, System.getProperty("file.encoding"), monitor); + } + + /** + * Get the remote file and save it locally. The file is saved in the encoding + * specified. + * @param source remote file that represents the file to be obtained + * @param destination the absolute path of the local file + * @param encoding the encoding of the local file + * @param monitor the progress monitor + */ +// public void copy(IRemoteFile source, String destination, String encoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException +// { +// return; +// } + + /** + * Get the remote file and save it locally. The file is saved in UTF-8 encoding. + * This is a recommended method to use for file transfer + * @param source remote file that represents the file to be obtained + * @param destination the absolute path of the local file + * @param monitor the progress monitor + */ + public void downloadUTF8(IRemoteFile source, String destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + download(source, destination, SystemEncodingUtil.ENCODING_UTF_8, monitor); + } + + /** + * Get the remote file and save it locally. The file is saved in the encoding + * of the operating system. + * @param source remote file that represents the file to be obtained + * @param destination the local file + * @param monitor the progress monitor + */ + public void download(IRemoteFile source, File destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + download(source, destination.getAbsolutePath(), monitor); + } + + /** + * Get the remote file and save it locally. The file is saved in the encoding + * specified. + * @param source remote file that represents the file to be obtained + * @param destination the local file + * @param encoding the encoding of the local file + * @param monitor the progress monitor + */ + public void download(IRemoteFile source, File destination, String encoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + download(source, destination.getAbsolutePath(), encoding, monitor); + } + + /** + * Get the remote file and save it locally. The file is saved in UTF-8 encoding. + * This is a recommended method to use for file transfer + * @param source remote file that represents the file to be obtained + * @param destination the local file + * @param monitor the progress monitor + */ + public void downloadUTF8(IRemoteFile source, File destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + downloadUTF8(source, destination.getAbsolutePath(), monitor); + } + + /** + * Get the remote file and save it locally. The file is saved in the encoding + * of the operating system. + * @param source remote file that represents the file to be obtained + * @param destination the local file + * @param monitor the progress monitor + */ + public void download(IRemoteFile source, IFile destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + download(source, destination.getLocation().makeAbsolute().toOSString(), monitor); + } + + /** + * Get the remote file and save it locally. The file is saved in the encoding + * specified. + * @param source remote file that represents the file to be obtained + * @param destination the local file + * @param encoding the encoding of the local file + * @param monitor the progress monitor + */ + public void download(IRemoteFile source, IFile destination, String encoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + download(source, destination.getLocation().makeAbsolute().toOSString(), encoding, monitor); + } + + /** + * Get the remote file and save it locally. The file is saved in UTF-8 encoding. + * This is a recommended method to use for file transfer + * @param source remote file that represents the file to be obtained + * @param destination the local file + * @param monitor the progress monitor + */ + public void downloadUTF8(IRemoteFile source, IFile destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + downloadUTF8(source, destination.getLocation().makeAbsolute().toOSString(), monitor); + } + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding of the local operating system + * @param source the absolute path of the local copy + * @param destination remote file that represents the file on the server + * @param monitor the progress monitor + */ + public void upload(String source, IRemoteFile destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + upload(source, destination, System.getProperty("file.encoding"), monitor); + destination.markStale(true); + } + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding specified + * @param source the absolute path of the local copy + * @param destination remote file that represents the file on the server + * @param encoding the encoding of the local copy + * @param monitor the progress monitor + */ + +// public void copy(String source, IRemoteFile destination, String encoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException +// { +// return; +// } + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding of the local operating system + * @param source the absolute path of the local copy + * @param destination remote file that represents the file on the server + * @param monitor the progress monitor + */ + public void upload(String source, String destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + upload(source, SystemEncodingUtil.ENCODING_UTF_8, destination, System.getProperty("file.encoding"), monitor); + } + + /** + * Put the local copy of the remote file back to the remote location. The local file + * must be in UTF-8 encoding. + * @param source the absolute path of the local copy + * @param destination remote file that represents the file on the server + * @param monitor the progress monitor + */ + public void uploadUTF8(String source, IRemoteFile destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + upload(source, destination, SystemEncodingUtil.ENCODING_UTF_8, monitor); + destination.markStale(true); + } + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding of the local operating system + * @param source the local copy + * @param destination remote file that represents the file on the server + * @param monitor the progress monitor + */ + public void upload(File source, IRemoteFile destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + upload(source.getAbsolutePath(), destination, monitor); + } + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding specified + * @param source the local copy + * @param destination remote file that represents the file on the server + * @param encoding the encoding of the local copy + * @param monitor the progress monitor + */ + public void upload(File source, IRemoteFile destination, String encoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + upload(source.getAbsolutePath(), destination, encoding, monitor); + destination.markStale(true); + } + + /** + * Put the local copy of the remote file back to the remote location. The local file + * must be in UTF-8 encoding. + * @param source the local copy + * @param destination remote file that represents the file on the server + * @param monitor the progress monitor + */ + public void uploadUTF8(File source, IRemoteFile destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + uploadUTF8(source.getAbsolutePath(), destination, monitor); + } + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding of the local operating system + * @param source the local copy + * @param destination remote file that represents the file on the server + * @param monitor the progress monitor + */ + public void upload(IFile source, IRemoteFile destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + upload(source.getLocation().makeAbsolute().toOSString(), destination, monitor); + } + + /** + * Put the local copy of the remote file back to the remote location. The file + * is assumed to be in the encoding specified + * @param source the local copy + * @param destination remote file that represents the file on the server + * @param encoding the encoding of the local copy + * @param monitor the progress monitor + */ + public void upload(IFile source, IRemoteFile destination, String encoding, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + upload(source.getLocation().makeAbsolute().toOSString(), destination, encoding, monitor); + } + + /** + * Put the local copy of the remote file back to the remote location. The local file + * must be in UTF-8 encoding. + * @param source the local copy + * @param destination remote file that represents the file on the server + * @param monitor the progress monitor + */ + public void uploadUTF8(IFile source, IRemoteFile destination, IProgressMonitor monitor) throws RemoteFileSecurityException, RemoteFileIOException + { + uploadUTF8(source.getLocation().makeAbsolute().toOSString(), destination, monitor); + } + + + + /** + * helper method to run an external command + */ + public static int runLocalCommand(String cmd, Vector lines) throws Exception + { + + boolean debug = true; + int rc = -99; + Process process; + try + { + if (debug) + SystemBasePlugin.logInfo("Running local command: " + cmd); + process = Runtime.getRuntime().exec(cmd); + } + catch (IOException exc) + { + if (debug) + { + String msg = exc.getMessage(); + if (msg == null) + msg = exc.getClass().getName(); + SystemBasePlugin.logInfo("...Unexpected error running command '" + cmd + "'. Error msg: " + msg); + } + throw exc; + } + String line; + DataInputStream err = new DataInputStream(process.getErrorStream()); // capture standard err + BufferedReader berr = new BufferedReader(new InputStreamReader(err)); + try + { + while ((line = berr.readLine()) != null) + { + if (debug) + SystemBasePlugin.logInfo("...System.err: " + line); + if ((lines != null) && (line.trim().length() > 0)) + lines.addElement(line); + } + } + catch (IOException exc) + { + } + DataInputStream in = new DataInputStream(process.getInputStream()); // capture standard out + BufferedReader bin = new BufferedReader(new InputStreamReader(in)); + try + { + while ((line = bin.readLine()) != null) + { + if (debug) + SystemBasePlugin.logInfo("...System out: " + line); + if ((lines != null) && (line.trim().length() > 0)) + lines.addElement(line); + } + } + catch (IOException exc) + { + } + try + { + rc = process.waitFor(); + } + catch (InterruptedException exc) + { + } + return rc; + } // end runCmd method + + /** + * @generated This field/method will be replaced during code generation + */ + public String getHomeFolder() + { + return homeFolder; + } + + /** + * @generated This field/method will be replaced during code generation. + */ + public void setHomeFolder(String newHomeFolder) + { + homeFolder = newHomeFolder; + } + + public void initializeSubSystem(IProgressMonitor monitor) + { + getConnectorService().addCommunicationsListener(this); + } + + /** + * Store the IRemoteFile in a hashmap to quick subsequent retrieval + * @param file the file + */ + public void cacheRemoteFile(IRemoteFile file, String path) + { + + if (_cachedRemoteFiles.containsKey(path)) + { + IRemoteFile oldFile = (IRemoteFile)_cachedRemoteFiles.remove(path); + if (oldFile == file) + { + // already cached - recache + _cachedRemoteFiles.put(path, file); + return; + } + + // replace file under parent + if (oldFile != null && oldFile.getParentRemoteFile() != null) + { + oldFile.getParentRemoteFile().replaceContent(oldFile, file); + } + + // preserve persistent information from old file to new + oldFile.copyContentsTo(file); + + } + _cachedRemoteFiles.put(path, file); + } + + /** + * Store the IRemoteFile in a hashmap to quick subsequent retrieval + * @param file the file + */ + public void cacheRemoteFile(IRemoteFile file) + { + if (file.exists()) + { + cacheRemoteFile(file, file.getAbsolutePath()); + } + } + /** + * Returns the cached remote file with the specified path. If no such file + * is found, returns null + * @param path + * @return the cached file, if found in the cache, else null + */ + public IRemoteFile getCachedRemoteFile(String path) + { + if (_cachedRemoteFiles.size() > 0) + { + path = path.replaceAll("//", "/"); + if (path.endsWith("\\") || (path.endsWith("/") && path.length() > 1)) + { + path = path.substring(0, path.length() - 1); + } + if (_cachedRemoteFiles.containsKey(path)) + { + {return (IRemoteFile)_cachedRemoteFiles.get(path);} + } + + } + return null; + } + + protected void removeCachedRemoteFile(IRemoteFile file) + { + if (file instanceof IRemoteContainer) + { + Object[] children = ((IRemoteContainer)file).getContents(SystemChildrenContentsType.getInstance()); + if (children != null) + { + for (int i = 0; i < children.length; i++) + { + if (children[i] instanceof IRemoteFile) + { + removeCachedRemoteFile((IRemoteFile)children[i]); + } + } + } + } + _cachedRemoteFiles.remove(file.getAbsolutePath()); + } + + protected void removeCachedRemoteFile(String path) + { + _cachedRemoteFiles.remove(path); + } + + + public void communicationsStateChange(CommunicationsEvent e) + { + switch (e.getState()) + { + case CommunicationsEvent.AFTER_DISCONNECT : + _cachedRemoteFiles.clear(); + // DKM - taking this out because it causes an exception when the event occurs in Modal Context + //SystemRegistry sr = SystemPlugin.getDefault().getSystemRegistry(); + //sr.connectedStatusChange(this, false, true, true); + getConnectorService().removeCommunicationsListener(this); + + break; + + case CommunicationsEvent.BEFORE_DISCONNECT : + case CommunicationsEvent.CONNECTION_ERROR : + break; + default : + break; + } + } + + /** + * @see ICommunicationsListener#isPassiveCommunicationsListener() + */ + public boolean isPassiveCommunicationsListener() + { + return true; + } + + /** + * @generated This field/method will be replaced during code generation. + */ + public String toString() + { + + + StringBuffer result = new StringBuffer(super.toString()); + result.append(" (homeFolder: "); + result.append(homeFolder); + result.append(')'); + return result.toString(); + } + + + + /** + * Returns -1 by default. Subclasses should override if necessary. + * @see org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem#getUnusedPort() + */ + public int getUnusedPort() + { + + return -1; + } + + /** + * Returns the address found by calling InetAddress.getLocalHost(). If that + * call returns the local loopback address, it returns null. + * Subclasses should reimplement to handle cases where systems have multiple IP addresses due + * to multiple network cards or VPN. This method should return an address + * that is usable from the remote system to connect back to the local system. + * @see org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem#getLocalAddress() + */ + public InetAddress getLocalAddress() { + + InetAddress addr = null; + + try { + addr = InetAddress.getLocalHost(); + } + catch (UnknownHostException e) { + SystemBasePlugin.logError("Error occured trying to get local host address", e); + addr = null; + } + + // if the address is the loopback address + if (addr != null && addr.isLoopbackAddress()) { + return null; + } + + return addr; + } + + + public Object getTargetForFilter(ISystemFilterReference filterRef) + { + String firstFilterString = ((ISystemFilterReference)filterRef).getReferencedFilter().getFilterStrings()[0]; + RemoteFileFilterString fs = new RemoteFileFilterString(getParentRemoteFileSubSystemFactory(), firstFilterString); + try + { + // change target to be referenced remote folder + return getRemoteFileObject(fs.getPath()); + } + catch (Exception e) + { + } + return null; + } + + + + /** + * @deprecated + */ + public void cancelSearch(IHostSearchResultConfiguration searchConfig) + { + // TODO Auto-generated method stub + + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSubSystemConfiguration.java new file mode 100644 index 00000000000..ba165ca4153 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteFileSubSystemConfiguration.java @@ -0,0 +1,491 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; +import java.util.Vector; + +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.subsystems.IFileConstants; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.core.subsystems.ISubSystemConfiguration; +import org.eclipse.rse.core.subsystems.SubSystemConfiguration; +import org.eclipse.rse.filters.ISystemFilter; +import org.eclipse.rse.filters.ISystemFilterPool; +import org.eclipse.rse.filters.ISystemFilterPoolManager; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.subsystems.files.core.SystemFileResources; +import org.eclipse.rse.subsystems.files.core.model.RemoteFileFilterString; +import org.eclipse.rse.subsystems.files.core.util.ValidatorFileFilterString; +import org.eclipse.rse.ui.validators.ISystemValidator; +import org.eclipse.rse.ui.validators.ValidatorFileName; +import org.eclipse.rse.ui.validators.ValidatorFolderName; +import org.eclipse.rse.ui.wizards.ISystemNewConnectionWizardPage; + + +/** + * Specialization for file subsystem factories. + * It is subclassed via use of a Rose model and MOF/EMF, or better yet + * by subclassing {@link org.eclipse.rse.core.servicesubsystem.impl.FileServiceSubSystemConfiguration}. + * + * @see RemoteFileSubSystem + */ + +public abstract class RemoteFileSubSystemConfiguration extends SubSystemConfiguration implements IRemoteFileSubSystemConfiguration,ISubSystemConfiguration +{ + + protected boolean unixStyle = false; + protected String translatedType; + + /** + * Constructor + */ + public RemoteFileSubSystemConfiguration() + { + super(); + } + /** + * Tell us if this is a unix-style file system or a windows-style file system. The + * default is windows. + * Child classes must call this, so we know how to respond to separator and path-separator requests. + */ + protected void setIsUnixStyle(boolean isUnixStyle) + { + this.unixStyle = isUnixStyle; + } + /** + * Tell us if this is a unix-style file system or a windows-style file system. The + * default is windows. + * Child classes must call this, so we know how to respond to separator and path-separator requests. + */ + public boolean isUnixStyle() + { + return unixStyle; + } + /** + * Tell us if this file system is case sensitive. The default is isUnixStyle(), and so should + * rarely need to be overridden. + */ + public boolean isCaseSensitive() + { + return isUnixStyle(); + } + /** + * Tell us if this subsystem factory supports targets, which are destinations for + * pushes and builds. Normally only true for file system factories. + *

    We return true. + */ + public boolean supportsTargets() + { + return true; + } + /** + * Tell us if this subsystem factory supports server launch properties, which allow the user + * to configure how the server-side code for these subsystems are started. There is a Server + * Launch Setting property page, with a pluggable composite, where users can configure these + * properties. + *
    By default we return false. + */ + public abstract boolean supportsServerLaunchProperties(IHost host); + /** + * Return true if subsystems of this factory support the environment variables property. + * Return true to show it, return false to hide it. We return true. + */ + public boolean supportsEnvironmentVariablesPropertyPage() + { + return true; + } + + /** + * By default this returns true. Override if the file subsystem + * does not support search. + */ + public boolean supportsSearch() + { + return true; + } + + + + // -------------------------------- + // VALIDATOR METHODS... + // -------------------------------- + /** + * Return validator used in filter string dialog for the path part of the filter string. + * By default, returns ValidatorPathName which does very limited checking. + * Override as appropriate. + */ + public ISystemValidator getPathValidator() + { + return new org.eclipse.rse.ui.validators.ValidatorPathName(); + } + /** + * Return validator used in filter string dialog for the file part of the filter string + * By default, returns ValidatorFileFilterString. + * Override as appropriate. + */ + public ISystemValidator getFileFilterStringValidator() + { + return new ValidatorFileFilterString(this); + } + /** + * Return validator used when creating or renaming files + */ + public ValidatorFileName getFileNameValidator() + { + return new ValidatorFileName(); + } + /** + * Return validator used when creating or renaming folders + */ + public ValidatorFolderName getFolderNameValidator() + { + return new ValidatorFolderName(); + } + // -------------------------------- + // FILE SYSTEM ATTRIBUTE METHODS... + // -------------------------------- + /** + * Return in string format the character used to separate folders. Eg, "\" or "/" + */ + public String getSeparator() + { + return (unixStyle) ? IFileConstants.SEPARATOR_UNIX : IFileConstants.SEPARATOR_WINDOWS; + } + /** + * Return in character format the character used to separate folders. Eg, "\" or "/" + */ + public char getSeparatorChar() + { + return (unixStyle) ? IFileConstants.SEPARATOR_CHAR_UNIX : IFileConstants.SEPARATOR_CHAR_WINDOWS; + } + /** + * Return in string format the character used to separate paths. Eg, ";" or ":" + */ + public String getPathSeparator() + { + return (unixStyle) ? IFileConstants.PATH_SEPARATOR_UNIX : IFileConstants.PATH_SEPARATOR_WINDOWS; + } + /** + * Return in char format the character used to separate paths. Eg, ";" or ":" + */ + public char getPathSeparatorChar() + { + return (unixStyle) ? IFileConstants.PATH_SEPARATOR_CHAR_UNIX : IFileConstants.PATH_SEPARATOR_CHAR_WINDOWS; + } + /** + * Return as a string the line separator. + */ + public String getLineSeparator() + { + if (isUnixStyle()) { + return "\n"; + } + else { + return "\r\n"; + } + } + // -------------------------------------------- + // PARENT METHODS RELATED TO WHAT WE SUPPORT... + // -------------------------------------------- + /** + * We return true. + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#supportsUserId() + */ + public boolean supportsUserId() + { + return true; + } + /** + * We return true. + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#supportsSubSystemConnect() + */ + public boolean supportsSubSystemConnect() + { + return true; + } + /** + * We return true. + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#isPortEditable() + */ + public boolean isPortEditable() + { + return true; + } + + /** + * We return false. + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#supportsCommands() + */ + public boolean supportsCommands() + { + return false; + } + /** + * We return false. + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#supportsProperties() + */ + public boolean supportsProperties() + { + return false; + } + /** + * We return true. + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#supportsFilters() + */ + public boolean supportsFilters() + { + return true; + } + + /** + * Return true if filters of this subsystem factory support dropping into. + */ + public boolean supportsDropInFilters() + { + return true; + } + + /** + * Indicates that a drop on a filter will be handled as a copy by the file subsystem + * rather than having a filter update. + */ + public boolean providesCustomDropInFilters() + { + return true; + } + + /** + * We return supportsFilters() + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#supportsNestedFilters() + */ + public boolean supportsNestedFilters() + { + return supportsFilters(); + } + + /** + * Return true if you support user-defined actions for the remote system objects returned from expansion of + * subsystems created by this subsystem factory. + *

    We return true. + * @see #createActionSubSystem() + */ + public boolean supportsUserDefinedActions() + { + return true; + } + + + + /** + * Return true if you support user-defined/managed named file types + *

    We return true + */ + public boolean supportsFileTypes() + { + return true; + } + + /** + * Return true if you support compile actions for the remote system objects returned from expansion of + * subsystems created by this subsystem factory. + *

    + * By returning true, user sees a "Work with->Compile Commands..." action item in the popup menu for this + * subsystem. The action is supplied by the framework, but is populated using overridable methods in this subsystem. + *

    We return false, but really we expect subclasses to return true + */ + public boolean supportsCompileActions() + { + return false; + } + + // ------------------------------------------------------- + // PARENT METHODS RELATED TO FILTERS... + // ... ONLY INTERESTING IF supportsFilters() returns true! + // ------------------------------------------------------- + + /** + * Override from parent. + *

    + * Here we create the default filter pool for this subsystem factory, and populate it + * with default filters. + *

    + * This is overridden for local, windows and ifs file subsystem factories, so what we + * default here applies to Unix and Linux only. + */ + protected ISystemFilterPool createDefaultFilterPool(ISystemFilterPoolManager mgr) + { + //SystemPlugin.logDebugMessage(this.getClass().getName(),"in createDefaultFilterPool for remote file subsystem factory"); + ISystemFilterPool pool = null; + try { + // ----------------------------------------------------- + // create a pool named filters + // ----------------------------------------------------- + pool = mgr.createSystemFilterPool(getDefaultFilterPoolName(mgr.getName(), getId()), true); // true=>is deletable by user + //System.out.println("Pool created"); + // --------------------------------------------------------------------------------------------- + // create default filters in that pool iff this is the user's private profile we are creating... + // --------------------------------------------------------------------------------------------- + if (isUserPrivateProfile(mgr)) + { + + Vector filterStrings = new Vector(); + /* + RemoteFileFilterString rootsFilterString = new RemoteFileFilterString(this); + filterStrings.add(rootsFilterString.toString()); + mgr.createSystemFilter(pool, rb.getString(ISystemFileConstants.RESID_FILTER_ROOTS),filterStrings); + */ + + + // ---------------------- + // "My Home" filter... + // ---------------------- + filterStrings = new Vector(); + RemoteFileFilterString myHomeFilterString = new RemoteFileFilterString(this); + myHomeFilterString.setPath(getSeparator()); + filterStrings.add("./*"); + ISystemFilter filter = mgr.createSystemFilter(pool, SystemFileResources.RESID_FILTER_MYHOME,filterStrings); + filter.setNonChangable(true); + filter.setSingleFilterStringOnly(true); + + // ---------------------- + // "Home" filter... + // ---------------------- + String name = null; + String path = null; + if (mgr.getName().equals("Team")) + { + path = "/home"; + name = SystemFileResources.RESID_FILTER_HOME; + } + else + { + path = "/home"; //"/home/username"; + name = SystemFileResources.RESID_FILTER_USERHOME; + } + filterStrings.clear(); + RemoteFileFilterString homeFilterString = new RemoteFileFilterString(this); + homeFilterString.setPath(path); + filterStrings.add(homeFilterString.toString()); + mgr.createSystemFilter(pool, name, filterStrings); + + + // ---------------------- + // "Root Files" filter... + // ---------------------- + filterStrings = new Vector(); + RemoteFileFilterString rootFilesFilterString = new RemoteFileFilterString(this); + rootFilesFilterString.setPath(getSeparator()); + filterStrings.add(rootFilesFilterString.toString()); + mgr.createSystemFilter(pool, SystemFileResources.RESID_FILTER_ROOTFILES,filterStrings); + } + //else + //System.out.println("Did not create default filters because this is not the default private profile: " + mgr.getName()); + } catch (Exception exc) + { + SystemBasePlugin.logError("Error creating default filter pool",exc); + } + return pool; + } + + /** + * Return the translated string to show in the property sheet for the type property. + */ + public String getTranslatedFilterTypeProperty(ISystemFilter selectedFilter) + { + if (translatedType == null) + translatedType = SystemFileResources.RESID_PROPERTY_FILE_FILTER_VALUE; + return translatedType; + } + + // ------------------------------------------------------- + // PARENT METHODS RELATED TO SUBSYSTEMS... VERY IMPORTANT! + // ------------------------------------------------------- + + + /** + * Instantiate and return an instance of OUR subystem. Do not populate it yet though! + * Eg: + *

    
    +     *     	SubSystem subsys = ((AcmesubsysFactoryImpl)factory).createAcmeSubSystem();
    +     *     	return subsys;
    +     * 
    + * noteThis method should be abstract but MOF doesn't allow abstract impl classes at this point + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#createSubSystemInternal(IHost) + */ + public ISubSystem createSubSystemInternal(IHost conn) + { + // example code for subclasses... + //SubSystem subsys = factory.createRemoteCmdSubSystem(); + //return subsys; + return null; + } + + /** + * Populate a new subsystem with our unique attributes, and/or create default filter references. + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#initializeSubSystem(ISubSystem,ISystemNewConnectionWizardPage[]) + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#getNewConnectionWizardPages(org.eclipse.jface.wizard.IWizard) + */ + protected void initializeSubSystem(ISubSystem ss, ISystemNewConnectionWizardPage[] yourNewConnectionWizardPages) + { + super.initializeSubSystem(ss, yourNewConnectionWizardPages); // add a reference to the default filter pool + + /** FIXME - decouple wiz pages from core - do we still need this? + // Find the "set port" page we contributed to the New Connection wizard, reads it value, and + // default the subsystem's port value to it. + if (yourNewConnectionWizardPages != null) + { + SystemFileNewConnectionWizardPage ourPage = null; + for (int idx=0; (ourPage==null) && (idxnull
    for this implementation. + */ + public Object[] getChildren() { + return null; + } + + /** + * Indicates whether this search result has children + * @return false since there are no children. + */ + public boolean hasChildren() { + return false; + } + + /** + * Gets the displayable label for this output. Calls getText(). + * @return the label. + */ + public String getLabel() { + return getText(); + } + + /** + * Gets the search string that this result matches. + * @return the search string. + */ + public SystemSearchString getMatchingSearchString() { + return _matchingSearchString; + } + + /** + * Add a match to the result. A match comprises a char start offset and a char end offset, both + * relative to the beginning of the file. The matches are added in order. + * @param startOffset the char start offset, from the beginning of the file. + * @param endOffset the char end offset, from the beginning of the file. + */ + public void addMatch(int startOffset, int endOffset) { + _matches.add(new RemoteSearchResultMatch(startOffset, endOffset)); + } + + /** + * Gets the number of matches in this line. + * @return the number of matches. + */ + public int numOfMatches() { + return _matches.size(); + } + + /** + * Gets the char start offset for the given match index. + * @param matchIndex the match index. For example, to get the start offset for the first match, specify 0. + * @return the char start offset, or -1 if there is no match corresponding to the given index. + */ + public int getCharStart(int matchIndex) { + RemoteSearchResultMatch match = (RemoteSearchResultMatch)(_matches.get(matchIndex)); + + if (match != null) { + return match._startOffset; + } + else { + return -1; + } + } + + /** + * Gets the char end offset for the given match index. + * @param matchIndex the match index. For example, to get the end offset for the first match, specify 0. + * @return the char end offset, or -1 if there is no match corresponding to the given index. + */ + public int getCharEnd(int matchIndex) { + RemoteSearchResultMatch match = (RemoteSearchResultMatch)(_matches.get(matchIndex)); + + if (match != null) { + return match._endOffset; + } + else { + return -1; + } + } + + /** + * Returns the char start offset of the first match. + * @see org.eclipse.rse.core.subsystems.IRemoteLineReference#getCharEnd() + */ + public int getCharEnd() { + return getCharEnd(0); + } + + /** + * Returns the char end offset of the first match. + * @see org.eclipse.rse.core.subsystems.IRemoteLineReference#getCharStart() + */ + public int getCharStart() { + return getCharStart(0); + } + + public IHostSearchResultConfiguration getConfiguration() + { + return _configuration; + } + + public void setParent(Object parent) + { + _parent = parent; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteSearchResultConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteSearchResultConfiguration.java new file mode 100644 index 00000000000..63e36cae335 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteSearchResultConfiguration.java @@ -0,0 +1,210 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; + +import java.util.HashMap; +import java.util.Map; +import java.util.Vector; + +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.search.IHostSearchResult; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.services.search.IHostSearchResultSet; +import org.eclipse.rse.services.search.ISearchHandler; + + +/** + * This class represents a search result configuration. A configuration + * consists of a search target and a search string, and belongs to a search + * result set. Once a search has been started via a subsystem, the results + * are stored in the configuration itself. The status of the search can also be queried from + * the configuration. + */ +public class RemoteSearchResultConfiguration implements IHostSearchResultConfiguration { + + protected IHostSearchResultSet parentResultSet; + protected Object searchTarget; + protected SystemSearchString searchString; + protected Vector results; + protected int status; + protected Map _containedResults; + protected ISearchHandler _searchHandler; + + /** + * Constructor for a result set configuration. Sets status to RUNNING. + * @param resultSet the parent result set. + * @param searchObject the target of the search. + * @param searchString the search string. + */ + public RemoteSearchResultConfiguration(IHostSearchResultSet resultSet, Object searchObject, SystemSearchString string) { + results = new Vector(); + setParentResultSet(resultSet); + setSearchTarget(searchObject); + setSearchString(string); + setStatus(RUNNING); + _containedResults = new HashMap(); + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#setParentResultSet(org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultSet) + */ + public void setParentResultSet(IHostSearchResultSet resultSet) { + this.parentResultSet = resultSet; + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#getParentResultSet() + */ + public IHostSearchResultSet getParentResultSet() { + return parentResultSet; + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#setSearchTarget(java.lang.Object) + */ + public void setSearchTarget(Object searchObject) { + this.searchTarget = searchObject; + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#getSearchTarget() + */ + public Object getSearchTarget() { + return searchTarget; + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#setSearchString(org.eclipse.rse.services.clientserver.SystemSearchString) + */ + public void setSearchString(SystemSearchString string) { + this.searchString = string; + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#getSearchString() + */ + public SystemSearchString getSearchString() { + return searchString; + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#addResult(java.lang.Object) + */ + public void addResult(Object result) { + results.add(result); + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#removeResult(java.lang.Object) + */ + public void removeResult(Object result) { + results.remove(result); + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#removeAndAddResult(java.lang.Object, java.lang.Object) + */ + public void removeAndAddResult(Object oldResult, Object newResult) { + results.remove(oldResult); + results.add(newResult); + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#getResults() + */ + public Object[] getResults() { + return results.toArray(); + } + + public IHostSearchResult[] getContainedResults(Object resultContainer) + { + return (IHostSearchResult[])_containedResults.get(resultContainer); + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#getResultsSize() + */ + public int getResultsSize() { + return results.size(); + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#removeResults() + */ + public void removeResults() { + results.removeAllElements(); + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#setStatus(int) + */ + public void setStatus(int status) { + this.status = status; + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#getStatus() + */ + public int getStatus() { + return status; + } + + /** + * Does nothing. + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#cancel() + */ + public void cancel() { + + // if not running, return + if (getStatus() != RUNNING) { + return; + } + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#dispose() + */ + public void dispose() { + + // cancel search first + cancel(); + + // remove results + removeResults(); + } + + public void addResults(Object container, IHostSearchResult[] results) + { + addResult(container); + _containedResults.put(container, results); + + } + + public void setSearchHandler(ISearchHandler handler) + { + _searchHandler = handler; + } + + /** + * Gets the search handler. + * @return the search handler. + */ + public ISearchHandler getSearchHandler() + { + return _searchHandler; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteSearchResultsContentsType.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteSearchResultsContentsType.java new file mode 100644 index 00000000000..a5f1cc3071a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/subsystems/RemoteSearchResultsContentsType.java @@ -0,0 +1,50 @@ +/******************************************************************************** + * Copyright (c) 2004, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.subsystems; + +import org.eclipse.rse.model.ISystemContentsType; + +/** + * Represents contents that are children of a container + */ +public class RemoteSearchResultsContentsType implements ISystemContentsType +{ + public static String CONTENTS_TYPE_SEARCH_RESULTS = "contents_search_results"; + public static RemoteSearchResultsContentsType _instance = new RemoteSearchResultsContentsType(); + + public static RemoteSearchResultsContentsType getInstance() + { + return _instance; + } + + /* (non-Javadoc) + * @see com.ibm.etools.systems.subsystems.IRemoteContentsType#getType() + */ + public String getType() + { + return CONTENTS_TYPE_SEARCH_RESULTS; + } + + /* (non-Javadoc) + * @see com.ibm.etools.systems.subsystems.IRemoteContentsType#isPersistent() + */ + public boolean isPersistent() + { + return true; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/util/SystemRemoteFileMatcher.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/util/SystemRemoteFileMatcher.java new file mode 100644 index 00000000000..65a056c6ba0 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/util/SystemRemoteFileMatcher.java @@ -0,0 +1,93 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.util; +import org.eclipse.rse.core.SystemRemoteObjectMatcher; +import org.eclipse.rse.subsystems.files.core.model.ISystemFileRemoteTypes; + + + +/** + * This class encapsulates all the criteria required to identify a match on a remote + * system file object. + *

    + * Use the static method {@link #getFileOrFolderMatcher()} to get an default instance that + * matches on any directory of any name. + *

    + * You only need to instantiate this class if you want to match on a file of a + * particular name. + * + * @see org.eclipse.rse.ui.view.ISystemRemoteElementAdapter + */ +public class SystemRemoteFileMatcher extends SystemRemoteObjectMatcher +{ + public static SystemRemoteFileMatcher inst, instFiles, instFolders; + public static final String category = ISystemFileRemoteTypes.TYPECATEGORY; + public static final String fileType = ISystemFileRemoteTypes.TYPE_FILE; + public static final String folderType = ISystemFileRemoteTypes.TYPE_FOLDER; + + /** + * Constructor when you want to match on either folders or files + * You only need to instantiate yourself if you want to match on files/folder of a + * particular name + * Otherwise, call {@link #SystemRemoteFileMatcher(String, boolean)}. + */ + public SystemRemoteFileMatcher(String nameFilter) + { + super(null, category, nameFilter, null, null, null); + } + /** + * Constructor when you want to only list files or only list folders + * You only need to instantiate yourself if you want to match on files/folder of a + * particular name + * Otherwise, call {@link #SystemRemoteFileMatcher(String)}. + */ + public SystemRemoteFileMatcher(String nameFilter, boolean foldersOnly) + { + super(null, category, nameFilter, foldersOnly ? folderType : fileType, null, null); + } + + + /** + * Return an instance that will match on any file or folder of any name from any remote system + */ + public static SystemRemoteFileMatcher getFileOrFolderMatcher() + { + if (inst == null) + inst = new SystemRemoteFileMatcher(null); + return inst; + } + /** + * Return an instance that will match on any folder of any name from any remote system + */ + public static SystemRemoteFileMatcher getFolderOnlyMatcher() + { + if (instFolders == null) + instFolders = new SystemRemoteFileMatcher(null, true); + return instFolders; + } + /** + * Return an instance that will match on any file of any name from any remote system + */ + public static SystemRemoteFileMatcher getFileOnlyMatcher() + { + if (instFiles == null) + instFiles = new SystemRemoteFileMatcher(null, false); + return instFiles; + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/util/ValidatorFileFilterString.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/util/ValidatorFileFilterString.java new file mode 100644 index 00000000000..8edcfb8e42d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/util/ValidatorFileFilterString.java @@ -0,0 +1,210 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.util; +import java.util.Vector; + +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.services.clientserver.NamePatternMatcher; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystemConfiguration; +import org.eclipse.rse.ui.ISystemMessages; +import org.eclipse.rse.ui.validators.ValidatorFileName; +import org.eclipse.rse.ui.validators.ValidatorFolderName; +import org.eclipse.rse.ui.validators.ValidatorUniqueString; + + + +/** + * This class is used in dialogs that prompt for file filter strings. + * File filter strings are a bit complex to validate. They have to be: + *

      + *
    • Unique within their filter + *
    • Valid generic names (there are rules regarding number and location of asterisks) + *
    • Either a valid file or folder name, or both, when the asterisks are substituted with a letter like 'A' + *
    + *

    + * The IInputValidator interface is implemented by our parent and it + * is used by jface's InputDialog class and property sheet window. + *

    + * If you subclass this, consider overriding the getFileNameValidator and + * getFolderNameValidator methods. + */ +public class ValidatorFileFilterString + extends ValidatorUniqueString implements ISystemMessages +{ + //public static final boolean CASE_SENSITIVE = true; + //public static final boolean CASE_INSENSITIVE = false; + protected SystemMessage msg_Invalid; + protected IWorkspace workspace = ResourcesPlugin.getWorkspace(); + protected boolean isFileName, isFolderName; + private ValidatorFileName fileNameValidator; + private ValidatorFolderName folderNameValidator; + private IRemoteFileSubSystemConfiguration ssFactory; + + /** + * Constructor accepting a Vector for the list of existing names. + * @param ssFactory - The remote subsystem factory we are validating filter strings in + * @param existingList - A vector containing list of existing filter names to compare against. + * Note that toString() is used to get the string from each item. + */ + public ValidatorFileFilterString(IRemoteFileSubSystemConfiguration ssFactory, Vector existingList) + { + super(existingList, ssFactory.isCaseSensitive()); // case sensitive uniqueness + this.ssFactory = ssFactory; + init(); + } + /** + * Constructor accepting an Array for the list of existing names. + * @param ssFactory - The remote subsystem factory we are validating filter strings in + * @param existingList - An array containing list of existing strings to compare against. + */ + public ValidatorFileFilterString(IRemoteFileSubSystemConfiguration ssFactory, String[] existingList) + { + super(existingList, ssFactory.isCaseSensitive()); // case sensitive uniqueness + this.ssFactory = ssFactory; + init(); + } + + /** + * Use this constructor when the name need not be unique, and you just want + * the syntax checking. + * @param ssFactory - The remote subsystem factory we are validating filter strings in + */ + public ValidatorFileFilterString(IRemoteFileSubSystemConfiguration ssFactory) + { + super(new String[0], ssFactory.isCaseSensitive()); + this.ssFactory = ssFactory; + init(); + } + + + private void init() + { + //setErrorMessages(SystemPlugin.getPluginMessage(FILEMSG_VALIDATE_FILEFILTERSTRING_EMPTY), + setErrorMessages(SystemPlugin.getPluginMessage(MSG_VALIDATE_NAME_EMPTY), + SystemPlugin.getPluginMessage(FILEMSG_VALIDATE_FILEFILTERSTRING_NOTUNIQUE), + SystemPlugin.getPluginMessage(FILEMSG_VALIDATE_FILEFILTERSTRING_NOTVALID)); + isFileName = isFolderName = true; + } + + /** + * Supply your own error message text. By default, messages from SystemPlugin resource bundle are used. + * @param error message when entry field is empty + * @param error message when value entered is not unique + * @param error message when syntax is not valid + */ + public void setErrorMessages(SystemMessage msg_Empty, SystemMessage msg_NonUnique, SystemMessage msg_Invalid) + { + super.setErrorMessages(msg_Empty, msg_NonUnique); + this.msg_Invalid = msg_Invalid; + } + + /** + * Call this before calling isValid! + * Specify true if this is a file name filter + * @see #setIsFolderName(boolean) + */ + public void setIsFileName(boolean is) + { + this.isFileName = is; + } + /** + * Call this before calling isValid! + * Specify true if this is a folder name filter + * @see #setIsFileName(boolean) + */ + public void setIsFolderName(boolean is) + { + this.isFolderName = is; + } + + + /** + * Validate each character. + * Override of parent method. + * Override yourself to refine the error checking. + */ + public SystemMessage isSyntaxOk(String newText) + { + boolean ok = NamePatternMatcher.verifyPattern(newText, true); // true=>advanced-style-patterns + if (!ok) + return msg_Invalid; + String tempText = newText; + if (isFileName || isFolderName) + tempText = newText.replace('*','A'); + //if (isFileName && (errMsg==null)) + if (isFileName) + return getFileNameValidator().isSyntaxOk(tempText); + else if (isFolderName) + return getFolderNameValidator().isSyntaxOk(tempText); + return null; + } + + /** + * Overridable extension point to get basic file name validator + * By default, queries it from the file subsystem factory + */ + protected ValidatorFileName getFileNameValidator() + { + if (fileNameValidator == null) + fileNameValidator = ssFactory.getFileNameValidator();; + return fileNameValidator; + } + /** + * Overridable extension point to get basic folder name validator + * By default, queries it from the file subsystem factory + */ + protected ValidatorFolderName getFolderNameValidator() + { + if (folderNameValidator == null) + folderNameValidator = ssFactory.getFolderNameValidator();; + return folderNameValidator; + } + + /** + * Return true if case sensitive, false it not. + * By default, return ssFactory.isUnixStyle() + */ + protected boolean isCaseSensitive(IRemoteFileSubSystemConfiguration ssFactory) + { + return ssFactory.isUnixStyle(); + } + + /** + * Return the max length for this file or folder name + */ + public int getMaximumNameLength() + { + /* should probably do the following but too high risk right now + if (isFileName) + return getFileNameValidator().getMaximumNameLength(); + else if (isFolderName) + return getFolderNameValidator().getMaximumNameLength(); + */ + return -1; + } + + + public String toString() + { + return "ValidatorFileFilterString class"; + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/util/ValidatorFileUniqueName.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/util/ValidatorFileUniqueName.java new file mode 100644 index 00000000000..55a92958f32 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/util/ValidatorFileUniqueName.java @@ -0,0 +1,157 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.core.util; +import java.util.Vector; + +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.ui.ISystemMessages; +import org.eclipse.rse.ui.validators.ValidatorFileName; +import org.eclipse.rse.ui.validators.ValidatorFolderName; +import org.eclipse.rse.ui.validators.ValidatorUniqueString; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.widgets.Shell; + + + +/** + * This class is used in dialogs that prompt for file or folder names, and those names need to be unique + * within a given folder. To make sure error checking while typing is fast, we go get the list of names + * of the files and folders in the constructor and re-use it from then on. + *

    + * The IInputValidator interface is implemented by our parent and it + * is used by jface's InputDialog class and property sheet window. + *

    + * If you subclass this, consider overriding the getFileNameValidator and + * getFolderNameValidator methods. + */ +public class ValidatorFileUniqueName + extends ValidatorUniqueString implements ISystemMessages +{ + //public static final boolean CASE_SENSITIVE = true; + //public static final boolean CASE_INSENSITIVE = false; + protected SystemMessage msg_Invalid; + private ValidatorFileName fileNameValidator = new ValidatorFileName(); + private ValidatorFolderName folderNameValidator = new ValidatorFolderName(); + protected IRemoteFile parentFolder; + protected Vector names; + protected boolean isFolder; + + /** + * Constructor + * @param parentFolder the folder within which the name must be unique. + * @param true if validating a folder name versus a file name + */ + public ValidatorFileUniqueName(Shell shell, IRemoteFile parentFolder, boolean isFolder) + { + super((Vector)null, parentFolder.getParentRemoteFileSubSystem().isCaseSensitive() ); + this.parentFolder = parentFolder; + this.isFolder = isFolder; + init(shell); + } + + + private void init(Shell shell) + { + Cursor busyCursor = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT); + //shell.setCursor(busyCursor); + org.eclipse.rse.ui.dialogs.SystemPromptDialog.setDisplayCursor(shell, busyCursor); + + setErrorMessages(SystemPlugin.getPluginMessage(MSG_VALIDATE_NAME_EMPTY), + SystemPlugin.getPluginMessage(MSG_VALIDATE_NAME_NOTUNIQUE), + isFolder ? SystemPlugin.getPluginMessage(MSG_VALIDATE_FOLDERNAME_NOTVALID) : + SystemPlugin.getPluginMessage(MSG_VALIDATE_FILENAME_NOTVALID) + ); + IRemoteFile[] contents = parentFolder.getParentRemoteFileSubSystem().listFoldersAndFiles(parentFolder); + if (contents!=null) + { + String[] names = new String[contents.length]; + for (int idx=0; idx + + + + + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/.cvsignore b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/.cvsignore new file mode 100644 index 00000000000..ba077a4031a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/.project b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/.project new file mode 100644 index 00000000000..4b8a7699a5a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/.project @@ -0,0 +1,28 @@ + + + org.eclipse.rse.subsystems.files.dstore + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..c399ef20568 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin.name +Bundle-SymbolicName: org.eclipse.rse.subsystems.files.dstore;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.rse.subsystems.files.dstore.Activator +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.rse.services, + org.eclipse.rse.services.dstore, + org.eclipse.dstore.core, + org.eclipse.rse.connectorservice.dstore, + org.eclipse.dstore.extra, + org.eclipse.rse.files.ui, + org.eclipse.rse.subsystems.files.core, + org.eclipse.rse.ui +Eclipse-LazyStart: true +Export-Package: org.eclipse.rse.subsystems.files.dstore, + org.eclipse.rse.subsystems.files.dstore.model, + org.eclipse.rse.subsystems.files.dstore.subsystem +Bundle-Vendor: Eclipse.org +Bundle-ClassPath: filesDstore.jar diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/about.html b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/about.html new file mode 100644 index 00000000000..6f6b96c4c87 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/about.html @@ -0,0 +1,22 @@ + + + +About + + + +

    About This Content

    + +

    February 24, 2005

    +

    License

    + +

    The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

    + +

    If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content.

    + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/build.properties b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/build.properties new file mode 100644 index 00000000000..2a1e900ea81 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/build.properties @@ -0,0 +1,14 @@ +bin.includes = META-INF/,\ + about.html,\ + icons/,\ + plugin.properties,\ + plugin.xml,\ + filesDstore.jar +src.includes = META-INF/,\ + about.html,\ + icons/,\ + plugin.properties,\ + plugin.xml +jars.compile.order = filesDstore.jar +source.filesDstore.jar = src/ +output.filesDstore.jar = bin/ diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/icons/full/obj16/systemfiles_obj.gif b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/icons/full/obj16/systemfiles_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..874c992621585ee9cc49f4cf8c1a93bab77786d0 GIT binary patch literal 157 zcmZ?wbhEHb6krfw*v!Dt(7-T%zWx9I^W)>~>+9q9@1KAF{{H*>?f>78{|_SP|NsBL zp`jr@J|4(mU|>-E$->CMz{j8iWCKkQU|?YJy5K49FvFr@m`u<+ITm2x2aoV%!x%37q{q( IFfv#J0B(aoLI3~& literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/icons/full/obj16/systemfileslive_obj.gif b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/icons/full/obj16/systemfileslive_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..885b8a69e39be4762e9314498547527837cba710 GIT binary patch literal 224 zcmZ?wbhEHb6krfwIKsfd@SlO9fx$lBzM+9({(SrY|L4cY+t=5}@83WF{{8*;_uK!! zAOGu4d`oree-L~A|Ns9R8XDr`!8T q?^Yp8(X^KE-sYOKetWi;bkx31ef>U4kfWKSAyhE0vnEQB!5RQjK2eqc literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/plugin.properties b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/plugin.properties new file mode 100644 index 00000000000..7e62f08f6b4 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/plugin.properties @@ -0,0 +1,20 @@ +################################################################################ +# Copyright (c) 2006 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: +# {Name} (company) - description of contribution. +################################################################################ + +plugin.name = RSE Dstore Files + +Files=Files +FilesDescription=This configuration allows you to work with files on local or remote systems using the DataStore protocol. \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/plugin.xml b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/plugin.xml new file mode 100644 index 00000000000..2279b3608b8 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/plugin.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/Activator.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/Activator.java new file mode 100644 index 00000000000..f0275315920 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/Activator.java @@ -0,0 +1,69 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.dstore; + +import org.eclipse.rse.core.SystemBasePlugin; +import org.osgi.framework.BundleContext; + + +/** + * The main plugin class to be used in the desktop. + */ +public class Activator extends SystemBasePlugin { + + //The shared instance. + private static Activator plugin; + + /** + * The constructor. + */ + public Activator() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); +// make sure files.ui is activated + org.eclipse.rse.files.ui.Activator.getDefault(); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static Activator getDefault() { + return plugin; + } + + protected void initializeImageRegistry() + { + // TODO Auto-generated method stub + + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/model/DStoreFile.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/model/DStoreFile.java new file mode 100644 index 00000000000..99a59360568 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/model/DStoreFile.java @@ -0,0 +1,65 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.dstore.model; + +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.services.dstore.files.DStoreHostFile; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.AbstractRemoteFile; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileContext; + +import org.eclipse.dstore.core.model.DataElement; + +public class DStoreFile extends AbstractRemoteFile implements IRemoteFile +{ + protected DStoreHostFile _dstoreHostFile; + public DStoreFile(FileServiceSubSystem ss, IRemoteFileContext context, IRemoteFile parent, DStoreHostFile hostFile) + { + super(ss,context, parent, hostFile); + _dstoreHostFile = hostFile; + } + + public boolean isVirtual() + { + DataElement element = _dstoreHostFile.getDataElement(); + String type = element.getType(); + if ( + type.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || + type.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR) ) + { + return true; + } + return false; + } + + public String getCanonicalPath() + { + return getAbsolutePath(); + } + + public String getClassification() + { + return _dstoreHostFile.getClassification(); + } + + + + + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/model/DStoreFileAdapter.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/model/DStoreFileAdapter.java new file mode 100644 index 00000000000..be454c3448f --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/model/DStoreFileAdapter.java @@ -0,0 +1,125 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.dstore.model; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.rse.connectorservice.dstore.DStoreConnectorService; +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.services.dstore.files.DStoreHostFile; +import org.eclipse.rse.services.dstore.files.DStoreVirtualHostFile; +import org.eclipse.rse.services.files.IHostFile; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.IHostFileToRemoteFileAdapter; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileContext; +import org.eclipse.rse.subsystems.files.dstore.subsystem.RemoteFilePropertyChangeListener; +import org.eclipse.rse.ui.ISystemPreferencesConstants; + +import org.eclipse.dstore.core.model.DataElement; + +public class DStoreFileAdapter implements IHostFileToRemoteFileAdapter +{ + private RemoteFilePropertyChangeListener _listener; + + private void registerFilePropertyChangeListener(FileServiceSubSystem ss) + { + if (_listener == null) + { + DStoreConnectorService connectorService = (DStoreConnectorService)ss.getConnectorService(); + _listener = new RemoteFilePropertyChangeListener(SystemBasePlugin.getActiveWorkbenchShell(), connectorService, connectorService.getDataStore(), ss); + } + } + + + public IRemoteFile[] convertToRemoteFiles(FileServiceSubSystem ss, IRemoteFileContext context, IRemoteFile parent, IHostFile[] nodes) + { + registerFilePropertyChangeListener(ss); + boolean showHidden = SystemPlugin.getDefault().getPreferenceStore().getBoolean(ISystemPreferencesConstants.SHOWHIDDEN); + + List results = new ArrayList(); + for (int i = 0; i < nodes.length; i++) + { + DStoreHostFile node = (DStoreHostFile)nodes[i]; + if (showHidden || !node.isHidden()) + { + IRemoteFile lfile = null; + + if (node instanceof DStoreVirtualHostFile) + { + lfile = new DStoreVirtualFile(ss, context, parent, (DStoreVirtualHostFile) node); + } + else + { + lfile = new DStoreFile(ss, context, parent, node); + } + results.add(lfile); + ss.cacheRemoteFile(lfile); + } + } + return (IRemoteFile[])results.toArray(new IRemoteFile[results.size()]); + } + + + + public IRemoteFile convertToRemoteFile(FileServiceSubSystem ss, IRemoteFileContext context, IRemoteFile parent, IHostFile node) + { + registerFilePropertyChangeListener(ss); + + IRemoteFile file = null; + + if (node instanceof DStoreVirtualHostFile) + { + file = new DStoreVirtualFile(ss, context, parent, (DStoreVirtualHostFile)node); + } + else + { + file = new DStoreFile(ss, context, parent, (DStoreHostFile)node); + } + ss.cacheRemoteFile(file); + return file; + } + + + public IRemoteFile convertToRemoteFile(FileServiceSubSystem ss, IRemoteFileContext context, IRemoteFile parent, String name, boolean isDirectory, boolean isRoot) + { + // TODO Auto-generated method stub + return null; + } + + public IRemoteFile convertToRemoteFile(FileServiceSubSystem ss, IRemoteFileContext context, IRemoteFile parent, Object object) + { + registerFilePropertyChangeListener(ss); + if (object instanceof DataElement) + { + DStoreHostFile hostFile = new DStoreHostFile((DataElement)object); + IRemoteFile file = null; + + { + file = new DStoreFile(ss, context, parent, hostFile); + } + ss.cacheRemoteFile(file); + return file; + } + else + { + return null; + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/model/DStoreSearchResult.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/model/DStoreSearchResult.java new file mode 100644 index 00000000000..d61a9678883 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/model/DStoreSearchResult.java @@ -0,0 +1,77 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.dstore.model; + + + +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteSearchResult; + +import org.eclipse.dstore.core.model.DataElement; + +/** + * Class for describing a line of command output on a + * universal system + */ +public class DStoreSearchResult extends RemoteSearchResult +{ + + + public int getLine() + { + String src=_element.getSource(); + int colonIndex = src.indexOf(':'); + if (colonIndex > 2) + { + String srcNum = src.substring(colonIndex + 1); + return Integer.parseInt(srcNum); + } + return 0; + } + + + private DataElement _element; + + public DStoreSearchResult(IHostSearchResultConfiguration configuration, Object parent, DataElement element, SystemSearchString searchString) + { + super(configuration, parent, searchString); + _element = element; + } + + + public String getText() + { + if (_element != null && !_element.isDeleted() && _element.getName() != null) + { + String name = _element.getName(); + setText(name); + return name; + } + else + { + return super.getText(); + } + } + + public void dispose() + { + _element.getDataStore().deleteObject(_element.getParent(), _element); + _element.getParent().removeNestedData(_element); + _element = null; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/model/DStoreVirtualFile.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/model/DStoreVirtualFile.java new file mode 100644 index 00000000000..17fd61eb26a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/model/DStoreVirtualFile.java @@ -0,0 +1,76 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.dstore.model; + +import org.eclipse.rse.services.dstore.files.DStoreVirtualHostFile; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileContext; +import org.eclipse.rse.subsystems.files.core.subsystems.IVirtualRemoteFile; + +public class DStoreVirtualFile extends DStoreFile implements IVirtualRemoteFile +{ + + protected DStoreVirtualHostFile _node; + + public DStoreVirtualFile(FileServiceSubSystem ss, IRemoteFileContext context, IRemoteFile parent, DStoreVirtualHostFile hostFile) + { + super(ss, context, parent, hostFile); + _node = hostFile; + } + + public String getVirtualName() + { + return _node.getName(); + } + + public boolean isVirtualFolder() + { + return _node.isDirectory(); + } + + public boolean isVirtualFile() + { + return _node.isFile(); + } + + public long getCompressedSize() + { + return _node.getCompressedSize(); + } + + public String getCompressionMethod() + { + return _node.getCompressionMethod(); + } + + public double getCompressionRatio() + { + return _node.getCompressionRatio(); + } + + public long getExpandedSize() + { + return _node.getExpandedSize(); + } + + public String getComment() + { + return _node.getComment(); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/DownloadListener.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/DownloadListener.java new file mode 100644 index 00000000000..0e4043d74a3 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/DownloadListener.java @@ -0,0 +1,369 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.dstore.old; + + + +import java.io.File; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.connectorservice.dstore.util.ICommunicationsDiagnosticFactory; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.subsystems.CommunicationsEvent; +import org.eclipse.rse.core.subsystems.ICommunicationsListener; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.ui.ISystemMessages; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.extra.internal.extra.DomainEvent; +import org.eclipse.dstore.extra.internal.extra.IDomainListener; + +public class DownloadListener implements IDomainListener, ICommunicationsListener, IUniversalDataStoreConstants +{ + + private DataElement _status; + private Shell _shell; + private IProgressMonitor _monitor; + private DataStore _dataStore; + private File _localFile; + private Display _display; + + private boolean _networkDown = false; + private boolean _isDone = false; + private boolean _isCancelled = false; + private long _totalBytesNotified = 0; + private long _totalLength; + private static SystemMessage _percentMsg = SystemPlugin.getPluginMessage(ISystemMessages.MSG_PERCENT_DONE); + + public DownloadListener(Shell shell, IProgressMonitor monitor, IConnectorService system, DataElement status, File localFile, String remotePath, long totalLength) + { + _shell = shell; + _monitor = monitor; + _status = status; + _totalLength = totalLength; + _display = Display.getCurrent(); + + if (_status == null) + { + System.out.println("Status is null!"); + } + + _dataStore = _status.getDataStore(); + system.addCommunicationsListener(this); + _dataStore.getDomainNotifier().addDomainListener(this); + + _localFile = localFile; + + if (monitor != null) + { + if (_display != null) + { + while (_display.readAndDispatch()) + { + } + } + + } + if (_status.getValue().equals("done")) + { + updateDownloadState(); + setDone(true); + } + + } + public boolean isCancelled() + { + return _isCancelled; + } + + public DataElement getStatus() + { + return _status; + } + + /** + * @see IDomainListener#listeningTo(DomainEvent) + */ + public boolean listeningTo(DomainEvent event) + { + if (_status == null) + { + return false; + } + + if (_status == event.getParent()) + { + return true; + } + + return false; + } + + /** + * @see IDomainListener#domainChanged(DomainEvent) + */ + public void domainChanged(DomainEvent event) + { + if (_status.getValue().equals("done")) + { + + if (_status == event.getParent()) + { + setDone(true); + } + } + else + { + updateDownloadState(); + } + } + + private void updateDownloadState() + { + + if (_monitor != null) + { + long currentLength = _localFile.length(); + long delta = currentLength - _totalBytesNotified; + if (delta > 0) + { + //System.out.println(_status.getAttribute(DE.A_SOURCE)); + _monitor.worked((int)delta); + + try + { + long percent = (currentLength * 100) / _totalLength; + + + StringBuffer current = new StringBuffer(); + current.append(currentLength /KB_IN_BYTES); + current.append(" KB"); + + StringBuffer total = new StringBuffer(); + total.append(_totalLength / KB_IN_BYTES); + total.append(" KB"); + + StringBuffer percentBuf = new StringBuffer(); + percentBuf.append(percent); + percentBuf.append("%"); + + _percentMsg.makeSubstitution(current, total, percentBuf); + + _monitor.subTask(_percentMsg.getLevelOneText()); + + if (_display != null) + { + while (_display.readAndDispatch()) + { + } + } + } + catch (Exception e) + { + } + _totalBytesNotified = currentLength; + } + } + + if (!_status.getDataStore().getStatus().getName().equals("okay")) + { + _networkDown = true; + } + } + + /** + * setDone(boolean) + */ + public void setDone(boolean done) + { + this._isDone = done; + if (done) + { + updateDownloadState(); + _status.getDataStore().getDomainNotifier().removeDomainListener(this); + + } + } + + /** + * @see IDomainListener#getShell() + */ + public Shell getShell() + { + return _shell; + } + + /** + * + */ + public boolean wasCancelled() + { + return _isCancelled; + } + + /** + * @see ICommunicationsListener#communicationsStateChange(CommunicationsEvent) + */ + public void communicationsStateChange(CommunicationsEvent e) + { + if (e.getState() == CommunicationsEvent.CONNECTION_ERROR) + { + _networkDown = true; + } + } + + /** + * @see ICommunicationsListener#isPassiveCommunicationsListener() + */ + public boolean isPassiveCommunicationsListener() + { + return true; + } + + /** + * Wait for the the status DataElement to be refreshed + * + * @param + * ICommunicationsDiagnosticFactory factory : for creating system specific diagnostic class instance + * Int wait : threshold for starting diagnostic. Default is 60 seconds; a zero means to use the default. + * -1 means to force a timeout; mainly for testing purpose. + * + * @return The status DataElement after it has been updated, or the user + * has pressed cancel + * + * @throws InterruptedException if the thread was interrupted. + */ + public DataElement waitForUpdate() throws InterruptedException + { + return waitForUpdate(null, 0); //No diagnostic + } + + public DataElement waitForUpdate(ICommunicationsDiagnosticFactory factory) throws InterruptedException + { + return waitForUpdate(factory, 0); //Use the default wait threshold + } + + public DataElement waitForUpdate(ICommunicationsDiagnosticFactory factory, int wait) throws InterruptedException + { + Display display = _display; + + if (wait > 0) + { + } + else if (wait == -1) + { + } + + if (display != null) + { + if (_shell == null || _shell.isDisposed()) + { + _shell = Display.getDefault().getActiveShell(); + } + // Current thread is UI thread + while (!_isDone && !_isCancelled && !_networkDown) + { + // Process everything on event queue + while (display.readAndDispatch()) + { + } + + if ((_monitor != null) && (_monitor.isCanceled())) + { + // cancel remote request + cancelDownload(); + _isCancelled = true; + setDone(true); + } + else if (_networkDown) + { + _isCancelled = true; + setDone(true); + throw new InterruptedException(); + } + + if (getStatus().getAttribute(DE.A_NAME).equals("done")) + { + setDone(true); + } + else + { + Thread.sleep(100); + updateDownloadState(); + } + } + + } + else + { + // Current thread is not UI thread + while (!_isDone && !_isCancelled && !_networkDown) + { + if ((_monitor != null) && (_monitor.isCanceled())) + { + cancelDownload(); + _isCancelled = true; + setDone(true); + } + else if (_networkDown) + { + _isCancelled = true; + setDone(true); + throw new InterruptedException(); + } + + if (getStatus().getAttribute(DE.A_NAME).equals("done")) + { + setDone(true); + } + else + { + Thread.sleep(100); + updateDownloadState(); + } + } + } + return _status; + } + + public void cancelDownload() + { + DataElement status = _status; + if (status != null) + { + DataElement command = status.getParent(); + DataStore dataStore = command.getDataStore(); + DataElement cmdDescriptor = command.getDescriptor(); + DataElement cancelDescriptor = dataStore.localDescriptorQuery(cmdDescriptor, "C_CANCEL"); + if (cancelDescriptor != null) + { + dataStore.command(cancelDescriptor, command); + } + _localFile.delete(); + } + if (_monitor != null) + { + _monitor.done(); + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/FileTransferStatusListener.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/FileTransferStatusListener.java new file mode 100644 index 00000000000..daa0b83c83d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/FileTransferStatusListener.java @@ -0,0 +1,124 @@ +/******************************************************************************** + * Copyright (c) 2004, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.dstore.old; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.services.clientserver.IServiceConstants; +import org.eclipse.swt.widgets.Shell; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.core.model.DataStoreSchema; + +/** + * @author mjberger + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class FileTransferStatusListener extends StatusChangeListener +{ + + protected String _remotePath; + protected DataElement _log; + protected DataElement _statusElement; + + public FileTransferStatusListener(String remotePath, Shell shell, IProgressMonitor monitor, IConnectorService system, DataStore ds, DataElement uploadLog) throws Exception + { + super(shell, monitor, system); + _remotePath = remotePath.replace('\\', '/'); + + _log = uploadLog; + if (_log == null) + { + throw new Exception("Could not find log in DataStore."); + } + setStatus(findOrCreateUploadStatus(ds)); + } + + protected DataElement findOrCreateUploadStatus(DataStore ds) + { + DataElement result = ds.find(_log, DE.A_NAME, _remotePath,1); + + // first upload, this will always ben null + // but also need to handle case where it's been uploaded before in the sessoin (i.e. for reseting values) + if (result == null) + { + result = _log.getDataStore().createObject(_log, "uploadstatus", _remotePath); + result.setAttribute(DE.A_SOURCE, "running"); + result.setAttribute(DE.A_VALUE, ""); + + DataElement cmd = ds.findCommandDescriptor(DataStoreSchema.C_SET); + + DataElement setstatus = ds.command(cmd, _log, true); + /* + try + { + StatusMonitorFactory.getInstance().getStatusMonitorFor(system, ds).waitForUpdate(setstatus); + } + catch (Exception e) + { + } + */ + // DKM: no need for this - turns out the problem was that we need to send the LOG not the result - + // since the server needs to know the parent! + //ds.waitUntil(setstatus, "done"); + + } + else + { + + result.setAttribute(DE.A_SOURCE, "running"); + result.setAttribute(DE.A_VALUE, ""); + } + _statusElement = result; + return result; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.files.dstore.old.StatusChangeListener#determineStatusDone() + */ + protected boolean determineStatusDone() + { + return getStatus().getAttribute(DE.A_SOURCE).equals(IServiceConstants.SUCCESS) || getStatus().getAttribute(DE.A_SOURCE).equals(IServiceConstants.FAILED); + + } + + public boolean uploadHasFailed() + { + return getStatus().getAttribute(DE.A_SOURCE).equals(IServiceConstants.FAILED); + } + + public String getErrorMessage() + { + return getStatus().getAttribute(DE.A_VALUE); + } + + public String getRemotePath() + { + return _remotePath; + } + + public void setRemotePath(String remotePath) + { + _remotePath = remotePath; + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/SearchResultsChangeListener.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/SearchResultsChangeListener.java new file mode 100644 index 00000000000..fe826cce6d9 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/SearchResultsChangeListener.java @@ -0,0 +1,400 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.dstore.old; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.subsystems.CommunicationsEvent; +import org.eclipse.rse.core.subsystems.ICommunicationsListener; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.model.ISystemRegistry; +import org.eclipse.rse.model.ISystemResourceChangeEvents; +import org.eclipse.rse.model.SystemResourceChangeEvent; +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileContext; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteSearchConstants; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileContext; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteSearchResult; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteSearchResultsContentsType; +import org.eclipse.rse.subsystems.files.dstore.model.DStoreFile; +import org.eclipse.rse.subsystems.files.dstore.model.DStoreSearchResult; +import org.eclipse.rse.ui.ISystemMessages; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.extra.internal.extra.DomainEvent; +import org.eclipse.dstore.extra.internal.extra.IDomainListener; + + +public class SearchResultsChangeListener implements IDomainListener, ICommunicationsListener { + + + private Shell _shell; + private UniversalSearchResultConfigurationImpl _searchConfig; + private DataElement _status; + private IRemoteFileSubSystem _subsys; + private DataStore _dataStore; + private IRemoteFileContext _defaultContext; + private IRemoteFileContext _currentContext; + //private IRemoteFileFactory _factory; + private long _lastUpdateTime; + private boolean _disconnected = false; + private boolean _cancelled = false; + + private static int MAX_RESULTS = 10000; + + public SearchResultsChangeListener(Shell shell, UniversalSearchResultConfigurationImpl searchConfig) { + _shell = shell; + _searchConfig = searchConfig; + + IRemoteFile rmtFile = (IRemoteFile)_searchConfig.getSearchTarget(); + _subsys = rmtFile.getParentRemoteFileSubSystem(); + + _status = _searchConfig.getStatusObject(); + _dataStore = _status.getDataStore(); + + _dataStore.getDomainNotifier().addDomainListener(this); + _subsys.getConnectorService().addCommunicationsListener(this); + + _lastUpdateTime = 0; + + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + + //_factory = ((FileServiceSubSystem)_subsys).getRemoteFileFactory(); + + if (_status.getValue().equals("done")) { + setDone(); + } + else if (_status.getValue().equals("cancelled")) { + _cancelled = true; + setDone(); + } + } + + public IHostSearchResultConfiguration getSearchResults() { + return _searchConfig; + } + + public DataElement getStatus() { + return _status; + } + + /** + * @see IDomainListener#listeningTo(DomainEvent) + */ + public boolean listeningTo(DomainEvent event) { + + + DataElement parent = (DataElement)event.getParent(); + if (_status == null) { + return false; + } + else if (_status == parent) { + return true; + } + else if (_status.getParent() == parent) + { + return true; + } + + return false; + } + + /** + * @see IDomainListener#domainChanged(DomainEvent) + */ + public void domainChanged(DomainEvent event) { + + if (!_subsys.isConnected()) + { + _disconnected = true; + setDone(); + return; + } + + if (_status.getValue().equals("done")) { + setDone(); + } + else if (_status.getValue().equals("cancelled")) { + _cancelled = true; + setDone(); + } + else { + long currentTime = System.currentTimeMillis(); + long deltaTime = currentTime - _lastUpdateTime; + + // update frequency is inversely proportional to the number of search results + if (deltaTime > _searchConfig.getResultsSize() && _searchConfig.getResultsSize() < MAX_RESULTS) { + _lastUpdateTime = currentTime; + handleSearchResults(); + } + } + } + + private void handleSearchResults() { + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + + // append new results to existing results + List results = _status.getNestedData(); + if (results != null) + { + int totalSize = results.size(); + int currentSize = _searchConfig.getResultsSize(); + + for (int loop = currentSize; loop < totalSize && loop < MAX_RESULTS; loop++) { + + DataElement result = (DataElement)results.get(loop); + + if (_defaultContext == null) { + _defaultContext = new RemoteFileContext(_subsys, null, null); + _currentContext = _defaultContext; + } + + if (result.getName().length() > 0) { + + // for defect 47414, this code changes the context used for creating IRemoteFiles + char slash = '/'; + + if (_subsys.getHost().getSystemType().equals("Windows")) { + slash = '\\'; + } + + String parentPath = result.getValue(); + + // check if parent is an archive + boolean isParentArchive = ArchiveHandlerManager.getInstance().isRegisteredArchive(parentPath); + + int lastSlash = parentPath.lastIndexOf(slash); + + if (lastSlash > 0) { + + String parentName = parentPath.substring(lastSlash + 1, parentPath.length()); + String parentRoot = parentPath.substring(0, lastSlash); + + if ((_currentContext.getParentRemoteFile() == null) || !_currentContext.getParentRemoteFile().getAbsolutePath().equals(parentPath)) { + + // change the current context + DataElement parentElement = null; + + if (ArchiveHandlerManager.isVirtual(parentRoot)) { + parentElement = result.getDataStore().createObject(null, IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR, parentName); + } + else { + + if (!isParentArchive) { + parentElement = result.getDataStore().createObject(null, IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR, parentName); + } + else { + parentElement = result.getDataStore().createObject(null, IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR, parentName); + } + } + + parentElement.setAttribute(DE.A_VALUE, parentRoot); + + try + { + IRemoteFile remoteFileParent = _subsys.getRemoteFileObject(parentPath); + //_factory.createRemoteFile(_defaultContext, parentElement, false, true); + // DKM - need to see why we're not checking the cache first... + //((RemoteFileSubSystemImpl)_subsys).cacheRemoteFile(remoteFileParent, parentPath); + _currentContext = new RemoteFileContext(_subsys, remoteFileParent, null); + } + catch (Exception e) + { + + } + } + } + else { + _currentContext = _defaultContext; + } + + if (!_subsys.isConnected()) + { + _disconnected = true; + setDone(); + return; + } + + IRemoteFile remoteFile = null; + String remotePath = parentPath + slash + result.getName(); + if (_subsys instanceof FileServiceSubSystem) + { + remoteFile = (IRemoteFile)((FileServiceSubSystem)_subsys).getCachedRemoteFile(remotePath); + } + + if (remoteFile == null) + { + try + { + remoteFile = _subsys.getRemoteFileObject(remotePath); + //_factory.createRemoteFile(_currentContext, result, false, true); + ((RemoteFileSubSystem)_subsys).cacheRemoteFile(remoteFile, remotePath); + ((RemoteFile)remoteFile).setParentRemoteFile(_currentContext.getParentRemoteFile()); + } + catch (Exception e) + { + + } + } + + if (remoteFile != null) { + + if (result.getNestedSize() > 0) { + + boolean isWindows = _subsys.getHost().getSystemType().equals("Windows"); + char separator = isWindows ? '\\' : '/'; + List contents = new ArrayList(); + + // go through search results + for (int i = 0; i < result.getNestedSize(); i++) { + + DataElement resultElement = result.get(i); + + // search result object + DStoreSearchResult searchResult = new DStoreSearchResult(_searchConfig, remoteFile, resultElement, _searchConfig.getSearchString()); + + // set the name which should be the line + searchResult.setText(resultElement.getName()); + + String source = resultElement.getSource().replace('\\', separator).replace('/', separator); + String path = source; + String lineNumStr = null; + int colonIndex = source.indexOf(":"); + if (colonIndex > 2) + { + path = source.substring(0, colonIndex); + lineNumStr = source.substring(colonIndex); + } + + int lineNum = 0; + + if (lineNumStr != null && lineNumStr.length() > 0) { + Integer lineLocation = new Integer(lineNumStr); + lineNum = lineLocation.intValue(); + } + + // set the line number + searchResult.setLine(lineNum); + + // set the index + searchResult.setIndex(i); + + // add the search result + contents.add(searchResult); + } + + // set search results to contents of remote file + ((DStoreFile)remoteFile).setContents(RemoteSearchResultsContentsType.getInstance(), _searchConfig.getSearchString().toString(), contents.toArray()); + } + + // add remote file to search result set + _searchConfig.addResult(remoteFile); + } + } + } + + if (totalSize >= MAX_RESULTS) { + RemoteSearchResult warning = new RemoteSearchResult(_searchConfig, _searchConfig, _searchConfig.getSearchString()); + warning.setLine(0); + warning.setText(SystemPlugin.getPluginMessage(ISystemMessages.MSG_LIST_CANCELLED).getLevelOneText()); + _searchConfig.addResult(warning); + } + + registry.fireEvent(new SystemResourceChangeEvent(_searchConfig, ISystemResourceChangeEvents.EVENT_REFRESH, null)); + } + } + + /** + * Indicates search is done. + */ + public void setDone() { + + _status.getDataStore().getDomainNotifier().removeDomainListener(this); + + _subsys.getConnectorService().removeCommunicationsListener(this); + + if (!_disconnected) { + handleSearchResults(); + + if (_cancelled) { + _searchConfig.setStatus(IRemoteSearchConstants.CANCELLED); + } + else { + _searchConfig.setStatus(IRemoteSearchConstants.FINISHED); + } + } + else { + _searchConfig.setStatusObject(null); + _searchConfig.setStatus(IRemoteSearchConstants.DISCONNECTED); + } + + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + registry.fireEvent(new SystemResourceChangeEvent(_searchConfig, ISystemResourceChangeEvents.EVENT_SEARCH_FINISHED, null)); + } + + /** + * @see IDomainListener#getShell() + */ + public Shell getShell() { + return _shell; + } + + /** + * + */ + public boolean wasCancelled() { + return _cancelled; + } + + /** + * @see ICommunicationsListener#communicationsStateChange(CommunicationsEvent) + */ + public void communicationsStateChange(CommunicationsEvent e) { + + int connState = e.getState(); + + if (connState == CommunicationsEvent.CONNECTION_ERROR || connState == CommunicationsEvent.AFTER_DISCONNECT) { + _disconnected = true; + + Display.getDefault().asyncExec(new Runnable() { + + public void run() { + setDone(); + } + }); + } + } + + /** + * @see ICommunicationsListener#isPassiveCommunicationsListener() + */ + public boolean isPassiveCommunicationsListener() { + return true; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/StatusChangeListener.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/StatusChangeListener.java new file mode 100644 index 00000000000..86df66456f9 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/StatusChangeListener.java @@ -0,0 +1,482 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.dstore.old; + +import java.util.List; +import java.util.Vector; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.connectorservice.dstore.util.ICommunicationsDiagnostic; +import org.eclipse.rse.connectorservice.dstore.util.ICommunicationsDiagnosticFactory; +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.subsystems.CommunicationsEvent; +import org.eclipse.rse.core.subsystems.ICommunicationsListener; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.extra.internal.extra.DomainEvent; +import org.eclipse.dstore.extra.internal.extra.IDomainListener; + +/* + * Utility class for determining when a DataStore command is complete via the status. + */ +public class StatusChangeListener implements IDomainListener, ICommunicationsListener +{ + + + protected DataElement target; + protected Shell shell; + protected IProgressMonitor monitor; + protected IConnectorService system; + + protected boolean _networkDown = false; + protected boolean done = false; + protected boolean cancelled = false; + + protected Vector historyOfTargets; + + protected class FindShell implements Runnable { + private Shell shell; + + /** + * @see Runnable#run() + */ + public void run() { + try { + Shell[] shells = Display.getCurrent().getShells(); + for (int loop = 0; loop < shells.length && shell == null; loop++) { + if (shells[loop].isEnabled()) { + shell = shells[loop]; + } + } + } catch (Exception e) { + SystemBasePlugin.logError("StatusChangeListener.FindShell exception: ", e); + } + } + } + + + /** + * Construct a StatusChangeListener + * + * @param shell A valid Shell object + * + * @param monitor A progress monitor if you want this object to check if + * the user presses cancel while waiting for the status object + * to be updated + * + * @param target The status DataElement for which you wish to wait for an update + */ + public StatusChangeListener(Shell shell, IProgressMonitor monitor, IConnectorService system, DataElement target) { + this.shell = shell; + this.monitor = monitor; + this.target = target; + this.system = system; + system.addCommunicationsListener(this); + historyOfTargets = new Vector(); + } + + +// public StatusChangeListener(Shell shell, IProgressMonitor monitor, DataElement target) { +// this.shell = shell; +// this.monitor = monitor; +// this.target = target; +// historyOfTargets = new Vector(); +// } + + + public StatusChangeListener(Shell shell, IProgressMonitor monitor, IConnectorService system) { + this(shell, monitor, system, null); + } + + public StatusChangeListener(IConnectorService system) { + this (null, null, system, null); + } + +// public StatusChangeListener(Shell shell, DataElement target) { +// this(shell, null, target); +// } + + + /** + * + */ + public void setStatus(DataElement p_target) + { + this.target = p_target; + + for (int i = 0; i < historyOfTargets.size(); i++) + { + if (target == historyOfTargets.elementAt(i)) + { + setDone( true ); + historyOfTargets.clear(); + return; + } + } + + historyOfTargets.clear(); + } + + /** + * + */ + public DataElement getStatus() + { + return target; + } + + /** + * @see IDomainListener#listeningTo(DomainEvent) + */ + public boolean listeningTo(DomainEvent event) { + if (target == null) + { + return true; + } + + if (target == event.getParent()) { + return true; + } + + return false; + } + + + /** + * @see IDomainListener#domainChanged(DomainEvent) + */ + public void domainChanged(DomainEvent event) { + if (target == null) + { + if (historyOfTargets.size() < 1000) + { + historyOfTargets.addElement(event.getParent()); + } + } + + if (target == event.getParent()) + { + boolean isStatusDone = determineStatusDone(); + + if (isStatusDone) + { + setDone( true ); + } + } + } + + + /** + * setDone(boolean) + */ + public void setDone(boolean done) + { + this.done = done; + } + + /** + * @see IDomainListener#getShell() + */ + public Shell getShell() { + // dy: DomainNotifier (which calls this method) requires the shell not be disposed + //if (shell == null) { + if (shell == null || shell.isDisposed()) + { + FindShell findShell = new FindShell(); + Display.getDefault().syncExec(findShell); + shell = findShell.shell; + } + return shell; + } + + /** + * + */ + public boolean wasCancelled() { + return cancelled; + } + + /** + * @see ICommunicationsListener#communicationsStateChange(CommunicationsEvent) + */ + public void communicationsStateChange(CommunicationsEvent e) { + if (e.getState() == CommunicationsEvent.CONNECTION_ERROR) { + _networkDown = true; + } + } + + + /** + * Wait for the the status DataElement to be refreshed + * + * @param + * ICommunicationsDiagnosticFactory factory : for creating system specific diagnostic class instance + * Int wait : threshold for starting diagnostic. Default is 60 seconds; a zero means to use the default. + * -1 means to force a timeout; mainly for testing purpose. + * + * @return The status DataElement after it has been updated, or the user + * has pressed cancel + * + * @throws InterruptedException if the thread was interrupted. + */ + public DataElement waitForUpdate() throws InterruptedException + { + return waitForUpdate(null, 0); //No diagnostic + } + + public DataElement waitForUpdate(ICommunicationsDiagnosticFactory factory) throws InterruptedException + { + return waitForUpdate(factory, 0); //Use the default wait threshold + } + + public DataElement waitForUpdate(ICommunicationsDiagnosticFactory factory, int wait) throws InterruptedException + { + boolean statusDone = determineStatusDone(); + if (statusDone) + { + setDone(true); + } + else + { + Display display = Display.getCurrent(); + + // Prevent infinite looping by introducing a threshold for wait + int WaitThreshold = 600; //default. sleep(100ms) for 600 times + if ( wait > 0 ) + WaitThreshold = wait*10; // 1 second means 10 sleep(100ms) + else if ( wait == -1 ) // force a diagnostic + WaitThreshold = -1; + + ICommunicationsDiagnostic diagnostic = null; + boolean diagnosticStarted = false; //Flag to indicate diagnostic started + + if (display != null) { + if (shell == null || shell.isDisposed()) { + shell = Display.getDefault().getActiveShell(); + } + // Current thread is UI thread + while (!done && !cancelled) { + // Process everything on event queue + while (display.readAndDispatch()) { + } + + if ((monitor != null) && (monitor.isCanceled())) { + cancelled = true; + target.getDataStore().getDomainNotifier().removeDomainListener(this); + system.removeCommunicationsListener(this); + throw new InterruptedException(); + } + + statusDone = determineStatusDone(); + + if (statusDone) + { + setDone(true); + } + else + { + Thread.sleep(100); + + if (factory != null) { + + if (WaitThreshold > 0) // update timer count if + // threshold not reached + --WaitThreshold; // decrement the timer count + + //Check if timeout threshold reached @01 + if ((WaitThreshold < 1) && !diagnosticStarted && (diagnostic == null)) + { + diagnosticStarted = true; + diagnostic = whatIsGoingOn(factory, false); + } + else + { + if (diagnosticStarted && (diagnostic != null)) + { + + if (ICommunicationsDiagnostic.CANCEL_WAIT_REQUESTED == diagnostic.diagnosticStatus()) { + cancelled = true; + SystemBasePlugin.logError("StatusChangeListener.waitForUpdate cancelled by user."); + } + } + } + } + else if (_networkDown) + { + target.getDataStore().getDomainNotifier().removeDomainListener(this); + system.removeCommunicationsListener(this); + throw new InterruptedException(); + } + } + } + + } else { + // Current thread is not UI thread + while (!done && !cancelled) + { + + if ((monitor != null) && (monitor.isCanceled())) + { + cancelled = true; + target.getDataStore().getDomainNotifier().removeDomainListener(this); + system.removeCommunicationsListener(this); + throw new InterruptedException(); + } + + statusDone = determineStatusDone(); + + if (statusDone) + { + setDone(true); + } + else { + Thread.sleep(100); + + if (factory != null) { + + if (WaitThreshold > 0) // update timer count if + // threshold not reached + --WaitThreshold; // decrement the timer count + + //Check if timeout threshold reached @01 + if ((WaitThreshold < 1) && !diagnosticStarted && (diagnostic == null)) + { + diagnosticStarted = true; + diagnostic = whatIsGoingOn(factory, false); + } + else + { + if (diagnosticStarted && (diagnostic != null)) + { + if (ICommunicationsDiagnostic.CANCEL_WAIT_REQUESTED == diagnostic.diagnosticStatus()) + { + cancelled = true; + SystemBasePlugin.logError("StatusChangeListener.waitForUpdate cancelled by user."); + } + } + } + } + else if (_networkDown) + { + target.getDataStore().getDomainNotifier().removeDomainListener(this); + system.removeCommunicationsListener(this); + throw new InterruptedException(); + } + } + } + } + } + + // Reset done so we can detect the next event if waitForUpdate + // is called again + done = false; + system.removeCommunicationsListener(this); + + return target; + } + + /** + * Determines whether the status is done. + * @return true if status done, false otherwise. + */ + protected boolean determineStatusDone() { + return getStatus().getAttribute(DE.A_VALUE).equals("done") || getStatus().getAttribute(DE.A_NAME).equals("done"); + } + + /** + * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#isPassiveCommunicationsListener() + */ + public boolean isPassiveCommunicationsListener() { + return false; + } + + /** + * Start diagnostic + * + * @param Class diagnostic is the an implementation of ICommunicationsDiagnostic + * @param boolean quiet is the flag to indicate if user should be prompted + * - true for no prompt + * @return ICommunciationsDiagnostic class instance + */ + public ICommunicationsDiagnostic whatIsGoingOn(ICommunicationsDiagnosticFactory factory, boolean quiet ) throws InterruptedException //@01 + { + if (target == null) + return null; + + ICommunicationsDiagnostic d = null; + DataStore ds = null; + try { + String name = getStatus().getName(); /* Get the current element status name: started/working/done */ + /* Log the current status */ + SystemBasePlugin.logError("StatusChangeListener."+name+": " + "Communications Diagnostic started"); + SystemBasePlugin.logError("StatusChangeListener."+name + + ": done = " + done + + "; cancelled = " + cancelled + + "; _networkDown = " + _networkDown ); + + ds = target.getDataStore(); + /* Log the status in DataStore */ + SystemBasePlugin.logError("StatusChangeListener."+name+"(DataStore): " + " isConnected = " + ds.isConnected() + "; isWaiting = " + ds.isWaiting(target)); + + /*Log all nested DataElement's in target's parent*/ + List deList = target.getParent().getNestedData(); + if (deList != null && !deList.isEmpty() ) { + int num = deList.size(); + for ( int i = 0; i < num; i++) + { + DataElement child = (DataElement) deList.get(i); + if (child != null) { + SystemBasePlugin.logError("StatusChangeListener."+name+".child"+i+"(DataElement): " + child.toString()); + DataElement descriptor = child.getDescriptor(); + if (descriptor != null) + SystemBasePlugin.logError("StatusChangeListener."+name+".child"+i+"(Descriptor): " + descriptor.toString()); + } + } + } + //Spawn off a diagnostic to check more stuff + if (factory != null) { + d = factory.createInstance(); + + //Initialize the diagnostic instance + //Set diagnostic id(name), server name(ds.getName()), this connection(system) + d.setUp(name, quiet, ds.getName(),system, null ,null, null); + + new Thread(d).start(); + } + + } + catch (Exception e) + { + SystemBasePlugin.logError("StatusChangeListener.ICommunicationsDiagnostic exception: ", e); + } + + return d; // return the created diagnostic class instance + } + + /** + * Test if the StatusChangeListener returned because the network connection to the + * remote system was broken. + */ + public boolean isNetworkDown() { + return _networkDown; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/UniversalSearchResultConfigurationFactory.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/UniversalSearchResultConfigurationFactory.java new file mode 100644 index 00000000000..298670160f4 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/UniversalSearchResultConfigurationFactory.java @@ -0,0 +1,58 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.dstore.old; + +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.services.search.IHostSearchResultConfigurationFactory; +import org.eclipse.rse.services.search.IHostSearchResultSet; + +/** + * Singleton class that is a factory for creating search result configurations. + */ +public class UniversalSearchResultConfigurationFactory implements IHostSearchResultConfigurationFactory { + + private static UniversalSearchResultConfigurationFactory instance; + + /** + * Constructor for creating a search configuration factory. + */ + private UniversalSearchResultConfigurationFactory() { + } + + /** + * Gets the singleton instance of the factory. + * @return the singleton instance of the factory. + */ + public static UniversalSearchResultConfigurationFactory getInstance() { + + if (instance == null) { + instance = new UniversalSearchResultConfigurationFactory(); + } + + return instance; + } + + /** + * Creates a config and adds it to the result set. + */ + public IHostSearchResultConfiguration createSearchConfiguration(IHostSearchResultSet resultSet, Object searchTarget, SystemSearchString searchString) { + IHostSearchResultConfiguration config = new UniversalSearchResultConfigurationImpl(resultSet, searchTarget, searchString); + resultSet.addSearchConfiguration(config); + return config; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/UniversalSearchResultConfigurationImpl.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/UniversalSearchResultConfigurationImpl.java new file mode 100644 index 00000000000..e964cec0dd2 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/old/UniversalSearchResultConfigurationImpl.java @@ -0,0 +1,63 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.dstore.old; + +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.search.IHostSearchResultSet; +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.RemoteSearchResultConfiguration; + +import org.eclipse.dstore.core.model.DataElement; + +public class UniversalSearchResultConfigurationImpl extends RemoteSearchResultConfiguration { + + protected DataElement statusObject; + + /** + * Constructor to create a universal search result configuration. + * @param resultSet the parent result set. + * @param searchObject the search target. + * @param string the search string. + */ + public UniversalSearchResultConfigurationImpl(IHostSearchResultSet resultSet, Object searchObject, SystemSearchString string) { + super(resultSet, searchObject, string); + } + + public void setStatusObject(DataElement statusObject) { + this.statusObject = statusObject; + } + + public DataElement getStatusObject() { + return statusObject; + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#cancel() + */ + public void cancel() { + + if (getStatus() != RUNNING) { + super.cancel(); + return; + } + + IRemoteFile remoteFile = (IRemoteFile)getSearchTarget(); + IRemoteFileSubSystem subsys = remoteFile.getParentRemoteFileSubSystem(); + subsys.cancelSearch(this); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreFileSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreFileSubSystemConfiguration.java new file mode 100644 index 00000000000..d1760a541f1 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreFileSubSystemConfiguration.java @@ -0,0 +1,164 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.dstore.subsystem; + +import org.eclipse.rse.connectorservice.dstore.DStoreConnectorService; +import org.eclipse.rse.connectorservice.dstore.DStoreConnectorServiceManager; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.internal.subsystems.files.core.ILanguageUtilityFactory; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.dstore.IDStoreService; +import org.eclipse.rse.services.dstore.files.DStoreFileService; +import org.eclipse.rse.services.dstore.search.DStoreSearchService; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.services.search.IHostSearchResultSet; +import org.eclipse.rse.services.search.ISearchService; +import org.eclipse.rse.subsystems.files.core.model.SystemFileTransferModeRegistry; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystemConfiguration; +import org.eclipse.rse.subsystems.files.core.subsystems.IHostFileToRemoteFileAdapter; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.subsystems.files.dstore.model.DStoreFileAdapter; + + +/** + * Provides a factory for generating instances of the class + * SampleFileSubSystem. + */ +public class DStoreFileSubSystemConfiguration extends FileServiceSubSystemConfiguration +{ + protected boolean _isWindows; + protected IHostFileToRemoteFileAdapter _hostFileAdapter; + public DStoreFileSubSystemConfiguration() + { + super(); + _isWindows = false; + setIsUnixStyle(!_isWindows); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSubSystemConfiguration#isFactoryFor(java.lang.Class) + */ + public boolean isFactoryFor(Class subSystemType) + { + boolean isFor = FileServiceSubSystem.class.equals(subSystemType); + return isFor; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystemConfiguration#supportsArchiveManagement() + */ + public boolean supportsArchiveManagement() + { + return true; + } + + /** + * Instantiate and return an instance of OUR subystem. + * Do not populate it yet though! + * @see org.eclipse.rse.core.subsystems.impl.SubSystemFactoryImpl#createSubSystemInternal(Host) + */ + public ISubSystem createSubSystemInternal(IHost host) + { + DStoreConnectorService connectorService = (DStoreConnectorService)getConnectorService(host); + ISubSystem subsys = new FileServiceSubSystem(host, connectorService, getFileService(host), getHostFileAdapter(), getSearchService(host)); + return subsys; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSubSystemConfiguration#supportsFileTypes() + */ + public boolean supportsFileTypes() + { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSubSystemConfiguration#supportsSearch() + */ + public boolean supportsSearch() + { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSubSystemConfiguration#supportsEnvironmentVariablesPropertyPage() + */ + public boolean supportsEnvironmentVariablesPropertyPage() + { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSubSystemConfiguration#supportsFilters() + */ + public boolean supportsFilters() + { + return true; + } + + public void setConnectorService(IHost host, IConnectorService connectorService) + { + DStoreConnectorServiceManager.getTheUniversalSystemManager().setConnectorService(host, getServiceImplType(), connectorService); + } + + public IConnectorService getConnectorService(IHost host) + { + return DStoreConnectorServiceManager.getTheUniversalSystemManager().getConnectorService(host, getServiceImplType()); + } + + public IFileService createFileService(IHost host) + { + DStoreConnectorService connectorService = (DStoreConnectorService)getConnectorService(host); + return new DStoreFileService(connectorService, SystemFileTransferModeRegistry.getDefault()); + } + + public ISearchService createSearchService(IHost host) + { + DStoreConnectorService connectorService = (DStoreConnectorService)getConnectorService(host); + return new DStoreSearchService(connectorService); + } + + public IHostFileToRemoteFileAdapter getHostFileAdapter() + { + if (_hostFileAdapter == null) + { + _hostFileAdapter = new DStoreFileAdapter(); + } + return _hostFileAdapter; + } + + public IHostSearchResultConfiguration createSearchConfiguration(IHost host, IHostSearchResultSet resultSet, Object searchTarget, SystemSearchString searchString) + { + DStoreFileSubSystemSearchResultConfiguration config = new DStoreFileSubSystemSearchResultConfiguration(resultSet, searchTarget, searchString, getSearchService(host), getHostFileAdapter()); + resultSet.addSearchConfiguration(config); + return config; + } + + public ILanguageUtilityFactory getLanguageUtilityFactory(IRemoteFileSubSystem ss) + { + return DStoreLanguageUtilityFactory.getInstance(ss); + } + + public Class getServiceImplType() + { + return IDStoreService.class; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreFileSubSystemSearchResultConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreFileSubSystemSearchResultConfiguration.java new file mode 100644 index 00000000000..04fa8b43840 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreFileSubSystemSearchResultConfiguration.java @@ -0,0 +1,143 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.dstore.subsystem; + +import java.util.List; + +import org.eclipse.rse.core.subsystems.RemoteChildrenContentsType; +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.dstore.search.DStoreSearchResultConfiguration; +import org.eclipse.rse.services.search.IHostSearchResult; +import org.eclipse.rse.services.search.IHostSearchResultSet; +import org.eclipse.rse.services.search.ISearchService; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.OutputRefresh; +import org.eclipse.rse.subsystems.files.core.subsystems.IHostFileToRemoteFileAdapter; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteSearchResultsContentsType; +import org.eclipse.rse.subsystems.files.dstore.model.DStoreSearchResult; +import org.eclipse.swt.widgets.Display; + +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.extra.internal.extra.DomainEvent; + +public class DStoreFileSubSystemSearchResultConfiguration extends DStoreSearchResultConfiguration +{ + private FileServiceSubSystem _fileSubSystem; + private IRemoteFile _searchObject; + + public DStoreFileSubSystemSearchResultConfiguration(IHostSearchResultSet set, Object searchObject, SystemSearchString searchString, ISearchService searchService, IHostFileToRemoteFileAdapter fileAdapter) + { + super(set, searchObject, searchString, searchService); + _searchObject = (IRemoteFile)searchObject; + _fileSubSystem = (FileServiceSubSystem)_searchObject.getParentRemoteFileSubSystem(); + } + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#getResultsSize() + */ + public int getResultsSize() + { + DataElement status = getStatusObject(); + if (status != null) + { + return getStatusObject().getNestedSize(); + } + else + { + return 0; + } + } + + public Object[] getResults() + { + List results = getStatusObject().getNestedData(); + if (results != null) + { + IRemoteFile[] convertedResults = new IRemoteFile[results.size()]; + for (int i = 0; i < results.size(); i++) + { + DataElement fileNode = (DataElement)results.get(i); + if (fileNode != null) + { + IRemoteFile parentRemoteFile = null; + try + { + parentRemoteFile = _fileSubSystem.getRemoteFileObject(fileNode.getValue()); + if (!parentRemoteFile.hasContents(RemoteChildrenContentsType.getInstance())) + { + // query all files to save time (so we can retrieve cached files + _fileSubSystem.listFiles(parentRemoteFile); + } + + String path = fileNode.getValue() + "/" + fileNode.getName(); + IRemoteFile remoteFile = _fileSubSystem.getRemoteFileObject(path); + + List contained = fileNode.getNestedData(); + if (contained != null) + { + IHostSearchResult[] searchResults = new IHostSearchResult[contained.size()]; + // reset the parent of search results to the remote file + for (int c = 0; c < contained.size(); c++) + { + searchResults[c] = new DStoreSearchResult(this, remoteFile, (DataElement)contained.get(c), getSearchString()); + } + remoteFile.setContents(RemoteSearchResultsContentsType.getInstance(), getSearchString().getTextString(), searchResults); + } + convertedResults[i] = remoteFile; + } + catch (Exception e) + { + + } + } + } + return convertedResults; + } + else + { + return new IRemoteFile[0]; + } + + } + + public Object getSearchTarget() + { + try + { + return _fileSubSystem.getFileService().getFile(null, _searchObject.getParentPath(), _searchObject.getName()); + } + catch (Exception e) + { + + } + return null; + } + + public void domainChanged(DomainEvent e) + { + if (_status.getValue().equals("done")) + { + setStatus(FINISHED); + + _status.getDataStore().getDomainNotifier().removeDomainListener(this); + } + + OutputRefresh refresh = new OutputRefresh(this); + Display.getDefault().asyncExec(refresh); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreJavaLanguageUtility.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreJavaLanguageUtility.java new file mode 100644 index 00000000000..09fc1b22cb6 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreJavaLanguageUtility.java @@ -0,0 +1,79 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.dstore.subsystem; + +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.internal.subsystems.files.core.AbstractJavaLanguageUtility; +import org.eclipse.rse.services.dstore.files.DStoreHostFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.subsystems.files.dstore.model.DStoreFile; +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; + +/** + * This class is the Java language utility for universal. + */ +public class DStoreJavaLanguageUtility extends AbstractJavaLanguageUtility implements IUniversalDataStoreConstants { + + /** + * Constructor. + * @param subsystem the subsystem with which the utility is associated. + * @param language the language. + */ + public DStoreJavaLanguageUtility(IRemoteFileSubSystem subsystem, String language) { + super(subsystem, language); + } + + /** + * The given remote file must be an instance of DStoreFileImpl. + * @see org.eclipse.rse.internal.subsystems.files.core.IJavaLanguageUtility#getQualifiedClassName(org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile) + */ + public String getQualifiedClassName(IRemoteFile remoteFile) { + + DStoreFile univFile = null; + + if (remoteFile instanceof DStoreFile) { + univFile = (DStoreFile)remoteFile; + } + else { + return null; + } + + String remotePath = remoteFile.getAbsolutePath(); + DataElement deObj = ((DStoreHostFile)univFile.getHostFile()).getDataElement(); + + DataStore ds = deObj.getDataStore(); + DataElement queryCmd = ds.localDescriptorQuery(deObj.getDescriptor(), C_QUERY_QUALIFIED_CLASSNAME); + + if (queryCmd != null) { + DataElement status = ds.synchronizedCommand(queryCmd, deObj, true); + DataElement className = ds.find(status, DE.A_TYPE, TYPE_QUALIFIED_CLASSNAME, 1); + + if (className != null && !className.equals("null")) { + return className.getName(); + } + else { + SystemBasePlugin.logWarning("Qualified class name for " + remoteFile.getAbsolutePath() + " is null"); + } + } + + return null; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreLanguageUtilityFactory.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreLanguageUtilityFactory.java new file mode 100644 index 00000000000..058887219cd --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreLanguageUtilityFactory.java @@ -0,0 +1,79 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.dstore.subsystem; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.rse.internal.subsystems.files.core.AbstractLanguageUtilityFactory; +import org.eclipse.rse.internal.subsystems.files.core.ILanguageUtility; +import org.eclipse.rse.internal.subsystems.files.core.ILanguageUtilityFactory; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; + + +/** + * This is a singleton factory class associated each universal subsystem. + */ +public class DStoreLanguageUtilityFactory extends AbstractLanguageUtilityFactory { + + private static Map instances; + + /** + * Constructor. + * @param subsystem the universal subsystem with which this factory is associated. + */ + private DStoreLanguageUtilityFactory(IRemoteFileSubSystem subsystem) { + super(subsystem); + } + + /** + * Returns an instance for each subsystem. Note that there is just a singleton instance for + * each universal subsystem. + * @param subsystem the universal subsystem. + * @return the singleton instance associated with the subsystem. + */ + public static ILanguageUtilityFactory getInstance(IRemoteFileSubSystem subsystem) { + + // initialize map if needed + if (instances == null) { + instances = new HashMap(); + } + + // check if there is a factory for the subsystem already + ILanguageUtilityFactory factory = (ILanguageUtilityFactory)(instances.get(subsystem)); + + // if none, then create the factory, and store the factory for this subsystem + if (factory == null) { + factory = new DStoreLanguageUtilityFactory(subsystem); + instances.put(subsystem, factory); + } + + return factory; + } + + /** + * @see org.eclipse.rse.internal.subsystems.files.core.ILanguageUtilityFactory#getUtility(java.lang.String) + */ + public ILanguageUtility getUtility(String language) { + + if (language.equals(ILanguageUtility.LANGUAGE_JAVA)) { + return new DStoreJavaLanguageUtility(getSubSystem(), language); + } + + return null; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreWindowsFileSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreWindowsFileSubSystemConfiguration.java new file mode 100644 index 00000000000..456a9a2cf17 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/DStoreWindowsFileSubSystemConfiguration.java @@ -0,0 +1,74 @@ +package org.eclipse.rse.subsystems.files.dstore.subsystem; + +import java.util.Vector; + +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.filters.ISystemFilterPool; +import org.eclipse.rse.filters.ISystemFilterPoolManager; +import org.eclipse.rse.subsystems.files.core.SystemFileResources; +import org.eclipse.rse.subsystems.files.core.model.RemoteFileFilterString; + +public class DStoreWindowsFileSubSystemConfiguration extends DStoreFileSubSystemConfiguration +{ + + protected ISystemFilterPool createDefaultFilterPool(ISystemFilterPoolManager mgr) + { + ISystemFilterPool pool = null; + try { + // ----------------------------------------------------- + // create a pool named filters + // ----------------------------------------------------- + pool = mgr.createSystemFilterPool(getDefaultFilterPoolName(mgr.getName(), getId()), true); // true=>is deletable by user + if (pool == null) // hmmm, why would this happen? + { + SystemBasePlugin.logError("Creating default filter pool "+getDefaultFilterPoolName(mgr.getName(), getId())+" for mgr "+mgr.getName()+" failed.",null); + return null; + } + if (isUserPrivateProfile(mgr)) + { + Vector filterStrings = new Vector(); + RemoteFileFilterString defaultFilterString = new RemoteFileFilterString(this); + + filterStrings.add(defaultFilterString.toString()); + //System.out.println("creating filter..."); + String filterName = SystemFileResources.RESID_FILTER_DRIVES; + + mgr.createSystemFilter(pool, filterName, filterStrings); + + // Create 'My Home' filter for local (should apply to both _isWindows and linux clients) + filterName = SystemFileResources.RESID_FILTER_MYHOME; + RemoteFileFilterString myDocsFilterString = new RemoteFileFilterString(this); + myDocsFilterString.setPath(System.getProperty("user.home") + getSeparator()); + Vector myDocsFilterStrings = new Vector(); + myDocsFilterStrings.add(myDocsFilterString.toString()); + mgr.createSystemFilter(pool, filterName, myDocsFilterStrings); + + //System.out.println("filter created"); + // ----------------------------------------------------- + // add a default named filter for integrated file system + // ----------------------------------------------------- + //filterStrings = new Vector(); + //filterStrings.add(new AS400IFSFilterString().toString()); + //mgr.createSystemFilter(pool,rb.getString(IAS400Constants.RESID_IFS_LIST),filterStrings); + } + } + catch (Exception exc) + { + SystemBasePlugin.logError("Error creating default filter pool",exc); + } + return pool; + } + + public String getSeparator() + { + return "\\"; + } + + public char getSeparatorChar() + { + return '\\'; + } + + + +} diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/RemoteFilePropertyChangeListener.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/RemoteFilePropertyChangeListener.java new file mode 100644 index 00000000000..f7a5922f29f --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/subsystem/RemoteFilePropertyChangeListener.java @@ -0,0 +1,281 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.dstore.subsystem; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.subsystems.CommunicationsEvent; +import org.eclipse.rse.core.subsystems.ICommunicationsListener; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; +import org.eclipse.rse.model.ISystemRegistry; +import org.eclipse.rse.model.ISystemResourceChangeEvents; +import org.eclipse.rse.subsystems.files.core.SystemFileResources; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.dstore.model.DStoreFile; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.progress.UIJob; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.dstore.core.model.DE; +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.dstore.core.model.DataStore; +import org.eclipse.dstore.extra.internal.extra.DomainEvent; +import org.eclipse.dstore.extra.internal.extra.IDomainListener; + + + +public class RemoteFilePropertyChangeListener implements IDomainListener, + ICommunicationsListener +{ + + protected DataStore dataStore; + + protected FileServiceSubSystem _fileSubSystem; + + protected Shell shell; + + protected ISystemRegistry _registry; + + protected IConnectorService system; + + protected boolean _networkDown = false; + + protected class FindShell implements Runnable + { + + private Shell shell; + + /** + * @see Runnable#run() + */ + public void run() + { + try + { + Shell[] shells = Display.getCurrent().getShells(); + for (int loop = 0; loop < shells.length && shell == null; loop++) + { + if (shells[loop].isEnabled()) + { + shell = shells[loop]; + } + } + } + catch (Exception e) + { + SystemBasePlugin.logError( + "StatusChangeListener.FindShell exception: ", e); + } + } + } + + public class DecorateJob extends UIJob + { + private DStoreFile[] _files; + private DStoreFile _parentFile; + public DecorateJob(DStoreFile[] files, DStoreFile parentFile) + { + super(SystemFileResources.RESID_JOB_DECORATEFILES_NAME); + _files= files; + _parentFile = parentFile; + } + + public IStatus runInUIThread(IProgressMonitor monitor) + { + for (int i = 0; i < _files.length; i++) + { + _registry.fireEvent(new + org.eclipse.rse.model.SystemResourceChangeEvent(_files[i], + ISystemResourceChangeEvents.EVENT_ICON_CHANGE, + _parentFile)); + } + + /* + _registry.fireEvent(new + org.eclipse.rse.model.SystemResourceChangeEvent(_files, + ISystemResourceChangeEvent.EVENT_REPLACE_CHILDREN, + _parentFile)); + */ + return Status.OK_STATUS; + } + + } + + public RemoteFilePropertyChangeListener(Shell shell, IConnectorService system, + DataStore dataStore, FileServiceSubSystem fileSS) + { + this.shell = shell; + this._fileSubSystem = fileSS; + this.dataStore = dataStore; + this.system = system; + this._registry = SystemPlugin.getTheSystemRegistry(); + system.addCommunicationsListener(this); + dataStore.getDomainNotifier().addDomainListener(this); + } + + public DataStore getDataStore() + { + return dataStore; + } + + /** + * @see IDomainListener#listeningTo(DomainEvent) + */ + public boolean listeningTo(DomainEvent event) + { + + DataElement parent = (DataElement) event.getParent(); + + if (dataStore == parent.getDataStore()) + { + String dataElementType = parent.getType(); + if (dataElementType + .equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR) || + dataElementType + .equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) + ) + { + return true; + } + else + { + return false; + } + } + + return false; + } + + public void finish() + { + dataStore.getDomainNotifier().removeDomainListener(this); + } + + /** + * @see IDomainListener#domainChanged(DomainEvent) + */ + public void domainChanged(DomainEvent event) + { + DataElement parent = (DataElement)event.getParent(); + + List children = parent.getNestedData(); + if (children != null) + { + + StringBuffer parentPath = new StringBuffer(parent.getAttribute(DE.A_VALUE)); + parentPath.append(_fileSubSystem.getSeparatorChar()); + parentPath.append(parent.getName()); + DStoreFile parentFile = (DStoreFile) _fileSubSystem.getCachedRemoteFile(parentPath.toString()); + + boolean refreshParent = false; + List toUpdate = new ArrayList(); + for (int i = 0; i < children.size(); i++) + { + + DataElement subject = (DataElement) children.get(i); + String type = subject.getType(); + if (type + .equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) || + type.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR)) + + { + StringBuffer path = new StringBuffer(subject.getAttribute(DE.A_VALUE)); + path.append(_fileSubSystem.getSeparatorChar()); + path.append(subject.getName()); + + + // find cached copy + try + { + DStoreFile updated = (DStoreFile) _fileSubSystem.getCachedRemoteFile(path.toString()); + + if (updated != null) + { + String classification = updated.getClassification(); + if (!classification.equals("file") && !classification.equals("directory")) + { + refreshParent = true; + toUpdate.add(updated); + } + + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + } + + if (refreshParent) + { + + DecorateJob job = new DecorateJob((DStoreFile[])toUpdate.toArray(new DStoreFile[toUpdate.size()]), parentFile); + job.schedule(); + } + } + + } + + /** + * @see IDomainListener#getShell() + */ + public Shell getShell() + { + // dy: DomainNotifier (which calls this method) requires the shell not + // be disposed + //if (shell == null) { + if (shell == null || shell.isDisposed()) + { + FindShell findShell = new FindShell(); + Display.getDefault().syncExec(findShell); + shell = findShell.shell; + } + return shell; + } + + /** + * @see ICommunicationsListener#communicationsStateChange(CommunicationsEvent) + */ + public void communicationsStateChange(CommunicationsEvent e) + { + if (e.getState() == CommunicationsEvent.CONNECTION_ERROR) + { + _networkDown = true; + } + else if (e.getState() == CommunicationsEvent.BEFORE_DISCONNECT) + { + finish(); + } + } + + /** + * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#isPassiveCommunicationsListener() + */ + public boolean isPassiveCommunicationsListener() + { + return false; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/.classpath b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/.classpath new file mode 100644 index 00000000000..751c8f2e504 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/.cvsignore b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/.cvsignore new file mode 100644 index 00000000000..ba077a4031a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/.project b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/.project new file mode 100644 index 00000000000..88cd944a147 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/.project @@ -0,0 +1,28 @@ + + + org.eclipse.rse.subsystems.files.ftp + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..2928c6be628 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin.name +Bundle-SymbolicName: org.eclipse.rse.subsystems.files.ftp;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.rse.subsystems.files.ftp.Activator +Bundle-Vendor: Eclipse.org +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.rse.services, + org.eclipse.rse.services.files.ftp, + org.eclipse.rse.files.ui, + org.eclipse.rse.subsystems.files.core, + org.eclipse.rse.ui +Eclipse-LazyStart: true +Export-Package: org.eclipse.rse.subsystems.files.ftp, + org.eclipse.rse.subsystems.files.ftp.connectorservice, + org.eclipse.rse.subsystems.files.ftp.model +Bundle-ClassPath: filesFTP.jar diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/about.html b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/about.html new file mode 100644 index 00000000000..6f6b96c4c87 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/about.html @@ -0,0 +1,22 @@ + + + +About + + + +

    About This Content

    + +

    February 24, 2005

    +

    License

    + +

    The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

    + +

    If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content.

    + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/build.properties b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/build.properties new file mode 100644 index 00000000000..76cca47f060 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/build.properties @@ -0,0 +1,14 @@ +bin.includes = META-INF/,\ + about.html,\ + icons/,\ + plugin.properties,\ + plugin.xml,\ + filesFTP.jar +src.includes = META-INF/,\ + about.html,\ + plugin.properties,\ + plugin.xml,\ + icons/ +jars.compile.order = filesFTP.jar +source.filesFTP.jar = src/ +output.filesFTP.jar = bin/ diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/icons/full/obj16/systemfiles_obj.gif b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/icons/full/obj16/systemfiles_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..874c992621585ee9cc49f4cf8c1a93bab77786d0 GIT binary patch literal 157 zcmZ?wbhEHb6krfw*v!Dt(7-T%zWx9I^W)>~>+9q9@1KAF{{H*>?f>78{|_SP|NsBL zp`jr@J|4(mU|>-E$->CMz{j8iWCKkQU|?YJy5K49FvFr@m`u<+ITm2x2aoV%!x%37q{q( IFfv#J0B(aoLI3~& literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/icons/full/obj16/systemfileslive_obj.gif b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/icons/full/obj16/systemfileslive_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..885b8a69e39be4762e9314498547527837cba710 GIT binary patch literal 224 zcmZ?wbhEHb6krfwIKsfd@SlO9fx$lBzM+9({(SrY|L4cY+t=5}@83WF{{8*;_uK!! zAOGu4d`oree-L~A|Ns9R8XDr`!8T q?^Yp8(X^KE-sYOKetWi;bkx31ef>U4kfWKSAyhE0vnEQB!5RQjK2eqc literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/plugin.properties b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/plugin.properties new file mode 100644 index 00000000000..84b4a821067 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/plugin.properties @@ -0,0 +1,20 @@ +################################################################################ +# Copyright (c) 2006 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: +# {Name} (company) - description of contribution. +################################################################################ + +plugin.name = RSE FTP Files + +Files=Files +FilesDescription=This configuration allows you to work with files on local or remote systems using the FTP protocol. \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/plugin.xml b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/plugin.xml new file mode 100644 index 00000000000..5b0e5e3f1d6 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/plugin.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/Activator.java b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/Activator.java new file mode 100644 index 00000000000..48d43883c51 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/Activator.java @@ -0,0 +1,73 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.ftp; + +import org.eclipse.ui.plugin.*; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class Activator extends AbstractUIPlugin { + + //The shared instance. + private static Activator plugin; + + /** + * The constructor. + */ + public Activator() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + +// make sure files.ui is activated + org.eclipse.rse.files.ui.Activator.getDefault(); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static Activator getDefault() { + 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("com.ibm.rse.subsystems.files.ftp", path); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/FTPFileSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/FTPFileSubSystemConfiguration.java new file mode 100644 index 00000000000..d2525c7a5ec --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/FTPFileSubSystemConfiguration.java @@ -0,0 +1,155 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.ftp; + +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.internal.subsystems.files.core.ILanguageUtilityFactory; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.files.ftp.IFTPService; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.services.search.IHostSearchResultSet; +import org.eclipse.rse.services.search.ISearchService; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystemConfiguration; +import org.eclipse.rse.subsystems.files.core.subsystems.IHostFileToRemoteFileAdapter; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.subsystems.files.ftp.connectorservice.FTPConnectorService; +import org.eclipse.rse.subsystems.files.ftp.connectorservice.FTPConnectorServiceManager; +import org.eclipse.rse.subsystems.files.ftp.model.FTPFileAdapter; + + +/** + * Provides a factory for generating instances of the class + * SampleFileSubSystem. + */ +public class FTPFileSubSystemConfiguration extends FileServiceSubSystemConfiguration +{ + protected IHostFileToRemoteFileAdapter _hostFileAdapter; + public FTPFileSubSystemConfiguration() + { + super(); + setIsUnixStyle(true); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSubSystemConfiguration#isFactoryFor(java.lang.Class) + */ + public boolean isFactoryFor(Class subSystemType) { + boolean isFor = FileServiceSubSystem.class.equals(subSystemType); + return isFor; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystemConfiguration#supportsArchiveManagement() + */ + public boolean supportsArchiveManagement() { + return false; + } + + /** + * Instantiate and return an instance of OUR subystem. + * Do not populate it yet though! + * @see org.eclipse.rse.core.subsystems.impl.SubSystemFactoryImpl#createSubSystemInternal(IHost) + */ + public ISubSystem createSubSystemInternal(IHost host) + { + FTPConnectorService connectorService = (FTPConnectorService)getConnectorService(host); + ISubSystem subsys = new FileServiceSubSystem(host, connectorService, getFileService(host), getHostFileAdapter(), getSearchService(host)); + return subsys; + } + + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSubSystemConfiguration#supportsFileTypes() + */ + public boolean supportsFileTypes() { + return false; + } + + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSubSystemConfiguration#supportsSearch() + */ + public boolean supportsSearch() { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSubSystemConfiguration#supportsEnvironmentVariablesPropertyPage() + */ + public boolean supportsEnvironmentVariablesPropertyPage() { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.files.core.subsystems.RemoteFileSubSystemConfiguration#supportsFilters() + */ + public boolean supportsFilters() { + return true; + } + + public IConnectorService getConnectorService(IHost host) + { + return FTPConnectorServiceManager.getDefault().getConnectorService(host, getServiceImplType()); + } + public void setConnectorService(IHost host, IConnectorService connectorService) + { + FTPConnectorServiceManager.getDefault().setConnectorService(host, getServiceImplType(), connectorService); + } + + + public IFileService createFileService(IHost host) + { + FTPConnectorService connectorService = (FTPConnectorService)getConnectorService(host); + return connectorService.getFileService(); + } + + public ISearchService createSearchService(IHost host) + { + // no search service supported for ftp at moment + return null; + } + + public IHostFileToRemoteFileAdapter getHostFileAdapter() + { + if (_hostFileAdapter == null) + { + _hostFileAdapter = new FTPFileAdapter(); + } + return _hostFileAdapter; + } + + public IHostSearchResultConfiguration createSearchConfiguration(IHost host, IHostSearchResultSet resultSet, Object searchTarget, SystemSearchString searchString) + { + // TODO Auto-generated method stub + return null; + } + + public ILanguageUtilityFactory getLanguageUtilityFactory(IRemoteFileSubSystem ss) + { + // TODO Auto-generated method stub + return null; + } + + public Class getServiceImplType() + { + return IFTPService.class; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/connectorservice/FTPConnectorService.java b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/connectorservice/FTPConnectorService.java new file mode 100644 index 00000000000..11eab325a0d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/connectorservice/FTPConnectorService.java @@ -0,0 +1,87 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.ftp.connectorservice; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.core.subsystems.AbstractConnectorService; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.model.SystemSignonInformation; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.files.ftp.FTPService; +import org.eclipse.rse.subsystems.files.core.SystemFileResources; + + + +public class FTPConnectorService extends AbstractConnectorService +{ + protected FTPService _ftpService; + + public FTPConnectorService(IHost host, int port) + { + super(SystemFileResources.RESID_FTP_CONNECTORSERVICE_NAME,SystemFileResources.RESID_FTP_CONNECTORSERVICE_DESCRIPTION, host, port); + _ftpService = new FTPService(); + } + + public void internalConnect(IProgressMonitor monitor) throws Exception + { + internalConnect(); + } + + private void internalConnect() throws Exception + { + SystemSignonInformation info = getPasswordInformation(); + _ftpService.setHostName(info.getHostname()); + _ftpService.setUserId(info.getUserid()); + _ftpService.setPassword(info.getPassword()); + _ftpService.connect(); + } + + public IFileService getFileService() + { + return _ftpService; + } + + public void disconnect() + { + _ftpService.disconnect(); + } + + + public boolean hasRemoteServerLauncherProperties() + { + return false; + } + + public boolean supportsRemoteServerLaunching() + { + return false; + } + + + + public boolean isConnected() + { + return (_ftpService != null && _ftpService.isConnected()); + } + + public boolean supportsServerLaunchProperties() + { + return false; + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/connectorservice/FTPConnectorServiceManager.java b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/connectorservice/FTPConnectorServiceManager.java new file mode 100644 index 00000000000..9346919c925 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/connectorservice/FTPConnectorServiceManager.java @@ -0,0 +1,110 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.ftp.connectorservice; + + +import org.eclipse.rse.core.subsystems.AbstractConnectorServiceManager; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.model.IHost; + + + +/** + * ISystem manager class. + * There should be only one of these instantiated. + * The job of this manager is to manage and return ISystem objects. + * It ensures there is only ever one per unique SystemConnection, + * so that both the file and cmd subsystems can share the same system object. + */ +public class FTPConnectorServiceManager extends AbstractConnectorServiceManager +{ + private static FTPConnectorServiceManager inst = null; + + /** + * Private constructor to ensure not instantiated this way. + * Use getDefault instead. + */ + private FTPConnectorServiceManager() + { + } + + /** + * Return singleton instance of this class + */ + public static FTPConnectorServiceManager getDefault() + { + if (inst == null) + inst = new FTPConnectorServiceManager(); + return inst; + } + + /** + * Return true if the singleton has been created. + * This saves creating it at shutdown just to test for isConnected. + */ + public static boolean isInstantiated() + { + return (inst != null); + } + + // ------------------------------------- + // ABSTRACT METHODS FROM PARENT CLASS... + // ------------------------------------- + + /** + * Return the actual ISystem object. We return an instance of UniversalSystem. + */ + public IConnectorService createConnectorService(IHost host) + { + return new FTPConnectorService(host, 22); + } + + /** + * For all subsystems in a particular SystemConnection, we need to know which + * ones are to share a single ISystem object. To do this, we need a key which + * is canonical for all subsystems in a given connection. This can be anything, + * but is typically a unique interface that all subsystems supported a shared + * ISystem object implement. + *

    + * Whatever is returned from here is used as the key into a hashtable to find the + * singleton ISystem object in getSystemObject. + */ + public Class getSubSystemCommonInterface(ISubSystem subsystem) + { + return IFTPSubSystem.class; + } + /** + * Given another subsystem, return true if that subsystem shares a single ISystem object + * with this one. You must override this to return true if you recognize that subsystem + * as one of your own. You are guaranteed the other subsystem will be from the same + * SystemConnection as this one. + *

    + * You can't assume a SystemConnection will you only have subsystems of that you created, + * so you should only return true if it implements your interface or you know it is an + * instance of your subsystem class. + *

    + * This should simply return (otherSubSystem instanceof interface) where interface is + * the same one returned from getSubSystemCommonInterface + * + * @return true if otherSubSystem instanceof IUniversalSubSystem + */ + public boolean sharesSystem(ISubSystem otherSubSystem) + { + return (otherSubSystem instanceof IFTPSubSystem); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/connectorservice/IFTPSubSystem.java b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/connectorservice/IFTPSubSystem.java new file mode 100644 index 00000000000..49bc64220e4 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/connectorservice/IFTPSubSystem.java @@ -0,0 +1,21 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.ftp.connectorservice; + +public interface IFTPSubSystem { + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/model/FTPFileAdapter.java b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/model/FTPFileAdapter.java new file mode 100644 index 00000000000..073197764b0 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/model/FTPFileAdapter.java @@ -0,0 +1,70 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.ftp.model; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.services.files.IHostFile; +import org.eclipse.rse.services.files.ftp.FTPHostFile; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.IHostFileToRemoteFileAdapter; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileContext; +import org.eclipse.rse.ui.ISystemPreferencesConstants; + + +public class FTPFileAdapter implements IHostFileToRemoteFileAdapter +{ + + public IRemoteFile[] convertToRemoteFiles(FileServiceSubSystem ss, IRemoteFileContext context, IRemoteFile parent, IHostFile[] nodes) + { + boolean showHidden = SystemPlugin.getDefault().getPreferenceStore().getBoolean(ISystemPreferencesConstants.SHOWHIDDEN); + + List results = new ArrayList(); + for (int i = 0; i < nodes.length; i++) + { + FTPHostFile node = (FTPHostFile)nodes[i]; + if (showHidden || !node.isHidden()) + { + IRemoteFile ftpFile = new FTPRemoteFile(ss, context, parent, node); + results.add(ftpFile); + ss.cacheRemoteFile(ftpFile); + } + } + return (IRemoteFile[])results.toArray(new IRemoteFile[results.size()]); + } + + public IRemoteFile convertToRemoteFile(FileServiceSubSystem ss, IRemoteFileContext context, IRemoteFile parent, String name, boolean isDirectory, boolean isRoot) + { + return null; + } + + public IRemoteFile convertToRemoteFile(FileServiceSubSystem ss, IRemoteFileContext context, IRemoteFile parent, IHostFile node) + { + IRemoteFile file = new FTPRemoteFile(ss, context, parent, (FTPHostFile)node); + ss.cacheRemoteFile(file); + return file; + } + + public IRemoteFile convertToRemoteFile(FileServiceSubSystem ss, IRemoteFileContext context, IRemoteFile parent, Object object) + { + // TODO Auto-generated method stub + return null; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/model/FTPRemoteFile.java b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/model/FTPRemoteFile.java new file mode 100644 index 00000000000..972697c8a54 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.ftp/src/org/eclipse/rse/subsystems/files/ftp/model/FTPRemoteFile.java @@ -0,0 +1,67 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.ftp.model; + + +import org.eclipse.rse.services.files.ftp.FTPHostFile; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.AbstractRemoteFile; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileContext; + + + +public class FTPRemoteFile extends AbstractRemoteFile +{ + protected FTPHostFile _ftpHostFile; + + public FTPRemoteFile(FileServiceSubSystem ss, IRemoteFileContext context, IRemoteFile parent, FTPHostFile hostFile) + { + super(ss, context, parent, hostFile); + _ftpHostFile = hostFile; + } + + public boolean isVirtual() + { + return false; + } + + public String getCanonicalPath() + { + return getAbsolutePath(); + } + + public String getClassification() + { + if (isFile()) + { + return "file"; + } + else + { + return "directory"; + } + } + + + + + + + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/.classpath b/rse/plugins/org.eclipse.rse.subsystems.files.local/.classpath new file mode 100644 index 00000000000..751c8f2e504 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.local/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/.cvsignore b/rse/plugins/org.eclipse.rse.subsystems.files.local/.cvsignore new file mode 100644 index 00000000000..ba077a4031a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.local/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/.project b/rse/plugins/org.eclipse.rse.subsystems.files.local/.project new file mode 100644 index 00000000000..34f32642dcf --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.local/.project @@ -0,0 +1,28 @@ + + + org.eclipse.rse.subsystems.files.local + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.subsystems.files.local/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..8de781141df --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.local/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin.name +Bundle-SymbolicName: org.eclipse.rse.subsystems.files.local;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.rse.subsystems.files.local.Activator +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.rse.services, + org.eclipse.rse.services.local, + org.eclipse.rse.connectorservice.local, + org.eclipse.rse.files.ui, + org.eclipse.rse.subsystems.files.core, + org.eclipse.rse.ui +Eclipse-LazyStart: true +Bundle-Vendor: Eclipse.org +Bundle-ClassPath: filesLocal.jar +Export-Package: org.eclipse.rse.subsystems.files.local, + org.eclipse.rse.subsystems.files.local.model diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/about.html b/rse/plugins/org.eclipse.rse.subsystems.files.local/about.html new file mode 100644 index 00000000000..6f6b96c4c87 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.local/about.html @@ -0,0 +1,22 @@ + + + +About + + + +

    About This Content

    + +

    February 24, 2005

    +

    License

    + +

    The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

    + +

    If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content.

    + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/build.properties b/rse/plugins/org.eclipse.rse.subsystems.files.local/build.properties new file mode 100644 index 00000000000..e844199e676 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.local/build.properties @@ -0,0 +1,14 @@ +bin.includes = META-INF/,\ + about.html,\ + icons/,\ + plugin.properties,\ + plugin.xml,\ + filesLocal.jar +src.includes = META-INF/,\ + about.html,\ + icons/,\ + plugin.properties,\ + plugin.xml +jars.compile.order = filesLocal.jar +source.filesLocal.jar = src/ +output.filesLocal.jar = bin/ diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/icons/full/obj16/systemfiles_obj.gif b/rse/plugins/org.eclipse.rse.subsystems.files.local/icons/full/obj16/systemfiles_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..874c992621585ee9cc49f4cf8c1a93bab77786d0 GIT binary patch literal 157 zcmZ?wbhEHb6krfw*v!Dt(7-T%zWx9I^W)>~>+9q9@1KAF{{H*>?f>78{|_SP|NsBL zp`jr@J|4(mU|>-E$->CMz{j8iWCKkQU|?YJy5K49FvFr@m`u<+ITm2x2aoV%!x%37q{q( IFfv#J0B(aoLI3~& literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/icons/full/obj16/systemfileslive_obj.gif b/rse/plugins/org.eclipse.rse.subsystems.files.local/icons/full/obj16/systemfileslive_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..885b8a69e39be4762e9314498547527837cba710 GIT binary patch literal 224 zcmZ?wbhEHb6krfwIKsfd@SlO9fx$lBzM+9({(SrY|L4cY+t=5}@83WF{{8*;_uK!! zAOGu4d`oree-L~A|Ns9R8XDr`!8T q?^Yp8(X^KE-sYOKetWi;bkx31ef>U4kfWKSAyhE0vnEQB!5RQjK2eqc literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/plugin.properties b/rse/plugins/org.eclipse.rse.subsystems.files.local/plugin.properties new file mode 100644 index 00000000000..fe74c42c798 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.local/plugin.properties @@ -0,0 +1,20 @@ +################################################################################ +# Copyright (c) 2006 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: +# {Name} (company) - description of contribution. +################################################################################ + +plugin.name = RSE Local Files + +Files=Local Files +FilesDescription=This configuration allows you to work with files on the local system and doesn't require any communication server to be running. \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/plugin.xml b/rse/plugins/org.eclipse.rse.subsystems.files.local/plugin.xml new file mode 100644 index 00000000000..e5855fd1842 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.local/plugin.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/Activator.java b/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/Activator.java new file mode 100644 index 00000000000..b13c93fb5f8 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/Activator.java @@ -0,0 +1,73 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.local; + +import org.eclipse.ui.plugin.*; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class Activator extends AbstractUIPlugin { + + //The shared instance. + private static Activator plugin; + + /** + * The constructor. + */ + public Activator() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + + // make sure files.ui is activated + org.eclipse.rse.files.ui.Activator.getDefault(); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static Activator getDefault() { + 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.subsystems.dstore", path); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/LocalFileSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/LocalFileSubSystemConfiguration.java new file mode 100644 index 00000000000..9b1be8b589e --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/LocalFileSubSystemConfiguration.java @@ -0,0 +1,238 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.local; + +import java.util.Vector; + +import org.eclipse.rse.connectorservice.local.LocalConnectorService; +import org.eclipse.rse.connectorservice.local.LocalConnectorServiceManager; +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.filters.ISystemFilterPool; +import org.eclipse.rse.filters.ISystemFilterPoolManager; +import org.eclipse.rse.internal.subsystems.files.core.ILanguageUtilityFactory; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.local.ILocalService; +import org.eclipse.rse.services.local.files.LocalFileService; +import org.eclipse.rse.services.local.search.LocalSearchService; +import org.eclipse.rse.services.search.IHostSearchResultConfiguration; +import org.eclipse.rse.services.search.IHostSearchResultSet; +import org.eclipse.rse.services.search.ISearchService; +import org.eclipse.rse.subsystems.files.core.SystemFileResources; +import org.eclipse.rse.subsystems.files.core.model.RemoteFileFilterString; +import org.eclipse.rse.subsystems.files.core.model.SystemFileTransferModeRegistry; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystemConfiguration; +import org.eclipse.rse.subsystems.files.core.subsystems.IHostFileToRemoteFileAdapter; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.subsystems.files.local.model.LocalFileAdapter; + + +/** + * Provides a factory for generating instances of the class + * SampleFileSubSystem. + */ +public class LocalFileSubSystemConfiguration extends FileServiceSubSystemConfiguration +{ + protected boolean _isWindows; + protected IHostFileToRemoteFileAdapter _hostFileAdapter; + public LocalFileSubSystemConfiguration() + { + super(); + String osName = System.getProperty("os.name").toLowerCase(); + + _isWindows = (osName.startsWith("windows")); + setIsUnixStyle(!_isWindows); + } + + /* (non-Javadoc) + * @see com.ibm.etools.systems.subsystems.SubSystemFactory#isFactoryFor(java.lang.Class) + */ + public boolean isFactoryFor(Class subSystemType) { + boolean isFor = FileServiceSubSystem.class.equals(subSystemType); + return isFor; + } + + /* (non-Javadoc) + * @see com.ibm.etools.systems.files.subsystems.RemoteFileSubSystemFactory#supportsArchiveManagement() + */ + public boolean supportsArchiveManagement() { + return true; + } + + /** + * Override from parent. + * Create the default filter pool when this factory is first created, and populate it with + * default filters. + *

    + * For local, what default filters we create we depends on the local operating system: + *

      + *
    • _isWindows: "Drives" listing all the local drives + *
    • Others: "Root files" listing all the contents of the root drive + *
    + */ + protected ISystemFilterPool createDefaultFilterPool(ISystemFilterPoolManager mgr) + { + //SystemPlugin.logDebugMessage(this.getClass().getName(),"in createDefaultFilterPool for remote file subsystem factory"); + ISystemFilterPool pool = null; + try { + // ----------------------------------------------------- + // create a pool named filters + // ----------------------------------------------------- + pool = mgr.createSystemFilterPool(getDefaultFilterPoolName(mgr.getName(), getId()), true); // true=>is deletable by user + if (pool == null) // hmmm, why would this happen? + { + SystemBasePlugin.logError("Creating default filter pool "+getDefaultFilterPoolName(mgr.getName(), getId())+" for mgr "+mgr.getName()+" failed.",null); + return null; + } + //System.out.println("Pool created"); + // --------------------------------------------------------------------------------------------- + // create default filters in that pool iff this is the user's private profile we are creating... + // --------------------------------------------------------------------------------------------- + if (isUserPrivateProfile(mgr)) + { + Vector filterStrings = new Vector(); + RemoteFileFilterString defaultFilterString = new RemoteFileFilterString(this); + if (!_isWindows) + defaultFilterString.setPath(getSeparator()); + filterStrings.add(defaultFilterString.toString()); + //System.out.println("creating filter..."); + String filterName = null; + if (_isWindows) + filterName = SystemFileResources.RESID_FILTER_DRIVES; + else + filterName = SystemFileResources.RESID_FILTER_ROOTFILES; + mgr.createSystemFilter(pool, filterName, filterStrings); + + // Create 'My Home' filter for local (should apply to both _isWindows and linux clients) + filterName = SystemFileResources.RESID_FILTER_MYHOME; + RemoteFileFilterString myDocsFilterString = new RemoteFileFilterString(this); + myDocsFilterString.setPath(System.getProperty("user.home") + getSeparator()); + Vector myDocsFilterStrings = new Vector(); + myDocsFilterStrings.add(myDocsFilterString.toString()); + mgr.createSystemFilter(pool, filterName, myDocsFilterStrings); + + //System.out.println("filter created"); + // ----------------------------------------------------- + // add a default named filter for integrated file system + // ----------------------------------------------------- + //filterStrings = new Vector(); + //filterStrings.add(new AS400IFSFilterString().toString()); + //mgr.createSystemFilter(pool,rb.getString(IAS400Constants.RESID_IFS_LIST),filterStrings); + } + } catch (Exception exc) + { + SystemBasePlugin.logError("Error creating default filter pool",exc); + } + return pool; + } + + /** + * Instantiate and return an instance of OUR subystem. + * Do not populate it yet though! + * @see org.eclipse.rse.core.subsystems.impl.SubSystemFactoryImpl#createSubSystemInternal(Host) + */ + public ISubSystem createSubSystemInternal(IHost host) + { + LocalConnectorService connectorService = (LocalConnectorService)getConnectorService(host); + ISubSystem subsys = new FileServiceSubSystem(host, connectorService, getFileService(host), getHostFileAdapter(), getSearchService(host)); + return subsys; + } + + /* (non-Javadoc) + * @see com.ibm.etools.systems.subsystems.SubSystemFactory#supportsFileTypes() + */ + public boolean supportsFileTypes() { + return false; + } + + + + /* (non-Javadoc) + * @see com.ibm.etools.systems.files.subsystems.RemoteFileSubSystemFactory#supportsSearch() + */ + public boolean supportsSearch() { + return true; + } + + /* (non-Javadoc) + * @see com.ibm.etools.systems.files.subsystems.RemoteFileSubSystemFactory#supportsEnvironmentVariablesPropertyPage() + */ + public boolean supportsEnvironmentVariablesPropertyPage() { + return false; + } + + /* (non-Javadoc) + * @see com.ibm.etools.systems.subsystems.SubSystemFactory#supportsFilters() + */ + public boolean supportsFilters() { + return true; + } + + public IConnectorService getConnectorService(IHost host) + { + return LocalConnectorServiceManager.getTheLocalSystemManager().getConnectorService(host, getServiceImplType()); + } + + public void setConnectorService(IHost host, IConnectorService connectorService) + { + LocalConnectorServiceManager.getTheLocalSystemManager().setConnectorService(host, getServiceImplType(), connectorService); + } + + public IFileService createFileService(IHost host) + { + return new LocalFileService(SystemFileTransferModeRegistry.getDefault()); + } + + public ISearchService createSearchService(IHost host) + { + return new LocalSearchService(); + } + + /** + * Creates a config and adds it to the result set. + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfigurationFactory#createSearchConfiguration(org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultSet, java.lang.Object, org.eclipse.rse.services.clientserver.SystemSearchString) + */ + public IHostSearchResultConfiguration createSearchConfiguration(IHost host, IHostSearchResultSet resultSet, Object searchTarget, SystemSearchString searchString) + { + IHostSearchResultConfiguration config = new LocalSearchResultConfiguration(resultSet, searchTarget, searchString, getSearchService(host)); + resultSet.addSearchConfiguration(config); + return config; + } + + public IHostFileToRemoteFileAdapter getHostFileAdapter() + { + if (_hostFileAdapter == null) + { + _hostFileAdapter = new LocalFileAdapter(); + } + return _hostFileAdapter; + } + + public ILanguageUtilityFactory getLanguageUtilityFactory(IRemoteFileSubSystem ss) + { + return LocalLanguageUtilityFactory.getInstance(ss); + } + + public Class getServiceImplType() + { + return ILocalService.class; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/LocalJavaLanguageUtility.java b/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/LocalJavaLanguageUtility.java new file mode 100644 index 00000000000..2fe2bb143b5 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/LocalJavaLanguageUtility.java @@ -0,0 +1,63 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.local; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.internal.subsystems.files.core.AbstractJavaLanguageUtility; +import org.eclipse.rse.services.clientserver.java.ClassFileUtil; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.subsystems.files.local.model.LocalFile; + +/** + * This class is the Java language utility for local. + */ +public class LocalJavaLanguageUtility extends AbstractJavaLanguageUtility { + + /** + * Constructor. + * @param subsystem the subsystem with which the utility is associated. + * @param language the language. + */ + public LocalJavaLanguageUtility(IRemoteFileSubSystem subsystem, String language) { + super(subsystem, language); + } + + /** + * The given remote file must be an instance of LocalFileImpl. + * @see com.ibm.etools.systems.subsystems.util.IJavaLanguageUtility#getQualifiedClassName(com.ibm.etools.systems.subsystems.IRemoteFile) + */ + public String getQualifiedClassName(IRemoteFile remoteFile) { + + try { + if (remoteFile instanceof LocalFile) { + File file = (File)(remoteFile.getFile()); + return ClassFileUtil.getInstance().getQualifiedClassName(file); + } + else { + return null; + } + } + catch (IOException e) { + SystemBasePlugin.logError("Error occurred trying to get qualified class name", e); + return null; + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/LocalLanguageUtilityFactory.java b/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/LocalLanguageUtilityFactory.java new file mode 100644 index 00000000000..41806b3d8b4 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/LocalLanguageUtilityFactory.java @@ -0,0 +1,78 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.local; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.rse.internal.subsystems.files.core.AbstractLanguageUtilityFactory; +import org.eclipse.rse.internal.subsystems.files.core.ILanguageUtility; +import org.eclipse.rse.internal.subsystems.files.core.ILanguageUtilityFactory; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; + +/** + * This is a singleton factory class associated each universal subsystem. + */ +public class LocalLanguageUtilityFactory extends AbstractLanguageUtilityFactory { + + private static Map instances; + + /** + * Constructor. + * @param subsystem the local subsystem with which this factory is associated. + */ + private LocalLanguageUtilityFactory(IRemoteFileSubSystem subsystem) { + super(subsystem); + } + + /** + * Returns an instance for each subsystem. Note that there is just a singleton instance for + * each local subsystem. + * @param subsystem the local subsystem. + * @return the singleton instance associated with the subsystem. + */ + public static ILanguageUtilityFactory getInstance(IRemoteFileSubSystem subsystem) { + + // initialize map if needed + if (instances == null) { + instances = new HashMap(); + } + + // check if there is a factory for the subsystem already + ILanguageUtilityFactory factory = (ILanguageUtilityFactory)(instances.get(subsystem)); + + // if none, then create the factory, and store the factory for this subsystem + if (factory == null) { + factory = new LocalLanguageUtilityFactory(subsystem); + instances.put(subsystem, factory); + } + + return factory; + } + + /** + * @see com.ibm.etools.systems.subsystems.util.ILanguageUtilityFactory#getUtility(java.lang.String) + */ + public ILanguageUtility getUtility(String language) { + + if (language.equals(ILanguageUtility.LANGUAGE_JAVA)) { + return new LocalJavaLanguageUtility(getSubSystem(), language); + } + + return null; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/LocalSearchResultConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/LocalSearchResultConfiguration.java new file mode 100644 index 00000000000..95ed8532a9b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/LocalSearchResultConfiguration.java @@ -0,0 +1,121 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.local; + +import org.eclipse.rse.services.clientserver.SystemSearchString; +import org.eclipse.rse.services.files.IHostFile; +import org.eclipse.rse.services.search.AbstractSearchResultConfiguration; +import org.eclipse.rse.services.search.IHostSearchResult; +import org.eclipse.rse.services.search.IHostSearchResultSet; +import org.eclipse.rse.services.search.ISearchService; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.IHostFileToRemoteFileAdapter; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteSearchResultsContentsType; + + +public class LocalSearchResultConfiguration extends AbstractSearchResultConfiguration +{ + protected IHostFileToRemoteFileAdapter _fileAdapter; + protected IRemoteFile _searchObject; + protected FileServiceSubSystem _fileSubSystem; + + /** + * Constructor to create a local search result configuration. + * @param resultSet the parent result set. + * @param searchObject the search target. + * @param string the search string. + */ + public LocalSearchResultConfiguration(IHostSearchResultSet resultSet, Object searchObject, SystemSearchString string, ISearchService searchService) + { + super(resultSet, searchObject, string, searchService); + if (searchObject instanceof IRemoteFile) + { + _searchObject = (IRemoteFile)searchObject; + _fileSubSystem = (FileServiceSubSystem)_searchObject.getParentRemoteFileSubSystem(); + _fileAdapter = _fileSubSystem.getHostFileToRemoteFileAdapter(); + } + } + + public Object[] getResults() + { + Object[] results = super.getResults(); + IRemoteFile[] convertedResults = new IRemoteFile[results.length]; + for (int i = 0; i < results.length; i++) + { + IHostFile fileNode = (IHostFile)results[i]; + if (fileNode != null) + { + IRemoteFile remoteFile = _fileAdapter.convertToRemoteFile(_fileSubSystem, _fileSubSystem.getContextFor(_searchObject), null, fileNode); + + Object[] contained = getContainedResults(fileNode); + + if (contained != null) + { + // reset the parent of search results to the remote file + for (int c = 0; c < contained.length; c++) + { + ((IHostSearchResult)contained[c]).setParent(remoteFile); + } + remoteFile.setContents(RemoteSearchResultsContentsType.getInstance(), getSearchString().getTextString(), contained); + } + convertedResults[i] = remoteFile; + } + } + + return convertedResults; + } + + + + + + /** + * @see org.eclipse.rse.core.subsystems.files.core.subsystems.IHostSearchResultConfiguration#cancel() + */ + public void cancel() { + + // if not running, call super + if (getStatus() != RUNNING) { + super.cancel(); + return; + } + + // cancel search + getSearchService().cancelSearch(null, this); + } + + public Object getSearchTarget() + { + try + { + return _fileSubSystem.getFileService().getFile(null, _searchObject.getParentPath(), _searchObject.getName()); + //return _searchObject.getAbsolutePath(); + } + catch (Exception e) + { + + } + return null; + } + + public FileServiceSubSystem getFileServiceSubSystem() + { + return _fileSubSystem; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/model/LocalFile.java b/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/model/LocalFile.java new file mode 100644 index 00000000000..844757252e6 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/model/LocalFile.java @@ -0,0 +1,74 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.local.model; + +import org.eclipse.rse.services.clientserver.SystemFileClassifier; +import org.eclipse.rse.services.local.files.LocalHostFile; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.AbstractRemoteFile; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileContext; + + + +public class LocalFile extends AbstractRemoteFile implements IRemoteFile +{ + protected LocalHostFile _localHostFile; + protected String _classification; + + public LocalFile(FileServiceSubSystem subSystem, IRemoteFileContext context, IRemoteFile parent, LocalHostFile hostFile) + { + super(subSystem, context, parent, hostFile); + _localHostFile = hostFile; + } + + public Object getFile() + { + return _localHostFile.getFile(); + } + + public boolean isVirtual() + { + return false; + } + + public String getCanonicalPath() + { + try + { + return _localHostFile.getFile().getCanonicalPath(); + } + catch (Exception e) + { + return ""; + } + } + + public String getClassification() { + + if (_classification == null && isFile()) + { + _classification = SystemFileClassifier.getInstance().classifyFile(getAbsolutePath()); + } + + return _classification; + } + + + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/model/LocalFileAdapter.java b/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/model/LocalFileAdapter.java new file mode 100644 index 00000000000..859a0a8a65c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/model/LocalFileAdapter.java @@ -0,0 +1,79 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.local.model; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.services.files.IHostFile; +import org.eclipse.rse.services.local.files.LocalHostFile; +import org.eclipse.rse.services.local.files.LocalVirtualHostFile; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.IHostFileToRemoteFileAdapter; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileContext; +import org.eclipse.rse.ui.ISystemPreferencesConstants; + + +public class LocalFileAdapter implements IHostFileToRemoteFileAdapter +{ + + + + public IRemoteFile[] convertToRemoteFiles(FileServiceSubSystem ss, IRemoteFileContext context, IRemoteFile parent, IHostFile[] nodes) + { + if (nodes == null) return null; + boolean showHidden = SystemPlugin.getDefault().getPreferenceStore().getBoolean(ISystemPreferencesConstants.SHOWHIDDEN); + + List results = new ArrayList(); + for (int i = 0; i < nodes.length; i++) + { + IHostFile child = nodes[i]; + if (showHidden || !child.isHidden()) + { + IRemoteFile lfile; + if (child instanceof LocalVirtualHostFile) + { + LocalVirtualHostFile node = (LocalVirtualHostFile)child; + lfile = new LocalVirtualFile(ss, context, node); + } + else + { + LocalHostFile node = (LocalHostFile)child; + lfile = new LocalFile(ss, context, parent, node); + } + results.add(lfile); + ss.cacheRemoteFile(lfile); + } + } + return (IRemoteFile[])results.toArray(new IRemoteFile[results.size()]); + + } + + + + public IRemoteFile convertToRemoteFile(FileServiceSubSystem ss, IRemoteFileContext context, IRemoteFile parent, IHostFile node) + { + IRemoteFile file = null; + if (node instanceof LocalVirtualHostFile) + file = new LocalVirtualFile(ss, context, (LocalVirtualHostFile) node); + else file = new LocalFile(ss, context, parent, (LocalHostFile)node); + ss.cacheRemoteFile(file); + return file; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/model/LocalVirtualFile.java b/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/model/LocalVirtualFile.java new file mode 100644 index 00000000000..ff00503bdf4 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.local/src/org/eclipse/rse/subsystems/files/local/model/LocalVirtualFile.java @@ -0,0 +1,188 @@ +/******************************************************************************** + * Copyright (c) 2003, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.files.local.model; + +import java.io.File; + +import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; +import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; +import org.eclipse.rse.services.local.files.LocalVirtualHostFile; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileContext; +import org.eclipse.rse.subsystems.files.core.subsystems.IVirtualRemoteFile; + + +/** + * @author mjberger + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class LocalVirtualFile extends LocalFile implements IVirtualRemoteFile +{ + + protected File _parentArchive; + protected LocalVirtualHostFile _node; + protected String _absolutePath = null; + + public LocalVirtualFile(FileServiceSubSystem ss, IRemoteFileContext context, LocalVirtualHostFile node) + { + super(ss, context, context.getParentRemoteFile(), node); + _node = node; + _parentArchive = _node.getChild().getContainingArchive(); + } + + + public String getAbsolutePath() + { + return _parentArchive.getAbsolutePath() + ArchiveHandlerManager.VIRTUAL_SEPARATOR + getVirtualFullName(); + } + + public File getParentArchive() + { + return _parentArchive; + } + + public VirtualChild getVirtualChild() + { + return _node.getChild(); + } + + public boolean isVirtual() + { + return true; + } + + public String getVirtualFullName() + { + return _node.getChild().fullName; + } + + public String getVirtualFullPath() + { + return _node.getChild().path; + } + + public String getVirtualName() + { + return _node.getChild().name; + } + + public void setVirtualFullName(String string) + { + _node.getChild().renameTo(string); + } + + public void setVirtualFullPath(String string) + { + if (string.equals("")) + { + _node.getChild().renameTo(_node.getChild().name); + } + else + { + _node.getChild().renameTo(string + "/" + _node.getChild().name); + } + } + + public void setVirtualName(String string) + { + if (_node.getChild().path.equals("")) + { + _node.getChild().renameTo(string); + } + else + { + _node.getChild().renameTo(_node.getChild().path + "/" + string); + } + } + + public File getFileWrapper() + { + return _node.getFile(); + } + + public boolean canRead() + { + return _parentArchive.canRead(); + } + + public boolean canWrite() + { + return _parentArchive.canWrite(); + } + + /* (non-Javadoc) + * @see com.ibm.etools.systems.subsystems.IRemoteFile#getComment() + */ + public String getComment() + { + return _node.getChild().getComment(); + } + + /* (non-Javadoc) + * @see com.ibm.etools.systems.subsystems.IRemoteFile#getCompressedSize() + */ + public long getCompressedSize() + { + return _node.getChild().getCompressedSize(); + } + + /* (non-Javadoc) + * @see com.ibm.etools.systems.subsystems.IRemoteFile#getCompressionMethod() + */ + public String getCompressionMethod() + { + return _node.getChild().getCompressionMethod(); + } + + /* (non-Javadoc) + * @see com.ibm.etools.systems.subsystems.IRemoteFile#getCompressionRatio() + */ + public double getCompressionRatio() + { + return _node.getChild().getCompressionRatio(); + } + + public Object getFile(String srcEncoding, boolean isText) + { + return _node.getChild().getExtractedFile(srcEncoding, isText); + } + + public String getContainingArchiveFullName() + { + return _node.getChild().getContainingArchive().getAbsolutePath(); + } + + + public long getExpandedSize() + { + return _node.getSize(); + } + + + public boolean isVirtualFile() + { + return !_node.getChild().isDirectory; + } + + + public boolean isVirtualFolder() + { + return _node.getChild().isDirectory; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/.classpath b/rse/plugins/org.eclipse.rse.subsystems.processes.core/.classpath new file mode 100644 index 00000000000..065ac06e197 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/.cvsignore b/rse/plugins/org.eclipse.rse.subsystems.processes.core/.cvsignore new file mode 100644 index 00000000000..c5e82d74585 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/.cvsignore @@ -0,0 +1 @@ +bin \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/.project b/rse/plugins/org.eclipse.rse.subsystems.processes.core/.project new file mode 100644 index 00000000000..7651403d0ce --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/.project @@ -0,0 +1,28 @@ + + + org.eclipse.rse.subsystems.processes.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.subsystems.processes.core/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..55d11d44900 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin.name +Bundle-SymbolicName: org.eclipse.rse.subsystems.processes.core;singleton:=true +Bundle-Version: 1.0.0 +Bundle-ClassPath: processes.jar +Bundle-Vendor: Eclipse.org +Bundle-Localization: plugin +Export-Package: org.eclipse.rse.subsystems.processes.core, + org.eclipse.rse.subsystems.processes.core.subsystem, + org.eclipse.rse.subsystems.processes.core.subsystem.impl, + org.eclipse.rse.subsystems.processes.servicesubsystem +art: true +Require-Bundle: org.eclipse.rse.services, + org.eclipse.core.runtime, + org.eclipse.swt, + org.eclipse.ui, + org.eclipse.rse.ui +Bundle-Activator: org.eclipse.rse.subsystems.processes.core.Activator +Eclipse-LazyStart: true diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/about.html b/rse/plugins/org.eclipse.rse.subsystems.processes.core/about.html new file mode 100644 index 00000000000..6f6b96c4c87 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/about.html @@ -0,0 +1,22 @@ + + + +About + + + +

    About This Content

    + +

    February 24, 2005

    +

    License

    + +

    The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

    + +

    If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content.

    + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/build.properties b/rse/plugins/org.eclipse.rse.subsystems.processes.core/build.properties new file mode 100644 index 00000000000..750d7fe5f92 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/build.properties @@ -0,0 +1,10 @@ +bin.includes = META-INF/,\ + about.html,\ + processes.jar,\ + plugin.properties +jars.compile.order = processes.jar +source.processes.jar = src/ +output.processes.jar = bin/ +src.includes = META-INF/,\ + about.html,\ + plugin.properties diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/plugin.properties b/rse/plugins/org.eclipse.rse.subsystems.processes.core/plugin.properties new file mode 100644 index 00000000000..a5b989a82d3 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/plugin.properties @@ -0,0 +1,12 @@ +############################################################################### +# Copyright (c) 2000, 2006 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 +############################################################################### + +plugin.name = RSE Processes Core diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/Activator.java b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/Activator.java new file mode 100644 index 00000000000..50a7cb3b763 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/Activator.java @@ -0,0 +1,68 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.core; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +public class Activator extends AbstractUIPlugin { + + //The shared instance. + private static Activator plugin; + + /** + * The constructor. + */ + public Activator() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception + { + super.start(context); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static Activator getDefault() { + 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.subsystems.processes.core", path); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/IHostProcessToRemoteProcessAdapter.java b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/IHostProcessToRemoteProcessAdapter.java new file mode 100644 index 00000000000..d210ce6ea38 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/IHostProcessToRemoteProcessAdapter.java @@ -0,0 +1,47 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.core.subsystem; + +import org.eclipse.rse.services.clientserver.processes.IHostProcess; + +/** + * An adapter for converting from IHostProcesses to IRemoteProcesses. An IHostProcess is an abstract representation of a + * process on a host machine, whereas an IRemoteProcess also contains information that is RSE specific. + * @author mjberger + * + */ +public interface IHostProcessToRemoteProcessAdapter +{ + /** + * Convert a set of IHostProcess objects to IRemoteProcess objects. + * @param context An object representing some contextual information for the processes + * @param parent The parent process object + * @param nodes The set of IHostProcess objects to convert + * @return the converted objects + */ + public IRemoteProcess[] convertToRemoteProcesses(IRemoteProcessContext context, IRemoteProcess parent, IHostProcess[] nodes); + + /** + * Convert a single IHostProcess object to an IRemoteProcess object. + * @param context An object representing some contextual information for the process + * @param parent The parent process object + * @param node The IHostProcess object to convert + * @return the converted object + */ + public IRemoteProcess convertToRemoteProcess(IRemoteProcessContext context, IRemoteProcess parent, IHostProcess node); + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/IRemoteProcess.java b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/IRemoteProcess.java new file mode 100644 index 00000000000..c635fd2e1ac --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/IRemoteProcess.java @@ -0,0 +1,96 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.core.subsystem; + + + + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.clientserver.processes.IHostProcess; +import org.eclipse.rse.services.clientserver.processes.IHostProcessFilter; + + +/** + * + * @author mjberger + * + * This interface represents a handle to a remote process object + * It differs from an IHostProcess in that it contains extra, RSE-specific + * information. + *
      + *
    • This is an interface, so there are no static methods + *
    • This are no action methods, only read methods. The action methods + * such as kill are found in the process subsystem interface. + * All remote commands/actions are funnelled through subsystems in this + * remote system framework. + *
    • Similarly, you do not construct these objects directly. Rather, there are + * factory methods in IRemoteProcessSubSystem to create them. + *
    + *

    + */ +public interface IRemoteProcess extends IHostProcess, IAdaptable +{ + + /** + * Get parent subsystem + */ + public RemoteProcessSubSystem getParentRemoteProcessSubSystem(); + + /** + * Return the connection this remote process is from. + */ + public IHost getSystemConnection(); + + /** + * Return the filter string resolved to get this object + */ + public IHostProcessFilter getFilterString(); + + /** + * Set the filter string resolved to get this object + */ + public void setFilterString(IHostProcessFilter filterString); + + /** + * Get fully qualified connection and folder name of associated object in /proc filesystem: profile.connection/path/procfolder. + * Note the separator character between the profile name and the connection name is always '.' + * Note the separator character between the connection and qualified-folder is always ':' + */ + public String getAbsolutePathPlusConnection(); + + /** + * Get the parent remote process of this process + */ + public IRemoteProcess getParentRemoteProcess(); + + /** + * Return the context associated with this remote file + */ + public IRemoteProcessContext getContext(); + + /** + * Get fully qualified name of associated object in /proc filesystem: root plus path plus pid. No connection name. + */ + public String getAbsolutePath(); + + /** + * Get the underlying object that this object wrappers, whether that is a + * DataElement or an IRemoteServerProcess, or something else is implementation specific. + */ + public Object getObject(); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/IRemoteProcessContext.java b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/IRemoteProcessContext.java new file mode 100644 index 00000000000..63e8691a53f --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/IRemoteProcessContext.java @@ -0,0 +1,76 @@ +/******************************************************************************** + * Copyright (c) 2005, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.core.subsystem; + +import org.eclipse.rse.services.clientserver.processes.IHostProcessFilter; + + +/** + * This interface represents a place to hold contextual information stored within + * each remote process object. + *

    + * We store in here information that might be the same for multiple remote process objects, + * in order to save memory. This way, we can merely hold a reference to a single object, + * which itself may have numerous pieces of information helpful when processing actions + * on a particular remote object. + */ +public interface IRemoteProcessContext +{ + + /** + * Get parent subsystem + */ + public RemoteProcessSubSystem getParentRemoteProcessSubSystem(); + + /** + * Return the parent remote process object expanded to get this object, or null if no such parent + */ + public IRemoteProcess getParentRemoteProcess(); + + /** + * Return the filter string used to resolve the list resulting in this remote object. + */ + public IHostProcessFilter getFilterString(); + + /** + * Return all the filter string objects applicable to this folder object. + */ + public IHostProcessFilter[] getAllFilterStrings(); + + /** + * Set parent subsystem + */ + public void setParentRemoteProcessSubSystem(RemoteProcessSubSystem parentSubSystem); + + /** + * Set the parent remote process object expanded to get this object, or null if no such parent + */ + public void setParentRemoteProcess(IRemoteProcess parentProcess); + + /** + * Set the filter string used to resolve the list resulting in this remote object. + */ + public void setFilterString(IHostProcessFilter filterString); + + /** + * Add an additional filter string. This is called for processes in a multi-filter string + * filter. It is called for each filter string that lists the contents of the same parent + * path, when show subprocesses is true. It is needed to support the subsequent expansion of + * this branch of the process tree, so that it can filter on all the appropriate filter strings. + */ + public void addFilterString(IHostProcessFilter additionalFilterString); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/IRemoteProcessSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/IRemoteProcessSubSystemConfiguration.java new file mode 100644 index 00000000000..7ee9fa99d50 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/IRemoteProcessSubSystemConfiguration.java @@ -0,0 +1,28 @@ +/******************************************************************************** + * Copyright (c) 2005, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.core.subsystem; + +import org.eclipse.rse.core.subsystems.ISubSystemConfiguration; + +/** + * An interface representing factories for creating RemoteProcessSubSystem objects. + * @author mjberger + * + */ +public interface IRemoteProcessSubSystemConfiguration extends ISubSystemConfiguration +{ +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/RemoteProcessSubSystem.java b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/RemoteProcessSubSystem.java new file mode 100644 index 00000000000..2d80b3b509c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/RemoteProcessSubSystem.java @@ -0,0 +1,108 @@ +/******************************************************************************** + * Copyright (c) 2005, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.core.subsystem; + + +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.clientserver.processes.IHostProcessFilter; + +/** + * The RSE subsystem for Remote Processes + * @author mjberger + * + */ +public interface RemoteProcessSubSystem extends ISubSystem +{ + + // ---------------------- + // HELPER METHODS... + // ---------------------- + + /** + * Return parent subsystem factory, cast to a RemoteProcessSubSystemFactory + */ + public IRemoteProcessSubSystemConfiguration getParentRemoteProcessSubSystemFactory(); + + /** + * Return true if names are case-sensitive. Used when doing name or type filtering + */ + public boolean isCaseSensitive(); + + // ---------------------- + // PROCESS METHODS... + // ---------------------- + + /** + * Return a list of all processes on the remote system. + * This version is called directly by users. + * @param processNameFilter filter the results according to this object + * @param context A context object that will be associated with each returned process + * @return the list of all processes running on the host machine that correspond to the filter, + * or null if there are none. + */ + public IRemoteProcess[] listAllProcesses(IHostProcessFilter processNameFilter, IRemoteProcessContext context) throws InterruptedException, SystemMessageException; + + /** + * Returns root processes + * @param context A context object that will be associated with each returned process + */ + public IRemoteProcess[] listRoots(IRemoteProcessContext context); + + /** + * Return a list of all remote child processes of the given parent process on the remote system + * @param parent The parent process whose children to list + * @param context A context object that will be associated with each returned process + */ + public IRemoteProcess[] listChildProcesses(IRemoteProcess parent, IRemoteProcessContext context) throws SystemMessageException; + + /** + * Return a list of remote child processes of the given process, which match the filter. + * @param parent The parent process whose children to list + * @param processFilter The process filter to subset the list by, or null to return all child processes. + * @param context A context object that will be associated with each returned process + */ + public IRemoteProcess[] listChildProcesses(IRemoteProcess parent, IHostProcessFilter processFilter, IRemoteProcessContext context) throws SystemMessageException; + + /** + * Given a process, return its parent process object. + * @param process the process to return parent of. + */ + public IRemoteProcess getParentProcess(IRemoteProcess process); + + /** + * Given a pid, return an IRemoteProcess object for it. + * @param pid The pid of the desired process + */ + public IRemoteProcess getRemoteProcessObject(long pid) throws SystemMessageException; + + /** + * Kill the given process. + * + * @param process represents the object to be killed. + * @param the signal to send to the process + * @return false if the given process doesn't exist, else true. Throws an exception if anything fails. + */ + public boolean kill(IRemoteProcess process, String signal) throws SystemMessageException; + + /** + * Returns a list of the types of signals that can be sent to + * a process on the remote system. + * @return the signal types, or null if there are none, or they cannot be found. + */ + public String[] getSignalTypes() throws SystemMessageException; +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/SystemProcessesCoreResources.java b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/SystemProcessesCoreResources.java new file mode 100644 index 00000000000..da33417ad58 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/SystemProcessesCoreResources.java @@ -0,0 +1,34 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.core.subsystem; + +import org.eclipse.osgi.util.NLS; + + +public class SystemProcessesCoreResources extends NLS +{ + private static String BUNDLE_NAME = "org.eclipse.rse.subsystems.processes.core.subsystem.SystemProcessesCoreResources"; + + // PROCESS PROPERTIES + public static String RESID_PROPERTY_PROCESS_DEFAULTFILTER_LABEL; + public static String RESID_PROPERTY_PROCESS_MYPROCESSESFILTER_LABEL; + + static { + // load message values from bundle file + NLS.initializeMessages(BUNDLE_NAME, SystemProcessesCoreResources.class); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/SystemProcessesCoreResources.properties b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/SystemProcessesCoreResources.properties new file mode 100644 index 00000000000..1247342c7e3 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/SystemProcessesCoreResources.properties @@ -0,0 +1,19 @@ +################################################################################ +# Copyright (c) 2005, 2006 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: +# {Name} (company) - description of contribution. +################################################################################ + + +RESID_PROPERTY_PROCESS_DEFAULTFILTER_LABEL=All Processes +RESID_PROPERTY_PROCESS_MYPROCESSESFILTER_LABEL=My Processes \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/impl/RemoteProcessContext.java b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/impl/RemoteProcessContext.java new file mode 100644 index 00000000000..3a5e6f027d8 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/impl/RemoteProcessContext.java @@ -0,0 +1,157 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.core.subsystem.impl; + + +import java.util.Vector; + +import org.eclipse.rse.services.clientserver.processes.IHostProcessFilter; +import org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcess; +import org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcessContext; +import org.eclipse.rse.subsystems.processes.core.subsystem.RemoteProcessSubSystem; + +/** + * This class represents a place to hold contextual information stored within + * each remote process object. + *

    + * We store in here information that might be the same for multiple remote process objects, + * in order to save memory. This way, we can merely hold a reference to a single object, + * which itself may have numerous pieces of information helpful when processing actions + * on a particular remote object. + */ +public class RemoteProcessContext implements IRemoteProcessContext +{ + + protected RemoteProcessSubSystem subsystem; + protected IRemoteProcess parentProcess; + protected IHostProcessFilter filterString; + protected Vector allFilterStrings; + + /** + * Constructor that takes all inputs. + */ + public RemoteProcessContext(RemoteProcessSubSystem subsystem, IRemoteProcess parentProcessObject, + IHostProcessFilter filterString) + { + this.subsystem = subsystem; + this.parentProcess = parentProcessObject; + this.filterString = filterString; + } + + /** + * Constructor that takes no inputs. + */ + public RemoteProcessContext() + { + } + // ------------------------------------------------------------------------ + // SETTER METHODS... + // ------------------------------------------------------------------------ + /** + * Set the parent subsystem + */ + public void setParentRemoteProcessSubSystem(RemoteProcessSubSystem subsystem) + { + this.subsystem = subsystem; + } + + /** + * Set the parent remote process object of this process + */ + public void setParentRemoteProcess(IRemoteProcess parentProcessObject) + { + this.parentProcess = parentProcessObject; + } + + /** + * Set the filter string object resolved to get this object + */ + public void setFilterString(IHostProcessFilter filterString) + { + this.filterString = filterString; + allFilterStrings = null; + } + + /** + * Add an additional filter string. This is called for folders in a multi-filter string + * filter. It is needed to support the subsequent expansion of + * this process, so that it can filter on all the appropriate filter strings. + */ + public void addFilterString(IHostProcessFilter additionalFilterString) + { + if (allFilterStrings == null) + { + allFilterStrings = new Vector(); + if (filterString != null) + allFilterStrings.addElement(filterString); + } + // ensure this filter string is not already in the list... + boolean match = false; + String newfs = additionalFilterString.toString(); + for (int idx=0; !match && (idx + * By returning true, user sees a "Work with->Compile Commands..." action item in the popup menu for this + * subsystem. The action is supplied by the framework, but is populated using overridable methods in this subsystem. + *

    We return true. + */ + public boolean supportsCompileActions() + { + return false; + } + + /** + * Tell us if this subsystem factory supports server launch properties, which allow the user + * to configure how the server-side code for these subsystems are started. There is a Server + * Launch Setting property page, with a pluggable composite, where users can configure these + * properties. + *
    We return true. + */ + public boolean supportsServerLaunchProperties() + { + return true; + } + + + + // ------------------------------------------------------ + // PARENT METHODS RELATED TO FILTERS... + // ... ONLY INTERESTING IF supportsFilters() return true! + // ------------------------------------------------------ + + /** + * Override from parent. + *

    + * Here we create the default filter pool for this subsystem factory, and populate it + * with default filters. + *

    + */ + protected ISystemFilterPool createDefaultFilterPool(ISystemFilterPoolManager mgr) + { + ISystemFilterPool pool = null; + try { + // ----------------------------------------------------- + // create a pool named filters + // ----------------------------------------------------- + pool = mgr.createSystemFilterPool(getDefaultFilterPoolName(mgr.getName(), getId()), true); // true=>is deletable by user + + // --------------------------------------------------------------------------------------------- + // create default filters in that pool iff this is the user's private profile we are creating... + // --------------------------------------------------------------------------------------------- + if (isUserPrivateProfile(mgr)) + { + + Vector filterStrings = new Vector(); + + // ---------------------- + // "All Processes" filter... + // ---------------------- + filterStrings = new Vector(); + HostProcessFilterImpl allProcessesFilterString = new HostProcessFilterImpl(); + filterStrings.add(allProcessesFilterString.toString()); + ISystemFilter filter = mgr.createSystemFilter(pool, SystemProcessesCoreResources.RESID_PROPERTY_PROCESS_DEFAULTFILTER_LABEL,filterStrings); + filter.setNonChangable(true); + filter.setSingleFilterStringOnly(true); + + //------------------------ + // "My Processes" filter... + // ---------------------- + filterStrings = new Vector(); + HostProcessFilterImpl myProcessesFilterString = new HostProcessFilterImpl(); + myProcessesFilterString.setUsername("${user.id}"); + + filterStrings.add(myProcessesFilterString.toString()); + filter = mgr.createSystemFilter(pool, SystemProcessesCoreResources.RESID_PROPERTY_PROCESS_MYPROCESSESFILTER_LABEL,filterStrings); + filter.setNonChangable(true); + filter.setSingleFilterStringOnly(true); + } + } catch (Exception exc) + { + SystemBasePlugin.logError("Error creating default filter pool",exc); + } + return pool; + } + + + + /** + * Return the translated string to show in the property sheet for the type property. + */ + public String getTranslatedFilterTypeProperty(ISystemFilter selectedFilter) + { + return super.getTranslatedFilterTypeProperty(selectedFilter); + } + + public ISystemValidator getPortValidator() + { + ISystemValidator portValidator = new ValidatorServerPortInput(); + return portValidator; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/impl/RemoteProcessSubSystemImpl.java b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/impl/RemoteProcessSubSystemImpl.java new file mode 100644 index 00000000000..b31a81318fe --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/core/subsystem/impl/RemoteProcessSubSystemImpl.java @@ -0,0 +1,199 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.core.subsystem.impl; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.subsystems.CommunicationsEvent; +import org.eclipse.rse.core.subsystems.ICommunicationsListener; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.core.subsystems.SubSystem; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.clientserver.processes.HostProcessFilterImpl; +import org.eclipse.rse.services.clientserver.processes.IHostProcessFilter; +import org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcess; +import org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcessContext; +import org.eclipse.rse.subsystems.processes.core.subsystem.RemoteProcessSubSystem; +import org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcessSubSystemConfiguration; + +/** + * The implementation of the RemoteProcessSubSystem interface. + * Some of the methods are simply convenience methods - these are + * implemented here, whereas the real work takes place in the + * ProcessServiceSubSystem. + * @author mjberger + * + */ +/** + * @author mjberger + * + */ +public abstract class RemoteProcessSubSystemImpl extends SubSystem implements + RemoteProcessSubSystem, ICommunicationsListener +{ + + public RemoteProcessSubSystemImpl(IHost host, IConnectorService connectorService) + { + super(host, connectorService); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.RemoteProcessSubSystem#getParentRemoteProcessSubSystemFactory() + */ + public IRemoteProcessSubSystemConfiguration getParentRemoteProcessSubSystemFactory() + { + return (IRemoteProcessSubSystemConfiguration) super.getSubSystemConfiguration(); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.RemoteProcessSubSystem#isCaseSensitive() + */ + public boolean isCaseSensitive() + { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#communicationsStateChange(org.eclipse.rse.core.subsystems.CommunicationsEvent) + */ + public void communicationsStateChange(CommunicationsEvent e) + { + switch (e.getState()) + { + case CommunicationsEvent.BEFORE_CONNECT : + break; + case CommunicationsEvent.AFTER_DISCONNECT : + getConnectorService().removeCommunicationsListener(this); + + break; + + case CommunicationsEvent.BEFORE_DISCONNECT : + case CommunicationsEvent.CONNECTION_ERROR : + break; + default : + break; + } + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.SubSystem#initializeSubSystem(org.eclipse.core.runtime.IProgressMonitor) + */ + public void initializeSubSystem(IProgressMonitor monitor) + { + getConnectorService().addCommunicationsListener(this); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.RemoteProcessSubSystem#getParentProcess(org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcess) + */ + public IRemoteProcess getParentProcess(IRemoteProcess process) + { + return process.getParentRemoteProcess(); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.SubSystem#internalResolveFilterString(org.eclipse.core.runtime.IProgressMonitor, java.lang.String) + */ + protected Object[] internalResolveFilterString(IProgressMonitor monitor, String filterString) + throws InvocationTargetException, + InterruptedException + { + HostProcessFilterImpl rpf = new HostProcessFilterImpl(filterString); + IRemoteProcessContext context = new RemoteProcessContext(this, null, rpf); + IRemoteProcess[] ps = null; + try + { + ps = listAllProcesses(rpf, context); + } + catch (SystemMessageException e) + { + displayAsyncMsg(e); + } + return ps; + } + + /** + * At this point there is only one root process, the 'init' process with pid 1 + */ + public IRemoteProcess[] listRoots(IRemoteProcessContext context) + { + IRemoteProcess[] roots = new IRemoteProcess[1]; + try + { + roots[0] = getRemoteProcessObject(1); + } + catch (SystemMessageException e) + { + SystemBasePlugin.logError("Exception resolving roots", e); + } + return roots; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.RemoteProcessSubSystem#listAllProcesses(org.eclipse.rse.services.clientserver.processes.IHostProcessFilter, org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcessContext) + */ + public abstract IRemoteProcess[] listAllProcesses( + IHostProcessFilter processNameFilter, + IRemoteProcessContext context) throws InterruptedException, + SystemMessageException; + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.RemoteProcessSubSystem#getRemoteProcessObject(long) + */ + public abstract IRemoteProcess getRemoteProcessObject(long pid) + throws SystemMessageException; + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.RemoteProcessSubSystem#kill(org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcess, java.lang.String) + */ + public abstract boolean kill(IRemoteProcess process, String signal) + throws SystemMessageException; + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.RemoteProcessSubSystem#getSignalTypes() + */ + public abstract String[] getSignalTypes() throws SystemMessageException; + + + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#isPassiveCommunicationsListener() + */ + public boolean isPassiveCommunicationsListener() + { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.SubSystem#getObjectWithAbsoluteName(java.lang.String) + */ + public Object getObjectWithAbsoluteName(String key) throws Exception + { + try + { + long pid = Long.parseLong(key); + return getRemoteProcessObject(pid); + } + catch (NumberFormatException e) + { + return super.getObjectWithAbsoluteName(key); + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/servicesubsystem/IProcessServiceSubSystem.java b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/servicesubsystem/IProcessServiceSubSystem.java new file mode 100644 index 00000000000..68a7b52e39c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/servicesubsystem/IProcessServiceSubSystem.java @@ -0,0 +1,26 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.servicesubsystem; + +import org.eclipse.rse.core.servicesubsystem.IServiceSubSystem; +import org.eclipse.rse.subsystems.processes.core.subsystem.RemoteProcessSubSystem; + + +public interface IProcessServiceSubSystem extends RemoteProcessSubSystem, IServiceSubSystem +{ + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/servicesubsystem/IProcessServiceSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/servicesubsystem/IProcessServiceSubSystemConfiguration.java new file mode 100644 index 00000000000..d2f87a7ebf9 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/servicesubsystem/IProcessServiceSubSystemConfiguration.java @@ -0,0 +1,51 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.servicesubsystem; + +import org.eclipse.rse.core.servicesubsystem.IServiceSubSystemConfiguration; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.processes.IProcessService; +import org.eclipse.rse.subsystems.processes.core.subsystem.IHostProcessToRemoteProcessAdapter; +import org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcessSubSystemConfiguration; + +/** + * Factory for creating the ProcessServiceSubSystem and for getting the associated + * service and adapter. + * @author mjberger + * + */ +public interface IProcessServiceSubSystemConfiguration extends IServiceSubSystemConfiguration, IRemoteProcessSubSystemConfiguration +{ + /** + * @param host The object representing the remote machine to which the process service is associated + * @return The process service associated with the host. + */ + public IProcessService getProcessService(IHost host); + + /** + * Creates a new process service object associated with a specific remote host + * @param host The object representing the remote machine to which the process service is associated + * @return The process service associated with the host. + */ + public IProcessService createProcessService(IHost host); + + /** + * @return An adapter for converting IHostProcess objects to IRemoteProcess + */ + public IHostProcessToRemoteProcessAdapter getHostProcessAdapter(); + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/servicesubsystem/ProcessServiceSubSystem.java b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/servicesubsystem/ProcessServiceSubSystem.java new file mode 100644 index 00000000000..4c3a001fa48 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/servicesubsystem/ProcessServiceSubSystem.java @@ -0,0 +1,201 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.servicesubsystem; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.servicesubsystem.IServiceSubSystemConfiguration; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.clientserver.processes.HostProcessFilterImpl; +import org.eclipse.rse.services.clientserver.processes.IHostProcess; +import org.eclipse.rse.services.clientserver.processes.IHostProcessFilter; +import org.eclipse.rse.services.processes.IProcessService; +import org.eclipse.rse.subsystems.processes.core.subsystem.IHostProcessToRemoteProcessAdapter; +import org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcess; +import org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcessContext; +import org.eclipse.rse.subsystems.processes.core.subsystem.impl.RemoteProcessContext; +import org.eclipse.rse.subsystems.processes.core.subsystem.impl.RemoteProcessSubSystemImpl; + +/** + * The subsystem that, coupled with a ProcessService implementation, + * can query and kill remote processes on a remote system. + * @author mjberger + * + */ +public class ProcessServiceSubSystem extends RemoteProcessSubSystemImpl implements IProcessServiceSubSystem +{ + protected IProcessService _hostProcessService; + protected IHostProcessToRemoteProcessAdapter _hostProcessToRemoteProcessAdapter; + + public ProcessServiceSubSystem(IHost host, IConnectorService connectorService, IProcessService hostProcessService, IHostProcessToRemoteProcessAdapter adapter) + { + super(host, connectorService); + _hostProcessService = hostProcessService; + _hostProcessToRemoteProcessAdapter = adapter; + } + + /** + * @return the process service associated with this subsystem. + */ + public IProcessService getProcessService() + { + return _hostProcessService; + } + + /** + * Sets which process service is associated with and used by this subsystem. + * @param service The IProcessService with which to associate this subsystem. + */ + public void setProcessService(IProcessService service) + { + _hostProcessService = service; + } + + /** + * @return the associated adapter for converting IHostProcess objects to IRemoteProcess objects + */ + public IHostProcessToRemoteProcessAdapter getHostProcessToRemoteProcessAdapter() + { + return _hostProcessToRemoteProcessAdapter; + } + + /** + * Sets the associated adapter for converting IHostProcess objects to IRemoteProcess objects + */ + public void setHostProcessToRemoteProcessAdapter(IHostProcessToRemoteProcessAdapter hostProcessAdapter) + { + _hostProcessToRemoteProcessAdapter = hostProcessAdapter; + } + + /** + * Returns the IRemoteProcess representing the process on the remote machine that has a + * certain pid. + * @param pid The pid of the process to return + */ + public IRemoteProcess getRemoteProcessObject(long pid) throws SystemMessageException + { + checkIsConnected(); + HostProcessFilterImpl rpfs = new HostProcessFilterImpl(); + rpfs.setPid("" + pid); + IRemoteProcessContext context = new RemoteProcessContext(this, null, rpfs); + IHostProcess process = getProcessService().getProcess(null, pid); + return getHostProcessToRemoteProcessAdapter().convertToRemoteProcess(context, null, process); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.impl.RemoteProcessSubSystemImpl#getSignalTypes() + */ + public String[] getSignalTypes() throws SystemMessageException + { + return getProcessService().getSignalTypes(); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.impl.RemoteProcessSubSystemImpl#kill(org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcess, java.lang.String) + */ + public boolean kill(IRemoteProcess process, String signal) throws SystemMessageException + { + checkIsConnected(); + return getProcessService().kill(null, process.getPid(), signal); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.impl.RemoteProcessSubSystemImpl#listAllProcesses(org.eclipse.rse.services.clientserver.processes.IHostProcessFilter, org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcessContext) + */ + public IRemoteProcess[] listAllProcesses(IHostProcessFilter processFilter, IRemoteProcessContext context) throws InterruptedException, SystemMessageException + { + checkIsConnected(); + IHostProcess[] processes = getProcessService().listAllProcesses(null, processFilter); + return getHostProcessToRemoteProcessAdapter().convertToRemoteProcesses(context, null, processes); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.RemoteProcessSubSystem#listChildProcesses(org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcess, org.eclipse.rse.services.clientserver.processes.IHostProcessFilter, org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcessContext) + */ + public IRemoteProcess[] listChildProcesses(IRemoteProcess parent, IHostProcessFilter processFilter, IRemoteProcessContext context) throws SystemMessageException + { + checkIsConnected(); + IHostProcess[] processes = getProcessService().listChildProcesses(null, parent.getPid(), processFilter); + return getHostProcessToRemoteProcessAdapter().convertToRemoteProcesses(context, parent, processes); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.RemoteProcessSubSystem#listChildProcesses(org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcess, org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcessContext) + */ + public IRemoteProcess[] listChildProcesses(IRemoteProcess parent, IRemoteProcessContext context) throws SystemMessageException + { + checkIsConnected(); + IHostProcess[] processes = getProcessService().listChildProcesses(null, parent.getPid()); + return getHostProcessToRemoteProcessAdapter().convertToRemoteProcesses(context, parent, processes); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.servicesubsystem.IServiceSubSystem#switchServiceFactory(org.eclipse.rse.core.servicesubsystem.IServiceSubSystemFactory) + */ + public void switchServiceFactory(IServiceSubSystemConfiguration fact) + { + if (fact != getSubSystemConfiguration() && fact instanceof IProcessServiceSubSystemConfiguration) + { + IProcessServiceSubSystemConfiguration factory = (IProcessServiceSubSystemConfiguration)fact; + try + { + disconnect(SystemBasePlugin.getActiveWorkbenchShell()); + } + catch (Exception e) + { + } + + IHost host = getHost(); + setSubSystemConfiguration(factory); + + + IConnectorService oldConnectorService = getConnectorService(); + oldConnectorService.deregisterSubSystem(this); + + IConnectorService newConnectorService = factory.getConnectorService(host); + setConnectorService(newConnectorService); + + oldConnectorService.commit(); + newConnectorService.commit(); + + setProcessService(factory.getProcessService(host)); + setHostProcessToRemoteProcessAdapter(factory.getHostProcessAdapter()); + } + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.servicesubsystem.IServiceSubSystem#getServiceType() + */ + public Class getServiceType() + { + return IProcessService.class; + } + + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.impl.RemoteProcessSubSystemImpl#initializeSubSystem(org.eclipse.core.runtime.IProgressMonitor) + */ + public void initializeSubSystem(IProgressMonitor monitor) + { + super.initializeSubSystem(monitor); + getProcessService().initService(monitor); + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/servicesubsystem/ProcessServiceSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/servicesubsystem/ProcessServiceSubSystemConfiguration.java new file mode 100644 index 00000000000..71a5dd11d0b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.core/src/org/eclipse/rse/subsystems/processes/servicesubsystem/ProcessServiceSubSystemConfiguration.java @@ -0,0 +1,81 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.servicesubsystem; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.IService; +import org.eclipse.rse.services.processes.IProcessService; +import org.eclipse.rse.subsystems.processes.core.subsystem.impl.RemoteProcessSubSystemConfiguration; + +/** + * Factory for creating the ProcessServiceSubSystem and for getting the associated + * service and adapter. + * @author mjberger + * + */ +public abstract class ProcessServiceSubSystemConfiguration extends RemoteProcessSubSystemConfiguration implements IProcessServiceSubSystemConfiguration +{ + + protected Map _services; + + protected ProcessServiceSubSystemConfiguration() + { + super(); + _services = new HashMap(); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.servicesubsystem.IProcessServiceSubSystemFactory#getProcessService(org.eclipse.rse.model.IHost) + */ + public IProcessService getProcessService(IHost host) + { + IProcessService service = (IProcessService)_services.get(host); + if (service == null) + { + service = createProcessService(host); + _services.put(host, service); + } + return service; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.servicesubsystem.IServiceSubSystemFactory#getServiceType() + */ + public final Class getServiceType() + { + return IProcessService.class; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.SubSystemFactory#supportsServerLaunchProperties(org.eclipse.rse.model.IHost) + */ + public boolean supportsServerLaunchProperties(IHost host) + { + return getConnectorService(host).supportsServerLaunchProperties(); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.servicesubsystem.IServiceSubSystemFactory#getService(org.eclipse.rse.model.IHost) + */ + public IService getService(IHost host) + { + return getProcessService(host); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/.classpath b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/.classpath new file mode 100644 index 00000000000..751c8f2e504 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/.cvsignore b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/.cvsignore new file mode 100644 index 00000000000..ba077a4031a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/.project b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/.project new file mode 100644 index 00000000000..2e36b31bdd4 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/.project @@ -0,0 +1,28 @@ + + + org.eclipse.rse.subsystems.processes.dstore + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..bcdbc53aa26 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin.name +Bundle-SymbolicName: org.eclipse.rse.subsystems.processes.dstore;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.rse.subsystems.processes.dstore.Activator +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.rse.services, + org.eclipse.rse.services.dstore, + org.eclipse.dstore.core, + org.eclipse.dstore.extra, + org.eclipse.rse.connectorservice.dstore, + org.eclipse.rse.subsystems.processes.core, + org.eclipse.rse.processes.ui, + org.eclipse.rse.ui +Eclipse-LazyStart: true +Bundle-Vendor: Eclipse.org +Bundle-ClassPath: processesDstore.jar diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/about.html b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/about.html new file mode 100644 index 00000000000..6f6b96c4c87 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/about.html @@ -0,0 +1,22 @@ + + + +About + + + +

    About This Content

    + +

    February 24, 2005

    +

    License

    + +

    The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

    + +

    If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content.

    + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/build.properties b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/build.properties new file mode 100644 index 00000000000..34fff98542a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/build.properties @@ -0,0 +1,14 @@ +bin.includes = META-INF/,\ + about.html,\ + plugin.properties,\ + icons/,\ + plugin.xml,\ + processesDstore.jar +src.includes = META-INF/,\ + about.html,\ + icons/,\ + plugin.properties,\ + plugin.xml +source.processesDstore.jar = src/ +output.processesDstore.jar = bin/ +jars.compile.order = processesDstore.jar diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/icons/full/obj16/activeprocess.gif b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/icons/full/obj16/activeprocess.gif new file mode 100644 index 0000000000000000000000000000000000000000..7902f8115c38e8ecbe602a9546c5748fe6ed0940 GIT binary patch literal 962 zcmZ?wbhEHb6krfw_|5=kK?-kGGGnUv}z4eEocehKBq1_wV07 z9|-O3>*M3=7c5u;Tn3`L)WZnLGOV%x1wr>00V@FP1K6vz0 z(fsCPCl7AfzUt5a<^TS^{rfQg&x3-$kBSz}Y5M;l|Nq0n-R@vy(gLYK~JUN*Do-pZiID*_%Z4|ud9VA=G>nmDt%1k0*8%gQ+G`Z%-N zILq32%bGaLnphxd(->!+=I5B=5}f@^8f#T2D$^qpDc_F43P{v zAe%vP!oWVeAu>`%sI^U|sk2i^vbUE}sH;mzn0p$xz{E*SLcARF=g*qmwq(&HAs%UI z9v<;!lf@Vqm{?dOoV@~Z!`si2~&Vbv|l#>VLprljwxtQg=s zN0gsm&`DP-Ts}lk%jZ5TE3-?ej;Wi0c98oVc9B0)X6lA1XAB-H2eQXmHs~xATynhE RchaPUnM@lOEplM61_1KM$h!al literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/icons/full/obj16/processsubsystemlive_obj.gif b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/icons/full/obj16/processsubsystemlive_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..96a447a71757c17f3fcb729a8598da80ffcc41a1 GIT binary patch literal 594 zcmZ?wbhEHb6krfwc*ekR)G2e#x~-*EU8m3AK5^Tn3`L)WZnLGOV%x1wr>00V@FP1K6vz$ zT#a+z-i0Qep+)nX8PbG1K00sz-gn{WmSZOmZrQ%-&;RBB{=WVDF#pekg1?W77R_n; z{~-VW!@}dM0*@^ZI<_MC$coT^NB#dC4gPl|^xyHYzsEwC&T3vZv+3T-pvNl$9xV@e zv?5^H^v0Svv$_P!syNHaIP3a2v)XvenmEhT`#03Y0vR@qan@;mjwwEl%gU1%SEQwQ zJ0|T8lu&-}OP!?)wRZi%T?&uJb?CWC`>Xz>6 z5$2x3Eig%DiqcdeUXI0!Cn+kdP>@e(T{}lsdQ}gPoE#62_@vI&Jz@+DOe`!CUV+h5 zd)7)gIfto+y4ZIMab4x(b2Cua*3oyoEXu~l=^v|U=A)$%9?~Pq&oAg{Vi>0uWoj7w zj+K?!J0|TzMv*g{n0gOiK*WlL?c6e!C0jH$b+i~MxG#C*V07g8qJH^>H7A)iE%9_| IWMHrc04UnuO#lD@ literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/plugin.properties b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/plugin.properties new file mode 100644 index 00000000000..c42f176b75a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/plugin.properties @@ -0,0 +1,20 @@ +################################################################################ +# Copyright (c) 2006 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: +# {Name} (company) - description of contribution. +################################################################################ + +plugin.name = RSE Dstore Processes + +Processes=Processes +ProcessesDescription=This configuration allows you to work with processes on local or remote systems using the DataStore protocol. \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/plugin.xml b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/plugin.xml new file mode 100644 index 00000000000..f143712d003 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/plugin.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/src/org/eclipse/rse/subsystems/processes/dstore/Activator.java b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/src/org/eclipse/rse/subsystems/processes/dstore/Activator.java new file mode 100644 index 00000000000..63b7fb340f8 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/src/org/eclipse/rse/subsystems/processes/dstore/Activator.java @@ -0,0 +1,72 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.dstore; + +import org.eclipse.rse.processes.ui.ProcessesPlugin; +import org.eclipse.ui.plugin.*; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class Activator extends AbstractUIPlugin { + + //The shared instance. + private static Activator plugin; + + /** + * The constructor. + */ + public Activator() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + ProcessesPlugin.getDefault(); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static Activator getDefault() { + 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.subsystems.processes.dstore", path); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/src/org/eclipse/rse/subsystems/processes/dstore/DStoreProcessAdapter.java b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/src/org/eclipse/rse/subsystems/processes/dstore/DStoreProcessAdapter.java new file mode 100644 index 00000000000..7acd02e0996 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/src/org/eclipse/rse/subsystems/processes/dstore/DStoreProcessAdapter.java @@ -0,0 +1,86 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.dstore; + +import java.util.ArrayList; + +import org.eclipse.rse.services.clientserver.processes.IHostProcess; +import org.eclipse.rse.services.dstore.processes.DStoreHostProcess; +import org.eclipse.rse.subsystems.processes.core.subsystem.IHostProcessToRemoteProcessAdapter; +import org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcess; +import org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcessContext; +import org.eclipse.rse.subsystems.processes.core.subsystem.impl.RemoteProcessImpl; + +import org.eclipse.dstore.core.model.DataElement; + +/** + * Adapter for converting DStoreHostProcess objects (objects where the underlying + * process is represented by a DataElement) to IRemoteProcess objects + * + * @author mjberger + * + */ +public class DStoreProcessAdapter implements IHostProcessToRemoteProcessAdapter { + + /** + * @see org.eclipse.rse.subsystems.processes.core.subsystem.IHostProcessToRemoteProcessAdapter#convertToRemoteProcesses(org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcessContext, org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcess, org.eclipse.rse.services.clientserver.processes.IHostProcess[]) + * Precondition: each element of nodes must be a DStoreHostProcess + */ + public IRemoteProcess[] convertToRemoteProcesses(IRemoteProcessContext context, IRemoteProcess parent, IHostProcess[] nodes) + { + if (nodes == null) + return null; + + ArrayList list = new ArrayList(nodes.length); + + for (int idx = 0; idx < nodes.length; idx++) + { + DStoreHostProcess node = (DStoreHostProcess) nodes[idx]; + DataElement de = (DataElement) node.getObject(); + if (!de.isDeleted()) + { + IRemoteProcess newProcess = new RemoteProcessImpl(context, node); + list.add(newProcess); + } + } + + IRemoteProcess[] processes = new IRemoteProcess[list.size()]; + + for (int idx = 0; idx < list.size(); idx++) + { + processes[idx] = (IRemoteProcess) list.get(idx); + } + + return processes; + } + + /** + * @see org.eclipse.rse.subsystems.processes.core.subsystem.IHostProcessToRemoteProcessAdapter#convertToRemoteProcess(org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcessContext, org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcess, org.eclipse.rse.services.clientserver.processes.IHostProcess) + * Precondition: node must be a DStoreHostProcess + */ + public IRemoteProcess convertToRemoteProcess(IRemoteProcessContext context, IRemoteProcess parent, IHostProcess node) + { + IHostProcess[] nodes = new IHostProcess[1]; + nodes[0] = node; + + IRemoteProcess[] processes = convertToRemoteProcesses(context, parent, nodes); + if (processes != null && processes.length > 0) + return processes[0]; + else return null; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/src/org/eclipse/rse/subsystems/processes/dstore/DStoreProcessSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/src/org/eclipse/rse/subsystems/processes/dstore/DStoreProcessSubSystemConfiguration.java new file mode 100644 index 00000000000..ee52b1ebb78 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.dstore/src/org/eclipse/rse/subsystems/processes/dstore/DStoreProcessSubSystemConfiguration.java @@ -0,0 +1,126 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.dstore; + +import org.eclipse.rse.connectorservice.dstore.DStoreConnectorService; +import org.eclipse.rse.connectorservice.dstore.DStoreConnectorServiceManager; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.dstore.IDStoreService; +import org.eclipse.rse.services.dstore.processes.DStoreProcessService; +import org.eclipse.rse.services.processes.IProcessService; +import org.eclipse.rse.subsystems.processes.core.subsystem.IHostProcessToRemoteProcessAdapter; +import org.eclipse.rse.subsystems.processes.servicesubsystem.ProcessServiceSubSystem; +import org.eclipse.rse.subsystems.processes.servicesubsystem.ProcessServiceSubSystemConfiguration; + + +public class DStoreProcessSubSystemConfiguration extends ProcessServiceSubSystemConfiguration +{ + protected IHostProcessToRemoteProcessAdapter _hostProcessAdapter; + + public DStoreProcessSubSystemConfiguration() + { + super(); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#isFactoryFor(java.lang.Class) + */ + public boolean isFactoryFor(Class subSystemType) { + boolean isFor = ProcessServiceSubSystem.class.equals(subSystemType); + return isFor; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.SubSystemFactory#createSubSystemInternal(org.eclipse.rse.model.IHost) + */ + public ISubSystem createSubSystemInternal(IHost host) + { + DStoreConnectorService connectorService = (DStoreConnectorService)getConnectorService(host); + ISubSystem subsys = new ProcessServiceSubSystem(host, connectorService, getProcessService(host), getHostProcessAdapter()); + return subsys; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#supportsFileTypes() + */ + public boolean supportsFileTypes() { + return false; + } + + /** + * @return true if the subsystem supports remote search + */ + public boolean supportsSearch() { + return false; + } + + /** + * @return + */ + public boolean supportsEnvironmentVariablesPropertyPage() { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.impl.RemoteProcessSubSystemConfiguration#supportsFilters() + */ + public boolean supportsFilters() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.servicesubsystem.IProcessServiceSubSystemFactory#createProcessService(org.eclipse.rse.model.IHost) + */ + public IProcessService createProcessService(IHost host) + { + DStoreConnectorService connectorService = (DStoreConnectorService)getConnectorService(host); + return new DStoreProcessService(connectorService); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.servicesubsystem.IProcessServiceSubSystemFactory#getHostProcessAdapter() + */ + public IHostProcessToRemoteProcessAdapter getHostProcessAdapter() + { + if (_hostProcessAdapter == null) + { + _hostProcessAdapter = new DStoreProcessAdapter(); + } + return _hostProcessAdapter; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.ISubSystemFactory#getConnectorService(org.eclipse.rse.model.IHost) + */ + public IConnectorService getConnectorService(IHost host) + { + return DStoreConnectorServiceManager.getTheUniversalSystemManager().getConnectorService(host, getServiceImplType()); + } + + public void setConnectorService(IHost host, IConnectorService connectorService) + { + DStoreConnectorServiceManager.getTheUniversalSystemManager().setConnectorService(host, getServiceImplType(), connectorService); + } + + public Class getServiceImplType() + { + return IDStoreService.class; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.local/.classpath b/rse/plugins/org.eclipse.rse.subsystems.processes.local/.classpath new file mode 100644 index 00000000000..751c8f2e504 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.local/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.local/.cvsignore b/rse/plugins/org.eclipse.rse.subsystems.processes.local/.cvsignore new file mode 100644 index 00000000000..ba077a4031a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.local/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.local/.project b/rse/plugins/org.eclipse.rse.subsystems.processes.local/.project new file mode 100644 index 00000000000..20b02bee422 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.local/.project @@ -0,0 +1,28 @@ + + + org.eclipse.rse.subsystems.processes.local + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.local/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.subsystems.processes.local/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..e6b7b7b9bf1 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.local/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin.name +Bundle-SymbolicName: org.eclipse.rse.subsystems.processes.local;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.rse.subsystems.processes.local.Activator +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.rse.services, + org.eclipse.rse.services.local, + org.eclipse.rse.connectorservice.local, + org.eclipse.rse.subsystems.processes.core, + org.eclipse.rse.processes.ui, + org.eclipse.rse.ui +Eclipse-LazyStart: true +Bundle-Vendor: Eclipse.org +Bundle-ClassPath: processesLocal.jar +Export-Package: org.eclipse.rse.subsystems.processes.local diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.local/about.html b/rse/plugins/org.eclipse.rse.subsystems.processes.local/about.html new file mode 100644 index 00000000000..6f6b96c4c87 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.local/about.html @@ -0,0 +1,22 @@ + + + +About + + + +

    About This Content

    + +

    February 24, 2005

    +

    License

    + +

    The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

    + +

    If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content.

    + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.local/build.properties b/rse/plugins/org.eclipse.rse.subsystems.processes.local/build.properties new file mode 100644 index 00000000000..92c5c8142d4 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.local/build.properties @@ -0,0 +1,14 @@ +bin.includes = META-INF/,\ + about.html,\ + icons/,\ + plugin.properties,\ + plugin.xml,\ + processesLocal.jar +src.includes = META-INF/,\ + about.html,\ + icons/,\ + plugin.properties,\ + plugin.xml +source.processesLocal.jar = src/ +output.processesLocal.jar = bin/ +jars.compile.order = processesLocal.jar diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.local/icons/full/obj16/activeprocess.gif b/rse/plugins/org.eclipse.rse.subsystems.processes.local/icons/full/obj16/activeprocess.gif new file mode 100644 index 0000000000000000000000000000000000000000..7902f8115c38e8ecbe602a9546c5748fe6ed0940 GIT binary patch literal 962 zcmZ?wbhEHb6krfw_|5=kK?-kGGGnUv}z4eEocehKBq1_wV07 z9|-O3>*M3=7c5u;Tn3`L)WZnLGOV%x1wr>00V@FP1K6vz0 z(fsCPCl7AfzUt5a<^TS^{rfQg&x3-$kBSz}Y5M;l|Nq0n-R@vy(gLYK~JUN*Do-pZiID*_%Z4|ud9VA=G>nmDt%1k0*8%gQ+G`Z%-N zILq32%bGaLnphxd(->!+=I5B=5}f@^8f#T2D$^qpDc_F43P{v zAe%vP!oWVeAu>`%sI^U|sk2i^vbUE}sH;mzn0p$xz{E*SLcARF=g*qmwq(&HAs%UI z9v<;!lf@Vqm{?dOoV@~Z!`si2~&Vbv|l#>VLprljwxtQg=s zN0gsm&`DP-Ts}lk%jZ5TE3-?ej;Wi0c98oVc9B0)X6lA1XAB-H2eQXmHs~xATynhE RchaPUnM@lOEplM61_1KM$h!al literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.local/icons/full/obj16/processsubsystemlive_obj.gif b/rse/plugins/org.eclipse.rse.subsystems.processes.local/icons/full/obj16/processsubsystemlive_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..96a447a71757c17f3fcb729a8598da80ffcc41a1 GIT binary patch literal 594 zcmZ?wbhEHb6krfwc*ekR)G2e#x~-*EU8m3AK5^Tn3`L)WZnLGOV%x1wr>00V@FP1K6vz$ zT#a+z-i0Qep+)nX8PbG1K00sz-gn{WmSZOmZrQ%-&;RBB{=WVDF#pekg1?W77R_n; z{~-VW!@}dM0*@^ZI<_MC$coT^NB#dC4gPl|^xyHYzsEwC&T3vZv+3T-pvNl$9xV@e zv?5^H^v0Svv$_P!syNHaIP3a2v)XvenmEhT`#03Y0vR@qan@;mjwwEl%gU1%SEQwQ zJ0|T8lu&-}OP!?)wRZi%T?&uJb?CWC`>Xz>6 z5$2x3Eig%DiqcdeUXI0!Cn+kdP>@e(T{}lsdQ}gPoE#62_@vI&Jz@+DOe`!CUV+h5 zd)7)gIfto+y4ZIMab4x(b2Cua*3oyoEXu~l=^v|U=A)$%9?~Pq&oAg{Vi>0uWoj7w zj+K?!J0|TzMv*g{n0gOiK*WlL?c6e!C0jH$b+i~MxG#C*V07g8qJH^>H7A)iE%9_| IWMHrc04UnuO#lD@ literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.local/plugin.properties b/rse/plugins/org.eclipse.rse.subsystems.processes.local/plugin.properties new file mode 100644 index 00000000000..4b64bcf712d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.local/plugin.properties @@ -0,0 +1,19 @@ +################################################################################ +# Copyright (c) 2006 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: +# {Name} (company) - description of contribution. +################################################################################ + +plugin.name = RSE Local Processes + +Processes=Processes \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.local/plugin.xml b/rse/plugins/org.eclipse.rse.subsystems.processes.local/plugin.xml new file mode 100644 index 00000000000..0935d70e68d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.local/plugin.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.local/src/org/eclipse/rse/subsystems/processes/local/Activator.java b/rse/plugins/org.eclipse.rse.subsystems.processes.local/src/org/eclipse/rse/subsystems/processes/local/Activator.java new file mode 100644 index 00000000000..36577aef1a1 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.local/src/org/eclipse/rse/subsystems/processes/local/Activator.java @@ -0,0 +1,72 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.local; + +import org.eclipse.rse.processes.ui.ProcessesPlugin; +import org.eclipse.ui.plugin.*; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class Activator extends AbstractUIPlugin { + + //The shared instance. + private static Activator plugin; + + /** + * The constructor. + */ + public Activator() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + ProcessesPlugin.getDefault(); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static Activator getDefault() { + 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.subsystems.processes.dstore", path); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.local/src/org/eclipse/rse/subsystems/processes/local/LocalProcessAdapter.java b/rse/plugins/org.eclipse.rse.subsystems.processes.local/src/org/eclipse/rse/subsystems/processes/local/LocalProcessAdapter.java new file mode 100644 index 00000000000..176ede61b37 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.local/src/org/eclipse/rse/subsystems/processes/local/LocalProcessAdapter.java @@ -0,0 +1,69 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.local; + +import org.eclipse.rse.services.clientserver.processes.IHostProcess; +import org.eclipse.rse.subsystems.processes.core.subsystem.IHostProcessToRemoteProcessAdapter; +import org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcess; +import org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcessContext; +import org.eclipse.rse.subsystems.processes.core.subsystem.impl.RemoteProcessImpl; + +/** + * Adapter for converting IHostProcess objects (objects where the underlying + * process resides on the local machine) to IRemoteProcess objects + * + * @author mjberger + * + */ +public class LocalProcessAdapter implements IHostProcessToRemoteProcessAdapter { + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.IHostProcessToRemoteProcessAdapter#convertToRemoteProcesses(org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcessContext, org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcess, org.eclipse.rse.services.clientserver.processes.IHostProcess[]) + */ + public IRemoteProcess[] convertToRemoteProcesses( + IRemoteProcessContext context, IRemoteProcess parent, + IHostProcess[] nodes) + { + if (nodes == null) + return null; + + IRemoteProcess[] processes = new IRemoteProcess[nodes.length]; + + for (int idx = 0; idx < nodes.length; idx++) + { + processes[idx] = new RemoteProcessImpl(context, nodes[idx]); + } + + return processes; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.IHostProcessToRemoteProcessAdapter#convertToRemoteProcess(org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcessContext, org.eclipse.rse.subsystems.processes.core.subsystem.IRemoteProcess, org.eclipse.rse.services.clientserver.processes.IHostProcess) + */ + public IRemoteProcess convertToRemoteProcess(IRemoteProcessContext context, + IRemoteProcess parent, IHostProcess node) + { + IHostProcess[] nodes = new IHostProcess[1]; + nodes[0] = node; + + IRemoteProcess[] processes = convertToRemoteProcesses(context, parent, nodes); + if (processes != null && processes.length > 0) + return processes[0]; + else return null; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.processes.local/src/org/eclipse/rse/subsystems/processes/local/LocalProcessSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.processes.local/src/org/eclipse/rse/subsystems/processes/local/LocalProcessSubSystemConfiguration.java new file mode 100644 index 00000000000..e2fb487d42f --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.processes.local/src/org/eclipse/rse/subsystems/processes/local/LocalProcessSubSystemConfiguration.java @@ -0,0 +1,126 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.processes.local; + + +import org.eclipse.rse.connectorservice.local.LocalConnectorService; +import org.eclipse.rse.connectorservice.local.LocalConnectorServiceManager; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.local.ILocalService; +import org.eclipse.rse.services.local.processes.LocalProcessService; +import org.eclipse.rse.services.processes.IProcessService; +import org.eclipse.rse.subsystems.processes.core.subsystem.IHostProcessToRemoteProcessAdapter; +import org.eclipse.rse.subsystems.processes.servicesubsystem.ProcessServiceSubSystem; +import org.eclipse.rse.subsystems.processes.servicesubsystem.ProcessServiceSubSystemConfiguration; + + +public class LocalProcessSubSystemConfiguration extends ProcessServiceSubSystemConfiguration +{ + public LocalProcessSubSystemConfiguration() + { + super(); + } + protected IHostProcessToRemoteProcessAdapter _hostProcessAdapter; + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#isFactoryFor(java.lang.Class) + */ + public boolean isFactoryFor(Class subSystemType) { + boolean isFor = ProcessServiceSubSystem.class.equals(subSystemType); + return isFor; + } + + /** + * Instantiate and return an instance of OUR subystem. Do not populate it yet though! + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#createSubSystemInternal(IHost) + */ + public ISubSystem createSubSystemInternal(IHost host) + { + LocalConnectorService connectorService = (LocalConnectorService)getConnectorService(host); + ISubSystem subsys = new ProcessServiceSubSystem(host, connectorService, getProcessService(host), getHostProcessAdapter()); + return subsys; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#supportsFileTypes() + */ + public boolean supportsFileTypes() { + return false; + } + + /** + * @return + */ + public boolean supportsSearch() { + return false; + } + + /** + * @return + */ + public boolean supportsEnvironmentVariablesPropertyPage() { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.core.subsystem.impl.RemoteProcessSubSystemConfiguration#supportsFilters() + */ + public boolean supportsFilters() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.ISubSystemFactory#getConnectorService(org.eclipse.rse.model.IHost) + */ + public IConnectorService getConnectorService(IHost host) + { + return LocalConnectorServiceManager.getTheLocalSystemManager().getConnectorService(host, getServiceImplType()); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.servicesubsystem.IProcessServiceSubSystemFactory#createProcessService(org.eclipse.rse.model.IHost) + */ + public IProcessService createProcessService(IHost host) + { + //LocalConnectorService connectorService = (LocalConnectorService)getConnectorService(host); + return new LocalProcessService(); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.subsystems.processes.servicesubsystem.IProcessServiceSubSystemFactory#getHostProcessAdapter() + */ + public IHostProcessToRemoteProcessAdapter getHostProcessAdapter() + { + if (_hostProcessAdapter == null) + { + _hostProcessAdapter = new LocalProcessAdapter(); + } + return _hostProcessAdapter; + } + + public void setConnectorService(IHost host, IConnectorService connectorService) + { + LocalConnectorServiceManager.getTheLocalSystemManager().setConnectorService(host, getServiceImplType(), connectorService); + } + + public Class getServiceImplType() + { + return ILocalService.class; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/.classpath b/rse/plugins/org.eclipse.rse.subsystems.shells.core/.classpath new file mode 100644 index 00000000000..751c8f2e504 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/.cvsignore b/rse/plugins/org.eclipse.rse.subsystems.shells.core/.cvsignore new file mode 100644 index 00000000000..ba077a4031a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/.project b/rse/plugins/org.eclipse.rse.subsystems.shells.core/.project new file mode 100644 index 00000000000..2bfc1392402 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/.project @@ -0,0 +1,28 @@ + + + org.eclipse.rse.subsystems.shells.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.subsystems.shells.core/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..c4e2e167a60 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin.name +Bundle-SymbolicName: org.eclipse.rse.subsystems.shells.core +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.rse.subsystems.shells.core.Activator +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.rse.services, + org.eclipse.core.resources, + org.eclipse.rse.subsystems.files.core, + org.eclipse.rse.ui +Eclipse-LazyStart: true +Export-Package: org.eclipse.rse.internal.subsystems.shells.servicesubsystem, + org.eclipse.rse.internal.subsystems.shells.subsystems, + org.eclipse.rse.subsystems.shells.core, + org.eclipse.rse.subsystems.shells.core.model, + org.eclipse.rse.subsystems.shells.core.subsystems, + org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem +Bundle-Vendor: Eclipse.org +Bundle-ClassPath: shells_core.jar diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/about.html b/rse/plugins/org.eclipse.rse.subsystems.shells.core/about.html new file mode 100644 index 00000000000..6f6b96c4c87 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/about.html @@ -0,0 +1,22 @@ + + + +About + + + +

    About This Content

    + +

    February 24, 2005

    +

    License

    + +

    The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

    + +

    If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content.

    + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/build.properties b/rse/plugins/org.eclipse.rse.subsystems.shells.core/build.properties new file mode 100644 index 00000000000..0d7698806f5 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/build.properties @@ -0,0 +1,10 @@ +bin.includes = META-INF/,\ + about.html,\ + plugin.properties,\ + shells_core.jar +src.includes = META-INF/,\ + about.html,\ + plugin.properties +jars.compile.order = shells_core.jar +source.shells_core.jar = src/ +output.shells_core.jar = bin/ diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/plugin.properties b/rse/plugins/org.eclipse.rse.subsystems.shells.core/plugin.properties new file mode 100644 index 00000000000..bf04fa2c2e7 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/plugin.properties @@ -0,0 +1,12 @@ +############################################################################### +# Copyright (c) 2000, 2006 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 +############################################################################### + +plugin.name = RSE Shells Core diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/servicesubsystem/OutputRefreshJob.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/servicesubsystem/OutputRefreshJob.java new file mode 100644 index 00000000000..157e7228cb9 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/servicesubsystem/OutputRefreshJob.java @@ -0,0 +1,77 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.shells.servicesubsystem; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.model.ISystemRegistry; +import org.eclipse.rse.model.ISystemResourceChangeEvents; +import org.eclipse.rse.model.SystemResourceChangeEvent; +import org.eclipse.rse.subsystems.shells.core.ShellStrings; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteOutput; +import org.eclipse.ui.progress.UIJob; + + +public class OutputRefreshJob extends UIJob + { + private IRemoteCommandShell _command; + private IRemoteOutput[] _outputs; + private boolean _cwdChanged = false; + private boolean _isComplete = false; + + + public OutputRefreshJob(IRemoteCommandShell command, IRemoteOutput[] outputs, boolean cwdChanged) + { + super(ShellStrings.RSESubSystemOperation_Refresh_Output); + _command = command; + _cwdChanged = cwdChanged; + _outputs = outputs; + } + + public boolean isComplete() + { + return _isComplete; + } + + public IStatus runInUIThread(IProgressMonitor monitor) + { + try + { + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + if (_outputs != null) + { + registry.fireEvent( + new SystemResourceChangeEvent(_outputs, ISystemResourceChangeEvents.EVENT_REFRESH, _command)); + + if (_cwdChanged) + { + registry.fireEvent( + new SystemResourceChangeEvent(_command, ISystemResourceChangeEvents.EVENT_PROPERTY_CHANGE, _command.getCommandSubSystem())); + } + } + } + catch (Exception e) + { + e.printStackTrace(); + } + _isComplete= true; + return Status.OK_STATUS; + } + } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/CandidateCommand.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/CandidateCommand.java new file mode 100644 index 00000000000..f3b46138d98 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/CandidateCommand.java @@ -0,0 +1,110 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.shells.subsystems; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.rse.subsystems.shells.core.subsystems.ICandidateCommand; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; + + +/** + * class represents a candidate command to run + */ +public class CandidateCommand implements IAdaptable, ICandidateCommand +{ + + protected String _name; + protected String _type; + protected String _description; + protected String _path; + protected ImageDescriptor _imageDescriptor; + + /** + * Constructor + * + * @param type indicates the type of the candidate command + * @param name indicates the name of the candidate command + * @param description describes the candidate command + * @param path indicates the path of the candidate command if one exists + */ + public CandidateCommand(String type, String name, String description, String path) + { + _name = name; + _type = type; + _description = description; + _path = path; + } + + /** + * Gets the name of the candidate command + * @return the name of the candidate command + */ + public String getName() + { + return _name; + } + + /** + * Gets the type of the candidate command. + * @return the type of the command + */ + public String getType() + { + return _type; + } + + /** + * Gets the path of a candidate command. + * @return the path to the command, if one exists + */ + public String getPath() + { + return _path; + } + + /** + * Gets the description for a candidate command. + * @return the description of the command + */ + public String getDescription() + { + return _description; + } + + /** + * Gets the image descriptor to display for a candidate command + * @return the image descriptor for the command + */ + public ImageDescriptor getImageDescriptor() + { + if (_imageDescriptor == null) + { + _imageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE); + //_imageDescriptor = SystemPlugin.getDefault().getImageDescriptor(ISystemConstants.ICON_SYSTEM_RUN_ID); + } + return _imageDescriptor; + } + + + public Object getAdapter(Class adapterType) + { + return Platform.getAdapterManager().getAdapter(this, adapterType); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteCmdSubSystem.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteCmdSubSystem.java new file mode 100644 index 00000000000..88627d25297 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteCmdSubSystem.java @@ -0,0 +1,1233 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.shells.subsystems; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.StringTokenizer; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.subsystems.CommunicationsEvent; +import org.eclipse.rse.core.subsystems.ICommunicationsListener; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.core.subsystems.IRemoteSystemEnvVar; +import org.eclipse.rse.core.subsystems.SubSystem; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.model.IPropertySet; +import org.eclipse.rse.model.ISystemRegistry; +import org.eclipse.rse.model.ISystemResourceChangeEvents; +import org.eclipse.rse.model.SystemResourceChangeEvent; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +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.subsystems.shells.core.ShellStrings; +import org.eclipse.rse.subsystems.shells.core.subsystems.ICandidateCommand; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystemConfiguration; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.ui.ISystemMessages; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + + +/** + * This is the abstraction of a subsystem specialized for remote execution of + * commands. + */ + +public abstract class RemoteCmdSubSystem extends SubSystem implements IRemoteCmdSubSystem, ICommunicationsListener +{ + + public static String COMMAND_SHELLS_MEMENTO = "commandshells"; + + protected java.util.List envVars = null; + + protected List _envVars; + + protected ArrayList _cmdShells; + + protected IRemoteCommandShell _defaultShell; + + protected IRemoteFileSubSystem _fileSubSystem; + + public RemoteCmdSubSystem(IHost host, IConnectorService connectorService) + { + super(host, connectorService); + _cmdShells = new ArrayList(); + } + + /** + * Return parent subsystem factory, cast to a RemoteCmdSubSystemFactory + */ + public IRemoteCmdSubSystemConfiguration getParentRemoteCmdSubSystemFactory() + { + return (IRemoteCmdSubSystemConfiguration) super.getSubSystemConfiguration(); + } + + public String getShellEncoding() + { + IPropertySet set = getPropertySet("IBM"); + if (set != null) + { + return set.getPropertyValue("shell.encoding"); + } + return null; + } + + public void setShellEncoding(String encoding) + { + IPropertySet set = getPropertySet("IBM"); + if (set == null) + { + set = createPropertySet("IBM", getDescription()); + } + set.addProperty("shell.encoding", encoding); + } + + /** + * Long running list processing calls this method to check for a user-cancel + * event. If user did cancel, an exception is thrown. + * + * @return true if caller wants to cancel + */ + public boolean checkForCancel(IProgressMonitor monitor) + { + if ((monitor != null) && monitor.isCanceled()) + throw new OperationCanceledException(SystemPlugin.getPluginMessage(ISystemMessages.MSG_OPERATION_CANCELLED) + .getLevelOneText()); + return false; + } + + // --------------------------------- + // ENVIRONMENT VARIABLE METHODS ... + // --------------------------------- + + /** + * Get the initial environment variable list as a string of + * RemoteSystemEnvVar objects. Array returned may be size zero but will not + * be null. + */ + public IRemoteSystemEnvVar[] getEnvironmentVariableList() + { + java.util.List initEVL = getEnvVars(); + IRemoteSystemEnvVar[] envl = new IRemoteSystemEnvVar[initEVL.size()]; + Iterator i = initEVL.iterator(); + int idx = 0; + while (i.hasNext()) + envl[idx++] = (IRemoteSystemEnvVar) i.next(); + return envl; + } + + /** + * Set the initial environment variable list entries, all in one shot, using + * a pair of String arrays: the first is the environment variable names, the + * second is the corresponding environment variable values. + *

    + * Note, this calls getParentSubSystemFactory().saveSubSystem(this) for you. + */ + public void setEnvironmentVariableList(String[] envVarNames, String[] envVarValues) + { + java.util.List initEVL = getEnvVars(); + initEVL.clear(); + if (envVarNames != null) + { + IRemoteSystemEnvVar rsev = null; + for (int idx = 0; idx < envVarNames.length; idx++) + { + rsev = new RemoteSystemEnvVar(); + rsev.setName(envVarNames[idx]); + rsev.setValue(envVarValues[idx]); + initEVL.add(rsev); + } + } + try + { + if (getSubSystemConfiguration() != null) + getSubSystemConfiguration().saveSubSystem(this); + } + catch (Exception exc) + { + SystemBasePlugin.logError("Error saving command subsystem after setting env var entries", exc); + } + } + + /** + * Add environment variable entry, given a name and value + */ + public void addEnvironmentVariable(String name, String value) + { + /* + * FIXME RemoteSystemEnvVar rsev = + * SubSystemFactoryImpl.getSSMOFfactory().createRemoteSystemEnvVar(); + * rsev.setName(name); rsev.setValue(value); + * addEnvironmentVariable(rsev); + */ + RemoteSystemEnvVar rsev = new RemoteSystemEnvVar(); + rsev.setName(name); + rsev.setValue(value); + addEnvironmentVariable(rsev); + return; + } + + /** + * Add environment variable entry, given a RemoteSystemEnvVar object + */ + public void addEnvironmentVariable(IRemoteSystemEnvVar rsev) + { + getEnvVars().add(rsev); + try + { + getSubSystemConfiguration().saveSubSystem(this); + } + catch (Exception exc) + { + SystemBasePlugin.logError("Error saving command subsystem after adding env var entry", exc); + } + } + + /** + * Remove environment variable entry given its RemoteSystemEnvVar object + */ + public void removeEnvironmentVariable(IRemoteSystemEnvVar rsev) + { + getEnvVars().remove(rsev); + try + { + getSubSystemConfiguration().saveSubSystem(this); + } + catch (Exception exc) + { + SystemBasePlugin.logError("Error saving command subsystem after removing env var entry", exc); + } + } + + /** + * Remove environment variable entry given only its environment variable + * name + */ + public void removeEnvironmentVariable(String name) + { + IRemoteSystemEnvVar rsev = getEnvironmentVariable(name); + if (rsev != null) + removeEnvironmentVariable(rsev); + } + + /** + * Given an environment variable name, find its RemoteSystemEnvVar object. + * Returns null if not found! + */ + public IRemoteSystemEnvVar getEnvironmentVariable(String name) + { + java.util.List envVarList = getEnvVars(); + IRemoteSystemEnvVar match = null; + Iterator i = envVarList.iterator(); + while ((match == null) && i.hasNext()) + { + IRemoteSystemEnvVar rsev = (IRemoteSystemEnvVar) i.next(); + if (rsev.getName().equals(name)) + match = rsev; + } + return match; + } + + /** + * Given an environment variable name, find its value. Returns null if not + * found. + */ + public String getEnvironmentVariableValue(String name) + { + IRemoteSystemEnvVar match = getEnvironmentVariable(name); + if (match != null) + return match.getValue(); + else + return null; + } + + /** + * + */ + protected String[] getEnvVarsAsStringArray() + { + String[] envVars = null; + IRemoteSystemEnvVar[] list = getEnvironmentVariableList(); + if (list != null && list.length > 0) + { + envVars = new String[list.length]; + for (int i = 0; i < list.length; i++) + { + String name = list[i].getName(); + if (isWindows()) + { + name = name.toUpperCase(); + } + envVars[i] = name + "=" + list[i].getValue(); + } + } + + return envVars; + } + + protected boolean isUniqueVariable(List variables, String varName) + { + for (int i = 0; i < variables.size(); i++) + { + String variableStr = (String) variables.get(i); + if (variableStr.startsWith(varName)) + { + return false; + } + } + return true; + } + + protected String[] getUserAndHostEnvVarsAsStringArray() + { + String[] userVars = getEnvVarsAsStringArray(); + List systemVars = getHostEnvironmentVariables(); + + List combinedVars = new ArrayList(); + + // add user vars first + // going in reverse order so that last set takes precedence over + // previous + // note that we currently don't support variable substituation via + // multiple user + // definitions of same variable + if (userVars != null) + { + for (int i = userVars.length - 1; i >= 0; i--) + { + String userVar = userVars[i]; + String varName = null; + int assignIndex = userVar.indexOf('='); + if (assignIndex > 0) + { + varName = userVar.substring(0, assignIndex + 1); + if (isUniqueVariable(combinedVars, varName)) + { + combinedVars.add(userVar); + } + } + } + } + + // add system vars that are unique + // any system var currently defined as user var is considered + // overridden + // note that we currently don't support variable sbustitution via user + // variable extension over system vars + for (int s = 0; s < systemVars.size(); s++) + { + String systemVar = (String) systemVars.get(s); + String varName = null; + int assignIndex = systemVar.indexOf('='); + if (assignIndex > 0) + { + varName = systemVar.substring(0, assignIndex + 1); + + if (isUniqueVariable(combinedVars, varName)) + { + combinedVars.add(systemVar); + } + } + } + + // convert to string array + String[] result = new String[combinedVars.size()]; + for (int a = 0; a < combinedVars.size(); a++) + { + result[a] = (String) combinedVars.get(a); + } + + return result; + } + + public boolean isWindows() + { + String type = getSystemType(); + return (type.equals("Windows") || type.equals("Local") + && System.getProperty("os.name").toLowerCase().startsWith("win")); + } + + /** + * Lists the possible commands for the given context + * + * @param context + * the context for a command + * @return the list of possible commands + */ + public ICandidateCommand[] getCandidateCommands(Object context) + { + if (context instanceof IRemoteCommandShell) + { + IRemoteCommandShell command = (IRemoteCommandShell) context; + return command.getCandidateCommands(); + } + return null; + } + + protected List parsePathEnvironmentVariable(String path) + { + ArrayList addedPaths = new ArrayList(); + ArrayList addedFolders = new ArrayList(); + + char separator = isWindows() ? ';' : ':'; + StringTokenizer tokenizer = new StringTokenizer(path, separator + ""); + while (tokenizer.hasMoreTokens()) + { + String token = tokenizer.nextToken(); + if (!addedPaths.contains(token)) + { + addedPaths.add(token); + + // resolve folder + IRemoteFileSubSystem fs = getFileSubSystem(); + try + { + IRemoteFile file = fs.getRemoteFileObject(token); + addedFolders.add(file); + } + catch (Exception e) + { + } + } + } + return addedFolders; + } + + public IRemoteFileSubSystem getFileSubSystem() + { + if (_fileSubSystem == null) + { + _fileSubSystem = RemoteFileUtility.getFileSubSystem(getHost()); + } + return _fileSubSystem; + } + + /** + * Default implementation of getInvalidEnvironmentVariableNameCharacters. + * This default implementation just returns "=" (the only invalid character + * is the = sign.) Subclasses can override this to provide a more + * comprehensive list. + * + * @see org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem#getInvalidEnvironmentVariableNameCharacters() + */ + public String getInvalidEnvironmentVariableNameCharacters() + { + return "="; + } + + // ------------------------------- + // SubSystem METHODS ... + // ------------------------------- + + /** + * Return the associated command subsystem. By default, returns the first + * command subsystem found for this connection, but can be refined by each + * subsystem implementation. For command subsystems, returns "this". + */ + public IRemoteCmdSubSystem getCommandSubSystem() + { + return this; + } + + /** + * Actually resolve an absolute filter string. This is called by the + * run(IProgressMonitor monitor) method, which in turn is called by + * resolveFilterString. + * + * @see org.eclipse.rse.core.subsystems.SubSystem#internalResolveFilterString(IProgressMonitor,String) + */ + protected Object[] internalResolveFilterString(IProgressMonitor monitor, String filterString) + throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException + { + return null; + } + + public Object[] getChildren() + { + return getShells(); + // return null; + } + + public boolean hasChildren() + { + if (_cmdShells == null) + return false; + return _cmdShells.size() > 0; + } + + /** + * Get the default running command shell for this command subsystem. If no + * such shell exists or is running, a new one is launched. + * + * @param shell, + * the window used for notification + * @return the default running command shell + */ + public IRemoteCommandShell getDefaultShell(Shell shell) throws Exception + { + return null; + } + + /** + * Get all command shells and transient commands that have been run or are + * running for this command subsystem. + * + * @return the list of running command shells and commands + */ + public IRemoteCommandShell[] getShells() + { + IRemoteCommandShell[] shells = new IRemoteCommandShell[_cmdShells.size()]; + for (int i = 0; i < _cmdShells.size(); i++) + { + shells[i] = (IRemoteCommandShell) _cmdShells.get(i); + } + return shells; + } + + /** + * Determine whether the command subsystem can run a shell + * + * @return whether a shell can be run or not + */ + public boolean canRunShell() + { + return true; + } + + /** + * Determine whether the command subsystem can run a command + * + * @return whether a command can be run or not + */ + public boolean canRunCommand() + { + return true; + } + + /** + * Return the object within the subsystem that corresponds to the specified + * unique ID. For remote command, the key is determined by the command ID + * and the ouput ID + */ + public Object getObjectWithAbsoluteName(String key) throws Exception + { + String cmdKey = key; + String outKey = null; + int indexOfColon = key.indexOf(':'); + if (indexOfColon > 0) + { + // get an output + cmdKey = key.substring(0, indexOfColon); + outKey = key.substring(indexOfColon + 1, key.length()); + } + + IRemoteCommandShell theCmd = null; + // get a command + IRemoteCommandShell[] cmds = getShells(); + for (int i = 0; i < cmds.length && theCmd == null; i++) + { + IRemoteCommandShell cmd = cmds[i]; + if (cmd != null && cmd.getId().equals(cmdKey)) + { + theCmd = cmd; + } + } + if (theCmd != null && outKey != null) + { + int outIndex = Integer.parseInt(outKey); + return theCmd.getOutputAt(outIndex); + } + else + { + return theCmd; + } + } + + // called by subsystem on disconnect + protected void saveShellState(List cmdShells) + { + // DKM: changing this so that only first active shell is saved + StringBuffer shellBuffer = new StringBuffer(); + boolean gotShell = false; + for (int i = 0; i < cmdShells.size() && !gotShell; i++) + { + /* + * if (i != 0) { shellBuffer.append('|'); } + */ + IRemoteCommandShell cmd = (IRemoteCommandShell) cmdShells.get(i); + if (cmd.isActive()) + { + Object context = cmd.getContext(); + if (context instanceof IRemoteFile) + { + IRemoteFile pwdf = (IRemoteFile) context; + if (pwdf != null) + { + String pwd = pwdf.getAbsolutePath(); + shellBuffer.append(pwd); + gotShell = true; + } + } + else + { + shellBuffer.append(cmd.getType()); + gotShell = true; + } + } + } + + setIBMAttribute(COMMAND_SHELLS_MEMENTO, shellBuffer.toString()); + } + + protected void internalRemoveShell(Object command) throws java.lang.reflect.InvocationTargetException, + java.lang.InterruptedException + { + if (command instanceof IRemoteCommandShell) + { + IRemoteCommandShell cmdShell = (IRemoteCommandShell) command; + if (cmdShell.isActive()) + { + internalCancelShell(null, command); + } + if (_defaultShell == command) + { + _defaultShell = null; + } + _cmdShells.remove(command); + } + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + + // tell remote shell view of removed shell + registry.fireEvent(new SystemResourceChangeEvent(command, + ISystemResourceChangeEvents.EVENT_COMMAND_SHELL_REMOVED, null)); + + // tell systems view to refresh cmd subsystem + registry.fireEvent(new SystemResourceChangeEvent(this, ISystemResourceChangeEvents.EVENT_REFRESH, this)); + } + + // called to restore running shells - behaviour determined by UI + public IRemoteCommandShell[] restoreShellState(Shell shellWindow) + { + this.shell = shellWindow; + IRemoteCommandShell[] results = null; + String shellStr = getIBMAttribute(COMMAND_SHELLS_MEMENTO); + int numShells = 0; + if (shellStr != null && shellStr.length() > 0) + { + StringTokenizer tok = new StringTokenizer(shellStr, "|"); + results = new IRemoteCommandShell[tok.countTokens()]; + + while (tok.hasMoreTokens()) + { + String context = tok.nextToken(); + if (context != null && context.length() > 0) + { + try + { + IRemoteCommandShell rmtCmd = internalRunShell(null, context); + results[numShells] = rmtCmd; + numShells++; + } + catch (Exception e) + { + } + } + } + } + + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + registry.fireEvent(new SystemResourceChangeEvent(this, ISystemResourceChangeEvents.EVENT_REFRESH, this)); + + return results; + } + + public void cancelAllShells() + { + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + for (int i = _cmdShells.size() - 1; i >= 0; i--) + { + IRemoteCommandShell cmdShell = (IRemoteCommandShell) _cmdShells.get(i); + + try + { + internalRemoveShell(cmdShell); + } + catch (Exception exc) + { + exc.printStackTrace(); + } + + } + + _cmdShells.clear(); + _defaultShell = null; + // registry.fireEvent(new + // org.eclipse.rse.model.SystemResourceChangeEvent(this, + // ISystemResourceChangeEvent.EVENT_COMMAND_SHELL_FINISHED, null)); + registry.fireEvent(new SystemResourceChangeEvent(this, ISystemResourceChangeEvents.EVENT_REFRESH, this)); + + } + + /** + * @see ICommunicationsListener#isPassiveCommunicationsListener() + */ + public boolean isPassiveCommunicationsListener() + { + return true; + } + + private class CancelAllShells implements Runnable + { + public void run() + { + cancelAllShells(); + } + } + + public class RefreshSubSystem implements Runnable + { + RemoteCmdSubSystem _ss; + + public RefreshSubSystem(RemoteCmdSubSystem ss) + { + _ss = ss; + } + + public void run() + { + SystemPlugin.getTheSystemRegistry().fireEvent( + new SystemResourceChangeEvent(_ss, ISystemResourceChangeEvents.EVENT_COMMAND_SHELL_REMOVED, _ss)); + } + + } + + public void communicationsStateChange(CommunicationsEvent e) + { + switch (e.getState()) + { + case CommunicationsEvent.AFTER_DISCONNECT: + // no longer listen + getConnectorService().removeCommunicationsListener(this); + // if (_cmdShells != null) _cmdShells.clear(); + // if (_envVars != null) _envVars.clear(); + // _defaultShell = null; + + break; + + case CommunicationsEvent.BEFORE_DISCONNECT: + case CommunicationsEvent.CONNECTION_ERROR: + // remove all shells + saveShellState(_cmdShells); + if (getShells().length > 0) + { + Display.getDefault().asyncExec(new CancelAllShells()); + // cancelAllShells(); + } + break; + default: + break; + } + } + + /** + * @generated This field/method will be replaced during code generation + */ + public java.util.List getEnvVars() + { + if (envVars == null) + { + envVars = new ArrayList();// FIXME new + // EObjectContainmenteList(RemoteSystemEnvVar.class, + // this, + // SubsystemsPackage.REMOTE_CMD_SUB_SYSTEM__ENV_VARS); + } + return envVars; + } + + /** + * overridden so that for universal we don't need to do in modal thread + */ + public Object[] runCommand(String command, Shell shell, Object context, boolean interpretOutput) throws Exception + { + if (shell != null) + this.shell = shell; + if (isConnected()) + { + return internalRunCommand(null, command, context, interpretOutput); + } + else + { + try + { + this.shell = shell; // FIXME remove this + + RunCommandJob job = new RunCommandJob(command, context, interpretOutput); + + IStatus status = scheduleJob(job, null, true); + if (status.isOK()) + { + return job.getOutputs(); + } + } + catch (InterruptedException exc) + { + if (shell == null) + throw exc; + else + showOperationCancelledMessage(shell); + } + return null; + } + } + + /** + * overridden so that for universal we don't need to do in modal thread + */ + public IRemoteCommandShell runShell(Shell shell, Object context) throws Exception + { + if (shell != null) + this.shell = shell; + IRemoteCommandShell cmdShell = null; + if (isConnected()) + { + cmdShell = internalRunShell(null, context); + } + else + { + try + { + this.shell = shell; // FIXME remove this + RunShellJob job = new RunShellJob(context); + + IStatus status = scheduleJob(job, null, true); + if (status.isOK()) + { + return (IRemoteCommandShell) job.getOutputs()[0]; + } + } + catch (InterruptedException exc) + { + if (shell == null) + throw exc; + else + showOperationCancelledMessage(shell); + } + } + + ISystemRegistry registry = SystemPlugin.getTheSystemRegistry(); + registry.fireEvent(new SystemResourceChangeEvent(this, ISystemResourceChangeEvents.EVENT_REFRESH, this)); + + return cmdShell; + } + + /** + * Execute a remote command. This is only applicable if the subsystem + * factory reports true for supportsCommands(). + * + * @param command + * Command to be executed remotely. + * @param Shell + * parent shell used to show error message. Null means you will + * handle showing the error message. + * @param Object + * context context of a command (i.e. working directory). Null is + * valid and means to use the default context. + * @return Array of objects that are the result of running this command. + * Typically, these are messages logged by the command. + */ + public Object[] runCommand(String command, Shell shell, Object context) throws Exception + { + return runCommand(command, shell, context, true); + } + + /** + * Send a command as input to a running command shell. + * + * @param String + * input the command to invoke in the shell. + * @param Shell + * parent shell used to show error message. Null means you will + * handle showing the error message. + * @param Object + * commandObject the shell or command to send the invocation to. + */ + public void sendCommandToShell(String input, Shell shell, Object commandObject) throws Exception + { + boolean ok = true; + if (!isConnected()) + ok = promptForPassword(shell); + if (ok) + { + try + { + this.shell = shell; // FIXME remove this + SendCommandToShellJob job = new SendCommandToShellJob(input, commandObject); + + IStatus status = scheduleJob(job, null, true); + if (status.isOK()) + { + return; + } + } + catch (InterruptedException exc) + { + if (shell == null) + throw exc; + else + showOperationCancelledMessage(shell); + } + } + else + SystemBasePlugin.logDebugMessage(this.getClass().getName(), + "in SubSystemImpl.sendCommandToShell: isConnected() returning false!"); + + } + + /** + * Cancel a shell or running command. + * + * @param Shell + * parent shell used to show error message. Null means you will + * handle showing the error message. + * @param Object + * commandObject the shell or command to cancel. + */ + public void cancelShell(Shell shell, Object commandObject) throws Exception + { + if (isConnected()) + { + internalCancelShell(null, commandObject); + } + else + { + boolean ok = true; + if (!isConnected()) + ok = promptForPassword(shell); + if (ok) + { + try + { + this.shell = shell; // FIXME remove this + CancelShellJob job = new CancelShellJob(commandObject); + scheduleJob(job, null, false); + } + catch (InterruptedException exc) + { + if (shell == null) + throw exc; + else + showOperationCancelledMessage(shell); + } + } + else + SystemBasePlugin.logDebugMessage(this.getClass().getName(), + "in SubSystemImpl.cancelShell: isConnected() returning false!"); + } + } + + /** + * Remove and Cancel a shell or running command. + * + * @param Shell + * parent shell used to show error message. Null means you will + * handle showing the error message. + * @param Object + * commandObject the shell or command to cancel. + */ + public void removeShell(Shell shell, Object commandObject) throws Exception + { + if (isConnected()) + { + internalRemoveShell(commandObject); + } + else + { + boolean ok = true; + if (!isConnected()) + ok = promptForPassword(shell); + if (ok) + { + try + { + this.shell = shell; // FIXME remove this + RemoveShellJob job = new RemoveShellJob(commandObject); + scheduleJob(job, null, false); + } + catch (InterruptedException exc) + { + if (shell == null) + throw exc; + else + showOperationCancelledMessage(shell); + } + } + else + SystemBasePlugin.logDebugMessage(this.getClass().getName(), + "in SubSystemImpl.removeShell: isConnected() returning false!"); + } + } + + /** + * Represents the subsystem operation of running a remote command. + */ + protected class RunCommandJob extends SubSystemOperationJob + { + protected String _cmd; + + protected Object _runContext; + + protected boolean _runInterpret; + + /** + * Creates a new RunCommandJob + * + * @param cmd + * The remote command to run + * @param runContext + * The context in which to run the command + * @param runInterpret + * Whether or not to interpret results of the command as RSE + * objects + */ + public RunCommandJob(String cmd, Object runContext, boolean runInterpret) + { + super(ShellStrings.RSESubSystemOperation_Run_command_message); + _cmd = cmd; + _runContext = runContext; + _runInterpret = runInterpret; + } + + public void performOperation(IProgressMonitor mon) throws InterruptedException, InvocationTargetException, + Exception + { + String msg = null; + int totalWorkUnits = IProgressMonitor.UNKNOWN; + + msg = getRunningMessage(_cmd); + + if (!implicitConnect(false, mon, msg, totalWorkUnits)) + throw new Exception(SystemPlugin.getPluginMessage(ISystemMessages.MSG_CONNECT_FAILED).makeSubstitution( + getHostName()).getLevelOneText()); + runOutputs = internalRunCommand(mon, _cmd, _runContext, _runInterpret); + } + } + + /** + * Represents the subsystem operation of running a remote shell. + */ + protected class RunShellJob extends SubSystemOperationJob + { + protected Object _runContext; + + /** + * Creates a new RunShellJob + * + * @param runContext + * the context within which the shell will be ran + */ + public RunShellJob(Object runContext) + { + super(ShellStrings.RSESubSystemOperation_Run_Shell_message); + _runContext = runContext; + } + + public void performOperation(IProgressMonitor mon) throws InterruptedException, InvocationTargetException, + Exception + { + String msg = null; + int totalWorkUnits = IProgressMonitor.UNKNOWN; + + if (!implicitConnect(false, mon, msg, totalWorkUnits)) + throw new Exception(SystemPlugin.getPluginMessage(ISystemMessages.MSG_CONNECT_FAILED).makeSubstitution( + getHostName()).getLevelOneText()); + runOutputs = new Object[] + { + internalRunShell(mon, _runContext) + }; + } + } + + /** + * Represents the subsystem operation of cancelling a remote shell. + */ + protected class CancelShellJob extends SubSystemOperationJob + { + protected Object _runContext; + + /** + * Constructs a new CancelShellJob + * + * @param runContext + * The context for the cancelled shell + */ + public CancelShellJob(Object runContext) + { + super(ShellStrings.RSESubSystemOperation_Cancel_Shell_message); + _runContext = runContext; + } + + public void performOperation(IProgressMonitor mon) throws InterruptedException, InvocationTargetException, + Exception + { + String msg = null; + int totalWorkUnits = IProgressMonitor.UNKNOWN; + + if (!implicitConnect(false, mon, msg, totalWorkUnits)) + throw new Exception(SystemPlugin.getPluginMessage(ISystemMessages.MSG_CONNECT_FAILED).makeSubstitution( + getHostName()).getLevelOneText()); + internalCancelShell(mon, _runContext); + } + } + + /** + * Represents the subsystem operation of sending a command to a remote + * shell. + */ + protected class SendCommandToShellJob extends SubSystemOperationJob + { + protected Object _runContext; + + protected String _cmd; + + /** + * Constructs a new SendCommandToShellJob + * + * @param cmd + * The command to send to the shell + * @param runContext + * The context in which the command is to be run + */ + public SendCommandToShellJob(String cmd, Object runContext) + { + super(ShellStrings.RSESubSystemOperation_Send_command_to_Shell_message); + _cmd = cmd; + _runContext = runContext; + } + + public void performOperation(IProgressMonitor mon) throws InterruptedException, InvocationTargetException, + Exception + { + String msg = null; + int totalWorkUnits = IProgressMonitor.UNKNOWN; + + msg = getRunningMessage(_cmd); + + if (!implicitConnect(false, mon, msg, totalWorkUnits)) + throw new Exception(SystemPlugin.getPluginMessage(ISystemMessages.MSG_CONNECT_FAILED).makeSubstitution( + getHostName()).getLevelOneText()); + internalSendCommandToShell(mon, _cmd, _runContext); + } + } + + /** + * Represents the subsystem operation of cancelling and removing a remote + * shell from the view. + */ + protected class RemoveShellJob extends SubSystemOperationJob + { + protected Object _runContext; + + /** + * Constructs a new RemoveShellJob + * + * @param runContext + * the context for the removed shell + */ + public RemoveShellJob(Object runContext) + { + super(ShellStrings.RSESubSystemOperation_Remove_Shell_message); + _runContext = runContext; + } + + public void performOperation(IProgressMonitor mon) throws InterruptedException, InvocationTargetException, + Exception + { + String msg = null; + int totalWorkUnits = IProgressMonitor.UNKNOWN; + + if (!implicitConnect(false, mon, msg, totalWorkUnits)) + throw new Exception(SystemPlugin.getPluginMessage(ISystemMessages.MSG_CONNECT_FAILED).makeSubstitution( + getHostName()).getLevelOneText()); + internalRemoveShell(_runContext); + } + } + + /** + * Actually run a remote command. This is called by the run(IProgressMonitor + * monitor) method, which in turn is called by runCommand(...). + *

    + * As per IRunnableWithProgress rules: + *

      + *
    • if the user cancels (monitor.isCanceled()), throw new + * InterruptedException() + *
    • if something else bad happens, throw new + * java.lang.reflect.InvocationTargetException(exc); + *
    • do not worry about calling monitor.done() ... caller will do that! + *
    + * YOU MUST OVERRIDE THIS IF YOU SUPPORT COMMANDS! + */ + protected Object[] internalRunCommand(IProgressMonitor monitor, String cmd, Object context) + throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException, SystemMessageException + { + return null; + } + + /** + * Actually run a remote command. This is called by the run(IProgressMonitor + * monitor) method, which in turn is called by runCommand(...). + *

    + * As per IRunnableWithProgress rules: + *

      + *
    • if the user cancels (monitor.isCanceled()), throw new + * InterruptedException() + *
    • if something else bad happens, throw new + * java.lang.reflect.InvocationTargetException(exc); + *
    • do not worry about calling monitor.done() ... caller will do that! + *
    + * YOU MUST OVERRIDE THIS IF YOU SUPPORT COMMANDS! + */ + protected Object[] internalRunCommand(IProgressMonitor monitor, String cmd, Object context, boolean interpretOutput) + throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException, SystemMessageException + { + return null; + } + + protected IRemoteCommandShell internalRunShell(IProgressMonitor monitor, Object context) + throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException, SystemMessageException + { + return null; + } + + protected void internalCancelShell(IProgressMonitor monitor, Object command) + throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException + { + } + + protected void internalSendCommandToShell(IProgressMonitor monitor, String cmd, Object command) + throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException + { + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteCmdSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteCmdSubSystemConfiguration.java new file mode 100644 index 00000000000..f08b6e41e80 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteCmdSubSystemConfiguration.java @@ -0,0 +1,200 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.shells.subsystems; + +import org.eclipse.rse.core.subsystems.SubSystemConfiguration; +import org.eclipse.rse.filters.ISystemFilter; +import org.eclipse.rse.filters.ISystemFilterPool; +import org.eclipse.rse.filters.ISystemFilterPoolManager; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystemConfiguration; + + + +public abstract class RemoteCmdSubSystemConfiguration extends SubSystemConfiguration implements IRemoteCmdSubSystemConfiguration +{ + protected String translatedType; + + + /** + * Default constructor. + */ + public RemoteCmdSubSystemConfiguration() + { + super(); + } + // -------------------------------------------- + // PARENT METHODS RELATED TO WHAT WE SUPPORT... + // -------------------------------------------- + /** + * We return true. + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#supportsUserId() + */ + public boolean supportsUserId() + { + return true; + } + /** + * We return true. + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#supportsSubSystemConnect() + */ + public boolean supportsSubSystemConnect() + { + return true; + } + + /** + * Return true if the subsystem supports more than one filter string + */ + public boolean supportsMultiStringFilters() + { + return false; + } + + /** + * Return true if the subsystem supports the exporting of filter strings from it's filters + */ + public boolean supportsFilterStringExport() + { + return false; + } + /** + * Return true if subsystems of this factory support the environment variables property. + * Return true to show it, return false to hide it. We return true. + */ + public boolean supportsEnvironmentVariablesPropertyPage() + { + return true; + } + + /** + * We return true. + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#isPortEditable() + */ + public boolean isPortEditable() + { + return true; + } + + /** + * We return true. + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#supportsCommands() + */ + public boolean supportsCommands() + { + return true; + } + /** + * We return false. + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#supportsProperties() + */ + public boolean supportsProperties() + { + return false; + } + /** + * We return true. + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#supportsFilters() + */ + public boolean supportsFilters() + { + return false; + } + /** + * We return false + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#supportsNestedFilters() + */ + public boolean supportsNestedFilters() + { + return false; + } + /** + * Tell us if filter strings are case sensitive. The default is false. + */ + public boolean isCaseSensitive() + { + return false; + } + /** + * Tell us if duplicate filter strings are supported. The default is true for command subsystem factories! + */ + public boolean supportsDuplicateFilterStrings() + { + return true; + } + + // ------------------------------------------------------ + // PARENT METHODS RELATED TO FILTERS... + // ... ONLY INTERESTING IF supportsFilters() return true! + // ------------------------------------------------------ + + /** + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#createDefaultFilterPool(ISystemFilterPoolManager) + */ + protected ISystemFilterPool createDefaultFilterPool(ISystemFilterPoolManager mgr) + { + //SystemPlugin.logDebugMessage(this.getClass().getName(),"in createDefaultFilterPool for remote file subsystem factory"); + ISystemFilterPool pool = null; + //try { + // ----------------------------------------------------- + // create a pool named filters + // ----------------------------------------------------- + // PHIL HERE: SINCE WE DON'T SHOW CMD SUBSYSTEMS BY DEFAULT, WHY BOTHER CREATING A DEFAULT POOL? + //pool = mgr.createSystemFilterPool(getDefaultFilterPoolName(mgr.getName()), true); // true=>is deletable by user + //System.out.println("Pool created"); + // --------------------------------------------------------------------------------------------- + // create default filters in that pool iff this is the user's private profile we are creating... + // --------------------------------------------------------------------------------------------- + //if (isUserPrivateProfile(mgr)) + //{ + //} + //} catch (Exception exc) + //{ + //SystemPlugin.logError("Error creating default filter pool",exc); + //} + return pool; + } + + + + + /** + * Return the translated string to show in the property sheet for the type property. + */ + public String getTranslatedFilterTypeProperty(ISystemFilter selectedFilter) + { + // do we really need this? + //if (translatedType == null) + // translatedType = SystemResources.RESID_PROPERTY_FILE_FILTER_VALUE; + return translatedType; + } + + /** + * Return in string format the character used to separate commands. Eg, ";" or "&" + */ + public String getCommandSeparator() + { + return ";"; + } + + + + + + + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteCommandShell.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteCommandShell.java new file mode 100644 index 00000000000..de59f20b641 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteCommandShell.java @@ -0,0 +1,305 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.shells.subsystems; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.Platform; +import org.eclipse.rse.core.SystemPlugin; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.model.ISystemRegistry; +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.subsystems.shells.core.subsystems.ICandidateCommand; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; + + +public abstract class RemoteCommandShell implements IAdaptable, IRemoteCommandShell +{ + + + protected String _id; + protected String _name; + protected String _type; + protected IRemoteFile _cwd; + protected ArrayList _output; + protected IRemoteFileSubSystem _fileSubSystem; + protected IRemoteCmdSubSystem _cmdSubSystem; + protected ArrayList _cmdHistory; + protected IProject _project; + + + + public RemoteCommandShell(IRemoteCmdSubSystem cmdSubSystem) + { + _output = new ArrayList(); + _cmdHistory = new ArrayList(); + _cmdSubSystem = cmdSubSystem; + } + + public void setName(String name) + { + _name = name; + } + + public String getName() + { + return _name; + } + + + + public String getId() + { + if (_id == null) + { + IRemoteCmdSubSystem subSystem = getCommandSubSystem(); + IHost connection = subSystem.getHost(); + String name = connection.getAliasName(); + + IRemoteCommandShell[] shells = subSystem.getShells(); + + List currentNames = new ArrayList(); + for (int i = 0; i < shells.length; i++) + { + IRemoteCommandShell shell = shells[i]; + if (shell != this) + { + // DKM - noticed that this caused a stack overflow in one scenario + if (shell instanceof RemoteCommandShell) + { + currentNames.add(((RemoteCommandShell)shell)._id); + } + } + } + if (currentNames.size() > 0) + { + int number = 2; + String newName = name + " " + number; + if (currentNames.contains(name)) { + while (currentNames.contains(newName)) + { + number++; + newName = name + " " + number; + } + name = newName; + } + } + _id = name; + + } + return _id; + } + + + + public void setType(String type) + { + _type = type; + } + + public String getType() + { + return _type; + } + + public Object getAdapter(Class adapterType) + { + return Platform.getAdapterManager().getAdapter(this, adapterType); + } + + public Object[] listOutput() + { + return _output.toArray(); + } + + public int getIndexOf(Object output) + { + return _output.indexOf(output); + } + + public Object getOutputAt(int index) + { + return _output.get(index); + } + + public int getSize() + { + return _output.size(); + } + + public void addOutput(Object output) + { + _output.add(output); + } + + public void removeOutput() + { + _output.clear(); + } + + public void removeOutput(Object output) + { + _output.remove(output); + } + + public IRemoteFileSubSystem getFileSubSystem() + { + if (_fileSubSystem == null) + { + if (_cmdSubSystem != null) + { + _fileSubSystem = RemoteFileUtility.getFileSubSystem(_cmdSubSystem.getHost()); + } + } + return _fileSubSystem; + } + + public IRemoteCmdSubSystem getCommandSubSystem() + { + if (_cmdSubSystem == null) + { + if (_fileSubSystem != null) + { + try + { + IHost host = _fileSubSystem.getHost(); + ISystemRegistry sr = SystemPlugin.getTheSystemRegistry(); + ISubSystem[] sses = sr.getSubSystems(host); + for (int i = 0; i < sses.length; i++) + { + if (sses[i] instanceof IRemoteCmdSubSystem) + { + IRemoteCmdSubSystem cmdSubSystem = (RemoteCmdSubSystem)sses[i]; + _cmdSubSystem = cmdSubSystem; + } + } + } + catch (Exception e) + { + } + } + } + + return _cmdSubSystem; + } + + public Object[] getRoots() + { + RemoteOutput[] results = new RemoteOutput[_output.size()]; + for (int i = 0; i < _output.size(); i++) + { + results[i] = (RemoteOutput) _output.get(i); + } + return results; + } + + public abstract String getTitle(); + + public abstract boolean isActive(); + + public void updateHistory(String cmd) + { + /* + String text = cmd; + int tagIndex = text.indexOf("BEGIN-END-TAG"); + if (tagIndex > 0) + { + text= text.substring(0, tagIndex - 6); + cmd = text; + } + */ + _cmdHistory.add(cmd); + } + + public String[] getHistory() + { + String[] cmds = null; + if (_cmdHistory.size() > 0) + { + cmds = new String[_cmdHistory.size()]; + for (int i = 0; i < cmds.length; i++) + cmds[i] = (String) _cmdHistory.get(i); + } + else + { + cmds = new String[0]; + } + return cmds; + } + + + /** + * Get the current working directory for this command + * @return the current working directory + */ + public Object getContext() + { + return _cwd; + } + + /** + * Get the current working directory for this command + * @return the current working directory + */ + public IRemoteFile getWorkingDirectory() + { + return _cwd; + } + + /** + * Set the current working directory for this command + * @param file + */ + public void setWorkingDirectory(IRemoteFile file) + { + _cwd = file; + } + + protected boolean isWindows() + { + String type = getCommandSubSystem().getHost().getSystemType(); + + return (type.equals("Windows") || + type.equals("Local") && System.getProperty("os.name").toLowerCase().startsWith("win")); + } + + + + /** + * Override to provide a list of possible commands + */ + public abstract ICandidateCommand[] getCandidateCommands(); + + + public void associateProject(IProject project) + { + _project = project; + } + + + public IProject getAssociatedProject() + { + return _project; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteError.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteError.java new file mode 100644 index 00000000000..627ea232a92 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteError.java @@ -0,0 +1,39 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.shells.subsystems; + +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteError; + +/** + * The RemoteOuputImpl class is an implementation of IRemoteOutput. + * It is used for storing information about a particular line of output + */ +public class RemoteError extends RemoteOutput implements IRemoteError +{ + + /** + * Constructor + * @param parent container of the output + */ + public RemoteError(Object parent, String type) + { + super(parent, type); + } + + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteOutput.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteOutput.java new file mode 100644 index 00000000000..6e8a49fdf6b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteOutput.java @@ -0,0 +1,208 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.shells.subsystems; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.Platform; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteOutput; + + +/** + * The RemoteOuputImpl class is an implementation of IRemoteOutput. + * It is used for storing information about a particular line of output + */ +public class RemoteOutput implements IAdaptable, IRemoteOutput +{ + + protected String _type; + protected String _text; + protected String _path; + protected int _line = 0; + protected int _startOffset = -1; + protected int _endOffset = -1; + + private Object _parent; + + /** + * Constructor + * @param parent container of the output + */ + public RemoteOutput(Object parent, String type) + { + _parent = parent; + _type = type; + } + + /** + * Sets the type of remote output + * @param type + */ + public void setType(String type) + { + _type = type; + } + + /** + * Sets the displayable text for the remote output + * @param text + */ + public void setText(String text) + { + _text = text; + } + + /** + * Sets the absolute path for an associated file if applicable + * @param path + */ + public void setAbsolutePath(String path) + { + _path = path; + } + + /** + * Sets the associated line number for a particular source if applicable + * @param line + */ + public void setLine(int line) + { + _line = line; + } + + /** + * Gets the type of this output + */ + public String getType() + { + return _type; + } + + /** + * Gets the displayable text for this output + */ + public String getText() + { + return _text; + } + + /** + * Gets the index of this object within a command object + */ + public int getIndex() + { + if (_parent instanceof IRemoteCommandShell) + { + IRemoteCommandShell cmd = (IRemoteCommandShell) _parent; + return cmd.getIndexOf(this); + } + return -1; + } + + /** + * Gets the absolute path of an associated file if applicable + */ + public String getAbsolutePath() + { + return _path; + } + + /** + * Gets the associated line within a file if applicable + */ + public int getLine() + { + return _line; + } + + /** + * Gets the containing object for this output + */ + public Object getParent() + { + return _parent; + } + + /** + * Gets the associated adapter for this output + */ + public Object getAdapter(Class adapterType) + { + return Platform.getAdapterManager().getAdapter(this, adapterType); + } + + /** + * Returns children of the output, if applicable + * @return null for this implementation + */ + public Object[] getChildren() + { + return null; + } + + /** + * Indicates whether this output has children + * @return false since there are no children + */ + public boolean hasChildren() + { + return false; + } + + /** + * Gets the displayable label for this output + * @return the label + */ + public String getLabel() + { + return getText(); + } + + /** + * set the start offset for the line + * @param offset + */ + public void setCharStart(int offset) + { + _startOffset = offset; + } + + /** + * set the end offset for the line + * @param offset + */ + public void setCharEnd(int offset) + { + _endOffset = offset; + } + + /** + * Gets the associated char start offset for the line + */ + public int getCharStart() + { + return _startOffset; + } + + /** + * Gets the associated char end offset for the line + */ + public int getCharEnd() + { + return _endOffset; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteSystemEnvVar.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteSystemEnvVar.java new file mode 100644 index 00000000000..7194dbb0f83 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/RemoteSystemEnvVar.java @@ -0,0 +1,163 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.shells.subsystems; + + + + + + + +import org.eclipse.rse.core.subsystems.IRemoteSystemEnvVar; + +/** + * Encapsulation of environment variable properties set uniquely per connection. + */ +/** + * @lastgen class RemoteSystemEnvVarImpl Impl implements RemoteSystemEnvVar {} + */ +public class RemoteSystemEnvVar implements IRemoteSystemEnvVar +{ + /** + * + * + * @generated + */ + + /** + * The default value of the '{@link #getName() Name}' attribute. + * + * + * @see #getName() + * @generated + * @ordered + */ + protected static final String NAME_EDEFAULT = null; + + /** + * @generated This field/method will be replaced during code generation. + */ + /** + * @generated This field/method will be replaced during code generation. + */ + protected String name = NAME_EDEFAULT; + /** + * The default value of the '{@link #getValue() Value}' attribute. + * + * + * @see #getValue() + * @generated + * @ordered + */ + protected static final String VALUE_EDEFAULT = null; + + /** + * @generated This field/method will be replaced during code generation. + */ + protected String value = VALUE_EDEFAULT; + /** + * The default value of the '{@link #getAdditionalAttributes() Additional Attributes}' attribute. + * + * + * @see #getAdditionalAttributes() + * @generated + * @ordered + */ + protected static final String ADDITIONAL_ATTRIBUTES_EDEFAULT = null; + + /** + * @generated This field/method will be replaced during code generation. + */ + protected String additionalAttributes = ADDITIONAL_ATTRIBUTES_EDEFAULT; + /** + * @generated This field/method will be replaced during code generation. + */ + public RemoteSystemEnvVar() + { + super(); + } + + /** + * @generated This field/method will be replaced during code generation + * The name of the environment variable to set at connect time + */ + public String getName() + { + return name; + } + + /** + * @generated This field/method will be replaced during code generation. + */ + public void setName(String newName) + { + name = newName; + } + + /** + * @generated This field/method will be replaced during code generation + * The value to set this environment variable to at connect time + */ + public String getValue() + { + return value; + } + + /** + * @generated This field/method will be replaced during code generation. + */ + public void setValue(String newValue) + { + value = newValue; + } + + /** + * @generated This field/method will be replaced during code generation + * Additional attributes that may need to be persisted per environment variable. + */ + public String getAdditionalAttributes() + { + return additionalAttributes; + } + + /** + * @generated This field/method will be replaced during code generation. + */ + public void setAdditionalAttributes(String newAdditionalAttributes) + { + additionalAttributes = newAdditionalAttributes; + } + + /** + * @generated This field/method will be replaced during code generation. + */ + public String toString() + { + + + StringBuffer result = new StringBuffer(super.toString()); + result.append(" (name: "); + result.append(name); + result.append(", value: "); + result.append(value); + result.append(", additionalAttributes: "); + result.append(additionalAttributes); + result.append(')'); + return result.toString(); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/SystemRemoteCommand.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/SystemRemoteCommand.java new file mode 100644 index 00000000000..d76b5a38166 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/SystemRemoteCommand.java @@ -0,0 +1,154 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.shells.subsystems; + +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.subsystems.files.core.model.ISystemRemoteCommand; +import org.eclipse.rse.subsystems.files.core.model.ISystemRemoteCommandMessage; + + + +/** + * A remote command with the command string, messages retrieved, and possibly additional information + */ +public class SystemRemoteCommand implements ISystemRemoteCommand { + + + + private String cmd = null; + private String info = null; + private Object object = null; + private ISystemRemoteCommandMessage[] msgs = null; + private ISubSystem subSys; + + + public SystemRemoteCommand(String cmd, String[] msgsText) + { + this(cmd, msgsText, null, null); + } + + public SystemRemoteCommand(String cmd, String[] msgsText, ISubSystem subSys) + { + this(cmd, msgsText, null, subSys); + } + + public SystemRemoteCommand(String cmd, String[] msgsText, String[] msgsHelp) + { + this(cmd, msgsText, msgsHelp, null); + } + + public SystemRemoteCommand(String cmd, String[] msgsText, String[] msgsHelp, ISubSystem subSys) + { + this.cmd = cmd; + this.subSys = subSys; + if ( msgsText != null ) + { + this.msgs = new SystemRemoteCommandMessage[ msgsText.length ]; + for ( int i = 0; i < msgsText.length; i++) + { + String msgHelp = null; + if ( msgsHelp != null && msgsHelp[i] != null ) + msgHelp = msgsHelp[i]; + this.msgs[i] = new SystemRemoteCommandMessage(msgsText[i], msgHelp ); + } + } + } + + + public SystemRemoteCommand(String cmd, ISystemRemoteCommandMessage[] msgs) + { + this(cmd, msgs, null); + } + + public SystemRemoteCommand(String cmd, ISystemRemoteCommandMessage[] msgs, ISubSystem subSys) + { + this.cmd = cmd; + this.msgs = msgs; + this.subSys = subSys; + } + + + /** + * @return command string + */ + public String getCommand() + { + return cmd; + } + + /** + * @return any additional information that has been set for the command + */ + public String getInfo() + { + return info; + } + + /** + * @return any additional object that has been set for the command + */ + public Object getObject() + { + return object; + } + + /** + * @return the subsystem the command is run on + */ + public ISubSystem getSubSystem() + { + return subSys; + } + + /** + * @return the messages retrieved by running the command + */ + public ISystemRemoteCommandMessage[] getMessages() + { + return msgs; + } + + public void setSubSystem(ISubSystem sys) + { + subSys = sys; + } + + public void setInfo(String info) + { + this.info = info; + } + + public void setObject(Object object) + { + this.object = object; + } + + public String toString() + { + StringBuffer text = new StringBuffer(); + text.append( cmd + '\n'); + for ( int j = 0; j < msgs.length; j++) + { + text.append( msgs[j].getMessageText() + '\n' ); + String msgHelp = msgs[j].getMessageHelp(); + if ( msgHelp != null ) + text.append( msgHelp + '\n' ); + } + return text.toString(); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/SystemRemoteCommandMessage.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/SystemRemoteCommandMessage.java new file mode 100644 index 00000000000..b8aef97b7cb --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/internal/subsystems/shells/subsystems/SystemRemoteCommandMessage.java @@ -0,0 +1,45 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.internal.subsystems.shells.subsystems; + +import org.eclipse.rse.subsystems.files.core.model.ISystemRemoteCommandMessage; + +public class SystemRemoteCommandMessage + implements ISystemRemoteCommandMessage { + + + + private String msg; + private String help; + + public SystemRemoteCommandMessage(String msg, String help) + { + this.msg = msg; + this.help = help; + } + + public String getMessageText() + { + return msg; + } + + public String getMessageHelp() + { + return help; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/Activator.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/Activator.java new file mode 100644 index 00000000000..c3bd7be543b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/Activator.java @@ -0,0 +1,70 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core; + +import org.eclipse.ui.plugin.*; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class Activator extends AbstractUIPlugin { + + //The shared instance. + private static Activator plugin; + + /** + * The constructor. + */ + public Activator() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static Activator getDefault() { + 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.subsystems.shells.core", path); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/ShellStrings.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/ShellStrings.java new file mode 100644 index 00000000000..6c598cfee9a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/ShellStrings.java @@ -0,0 +1,39 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core; + +import org.eclipse.osgi.util.NLS; + +public class ShellStrings extends NLS +{ + private static String BUNDLE_NAME = "org.eclipse.rse.subsystems.shells.core.ShellStrings"; + + public static String RESID_SHELLS_COMMAND_SHELL_LABEL; + public static String RSESubSystemOperation_Cancel_Shell_message; + public static String RSESubSystemOperation_Remove_Shell_message; + public static String RSESubSystemOperation_Run_command_message; + public static String RSESubSystemOperation_Run_Shell_message; + public static String RSESubSystemOperation_Send_command_to_Shell_message; + public static String RSESubSystemOperation_Refresh_Output; + + static + { + // load message values from bundle file + NLS.initializeMessages(BUNDLE_NAME, ShellStrings.class); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/ShellStrings.properties b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/ShellStrings.properties new file mode 100644 index 00000000000..2f75f5b4ed6 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/ShellStrings.properties @@ -0,0 +1,24 @@ +################################################################################ +# Copyright (c) 2006 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: +# {Name} (company) - description of contribution. +################################################################################ + + +RESID_SHELLS_COMMAND_SHELL_LABEL = Command Shell +RSESubSystemOperation_Cancel_Shell_message = Cancel Shell +RSESubSystemOperation_Remove_Shell_message = Remove Shell +RSESubSystemOperation_Run_command_message = Run command +RSESubSystemOperation_Run_Shell_message = Run Shell +RSESubSystemOperation_Send_command_to_Shell_message = Send command to Shell +RSESubSystemOperation_Refresh_Output = Refresh Output \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/ISystemOutputRemoteTypes.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/ISystemOutputRemoteTypes.java new file mode 100644 index 00000000000..73ce0478dcf --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/ISystemOutputRemoteTypes.java @@ -0,0 +1,101 @@ +/******************************************************************************** + * Copyright (c) 2000, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core.model; +/** + * All remote object types we support. + * These can be used when registering property pages against remote output objects. + */ +public interface ISystemOutputRemoteTypes +{ + + // ------------------ + // TYPE CATEGORIES... + // ------------------ + + /** + * There is only one type category for remote output. + * It is "output". + */ + public static final String TYPECATEGORY = "output"; + + + // ----------- + // TYPES... + // ----------- + + /** + * A folder object + */ + public static final String TYPE_DIRECTORY = "directory"; + + /** + * A file object + */ + public static final String TYPE_FILE = "file"; + + /** + * A command object + */ + public static final String TYPE_COMMAND = "command"; + + /** + * A prompt object + */ + public static final String TYPE_PROMPT = "prompt"; + + /** + * An error object + */ + public static final String TYPE_ERROR = "error"; + + /** + * A warning object + */ + public static final String TYPE_WARNING = "warning"; + + /** + * An informational object + */ + public static final String TYPE_INFORMATIONAL = "informational"; + + /** + * A grep object + */ + public static final String TYPE_GREP = "grep"; + + + /** + * An environment variable object + */ + public static final String TYPE_ENVVAR = "envvar"; + + /** + * A libpath environment variable object + */ + public static final String TYPE_ENVVAR_LIBPATH = "libpathenvvar"; + + /** + * The path environment variable object + */ + public static final String TYPE_ENVVAR_PATH = "pathenvvar"; + + /** + * A process object + */ + public static final String TYPE_PROCESS = "process"; + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/RemoteCommandFilterString.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/RemoteCommandFilterString.java new file mode 100644 index 00000000000..65e42be0d96 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/RemoteCommandFilterString.java @@ -0,0 +1,166 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core.model; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystemConfiguration; + + +/** + * A string representing a filter sent to remote file subsystems. + *

    + * Filters can be absolute or relative. Absolute contains a folder path, while relative do not. + *

    + * The files can be filtered by name, or by a list of file types. If by name, it can have + * up to 2 asterisks anywhere in the name for wildcarding. If by types, multiple types can + * by specified. The types are the file extensions without the dot, as in "java" or "class". + *

    + * Examples: + *

      + *
    • Absolute file name filter: d:\mystuff\phil*.abc + *
    • Relative file name filter: phil*.abc + *
    • Absolute file type filter: d:\mystuff\java,class, + *
    • Relative file type filter: java,class, + *

      + * Syntactically, file type filter strings have at least one comma. + * Note that the file name filter string "*.java" is semantically the same + * as a type filter string "java,". Either one can be used and will get + * the same results. However, if you specify "java" you will be in trouble, + * as it will mean look for a file explicitly named "java". + *

      + * It is invalid to have both a comma and an asterisk in the same filter string. + * It is also invalid to have both a comma and a period in the same filter string. + */ +public class RemoteCommandFilterString implements Cloneable +{ + protected String shellStr; + protected String[] types; + protected boolean filterByTypes; + + /** + * Constructor to use for a filter to list roots when used absolutely, or list all contents + * when used relatively. + */ + public RemoteCommandFilterString() + { + shellStr = "*"; + } + /** + * Constructor to use when there is no existing filter string. + *

      + * This constructor is better that the default constructor, because it takes a remote file subsystem + * factory, from which we can query the folder and path separator characters, which are needed + * to parse and re-build filter strings. + * @see #setTypes(String[]) + */ + public RemoteCommandFilterString(IRemoteCmdSubSystemConfiguration subsysFactory) + { + shellStr = "*"; + } + /** + * Constructor to use when an absolute filter string already exists. + */ + public RemoteCommandFilterString(IRemoteCmdSubSystemConfiguration subsysFactory, String input) + { + this(subsysFactory); + } + /** + * Constructor to use when you have a path and filename filter or comma-separated file types list. + * In the latter case, the last char must be a TYPE_SEP or comma, even for a single type. + */ + public RemoteCommandFilterString(IRemoteCmdSubSystemConfiguration subsysFactory, String path, String input) + { + this(subsysFactory); + } + + public void setSubSystemFactory(IRemoteCmdSubSystemConfiguration subsysFactory) + { + } + + /** + * Set the file types to subset by. These are extensions, without the dot, as + * in java, class, gif, etc. + * You either call this or setFile! + */ + public void setTypes(String[] types) + { + this.types = types; + filterByTypes = (types != null); + } + + + /** + * Concatenate the given file types as a single string, each type comma-separated + */ + public static String getTypesString(String[] typesArray) + { + StringBuffer typesBuffer = new StringBuffer(""); + for (int idx=0; idx 0) + { + CommandAlias firstCommand = (CommandAlias)_commandStack.firstElement(); + return firstCommand.getCommand(); + } + return null; + } + + /** + * Send a command to the running command shell. + * @param cmd the command to run in the shell + */ + public void sendCommand(String cmd) + { + if (_remoteCmdShell != null) + { + try + { + String newId = String.valueOf(_random.nextInt()); + CommandAlias alias = new CommandAlias(newId, cmd); + _commandStack.push(alias); + String echoCmd = getEchoCmd(alias); + + // echo command appended after ; so that + // it isn't treated like stdin for the intial command + _cmdSubSystem.sendCommandToShell(cmd + _cmdSeparator + echoCmd, getShell(), _remoteCmdShell); + + } + catch (Exception e) + { + } + } + } + + /** + * Send input to the running command shell. The input is treated as input to + * a running program - rather than a new command. As such, no echos are used + * and it's not logged for completion. + * @param input the input to send to the running program + */ + public void sendInput(String input) + { + if (_remoteCmdShell != null) + { + try + { + _cmdSubSystem.sendCommandToShell(input, getShell(), _remoteCmdShell); + + } + catch (Exception e) + { + } + } + } + + + public Shell getShell() + { + if (_shell.isDisposed()) + { + _shell = SystemBasePlugin.getActiveWorkbenchShell(); + } + return _shell; + } + + + + /** + * Indicates whether the command shell is active or not + * @return true if the command shell is running + */ + public boolean isActive() + { + if (_remoteCmdShell != null) + { + return _remoteCmdShell.isActive() && _cmdSubSystem.isConnected(); + } + return false; + } + + /* + * Check for remote changes + */ + public void systemResourceChanged(ISystemResourceChangeEvent event) + { + if (event.getType() == ISystemResourceChangeEvents.EVENT_COMMAND_SHELL_FINISHED) + { + Object source = event.getSource(); + if (source == _cmdSubSystem) + { + handleShellFinished(); + } + else if (source == _remoteCmdShell) + { + handleShellFinished(); + } + } + else if (event.getType() == ISystemResourceChangeEvents.EVENT_REFRESH) + { + Object parent = event.getParent(); + if (parent == _remoteCmdShell) + { + outputUpdated(); + } + } + } + + /** + * Called whenever output is retrieved from the host + */ + public void outputUpdated() + { + // check for command completion + synchronized(_commandStack) + { + if (!_commandStack.empty()) + { + Object[] outputs = _remoteCmdShell.listOutput(); + synchronized(outputs) + { + for (int i = _outputOffset; i < outputs.length && !_commandStack.empty(); i++) + { + boolean handledOutput = false; + + CommandAlias firstCommand = (CommandAlias)_commandStack.firstElement(); + + Object output = outputs[_outputOffset]; + if (output instanceof IRemoteOutput) + { + IRemoteOutput rmtOutput = (IRemoteOutput)output; + String text = rmtOutput.getText(); + if (commandMatches(text, firstCommand)) + { + _commandStack.remove(0); + handleCommandFinished(firstCommand.getCommand()); + handledOutput = true; + } + } + if (!handledOutput) + { + handleOutputChanged(firstCommand.getCommand(), output); + } + _outputOffset++; + } + } + + } + } + } + + protected boolean commandMatches(String outputEcho, CommandAlias firstCommand) + { + String expected = getEchoResult(firstCommand); + if (outputEcho.equals(expected)) + { + return true; + } + else + { + int index = outputEcho.indexOf(expected); + if (index > 0) + { + if (outputEcho.charAt(index - 1) != ';' && (outputEcho.indexOf("echo") == -1)) + { + return true; + } + } + } + + return false; + } + + /* + * Called when the shell is complete + */ + public void handleShellFinished() + { + finish(); + } + + /* + * Called when the specified command is complete + * @param cmd the completed command + */ + public abstract void handleCommandFinished(String cmd); + + /* + * Called whenever output has changed + * @param command the current command + * @param output the new output object + */ + public abstract void handleOutputChanged(String command, Object output); + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/RemoteCommandShellOperationManager.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/RemoteCommandShellOperationManager.java new file mode 100644 index 00000000000..1183203596c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/RemoteCommandShellOperationManager.java @@ -0,0 +1,75 @@ +/******************************************************************************** + * Copyright (c) 2004, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core.model; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; + + +/** + * class for managing sets of remote command shell operations. + */ +public class RemoteCommandShellOperationManager +{ + protected List _commandShellOperations; + protected static RemoteCommandShellOperationManager _instance= new RemoteCommandShellOperationManager(); + + protected RemoteCommandShellOperationManager() + { + _commandShellOperations = new ArrayList(); + } + + public static RemoteCommandShellOperationManager getInstance() + { + return _instance; + } + + public RemoteCommandShellOperation findRemoteCommandShellOperation(IRemoteCmdSubSystem ss, IProject project, Class type) + { + for (int i = 0; i < _commandShellOperations.size();i++) + { + RemoteCommandShellOperation op = (RemoteCommandShellOperation)_commandShellOperations.get(i); + if (op.isActive()) + { + if (op.getClass() == type) + { + IRemoteCommandShell rmtShell = op.getRemoteCommandShell(); + if (rmtShell.getCommandSubSystem() == ss && rmtShell.getAssociatedProject() == project) + { + return op; + } + } + } + else + { + _commandShellOperations.remove(op); + } + } + + return null; + } + + public void registerRemoteCommandShellOperation(RemoteCommandShellOperation newOp) + { + _commandShellOperations.add(newOp); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/SimpleCommandOperation.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/SimpleCommandOperation.java new file mode 100644 index 00000000000..14ea7054608 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/model/SimpleCommandOperation.java @@ -0,0 +1,130 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core.model; + + +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteOutput; +import org.eclipse.swt.widgets.Display; + + +public class SimpleCommandOperation +{ + private IRemoteCmdSubSystem _subsystem; + private IRemoteFile _workingDirectory; + private IRemoteCommandShell _cmdShell; + private int _outputLineIndex = 0; + + public SimpleCommandOperation(IRemoteCmdSubSystem subsystem, IRemoteFile workingDirectory) + { + _subsystem = subsystem; + _workingDirectory = workingDirectory; + } + + public void runCommand(String command) throws Exception + { + Object[] result =_subsystem.runCommand(command, null, _workingDirectory, false); + _cmdShell = (IRemoteCommandShell)result[0]; + } + + public void putInput(String input) throws Exception + { + if (isActive()) + { + _subsystem.sendCommandToShell(input, null, _cmdShell); + } + } + + public boolean isActive() + { + if (_cmdShell != null) + { + return _cmdShell.isActive(); + } + return false; + } + + protected boolean hasMoreOutput() + { + if (_cmdShell != null) + { + + if (_cmdShell.listOutput().length > _outputLineIndex) + { + return true; + } + } + return false; + } + + public void cancelCommand() throws Exception + { + if (_cmdShell != null && _cmdShell.isActive()) + { + _cmdShell.getCommandSubSystem().cancelShell(null, _cmdShell); + } + } + + + public String readLine(boolean waitForOutput) + { + if (_cmdShell != null) + { + if (!hasMoreOutput() && waitForOutput) + { + while (!hasMoreOutput()) + { + if (!isActive()) + { + return null; + } + try + { + Display d = Display.getCurrent(); + if (d != null) + { + while (d.readAndDispatch()); + } + Thread.sleep(100); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + } + + { + Object output = _cmdShell.getOutputAt(_outputLineIndex); + _outputLineIndex++; + if (output instanceof IRemoteOutput) + { + return ((IRemoteOutput)output).getText(); + } + else if (output instanceof IRemoteFile) + { + return ((IRemoteFile)output).getLabel(); + } + + } + } + return ""; + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/ICandidateCommand.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/ICandidateCommand.java new file mode 100644 index 00000000000..89c59134fc8 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/ICandidateCommand.java @@ -0,0 +1,60 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core.subsystems; + +import org.eclipse.jface.resource.ImageDescriptor; + +/** + * This interface represents a candidate command. A candidate command is a command that can be + * run in a command subsystem. The command subsystem api, getCandidateCommands(), returns a list + * of candidate commands. The primary use of candidate commands is for command line content assist. + * Implement this interface to provide unique command candidates for a particular command subsystem. + */ +public interface ICandidateCommand +{ + + /** + * Gets the name of the candidate command + * @return the name of the candidate command + */ + public String getName(); + + /** + * Gets the type of the candidate command. + * @return the type of the command + */ + public String getType(); + + /** + * Gets the description for a candidate command. + * @return the description of the command + */ + public String getDescription(); + + /** + * Gets the image descriptor to display for a candidate command + * @return the image descriptor for the command + */ + public ImageDescriptor getImageDescriptor(); + + /** + * Gets the path for a candidate command + * @return the path of the command if one exists + */ + public String getPath(); + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteCmdSubSystem.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteCmdSubSystem.java new file mode 100644 index 00000000000..f43164e299e --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteCmdSubSystem.java @@ -0,0 +1,220 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core.subsystems; + +// + + +import java.util.List; + +import org.eclipse.rse.core.subsystems.IRemoteSystemEnvVar; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.swt.widgets.Shell; + +/** + * @lastgen interface RemoteCmdSubSystem extends SubSystem {} + */ + +public interface IRemoteCmdSubSystem extends ISubSystem{ + + + + + /** + * Return parent subsystem factory, cast to a RemoteCmdSubSystemFactory + */ + public IRemoteCmdSubSystemConfiguration getParentRemoteCmdSubSystemFactory(); + + /** + * Execute a remote command. This is only applicable if the subsystem factory reports + * true for supportsCommands(). + * @param command Command to be executed remotely. + * @param Shell parent shell used to show error message. Null means you will handle showing the error message. + * @param Object context context of a command (i.e. working directory). Null is valid and means to run the + * command as a shell command in the default shell. + * @return Array of objects that are the result of running this command. Typically, these + * are messages logged by the command. + * @see org.eclipse.rse.core.subsystems.shells.ui.RemoteCommandHelpers + */ + public Object[] runCommand(String command, Shell shell, Object context) throws Exception; + + /** + * Execute a remote command. This is only applicable if the subsystem factory reports + * true for supportsCommands(). + * @param command Command to be executed remotely. + * @param Shell parent shell used to show error message. Null means you will handle showing the error message. + * @param Object context context of a command (i.e. working directory). Null is valid and means to run the + * command as a shell command in the default shell. + * @param interpretOutput whether to interpret the output or not + * @return Array of objects that are the result of running this command. Typically, these + * are messages logged by the command. + * @see org.eclipse.rse.core.subsystems.shells.ui.RemoteCommandHelpers + */ + public Object[] runCommand(String command, Shell shell, Object context, boolean interpretOutput) throws Exception; + + + /** + * Launch a new command shell. This is only applicable if the subsystem factory reports + * true for supportsCommands(). + * @param Shell parent shell used to show error message. Null means you will handle showing the error message. + * @param Object context context of a shell (i.e. working directory). Null is valid and means to use the default context. + * @return An object that represents the command and it's output. + * @see org.eclipse.rse.core.subsystems.shells.ui.RemoteCommandHelpers + */ + public IRemoteCommandShell runShell(Shell shell, Object context) throws Exception; + + + /** + * Send a command as input to a running command shell. + * @param String input the command to invoke in the shell. + * @param Shell parent shell used to show error message. Null means you will handle showing the error message. + * @param Object commandObject the shell or command to send the invocation to. + * @see org.eclipse.rse.core.subsystems.shells.ui.RemoteCommandHelpers + */ + public void sendCommandToShell(String input, Shell shell, Object commandObject) throws Exception; + + /** + * Cancel a shell or running command. + * @param Shell parent shell used to show error message. Null means you will handle showing the error message. + * @param Object commandObject the shell or command to cancel. + */ + public void cancelShell(Shell shell, Object commandObject) throws Exception; + + /** + * Remove a shell. If the shell is running cancel it first. + * @param Shell parent shell used to show error message. Null means you will handle showing the error message. + * @param Object commandObject the shell or command to cancel & remove. + */ + public void removeShell(Shell shell, Object commandObject) throws Exception; + + /** + * Get the default running command shell for this command subsystem. If no such shell exists or is running, a new one is launched. + * @param shell a window used for notification + * @return the default running command shell + */ + public IRemoteCommandShell getDefaultShell(Shell shell) throws Exception; + + /** + * Get all command shells and transient commands that have been run or are running for this command subsystem. + * @return the list of running command shells and commands + */ + public IRemoteCommandShell[] getShells(); + + /** + * Restore all the command shells that were open before disconnecting during + * the previous session + * @param shell a window used for notification + * @return the command shells that were restored + */ + public IRemoteCommandShell[] restoreShellState(Shell shell); + + /** + * Determine whether the command subsystem can run a shell + * @return whether a shell can be run or not + */ + public boolean canRunShell(); + + /** + * Determine whether the command subsystem can run a command + * @return whether a command can be run or not + */ + public boolean canRunCommand(); + + + /** + * Provide list of executed commands on subsystem.This is only applicable if the subsystem factory reports + * true for supportsCommands(). + */ + public String[] getExecutedCommands(); + + + /** + * Returns the shell encoding to assume when reading IO from a remote shell + */ + public String getShellEncoding(); + + + /** + * Provide a list of possible commands for the specified context. This method is primarily used + * for command line assist to get a list of possible command completions. Typically the context is + * a handle to a shell or command, such as an IRemoteCommandShell, but the interface is left generic, with Object, + * because some command subsystems have different notions of context. + * + * @param context the context for the possible commands + * @return a list of possible commands + */ + public ICandidateCommand[] getCandidateCommands(Object context); + + // ---------------------------------------- + // ENVIRONMENT VARIABLE METHODS ... + // ---------------------------------------- + /** + * Get the initial environment variable list as a string of RemoteSystemEnvVar objects. + * Array returned may be size zero but will not be null. + */ + public IRemoteSystemEnvVar[] getEnvironmentVariableList(); + /** + * Set the initial environment variable list entries, all in one shot, using + * a pair of String arrays: the first is the environment variable names, + * the second is the corresponding environment variable values. + */ + public void setEnvironmentVariableList(String[] envVarNames, String[] envVarValues); + /** + * Add environment variable entry, given a name and value + */ + public void addEnvironmentVariable(String name, String value); + /** + * Add environment variable entry, given a RemoteSystemEnvVar object + */ + public void addEnvironmentVariable(IRemoteSystemEnvVar rsev); + /** + * Remove environment variable entry given its RemoteSystemEnvVar object + */ + public void removeEnvironmentVariable(IRemoteSystemEnvVar rsev); + /** + * Remove environment variable entry given only its environment variable name + */ + public void removeEnvironmentVariable(String name); + /** + * Given an environment variable name, find its RemoteSystemEnvVar object. + * Returns null if not found! + */ + public IRemoteSystemEnvVar getEnvironmentVariable(String name); + /** + * Given an environment variable name, find its value. + * Returns null if not found. + */ + public String getEnvironmentVariableValue(String name); + + /** + * Get the invalid characters for an environment variable name. Used + * by the environment variables property page to diagnose invalid + * environment variable names. + */ + public String getInvalidEnvironmentVariableNameCharacters(); + + /** + * Private. Do not override or call. + * @generated This field/method will be replaced during code generation + * @return The list of EnvVars references + */ + java.util.List getEnvVars(); + + public List getHostEnvironmentVariables(); + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteCmdSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteCmdSubSystemConfiguration.java new file mode 100644 index 00000000000..c3b2a4ba8eb --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteCmdSubSystemConfiguration.java @@ -0,0 +1,43 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core.subsystems; + +import org.eclipse.rse.core.subsystems.ISubSystemConfiguration; + + + +// +/** + * @lastgen interface RemoteCmdSubSystemFactory extends SubSystemFactory {} + */ +public interface IRemoteCmdSubSystemConfiguration extends ISubSystemConfiguration +{ + + /** + * Return true if subsystems of this factory support the environment variables property. + * Return true to show it, return false to hide it. + */ + public boolean supportsEnvironmentVariablesPropertyPage(); + + + /** + * Return in string format the character used to separate commands. Eg, ";" or "&" + */ + public String getCommandSeparator(); + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteCommandShell.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteCommandShell.java new file mode 100644 index 00000000000..0a9acae4300 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteCommandShell.java @@ -0,0 +1,143 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core.subsystems; + +import org.eclipse.core.resources.IProject; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; + + +/** + * This interface represents a handle to a remote command, + * which is either a transient command or a command shell. + */ +public interface IRemoteCommandShell +{ + + /** + * Gets the ID of the command shell + * @return the id + */ + public String getId(); + + + /** + * Gets the name of the command shell or command that is being run. + * @return the name of the command + */ + public String getName(); + + /** + * Gets the type of the command shell or command that is being run. The type may either be a "Shell" or a "Command". + * @return the type of the command + */ + public String getType(); + + /** + * Get the list of output objects for this command. + * @return the list of output objects + */ + public Object[] listOutput(); + + /** + * Get the current context for this command shell. In the case of a unix shell, this + * will be the working directory + * @return the current context + */ + public Object getContext(); + + + /** + * Return the number of output objects for this command. + * @return the number of output objects + */ + public int getSize(); + + /** + * Return the file subsystem associated with this command + * @return the file subsystem associated with this command + */ + public IRemoteFileSubSystem getFileSubSystem(); + + /** + * Return the command subsystem associated with this command + * @return the command subsystem associated with this command + */ + public IRemoteCmdSubSystem getCommandSubSystem(); + + + /* + * Set the associated project for this command shell. The + * associated project is looked up first when resolving files + * from shell (i.e. during double click on errors) + * @param the project to associate with this shell + */ + public void associateProject(IProject project); + + /* + * Return the associated project for this command shell. The + * associated project is looked up first when resolving files + * from shell (i.e. during double click on errors) + * @return the associated project for this command shell + */ + public IProject getAssociatedProject(); + + /** + * Add an output object to the list of output for this command + * @param output the output object to add + */ + public void addOutput(Object output); + + /** + * Remove output from the list of output for this command + */ + public void removeOutput(); + + /** + * Remove output from the list of output for this command + */ + public void removeOutput(Object output); + + /** + * Get the position of this output object in the command container + */ + public int getIndexOf(Object output); + + /** + * Get the output object the specified index + */ + public Object getOutputAt(int index); + + /** + * Indicate whether the corresponding command is running or not + * @return whether the command is running or not + */ + public boolean isActive(); + + /** + * Return the list of commands passed into this command + * @return the list of commands issued + */ + public String[] getHistory(); + + public void updateHistory(String cmd); + + /** + * Return the list of possible commands for this command shell + * @return the list of possible commands + */ + public ICandidateCommand[] getCandidateCommands(); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteError.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteError.java new file mode 100644 index 00000000000..70fd3df8ca1 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteError.java @@ -0,0 +1,23 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core.subsystems; +/** + * This interface represents a handle to a line of remote command error. + */ +public interface IRemoteError extends IRemoteOutput +{ +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteOutput.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteOutput.java new file mode 100644 index 00000000000..ad6052e716d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/IRemoteOutput.java @@ -0,0 +1,52 @@ +/******************************************************************************** + * Copyright (c) 2002, 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core.subsystems; + +import org.eclipse.rse.core.subsystems.IRemoteLineReference; + +/** + * This interface represents a handle to a line of remote command output. + */ +public interface IRemoteOutput extends IRemoteLineReference +{ + + + /** + * Gets the type of a line of output. By default remote output is "stdout", but it could be one of a + * number of things (i.e. "error", "warning", "file", "directory", "grep", etc.) + * + * @return the output type + */ + public String getType(); + + /** + * Gets the text to display for a line of output. + * + * @return the output text + */ + public String getText(); + + /** + * Gets the index of this output within a command + * + * @return the index within the command + */ + public int getIndex(); + + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/IServiceCommandShell.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/IServiceCommandShell.java new file mode 100644 index 00000000000..6688c1e805e --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/IServiceCommandShell.java @@ -0,0 +1,28 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem; + +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IHostShellOutputListener; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; + + +public interface IServiceCommandShell extends IRemoteCommandShell, IHostShellOutputListener +{ + public IHostShell getHostShell(); + public void writeToShell(String cmd); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/IShellServiceSubSystem.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/IShellServiceSubSystem.java new file mode 100644 index 00000000000..6254bd7d147 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/IShellServiceSubSystem.java @@ -0,0 +1,29 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem; + + +import org.eclipse.rse.core.servicesubsystem.IServiceSubSystem; +import org.eclipse.rse.services.shells.IShellService; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; + + + +public interface IShellServiceSubSystem extends IRemoteCmdSubSystem, IServiceSubSystem +{ + public IShellService getShellService(); +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/IShellServiceSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/IShellServiceSubSystemConfiguration.java new file mode 100644 index 00000000000..6121e3b6898 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/IShellServiceSubSystemConfiguration.java @@ -0,0 +1,37 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem; + + +import org.eclipse.rse.core.servicesubsystem.IServiceSubSystemConfiguration; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IShellService; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystemConfiguration; + + +/** + * @lastgen interface DefaultCmdSubSystemFactory extends RemoteCmdSubSystemFactory {} + */ +public interface IShellServiceSubSystemConfiguration extends IRemoteCmdSubSystemConfiguration, IServiceSubSystemConfiguration +{ + public IShellService getShellService(IHost host); + public IShellService createShellService(IHost host); + public IServiceCommandShell createRemoteCommandShell(IRemoteCmdSubSystem cmdSS, IHostShell hostShell); + +} //DefaultCmdSubSystemFactory \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/ServiceCommandShell.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/ServiceCommandShell.java new file mode 100644 index 00000000000..08cb1d3a3d9 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/ServiceCommandShell.java @@ -0,0 +1,109 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem; + +import org.eclipse.rse.internal.subsystems.shells.servicesubsystem.OutputRefreshJob; +import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteCommandShell; +import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteError; +import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteOutput; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IHostShellChangeEvent; +import org.eclipse.rse.subsystems.shells.core.ShellStrings; +import org.eclipse.rse.subsystems.shells.core.subsystems.ICandidateCommand; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteOutput; + + +public class ServiceCommandShell extends RemoteCommandShell implements IServiceCommandShell +{ + protected IHostShell _hostShell; + protected OutputRefreshJob _lastRefreshJob; + public ServiceCommandShell(IRemoteCmdSubSystem cmdSS, IHostShell hostShell) + { + super(cmdSS); + _hostShell = hostShell; + setType(ShellStrings.RESID_SHELLS_COMMAND_SHELL_LABEL); + } + + public String getTitle() + { + return getId(); + } + + public boolean isActive() + { + return _hostShell.isActive(); + } + + + public IHostShell getHostShell() + { + return _hostShell; + } + + + + public void shellOutputChanged(IHostShellChangeEvent event) + { + Object[] lines = event.getLines(); + IRemoteOutput[] outputs = new IRemoteOutput[lines.length]; + for (int i = 0; i < lines.length; i++) + { + RemoteOutput output = null; + Object lineObj = lines[i]; + if (lineObj instanceof String) + { + String line = (String)lineObj; + + if (line != null) + { + String type = event.isError() ? "stderr" : "stdout"; + if (event.isError()) + { + output = new RemoteError(this, type); + + } + else + { + output = new RemoteOutput(this, type); + } + output.setText(line); + + addOutput(output); + outputs[i] = output; + } + } + } + if (_lastRefreshJob == null || _lastRefreshJob.isComplete()) + { + _lastRefreshJob = new OutputRefreshJob(this, outputs, false); + _lastRefreshJob.schedule(); + } + } + + + public ICandidateCommand[] getCandidateCommands() + { + // TODO Auto-generated method stub + return null; + } + + public void writeToShell(String cmd) + { + _hostShell.writeToShell(cmd); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/ShellServiceSubSystem.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/ShellServiceSubSystem.java new file mode 100644 index 00000000000..cab317e733b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/ShellServiceSubSystem.java @@ -0,0 +1,247 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.core.ISystemTypes; +import org.eclipse.rse.core.SystemBasePlugin; +import org.eclipse.rse.core.servicesubsystem.IServiceSubSystemConfiguration; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteCmdSubSystem; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IShellService; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCommandShell; + + + +public final class ShellServiceSubSystem extends RemoteCmdSubSystem implements IShellServiceSubSystem +{ + protected String _userHome = null; + protected IShellService _hostService; + public ShellServiceSubSystem(IHost host, IConnectorService connectorService, IShellService hostService) + { + super(host, connectorService); + _hostService = hostService; + } + + public IShellService getShellService() + { + return _hostService; + } + + public void setShellService(IShellService service) + { + _hostService = service; + } + + protected String getUserHome() + { + if (_userHome == null) + { + if (getSystemType() == ISystemTypes.SYSTEMTYPE_WINDOWS) + { + _userHome = "c:\\"; + } + else if (getSystemType() == ISystemTypes.SYSTEMTYPE_LOCAL) + { + _userHome = System.getProperty("user.home"); + } + else + { + // Assume UNIX compatible file system + _userHome = "/home/" + getUserId(); + } + } + return _userHome; + } + + + protected Object[] internalRunCommand(IProgressMonitor monitor, String cmd, Object context) throws InvocationTargetException, InterruptedException, SystemMessageException + { + return internalRunCommand(monitor, cmd, context, false); + } + + protected Object[] internalRunCommand(IProgressMonitor monitor, String cmd, Object context, boolean interpretOutput) throws InvocationTargetException, InterruptedException, SystemMessageException + { + String cwd = ""; + if (context instanceof IRemoteFile) + { + IRemoteFile file = (IRemoteFile) context; + cwd = file.getAbsolutePath(); + } + else if (context instanceof String) + { + // assume the string is a remote path + cwd = (String)context; + } + if (cwd == null || cwd.equals("null")) + { + cwd = getUserHome(); + } + + + IShellService service = getShellService(); + IHostShell hostShell = service.launchShell(monitor, cwd, getUserAndHostEnvVarsAsStringArray()); + IServiceCommandShell cmdShell = createRemoteCommandShell(this, hostShell); + hostShell.addOutputListener(cmdShell); + + + if (_cmdShells.size() == 0) + { + // if this is first shell, start listening so that on disconnect, we persist + getConnectorService().addCommunicationsListener(this); + } + _cmdShells.add(cmdShell); + + + + return new Object[] {cmdShell}; + } + + protected IRemoteCommandShell internalRunShell(IProgressMonitor monitor, Object context) throws InvocationTargetException, InterruptedException, SystemMessageException + { + String cwd = ""; + if (context instanceof IRemoteFile) + { + IRemoteFile file = (IRemoteFile) context; + cwd = file.getAbsolutePath(); + } + else if (context instanceof String) + { + // assume the string is a remote path + cwd = (String)context; + } + if (cwd == null || cwd.equals("null")) + { + cwd = getUserHome(); + } + + + IShellService service = getShellService(); + IHostShell hostShell = service.launchShell(monitor, cwd, getUserAndHostEnvVarsAsStringArray()); + IServiceCommandShell cmdShell = createRemoteCommandShell(this, hostShell); + if (cmdShell != null) + { + hostShell.addOutputListener(cmdShell); + + + if (_cmdShells.size() == 0) + { + // if this is first shell, start listening so that on disconnect, we persist + getConnectorService().addCommunicationsListener(this); + } + _cmdShells.add(cmdShell); + + } + + return cmdShell; + } + + + protected void internalCancelShell(IProgressMonitor monitor, Object command) throws InvocationTargetException, InterruptedException + { + if (command instanceof IServiceCommandShell) + { + IServiceCommandShell cmd = (IServiceCommandShell)command; + cmd.getHostShell().exit(); + } + } + + protected void internalSendCommandToShell(IProgressMonitor monitor, String cmd, Object command) throws InvocationTargetException, InterruptedException + { + if (command instanceof IServiceCommandShell) + { + IServiceCommandShell cmdWrapper = (IServiceCommandShell)command; + cmdWrapper.writeToShell(cmd); + cmdWrapper.updateHistory(cmd); + } + } + + protected IServiceCommandShell createRemoteCommandShell(IRemoteCmdSubSystem cmdSS, IHostShell hostShell) + { + IShellServiceSubSystemConfiguration config = (IShellServiceSubSystemConfiguration)getParentRemoteCmdSubSystemFactory(); + return config.createRemoteCommandShell(cmdSS, hostShell); + } + + public String[] getHostEnvironment() + { + return getShellService().getHostEnvironment(); + } + + public List getHostEnvironmentVariables() + { + List l = new ArrayList(); + String[] vars = getHostEnvironment(); + for (int i = 0; i < vars.length; i++) + { + l.add(vars[i]); + } + return l; + } + + /** + * swtich from one protocol to another + */ + public void switchServiceFactory(IServiceSubSystemConfiguration fact) + { + if (fact != getSubSystemConfiguration() && fact instanceof IShellServiceSubSystemConfiguration) + { + IShellServiceSubSystemConfiguration factory = (IShellServiceSubSystemConfiguration)fact; + try + { + disconnect(SystemBasePlugin.getActiveWorkbenchShell()); + } + catch (Exception e) + { + } + + IHost host = getHost(); + setSubSystemConfiguration(factory); + + IConnectorService oldConnectorService = getConnectorService(); + oldConnectorService.deregisterSubSystem(this); + + IConnectorService newConnectorService = factory.getConnectorService(host); + setConnectorService(newConnectorService); + + oldConnectorService.commit(); + newConnectorService.commit(); + + setShellService(factory.getShellService(host)); + } + } + + public Class getServiceType() + { + return IShellService.class; + } + + public void initializeSubSystem(IProgressMonitor monitor) + { + getShellService().initService(monitor); + } + + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/ShellServiceSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/ShellServiceSubSystemConfiguration.java new file mode 100644 index 00000000000..0f25bbd3f2a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.core/src/org/eclipse/rse/subsystems/shells/core/subsystems/servicesubsystem/ShellServiceSubSystemConfiguration.java @@ -0,0 +1,73 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem; + + + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteCmdSubSystemConfiguration; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.IService; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IShellService; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; + + + + +public abstract class ShellServiceSubSystemConfiguration extends RemoteCmdSubSystemConfiguration implements IShellServiceSubSystemConfiguration +{ + private Map _services; + protected ShellServiceSubSystemConfiguration() + { + super(); + _services = new HashMap(); + } + + public final Class getServiceType() + { + return IShellService.class; + } + + public final IShellService getShellService(IHost host) + { + IShellService service = (IShellService)_services.get(host); + if (service == null) + { + service = createShellService(host); + _services.put(host, service); + } + return service; + } + + public final IService getService(IHost host) + { + return getShellService(host); + } + + public boolean supportsServerLaunchProperties(IHost host) + { + return getConnectorService(host).supportsServerLaunchProperties(); + } + + public IServiceCommandShell createRemoteCommandShell(IRemoteCmdSubSystem cmdSS, IHostShell hostShell) + { + return new ServiceCommandShell(cmdSS, hostShell); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/.classpath b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/.classpath new file mode 100644 index 00000000000..751c8f2e504 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/.cvsignore b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/.cvsignore new file mode 100644 index 00000000000..ba077a4031a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/.project b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/.project new file mode 100644 index 00000000000..b7d39778656 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/.project @@ -0,0 +1,28 @@ + + + org.eclipse.rse.subsystems.shells.dstore + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..26dad89496d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin.name +Bundle-SymbolicName: org.eclipse.rse.subsystems.shells.dstore;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.rse.subsystems.shells.dstore.Activator +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.rse.services, + org.eclipse.rse.services.dstore, + org.eclipse.dstore.core, + org.eclipse.dstore.extra, + org.eclipse.rse.connectorservice.dstore, + org.eclipse.rse.shells.ui, + org.eclipse.rse.subsystems.shells.core, + org.eclipse.rse.ui, + org.eclipse.rse.subsystems.files.core +Eclipse-LazyStart: true +Bundle-Vendor: Eclipse.org +Bundle-ClassPath: shellsDStore.jar +Export-Package: org.eclipse.rse.subsystems.shells.dstore, + org.eclipse.rse.subsystems.shells.dstore.model diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/about.html b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/about.html new file mode 100644 index 00000000000..6f6b96c4c87 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/about.html @@ -0,0 +1,22 @@ + + + +About + + + +

      About This Content

      + +

      February 24, 2005

      +

      License

      + +

      The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

      + +

      If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content.

      + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/build.properties b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/build.properties new file mode 100644 index 00000000000..650aa257f69 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/build.properties @@ -0,0 +1,14 @@ +bin.includes = META-INF/,\ + about.html,\ + icons/,\ + plugin.properties,\ + plugin.xml,\ + shellsDStore.jar +src.includes = plugin.xml,\ + plugin.properties,\ + icons/,\ + META-INF/,\ + about.html +source.shellsDStore.jar = src/ +output.shellsDStore.jar = bin/ +jars.compile.order = shellsDStore.jar diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/icons/full/obj16/systemcommands_obj.gif b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/icons/full/obj16/systemcommands_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..061b6e226a9ee80a9797e330ca407774f314dfe7 GIT binary patch literal 230 zcmZ?wbhEHb6krfwIKsfNfBt?3h6a24dVBl$_;?^0ykNl+`}qBCerfjc^X=>RGc+{V z&j*6~{rl(NzrX+g?+^d~|KGoVe@jbCLqh{l4+8@OPy|R~1&Tje7#SGE8FWChAUhdY zlOL$|rD(EctXh;(Fd3;*8D8UCP`X-4hiV FtO3DMPksOZ literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/icons/full/obj16/systemcommandslive_obj.gif b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/icons/full/obj16/systemcommandslive_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..3faca447424a6aa52b08191dbce3246c11d582c2 GIT binary patch literal 246 zcmZ?wbhEHb6krfwIKsfNfBt?3h6a24dVBl$_;?^0ykNl+`}qBCerfjg`xzPe`mP{%#43z5cEU}ts;yp#9 zRBPf4o#<653L1@vgFG817^a+yc2aDZ$RLux + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/src/org/eclipse/rse/subsystems/shells/dstore/Activator.java b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/src/org/eclipse/rse/subsystems/shells/dstore/Activator.java new file mode 100644 index 00000000000..5038e5f888e --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/src/org/eclipse/rse/subsystems/shells/dstore/Activator.java @@ -0,0 +1,74 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.dstore; + +import org.eclipse.ui.plugin.*; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class Activator extends AbstractUIPlugin { + + //The shared instance. + private static Activator plugin; + + /** + * The constructor. + */ + public Activator() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception + { + super.start(context); + + // shells ui needs to be started for proper UI init + org.eclipse.rse.shells.ui.Activator.getDefault(); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static Activator getDefault() { + 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.subsystems.shells.dstore", path); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/src/org/eclipse/rse/subsystems/shells/dstore/DStoreShellSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/src/org/eclipse/rse/subsystems/shells/dstore/DStoreShellSubSystemConfiguration.java new file mode 100644 index 00000000000..d79249a6968 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/src/org/eclipse/rse/subsystems/shells/dstore/DStoreShellSubSystemConfiguration.java @@ -0,0 +1,111 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.dstore; + +import org.eclipse.rse.connectorservice.dstore.DStoreConnectorService; +import org.eclipse.rse.connectorservice.dstore.DStoreConnectorServiceManager; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.dstore.IDStoreService; +import org.eclipse.rse.services.dstore.shells.DStoreShellService; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IShellService; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.IServiceCommandShell; +import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.ShellServiceSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.ShellServiceSubSystemConfiguration; +import org.eclipse.rse.subsystems.shells.dstore.model.DStoreServiceCommandShell; + +import org.eclipse.dstore.core.model.IDataStoreProvider; + +/** + * Provides a factory for generating instances of the class + * SampleFileSubSystem. + */ +public class DStoreShellSubSystemConfiguration extends ShellServiceSubSystemConfiguration +{ + protected boolean _isWindows; + public DStoreShellSubSystemConfiguration() + { + super(); + } + + /* (non-Javadoc) + * @see com.ibm.etools.systems.subsystems.SubSystemFactory#isFactoryFor(java.lang.Class) + */ + public boolean isFactoryFor(Class subSystemType) { + boolean isFor = ShellServiceSubSystem.class.equals(subSystemType); + return isFor; + } + + + + /** + * Instantiate and return an instance of OUR subystem. + * Do not populate it yet though! + * @see org.eclipse.rse.core.subsystems.impl.SubSystemFactoryImpl#createSubSystemInternal(Host) + */ + public ISubSystem createSubSystemInternal(IHost host) + { + DStoreConnectorService connectorService = (DStoreConnectorService)getConnectorService(host); + ISubSystem subsys = new ShellServiceSubSystem(host, connectorService, new DStoreShellService(connectorService)); + return subsys; + } + + + /* (non-Javadoc) + * @see com.ibm.etools.systems.subsystems.SubSystemFactory#supportsFilters() + */ + public boolean supportsFilters() { + return false; + } + + public IConnectorService getConnectorService(IHost host) + { + return DStoreConnectorServiceManager.getTheUniversalSystemManager().getConnectorService(host, getServiceImplType()); + } + + public void setConnectorService(IHost host, IConnectorService connectorService) + { + DStoreConnectorServiceManager.getTheUniversalSystemManager().setConnectorService(host, getServiceImplType(), connectorService); + } + + public IShellService createShellService(IHost host) + { + return new DStoreShellService((IDataStoreProvider)getConnectorService(host)); + } + + public boolean supportsCommands() + { + return true; + } + public boolean canRunCommand() + { + return true; + } + + public IServiceCommandShell createRemoteCommandShell(IRemoteCmdSubSystem cmdSS, IHostShell hostShell) + { + return new DStoreServiceCommandShell(cmdSS, hostShell); + } + + public Class getServiceImplType() + { + return IDStoreService.class; + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/src/org/eclipse/rse/subsystems/shells/dstore/model/DStoreServiceCommandShell.java b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/src/org/eclipse/rse/subsystems/shells/dstore/model/DStoreServiceCommandShell.java new file mode 100644 index 00000000000..db6f39f7289 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/src/org/eclipse/rse/subsystems/shells/dstore/model/DStoreServiceCommandShell.java @@ -0,0 +1,79 @@ +package org.eclipse.rse.subsystems.shells.dstore.model; + +import org.eclipse.dstore.core.model.DataElement; +import org.eclipse.rse.internal.services.dstore.shell.DStoreShellOutputReader; +import org.eclipse.rse.internal.subsystems.shells.servicesubsystem.OutputRefreshJob; +import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteError; +import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteOutput; +import org.eclipse.rse.services.dstore.shells.DStoreHostShell; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IHostShellChangeEvent; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteOutput; +import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.ServiceCommandShell; + +public class DStoreServiceCommandShell extends ServiceCommandShell +{ + + public DStoreServiceCommandShell(IRemoteCmdSubSystem cmdSS, IHostShell hostShell) + { + super(cmdSS, hostShell); + } + + public Object getContext() + { + DStoreHostShell shell = (DStoreHostShell)getHostShell(); + DStoreShellOutputReader reader = (DStoreShellOutputReader)shell.getStandardOutputReader(); + String workingDir = reader.getWorkingDirectory(); + if (workingDir != null && workingDir.length() > 0) + { + try + { + return getFileSubSystem().getRemoteFileObject(workingDir); + } + catch (Exception e) + { + } + } + return null; + + } + + public void shellOutputChanged(IHostShellChangeEvent event) + { + Object[] lines = event.getLines(); + IRemoteOutput[] outputs = new IRemoteOutput[lines.length]; + for (int i = 0; i < lines.length; i++) + { + RemoteOutput output = null; + Object lineObj = lines[i]; + if (lineObj instanceof DataElement) + { + DataElement line = (DataElement)lineObj; + if (line != null) + { + String type = line.getType(); + if (event.isError()) + { + output = new RemoteError(this, type); + } + else + { + output = new RemoteOutput(this, type); + } + output.setText(line.getName()); + output.setAbsolutePath(line.getSource()); + + addOutput(output); + outputs[i] = output; + } + } + } + if (_lastRefreshJob == null || _lastRefreshJob.isComplete()) + { + _lastRefreshJob = new OutputRefreshJob(this, outputs, false); + _lastRefreshJob.schedule(); + } + } + +} diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.local/.classpath b/rse/plugins/org.eclipse.rse.subsystems.shells.local/.classpath new file mode 100644 index 00000000000..751c8f2e504 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.local/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.local/.cvsignore b/rse/plugins/org.eclipse.rse.subsystems.shells.local/.cvsignore new file mode 100644 index 00000000000..ba077a4031a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.local/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.local/.project b/rse/plugins/org.eclipse.rse.subsystems.shells.local/.project new file mode 100644 index 00000000000..45811d0239c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.local/.project @@ -0,0 +1,28 @@ + + + org.eclipse.rse.subsystems.shells.local + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.local/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.subsystems.shells.local/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..f4fa146536d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.local/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %plugin.name +Bundle-SymbolicName: org.eclipse.rse.subsystems.shells.local;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.rse.subsystems.shells.local.Activator +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.rse.services, + org.eclipse.rse.services.local, + org.eclipse.rse.connectorservice.local, + org.eclipse.rse.shells.ui, + org.eclipse.rse.subsystems.shells.core, + org.eclipse.rse.ui, + org.eclipse.rse.subsystems.files.core +Eclipse-LazyStart: true +Bundle-Vendor: Eclipse.org +Bundle-ClassPath: shellsLocal.jar +Export-Package: org.eclipse.rse.subsystems.shells.local diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.local/about.html b/rse/plugins/org.eclipse.rse.subsystems.shells.local/about.html new file mode 100644 index 00000000000..6f6b96c4c87 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.local/about.html @@ -0,0 +1,22 @@ + + + +About + + + +

      About This Content

      + +

      February 24, 2005

      +

      License

      + +

      The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

      + +

      If you did not receive this Content directly from the Eclipse Foundation, the Content is being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content.

      + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.local/build.properties b/rse/plugins/org.eclipse.rse.subsystems.shells.local/build.properties new file mode 100644 index 00000000000..394c41240b0 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.local/build.properties @@ -0,0 +1,14 @@ +bin.includes = META-INF/,\ + about.html,\ + icons/,\ + plugin.properties,\ + plugin.xml,\ + shellsLocal.jar +src.includes = META-INF/,\ + about.html,\ + icons/,\ + plugin.properties,\ + plugin.xml +source.shellsLocal.jar = src/ +output.shellsLocal.jar = bin/ +jars.compile.order = shellsLocal.jar diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.local/icons/full/obj16/systemcommands_obj.gif b/rse/plugins/org.eclipse.rse.subsystems.shells.local/icons/full/obj16/systemcommands_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..061b6e226a9ee80a9797e330ca407774f314dfe7 GIT binary patch literal 230 zcmZ?wbhEHb6krfwIKsfNfBt?3h6a24dVBl$_;?^0ykNl+`}qBCerfjc^X=>RGc+{V z&j*6~{rl(NzrX+g?+^d~|KGoVe@jbCLqh{l4+8@OPy|R~1&Tje7#SGE8FWChAUhdY zlOL$|rD(EctXh;(Fd3;*8D8UCP`X-4hiV FtO3DMPksOZ literal 0 HcmV?d00001 diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.local/icons/full/obj16/systemcommandslive_obj.gif b/rse/plugins/org.eclipse.rse.subsystems.shells.local/icons/full/obj16/systemcommandslive_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..3faca447424a6aa52b08191dbce3246c11d582c2 GIT binary patch literal 246 zcmZ?wbhEHb6krfwIKsfNfBt?3h6a24dVBl$_;?^0ykNl+`}qBCerfjg`xzPe`mP{%#43z5cEU}ts;yp#9 zRBPf4o#<653L1@vgFG817^a+yc2aDZ$RLux + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.local/src/org/eclipse/rse/subsystems/shells/local/Activator.java b/rse/plugins/org.eclipse.rse.subsystems.shells.local/src/org/eclipse/rse/subsystems/shells/local/Activator.java new file mode 100644 index 00000000000..2e5376562a0 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.local/src/org/eclipse/rse/subsystems/shells/local/Activator.java @@ -0,0 +1,74 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.local; + +import org.eclipse.ui.plugin.*; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class Activator extends AbstractUIPlugin { + + //The shared instance. + private static Activator plugin; + + /** + * The constructor. + */ + public Activator() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception + { + super.start(context); + + // shells ui needs to be started for proper UI init + org.eclipse.rse.shells.ui.Activator.getDefault(); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static Activator getDefault() { + 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.subsystems.shells.dstore", path); + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.local/src/org/eclipse/rse/subsystems/shells/local/LocalShellSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.shells.local/src/org/eclipse/rse/subsystems/shells/local/LocalShellSubSystemConfiguration.java new file mode 100644 index 00000000000..24340c6c3ad --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.local/src/org/eclipse/rse/subsystems/shells/local/LocalShellSubSystemConfiguration.java @@ -0,0 +1,124 @@ +/******************************************************************************** + * Copyright (c) 2006 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: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.rse.subsystems.shells.local; + +import org.eclipse.rse.connectorservice.local.LocalConnectorService; +import org.eclipse.rse.connectorservice.local.LocalConnectorServiceManager; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.model.IHost; +import org.eclipse.rse.services.local.ILocalService; +import org.eclipse.rse.services.local.shells.LocalShellService; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IShellService; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.IServiceCommandShell; +import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.ShellServiceSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.ShellServiceSubSystemConfiguration; +import org.eclipse.rse.subsystems.shells.local.model.LocalServiceCommandShell; + + + +public class LocalShellSubSystemConfiguration extends ShellServiceSubSystemConfiguration +{ + public LocalShellSubSystemConfiguration() + { + super(); + } + + /** + * Return in string format the character used to separate commands. Eg, ";" or "&" + */ + public String getCommandSeparator() + { + String os = System.getProperty("os.name").toLowerCase(); + if (os.startsWith("win")) + { + return "&"; + } + else + { + return ";"; + } + + } + + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#isFactoryFor(java.lang.Class) + */ + public boolean isFactoryFor(Class subSystemType) { + boolean isFor = ShellServiceSubSystem.class.equals(subSystemType); + return isFor; + } + + + + /** + * Instantiate and return an instance of OUR subystem. + * Do not populate it yet though! + */ + public ISubSystem createSubSystemInternal(IHost host) + { + LocalConnectorService connectorService = (LocalConnectorService)getConnectorService(host); + ISubSystem subsys = new ShellServiceSubSystem(host, connectorService, getShellService(host)); + return subsys; + } + + + /* (non-Javadoc) + * @see org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteCmdSubSystemConfiguration#supportsFilters() + */ + public boolean supportsFilters() { + return false; + } + + public IConnectorService getConnectorService(IHost host) + { + return LocalConnectorServiceManager.getTheLocalSystemManager().getConnectorService(host, getServiceImplType()); + } + + public IShellService createShellService(IHost host) + { + return new LocalShellService(); + } + + public boolean supportsCommands() + { + return true; + } + public boolean canRunCommand() + { + return true; + } + + public void setConnectorService(IHost host, IConnectorService connectorService) + { + LocalConnectorServiceManager.getTheLocalSystemManager().setConnectorService(host, getServiceImplType(), connectorService); + } + + public Class getServiceImplType() + { + return ILocalService.class; + } + + public IServiceCommandShell createRemoteCommandShell(IRemoteCmdSubSystem cmdSS, IHostShell hostShell) + { + return new LocalServiceCommandShell(cmdSS, hostShell); + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.local/src/org/eclipse/rse/subsystems/shells/local/model/LocalServiceCommandShell.java b/rse/plugins/org.eclipse.rse.subsystems.shells.local/src/org/eclipse/rse/subsystems/shells/local/model/LocalServiceCommandShell.java new file mode 100644 index 00000000000..09df86d1717 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.local/src/org/eclipse/rse/subsystems/shells/local/model/LocalServiceCommandShell.java @@ -0,0 +1,123 @@ +package org.eclipse.rse.subsystems.shells.local.model; + + +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.internal.services.local.shells.ParsedOutput; +import org.eclipse.rse.internal.services.local.shells.Patterns; +import org.eclipse.rse.internal.subsystems.shells.servicesubsystem.OutputRefreshJob; +import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteError; +import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteOutput; + + +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IHostShellChangeEvent; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem; +import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteOutput; +import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.ServiceCommandShell; + +public class LocalServiceCommandShell extends ServiceCommandShell +{ + private Patterns _patterns; + private String _workingDir; + private IRemoteFileSubSystem _fs; + + public LocalServiceCommandShell(IRemoteCmdSubSystem cmdSS, IHostShell hostShell) + { + super(cmdSS, hostShell); + _patterns = new Patterns(); + _patterns.update("cmd"); + ISubSystem[] sses = cmdSS.getHost().getSubSystems(); + for (int i = 0; i < sses.length; i++) + { + if (sses[i] instanceof IRemoteFileSubSystem) + { + _fs = (IRemoteFileSubSystem)sses[i]; + } + } + } + + public Object getContext() + { + String workingDir = _workingDir; + if (workingDir != null && workingDir.length() > 0) + { + try + { + return _fs.getRemoteFileObject(workingDir); + } + catch (Exception e) + { + } + } + return null; + + } + + + + public void shellOutputChanged(IHostShellChangeEvent event) + { + Object[] lines = event.getLines(); + IRemoteOutput[] outputs = new IRemoteOutput[lines.length]; + for (int i = 0; i < lines.length; i++) + { + String line = (String)lines[i]; + ParsedOutput parsedMsg = null; + + try + { + parsedMsg = _patterns.matchLine(line); + } + catch (Throwable e) + { + e.printStackTrace(); + } + + RemoteOutput output = null; + String type = "stdout"; + if (parsedMsg != null) + { + type = parsedMsg.type; + } + if (event.isError()) + { + output = new RemoteError(this, type); + } + else + { + output = new RemoteOutput(this, type); + } + + output.setText(line); + if (parsedMsg != null) + { + String file = parsedMsg.file; + if (type.equals("prompt")) + { + _workingDir = file; + output.setAbsolutePath(_workingDir); + } + else + { + output.setAbsolutePath(_workingDir + "\\" + file); + } + } + + addOutput(output); + outputs[i] = output; + } + if (_lastRefreshJob == null || _lastRefreshJob.isComplete()) + { + _lastRefreshJob = new OutputRefreshJob(this, outputs, false); + _lastRefreshJob.schedule(); + } + } + + public void writeToShell(String cmd) + { + super.writeToShell(cmd); + _patterns.update(cmd); + } + +}