require File.join(File.dirname(__FILE__), "..", "tools", 'model.rb') module Maven module Model class DependencyArray < Array def <<(dep) d = detect { |item| item == dep } if d d.version = arg.version self else super end end alias :push :<< end class ExclusionArray < Array def <<(dep) excl = dep.is_a?(Exclusion) ? dep: Exclusion.new(dep) d = detect { |item| item == excl } if d delete d end super excl end alias :push :<< end class Coordinate < Maven::Tools::Tag tags :group_id, :artifact_id, :version def initialize(*args) @group_id, @artifact_id, @version = *coordinate(*args.flatten) end def coordinate(*args) if args[0] =~ /:/ [args[0].sub(/:[^:]+$/, ''), args[0].sub(/.*:/, ''), version(*args[1, 2])] else [args[0], args[1], version(*args[2,3])] end end def version(*args) if args.size == 0 nil else low, high = convert(args[0]) low, high = convert(args[1], low, high) if args[1] if low == high low else "#{low || '[0.0.0'},#{high || ')'}" end end end def convert(arg, low = nil, high = nil) if arg =~ /~>/ val = arg.sub(/~>\s*/, '') last = val.sub(/\.[^.]+$/, '.99999') ["[#{val}", "#{last}]"] elsif arg =~ />=/ val = arg.sub(/>=\s*/, '') ["[#{val}", (nil || high)] elsif arg =~ /<=/ val = arg.sub(/<=\s*/, '') [(nil || low), "#{val}]"] elsif arg =~ />/ val = arg.sub(/>\s*/, '') ["(#{val}", (nil || high)] elsif arg =~ /= 0.0.0" unless args[1] add_dependency(:gem, args, block) else result = add_dependency(:gem, args[0], block) # add its dependencies as well to have the version # determine by the dependencyManagement lock_file.dependency_hull(args[0]).map.each do |d| add_dependency(:gem, d[0], block) end result end end private :add_gem def jar(*args, &block) if args.last.is_a?(Hash) raise "hash not allowed for jar" end add_dependency(:jar, args, block) end def test_jar(*args, &block) if args.last.is_a?(Hash) raise "hash not allowed for test_jar" end add_dependency(:test_jar, args, block) end def gem(*args, &block) if args.last.is_a?(Hash) raise "hash not allowed in that context" end add_gem(args, block) end def maven_gem(*args, &block) if args.last.is_a?(Hash) raise "hash not allowed in that context" end add_dependency(:maven_gem, args, block) end end end end