naether 0.10.1 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -8
- data/Gemfile.lock +8 -2
- data/README.md +8 -6
- data/VERSION +1 -1
- data/core-0.11.0.jar +0 -0
- data/doc/Naether.html +476 -0
- data/doc/Naether/s_20Ja.html +607 -0
- data/doc/Naether/s_20Ja/s_20JRu.html +597 -0
- data/doc/Naether/s_20Ja/s_20Ru.html +606 -0
- data/doc/Naether/s_20Mav.html +828 -0
- data/doc/_index.html +206 -0
- data/doc/class_list.html +53 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +328 -0
- data/doc/er_A_20_20_A_20.html +121 -0
- data/doc/er_A_20_20_A_20/tstrap_A_20_20.html +233 -0
- data/doc/file.README.html +197 -0
- data/doc/file_list.html +55 -0
- data/doc/frames.html +28 -0
- data/doc/index.html +197 -0
- data/doc/js/app.js +214 -0
- data/doc/js/full_list.js +173 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +796 -0
- data/doc/top-level-namespace.html +112 -0
- data/jar_dependencies.yml +33 -33
- data/lib/naether.rb +15 -380
- data/lib/naether/bootstrap.rb +2 -2
- data/lib/naether/configuration.rb +2 -1
- data/lib/naether/java.rb +1 -1
- data/lib/naether/java/jruby.rb +1 -1
- data/lib/naether/java/ruby.rb +1 -1
- data/lib/naether/maven.rb +1 -1
- data/lib/naether/notation.rb +1 -1
- data/lib/naether/runtime.rb +400 -0
- data/naether.gemspec +48 -4
- data/pom.xml +238 -129
- metadata +140 -5
- data/core-0.10.1.jar +0 -0
data/lib/naether/bootstrap.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
|
2
|
+
module Naether
|
3
3
|
|
4
4
|
#
|
5
5
|
# Naether runtime configuration
|
@@ -22,6 +22,7 @@ class Naether
|
|
22
22
|
|
23
23
|
|
24
24
|
@data = {
|
25
|
+
:version => version,
|
25
26
|
:gem_dir => gem_dir,
|
26
27
|
:naether_jar => File.join( gem_dir, "core-#{version}.jar"),
|
27
28
|
:platform => ($platform || RUBY_PLATFORM[/java/] || 'ruby'),
|
data/lib/naether/java.rb
CHANGED
data/lib/naether/java/jruby.rb
CHANGED
data/lib/naether/java/ruby.rb
CHANGED
data/lib/naether/maven.rb
CHANGED
data/lib/naether/notation.rb
CHANGED
@@ -0,0 +1,400 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with this
|
3
|
+
# work for additional information regarding copyright ownership. The ASF
|
4
|
+
# licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations under
|
14
|
+
# the License.
|
15
|
+
|
16
|
+
require "#{File.dirname(__FILE__)}/configuration"
|
17
|
+
require "#{File.dirname(__FILE__)}/bootstrap"
|
18
|
+
require "#{File.dirname(__FILE__)}/java"
|
19
|
+
|
20
|
+
#
|
21
|
+
# Java dependency resolver
|
22
|
+
#
|
23
|
+
# @author Michael Guymon
|
24
|
+
# @see https://github.com/mguymon/naether/tree/master/core
|
25
|
+
#
|
26
|
+
module Naether
|
27
|
+
class Runtime
|
28
|
+
|
29
|
+
attr_reader :resolver
|
30
|
+
|
31
|
+
# Create new instance.
|
32
|
+
def initialize
|
33
|
+
@resolver = Naether::Java.create('com.tobedevoured.naether.impl.NaetherImpl')
|
34
|
+
end
|
35
|
+
|
36
|
+
# Clear all remote repositories
|
37
|
+
def clear_remote_repositories
|
38
|
+
@resolver.clearRemoteRepositories()
|
39
|
+
end
|
40
|
+
|
41
|
+
# Add remote repository
|
42
|
+
#
|
43
|
+
# @param [String] url of remote repo
|
44
|
+
# @param [String] username optional
|
45
|
+
# @param [String] password optioanl
|
46
|
+
def add_remote_repository( url, username = nil, password = nil )
|
47
|
+
if username
|
48
|
+
@resolver.addRemoteRepositoryByUrl( url, username, password )
|
49
|
+
else
|
50
|
+
@resolver.addRemoteRepositoryByUrl( url )
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Get remote repositories
|
55
|
+
#
|
56
|
+
# @return [Array] of remote repos
|
57
|
+
def remote_repositories
|
58
|
+
Naether::Java.convert_to_ruby_array(@resolver.getRemoteRepositories())
|
59
|
+
end
|
60
|
+
|
61
|
+
# Get remote repositories as urls
|
62
|
+
#
|
63
|
+
# @return [Array<String>] of String urls
|
64
|
+
def remote_repository_urls
|
65
|
+
Naether::Java.convert_to_ruby_array(@resolver.getRemoteRepositoryUrls(), true)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Path to local maven repo
|
69
|
+
#
|
70
|
+
# @return [String] path to local repo
|
71
|
+
def local_repo_path
|
72
|
+
@resolver.getLocalRepoPath()
|
73
|
+
end
|
74
|
+
|
75
|
+
# Set path to local maven repo
|
76
|
+
#
|
77
|
+
# @param [String] path local repo
|
78
|
+
def local_repo_path=( path )
|
79
|
+
@resolver.setLocalRepoPath( path )
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Add a local Build Artifact, that will be used in the Dependency Resolution
|
84
|
+
#
|
85
|
+
# @param [String] notation
|
86
|
+
# @param [String] path to artifact
|
87
|
+
# @param [String] pom optional path to pom.xml
|
88
|
+
#
|
89
|
+
def add_build_artifact( notation, path, pom = nil )
|
90
|
+
@resolver.addBuildArtifact(notation, path, pom )
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# Set local Build Artifacts, that will be used in the Dependency Resolution
|
95
|
+
#
|
96
|
+
# @param [Array<Hash>] artifacts of Hashs with { notation => path } or { notation => { :path => path, :pom => pom_path }
|
97
|
+
#
|
98
|
+
def build_artifacts=( artifacts )
|
99
|
+
@resolver.clearBuildArtifacts()
|
100
|
+
|
101
|
+
unless artifacts.is_a? Array
|
102
|
+
artifacts = [artifacts]
|
103
|
+
end
|
104
|
+
|
105
|
+
artifacts.each do |artifact|
|
106
|
+
# Hash of notation => path or notation => { :path =>, :pom => }
|
107
|
+
if artifact.is_a? Hash
|
108
|
+
|
109
|
+
notation, opts = artifact.shift
|
110
|
+
|
111
|
+
if opts.is_a? Hash
|
112
|
+
@resolver.add_build_artifact( notation, opts[:path], opts[:pom] )
|
113
|
+
else
|
114
|
+
@resolver.add_build_artifact( notation, opts )
|
115
|
+
end
|
116
|
+
|
117
|
+
else
|
118
|
+
raise "invalid build_artifacts format"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# Get Build Artifacts
|
125
|
+
#
|
126
|
+
# @return [Array] of build artifacts
|
127
|
+
#
|
128
|
+
def build_artifacts
|
129
|
+
Naether::Java.convert_to_ruby_array( @resolver.getBuildArtifacts() )
|
130
|
+
end
|
131
|
+
|
132
|
+
# Add a dependency
|
133
|
+
#
|
134
|
+
# @param [String] notation in the format of groupId:artifactId:version
|
135
|
+
# @param [String] scope valid options are compile,test,runtime
|
136
|
+
# @see https://github.com/mguymon/naether/wiki/Notations
|
137
|
+
def add_notation_dependency( notation, scope='compile' )
|
138
|
+
@resolver.addDependency( notation, scope )
|
139
|
+
end
|
140
|
+
|
141
|
+
# Add dependencies from a Maven POM
|
142
|
+
#
|
143
|
+
# @param [String] pom_path
|
144
|
+
# @param [Array<String>] scopes valid options are compile,test,runtime
|
145
|
+
def add_pom_dependencies( pom_path, scopes=['compile'] )
|
146
|
+
if Naether.platform == 'java'
|
147
|
+
@resolver.addDependencies( pom_path, scopes )
|
148
|
+
else
|
149
|
+
list = Naether::Java.convert_to_java_list( scopes )
|
150
|
+
@resolver._invoke( 'addDependencies', 'Ljava.lang.String;Ljava.util.List;', pom_path, list )
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# Add a dependency of org.sonatype.aether.graph.Dependency
|
155
|
+
#
|
156
|
+
# @param [org.sonatype.aether.graph.Dependency] dependency
|
157
|
+
def add_dependency( dependency )
|
158
|
+
#@resolver.addDependency( dependency )
|
159
|
+
if Naether.platform == 'java'
|
160
|
+
@resolver.addDependency( dependency )
|
161
|
+
else
|
162
|
+
@resolver._invoke('addDependency', 'Lorg.sonatype.aether.graph.Dependency;', dependency)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Set the dependencies
|
167
|
+
#
|
168
|
+
# The dependencies param takes an [Array] of mixed dependencies:
|
169
|
+
# * [String] Artifact notation, such as groupId:artifactId:version, e.g. 'junit:junit:4.7'
|
170
|
+
# * [Hash] of a single artifaction notation => scope - { 'junit:junit:4.7' => 'test' }
|
171
|
+
# * [String] path to a local pom - 'lib/pom.xml'
|
172
|
+
# * [Hash] of a single path to a local pom => scope - { 'lib/pom.xml' => ['compile','test'] }
|
173
|
+
#
|
174
|
+
# @param [Array] dependencies
|
175
|
+
# @see https://github.com/mguymon/naether/wiki/Notations
|
176
|
+
def dependencies=(dependencies)
|
177
|
+
@resolver.clearDependencies()
|
178
|
+
|
179
|
+
unless dependencies.is_a? Array
|
180
|
+
dependencies = [dependencies]
|
181
|
+
end
|
182
|
+
|
183
|
+
dependencies.each do |dependent|
|
184
|
+
# Hash of notation => scope
|
185
|
+
if dependent.is_a? Hash
|
186
|
+
key = dependent.keys.first
|
187
|
+
|
188
|
+
# Add pom dependencies with scopes
|
189
|
+
if key =~ /\.xml$/i
|
190
|
+
scopes = nil
|
191
|
+
if dependent[key].is_a? Array
|
192
|
+
scopes = dependent[key]
|
193
|
+
else
|
194
|
+
scopes = [dependent[key]]
|
195
|
+
end
|
196
|
+
|
197
|
+
add_pom_dependencies( key, scopes )
|
198
|
+
|
199
|
+
# Add a dependency notation with scopes
|
200
|
+
else
|
201
|
+
add_notation_dependency( key, dependent[key] )
|
202
|
+
end
|
203
|
+
|
204
|
+
elsif dependent.is_a? String
|
205
|
+
|
206
|
+
# Add pom dependencies with default scopes
|
207
|
+
if dependent =~ /\.xml$/i
|
208
|
+
add_pom_dependencies( dependent )
|
209
|
+
|
210
|
+
# Add a dependency notation with compile scope
|
211
|
+
else
|
212
|
+
add_notation_dependency( dependent, 'compile' )
|
213
|
+
end
|
214
|
+
|
215
|
+
# Add an Aether dependency
|
216
|
+
else
|
217
|
+
add_dependency( dependent )
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
# Get array of dependencies
|
223
|
+
#
|
224
|
+
# @return [Array]
|
225
|
+
def dependencies
|
226
|
+
Naether::Java.convert_to_ruby_array( @resolver.currentDependencies() )
|
227
|
+
end
|
228
|
+
|
229
|
+
# Get array of dependencies as notation
|
230
|
+
#
|
231
|
+
# @return [Array<String>] of notations
|
232
|
+
# @see https://github.com/mguymon/naether/wiki/Notations
|
233
|
+
def dependencies_notation
|
234
|
+
Naether::Java.convert_to_ruby_array(@resolver.getDependenciesNotation(), true)
|
235
|
+
end
|
236
|
+
|
237
|
+
# Hash of dependency paths
|
238
|
+
#
|
239
|
+
# @return [Array<Hash>] of { notation => path }
|
240
|
+
def dependencies_path
|
241
|
+
Naether::Java.convert_to_ruby_hash( @resolver.getDependenciesPath(), true )
|
242
|
+
end
|
243
|
+
|
244
|
+
# Convert dependencies to Classpath friendly string
|
245
|
+
#
|
246
|
+
# @return [String]
|
247
|
+
def dependencies_classpath
|
248
|
+
@resolver.getResolvedClassPath()
|
249
|
+
end
|
250
|
+
|
251
|
+
# Dependencies as a Graph of nested Hashes
|
252
|
+
#
|
253
|
+
# @return [Hash]
|
254
|
+
def dependencies_graph(nodes=nil)
|
255
|
+
nodes = @resolver.getDependenciesGraph() unless nodes
|
256
|
+
|
257
|
+
graph = {}
|
258
|
+
if Naether.platform == 'java'
|
259
|
+
nodes.each do |k,v|
|
260
|
+
deps = dependencies_graph(v)
|
261
|
+
graph[k] = Naether::Java.convert_to_ruby_hash( deps )
|
262
|
+
end
|
263
|
+
else
|
264
|
+
iterator = nodes.entrySet().iterator();
|
265
|
+
while iterator.hasNext()
|
266
|
+
entry = iterator.next()
|
267
|
+
deps = dependencies_graph(entry.getValue())
|
268
|
+
graph[entry.getKey().toString()] = Naether::Java.convert_to_ruby_hash( deps )
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
graph
|
273
|
+
end
|
274
|
+
|
275
|
+
# Load dependencies to Classpath
|
276
|
+
#
|
277
|
+
# @return [Array] of loaded jars
|
278
|
+
def load_dependencies_to_classpath
|
279
|
+
jars = dependencies_classpath.split(":")
|
280
|
+
Naether::Java.load_jars(jars)
|
281
|
+
|
282
|
+
jars
|
283
|
+
end
|
284
|
+
|
285
|
+
# Resolve dependencies
|
286
|
+
#
|
287
|
+
# @return [Array<String>] of notations
|
288
|
+
# @see https://github.com/mguymon/naether/wiki/Notations
|
289
|
+
def resolve_dependencies( download_artifacts = true, properties = nil )
|
290
|
+
|
291
|
+
if properties
|
292
|
+
# Convert to HashMap
|
293
|
+
map = Naether::Java.create( "java.util.HashMap" )
|
294
|
+
properties.each do |k,v|
|
295
|
+
map.put( k, v )
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
@resolver.resolveDependencies( download_artifacts, map );
|
300
|
+
dependencies_notation
|
301
|
+
end
|
302
|
+
|
303
|
+
# Convert notations to local paths of artifacts
|
304
|
+
#
|
305
|
+
# @param [Array<String>] notations
|
306
|
+
# @return [Array<String>] of paths to artifacts
|
307
|
+
# @see https://github.com/mguymon/naether/wiki/Notations
|
308
|
+
def to_local_paths( notations )
|
309
|
+
if Naether.platform == 'java'
|
310
|
+
Naether::Java.convert_to_ruby_array(
|
311
|
+
Naether::Java.exec_static_method(
|
312
|
+
'com.tobedevoured.naether.util.Notation',
|
313
|
+
'getLocalPaths',
|
314
|
+
[local_repo_path, notations ],
|
315
|
+
['java.lang.String', 'java.util.List'] ) )
|
316
|
+
else
|
317
|
+
paths = Naether::Java.exec_static_method(
|
318
|
+
'com.tobedevoured.naether.util.Notation',
|
319
|
+
'getLocalPaths',
|
320
|
+
[local_repo_path, Naether::Java.convert_to_java_list(notations) ],
|
321
|
+
['java.lang.String', 'java.util.List'] )
|
322
|
+
Naether::Java.convert_to_ruby_array( paths, true )
|
323
|
+
end
|
324
|
+
|
325
|
+
end
|
326
|
+
|
327
|
+
# Download artifacts
|
328
|
+
#
|
329
|
+
# @param [Array<String>] notations
|
330
|
+
# @return [Array<String>] of paths of downloaded artifacts
|
331
|
+
def download_artifacts( notations )
|
332
|
+
if( notations.is_a? String )
|
333
|
+
notations = [notations]
|
334
|
+
end
|
335
|
+
|
336
|
+
files = nil
|
337
|
+
if Naether.platform == 'java'
|
338
|
+
files = @resolver.downloadArtifacts( notations )
|
339
|
+
else
|
340
|
+
list = Naether::Java.convert_to_java_list( notations )
|
341
|
+
files = @resolver._invoke('downloadArtifacts', 'Ljava.util.List;', list)
|
342
|
+
end
|
343
|
+
|
344
|
+
paths = []
|
345
|
+
Naether::Java.convert_to_ruby_array(files).each do |file|
|
346
|
+
paths << file.getAbsolutePath();
|
347
|
+
end
|
348
|
+
|
349
|
+
paths
|
350
|
+
end
|
351
|
+
|
352
|
+
|
353
|
+
# Deploy artifact to remote repo url
|
354
|
+
#
|
355
|
+
# @param [String] notation
|
356
|
+
# @param [String] file_path to artifact to deploy
|
357
|
+
# @param [String] url to deploy to
|
358
|
+
# @param [Hash] opts
|
359
|
+
# @option opts [String] :pom_path path to pom.xml
|
360
|
+
# @option opts [String] :username for optional auth
|
361
|
+
# @option opts [String] :password for optional auth
|
362
|
+
# @option opts [String] :pub_key for optional auth
|
363
|
+
# @option opts [String] :pub_key_passphrase for optional auth
|
364
|
+
def deploy_artifact( notation, file_path, url, opts = {} )
|
365
|
+
artifact = Naether::Java.create( "com.tobedevoured.naether.deploy.DeployArtifact" )
|
366
|
+
|
367
|
+
artifact.setRemoteRepo( url )
|
368
|
+
artifact.setNotation( notation )
|
369
|
+
artifact.setFilePath( file_path )
|
370
|
+
if opts[:pom_path]
|
371
|
+
artifact.setPomPath( opts[:pom_path] )
|
372
|
+
end
|
373
|
+
|
374
|
+
if opts[:username] || opts[:pub_key]
|
375
|
+
artifact.setAuth(opts[:username], opts[:password], opts[:pub_key], opts[:pub_key_passphrase] )
|
376
|
+
end
|
377
|
+
if Naether.platform == 'java'
|
378
|
+
@resolver.deployArtifact(artifact)
|
379
|
+
else
|
380
|
+
@resolver._invoke( 'deployArtifact', 'Lcom.tobedevoured.naether.deploy.DeployArtifact;', artifact )
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
# Install artifact or pom to local repo, must specify pom_path and/or jar_path
|
385
|
+
#
|
386
|
+
# @param [String] notation
|
387
|
+
# @param [String] pom_path
|
388
|
+
# @param [String] jar_path
|
389
|
+
def install( notation, pom_path =nil, jar_path = nil )
|
390
|
+
@resolver.install(notation, pom_path, jar_path)
|
391
|
+
end
|
392
|
+
|
393
|
+
# Set Log level for Naether Java logging
|
394
|
+
#
|
395
|
+
# @param [String] level to debug, info, warn, or error
|
396
|
+
def set_log_level( level )
|
397
|
+
Naether::Java.exec_static_method('com.tobedevoured.naether.util.LogUtil', 'changeLevel', ['com.tobedevoured', level] )
|
398
|
+
end
|
399
|
+
end
|
400
|
+
end
|