Skip to content

Instantly share code, notes, and snippets.

@stuartf
Created August 23, 2012 20:37
Show Gist options
  • Save stuartf/3441363 to your computer and use it in GitHub Desktop.
Save stuartf/3441363 to your computer and use it in GitHub Desktop.
Update versions in poms
#!/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