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
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, MavenVersion

Constant Summary collapse

VERSION =
'0.2.1'.freeze
JRUBY_PLUGINS_VERSION =
'1.0.10'.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

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.


87
88
89
# File 'lib/jar_dependencies.rb', line 87

def require=(value)
  @require = value
end

Class Method Details

.debug?Boolean

Returns:

  • (Boolean)
[View source]

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

def debug?
  to_boolean( DEBUG )
end

.freeze_loadingObject

[View source]

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

def freeze_loading
  self.require = false
end

.homeObject

[View source]

180
181
182
183
184
185
# File 'lib/jar_dependencies.rb', line 180

def home
  @_jars_home_ ||= absolute(to_prop(HOME)) ||
                   detect_local_repository() ||
                   detect_local_repository(maven_global_settings) ||
                   File.join( user_home, '.m2', 'repository' )
end

.jarfileObject

[View source]

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

.local_maven_repoObject

[View source]

135
136
137
# File 'lib/jar_dependencies.rb', line 135

def local_maven_repo
  to_prop( LOCAL_MAVEN_REPO ) || home
end

.lockObject

[View source]

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

[View source]

49
50
51
52
# File 'lib/jar_dependencies.rb', line 49

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

.lock_path(basedir = nil) ⇒ Object

[View source]

124
125
126
127
128
129
130
131
132
133
# File 'lib/jar_dependencies.rb', line 124

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]

220
221
222
223
# File 'lib/jar_dependencies.rb', line 220

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]

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/jar_dependencies.rb', line 164

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_settingsObject Also known as: maven_settings

[View source]

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/jar_dependencies.rb', line 144

def 
  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)
        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_warningsObject

[View source]

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

def no_more_warnings
  @silent = true
end

.no_require?Boolean

Deprecated.

Returns:

  • (Boolean)
[View source]

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

def no_require?; ! require? end

.quiet?Boolean

Returns:

  • (Boolean)
[View source]

89
90
91
# File 'lib/jar_dependencies.rb', line 89

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

.require?Boolean

Returns:

  • (Boolean)
[View source]

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

[View source]

225
226
227
228
229
230
# File 'lib/jar_dependencies.rb', line 225

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_lockObject

[View source]

212
213
214
215
216
217
218
# File 'lib/jar_dependencies.rb', line 212

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]

187
188
189
190
191
192
193
194
195
196
197
# File 'lib/jar_dependencies.rb', line 187

def require_jars_lock!( scope = :runtime )
  if jars_lock = Jars.lock_path
    @@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
end

.resetObject

[View source]

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

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

.setup(options = nil) ⇒ Object

[View source]

199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/jar_dependencies.rb', line 199

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]

71
72
73
# File 'lib/jar_dependencies.rb', line 71

def skip?
  to_boolean( SKIP )
end

.to_boolean(key) ⇒ Object

[View source]

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

Returns:

  • (Boolean)
[View source]

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

def vendor?
  to_boolean( VENDOR )
end

.verbose?Boolean

Returns:

  • (Boolean)
[View source]

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

def verbose?
  to_boolean( VERBOSE )
end

.warn(msg) ⇒ Object

[View source]

232
233
234
# File 'lib/jar_dependencies.rb', line 232

def warn(msg)
  Kernel.warn(msg) unless quiet?
end

Instance Method Details

#to_prop(key) ⇒ Object

[View source]

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