From 6cc4b63b815ff73bb46a6e80c0e664a52e3a0121 Mon Sep 17 00:00:00 2001
From: ribeaudc <ribeaudc>
Date: Mon, 26 May 2008 06:40:13 +0000
Subject: [PATCH] change: - Extract private method 'findExecutable'.

SVN: 6298
---
 .../filesystem/FileSysOperationsFactory.java  | 46 +++++++------------
 1 file changed, 16 insertions(+), 30 deletions(-)

diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/FileSysOperationsFactory.java b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/FileSysOperationsFactory.java
index 035659cc50f..a3a752a1fed 100644
--- a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/FileSysOperationsFactory.java
+++ b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/FileSysOperationsFactory.java
@@ -57,25 +57,23 @@ public class FileSysOperationsFactory implements IFileSysOperationsFactory
         this.parameters = parameters;
     }
 
-    private final static File findRsyncExecutable(final String rsyncExecutablePath)
+    private final static File findExecutable(final String executablePath,
+            final String executableName)
     {
-        final File rsyncExecutable;
-        if (rsyncExecutablePath != null)
+        final File executableFile;
+        if (StringUtils.isNotBlank(executablePath))
         {
-            rsyncExecutable = new File(rsyncExecutablePath);
-        } else if (OSUtilities.isWindows() == false)
-        {
-            rsyncExecutable = OSUtilities.findExecutable("rsync");
+            executableFile = new File(executablePath);
         } else
         {
-            rsyncExecutable = null;
+            executableFile = OSUtilities.findExecutable(executableName);
         }
-        if (rsyncExecutable != null && OSUtilities.executableExists(rsyncExecutable) == false)
+        if (executableFile != null && OSUtilities.executableExists(executableFile) == false)
         {
-            throw ConfigurationFailureException.fromTemplate("Cannot find rsync executable '%s'.",
-                    rsyncExecutable.getAbsoluteFile());
+            throw ConfigurationFailureException.fromTemplate("Cannot find executable '%s'.",
+                    executableFile.getAbsoluteFile());
         }
-        return rsyncExecutable;
+        return executableFile;
     }
 
     private final IPathImmutableCopier createFakedImmCopier()
@@ -110,7 +108,8 @@ public class FileSysOperationsFactory implements IFileSysOperationsFactory
 
     public final IPathRemover getRemover()
     {
-        return new RetryingPathRemover(MAX_RETRIES_ON_FAILURE, Constants.MILLIS_TO_SLEEP_BEFORE_RETRYING);
+        return new RetryingPathRemover(MAX_RETRIES_ON_FAILURE,
+                Constants.MILLIS_TO_SLEEP_BEFORE_RETRYING);
     }
 
     public final IPathImmutableCopier getImmutableCopier()
@@ -135,7 +134,7 @@ public class FileSysOperationsFactory implements IFileSysOperationsFactory
 
     public final IPathCopier getCopier(final boolean requiresDeletionBeforeCreation)
     {
-        final File rsyncExecutable = findRsyncExecutable(parameters.getRsyncExecutable());
+        final File rsyncExecutable = findExecutable(parameters.getRsyncExecutable(), "rsync");
         final File sshExecutable = tryFindSshExecutable();
         if (rsyncExecutable != null)
         {
@@ -149,25 +148,12 @@ public class FileSysOperationsFactory implements IFileSysOperationsFactory
 
     public final File tryFindSshExecutable()
     {
-        final String sshExecutablePath = parameters.getSshExecutable();
-        File sshExecutable = null;
-        if (StringUtils.isNotBlank(sshExecutablePath))
-        {
-            sshExecutable = new File(sshExecutablePath);
-        } else
-        {
-            sshExecutable = OSUtilities.findExecutable("ssh");
-        }
-        if (sshExecutable != null && OSUtilities.executableExists(sshExecutable) == false)
-        {
-            throw ConfigurationFailureException.fromTemplate("Cannot find ssh executable '%s'.",
-                    sshExecutable.getAbsoluteFile());
-        }
-        return sshExecutable;
+        return findExecutable(parameters.getSshExecutable(), "ssh");
     }
 
     public final IPathMover getMover()
     {
-        return new RetryingPathMover(MAX_RETRIES_ON_FAILURE, Constants.MILLIS_TO_SLEEP_BEFORE_RETRYING);
+        return new RetryingPathMover(MAX_RETRIES_ON_FAILURE,
+                Constants.MILLIS_TO_SLEEP_BEFORE_RETRYING);
     }
 }
-- 
GitLab