class Motion::Project::Maven

Constants

MAVEN_ROOT
VERSION

Public Class Methods

new(config) click to toggle source
# File lib/motion/project/maven.rb, line 25
def initialize(config)
  @maven_path = 'mvn'
  @config = config
  @dependencies = []
  @repositories = []
  configure_project
end

Public Instance Methods

configure_project() click to toggle source
# File lib/motion/project/maven.rb, line 33
def configure_project
  @config.vendor_project(:jar => "#{MAVEN_ROOT}/target/dependencies.jar")
end
dependency(name, options = {}) click to toggle source
# File lib/motion/project/maven.rb, line 41
def dependency(name, options = {})
  @dependencies << normalized_dependency(name, options)
end
generate_pom() click to toggle source

Helpers

# File lib/motion/project/maven.rb, line 55
def generate_pom
  template_path = File.expand_path("../pom.erb", __FILE__)
  template = ERB.new(File.new(template_path).read, nil, "%")
  File.open(pom_path, 'w') do |io|
    io.puts template.result(binding)
  end
  system "xmllint --output #{pom_path} --format #{pom_path}"
end
inspect() click to toggle source
# File lib/motion/project/maven.rb, line 99
def inspect
  @dependencies.map do |dependency|
    "#{dependency[:name]} - #{dependency[:artifact]} (#{dependency[:version]})"
  end.inspect
end
install!(update) click to toggle source
# File lib/motion/project/maven.rb, line 49
def install!(update)
  generate_pom
  system "#{maven_command} -f #{pom_path} clean install"
end
maven_command() click to toggle source
# File lib/motion/project/maven.rb, line 68
def maven_command
  unless system("command -v #{@maven_path} >/dev/null")
    $stderr.puts "[!] #{@maven_path} command doesn’t exist. Verify your maven installation."
    exit 1
  end

  if ENV['MAVEN_DEBUG']
    "#{@maven_path} -X"
  else
    "#{@maven_path}"
  end
end
normalized_dependency(name, options) click to toggle source
# File lib/motion/project/maven.rb, line 89
def normalized_dependency(name, options)
  {
    name: name,
    version: options.fetch(:version, 'LATEST'),
    artifact: options.fetch(:artifact, name),
    scope: options.fetch(:scope, false),
    type: options.fetch(:type, false)
  }
end
normalized_repository(url, options) click to toggle source
# File lib/motion/project/maven.rb, line 81
def normalized_repository(url, options)
  {
    url: url,
    releases: options.fetch(:releases, true),
    snapshots: options.fetch(:snapshots, true)
  }
end
path=(path) click to toggle source
# File lib/motion/project/maven.rb, line 37
def path=(path)
  @maven_path = path
end
pom_path() click to toggle source
# File lib/motion/project/maven.rb, line 64
def pom_path
  "#{MAVEN_ROOT}/pom.xml"
end
repository(url, options = {}) click to toggle source
# File lib/motion/project/maven.rb, line 45
def repository(url, options = {})
  @repositories << normalized_repository(url, options)
end