Class: Naether::Maven

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

Overview

Helper for interacting with a Maven POM

Author:

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Maven) initialize(pom_path = nil)

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

+ (Naether::Maven) create_from_notation(notation)

Create an instance based on notation

Parameters:

  • notation (String)

Returns:

See Also:



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

+ (Naether::Maven) create_from_pom(pom_path)

Create an instance from a POM

Parameters:

  • pom_path (String)

Returns:



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

- (Object) add_dependency(notation, scope = nil)

Add dependency by scope

Parameters:

  • notation (String)
  • scope (String) (defaults to: nil)


105
106
107
# File 'lib/naether/maven.rb', line 105

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

- (String) build_pom

Create the XML for a Maven Pom

Returns:

  • (String)

    pom xml



140
141
142
# File 'lib/naether/maven.rb', line 140

def build_pom()
  @project.toXml()
end

- (Object) dependencies(scopes = nil)

Get dependences for Project as notations

Parameters:

  • scopes (Array<String>) (defaults to: nil)

    valid options are compile,test,runtime



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
96
97
98
# 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
    
  else
    list = nil
    if scopes
      list = Naether::Java.convert_to_java_list( scopes )
      
      deps = @project._invoke('getDependenciesNotation', 'Ljava.util.List;', list)
    else
      deps = @project.getDependenciesNotation()
    end
    
  end
  
  Naether::Java.convert_to_ruby_array( deps, true )
end

- (Object) dependencies=(dependencies)

Set dependencies

Parameters:

  • dependencies (Array)


113
114
115
# File 'lib/naether/maven.rb', line 113

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

- (Object) load_naether(naether)

Load dependencies and remote repo from a Naether instance



132
133
134
135
# File 'lib/naether/maven.rb', line 132

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

- (Object) notation=(notation)

Set the Notation for this Project

Parameters:

  • notation (String)

See Also:



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

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

- (Object) repositories=(repositories)

Set repositories

Parameters:

  • repositories (Array)

    of urls



120
121
122
# File 'lib/naether/maven.rb', line 120

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

- (Object) version

Get the version

return [String] version



127
128
129
# File 'lib/naether/maven.rb', line 127

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

- (Object) write_pom(file_path)

Write Maven Pom

Parameters:

  • file_path (String)


148
149
150
# File 'lib/naether/maven.rb', line 148

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