Class: Maven::Ruby::Maven

Inherits:
Object
  • Object
show all
Defined in:
lib/maven/ruby/maven.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project = nil, temp_pom = nil) ⇒ Maven

Returns a new instance of Maven.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/maven/ruby/maven.rb', line 49

def initialize( project = nil, temp_pom = nil )
  super()
  
  if project
    warn 'deprecated: End Of Life - just tell maven where your (ruby) pom is'
    begin
      require 'maven/tools/model'
      require 'maven/tools/visitor'
    rescue LoadError => e
      warn 'maven-tools gem is not a direct dependency anymore'
      raise e
    end
    f = File.expand_path( temp_pom || '.pom.xml' )
    v = ::Maven::Tools::Visitor.new( File.open( f, 'w' ) )
    # parse project and write out to temp_pom file
    v.accept_project( project )
    # tell maven to use the generated file
    options[ '-f' ] = f
    @embedded = true
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



117
118
119
120
# File 'lib/maven/ruby/maven.rb', line 117

def method_missing( method, *args )
  method = method.to_s.gsub( /_/, '-' ).to_sym
  exec( *([ method ] + args) )
end

Instance Attribute Details

#embeddedObject

Returns the value of attribute embedded.



28
29
30
# File 'lib/maven/ruby/maven.rb', line 28

def embedded
  @embedded
end

Instance Method Details

#<<(v) ⇒ Object



75
76
77
# File 'lib/maven/ruby/maven.rb', line 75

def <<( v )
  options[ v ] = nil
end

#exec(*args) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/maven/ruby/maven.rb', line 102

def exec(*args)
  mvn_args = (args + options_array)
  if verbose
    puts "mvn #{mvn_args.join(' ')}"
  end   
  
  result = RubyMaven.exec( *mvn_args )
  if @embedded and not result
    # TODO remove this when the embedded case is gone
    raise "error in executing maven #{result}"
  else
    result
  end
end

#inherit_jruby_versionObject



96
97
98
99
100
# File 'lib/maven/ruby/maven.rb', line 96

def inherit_jruby_version
  if defined? JRUBY_VERSION
    self['jruby.version'] = JRUBY_VERSION
  end
end

#optionsObject



71
72
73
# File 'lib/maven/ruby/maven.rb', line 71

def options
  @options ||= {}
end

#property(key, value = nil) ⇒ Object Also known as: []=



83
84
85
# File 'lib/maven/ruby/maven.rb', line 83

def property(key, value = nil)
  options["-D#{key}"] = value
end

#verboseObject



88
89
90
91
92
93
94
# File 'lib/maven/ruby/maven.rb', line 88

def verbose
  if @verbose.nil?
    @verbose = options.delete('-Dverbose').to_s == 'true'
  else
    @verbose
  end
end

#verbose=(v) ⇒ Object



79
80
81
# File 'lib/maven/ruby/maven.rb', line 79

def verbose= v
  @verbose = v
end