diff --git a/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/miners/Miner.java b/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/miners/Miner.java index 897701389d8..eb4c5a1ad8c 100644 --- a/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/miners/Miner.java +++ b/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/miners/Miner.java @@ -12,10 +12,11 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * Noriaki Takatsu (IBM) [220126] [dstore][api][breaking] Single process server for multiple clients - * David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability - * Noriaki Takatsu (IBM) [229146] [multithread] changes to stop Miner threads when clients disconnect - * David McKnight (IBM) - [226561] [apidoc] Add API markup to RSE Javadocs where extend / implement is allowed + * Noriaki Takatsu (IBM) [220126] [dstore][api][breaking] Single process server for multiple clients + * David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability + * Noriaki Takatsu (IBM) [229146] [multithread] changes to stop Miner threads when clients disconnect + * David McKnight (IBM) - [226561] [apidoc] Add API markup to RSE Javadocs where extend / implement is allowed + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.dstore.core.miners; @@ -39,7 +40,7 @@ import org.eclipse.dstore.core.server.SystemServiceManager; * The DataStore framework knows how to load and route commands to miners * because it interfaces miners through the restricted set of interfaces declared here. * To add a new miner, developers must extend this class and implement the abstract methods declared here. - * + * * @noinstantiate This class is not intended to be instantiated by clients. The dstore server infrastructure * will take care of loading the Miner. */ @@ -681,7 +682,7 @@ implements ISchemaExtender * * @param theCommand an instance of a command containing a tree of arguments */ - public abstract DataElement handleCommand(DataElement theCommand); + public abstract DataElement handleCommand(DataElement theCommand) throws Exception; /** diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/UniversalByteStreamHandler.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/UniversalByteStreamHandler.java index 4b3393ad726..1ac9b591c7b 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/UniversalByteStreamHandler.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/UniversalByteStreamHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * Copyright (c) 2006, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,13 +7,14 @@ * * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer - * component that contains this file: David McKnight, Kushal Munir, - * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * component that contains this file: David McKnight, 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. * Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.rse.dstore.universal.miners; @@ -43,7 +44,7 @@ import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; */ public class UniversalByteStreamHandler extends ByteStreamHandler { - + public UniversalByteStreamHandler(DataStore dataStore, DataElement log) { super(dataStore, log); @@ -53,7 +54,7 @@ public class UniversalByteStreamHandler extends ByteStreamHandler /** * Save a file in the specified location. This method is called by the - * DataStore when the communication layer receives a file transfer + * 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 @@ -63,7 +64,7 @@ public class UniversalByteStreamHandler extends ByteStreamHandler public void receiveBytes(String remotePath, byte[] buffer, int size, boolean binary) { boolean isVirtual = ArchiveHandlerManager.isVirtual(remotePath); - + if (!isVirtual) { super.receiveBytes(remotePath, buffer, size, binary); @@ -79,11 +80,11 @@ public class UniversalByteStreamHandler extends ByteStreamHandler String virtualFileName = fileName; ArchiveHandlerManager mgr = ArchiveHandlerManager.getInstance(); - VirtualChild child = mgr.getVirtualObject(virtualFileName); - ISystemArchiveHandler handler = child.getHandler(); try { + VirtualChild child = mgr.getVirtualObject(virtualFileName); + ISystemArchiveHandler handler = child.getHandler(); File file = child.getExtractedFile(); fileName = file.getAbsolutePath(); @@ -128,20 +129,12 @@ public class UniversalByteStreamHandler extends ByteStreamHandler String filePath = virtualFileName.substring(0, virtualIndex); handler = mgr.getRegisteredHandler(new File(filePath)); } - boolean success = handler != null && handler.add(newFile, child.path, child.name, null); - 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()); - } + if (handler != null) + handler.add(newFile, child.path, child.name, null); + if (status == null) + return; + status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); + _dataStore.refresh(status.getParent()); } catch (IOException e) { @@ -164,7 +157,7 @@ public class UniversalByteStreamHandler extends ByteStreamHandler /** * 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. + * 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 @@ -173,7 +166,7 @@ public class UniversalByteStreamHandler extends ByteStreamHandler */ public void receiveAppendedBytes(String remotePath, byte[] buffer, int size, boolean binary) { - + boolean isVirtual = ArchiveHandlerManager.isVirtual(remotePath); if (!isVirtual) { @@ -188,20 +181,15 @@ public class UniversalByteStreamHandler extends ByteStreamHandler 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; - + ArchiveHandlerManager mgr = ArchiveHandlerManager.getInstance(); + VirtualChild child = mgr.getVirtualObject(virtualFileName); + if (!child.exists()) { + // System.out.println(virtualFileName + " does not exist."); + return; + } + ISystemArchiveHandler handler = child.getHandler(); File file = child.getExtractedFile(); fileName = file.getAbsolutePath(); @@ -242,7 +230,9 @@ public class UniversalByteStreamHandler extends ByteStreamHandler String filePath = virtualFileName.substring(0, virtualIndex); handler = mgr.getRegisteredHandler(new File(filePath)); } - success = handler != null && handler.add(newFile, child.path, child.name, null); + if (handler != null) { + handler.add(newFile, child.path, child.name, null); + } } else @@ -308,7 +298,7 @@ public class UniversalByteStreamHandler extends ByteStreamHandler // remote old file oldFile.delete(); - // rename new file + // rename new file newFile.renameTo(oldFile); // write the temp file to the archive @@ -318,25 +308,17 @@ public class UniversalByteStreamHandler extends ByteStreamHandler String filePath = virtualFileName.substring(0, virtualIndex); handler = mgr.getRegisteredHandler(new File(filePath)); } - success = handler != null && handler.add(newFile, child.path, child.name, null); + if (handler != null) { + handler.add(newFile, child.path, child.name, null); + } + } - } - - 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()); - } + if (status == null) + return; + status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); + _dataStore.refresh(status.getParent()); } - catch (IOException e) + catch (Exception e) { _dataStore.trace(e); if (status == null) return; diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/UniversalFileSystemMiner.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/UniversalFileSystemMiner.java index 8dd99917f0f..72a407cb4e7 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/UniversalFileSystemMiner.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/UniversalFileSystemMiner.java @@ -7,13 +7,13 @@ * * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer - * component that contains this file: David McKnight, Kushal Munir, - * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. - * + * * Contributors: - * Martin Oberhuber (Wind River) - Fix 154874 - handle files with space or $ in the name - * Xuan Chen (IBM) - Fix 160768 - [refresh][dstore] Refresh on renamed node within a zip does not work; + * Martin Oberhuber (Wind River) - Fix 154874 - handle files with space or $ in the name + * Xuan Chen (IBM) - Fix 160768 - [refresh][dstore] Refresh on renamed node within a zip does not work; * Xuan Chen (IBM) - Fix 189487 - copy and paste a folder did not work - workbench hang * Xuan Chen (IBM) - [189681] [dstore][linux] Refresh Folder in My Home messes up Refresh in Root * Xuan Chen (IBM) - [191280] [dstore] Expand fails for folder "/folk" with 3361 children @@ -33,6 +33,7 @@ * Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients * David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability * David McKnight (IBM) [225507] [api][breaking] RSE dstore API leaks non-API types + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.rse.dstore.universal.miners; @@ -76,6 +77,7 @@ import org.eclipse.rse.services.clientserver.archiveutils.SystemTgzHandler; import org.eclipse.rse.services.clientserver.archiveutils.SystemZipHandler; import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; import org.eclipse.rse.services.clientserver.java.ClassFileUtil; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; public class UniversalFileSystemMiner extends Miner { @@ -110,20 +112,20 @@ public class UniversalFileSystemMiner extends Miner { /** * @see Miner#handleCommand(DataElement) */ - public DataElement handleCommand(DataElement theElement) { + public DataElement handleCommand(DataElement theElement) throws SystemMessageException { String name = getCommandName(theElement); - + DataElement status = getCommandStatus(theElement); DataElement subject = getCommandArgument(theElement, 0); - + UniversalServerUtilities.logInfo(getName(), name + ":" + subject, _dataStore); //$NON-NLS-1$ - + String queryType = (String) subject.getElementProperty(DE.P_TYPE); boolean caseSensitive = !_isWindows; // TODO: test on WINDOWS! - if (IUniversalDataStoreConstants.C_QUERY_VIEW_ALL.equals(name)) { + if (IUniversalDataStoreConstants.C_QUERY_VIEW_ALL.equals(name)) { DataElement attributes = getCommandArgument(theElement, 1); if (attributes != null && attributes.getType().equals("attributes")) //$NON-NLS-1$ { @@ -135,19 +137,19 @@ public class UniversalFileSystemMiner extends Miner { return handleQueryAll(subject, null, status, queryType, caseSensitive); } - } else if (IUniversalDataStoreConstants.C_QUERY_VIEW_FILES.equals(name)) { + } else if (IUniversalDataStoreConstants.C_QUERY_VIEW_FILES.equals(name)) { DataElement attributes = getCommandArgument(theElement, 1); if (attributes != null && attributes.getType().equals("attributes")) //$NON-NLS-1$ { return handleQueryFiles(subject, attributes, status, queryType, - caseSensitive); + caseSensitive); } else { return handleQueryFiles(subject, null, status, queryType, caseSensitive); } - } else if (IUniversalDataStoreConstants.C_QUERY_VIEW_FOLDERS.equals(name)) { + } else if (IUniversalDataStoreConstants.C_QUERY_VIEW_FOLDERS.equals(name)) { DataElement attributes = getCommandArgument(theElement, 1); if (attributes != null && attributes.getType().equals("attributes")) //$NON-NLS-1$ { @@ -159,44 +161,44 @@ public class UniversalFileSystemMiner extends Miner { return handleQueryFolders(subject, null, status, queryType, caseSensitive); } - } else if (IUniversalDataStoreConstants.C_QUERY_ROOTS.equals(name)) { + } else if (IUniversalDataStoreConstants.C_QUERY_ROOTS.equals(name)) { return handleQueryRoots(subject, status); - } else if (IUniversalDataStoreConstants.C_SEARCH.equals(name)) { + } else if (IUniversalDataStoreConstants.C_SEARCH.equals(name)) { return handleSearch(theElement, status, queryType, caseSensitive); - } else if (IUniversalDataStoreConstants.C_CANCEL.equals(name)) { + } else if (IUniversalDataStoreConstants.C_CANCEL.equals(name)) { subject.getName(); return handleCancel(subject, status); - } else if (IUniversalDataStoreConstants.C_RENAME.equals(name)) { + } else if (IUniversalDataStoreConstants.C_RENAME.equals(name)) { return handleRename(subject, status); - } else if (IUniversalDataStoreConstants.C_DELETE.equals(name)) { + } else if (IUniversalDataStoreConstants.C_DELETE.equals(name)) { return handleDelete(subject, status, true); - } else if (IUniversalDataStoreConstants.C_DELETE_BATCH.equals(name)) { + } else if (IUniversalDataStoreConstants.C_DELETE_BATCH.equals(name)) { return handleDeleteBatch(theElement, status); - } else if (IUniversalDataStoreConstants.C_COPY.equals(name)) { + } else if (IUniversalDataStoreConstants.C_COPY.equals(name)) { return handleCopy(subject, getCommandArgument(theElement, 1), getCommandArgument(theElement, 2), status); - } else if (IUniversalDataStoreConstants.C_COPY_BATCH.equals(name)) { + } else if (IUniversalDataStoreConstants.C_COPY_BATCH.equals(name)) { return handleCopyBatch(subject, theElement, status); - } else if (IUniversalDataStoreConstants.C_CREATE_FILE.equals(name)) { + } else if (IUniversalDataStoreConstants.C_CREATE_FILE.equals(name)) { return handleCreateFile(subject, status, queryType); - } else if (IUniversalDataStoreConstants.C_CREATE_FOLDER.equals(name)) { + } else if (IUniversalDataStoreConstants.C_CREATE_FOLDER.equals(name)) { return handleCreateFolder(subject, status, queryType); - } else if (IUniversalDataStoreConstants.C_SET_READONLY.equals(name)) { + } else if (IUniversalDataStoreConstants.C_SET_READONLY.equals(name)) { return handleSetReadOnly(subject, status); - } else if (IUniversalDataStoreConstants.C_SET_LASTMODIFIED.equals(name)) { + } else if (IUniversalDataStoreConstants.C_SET_LASTMODIFIED.equals(name)) { return handleSetLastModified(subject, status); - } else if (IUniversalDataStoreConstants.C_QUERY_BASIC_PROPERTY.equals(name)) { + } else if (IUniversalDataStoreConstants.C_QUERY_BASIC_PROPERTY.equals(name)) { return handleQueryBasicProperty(subject, status); } else if (IUniversalDataStoreConstants.C_QUERY_CAN_WRITE_PROPERTY.equals(name)) { return handleQuerycanWriteProperty(subject, status); } else if (IUniversalDataStoreConstants.C_QUERY_ADVANCE_PROPERTY.equals(name)) { return handleQueryAdvanceProperty(subject, status); - } else if (IUniversalDataStoreConstants.C_QUERY_EXISTS.equals(name)) { + } else if (IUniversalDataStoreConstants.C_QUERY_EXISTS.equals(name)) { return handleQueryExists(subject, status, queryType); - } else if (IUniversalDataStoreConstants.C_QUERY_GET_REMOTE_OBJECT.equals(name)) { + } else if (IUniversalDataStoreConstants.C_QUERY_GET_REMOTE_OBJECT.equals(name)) { return handleQueryGetRemoteObject(subject, status, queryType); - } else if (IUniversalDataStoreConstants.C_GET_OSTYPE.equals(name)) { + } else if (IUniversalDataStoreConstants.C_GET_OSTYPE.equals(name)) { return handleGetOSType(subject, status); } else if (IUniversalDataStoreConstants.C_DOWNLOAD_FILE.equals(name)) { return handleDownload(theElement, status); @@ -204,7 +206,7 @@ public class UniversalFileSystemMiner extends Miner { return handleQueryEncoding(subject, status); } else if (IUniversalDataStoreConstants.C_QUERY_UNUSED_PORT.equals(name)) { return handleQueryUnusedPort(subject, status); - } else if (IUniversalDataStoreConstants.C_QUERY_CLASSNAME.equals(name)) { + } else if (IUniversalDataStoreConstants.C_QUERY_CLASSNAME.equals(name)) { return handleQueryClassName(subject, status); } else if (IUniversalDataStoreConstants.C_QUERY_QUALIFIED_CLASSNAME.equals(name)) { return handleQueryQualifiedClassName(subject, status); @@ -212,7 +214,7 @@ public class UniversalFileSystemMiner extends Miner { return handleQueryFilePermissions(subject, status); } else if (IUniversalDataStoreConstants.C_SET_FILE_PERMISSIONS.equals(name)) { DataElement newPermissions = getCommandArgument(theElement, 1); - return handleSetFilePermissions(subject, newPermissions, status); + return handleSetFilePermissions(subject, newPermissions, status); } else { UniversalServerUtilities.logError(CLASSNAME, "Invalid query to handlecommand", null, _dataStore); //$NON-NLS-1$ @@ -220,20 +222,20 @@ public class UniversalFileSystemMiner extends Miner { return statusDone(status); } - private DataElement handleCopyBatch(DataElement targetFolder, DataElement theElement, DataElement status) + private DataElement handleCopyBatch(DataElement targetFolder, DataElement theElement, DataElement status) { - + CopyBatchThread copyBatchThread = new CopyBatchThread(targetFolder, theElement, this, _isWindows, status); copyBatchThread.start(); updateCancellableThreads(status.getParent(), copyBatchThread); - + return status; } - - + + /** * Method to do a search. @@ -273,25 +275,25 @@ public class UniversalFileSystemMiner extends Miner { 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(); 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(); updateCancellableThreads(status.getParent(), searchThread); @@ -305,7 +307,7 @@ public class UniversalFileSystemMiner extends Miner { ICancellableHandler thread = (ICancellableHandler) _cancellableThreads .get(subject); - + if (thread != null) { if (!thread.isDone()) { thread.cancel(); @@ -318,18 +320,19 @@ public class UniversalFileSystemMiner extends Miner { // 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) + String queryType, boolean caseSensitive) + throws SystemMessageException { boolean isArchive = false; String fullName = subject.getValue(); - - if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) + + if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { //check if it is a archive file if (ArchiveHandlerManager.getInstance().isArchive(new File(fullName))) @@ -340,7 +343,7 @@ public class UniversalFileSystemMiner extends Miner { { isArchive = ArchiveHandlerManager.isVirtual(fullName); } - } + } else if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) || queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { @@ -365,7 +368,7 @@ public class UniversalFileSystemMiner extends Miner { filter = getFilterString(subject.getAttribute(DE.A_SOURCE)); showHidden = getShowHiddenFlag(subject.getAttribute(DE.A_SOURCE)); } - + if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) fileobj = new File(subject.getName()); else if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR)) @@ -383,15 +386,15 @@ public class UniversalFileSystemMiner extends Miner { { subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR); subject.setAttribute(DE.A_SOURCE, setProperties(fileobj)); - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_DOES_NOT_EXIST); - + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_DOES_NOT_EXIST); + if (subject.getNestedSize() > 0) { List children = subject.getNestedData(); for (int i = children.size() - 1; i >= 0; i--) { _dataStore.deleteObject(subject, (DataElement)children.get(i)); - } + } } _dataStore.refresh(subject); } @@ -403,18 +406,18 @@ public class UniversalFileSystemMiner extends Miner { return status; // query done in a thread so don't mark done } } - + return statusDone(status); } protected void internalQueryAll(DataElement subject, File fileobj, String queryType, String filter, boolean caseSensitive, int inclusion, DataElement status) { - + // do query on a thread FileQueryThread queryThread = new FileQueryThread(subject, fileobj, queryType, filter, caseSensitive, inclusion, showHidden, _isWindows, status); - queryThread.start(); - + queryThread.start(); + updateCancellableThreads(status.getParent(), queryThread); } @@ -428,7 +431,7 @@ public class UniversalFileSystemMiner extends Miner { { String threadName = (String) iter.next(); ICancellableHandler theThread = (ICancellableHandler) _cancellableThreads.get(threadName); - if ((theThread == null) || + if ((theThread == null) || theThread.isDone() || theThread.isCancelled()) { _cancellableThreads.remove(threadName); @@ -442,13 +445,14 @@ public class UniversalFileSystemMiner extends Miner { // save find thread in hashmap for retrieval during cancel _cancellableThreads.put(command, thread); } - - + + /** * Method to list the files for a given filter. */ - public DataElement handleQueryFiles(DataElement subject, DataElement attributes, - DataElement status, String queryType, boolean caseSensitive) { + public DataElement handleQueryFiles(DataElement subject, DataElement attributes, + DataElement status, String queryType, boolean caseSensitive) + throws SystemMessageException { File fileobj = null; @@ -463,7 +467,7 @@ public class UniversalFileSystemMiner extends Miner { filter = getFilterString(subject.getAttribute(DE.A_SOURCE)); showHidden = getShowHiddenFlag(subject.getAttribute(DE.A_SOURCE)); } - + if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) fileobj = new File(subject.getName()); else if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR)) @@ -478,7 +482,7 @@ public class UniversalFileSystemMiner extends Miner { { subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR); subject.setAttribute(DE.A_SOURCE, setProperties(fileobj)); - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_DOES_NOT_EXIST); + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_DOES_NOT_EXIST); if (subject.getNestedSize() > 0) { List children = subject.getNestedData(); @@ -500,7 +504,8 @@ public class UniversalFileSystemMiner extends Miner { * Method to list the folders for a given filter. */ public DataElement handleQueryFolders(DataElement subject, DataElement attributes, - DataElement status, String queryType, boolean caseSensitive) { + DataElement status, String queryType, boolean caseSensitive) + throws SystemMessageException { if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) || queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { @@ -509,7 +514,7 @@ public class UniversalFileSystemMiner extends Miner { File fileobj = null; String filter = null; - + if (attributes != null) { filter = getFilterString(attributes.getAttribute(DE.A_SOURCE)); @@ -534,7 +539,7 @@ public class UniversalFileSystemMiner extends Miner { { subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR); subject.setAttribute(DE.A_SOURCE, setProperties(fileobj)); - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_DOES_NOT_EXIST); + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_DOES_NOT_EXIST); if (subject.getNestedSize() > 0) { List children = subject.getNestedData(); @@ -549,14 +554,14 @@ public class UniversalFileSystemMiner extends Miner { internalQueryAll(subject, fileobj, queryType, filter, caseSensitive, IClientServerConstants.INCLUDE_FOLDERS_ONLY, status); return status; // query done in a thread so not marking done here } - + return statusDone(status); } /** * Method to list the roots. */ - public DataElement handleQueryRoots(DataElement subject, DataElement status) { + public DataElement handleQueryRoots(DataElement subject, DataElement status) throws SystemMessageException { // File fileobj = new File(subject.getName()); new File(subject.getName()); DataElement deObj = null; @@ -604,17 +609,17 @@ public class UniversalFileSystemMiner extends Miner { deleteThread.start(); updateCancellableThreads(status.getParent(), deleteThread); - + return status; } - + private DataElement handleDeleteBatch(DataElement theElement, DataElement status) { DeleteThread deleteThread = new DeleteThread(theElement, this, _dataStore, true, status); deleteThread.start(); updateCancellableThreads(status.getParent(), deleteThread); - + return status; } @@ -622,12 +627,12 @@ public class UniversalFileSystemMiner extends Miner { * Method to Rename a file or folder. */ public DataElement handleRename(DataElement subject, DataElement status) { - + RenameThread renameThread = new RenameThread(subject, this, _dataStore, status); renameThread.start(); updateCancellableThreads(status.getParent(), renameThread); - + return status; } @@ -636,12 +641,12 @@ public class UniversalFileSystemMiner extends Miner { */ public DataElement handleCreateFile(DataElement subject, DataElement status, String queryType) { - + CreateFileThread createFileThread = new CreateFileThread(subject, queryType, this, _dataStore, status); createFileThread.start(); updateCancellableThreads(status.getParent(), createFileThread); - + return status; } @@ -654,7 +659,7 @@ public class UniversalFileSystemMiner extends Miner { createFolderThread.start(); updateCancellableThreads(status.getParent(), createFolderThread); - + return status; } @@ -664,7 +669,7 @@ public class UniversalFileSystemMiner extends Miner { public DataElement handleSetReadOnly(DataElement subject, DataElement status) { File filename = new File(subject.getAttribute(DE.A_VALUE), subject.getAttribute(DE.A_NAME)); - + if (!filename.exists()) { filename = new File(subject.getAttribute(DE.A_VALUE)); @@ -710,7 +715,7 @@ public class UniversalFileSystemMiner extends Miner { done = (exitValue == 0); } } - if (done) + if (done) { status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); } @@ -718,12 +723,12 @@ public class UniversalFileSystemMiner extends Miner { { status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); } - - // update filename? + + // update filename? filename = new File(filename.getAbsolutePath()); subject.setAttribute(DE.A_SOURCE, setProperties(filename)); _dataStore.refresh(subject); - + } catch (Exception e) { UniversalServerUtilities.logError(CLASSNAME, "handleSetreadOnly", e, _dataStore); //$NON-NLS-1$ @@ -737,10 +742,10 @@ public class UniversalFileSystemMiner extends Miner { * Method to set LastModified to a file or folder. */ public DataElement handleSetLastModified(DataElement subject, - DataElement status) - { + DataElement status) + { File filename = new File(subject.getAttribute(DE.A_VALUE), subject.getAttribute(DE.A_NAME)); - + if (!filename.exists()) { filename = new File(subject.getAttribute(DE.A_VALUE)); @@ -750,22 +755,22 @@ public class UniversalFileSystemMiner extends Miner { else { try { String str = subject.getAttribute(DE.A_SOURCE); - + long date = Long.parseLong(str); boolean done = filename.setLastModified(date); if (done) { status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); - } + } else { status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); } - + filename = new File(filename.getAbsolutePath()); subject.setAttribute(DE.A_SOURCE, setProperties(filename)); _dataStore.refresh(subject); - + } catch (Exception e) { UniversalServerUtilities.logError(CLASSNAME, "handleSetLastModified", e, _dataStore); //$NON-NLS-1$ @@ -779,7 +784,7 @@ public class UniversalFileSystemMiner extends Miner { * Method to Retrieve properties of the file or folder. */ protected DataElement handleQueryBasicProperty(DataElement subject, - DataElement status) { + DataElement status) throws SystemMessageException { File fileobj = new File(subject.getAttribute(DE.A_VALUE) + File.separatorChar + subject.getName()); subject.setAttribute(DE.A_SOURCE, setProperties(fileobj)); @@ -820,7 +825,7 @@ public class UniversalFileSystemMiner extends Miner { * Method to query existence of the file or folder. */ protected DataElement handleQueryExists(DataElement subject, - DataElement status, String queryType) { + DataElement status, String queryType) throws SystemMessageException { File fileobj = null; if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { @@ -873,12 +878,12 @@ public class UniversalFileSystemMiner extends Miner { * Method to get remote object */ public DataElement handleQueryGetRemoteObject(DataElement subject, - DataElement status, String queryType) { + DataElement status, String queryType) throws SystemMessageException { File fileobj = null; boolean isVirtual = false; boolean isFilter = false; String fullName = subject.getValue(); - if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) + if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { isFilter = true; isVirtual = ArchiveHandlerManager.isVirtual(fullName); @@ -887,7 +892,7 @@ public class UniversalFileSystemMiner extends Miner { if (filterValue.equals(".")) //$NON-NLS-1$ { if (_dataStore.getClient() != null){ - filterValue = _dataStore.getClient().getProperty("user.home"); //$NON-NLS-1$ + filterValue = _dataStore.getClient().getProperty("user.home"); //$NON-NLS-1$ } else { filterValue = System.getProperty("user.home"); //$NON-NLS-1$ @@ -896,16 +901,16 @@ public class UniversalFileSystemMiner extends Miner { } if (!isVirtual) fileobj = new File(filterValue); - } + } else if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR)) { String name = subject.getName(); String path = subject.getValue(); - fileobj = new File(path, name); + fileobj = new File(path, name); } else if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR)) { - String name = subject.getName(); + String name = subject.getName(); String path = subject.getValue(); if (name.length() == 0) { @@ -913,7 +918,7 @@ public class UniversalFileSystemMiner extends Miner { } else { - fileobj = new File(path, name); + fileobj = new File(path, name); } } else if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) @@ -940,18 +945,18 @@ public class UniversalFileSystemMiner extends Miner { return statusDone(status); } - if (fileobj.isFile()) + if (fileobj.isFile()) { if (_archiveHandlerManager.isArchive(fileobj)) { subject.setAttribute(DE.A_TYPE,IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR); } else { subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR); } - } + } else { // directory subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR); } - + String name = fullName .substring( fullName.lastIndexOf(File.separatorChar) + 1, @@ -972,15 +977,15 @@ public class UniversalFileSystemMiner extends Miner { } subject.setAttribute(DE.A_NAME, name); subject.setAttribute(DE.A_VALUE, path); - - + + // DKM - do basic property stuff here subject.setAttribute(DE.A_SOURCE, setProperties(fileobj)); /* - // classify the file too + // classify the file too if (fileobj.isFile()) { subject.setAttribute(DE.A_SOURCE, subject .getAttribute(DE.A_SOURCE) @@ -1011,23 +1016,23 @@ public class UniversalFileSystemMiner extends Miner { subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR); subject.setAttribute(DE.A_NAME, child.name); - + subject.setAttribute(DE.A_VALUE, avp .getContainingArchiveString() + ArchiveHandlerManager.VIRTUAL_SEPARATOR + child.path); - + } else { subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR); String name = child.name; String path = avp.getContainingArchiveString(); - + path = path + ArchiveHandlerManager.VIRTUAL_SEPARATOR + child.path; - + subject.setAttribute(DE.A_NAME, name); subject.setAttribute(DE.A_VALUE, path); @@ -1079,7 +1084,7 @@ public class UniversalFileSystemMiner extends Miner { } - + /** * Method to obtain the classificatoin string of file or folder. */ @@ -1091,7 +1096,7 @@ public class UniversalFileSystemMiner extends Miner { if (tokens < 10) return null; - + return (str[10]); } /** @@ -1111,7 +1116,7 @@ public class UniversalFileSystemMiner extends Miner { str[i] = tokenizer.nextToken(); } */ - if (tokens > 1) + if (tokens > 1) { return (str[1]); } @@ -1152,7 +1157,7 @@ public class UniversalFileSystemMiner extends Miner { /** * Method to obtain the depth for a search */ - protected int getDepth(String s) + protected int getDepth(String s) { String[] str = s.split("\\"+IServiceConstants.TOKEN_SEPARATOR); //$NON-NLS-1$ int tokens = str.length; @@ -1171,13 +1176,13 @@ public class UniversalFileSystemMiner extends Miner { str[i] = tokenizer.nextToken(); } */ - return ((new Integer(str[3])).intValue()); + return ((new Integer(str[3])).intValue()); } /** * Method to download a file. */ - protected DataElement handleDownload(DataElement theElement, DataElement status) + protected DataElement handleDownload(DataElement theElement, DataElement status) { UniversalDownloadHandler downloadThread = new UniversalDownloadHandler( @@ -1200,12 +1205,12 @@ public class UniversalFileSystemMiner extends Miner { 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) @@ -1218,7 +1223,7 @@ public class UniversalFileSystemMiner extends Miner { UniversalServerUtilities.logError(CLASSNAME, "Can not get unused port", e, _dataStore); //$NON-NLS-1$ port = -1; } - + String portNum = String.valueOf(port); subject.setAttribute(DE.A_VALUE, portNum); _dataStore.refresh(subject); @@ -1256,11 +1261,11 @@ public class UniversalFileSystemMiner extends Miner { _dataStore.createObject(deUFSnode, IUniversalDataStoreConstants.UNIVERSAL_NODE_DESCRIPTOR, "universal.filters"); //$NON-NLS-1$ deUFSuploadlog = _dataStore.createObject(deUFSnode, IUniversalDataStoreConstants.UNIVERSAL_NODE_DESCRIPTOR, "universal.uploadlog"); //$NON-NLS-1$ - UniversalByteStreamHandler universalHandler = new UniversalByteStreamHandler(_dataStore, deUFSuploadlog); - + UniversalByteStreamHandler universalHandler = new UniversalByteStreamHandler(_dataStore, deUFSuploadlog); + //_dataStore.setByteStreamHandler(new UniversalByteStreamHandler(_dataStore, deUFSuploadlog)); _dataStore.registerByteStreamHandler(universalHandler); - + _dataStore.refresh(_minerData); _dataStore.refresh(deUFSuploadlog); } @@ -1304,25 +1309,25 @@ public class UniversalFileSystemMiner extends Miner { // 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 = "/"; //$NON-NLS-1$ } - + // 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; @@ -1337,9 +1342,9 @@ public class UniversalFileSystemMiner extends Miner { } try { - + String className = null; - + // if parent is not an archive or a virtual folder, then file must be // a file if (!(isParentArchive || isParentVirtual)) { @@ -1349,15 +1354,15 @@ public class UniversalFileSystemMiner extends Miner { else { String classification = SystemFileClassifier.getInstance().classifyFile(filePath); String execJava = "executable(java:"; //$NON-NLS-1$ - + int idx = classification.indexOf(execJava); - + if (idx != -1) { - idx = idx + execJava.length(); + idx = idx + execJava.length(); int jdx = classification.indexOf(")", idx); //$NON-NLS-1$ - + if (jdx != -1) { - + if (jdx > idx) { className = classification.substring(idx, jdx); } @@ -1377,7 +1382,7 @@ public class UniversalFileSystemMiner extends Miner { UniversalServerUtilities.logError(CLASSNAME, "I/O error occured trying to read class file " + filePath, //$NON-NLS-1$ null, _dataStore); - + _dataStore.createObject(status, IUniversalDataStoreConstants.TYPE_QUALIFIED_CLASSNAME, "null"); //$NON-NLS-1$ } @@ -1430,41 +1435,41 @@ public class UniversalFileSystemMiner extends Miner { // the cancellable object descriptor DataElement cancellable = _dataStore.find(schemaRoot, DE.A_NAME, DataStoreResources.model_Cancellable, 1); - + // Define command descriptors DataElement queryAllFilterDescriptor = createCommandDescriptor(UniversalFilter, "Filter", IUniversalDataStoreConstants.C_QUERY_VIEW_ALL); //$NON-NLS-1$ - _dataStore.createReference(cancellable, queryAllFilterDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); - + _dataStore.createReference(cancellable, queryAllFilterDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + DataElement queryFilesFilterDescriptor = createCommandDescriptor(UniversalFilter, "Filter", IUniversalDataStoreConstants.C_QUERY_VIEW_FILES); //$NON-NLS-1$ _dataStore.createReference(cancellable, queryFilesFilterDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); - - DataElement queryFolderFilterDescriptor = createCommandDescriptor(UniversalFilter, "Filter", IUniversalDataStoreConstants.C_QUERY_VIEW_FOLDERS); //$NON-NLS-1$ - _dataStore.createReference(cancellable, queryFolderFilterDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); - - createCommandDescriptor(UniversalFilter, "Filter", IUniversalDataStoreConstants.C_QUERY_ROOTS); //$NON-NLS-1$ - + DataElement queryFolderFilterDescriptor = createCommandDescriptor(UniversalFilter, "Filter", IUniversalDataStoreConstants.C_QUERY_VIEW_FOLDERS); //$NON-NLS-1$ + _dataStore.createReference(cancellable, queryFolderFilterDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + + createCommandDescriptor(UniversalFilter, "Filter", IUniversalDataStoreConstants.C_QUERY_ROOTS); //$NON-NLS-1$ + + DataElement queryAllDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "Filter", IUniversalDataStoreConstants.C_QUERY_VIEW_ALL); //$NON-NLS-1$ - _dataStore.createReference(cancellable, queryAllDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); - + _dataStore.createReference(cancellable, queryAllDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + DataElement queryFilesDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "Filter", IUniversalDataStoreConstants.C_QUERY_VIEW_FILES); //$NON-NLS-1$ - _dataStore.createReference(cancellable, queryFilesDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + _dataStore.createReference(cancellable, queryFilesDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); DataElement queryFolderDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "Filter", IUniversalDataStoreConstants.C_QUERY_VIEW_FOLDERS); //$NON-NLS-1$ - _dataStore.createReference(cancellable, queryFolderDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + _dataStore.createReference(cancellable, queryFolderDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + - DataElement queryAllArchiveDescriptor = createCommandDescriptor(FileDescriptors._deUniversalArchiveFileObject, "Filter", IUniversalDataStoreConstants.C_QUERY_VIEW_ALL); //$NON-NLS-1$ - _dataStore.createReference(cancellable, queryAllArchiveDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + _dataStore.createReference(cancellable, queryAllArchiveDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); DataElement queryFilesArchiveDescriptor = createCommandDescriptor(FileDescriptors._deUniversalArchiveFileObject, "Filter", IUniversalDataStoreConstants.C_QUERY_VIEW_FILES); //$NON-NLS-1$ - _dataStore.createReference(cancellable, queryFilesArchiveDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + _dataStore.createReference(cancellable, queryFilesArchiveDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); DataElement queryFolderArchiveDescriptor = createCommandDescriptor(FileDescriptors._deUniversalArchiveFileObject, "Filter", IUniversalDataStoreConstants.C_QUERY_VIEW_FOLDERS); //$NON-NLS-1$ - _dataStore.createReference(cancellable, queryFolderArchiveDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); - - createCommandDescriptor(UniversalFilter, "GetOSType", IUniversalDataStoreConstants.C_GET_OSTYPE); //$NON-NLS-1$ - createCommandDescriptor(UniversalFilter, "Exists", IUniversalDataStoreConstants.C_QUERY_EXISTS); //$NON-NLS-1$ + _dataStore.createReference(cancellable, queryFolderArchiveDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + + createCommandDescriptor(UniversalFilter, "GetOSType", IUniversalDataStoreConstants.C_GET_OSTYPE); //$NON-NLS-1$ + createCommandDescriptor(UniversalFilter, "Exists", IUniversalDataStoreConstants.C_QUERY_EXISTS); //$NON-NLS-1$ createCommandDescriptor(UniversalFilter, "GetRemoteObject", IUniversalDataStoreConstants.C_QUERY_GET_REMOTE_OBJECT); //$NON-NLS-1$ DataElement createNewFileFromFilterDescriptor = createCommandDescriptor(UniversalFilter, "CreateNewFile", IUniversalDataStoreConstants.C_CREATE_FILE); //$NON-NLS-1$ _dataStore.createReference(cancellable, createNewFileFromFilterDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); @@ -1474,21 +1479,21 @@ public class UniversalFileSystemMiner extends Miner { _dataStore.createReference(FileDescriptors._deUniversalFileObject, - FileDescriptors._deUniversalArchiveFileObject, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + FileDescriptors._deUniversalArchiveFileObject, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); _dataStore.createReference(FileDescriptors._deUniversalFolderObject, - FileDescriptors._deUniversalArchiveFileObject, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + FileDescriptors._deUniversalArchiveFileObject, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); _dataStore.createReference(FileDescriptors._deUniversalFileObject, - FileDescriptors._deUniversalVirtualFileObject, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + FileDescriptors._deUniversalVirtualFileObject, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); _dataStore.createReference(FileDescriptors._deUniversalFolderObject, - FileDescriptors._deUniversalVirtualFolderObject, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + FileDescriptors._deUniversalVirtualFolderObject, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); // create the search descriptor and make it cancelable - DataElement searchDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "Search", IUniversalDataStoreConstants.C_SEARCH); //$NON-NLS-1$ - _dataStore.createReference(cancellable, searchDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); - + DataElement searchDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "Search", IUniversalDataStoreConstants.C_SEARCH); //$NON-NLS-1$ + _dataStore.createReference(cancellable, searchDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "GetAdvanceProperty", IUniversalDataStoreConstants.C_QUERY_ADVANCE_PROPERTY); //$NON-NLS-1$ - createCommandDescriptor(tempnode, "Filter", IUniversalDataStoreConstants.C_CREATE_TEMP); //$NON-NLS-1$ + createCommandDescriptor(tempnode, "Filter", IUniversalDataStoreConstants.C_CREATE_TEMP); //$NON-NLS-1$ //create deleteDescriptor and make it cancelable DataElement deleteFileDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFileObject, "Delete", IUniversalDataStoreConstants.C_DELETE); //$NON-NLS-1$ _dataStore.createReference(cancellable, deleteFileDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); @@ -1507,11 +1512,11 @@ public class UniversalFileSystemMiner extends Miner { createCommandDescriptor(FileDescriptors._deUniversalFileObject, "SetReadOnly", IUniversalDataStoreConstants.C_SET_READONLY); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalFileObject, "SetLastModified", IUniversalDataStoreConstants.C_SET_LASTMODIFIED); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalFileObject, "GetAdvanceProperty", IUniversalDataStoreConstants.C_QUERY_ADVANCE_PROPERTY); //$NON-NLS-1$ - createCommandDescriptor(FileDescriptors._deUniversalFileObject, "GetBasicProperty", IUniversalDataStoreConstants.C_QUERY_BASIC_PROPERTY); //$NON-NLS-1$ + createCommandDescriptor(FileDescriptors._deUniversalFileObject, "GetBasicProperty", IUniversalDataStoreConstants.C_QUERY_BASIC_PROPERTY); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalFileObject, "GetcanWriteProperty", IUniversalDataStoreConstants.C_QUERY_CAN_WRITE_PROPERTY); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalFileObject, "Exists", IUniversalDataStoreConstants.C_QUERY_EXISTS); //$NON-NLS-1$ - + //create deleteDescriptor and make it cancelable DataElement deleteFolderDescriptor = createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "Delete", IUniversalDataStoreConstants.C_DELETE); //$NON-NLS-1$ _dataStore.createReference(cancellable, deleteFolderDescriptor, DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); @@ -1547,22 +1552,22 @@ public class UniversalFileSystemMiner extends Miner { createCommandDescriptor(FileDescriptors._deUniversalArchiveFileObject, "GetRemoteObject", IUniversalDataStoreConstants.C_QUERY_GET_REMOTE_OBJECT); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalVirtualFileObject, "GetRemoteObject", IUniversalDataStoreConstants.C_QUERY_GET_REMOTE_OBJECT); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalVirtualFolderObject, "GetRemoteObject", IUniversalDataStoreConstants.C_QUERY_GET_REMOTE_OBJECT); //$NON-NLS-1$ - + // create a download command descriptor and make it cancelable DataElement downloadDescriptor = createCommandDescriptor( FileDescriptors._deUniversalFileObject, "DownloadFile", IUniversalDataStoreConstants.C_DOWNLOAD_FILE); //$NON-NLS-1$ _dataStore.createReference(cancellable, downloadDescriptor, - DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); DataElement adownloadDescriptor = createCommandDescriptor( FileDescriptors._deUniversalArchiveFileObject, "DownloadFile", IUniversalDataStoreConstants.C_DOWNLOAD_FILE); //$NON-NLS-1$ _dataStore.createReference(cancellable, adownloadDescriptor, - DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + DataStoreResources.model_abstracts, DataStoreResources.model_abstracted_by); + - createCommandDescriptor(tempnode, "SystemEncoding", IUniversalDataStoreConstants.C_SYSTEM_ENCODING); //$NON-NLS-1$ - + createCommandDescriptor(tempnode, "UnusedPort", IUniversalDataStoreConstants.C_QUERY_UNUSED_PORT); //$NON-NLS-1$ // command descriptor to retrieve package name for a class file @@ -1571,8 +1576,8 @@ public class UniversalFileSystemMiner extends Miner { // command descriptor to retrieve qualified class name for class file createCommandDescriptor(FileDescriptors._deUniversalFileObject, "GetFullClassName", //$NON-NLS-1$ IUniversalDataStoreConstants.C_QUERY_QUALIFIED_CLASSNAME); - - + + // permissions and ownership not supported on windows if (!_isWindows) { // descriptors for permissions @@ -1580,14 +1585,14 @@ public class UniversalFileSystemMiner extends Miner { createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "GetPermissions", IUniversalDataStoreConstants.C_QUERY_FILE_PERMISSIONS); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalFileObject, "GetPermissions", IUniversalDataStoreConstants.C_QUERY_FILE_PERMISSIONS); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalArchiveFileObject, "GetPermissions",IUniversalDataStoreConstants.C_QUERY_FILE_PERMISSIONS); //$NON-NLS-1$ - + createCommandDescriptor(UniversalFilter, "SetPermissions", IUniversalDataStoreConstants.C_SET_FILE_PERMISSIONS); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalFolderObject, "SetPermissions", IUniversalDataStoreConstants.C_SET_FILE_PERMISSIONS); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalFileObject, "SetPermissions", IUniversalDataStoreConstants.C_SET_FILE_PERMISSIONS); //$NON-NLS-1$ createCommandDescriptor(FileDescriptors._deUniversalArchiveFileObject, "SetPermissions",IUniversalDataStoreConstants.C_SET_FILE_PERMISSIONS); //$NON-NLS-1$ } } - + public AbsoluteVirtualPath getAbsoluteVirtualPath(DataElement subject) { StringBuffer path = new StringBuffer(subject.getAttribute(DE.A_VALUE)); @@ -1608,39 +1613,39 @@ public class UniversalFileSystemMiner extends Miner { - public DataElement handleQueryAllArchive(DataElement subject, DataElement attributes, - DataElement status, boolean caseSensitive, boolean foldersOnly) + public DataElement handleQueryAllArchive(DataElement subject, DataElement attributes, + DataElement status, boolean caseSensitive, boolean foldersOnly) { // do query on a thread ArchiveQueryThread queryThread = new ArchiveQueryThread(subject, attributes, caseSensitive, foldersOnly, showHidden, _isWindows, status); - queryThread.start(); - + queryThread.start(); + updateCancellableThreads(status.getParent(), queryThread); return status; // query is in thread so not updating status here } - public ISystemArchiveHandler getArchiveHandlerFor(String archivePath) { + public ISystemArchiveHandler getArchiveHandlerFor(String archivePath) throws SystemMessageException { File file = new File(archivePath); return _archiveHandlerManager.getRegisteredHandler(file); } public DataElement handleCopy(DataElement targetFolder, DataElement sourceFile, DataElement nameObj, DataElement status) { - + CopySingleThread copySingleThread = new CopySingleThread(targetFolder, sourceFile, nameObj, this, _isWindows, status); copySingleThread.start(); updateCancellableThreads(status.getParent(), copySingleThread); - + return status; } - + /** * Method to obtain the properties of file or folder. */ - public String setProperties(File fileObj, boolean doArchiveProperties) { + public String setProperties(File fileObj, boolean doArchiveProperties) throws SystemMessageException { String version = IServiceConstants.VERSION_1; StringBuffer buffer = new StringBuffer(500); long date = fileObj.lastModified(); @@ -1687,7 +1692,7 @@ public class UniversalFileSystemMiner extends Miner { IServiceConstants.TOKEN_SEPARATOR); buffer.append(compressionRatio).append(IServiceConstants.TOKEN_SEPARATOR).append( expandedSize); - + String buf = buffer.toString(); return buf; @@ -1729,8 +1734,8 @@ public class UniversalFileSystemMiner extends Miner { return buffer.toString(); } - - public String setProperties(File fileObj) { + + public String setProperties(File fileObj) throws SystemMessageException { return setProperties(fileObj, false); } @@ -1739,14 +1744,14 @@ public class UniversalFileSystemMiner extends Miner { { return "7.0.0"; //$NON-NLS-1$ } - + private File getFileFor(DataElement subject) { File fileobj = null; boolean isVirtual = false; String fullName = subject.getValue(); String queryType = subject.getType(); - if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) + if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { isVirtual = ArchiveHandlerManager.isVirtual(fullName); String filterValue = subject.getValue(); @@ -1763,16 +1768,16 @@ public class UniversalFileSystemMiner extends Miner { } if (!isVirtual) fileobj = new File(filterValue); - } + } else if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR)) { String name = subject.getName(); String path = subject.getValue(); - fileobj = new File(path, name); + fileobj = new File(path, name); } else if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR)) { - String name = subject.getName(); + String name = subject.getName(); String path = subject.getValue(); if (name.length() == 0) { @@ -1780,12 +1785,12 @@ public class UniversalFileSystemMiner extends Miner { } else { - fileobj = new File(path, name); + fileobj = new File(path, name); } } else if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) { - String name = subject.getName(); + String name = subject.getName(); String path = subject.getValue(); if (name.length() == 0) { @@ -1793,8 +1798,8 @@ public class UniversalFileSystemMiner extends Miner { } else { - fileobj = new File(path, name); - } + fileobj = new File(path, name); + } } else if (queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { @@ -1802,8 +1807,8 @@ public class UniversalFileSystemMiner extends Miner { } return fileobj; } - - + + /** * Convert permissions in rwxrwxrwx form to octal * @param userPermissions @@ -1814,11 +1819,11 @@ public class UniversalFileSystemMiner extends Miner { StringBuffer buf = new StringBuffer(); // permissions char[] chars = alphaPermissions.toCharArray(); - + int offset = -1; for (int i = 0; i < 3; i++){ int value = 0; - + if (chars[++offset] == 'r'){ value = 4; } @@ -1827,14 +1832,14 @@ public class UniversalFileSystemMiner extends Miner { } if (chars[++offset] == 'x'){ value += 1; - } + } buf.append(value); } - - return buf.toString(); + + return buf.toString(); } - - + + /** * Gets file permissions in the form || * @param subject @@ -1844,26 +1849,26 @@ public class UniversalFileSystemMiner extends Miner { private DataElement handleQueryFilePermissions(DataElement subject, DataElement status) { File file = getFileFor(subject); - - + + // permissions in form "drwxrwxrwx ..." String ldStr = simpleShellCommand("ls -ld", file); //$NON-NLS-1$ - + StringTokenizer tokenizer = new StringTokenizer(ldStr, " \t"); //$NON-NLS-1$ - + // permissions in form "rwxrwxrwx" - String permString = tokenizer.nextToken().substring(1); + String permString = tokenizer.nextToken().substring(1); String octalPermissions = alphaPermissionsToOctal(permString); - // user and group + // user and group tokenizer.nextToken(); // nothing important String user = tokenizer.nextToken(); // 3rd String group = tokenizer.nextToken(); // 4th - String result = octalPermissions + '|' + user + '|' + group; + String result = octalPermissions + '|' + user + '|' + group; status.setAttribute(DE.A_SOURCE, result); statusDone(status); - + return status; } @@ -1877,22 +1882,22 @@ public class UniversalFileSystemMiner extends Miner { private DataElement handleSetFilePermissions(DataElement subject, DataElement newPermissions, DataElement status) { File file = getFileFor(subject); - + String permissionsStr = newPermissions.getName(); String[] permAttributes = permissionsStr.split("\\"+IServiceConstants.TOKEN_SEPARATOR); //$NON-NLS-1$ // set the permissions String result = simpleShellCommand("chmod " + permAttributes[0], file); //$NON-NLS-1$ - + // set the user simpleShellCommand("chown " + permAttributes[1], file); //$NON-NLS-1$ - + // set the group simpleShellCommand("chown :" + permAttributes[2], file); //$NON-NLS-1$ - + status.setAttribute(DE.A_SOURCE, result); statusDone(status); - + return status; } @@ -1903,12 +1908,12 @@ public class UniversalFileSystemMiner extends Miner { String args[] = new String[3]; args[0] = "sh"; //$NON-NLS-1$ args[1] = "-c"; //$NON-NLS-1$ - args[2] = cmd; - + args[2] = cmd; + BufferedReader childReader = null; try { Process childProcess = Runtime.getRuntime().exec(args); - + childReader = new BufferedReader(new InputStreamReader(childProcess.getInputStream())); result = childReader.readLine().trim(); @@ -1921,11 +1926,11 @@ public class UniversalFileSystemMiner extends Miner { catch (IOException ex){} } return result; - + } - + */ - + private String simpleShellCommand(String cmd, File file) { String result = null; @@ -1933,11 +1938,11 @@ public class UniversalFileSystemMiner extends Miner { args[0] = "sh"; //$NON-NLS-1$ args[1] = "-c"; //$NON-NLS-1$ args[2] = cmd + " " + PathUtility.enQuoteUnix(file.getAbsolutePath()); //$NON-NLS-1$ - + BufferedReader childReader = null; try { Process childProcess = Runtime.getRuntime().exec(args); - + childReader = new BufferedReader(new InputStreamReader(childProcess.getInputStream())); result = childReader.readLine().trim(); @@ -1950,6 +1955,6 @@ public class UniversalFileSystemMiner extends Miner { catch (IOException ex){} } return result; - + } } diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopyBatchThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopyBatchThread.java index f0f1281e3a5..9fede0e47e2 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopyBatchThread.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopyBatchThread.java @@ -8,10 +8,11 @@ * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer * component that contains this file: David McKnight. - * + * * Contributors: * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations * Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.rse.internal.dstore.universal.miners.filesystem; @@ -28,52 +29,52 @@ import org.eclipse.rse.services.clientserver.SystemOperationMonitor; import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath; import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler; import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; + +public class CopyBatchThread extends CopyThread { + -public class CopyBatchThread extends CopyThread { - - public CopyBatchThread(DataElement targetFolder, DataElement theElement, UniversalFileSystemMiner miner, boolean isWindows, DataElement status) { super(targetFolder, theElement, miner, isWindows, status); } - + public void run() { super.run(); - handleCopyBatch(); + try { + handleCopyBatch(); + } catch (SystemMessageException e) { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + miner.statusDone(status); + } _isDone = true; } - - private DataElement handleCopyBatch() + + private DataElement handleCopyBatch() throws SystemMessageException { String targetType = targetFolder.getType(); File tgtFolder = getFileFor(targetFolder); int numOfSources = theElement.getNestedSize() - 2; systemOperationMonitor = new SystemOperationMonitor(); - - if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) || targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) + + if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) || targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { // if target is virtual or an archive, insert into an archive AbsoluteVirtualPath vpath = miner.getAbsoluteVirtualPath(targetFolder); ISystemArchiveHandler handler = miner.getArchiveHandlerFor(vpath.getContainingArchiveString()); boolean result = true; - - if (handler == null) - { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - return miner.statusDone(status); - } List nonDirectoryArrayList = new ArrayList(); List nonDirectoryNamesArrayList = new ArrayList(); - + String virtualContainer = ""; //$NON-NLS-1$ - - if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) + + if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { virtualContainer = vpath.getVirtualPart(); } - + for (int i = 0; i < numOfSources; i++) { if (isCancelled()) @@ -86,21 +87,21 @@ public class CopyBatchThread extends CopyThread { File srcFile; if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR) - || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) - { + || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) + { srcFile = getFileFor(sourceFile); } - else if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) + else if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { AbsoluteVirtualPath svpath = miner.getAbsoluteVirtualPath(sourceFile); ISystemArchiveHandler shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString()); - - if (shandler == null) + + if (shandler == null) { status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); return miner.statusDone(status); } - + VirtualChild child = shandler.getVirtualFile(svpath.getVirtualPart(), systemOperationMonitor); srcFile = child.getExtractedFile(); } @@ -109,15 +110,16 @@ public class CopyBatchThread extends CopyThread { status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); return miner.statusDone(status); } - - //If this source file object is directory, we will call ISystemArchiveHandler#add(File ...) method to + + //If this source file object is directory, we will call ISystemArchiveHandler#add(File ...) method to //it and all its descendants into the archive file. //If this source file object is not a directory, we will add it into a list, and then //call ISystemArchiveHandler#add(File[] ...) to add them in batch. if (srcFile.isDirectory()) { - result = handler.add(srcFile, virtualContainer, srcName, systemOperationMonitor); - if (!result) { + try { + handler.add(srcFile, virtualContainer, srcName, systemOperationMonitor); + } catch (SystemMessageException e) { status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); if (isCancelled()) { @@ -127,6 +129,7 @@ public class CopyBatchThread extends CopyThread { { return miner.statusDone(status); } + } } else @@ -135,15 +138,19 @@ public class CopyBatchThread extends CopyThread { nonDirectoryNamesArrayList.add(srcName); } } - + if (nonDirectoryArrayList.size() > 0) { File[] resultFiles = (File[])nonDirectoryArrayList.toArray(new File[nonDirectoryArrayList.size()]); String[] resultNames = (String[])nonDirectoryNamesArrayList.toArray(new String[nonDirectoryNamesArrayList.size()]); //we need to add those files into the archive file as well. - result = handler.add(resultFiles, virtualContainer, resultNames, systemOperationMonitor); + try { + handler.add(resultFiles, virtualContainer, resultNames, systemOperationMonitor); + } catch (SystemMessageException e) { + result = false; + } } - + if (result) { status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); @@ -176,42 +183,38 @@ public class CopyBatchThread extends CopyThread { } DataElement sourceFile = miner.getCommandArgument(theElement, i+1); String srcType = sourceFile.getType(); - - if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) + + if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { // extract from an archive to folder - AbsoluteVirtualPath svpath = miner.getAbsoluteVirtualPath(sourceFile); - ISystemArchiveHandler shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString()); - - if (shandler == null) - { + try { + AbsoluteVirtualPath svpath = miner.getAbsoluteVirtualPath(sourceFile); + ISystemArchiveHandler shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString()); + VirtualChild child = shandler.getVirtualFile(svpath.getVirtualPart(), systemOperationMonitor); + + File parentDir = getFileFor(targetFolder); + File destination = new File(parentDir, sourceFile.getName()); + + if (child.isDirectory) { + shandler.extractVirtualDirectory(svpath.getVirtualPart(), parentDir, destination, systemOperationMonitor); + } else { + shandler.extractVirtualFile(svpath.getVirtualPart(), destination, systemOperationMonitor); + } + + } catch (SystemMessageException e) { status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); return miner.statusDone(status); } - - VirtualChild child = shandler.getVirtualFile(svpath.getVirtualPart(), systemOperationMonitor); - - File parentDir = getFileFor(targetFolder); - File destination = new File(parentDir, sourceFile.getName()); - - if (child.isDirectory) - { - shandler.extractVirtualDirectory(svpath.getVirtualPart(), parentDir, destination, systemOperationMonitor); - } - else - { - shandler.extractVirtualFile(svpath.getVirtualPart(), destination, systemOperationMonitor); - } } 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 + + // handle special characters in source and target strings src = enQuote(src); - + // handle window case separately, since xcopy command could not handler // multiple source names if (isWindows) @@ -234,13 +237,13 @@ public class CopyBatchThread extends CopyThread { source = source + " " + src; //$NON-NLS-1$ } numOfNonVirtualSources++; - } + } } // end for loop iterating through sources - + if (numOfNonVirtualSources > 0) { doCopyCommand(source, tgt, folderCopy, status); - } + } } // end if/then/else (target is regular folder) if (isCancelled()) { @@ -251,7 +254,7 @@ public class CopyBatchThread extends CopyThread { return miner.statusDone(status); } } - - + + } diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopySingleThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopySingleThread.java index bcb3641ae57..d253fd734e4 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopySingleThread.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CopySingleThread.java @@ -8,10 +8,11 @@ * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer * component that contains this file: David McKnight. - * + * * Contributors: * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations * Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.rse.internal.dstore.universal.miners.filesystem; @@ -27,32 +28,38 @@ 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.SystemMessageException; + +public class CopySingleThread extends CopyThread { -public class CopySingleThread extends CopyThread { - private DataElement nameObj; - - + + public CopySingleThread(DataElement targetFolder, DataElement theElement, DataElement nameObj, UniversalFileSystemMiner miner, boolean isWindows, DataElement status) { super(targetFolder, theElement, miner, isWindows, status); this.nameObj = nameObj; } - + public void run() { super.run(); - handleCopy(); + try { + handleCopy(); + } catch (SystemMessageException e) { + status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + miner.statusDone(status); + } _isDone = true; } - - private DataElement handleCopy() + + private DataElement handleCopy() throws SystemMessageException { DataElement sourceFile = theElement; String newName = nameObj.getName(); String targetType = targetFolder.getType(); String srcType = sourceFile.getType(); - //In the case of super transfer, the source file is a virtual file/folder inside the temporary zip file, and its type information is set to + //In the case of super transfer, the source file is a virtual file/folder inside the temporary zip file, and its type information is set to //default UNIVERSAL_FILTER_DESCRIPTOR since its information never been cached before. //We need to find out its real type first before going to different if statement. File srcFile = null; @@ -64,25 +71,25 @@ public class CopySingleThread extends CopyThread { { String goodFullName = ArchiveHandlerManager.cleanUpVirtualPath(sourceFile.getValue()); child = ArchiveHandlerManager.getInstance().getVirtualObject(goodFullName); - if (child.exists()) + if (child.exists()) { - if (child.isDirectory) + if (child.isDirectory) { srcType = IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR; - } else + } else { srcType = IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR; } } } } - + if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR) || targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { - + // insert into an archive AbsoluteVirtualPath vpath = miner.getAbsoluteVirtualPath(targetFolder); ISystemArchiveHandler handler = miner.getArchiveHandlerFor(vpath.getContainingArchiveString()); - + if (handler == null) { status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); return miner.statusDone(status); @@ -90,7 +97,7 @@ public class CopySingleThread extends CopyThread { if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR)) { - + srcFile = getFileFor(sourceFile); } else if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { @@ -99,7 +106,7 @@ public class CopySingleThread extends CopyThread { { AbsoluteVirtualPath svpath = miner.getAbsoluteVirtualPath(sourceFile); shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString()); - + if (shandler == null) { status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); return miner.statusDone(status); @@ -115,19 +122,12 @@ public class CopySingleThread extends CopyThread { } String virtualContainer = ""; //$NON-NLS-1$ - + if (targetType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { virtualContainer = vpath.getVirtualPart(); } - boolean result = handler.add(srcFile, virtualContainer, newName, systemOperationMonitor); - - if (result) { - status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); - } - else { - status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); - } + handler.add(srcFile, virtualContainer, newName, systemOperationMonitor); } else if (srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR) || srcType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { ISystemArchiveHandler shandler = null; @@ -136,7 +136,7 @@ public class CopySingleThread extends CopyThread { { svpath = miner.getAbsoluteVirtualPath(sourceFile); shandler = miner.getArchiveHandlerFor(svpath.getContainingArchiveString()); - + if (shandler == null) { status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); return miner.statusDone(status); @@ -152,7 +152,7 @@ public class CopySingleThread extends CopyThread { File parentDir = getFileFor(targetFolder); File destination = new File(parentDir, newName); - + if (child.isDirectory) { shandler.extractVirtualDirectory(svpath.getVirtualPart(), parentDir, destination, systemOperationMonitor); } @@ -169,7 +169,7 @@ public class CopySingleThread extends CopyThread { String src = srcFile.getAbsolutePath(); String tgt = tgtFolder.getAbsolutePath() + File.separatorChar + newName; File tgtFile = new File(tgt); - + if (tgtFile.exists() && tgtFile.isDirectory()) { //For Windows, we need to use xcopy command, which require the new directory @@ -179,13 +179,13 @@ public class CopySingleThread extends CopyThread { tgt = tgtFolder.getAbsolutePath(); } } - + doCopyCommand(enQuote(src), enQuote(tgt), folderCopy, status); } - + return miner.statusDone(status); } - - + + } diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CreateFileThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CreateFileThread.java index f8c40acf515..3a98e4cac41 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CreateFileThread.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CreateFileThread.java @@ -8,10 +8,11 @@ * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer * component that contains this file: David McKnight. - * + * * Contributors: * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations * Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.rse.internal.dstore.universal.miners.filesystem; @@ -20,6 +21,7 @@ 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.server.SecuredThread; import org.eclipse.rse.dstore.universal.miners.ICancellableHandler; import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner; @@ -29,7 +31,7 @@ import org.eclipse.rse.services.clientserver.SystemOperationMonitor; 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.dstore.core.server.SecuredThread; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; public class CreateFileThread extends SecuredThread implements ICancellableHandler { @@ -37,14 +39,14 @@ public class CreateFileThread extends SecuredThread implements ICancellableHandl protected DataElement _status; protected UniversalFileSystemMiner _miner; protected String _queryType; - + protected boolean _isCancelled = false; protected boolean _isDone = false; protected SystemOperationMonitor systemOperationMonitor = new SystemOperationMonitor(); - + public static final String CLASSNAME = "CreateFileThread"; //$NON-NLS-1$ - - + + public CreateFileThread(DataElement theElement, String queryType, UniversalFileSystemMiner miner, DataStore dataStore, DataElement status) { super(dataStore); @@ -53,9 +55,9 @@ public class CreateFileThread extends SecuredThread implements ICancellableHandl this._status = status; this._queryType = queryType; } - - - + + + public void cancel() { _isCancelled = true; @@ -72,16 +74,20 @@ public class CreateFileThread extends SecuredThread implements ICancellableHandl public boolean isDone() { return _isDone; } - + public void run() { super.run(); - - handleCreateFile(); + try { + handleCreateFile(); + } catch (SystemMessageException e) { + _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + _miner.statusDone(_status); + } _isDone = true; } - - private DataElement handleCreateFile() + + private DataElement handleCreateFile() throws SystemMessageException { boolean wasFilter = _queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR); if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FILE_DESCRIPTOR)) { @@ -115,11 +121,9 @@ public class CreateFileThread extends SecuredThread implements ICancellableHandl try { boolean done = filename.createNewFile(); if (ArchiveHandlerManager.getInstance().isArchive(filename)) { - done = ArchiveHandlerManager.getInstance() + ArchiveHandlerManager.getInstance() .createEmptyArchive(filename); - if (done) - _subject.setAttribute(DE.A_TYPE, - IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR); + _subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_ARCHIVE_FILE_DESCRIPTOR); } else { if (done) { @@ -152,9 +156,9 @@ public class CreateFileThread extends SecuredThread implements ICancellableHandl _dataStore.refresh(_subject); return _miner.statusDone(_status); } - + public DataElement handleCreateVirtualFile(DataElement subject, - DataElement status, String type) { + DataElement status, String type) throws SystemMessageException { AbsoluteVirtualPath vpath = null; if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CreateFolderThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CreateFolderThread.java index 157dede441a..ae357de7115 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CreateFolderThread.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/CreateFolderThread.java @@ -8,10 +8,11 @@ * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer * component that contains this file: David McKnight. - * + * * Contributors: * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations * Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.rse.internal.dstore.universal.miners.filesystem; @@ -20,6 +21,7 @@ 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.server.SecuredThread; import org.eclipse.rse.dstore.universal.miners.ICancellableHandler; import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner; @@ -29,7 +31,7 @@ import org.eclipse.rse.services.clientserver.SystemOperationMonitor; 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.dstore.core.server.SecuredThread; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; public class CreateFolderThread extends SecuredThread implements ICancellableHandler { @@ -37,14 +39,14 @@ public class CreateFolderThread extends SecuredThread implements ICancellableHan protected DataElement _status; protected UniversalFileSystemMiner _miner; protected String _queryType; - + protected boolean _isCancelled = false; protected boolean _isDone = false; protected SystemOperationMonitor systemOperationMonitor = new SystemOperationMonitor(); - + public static final String CLASSNAME = "CreateFileThread"; //$NON-NLS-1$ - - + + public CreateFolderThread(DataElement theElement, String queryType, UniversalFileSystemMiner miner, DataStore dataStore, DataElement status) { super(dataStore); @@ -53,9 +55,9 @@ public class CreateFolderThread extends SecuredThread implements ICancellableHan this._status = status; this._queryType = queryType; } - - - + + + public void cancel() { _isCancelled = true; @@ -72,37 +74,42 @@ public class CreateFolderThread extends SecuredThread implements ICancellableHan public boolean isDone() { return _isDone; } - + public void run() { super.run(); - handleCreateFile(); + try { + handleCreateFile(); + } catch (SystemMessageException e) { + _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + _miner.statusDone(_status); + } _isDone = true; } - - private DataElement handleCreateFile() + + private DataElement handleCreateFile() throws SystemMessageException { if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR)) { return handleCreateVirtualFolder(_subject, _status, _queryType); } File filename = null; - if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) + if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { if (_subject.getName().indexOf( - ArchiveHandlerManager.VIRTUAL_SEPARATOR) > 0) + ArchiveHandlerManager.VIRTUAL_SEPARATOR) > 0) { _subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_VIRTUAL_FOLDER_DESCRIPTOR); return handleCreateVirtualFolder(_subject, _status, _queryType); - } - else + } + else { filename = new File(_subject.getValue()); _subject.setAttribute(DE.A_TYPE, IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR); _subject.setAttribute(DE.A_SOURCE, _miner.setProperties(filename)); } - } + } else if (_queryType.equals(IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR)) { filename = new File(_subject.getValue()); @@ -115,23 +122,23 @@ public class CreateFolderThread extends SecuredThread implements ICancellableHan { if (filename.exists()) _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED_WITH_EXIST); - else + else { try { boolean done = filename.mkdirs(); - if (done) + if (done) { _status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); _subject.setAttribute(DE.A_SOURCE, _miner.setProperties(filename)); _subject.setAttribute(DE.A_TYPE,IUniversalDataStoreConstants.UNIVERSAL_FOLDER_DESCRIPTOR); _subject.setAttribute(DE.A_NAME, filename.getName()); _subject.setAttribute(DE.A_VALUE, filename.getParentFile().getAbsolutePath()); - } + } else { _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); } - + } catch (Exception e) { UniversalServerUtilities.logError(CLASSNAME, "handleCreateFolder failed", e, _dataStore); //$NON-NLS-1$ @@ -142,9 +149,9 @@ public class CreateFolderThread extends SecuredThread implements ICancellableHan _dataStore.refresh(_subject); return _miner.statusDone(_status); } - + public DataElement handleCreateVirtualFolder(DataElement subject, - DataElement status, String type) { + DataElement status, String type) throws SystemMessageException { AbsoluteVirtualPath vpath = null; if (type.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR)) { diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/DeleteThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/DeleteThread.java index 83b1afae6e3..a2440e04f2a 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/DeleteThread.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/DeleteThread.java @@ -8,10 +8,11 @@ * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer * component that contains this file: David McKnight. - * + * * Contributors: * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations * Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.rse.internal.dstore.universal.miners.filesystem; @@ -20,6 +21,7 @@ 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.server.SecuredThread; import org.eclipse.rse.dstore.universal.miners.ICancellableHandler; import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner; @@ -29,7 +31,7 @@ import org.eclipse.rse.services.clientserver.SystemOperationMonitor; 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.dstore.core.server.SecuredThread; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; public class DeleteThread extends SecuredThread implements ICancellableHandler { @@ -37,14 +39,14 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler { protected DataElement _status; protected UniversalFileSystemMiner _miner; protected boolean _batch; - + protected boolean _isCancelled = false; protected boolean _isDone = false; protected SystemOperationMonitor systemOperationMonitor = new SystemOperationMonitor(); - + public static final String CLASSNAME = "DeleteThread"; //$NON-NLS-1$ - - + + public DeleteThread(DataElement theElement, UniversalFileSystemMiner miner, DataStore dataStore, boolean batch, DataElement status) { super(dataStore); @@ -53,9 +55,9 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler { this._status = status; this._batch = batch; } - - - + + + public void cancel() { _isCancelled = true; @@ -72,22 +74,24 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler { public boolean isDone() { return _isDone; } - + public void run() { super.run(); - if (_batch) - { - handleDeleteBatch(); - } - else - { - handleDelete(_theElement, _status); + try { + if (_batch) { + handleDeleteBatch(); + } else { + handleDelete(_theElement, _status); + } + } catch (SystemMessageException e) { + _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + _miner.statusDone(_status); } _isDone = true; } - - private DataElement handleDeleteBatch() + + private DataElement handleDeleteBatch() throws SystemMessageException { DataElement substatus = _dataStore.createObject(null, "status", "substatus"); //$NON-NLS-1$ //$NON-NLS-2$ int numOfSources = _theElement.getNestedSize() - 2; @@ -100,7 +104,7 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler { DataElement subject = _miner.getCommandArgument(_theElement, i+1); handleDelete(subject, substatus); /* - if (!substatus.getSource().startsWith(IServiceConstants.SUCCESS)) + if (!substatus.getSource().startsWith(IServiceConstants.SUCCESS)) { status.setAttribute(DE.A_SOURCE, substatus.getSource()); return statusDone(status); @@ -110,7 +114,7 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler { _status.setAttribute(DE.A_SOURCE, substatus.getSource()); return _miner.statusDone(_status); } - private DataElement handleDelete(DataElement subject, DataElement thisStatus) + private DataElement handleDelete(DataElement subject, DataElement thisStatus) throws SystemMessageException { String type = subject.getType(); @@ -172,11 +176,11 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler { } _dataStore.refresh(subject); return _miner.statusDone(_status); - + } - + public DataElement handleDeleteFromArchive(DataElement subject, - DataElement status) { + DataElement status) throws SystemMessageException { String type = subject.getType(); DataElement deObj = null; @@ -207,10 +211,10 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler { _dataStore.refresh(subject); return _miner.statusDone(status); } - + /** * Delete directory and its children. - * + * */ public void deleteDir(File fileObj, DataElement status) { try { @@ -238,5 +242,5 @@ public class DeleteThread extends SecuredThread implements ICancellableHandler { "Deletion of dir failed", e, _dataStore); //$NON-NLS-1$ } } - + } diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/FileClassifier.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/FileClassifier.java index 8e8d88beb2a..843528dac25 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/FileClassifier.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/FileClassifier.java @@ -7,15 +7,16 @@ * * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer - * component that contains this file: David McKnight, Kushal Munir, - * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. - * + * * Contributors: - * Martin Oberhuber (Wind River) - Fix 154874 - handle files with space or $ in the name + * Martin Oberhuber (Wind River) - Fix 154874 - handle files with space or $ in the name * Martin Oberhuber (Wind River) - [186640] Fix case sensitive issue comparing z/OS - * Xuan Chen (IBM) - [191280] [dstore] Expand fails for folder "/folk" with 3361 children + * Xuan Chen (IBM) - [191280] [dstore] Expand fails for folder "/folk" with 3361 children * Xuan Chen (IBM) - [215863]] NPE when Expanding Empty Zip File + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.rse.internal.dstore.universal.miners.filesystem; @@ -82,10 +83,10 @@ public class FileClassifier extends Thread } public static final String symbolicLinkStr = "symbolic link to"; //$NON-NLS-1$ - + public static final String fileSep = System.getProperty("file.separator"); //$NON-NLS-1$ public static final String defaultType = "file"; //$NON-NLS-1$ - + public static final String STR_SYMBOLIC_LINK = "symbolic link"; //$NON-NLS-1$ public static final String STR_SHARED_OBJECT="shared object"; //$NON-NLS-1$ public static final String STR_OBJECT_MODULE="object module"; //$NON-NLS-1$ @@ -100,7 +101,7 @@ public class FileClassifier extends Thread public static final String STR_DOT_SO_DOT=".so."; //$NON-NLS-1$ public static final String STR_DIRECTORY="diectory"; //$NON-NLS-1$ - + private DataElement _subject; private DataStore _dataStore; @@ -112,7 +113,7 @@ public class FileClassifier extends Thread private List _fileMap; private boolean _classifyChildren = true; - + private boolean _classifyFilter = false; private boolean _canResolveLinks = false; @@ -120,9 +121,9 @@ public class FileClassifier extends Thread private boolean _classifyVirtual = false; private boolean _systemSupportsClassify = true; - + private boolean _systemSupportsClassFilesOnly = false; - + private List _lines; public FileClassifier(DataElement subject) @@ -144,7 +145,7 @@ public class FileClassifier extends Thread else if (osName.equals("z/os")) { //$NON-NLS-1$ _systemSupportsClassFilesOnly = true; } - + _systemShell = "sh"; //$NON-NLS-1$ _canResolveLinks = osName.startsWith("linux"); //$NON-NLS-1$ @@ -165,7 +166,7 @@ public class FileClassifier extends Thread { _classifyVirtual = false; } - + _classifyFilter = objType.equals(IUniversalDataStoreConstants.UNIVERSAL_FILTER_DESCRIPTOR); // if the subject is a file or a virtual file (i.e. not a directory or @@ -221,7 +222,7 @@ public class FileClassifier extends Thread /** * 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. @@ -274,12 +275,12 @@ public class FileClassifier extends Thread { filePath = _subject.getValue(); } - - + + // if we have to classify children if (_classifyChildren) { - + // if it's not a classification of virtual files if (!_classifyVirtual) @@ -315,7 +316,7 @@ public class FileClassifier extends Thread classifiedProperties.append(type); classifiedProperties.append(')'); _subject.setAttribute(DE.A_SOURCE, classifiedProperties.toString()); - + } catch (Exception e) { @@ -328,7 +329,7 @@ public class FileClassifier extends Thread /** * 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. @@ -339,7 +340,7 @@ public class FileClassifier extends Thread { // this string should be contained in an output line that indicates a // symbolic link - + // default type String type = defaultType; @@ -361,7 +362,7 @@ public class FileClassifier extends Thread String parentPath = parentFile.getAbsolutePath(); // get file separator - + // if parent path does not end with separator, then add it if (!parentPath.endsWith(fileSep)) @@ -416,18 +417,18 @@ public class FileClassifier extends Thread } return type; } - + // if the system supports only classifying *.class files, then return generic type "file". if (_systemSupportsClassFilesOnly) { return type; } /* DKM - let the client have the raw type instead of doing this for it - * + * 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)) { @@ -529,7 +530,7 @@ public class FileClassifier extends Thread /** * Classify a file. It classifies the file by running "sh -c file * ". - * + * * @param aFile the file to classify. * @return the classification. */ @@ -597,8 +598,8 @@ public class FileClassifier extends Thread { encoding = System.getProperty("file.encoding"); //$NON-NLS-1$ } - - + + try { byte[] readBytes = new byte[1024]; @@ -615,14 +616,14 @@ public class FileClassifier extends Thread { return _lines; } - - + + // 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 // tokenize the output so that we can get each line of @@ -636,7 +637,7 @@ public class FileClassifier extends Thread 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]); @@ -647,23 +648,23 @@ public class FileClassifier extends Thread { e.printStackTrace(); } - available = stream.available(); + available = stream.available(); } } catch (Exception e) { e.printStackTrace(); } - + return _lines; } - + protected String readLine(DataInputStream stream, String encoding) throws Exception { if (_lines.size() == 0) { - _lines = readLines(stream, encoding); + _lines = readLines(stream, encoding); } if (_lines == null) { @@ -678,7 +679,7 @@ public class FileClassifier extends Thread /** * 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. @@ -864,7 +865,7 @@ public class FileClassifier extends Thread if (linkIndex != -1) { int cutOffIndex = linkIndex + textToCheck.length(); - + StringBuffer typeBuf = new StringBuffer(); typeBuf.append('('); typeBuf.append(type); @@ -941,8 +942,8 @@ public class FileClassifier extends Thread /** * Classify virtual children. - * - * @param parentPath the full path of the parent file. + * + * @param parentPath the full path of the parent file. * The path could represent an archive or a virtual folder. */ protected void classifyVirtualChildren(String parentPath) @@ -1035,14 +1036,14 @@ public class FileClassifier extends Thread StringBuffer currentProperties = new StringBuffer(element.getAttribute(DE.A_SOURCE)); currentProperties.append('|'); currentProperties.append(type); - + element.setAttribute(DE.A_SOURCE, currentProperties.toString()); } } } } } - catch (IOException e) + catch (Exception e) { // TODO: log error } diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/QueryThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/QueryThread.java index ce6ed47bad9..b13c709bd8c 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/QueryThread.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/QueryThread.java @@ -8,9 +8,10 @@ * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer * component that contains this file: David McKnight. - * + * * Contributors: * Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.rse.internal.dstore.universal.miners.filesystem; @@ -24,22 +25,23 @@ import org.eclipse.rse.dstore.universal.miners.ICancellableHandler; import org.eclipse.rse.services.clientserver.IServiceConstants; import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; public class QueryThread extends SecuredThread implements ICancellableHandler { protected DataElement _subject; protected DataElement _status; - + protected boolean _isCancelled = false; protected boolean _isDone = false; - + public QueryThread(DataElement subject, DataElement status) { super(subject.getDataStore()); _subject = subject; _status = status; } - + /** * Complete status. */ @@ -48,7 +50,7 @@ public class QueryThread extends SecuredThread implements ICancellableHandler { _dataStore.refresh(status); return status; } - + public void cancel() { _isCancelled = true; @@ -61,7 +63,7 @@ public class QueryThread extends SecuredThread implements ICancellableHandler { public boolean isDone() { return _isDone; } - + public String setProperties(File fileObj) { return setProperties(fileObj, false); @@ -82,14 +84,18 @@ public class QueryThread extends SecuredThread implements ICancellableHandler { // 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.. + // DKM: defer this until later as it is bad for performance... // 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); + try { + comment = ArchiveHandlerManager.getInstance().getComment(fileObj); + } catch (SystemMessageException e) { + comment = " "; //$NON-NLS-1$ + } else comment = " "; //$NON-NLS-1$ @@ -99,8 +105,11 @@ public class QueryThread extends SecuredThread implements ICancellableHandler { long expandedSize; if (isArchive) - expandedSize = ArchiveHandlerManager.getInstance().getExpandedSize( - fileObj); + try { + expandedSize = ArchiveHandlerManager.getInstance().getExpandedSize(fileObj); + } catch (SystemMessageException e) { + expandedSize = 0; + } else expandedSize = size; @@ -117,7 +126,7 @@ public class QueryThread extends SecuredThread implements ICancellableHandler { IServiceConstants.TOKEN_SEPARATOR); buffer.append(compressionRatio).append(IServiceConstants.TOKEN_SEPARATOR).append( expandedSize); - + String buf = buffer.toString(); return buf; diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/RenameThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/RenameThread.java index e505b26be0f..0cd96f2fd24 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/RenameThread.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/RenameThread.java @@ -8,10 +8,11 @@ * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer * component that contains this file: David McKnight. - * + * * Contributors: * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations * Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.rse.internal.dstore.universal.miners.filesystem; @@ -20,6 +21,7 @@ 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.server.SecuredThread; import org.eclipse.rse.dstore.universal.miners.ICancellableHandler; import org.eclipse.rse.dstore.universal.miners.UniversalFileSystemMiner; import org.eclipse.rse.dstore.universal.miners.UniversalServerUtilities; @@ -28,21 +30,21 @@ import org.eclipse.rse.services.clientserver.SystemOperationMonitor; 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.dstore.core.server.SecuredThread; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; public class RenameThread extends SecuredThread implements ICancellableHandler { protected DataElement _subject; protected DataElement _status; protected UniversalFileSystemMiner _miner; - + protected boolean _isCancelled = false; protected boolean _isDone = false; protected SystemOperationMonitor systemOperationMonitor = new SystemOperationMonitor(); - + public static final String CLASSNAME = "RenameThread"; //$NON-NLS-1$ - - + + public RenameThread(DataElement theElement, UniversalFileSystemMiner miner, DataStore dataStore, DataElement status) { super(dataStore); @@ -50,8 +52,8 @@ public class RenameThread extends SecuredThread implements ICancellableHandler { this._miner = miner; this._status = status; } - - + + public void cancel() { _isCancelled = true; @@ -68,15 +70,20 @@ public class RenameThread extends SecuredThread implements ICancellableHandler { public boolean isDone() { return _isDone; } - + public void run() { super.run(); - handleRename(); + try { + handleRename(); + } catch (SystemMessageException e) { + _status.setAttribute(DE.A_SOURCE, IServiceConstants.FAILED); + _miner.statusDone(_status); + } _isDone = true; } - - private DataElement handleRename() + + private DataElement handleRename() throws SystemMessageException { File fileoldname = new File(_subject.getAttribute(DE.A_VALUE) + File.separatorChar + _subject.getName()); @@ -91,16 +98,14 @@ public class RenameThread extends SecuredThread implements ICancellableHandler { ISystemArchiveHandler handler = archiveHandlerManager .getRegisteredHandler(new File(oldAbsPath .getContainingArchiveString())); - boolean success = !(handler == null) - && handler.fullRename(oldAbsPath.getVirtualPart(), - newAbsPath.getVirtualPart(), systemOperationMonitor); - if (success && handler != null) { + if (handler != null) { + handler.fullRename(oldAbsPath.getVirtualPart(), newAbsPath.getVirtualPart(), systemOperationMonitor); _subject.setAttribute(DE.A_NAME, filerename.getName()); _subject.setAttribute(DE.A_SOURCE, _miner.setProperties(handler .getVirtualFile(newAbsPath.getVirtualPart(), systemOperationMonitor))); _status.setAttribute(DE.A_SOURCE, IServiceConstants.SUCCESS); _dataStore.update(_subject); - } + } else if (systemOperationMonitor.isCancelled()) { _subject.setAttribute(DE.A_SOURCE, _miner.setProperties(handler @@ -140,7 +145,7 @@ public class RenameThread extends SecuredThread implements ICancellableHandler { _dataStore.refresh(_subject); return _miner.statusDone(_status); } - + // DKM: during folder rename we need to recursively update all the parent // paths private void updateChildProperties(DataElement subject, File filerename) { diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/UniversalSearchHandler.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/UniversalSearchHandler.java index a4524527347..57089153e20 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/UniversalSearchHandler.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/filesystem/UniversalSearchHandler.java @@ -7,16 +7,17 @@ * * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer - * component that contains this file: David McKnight, Kushal Munir, - * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. - * + * * Contributors: * Michael Berger (IBM) - Bug 147791 - symbolic links can cause circular search. * David McKnight (IBM) - [190010] cancelling search * Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread * David McKnight (IBM) - [214378] canonical path not required - problem is in the client * Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.rse.internal.dstore.universal.miners.filesystem; @@ -31,6 +32,7 @@ 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.server.SecuredThread; import org.eclipse.dstore.core.util.StringCompare; import org.eclipse.rse.dstore.universal.miners.ICancellableHandler; import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; @@ -41,11 +43,11 @@ 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.messages.SystemMessageException; 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; -import org.eclipse.dstore.core.server.SecuredThread; public class UniversalSearchHandler extends SecuredThread implements ICancellableHandler { @@ -59,19 +61,19 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl 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) { @@ -80,35 +82,35 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl _searchString = searchString; _fsCaseSensitive = fsCaseSensitive; _alreadySearched = new HashSet(); - + _deGrep = _dataStore.findObjectDescriptor("grep"); //$NON-NLS-1$ _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(); } @@ -123,7 +125,7 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl } _isDone = true; - + if (_isCancelled) { _miner.statusCancelled(_status); @@ -134,10 +136,10 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl // 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); + // _miner.statusDone(_status); _status.setAttribute(DE.A_NAME, "done"); //$NON-NLS-1$ _dataStore.refresh(_status, true); // true indicates refresh immediately - + } } @@ -150,10 +152,10 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl } public void cancel() { - _isCancelled = true; + _isCancelled = true; } - protected boolean hasSearchedDirectory(File file) + protected boolean hasSearchedDirectory(File file) { try { @@ -166,25 +168,25 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl } } - protected void internalSearch(File theFile, int depth) { - + protected void internalSearch(File theFile, int depth) throws SystemMessageException { + // 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); @@ -194,38 +196,38 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl // 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) && + if (!isDirectory && + (!isArchive || _isFileSearch) && !isVirtualDirectory && - doesFilePatternMatch(compareStr) && - doesClassificationMatch(absPath)) + 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("")) { //$NON-NLS-1$ - deObj.setAttribute(DE.A_VALUE, vc.getContainingArchive().getAbsolutePath()); + 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, null); - + // if at least one match found, then send back the remote file with matches if (results != null && results.length > 0) { convert(deObj, absPath, results); @@ -236,7 +238,7 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl // otherwise if it is a file search, return the remote file back with no children else { deObj.setParent(_status); - _status.addNestedData(deObj, false); + _status.addNestedData(deObj, false); } } } @@ -248,10 +250,10 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl 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)) { @@ -259,21 +261,21 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl _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)) { - + try { _alreadySearched.add(theFile.getCanonicalFile()); @@ -285,34 +287,34 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl } 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) { + catch (Exception e) { UniversalServerUtilities.logError(_miner.getName(), "Error occured trying to get the canonical file", e, _dataStore); //$NON-NLS-1$ } - + 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; } @@ -322,11 +324,11 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl else { children = theFile.listFiles(); } - + if (children != null) { - + for (int i = 0; i < children.length && !_isCancelled; i++) { - + File child = children[i]; internalSearch(child, depth - 1); } @@ -341,24 +343,24 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl 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) { @@ -371,14 +373,14 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl 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("")) { //$NON-NLS-1$ return true; } @@ -387,7 +389,7 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl 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. @@ -395,9 +397,9 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl * @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); diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/SystemFileClassifier.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/SystemFileClassifier.java index c6424f041a9..51a46e0b54e 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/SystemFileClassifier.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/SystemFileClassifier.java @@ -1,17 +1,18 @@ /******************************************************************************** - * Copyright (c) 2006 IBM Corporation and others. All rights reserved. + * Copyright (c) 2006, 2008 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 + * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html - * + * * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer - * component that contains this file: David McKnight, Kushal Munir, - * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. - * + * * Contributors: - * Martin Oberhuber (Wind River) - Fix 154874 - handle files with space or $ in the name + * Martin Oberhuber (Wind River) - Fix 154874 - handle files with space or $ in the name + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers ********************************************************************************/ package org.eclipse.rse.services.clientserver; @@ -26,13 +27,14 @@ import java.io.UnsupportedEncodingException; import org.eclipse.rse.services.clientserver.archiveutils.AbsoluteVirtualPath; import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; import org.eclipse.rse.services.clientserver.java.BasicClassFileParser; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; /** * This singleton class classifies a file on the remote system. */ public class SystemFileClassifier { - + private static SystemFileClassifier instance; /** @@ -41,20 +43,20 @@ public class SystemFileClassifier { private SystemFileClassifier() { super(); } - + /** * Returns the singleton instance. * @return the singleton instance. */ public static SystemFileClassifier getInstance() { - + if (instance == null) { instance = new SystemFileClassifier(); } - + return instance; } - + /** * Classifies the file with the given absolute path. The absolute path can represent a virtual file. * By default, returns "file". @@ -62,10 +64,10 @@ public class SystemFileClassifier { * @return the classification. */ public String classifyFile(String absolutePath) { - + // first check if the absolute path is virtual boolean isVirtual = ArchiveHandlerManager.isVirtual(absolutePath); - + // if virtual, classify using archive handler manager if (isVirtual) { return classifyVirtual(absolutePath); @@ -75,52 +77,56 @@ public class SystemFileClassifier { return classifyNonVirtual(absolutePath); } } - + /** * Classifies a virtual file with the given path. * @param absolutePath the absolute path of the virtual file. * @return the classification. */ protected String classifyVirtual(String absolutePath) { - - // create an abolute virtual path object + + // create an absolute virtual path object AbsoluteVirtualPath avp = new AbsoluteVirtualPath(absolutePath); - + // get the path of the containing archive String archivePath = avp.getContainingArchiveString(); - + // get the virtual part of the file path String virtualPath = avp.getVirtualPart(); - + // get archive file File archiveFile = new File(archivePath); - + // get classification of virtual file - return ArchiveHandlerManager.getInstance().getClassification(archiveFile, virtualPath); + try { + return ArchiveHandlerManager.getInstance().getClassification(archiveFile, virtualPath); + } catch (SystemMessageException e) { + return "file"; //FIXME check fallback //$NON-NLS-1$ + } } - + /** * Classifies a non-virtual file with the given path. * @param absolutePath the absolute path of the file. * @return the classification. */ protected String classifyNonVirtual(String absolutePath) { - + // default type String type = "file"; //$NON-NLS-1$ - + File file = new File(absolutePath); - + // check if file exists if (!file.exists()) { return type; } - + // find out if we are on Windows boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("win"); //$NON-NLS-1$ //$NON-NLS-2$ - + // for Windows, we only detect *.exe and *.dll files - if (isWindows) + if (isWindows) { absolutePath = absolutePath.toLowerCase(); // classify *.class file @@ -135,43 +141,43 @@ public class SystemFileClassifier { else if (absolutePath.endsWith(".dll")) { //$NON-NLS-1$ type = "module"; //$NON-NLS-1$ } - + return type; } - + // get specified encoding if any String encoding = System.getProperty("dstore.stdin.encoding"); //$NON-NLS-1$ - + // otherwise, default to system encoding if (encoding == null || encoding.equals("")) { //$NON-NLS-1$ encoding = System.getProperty("file.encoding"); //$NON-NLS-1$ } - + // create command "sh -c file " String args[] = new String[3]; args[0] = "sh"; //$NON-NLS-1$ args[1] = "-c"; //$NON-NLS-1$ args[2] = "file " + PathUtility.enQuoteUnix(absolutePath); //$NON-NLS-1$ - + BufferedReader poutReader = null; - + try { Process childProcess = Runtime.getRuntime().exec(args); InputStreamReader reader = new InputStreamReader(childProcess.getInputStream(), encoding); poutReader = new BufferedReader(reader); - + // get line of output String line = poutReader.readLine(); - + if (line != null) { line = line.trim(); - + // classify from line of output type = getClassification(absolutePath, line); - + // close stream poutReader.close(); - + // if it a symbolic link, then get the canonical path and classify it as well if (type.equals("link")) { //$NON-NLS-1$ String canonicalPath = file.getCanonicalPath(); @@ -190,37 +196,37 @@ public class SystemFileClassifier { // TODO: log it return type; } - + return type; } - + /** * Classifies from the given line of classification output. * @param absolutePath the absolute path of the file that was classified. - * @param line the line of output to parse. + * @param line the line of output to parse. * @return the classification. */ protected String getClassification(String absolutePath, String line) { - + // default type String type = "file"; //$NON-NLS-1$ - + String name = line; String fulltype = ""; //$NON-NLS-1$ - + // Look for colon. Name appears before colon. Full type appears after the colon int colon = line.indexOf(':'); if (colon >= 0) { name = line.substring(0, colon); fulltype = line.substring(colon + 1, line.length()).trim(); } - + // if it is a *.class file, then we look for main method and qulaified class name // as part of the classification if (name.endsWith(".class")) { //$NON-NLS-1$ type = classifyClassFile(absolutePath); } - + // check if it is a shared library boolean matchesLib = (fulltype.indexOf("shared object") > -1) || //$NON-NLS-1$ (fulltype.indexOf("object module") > -1) || //$NON-NLS-1$ @@ -228,22 +234,22 @@ public class SystemFileClassifier { // check if it is an executable boolean matchesExe = (fulltype.indexOf("executable") > -1); //$NON-NLS-1$ - + // check if it is a script boolean matchesScript = (fulltype.indexOf("script") > -1); //$NON-NLS-1$ - + // shared library if (matchesLib) { - + // all *.a, *.so and *.so.* files are of type "module" if (name.endsWith(".a") || name.endsWith(".so") || (name.indexOf(".so.") > 0)) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ type = "module"; //$NON-NLS-1$ } } - + // a script file else if (matchesScript) { - + // an executable script file if (matchesExe) { type = "executable(script)"; //$NON-NLS-1$ @@ -253,74 +259,74 @@ public class SystemFileClassifier { type = "script"; //$NON-NLS-1$ } } - + // binary executable else if (matchesExe) { type = "executable(binary)"; //$NON-NLS-1$ } - + // on iSeries we look for "OS/400 object" as a type else if (fulltype.indexOf("OS/400 object") > -1) { //$NON-NLS-1$ type = "OS/400 object"; //$NON-NLS-1$ } - + // finally, if the full type contains the symbolic link string, then type is simply "link" else if (fulltype.startsWith("symbolic link to")) { //$NON-NLS-1$ type = "link"; //$NON-NLS-1$ } - - return type; + + return type; } - + /** * Classifies a class file. * @param absolutePath the absolute path of the class file. * @return the classification. */ protected String classifyClassFile(String absolutePath) { - + // default type String type = "file"; //$NON-NLS-1$ - + // input stream to file FileInputStream stream = null; - + // class file parser BasicClassFileParser parser = null; - + boolean isExecutable = false; - + try { stream = new FileInputStream(absolutePath); - + // 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; return type; } - + // if it is executable, then also get qualified class name if (isExecutable) { type = "executable(java"; //$NON-NLS-1$ - + String qualifiedClassName = parser.getQualifiedClassName(); - + if (qualifiedClassName != null) { type = type + ":" + qualifiedClassName; //$NON-NLS-1$ } - + type = type + ")"; //$NON-NLS-1$ } - + return type; } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/ArchiveHandlerManager.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/ArchiveHandlerManager.java index 4fb16b9337c..0f4973439f0 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/ArchiveHandlerManager.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/ArchiveHandlerManager.java @@ -10,13 +10,14 @@ * component that contains this file: David McKnight, Kushal Munir, * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. - * + * * Contributors: * Xuan Chen (IBM) - [194293] [Local][Archives] Saving file second time in an Archive Errors * Xuan Chen (IBM) - [202949] [archives] copy a folder from one connection to an archive file in a different connection does not work * Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread * Xuan Chen (IBM) - [218491] ArchiveHandlerManager#cleanUpVirtualPath is messing up the file separators (with updated fix) * Johnson Ma (Wind River) - [195402] [api] add tar.gz archive support + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.rse.services.clientserver.archiveutils; @@ -27,6 +28,11 @@ import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Iterator; +import org.eclipse.rse.internal.services.Activator; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.clientserver.messages.SystemOperationFailedException; +import org.eclipse.rse.services.clientserver.messages.SystemUnsupportedOperationException; + /** * This class manages all the Archive Handlers that correspond to the archive file that the system * would like to deal with. It contains methods for registering handlers with file types, as well as @@ -46,14 +52,14 @@ public class ArchiveHandlerManager /** * Folder separator used in virtual paths inside the archive, i.e. after the * VIRTUAL_SEPARATOR. - * + * * @since org.eclipse.rse.services 3.0 */ public static final String VIRTUAL_FOLDER_SEPARATOR = "/"; //$NON-NLS-1$ /** * Character used to separate file extension from file name. This is used in * order to recognize file patterns that should be treated as archives. - * + * * @since org.eclipse.rse.services 3.0 */ public static final String EXTENSION_SEPARATOR = "."; //$NON-NLS-1$ @@ -82,36 +88,51 @@ public class ArchiveHandlerManager } /** - * Returns the children of an object in the virtual file system. + * Returns the children of an object in the virtual file system. Throws + * SystemMessageException instead of IOException since RSE 3.0. + * * @param file The archive in whose virtual file system the children reside. - * @param virtualpath The parent virtual object whose children this method is to return. To - * get the top level virtualchildren in the archive, set virtualpath to "" or null. - * @return An array of VirtualChild objects representing the children of the virtual object - * in file referred to by virtualpath. If no class implementing - * ISystemArchiveHandler can be found that corresponds to file, then this method returns null. - * If the virtual object has no children, this method also returns null. - * @throws IOException if there was a problem getting the registered handler for the - * file. This usually means the archive is corrupted. + * @param virtualpath The parent virtual object whose children this method + * is to return. To get the top level virtual children in the archive, + * set virtual path to "" or null. + * @return An array of VirtualChild objects representing the children of the + * virtual object in file referred to by + * virtual path. If no class implementing ISystemArchiveHandler + * can be found that corresponds to file, then this method returns null. If + * the virtual object has no children, this method also returns null. + * @throws SystemMessageException in case of an error, e.g. there was a + * problem getting the registered handler for the file. This usually + * means the archive is corrupted. + * @since 3.0 */ - public VirtualChild[] getContents(File file, String virtualpath) throws IOException + public VirtualChild[] getContents(File file, String virtualpath) throws SystemMessageException { if (virtualpath == null) virtualpath = ""; //$NON-NLS-1$ ISystemArchiveHandler handler = getRegisteredHandler(file); - if (handler == null || !handler.exists()) throw new IOException(); + if (handler == null || !handler.exists()) { + throw new SystemUnsupportedOperationException(Activator.PLUGIN_ID, "No handler for " + file); //$NON-NLS-1$ + } return handler.getVirtualChildren(virtualpath, null); } /** - * Returns the children of an object in the virtual file system that are folders. + * Returns the children of an object in the virtual file system that are + * folders. + * * @param file The archive in whose virtual file system the children reside. - * @param virtualpath The parent virtual object whose children this method is to return. To - * get the top level virtualchildren in the archive, set virtualpath to "" or null. - * @return An array of VirtualChild objects representing the children of the virtual object - * in file referred to by virtualpath that are themselves folders. - * If no class implementing ISystemArchiveHandler can be found that corresponds to file, then - * this method returns null. If the virtual object has no children, this method also returns null. + * @param virtualpath The parent virtual object whose children this method + * is to return. To get the top level virtual children in the archive, + * set virtual path to "" or null. + * @return An array of VirtualChild objects representing the children of the + * virtual object in file referred to by + * virtualpath that are themselves folders. If no class + * implementing ISystemArchiveHandler can be found that corresponds to + * file, then this method returns null. If the virtual object has no + * children, this method also returns null. + * @throws SystemMessageException in case of an error + * @since 3.0 */ - public VirtualChild[] getFolderContents(File file, String virtualpath) + public VirtualChild[] getFolderContents(File file, String virtualpath) throws SystemMessageException { if (virtualpath == null) virtualpath = ""; //$NON-NLS-1$ ISystemArchiveHandler handler = getRegisteredHandler(file); @@ -222,14 +243,18 @@ public class ArchiveHandlerManager } /** - * Given the absolute path to a virtual object, returns that object - * as a VirtualChild. - * @param fullyQualifiedName The absolute path to the object. Usually consists - * of the fullyQualifiedName of the archive, followed by the virtual path separator - * (defined in ArchiveHandlerManager.VIRTUAL_SEPARATOR) followed by the virtual path to - * the object within the archive's virtual file system. + * Given the absolute path to a virtual object, returns that object as a + * VirtualChild. + * + * @param fullyQualifiedName The absolute path to the object. Usually + * consists of the fullyQualifiedName of the archive, followed by the + * virtual path separator (defined in + * ArchiveHandlerManager.VIRTUAL_SEPARATOR) followed by the virtual + * path to the object within the archive's virtual file system. + * @throws SystemMessageException in case of an error + * @since 3.0 */ - public VirtualChild getVirtualObject(String fullyQualifiedName) + public VirtualChild getVirtualObject(String fullyQualifiedName) throws SystemMessageException { String cleanName = cleanUpVirtualPath(fullyQualifiedName); AbsoluteVirtualPath avp = new AbsoluteVirtualPath(cleanName); @@ -243,11 +268,15 @@ public class ArchiveHandlerManager } /** - * Returns the registered handler for the File file. If - * no handler exists for that file yet, create it. If the extension of + * Returns the registered handler for the File file. If no + * handler exists for that file yet, create it. If the extension of * file is not registered, then returns null. + * + * @throws SystemMessageException in case of an error instantiating the + * handler + * @since 3.0 */ - public ISystemArchiveHandler getRegisteredHandler(File file) + public ISystemArchiveHandler getRegisteredHandler(File file) throws SystemMessageException { ISystemArchiveHandler handler = null; if (_handlers.containsKey(file)) @@ -279,17 +308,11 @@ public class ArchiveHandlerManager catch (InvocationTargetException e) { //Throwable target = e.getCause(); - System.out.println(e.getMessage()); - e.printStackTrace(); - System.out.println("Could not instantiate handler for " + file.getName()); //$NON-NLS-1$ - return null; - + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "instantiate handler for " + file.getName(), e); //$NON-NLS-1$ } catch (Exception e) { - System.out.println(e.getMessage()); - System.out.println("Could not instantiate handler for " + file.getName()); //$NON-NLS-1$ - return null; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "instantiate handler for " + file.getName(), e); //$NON-NLS-1$ } _handlers.put(file, handler); return handler; @@ -475,28 +498,30 @@ public class ArchiveHandlerManager _handlers.clear(); } - public boolean createEmptyArchive(File newFile) + /** + * Create an empty archive + * + * @throws SystemMessageException in case of an error + */ + public void createEmptyArchive(File newFile) throws SystemMessageException { if (!isRegisteredArchive(newFile.getName())) { - System.out.println("Could not create new archive."); //$NON-NLS-1$ - System.out.println(newFile + " is not a registered type of archive."); //$NON-NLS-1$ - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create new archive, because " //$NON-NLS-1$ + + newFile + " is not a registered type of archive."); //$NON-NLS-1$ } if (newFile.exists()) { if (!newFile.isFile()) { - System.out.println("Could not create new archive."); //$NON-NLS-1$ - System.out.println(newFile + " is not a file."); //$NON-NLS-1$ - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create new archive." //$NON-NLS-1$ + + newFile + " is not a file."); //$NON-NLS-1$ } if (!newFile.delete()) { - System.out.println("Could not create new archive."); //$NON-NLS-1$ - System.out.println(newFile + " could not be deleted."); //$NON-NLS-1$ - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create new archive." //$NON-NLS-1$ + + newFile + " could not be deleted."); //$NON-NLS-1$ } } @@ -504,20 +529,17 @@ public class ArchiveHandlerManager { if (!newFile.createNewFile()) { - System.out.println("Could not create new archive."); //$NON-NLS-1$ - System.out.println(newFile + " could not be created."); //$NON-NLS-1$ - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create new archive." //$NON-NLS-1$ + + newFile + " could not be created."); //$NON-NLS-1$ } } catch (IOException e) { - System.out.println("Could not create new archive."); //$NON-NLS-1$ - System.out.println(e.getMessage()); - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create new archive: " + newFile, e); //$NON-NLS-1$ } ISystemArchiveHandler handler = getRegisteredHandler(newFile); - return handler.create(); + handler.create(); } /** @@ -535,14 +557,26 @@ public class ArchiveHandlerManager return extensions; } - public String getComment(File archive) + /** + * Get archive comment. + * + * @throws SystemMessageException in case of an error + * @since 3.0 + */ + public String getComment(File archive) throws SystemMessageException { ISystemArchiveHandler handler = getRegisteredHandler(archive); if (handler == null || !handler.exists()) return ""; //$NON-NLS-1$ return handler.getArchiveComment(); } - public long getExpandedSize(File archive) + /** + * Get total expanded size of an archive. + * + * @throws SystemMessageException in case of an error + * @since 3.0 + */ + public long getExpandedSize(File archive) throws SystemMessageException { ISystemArchiveHandler handler = getRegisteredHandler(archive); if (handler == null || !handler.exists()) return 0; @@ -556,12 +590,15 @@ public class ArchiveHandlerManager } /** - * Returns the classification for the entry in a archive with the given virtual path. + * Returns the classification for the entry in a archive with the given + * virtual path. + * * @param file the archive file. * @param virtualPath the virtual path. * @return the classification for the virtual file. + * @throws SystemMessageException in case of an error */ - public String getClassification(File file, String virtualPath) { + public String getClassification(File file, String virtualPath) throws SystemMessageException { // if archive file is null, or if it does not exist, or if the virtual path // is null, then return null for the classification diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/ISystemArchiveHandler.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/ISystemArchiveHandler.java index cd0567b3ed7..ce4cf4f81d8 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/ISystemArchiveHandler.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/ISystemArchiveHandler.java @@ -10,10 +10,11 @@ * component that contains this file: David McKnight, Kushal Munir, * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. - * + * * Contributors: * Xuan Chen (IBM) - [160775][api][breaking] rename (at least within a zip) blocks UI thread * Martin Oberhuber (Wind River) - [cleanup] add API "since" tags to Archive Handler Javadoc + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.rse.services.clientserver.archiveutils; @@ -23,6 +24,7 @@ import java.io.InputStream; import org.eclipse.rse.services.clientserver.ISystemFileTypes; import org.eclipse.rse.services.clientserver.ISystemOperationMonitor; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; import org.eclipse.rse.services.clientserver.search.SystemSearchLineMatch; import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher; @@ -30,7 +32,7 @@ import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher; /** * An interface that allows implementing classes to create their own handlers * for various types of archive files, ie: zip, jar, tar, rpm. - * + * * @author mjberger */ public interface ISystemArchiveHandler @@ -39,23 +41,26 @@ public interface ISystemArchiveHandler * Turns the archive that this handler represents into a new, empty archive. * (The archive could not exist before, in which case this would be a true * creation). - * - * @return Whether or not the blank archive was successfully created. + * + * @throws SystemMessageException in case of an error + * @since org.eclipse.rse.services 3.0 */ - public boolean create(); + public void create() throws SystemMessageException; /** * Return a flat list of entries in an archive. - * + * * @param archiveOperationMonitor the operation progress monitor * @return an array containing all the entries in the archive file in a flat - * format, where the entries' filenames are prepended by the path to - * the entry within the virtual file system. If there are no entries - * in the file, returns an array of size 0. - * + * format, where the entries' filenames are prepended by the path to the + * entry within the virtual file system. If there are no entries in the + * file, returns an array of size 0. + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation + * * @since org.eclipse.rse.services 3.0 */ - public VirtualChild[] getVirtualChildrenList(ISystemOperationMonitor archiveOperationMonitor); + public VirtualChild[] getVirtualChildrenList(ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Return a flat list of entries in an archive, whose full paths begin with @@ -64,13 +69,14 @@ public interface ISystemArchiveHandler * @param parent full path of the parent * @param archiveOperationMonitor the operation progress monitor * @return an array containing all the entries in the archive file in a flat - * format, whose full paths begin with the String - * parent. Returns an array of length 0 if there are - * no such entries. + * format, whose full paths begin with the String parent. + * Returns an array of length 0 if there are no such entries. + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * * @since org.eclipse.rse.services 3.0 */ - public VirtualChild[] getVirtualChildrenList(String parent, ISystemOperationMonitor archiveOperationMonitor); + public VirtualChild[] getVirtualChildrenList(String parent, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Return the children of a specified node in an archive. @@ -78,14 +84,15 @@ public interface ISystemArchiveHandler * @param fullVirtualName full virtual path of the parent * @param archiveOperationMonitor the operation progress monitor * @return an array containing the virtual children of the virtual directory - * named fullVirtualName. If - * fullVirtualName is "", returns the top level in - * the virtual file system tree. If there are no values to return, - * returns null. + * named fullVirtualName. If fullVirtualName is + * "", returns the top level in the virtual file system tree. If there are + * no values to return, returns null. + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * * @since org.eclipse.rse.services 3.0 */ - public VirtualChild[] getVirtualChildren(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor); + public VirtualChild[] getVirtualChildren(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Return those children of a specified node in an archive, which are @@ -94,14 +101,16 @@ public interface ISystemArchiveHandler * @param fullVirtualName full virtual path of the parent * @param archiveOperationMonitor the operation progress monitor * @return an array containing the virtual children of the virtual directory - * named fullVirtualName that are themselves - * directories. If fullVirtualName is "", returns the - * top level of directories in the virtual file system tree. If - * there are no values to return, returns null. + * named fullVirtualName that are themselves directories. If + * fullVirtualName is "", returns the top level of directories + * in the virtual file system tree. If there are no values to return, + * returns null. + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * * @since org.eclipse.rse.services 3.0 */ - public VirtualChild[] getVirtualChildFolders(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor); + public VirtualChild[] getVirtualChildFolders(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Return an archive node specified by a given virtual path. @@ -109,14 +118,16 @@ public interface ISystemArchiveHandler * @param fullVirtualName full virtual path of the object to retrieve * @param archiveOperationMonitor the operation progress monitor * @return the virtual File or Folder referred to by - * fullVirtualName. This method never returns null. - * In cases where the VirtualChild does not physically exist in the - * archive, this method returns a new VirtualChild object whose - * exists() method returns false. + * fullVirtualName. This method never returns null. In cases + * where the VirtualChild does not physically exist in the archive, this + * method returns a new VirtualChild object whose exists() method returns + * false. + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * * @since org.eclipse.rse.services 3.0 */ - public VirtualChild getVirtualFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor); + public VirtualChild getVirtualFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Check whether a given virtual node exists in an archive. @@ -124,17 +135,18 @@ public interface ISystemArchiveHandler * @param fullVirtualName full virtual path of the object * @param archiveOperationMonitor the operation progress monitor * @return Whether or not the virtual file or folder named - * fullVirtualName exists in the archive - * (physically). + * fullVirtualName exists in the archive (physically). + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * * @since org.eclipse.rse.services 3.0 */ - public boolean exists(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor); + public boolean exists(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Check if the archive handler implementation associated with this class * exists. - * + * * @return Whether or not the handler exists. Usually false if the archive * is corrupted or unreadable. */ @@ -142,7 +154,7 @@ public interface ISystemArchiveHandler /** * Return the archive that this handler deals with. - * + * * @return the archive that this handler deals with */ public File getArchive(); @@ -152,50 +164,55 @@ public interface ISystemArchiveHandler * * @param fullVirtualName virtual path specifying the node to check * @return the current timestamp (last modified) for the archive entry named - * fullVirtualName + * fullVirtualName + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation */ - public long getTimeStampFor(String fullVirtualName); + public long getTimeStampFor(String fullVirtualName) throws SystemMessageException; /** * Return the size for an archive node. * * @param fullVirtualName virtual path specifying the node to check * @return the current size (uncompressed) for the entry in the archive - * named fullVirtualName + * named fullVirtualName + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation */ - public long getSizeFor(String fullVirtualName); + public long getSizeFor(String fullVirtualName) throws SystemMessageException; /** * Extracts the virtual file named fullVirtualName from the * archive, placing the results in destination. * * @param fullVirtualName The full path and name of the virtual file in the - * archive. + * archive. * @param destination The destination file for the extracted virtual file. * @param archiveOperationMonitor the operation progress monitor - * @return true if the extraction is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean extractVirtualFile(String fullVirtualName, File destination, ISystemOperationMonitor archiveOperationMonitor); + public void extractVirtualFile(String fullVirtualName, File destination, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Extracts the virtual file named fullVirtualName from the - * archive, placing the results in destination. Extracts to - * the native encoding, but assumes that the source was archived using + * archive, placing the results in destination. Extracts to the + * native encoding, but assumes that the source was archived using * sourceEncoding if isText is true. * * @param fullVirtualName The full path and name of the virtual file in the - * archive. + * archive. * @param destination The destination file for the extracted virtual file. * @param sourceEncoding The encoding of the file in the archive. * @param isText Whether or not the virtual file is a text file. * @param archiveOperationMonitor the operation progress monitor - * @return true if the extraction is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean extractVirtualFile(String fullVirtualName, File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor); + public void extractVirtualFile(String fullVirtualName, File destination, String sourceEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Extracts the directory dir (and its children) from the @@ -204,13 +221,13 @@ public interface ISystemArchiveHandler * * @param dir The full name of the virtual directory to extract * @param destinationParent A handle to the directory in which the extracted - * directory will be placed as a subdirectory. + * directory will be placed as a subdirectory. * @param archiveOperationMonitor the operation progress monitor - * @return true if the extraction is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean extractVirtualDirectory(String dir, File destinationParent, ISystemOperationMonitor archiveOperationMonitor); + public void extractVirtualDirectory(String dir, File destinationParent, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Extracts the directory dir (and its children) from the @@ -221,15 +238,16 @@ public interface ISystemArchiveHandler * * @param dir The full name of the virtual directory to extract * @param destinationParent A handle to the directory in which the extracted - * directory will be placed as a subdirectory. + * directory will be placed as a subdirectory. * @param sourceEncoding The encoding of the files in the archive. * @param isText Whether or not the files in the directory are text files * @param archiveOperationMonitor the operation progress monitor - * @return true if the extraction is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean extractVirtualDirectory(String dir, File destinationParent, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor); + public void extractVirtualDirectory(String dir, File destinationParent, String sourceEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Extracts the directory dir (and its children) from the @@ -239,67 +257,68 @@ public interface ISystemArchiveHandler * * @param dir The full name of the virtual directory to extract * @param destinationParent A handle to the directory in which the extracted - * directory will be placed as a subdirectory. + * directory will be placed as a subdirectory. * @param destination A handle to the directory that will be created. - * Whatever contents are in that directory will be replaced with - * what is extracted from the archive. + * Whatever contents are in that directory will be replaced with what + * is extracted from the archive. * @param archiveOperationMonitor the operation progress monitor - * @return true if the extraction is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean extractVirtualDirectory(String dir, File destinationParent, File destination, ISystemOperationMonitor archiveOperationMonitor); + public void extractVirtualDirectory(String dir, File destinationParent, File destination, ISystemOperationMonitor archiveOperationMonitor) + throws SystemMessageException; /** * Extracts the directory dir (and its children) from the * archive and places the results in the directory * destinationParent. The results will be named * destination.getName() rather than dir's name. Extracts to - * the native encoding (if isText), but assumes that the - * source was archived using sourceEncoding. + * the native encoding (if isText), but assumes that the source + * was archived using sourceEncoding. * * @param dir The full name of the virtual directory to extract * @param destinationParent A handle to the directory in which the extracted - * directory will be placed as a subdirectory. + * directory will be placed as a subdirectory. * @param destination A handle to the directory that will be created. - * Whatever contents are in that directory will be replaced with - * what is extracted from the archive. + * Whatever contents are in that directory will be replaced with what + * is extracted from the archive. * @param sourceEncoding The encoding of the files in the archive. * @param isText Whether or not the files to be extracted in the directory - * are all text files + * are all text files * @param archiveOperationMonitor the operation progress monitor - * @return true if the extraction is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean extractVirtualDirectory(String dir, File destinationParent, File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor); + public void extractVirtualDirectory(String dir, File destinationParent, File destination, String sourceEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** - * Compresses the file file and adds it to the archive, - * placing it in the virtual directory virtualPath. Pass the - * name as the parameter name. If the virtual path does not - * exist in the archive, create it. If file is a directory, - * copy it and its contents into the archive, maintaining the tree - * structure. + * Compresses the file file and adds it to the archive, placing + * it in the virtual directory virtualPath. Pass the name as + * the parameter name. If the virtual path does not exist in + * the archive, create it. If file is a directory, copy it and + * its contents into the archive, maintaining the tree structure. * * @param file the file to be added to the archive * @param virtualPath the destination of the file * @param name the name of the result virtual file * @param archiveOperationMonitor the operation progress monitor - * @return true if the addition is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean add(File file, String virtualPath, String name, ISystemOperationMonitor archiveOperationMonitor); + public void add(File file, String virtualPath, String name, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** - * Compresses the file file and adds it to the archive, - * saving it in the encoding specified by encoding if the - * isText is true. placing it in the virtual directory - * virtualPath. Pass the name as the parameter - * name. If the virtual path does not exist in the archive, - * create it. If file is a directory, copy it and its - * contents into the archive, maintaining the tree structure. + * Compresses the file file and adds it to the archive, saving + * it in the encoding specified by encoding if the isText is + * true. placing it in the virtual directory virtualPath. Pass + * the name as the parameter name. If the virtual path does not + * exist in the archive, create it. If file is a directory, + * copy it and its contents into the archive, maintaining the tree + * structure. * * @param file the file to be added to the archive * @param virtualPath the destination of the file @@ -308,19 +327,20 @@ public interface ISystemArchiveHandler * @param targetEncoding the encoding of the result file * @param isText is the file a text file * @param archiveOperationMonitor the operation progress monitor - * @return true if the addition is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor); + public void add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** - * Compresses the bytes in the InputStream stream and adds - * them as an entry to the archive, saving them in the encoding specified by - * encoding if isText is true, and placing it - * in the virtual directory virtualPath. Pass the name as - * the parameter name. If the virtual path does not exist in - * the archive, create it. + * Compresses the bytes in the InputStream stream and adds them + * as an entry to the archive, saving them in the encoding specified by + * encoding if isText is true, and placing it in + * the virtual directory virtualPath. Pass the name as the + * parameter name. If the virtual path does not exist in the + * archive, create it. * * @param stream the InputStream to be added as an entry to the archive * @param virtualPath the destination of the stream @@ -329,20 +349,21 @@ public interface ISystemArchiveHandler * @param targetEncoding the encoding of the result file * @param isText is the file a text file * @param archiveOperationMonitor the operation progress monitor - * @return true if the addition is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean add(InputStream stream, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor); + public void add(InputStream stream, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** - * Compresses the file file and adds it to the archive, - * saving it in the encoding specified by encoding if the - * isText is true. placing it in the virtual directory - * virtualPath. Pass the name as the parameter - * name. If the virtual path does not exist in the archive, - * create it. If file is a directory, copy it and its - * contents into the archive, maintaining the tree structure. + * Compresses the file file and adds it to the archive, saving + * it in the encoding specified by encoding if the isText is + * true. placing it in the virtual directory virtualPath. Pass + * the name as the parameter name. If the virtual path does not + * exist in the archive, create it. If file is a directory, + * copy it and its contents into the archive, maintaining the tree + * structure. * * @param file the file to be added to the archive * @param virtualPath the destination of the file @@ -351,39 +372,39 @@ public interface ISystemArchiveHandler * @param targetEncoding the encoding of the result file * @param typeRegistery file transfer mode (binary or text) of this file * @param archiveOperationMonitor the operation progress monitor - * @return true if the addition is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, ISystemFileTypes typeRegistery, ISystemOperationMonitor archiveOperationMonitor); + public void add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, ISystemFileTypes typeRegistery, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * A generalization of the add method. Compresses the array of files - * files and adds each of them to the archive, placing them - * in the virtual directory virtualPath. Pass the names of - * the files as the parameter names, where - * files[i] has the name names[i]. If the - * virtual path does not exist in the archive, create it. + * files and adds each of them to the archive, placing them in + * the virtual directory virtualPath. Pass the names of the + * files as the parameter names, where files[i] + * has the name names[i]. If the virtual path does not exist in + * the archive, create it. * * @param files the list of files to be added to the archive * @param virtualPath the destination of the file * @param names the names of the result virtual files * @param archiveOperationMonitor the operation progress monitor - * @return true if the addition is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean add(File[] files, String virtualPath, String[] names, ISystemOperationMonitor archiveOperationMonitor); + public void add(File[] files, String virtualPath, String[] names, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * A generalization of the add method. Compresses the array of files - * files and adds each of them to the archive, placing them - * in the virtual directory virtualPath. Save the i'th file - * in the i'th encoding (if isText[i] is true) specified by - * encodings. Pass the names of the files as the parameter - * names, where files[i] has the name - * names[i]. If the virtual path does not exist in the - * archive, create it. + * files and adds each of them to the archive, placing them in + * the virtual directory virtualPath. Save the i'th file in the + * i'th encoding (if isText[i] is true) specified by encodings. + * Pass the names of the files as the parameter names, where + * files[i] has the name names[i]. If the virtual + * path does not exist in the archive, create it. * * @param files the list of files to be added to the archive * @param virtualPath the destination of the files @@ -392,33 +413,34 @@ public interface ISystemArchiveHandler * @param targetEncodings the encoding of the result files * @param isText file transfer mode (binary or text) of the files * @param archiveOperationMonitor the operation progress monitor - * @return true if the addition is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean add(File[] files, String virtualPath, String[] names, String[] sourceEncodings, String[] targetEncodings, boolean[] isText, ISystemOperationMonitor archiveOperationMonitor); + public void add(File[] files, String virtualPath, String[] names, String[] sourceEncodings, String[] targetEncodings, boolean[] isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** - * Compress the file file and replace the virtual file - * referred to by fullVirtualName with the compressed file. - * Pass the name of the file as the parameter name. + * Compress the file file and replace the virtual file referred + * to by fullVirtualName with the compressed file. Pass the + * name of the file as the parameter name. * * @param fullVirtualName the path of the file to be replaced * @param file the file to be added to the archive * @param name the name of the file * @param archiveOperationMonitor the operation progress monitor - * @return true if the replacement is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean replace(String fullVirtualName, File file, String name, ISystemOperationMonitor archiveOperationMonitor); + public void replace(String fullVirtualName, File file, String name, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** - * Compress the InputStream stream and replace the virtual - * file referred to by fullVirtualName with the compressed - * stream. Pass the name of the new entry as the parameter name, - * the encoding of the entry as encoding and whether or not - * the entry isText or not. + * Compress the InputStream stream and replace the virtual file + * referred to by fullVirtualName with the compressed stream. + * Pass the name of the new entry as the parameter name, the + * encoding of the entry as encoding and whether or not the + * entry isText or not. * * @param fullVirtualName the path of the file to be replaced * @param stream the InputStream to be added as an entry to the archive @@ -427,11 +449,12 @@ public interface ISystemArchiveHandler * @param targetEncoding the encoding of the result file * @param isText is the file a text file * @param archiveOperationMonitor the operation progress monitor - * @return true if the replacement is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean replace(String fullVirtualName, InputStream stream, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor); + public void replace(String fullVirtualName, InputStream stream, String name, String sourceEncoding, String targetEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Deletes the entry fullVirtualName from the archive, and @@ -440,10 +463,13 @@ public interface ISystemArchiveHandler * @param fullVirtualName the path of the file to be deleted * @param archiveOperationMonitor the operation progress monitor * @return true if the deletion is successful, - * false otherwise + * false if the file to delete was not found so this was a + * successful no-op. + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean delete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor); + public boolean delete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Renames the entry fullVirtualName to the new name @@ -452,25 +478,25 @@ public interface ISystemArchiveHandler * * @param fullVirtualName the path of the file to be renamed * @param archiveOperationMonitor the operation progress monitor - * @return true if the rename is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean rename(String fullVirtualName, String newName, ISystemOperationMonitor archiveOperationMonitor); + public void rename(String fullVirtualName, String newName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** - * Moves the entry fullVirtualName to the location specified - * by destinationVirtualPath, while leaving the entry with - * the same name as before. + * Moves the entry fullVirtualName to the location specified by + * destinationVirtualPath, while leaving the entry with the + * same name as before. * * @param fullVirtualName the path of the file to be renamed * @param destinationVirtualPath the destination of the file to move to * @param archiveOperationMonitor the operation progress monitor - * @return true if the move is successful, false - * otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean move(String fullVirtualName, String destinationVirtualPath, ISystemOperationMonitor archiveOperationMonitor); + public void move(String fullVirtualName, String destinationVirtualPath, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Replaces the full name and path of the entry fullVirtualName @@ -479,11 +505,11 @@ public interface ISystemArchiveHandler * @param fullVirtualName the path of the file to be renamed * @param newFullVirtualName the full path of the virtual file name * @param archiveOperationMonitor the operation progress monitor - * @return true if the rename is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean fullRename(String fullVirtualName, String newFullVirtualName, ISystemOperationMonitor archiveOperationMonitor); + public void fullRename(String fullVirtualName, String newFullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Extracts and returns the specified list of virtual files from the @@ -492,42 +518,44 @@ public interface ISystemArchiveHandler * @param fullNames The list of files to return * @param archiveOperationMonitor the operation progress monitor * @return An array of handles to the extracted files. If fullNames has - * length 0 then this method returns an array of length 0. + * length 0 then this method returns an array of length 0. + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public File[] getFiles(String[] fullNames, ISystemOperationMonitor archiveOperationMonitor); + public File[] getFiles(String[] fullNames, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Creates a new, empty folder in the archive. If parent folders do not * exist either, creates them. * * @param fullVirtualName The full name and path of the new folder within - * the virtual file system. + * the virtual file system. * @param archiveOperationMonitor the operation progress monitor - * @return true if the create operation is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean createFolder(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor); + public void createFolder(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Creates a new, empty file in the archive. If parent folders do not exist * either, creates them. * * @param fullVirtualName The full name and path of the new file within the - * virtual file system. + * virtual file system. * @param archiveOperationMonitor the operation progress monitor - * @return true if the create operation is successful, - * false otherwise + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public boolean createFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor); + public void createFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException; /** * Get the archive-type specific standard name for the VirtualChild * vc. For example, for Zip archives, if vc is a directory, * then the standard name must end with a "/". - * + * * @param vc the archive node to use * @return the standard name for the node */ @@ -541,18 +569,22 @@ public interface ISystemArchiveHandler * @param matcher the pattern matcher to use. * @param archiveOperationMonitor the operation progress monitor * @return an array of match objects corresponding to lines where matches - * were found. Returns an empty array if there are no results. + * were found. Returns an empty array if there are no results. + * @throws SystemMessageException in case of an error, + * or SystemOperationCancelledException in case of user cancellation * @since org.eclipse.rse.services 3.0 */ - public SystemSearchLineMatch[] search(String fullVirtualName, SystemSearchStringMatcher matcher, ISystemOperationMonitor archiveOperationMonitor); + public SystemSearchLineMatch[] search(String fullVirtualName, SystemSearchStringMatcher matcher, ISystemOperationMonitor archiveOperationMonitor) + throws SystemMessageException; /** * Get the user-defined comment for a specific entry in the archive. * * @param fullVirtualName The entry who's comment is desired * @return the comment as a String or "" if there is none + * @throws SystemMessageException in case of an error */ - public String getCommentFor(String fullVirtualName); + public String getCommentFor(String fullVirtualName) throws SystemMessageException; /** * Get the amount of space taken up by a specific entry in the archive when @@ -561,31 +593,35 @@ public interface ISystemArchiveHandler * * @param fullVirtualName The entry who's compressed size is desired * @return the compressed size of the specified entry, or 0 if the entry is - * not found. If the archive is not a compression type (ie. tar), - * return the same as getSizeFor(String). + * not found. If the archive is not a compression type (ie. tar), return + * the same as getSizeFor(String). + * @throws SystemMessageException in case of an error */ - public long getCompressedSizeFor(String fullVirtualName); + public long getCompressedSizeFor(String fullVirtualName) throws SystemMessageException; /** * Get the method used to compress a specific entry in the archive. * * @param fullVirtualName The entry who's compression method is desired * @return The compression method of the specified entry, or "" if none. + * @throws SystemMessageException in case of an error */ - public String getCompressionMethodFor(String fullVirtualName); + public String getCompressionMethodFor(String fullVirtualName) throws SystemMessageException; /** * Get the comment associated with an archive. * * @return The comment associated with this archive, or "" if there is none. + * @throws SystemMessageException in case of an error */ - public String getArchiveComment(); + public String getArchiveComment() throws SystemMessageException; /** * Get the classification for the entry with the given path. * * @param fullVirtualName the virtual name. * @return the classification. + * @throws SystemMessageException in case of an error */ - public String getClassification(String fullVirtualName); + public String getClassification(String fullVirtualName) throws SystemMessageException; } diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTarHandler.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTarHandler.java index aab5b440f6f..8ad7159a1b5 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTarHandler.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTarHandler.java @@ -10,7 +10,7 @@ * component that contains this file: David McKnight, Kushal Munir, * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. - * + * * Contributors: * Xuan Chen (IBM) - [194293] [Local][Archives] Saving file second time in an Archive Errors * Xuan Chen (IBM) - [199132] [Archives-TAR][Local-Windows] Can't open files in tar archives @@ -24,6 +24,7 @@ * Xuan Chen (IBM) - [api] SystemTarHandler has inconsistent API * Johnson Ma (Wind River) - [195402][api] Add tar.gz archive support * Xuan Chen (IBM) - [224576] [api] Inconsistent boolean return values in SystemTarHandler API + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.rse.services.clientserver.archiveutils; @@ -46,12 +47,19 @@ import java.util.Iterator; import java.util.List; import java.util.Vector; +import org.eclipse.rse.internal.services.Activator; import org.eclipse.rse.internal.services.clientserver.archiveutils.ITarConstants; import org.eclipse.rse.internal.services.clientserver.archiveutils.SystemArchiveUtil; import org.eclipse.rse.services.clientserver.ISystemFileTypes; import org.eclipse.rse.services.clientserver.ISystemOperationMonitor; import org.eclipse.rse.services.clientserver.SystemReentrantMutex; import org.eclipse.rse.services.clientserver.java.BasicClassFileParser; +import org.eclipse.rse.services.clientserver.messages.SystemLockTimeoutException; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.clientserver.messages.SystemOperationCancelledException; +import org.eclipse.rse.services.clientserver.messages.SystemOperationFailedException; +import org.eclipse.rse.services.clientserver.messages.SystemUnexpectedErrorException; +import org.eclipse.rse.services.clientserver.messages.SystemUnsupportedOperationException; import org.eclipse.rse.services.clientserver.search.SystemSearchLineMatch; import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatchLocator; import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher; @@ -894,7 +902,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualFile(java.lang.String, java.io.File) */ - public boolean extractVirtualFile(String fullVirtualName, File destination, ISystemOperationMonitor archiveOperationMonitor) { + public void extractVirtualFile(String fullVirtualName, File destination, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); TarEntry entry = null; @@ -922,14 +930,14 @@ public class SystemTarHandler implements ISystemArchiveHandler { // the entry's last modified time destination.mkdirs(); destination.setLastModified(entry.getModificationTime()); - return true; + return; } inStream = getTarFile().getInputStream(entry); if (inStream == null) { destination.setLastModified(entry.getModificationTime()); - return false; // TODO: return true or false? + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); } //Need to make sure destination file exists. if (!destination.exists()) @@ -952,7 +960,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { } } catch (IOException e) { - // TODO: log error + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } finally { @@ -980,38 +988,37 @@ public class SystemTarHandler implements ISystemArchiveHandler { releaseMutex(mutexLockStatus); } - return true; } /** * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, ISystemOperationMonitor) */ - public boolean extractVirtualDirectory(String fullVirtualName, File destinationParent, ISystemOperationMonitor archiveOperationMonitor) { - return extractVirtualDirectory(fullVirtualName, destinationParent, (File) null, archiveOperationMonitor); + public void extractVirtualDirectory(String fullVirtualName, File destinationParent, ISystemOperationMonitor archiveOperationMonitor) + throws SystemMessageException { + extractVirtualDirectory(fullVirtualName, destinationParent, (File) null, archiveOperationMonitor); } /* * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.io.File, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean extractVirtualDirectory(String fullVirtualName, File destinationParent, File destination, ISystemOperationMonitor archiveOperationMonitor) { + public void extractVirtualDirectory(String fullVirtualName, File destinationParent, File destination, ISystemOperationMonitor archiveOperationMonitor) + throws SystemMessageException { // if the destination directory doesn't exist, create it if (!destinationParent.exists()) { if (!destinationParent.mkdirs()) { - // TODO: log error - return false; // quit if we fail to create the destination directory + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Create folder " + destinationParent); //$NON-NLS-1$ } } // otherwise if the destination directory does exist, but is not a directory, then quit else if (!destinationParent.isDirectory()) { - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "No folder: " + destinationParent); //$NON-NLS-1$ } fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); - int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; try { @@ -1024,7 +1031,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { VirtualChild dir = vfs.getEntry(fullVirtualName); if (dir == null || !dir.isDirectory) { - return false; + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); } if (destination == null) { @@ -1052,15 +1059,10 @@ public class SystemTarHandler implements ISystemArchiveHandler { // if the directory does not exist, try to create it if (!topDir.exists() && !topDir.mkdirs()) { - // TODO: log error - return false; // log error and quit if we fail to create the directory + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Create folder " + topDir); //$NON-NLS-1$ } else { - boolean returnCode = extractVirtualFile(fullVirtualName, topDir, archiveOperationMonitor); - if (returnCode == false) - { - return returnCode; - } + extractVirtualFile(fullVirtualName, topDir, archiveOperationMonitor); } // get the children of this directory @@ -1075,41 +1077,34 @@ public class SystemTarHandler implements ISystemArchiveHandler { } File childFile = new File(childPath); - boolean returnCode = false; // if the child is a directory, then we need to extract it and its children if (tempChild.isDirectory) { // and now extract its children - returnCode = extractVirtualDirectory(tempChild.fullName, childFile, (File) null, archiveOperationMonitor); + extractVirtualDirectory(tempChild.fullName, childFile, (File) null, archiveOperationMonitor); } // otherwise if the child is a file, simply extract it else { - returnCode = extractVirtualFile(tempChild.fullName, childFile, archiveOperationMonitor); - } - if (returnCode == false) - { - return returnCode; + extractVirtualFile(tempChild.fullName, childFile, archiveOperationMonitor); } } } } catch (IOException e) { - e.printStackTrace(); - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } finally { releaseMutex(mutexLockStatus); } - return true; } /* * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File, java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean add(File file, String virtualPath, String name, ISystemOperationMonitor archiveOperationMonitor ) { + public void add(File file, String virtualPath, String name, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { virtualPath = ArchiveHandlerManager.cleanUpVirtualPath(virtualPath); int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; @@ -1123,18 +1118,16 @@ public class SystemTarHandler implements ISystemArchiveHandler { // if it exists, call replace String fullVirtualName = getFullVirtualName(virtualPath, name); if (exists(fullVirtualName, archiveOperationMonitor)) { - boolean returnCode = replace(fullVirtualName, file, name, archiveOperationMonitor); + replace(fullVirtualName, file, name, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return returnCode; } else { File[] files = new File[1]; files[0] = file; String[] names = new String[1]; names[0] = name; - boolean returnCode = add(files, virtualPath, names, archiveOperationMonitor); + add(files, virtualPath, names, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return returnCode; } } else { @@ -1162,22 +1155,21 @@ public class SystemTarHandler implements ISystemArchiveHandler { newNames[numOfChildren] = newNames[numOfChildren] + "/"; //$NON-NLS-1$ } - boolean returnCode = add(sources, virtualPath, newNames, archiveOperationMonitor); + add(sources, virtualPath, newNames, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return returnCode; } } } catch (Exception e) { - e.printStackTrace(); + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } finally { releaseMutex(mutexLockStatus); } setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return false; + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); } /** @@ -1203,7 +1195,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File[], java.lang.String, java.lang.String[], org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean add(File[] files, String virtualPath, String[] names, ISystemOperationMonitor archiveOperationMonitor) { + public void add(File[] files, String virtualPath, String[] names, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; File outputTempFile = null; @@ -1225,7 +1217,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { if (!files[i].exists() || !files[i].canRead()) { setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Cannot read: " + files[i]); //$NON-NLS-1$ } // if the entry already exists, then we should do a replace @@ -1234,9 +1226,8 @@ public class SystemTarHandler implements ISystemArchiveHandler { String fullVirtualName = getFullVirtualName(virtualPath, names[i]); if (exists(fullVirtualName, archiveOperationMonitor)) { - boolean returnCode = replace(fullVirtualName, files[i], names[i], archiveOperationMonitor); + replace(fullVirtualName, files[i], names[i], archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return returnCode; } } @@ -1252,13 +1243,13 @@ public class SystemTarHandler implements ISystemArchiveHandler { boolean ok = createTar(children, outStream, (HashSet)null, archiveOperationMonitor); if (!ok) { + //cancelled outStream.close(); if (outputTempFile != null) { outputTempFile.delete(); } - return false; - + throw new SystemOperationCancelledException(); } } VirtualChild[] newEntriesAdded = new VirtualChild[numFiles]; @@ -1272,7 +1263,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { { outputTempFile.delete(); } - return false; + throw new SystemOperationCancelledException(); } String childVirtualPath = virtualPath + "/" + names[i]; //$NON-NLS-1$ @@ -1303,7 +1294,6 @@ public class SystemTarHandler implements ISystemArchiveHandler { } catch (IOException e) { - e.printStackTrace(); // close output stream if (outStream != null) { @@ -1321,27 +1311,27 @@ public class SystemTarHandler implements ISystemArchiveHandler { outputTempFile.delete(); } setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } finally { releaseMutex(mutexLockStatus); } setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return true; } /** * Create a tar file from the given virtual child objects, using the given * output stream and omitting the children in the given set. - * + * * @param children an array of virtual children from which to create a tar - * file. + * file. * @param outStream the tar output stream to use. * @param omitChildren the set of names for children that should be omitted - * from the given array of virtual children. + * from the given array of virtual children. * @param archiveOperationMonitor the operation progress monitor - * @return true if the operation has been cancelled, false otherwise + * @return true if the operation completes successfully, or + * false if it has been cancelled. * @throws IOException if an I/O exception occurs. * @since org.eclipse.rse.services 3.0 */ @@ -1661,26 +1651,25 @@ public class SystemTarHandler implements ISystemArchiveHandler { * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#replace(java.lang.String, java.io.File, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean replace(String fullVirtualName, File file, String name, ISystemOperationMonitor archiveOperationMonitor) { + public void replace(String fullVirtualName, File file, String name, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { // update our cache before accessing cache try { updateCache(); } catch (IOException e) { - // TODO: log error - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } if (!file.exists() && !file.canRead()) { - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Cannot read " + file); //$NON-NLS-1$ } fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); // if the virtual file does not exist, we actually want to add if (!exists(fullVirtualName, archiveOperationMonitor)) { - return add(file, fullVirtualName, name, archiveOperationMonitor); + add(file, fullVirtualName, name, archiveOperationMonitor); } try { @@ -1707,8 +1696,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { { outputTempFile.delete(); } - return false; - + throw new SystemOperationCancelledException(); } // now append the new file to the tar @@ -1751,12 +1739,9 @@ public class SystemTarHandler implements ISystemArchiveHandler { // replace the current tar file with the new one, and do not update cache since // we just did replaceFile(outputTempFile, false); - - return true; } catch (IOException e) { - // TODO: log error - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } } @@ -1764,7 +1749,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#delete(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean delete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) + public boolean delete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { boolean returnCode = doDelete(fullVirtualName, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); @@ -1772,15 +1757,17 @@ public class SystemTarHandler implements ISystemArchiveHandler { } - /** + /** * Delete a virtual object. - * + * * @param fullVirtualName virtual path identifying the object * @param archiveOperationMonitor the operation progress monitor - * @return true if successful, false otherwise + * @return true if successful, false if the entry + * to delete did not exist (so this was a successful no-op). + * @throws SystemMessageException in case of an error * @since org.eclipse.rse.services 3.0 */ - protected boolean doDelete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) { + protected boolean doDelete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { File outputTempFile = null; int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; @@ -1831,8 +1818,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { { outputTempFile.delete(); } - return false; - + throw new SystemOperationCancelledException(); } // delete the child from the cache (this will also delete its children if it @@ -1845,53 +1831,48 @@ public class SystemTarHandler implements ISystemArchiveHandler { // replace the current tar file with the new one, and do not update cache since // we just did replaceFile(outputTempFile, false); - - return true; + } else { + throw new SystemLockTimeoutException(Activator.PLUGIN_ID); } } catch (IOException e) { - System.out.println(e.getMessage()); - System.out.println("Could not delete " + fullVirtualName); //$NON-NLS-1$ if (!(outputTempFile == null)) outputTempFile.delete(); - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not delete " + fullVirtualName, e); //$NON-NLS-1$ } finally { releaseMutex(mutexLockStatus); } - return false; + return true; } /* * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#rename(java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean rename(String fullVirtualName, String newName, ISystemOperationMonitor archiveOperationMonitor) { + public void rename(String fullVirtualName, String newName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$ - boolean resultCode = false; - // if the original does not have any separator, simply rename it. if (i == -1) { - resultCode = fullRename(fullVirtualName, newName, archiveOperationMonitor); + fullRename(fullVirtualName, newName, archiveOperationMonitor); } // otherwise, get the parent path and append the new name to it. else { String fullNewName = fullVirtualName.substring(0, i+1) + newName; - resultCode = fullRename(fullVirtualName, fullNewName, archiveOperationMonitor); + fullRename(fullVirtualName, fullNewName, archiveOperationMonitor); } setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return resultCode; } /* * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#move(java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean move(String fullVirtualName, String destinationVirtualPath, ISystemOperationMonitor archiveOperationMonitor) { + public void move(String fullVirtualName, String destinationVirtualPath, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); destinationVirtualPath = ArchiveHandlerManager.cleanUpVirtualPath(destinationVirtualPath); @@ -1899,12 +1880,12 @@ public class SystemTarHandler implements ISystemArchiveHandler { // if the original does not have any separator, simply append it to the destination path. if (i == -1) { - return fullRename(fullVirtualName, destinationVirtualPath + "/" + fullVirtualName, archiveOperationMonitor); //$NON-NLS-1$ + fullRename(fullVirtualName, destinationVirtualPath + "/" + fullVirtualName, archiveOperationMonitor); //$NON-NLS-1$ } // otherwise, get the last segment (the name) and append that to the destination path. else { String name = fullVirtualName.substring(i); - return fullRename(fullVirtualName, destinationVirtualPath + name, archiveOperationMonitor); + fullRename(fullVirtualName, destinationVirtualPath + name, archiveOperationMonitor); } } @@ -1912,7 +1893,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#fullRename(java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean fullRename(String fullVirtualName, String newFullVirtualName, ISystemOperationMonitor archiveOperationMonitor) { + public void fullRename(String fullVirtualName, String newFullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; File outputTempFile = null; @@ -1929,10 +1910,9 @@ public class SystemTarHandler implements ISystemArchiveHandler { // if the virtual file to be renamed does not exist, then quit if (!child.exists()) { - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Not exists: " + child); //$NON-NLS-1$ } - // open a new temp file which will be our destination for the new tar file outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$ TarOutputStream outStream = getTarOutputStream(outputTempFile); @@ -1999,11 +1979,10 @@ public class SystemTarHandler implements ISystemArchiveHandler { { outputTempFile.delete(); } - return false; - + throw new SystemOperationCancelledException(); } - + // close the output stream outStream.close(); @@ -2013,19 +1992,15 @@ public class SystemTarHandler implements ISystemArchiveHandler { // probably be more efficient replaceFile(outputTempFile, true); updateTree(newOldNames); - - return true; } else { - return false; + throw new SystemLockTimeoutException(Activator.PLUGIN_ID); } } catch (IOException e) { - e.printStackTrace(); - System.out.println("Could not rename " + fullVirtualName); //$NON-NLS-1$ if (!(outputTempFile == null)) outputTempFile.delete(); - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not rename " + fullVirtualName, e); //$NON-NLS-1$ } finally { @@ -2036,15 +2011,16 @@ public class SystemTarHandler implements ISystemArchiveHandler { /** * Creates a tar file from the given virtual child objects, using the given * output stream and renaming entries according to hash map entries. - * + * * @param children an array of virtual children from which to create a tar - * file. + * file. * @param outStream the tar output stream to use. * @param renameMap a map containing associations between old names and new - * names. Old names are the keys in the map, and the values are - * the new names. + * names. Old names are the keys in the map, and the values are the new + * names. * @param archiveOperationMonitor the operation progress monitor - * @return true if the operation has been cancelled, false otherwise. + * @return true if the operation completes successfully, or + * false if it is cancelled by the user. * @throws IOException if an I/O exception occurs. * @since org.eclipse.rse.services 3.0 */ @@ -2148,7 +2124,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getFiles(java.lang.String[], org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public File[] getFiles(String[] fullNames, ISystemOperationMonitor archiveOperationMonitor) { + public File[] getFiles(String[] fullNames, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { File[] files = new File[fullNames.length]; @@ -2171,8 +2147,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { extractVirtualFile(fullNames[i], files[i], archiveOperationMonitor); } catch (IOException e) { - // TODO: log error - return null; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } } @@ -2183,36 +2158,42 @@ public class SystemTarHandler implements ISystemArchiveHandler { * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#createFolder(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean createFolder(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) { + public void createFolder(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); fullVirtualName = fullVirtualName + "/"; //$NON-NLS-1$ - boolean returnCode = createVirtualObject(fullVirtualName, archiveOperationMonitor); - setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return returnCode; + try { + createVirtualObject(fullVirtualName, archiveOperationMonitor); + } finally { + setArchiveOperationMonitorStatusDone(archiveOperationMonitor); + } } /* * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#createFile(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean createFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) { + public void createFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); - boolean returnCode = createVirtualObject(fullVirtualName, archiveOperationMonitor); - setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return returnCode; + try { + createVirtualObject(fullVirtualName, archiveOperationMonitor); + } finally { + setArchiveOperationMonitorStatusDone(archiveOperationMonitor); + } } /** * Creates a virtual object that does not already exist in the virtual file * system. Creates an empty file in the tar file. - * + * * @param name the name of the virtual object. * @param archiveOperationMonitor the operation progress monitor * @return true if the object was created successfully, - * false otherwise. + * false if the object already exists such that this is a + * successful no-op, or if the operation is cancelled by the user. + * @throws SystemMessageException in case of an error. * @since org.eclipse.rse.services 3.0 */ - protected boolean createVirtualObject(String name, ISystemOperationMonitor archiveOperationMonitor) { + protected boolean createVirtualObject(String name, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { File outputTempFile = null; TarOutputStream outStream = null; @@ -2224,7 +2205,6 @@ public class SystemTarHandler implements ISystemArchiveHandler { { updateCache(); - // if the object already exists, return false if (exists(name, archiveOperationMonitor)) { return false; @@ -2247,8 +2227,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { { outputTempFile.delete(); } - return false; - + throw new SystemOperationCancelledException(); } } @@ -2265,12 +2244,11 @@ public class SystemTarHandler implements ISystemArchiveHandler { // replace the current tar file with the new one, but do not update the cache // since we have already updated to the cache replaceFile(outputTempFile, false); - - return true; + } else { + throw new SystemLockTimeoutException(Activator.PLUGIN_ID); } } catch (IOException e) { - e.printStackTrace(); // close output stream if (outStream != null) { @@ -2287,13 +2265,13 @@ public class SystemTarHandler implements ISystemArchiveHandler { { outputTempFile.delete(); } - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } finally { releaseMutex(mutexLockStatus); } - return false; + return true; } /** @@ -2380,7 +2358,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#create() */ - public boolean create() { + public void create() throws SystemMessageException { try { @@ -2397,13 +2375,12 @@ public class SystemTarHandler implements ISystemArchiveHandler { modTimeDuringCache = file.lastModified(); } catch (IOException e) { - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } - - return true; } - public SystemSearchLineMatch[] search(String fullVirtualName, SystemSearchStringMatcher matcher, ISystemOperationMonitor archiveOperationMonitor) { + public SystemSearchLineMatch[] search(String fullVirtualName, SystemSearchStringMatcher matcher, ISystemOperationMonitor archiveOperationMonitor) + throws SystemMessageException { // if the search string is empty or if it is "*", then return no matches // since it is a file search if (matcher.isSearchStringEmpty() || matcher.isSearchStringAsterisk()) { @@ -2443,8 +2420,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { } } catch (IOException e) { - // TODO: log error - return new SystemSearchLineMatch[0]; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } } @@ -2491,73 +2467,76 @@ public class SystemTarHandler implements ISystemArchiveHandler { } /** - * Compresses the file file and adds it to the archive, - * saving it in the encoding specified by encoding if saving - * in text mode. Places the file in the virtual directory - * virtualPath. Pass the name as the parameter - * name. If the virtual path does not exist in the archive, - * create it. If file is a directory, copy it and its - * contents into the archive, maintaining the tree structure. - * + * Compresses the file file and adds it to the archive, saving + * it in the encoding specified by encoding if saving in text + * mode. Places the file in the virtual directory virtualPath. + * Pass the name as the parameter name. If the virtual path + * does not exist in the archive, create it. If file is a + * directory, copy it and its contents into the archive, maintaining the + * tree structure. + * * @param file the file to be added to the archive * @param virtualPath the destination of the file * @param name the name of the result virtual file * @param encoding the file encoding to use * @param registry the file type to use (text or binary) * @param archiveOperationMonitor the operation progress monitor - * @return true if and only if the add was successful + * @throws SystemMessageException in case of an error * @since org.eclipse.rse.services 3.0 */ - public boolean add(File file, String virtualPath, String name, - String encoding, ISystemFileTypes registry, ISystemOperationMonitor archiveOperationMonitor) { - return add(file, virtualPath, name, archiveOperationMonitor); + public void add(File file, String virtualPath, String name, String encoding, ISystemFileTypes registry, ISystemOperationMonitor archiveOperationMonitor) + throws SystemMessageException { + add(file, virtualPath, name, archiveOperationMonitor); } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean) */ - public boolean add(File file, String virtualPath, String name, - String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { - return add(file, virtualPath, name, archiveOperationMonitor); + public void add(File file, String virtualPath, String name, + String sourceEncoding, String targetEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { + add(file, virtualPath, name, archiveOperationMonitor); } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File[], java.lang.String, java.lang.String[], java.lang.String[], java.lang.String[], boolean[]) */ - public boolean add(File[] files, String virtualPath, String[] names, - String[] sourceEncodings, String[] targetEncodings, boolean[] isTexts, ISystemOperationMonitor archiveOperationMonitor) { - return add(files, virtualPath, names, archiveOperationMonitor); + public void add(File[] files, String virtualPath, String[] names, + String[] sourceEncodings, String[] targetEncodings, boolean[] isTexts, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { + add(files, virtualPath, names, archiveOperationMonitor); } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.io.File, java.lang.String, boolean) */ - public boolean extractVirtualDirectory(String dir, File destinationParent, - File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { - return extractVirtualDirectory(dir, destinationParent, destination, archiveOperationMonitor); + public void extractVirtualDirectory(String dir, File destinationParent, + File destination, String sourceEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { + extractVirtualDirectory(dir, destinationParent, destination, archiveOperationMonitor); } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.lang.String, boolean) */ - public boolean extractVirtualDirectory(String dir, File destinationParent, - String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { - return extractVirtualDirectory(dir, destinationParent, archiveOperationMonitor); + public void extractVirtualDirectory(String dir, File destinationParent, String sourceEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { + extractVirtualDirectory(dir, destinationParent, archiveOperationMonitor); } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualFile(java.lang.String, java.io.File, java.lang.String, boolean) */ - public boolean extractVirtualFile(String fullVirtualName, File destination, - String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { - return extractVirtualFile(fullVirtualName, destination, archiveOperationMonitor); + public void extractVirtualFile(String fullVirtualName, File destination, String sourceEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { + extractVirtualFile(fullVirtualName, destination, archiveOperationMonitor); } /* * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getClassification(java.lang.String) */ - public String getClassification(String fullVirtualName) { + public String getClassification(String fullVirtualName) throws SystemMessageException { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); // default type @@ -2612,18 +2591,19 @@ public class SystemTarHandler implements ISystemArchiveHandler { return type; } - public boolean add(InputStream stream, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { - // TODO Auto-generated method stub - return false; + public void add(InputStream stream, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { + throw new SystemUnsupportedOperationException(Activator.PLUGIN_ID, "add"); //$NON-NLS-1$ } - public boolean add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, ISystemFileTypes typeRegistery, ISystemOperationMonitor archiveOperationMonitor) { - return add(file, virtualPath, name, archiveOperationMonitor); + public void add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, ISystemFileTypes typeRegistery, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { + add(file, virtualPath, name, archiveOperationMonitor); } - public boolean replace(String fullVirtualName, InputStream stream, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { - // TODO Auto-generated method stub - return false; + public void replace(String fullVirtualName, InputStream stream, String name, String sourceEncoding, String targetEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { + throw new SystemUnsupportedOperationException(Activator.PLUGIN_ID, "replace"); //$NON-NLS-1$ } /** @@ -2667,7 +2647,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { /** * Get the tar output stream for a given file. This method can be overridden * by subclass to return compressed output steam if needed. - * + * * @param outputFile the output file to create stream * @return OutputStream the output stream to write * @throws FileNotFoundException when the output file doesn't exist diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemZipHandler.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemZipHandler.java index 064880e6c8f..1a9fca89305 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemZipHandler.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemZipHandler.java @@ -23,6 +23,7 @@ * Xuan Chen (IBM) - [214786] [regression][archive]rename a virtual directory does not work properly * Xuan Chen (IBM) - [191370] [dstore] Supertransfer zip not deleted when canceling copy * Martin Oberhuber (Wind River) - [cleanup] Add API "since" tags + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.rse.services.clientserver.archiveutils; @@ -44,6 +45,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; +import org.eclipse.rse.internal.services.Activator; import org.eclipse.rse.internal.services.clientserver.archiveutils.SystemArchiveUtil; import org.eclipse.rse.internal.services.clientserver.archiveutils.SystemUniversalZipEntry; import org.eclipse.rse.services.clientserver.ISystemFileTypes; @@ -51,6 +53,11 @@ import org.eclipse.rse.services.clientserver.ISystemOperationMonitor; import org.eclipse.rse.services.clientserver.SystemEncodingUtil; import org.eclipse.rse.services.clientserver.SystemReentrantMutex; import org.eclipse.rse.services.clientserver.java.BasicClassFileParser; +import org.eclipse.rse.services.clientserver.messages.SystemLockTimeoutException; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.clientserver.messages.SystemOperationCancelledException; +import org.eclipse.rse.services.clientserver.messages.SystemOperationFailedException; +import org.eclipse.rse.services.clientserver.messages.SystemUnexpectedErrorException; import org.eclipse.rse.services.clientserver.search.SystemSearchLineMatch; import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatchLocator; import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher; @@ -113,7 +120,7 @@ public class SystemZipHandler implements ISystemArchiveHandler * @param file The file that this handler will wrapper. * @throws IOException If there is an error handling file */ - public SystemZipHandler(File file) + public SystemZipHandler(File file) throws IOException { _file = file; _vfsLastModified = _file.lastModified(); @@ -493,17 +500,19 @@ public class SystemZipHandler implements ISystemArchiveHandler /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getVirtualChildrenList() */ - public VirtualChild[] getVirtualChildrenList(ISystemOperationMonitor archiveOperationMonitor) + public VirtualChild[] getVirtualChildrenList(ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { return getVirtualChildrenList(true, archiveOperationMonitor); } /** - * Same as getVirtualChildrenList(), but you can choose whether - * to leave the zip file open or closed upon return. + * Same as getVirtualChildrenList(), but you can choose whether to leave the + * zip file open or closed upon return. + * + * @throws SystemMessageException in case of an error * @since org.eclipse.rse.services 3.0 */ - public VirtualChild[] getVirtualChildrenList(boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) + public VirtualChild[] getVirtualChildrenList(boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { if (!_exists) return new VirtualChild[0]; if (!updateVirtualFSIfNecessary(archiveOperationMonitor)) return new VirtualChild[0]; @@ -533,12 +542,14 @@ public class SystemZipHandler implements ISystemArchiveHandler if (closeZipFile) closeZipFile(); return retVal; } + } else { + throw new SystemLockTimeoutException(Activator.PLUGIN_ID); } } catch (Exception e) { - e.printStackTrace(); if (closeZipFile) closeZipFile(); + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } finally { @@ -551,7 +562,7 @@ public class SystemZipHandler implements ISystemArchiveHandler /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getVirtualChildrenList(java.lang.String) */ - public VirtualChild[] getVirtualChildrenList(String parent, ISystemOperationMonitor archiveOperationMonitor) + public VirtualChild[] getVirtualChildrenList(String parent, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { return getVirtualChildrenList(parent, true, archiveOperationMonitor); } @@ -559,9 +570,12 @@ public class SystemZipHandler implements ISystemArchiveHandler /** * Same as getVirtualChildrenList(String parent) but you can choose whether * or not you want to leave the zipfile open after return. + * + * @throws SystemMessageException in case of an error * @since org.eclipse.rse.services 3.0 */ public VirtualChild[] getVirtualChildrenList(String parent, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) + throws SystemMessageException { if (!_exists) return new VirtualChild[0]; if (!updateVirtualFSIfNecessary(archiveOperationMonitor)) return new VirtualChild[0]; @@ -605,16 +619,14 @@ public class SystemZipHandler implements ISystemArchiveHandler } catch (Exception e) { - e.printStackTrace(); if (closeZipFile) closeZipFile(); + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } finally { releaseMutex(mutexLockStatus); } - return new VirtualChild[0]; - } /* (non-Javadoc) @@ -701,7 +713,7 @@ public class SystemZipHandler implements ISystemArchiveHandler /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#exists(java.lang.String) */ - public boolean exists(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) + public boolean exists(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { if (!_exists) return false; @@ -732,35 +744,31 @@ public class SystemZipHandler implements ISystemArchiveHandler { boolean retval = false; boolean keepOpen = _zipfile != null; - if (openZipFile()) + try { + openZipFile(); + } catch (IOException ioe) { + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not open the ZipFile " + _file.toString(), ioe); //$NON-NLS-1$ + } + try { + safeGetEntry(fullVirtualName); + retval = true; + } catch (IOException e) { try { - safeGetEntry(fullVirtualName); + safeGetEntry(fullVirtualName + "/"); //$NON-NLS-1$ retval = true; } - catch (IOException e) + catch (IOException f) { - try - { - safeGetEntry(fullVirtualName + "/"); //$NON-NLS-1$ - retval = true; - } - catch (IOException f) - { - retval = false; - } + retval = false; } - buildTree(); - _vfsLastModified = _file.lastModified(); - if (!keepOpen) closeZipFile(); - return retval; - } - else - { - System.out.println("Could not open the ZipFile " + _file.toString()); //$NON-NLS-1$ - return false; } + buildTree(); + _vfsLastModified = _file.lastModified(); + if (!keepOpen) + closeZipFile(); + return retval; } } @@ -775,7 +783,7 @@ public class SystemZipHandler implements ISystemArchiveHandler /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getTimeStampFor(java.lang.String) */ - public long getTimeStampFor(String fullVirtualName) + public long getTimeStampFor(String fullVirtualName) throws SystemMessageException { return getTimeStampFor(fullVirtualName, true); } @@ -784,33 +792,29 @@ public class SystemZipHandler implements ISystemArchiveHandler * Same as getTimeStampFor(String fullVirtualName) but you can choose whether * or not you want to leave the zipfile open after return. */ - public long getTimeStampFor(String fullVirtualName, boolean closeZipFile) + public long getTimeStampFor(String fullVirtualName, boolean closeZipFile) throws SystemMessageException { if (!_exists) return 0; - - if (openZipFile()) + try { + openZipFile(); fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); ZipEntry entry = null; - try - { - entry = safeGetEntry(fullVirtualName); - } - catch (IOException e) - { - if (closeZipFile) closeZipFile(); - return _file.lastModified(); - } + entry = safeGetEntry(fullVirtualName); if (closeZipFile) closeZipFile(); return entry.getTime(); } - else return _file.lastModified(); + catch (IOException e) { + if (closeZipFile) + closeZipFile(); + return _file.lastModified(); + } } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getSizeFor(java.lang.String) */ - public long getSizeFor(String fullVirtualName) + public long getSizeFor(String fullVirtualName) throws SystemMessageException { return getSizeFor(fullVirtualName, true); } @@ -824,43 +828,40 @@ public class SystemZipHandler implements ISystemArchiveHandler * @return the uncompressed size of the node requested. * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getSizeFor(java.lang.String) */ - public long getSizeFor(String fullVirtualName, boolean closeZipFile) + public long getSizeFor(String fullVirtualName, boolean closeZipFile) throws SystemMessageException { if (!_exists) return 0; - - if (openZipFile()) + try { + openZipFile(); fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); ZipEntry entry = null; - try - { - entry = safeGetEntry(fullVirtualName); - } - catch (IOException e) - { - if (closeZipFile) closeZipFile(); - return 0; - } + entry = safeGetEntry(fullVirtualName); if (closeZipFile) closeZipFile(); return entry.getSize(); } - else return 0; + catch (IOException e) { + if (closeZipFile) + closeZipFile(); + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); + } } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualFile(java.lang.String, java.io.File) */ - public boolean extractVirtualFile(String fullVirtualName, File destination, ISystemOperationMonitor archiveOperationMonitor) + public void extractVirtualFile(String fullVirtualName, File destination, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { - return extractVirtualFile(fullVirtualName, destination, true, SystemEncodingUtil.ENCODING_UTF_8, false, archiveOperationMonitor); + extractVirtualFile(fullVirtualName, destination, true, SystemEncodingUtil.ENCODING_UTF_8, false, archiveOperationMonitor); } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualFile(java.lang.String, java.io.File, java.lang.String, boolean) */ - public boolean extractVirtualFile(String fullVirtualName, File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) + public void extractVirtualFile(String fullVirtualName, File destination, String sourceEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { - return extractVirtualFile(fullVirtualName, destination, true, sourceEncoding, isText, archiveOperationMonitor); + extractVirtualFile(fullVirtualName, destination, true, sourceEncoding, isText, archiveOperationMonitor); } /** @@ -868,9 +869,11 @@ public class SystemZipHandler implements ISystemArchiveHandler * or not you want to leave the zipfile open after return. * @since org.eclipse.rse.services 3.0 */ - public boolean extractVirtualFile(String fullVirtualName, File destination, boolean closeZipFile, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) + public void extractVirtualFile(String fullVirtualName, File destination, boolean closeZipFile, String sourceEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { - if (!_exists) return false; + if (!_exists) + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); int mutexLockStatus = _mutex.waitForLock(archiveOperationMonitor, Long.MAX_VALUE); if (SystemReentrantMutex.LOCK_STATUS_NOLOCK != mutexLockStatus) { @@ -888,14 +891,14 @@ public class SystemZipHandler implements ISystemArchiveHandler destination.mkdirs(); destination.setLastModified(entry.getTime()); if (closeZipFile) closeZipFile(); - return true; + return; } InputStream is = _zipfile.getInputStream(entry); if (is == null) { destination.setLastModified(entry.getTime()); if (closeZipFile) closeZipFile(); - return true; + return; } BufferedInputStream reader = new BufferedInputStream(is); @@ -932,7 +935,7 @@ public class SystemZipHandler implements ISystemArchiveHandler } destination.setLastModified(entry.getTime()); if (closeZipFile) closeZipFile(); - return true; + return; } catch (IOException e) { @@ -942,11 +945,10 @@ public class SystemZipHandler implements ISystemArchiveHandler destination.mkdirs(); destination.setLastModified(_file.lastModified()); if (closeZipFile) closeZipFile(); - return true; + return; } - System.out.println(e.getMessage()); if (closeZipFile) closeZipFile(); - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } finally { @@ -956,45 +958,51 @@ public class SystemZipHandler implements ISystemArchiveHandler } else { - return false; + throw new SystemLockTimeoutException(Activator.PLUGIN_ID); } } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File) */ - public boolean extractVirtualDirectory(String dir, File destinationParent, ISystemOperationMonitor archiveOperationMonitor) + public void extractVirtualDirectory(String dir, File destinationParent, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { - return extractVirtualDirectory(dir, destinationParent, (File) null, SystemEncodingUtil.ENCODING_UTF_8, false, archiveOperationMonitor); + extractVirtualDirectory(dir, destinationParent, (File) null, SystemEncodingUtil.ENCODING_UTF_8, false, archiveOperationMonitor); } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.lang.String, boolean) */ - public boolean extractVirtualDirectory(String dir, File destinationParent, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) + public void extractVirtualDirectory(String dir, File destinationParent, String sourceEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { - return extractVirtualDirectory(dir, destinationParent, (File) null, sourceEncoding, isText, archiveOperationMonitor); + extractVirtualDirectory(dir, destinationParent, (File) null, sourceEncoding, isText, archiveOperationMonitor); } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.io.File) */ - public boolean extractVirtualDirectory(String dir, File destinationParent, File destination, ISystemOperationMonitor archiveOperationMonitor) + public void extractVirtualDirectory(String dir, File destinationParent, File destination, ISystemOperationMonitor archiveOperationMonitor) + throws SystemMessageException { - return extractVirtualDirectory(dir, destinationParent, destination, SystemEncodingUtil.ENCODING_UTF_8, false, archiveOperationMonitor); + extractVirtualDirectory(dir, destinationParent, destination, SystemEncodingUtil.ENCODING_UTF_8, false, archiveOperationMonitor); } /* * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.io.File, java.lang.String, boolean, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean extractVirtualDirectory(String dir, File destinationParent, File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) + public void extractVirtualDirectory(String dir, File destinationParent, File destination, String sourceEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { - if (!_exists) return false; + if (!_exists) + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); - if (!destinationParent.isDirectory()) return false; + if (!destinationParent.isDirectory()) + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); dir = ArchiveHandlerManager.cleanUpVirtualPath(dir); - if (!_virtualFS.containsKey(dir)) return false; + if (!_virtualFS.containsKey(dir)) + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); String name; int charsToTrim; @@ -1028,9 +1036,7 @@ public class SystemZipHandler implements ISystemArchiveHandler { if (!SystemArchiveUtil.delete(destination)) { - System.out.println("Could not overwrite directory " + destination); //$NON-NLS-1$ - System.out.println("(Could not delete old directory)"); //$NON-NLS-1$ - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not overwrite directory " + destination); //$NON-NLS-1$ } } @@ -1038,9 +1044,7 @@ public class SystemZipHandler implements ISystemArchiveHandler { if (!destination.mkdirs()) { - System.out.println("Could not overwrite directory " + destination); //$NON-NLS-1$ - System.out.println("(Could not create new directory)"); //$NON-NLS-1$ - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not overwrite directory " + destination); //$NON-NLS-1$ } } } @@ -1068,7 +1072,7 @@ public class SystemZipHandler implements ISystemArchiveHandler if (newChildren.length == 0) { //it is a error situation, or the operation has been cancelled. - return false; + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); } extractVirtualFile(dir + '/', topFile, sourceEncoding, isText, archiveOperationMonitor); @@ -1094,85 +1098,80 @@ public class SystemZipHandler implements ISystemArchiveHandler { if (!nextFile.mkdirs()) { - System.out.println("Could not create folder " + nextFile.toString()); //$NON-NLS-1$ - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create folder " + nextFile.toString()); //$NON-NLS-1$ } } else { createFile(nextFile); } - boolean success = false; if (newChildren[i].isDirectory) { - success = extractVirtualFile(newChildren[i].fullName + '/', nextFile, sourceEncoding, isText, archiveOperationMonitor); + extractVirtualFile(newChildren[i].fullName + '/', nextFile, sourceEncoding, isText, archiveOperationMonitor); } else { - success = extractVirtualFile(newChildren[i].fullName, nextFile, sourceEncoding, isText, archiveOperationMonitor); + extractVirtualFile(newChildren[i].fullName, nextFile, sourceEncoding, isText, archiveOperationMonitor); } - if (!success) return false; } } - return true; } /** * Create an empty file, also creating parent folders if necessary. * * @param file An abstract file handle to create physically. - * @return true if successful, false - * otherwise. + * @throws SystemMessageException in case of an error otherwise. */ - protected boolean createFile(File file) + protected void createFile(File file) throws SystemMessageException { try { if (!file.createNewFile()) { - System.out.println("File already exists: " + file.toString()); //$NON-NLS-1$ - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "File already exists: " + file.toString()); //$NON-NLS-1$ } else { - return true; + return; } } catch (IOException e) { if (!file.getParentFile().exists() && file.getParentFile().mkdirs()) { - return createFile(file); + createFile(file); } else { - System.out.println("Could not create " + file.toString()); //$NON-NLS-1$ - System.out.println(e.getMessage()); - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not create " + file.toString()); //$NON-NLS-1$ } } } + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File, java.lang.String, java.lang.String) */ - public boolean add(File file, String virtualPath, String name, ISystemOperationMonitor archiveOperationMonitor) + public void add(File file, String virtualPath, String name, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { - return add(file, virtualPath, name, SystemEncodingUtil.ENCODING_UTF_8, SystemEncodingUtil.ENCODING_UTF_8, false, archiveOperationMonitor); + add(file, virtualPath, name, SystemEncodingUtil.ENCODING_UTF_8, SystemEncodingUtil.ENCODING_UTF_8, false, archiveOperationMonitor); } /* * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.InputStream, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean add(InputStream stream, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) + public void add(InputStream stream, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { - if (!_exists) return false; + if (!_exists) + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); virtualPath = ArchiveHandlerManager.cleanUpVirtualPath(virtualPath); if (exists(virtualPath + "/" + name, archiveOperationMonitor)) //$NON-NLS-1$ { // wrong method - return replace(virtualPath + "/" + name, stream, name, sourceEncoding, targetEncoding, isText, archiveOperationMonitor); //$NON-NLS-1$ + replace(virtualPath + "/" + name, stream, name, sourceEncoding, targetEncoding, isText, archiveOperationMonitor); //$NON-NLS-1$ } int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; @@ -1205,7 +1204,7 @@ public class SystemZipHandler implements ISystemArchiveHandler dest.close(); if (!(outputTempFile == null)) outputTempFile.delete(); closeZipFile(); - return false; + throw new SystemOperationCancelledException(); } } @@ -1222,33 +1221,30 @@ public class SystemZipHandler implements ISystemArchiveHandler } catch (IOException e) { - System.out.println("Could not add a file."); //$NON-NLS-1$ - System.out.println(e.getMessage()); closeZipFile(); - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not add a file.", e); //$NON-NLS-1$ } closeZipFile(); - return true; } + } else { + throw new SystemLockTimeoutException(Activator.PLUGIN_ID); } } catch(Exception e) { - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } finally { releaseMutex(mutexLockStatus); } - - return false; } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File[], java.lang.String, java.lang.String[]) */ - public boolean add(File[] files, String virtualPath, String[] names, ISystemOperationMonitor archiveOperationMonitor) + public void add(File[] files, String virtualPath, String[] names, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { String[] encodings = new String[files.length]; boolean[] isTexts = new boolean[files.length]; @@ -1257,16 +1253,17 @@ public class SystemZipHandler implements ISystemArchiveHandler encodings[i] = SystemEncodingUtil.ENCODING_UTF_8; isTexts[i] = false; } - return add(files, virtualPath, names, encodings, encodings, isTexts, true, archiveOperationMonitor); + add(files, virtualPath, names, encodings, encodings, isTexts, true, archiveOperationMonitor); } /* * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File[], java.lang.String, java.lang.String[], java.lang.String[], java.lang.String[], boolean[], org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean add(File[] files, String virtualPath, String[] names, String[] sourceEncodings, String[] targetEncodings, boolean[] isText, ISystemOperationMonitor archiveOperationMonitor) + public void add(File[] files, String virtualPath, String[] names, String[] sourceEncodings, String[] targetEncodings, boolean[] isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { - return add(files, virtualPath, names, sourceEncodings, targetEncodings, isText, true, archiveOperationMonitor); + add(files, virtualPath, names, sourceEncodings, targetEncodings, isText, true, archiveOperationMonitor); } @@ -1275,9 +1272,11 @@ public class SystemZipHandler implements ISystemArchiveHandler * or not you want to leave the zipfile open after return. * @since org.eclipse.rse.services 3.0 */ - public boolean add(File[] files, String virtualPath, String[] names, String[] sourceEncodings, String[] targetEncodings, boolean[] isText, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) + public void add(File[] files, String virtualPath, String[] names, String[] sourceEncodings, String[] targetEncodings, boolean[] isText, + boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { - if (!_exists) return false; + if (!_exists) + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; try @@ -1295,14 +1294,16 @@ public class SystemZipHandler implements ISystemArchiveHandler { //the operation has been cancelled closeZipFile(); - return false; + throw new SystemOperationCancelledException(); + } + if (!files[i].exists() || !files[i].canRead()) { + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Cannot read: " + files[i]); //$NON-NLS-1$ } - if (!files[i].exists() || !files[i].canRead()) return false; String fullVirtualName = getFullVirtualName(virtualPath, names[i]); if (exists(fullVirtualName, archiveOperationMonitor)) { // sorry, wrong method buddy - return replace(fullVirtualName, files[i], names[i], archiveOperationMonitor); + replace(fullVirtualName, files[i], names[i], archiveOperationMonitor); } } File outputTempFile; @@ -1328,7 +1329,7 @@ public class SystemZipHandler implements ISystemArchiveHandler outputTempFile.delete(); } if (closeZipFile) closeZipFile(); - return false; + throw new SystemOperationCancelledException(); } } @@ -1347,7 +1348,7 @@ public class SystemZipHandler implements ISystemArchiveHandler outputTempFile.delete(); } closeZipFile(); - return false; + throw new SystemOperationCancelledException(); } // append the additional entry to the zip file. ZipEntry newEntry = appendFile(files[i], dest, virtualPath, names[i], sourceEncodings[i], targetEncodings[i], isText[i]); @@ -1366,21 +1367,19 @@ public class SystemZipHandler implements ISystemArchiveHandler } if (closeZipFile) closeZipFile(); - return true; } + } else { + throw new SystemLockTimeoutException(Activator.PLUGIN_ID); } } - catch(Exception e) - { - if (closeZipFile) closeZipFile(); - return false; + catch (IOException ioe) { + throw new SystemOperationFailedException(Activator.PLUGIN_ID, ioe); } finally { + if (closeZipFile) closeZipFile(); releaseMutex(mutexLockStatus); } - - return false; } /** @@ -1421,14 +1420,16 @@ public class SystemZipHandler implements ISystemArchiveHandler } /** - * Recreates a zip file from a list of virtual children, optionally - * omitting a group of children whose names are in the Set omitChildren + * Recreates a zip file from a list of virtual children, optionally omitting + * a group of children whose names are in the Set omitChildren + * * @param vcList The list of virtual children to create the zip from * @param dest The ZipOutputStream representing the zip file where the - * children are to be recreated + * children are to be recreated * @param omitChildren The set of names of children to omit when creating - * the zipfile. Null or empty set if there are no omissions. + * the zipfile. Null or empty set if there are no omissions. * @throws IOException in case of a file I/O error + * @return true if the operation is cancelled * @since org.eclipse.rse.services 3.0 */ protected boolean recreateZipDeleteEntries(VirtualChild[] vcList, ZipOutputStream dest, HashSet omitChildren, ISystemOperationMonitor archiveOperationMonitor) throws IOException @@ -1483,11 +1484,14 @@ public class SystemZipHandler implements ISystemArchiveHandler /** * Recreates a zip file from a list of virtual children, but renaming the * one of the VirtualChildren. + * * @param vcList The list of virtual children to create the zip from * @param dest The ZipOutputStream representing the zip file where the - * children are to be recreated - * @param names HashMap maps the full path of a virtual file to the entry in the archive file - * @throws IOException + * children are to be recreated + * @param names HashMap maps the full path of a virtual file to the entry in + * the archive file + * @return true if the operation has been cancelled + * @throws IOException in case of an error. * @since org.eclipse.rse.services 3.0 */ protected boolean recreateZipRenameEntries(VirtualChild[] vcList, ZipOutputStream dest, HashMap names, ISystemOperationMonitor archiveOperationMonitor) throws IOException @@ -1544,13 +1548,14 @@ public class SystemZipHandler implements ISystemArchiveHandler } /** - * Compresses the contents of file, adding them to the - * ZipFile managed by dest. The file is encoded in the encoding - * specified by encoding. A new entry is created in the - * ZipFile with virtual path and name of virtualPath and name - * respectively. + * Compresses the contents of file, adding them to the ZipFile + * managed by dest. The file is encoded in the encoding + * specified by encoding. A new entry is created in the ZipFile + * with virtual path and name of virtualPath and + * name respectively. + * * @return The ZipEntry that was added to the destination zip file. - * @throws IOException + * @throws IOException in case of an error. */ protected ZipEntry appendFile(File file, ZipOutputStream dest, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText) throws IOException { @@ -1612,12 +1617,13 @@ public class SystemZipHandler implements ISystemArchiveHandler /** * Compresses the contents of stream, adding them to the - * ZipFile managed by dest. The stream is encoded in the encoding - * specified by encoding. A new entry is created in the - * ZipFile with virtual path and name of virtualPath and name - * respectively. + * ZipFile managed by dest. The stream is encoded in the + * encoding specified by encoding. A new entry is created in + * the ZipFile with virtual path and name of virtualPath and + * name respectively. + * * @return The ZipEntry that was added to the destination zip file. - * @throws IOException + * @throws IOException in case of an error. */ protected ZipEntry appendBytes(InputStream stream, ZipOutputStream dest, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText) throws IOException { @@ -1682,7 +1688,7 @@ public class SystemZipHandler implements ISystemArchiveHandler /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#delete(java.lang.String) */ - public boolean delete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) + public boolean delete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { boolean returnCode = delete(fullVirtualName, true, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); @@ -1694,7 +1700,7 @@ public class SystemZipHandler implements ISystemArchiveHandler * or not you want to leave the zipfile open after return. * @since org.eclipse.rse.services 3.0 */ - public boolean delete(String fullVirtualName, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) + public boolean delete(String fullVirtualName, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { if (!_exists) return false; File outputTempFile = null; @@ -1757,7 +1763,7 @@ public class SystemZipHandler implements ISystemArchiveHandler dest.close(); if (!(outputTempFile == null)) outputTempFile.delete(); if (closeZipFile) closeZipFile(); - return false; + throw new SystemOperationCancelledException(); } dest.close(); @@ -1776,15 +1782,15 @@ public class SystemZipHandler implements ISystemArchiveHandler setArchiveOperationMonitorStatusDone(archiveOperationMonitor); return true; } + } else { + throw new SystemLockTimeoutException(Activator.PLUGIN_ID); } } catch (IOException e) { - System.out.println(e.getMessage()); - System.out.println("Could not delete " + fullVirtualName); //$NON-NLS-1$ if (!(outputTempFile == null)) outputTempFile.delete(); if (closeZipFile) closeZipFile(); - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not delete " + fullVirtualName, e); //$NON-NLS-1$ } finally { @@ -1816,9 +1822,9 @@ public class SystemZipHandler implements ISystemArchiveHandler /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#replace(java.lang.String, java.io.File, java.lang.String) */ - public boolean replace(String fullVirtualName, File file, String name, ISystemOperationMonitor archiveOperationMonitor) + public void replace(String fullVirtualName, File file, String name, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { - return replace(fullVirtualName, file, name, true, archiveOperationMonitor); + replace(fullVirtualName, file, name, true, archiveOperationMonitor); } /** @@ -1826,80 +1832,75 @@ public class SystemZipHandler implements ISystemArchiveHandler * or not you want to leave the zipfile open after return. * @since org.eclipse.rse.services 3.0 */ - public boolean replace(String fullVirtualName, File file, String name, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) + public void replace(String fullVirtualName, File file, String name, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) + throws SystemMessageException { - if (!_exists) return false; + if (!_exists) + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); - if (!file.exists() || !file.canRead()) return false; + if (!file.exists() || !file.canRead()) { + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Cannot read: " + file); //$NON-NLS-1$ + } fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); if (!exists(fullVirtualName, archiveOperationMonitor)) { // sorry, wrong method buddy - return add(file, fullVirtualName, name, archiveOperationMonitor); + add(file, fullVirtualName, name, archiveOperationMonitor); } - - - if (openZipFile()) + File outputTempFile = null; + try { - File outputTempFile = null; - try + openZipFile(); + // Open a new tempfile which will be our destination for the new zip + outputTempFile = new File(_file.getAbsolutePath() + "temp"); //$NON-NLS-1$ + ZipOutputStream dest = new ZipOutputStream(new FileOutputStream(outputTempFile)); + dest.setMethod(ZipOutputStream.DEFLATED); + // get all the entries in the old zip + VirtualChild[] vcList = getVirtualChildrenList(false, archiveOperationMonitor); + HashSet omissions = new HashSet(); + omissions.add(fullVirtualName); + + boolean isCancelled = recreateZipDeleteEntries(vcList, dest, omissions, archiveOperationMonitor); + if (isCancelled) { - // Open a new tempfile which will be our destination for the new zip - outputTempFile = new File(_file.getAbsolutePath() + "temp"); //$NON-NLS-1$ - ZipOutputStream dest = new ZipOutputStream( - new FileOutputStream(outputTempFile)); - dest.setMethod(ZipOutputStream.DEFLATED); - // get all the entries in the old zip - VirtualChild[] vcList = getVirtualChildrenList(false, archiveOperationMonitor); - HashSet omissions = new HashSet(); - omissions.add(fullVirtualName); - - boolean isCancelled = recreateZipDeleteEntries(vcList, dest, omissions, archiveOperationMonitor); - if (isCancelled) - { - dest.close(); - if (!(outputTempFile == null)) outputTempFile.delete(); - if (closeZipFile) closeZipFile(); - return false; - } - - // Now append the additional entry to the zip file. - int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$ - String virtualPath; - if (i == -1) - { - virtualPath = ""; //$NON-NLS-1$ - } - else - { - virtualPath = fullVirtualName.substring(0,i); - } - - - // append the additional entry to the zip file. - ZipEntry newEntry = appendFile(file, dest, virtualPath, name, SystemEncodingUtil.ENCODING_UTF_8, SystemEncodingUtil.ENCODING_UTF_8, false); - - // Add the new entry to the virtual file system in memory - fillBranch(newEntry); - dest.close(); - - // Now replace the old zip file with the new one - replaceOldZip(outputTempFile); - + if (!(outputTempFile == null)) + outputTempFile.delete(); + if (closeZipFile) + closeZipFile(); + throw new SystemOperationCancelledException(); } - catch (IOException e) - { - System.out.println("Could not replace " + file.getName()); //$NON-NLS-1$ - if (!(outputTempFile == null)) outputTempFile.delete(); - if (closeZipFile) closeZipFile(); - return false; + + // Now append the additional entry to the zip file. + int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$ + String virtualPath; + if (i == -1) { + virtualPath = ""; //$NON-NLS-1$ + } else { + virtualPath = fullVirtualName.substring(0, i); } + + + // append the additional entry to the zip file. + ZipEntry newEntry = appendFile(file, dest, virtualPath, name, SystemEncodingUtil.ENCODING_UTF_8, SystemEncodingUtil.ENCODING_UTF_8, false); + + // Add the new entry to the virtual file system in memory + fillBranch(newEntry); + + dest.close(); + + // Now replace the old zip file with the new one + replaceOldZip(outputTempFile); + + } catch (IOException e) { + if (!(outputTempFile == null)) + outputTempFile.delete(); if (closeZipFile) closeZipFile(); - return true; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not replace " + file.getName(), e); //$NON-NLS-1$ } - else return false; + if (closeZipFile) + closeZipFile(); } @@ -1907,96 +1908,95 @@ public class SystemZipHandler implements ISystemArchiveHandler * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#replace(java.lang.String, java.io.InputStream, java.lang.String, java.lang.String, java.lang.String, boolean, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean replace(String fullVirtualName, InputStream stream, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) + public void replace(String fullVirtualName, InputStream stream, String name, String sourceEncoding, String targetEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { - if (!_exists) return false; + if (!_exists) + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); if (!exists(fullVirtualName, archiveOperationMonitor)) { // wrong method - return add(stream, fullVirtualName, name, sourceEncoding, targetEncoding, isText, archiveOperationMonitor); + add(stream, fullVirtualName, name, sourceEncoding, targetEncoding, isText, archiveOperationMonitor); } - if (openZipFile()) + File outputTempFile = null; + try { - File outputTempFile = null; - try + openZipFile(); + // Open a new tempfile which will be our destination for the new zip + outputTempFile = new File(_file.getAbsolutePath() + "temp"); //$NON-NLS-1$ + ZipOutputStream dest = new ZipOutputStream(new FileOutputStream(outputTempFile)); + dest.setMethod(ZipOutputStream.DEFLATED); + // get all the entries in the old zip + VirtualChild[] vcList = getVirtualChildrenList(false, archiveOperationMonitor); + HashSet omissions = new HashSet(); + omissions.add(fullVirtualName); + boolean isCancelled = recreateZipDeleteEntries(vcList, dest, omissions, archiveOperationMonitor); + if (isCancelled) { - // Open a new tempfile which will be our destination for the new zip - outputTempFile = new File(_file.getAbsolutePath() + "temp"); //$NON-NLS-1$ - ZipOutputStream dest = new ZipOutputStream( - new FileOutputStream(outputTempFile)); - dest.setMethod(ZipOutputStream.DEFLATED); - // get all the entries in the old zip - VirtualChild[] vcList = getVirtualChildrenList(false, archiveOperationMonitor); - HashSet omissions = new HashSet(); - omissions.add(fullVirtualName); - boolean isCancelled = recreateZipDeleteEntries(vcList, dest, omissions, archiveOperationMonitor); - if (isCancelled) - { - dest.close(); - if (!(outputTempFile == null)) outputTempFile.delete(); - closeZipFile(); - return false; - } - - // Now append the additional entry to the zip file. - int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$ - String virtualPath; - if (i == -1) - { - virtualPath = ""; //$NON-NLS-1$ - } - else - { - virtualPath = fullVirtualName.substring(0,i); - } - appendBytes(stream, dest, virtualPath, name, sourceEncoding, targetEncoding, isText); dest.close(); - - // Now replace the old zip file with the new one - replaceOldZip(outputTempFile); - - } - catch (IOException e) - { - System.out.println("Could not replace " + fullVirtualName); //$NON-NLS-1$ - if (!(outputTempFile == null)) outputTempFile.delete(); + if (!(outputTempFile == null)) + outputTempFile.delete(); closeZipFile(); - return false; + throw new SystemOperationCancelledException(); } + + // Now append the additional entry to the zip file. + int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$ + String virtualPath; + if (i == -1) { + virtualPath = ""; //$NON-NLS-1$ + } + else + { + virtualPath = fullVirtualName.substring(0, i); + } + appendBytes(stream, dest, virtualPath, name, sourceEncoding, targetEncoding, isText); + dest.close(); + + // Now replace the old zip file with the new one + replaceOldZip(outputTempFile); + + } catch (IOException e) { + if (!(outputTempFile == null)) + outputTempFile.delete(); closeZipFile(); - return true; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not replace " + fullVirtualName, e); //$NON-NLS-1$ } - else return false; + closeZipFile(); } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#fullRename(java.lang.String, java.lang.String) */ - public boolean fullRename(String fullVirtualName, String newFullVirtualName, ISystemOperationMonitor archiveOperationMonitor) + public void fullRename(String fullVirtualName, String newFullVirtualName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { - return fullRename(fullVirtualName, newFullVirtualName, true, archiveOperationMonitor); + fullRename(fullVirtualName, newFullVirtualName, true, archiveOperationMonitor); } /** - * Same as fullRename(String fullVirtualName, String newFullVirtualName) but you can choose whether - * or not you want to leave the zipfile open after return. + * Same as fullRename(String fullVirtualName, String newFullVirtualName) but + * you can choose whether or not you want to leave the zipfile open after + * return. + * + * @throws SystemMessageException in case of an error or user cancellation. * @since org.eclipse.rse.services 3.0 */ - public boolean fullRename(String fullVirtualName, String newFullVirtualName, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) + public void fullRename(String fullVirtualName, String newFullVirtualName, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) + throws SystemMessageException { - if (!_exists) return false; + if (!_exists) + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); newFullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(newFullVirtualName); VirtualChild vc = getVirtualFile(fullVirtualName, archiveOperationMonitor); if (!vc.exists()) { - System.out.println("The virtual file " + fullVirtualName + " does not exist."); //$NON-NLS-1$ //$NON-NLS-2$ - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "The virtual file " + fullVirtualName + " does not exist."); //$NON-NLS-1$ //$NON-NLS-2$ } File outputTempFile = null; int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; @@ -2062,7 +2062,7 @@ public class SystemZipHandler implements ISystemArchiveHandler { if (!(outputTempFile == null)) outputTempFile.delete(); if (closeZipFile) closeZipFile(); - return false; + throw new SystemOperationCancelledException(); } // Now replace the old zip file with the new one replaceOldZip(outputTempFile); @@ -2070,20 +2070,17 @@ public class SystemZipHandler implements ISystemArchiveHandler // Now rebuild the tree updateTreeAfterRename(newOldNames, renameList); if (closeZipFile) closeZipFile(); - return true; } else { - return false; + throw new SystemLockTimeoutException(Activator.PLUGIN_ID); } } catch (IOException e) { - e.printStackTrace(); - System.out.println("Could not rename " + fullVirtualName); //$NON-NLS-1$ if (!(outputTempFile == null)) outputTempFile.delete(); if (closeZipFile) closeZipFile(); - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not rename " + fullVirtualName, e); //$NON-NLS-1$ } finally { @@ -2094,41 +2091,40 @@ public class SystemZipHandler implements ISystemArchiveHandler /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#move(java.lang.String, java.lang.String) */ - public boolean move(String fullVirtualName, String destinationVirtualPath, ISystemOperationMonitor archiveOperationMonitor) + public void move(String fullVirtualName, String destinationVirtualPath, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); destinationVirtualPath = ArchiveHandlerManager.cleanUpVirtualPath(destinationVirtualPath); int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$ if (i == -1) { - return fullRename(fullVirtualName, destinationVirtualPath + "/" + fullVirtualName, archiveOperationMonitor); //$NON-NLS-1$ + fullRename(fullVirtualName, destinationVirtualPath + "/" + fullVirtualName, archiveOperationMonitor); //$NON-NLS-1$ } String name = fullVirtualName.substring(i); - return fullRename(fullVirtualName, destinationVirtualPath + name, archiveOperationMonitor); + fullRename(fullVirtualName, destinationVirtualPath + name, archiveOperationMonitor); } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#rename(java.lang.String, java.lang.String) */ - public boolean rename(String fullVirtualName, String newName, ISystemOperationMonitor archiveOperationMonitor) + public void rename(String fullVirtualName, String newName, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$ if (i == -1) { - return fullRename(fullVirtualName, newName, archiveOperationMonitor); + fullRename(fullVirtualName, newName, archiveOperationMonitor); } String fullNewName = fullVirtualName.substring(0, i+1) + newName; - boolean returnValue = fullRename(fullVirtualName, fullNewName, archiveOperationMonitor); + fullRename(fullVirtualName, fullNewName, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return returnValue; } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getFiles(java.lang.String[]) */ - public File[] getFiles(String[] fullNames, ISystemOperationMonitor archiveOperationMonitor) + public File[] getFiles(String[] fullNames, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { if (!_exists) return new File[0]; @@ -2155,9 +2151,7 @@ public class SystemZipHandler implements ISystemArchiveHandler } catch (IOException e) { - System.out.println(e.getMessage()); - System.out.println("Could not extract virtual file: " + fullNames[i]); //$NON-NLS-1$ - return null; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not extract virtual file: " + fullNames[i], e); //$NON-NLS-1$ } } return files; @@ -2166,40 +2160,40 @@ public class SystemZipHandler implements ISystemArchiveHandler /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#createFolder(java.lang.String) */ - public boolean createFolder(String name, ISystemOperationMonitor archiveOperationMonitor) + public void createFolder(String name, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { name = ArchiveHandlerManager.cleanUpVirtualPath(name); name = name + "/"; //$NON-NLS-1$ - boolean returnCode = createVirtualObject(name, true, archiveOperationMonitor); + createVirtualObject(name, true, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return returnCode; } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#createFile(java.lang.String) */ - public boolean createFile(String name, ISystemOperationMonitor archiveOperationMonitor) + public void createFile(String name, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { name = ArchiveHandlerManager.cleanUpVirtualPath(name); - boolean returnCode = createVirtualObject(name, true, archiveOperationMonitor); + createVirtualObject(name, true, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return returnCode; } /** - * Creates a new, empty object in the virtual File system, and - * creates an empty file or folder in the physical zip file. - * @param name The name of the file or folder to create. The object - * created will be a folder if and only if - * name ends in a "/". - * @return Whether the creation was successful or not. + * Creates a new, empty object in the virtual File system, and creates an + * empty file or folder in the physical zip file. + * + * @param name The name of the file or folder to create. The object created + * will be a folder if and only if name ends in a "/". + * @return true if the object was created. false + * if the creation was a no-op because the object already existed. + * @throws SystemMessageException in case of an error or cancellation. * @since org.eclipse.rse.services 3.0 */ - protected boolean createVirtualObject(String name, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) + protected boolean createVirtualObject(String name, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { if (!_exists) { - return false; + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); } if (exists(name, archiveOperationMonitor)) { @@ -2234,7 +2228,7 @@ public class SystemZipHandler implements ISystemArchiveHandler dest.close(); if (!(outputTempFile == null)) outputTempFile.delete(); if (closeZipFile) closeZipFile(); - return false; + throw new SystemOperationCancelledException(); } } @@ -2251,14 +2245,16 @@ public class SystemZipHandler implements ISystemArchiveHandler if (closeZipFile) closeZipFile(); return true; } + } else { + throw new SystemLockTimeoutException(Activator.PLUGIN_ID); } } catch (IOException e) { - System.out.println("Could not add a file."); //$NON-NLS-1$ + System.out.println(); System.out.println(e.getMessage()); if (closeZipFile) closeZipFile(); - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "Could not add a file.", e); //$NON-NLS-1$ } finally { @@ -2315,21 +2311,13 @@ public class SystemZipHandler implements ISystemArchiveHandler /** * Opens the zipfile that this handler manages. - * @return Whether the zipfile was successfully opened. + * + * @throws IOException in case of an error */ - protected boolean openZipFile() + protected boolean openZipFile() throws IOException { if (!(_zipfile == null)) closeZipFile(); - try - { - _zipfile = new ZipFile(_file); - } - catch (IOException e) - { - System.out.println("Could not open zipfile: " + _file); //$NON-NLS-1$ - System.out.println(e.getMessage()); - return false; - } + _zipfile = new ZipFile(_file); return true; } @@ -2408,7 +2396,7 @@ public class SystemZipHandler implements ISystemArchiveHandler * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#create() */ - public boolean create() + public void create() throws SystemMessageException { try { @@ -2424,23 +2412,15 @@ public class SystemZipHandler implements ISystemArchiveHandler recreateZipDeleteEntries(vcList, dest, omissions, null); dest.close(); - if (openZipFile()) - { - buildTree(); - closeZipFile(); - } - else - { - return false; - } + openZipFile(); + buildTree(); + closeZipFile(); } catch (IOException e) { - System.out.println(e.getMessage()); - return false; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } _exists = true; - return true; } /* @@ -2448,6 +2428,7 @@ public class SystemZipHandler implements ISystemArchiveHandler * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#search(java.lang.String, org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public SystemSearchLineMatch[] search(String fullVirtualName, SystemSearchStringMatcher matcher, ISystemOperationMonitor archiveOperationMonitor) + throws SystemMessageException { // if the search string is empty or if it is "*", then return no matches @@ -2464,44 +2445,35 @@ public class SystemZipHandler implements ISystemArchiveHandler return new SystemSearchLineMatch[0]; } - if (openZipFile()) { + ZipEntry entry = null; + SystemSearchLineMatch[] matches = null; - ZipEntry entry = null; + try { + openZipFile(); + entry = safeGetEntry(fullVirtualName); + InputStream is = _zipfile.getInputStream(entry); - SystemSearchLineMatch[] matches = null; - - try + if (is == null) { - entry = safeGetEntry(fullVirtualName); - InputStream is = _zipfile.getInputStream(entry); - - if (is == null) - { - return new SystemSearchLineMatch[0]; - } - - InputStreamReader isr = new InputStreamReader(is); - BufferedReader bufReader = new BufferedReader(isr); - - SystemSearchStringMatchLocator locator = new SystemSearchStringMatchLocator(bufReader, matcher); - matches = locator.locateMatches(); - } - catch (IOException e) - { - System.out.println(e.getMessage()); - } - - closeZipFile(); - - if (matches == null) { return new SystemSearchLineMatch[0]; } - else { - return matches; - } + + InputStreamReader isr = new InputStreamReader(is); + BufferedReader bufReader = new BufferedReader(isr); + + SystemSearchStringMatchLocator locator = new SystemSearchStringMatchLocator(bufReader, matcher); + matches = locator.locateMatches(); + } catch (IOException e) { + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); + } + + closeZipFile(); + + if (matches == null) { + return new SystemSearchLineMatch[0]; } else { - return new SystemSearchLineMatch[0]; + return matches; } } @@ -2517,7 +2489,7 @@ public class SystemZipHandler implements ISystemArchiveHandler /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getCommentFor(java.lang.String) */ - public String getCommentFor(String fullVirtualName) + public String getCommentFor(String fullVirtualName) throws SystemMessageException { return getCommentFor(fullVirtualName, true); } @@ -2526,35 +2498,33 @@ public class SystemZipHandler implements ISystemArchiveHandler * same as getCommentFor(String) but you can choose whether or not to leave * the zipfile open after the method is closed */ - public String getCommentFor(String fullVirtualName, boolean closeZipFile) + public String getCommentFor(String fullVirtualName, boolean closeZipFile) throws SystemMessageException { if (!_exists) return ""; //$NON-NLS-1$ - if (openZipFile()) + ZipEntry entry = null; + try { + openZipFile(); fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); - ZipEntry entry = null; - try - { - entry = safeGetEntry(fullVirtualName); - } - catch (IOException e) - { - if (closeZipFile) closeZipFile(); - return ""; //$NON-NLS-1$ - } + entry = safeGetEntry(fullVirtualName); + } catch (IOException e) { if (closeZipFile) closeZipFile(); - String comment = entry.getComment(); - if (comment == null) return ""; //$NON-NLS-1$ - else return comment; + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } - else return ""; //$NON-NLS-1$ + if (closeZipFile) + closeZipFile(); + String comment = entry.getComment(); + if (comment == null) + return ""; //$NON-NLS-1$ + else + return comment; } /* (non-Javadoc) * @see org.eclipse.rse.core.archiveutils.ISystemArchiveHandler#getCompressedSizeFor(java.lang.String) */ - public long getCompressedSizeFor(String fullVirtualName) + public long getCompressedSizeFor(String fullVirtualName) throws SystemMessageException { return getCompressedSizeFor(fullVirtualName, true); } @@ -2563,33 +2533,30 @@ public class SystemZipHandler implements ISystemArchiveHandler * same as getCompressedSizeFor(String) but you can choose whether or not to leave * the zipfile open after the method is closed */ - public long getCompressedSizeFor(String fullVirtualName, boolean closeZipFile) + public long getCompressedSizeFor(String fullVirtualName, boolean closeZipFile) throws SystemMessageException { if (!_exists) return 0; - if (openZipFile()) + ZipEntry entry = null; + try { + openZipFile(); fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); - ZipEntry entry = null; - try - { - entry = safeGetEntry(fullVirtualName); - } - catch (IOException e) - { - if (closeZipFile) closeZipFile(); - return 0; - } - if (closeZipFile) closeZipFile(); - return entry.getCompressedSize(); + entry = safeGetEntry(fullVirtualName); } - else return 0; + catch (IOException e) + { + if (closeZipFile) closeZipFile(); + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); + } + if (closeZipFile) closeZipFile(); + return entry.getCompressedSize(); } /* (non-Javadoc) * @see org.eclipse.rse.core.archiveutils.ISystemArchiveHandler#getCompressionMethodFor(java.lang.String) */ - public String getCompressionMethodFor(String fullVirtualName) + public String getCompressionMethodFor(String fullVirtualName) throws SystemMessageException { return getCompressionMethodFor(fullVirtualName, true); } @@ -2598,27 +2565,23 @@ public class SystemZipHandler implements ISystemArchiveHandler * same as getCompressionMethodFor(String) but you can choose whether or not to leave * the zipfile open after the method is closed */ - public String getCompressionMethodFor(String fullVirtualName, boolean closeZipFile) + public String getCompressionMethodFor(String fullVirtualName, boolean closeZipFile) throws SystemMessageException { if (!_exists) return ""; //$NON-NLS-1$ - if (openZipFile()) + ZipEntry entry = null; + try { + openZipFile(); fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); - ZipEntry entry = null; - try - { - entry = safeGetEntry(fullVirtualName); - } - catch (IOException e) - { - if (closeZipFile) closeZipFile(); - return ""; //$NON-NLS-1$ - } + entry = safeGetEntry(fullVirtualName); + } catch (IOException e) { if (closeZipFile) closeZipFile(); - return (new Integer(entry.getMethod())).toString(); + throw new SystemOperationFailedException(Activator.PLUGIN_ID, e); } - else return ""; //$NON-NLS-1$ + if (closeZipFile) + closeZipFile(); + return (new Integer(entry.getMethod())).toString(); } /* (non-Javadoc) @@ -2633,7 +2596,7 @@ public class SystemZipHandler implements ISystemArchiveHandler * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getClassification(java.lang.String) */ - public String getClassification(String fullVirtualName) { + public String getClassification(String fullVirtualName) throws SystemMessageException { return getClassification(fullVirtualName, true); } @@ -2642,7 +2605,7 @@ public class SystemZipHandler implements ISystemArchiveHandler * open after the method is closed. * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getClassification(java.lang.String) */ - public String getClassification(String fullVirtualName, boolean closeZipFile) { + public String getClassification(String fullVirtualName, boolean closeZipFile) throws SystemMessageException { // default type String type = "file"; //$NON-NLS-1$ @@ -2663,34 +2626,31 @@ public class SystemZipHandler implements ISystemArchiveHandler boolean isExecutable = false; - if (openZipFile()) { + // get the input stream for the entry + InputStream stream = null; - // get the input stream for the entry - InputStream stream = null; + try { + openZipFile(); + ZipEntry entry = safeGetEntry(fullVirtualName); + stream = _zipfile.getInputStream(entry); - try { - ZipEntry entry = safeGetEntry(fullVirtualName); - stream = _zipfile.getInputStream(entry); + // use class file parser to parse the class file + parser = new BasicClassFileParser(stream); + parser.parse(); - // 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(); - // query if it is executable, i.e. whether it has main method - isExecutable = parser.isExecutable(); - - if (closeZipFile) { - closeZipFile(); - } + if (closeZipFile) { + closeZipFile(); } - catch (IOException e) { + } catch (IOException e) { - if (closeZipFile) { - closeZipFile(); - } - - return type; + if (closeZipFile) { + closeZipFile(); } + + return type; } // if it is executable, then also get qualified class name @@ -2713,12 +2673,13 @@ public class SystemZipHandler implements ISystemArchiveHandler * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemFileTypes, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, ISystemFileTypes registry, ISystemOperationMonitor archiveOperationMonitor) + public void add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, ISystemFileTypes registry, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { if (!_exists) { setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return false; + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); } virtualPath = ArchiveHandlerManager.cleanUpVirtualPath(virtualPath); @@ -2727,9 +2688,9 @@ public class SystemZipHandler implements ISystemArchiveHandler if (exists(virtualPath + "/" + name, archiveOperationMonitor)) //$NON-NLS-1$ { // wrong method - boolean returnCode = replace(virtualPath + "/" + name, file, name, archiveOperationMonitor); //$NON-NLS-1$ + replace(virtualPath + "/" + name, file, name, archiveOperationMonitor); //$NON-NLS-1$ setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return returnCode; + return; } else { @@ -2743,9 +2704,8 @@ public class SystemZipHandler implements ISystemArchiveHandler targetEncodings[0] = targetEncoding; boolean[] isTexts = new boolean[1]; isTexts[0] = registry.isText(file); - boolean returnCode = add(files, virtualPath, names, sourceEncodings, targetEncodings, isTexts, archiveOperationMonitor); + add(files, virtualPath, names, sourceEncodings, targetEncodings, isTexts, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return returnCode; } } else @@ -2755,7 +2715,7 @@ public class SystemZipHandler implements ISystemArchiveHandler boolean isCancelled = listAllFiles(file, children, archiveOperationMonitor); if (isCancelled) { - return false; + throw new SystemOperationCancelledException(); } File[] sources = new File[children.size() + 1]; String[] newNames = new String[children.size() + 1]; @@ -2785,9 +2745,8 @@ public class SystemZipHandler implements ISystemArchiveHandler isTexts[children.size()] = registry.isText(file); if (!newNames[children.size()].endsWith("/")) newNames[children.size()] = newNames[children.size()] + "/"; //$NON-NLS-1$ //$NON-NLS-2$ - boolean returnCode = add(sources, virtualPath, newNames, sourceEncodings, targetEncodings, isTexts, archiveOperationMonitor); + add(sources, virtualPath, newNames, sourceEncodings, targetEncodings, isTexts, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return returnCode; } } @@ -2795,12 +2754,13 @@ public class SystemZipHandler implements ISystemArchiveHandler * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) + public void add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, + ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { if (!_exists) { setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return false; + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); } virtualPath = ArchiveHandlerManager.cleanUpVirtualPath(virtualPath); @@ -2816,9 +2776,8 @@ public class SystemZipHandler implements ISystemArchiveHandler String fullVirtualName = getFullVirtualName(virtualPath, name); if (exists(fullVirtualName, archiveOperationMonitor)) { - boolean returnCode = replace(fullVirtualName, file, name, archiveOperationMonitor); + replace(fullVirtualName, file, name, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return returnCode; } else { @@ -2832,9 +2791,8 @@ public class SystemZipHandler implements ISystemArchiveHandler targetEncodings[0] = targetEncoding; boolean[] isTexts = new boolean[1]; isTexts[0] = isText; - boolean returnCode = add(files, virtualPath, names, sourceEncodings, targetEncodings, isTexts, archiveOperationMonitor); + add(files, virtualPath, names, sourceEncodings, targetEncodings, isTexts, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return returnCode; } } else @@ -2843,7 +2801,7 @@ public class SystemZipHandler implements ISystemArchiveHandler boolean isCancelled = listAllFiles(file, children, archiveOperationMonitor); if (isCancelled) { - return false; + throw new SystemOperationCancelledException(); } File[] sources = new File[children.size() + 1]; String[] newNames = new String[children.size() + 1]; @@ -2871,10 +2829,11 @@ public class SystemZipHandler implements ISystemArchiveHandler targetEncodings[children.size()] = targetEncoding; isTexts[children.size()] = isText; if (!newNames[children.size()].endsWith("/")) newNames[children.size()] = newNames[children.size()] + "/"; //$NON-NLS-1$ //$NON-NLS-2$ - boolean returnCode = add(sources, virtualPath, newNames, sourceEncodings, targetEncodings, isTexts, archiveOperationMonitor); + add(sources, virtualPath, newNames, sourceEncodings, targetEncodings, isTexts, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); - return returnCode; } + } else { + throw new SystemLockTimeoutException(Activator.PLUGIN_ID); } } catch (Exception e) @@ -2885,8 +2844,6 @@ public class SystemZipHandler implements ISystemArchiveHandler { releaseMutex(mutexLockStatus); } - - return false; } /** @@ -2911,7 +2868,7 @@ public class SystemZipHandler implements ISystemArchiveHandler private void releaseMutex(int mutexLockStatus) { - //We only release the mutex if we aquired it, not borrowed it. + //We only release the mutex if we acquired it, not borrowed it. if (SystemReentrantMutex.LOCK_STATUS_AQUIRED == mutexLockStatus) { _mutex.release(); @@ -2920,7 +2877,7 @@ public class SystemZipHandler implements ISystemArchiveHandler private void setArchiveOperationMonitorStatusDone(ISystemOperationMonitor archiveOperationMonitor) { - //We only set the status of the archive operation montor to done if it is not been cancelled. + //We only set the status of the archive operation monitor to done if it is not been cancelled. if (null != archiveOperationMonitor && !archiveOperationMonitor.isCancelled()) { archiveOperationMonitor.setDone(true); diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/VirtualChild.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/VirtualChild.java index 2b43108f008..3b331492087 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/VirtualChild.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/VirtualChild.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2007 IBM Corporation and others. + * Copyright (c) 2003, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,14 +7,15 @@ * * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer - * component that contains this file: David McKnight, Kushal Munir, - * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * component that contains this file: David McKnight, 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. * Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread - * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations + * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancellation of archive operations + * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers *******************************************************************************/ package org.eclipse.rse.services.clientserver.archiveutils; @@ -22,13 +23,18 @@ package org.eclipse.rse.services.clientserver.archiveutils; import java.io.File; import java.io.IOException; +import org.eclipse.rse.internal.services.Activator; import org.eclipse.rse.services.clientserver.ISystemOperationMonitor; import org.eclipse.rse.services.clientserver.SystemEncodingUtil; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.services.clientserver.messages.SystemOperationFailedException; +import org.eclipse.rse.services.clientserver.messages.SystemUnexpectedErrorException; /** - * @author mjberger * A simple structure for passing information about virtual files and folders. + * + * @author mjberger */ public final class VirtualChild { @@ -39,7 +45,7 @@ public final class VirtualChild { protected ISystemArchiveHandler _handler; protected File _extractedFile; protected File _containingArchive; - + private String comment; private long compressedSize; private String compressionMethod; @@ -50,8 +56,8 @@ public final class VirtualChild { * Constructs a new VirtualChild given a reference to its parent archive's * handler, but does not populate any fields in the child. Clients must * populate the fullName, name, path, and isDirectory fields. - */ - public VirtualChild(ISystemArchiveHandler handler) + */ + public VirtualChild(ISystemArchiveHandler handler) { fullName = ""; //$NON-NLS-1$ name = ""; //$NON-NLS-1$ @@ -60,14 +66,14 @@ public final class VirtualChild { _handler = handler; _extractedFile = null; _containingArchive = null; - + comment = ""; //$NON-NLS-1$ compressedSize = -1; compressionMethod = ""; //$NON-NLS-1$ size = -1; - timeStamp = -1; + timeStamp = -1; } - + /** * Constructs a new VirtualChild given a reference to its parent archive's * handler (handler), and immediately populates the name and path info @@ -79,9 +85,9 @@ public final class VirtualChild { this(handler); renameTo(fullVirtualName); } - + /** - * Constructs a new VirtualChild given the name of its parent archive, + * Constructs a new VirtualChild given the name of its parent archive, * and immediately populates the name and path info * for the VirtualChild given its fullVirtualName. Clients * must still populate the isDirectory field. @@ -94,7 +100,7 @@ public final class VirtualChild { renameTo(fullVirtualName); _containingArchive = containingArchive; } - + /** * @return This VirtualChild's parent archive's Handler. */ @@ -102,7 +108,7 @@ public final class VirtualChild { { return _handler; } - + /** * @return This VirtualChild's time stamp (retrieves the latest one * from the archive). @@ -115,15 +121,15 @@ public final class VirtualChild { */ return timeStamp; } - + /** * @param value the time stamp value */ - public void setTimeStamp(long value) + public void setTimeStamp(long value) { timeStamp = value; } - + /** * @return This VirtualChild's uncompressed size (retrieves the latest one * from the archive). @@ -136,19 +142,19 @@ public final class VirtualChild { */ return size; } - + /** * @param value the size value */ - public void setSize(long value) + public void setSize(long value) { size = value; } - + /** * @return The comment associated with this VirtualChild. */ - public String getComment() + public String getComment() { /* if (_handler == null) return ""; //$NON-NLS-1$ @@ -156,11 +162,11 @@ public final class VirtualChild { */ return comment; } - + /** * @param value the comment value */ - public void setComment(String value) + public void setComment(String value) { if (null != value) { @@ -176,7 +182,7 @@ public final class VirtualChild { * @return The amount of space this VirtualChild takes up in the archive * in compressed form. */ - public long getCompressedSize() + public long getCompressedSize() { /* if (_handler == null) return 0; @@ -184,11 +190,11 @@ public final class VirtualChild { */ return compressedSize; } - + /** * @param value the compressedSize value */ - public void setCompressedSize(long value) + public void setCompressedSize(long value) { compressedSize = value; } @@ -196,7 +202,7 @@ public final class VirtualChild { /** * @return The method used to compress this VirtualChild. */ - public String getCompressionMethod() + public String getCompressionMethod() { /* if (_handler == null) return ""; //$NON-NLS-1$ @@ -208,7 +214,7 @@ public final class VirtualChild { /** * @param value the compression method value */ - public void setCompressionMethod(String value) + public void setCompressionMethod(String value) { if (null != value) { @@ -219,12 +225,12 @@ public final class VirtualChild { compressionMethod = ""; //$NON-NLS-1$ } } - + /** * @return The actual minus compressed size of this VirtualChild, divided * by the actual size. */ - public double getCompressionRatio() + public double getCompressionRatio() { /* if (getSize() == 0) @@ -241,29 +247,29 @@ public final class VirtualChild { { return 1; } - + return ((double)size - (double)compressedSize) / size; } - + /** * @return The extracted file or directory represented by this VirtualChild from the archive. - * Note that the extracted file is cached after it is extracted once, but if the + * Note that the extracted file is cached after it is extracted once, but if the * timestamps on the cached and archived files do not match, the cached file is erased, * and reextracted from the archive. */ - public File getExtractedFile() + public File getExtractedFile() throws SystemMessageException { return getExtractedFile(SystemEncodingUtil.ENCODING_UTF_8, false, null); } - + /** * @return The extracted file or directory represented by this VirtualChild from the archive. * Assumes that the file has been encoded in the encoding specified. - * Note that the extracted file is cached after it is extracted once, but if the + * Note that the extracted file is cached after it is extracted once, but if the * timestamps on the cached and archived files do not match, the cached file is erased, * and reextracted from the archive. */ - public File getExtractedFile(String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) + public File getExtractedFile(String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { File returnedFile = null; if (_extractedFile == null || _extractedFile.lastModified() != getTimeStamp()) @@ -307,11 +313,10 @@ public final class VirtualChild { } catch (IOException e) { - System.out.println("VirtualChild.getExtractedFile(): "); //$NON-NLS-1$ - System.out.println(e.getMessage()); + throw new SystemOperationFailedException(Activator.PLUGIN_ID, "VirtualChild.getExtractedFile()", e); //$NON-NLS-1$ } } - + if (isDirectory) { returnedFile = new File(_extractedFile, name); @@ -320,77 +325,80 @@ public final class VirtualChild { { returnedFile = _extractedFile; } - + //We only set the status of the archive operation montor to done if it is not been cancelled. if (null != archiveOperationMonitor && !archiveOperationMonitor.isCancelled()) { archiveOperationMonitor.setDone(true); } - + return returnedFile; } /** - * Gets the extracted file or directory represented by this VirtualChild from the archive, - * and replaces the object referred to by destination with that extracted file or directory. - * Note that the extracted file is cached after it is extracted once, but if the - * timestamps on the cached and archived files do not match, the cached file is erased, - * and reextracted from the archive. - * destination is always overwritten with either what is cached, or - * what is in the archive. - * @return true if and only if the extraction succeeded. + * Gets the extracted file or directory represented by this VirtualChild + * from the archive, and replaces the object referred to by + * destination with that extracted file or directory. Note that + * the extracted file is cached after it is extracted once, but if the + * timestamps on the cached and archived files do not match, the cached file + * is erased, and reextracted from the archive. destination is + * always overwritten with either what is cached, or what is in the archive. + * + * @throws SystemMessageException in case of an error */ - public boolean getExtractedFile(File destination, ISystemOperationMonitor archiveOperationMonitor) + public void getExtractedFile(File destination, ISystemOperationMonitor archiveOperationMonitor) throws SystemMessageException { - return getExtractedFile(destination, SystemEncodingUtil.ENCODING_UTF_8, false, archiveOperationMonitor); + getExtractedFile(destination, SystemEncodingUtil.ENCODING_UTF_8, false, archiveOperationMonitor); } - + + /** - * Gets the extracted file or directory represented by this VirtualChild from the archive, - * and replaces the object referred to by destination with that extracted file or directory. - * Note that the extracted file is cached after it is extracted once, but if the - * timestamps on the cached and archived files do not match, the cached file is erased, - * and reextracted from the archive. - * destination is always overwritten with either what is cached, or - * what is in the archive. - * @return true if and only if the extraction succeeded. + * Gets the extracted file or directory represented by this VirtualChild + * from the archive, and replaces the object referred to by + * destination with that extracted file or directory. Note that + * the extracted file is cached after it is extracted once, but if the + * timestamps on the cached and archived files do not match, the cached file + * is erased, and reextracted from the archive. destination is + * always overwritten with either what is cached, or what is in the archive. + * + * @throws SystemMessageException in case of an error */ - public boolean getExtractedFile(File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) + public void getExtractedFile(File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) + throws SystemMessageException { - boolean success = true; - if (_handler == null) return false; - if (_extractedFile == null || + if (_handler == null) + throw new SystemUnexpectedErrorException(Activator.PLUGIN_ID); + if (_extractedFile == null || _extractedFile.lastModified() != getTimeStamp() || !destination.getAbsolutePath().equals(_extractedFile.getAbsolutePath()) ) { if (isDirectory) { - success = _handler.extractVirtualDirectory(fullName, destination.getParentFile(), destination, sourceEncoding, isText, archiveOperationMonitor); + _handler.extractVirtualDirectory(fullName, destination.getParentFile(), destination, sourceEncoding, isText, archiveOperationMonitor); } else { - success = _handler.extractVirtualFile(fullName, destination, sourceEncoding, isText, archiveOperationMonitor); + _handler.extractVirtualFile(fullName, destination, sourceEncoding, isText, archiveOperationMonitor); } _extractedFile = destination; } - //We only set the status of the archive operation montor to done if it is not been cancelled. + //We only set the status of the archive operation monitor to done if it is not been cancelled. if (null != archiveOperationMonitor && !archiveOperationMonitor.isCancelled()) { archiveOperationMonitor.setDone(true); } - return success; } - + /** * @return Whether or not this VirtualChild exists in the archive. */ - public boolean exists() + public boolean exists() throws SystemMessageException { if (_handler == null) return false; return _handler.exists(fullName, null); } - + /** * Renames this virtual child to newName. WARNING!! * This method does not change the underlying zip file, @@ -414,9 +422,9 @@ public final class VirtualChild { } // force reextraction of temp file _extractedFile = null; - + } - + /** * @return The "standard" name for this VirtualChild, based on * the handler type. @@ -426,12 +434,12 @@ public final class VirtualChild { if (_handler == null) return fullName; return _handler.getStandardName(this); } - + public File getContainingArchive() { if (_handler == null) return _containingArchive; return _handler.getArchive(); } - - + + }