Class: Naether
- Inherits:
-
Object
- Object
- Naether
- Defined in:
- lib/naether.rb,
lib/naether/java.rb,
lib/naether/maven.rb,
lib/naether/notation.rb,
lib/naether/bootstrap.rb,
lib/naether/java/ruby.rb,
lib/naether/java/jruby.rb,
lib/naether/configuration.rb
Overview
Defined Under Namespace
Classes: Bootstrap, Configurator, Java, Maven, Notation
Instance Attribute Summary (collapse)
-
- (Object) resolver
readonly
Returns the value of attribute resolver.
Class Method Summary (collapse)
-
+ (Object) bootstrap_dependencies(dep_file = nil)
List of Java dependencies needed to bootstrap Naether.
-
+ (Naether) create_from_jars(jars)
Loads all jars creates a new instance of Naether.
-
+ (Object) platform
Helper for platform detection.
Instance Method Summary (collapse)
-
- (Object) add_build_artifact(notation, path, pom = nil)
Add a local Build Artifact, that will be used in the Dependency Resolution.
-
- (Object) add_dependency(dependency)
Add a dependency of org.sonatype.aether.graph.Dependency.
-
- (Object) add_notation_dependency(notation, scope = 'compile')
Add a dependency.
-
- (Object) add_pom_dependencies(pom_path, scopes = ['compile'])
Add dependencies from a Maven POM.
-
- (Object) add_remote_repository(url, username = nil, password = nil)
Add remote repository.
-
- (Array) build_artifacts
Get Build Artifacts.
-
- (Object) build_artifacts=(artifacts)
Set local Build Artifacts, that will be used in the Dependency Resolution.
-
- (Object) clear_remote_repositories
Clear all remote repositories.
-
- (Array) dependencies
Get array of dependencies.
-
- (Object) dependencies=(dependencies)
Set the dependencies.
-
- (String) dependencies_classpath
Convert dependencies to Classpath friendly string.
-
- (Hash) dependencies_graph(nodes = nil)
Dependencies as a Graph of nested Hashes.
-
- (Array<String>) dependencies_notation
Get array of dependencies as notation.
-
- (Array<Hash>) dependencies_path
Hash of dependency paths.
-
- (Object) deploy_artifact(notation, file_path, url, opts = {})
Deploy artifact to remote repo url.
-
- (Array<String>) download_artifacts(notations)
Download artifacts.
-
- (Naether) initialize
constructor
Create new instance.
-
- (Object) install(notation, pom_path = nil, jar_path = nil)
Install artifact or pom to local repo, must specify pom_path and/or jar_path.
-
- (Array) load_dependencies_to_classpath
Load dependencies to Classpath.
-
- (String) local_repo_path
Path to local maven repo.
-
- (Object) local_repo_path=(path)
Set path to local maven repo.
-
- (Array) remote_repositories
Get remote repositories.
-
- (Array<String>) remote_repository_urls
Get remote repositories as urls.
-
- (Array<String>) resolve_dependencies(download_artifacts = true, properties = nil)
Resolve dependencies.
-
- (Object) set_log_level(level)
Set Log level for Naether Java logging.
-
- (Array<String>) to_local_paths(notations)
Convert notations to local paths of artifacts.
Constructor Details
- (Naether) initialize
Create new instance.
60 61 62 |
# File 'lib/naether.rb', line 60 def initialize @resolver = Naether::Java.create('com.tobedevoured.naether.impl.NaetherImpl') end |
Instance Attribute Details
- (Object) resolver (readonly)
Returns the value of attribute resolver
28 29 30 |
# File 'lib/naether.rb', line 28 def resolver @resolver end |
Class Method Details
+ (Object) bootstrap_dependencies(dep_file = nil)
List of Java dependencies needed to bootstrap Naether
36 37 38 |
# File 'lib/naether.rb', line 36 def bootstrap_dependencies( dep_file=nil ) Naether::Bootstrap.dependencies( dep_file ) end |
+ (Naether) create_from_jars(jars)
Loads all jars creates a new instance of Naether
52 53 54 55 |
# File 'lib/naether.rb', line 52 def create_from_jars( jars ) Naether::Java.internal_load_paths( jars ) Naether.new end |
+ (Object) platform
Helper for platform detection
43 44 45 |
# File 'lib/naether.rb', line 43 def platform Naether::Configuration.platform end |
Instance Method Details
- (Object) add_build_artifact(notation, path, pom = nil)
Add a local Build Artifact, that will be used in the Dependency Resolution
117 118 119 |
# File 'lib/naether.rb', line 117 def add_build_artifact( notation, path, pom = nil ) @resolver.addBuildArtifact(notation, path, pom ) end |
- (Object) add_dependency(dependency)
Add a dependency of org.sonatype.aether.graph.Dependency
185 186 187 188 189 190 191 192 |
# File 'lib/naether.rb', line 185 def add_dependency( dependency ) #@resolver.addDependency( dependency ) if Naether.platform == 'java' @resolver.addDependency( dependency ) else @resolver._invoke('addDependency', 'Lorg.sonatype.aether.graph.Dependency;', dependency) end end |
- (Object) add_notation_dependency(notation, scope = 'compile')
Add a dependency
165 166 167 |
# File 'lib/naether.rb', line 165 def add_notation_dependency( notation, scope='compile' ) @resolver.addDependency( notation, scope ) end |
- (Object) add_pom_dependencies(pom_path, scopes = ['compile'])
Add dependencies from a Maven POM
173 174 175 176 177 178 179 180 |
# File 'lib/naether.rb', line 173 def add_pom_dependencies( pom_path, scopes=['compile'] ) if Naether.platform == 'java' @resolver.addDependencies( pom_path, scopes ) else list = Naether::Java.convert_to_java_list( scopes ) @resolver._invoke( 'addDependencies', 'Ljava.lang.String;Ljava.util.List;', pom_path, list ) end end |
- (Object) add_remote_repository(url, username = nil, password = nil)
Add remote repository
74 75 76 77 78 79 80 |
# File 'lib/naether.rb', line 74 def add_remote_repository( url, username = nil, password = nil ) if username @resolver.addRemoteRepositoryByUrl( url, username, password ) else @resolver.addRemoteRepositoryByUrl( url ) end end |
- (Array) build_artifacts
Get Build Artifacts
156 157 158 |
# File 'lib/naether.rb', line 156 def build_artifacts Naether::Java.convert_to_ruby_array( @resolver.getBuildArtifacts() ) end |
- (Object) build_artifacts=(artifacts)
Set local Build Artifacts, that will be used in the Dependency Resolution
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/naether.rb', line 126 def build_artifacts=( artifacts ) @resolver.clearBuildArtifacts() unless artifacts.is_a? Array artifacts = [artifacts] end artifacts.each do |artifact| # Hash of notation => path or notation => { :path =>, :pom => } if artifact.is_a? Hash notation, opts = artifact.shift if opts.is_a? Hash @resolver.add_build_artifact( notation, opts[:path], opts[:pom] ) else @resolver.add_build_artifact( notation, opts ) end else raise "invalid build_artifacts format" end end end |
- (Object) clear_remote_repositories
Clear all remote repositories
65 66 67 |
# File 'lib/naether.rb', line 65 def clear_remote_repositories @resolver.clearRemoteRepositories() end |
- (Array) dependencies
Get array of dependencies
253 254 255 |
# File 'lib/naether.rb', line 253 def dependencies Naether::Java.convert_to_ruby_array( @resolver.currentDependencies() ) end |
- (Object) dependencies=(dependencies)
Set the dependencies
The dependencies param takes an [Array] of mixed dependencies:
* [String] Artifact notation, such as groupId:artifactId:version, e.g. 'junit:junit:4.7' * [Hash] of a single artifaction notation => scope - { 'junit:junit:4.7' => 'test' } * [String] path to a local pom - 'lib/pom.xml' * [Hash] of a single path to a local pom => scope - { 'lib/pom.xml' => ['compile','test'] }
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/naether.rb', line 204 def dependencies=(dependencies) @resolver.clearDependencies() unless dependencies.is_a? Array dependencies = [dependencies] end dependencies.each do |dependent| # Hash of notation => scope if dependent.is_a? Hash key = dependent.keys.first # Add pom dependencies with scopes if key =~ /\.xml$/i scopes = nil if dependent[key].is_a? Array scopes = dependent[key] else scopes = [dependent[key]] end add_pom_dependencies( key, scopes ) # Add a dependency notation with scopes else add_notation_dependency( key, dependent[key] ) end elsif dependent.is_a? String # Add pom dependencies with default scopes if dependent =~ /\.xml$/i add_pom_dependencies( dependent ) # Add a dependency notation with compile scope else add_notation_dependency( dependent, 'compile' ) end # Add an Aether dependency else add_dependency( dependent ) end end end |
- (String) dependencies_classpath
Convert dependencies to Classpath friendly string
275 276 277 |
# File 'lib/naether.rb', line 275 def dependencies_classpath @resolver.getResolvedClassPath() end |
- (Hash) dependencies_graph(nodes = nil)
Dependencies as a Graph of nested Hashes
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/naether.rb', line 282 def dependencies_graph(nodes=nil) nodes = @resolver.getDependenciesGraph() unless nodes graph = {} if Naether.platform == 'java' nodes.each do |k,v| deps = dependencies_graph(v) graph[k] = Naether::Java.convert_to_ruby_hash( deps ) end else iterator = nodes.entrySet().iterator(); while iterator.hasNext() entry = iterator.next() deps = dependencies_graph(entry.getValue()) graph[entry.getKey().toString()] = Naether::Java.convert_to_ruby_hash( deps ) end end graph end |
- (Array<String>) dependencies_notation
Get array of dependencies as notation
261 262 263 |
# File 'lib/naether.rb', line 261 def dependencies_notation Naether::Java.convert_to_ruby_array(@resolver.getDependenciesNotation(), true) end |
- (Array<Hash>) dependencies_path
Hash of dependency paths
268 269 270 |
# File 'lib/naether.rb', line 268 def dependencies_path Naether::Java.convert_to_ruby_hash( @resolver.getDependenciesPath(), true ) end |
- (Object) deploy_artifact(notation, file_path, url, opts = {})
Deploy artifact to remote repo url
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/naether.rb', line 392 def deploy_artifact( notation, file_path, url, opts = {} ) artifact = Naether::Java.create( "com.tobedevoured.naether.deploy.DeployArtifact" ) artifact.setRemoteRepo( url ) artifact.setNotation( notation ) artifact.setFilePath( file_path ) if opts[:pom_path] artifact.setPomPath( opts[:pom_path] ) end if opts[:username] || opts[:pub_key] artifact.setAuth(opts[:username], opts[:password], opts[:pub_key], opts[:pub_key_passphrase] ) end if Naether.platform == 'java' @resolver.deployArtifact(artifact) else @resolver._invoke( 'deployArtifact', 'Lcom.tobedevoured.naether.deploy.DeployArtifact;', artifact ) end end |
- (Array<String>) download_artifacts(notations)
Download artifacts
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/naether.rb', line 359 def download_artifacts( notations ) if( notations.is_a? String ) notations = [notations] end files = nil if Naether.platform == 'java' files = @resolver.downloadArtifacts( notations ) else list = Naether::Java.convert_to_java_list( notations ) files = @resolver._invoke('downloadArtifacts', 'Ljava.util.List;', list) end paths = [] Naether::Java.convert_to_ruby_array(files).each do |file| paths << file.getAbsolutePath(); end paths end |
- (Object) install(notation, pom_path = nil, jar_path = nil)
Install artifact or pom to local repo, must specify pom_path and/or jar_path
417 418 419 |
# File 'lib/naether.rb', line 417 def install( notation, pom_path =nil, jar_path = nil ) @resolver.install(notation, pom_path, jar_path) end |
- (Array) load_dependencies_to_classpath
Load dependencies to Classpath
306 307 308 309 310 311 |
# File 'lib/naether.rb', line 306 def load_dependencies_to_classpath jars = dependencies_classpath.split(":") Naether::Java.load_jars(jars) jars end |
- (String) local_repo_path
Path to local maven repo
99 100 101 |
# File 'lib/naether.rb', line 99 def local_repo_path @resolver.getLocalRepoPath() end |
- (Object) local_repo_path=(path)
Set path to local maven repo
106 107 108 |
# File 'lib/naether.rb', line 106 def local_repo_path=( path ) @resolver.setLocalRepoPath( path ) end |
- (Array) remote_repositories
Get remote repositories
85 86 87 |
# File 'lib/naether.rb', line 85 def remote_repositories Naether::Java.convert_to_ruby_array(@resolver.getRemoteRepositories()) end |
- (Array<String>) remote_repository_urls
Get remote repositories as urls
92 93 94 |
# File 'lib/naether.rb', line 92 def remote_repository_urls Naether::Java.convert_to_ruby_array(@resolver.getRemoteRepositoryUrls(), true) end |
- (Array<String>) resolve_dependencies(download_artifacts = true, properties = nil)
Resolve dependencies
317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/naether.rb', line 317 def resolve_dependencies( download_artifacts = true, properties = nil ) if properties # Convert to HashMap map = Naether::Java.create( "java.util.HashMap" ) properties.each do |k,v| map.put( k, v ) end end @resolver.resolveDependencies( download_artifacts, map ); dependencies_notation end |
- (Object) set_log_level(level)
Set Log level for Naether Java logging
424 425 426 |
# File 'lib/naether.rb', line 424 def set_log_level( level ) Naether::Java.exec_static_method('com.tobedevoured.naether.util.LogUtil', 'changeLevel', ['com.tobedevoured', level] ) end |
- (Array<String>) to_local_paths(notations)
Convert notations to local paths of artifacts
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/naether.rb', line 336 def to_local_paths( notations ) if Naether.platform == 'java' Naether::Java.convert_to_ruby_array( Naether::Java.exec_static_method( 'com.tobedevoured.naether.util.Notation', 'getLocalPaths', [local_repo_path, notations ], ['java.lang.String', 'java.util.List'] ) ) else paths = Naether::Java.exec_static_method( 'com.tobedevoured.naether.util.Notation', 'getLocalPaths', [local_repo_path, Naether::Java.convert_to_java_list(notations) ], ['java.lang.String', 'java.util.List'] ) Naether::Java.convert_to_ruby_array( paths, true ) end end |