lock_jar 0.15.1 → 0.15.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d0feaafb9dec0247045b0a9fc3f93d2f5c436f4
4
- data.tar.gz: 92bcdb938a888a3e1b257ea55f249fd42b45d701
3
+ metadata.gz: 4b41c3d8273b939aac806212cb513231814b9e8d
4
+ data.tar.gz: be972001b5e6b24e10e51d2118befbc683fe02ad
5
5
  SHA512:
6
- metadata.gz: 99432144f9aaf70cdc09f3022700fcb50462e38906fbca63a700662caf85578c11df5eff17e2bb67b6b17e679a42040d51f4470d2266ffe50e4fc13535afd676
7
- data.tar.gz: 8fb7bfbd937b66c069d90f58ae15508e49aca8f056fc45411ddae5afd92c96aa6cfc8d43fb945cd8b6c2d4158f03807b262ffcb48c33e1d38b4d57ed878dd797
6
+ metadata.gz: 4c0316ff7f5de2b1be1d3ad31a627d658e511f93092cb2b06cb0b7d9d388a18116417bdba1588d175589b0204ffc1c4d52bbfec6cf35768d3a6f6251885cb780
7
+ data.tar.gz: d84ba953c5da074528dc2bae16634715db45622a0e98d5f7470beeb4db8fbe3f996c8c7e0ef847b79769e13ce7b3e553ec6dcc426a99e2541d63d3da4cd5a50e
data/Gemfile CHANGED
@@ -11,5 +11,4 @@ end
11
11
  group :development do
12
12
  gem 'pry'
13
13
  gem 'yard'
14
- gem 'rubocop', '~> 0.36.0'
15
14
  end
