diff --git a/core/src/main/groovy/noe/common/utils/Cmd.groovy b/core/src/main/groovy/noe/common/utils/Cmd.groovy index a5e28f7d..2d791149 100644 --- a/core/src/main/groovy/noe/common/utils/Cmd.groovy +++ b/core/src/main/groovy/noe/common/utils/Cmd.groovy @@ -240,8 +240,23 @@ public class Cmd { * * @deprecated args */ - public static int executeCommand(command, File targetDir, Map args = null, Map tmpProps = null) { - return executeCommandRedirectIO(command, targetDir, null, System.out, System.err, args, tmpProps) + static int executeCommand(command, File targetDir, Map args = null, Map tmpProps = null) { + + if (command instanceof String || command instanceof GString) { + if (command.length() > 2 && command[0] == "[" && command[command.length() - 1] == "]") { + command = command[1..command.length() - 2] + } + command = command.tokenize(", ") + } + + Map rv = executeCommandConsumeStreams(command as List, targetDir, null, 60000L, tmpProps) + if (!rv.stdOut.isEmpty()) { + log.info(rv.stdOut) + } + if (!rv.stdErr.isEmpty()) { + log.trace(rv.stdErr) + } + return rv.exitValue } /** diff --git a/core/src/main/groovy/noe/common/utils/JBFile.groovy b/core/src/main/groovy/noe/common/utils/JBFile.groovy index c6423cc8..3af844c7 100644 --- a/core/src/main/groovy/noe/common/utils/JBFile.groovy +++ b/core/src/main/groovy/noe/common/utils/JBFile.groovy @@ -5,6 +5,8 @@ import noe.common.Constants import noe.common.DefaultProperties import org.apache.commons.io.FileUtils +import java.nio.file.Files +import java.nio.file.Path import java.util.concurrent.TimeUnit /** @@ -186,21 +188,21 @@ class JBFile { } def returnValue = 0 - try { - // try to copy with ant - ant.copy(file: src.getAbsolutePath(), tofile: dest.getAbsolutePath(), overwrite: "true") - } catch (e) { - // Try it with sudo rights - if (!platform.isWindows()) { - def args = (preserveRights) ? '-p' : '' - args += (dereference) ? ' -L' : '' - if (useAdminPrivileges) { - returnValue += Cmd.executeSudoCommand("cp -r ${args} ${src.absolutePath} ${dest}", new File('.')) - } else { - returnValue += Cmd.executeCommand("cp -r ${args} ${src.absolutePath} ${dest}", new File('.')) - } + if (platform.isWindows()) { + try { + log.info("Copying ${src.absolutePath} to ${dest.absolutePath}") + dest << src.text + } catch (e) { + log.trace("JBFIle.copyFile failed", e) + returnValue = 2 + } + } else { + def args = (preserveRights) ? '-p' : '' + args += (dereference) ? ' -L' : '' + if (useAdminPrivileges) { + returnValue += Cmd.executeSudoCommand("cp -r ${args} ${src.absolutePath} ${dest}", new File('.')) } else { - returnValue = -1 + returnValue += Cmd.executeCommand("cp -r ${args} ${src.absolutePath} ${dest}", new File('.')) } } return returnValue == 0