Module: Grump::Plugin::Maven
- Defined in:
- lib/grump-maven.rb
Instance Method Summary collapse
- #download(url) ⇒ Object
- #maven(*args) ⇒ Object
- #maven_artifact(dependency) ⇒ Object
- #maven_download ⇒ Object
- #maven_jar(dependency) ⇒ Object
- #maven_latest(dependency) ⇒ Object
- #maven_plugin_setup ⇒ Object
- #maven_pom(dependency) ⇒ Object
- #maven_root ⇒ Object
- #maven_subst(xml, str) ⇒ Object
- #maven_tree ⇒ Object
Instance Method Details
#download(url) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/grump-maven.rb', line 14 def download(url) FileUtils.mkdir_p(@temp) d = Digest::MD5.hexdigest(url) if File.exists?("#{@temp}/#{d}") return File.read("#{@temp}/#{d}") end temp = nil open(url) do |io| temp = io.read end File.open("#{@temp}/#{d}", "w") do |file| file.write(temp) end temp end |
#maven(*args) ⇒ Object
30 31 32 |
# File 'lib/grump-maven.rb', line 30 def maven(*args) (@maven ||= []) << args.join(':') end |
#maven_artifact(dependency) ⇒ Object
38 39 40 41 |
# File 'lib/grump-maven.rb', line 38 def maven_artifact(dependency) group, artifact, version = dependency.split(':') File.join(maven_root, group.gsub('.','/'), artifact, version, artifact + '-' + version) end |
#maven_download ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/grump-maven.rb', line 97 def maven_download FileUtils.mkdir_p(@java_libs) maven_tree.each do |dependency| jar = maven_jar(dependency) file = File.join(@java_libs, File.basename(jar)) `curl -o #{file} #{jar}` unless File.exists?(file) end end |
#maven_jar(dependency) ⇒ Object
47 48 49 |
# File 'lib/grump-maven.rb', line 47 def maven_jar(dependency) maven_artifact(dependency) + '.jar' end |
#maven_latest(dependency) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/grump-maven.rb', line 51 def maven_latest(dependency) group, artifact = dependency.split(':') xml = download(File.join(maven_root, group.gsub('.','/'), artifact, 'maven-metadata.xml')) xml = REXML::Document.new(xml) (REXML::XPath.match(xml, '/metadata/versioning/latest').first || REXML::XPath.match(xml, '/metadata/version').first).text end |
#maven_plugin_setup ⇒ Object
9 10 11 12 |
# File 'lib/grump-maven.rb', line 9 def maven_plugin_setup plugin(:java) @temp = File.join(path, '.grump', 'temp') end |
#maven_pom(dependency) ⇒ Object
43 44 45 |
# File 'lib/grump-maven.rb', line 43 def maven_pom(dependency) maven_artifact(dependency) + '.pom' end |
#maven_root ⇒ Object
34 35 36 |
# File 'lib/grump-maven.rb', line 34 def maven_root 'http://central.maven.org/maven2' end |
#maven_subst(xml, str) ⇒ Object
58 59 60 |
# File 'lib/grump-maven.rb', line 58 def maven_subst(xml, str) str.gsub(/\$\{([^\}]+)\}/) { |var| var = var.split('.').last; REXML::XPath.match(xml, "/project/parent/#{var}").first.text } end |
#maven_tree ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/grump-maven.rb', line 62 def maven_tree @maven.each do |artifact| xml = download(maven_pom(artifact)) xml = REXML::Document.new(xml) REXML::XPath.match(xml, '/project/dependencies/dependency').each do |dependency| next if dependency.elements['optional'] && dependency.elements['optional'].text == 'true' next if dependency.elements['scope'] && dependency.elements['scope'].text == 'test' group = dependency.elements['groupId'].text group = maven_subst(xml, group) artifact = dependency.elements['artifactId'].text artifact = maven_subst(xml, artifact) if dependency.elements['version'] version = dependency.elements['version'].text version = maven_subst(xml, version) else version = maven_latest(group + ':' + artifact) end id = "#{group}:#{artifact}:#{version}" unless @maven.include?(id) maven(group, artifact, version) end end end @maven end |