Created
August 23, 2012 20:37
-
-
Save stuartf/3441363 to your computer and use it in GitHub Desktop.
Update versions in poms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'nokogiri' | |
require 'getopt/long' | |
@opt = Getopt::Long.getopts( | |
["--file", "-f", Getopt::REQUIRED], | |
["--artifact", "-a", Getopt::OPTIONAL], | |
["--expected", "-e", Getopt::OPTIONAL], | |
["--group", "-g", Getopt::REQUIRED], | |
["--version", "-v", Getopt::REQUIRED] | |
) | |
def updateVersion(node) | |
node.css('> version').map do |version| | |
if version.text == @opt['expected'] or not @opt['expected'] | |
version.content = @opt['version'] | |
end | |
end | |
end | |
doc = Nokogiri::XML(open(@opt['file'])) | |
doc.css('groupId').each do |group| | |
if group.text == @opt['group'] | |
p = group.parent | |
if @opt['artifact'] | |
p.css('> artifactId').map do |artifact| | |
if artifact.text == @opt['artifact'] | |
updateVersion(p) | |
end | |
end | |
else | |
updateVersion(p) | |
end | |
end | |
end | |
File.open(@opt['file'], 'w') {|f| f.write(doc.to_xml)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment