From 2c074065e50e2bbc6197e21a04ca0c704dce5e27 Mon Sep 17 00:00:00 2001 From: Paul Lodge Date: Thu, 22 May 2025 14:36:21 +0200 Subject: [PATCH 1/5] Moved copy errors to the trace --- .../main/groovy/noe/common/utils/Cmd.groovy | 19 +++++++++++++++++-- .../groovy/noe/server/ServerAbstract.groovy | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) 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/server/ServerAbstract.groovy b/core/src/main/groovy/noe/server/ServerAbstract.groovy index 7a90c0fc..52f3d064 100644 --- a/core/src/main/groovy/noe/server/ServerAbstract.groovy +++ b/core/src/main/groovy/noe/server/ServerAbstract.groovy @@ -32,7 +32,7 @@ abstract class ServerAbstract implements IApp { //TODO: EWS specific, pls remove. Boolean ignoreShutdownPort /// def start ///standard startup command (apachectl start) - def stop ///standard shutdown command (apachectl stop) + String stop ///standard shutdown command (apachectl stop) String binPath // relative path (server root) to dir where stop handler is stored List configDirs = [] // relative paths to dir where server config files are stored List logDirs = [] // relative paths to dir where server logs are stored From 530da832c6a6cbcdff4b98a0da80481d93649c4d Mon Sep 17 00:00:00 2001 From: Paul Lodge Date: Thu, 22 May 2025 15:40:59 +0200 Subject: [PATCH 2/5] Reduce reliance on ant for copying --- .../groovy/noe/common/utils/JBFile.groovy | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/core/src/main/groovy/noe/common/utils/JBFile.groovy b/core/src/main/groovy/noe/common/utils/JBFile.groovy index c6423cc8..fc6e573b 100644 --- a/core/src/main/groovy/noe/common/utils/JBFile.groovy +++ b/core/src/main/groovy/noe/common/utils/JBFile.groovy @@ -186,21 +186,31 @@ 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()) { + File absDest = src.isDirectory() ? new File(dest, src.name) : dest + def command = ["xcopy", "${src.absolutePath}", absDest.absolutePath, "/H", "/S", "/E", "/I", "/Y", "/C", "/F", "/R", "/K", "/X"] + returnValue = Cmd.executeCommand(command, new File('.')) + if (returnValue > 0) { + try { + // try to copy with ant + if (src.isDirectory()) { + ant.copy(todir: dest.getAbsolutePath(), overwrite: true) { fileset(dir: src.getAbsolutePath()) } + } else { + ant.copy(file: src.getAbsolutePath(), todir: dest.getAbsolutePath(), overwrite: "true") + } + returnValue = 0 + } catch (e) { + log.trace("JBFIle.copy with ant 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 From 9ece8f8777676d57ae1c90ba3b9c4c5d33e658c1 Mon Sep 17 00:00:00 2001 From: Paul Lodge Date: Thu, 20 Nov 2025 13:17:39 +0100 Subject: [PATCH 3/5] Removed the recursion into subdirs --- core/src/main/groovy/noe/common/utils/JBFile.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/groovy/noe/common/utils/JBFile.groovy b/core/src/main/groovy/noe/common/utils/JBFile.groovy index fc6e573b..6ba98ce9 100644 --- a/core/src/main/groovy/noe/common/utils/JBFile.groovy +++ b/core/src/main/groovy/noe/common/utils/JBFile.groovy @@ -188,7 +188,7 @@ class JBFile { def returnValue = 0 if (platform.isWindows()) { File absDest = src.isDirectory() ? new File(dest, src.name) : dest - def command = ["xcopy", "${src.absolutePath}", absDest.absolutePath, "/H", "/S", "/E", "/I", "/Y", "/C", "/F", "/R", "/K", "/X"] + def command = ["xcopy", "${src.absolutePath}", absDest.absolutePath, "/H", "/E", "/I", "/Y", "/C", "/F", "/R", "/K", "/X"] returnValue = Cmd.executeCommand(command, new File('.')) if (returnValue > 0) { try { From c1d9576bfc2c19687d8d775d7cd7a36af16ce832 Mon Sep 17 00:00:00 2001 From: Paul Lodge Date: Wed, 3 Dec 2025 09:43:35 +0100 Subject: [PATCH 4/5] Reverted type on stop command --- core/src/main/groovy/noe/server/ServerAbstract.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/groovy/noe/server/ServerAbstract.groovy b/core/src/main/groovy/noe/server/ServerAbstract.groovy index 52f3d064..7a90c0fc 100644 --- a/core/src/main/groovy/noe/server/ServerAbstract.groovy +++ b/core/src/main/groovy/noe/server/ServerAbstract.groovy @@ -32,7 +32,7 @@ abstract class ServerAbstract implements IApp { //TODO: EWS specific, pls remove. Boolean ignoreShutdownPort /// def start ///standard startup command (apachectl start) - String stop ///standard shutdown command (apachectl stop) + def stop ///standard shutdown command (apachectl stop) String binPath // relative path (server root) to dir where stop handler is stored List configDirs = [] // relative paths to dir where server config files are stored List logDirs = [] // relative paths to dir where server logs are stored From 7870065cc70fd7cb0d3504dfa8a33e4aac88d217 Mon Sep 17 00:00:00 2001 From: Paul Lodge Date: Wed, 3 Dec 2025 17:06:04 +0100 Subject: [PATCH 5/5] Corrected issue using xcopy and replaced it with a native groovy file copy --- .../groovy/noe/common/utils/JBFile.groovy | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/core/src/main/groovy/noe/common/utils/JBFile.groovy b/core/src/main/groovy/noe/common/utils/JBFile.groovy index 6ba98ce9..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 /** @@ -187,22 +189,12 @@ class JBFile { def returnValue = 0 if (platform.isWindows()) { - File absDest = src.isDirectory() ? new File(dest, src.name) : dest - def command = ["xcopy", "${src.absolutePath}", absDest.absolutePath, "/H", "/E", "/I", "/Y", "/C", "/F", "/R", "/K", "/X"] - returnValue = Cmd.executeCommand(command, new File('.')) - if (returnValue > 0) { - try { - // try to copy with ant - if (src.isDirectory()) { - ant.copy(todir: dest.getAbsolutePath(), overwrite: true) { fileset(dir: src.getAbsolutePath()) } - } else { - ant.copy(file: src.getAbsolutePath(), todir: dest.getAbsolutePath(), overwrite: "true") - } - returnValue = 0 - } catch (e) { - log.trace("JBFIle.copy with ant failed", e) - returnValue = 2 - } + 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' : ''