Sha256: 92291e38fb0e5e87b6f39b0fffba45bf93172ba0bd69827f42c5925095e4a9ce

Contents?: true

Size: 1.61 KB

Versions: 7

Compression:

Stored size: 1.61 KB

Contents

module JBundler
  module MavenUtil
    
    def to_coordinate(line)
      if line =~ /^\s*(jar|pom)\s/
        
        group_id, artifact_id, version, second_version = line.sub(/\s*[a-z]+\s+/, '').sub(/#.*/,'').gsub(/\s+/,'').gsub(/['"],/, ':').gsub(/['"]/, '').split(/:/)
        mversion = second_version ? to_version(version, second_version) : to_version(version)
        extension = line.strip.sub(/\s+.*/, '')
        "#{group_id}:#{artifact_id}:#{extension}:#{mversion}"
      end
    end

    def to_version(*args)
      if args.size == 0 || (args.size == 1 && args[0].nil?)
        "[0,)"
      else
        low, high = convert(args[0])
        low, high = convert(args[1], low, high) if args[1] =~ /[=~><]/
        if low == high
          low
        else
          "#{low || '[0'},#{high || ')'}"
        end
      end
    end
    
    private

    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}]"]
        # treat '!' the same way as '>' since maven can not describe such range
      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, val + '.0.0.0.0.1)']
      else
        [arg, arg]
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
maven-tools-0.31.0 lib/maven/maven_util.rb~
maven-tools-0.30.0 lib/maven/maven_util.rb~
maven-tools-0.29.3 lib/maven/maven_util.rb~
maven-tools-0.29.2 lib/maven/maven_util.rb~
maven-tools-0.29.1 lib/maven/maven_util.rb~
maven-tools-0.29.0 lib/maven/maven_util.rb~
jbundler-0.0.1 lib/jbundler/maven_util.rb