Module: Jars
- Defined in:
- lib/jar_dependencies.rb,
lib/jars/lock.rb,
lib/jars/mima.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/mima/version.rb,
lib/jars/maven_settings.rb,
lib/jars/gemspec_artifacts.rb
Overview
Copyright (C) 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
Modules: MavenVersion, Mima Classes: Classpath, GemspecArtifacts, Installer, JarDetails, JarLoadError, Lock, LockDown, MavenExec, MavenSettings
Constant Summary collapse
- VERSION =
'0.6.0'- MAVEN_SETTINGS =
rubocop:disable Style/RedundantFreeze
'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 resolver output
'JARS_VERBOSE'.freeze
- DEBUG =
show jar-dependencies debug output
'JARS_DEBUG'.freeze
- VENDOR =
vendor jars inside gem when installing gem
'JARS_VENDOR'.freeze
- UNKNOWN =
string used when the version is unknown
'unknown'.freeze
Class Attribute Summary collapse
-
.require ⇒ Object
writeonly
Sets the attribute require.
Class Method Summary collapse
- .absolute(file) ⇒ Object
- .debug(msg = nil) ⇒ Object
- .debug? ⇒ Boolean
- .freeze_loading ⇒ Object
- .home ⇒ Object
- .info(msg = nil, newline: true) ⇒ Object
- .jarfile ⇒ Object
- .jars_lock_from_class_loader ⇒ Object
- .local_maven_repo ⇒ Object
- .lock ⇒ Object
- .lock_down(debug: nil, verbose: nil, **kwargs) ⇒ Object
- .lock_path(basedir = nil) ⇒ Object
- .locked_jar?(coordinate) ⇒ Boolean
- .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 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
- .user_home ⇒ Object
- .vendor? ⇒ Boolean
- .verbose? ⇒ Boolean
- .warn(msg = nil) ⇒ Object
Instance Method Summary collapse
Class Attribute Details
.require=(value) ⇒ Object (writeonly)
Sets the attribute require
116 117 118 |
# File 'lib/jar_dependencies.rb', line 116 def require=(value) @require = value end |
Class Method Details
.absolute(file) ⇒ Object
310 311 312 |
# File 'lib/jar_dependencies.rb', line 310 def absolute(file) File.(file) if file end |
.debug(msg = nil) ⇒ Object
303 304 305 306 307 308 |
# File 'lib/jar_dependencies.rb', line 303 def debug(msg = nil) return unless debug? msg = "#{msg.inspect}\n\t#{(msg.backtrace || []).join("\n\t")}" if msg.is_a?(Exception) Kernel.warn(msg || yield) end |
.debug? ⇒ Boolean
141 142 143 |
# File 'lib/jar_dependencies.rb', line 141 def debug? to_boolean(DEBUG) end |
.freeze_loading ⇒ Object
149 150 151 |
# File 'lib/jar_dependencies.rb', line 149 def freeze_loading self.require = false end |
.home ⇒ Object
213 214 215 |
# File 'lib/jar_dependencies.rb', line 213 def home @home ||= absolute(to_prop(HOME)) || local_maven_repo end |
.info(msg = nil, newline: true) ⇒ Object
290 291 292 293 294 295 |
# File 'lib/jar_dependencies.rb', line 290 def info(msg = nil, newline: true) return if quiet? msg = yield if msg.nil? && block_given? Kernel.print("#{msg}#{"\n" if newline}") end |
.jarfile ⇒ Object
132 133 134 |
# File 'lib/jar_dependencies.rb', line 132 def jarfile ENV['JARFILE'] || ENV_JAVA['jarfile'] || ENV['JBUNDLER_JARFILE'] || ENV_JAVA['jbundler.jarfile'] || 'Jarfile' end |
.jars_lock_from_class_loader ⇒ Object
161 162 163 164 165 |
# File 'lib/jar_dependencies.rb', line 161 def jars_lock_from_class_loader return unless defined?(JRUBY_VERSION) JRuby::Util.class_loader_resources('Jars.lock') end |
.local_maven_repo ⇒ Object
205 206 207 208 209 210 211 |
# File 'lib/jar_dependencies.rb', line 205 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
157 158 159 |
# File 'lib/jar_dependencies.rb', line 157 def lock @lock ||= to_prop(LOCK) || 'Jars.lock' end |
.lock_down(debug: nil, verbose: nil, **kwargs) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/jar_dependencies.rb', line 65 def lock_down(debug: nil, verbose: nil, **kwargs) previous_debug = ENV[DEBUG] previous_verbose = ENV[VERBOSE] previous_skip_lock = ENV[SKIP_LOCK] ENV[DEBUG] = debug.to_s unless debug.nil? ENV[VERBOSE] = verbose.to_s unless verbose.nil? ENV[SKIP_LOCK] = 'true' require 'jars/lock_down' # do this lazy to keep things clean Jars::LockDown.new.lock_down(kwargs.delete(:vendor_dir), **kwargs) ensure ENV[DEBUG] = previous_debug unless debug.nil? ENV[VERBOSE] = previous_verbose unless verbose.nil? ENV[SKIP_LOCK] = previous_skip_lock end |
.lock_path(basedir = nil) ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/jar_dependencies.rb', line 167 def lock_path(basedir = nil) return lock if File.exist?(lock) basedir ||= '.' ['.', 'jars', 'vendor/jars'].each do |dir| file = File.join(basedir, dir, lock) return file if File.exist?(file) end nil end |
.locked_jar?(coordinate) ⇒ Boolean
128 129 130 |
# File 'lib/jar_dependencies.rb', line 128 def locked_jar?(coordinate) @jars_locked&.include?(coordinate) end |
.mark_as_required(group_id, artifact_id, *classifier_version) ⇒ Object
273 274 275 276 277 |
# File 'lib/jar_dependencies.rb', line 273 def mark_as_required(group_id, artifact_id, *classifier_version) require_jar_with_block(group_id, artifact_id, *classifier_version) do # ignore end end |
.maven_global_settings ⇒ Object
201 202 203 |
# File 'lib/jar_dependencies.rb', line 201 def maven_global_settings Jars::MavenSettings.global_settings end |
.maven_local_settings ⇒ Object
189 190 191 |
# File 'lib/jar_dependencies.rb', line 189 def maven_local_settings Jars::MavenSettings.local_settings end |
.maven_settings ⇒ Object
197 198 199 |
# File 'lib/jar_dependencies.rb', line 197 def maven_settings Jars::MavenSettings.settings end |
.maven_user_settings ⇒ Object
193 194 195 |
# File 'lib/jar_dependencies.rb', line 193 def maven_user_settings Jars::MavenSettings.user_settings end |
.no_more_warnings ⇒ Object
124 125 126 |
# File 'lib/jar_dependencies.rb', line 124 def no_more_warnings @quiet = true end |
.quiet? ⇒ Boolean
118 119 120 121 |
# File 'lib/jar_dependencies.rb', line 118 def quiet? @quiet = to_boolean(QUIET) if @quiet.nil? @quiet end |
.require? ⇒ Boolean
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/jar_dependencies.rb', line 105 def require? if @require.nil? if (require = to_boolean(REQUIRE)).nil? no_require = to_boolean(NO_REQUIRE) @require = no_require.nil? || !no_require else @require = require end end @require end |
.require_jar(group_id, artifact_id, *classifier_version) ⇒ Object
279 280 281 282 283 284 285 286 287 288 |
# File 'lib/jar_dependencies.rb', line 279 def require_jar(group_id, artifact_id, *classifier_version) require_jars_lock unless skip_lock? if classifier_version.empty? && block_given? classifier_version = [yield].compact return mark_as_required(group_id, artifact_id, UNKNOWN) || false if classifier_version.empty? end 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
266 267 268 269 270 271 |
# File 'lib/jar_dependencies.rb', line 266 def require_jars_lock return if @jars_lock require_jars_lock! @jars_lock ||= true # rubocop:disable Naming/MemoizedInstanceVariableName end |
.require_jars_lock!(scope = :runtime) ⇒ Object
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 249 250 251 |
# File 'lib/jar_dependencies.rb', line 217 def require_jars_lock!(scope = :runtime) urls = jars_lock_from_class_loader if to_prop(LOCK).nil? pre_lock_jars = @jars.keys.dup if urls && !urls.empty? @jars_lock = true done = [] while done != urls urls.each do |url| next if done.member?(url) Jars.debug { "--- load jars from uri #{url}" } classpath = Jars::Classpath.new(nil, "uri:#{url}") classpath.require(scope) done << url end end elsif (jars_lock = Jars.lock_path) Jars.debug { "--- load jars from #{jars_lock}" } @jars_lock = jars_lock classpath = Jars::Classpath.new(nil, jars_lock) classpath.require(scope) end return unless @jars_lock @jars_locked = (@jars.keys - pre_lock_jars).freeze return if @jars_locked.empty? Jars.debug do loaded = @jars.collect { |k, v| "#{k}:#{v}" } "--- loaded jars ---\n\t#{loaded.join("\n\t")}" end end |
.reset ⇒ Object
178 179 180 181 182 183 184 185 186 187 |
# File 'lib/jar_dependencies.rb', line 178 def reset instance_variables.each do |var| next if var == :@jars_lock instance_variable_set(var, nil) end Jars::MavenSettings.reset @jars = {} @jars_locked = nil end |
.setup(options = nil) ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/jar_dependencies.rb', line 253 def setup( = nil) case when Symbol require_jars_lock!() when Hash @home = [:jars_home] @lock = [:jars_lock] require_jars_lock!([:scope] || :runtime) else require_jars_lock! end end |
.skip? ⇒ Boolean
101 102 103 |
# File 'lib/jar_dependencies.rb', line 101 def skip? to_boolean(SKIP) end |
.skip_lock? ⇒ Boolean
153 154 155 |
# File 'lib/jar_dependencies.rb', line 153 def skip_lock? to_prop(SKIP_LOCK) || false end |
.to_boolean(key) ⇒ Object
95 96 97 98 99 |
# File 'lib/jar_dependencies.rb', line 95 def to_boolean(key) return nil if (prop = to_prop(key)).nil? prop.empty? || prop.eql?('true') end |
.user_home ⇒ Object
314 315 316 317 318 319 320 |
# File 'lib/jar_dependencies.rb', line 314 def user_home ENV['HOME'] || begin user_home = Dir.home if Dir.respond_to?(:home) user_home = ENV_JAVA['user.home'] if !user_home && Object.const_defined?(:ENV_JAVA) user_home end end |
.vendor? ⇒ Boolean
145 146 147 |
# File 'lib/jar_dependencies.rb', line 145 def vendor? to_boolean(VENDOR) end |
.verbose? ⇒ Boolean
136 137 138 139 |
# File 'lib/jar_dependencies.rb', line 136 def verbose? verbose = to_boolean(VERBOSE) verbose.nil? ? debug? : (verbose || !!debug?) end |
.warn(msg = nil) ⇒ Object
297 298 299 300 301 |
# File 'lib/jar_dependencies.rb', line 297 def warn(msg = nil) return if quiet? && !debug? Kernel.warn(msg || yield) end |
Instance Method Details
#to_prop(key) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/jar_dependencies.rb', line 81 def to_prop(key) key = key.tr('_', '.') ENV_JAVA[(key.downcase! key)] || ENV[(key.tr!('.', '_') key.upcase! key)] end |