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
more...

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.11'.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

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.require=(value) ⇒ Object (writeonly)

Sets the attribute require

Parameters:

  • value

    the value to set the attribute require to.


95
96
97
# File 'lib/jar_dependencies.rb', line 95

def require=(value)
  @require = value
end

Class Method Details

.absolute(file) ⇒ Object

[View source]

267
268
269
# File 'lib/jar_dependencies.rb', line 267

def absolute( file )
  File.expand_path( file ) if file
end

.debug(msg = nil, &block) ⇒ Object

[View source]

263
264
265
# File 'lib/jar_dependencies.rb', line 263

def debug(msg = nil, &block)
  Kernel.warn(msg || block.call) if verbose?
end

.debug?Boolean

Returns:

  • (Boolean)
[View source]

112
113
114
# File 'lib/jar_dependencies.rb', line 112

def debug?
  to_boolean( DEBUG )
end

.freeze_loadingObject

[View source]

124
125
126
# File 'lib/jar_dependencies.rb', line 124

def freeze_loading
  self.require = false
end

.homeObject

[View source]

185
186
187
# File 'lib/jar_dependencies.rb', line 185

def home
  absolute(to_prop(HOME)) || local_maven_repo
end

.jarfileObject

[View source]

101
102
103
# File 'lib/jar_dependencies.rb', line 101

def jarfile
  ENV[ 'JARFILE' ] || ENV_JAVA[ 'jarfile' ] || ENV[ 'JBUNDLER_JARFILE' ] || ENV_JAVA[ 'jbundler.jarfile' ] || 'Jarfile'
end

.jars_lock_from_class_loaderObject

[View source]

136
137
138
139
140
141
142
# File 'lib/jar_dependencies.rb', line 136

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_repoObject

[View source]

177
178
179
180
181
182
183
# File 'lib/jar_dependencies.rb', line 177

def local_maven_repo
  @_local_maven_repo ||= absolute(to_prop(LOCAL_MAVEN_REPO)) ||
                         detect_local_repository(maven_local_settings) ||
                         detect_local_repository() ||
                         detect_local_repository(maven_global_settings) ||
                         File.join( user_home, '.m2', 'repository' )
end

.lockObject

[View source]

132
133
134
# File 'lib/jar_dependencies.rb', line 132

def lock
  to_prop( LOCK ) || 'Jars.lock'
end

.lock_down(debug = false, verbose = false, options = {}) ⇒ Object

[View source]

54
55
56
57
58
59
60
# File 'lib/jar_dependencies.rb', line 54

def lock_down( debug = false, verbose = false, options = {} )
  ENV[ SKIP_LOCK ] = 'true'
  require 'jars/lock_down' # do this lazy to keep things clean
  Jars::LockDown.new( debug, verbose ).lock_down( options )
ensure
  ENV[ SKIP_LOCK ] = nil
end

.lock_path(basedir = nil) ⇒ Object

[View source]

144
145
146
147
148
149
150
151
152
153
# File 'lib/jar_dependencies.rb', line 144

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

[View source]

247
248
249
250
# File 'lib/jar_dependencies.rb', line 247

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_settingsObject

[View source]

173
174
175
# File 'lib/jar_dependencies.rb', line 173

def maven_global_settings
  Jars::MavenSettings.global_settings
end

.maven_local_settingsObject

[View source]

161
162
163
# File 'lib/jar_dependencies.rb', line 161

def maven_local_settings
  Jars::MavenSettings.local_settings
end

.maven_settingsObject

[View source]

169
170
171
# File 'lib/jar_dependencies.rb', line 169

def maven_settings
  Jars::MavenSettings.settings
end

.maven_user_settingsObject

[View source]

165
166
167
# File 'lib/jar_dependencies.rb', line 165

def 
  Jars::MavenSettings.
end

.no_more_warningsObject

[View source]

120
121
122
# File 'lib/jar_dependencies.rb', line 120

def no_more_warnings
  @silent = true
end

.no_require?Boolean

Deprecated.

Returns:

  • (Boolean)
[View source]

106
# File 'lib/jar_dependencies.rb', line 106

def no_require?; ! require? end

.quiet?Boolean

Returns:

  • (Boolean)
[View source]

97
98
99
# File 'lib/jar_dependencies.rb', line 97

def quiet?
  ( @silent ||= false ) || to_boolean( QUIET )
end

.require?Boolean

Returns:

  • (Boolean)
[View source]

83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/jar_dependencies.rb', line 83

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

[View source]

252
253
254
255
256
257
# File 'lib/jar_dependencies.rb', line 252

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_lockObject

[View source]

239
240
241
242
243
244
245
# File 'lib/jar_dependencies.rb', line 239

def require_jars_lock
  @@jars_lock ||= false
  unless @@jars_lock
    require_jars_lock!
    @@jars_lock ||= true
  end
end

.require_jars_lock!(scope = :runtime) ⇒ Object

[View source]

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
223
224
# File 'lib/jar_dependencies.rb', line 189

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

.resetObject

[View source]

155
156
157
158
159
# File 'lib/jar_dependencies.rb', line 155

def reset
  instance_variables.each { |var| instance_variable_set(var, nil) }
  Jars::MavenSettings.reset
  ( @@jars ||= {} ).clear
end

.setup(options = nil) ⇒ Object

[View source]

226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/jar_dependencies.rb', line 226

def setup( options = nil )
  case options
  when Symbol
    require_jars_lock!( options )
  when Hash
    @_jars_home = options[:jars_home]
    @_jars_lock = options[:jars_lock]
    require_jars_lock!( options[:scope] || :runtime )
  else
    require_jars_lock!
  end
end

.skip?Boolean

Returns:

  • (Boolean)
[View source]

79
80
81
# File 'lib/jar_dependencies.rb', line 79

def skip?
  to_boolean( SKIP )
end

.skip_lock?Boolean

Returns:

  • (Boolean)
[View source]

128
129
130
# File 'lib/jar_dependencies.rb', line 128

def skip_lock?
  to_prop( SKIP_LOCK ) || false
end

.to_boolean(key) ⇒ Object

[View source]

74
75
76
77
# File 'lib/jar_dependencies.rb', line 74

def to_boolean( key )
  return nil if ( prop = to_prop( key ) ).nil?
  prop.empty? || prop.eql?('true')
end

.user_homeObject

[View source]

271
272
273
274
275
276
277
278
279
# File 'lib/jar_dependencies.rb', line 271

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

Returns:

  • (Boolean)
[View source]

116
117
118
# File 'lib/jar_dependencies.rb', line 116

def vendor?
  to_boolean( VENDOR )
end

.verbose?Boolean

Returns:

  • (Boolean)
[View source]

108
109
110
# File 'lib/jar_dependencies.rb', line 108

def verbose?
  to_boolean( VERBOSE )
end

.warn(msg = nil, &block) ⇒ Object

[View source]

259
260
261
# File 'lib/jar_dependencies.rb', line 259

def warn(msg = nil, &block)
  Kernel.warn(msg || block.call) unless quiet? and not verbose?
end

Instance Method Details

#to_prop(key) ⇒ Object

[View source]

63
64
65
66
67
# File 'lib/jar_dependencies.rb', line 63

def to_prop( key )
  key = key.gsub( '_', '.' )
  ENV_JAVA[ ( key.downcase!; key ) ] ||
    ENV[ ( key.gsub!( '.', '_' ); key.upcase!; key ) ]
end