data/README.md CHANGED
@@ -7,7 +7,7 @@ LockJar manages Java Jars for Ruby. Powered by [Naether](https://github.com/mguy
7
7
  create a frankenstein of Bundler and Maven. A Jarfile ([example](https://github.com/mguymon/lock_jar/blob/master/spec/support/Jarfile)) is used to generate a Jarfile.lock that contains all the resolved jar dependencies. The Jarfile.lock can be used to populate the classpath.
8
8
 
9
9
  LockJar can:
10
- * Be used directly in MRI 1.9.3, 2.0, 2.1 and JRuby 1.6, 1.7
10
+ * Be used directly in MRI 2.x and JRuby 1.7, 9.0
11
11
  * From the [command line](https://github.com/mguymon/lock_jar/blob/master/README.md#command-line)
12
12
  * [Triggered from a Gem install](https://github.com/mguymon/lock_jar/blob/master/README.md#gem-integration)
13
13
  * [Integrated into Buildr](https://github.com/mguymon/lock_jar/blob/master/README.md#buildr-integration)
@@ -271,6 +271,17 @@ As part of the load process for the Gem (an entry file that is required, etc) us
271
271
 
272
272
  See also [loading Jars into a custom ClassLoader](https://github.com/mguymon/lock_jar/wiki/ClassLoader).
273
273
 
274
+ ## Authentication
275
+
276
+ LockJar supports authentication to repository by passing in credentials from a `.lockjar` file. The YAML file contains a username and passwords per repository, for example:
277
+
278
+ repositories:
279
+ 'https://some.fancy.doman/maven':
280
+ username: 'user1'
281
+ password: 'the_pass'
282
+
283
+ The order of precedence for locating the `.lockjar` file is the `ENV['LOCKJAR_CONFIG']`, current working directory, and last the user's home directory.
284
+
274
285
  ## Buildr Integration
275
286
 
276
287
  LockJar integrates with [Buildr](http://buildr.apache.org/) using an [Addon](https://github.com/mguymon/lock_jar/blob/master/lib/lock_jar/buildr.rb). This allows the Jarfile to be defined directly into a _buildfile_. A global LockJar definition can be set and is inherited to all projects. Each project may have its own LockJar definition. A lock file is generated per project based on the project name.
@@ -14,6 +14,7 @@
14
14
  # the License.
15
15
 
16
16
  require 'yaml'
17
+ require 'lock_jar/config'
17
18
  require 'lock_jar/resolver'
18
19
  require 'lock_jar/runtime'
19
20
  require 'lock_jar/version'
@@ -0,0 +1,41 @@
1
+ require 'yaml'
2
+
3
+ module LockJar
4
+ # Global configuration for LockJar
5
+ class Config
6
+ CONFIG_ENV = 'LOCKJAR_CONFIG'.freeze
7
+ DEFAULT_FILENAME = '.lockjar'.freeze
8
+
9
+ attr_reader :repositories
10
+
11
+ class << self
12
+ # Load .lockjar YAML config file from ENV['LOCKJAR_CONFIG'], current_dir, or
13
+ # home dir.
14
+ def load_config_file
15
+ local_config_paths =
16
+ [Dir.pwd, Dir.home]
17
+ .map { |path| File.join(path, DEFAULT_FILENAME) }
18
+
19
+ config_path =
20
+ ([ENV[CONFIG_ENV]] + local_config_paths)
21
+ .compact
22
+ .find { |path| File.exist? path }
23
+
24
+ new(YAML.load_file(config_path)) if config_path
25
+ end
26
+ end
27
+
28
+ #
29
+ # {
30
+ # 'repositories' => {
31
+ # ':url' => {
32
+ # 'username' => ''
33
+ # 'password' => ''
34
+ # }
35
+ # }
36
+ # }
37
+ def initialize(config)
38
+ @repositories = config['repositories'] || {}
39
+ end
40
+ end
41
+ end
@@ -21,9 +21,10 @@ require 'fileutils'
21
21
  module LockJar
22
22
  #
23
23
  class Resolver
24
- attr_reader :opts, :naether
24
+ attr_reader :config, :opts, :naether
25
25
 
26
- def initialize(opts = {})
26
+ def initialize(config, opts = {})
27
+ @config = config || LockJar::Config.new({})
27
28
  @opts = opts
28
29
  local_repo = opts[:local_repo] || Naether::Bootstrap.default_local_repo
29
30
 
@@ -31,7 +32,6 @@ module LockJar
31
32
  Naether::Bootstrap.bootstrap_local_repo(local_repo, opts)
32
33
 
33
34
  # Bootstrapping naether will create an instance from downloaded jars.
34
- # If jars exist locally already, create manually
35
35
  @naether = Naether.create
36
36
  @naether.local_repo_path = local_repo if local_repo
37
37
  @naether.clear_remote_repositories if opts[:offline]
@@ -46,7 +46,10 @@ module LockJar
46
46
  end
47
47
 
48
48
  def add_remote_repository(repo)
49
- @naether.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)
50
53
  end
51
54
 
52
55
  def resolve(dependencies, download_artifacts = true)
@@ -15,6 +15,7 @@
15
15
 
16
16
  require 'yaml'
17
17
  require 'singleton'
18
+ require 'lock_jar/config'
18
19
  require 'lock_jar/resolver'
19
20
  require 'lock_jar/registry'
20
21
  require 'lock_jar/domain/dsl'
@@ -33,9 +34,10 @@ module LockJar
33
34
  include List
34
35
  include Install
35
36
 
36
- attr_reader :current_resolver
37
+ attr_reader :current_resolver, :config
37
38
 
38
39
  def initialize
40
+ @config = Config.load_config_file
39
41
  @current_resolver = nil
40
42
  end
41
43
 
@@ -59,7 +61,7 @@ module LockJar
59
61
  end
60
62
 
61
63
  if @current_resolver.nil? || opts != @current_resolver.opts
62
- @current_resolver = LockJar::Resolver.new(opts)
64
+ @current_resolver = LockJar::Resolver.new(config, opts)
63
65
  end
64
66
 
65
67
  @current_resolver
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module LockJar
3
3
  # still the version
4
- VERSION = '0.15.1'.freeze
4
+ VERSION = '0.15.2'.freeze
5
5
  end
@@ -26,5 +26,6 @@ classpath'
26
26
  s.add_dependency('naether', ['~> 0.15.0'])
27
27
  s.add_dependency('thor', ['>= 0.18.1'])
28
28
  s.add_development_dependency('rspec', '~> 2.14.1')
29
+ s.add_development_dependency('rubocop', '~> 0.35.0')
29
30
  s.add_development_dependency('rake')
30
31
  end
@@ -0,0 +1,4 @@
1
+ repositories:
2
+ 'https://some.fancy.doman/maven':
3
+ username: 'user1'
4
+ password: 'the_pass'
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe LockJar::Config do
4
+ describe '.load_config_file' do
5
+ let(:test_config_file) { File.join('spec', 'fixtures', 'lock_jar_config.yml') }
6
+ let(:temp_config_file) { File.join(TEMP_DIR, described_class::DEFAULT_FILENAME) }
7
+ let(:config) { described_class.load_config_file }
8
+ let(:expected_repo_config) do
9
+ {
10
+ 'https://some.fancy.doman/maven' => {
11
+ 'username' => 'user1',
12
+ 'password' => 'the_pass'
13
+ }
14
+ }
15
+ end
16
+
17
+ before do
18
+ FileUtils.cp(test_config_file, temp_config_file)
19
+ end
20
+
21
+ context 'using current dir config' do
22
+ before do
23
+ allow(Dir).to receive(:pwd).and_return(TEMP_DIR)
24
+ end
25
+
26
+ it 'should have a repository config' do
27
+ expect(config.repositories).to eq(expected_repo_config)
28
+ end
29
+ end
30
+
31
+ context 'using home dir config' do
32
+ before do
33
+ allow(Dir).to receive(:home).and_return(TEMP_DIR)
34
+ end
35
+
36
+ it 'should have a repository config' do
37
+ expect(config.repositories).to eq(expected_repo_config)
38
+ end
39
+ end
40
+
41
+ context 'using ENV path to config' do
42
+ before do
43
+ ENV[described_class::CONFIG_ENV] = temp_config_file
44
+ end
45
+
46
+ it 'should have a repository config' do
47
+ expect(config.repositories).to eq(expected_repo_config)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -4,12 +4,26 @@ require 'fileutils'
4
4
  require 'naether'
5
5
 
6
6
  describe LockJar::Resolver do
7
- before(:each) do
7
+ subject { described_class.new(config, local_repo: "#{TEMP_DIR}/test-repo") }
8
+
9
+ before do
8
10
  FileUtils.mkdir_p("#{TEMP_DIR}/test-repo")
9
- @resolver = LockJar::Resolver.new(local_repo: "#{TEMP_DIR}/test-repo")
11
+ end
12
+
13
+ let(:config) do
14
+ LockJar::Config.new(
15
+ 'repositories' => {
16
+ 'https://test/repo' => {
17
+ 'username' => 'user1',
18
+ 'password' => 'pass1'
19
+ }
20
+ }
21
+ )
10
22
  end
11
23
 
12
24
  it 'should bootstrap naether' do
25
+ subject
26
+
13
27
  deps = Naether::Bootstrap.check_local_repo_for_deps("#{TEMP_DIR}/test-repo")
14
28
  deps[:missing].should eql([])
15
29
  deps[:exists].each do |dep|
@@ -17,9 +31,39 @@ describe LockJar::Resolver do
17
31
  end
18
32
  end
19
33
 
20
- it 'should return local paths for notations' do
21
- expect(@resolver.to_local_paths(['org.testng:testng:jar:6.9.10'])).to(
22
- eql([File.expand_path("#{TEMP_DIR}/test-repo/org/testng/testng/6.9.10/testng-6.9.10.jar")])
23
- )
34
+ describe '#to_local_paths' do
35
+ it 'should return local paths for notations' do
36
+ expect(subject.to_local_paths(['org.testng:testng:jar:6.9.10'])).to(
37
+ eql([File.expand_path("#{TEMP_DIR}/test-repo/org/testng/testng/6.9.10/testng-6.9.10.jar")])
38
+ )
39
+ end
40
+ end
41
+
42
+ describe '#add_remote_repository' do
43
+ let(:remote_repos) do
44
+ subject.naether.remote_repositories.map do |repo|
45
+ {
46
+ url: repo.url
47
+ }.tap do |hash|
48
+ if repo.authentication
49
+ hash[:username] = repo.authentication.username
50
+ hash[:password] = repo.authentication.password
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ let(:expected_remote_repos) do
57
+ [
58
+ { url: 'http://repo1.maven.org/maven2/' },
59
+ { url: 'https://test/repo', username: 'user1', password: 'pass1' }
60
+ ]
61
+ end
62
+
63
+ it 'should use repo config for auth' do
64
+ subject.add_remote_repository('https://test/repo')
65
+
66
+ expect(remote_repos).to eq(expected_remote_repos)
67
+ end
24
68
  end
25
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lock_jar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.15.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Guymon
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.14.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.35.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.35.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -95,6 +109,7 @@ files:
95
109
  - lib/lock_jar/bundler.rb
96
110
  - lib/lock_jar/class_loader.rb
97
111
  - lib/lock_jar/cli.rb
112
+ - lib/lock_jar/config.rb
98
113
  - lib/lock_jar/domain/artifact.rb
99
114
  - lib/lock_jar/domain/dsl.rb
100
115
  - lib/lock_jar/domain/dsl_merger.rb
@@ -119,10 +134,12 @@ files:
119
134
  - spec/fixtures/jarfile_gem/jarfile_gem.gemspec
120
135
  - spec/fixtures/jarfile_gem/lib/jarfile_gem.rb
121
136
  - spec/fixtures/jarfile_gem/lib/jarfile_gem/version.rb
137
+ - spec/fixtures/lock_jar_config.yml
122
138
  - spec/fixtures/naether-0.13.0.jar
123
139
  - spec/lock_jar/bundler_spec.rb
124
140
  - spec/lock_jar/class_loader_spec.rb
125
141
  - spec/lock_jar/cli_spec.rb
142
+ - spec/lock_jar/config_spec.rb
126
143
  - spec/lock_jar/domain/dsl_merger_spec.rb
127
144
  - spec/lock_jar/domain/dsl_spec.rb
128
145
  - spec/lock_jar/domain/gem_dsl_spec.rb
@@ -167,10 +184,12 @@ test_files:
167
184
  - spec/fixtures/jarfile_gem/jarfile_gem.gemspec
168
185
  - spec/fixtures/jarfile_gem/lib/jarfile_gem.rb
169
186
  - spec/fixtures/jarfile_gem/lib/jarfile_gem/version.rb
187
+ - spec/fixtures/lock_jar_config.yml
170
188
  - spec/fixtures/naether-0.13.0.jar
171
189
  - spec/lock_jar/bundler_spec.rb
172
190
  - spec/lock_jar/class_loader_spec.rb
173
191
  - spec/lock_jar/cli_spec.rb
192
+ - spec/lock_jar/config_spec.rb
174
193
  - spec/lock_jar/domain/dsl_merger_spec.rb
175
194
  - spec/lock_jar/domain/dsl_spec.rb
176
195
  - spec/lock_jar/domain/gem_dsl_spec.rb