Skip to content

Instantly share code, notes, and snippets.

@chtz
Created February 25, 2018 21:37
Show Gist options
  • Save chtz/980b703c1d4526b693aa4fa5c1f1daea to your computer and use it in GitHub Desktop.
Save chtz/980b703c1d4526b693aa4fa5c1f1daea to your computer and use it in GitHub Desktop.
require 'nokogiri'
def open_pom
File.open("pom.xml") { |f| Nokogiri::XML(f) }
end
def save_pom(pom)
File.open('pom.xml','w') {|f| pom.write_xml_to f}
end
def get_version(pom)
pom.xpath("/x:project/x:version", 'x' => 'http://maven.apache.org/POM/4.0.0').first.content
end
def set_version(pom, version)
pom.xpath("/x:project/x:version", 'x' => 'http://maven.apache.org/POM/4.0.0').first.content = version
end
def unsnapshot(version)
version =~ /(\d+\.\d+\.\d+)/
$1
end
def resnapshot(version)
version =~ /(\d+\.\d+)\.(\d+)/
$1 + "." + ($2.to_i + 1).to_s + "-SNAPSHOT"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment