@@ -288,59 +288,15 @@ end
288288# This is a FileUtils extension that defines several additional commands to be
289289# added to the FileUtils utility functions.
290290module FileUtils
291- # PowerShell quirks:
292- # - `powershell -Command -`:
293- # Arguments must be part of command, thus cannot pass arguments safely without escaping.
294- # - `powershell -Command <script-block> [-args <arg-array>]`:
295- # This only works when invoking powershell subshell in powershell.
296- # - `powershell -Command <string> [<CommandParameters>]`:
297- # CommandParameters are joined with command and then parsed, thus cannot pass arguments safely without escaping.
298- # - `powershell -File -`:
299- # Arguments must be part of file, thus cannot pass arguments safely without escaping.
300- # - `powershell -File <filePath> <args>`:
301- # This is the only way to pass arguments safely without escaping.
302- def powershell ( file , *args )
303- sh 'powershell' , '-NoLogo' , '-NoProfile' , '-NonInteractive' , '-ExecutionPolicy' , 'Bypass' , '-File' , file , *args
304- end
305-
306- def junzip ( archive , dest = '.' )
307- require 'java'
308-
309- Rake . rake_output_message "Archive: #{ archive } " if Rake ::FileUtilsExt . verbose_flag
310-
311- current_directory = java . nio . file . Paths . get ( org . jruby . Ruby . getGlobalRuntime . getCurrentDirectory )
312- zip_file = java . util . zip . ZipFile . new ( current_directory . resolve ( archive ) . toFile )
313- dest_path = current_directory . resolve ( dest ) . normalize
314- entries = zip_file . entries
315- while entries . hasMoreElements
316- entry = entries . nextElement
317- name = entry . getName
318- path = dest_path . resolve ( name ) . normalize
319- raise SecurityError unless path . startsWith ( dest_path )
320-
321- Rake . rake_output_message " inflating: #{ name } " if Rake ::FileUtilsExt . verbose_flag
322-
323- if entry . isDirectory
324- java . nio . file . Files . createDirectories ( path )
325- else
326- java . nio . file . Files . createDirectories ( path . getParent )
327- java . nio . file . Files . copy ( zip_file . getInputStream ( entry ) , path )
328- end
329- end
330- ensure
331- zip_file &.close
332- end
333-
334291 def unarchive ( archive , dest = '.' )
335292 case archive . downcase
336293 when -> ( name ) { name . include? ( '.tar.' ) || name . end_with? ( '.tar' ) }
337294 mkdir_p dest
338295 sh 'tar' , '-vxC' , dest , '-f' , archive , '--no-same-owner' , '--no-same-permissions'
339296 when -> ( name ) { name . end_with? ( '.zip' ) }
340- if RUBY_PLATFORM == 'java'
341- junzip archive , dest
342- elsif Gem . win_platform?
343- powershell 'expand-archive.ps1' , '-Force' , '-LiteralPath' , archive , '-DestinationPath' , dest
297+ if Gem . win_platform?
298+ mkdir_p dest
299+ sh File . absolute_path ( 'System32/tar.exe' , ENV . fetch ( 'SystemRoot' , 'C:/Windows' ) ) , '-vxC' , dest , '-f' , archive
344300 else
345301 sh 'unzip' , '-od' , dest , archive
346302 end
0 commit comments