Module: Maven::Tools::Coordinate

Included in:
Artifact::Helper, DSL::Gemspec, GemspecDependencies, Jarfile, Jarfile::DSL
Defined in:
lib/maven/tools/coordinate.rb

Instance Method Summary collapse

Instance Method Details

#gav(*args) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/maven/tools/coordinate.rb', line 106

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



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/maven/tools/coordinate.rb', line 92

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



84
85
86
87
88
89
90
# File 'lib/maven/tools/coordinate.rb', line 84

def to_coordinate( line )
  result = to_split_coordinate( line )
  if result
    exclusion = result.last.inspect.gsub( /[" ]/, '' )
    ( result[0..-2] + [ exclusion ] ).join( ':' )
  end
end

#to_split_coordinate(line) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/maven/tools/coordinate.rb', line 35

def to_split_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+/,'')

    exclusions = nil
    sanitized_line.gsub!( /[,:](\[.+:.+\]|'\[.+:.+\]'|"\[.+:.+\]")/ ) do |match|
      exclusions = match.gsub( /['"]/, '' )[2..-2].split( /,\s*/ )
      nil
    end

    # split to compartments
    parts = sanitized_line.split( /[,]/ ).collect{|o| o.gsub( /['"]/, '' ) }
    # fix no version on one argument
    if parts.size == 1
      parts << '[0,)'
    end

    # split first argument
    parts[ 0 ] = parts[ 0 ].split( /:/ )
    parts.flatten!
   
    # convert ruby version to maven version
    versions = parts.select { |i| i.match( /[~><=!]/ ) }
    if ! versions.empty?
      version = to_version( *versions )
      parts = parts - versions
      parts << version
    else
      # concat maven version ranges
      versions = parts.select { |i| i.match( /[\[\]()]/ ) }
      if ! versions.empty?
        version = versions.join( ',' )
        parts = parts - versions
        parts << version
      end
    end
    
    # insert packing and exclusion
    parts.insert( 2, packaging )
    parts << exclusions
                 
    # make sure there are no nils
    parts.compact
  end
end

#to_split_coordinate_with_scope(line) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/maven/tools/coordinate.rb', line 24

def to_split_coordinate_with_scope( line )
  line = line.sub( /#.*^/, '' )
  scope = :compile
  line.sub!( /,\s+:scope\s+=>\s(:provided|:runtime|:compile|:test)/ ) do |part|
    scope = part.sub( /.*:/, '' ).to_sym
    ''
  end
	coord = to_split_coordinate( line ) 
  [ scope ] + coord if coord
end

#to_version(*args) ⇒ Object



114
115
116
# File 'lib/maven/tools/coordinate.rb', line 114

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