|
| 1 | +lines = ARGF.readlines(chomp: true) |
| 2 | +lines.each do |line| |
| 3 | + line.sub!(/^\[lib[^:]+:\d+\]\s+/, '') |
| 4 | + line.sub!(/\s*\\$/, '') |
| 5 | + line.sub!(/^'(.+)'$/, '\1') |
| 6 | + line.sub!(/^(.+?)@(?:--macro|--language|--tool|jar|user|driver)[^=]*=(.*)$/, '\1=\2') |
| 7 | + line.sub!(/^(.+?)@(?:--macro|--language|--tool|jar|user|driver)[^=]*$/, '\1') |
| 8 | +end |
| 9 | +lines.reject! { _1.start_with?("Apply jar") } |
| 10 | +lines.delete("Executing [") |
| 11 | +lines.delete("]") |
| 12 | + |
| 13 | +to_merge_in_one_line = %w[ |
| 14 | + --add-exports |
| 15 | + --module-path |
| 16 | + --module |
| 17 | + -imagecp |
| 18 | + -imagemp |
| 19 | + -keepalive |
| 20 | +] |
| 21 | + |
| 22 | +to_merge_in_one_line.each do |option| |
| 23 | + lines.each_cons(2) do |a, b| |
| 24 | + if a == option |
| 25 | + b.prepend "#{option}=" |
| 26 | + end |
| 27 | + end |
| 28 | + lines.delete option |
| 29 | +end |
| 30 | + |
| 31 | +lines.sort! |
| 32 | +lines.uniq! |
| 33 | + |
| 34 | +fields_to_sort_value = %w[ |
| 35 | + --module-path= |
| 36 | + -imagecp= |
| 37 | + -imagemp= |
| 38 | + |
| 39 | + --add-modules= |
| 40 | + --enable-native-access= |
| 41 | + -Dorg.graalvm.launcher.classpath= |
| 42 | + -Dsvm.modulesupport.addedModules= |
| 43 | + -H:CLibraryPath= |
| 44 | +] |
| 45 | +lines.each do |line| |
| 46 | + if fields_to_sort_value.any? { |f| line.start_with?(f) } |
| 47 | + key, value = line.split('=', 2) |
| 48 | + # sep = %w[-Dorg.graalvm.launcher.classpath=].include?(key) ? ':' : ',' |
| 49 | + values = value.split(/[,:]/) |
| 50 | + if value.include?('/') # contains paths |
| 51 | + values = values.map { File.basename(_1) } |
| 52 | + end |
| 53 | + values = values.sort.uniq |
| 54 | + # value = values.join(',') |
| 55 | + value = "[\n#{values.join("\n")}\n]" |
| 56 | + |
| 57 | + line.replace "#{key}=#{value}" |
| 58 | + end |
| 59 | +end |
| 60 | + |
| 61 | +puts lines |
0 commit comments