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.2.5'.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
- 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_user_settings ⇒ Object (also: maven_settings)
- .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
- .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
87 88 89 |
# File 'lib/jar_dependencies.rb', line 87 def require=(value) @require = value end |
Class Method Details
.debug(msg = nil, &block) ⇒ Object
271 272 273 |
# File 'lib/jar_dependencies.rb', line 271 def debug(msg = nil, &block) Kernel.warn(msg || block.call) if verbose? end |
.debug? ⇒ Boolean
104 105 106 |
# File 'lib/jar_dependencies.rb', line 104 def debug? to_boolean( DEBUG ) end |
.freeze_loading ⇒ Object
116 117 118 |
# File 'lib/jar_dependencies.rb', line 116 def freeze_loading self.require = false end |
.home ⇒ Object
194 195 196 |
# File 'lib/jar_dependencies.rb', line 194 def home @_jars_home_ ||= absolute(to_prop(HOME)) || local_maven_repo end |
.jarfile ⇒ Object
93 94 95 |
# File 'lib/jar_dependencies.rb', line 93 def jarfile ENV[ 'JARFILE' ] || ENV_JAVA[ 'jarfile' ] || ENV[ 'JBUNDLER_JARFILE' ] || ENV_JAVA[ 'jbundler.jarfile' ] || 'Jarfile' end |
.jars_lock_from_class_loader ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/jar_dependencies.rb', line 124 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
143 144 145 |
# File 'lib/jar_dependencies.rb', line 143 def local_maven_repo to_prop( LOCAL_MAVEN_REPO ) || home end |
.lock ⇒ Object
120 121 122 |
# File 'lib/jar_dependencies.rb', line 120 def lock to_prop( LOCK ) || 'Jars.lock' end |
.lock_down(debug = false, verbose = false, options = {}) ⇒ Object
49 50 51 52 |
# File 'lib/jar_dependencies.rb', line 49 def lock_down( debug = false, verbose = false, = {} ) require 'jars/lock_down' # do this lazy to keep things clean Jars::LockDown.new( debug, verbose ).lock_down( ) end |
.lock_path(basedir = nil) ⇒ Object
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/jar_dependencies.rb', line 132 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
255 256 257 258 |
# 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 end end |
.maven_global_settings ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/jar_dependencies.rb', line 172 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_user_settings ⇒ Object Also known as: maven_settings
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/jar_dependencies.rb', line 152 def maven_user_settings unless instance_variable_defined?(:@_jars_maven_user_settings_) @_jars_maven_user_settings_ = nil end if ( @_jars_maven_user_settings_ ||= nil ).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
112 113 114 |
# File 'lib/jar_dependencies.rb', line 112 def no_more_warnings @silent = true end |
.no_require? ⇒ Boolean
98 |
# File 'lib/jar_dependencies.rb', line 98 def no_require?; ! require? end |
.quiet? ⇒ Boolean
89 90 91 |
# File 'lib/jar_dependencies.rb', line 89 def quiet? ( @silent ||= false ) || to_boolean( QUIET ) end |
.require? ⇒ Boolean
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/jar_dependencies.rb', line 75 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
260 261 262 263 264 265 |
# File 'lib/jar_dependencies.rb', line 260 def require_jar( group_id, artifact_id, *classifier_version ) require_jars_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
247 248 249 250 251 252 253 |
# File 'lib/jar_dependencies.rb', line 247 def require_jars_lock @@jars_lock ||= false unless @@jars_lock require_jars_lock! @@jars_lock ||= true end end |
.require_jars_lock!(scope = :runtime) ⇒ Object
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 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/jar_dependencies.rb', line 198 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 #{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 { loaded = @@jars.collect{ |k,v| "#{k}:#{v}" } "--- loaded jars ---\n\t#{loaded.join("\n\t")}" } end |
.reset ⇒ Object
147 148 149 150 |
# File 'lib/jar_dependencies.rb', line 147 def reset instance_variables.each { |var| instance_variable_set(var, nil) } ( @@jars ||= {} ).clear end |
.setup(options = nil) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/jar_dependencies.rb', line 234 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
71 72 73 |
# File 'lib/jar_dependencies.rb', line 71 def skip? to_boolean( SKIP ) end |
.to_boolean(key) ⇒ Object
66 67 68 69 |
# File 'lib/jar_dependencies.rb', line 66 def to_boolean( key ) return nil if ( prop = to_prop( key ) ).nil? prop.empty? || prop.eql?('true') end |
.vendor? ⇒ Boolean
108 109 110 |
# File 'lib/jar_dependencies.rb', line 108 def vendor? to_boolean( VENDOR ) end |
.verbose? ⇒ Boolean
100 101 102 |
# File 'lib/jar_dependencies.rb', line 100 def verbose? to_boolean( VERBOSE ) end |
.warn(msg = nil, &block) ⇒ Object
267 268 269 |
# File 'lib/jar_dependencies.rb', line 267 def warn(msg = nil, &block) Kernel.warn(msg || block.call) unless quiet? and not verbose? end |
Instance Method Details
#to_prop(key) ⇒ Object
55 56 57 58 59 |
# File 'lib/jar_dependencies.rb', line 55 def to_prop( key ) key = key.gsub( '_', '.' ) ENV_JAVA[ ( key.downcase!; key ) ] || ENV[ ( key.gsub!( '.', '_' ); key.upcase!; key ) ] end |