Class: Horatio::Detector::Maven

Inherits:
Object
  • Object
show all
Includes:
IOHandler, Validator
Defined in:
lib/horatio/detector/maven.rb

Instance Attribute Summary

Attributes included from IOHandler

#input, #output

Instance Method Summary collapse

Methods included from IOHandler

#default_output, #detect, included, #initialize, #memo_read

Methods included from Validator

#validate, #validate_name, #validate_version

Instance Method Details

#default_inputObject



13
14
15
# File 'lib/horatio/detector/maven.rb', line 13

def default_input
  'pom.xml'
end

#descriptionObject



43
44
45
# File 'lib/horatio/detector/maven.rb', line 43

def description
  'JAVA Maven pom.xml'
end

#infoObject



17
18
19
20
21
# File 'lib/horatio/detector/maven.rb', line 17

def info
  memo_read do
    File.open('pom.xml', 'r') { |f| Nori.new.parse(f.read) }
  end
end

#nameObject



23
24
25
# File 'lib/horatio/detector/maven.rb', line 23

def name
  info['project']['artifactId']
end

#versionObject

Maven version reader

We need to decrease the number if we see SNAPSHOT, this is becasue maven increments it in anticipation for the next build



33
34
35
36
37
38
39
40
41
# File 'lib/horatio/detector/maven.rb', line 33

def version
  version =  info['project']['version'] || info['project']['parent']['version']
  return version unless version =~ /-SNAPSHOT$/
  version = version.split('-')[0]
  version = version.split('.')
  minor = version.last.to_i > 1 ? version.last.to_i - 1 : version.last
  version[-1] = minor
  version.join('.')
end