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/maven_settings.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, MavenSettings, MavenVersion
Constant Summary collapse
- VERSION =
'0.5.4'
- JRUBY_PLUGINS_VERSION =
'3.0.2'
- DEPENDENCY_PLUGIN_VERSION =
'2.8'
- MAVEN_SETTINGS =
'JARS_MAVEN_SETTINGS'
- LOCAL_MAVEN_REPO =
'JARS_LOCAL_MAVEN_REPO'
- LOCK =
lock file to use
'JARS_LOCK'
- HOME =
where the locally stored jars are search for or stored
'JARS_HOME'
- SKIP =
skip the gem post install hook
'JARS_SKIP'
- SKIP_LOCK =
skip Jars.lock mainly to run lock_jars
'JARS_SKIP_LOCK'
- REQUIRE =
do not require any jars if set to false
'JARS_REQUIRE'
- NO_REQUIRE =
'JARS_NO_REQUIRE'
- 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'
- VERBOSE =
show maven output
'JARS_VERBOSE'
- DEBUG =
maven debug
'JARS_DEBUG'
- VENDOR =
vendor jars inside gem when installing gem
'JARS_VENDOR'
- UNKNOWN =
string used when the version is unknown
'unknown'
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
- .jarfile ⇒ Object
- .jars_lock_from_class_loader ⇒ Object
- .local_maven_repo ⇒ Object
- .lock ⇒ Object
- .lock_down(debug: false, verbose: false, **kwargs) ⇒ 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
- .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
105 106 107 |
# File 'lib/jar_dependencies.rb', line 105 def require=(value) @require = value end |
Class Method Details
.absolute(file) ⇒ Object
285 286 287 |
# File 'lib/jar_dependencies.rb', line 285 def absolute(file) File.(file) if file end |
.debug(msg = nil) ⇒ Object
278 279 280 281 282 283 |
# File 'lib/jar_dependencies.rb', line 278 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
124 125 126 |
# File 'lib/jar_dependencies.rb', line 124 def debug? to_boolean(DEBUG) end |
.freeze_loading ⇒ Object
132 133 134 |
# File 'lib/jar_dependencies.rb', line 132 def freeze_loading self.require = false end |
.home ⇒ Object
200 201 202 |
# File 'lib/jar_dependencies.rb', line 200 def home @home ||= absolute(to_prop(HOME)) || local_maven_repo end |
.jarfile ⇒ Object
116 117 118 |
# File 'lib/jar_dependencies.rb', line 116 def jarfile ENV['JARFILE'] || ENV_JAVA['jarfile'] || ENV['JBUNDLER_JARFILE'] || ENV_JAVA['jbundler.jarfile'] || 'Jarfile' end |
.jars_lock_from_class_loader ⇒ Object
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/jar_dependencies.rb', line 144 def jars_lock_from_class_loader return unless defined?(JRUBY_VERSION) if JRuby::Util.respond_to?(:class_loader_resources) JRuby::Util.class_loader_resources('Jars.lock') else require 'jruby' JRuby.runtime.jruby_class_loader.get_resources('Jars.lock').collect(&:to_s) end end |
.local_maven_repo ⇒ Object
192 193 194 195 196 197 198 |
# File 'lib/jar_dependencies.rb', line 192 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
140 141 142 |
# File 'lib/jar_dependencies.rb', line 140 def lock @lock ||= to_prop(LOCK) || 'Jars.lock' end |
.lock_down(debug: false, verbose: false, **kwargs) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/jar_dependencies.rb', line 61 def lock_down(debug: false, verbose: false, **kwargs) ENV[SKIP_LOCK] = 'true' require 'jars/lock_down' # do this lazy to keep things clean Jars::LockDown.new(debug, verbose).lock_down(kwargs.delete(:vendor_dir), **kwargs) ensure ENV[SKIP_LOCK] = nil end |
.lock_path(basedir = nil) ⇒ Object
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/jar_dependencies.rb', line 155 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 |
.mark_as_required(group_id, artifact_id, *classifier_version) ⇒ Object
255 256 257 258 259 |
# File 'lib/jar_dependencies.rb', line 255 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
188 189 190 |
# File 'lib/jar_dependencies.rb', line 188 def maven_global_settings Jars::MavenSettings.global_settings end |
.maven_local_settings ⇒ Object
176 177 178 |
# File 'lib/jar_dependencies.rb', line 176 def maven_local_settings Jars::MavenSettings.local_settings end |
.maven_settings ⇒ Object
184 185 186 |
# File 'lib/jar_dependencies.rb', line 184 def maven_settings Jars::MavenSettings.settings end |
.maven_user_settings ⇒ Object
180 181 182 |
# File 'lib/jar_dependencies.rb', line 180 def maven_user_settings Jars::MavenSettings.user_settings end |
.no_more_warnings ⇒ Object
112 113 114 |
# File 'lib/jar_dependencies.rb', line 112 def no_more_warnings @quiet = true end |
.quiet? ⇒ Boolean
107 108 109 110 |
# File 'lib/jar_dependencies.rb', line 107 def quiet? @quiet = to_boolean(QUIET) if @quiet.nil? @quiet end |
.require? ⇒ Boolean
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/jar_dependencies.rb', line 94 def 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
261 262 263 264 265 266 267 268 269 270 |
# File 'lib/jar_dependencies.rb', line 261 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
248 249 250 251 252 253 |
# File 'lib/jar_dependencies.rb', line 248 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
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 |
# File 'lib/jar_dependencies.rb', line 204 def require_jars_lock!(scope = :runtime) urls = jars_lock_from_class_loader if to_prop(LOCK).nil? 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 no_more_warnings 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) no_more_warnings end Jars.debug do loaded = @jars.collect { |k, v| "#{k}:#{v}" } "--- loaded jars ---\n\t#{loaded.join("\n\t")}" end end |
.reset ⇒ Object
166 167 168 169 170 171 172 173 174 |
# File 'lib/jar_dependencies.rb', line 166 def reset instance_variables.each do |var| next if var == :@jars_lock instance_variable_set(var, nil) end Jars::MavenSettings.reset @jars = {} end |
.setup(options = nil) ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/jar_dependencies.rb', line 235 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_lock? ⇒ Boolean
136 137 138 |
# File 'lib/jar_dependencies.rb', line 136 def skip_lock? to_prop(SKIP_LOCK) || false end |
.to_boolean(key) ⇒ Object
84 85 86 87 88 |
# File 'lib/jar_dependencies.rb', line 84 def to_boolean(key) return nil if (prop = to_prop(key)).nil? prop.empty? || prop.eql?('true') end |
.user_home ⇒ Object
289 290 291 292 293 294 295 |
# File 'lib/jar_dependencies.rb', line 289 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
128 129 130 |
# File 'lib/jar_dependencies.rb', line 128 def vendor? to_boolean(VENDOR) end |
.verbose? ⇒ Boolean
120 121 122 |
# File 'lib/jar_dependencies.rb', line 120 def verbose? to_boolean(VERBOSE) end |
.warn(msg = nil) ⇒ Object
272 273 274 275 276 |
# File 'lib/jar_dependencies.rb', line 272 def warn(msg = nil) return if (verbose? == nil && quiet?) || (verbose? == false && !debug?) Kernel.warn(msg || yield) end |
Instance Method Details
#to_prop(key) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/jar_dependencies.rb', line 70 def to_prop(key) key = key.tr('_', '.') ENV_JAVA[(key.downcase! key)] || ENV[(key.tr!('.', '_') key.upcase! key)] end |