Module: Maven::Tools::Coordinate

Included in:
Model::Coordinate, Model::Exclusion, Jarfile
Defined in:
lib/maven/tools/coordinate.rb

Instance Method Summary collapse

Instance Method Details

#gav(*args) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/maven/tools/coordinate.rb', line 57

def gav(*args)
  if args[0] =~ /:/
    [args[0].sub(/:[^:]+$/, ''), args[0].sub(/.*:/, ''), maven_version(*args[1, 2])]
  else
    [args[0], args[1], maven_version(*args[2,3])]
  end
end

#group_artifact(*args) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/maven/tools/coordinate.rb', line 43

def group_artifact(*args)
  case args.size
  when 1
    name = args[0]
    if name =~ /:/
      [name.sub(/:[^:]+$/, ''), name.sub(/.*:/, '')]
    else
      ["rubygems", name]
    end
  else
    [args[0], args[1]]
  end
end

#to_coordinate(line) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/maven/tools/coordinate.rb', line 25

def to_coordinate(line)
  if line =~ /^\s*(jar|pom)\s/
    packaging = line.strip.sub(/\s+.*/, '')

    # Remove packaging, comments and whitespaces
    sanitized_line = line.sub(/\s*[a-z]+\s+/, '').sub(/#.*/,'').gsub(/\s+/,'')

    # Remove version(s) and quotes to find the group id, artifact id and classifier
    group_id, artifact_id, classifier = sanitized_line.split(',')[0].gsub(/['"]/, '').split(/:/)

    # Remove the group id, artifact id and classifier to find the version(s)
    version, second_version = sanitized_line.split(',')[1..-1].join(',').gsub(/['"],/, ':').gsub(/['"]/, '').split(/:/)
    mversion = second_version ? to_version(version, second_version) : to_version(version)

    classifier ? "#{group_id}:#{artifact_id}:#{packaging}:#{classifier}:#{mversion}" : "#{group_id}:#{artifact_id}:#{packaging}:#{mversion}"
  end
end

#to_version(*args) ⇒ Object



65
66
67
# File 'lib/maven/tools/coordinate.rb', line 65

def to_version(*args)
  maven_version(*args) || "[0,)"
end