Class: Naether::Maven

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

Overview

Helper for interacting with a Maven POM

Author:

  • Michael Guymon

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pom_path = nil) ⇒ Maven

Create new instance



51
52
53
54
55
56
57
58
# File 'lib/naether/maven.rb', line 51

def initialize(pom_path = nil)
  if pom_path
    @project = Naether::Java.create("com.tobedevoured.naether.maven.Project", pom_path )
  else
    @project = Naether::Java.create("com.tobedevoured.naether.maven.Project" )
  end
  
end

Class Method Details

.create_from_notation(notation) ⇒ Naether::Maven

Create an instance based on notation



41
42
43
44
45
# File 'lib/naether/maven.rb', line 41

def create_from_notation( notation )
  maven = Maven.new
  maven.notation = notation
  maven
end

.create_from_pom(pom_path) ⇒ Naether::Maven

Create an instance from a POM



32
33
34
# File 'lib/naether/maven.rb', line 32

def create_from_pom( pom_path )
  maven = Maven.new( pom_path )
end

Instance Method Details

#add_dependency(notation, scope = nil) ⇒ Object

Add dependency by scope



102
103
104
# File 'lib/naether/maven.rb', line 102

def add_dependency( notation, scope = nil )
  @project.addDependency( notation, scope )
end

#build_pomString

Create the XML for a Maven Pom



137
138
139
# File 'lib/naether/maven.rb', line 137

def build_pom()
  @project.toXml()
end

#dependencies(scopes = nil) ⇒ Object

Get dependences for Project as notations



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/naether/maven.rb', line 71

def dependencies( scopes = nil)
  if scopes
    unless scopes.is_a? Array
       scopes = [scopes]
    end
  end
      
  if Naether.platform == 'java'
    if scopes.nil?
      deps = @project.getDependenciesNotation()
    else
      deps = @project.getDependenciesNotation( scopes )
    end
    
  elsif scopes
    list = Naether::Java.convert_to_java_list( scopes )

    deps = @project._invoke('getDependenciesNotation', 'Ljava.util.List;', list)
  else
    deps = @project.getDependenciesNotation()
  end

  
  Naether::Java.convert_to_ruby_array( deps, true )
end

#dependencies=(dependencies) ⇒ Object

Set dependencies



110
111
112
# File 'lib/naether/maven.rb', line 110

def dependencies=(dependencies)
  @project.setDependencies( dependencies )
end

#final_nameObject



178
179
180
# File 'lib/naether/maven.rb', line 178

def final_name
  @project.getFinalName()
end

#invoke(*opts) ⇒ Object

Invoke a Maven goal



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/naether/maven.rb', line 152

def invoke( *opts )
  #defaults
  config = {
    # Checks ENV for maven home, otherwise defaults /usr/share/maven
    # XXX: Reuse Eng.getMavenHome?
    :maven_home => ENV['maven.home'] || ENV['MAVEN_HOME'] || '/usr/share/maven',
    :local_repo => File.expand_path('~/.m2/repository')
  }

  if opts.last.is_a? Hash
    config = config.merge( opts.pop )
  end
  goals = opts

  pom = @project.getPomFile().getAbsolutePath()

  invoker = Naether::Java.create("com.tobedevoured.naether.maven.Invoker", config[:local_repo], config[:maven_home] )

  java_list = Naether::Java.convert_to_java_list(goals)
  if Naether.platform == 'java'
    invoker.execute( pom, java_list )
  else
    invoker._invoke('execute', 'Ljava.lang.String;Ljava.util.List;', pom, java_list)
  end
end

#load_naether(naether) ⇒ Object

Load dependencies and remote repo from a Naether instance



129
130
131
132
# File 'lib/naether/maven.rb', line 129

def load_naether( naether )
  self.dependencies= naether.resolver.currentDependencies()
  self.repositories= naether.resolver.getRemoteRepositoryUrls()
end

#notation=(notation) ⇒ Object

Set the Notation for this Project



64
65
66
# File 'lib/naether/maven.rb', line 64

def notation=(notation)
  @project.setProjectNotation( notation )
end

#repositories=(repositories) ⇒ Object

Set repositories



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

def repositories=( repositories )
  @project.setRepositories( repositories )
end

#versionObject

Get the version

return [String] version



124
125
126
# File 'lib/naether/maven.rb', line 124

def version()
  return @project.getVersion()
end

#write_pom(file_path) ⇒ Object

Write Maven Pom



145
146
147
# File 'lib/naether/maven.rb', line 145

def write_pom( file_path )
  @project.writePom( file_path )
end