Skip to content
Snippets Groups Projects
Commit 6cc4b63b authored by ribeaudc's avatar ribeaudc
Browse files

change: - Extract private method 'findExecutable'.

SVN: 6298
parent 9f95258e
No related branches found
No related tags found
No related merge requests found
...@@ -57,25 +57,23 @@ public class FileSysOperationsFactory implements IFileSysOperationsFactory ...@@ -57,25 +57,23 @@ public class FileSysOperationsFactory implements IFileSysOperationsFactory
this.parameters = parameters; 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; final File executableFile;
if (rsyncExecutablePath != null) if (StringUtils.isNotBlank(executablePath))
{ {
rsyncExecutable = new File(rsyncExecutablePath); executableFile = new File(executablePath);
} else if (OSUtilities.isWindows() == false)
{
rsyncExecutable = OSUtilities.findExecutable("rsync");
} else } 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'.", throw ConfigurationFailureException.fromTemplate("Cannot find executable '%s'.",
rsyncExecutable.getAbsoluteFile()); executableFile.getAbsoluteFile());
} }
return rsyncExecutable; return executableFile;
} }
private final IPathImmutableCopier createFakedImmCopier() private final IPathImmutableCopier createFakedImmCopier()
...@@ -110,7 +108,8 @@ public class FileSysOperationsFactory implements IFileSysOperationsFactory ...@@ -110,7 +108,8 @@ public class FileSysOperationsFactory implements IFileSysOperationsFactory
public final IPathRemover getRemover() 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() public final IPathImmutableCopier getImmutableCopier()
...@@ -135,7 +134,7 @@ public class FileSysOperationsFactory implements IFileSysOperationsFactory ...@@ -135,7 +134,7 @@ public class FileSysOperationsFactory implements IFileSysOperationsFactory
public final IPathCopier getCopier(final boolean requiresDeletionBeforeCreation) public final IPathCopier getCopier(final boolean requiresDeletionBeforeCreation)
{ {
final File rsyncExecutable = findRsyncExecutable(parameters.getRsyncExecutable()); final File rsyncExecutable = findExecutable(parameters.getRsyncExecutable(), "rsync");
final File sshExecutable = tryFindSshExecutable(); final File sshExecutable = tryFindSshExecutable();
if (rsyncExecutable != null) if (rsyncExecutable != null)
{ {
...@@ -149,25 +148,12 @@ public class FileSysOperationsFactory implements IFileSysOperationsFactory ...@@ -149,25 +148,12 @@ public class FileSysOperationsFactory implements IFileSysOperationsFactory
public final File tryFindSshExecutable() public final File tryFindSshExecutable()
{ {
final String sshExecutablePath = parameters.getSshExecutable(); return findExecutable(parameters.getSshExecutable(), "ssh");
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;
} }
public final IPathMover getMover() 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);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment