Class: JBundler::AetherRuby

Inherits:
Object
  • Object
show all
Defined in:
lib/jbundler/aether.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = Config.new) ⇒ AetherRuby

Returns a new instance of AetherRuby.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/jbundler/aether.rb', line 49

def initialize( config = Config.new )
  unless defined? Aether
    self.class.setup_classloader
  end
  @aether = Aether.new( config.verbose )
  @aether.add_proxy( config.proxy ) if config.proxy
  @aether.add_mirror( config.mirror ) if config.mirror
  @aether.offline = config.offline
  @aether. = config.settings if config.settings
  @aether.local_repository = java.io.File.new(config.local_repository) if config.local_repository
rescue NativeException => e
  e.cause.print_stack_trace
  raise e
end

Class Method Details

.setup_classloaderObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jbundler/aether.rb', line 28

def self.setup_classloader
  require 'java'

  maven_home = File.dirname(File.dirname(Gem.bin_path('ruby-maven',
                                                       'rmvn')))
  # TODO reduce to the libs which are really needed
  Dir.glob(File.join(maven_home, 'lib', "*jar")).each {|path| require path }
  begin
    require 'jbundler.jar'
  rescue LoadError
    # allow the classes already be added to the classloader
    begin
      java_import 'jbundler.Aether'
    rescue NameError
      # assume this happens only when working on the git clone
      raise "jbundler.jar is missing - maybe you need to build it first ? use\n$ rmvn prepare-package -Dmaven.test.skip\n"
    end
  end
  java_import 'jbundler.Aether'
end

Instance Method Details

#add_artifact(coordinate, extension = nil) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/jbundler/aether.rb', line 64

def add_artifact(coordinate, extension = nil)
  if extension
    coord = coordinate.split(/:/)
    coord.insert(2, extension)
    @aether.add_artifact(coord.join(":"))
  else
    @aether.add_artifact(coordinate)
  end
end

#add_repository(name, url) ⇒ Object



74
75
76
# File 'lib/jbundler/aether.rb', line 74

def add_repository(name, url)
  @aether.add_repository(name, url)
end

#artifactsObject



101
102
103
# File 'lib/jbundler/aether.rb', line 101

def artifacts
  @aether.artifacts
end

#classpathObject



85
86
87
88
89
90
91
# File 'lib/jbundler/aether.rb', line 85

def classpath
  if artifacts.empty?
    ''
  else
    @aether.classpath
  end
end

#classpath_arrayObject



93
94
95
# File 'lib/jbundler/aether.rb', line 93

def classpath_array
  classpath.split(/#{File::PATH_SEPARATOR}/)
end

#install(coordinate, file) ⇒ Object



113
114
115
116
117
118
# File 'lib/jbundler/aether.rb', line 113

def install(coordinate, file)
  @aether.install(coordinate, file)
rescue NativeException => e
  e.cause.print_stack_trace
  raise e
end

#repositoriesObject



97
98
99
# File 'lib/jbundler/aether.rb', line 97

def repositories
  @aether.repositories
end

#resolveObject



78
79
80
81
82
83
# File 'lib/jbundler/aether.rb', line 78

def resolve
  @aether.resolve unless artifacts.empty?
rescue NativeException => e
  e.cause.print_stack_trace
  raise e
end

#resolved_coordinatesObject



105
106
107
108
109
110
111
# File 'lib/jbundler/aether.rb', line 105

def resolved_coordinates
  if artifacts.empty?
    []
  else
    @aether.resolved_coordinates
  end
end