diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/impl/RecursiveHardLinkMaker.java b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/impl/RecursiveHardLinkMaker.java index 09e24c014b42e7a9fef2bdef0e0bcde9c17ffd18..40eba97aa8b8b1345083472c236ba796d860dc4d 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/impl/RecursiveHardLinkMaker.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/impl/RecursiveHardLinkMaker.java @@ -24,7 +24,7 @@ import org.apache.log4j.Logger; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; -import ch.systemsx.cisd.common.utilities.CmdLineHelper; +import ch.systemsx.cisd.common.utilities.ProcessExecutionHelper; import ch.systemsx.cisd.common.utilities.OSUtilities; import ch.systemsx.cisd.datamover.filesystem.intf.IPathImmutableCopier; @@ -151,7 +151,7 @@ public class RecursiveHardLinkMaker implements IPathImmutableCopier assert file.isFile(); File destFile = new File(destDir, file.getName()); List<String> cmd = createLnCmdLine(file, destFile); - boolean ok = CmdLineHelper.run(cmd, operationLog, machineLog); + boolean ok = ProcessExecutionHelper.runAndLog(cmd, operationLog, machineLog); return ok ? destFile : null; } diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/remote/rsync/RsyncCopier.java b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/remote/rsync/RsyncCopier.java index 84036a276fdc87597af9a703c3570f0a9a41148b..826e9cda6ded5254653b1d2741056b32857a1ad8 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/remote/rsync/RsyncCopier.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/remote/rsync/RsyncCopier.java @@ -34,7 +34,7 @@ import ch.systemsx.cisd.common.exceptions.Status; import ch.systemsx.cisd.common.exceptions.StatusFlag; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; -import ch.systemsx.cisd.common.utilities.CmdLineHelper; +import ch.systemsx.cisd.common.utilities.ProcessExecutionHelper; import ch.systemsx.cisd.common.utilities.FileUtilities; import ch.systemsx.cisd.common.utilities.OSUtilities; import ch.systemsx.cisd.datamover.filesystem.intf.IPathCopier; @@ -147,7 +147,7 @@ public class RsyncCopier implements IPathCopier copyProcessReference.set(copyProcess); final int exitValue = copyProcess.waitFor(); - logRsyncExitValue(exitValue, copyProcess); + logRsyncExitValue(copyProcess); return createStatus(exitValue); } catch (IOException e) { @@ -173,7 +173,7 @@ public class RsyncCopier implements IPathCopier return "path '" + path.getAbsolutePath() + "' does not exist"; } } - + private List<String> createCommandLine(File sourcePath, String sourceHost, File destinationDirectory, String destinationHost) { @@ -249,7 +249,7 @@ public class RsyncCopier implements IPathCopier private static Status createStatus(final int exitValue) { - if (CmdLineHelper.processTerminated(exitValue)) + if (ProcessExecutionHelper.isProcessTerminated(exitValue)) { return TERMINATED_STATUS; } @@ -261,9 +261,12 @@ public class RsyncCopier implements IPathCopier return new Status(flag, RsyncExitValueTranslator.getMessage(exitValue)); } - private static void logRsyncExitValue(final int exitValue, final Process copyProcess) + private static void logRsyncExitValue(final Process copyProcess) { - CmdLineHelper.logProcessExitValue(exitValue, copyProcess, "rsync", operationLog, machineLog); + final int exitValue = copyProcess.exitValue(); + final List<String> processOutput = + ProcessExecutionHelper.readProcessOutputLines(copyProcess, machineLog); + ProcessExecutionHelper.logProcessExecution("rsync", exitValue, processOutput, operationLog, machineLog); } /** @@ -339,7 +342,7 @@ public class RsyncCopier implements IPathCopier final Timer watchDogTimer = initWatchDog(listProcess); final int exitValue = listProcess.waitFor(); watchDogTimer.cancel(); - logRsyncExitValue(exitValue, listProcess); + logRsyncExitValue(listProcess); return Status.OK == createStatus(exitValue); } catch (IOException ex) { diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/remote/rsync/RsyncVersionChecker.java b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/remote/rsync/RsyncVersionChecker.java index 7cd888e0edb3be486ab6ede0369a2930c3816807..dcc56a153cd6cde317f3f3c2d9c90d18637fdce5 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/remote/rsync/RsyncVersionChecker.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/remote/rsync/RsyncVersionChecker.java @@ -16,17 +16,13 @@ package ch.systemsx.cisd.datamover.filesystem.remote.rsync; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.Timer; -import java.util.TimerTask; +import java.util.Arrays; import org.apache.log4j.Logger; -import ch.systemsx.cisd.common.exceptions.CheckedExceptionTunnel; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; +import ch.systemsx.cisd.common.utilities.ProcessExecutionHelper; /** * A class that helps checking an <code>rsync</code> binary for its version. @@ -36,12 +32,12 @@ import ch.systemsx.cisd.common.logging.LogFactory; final class RsyncVersionChecker { + private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, RsyncVersionChecker.class); + private static final Logger machineLog = LogFactory.getLogger(LogCategory.MACHINE, RsyncVersionChecker.class); /** * The class holding the version information about an <code>rsync</code> binary. - * - * @author bernd */ static class RsyncVersion { @@ -138,53 +134,13 @@ final class RsyncVersionChecker private static String getRsyncVersion(String rsyncExecutableToCheck) { - BufferedReader reader = null; - try - { - final Process process = new ProcessBuilder(rsyncExecutableToCheck, "--version").start(); - if (machineLog.isDebugEnabled()) - { - machineLog.debug("Waiting for rsync process to finish."); - } - final long TIME_TO_WAIT_FOR_COMPLETION = 2 * 1000; - final Timer watchDog = new Timer("Rsync Watch Dog"); - watchDog.schedule(new TimerTask() - { - @Override - public void run() - { - process.destroy(); - } - }, TIME_TO_WAIT_FOR_COMPLETION); - final int exitValue = process.waitFor(); - watchDog.cancel(); - if (machineLog.isDebugEnabled()) - { - machineLog.debug(String.format("Rsync process finished with exit value %s", exitValue)); - } - reader = new BufferedReader(new InputStreamReader(process.getInputStream())); - final String versionString = extractRsyncVersion(reader.readLine()); - return versionString; - } catch (IOException e) - { - return null; - } catch (InterruptedException e) - { - // This should never happen. - throw new CheckedExceptionTunnel(e); - } finally - { - if (reader != null) - { - try - { - reader.close(); - } catch (IOException e) - { - // Ignore. - } - } - } + final long TIME_TO_WAIT_FOR_COMPLETION = 2 * 1000; + final ProcessExecutionHelper.ProcessResult result = + ProcessExecutionHelper.run(Arrays.asList(rsyncExecutableToCheck, "--version"), + TIME_TO_WAIT_FOR_COMPLETION, operationLog, machineLog); + result.log(); + final String versionString = extractRsyncVersion(result.getProcessOutput().get(0)); + return versionString; } private static String extractRsyncVersion(String rsyncVersionLine)