Class: Jars::GemspecArtifacts::Artifact

Inherits:
Object
  • Object
show all
Defined in:
lib/jars/gemspec_artifacts.rb

Constant Summary collapse

ALLOWED_TYPES =
['jar', 'pom']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, *args) ⇒ Artifact

Returns a new instance of Artifact.



97
98
99
100
101
102
# File 'lib/jars/gemspec_artifacts.rb', line 97

def initialize( options, *args )
  @type, @group_id, @artifact_id, @classifier, @version, @exclusions = *args
  options.each do |k,v|
    instance_variable_set( "@#{k}", v )
  end
end

Instance Attribute Details

#artifact_idObject (readonly)

Returns the value of attribute artifact_id.



93
94
95
# File 'lib/jars/gemspec_artifacts.rb', line 93

def artifact_id
  @artifact_id
end

#classifierObject (readonly)

Returns the value of attribute classifier.



93
94
95
# File 'lib/jars/gemspec_artifacts.rb', line 93

def classifier
  @classifier
end

#exclusionsObject (readonly)

Returns the value of attribute exclusions.



93
94
95
# File 'lib/jars/gemspec_artifacts.rb', line 93

def exclusions
  @exclusions
end

#group_idObject (readonly)

Returns the value of attribute group_id.



93
94
95
# File 'lib/jars/gemspec_artifacts.rb', line 93

def group_id
  @group_id
end

#scopeObject (readonly)

Returns the value of attribute scope.



93
94
95
# File 'lib/jars/gemspec_artifacts.rb', line 93

def scope
  @scope
end

#typeObject (readonly)

Returns the value of attribute type.



93
94
95
# File 'lib/jars/gemspec_artifacts.rb', line 93

def type
  @type
end

#versionObject (readonly)

Returns the value of attribute version.



93
94
95
# File 'lib/jars/gemspec_artifacts.rb', line 93

def version
  @version
end

Class Method Details

.new(line) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/jars/gemspec_artifacts.rb', line 104

def self.new( line )
  line = line.strip
  index = line.index( /\s/ )
  if index.nil?
    return nil
  end
  type = line[0..index].strip
  unless ALLOWED_TYPES.member?( type )
    return nil
  end
  line = line[index..-1]
  line.gsub!(/['"]/, '')
  line.strip!

  options = {}
  line.sub!(/,\s*:exclusions\s*(:|=>)\s*(\[[^\]]+\])/) do
    options[ :exclusions ] = Exclusions.new( $2.strip )
    ''
  end
  line.sub!(/,\s*:([a-z]+)\s*(:|=>)\s*(:?[a-zA-Z0-9_]+)/) do
    options[ $1.to_sym ] = $3.sub(/^:/, '')
    ''
  end
  exclusions = nil
  line.sub!(/[,:]\s*\[(.+:.+,?\s*)+\]$/) do |a|
    exclusions = Exclusions.new( a[1..-1].strip )
    ''
  end

  line.strip!
  line.gsub!(/,\s*/, ':')

  if line.match(/[\[\(\)\]]/)
    index = line.index(/[\[\(].+$/)
    version = line[index..-1].sub(/:/, ', ')
    line = line[0..index - 1].strip.sub(/:$/, '')
  else
    index = line.index(/[:][^:]+$/)
    version = line[index + 1..-1]
    line = line[0..index - 1].strip
  end

  case line.count(':')
  when 2
    group_id, artifact_id, classifier = line.split(':')
  when 1
    group_id, artifact_id = line.split(':')
    classifier = nil
  else
    warn line
    return nil
  end
  super( options, type, group_id, artifact_id, classifier, version, exclusions )
end

Instance Method Details

#keyObject



189
190
191
192
193
# File 'lib/jars/gemspec_artifacts.rb', line 189

def key
  args = [@group_id, @artifact_id]
  args << @classifier if @classifier
  args.join(':')
end

#to_coordObject



181
182
183
184
185
186
187
# File 'lib/jars/gemspec_artifacts.rb', line 181

def to_coord
  args = [@group_id, @artifact_id]
  args << @classifier if @classifier
  args << @type
  args << MavenVersion.new( @version )
  args.join(':')
end

#to_coord_no_classifierObject



174
175
176
177
178
179
# File 'lib/jars/gemspec_artifacts.rb', line 174

def to_coord_no_classifier
  args = [@group_id, @artifact_id]
  args << @type
  args << MavenVersion.new( @version )
  args.join(':')
end

#to_gacvObject



167
168
169
170
171
172
# File 'lib/jars/gemspec_artifacts.rb', line 167

def to_gacv
  args = [@group_id, @artifact_id]
  args << @classifier if @classifier
  args << @version
  args.join(':')
end

#to_sObject



159
160
161
162
163
164
165
# File 'lib/jars/gemspec_artifacts.rb', line 159

def to_s
  args = [@group_id, @artifact_id]
  args << @classifier if @classifier
  args << @version
  args << @exclusions.to_s if @exclusions
  "#{@type} #{group_id}:#{args[1..-1].join(', ')}"
end