@@ -186,21 +186,31 @@ class JBFile {
186186 }
187187
188188 def returnValue = 0
189- try {
190- // try to copy with ant
191- ant. copy(file : src. getAbsolutePath(), tofile : dest. getAbsolutePath(), overwrite : " true" )
192- } catch (e) {
193- // Try it with sudo rights
194- if (! platform. isWindows()) {
195- def args = (preserveRights) ? ' -p' : ' '
196- args + = (dereference) ? ' -L' : ' '
197- if (useAdminPrivileges) {
198- returnValue + = Cmd . executeSudoCommand(" cp -r ${ args} ${ src.absolutePath} ${ dest} " , new File (' .' ))
199- } else {
200- returnValue + = Cmd . executeCommand(" cp -r ${ args} ${ src.absolutePath} ${ dest} " , new File (' .' ))
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
201205 }
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 (' .' ))
202212 } else {
203- returnValue = -1
213+ returnValue + = Cmd . executeCommand( " cp -r ${ args } ${ src.absolutePath } ${ dest } " , new File ( ' . ' ))
204214 }
205215 }
206216 return returnValue == 0
0 commit comments