Guest User

Untitled

a guest
Jun 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. #
  3. # Release utility script to update all version numbers in POMs.
  4. #
  5. # Usage: updatepoms.rb <new-version>
  6. #
  7. class Pom
  8. def initialize(filename)
  9. @filename = filename
  10. @lines = IO.readlines(filename)
  11. end
  12.  
  13. def update_version(version)
  14. group = nil
  15. artifact = nil
  16. @lines.each do |line|
  17. match = line.match(%r{<groupId>([^<]+)</groupId>})
  18. if match
  19. group = match[1]
  20. next
  21. end
  22. match = line.match(%r{<artifactId>([^<]+)</artifactId>})
  23. if match
  24. artifact = match[1]
  25. next
  26. end
  27. if line =~ %r{<version>[^<]+</version>} && group =~ /^org.jruby/ && artifact =~ /^(jruby|shared)/
  28. line.sub!(/<version>([^<]+)<\/version>/, "<version>#{version}</version>")
  29. end
  30. end
  31. end
  32.  
  33. def save
  34. File.open(@filename, 'w') {|f| @lines.each {|l| f << l } }
  35. end
  36. end
  37.  
  38. Version = ARGV.shift or abort("#$0 takes one argument, the new version")
  39.  
  40. dir = ARGV.shift || Dir.pwd
  41. (Dir["#{dir}/**/pom.xml"]).each do |f|
  42. puts "updating #{f}"
  43. pom = Pom.new(f)
  44. pom.update_version(Version)
  45. pom.save
  46. end
Add Comment
Please, Sign In to add comment