Class: Naether
- Inherits:
-
Object
- Object
- Naether
- Defined in:
- lib/naether.rb,
lib/naether/java.rb,
lib/naether/maven.rb,
lib/naether/bootstrap.rb,
lib/naether/java/ruby.rb,
lib/naether/java/jruby.rb,
lib/naether/configuration.rb
Overview
Authors
Michael Guymon
Defined Under Namespace
Classes: Bootstrap, Configurator, Java, Maven
Instance Attribute Summary (collapse)
-
- (Object) resolver
readonly
Returns the value of attribute resolver.
Class Method Summary (collapse)
-
+ (Object) bootstrap_dependencies(dep_file = nil)
Helper for 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.
-
- (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.
-
- (Object) 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.
59 60 61 |
# File 'lib/naether.rb', line 59 def initialize @resolver = Naether::Java.create('com.tobedevoured.naether.Naether') end |
Instance Attribute Details
- (Object) resolver (readonly)
Returns the value of attribute resolver
27 28 29 |
# File 'lib/naether.rb', line 27 def resolver @resolver end |
Class Method Details
+ (Object) bootstrap_dependencies(dep_file = nil)
Helper for Java dependencies needed to bootstrap Naether
35 36 37 |
# File 'lib/naether.rb', line 35 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
51 52 53 54 |
# File 'lib/naether.rb', line 51 def create_from_jars( jars ) Naether::Java.internal_load_paths( jars ) Naether.new end |
+ (Object) platform
Helper for platform detection
42 43 44 |
# File 'lib/naether.rb', line 42 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
116 117 118 |
# File 'lib/naether.rb', line 116 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
184 185 186 187 188 189 190 191 |
# File 'lib/naether.rb', line 184 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
164 165 166 |
# File 'lib/naether.rb', line 164 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
172 173 174 175 176 177 178 179 |
# File 'lib/naether.rb', line 172 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
73 74 75 76 77 78 79 |
# File 'lib/naether.rb', line 73 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
155 156 157 |
# File 'lib/naether.rb', line 155 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
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/naether.rb', line 125 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
64 65 66 |
# File 'lib/naether.rb', line 64 def clear_remote_repositories @resolver.clearRemoteRepositories() end |
- (Array) dependencies
Get array of dependencies
252 253 254 |
# File 'lib/naether.rb', line 252 def dependencies Naether::Java.convert_to_ruby_array( @resolver.getDependencies() ) 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'] }
203 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 |
# File 'lib/naether.rb', line 203 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
274 275 276 |
# File 'lib/naether.rb', line 274 def dependencies_classpath() @resolver.getResolvedClassPath() end |
- (Array<String>) dependencies_notation
Get array of dependencies as notation
260 261 262 |
# File 'lib/naether.rb', line 260 def dependencies_notation Naether::Java.convert_to_ruby_array(@resolver.getDependenciesNotation(), true) end |
- (Array<Hash>) dependencies_path
Hash of dependency paths
267 268 269 |
# File 'lib/naether.rb', line 267 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
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/naether.rb', line 365 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
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/naether.rb', line 332 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
390 391 392 |
# File 'lib/naether.rb', line 390 def install( notation, pom_path =nil, jar_path = nil ) @resolver.install(notation, pom_path, jar_path) end |
- (Object) load_dependencies_to_classpath
Load dependencies to Classpath
279 280 281 282 283 284 |
# File 'lib/naether.rb', line 279 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
98 99 100 |
# File 'lib/naether.rb', line 98 def local_repo_path @resolver.getLocalRepoPath() end |
- (Object) local_repo_path=(path)
Set path to local maven repo
105 106 107 |
# File 'lib/naether.rb', line 105 def local_repo_path=( path ) @resolver.setLocalRepoPath( path ) end |
- (Array) remote_repositories
Get remote repositories
84 85 86 |
# File 'lib/naether.rb', line 84 def remote_repositories Naether::Java.convert_to_ruby_array(@resolver.getRemoteRepositories()) end |
- (Array<String>) remote_repository_urls
Get remote repositories as urls
91 92 93 |
# File 'lib/naether.rb', line 91 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
290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/naether.rb', line 290 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
397 398 399 |
# File 'lib/naether.rb', line 397 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
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/naether.rb', line 309 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 |