Module: Jars
- Defined in:
- lib/jar_dependencies.rb,
lib/jars/lock.rb,
lib/jars/version.rb,
lib/jars/classpath.rb,
lib/jars/installer.rb,
lib/jars/lock_down.rb,
lib/jars/maven_exec.rb,
lib/jars/maven_factory.rb,
lib/jars/gemspec_artifacts.rb
Overview
Copyright © 2014 Christian Meier
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Defined Under Namespace
Classes: Classpath, GemspecArtifacts, Installer, JarDetails, Lock, LockDown, MavenExec, MavenFactory, MavenVersion
Constant Summary collapse
- VERSION =
'0.3.2'.freeze
- JRUBY_PLUGINS_VERSION =
'1.1.3'.freeze
- DEPENDENCY_PLUGIN_VERSION =
'2.8'.freeze
- JarInstaller =
to stay backward compatible
Installer
- MAVEN_SETTINGS =
'JARS_MAVEN_SETTINGS'.freeze
- LOCAL_MAVEN_REPO =
'JARS_LOCAL_MAVEN_REPO'.freeze
- LOCK =
lock file to use
'JARS_LOCK'.freeze
- HOME =
where the locally stored jars are search for or stored
'JARS_HOME'.freeze
- SKIP =
skip the gem post install hook
'JARS_SKIP'.freeze
- SKIP_LOCK =
skip Jars.lock mainly to run lock_jars
'JARS_SKIP_LOCK'.freeze
- REQUIRE =
do not require any jars if set to false
'JARS_REQUIRE'.freeze
- NO_REQUIRE =
'JARS_NO_REQUIRE'.freeze
- QUIET =
no more warnings on conflict. this still requires jars but will not warn. it is needed to load jars from (default) gems which do contribute to any dependency manager (maven, gradle, jbundler)
'JARS_QUIET'.freeze
- VERBOSE =
show maven output
'JARS_VERBOSE'.freeze
- DEBUG =
maven debug
'JARS_DEBUG'.freeze
- VENDOR =
vendor jars inside gem when installing gem
'JARS_VENDOR'.freeze
Class Attribute Summary collapse
-
.require ⇒ Object
writeonly
Sets the attribute require.
Class Method Summary collapse
- .debug(msg = nil, &block) ⇒ Object
- .debug? ⇒ Boolean
- .freeze_loading ⇒ Object
- .home ⇒ Object
- .jarfile ⇒ Object
- .jars_lock_from_class_loader ⇒ Object
- .local_maven_repo ⇒ Object
- .lock ⇒ Object
- .lock_down(debug = false, verbose = false, options = {}) ⇒ Object
- .lock_path(basedir = nil) ⇒ Object
- .mark_as_required(group_id, artifact_id, *classifier_version) ⇒ Object
- .maven_global_settings ⇒ Object
- .maven_local_settings ⇒ Object
- .maven_settings ⇒ Object
- .maven_user_settings ⇒ Object
- .no_more_warnings ⇒ Object
- .no_require? ⇒ Boolean deprecated Deprecated.
- .quiet? ⇒ Boolean
- .require? ⇒ Boolean
- .require_jar(group_id, artifact_id, *classifier_version) ⇒ Object
- .require_jars_lock ⇒ Object
- .require_jars_lock!(scope = :runtime) ⇒ Object
- .reset ⇒ Object
- .setup(options = nil) ⇒ Object
- .skip? ⇒ Boolean
- .skip_lock? ⇒ Boolean
- .to_boolean(key) ⇒ Object
- .vendor? ⇒ Boolean
- .verbose? ⇒ Boolean
- .warn(msg = nil, &block) ⇒ Object
Instance Method Summary collapse
Class Attribute Details
.require=(value) ⇒ Object (writeonly)
Sets the attribute require
92 93 94 |
# File 'lib/jar_dependencies.rb', line 92 def require=(value) @require = value end |
Class Method Details
.debug(msg = nil, &block) ⇒ Object
296 297 298 |
# File 'lib/jar_dependencies.rb', line 296 def debug(msg = nil, &block) Kernel.warn(msg || block.call) if verbose? end |
.debug? ⇒ Boolean
109 110 111 |
# File 'lib/jar_dependencies.rb', line 109 def debug? to_boolean( DEBUG ) end |
.freeze_loading ⇒ Object
121 122 123 |
# File 'lib/jar_dependencies.rb', line 121 def freeze_loading self.require = false end |
.home ⇒ Object
218 219 220 |
# File 'lib/jar_dependencies.rb', line 218 def home @_jars_home_ ||= absolute(to_prop(HOME)) || local_maven_repo end |
.jarfile ⇒ Object
98 99 100 |
# File 'lib/jar_dependencies.rb', line 98 def jarfile ENV[ 'JARFILE' ] || ENV_JAVA[ 'jarfile' ] || ENV[ 'JBUNDLER_JARFILE' ] || ENV_JAVA[ 'jbundler.jarfile' ] || 'Jarfile' end |
.jars_lock_from_class_loader ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/jar_dependencies.rb', line 133 def jars_lock_from_class_loader if to_prop( LOCK ).nil? && defined?(JRUBY_VERSION) JRuby.runtime.jruby_class_loader.get_resources( 'Jars.lock' ).collect do |url| url.to_s end end end |
.local_maven_repo ⇒ Object
210 211 212 213 214 215 216 |
# File 'lib/jar_dependencies.rb', line 210 def local_maven_repo @_local_maven_repo ||= absolute(to_prop(LOCAL_MAVEN_REPO)) || detect_local_repository(maven_local_settings) || detect_local_repository(maven_user_settings) || detect_local_repository(maven_global_settings) || File.join( user_home, '.m2', 'repository' ) end |
.lock ⇒ Object
129 130 131 |
# File 'lib/jar_dependencies.rb', line 129 def lock to_prop( LOCK ) || 'Jars.lock' end |
.lock_down(debug = false, verbose = false, options = {}) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/jar_dependencies.rb', line 51 def lock_down( debug = false, verbose = false, = {} ) ENV[ SKIP_LOCK ] = 'true' require 'jars/lock_down' # do this lazy to keep things clean Jars::LockDown.new( debug, verbose ).lock_down( ) ensure ENV[ SKIP_LOCK ] = nil end |
.lock_path(basedir = nil) ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/jar_dependencies.rb', line 141 def lock_path( basedir = nil ) deps = self.lock return deps if File.exists?( deps ) basedir ||= '.' [ '.', 'jars', 'vendor/jars' ].each do |dir| file = File.join( basedir, dir, self.lock ) return file if File.exists?( file ) end nil end |
.mark_as_required(group_id, artifact_id, *classifier_version) ⇒ Object
280 281 282 283 |
# File 'lib/jar_dependencies.rb', line 280 def mark_as_required( group_id, artifact_id, *classifier_version ) require_jar_with_block( group_id, artifact_id, *classifier_version ) do end end |
.maven_global_settings ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/jar_dependencies.rb', line 194 def maven_global_settings unless instance_variable_defined?(:@_jars_maven_global_settings_) @_jars_maven_global_settings_ = nil end if @_jars_maven_global_settings_.nil? if mvn_home = ENV[ 'M2_HOME' ] || ENV[ 'MAVEN_HOME' ] settings = File.join( mvn_home, 'conf/settings.xml' ) settings = false unless File.exists?(settings) else settings = false end @_jars_maven_global_settings_ = settings end @_jars_maven_global_settings_ || nil end |
.maven_local_settings ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/jar_dependencies.rb', line 157 def maven_local_settings unless instance_variable_defined?(:@_jars_maven_local_settings_) @_jars_maven_local_settings_ = nil end if @_jars_maven_local_settings_.nil? if settings = absolute( 'settings.xml' ) if File.exists?(settings) @_jars_maven_local_settings_ = settings end end end @_jars_maven_local_settings_ || nil end |
.maven_settings ⇒ Object
190 191 192 |
# File 'lib/jar_dependencies.rb', line 190 def maven_settings maven_local_settings || maven_user_settings end |
.maven_user_settings ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/jar_dependencies.rb', line 171 def maven_user_settings unless instance_variable_defined?(:@_jars_maven_user_settings_) @_jars_maven_user_settings_ = nil end if @_jars_maven_user_settings_.nil? if settings = absolute( to_prop( MAVEN_SETTINGS ) ) unless File.exists?(settings) Jars.warn { "configured ENV['#{MAVEN_SETTINGS}'] = '#{settings}' not found" } settings = false end else # use maven default (user) settings settings = File.join( user_home, '.m2', 'settings.xml' ) settings = false unless File.exists?(settings) end @_jars_maven_user_settings_ = settings end @_jars_maven_user_settings_ || nil end |
.no_more_warnings ⇒ Object
117 118 119 |
# File 'lib/jar_dependencies.rb', line 117 def no_more_warnings @silent = true end |
.no_require? ⇒ Boolean
103 |
# File 'lib/jar_dependencies.rb', line 103 def no_require?; ! require? end |
.quiet? ⇒ Boolean
94 95 96 |
# File 'lib/jar_dependencies.rb', line 94 def quiet? ( @silent ||= false ) || to_boolean( QUIET ) end |
.require? ⇒ Boolean
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/jar_dependencies.rb', line 80 def require? @require = nil unless instance_variable_defined?(:@require) if @require.nil? if ( require = to_boolean( REQUIRE ) ).nil? no_require = to_boolean( NO_REQUIRE ) @require = no_require.nil? ? true : ! no_require else @require = require end end @require end |
.require_jar(group_id, artifact_id, *classifier_version) ⇒ Object
285 286 287 288 289 290 |
# File 'lib/jar_dependencies.rb', line 285 def require_jar( group_id, artifact_id, *classifier_version ) require_jars_lock unless skip_lock? require_jar_with_block( group_id, artifact_id, *classifier_version ) do |gid, aid, version, classifier| do_require( gid, aid, version, classifier ) end end |
.require_jars_lock ⇒ Object
272 273 274 275 276 277 278 |
# File 'lib/jar_dependencies.rb', line 272 def require_jars_lock @@jars_lock ||= false unless @@jars_lock require_jars_lock! @@jars_lock ||= true end end |
.require_jars_lock!(scope = :runtime) ⇒ Object
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 249 250 251 252 253 254 255 256 257 |
# File 'lib/jar_dependencies.rb', line 222 def require_jars_lock!( scope = :runtime ) urls = jars_lock_from_class_loader if urls and urls.size > 0 @@jars_lock = true # funny error during spec where it tries to load it again # and finds it as gem instead of the LOAD_PATH require 'jars/classpath' unless defined? Jars::Classpath done = [] while done != urls do urls.each do |url| unless done.member?( url ) Jars.debug { "--- load jars from uri #{url}" } classpath = Jars::Classpath.new( nil, "uri:#{url}" ) classpath.require( scope ) done << url end end urls = jars_lock_from_class_loader end no_more_warnings elsif jars_lock = Jars.lock_path Jars.debug { "--- load jars from #{jars_lock}" } @@jars_lock = jars_lock # funny error during spec where it tries to load it again # and finds it as gem instead of the LOAD_PATH require 'jars/classpath' unless defined? Jars::Classpath classpath = Jars::Classpath.new( nil, jars_lock ) classpath.require( scope ) no_more_warnings end Jars.debug { @@jars ||= {} loaded = @@jars.collect{ |k,v| "#{k}:#{v}" } "--- loaded jars ---\n\t#{loaded.join("\n\t")}" } end |
.reset ⇒ Object
152 153 154 155 |
# File 'lib/jar_dependencies.rb', line 152 def reset instance_variables.each { |var| instance_variable_set(var, nil) } ( @@jars ||= {} ).clear end |
.setup(options = nil) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/jar_dependencies.rb', line 259 def setup( = nil ) case when Symbol require_jars_lock!( ) when Hash @_jars_home = [:jars_home] @_jars_lock = [:jars_lock] require_jars_lock!( [:scope] || :runtime ) else require_jars_lock! end end |
.skip? ⇒ Boolean
76 77 78 |
# File 'lib/jar_dependencies.rb', line 76 def skip? to_boolean( SKIP ) end |
.skip_lock? ⇒ Boolean
125 126 127 |
# File 'lib/jar_dependencies.rb', line 125 def skip_lock? to_prop( SKIP_LOCK ) || false end |
.to_boolean(key) ⇒ Object
71 72 73 74 |
# File 'lib/jar_dependencies.rb', line 71 def to_boolean( key ) return nil if ( prop = to_prop( key ) ).nil? prop.empty? || prop.eql?('true') end |
.vendor? ⇒ Boolean
113 114 115 |
# File 'lib/jar_dependencies.rb', line 113 def vendor? to_boolean( VENDOR ) end |
.verbose? ⇒ Boolean
105 106 107 |
# File 'lib/jar_dependencies.rb', line 105 def verbose? to_boolean( VERBOSE ) end |
.warn(msg = nil, &block) ⇒ Object
292 293 294 |
# File 'lib/jar_dependencies.rb', line 292 def warn(msg = nil, &block) Kernel.warn(msg || block.call) unless quiet? and not verbose? end |
Instance Method Details
#to_prop(key) ⇒ Object
60 61 62 63 64 |
# File 'lib/jar_dependencies.rb', line 60 def to_prop( key ) key = key.gsub( '_', '.' ) ENV_JAVA[ ( key.downcase!; key ) ] || ENV[ ( key.gsub!( '.', '_' ); key.upcase!; key ) ] end |