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.3.12'.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
- .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, 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
- .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
94 95 96 |
# File 'lib/jar_dependencies.rb', line 94 def require=(value) @require = value end |
Class Method Details
.absolute(file) ⇒ Object
265 266 267 |
# File 'lib/jar_dependencies.rb', line 265 def absolute(file) File.(file) if file end |
.debug(msg = nil) ⇒ Object
261 262 263 |
# File 'lib/jar_dependencies.rb', line 261 def debug(msg = nil) Kernel.warn(msg || yield) if verbose? end |
.debug? ⇒ Boolean
113 114 115 |
# File 'lib/jar_dependencies.rb', line 113 def debug? to_boolean(DEBUG) end |
.freeze_loading ⇒ Object
125 126 127 |
# File 'lib/jar_dependencies.rb', line 125 def freeze_loading self.require = false end |
.home ⇒ Object
184 185 186 |
# File 'lib/jar_dependencies.rb', line 184 def home absolute(to_prop(HOME)) || local_maven_repo end |
.jarfile ⇒ Object
100 101 102 |
# File 'lib/jar_dependencies.rb', line 100 def jarfile ENV['JARFILE'] || ENV_JAVA['jarfile'] || ENV['JBUNDLER_JARFILE'] || ENV_JAVA['jbundler.jarfile'] || 'Jarfile' end |
.jars_lock_from_class_loader ⇒ Object
137 138 139 140 141 |
# File 'lib/jar_dependencies.rb', line 137 def jars_lock_from_class_loader if to_prop(LOCK).nil? && defined?(JRUBY_VERSION) JRuby.runtime.jruby_class_loader.get_resources('Jars.lock').collect(&:to_s) end end |
.local_maven_repo ⇒ Object
176 177 178 179 180 181 182 |
# File 'lib/jar_dependencies.rb', line 176 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
133 134 135 |
# File 'lib/jar_dependencies.rb', line 133 def lock to_prop(LOCK) || 'Jars.lock' end |
.lock_down(debug = false, verbose = false, options = {}) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/jar_dependencies.rb', line 53 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
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/jar_dependencies.rb', line 143 def lock_path(basedir = nil) deps = lock return deps if File.exist?(deps) 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
245 246 247 248 |
# File 'lib/jar_dependencies.rb', line 245 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
172 173 174 |
# File 'lib/jar_dependencies.rb', line 172 def maven_global_settings Jars::MavenSettings.global_settings end |
.maven_local_settings ⇒ Object
160 161 162 |
# File 'lib/jar_dependencies.rb', line 160 def maven_local_settings Jars::MavenSettings.local_settings end |
.maven_settings ⇒ Object
168 169 170 |
# File 'lib/jar_dependencies.rb', line 168 def maven_settings Jars::MavenSettings.settings end |
.maven_user_settings ⇒ Object
164 165 166 |
# File 'lib/jar_dependencies.rb', line 164 def maven_user_settings Jars::MavenSettings.user_settings end |
.no_more_warnings ⇒ Object
121 122 123 |
# File 'lib/jar_dependencies.rb', line 121 def no_more_warnings @silent = true end |
.no_require? ⇒ Boolean
105 106 107 |
# File 'lib/jar_dependencies.rb', line 105 def no_require? !require? end |
.quiet? ⇒ Boolean
96 97 98 |
# File 'lib/jar_dependencies.rb', line 96 def quiet? (@silent ||= false) || to_boolean(QUIET) end |
.require? ⇒ Boolean
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/jar_dependencies.rb', line 82 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
250 251 252 253 254 255 |
# File 'lib/jar_dependencies.rb', line 250 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
237 238 239 240 241 242 243 |
# File 'lib/jar_dependencies.rb', line 237 def require_jars_lock @@jars_lock ||= false unless @@jars_lock require_jars_lock! @@jars_lock ||= true end end |
.require_jars_lock!(scope = :runtime) ⇒ Object
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 221 222 |
# File 'lib/jar_dependencies.rb', line 188 def require_jars_lock!(scope = :runtime) urls = jars_lock_from_class_loader if urls && !urls.empty? @@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 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 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 do @@jars ||= {} loaded = @@jars.collect { |k, v| "#{k}:#{v}" } "--- loaded jars ---\n\t#{loaded.join("\n\t")}" end end |
.reset ⇒ Object
154 155 156 157 158 |
# File 'lib/jar_dependencies.rb', line 154 def reset instance_variables.each { |var| instance_variable_set(var, nil) } Jars::MavenSettings.reset (@@jars ||= {}).clear end |
.setup(options = nil) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/jar_dependencies.rb', line 224 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_lock? ⇒ Boolean
129 130 131 |
# File 'lib/jar_dependencies.rb', line 129 def skip_lock? to_prop(SKIP_LOCK) || false end |
.to_boolean(key) ⇒ Object
73 74 75 76 |
# File 'lib/jar_dependencies.rb', line 73 def to_boolean(key) return nil if (prop = to_prop(key)).nil? prop.empty? || prop.eql?('true') end |
.user_home ⇒ Object
269 270 271 272 273 274 275 276 277 |
# File 'lib/jar_dependencies.rb', line 269 def user_home ENV['HOME'] || begin user_home = Dir.home if Dir.respond_to?(:home) unless user_home user_home = ENV_JAVA['user.home'] if Object.const_defined?(:ENV_JAVA) end user_home end end |
.vendor? ⇒ Boolean
117 118 119 |
# File 'lib/jar_dependencies.rb', line 117 def vendor? to_boolean(VENDOR) end |
.verbose? ⇒ Boolean
109 110 111 |
# File 'lib/jar_dependencies.rb', line 109 def verbose? to_boolean(VERBOSE) end |
.warn(msg = nil) ⇒ Object
257 258 259 |
# File 'lib/jar_dependencies.rb', line 257 def warn(msg = nil) Kernel.warn(msg || yield) unless quiet? && !verbose? end |
Instance Method Details
#to_prop(key) ⇒ Object
62 63 64 65 66 |
# File 'lib/jar_dependencies.rb', line 62 def to_prop(key) key = key.tr('_', '.') ENV_JAVA[(key.downcase!; key)] || ENV[(key.tr!('.', '_'); key.upcase!; key)] end |