rspec-openhab-scripting 0.0.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/rspec/bundler/inline.rb +12 -0
- data/lib/rspec/openhab/api.rb +34 -0
- data/lib/rspec/openhab/core/cron_scheduler.rb +13 -0
- data/lib/rspec/openhab/core/load_path.rb +13 -0
- data/lib/rspec/openhab/core/logger.rb +24 -0
- data/lib/rspec/openhab/core/openhab_setup.rb +11 -0
- data/lib/rspec/openhab/core/osgi.rb +19 -0
- data/lib/rspec/openhab/core/script_handling.rb +21 -0
- data/lib/rspec/openhab/dsl/imports.rb +231 -0
- data/lib/rspec/openhab/dsl/timers/timer.rb +86 -0
- data/lib/rspec/openhab/version.rb +7 -0
- data/lib/rspec-openhab-scripting.rb +115 -0
- data/lib/rspec-openhab-scripting_jars.rb +14 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jar-dependencies.rb +24 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jar_dependencies.rb +397 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jar_install_post_install_hook.rb +29 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jars/attach_jars_pom.rb +35 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jars/classpath.rb +92 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jars/gemspec_artifacts.rb +220 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jars/gemspec_pom.rb +11 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jars/installer.rb +221 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jars/lock.rb +75 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jars/lock_down.rb +102 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jars/lock_down_pom.rb +35 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jars/maven_exec.rb +88 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jars/maven_factory.rb +138 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jars/maven_require.rb +48 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jars/maven_settings.rb +124 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jars/output_jars_pom.rb +16 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jars/post_install_hook.rb +33 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jars/setup.rb +9 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/jars/version.rb +7 -0
- data/vendor/gems/jar-dependencies-1.0.0/lib/rubygems_plugin.rb +24 -0
- metadata +217 -0
@@ -0,0 +1,397 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (C) 2014 Christian Meier
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
7
|
+
# this software and associated documentation files (the "Software"), to deal in
|
8
|
+
# the Software without restriction, including without limitation the rights to
|
9
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
10
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
11
|
+
# subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
18
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
19
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
20
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
21
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#
|
23
|
+
|
24
|
+
require "jars/maven_require"
|
25
|
+
|
26
|
+
module Jars
|
27
|
+
unless defined? Jars::SKIP_LOCK
|
28
|
+
MAVEN_SETTINGS = "JARS_MAVEN_SETTINGS"
|
29
|
+
LOCAL_MAVEN_REPO = "JARS_LOCAL_MAVEN_REPO"
|
30
|
+
# lock file to use
|
31
|
+
LOCK = "JARS_LOCK"
|
32
|
+
# where the locally stored jars are search for or stored
|
33
|
+
HOME = "JARS_HOME"
|
34
|
+
# skip the gem post install hook
|
35
|
+
SKIP = "JARS_SKIP"
|
36
|
+
# skip Jars.lock mainly to run lock_jars
|
37
|
+
SKIP_LOCK = "JARS_SKIP_LOCK"
|
38
|
+
# do not require any jars if set to false
|
39
|
+
REQUIRE = "JARS_REQUIRE"
|
40
|
+
# additional repos to search for jars
|
41
|
+
ADDITIONAL_MAVEN_REPOS = "JARS_ADDITIONAL_MAVEN_REPOS"
|
42
|
+
# @private
|
43
|
+
NO_REQUIRE = "JARS_NO_REQUIRE"
|
44
|
+
# no more warnings on conflict. this still requires jars but will
|
45
|
+
# not warn. it is needed to load jars from (default) gems which
|
46
|
+
# do contribute to any dependency manager (maven, gradle, jbundler)
|
47
|
+
QUIET = "JARS_QUIET"
|
48
|
+
# show maven output
|
49
|
+
VERBOSE = "JARS_VERBOSE"
|
50
|
+
# maven debug
|
51
|
+
DEBUG = "JARS_DEBUG"
|
52
|
+
# vendor jars inside gem when installing gem
|
53
|
+
VENDOR = "JARS_VENDOR"
|
54
|
+
# string used when the version is unknown
|
55
|
+
UNKNOWN = "unknown"
|
56
|
+
end
|
57
|
+
|
58
|
+
autoload :MavenSettings, "jars/maven_settings"
|
59
|
+
|
60
|
+
@jars_lock = false
|
61
|
+
@jars = {}
|
62
|
+
|
63
|
+
class << self
|
64
|
+
def lock_down(debug: false, verbose: false, **kwargs)
|
65
|
+
ENV[SKIP_LOCK] = "true"
|
66
|
+
require "jars/lock_down" # do this lazy to keep things clean
|
67
|
+
Jars::LockDown.new(debug, verbose).lock_down(**kwargs)
|
68
|
+
ensure
|
69
|
+
ENV[SKIP_LOCK] = nil
|
70
|
+
end
|
71
|
+
|
72
|
+
if defined? JRUBY_VERSION
|
73
|
+
def to_prop(key)
|
74
|
+
key = key.tr("_", ".")
|
75
|
+
ENV_JAVA[(key.downcase!
|
76
|
+
key)] ||
|
77
|
+
ENV[(key.tr!(".", "_")
|
78
|
+
key.upcase!
|
79
|
+
key)]
|
80
|
+
end
|
81
|
+
else
|
82
|
+
def to_prop(key)
|
83
|
+
ENV[key.tr(".", "_").upcase]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def to_boolean(key)
|
88
|
+
return nil if (prop = to_prop(key)).nil?
|
89
|
+
|
90
|
+
prop.empty? || prop.eql?("true")
|
91
|
+
end
|
92
|
+
|
93
|
+
def skip?
|
94
|
+
to_boolean(SKIP)
|
95
|
+
end
|
96
|
+
|
97
|
+
def require?
|
98
|
+
@require = nil unless instance_variable_defined?(:@require)
|
99
|
+
if @require.nil?
|
100
|
+
if (require = to_boolean(REQUIRE)).nil?
|
101
|
+
no_require = to_boolean(NO_REQUIRE)
|
102
|
+
@require = no_require.nil? ? true : !no_require
|
103
|
+
else
|
104
|
+
@require = require
|
105
|
+
end
|
106
|
+
end
|
107
|
+
@require
|
108
|
+
end
|
109
|
+
attr_writer :require
|
110
|
+
|
111
|
+
def quiet?
|
112
|
+
(@silent ||= false) || to_boolean(QUIET)
|
113
|
+
end
|
114
|
+
|
115
|
+
def jarfile
|
116
|
+
ENV["JARFILE"] || ENV_JAVA["jarfile"] || ENV["JBUNDLER_JARFILE"] || ENV_JAVA["jbundler.jarfile"] || "Jarfile"
|
117
|
+
end
|
118
|
+
|
119
|
+
def verbose?
|
120
|
+
to_boolean(VERBOSE)
|
121
|
+
end
|
122
|
+
|
123
|
+
def debug?
|
124
|
+
to_boolean(DEBUG)
|
125
|
+
end
|
126
|
+
|
127
|
+
def vendor?
|
128
|
+
to_boolean(VENDOR)
|
129
|
+
end
|
130
|
+
|
131
|
+
def no_more_warnings
|
132
|
+
@silent = true
|
133
|
+
end
|
134
|
+
|
135
|
+
def freeze_loading
|
136
|
+
self.require = false
|
137
|
+
end
|
138
|
+
|
139
|
+
def skip_lock?
|
140
|
+
to_prop(SKIP_LOCK) || false
|
141
|
+
end
|
142
|
+
|
143
|
+
def lock
|
144
|
+
to_prop(LOCK) || "Jars.lock"
|
145
|
+
end
|
146
|
+
|
147
|
+
def jars_lock_from_class_loader
|
148
|
+
return unless to_prop(LOCK).nil? && defined?(JRUBY_VERSION)
|
149
|
+
|
150
|
+
if JRuby::Util.respond_to?(:class_loader_resources)
|
151
|
+
JRuby::Util.class_loader_resources("Jars.lock")
|
152
|
+
else
|
153
|
+
require "jruby"
|
154
|
+
JRuby.runtime.jruby_class_loader.get_resources("Jars.lock").collect(&:to_s)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def lock_path(basedir = nil)
|
159
|
+
deps = lock
|
160
|
+
return deps if File.exist?(deps)
|
161
|
+
|
162
|
+
basedir ||= "."
|
163
|
+
[".", "jars", "vendor/jars"].each do |dir|
|
164
|
+
file = File.join(basedir, dir, lock)
|
165
|
+
return file if File.exist?(file)
|
166
|
+
end
|
167
|
+
nil
|
168
|
+
end
|
169
|
+
|
170
|
+
def reset
|
171
|
+
instance_variables.each do |var|
|
172
|
+
next if var == :@jars_lock
|
173
|
+
|
174
|
+
instance_variable_set(var, nil)
|
175
|
+
end
|
176
|
+
Jars::MavenSettings.reset
|
177
|
+
@jars = {}
|
178
|
+
end
|
179
|
+
|
180
|
+
def maven_local_settings
|
181
|
+
Jars::MavenSettings.local_settings
|
182
|
+
end
|
183
|
+
|
184
|
+
def maven_user_settings
|
185
|
+
Jars::MavenSettings.user_settings
|
186
|
+
end
|
187
|
+
|
188
|
+
def maven_settings
|
189
|
+
Jars::MavenSettings.settings
|
190
|
+
end
|
191
|
+
|
192
|
+
def maven_global_settings
|
193
|
+
Jars::MavenSettings.global_settings
|
194
|
+
end
|
195
|
+
|
196
|
+
def local_maven_repo
|
197
|
+
@local_maven_repo ||= absolute(to_prop(LOCAL_MAVEN_REPO)) ||
|
198
|
+
detect_local_repository(maven_local_settings) ||
|
199
|
+
detect_local_repository(maven_user_settings) ||
|
200
|
+
detect_local_repository(maven_global_settings) ||
|
201
|
+
File.join(user_home, ".m2", "repository")
|
202
|
+
end
|
203
|
+
|
204
|
+
def home
|
205
|
+
absolute(to_prop(HOME)) || local_maven_repo
|
206
|
+
end
|
207
|
+
|
208
|
+
def additional_maven_repos
|
209
|
+
(to_prop(ADDITIONAL_MAVEN_REPOS) || "").split(":").freeze
|
210
|
+
end
|
211
|
+
|
212
|
+
def require_jars_lock!(scope = :runtime)
|
213
|
+
urls = jars_lock_from_class_loader
|
214
|
+
if urls && !urls.empty?
|
215
|
+
@jars_lock = true
|
216
|
+
# funny error during spec where it tries to load it again
|
217
|
+
# and finds it as gem instead of the LOAD_PATH
|
218
|
+
require "jars/classpath" unless defined? Jars::Classpath
|
219
|
+
done = []
|
220
|
+
while done != urls
|
221
|
+
urls.each do |url|
|
222
|
+
next if done.member?(url)
|
223
|
+
|
224
|
+
Jars.debug { "--- load jars from uri #{url}" }
|
225
|
+
classpath = Jars::Classpath.new(nil, "uri:#{url}")
|
226
|
+
classpath.require(scope)
|
227
|
+
done << url
|
228
|
+
end
|
229
|
+
urls = jars_lock_from_class_loader
|
230
|
+
end
|
231
|
+
no_more_warnings
|
232
|
+
elsif (jars_lock = Jars.lock_path)
|
233
|
+
Jars.debug { "--- load jars from #{jars_lock}" }
|
234
|
+
@jars_lock = jars_lock
|
235
|
+
# funny error during spec where it tries to load it again
|
236
|
+
# and finds it as gem instead of the LOAD_PATH
|
237
|
+
require "jars/classpath" unless defined? Jars::Classpath
|
238
|
+
classpath = Jars::Classpath.new(nil, jars_lock)
|
239
|
+
classpath.require(scope)
|
240
|
+
no_more_warnings
|
241
|
+
end
|
242
|
+
Jars.debug do
|
243
|
+
loaded = @jars.collect { |k, v| "#{k}:#{v}" }
|
244
|
+
"--- loaded jars ---\n\t#{loaded.join("\n\t")}"
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
def setup(options = nil)
|
249
|
+
case options
|
250
|
+
when Symbol
|
251
|
+
require_jars_lock!(options)
|
252
|
+
when Hash
|
253
|
+
@jars_home = options[:jars_home]
|
254
|
+
@jars_lock = options[:jars_lock]
|
255
|
+
require_jars_lock!(options[:scope] || :runtime)
|
256
|
+
else
|
257
|
+
require_jars_lock!
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def require_jars_lock
|
262
|
+
return if @jars_lock
|
263
|
+
|
264
|
+
require_jars_lock!
|
265
|
+
@jars_lock ||= true # rubocop:disable Naming/MemoizedInstanceVariableName
|
266
|
+
end
|
267
|
+
|
268
|
+
def mark_as_required(group_id, artifact_id, *classifier_version)
|
269
|
+
require_jar_with_block(group_id, artifact_id, *classifier_version) do
|
270
|
+
# ignore
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
def require_jar(group_id, artifact_id, *classifier_version)
|
275
|
+
require_jars_lock unless skip_lock?
|
276
|
+
if classifier_version.empty? && block_given?
|
277
|
+
classifier_version = [yield].compact
|
278
|
+
return mark_as_required(group_id, artifact_id, UNKNOWN) || false if classifier_version.empty?
|
279
|
+
end
|
280
|
+
require_jar_with_block(group_id, artifact_id, *classifier_version) do |gid, aid, version, classifier|
|
281
|
+
do_require(gid, aid, version, classifier)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
def find_jar(group_id, artifact_id, *classifier_version)
|
286
|
+
find_jar_internal(group_id, artifact_id, *classifier_version)
|
287
|
+
end
|
288
|
+
|
289
|
+
def warn(msg = nil)
|
290
|
+
Kernel.warn(msg || yield) unless quiet? && !verbose?
|
291
|
+
end
|
292
|
+
|
293
|
+
def debug(msg = nil)
|
294
|
+
Kernel.warn(msg || yield) if verbose?
|
295
|
+
end
|
296
|
+
|
297
|
+
def absolute(file)
|
298
|
+
File.expand_path(file) if file
|
299
|
+
end
|
300
|
+
|
301
|
+
def user_home
|
302
|
+
ENV["HOME"] || begin
|
303
|
+
user_home = Dir.home if Dir.respond_to?(:home)
|
304
|
+
user_home = ENV_JAVA["user.home"] if !user_home && Object.const_defined?(:ENV_JAVA)
|
305
|
+
user_home
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
private
|
310
|
+
|
311
|
+
def require_jar_with_block(group_id, artifact_id, *classifier_version)
|
312
|
+
version = classifier_version[-1]
|
313
|
+
classifier = classifier_version[-2]
|
314
|
+
|
315
|
+
coordinate = +"#{group_id}:#{artifact_id}"
|
316
|
+
coordinate << ":#{classifier}" if classifier
|
317
|
+
if @jars.key? coordinate
|
318
|
+
if @jars[coordinate] == version
|
319
|
+
false
|
320
|
+
else
|
321
|
+
@jars[coordinate] # version of already registered jar
|
322
|
+
end
|
323
|
+
else
|
324
|
+
yield group_id, artifact_id, version, classifier
|
325
|
+
@jars[coordinate] = version
|
326
|
+
true
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
def detect_local_repository(settings)
|
331
|
+
return nil unless settings
|
332
|
+
|
333
|
+
doc = File.read(settings)
|
334
|
+
# TODO: filter out xml comments
|
335
|
+
local_repo = doc.sub(%r{</localRepository>.*}m, "").sub(/.*<localRepository>/m, "")
|
336
|
+
# replace maven like system properties embedded into the string
|
337
|
+
local_repo.gsub!(/\$\{[a-zA-Z.]+\}/) do |a|
|
338
|
+
ENV_JAVA[a[2..-2]] || a
|
339
|
+
end
|
340
|
+
local_repo = nil if local_repo.empty? || !File.exist?(local_repo)
|
341
|
+
local_repo
|
342
|
+
rescue
|
343
|
+
Jars.warn { "error reading or parsing #{settings}" }
|
344
|
+
nil
|
345
|
+
end
|
346
|
+
|
347
|
+
def to_jar(group_id, artifact_id, version, classifier = nil)
|
348
|
+
file = +"#{group_id.tr(".", "/")}/#{artifact_id}/#{version}/#{artifact_id}-#{version}"
|
349
|
+
file << "-#{classifier}" if classifier
|
350
|
+
file << ".jar"
|
351
|
+
file
|
352
|
+
end
|
353
|
+
|
354
|
+
def find_jar_internal(group_id, artifact_id, *classifier_version, return_base_file: nil)
|
355
|
+
jar = to_jar(group_id, artifact_id, *classifier_version)
|
356
|
+
search_dirs = [
|
357
|
+
# use jar from local repository if exists
|
358
|
+
home,
|
359
|
+
# use jar from PWD/jars if exists
|
360
|
+
File.join(Dir.pwd, "jars"),
|
361
|
+
# use jar from PWD/vendor/jars if exists
|
362
|
+
File.join(Dir.pwd, "vendor", "jars")
|
363
|
+
] + additional_maven_repos
|
364
|
+
search_dirs.each do |dir|
|
365
|
+
file = File.join(dir, jar)
|
366
|
+
return file if File.exist?(file)
|
367
|
+
end
|
368
|
+
return_base_file && jar
|
369
|
+
end
|
370
|
+
|
371
|
+
def do_require(*args)
|
372
|
+
jar = find_jar_internal(*args, return_base_file: true)
|
373
|
+
# otherwise try to find it on the load path
|
374
|
+
require jar
|
375
|
+
rescue LoadError => e
|
376
|
+
raise "\n\n\tyou might need to reinstall the gem which depends on the " \
|
377
|
+
"missing jar or in case there is Jars.lock then resolve the jars with " \
|
378
|
+
"`lock_jars` command\n\n#{e.message} (LoadError)"
|
379
|
+
end
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
def require_jar(*args, &block)
|
384
|
+
return nil unless Jars.require?
|
385
|
+
|
386
|
+
result = Jars.require_jar(*args, &block)
|
387
|
+
if result.is_a? String
|
388
|
+
args << (yield || Jars::UNKNOWN) if args.size == 2 && block
|
389
|
+
Jars.warn do
|
390
|
+
"--- jar coordinate #{args[0..-2].join(":")} already loaded with version #{result} - omit version #{args[-1]}"
|
391
|
+
end
|
392
|
+
Jars.debug { " try to load from #{caller.join("\n\t")}" }
|
393
|
+
return false
|
394
|
+
end
|
395
|
+
Jars.debug { " register #{args.inspect} - #{result == true}" }
|
396
|
+
result
|
397
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (C) 2014 Christian Meier
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
7
|
+
# this software and associated documentation files (the "Software"), to deal in
|
8
|
+
# the Software without restriction, including without limitation the rights to
|
9
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
10
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
11
|
+
# subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
18
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
19
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
20
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
21
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#
|
23
|
+
|
24
|
+
if defined?(JRUBY_VERSION) && Gem.post_install_hooks.empty?
|
25
|
+
Gem.post_install do |gem_installer|
|
26
|
+
require 'jars/post_install_hook'
|
27
|
+
Jars.post_install_hook(gem_installer)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# this file is maven DSL
|
4
|
+
|
5
|
+
(0..1_000).each do |i|
|
6
|
+
path = ENV_JAVA["jars.repos.#{i}"]
|
7
|
+
break unless path
|
8
|
+
|
9
|
+
repository "repo#{i}", "file://#{path}", "Custom Local Repo"
|
10
|
+
end
|
11
|
+
|
12
|
+
(0..10_000).each do |i|
|
13
|
+
coord = ENV_JAVA["jars.#{i}"]
|
14
|
+
break unless coord
|
15
|
+
|
16
|
+
artifact = Maven::Tools::Artifact.from_coordinate(coord)
|
17
|
+
exclusions = []
|
18
|
+
(0..10_000).each do |j|
|
19
|
+
exclusion = ENV_JAVA["jars.#{i}.exclusions.#{j}"]
|
20
|
+
break unless exclusion
|
21
|
+
|
22
|
+
exclusions << exclusion
|
23
|
+
end
|
24
|
+
scope = ENV_JAVA["jars.#{i}.scope"]
|
25
|
+
artifact.scope = scope if scope
|
26
|
+
classifier = ENV_JAVA["jars.#{i}.classifier"]
|
27
|
+
artifact.classifier = classifier if classifier
|
28
|
+
|
29
|
+
# declare the artifact inside the POM
|
30
|
+
dependency_artifact(artifact) do
|
31
|
+
exclusions.each do |ex|
|
32
|
+
exclusion ex
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jars/maven_exec"
|
4
|
+
require "jars/lock"
|
5
|
+
require "fileutils"
|
6
|
+
|
7
|
+
module Jars
|
8
|
+
class Classpath
|
9
|
+
# convenient method
|
10
|
+
def self.require(scope = nil)
|
11
|
+
new.require(scope)
|
12
|
+
end
|
13
|
+
|
14
|
+
# convenient method
|
15
|
+
def self.classpath(scope = nil)
|
16
|
+
new.classpath(scope)
|
17
|
+
end
|
18
|
+
|
19
|
+
# convenient method
|
20
|
+
def self.classpath_string(scope = nil)
|
21
|
+
new.classpath_string(scope)
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(spec = nil, deps = nil)
|
25
|
+
@spec = spec
|
26
|
+
@deps = deps
|
27
|
+
end
|
28
|
+
|
29
|
+
def mvn
|
30
|
+
@mvn ||= MavenExec.new(@spec)
|
31
|
+
end
|
32
|
+
|
33
|
+
def workdir(dirname)
|
34
|
+
dir = File.join(mvn.basedir, dirname)
|
35
|
+
dir if File.directory?(dir)
|
36
|
+
end
|
37
|
+
|
38
|
+
def dependencies_list
|
39
|
+
if @deps.nil?
|
40
|
+
deps = Jars.lock_path(mvn.basedir)
|
41
|
+
@deps = deps if deps && File.exist?(deps)
|
42
|
+
end
|
43
|
+
@deps || resolve_dependencies
|
44
|
+
end
|
45
|
+
private :dependencies_list
|
46
|
+
|
47
|
+
DEPENDENCY_LIST = "dependencies.list"
|
48
|
+
def resolve_dependencies
|
49
|
+
basedir = workdir("pkg") || workdir("target") || workdir("")
|
50
|
+
deps = File.join(basedir, DEPENDENCY_LIST)
|
51
|
+
mvn.resolve_dependencies_list(deps)
|
52
|
+
deps
|
53
|
+
end
|
54
|
+
private :resolve_dependencies
|
55
|
+
|
56
|
+
def require(scope = nil)
|
57
|
+
process(scope) do |jar|
|
58
|
+
if jar.scope == :system
|
59
|
+
Kernel.require jar.path
|
60
|
+
else
|
61
|
+
require_jar(*jar.gacv)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
return unless scope.nil? || scope == :runtime
|
65
|
+
|
66
|
+
process(:provided) do |jar|
|
67
|
+
Jars.mark_as_required(*jar.gacv)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def classpath(scope = nil)
|
72
|
+
classpath = []
|
73
|
+
process(scope) do |jar|
|
74
|
+
classpath << jar.file
|
75
|
+
end
|
76
|
+
classpath
|
77
|
+
end
|
78
|
+
|
79
|
+
def process(scope, &block)
|
80
|
+
deps = dependencies_list
|
81
|
+
Lock.new(deps).process(scope, &block)
|
82
|
+
ensure
|
83
|
+
# just delete the temporary file if it exists
|
84
|
+
FileUtils.rm_f(DEPENDENCY_LIST)
|
85
|
+
end
|
86
|
+
private :process
|
87
|
+
|
88
|
+
def classpath_string(scope = nil)
|
89
|
+
classpath(scope).join(File::PATH_SEPARATOR)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|