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



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 29

def self.setup_classloader
  require 'java'

  Dir.glob( File.join( Maven.lib, '*.jar' ) ).each do |path|
    require path
  end
  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



72
73
74
75
76
77
78
79
80
# File 'lib/jbundler/aether.rb', line 72

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_local_jar(path) ⇒ Object



68
69
70
# File 'lib/jbundler/aether.rb', line 68

def add_local_jar( path )
   local_jars << File.expand_path( path )
end

#add_repository(name, url) ⇒ Object



82
83
84
# File 'lib/jbundler/aether.rb', line 82

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

#add_snapshot_repository(name, url) ⇒ Object



86
87
88
# File 'lib/jbundler/aether.rb', line 86

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

#artifactsObject



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

def artifacts
  @aether.artifacts
end

#classpathObject



97
98
99
100
101
102
103
104
105
# File 'lib/jbundler/aether.rb', line 97

def classpath
  if artifacts.empty? and local_jars.empty?
    ''
  else
    path = [ @aether.classpath ] 
    path = path + @local_jars if @local_jars
    path.join( File::PATH_SEPARATOR )
  end
end

#classpath_arrayObject



107
108
109
# File 'lib/jbundler/aether.rb', line 107

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

#install(coordinate, file) ⇒ Object



127
128
129
130
131
132
# File 'lib/jbundler/aether.rb', line 127

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

#local_jarsObject



64
65
66
# File 'lib/jbundler/aether.rb', line 64

def local_jars
  @local_jars ||= []
end

#repositoriesObject



111
112
113
# File 'lib/jbundler/aether.rb', line 111

def repositories
  @aether.repositories
end

#resolveObject



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

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

#resolved_coordinatesObject



119
120
121
122
123
124
125
# File 'lib/jbundler/aether.rb', line 119

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