Class: Naether::Runtime
- Inherits:
-
Object
- Object
- Naether::Runtime
- Defined in:
- lib/naether/runtime.rb
Instance Attribute Summary collapse
-
#resolver ⇒ Object
readonly
Returns the value of attribute resolver.
Instance Method Summary collapse
-
#add_build_artifact(notation, path, pom = nil) ⇒ Object
Add a local Build Artifact, that will be used in the Dependency Resolution.
-
#add_dependency(dependency) ⇒ Object
Add a dependency of org.sonatype.aether.graph.Dependency.
-
#add_notation_dependency(notation, scope = 'compile') ⇒ Object
Add a dependency.
-
#add_pom_dependencies(pom_path, scopes = ['compile']) ⇒ Object
Add dependencies from a Maven POM.
-
#add_remote_repository(url, username = nil, password = nil) ⇒ Object
Add remote repository.
-
#build_artifacts ⇒ Array
Get Build Artifacts.
-
#build_artifacts=(artifacts) ⇒ Object
Set local Build Artifacts, that will be used in the Dependency Resolution.
-
#clear_remote_repositories ⇒ Object
Clear all remote repositories.
-
#dependencies ⇒ Array
Get array of dependencies.
-
#dependencies=(dependencies) ⇒ Object
Set the dependencies.
-
#dependencies_classpath ⇒ String
Convert dependencies to Classpath friendly string.
-
#dependencies_graph(nodes = nil) ⇒ Hash
Dependencies as a Graph of nested Hashes.
-
#dependencies_notation ⇒ Array<String>
Get array of dependencies as notation.
-
#dependencies_path ⇒ Array<Hash>
Hash of dependency paths.
-
#deploy_artifact(notation, file_path, url, opts = {}) ⇒ Object
Deploy artifact to remote repo url.
-
#download_artifacts(notations) ⇒ Array<String>
Download artifacts.
-
#initialize ⇒ Runtime
constructor
Create new instance.
-
#install(notation, pom_path = nil, jar_path = nil) ⇒ Object
Install artifact or pom to local repo, must specify pom_path and/or jar_path.
-
#load_dependencies_to_classpath ⇒ Array
Load dependencies to Classpath.
-
#local_repo_path ⇒ String
Path to local maven repo.
-
#local_repo_path=(path) ⇒ Object
Set path to local maven repo.
-
#remote_repositories ⇒ Array
Get remote repositories.
-
#remote_repository_urls ⇒ Array<String>
Get remote repositories as urls.
-
#resolve_dependencies(download_artifacts = true, properties = nil) ⇒ Array<String>
Resolve dependencies.
-
#set_log_level(level) ⇒ Object
Set Log level for Naether Java logging.
-
#to_local_paths(notations) ⇒ Array<String>
Convert notations to local paths of artifacts.
Constructor Details
Instance Attribute Details
#resolver ⇒ Object (readonly)
Returns the value of attribute resolver.
29 30 31 |
# File 'lib/naether/runtime.rb', line 29 def resolver @resolver end |
Instance Method Details
#add_build_artifact(notation, path, pom = nil) ⇒ Object
Add a local Build Artifact, that will be used in the Dependency Resolution
89 90 91 |
# File 'lib/naether/runtime.rb', line 89 def add_build_artifact( notation, path, pom = nil ) @resolver.addBuildArtifact(notation, path, pom ) end |
#add_dependency(dependency) ⇒ Object
Add a dependency of org.sonatype.aether.graph.Dependency
157 158 159 160 161 162 163 164 |
# File 'lib/naether/runtime.rb', line 157 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 |
#add_notation_dependency(notation, scope = 'compile') ⇒ Object
Add a dependency
137 138 139 |
# File 'lib/naether/runtime.rb', line 137 def add_notation_dependency( notation, scope='compile' ) @resolver.addDependency( notation, scope ) end |
#add_pom_dependencies(pom_path, scopes = ['compile']) ⇒ Object
Add dependencies from a Maven POM
145 146 147 148 149 150 151 152 |
# File 'lib/naether/runtime.rb', line 145 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 |
#add_remote_repository(url, username = nil, password = nil) ⇒ Object
Add remote repository
46 47 48 49 50 51 52 |
# File 'lib/naether/runtime.rb', line 46 def add_remote_repository( url, username = nil, password = nil ) if username @resolver.addRemoteRepositoryByUrl( url, username, password ) else @resolver.addRemoteRepositoryByUrl( url ) end end |
#build_artifacts ⇒ Array
Get Build Artifacts
128 129 130 |
# File 'lib/naether/runtime.rb', line 128 def build_artifacts Naether::Java.convert_to_ruby_array( @resolver.getBuildArtifacts() ) end |
#build_artifacts=(artifacts) ⇒ Object
Set local Build Artifacts, that will be used in the Dependency Resolution
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/naether/runtime.rb', line 98 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 |
#clear_remote_repositories ⇒ Object
Clear all remote repositories
37 38 39 |
# File 'lib/naether/runtime.rb', line 37 def clear_remote_repositories @resolver.clearRemoteRepositories() end |
#dependencies ⇒ Array
Get array of dependencies
225 226 227 |
# File 'lib/naether/runtime.rb', line 225 def dependencies Naether::Java.convert_to_ruby_array( @resolver.currentDependencies() ) end |
#dependencies=(dependencies) ⇒ Object
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'] }
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/naether/runtime.rb', line 176 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 |
#dependencies_classpath ⇒ String
Convert dependencies to Classpath friendly string
247 248 249 |
# File 'lib/naether/runtime.rb', line 247 def dependencies_classpath @resolver.getResolvedClassPath() end |
#dependencies_graph(nodes = nil) ⇒ Hash
Dependencies as a Graph of nested Hashes
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/naether/runtime.rb', line 254 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 |
#dependencies_notation ⇒ Array<String>
Get array of dependencies as notation
233 234 235 |
# File 'lib/naether/runtime.rb', line 233 def dependencies_notation Naether::Java.convert_to_ruby_array(@resolver.getDependenciesNotation(), true) end |
#dependencies_path ⇒ Array<Hash>
Hash of dependency paths
240 241 242 |
# File 'lib/naether/runtime.rb', line 240 def dependencies_path Naether::Java.convert_to_ruby_hash( @resolver.getDependenciesPath(), true ) end |
#deploy_artifact(notation, file_path, url, opts = {}) ⇒ Object
Deploy artifact to remote repo url
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/naether/runtime.rb', line 364 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 |
#download_artifacts(notations) ⇒ Array<String>
Download artifacts
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/naether/runtime.rb', line 331 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 |
#install(notation, pom_path = nil, jar_path = nil) ⇒ Object
Install artifact or pom to local repo, must specify pom_path and/or jar_path
389 390 391 |
# File 'lib/naether/runtime.rb', line 389 def install( notation, pom_path =nil, jar_path = nil ) @resolver.install(notation, pom_path, jar_path) end |
#load_dependencies_to_classpath ⇒ Array
Load dependencies to Classpath
278 279 280 281 282 283 |
# File 'lib/naether/runtime.rb', line 278 def load_dependencies_to_classpath jars = dependencies_classpath.split(File::PATH_SEPARATOR) Naether::Java.load_jars(jars) jars end |
#local_repo_path ⇒ String
Path to local maven repo
71 72 73 |
# File 'lib/naether/runtime.rb', line 71 def local_repo_path @resolver.getLocalRepoPath() end |
#local_repo_path=(path) ⇒ Object
Set path to local maven repo
78 79 80 |
# File 'lib/naether/runtime.rb', line 78 def local_repo_path=( path ) @resolver.setLocalRepoPath( path ) end |
#remote_repositories ⇒ Array
Get remote repositories
57 58 59 |
# File 'lib/naether/runtime.rb', line 57 def remote_repositories Naether::Java.convert_to_ruby_array(@resolver.getRemoteRepositories()) end |
#remote_repository_urls ⇒ Array<String>
Get remote repositories as urls
64 65 66 |
# File 'lib/naether/runtime.rb', line 64 def remote_repository_urls Naether::Java.convert_to_ruby_array(@resolver.getRemoteRepositoryUrls(), true) end |
#resolve_dependencies(download_artifacts = true, properties = nil) ⇒ Array<String>
Resolve dependencies
289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/naether/runtime.rb', line 289 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 |
#set_log_level(level) ⇒ Object
Set Log level for Naether Java logging
396 397 398 |
# File 'lib/naether/runtime.rb', line 396 def set_log_level( level ) Naether::Java.exec_static_method('com.tobedevoured.naether.util.LogUtil', 'changeLevel', ['com.tobedevoured', level] ) end |
#to_local_paths(notations) ⇒ Array<String>
Convert notations to local paths of artifacts
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/naether/runtime.rb', line 308 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 |