diff --git a/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/FileBrowser.java b/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/FileBrowser.java index b30daa52d..d804fb257 100644 --- a/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/FileBrowser.java +++ b/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/FileBrowser.java @@ -55,24 +55,4 @@ public interface FileBrowser { */ public ArrayList getFileList(); - /** - * This method returns the list of files and their relative paths to the passed - * argument topDirectory. The argument should be the top-most directory that one - * wants to search through. - * - * @param topDirectory - * @return - */ - public abstract ArrayList listFiles(final String topDirectory); - - /** - * This method returns the list of directories and their relative paths to the - * passed argument topDirectory. The argument should be the top-most directory - * that one wants to search through. - * - * @param topDirectory - * @return - */ - public abstract ArrayList listDirectories(final String topDirectory); - } diff --git a/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/FileHandler.java b/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/FileHandler.java index 0a071f6d2..05844be0a 100644 --- a/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/FileHandler.java +++ b/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/FileHandler.java @@ -179,7 +179,7 @@ public CommandStatus copy(final String source, final String destination) { * See {@link org.eclipse.ice.commands.IFileHandler#getFileBrowser()} */ @Override - public abstract FileBrowser getFileBrowser(); + public abstract FileBrowser getFileBrowser(final String topDirectory); /** * This function gets and returns the private member variable command of type diff --git a/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/IFileHandler.java b/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/IFileHandler.java index 553194db7..20c0b09b1 100644 --- a/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/IFileHandler.java +++ b/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/IFileHandler.java @@ -12,7 +12,7 @@ package org.eclipse.ice.commands; import java.io.IOException; - +import org.eclipse.ice.commands.FileBrowser; /** * This interface defines and lays out the design for the FileHandler structures * responsible for moving and/or copying files to and from destinations. @@ -69,7 +69,8 @@ public interface IFileHandler { * Method that returns a FileBrowser instance * * @return - FileBrowser + * @param - Directory to browse */ - public abstract FileBrowser getFileBrowser(); + public abstract FileBrowser getFileBrowser(final String topDirectory); } diff --git a/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/LocalFileBrowser.java b/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/LocalFileBrowser.java index 61b55a060..a649ecd0b 100644 --- a/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/LocalFileBrowser.java +++ b/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/LocalFileBrowser.java @@ -36,8 +36,20 @@ public LocalFileBrowser() { fileList.clear(); directoryList.clear(); } + + /** + * Default constructor with a given path to fill the ArrayLists + */ + public LocalFileBrowser(final String topDirectory) { + // Make sure we are starting with a fresh file/directory list + fileList.clear(); + directoryList.clear(); + // Execute the file walking logic, which fills the arrays + walkTree(topDirectory); + + } - // Add the file path tp fileList + // Add the file path to fileList @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attr) { // Add the file, depending on it's attribute @@ -86,39 +98,13 @@ public ArrayList getDirectoryList() { return directoryList; } - /** - * See {@link org.eclipse.ice.commands.IFileHandler#listFiles(String)} - */ - @Override - public ArrayList listFiles(String topDirectory) { - logger.info("Searching " + topDirectory); - // Execute the file walking logic - walkTree(topDirectory); - - // Return the resulting file list hash map - return getFileList(); - } - - /** - * See {@link org.eclipse.ice.commands.IFileHandler#listDirectories(String)} - */ - @Override - public ArrayList listDirectories(String topDirectory) { - logger.info("Searching " + topDirectory); - // Executes the file walking logic - walkTree(topDirectory); - - // Return the resulting directory array list - return getDirectoryList(); - } - /** * This function performs the action of walking the file tree for the file * browsing capabilities of LocalFileHandler. It returns a LocalFileWalker so * that the files or directories could be obtained * */ - private void walkTree(String topDirectory) { + private void walkTree(final String topDirectory) { // Make a path variable of the topDirectory Path topPath = Paths.get(topDirectory); diff --git a/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/LocalFileHandler.java b/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/LocalFileHandler.java index 645cf2db0..cf3d6449e 100644 --- a/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/LocalFileHandler.java +++ b/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/LocalFileHandler.java @@ -91,8 +91,8 @@ public void checkExistence(final String source, final String destination) throws * See {@link org.eclipse.ice.commands.IFileHandler#getFileBrowser()} */ @Override - public FileBrowser getFileBrowser() { - LocalFileBrowser browser = new LocalFileBrowser(); + public FileBrowser getFileBrowser(final String topDirectory) { + LocalFileBrowser browser = new LocalFileBrowser(topDirectory); return browser; } diff --git a/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/RemoteFileBrowser.java b/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/RemoteFileBrowser.java index 474e73f71..8413447ad 100644 --- a/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/RemoteFileBrowser.java +++ b/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/RemoteFileBrowser.java @@ -32,13 +32,25 @@ public class RemoteFileBrowser implements FileBrowser { private Connection connection; /** - * Default constructor + * Default constructor */ - public RemoteFileBrowser(Connection connection) { - // Make sure we start with a fresh list everytime the walker is called + public RemoteFileBrowser() { + fileList.clear(); + directoryList.clear(); + this.connection = null; + } + + /** + * Default constructor with connection and top directory name + */ + public RemoteFileBrowser(Connection connection, final String topDirectory) { + // Make sure we start with a fresh list every time the browser is called fileList.clear(); directoryList.clear(); this.connection = connection; + + // Fill the arrays with the relevant file information + fillArrays(topDirectory, connection.getSftpChannel()); } /** @@ -105,24 +117,4 @@ public ArrayList getFileList() { return fileList; } - /** - * See {@link org.eclipse.ice.commands.FileBrowser#listFiles(String)} - */ - @Override - public ArrayList listFiles(final String topDirectory) { - fillArrays(topDirectory, connection.getSftpChannel()); - - return getFileList(); - } - - /** - * See {@link org.eclipse.ice.commands.FileBrowser#listDirectories(String)} - */ - @Override - public ArrayList listDirectories(final String topDirectory) { - fillArrays(topDirectory, connection.getSftpChannel()); - - return getDirectoryList(); - } - } diff --git a/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/RemoteFileHandler.java b/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/RemoteFileHandler.java index 4c359f75d..22a95098d 100644 --- a/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/RemoteFileHandler.java +++ b/org.eclipse.ice.commands/src/main/java/org/eclipse/ice/commands/RemoteFileHandler.java @@ -327,8 +327,8 @@ public void setPermissions(String permissions) { * See {@link org.eclipse.ice.commands.IFileHandler#getFileBrowser()} */ @Override - public FileBrowser getFileBrowser() { - RemoteFileBrowser browser = new RemoteFileBrowser(connection.get()); + public FileBrowser getFileBrowser(final String topDirectory) { + RemoteFileBrowser browser = new RemoteFileBrowser(connection.get(), topDirectory); return browser; } diff --git a/org.eclipse.ice.commands/src/test/java/org/eclipse/ice/tests/commands/LocalFileBrowserTest.java b/org.eclipse.ice.commands/src/test/java/org/eclipse/ice/tests/commands/LocalFileBrowserTest.java index a44ba7b29..8fd70ad77 100644 --- a/org.eclipse.ice.commands/src/test/java/org/eclipse/ice/tests/commands/LocalFileBrowserTest.java +++ b/org.eclipse.ice.commands/src/test/java/org/eclipse/ice/tests/commands/LocalFileBrowserTest.java @@ -37,34 +37,6 @@ */ public class LocalFileBrowserTest { - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception { - } - /** * Function to execute the local file browsing and local directory browsing * test. We call one main function so that a file structur can be created at the @@ -91,10 +63,11 @@ public void testLocalBrowsing() throws IOException { * @throws IOException */ public void testLocalFileBrowsing(Path topPath) throws IOException { - LocalFileBrowser browser = new LocalFileBrowser(); + LocalFileBrowser browser = new LocalFileBrowser(topPath.toString()); + // Get a file handler for existence checks LocalFileHandler handler = new LocalFileHandler(); - ArrayList files = browser.listFiles(topPath.toString()); + ArrayList files = browser.getFileList(); // four files were created assert (files.size() == 4); @@ -118,9 +91,9 @@ public void testLocalFileBrowsing(Path topPath) throws IOException { */ public void testLocalDirectoryBrowsing(Path topPath) throws IOException { LocalFileHandler handler = new LocalFileHandler(); - LocalFileBrowser browser = new LocalFileBrowser(); + LocalFileBrowser browser = new LocalFileBrowser(topPath.toString()); - ArrayList files = browser.listDirectories(topPath.toString()); + ArrayList files = browser.getDirectoryList(); for (int i = 0; i < files.size(); i++) { System.out.println(files.get(i)); } diff --git a/org.eclipse.ice.commands/src/test/java/org/eclipse/ice/tests/commands/RemoteFileBrowserTest.java b/org.eclipse.ice.commands/src/test/java/org/eclipse/ice/tests/commands/RemoteFileBrowserTest.java index ba0db78f2..1cab312c7 100644 --- a/org.eclipse.ice.commands/src/test/java/org/eclipse/ice/tests/commands/RemoteFileBrowserTest.java +++ b/org.eclipse.ice.commands/src/test/java/org/eclipse/ice/tests/commands/RemoteFileBrowserTest.java @@ -75,7 +75,6 @@ public static void setUpBeforeClass() throws Exception { } /** -<<<<<<< HEAD * @throws java.lang.Exception */ @AfterClass @@ -84,22 +83,6 @@ public static void tearDownAfterClass() throws Exception { } /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception { - } - - /** -======= ->>>>>>> 354a0ec8cad995c7e88a1f5ace79c97b811f1381 * Function to execute the remote file browsing and remote directory browsing * test. We call one main function so that a file structure can be created at * the beginning of the test, accessed by both "subtests", and then deleted at @@ -137,11 +120,11 @@ public void testRemoteBrowsing() throws Exception { public void testRemoteFileBrowsing(String topDirectory) throws IOException, SftpException { RemoteFileHandler handler = new RemoteFileHandler(); - RemoteFileBrowser browser = new RemoteFileBrowser(fileTransferConn); + RemoteFileBrowser browser = new RemoteFileBrowser(fileTransferConn, topDirectory); handler.setConnectionConfiguration(fileTransferConn.getConfiguration()); - ArrayList files = browser.listFiles(topDirectory); + ArrayList files = browser.getFileList(); // files should only be 4 entries since there are only 4 files in the tree // structure we created @@ -171,9 +154,9 @@ public void testRemoteDirectoryBrowsing(String topDirectory) throws IOException, RemoteFileHandler handler = new RemoteFileHandler(); handler.setConnectionConfiguration(fileTransferConn.getConfiguration()); - RemoteFileBrowser browser = new RemoteFileBrowser(fileTransferConn); + RemoteFileBrowser browser = new RemoteFileBrowser(fileTransferConn, topDirectory); - ArrayList files = browser.listDirectories(topDirectory); + ArrayList files = browser.getDirectoryList(); // directories should only be 3 entries since there are only 3 directories in // the tree structure we created