lock_jar 0.15.11-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.codeclimate.yml +16 -0
- data/.gitignore +59 -0
- data/.rubocop.yml +31 -0
- data/.travis.yml +21 -0
- data/CHANGELOG.md +80 -0
- data/Gemfile +13 -0
- data/Guardfile +8 -0
- data/LICENSE +176 -0
- data/README.md +392 -0
- data/Rakefile +28 -0
- data/bin/lockjar +6 -0
- data/lib/lock_jar/buildr.rb +151 -0
- data/lib/lock_jar/bundler.rb +68 -0
- data/lib/lock_jar/class_loader.rb +67 -0
- data/lib/lock_jar/cli.rb +92 -0
- data/lib/lock_jar/config.rb +41 -0
- data/lib/lock_jar/domain/artifact.rb +114 -0
- data/lib/lock_jar/domain/dsl.rb +165 -0
- data/lib/lock_jar/domain/dsl_merger.rb +76 -0
- data/lib/lock_jar/domain/gem_dsl.rb +43 -0
- data/lib/lock_jar/domain/jarfile_dsl.rb +35 -0
- data/lib/lock_jar/domain/lockfile.rb +113 -0
- data/lib/lock_jar/logging.rb +14 -0
- data/lib/lock_jar/maven.rb +112 -0
- data/lib/lock_jar/registry.rb +85 -0
- data/lib/lock_jar/resolver.rb +100 -0
- data/lib/lock_jar/runtime/install.rb +28 -0
- data/lib/lock_jar/runtime/list.rb +77 -0
- data/lib/lock_jar/runtime/load.rb +53 -0
- data/lib/lock_jar/runtime/lock.rb +152 -0
- data/lib/lock_jar/runtime.rb +106 -0
- data/lib/lock_jar/version.rb +5 -0
- data/lib/lock_jar.rb +203 -0
- data/lock_jar.gemspec +36 -0
- data/spec/fixtures/Jarfile +14 -0
- data/spec/fixtures/Jarfile2 +1 -0
- data/spec/fixtures/jarfile_gem/Gemfile +4 -0
- data/spec/fixtures/jarfile_gem/Jarfile +1 -0
- data/spec/fixtures/jarfile_gem/jarfile_gem.gemspec +23 -0
- data/spec/fixtures/jarfile_gem/lib/jarfile_gem/version.rb +3 -0
- data/spec/fixtures/jarfile_gem/lib/jarfile_gem.rb +5 -0
- data/spec/fixtures/lock_jar_config.yml +4 -0
- data/spec/fixtures/naether-0.13.0.jar +0 -0
- data/spec/lock_jar/bundler_spec.rb +34 -0
- data/spec/lock_jar/class_loader_spec.rb +55 -0
- data/spec/lock_jar/cli_spec.rb +93 -0
- data/spec/lock_jar/config_spec.rb +51 -0
- data/spec/lock_jar/domain/dsl_merger_spec.rb +51 -0
- data/spec/lock_jar/domain/dsl_spec.rb +55 -0
- data/spec/lock_jar/domain/gem_dsl_spec.rb +18 -0
- data/spec/lock_jar/maven_spec.rb +21 -0
- data/spec/lock_jar/resolver_spec.rb +69 -0
- data/spec/lock_jar/runtime_spec.rb +30 -0
- data/spec/lock_jar_spec.rb +472 -0
- data/spec/pom.xml +28 -0
- data/spec/spec_helper.rb +45 -0
- data/spec/support/Jarfile +1 -0
- data/spec/support/helper.rb +52 -0
- data/spec/support/shared_examples/lockfile.rb +45 -0
- metadata +203 -0
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
3
|
+
module LockJar
|
4
|
+
#
|
5
|
+
class Runtime
|
6
|
+
#
|
7
|
+
class Lock < SimpleDelegator
|
8
|
+
attr_accessor :jarfile, :lockfile, :opts
|
9
|
+
|
10
|
+
def initialize(runtime)
|
11
|
+
super(runtime)
|
12
|
+
|
13
|
+
@lockfile = LockJar::Domain::Lockfile.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def lock(jarfile_or_dsl, opts = {}, &blk)
|
17
|
+
@opts = { download: true }.merge(opts)
|
18
|
+
|
19
|
+
create_dsl!(jarfile_or_dsl, &blk)
|
20
|
+
|
21
|
+
apply_repositories!
|
22
|
+
|
23
|
+
apply_maps!
|
24
|
+
|
25
|
+
apply_excludes!
|
26
|
+
|
27
|
+
apply_merged!
|
28
|
+
|
29
|
+
artifacts = jarfile.artifacts.values.flatten
|
30
|
+
apply_artifacts!(artifacts) unless artifacts.empty?
|
31
|
+
|
32
|
+
lockfile.write(@opts[:lockfile] || 'Jarfile.lock')
|
33
|
+
|
34
|
+
lockfile
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def create_dsl!(jarfile_or_dsl, &blk)
|
40
|
+
if jarfile_or_dsl
|
41
|
+
@jarfile = if jarfile_or_dsl.is_a? LockJar::Domain::Dsl
|
42
|
+
jarfile_or_dsl
|
43
|
+
else
|
44
|
+
LockJar::Domain::JarfileDsl.create(jarfile_or_dsl)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
return @jarfile if blk.nil?
|
49
|
+
|
50
|
+
if @jarfile
|
51
|
+
@jarfile = LockJar::Domain::DslMerger.new(
|
52
|
+
jarfile, LockJar::Domain::Dsl.create(&blk)).merge
|
53
|
+
else
|
54
|
+
@jarfile = LockJar::Domain::Dsl.create(&blk)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# rubocop:disable Metrics/AbcSize
|
59
|
+
def apply_artifacts!(artifacts)
|
60
|
+
# Build the dependencies_graph hash in the resolver
|
61
|
+
resolver(opts).resolve(
|
62
|
+
artifacts.select(&:resolvable?).map(&:to_dep), opts[:download] == true
|
63
|
+
)
|
64
|
+
|
65
|
+
jarfile.artifacts.each do |group_name, group_artifacts|
|
66
|
+
group = { 'locals' => [], 'dependencies' => [], 'artifacts' => [] }
|
67
|
+
|
68
|
+
group_artifacts.each do |artifact|
|
69
|
+
artifact_data = {}
|
70
|
+
|
71
|
+
add_artifact!(group, artifact_data, artifact)
|
72
|
+
|
73
|
+
next unless artifact_data['transitive']
|
74
|
+
|
75
|
+
# flatten the graph of nested hashes
|
76
|
+
group['dependencies'] += dependency_merge(artifact_data['transitive'])
|
77
|
+
# xxX: set required_by ?
|
78
|
+
group['artifacts'] << { artifact.to_urn => artifact_data }
|
79
|
+
end
|
80
|
+
|
81
|
+
lockfile.excludes.each do |exclude|
|
82
|
+
group['dependencies'].delete_if { |dep| dep =~ /#{exclude}/ }
|
83
|
+
end if lockfile.excludes
|
84
|
+
|
85
|
+
group['dependencies'] = group['dependencies'].sort.uniq
|
86
|
+
|
87
|
+
group.delete 'locals' if group['locals'].empty?
|
88
|
+
|
89
|
+
lockfile.groups[group_name] = group
|
90
|
+
end
|
91
|
+
end
|
92
|
+
# rubocop:enable Metrics/AbcSize
|
93
|
+
|
94
|
+
def apply_excludes!
|
95
|
+
lockfile.excludes = jarfile.excludes if jarfile.excludes.size > 0
|
96
|
+
end
|
97
|
+
|
98
|
+
def apply_maps!
|
99
|
+
lockfile.maps = jarfile.maps if jarfile.maps.size > 0
|
100
|
+
end
|
101
|
+
|
102
|
+
def apply_merged!
|
103
|
+
lockfile.merged = jarfile.merged unless jarfile.merged.empty?
|
104
|
+
end
|
105
|
+
|
106
|
+
def apply_repositories!
|
107
|
+
lockfile.local_repository = opts[:local_repo] ||= jarfile.local_repository
|
108
|
+
|
109
|
+
if jarfile.clear_repositories
|
110
|
+
resolver(opts).clear_remote_repositories
|
111
|
+
else
|
112
|
+
repos = resolver(opts).remote_repositories
|
113
|
+
lockfile.remote_repositories += repos.to_a if repos
|
114
|
+
end
|
115
|
+
|
116
|
+
# Add remote repos to the resolver and the lockfile
|
117
|
+
jarfile.remote_repositories.each do |repo|
|
118
|
+
resolver(opts).add_remote_repository(repo)
|
119
|
+
lockfile.remote_repositories << repo
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def add_artifact!(group, artifact_data, artifact)
|
124
|
+
if artifact.is_a? LockJar::Domain::Jar
|
125
|
+
group['dependencies'] << artifact.notation
|
126
|
+
g = resolver(opts).dependencies_graph[artifact.notation]
|
127
|
+
artifact_data['transitive'] = g.to_hash if g
|
128
|
+
|
129
|
+
elsif artifact.is_a? LockJar::Domain::Pom
|
130
|
+
artifact_data['scopes'] = artifact.scopes
|
131
|
+
|
132
|
+
# iterate each dependency in Pom to map transitive dependencies
|
133
|
+
transitive = {}
|
134
|
+
artifact.notations.each do |notation|
|
135
|
+
transitive[notation] = resolver(opts).dependencies_graph[notation]
|
136
|
+
end
|
137
|
+
artifact_data['transitive'] = transitive
|
138
|
+
|
139
|
+
elsif artifact.is_a? LockJar::Domain::Local
|
140
|
+
group['locals'] << artifact.path
|
141
|
+
else
|
142
|
+
fail("Unsupported artifact: #{artifact.inspect}")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def dependency_merge(graph)
|
147
|
+
deps = graph.keys
|
148
|
+
graph.values.flat_map { |next_step| deps += dependency_merge(next_step) }
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with this
|
3
|
+
# work for additional information regarding copyright ownership. The ASF
|
4
|
+
# licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations under
|
14
|
+
# the License.
|
15
|
+
|
16
|
+
require 'yaml'
|
17
|
+
require 'singleton'
|
18
|
+
require 'lock_jar/config'
|
19
|
+
require 'lock_jar/resolver'
|
20
|
+
require 'lock_jar/registry'
|
21
|
+
require 'lock_jar/domain/dsl'
|
22
|
+
require 'lock_jar/domain/jarfile_dsl'
|
23
|
+
require 'lock_jar/domain/lockfile'
|
24
|
+
require 'lock_jar/runtime/load'
|
25
|
+
require 'lock_jar/runtime/lock'
|
26
|
+
require 'lock_jar/runtime/list'
|
27
|
+
require 'lock_jar/runtime/install'
|
28
|
+
|
29
|
+
module LockJar
|
30
|
+
#
|
31
|
+
class Runtime
|
32
|
+
include Singleton
|
33
|
+
include Load
|
34
|
+
include List
|
35
|
+
include Install
|
36
|
+
|
37
|
+
attr_reader :current_resolver, :config
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
@config = Config.load_config_file
|
41
|
+
@current_resolver = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def lock(jarfile_or_dsl, opts = {}, &blk)
|
45
|
+
Lock.new(self).lock(jarfile_or_dsl, opts, &blk)
|
46
|
+
end
|
47
|
+
|
48
|
+
def opts
|
49
|
+
current_resolver.opts if current_resolver
|
50
|
+
end
|
51
|
+
|
52
|
+
def resolver(opts = {})
|
53
|
+
# XXX: Caches the resolver by the options. Passing in nil opts will replay
|
54
|
+
# from the cache. This need to change.
|
55
|
+
if !opts.nil?
|
56
|
+
opts[:local_repo] = File.expand_path(opts[:local_repo]) if opts[:local_repo]
|
57
|
+
elsif @current_resolver
|
58
|
+
opts = @current_resolver.opts
|
59
|
+
else
|
60
|
+
opts = {}
|
61
|
+
end
|
62
|
+
|
63
|
+
if @current_resolver.nil? || opts != @current_resolver.opts
|
64
|
+
@current_resolver = LockJar::Resolver.new(config, opts)
|
65
|
+
end
|
66
|
+
|
67
|
+
@current_resolver
|
68
|
+
end
|
69
|
+
|
70
|
+
def reset!
|
71
|
+
@current_resolver = nil
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def lockfile_dependencies(lockfile, groups, with_locals = true)
|
77
|
+
dependencies = []
|
78
|
+
|
79
|
+
groups.each do |group|
|
80
|
+
next unless lockfile.groups[group.to_s]
|
81
|
+
dependencies += yield lockfile.groups[group.to_s]
|
82
|
+
|
83
|
+
if with_locals
|
84
|
+
locals = lockfile.groups[group.to_s]['locals']
|
85
|
+
dependencies += locals if locals
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
dependencies
|
90
|
+
end
|
91
|
+
|
92
|
+
def dsl_dependencies(dsl, groups, with_locals = true)
|
93
|
+
dependencies = []
|
94
|
+
|
95
|
+
groups.each do |group|
|
96
|
+
dependencies += dsl.artifacts[group.to_s] if dsl.artifacts[group.to_s]
|
97
|
+
end
|
98
|
+
|
99
|
+
unless with_locals
|
100
|
+
dependencies.select! { |dep| !dep.is_a? LockJar::Domain::Local }
|
101
|
+
end
|
102
|
+
|
103
|
+
dependencies
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
data/lib/lock_jar.rb
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with this
|
3
|
+
# work for additional information regarding copyright ownership. The ASF
|
4
|
+
# licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations under
|
14
|
+
# the License.
|
15
|
+
|
16
|
+
require 'yaml'
|
17
|
+
require 'lock_jar/config'
|
18
|
+
require 'lock_jar/resolver'
|
19
|
+
require 'lock_jar/runtime'
|
20
|
+
require 'lock_jar/version'
|
21
|
+
require 'lock_jar/domain/lockfile'
|
22
|
+
require 'lock_jar/domain/jarfile_dsl'
|
23
|
+
require 'lock_jar/domain/gem_dsl'
|
24
|
+
require 'lock_jar/domain/dsl'
|
25
|
+
|
26
|
+
#
|
27
|
+
# LockJar manages Java Jars for Ruby.
|
28
|
+
#
|
29
|
+
# @author Michael Guymon
|
30
|
+
#
|
31
|
+
module LockJar
|
32
|
+
class << self
|
33
|
+
#
|
34
|
+
# Override LockJar configuration
|
35
|
+
#
|
36
|
+
def config(opts)
|
37
|
+
Runtime.instance.resolver(opts)
|
38
|
+
end
|
39
|
+
|
40
|
+
def install(*args, &blk)
|
41
|
+
lockfile, groups, opts = extract_args :lockfile, args, &blk
|
42
|
+
Runtime.instance.install(lockfile, groups, opts, &blk)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Lists all dependencies as notations for groups from the Jarfile.lock.
|
46
|
+
# Depending on the type of arg, a different configuration is set.
|
47
|
+
#
|
48
|
+
# * An arg of a String will set the Jarfile.lock, e.g. 'Better.lock'.
|
49
|
+
# Default lock file is *Jarfile.lock*.
|
50
|
+
# * An arg of an Array will set the groups, e.g. ['development','test'].
|
51
|
+
# Defaults group is *default*
|
52
|
+
# * An arg of a Hash will set the options, e.g. { :local_repo => 'path' }
|
53
|
+
# * :local_repo [String] sets the local repo path
|
54
|
+
# * :local_paths [Boolean] to true converts the notations to paths to jars
|
55
|
+
# in the local repo path
|
56
|
+
# * :resolve [Boolean] to true will make transitive dependences resolve
|
57
|
+
# before loading to classpath
|
58
|
+
#
|
59
|
+
# A block can be passed in, overriding values from a Jarfile.lock.
|
60
|
+
#
|
61
|
+
# @return [Array] of jar and mapped path
|
62
|
+
def list(*args, &blk)
|
63
|
+
lockfile, groups, opts = extract_args :lockfile, args, &blk
|
64
|
+
Runtime.instance.list(lockfile, groups, opts, &blk)
|
65
|
+
end
|
66
|
+
|
67
|
+
# LockJar.load(*args): Loads all dependencies to the classpath for groups
|
68
|
+
# from the Jarfile.lock. Depending on the type of arg, a different configuration is set.
|
69
|
+
# * An arg of a String will set the Jarfile.lock, e.g. 'Better.lock'.
|
70
|
+
# Default lock file is *Jarfile.lock*.
|
71
|
+
# * An arg of an Array will set the groups, e.g. ['development','test'].
|
72
|
+
# Defaults group is *default*.
|
73
|
+
# * An arg of a Hash will set the options, e.g. { :local_repo => 'path' }
|
74
|
+
# * :local_repo [String] sets the local repo path
|
75
|
+
# * :resolve [Boolean] to true will make transitive dependences resolve
|
76
|
+
# before loading to classpath
|
77
|
+
# * :disable [Boolean] to true will disable any additional calls to load and lock
|
78
|
+
#
|
79
|
+
# A block can be passed in, overriding values from a Jarfile.lock.
|
80
|
+
#
|
81
|
+
# @return [Array] of absolute paths of jars and mapped paths loaded into claspath
|
82
|
+
def load(*args, &blk)
|
83
|
+
if Runtime.instance.opts.nil? || !Runtime.instance.opts[:disable]
|
84
|
+
lockfile, groups, opts = extract_args(:lockfile, args, &blk)
|
85
|
+
Runtime.instance.load(lockfile, groups, opts, &blk)
|
86
|
+
else
|
87
|
+
puts 'LockJar#load has been disabled'
|
88
|
+
[]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Lock a Jarfile and generate a Jarfile.lock.
|
93
|
+
#
|
94
|
+
# LockJar.lock accepts an Array for parameters. Depending on the type of
|
95
|
+
# arg, a different configuration is set.
|
96
|
+
#
|
97
|
+
# * An arg of a String will set the Jarfile, e.g. 'Jarfile.different'.
|
98
|
+
# Default Jarfile is *Jarfile*.
|
99
|
+
# * An arg of a Hash will set the options, e.g. { :local_repo => 'path' }
|
100
|
+
# * :download_artifacts if true, will download jars to local repo. Defaults to true.
|
101
|
+
# * :local_repo sets the local repo path
|
102
|
+
# * :lockfile sets the Jarfile.lock path. Default lockfile is *Jarfile.lock*.
|
103
|
+
# * :disable [Boolean] to true will disable any additional calls to load and lock
|
104
|
+
|
105
|
+
# A block can be passed in, overriding values from a Jarfile.
|
106
|
+
#
|
107
|
+
# @return [Hash] Lock data
|
108
|
+
def lock(*args, &blk)
|
109
|
+
if Runtime.instance.opts.nil? || !Runtime.instance.opts[:disable]
|
110
|
+
jarfile, _, opts = extract_args(:jarfile, args, &blk)
|
111
|
+
Runtime.instance.lock(jarfile, opts, &blk)
|
112
|
+
else
|
113
|
+
puts 'LockJar#lock has been disabled'
|
114
|
+
[]
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# Read a Jafile.lock and convert it to a LockJar::Domain::Lockfile
|
120
|
+
#
|
121
|
+
# @param [String] lockfile path to lockfile
|
122
|
+
# @return [Hash] Lock Data
|
123
|
+
def read(lockfile)
|
124
|
+
LockJar::Domain::Lockfile.read(lockfile)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Add a Jarfile to be included when LockJar.lock_registered_jarfiles is called.
|
128
|
+
#
|
129
|
+
# @param [String] jarfile path to register
|
130
|
+
# @param [GemSpec] gem spec if the Jarfile is from a gem
|
131
|
+
# @return [Array] All registered jarfiles
|
132
|
+
def register_jarfile(jarfile, gem_spec = nil)
|
133
|
+
fail "Jarfile not found: #{jarfile}" unless File.exist? jarfile
|
134
|
+
registered_jarfiles[jarfile] = gem_spec
|
135
|
+
end
|
136
|
+
|
137
|
+
# Clear all registered jarfiles
|
138
|
+
def reset_registered_jarfiles
|
139
|
+
@registered_jarfiles = {}
|
140
|
+
end
|
141
|
+
|
142
|
+
# Hash of registered jarfiles
|
143
|
+
def registered_jarfiles
|
144
|
+
@registered_jarfiles ||= {}
|
145
|
+
end
|
146
|
+
|
147
|
+
# Lock the registered Jarfiles and generate a Jarfile.lock.
|
148
|
+
#
|
149
|
+
# Options and groups are passed through to the LockJar.lock method, but
|
150
|
+
# if a Jarfile is specified, it will be ignored. Use LockJar.register_jarfile
|
151
|
+
# to add dependencies.
|
152
|
+
#
|
153
|
+
# A block can be passed in, overriding values from the Jarfiles.
|
154
|
+
#
|
155
|
+
# @return [Hash] Lock data
|
156
|
+
def lock_registered_jarfiles(*args, &blk)
|
157
|
+
jarfiles = registered_jarfiles
|
158
|
+
return if jarfiles.empty?
|
159
|
+
instances = jarfiles.map do |jarfile, spec|
|
160
|
+
if spec
|
161
|
+
LockJar::Domain::GemDsl.create spec, jarfile
|
162
|
+
else
|
163
|
+
LockJar::Domain::JarfileDsl.create jarfile
|
164
|
+
end
|
165
|
+
end
|
166
|
+
combined = instances.reduce do |result, inst|
|
167
|
+
LockJar::Domain::DslMerger.new(result, inst).merge
|
168
|
+
end
|
169
|
+
args = args.reject { |arg| arg.is_a? String }
|
170
|
+
lock(combined, *args, &blk)
|
171
|
+
end
|
172
|
+
|
173
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
174
|
+
def extract_args(type, args, &blk)
|
175
|
+
lockfile_or_path = nil
|
176
|
+
opts = {}
|
177
|
+
groups = ['default']
|
178
|
+
args.each do |arg|
|
179
|
+
case arg
|
180
|
+
when Hash
|
181
|
+
opts.merge!(arg)
|
182
|
+
when String
|
183
|
+
lockfile_or_path = arg
|
184
|
+
when LockJar::Domain::Lockfile
|
185
|
+
lockfile_or_path = arg if type == :lockfile
|
186
|
+
when LockJar::Domain::Dsl
|
187
|
+
lockfile_or_path = arg if type == :jarfile
|
188
|
+
when Array
|
189
|
+
groups = arg
|
190
|
+
end
|
191
|
+
end
|
192
|
+
if blk.nil? && lockfile_or_path.nil?
|
193
|
+
if type == :lockfile
|
194
|
+
lockfile_or_path = opts.fetch(:lockfile, 'Jarfile.lock')
|
195
|
+
elsif type == :jarfile
|
196
|
+
lockfile_or_path = 'Jarfile'
|
197
|
+
end
|
198
|
+
end
|
199
|
+
[lockfile_or_path, groups, opts]
|
200
|
+
end
|
201
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
202
|
+
end
|
203
|
+
end
|
data/lock_jar.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'lock_jar/version'
|
6
|
+
|
7
|
+
unless RUBY_PLATFORM == 'java'
|
8
|
+
raise "lock_jar requires JRuby. Current platform: #{RUBY_PLATFORM}. Please install and use JRuby to run this gem."
|
9
|
+
end
|
10
|
+
|
11
|
+
Gem::Specification.new do |s|
|
12
|
+
s.name = 'lock_jar'
|
13
|
+
s.version = LockJar::VERSION
|
14
|
+
s.authors = ['Michael Guymon']
|
15
|
+
s.date = '2014-03-06'
|
16
|
+
s.description = 'Manage Jar files for Ruby. In the spirit of Bundler, a Jarfile
|
17
|
+
is used to generate a Jarfile.lock that contains all the resolved jar dependencies
|
18
|
+
for scopes runtime, compile, and test. The Jarfile.lock can be used to populate the
|
19
|
+
classpath'
|
20
|
+
s.email = 'michael@tobedevoured.com'
|
21
|
+
s.files = `git ls-files -z`.split("\x0")
|
22
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
24
|
+
s.extra_rdoc_files = %w(LICENSE README.md)
|
25
|
+
s.homepage = 'http://github.com/mguymon/lock_jar'
|
26
|
+
s.licenses = %w(Apache)
|
27
|
+
s.require_paths = %w(lib)
|
28
|
+
s.summary = 'Manage Jar files for Ruby'
|
29
|
+
s.platform = 'java'
|
30
|
+
|
31
|
+
s.add_dependency('naether', ['~> 0.15.11'])
|
32
|
+
s.add_dependency('thor', ['>= 0.18.1'])
|
33
|
+
s.add_development_dependency('rspec', '~> 3.0')
|
34
|
+
s.add_development_dependency('rubocop', '~> 0.35.0')
|
35
|
+
s.add_development_dependency('rake')
|
36
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
local_repo '~/.m2/repository'
|
2
|
+
repository 'http://mirrors.ibiblio.org/pub/mirrors/maven2'
|
3
|
+
|
4
|
+
jar "org.apache.mina:mina-core:2.0.4"
|
5
|
+
local "spec/fixtures/naether-0.13.0.jar"
|
6
|
+
pom 'spec/pom.xml'
|
7
|
+
|
8
|
+
group 'development' do
|
9
|
+
jar 'com.typesafe:config:jar:0.5.0'
|
10
|
+
end
|
11
|
+
|
12
|
+
group 'test' do
|
13
|
+
jar 'org.testng:testng:jar:6.9.10'
|
14
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
jar "org.eclipse.jetty:jetty-servlet:8.1.3.v20120416"
|
@@ -0,0 +1 @@
|
|
1
|
+
jar 'commons-lang:commons-lang:jar:2.4'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jarfile_gem/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jarfile_gem"
|
8
|
+
spec.version = JarfileGem::VERSION
|
9
|
+
spec.authors = ["Michael Guymon"]
|
10
|
+
spec.email = ["michael@tobedevoured.com"]
|
11
|
+
spec.summary = %q{a short summary.}
|
12
|
+
spec.description = %q{a longer description.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
Binary file
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'lock_jar/bundler'
|
3
|
+
require 'bundler/cli'
|
4
|
+
require 'bundler/cli/install'
|
5
|
+
|
6
|
+
describe LockJar::Bundler do
|
7
|
+
include Spec::Helpers
|
8
|
+
|
9
|
+
describe '.lock!' do
|
10
|
+
let(:bundler) do
|
11
|
+
Class.new { attr_accessor :setup }.new
|
12
|
+
end
|
13
|
+
|
14
|
+
before do
|
15
|
+
remove_file('Jarfile.lock')
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when Bundler.install has run' do
|
19
|
+
xit 'should create Jarfile.lock' do
|
20
|
+
LockJar::Bundler.lock!('spec/fixtures/Jarfile')
|
21
|
+
expect(File).to exist('Jarfile.lock')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when Bundler.setup has run' do
|
26
|
+
before { bundler.setup = true }
|
27
|
+
|
28
|
+
it 'should not create Jarfile.lock' do
|
29
|
+
LockJar::Bundler.lock!(bundler, 'spec/fixtures/Jarfile')
|
30
|
+
expect(File).to_not exist('Jarfile.lock')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'lock_jar/class_loader'
|
3
|
+
|
4
|
+
describe LockJar::ClassLoader, '#isolate' do
|
5
|
+
if Naether.platform != 'java'
|
6
|
+
pending 'need tests for RJB backed classloader'
|
7
|
+
else
|
8
|
+
it 'should create a SimpleEmail' do
|
9
|
+
# Generate the IsolateJarfile.lock
|
10
|
+
LockJar.lock(lockfile: "#{TEMP_DIR}/IsolateJarfile.lock") do
|
11
|
+
jar 'org.apache.commons:commons-email:1.2'
|
12
|
+
end
|
13
|
+
|
14
|
+
email = LockJar::ClassLoader.new("#{TEMP_DIR}/IsolateJarfile.lock").isolate do
|
15
|
+
email = new_instance('org.apache.commons.mail.SimpleEmail')
|
16
|
+
email.setSubject('test subject')
|
17
|
+
|
18
|
+
email
|
19
|
+
end
|
20
|
+
|
21
|
+
email.getSubject.should eql 'test subject'
|
22
|
+
|
23
|
+
unless $CLASSPATH.nil?
|
24
|
+
$CLASSPATH.to_a.join(' ').should_not =~ /commons-email-1\.2\.jar/
|
25
|
+
end
|
26
|
+
|
27
|
+
expect { org.apache.commons.mail.SimpleEmail.new }.to raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should create a JsonFactory and ObjectMapper' do
|
31
|
+
# Generate the IsolateJarfile.lock
|
32
|
+
LockJar.lock(lockfile: "#{TEMP_DIR}/IsolateJarfile.lock") do
|
33
|
+
jar 'com.fasterxml.jackson.core:jackson-core:2.0.6'
|
34
|
+
jar 'com.fasterxml.jackson.core:jackson-databind:2.0.6'
|
35
|
+
end
|
36
|
+
|
37
|
+
json = '{ "test1": "1test1", "test2": "2test2" }'
|
38
|
+
|
39
|
+
map = LockJar::ClassLoader.new("#{TEMP_DIR}/IsolateJarfile.lock").isolate do
|
40
|
+
factory = new_instance('com.fasterxml.jackson.core.JsonFactory')
|
41
|
+
mapper = new_instance('com.fasterxml.jackson.databind.ObjectMapper', factory)
|
42
|
+
mapper.readValue(json, java.util.Map.java_class)
|
43
|
+
end
|
44
|
+
|
45
|
+
map.get('test1').should eql '1test1'
|
46
|
+
map.get('test2').should eql '2test2'
|
47
|
+
|
48
|
+
unless $CLASSPATH.nil?
|
49
|
+
$CLASSPATH.to_a.join(' ').should_not =~ /jackson-databind-2\.0\.6\.jar/
|
50
|
+
end
|
51
|
+
|
52
|
+
expect { com.fasterxml.jackson.core.JsonFactory.new }.to raise_error
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|