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,113 @@
|
|
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 'set'
|
18
|
+
require 'lock_jar/version'
|
19
|
+
|
20
|
+
module LockJar
|
21
|
+
module Domain
|
22
|
+
# Class representation of the lock file
|
23
|
+
class Lockfile
|
24
|
+
attr_accessor :local_repository, :maps, :excludes, :remote_repositories,
|
25
|
+
:version, :groups, :gems, :merged
|
26
|
+
|
27
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
28
|
+
def self.read(path)
|
29
|
+
lock_data = fs_or_classpath(path)
|
30
|
+
|
31
|
+
fail "lockfile #{path} not found" if lock_data.nil?
|
32
|
+
|
33
|
+
Lockfile.new.tap do |lockfile|
|
34
|
+
lockfile.version = lock_data['version'] || LockJar::VERSION
|
35
|
+
lockfile.merged = lock_data['merged']
|
36
|
+
lockfile.local_repository = lock_data['local_repository']
|
37
|
+
lockfile.merged = lock_data['merged'] || []
|
38
|
+
lockfile.maps = lock_data['maps'] || []
|
39
|
+
lockfile.excludes = lock_data['excludes'] || []
|
40
|
+
lockfile.groups = lock_data['groups'] || lock_data['scopes'] || {}
|
41
|
+
lockfile.remote_repositories =
|
42
|
+
Set.new(Array(lock_data['remote_repositories'] || lock_data['repositories']))
|
43
|
+
lockfile.gems = lock_data['gems'] || []
|
44
|
+
end
|
45
|
+
end
|
46
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
47
|
+
|
48
|
+
def self.fs_or_classpath(path)
|
49
|
+
if File.exist? path
|
50
|
+
YAML.load_file(path)
|
51
|
+
|
52
|
+
# Lookup of Jarfile.lock in the classpath
|
53
|
+
elsif Naether.platform == 'java' || path.start_with?('classpath:')
|
54
|
+
stream = java.lang.Object.java_class.resource_as_stream("/#{path.gsub('classpath:', '')}")
|
55
|
+
if stream
|
56
|
+
reader = java.io.BufferedReader.new(java.io.InputStreamReader.new(stream))
|
57
|
+
lines = ''
|
58
|
+
while (line = reader.read_line)
|
59
|
+
lines << line << "\n"
|
60
|
+
end
|
61
|
+
reader.close
|
62
|
+
|
63
|
+
YAML.load(lines)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def initialize
|
69
|
+
@groups = { 'default' => {} }
|
70
|
+
@maps = []
|
71
|
+
@excludes = []
|
72
|
+
@remote_repositories = Set.new
|
73
|
+
@gems = []
|
74
|
+
@merged = []
|
75
|
+
|
76
|
+
@version = LockJar::VERSION # default version
|
77
|
+
end
|
78
|
+
|
79
|
+
def to_hash
|
80
|
+
lock_data = { 'version' => @version }
|
81
|
+
|
82
|
+
lock_data['local_repository'] = local_repository unless local_repository.nil?
|
83
|
+
|
84
|
+
lock_data['merged'] = merged unless merged.empty?
|
85
|
+
|
86
|
+
lock_data['maps'] = maps if maps.size > 0
|
87
|
+
|
88
|
+
lock_data['excludes'] = excludes if excludes.size > 0
|
89
|
+
|
90
|
+
lock_data['gems'] = gems unless gems.empty?
|
91
|
+
|
92
|
+
lock_data['groups'] = groups
|
93
|
+
|
94
|
+
if remote_repositories.size > 0
|
95
|
+
lock_data['remote_repositories'] = remote_repositories.to_a
|
96
|
+
end
|
97
|
+
|
98
|
+
lock_data
|
99
|
+
end
|
100
|
+
alias_method :to_h, :to_hash
|
101
|
+
|
102
|
+
def to_yaml
|
103
|
+
to_hash.to_yaml
|
104
|
+
end
|
105
|
+
|
106
|
+
def write(path)
|
107
|
+
File.open(path, 'w') do |f|
|
108
|
+
f.write(to_yaml)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,112 @@
|
|
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 'naether/maven'
|
17
|
+
|
18
|
+
module LockJar
|
19
|
+
# Helper for providing Maven specific operations
|
20
|
+
#
|
21
|
+
# @author Michael Guymon
|
22
|
+
#
|
23
|
+
class Maven
|
24
|
+
class << self
|
25
|
+
#
|
26
|
+
# Get the version of a POM
|
27
|
+
#
|
28
|
+
# @param [String] pom_path path to the pom
|
29
|
+
#
|
30
|
+
# @return [String] version of POM
|
31
|
+
#
|
32
|
+
def pom_version(pom_path)
|
33
|
+
maven = Naether::Maven.create_from_pom(pom_path)
|
34
|
+
maven.version
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# Get dependencies of a Pom
|
39
|
+
#
|
40
|
+
# @param [String] pom_path path to the pom
|
41
|
+
# @param [Array] scopes
|
42
|
+
#
|
43
|
+
# @return [String] version of POM
|
44
|
+
#
|
45
|
+
def dependencies(pom_path, scopes = %w(compile runtime))
|
46
|
+
maven = Naether::Maven.create_from_pom(pom_path)
|
47
|
+
maven.dependencies(scopes)
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Write a POM from list of notations
|
52
|
+
#
|
53
|
+
# @param [String] pom notation
|
54
|
+
# @param [String] file_path path of new pom
|
55
|
+
# @param [Hash] opts
|
56
|
+
# @option opts [Boolean] :include_resolved to add dependencies of resolve
|
57
|
+
# dependencies from Jarfile.lock. Default is true.
|
58
|
+
# @option opts [Array] :dependencies Array of of mixed dependencies:
|
59
|
+
# * [String] Artifact notation, such as groupId:artifactId:version, e.g. 'junit:junit:4.7'
|
60
|
+
# * [Hash] of a single artifaction notation => scope - { 'junit:junit:4.7' => 'test' }
|
61
|
+
#
|
62
|
+
def write_pom(notation, file_path, opts = {})
|
63
|
+
opts = { include_resolved: true }.merge(opts)
|
64
|
+
|
65
|
+
maven = Naether::Maven.create_from_notataion(notation)
|
66
|
+
|
67
|
+
if opts[:include_resolved]
|
68
|
+
# Passes in nil to the resolver to get the cache
|
69
|
+
maven.load_naether(Runtime.instance.resolver.naether)
|
70
|
+
end
|
71
|
+
|
72
|
+
if opts[:dependencies]
|
73
|
+
opts[:dependencies].each do |dep|
|
74
|
+
if dep.is_a? Array
|
75
|
+
maven.add_dependency(dep[0], dep[1])
|
76
|
+
else
|
77
|
+
maven.add_dependency(dep)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
maven.write_pom(file_path)
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
# Deploy an artifact to a Maven repository
|
87
|
+
#
|
88
|
+
# @param [String] notation of artifact
|
89
|
+
# @param [String] file_path path to the Jar
|
90
|
+
# @param [String] url Maven repository deploying to
|
91
|
+
# @param [Hash] deploy_opts options for deploying
|
92
|
+
# @param [Hash] lockjar_opts options for initializing LockJar
|
93
|
+
#
|
94
|
+
def deploy_artifact(notation, file_path, url, deploy_opts = {}, lockjar_opts = {})
|
95
|
+
Runtime.instance.resolver(lockjar_opts).naether.deploy_artifact(
|
96
|
+
notation, file_path, url, deploy_opts)
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# Install an artifact to a local repository
|
101
|
+
#
|
102
|
+
# @param [String] notation of artifact
|
103
|
+
# @param [String] pom_path path to the pom
|
104
|
+
# @param [String] jar_path path to the jar
|
105
|
+
# @param [Hash] opts options
|
106
|
+
#
|
107
|
+
def install(notation, pom_path, jar_path, opts = {})
|
108
|
+
Runtime.instance.resolver(opts).naether.install(notation, pom_path, jar_path)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,85 @@
|
|
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 'singleton'
|
17
|
+
|
18
|
+
module LockJar
|
19
|
+
#
|
20
|
+
# Registry of resources loaded by LockJar
|
21
|
+
#
|
22
|
+
# @author Michael Guymon
|
23
|
+
#
|
24
|
+
class Registry
|
25
|
+
include Singleton
|
26
|
+
|
27
|
+
attr_accessor :loaded_gems, :loaded_jars, :loaded_lockfiles
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
@loaded_gems = {}
|
31
|
+
@loaded_jars = []
|
32
|
+
@loaded_lockfiles = []
|
33
|
+
end
|
34
|
+
|
35
|
+
def lockfile_registered?(lockfile)
|
36
|
+
@loaded_lockfiles.include? File.expand_path(lockfile) if lockfile
|
37
|
+
end
|
38
|
+
|
39
|
+
def register_lockfile(lockfile)
|
40
|
+
return if lockfile.nil? || lockfile_registered?(lockfile)
|
41
|
+
|
42
|
+
@loaded_lockfiles << File.expand_path(lockfile)
|
43
|
+
end
|
44
|
+
|
45
|
+
def register_jars(jars)
|
46
|
+
return if jars.nil?
|
47
|
+
|
48
|
+
jars_to_load = jars - @loaded_jars
|
49
|
+
|
50
|
+
@loaded_jars += jars_to_load
|
51
|
+
|
52
|
+
jars_to_load
|
53
|
+
end
|
54
|
+
|
55
|
+
def register_gem(spec)
|
56
|
+
@loaded_gems[spec.name] = spec
|
57
|
+
end
|
58
|
+
|
59
|
+
def gem_registered?(spec)
|
60
|
+
!@loaded_gems[spec.name].nil?
|
61
|
+
end
|
62
|
+
|
63
|
+
def load_gem(spec)
|
64
|
+
return if gem_registered?(spec)
|
65
|
+
|
66
|
+
register_gem(spec)
|
67
|
+
gem_dir = spec.gem_dir
|
68
|
+
|
69
|
+
lockfile = File.join(gem_dir, 'Jarfile.lock')
|
70
|
+
|
71
|
+
return unless File.exist?(lockfile)
|
72
|
+
|
73
|
+
puts "#{spec.name} has Jarfile.lock, loading jars"
|
74
|
+
LockJar.load(lockfile)
|
75
|
+
end
|
76
|
+
|
77
|
+
def load_jars_for_gems
|
78
|
+
specs = Gem.loaded_specs
|
79
|
+
return if specs.nil?
|
80
|
+
|
81
|
+
gems = specs.keys - @loaded_gems.keys
|
82
|
+
gems.each { |key| load_gem(specs[key]) }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,100 @@
|
|
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 'rubygems'
|
17
|
+
require 'naether'
|
18
|
+
require 'naether/bootstrap'
|
19
|
+
require 'fileutils'
|
20
|
+
|
21
|
+
module LockJar
|
22
|
+
#
|
23
|
+
class Resolver
|
24
|
+
attr_reader :config, :opts, :naether
|
25
|
+
|
26
|
+
def initialize(config, opts = {})
|
27
|
+
@config = config || LockJar::Config.new({})
|
28
|
+
@opts = opts
|
29
|
+
local_repo = opts[:local_repo] || Naether::Bootstrap.default_local_repo
|
30
|
+
|
31
|
+
# Bootstrap Naether
|
32
|
+
Naether::Bootstrap.bootstrap_local_repo(local_repo, opts)
|
33
|
+
|
34
|
+
# Bootstrapping naether will create an instance from downloaded jars.
|
35
|
+
@naether = Naether.create
|
36
|
+
@naether.local_repo_path = local_repo if local_repo
|
37
|
+
@naether.clear_remote_repositories if opts[:offline]
|
38
|
+
end
|
39
|
+
|
40
|
+
def remote_repositories
|
41
|
+
@naether.remote_repository_urls
|
42
|
+
end
|
43
|
+
|
44
|
+
def clear_remote_repositories
|
45
|
+
@naether.clear_remote_repositories
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_remote_repository(repo)
|
49
|
+
repo_config = config.repositories[repo] || {}
|
50
|
+
username = repo_config['username']
|
51
|
+
password = repo_config['password']
|
52
|
+
@naether.add_remote_repository(repo, username, password)
|
53
|
+
end
|
54
|
+
|
55
|
+
def resolve(dependencies, download_artifacts = true)
|
56
|
+
@naether.dependencies = dependencies
|
57
|
+
@naether.resolve_dependencies(download_artifacts)
|
58
|
+
@naether.dependencies_notation
|
59
|
+
end
|
60
|
+
|
61
|
+
def dependencies_graph
|
62
|
+
@naether.dependencies_graph
|
63
|
+
end
|
64
|
+
|
65
|
+
def download(dependencies)
|
66
|
+
@naether.download_artifacts(dependencies)
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_local_paths(notations)
|
70
|
+
paths = []
|
71
|
+
notations.each do |notation|
|
72
|
+
if File.exist?(notation)
|
73
|
+
paths << notation
|
74
|
+
else
|
75
|
+
paths += @naether.to_local_paths([notation])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
paths
|
80
|
+
end
|
81
|
+
|
82
|
+
def load_to_classpath(artifacts)
|
83
|
+
paths = []
|
84
|
+
notations = []
|
85
|
+
|
86
|
+
artifacts.each do |art|
|
87
|
+
if File.exist?(art)
|
88
|
+
paths << art
|
89
|
+
else
|
90
|
+
notations << art
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
paths += @naether.to_local_paths(notations)
|
95
|
+
Naether::Java.load_paths(paths)
|
96
|
+
|
97
|
+
paths
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module LockJar
|
2
|
+
#
|
3
|
+
class Runtime
|
4
|
+
#
|
5
|
+
module Install
|
6
|
+
def install(jarfile_lock, groups = ['default'], opts = {}, &blk)
|
7
|
+
deps = list(jarfile_lock, groups, { with_locals: false }.merge(opts), &blk)
|
8
|
+
|
9
|
+
lockfile = LockJar::Domain::Lockfile.read(jarfile_lock)
|
10
|
+
if opts[:local_repo].nil? && lockfile.local_repository
|
11
|
+
opts[:local_repo] = lockfile.local_repository
|
12
|
+
end
|
13
|
+
|
14
|
+
# Older Jarfile expected the defaul maven repo, but did not write
|
15
|
+
# it to the lockfile
|
16
|
+
resolver(opts).clear_remote_repositories if lockfile.version.to_f >= 0.11
|
17
|
+
|
18
|
+
lockfile.remote_repositories.each do |repo|
|
19
|
+
resolver(opts).add_remote_repository(repo)
|
20
|
+
end
|
21
|
+
|
22
|
+
files = resolver(opts).download(deps)
|
23
|
+
|
24
|
+
files
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module LockJar
|
2
|
+
#
|
3
|
+
class Runtime
|
4
|
+
#
|
5
|
+
module List
|
6
|
+
# rubocop:disable Metrics/PerceivedComplexity, MethodLength
|
7
|
+
def list(lockfile_or_path, groups = ['default'], opts = {}, &blk)
|
8
|
+
dependencies = []
|
9
|
+
maps = []
|
10
|
+
with_locals = { with_locals: true }.merge(opts).delete(:with_locals)
|
11
|
+
|
12
|
+
if lockfile_or_path
|
13
|
+
lockfile = build_lockfile(lockfile_or_path)
|
14
|
+
dependencies = dependencies_from_lockfile(lockfile, groups, with_locals, opts)
|
15
|
+
maps = lockfile.maps
|
16
|
+
end
|
17
|
+
|
18
|
+
# Support limited DSL from block
|
19
|
+
unless blk.nil?
|
20
|
+
dsl = LockJar::Domain::Dsl.create(&blk)
|
21
|
+
dependencies += dsl_dependencies(dsl, groups, with_locals).map(&:to_dep)
|
22
|
+
maps = dsl.maps
|
23
|
+
end
|
24
|
+
|
25
|
+
if maps && maps.size > 0
|
26
|
+
maps.each do |notation, replacements|
|
27
|
+
dependencies = dependencies.flat_map do |dep|
|
28
|
+
if dep =~ /#{notation}/
|
29
|
+
replacements
|
30
|
+
else
|
31
|
+
dep
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
dependencies = resolver(opts).resolve(dependencies) if opts[:resolve]
|
38
|
+
|
39
|
+
# local_paths and !resolve are mutualally exclusive
|
40
|
+
if opts[:local_paths] && opts[:resolve] != false
|
41
|
+
# remove local_paths opt so resolver is not reset
|
42
|
+
resolver(opts.reject { |k| k == :local_paths }).to_local_paths(dependencies)
|
43
|
+
|
44
|
+
else
|
45
|
+
dependencies
|
46
|
+
end
|
47
|
+
end
|
48
|
+
# rubocop:enable Metrics/PerceivedComplexity, MethodLength
|
49
|
+
|
50
|
+
def build_lockfile(lockfile_or_path)
|
51
|
+
if lockfile_or_path.is_a? LockJar::Domain::Lockfile
|
52
|
+
lockfile_or_path
|
53
|
+
elsif lockfile_or_path
|
54
|
+
LockJar::Domain::Lockfile.read(lockfile_or_path)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def dependencies_from_lockfile(lockfile, groups, with_locals, opts)
|
59
|
+
# Only list root dependencies
|
60
|
+
if opts[:resolve] == false
|
61
|
+
lockfile_dependencies(lockfile, groups, with_locals) do |group|
|
62
|
+
group['artifacts'].flat_map(&:keys).map do |notation|
|
63
|
+
# remove the prefix from artifacts, such as jar: or pom:
|
64
|
+
notation.gsub(/^.+?:/, '')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# List all dependencies
|
69
|
+
else
|
70
|
+
lockfile_dependencies(lockfile, groups, with_locals) do |group|
|
71
|
+
group['dependencies']
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module LockJar
|
2
|
+
#
|
3
|
+
class Runtime
|
4
|
+
#
|
5
|
+
module Load
|
6
|
+
# Load paths from a lockfile or block. Paths are loaded once per lockfile.
|
7
|
+
#
|
8
|
+
# @param [String] lockfile_path the lockfile
|
9
|
+
# @param [Array] groups to load into classpath
|
10
|
+
# @param [Hash] opts
|
11
|
+
# @param [Block] blk
|
12
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
13
|
+
def load(lockfile_or_path, groups = ['default'], opts = {}, &blk)
|
14
|
+
# lockfile is only loaded once
|
15
|
+
unless lockfile_or_path.nil?
|
16
|
+
# loaded a Lockfile instance
|
17
|
+
if lockfile_or_path.is_a? LockJar::Domain::Lockfile
|
18
|
+
lockfile = lockfile_or_path
|
19
|
+
|
20
|
+
else
|
21
|
+
# check if lockfile path is already loaded
|
22
|
+
return if LockJar::Registry.instance.lockfile_registered?(lockfile_or_path)
|
23
|
+
|
24
|
+
# convert lockfile path to a Lockfile instance
|
25
|
+
lockfile = LockJar::Domain::Lockfile.read(lockfile_or_path)
|
26
|
+
end
|
27
|
+
|
28
|
+
if opts[:local_repo].nil? && lockfile.local_repository
|
29
|
+
opts[:local_repo] = lockfile.local_repository
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# set local_repo if passed in the block
|
34
|
+
unless blk.nil?
|
35
|
+
dsl = LockJar::Domain::Dsl.create(&blk)
|
36
|
+
|
37
|
+
# set local_repo from block
|
38
|
+
opts[:local_repo] = dsl.local_repository if opts[:local_repo].nil? && dsl.local_repository
|
39
|
+
end
|
40
|
+
|
41
|
+
# registered merged lockfiles for lockfile
|
42
|
+
if lockfile && !lockfile.merged.empty?
|
43
|
+
lockfile.merged.each { |path| LockJar::Registry.instance.register_lockfile(path) }
|
44
|
+
end
|
45
|
+
|
46
|
+
dependencies = LockJar::Registry.instance.register_jars(list(lockfile, groups, opts, &blk))
|
47
|
+
|
48
|
+
resolver(opts).load_to_classpath(dependencies)
|
49
|
+
end
|
50
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|