Skip to content

Commit fc51c87

Browse files
committed
Reduce reliance on ant for copying
1 parent 214bbb8 commit fc51c87

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

core/src/main/groovy/noe/common/utils/JBFile.groovy

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,34 @@ class JBFile {
186186
}
187187

188188
def returnValue = 0
189+
if (platform.isWindows()) {
190+
File absDest = src.isDirectory() ? new File(dest, src.name) : dest
191+
def command = ["xcopy", "${src.absolutePath}", absDest.absolutePath, "/H", "/S", "/E", "/I", "/Y", "/C", "/F", "/R", "/K", "/X"]
192+
returnValue = Cmd.executeCommand(command, new File('.'))
193+
if (returnValue > 0) {
194+
try {
195+
// try to copy with ant
196+
if (src.isDirectory()) {
197+
ant.copy(todir: dest.getAbsolutePath(), overwrite: true) { fileset(dir: src.getAbsolutePath()) }
198+
} else {
199+
ant.copy(file: src.getAbsolutePath(), todir: dest.getAbsolutePath(), overwrite: "true")
200+
}
201+
returnValue = 0
202+
} catch (e) {
203+
log.trace("JBFIle.copy with ant failed", e)
204+
returnValue = 2
205+
}
206+
}
207+
} else {
208+
def args = (preserveRights) ? '-p' : ''
209+
args += (dereference) ? ' -L' : ''
210+
if (useAdminPrivileges) {
211+
returnValue += Cmd.executeSudoCommand("cp -r ${args} ${src.absolutePath} ${dest}", new File('.'))
212+
} else {
213+
returnValue += Cmd.executeCommand("cp -r ${args} ${src.absolutePath} ${dest}", new File('.'))
214+
}
215+
}
216+
189217
try {
190218
// try to copy with ant
191219
ant.copy(file: src.getAbsolutePath(), tofile: dest.getAbsolutePath(), overwrite: "true")

0 commit comments

Comments
 (0)