lock_jar 0.10.0 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +59 -59
  3. data/.travis.yml +8 -8
  4. data/CHANGELOG.md +30 -21
  5. data/Gemfile +13 -13
  6. data/Guardfile +9 -9
  7. data/README.md +375 -375
  8. data/Rakefile +24 -24
  9. data/bundler/Gemfile +21 -21
  10. data/bundler/LICENSE.txt +22 -22
  11. data/bundler/README.md +29 -29
  12. data/bundler/Rakefile +2 -2
  13. data/bundler/lib/lock_jar_bundler/bundler.rb +35 -35
  14. data/bundler/lib/lock_jar_bundler/piggy_back.rb +97 -97
  15. data/bundler/lib/lock_jar_bundler/version.rb +5 -5
  16. data/bundler/lib/lock_jar_bundler.rb +4 -4
  17. data/bundler/lock_jar_bundler.gemspec +24 -24
  18. data/bundler/spec/Jarfile +2 -2
  19. data/bundler/spec/dummy_gem/dummy_gem.gemspec +19 -19
  20. data/bundler/spec/lock_jar_bundler_spec.rb +48 -48
  21. data/bundler/spec/spec_helper.rb +88 -88
  22. data/lib/lock_jar/buildr.rb +144 -144
  23. data/lib/lock_jar/bundler.rb +154 -154
  24. data/lib/lock_jar/cli.rb +64 -64
  25. data/lib/lock_jar/domain/artifact.rb +123 -123
  26. data/lib/lock_jar/domain/dsl.rb +187 -187
  27. data/lib/lock_jar/domain/dsl_helper.rb +83 -83
  28. data/lib/lock_jar/domain/gem_dsl.rb +44 -44
  29. data/lib/lock_jar/domain/jarfile_dsl.rb +46 -46
  30. data/lib/lock_jar/domain/lockfile.rb +113 -113
  31. data/lib/lock_jar/maven.rb +111 -111
  32. data/lib/lock_jar/registry.rb +92 -92
  33. data/lib/lock_jar/resolver.rb +95 -95
  34. data/lib/lock_jar/runtime.rb +359 -355
  35. data/lib/lock_jar/version.rb +3 -3
  36. data/lib/lock_jar.rb +172 -177
  37. data/lock_jar.gemspec +27 -27
  38. data/spec/fixtures/Jarfile +13 -13
  39. data/spec/fixtures/Jarfile2 +1 -0
  40. data/spec/lock_jar/class_loader_spec.rb +57 -57
  41. data/spec/lock_jar/cli_spec.rb +100 -100
  42. data/spec/lock_jar/domain/dsl_helper_spec.rb +52 -52
  43. data/spec/lock_jar/domain/dsl_spec.rb +57 -57
  44. data/spec/lock_jar/maven_spec.rb +23 -23
  45. data/spec/lock_jar/resolver_spec.rb +26 -26
  46. data/spec/lock_jar/runtime_spec.rb +26 -26
  47. data/spec/lock_jar_spec.rb +372 -295
  48. data/spec/pom.xml +34 -34
  49. data/spec/spec_helper.rb +38 -38
  50. data/spec/support/helper.rb +44 -44
  51. metadata +3 -1
@@ -1,155 +1,155 @@
1
- require 'lock_jar'
2
- require 'lock_jar/registry'
3
- require 'lock_jar/domain/lockfile'
4
- require 'lock_jar/domain/dsl'
5
- require 'lock_jar/domain/gem_dsl'
6
- require 'lock_jar/domain/jarfile_dsl'
7
- require 'lock_jar/domain/dsl_helper'
8
-
9
- module LockJar
10
-
11
- class Bundler
12
-
13
- class << self
14
-
15
- attr_accessor :skip_lock
16
-
17
- def load(*groups)
18
- if groups && !groups.empty? && File.exists?( 'Jarfile.lock')
19
-
20
- lockfile = LockJar::Domain::Lockfile.read( 'Jarfile.lock' )
21
-
22
- # expand merged paths to include gem base path
23
- unless lockfile.merged.empty?
24
- lockfile.merged = LockJar::Bundler.expand_gem_paths( lockfile.merged )
25
- end
26
-
27
- LockJar.load( lockfile, groups )
28
-
29
- if ENV["DEBUG"]
30
- puts "[LockJar] Loaded Jars for #{groups.inspect}: #{LockJar::Registry.instance.loaded_jars.inspect}"
31
- end
32
- end
33
- end
34
-
35
- def expand_gem_paths(merged)
36
-
37
- merged_gem_paths = []
38
- Gem.path.each do |gem_root|
39
- merged.each do |merge|
40
- # merged gems follow the notation: gem:gemname:path
41
- if merge.start_with? 'gem:'
42
- gem_path = merge.gsub(/^gem:.+:/, '')
43
- gem_path = File.join( gem_root, gem_path )
44
- if File.exists? gem_path
45
- merged_gem_paths << gem_path
46
- end
47
- end
48
- end
49
- end
50
-
51
- merged_gem_paths
52
- end
53
- end
54
- end
55
-
56
- end
57
-
58
- module Bundler
59
- class << self
60
- alias :_lockjar_extended_require :require
61
- def require(*groups)
62
- LockJar::Bundler.load(*groups)
63
-
64
- LockJar::Bundler.skip_lock = true
65
-
66
- _lockjar_extended_require
67
- end
68
-
69
- alias :_lockjar_extended_setup :setup
70
- def setup(*groups)
71
- LockJar::Bundler.load(*groups)
72
-
73
- LockJar::Bundler.skip_lock = true
74
-
75
- _lockjar_extended_setup
76
- end
77
- end
78
-
79
- class Runtime
80
-
81
- alias :_lockjar_extended_require :require
82
- def require(*groups)
83
- LockJar::Bundler.load(*groups)
84
-
85
- LockJar::Bundler.skip_lock = true
86
-
87
- _lockjar_extended_require
88
- end
89
-
90
- alias :_lockjar_extended_setup :setup
91
- def setup(*groups)
92
- LockJar::Bundler.load(*groups)
93
-
94
- LockJar::Bundler.skip_lock = true
95
-
96
- _lockjar_extended_setup
97
- end
98
- end
99
-
100
- class Definition
101
- alias :_lockjar_extended_to_lock :to_lock
102
- def to_lock
103
- to_lock = _lockjar_extended_to_lock
104
-
105
- if LockJar::Bundler.skip_lock != true
106
- definition = Bundler.definition
107
- #if !definition.send( :nothing_changed? )
108
- gems_with_jars = []
109
-
110
- # load local Jarfile
111
- if File.exists?( 'Jarfile' )
112
- dsl = LockJar::Domain::JarfileDsl.create( File.expand_path( 'Jarfile' ) )
113
- gems_with_jars << 'jarfile:Jarfile'
114
- # Create new Dsl
115
- else
116
- dsl = LockJar::Domain::Dsl.new
117
- end
118
-
119
- definition.groups.each do |group|
120
- if ENV["DEBUG"]
121
- puts "[LockJar] Group #{group}:"
122
- end
123
-
124
- definition.specs_for( [group] ).each do |spec|
125
- gem_dir = spec.gem_dir
126
-
127
- jarfile = File.join( gem_dir, "Jarfile" )
128
-
129
- if File.exists?( jarfile )
130
- gems_with_jars << "gem:#{spec.name}"
131
-
132
- if ENV["DEBUG"]
133
- puts "[LockJar] #{spec.name} has Jarfile"
134
- end
135
-
136
- spec_dsl = LockJar::Domain::GemDsl.create( spec, "Jarfile" )
137
-
138
- dsl = LockJar::Domain::DslHelper.merge( dsl, spec_dsl, group.to_s )
139
- end
140
- end
141
-
142
- end
143
-
144
- puts "[LockJar] Locking Jars for: #{gems_with_jars.inspect}"
145
- LockJar.lock( dsl )
146
- #elsif ENV["DEBUG"]
147
- # puts "[LockJar] Locking skiped, Gemfile has not changed"
148
- #end
149
- end
150
-
151
- to_lock
152
- end
153
-
154
- end
1
+ require 'lock_jar'
2
+ require 'lock_jar/registry'
3
+ require 'lock_jar/domain/lockfile'
4
+ require 'lock_jar/domain/dsl'
5
+ require 'lock_jar/domain/gem_dsl'
6
+ require 'lock_jar/domain/jarfile_dsl'
7
+ require 'lock_jar/domain/dsl_helper'
8
+
9
+ module LockJar
10
+
11
+ class Bundler
12
+
13
+ class << self
14
+
15
+ attr_accessor :skip_lock
16
+
17
+ def load(*groups)
18
+ if groups && !groups.empty? && File.exists?( 'Jarfile.lock')
19
+
20
+ lockfile = LockJar::Domain::Lockfile.read( 'Jarfile.lock' )
21
+
22
+ # expand merged paths to include gem base path
23
+ unless lockfile.merged.empty?
24
+ lockfile.merged = LockJar::Bundler.expand_gem_paths( lockfile.merged )
25
+ end
26
+
27
+ LockJar.load( lockfile, groups )
28
+
29
+ if ENV["DEBUG"]
30
+ puts "[LockJar] Loaded Jars for #{groups.inspect}: #{LockJar::Registry.instance.loaded_jars.inspect}"
31
+ end
32
+ end
33
+ end
34
+
35
+ def expand_gem_paths(merged)
36
+
37
+ merged_gem_paths = []
38
+ Gem.path.each do |gem_root|
39
+ merged.each do |merge|
40
+ # merged gems follow the notation: gem:gemname:path
41
+ if merge.start_with? 'gem:'
42
+ gem_path = merge.gsub(/^gem:.+:/, '')
43
+ gem_path = File.join( gem_root, gem_path )
44
+ if File.exists? gem_path
45
+ merged_gem_paths << gem_path
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ merged_gem_paths
52
+ end
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+ module Bundler
59
+ class << self
60
+ alias :_lockjar_extended_require :require
61
+ def require(*groups)
62
+ LockJar::Bundler.load(*groups)
63
+
64
+ LockJar::Bundler.skip_lock = true
65
+
66
+ _lockjar_extended_require
67
+ end
68
+
69
+ alias :_lockjar_extended_setup :setup
70
+ def setup(*groups)
71
+ LockJar::Bundler.load(*groups)
72
+
73
+ LockJar::Bundler.skip_lock = true
74
+
75
+ _lockjar_extended_setup
76
+ end
77
+ end
78
+
79
+ class Runtime
80
+
81
+ alias :_lockjar_extended_require :require
82
+ def require(*groups)
83
+ LockJar::Bundler.load(*groups)
84
+
85
+ LockJar::Bundler.skip_lock = true
86
+
87
+ _lockjar_extended_require
88
+ end
89
+
90
+ alias :_lockjar_extended_setup :setup
91
+ def setup(*groups)
92
+ LockJar::Bundler.load(*groups)
93
+
94
+ LockJar::Bundler.skip_lock = true
95
+
96
+ _lockjar_extended_setup
97
+ end
98
+ end
99
+
100
+ class Definition
101
+ alias :_lockjar_extended_to_lock :to_lock
102
+ def to_lock
103
+ to_lock = _lockjar_extended_to_lock
104
+
105
+ if LockJar::Bundler.skip_lock != true
106
+ definition = Bundler.definition
107
+ #if !definition.send( :nothing_changed? )
108
+ gems_with_jars = []
109
+
110
+ # load local Jarfile
111
+ if File.exists?( 'Jarfile' )
112
+ dsl = LockJar::Domain::JarfileDsl.create( File.expand_path( 'Jarfile' ) )
113
+ gems_with_jars << 'jarfile:Jarfile'
114
+ # Create new Dsl
115
+ else
116
+ dsl = LockJar::Domain::Dsl.new
117
+ end
118
+
119
+ definition.groups.each do |group|
120
+ if ENV["DEBUG"]
121
+ puts "[LockJar] Group #{group}:"
122
+ end
123
+
124
+ definition.specs_for( [group] ).each do |spec|
125
+ gem_dir = spec.gem_dir
126
+
127
+ jarfile = File.join( gem_dir, "Jarfile" )
128
+
129
+ if File.exists?( jarfile )
130
+ gems_with_jars << "gem:#{spec.name}"
131
+
132
+ if ENV["DEBUG"]
133
+ puts "[LockJar] #{spec.name} has Jarfile"
134
+ end
135
+
136
+ spec_dsl = LockJar::Domain::GemDsl.create( spec, "Jarfile" )
137
+
138
+ dsl = LockJar::Domain::DslHelper.merge( dsl, spec_dsl, group.to_s )
139
+ end
140
+ end
141
+
142
+ end
143
+
144
+ puts "[LockJar] Locking Jars for: #{gems_with_jars.inspect}"
145
+ LockJar.lock( dsl )
146
+ #elsif ENV["DEBUG"]
147
+ # puts "[LockJar] Locking skiped, Gemfile has not changed"
148
+ #end
149
+ end
150
+
151
+ to_lock
152
+ end
153
+
154
+ end
155
155
  end
data/lib/lock_jar/cli.rb CHANGED
@@ -1,64 +1,64 @@
1
- require 'rubygems'
2
- require 'thor'
3
- require 'lock_jar'
4
-
5
- module LockJar
6
-
7
- class CLI < Thor
8
-
9
- module ClassMethods
10
- def generate_lockfile_option
11
- method_option :lockfile,
12
- :aliases => "-l",
13
- :default => 'Jarfile.lock',
14
- :desc => "Path to Jarfile.lock"
15
- end
16
-
17
- def generate_scopes_option
18
- method_option :scopes,
19
- :aliases => "-s",
20
- :default => ['default'],
21
- :desc => "Scopes to install from Jarfile.lock",
22
- :type => :array
23
- end
24
-
25
- def generate_jarfile_option
26
- method_option :jarfile,
27
- :aliases => "-j",
28
- :default => 'Jarfile',
29
- :desc => "Path to Jarfile"
30
- end
31
- end
32
- extend(ClassMethods)
33
-
34
- desc "version", "LockJar version"
35
- def version
36
- puts LockJar::VERSION
37
- end
38
-
39
- desc "install", "Install Jars from a Jarfile.lock"
40
- generate_lockfile_option
41
- generate_scopes_option
42
- def install
43
- puts "Installing Jars from #{options[:lockfile]} for #{options[:scopes].inspect}"
44
- LockJar.install( options[:lockfile], options[:scopes] )
45
- end
46
-
47
- desc "list", "List Jars from a Jarfile.lock"
48
- generate_lockfile_option
49
- generate_scopes_option
50
- def list
51
- puts "Listing Jars from #{options[:lockfile]} for #{options[:scopes].inspect}"
52
- puts LockJar.list( options[:lockfile], options[:scopes] ).inspect
53
- end
54
-
55
- desc 'lock', 'Lock Jars in a Jarfile.lock'
56
- generate_jarfile_option
57
- generate_lockfile_option
58
- def lock
59
- puts "Locking #{options[:jarfile]} to #{options[:lockfile]}"
60
- LockJar.lock( options[:jarfile], { :lockfile => options[:lockfile] } )
61
- end
62
-
63
- end
64
- end
1
+ require 'rubygems'
2
+ require 'thor'
3
+ require 'lock_jar'
4
+
5
+ module LockJar
6
+
7
+ class CLI < Thor
8
+
9
+ module ClassMethods
10
+ def generate_lockfile_option
11
+ method_option :lockfile,
12
+ :aliases => "-l",
13
+ :default => 'Jarfile.lock',
14
+ :desc => "Path to Jarfile.lock"
15
+ end
16
+
17
+ def generate_scopes_option
18
+ method_option :scopes,
19
+ :aliases => "-s",
20
+ :default => ['default'],
21
+ :desc => "Scopes to install from Jarfile.lock",
22
+ :type => :array
23
+ end
24
+
25
+ def generate_jarfile_option
26
+ method_option :jarfile,
27
+ :aliases => "-j",
28
+ :default => 'Jarfile',
29
+ :desc => "Path to Jarfile"
30
+ end
31
+ end
32
+ extend(ClassMethods)
33
+
34
+ desc "version", "LockJar version"
35
+ def version
36
+ puts LockJar::VERSION
37
+ end
38
+
39
+ desc "install", "Install Jars from a Jarfile.lock"
40
+ generate_lockfile_option
41
+ generate_scopes_option
42
+ def install
43
+ puts "Installing Jars from #{options[:lockfile]} for #{options[:scopes].inspect}"
44
+ LockJar.install( options[:lockfile], options[:scopes] )
45
+ end
46
+
47
+ desc "list", "List Jars from a Jarfile.lock"
48
+ generate_lockfile_option
49
+ generate_scopes_option
50
+ def list
51
+ puts "Listing Jars from #{options[:lockfile]} for #{options[:scopes].inspect}"
52
+ puts LockJar.list( options[:lockfile], options[:scopes] ).inspect
53
+ end
54
+
55
+ desc 'lock', 'Lock Jars in a Jarfile.lock'
56
+ generate_jarfile_option
57
+ generate_lockfile_option
58
+ def lock
59
+ puts "Locking #{options[:jarfile]} to #{options[:lockfile]}"
60
+ LockJar.lock( options[:jarfile], { :lockfile => options[:lockfile] } )
61
+ end
62
+
63
+ end
64
+ end
@@ -1,124 +1,124 @@
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 'set'
17
- require 'lock_jar/maven'
18
- require 'naether/notation'
19
-
20
- module LockJar
21
- module Domain
22
-
23
-
24
- class Artifact
25
- include Comparable
26
- attr_reader :type
27
-
28
- def <=>(another_artifact)
29
- if another_artifact.is_a? Artifact
30
- to_urn <=> another_artifact.to_urn
31
- else
32
- to_urn <=> another_artifact.to_s
33
- end
34
- end
35
-
36
- def resolvable?
37
- true
38
- end
39
- end
40
-
41
- class Jar < Artifact
42
- attr_reader :notation
43
-
44
- def initialize( notation )
45
- @type = 'jar'
46
- @notation = Naether::Notation.new( notation ).to_notation
47
- end
48
-
49
- def to_urn
50
- "jar:#{notation}"
51
- end
52
-
53
- def to_dep
54
- notation
55
- end
56
- end
57
-
58
- class Local < Artifact
59
- attr_reader :path
60
- def initialize( path )
61
- @type = 'local'
62
- @path = path
63
- end
64
-
65
- def to_urn
66
- "local:#{path}"
67
- end
68
-
69
- def to_dep
70
- path
71
- end
72
-
73
- def resolvable?
74
- false
75
- end
76
- end
77
-
78
- class Pom < Artifact
79
- attr_reader :path, :scopes
80
-
81
- def initialize( _path, _scopes = ['compile','runtime'] )
82
- @type = 'pom'
83
- @path = _path
84
- @scopes = _scopes
85
- end
86
-
87
- def to_urn
88
- "pom:#{path}"
89
- end
90
-
91
- def to_dep
92
- { path => scopes }
93
- end
94
-
95
- def notations
96
- LockJar::Maven.dependencies( path, scopes )
97
- end
98
-
99
- def ==(another_artifact)
100
- self.<=>(another_artifact) == 0
101
- end
102
-
103
- def <=>(another_artifact)
104
- if another_artifact.is_a? Pom
105
- if to_urn == another_artifact.to_urn
106
- return 0 if Set.new(scopes) == Set.new(another_artifact.scopes)
107
-
108
- # XXX: this is not a reliable way to compare.
109
- if scopes.size > another_artifact.scopes.size
110
- return 1
111
- else
112
- return -1
113
- end
114
- else
115
- to_urn <=> another_artifact.to_urn
116
- end
117
- else
118
- super
119
- end
120
- end
121
- end
122
-
123
- end
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 'set'
17
+ require 'lock_jar/maven'
18
+ require 'naether/notation'
19
+
20
+ module LockJar
21
+ module Domain
22
+
23
+
24
+ class Artifact
25
+ include Comparable
26
+ attr_reader :type
27
+
28
+ def <=>(another_artifact)
29
+ if another_artifact.is_a? Artifact
30
+ to_urn <=> another_artifact.to_urn
31
+ else
32
+ to_urn <=> another_artifact.to_s
33
+ end
34
+ end
35
+
36
+ def resolvable?
37
+ true
38
+ end
39
+ end
40
+
41
+ class Jar < Artifact
42
+ attr_reader :notation
43
+
44
+ def initialize( notation )
45
+ @type = 'jar'
46
+ @notation = Naether::Notation.new( notation ).to_notation
47
+ end
48
+
49
+ def to_urn
50
+ "jar:#{notation}"
51
+ end
52
+
53
+ def to_dep
54
+ notation
55
+ end
56
+ end
57
+
58
+ class Local < Artifact
59
+ attr_reader :path
60
+ def initialize( path )
61
+ @type = 'local'
62
+ @path = path
63
+ end
64
+
65
+ def to_urn
66
+ "local:#{path}"
67
+ end
68
+
69
+ def to_dep
70
+ path
71
+ end
72
+
73
+ def resolvable?
74
+ false
75
+ end
76
+ end
77
+
78
+ class Pom < Artifact
79
+ attr_reader :path, :scopes
80
+
81
+ def initialize( _path, _scopes = ['compile','runtime'] )
82
+ @type = 'pom'
83
+ @path = _path
84
+ @scopes = _scopes
85
+ end
86
+
87
+ def to_urn
88
+ "pom:#{path}"
89
+ end
90
+
91
+ def to_dep
92
+ { path => scopes }
93
+ end
94
+
95
+ def notations
96
+ LockJar::Maven.dependencies( path, scopes )
97
+ end
98
+
99
+ def ==(another_artifact)
100
+ self.<=>(another_artifact) == 0
101
+ end
102
+
103
+ def <=>(another_artifact)
104
+ if another_artifact.is_a? Pom
105
+ if to_urn == another_artifact.to_urn
106
+ return 0 if Set.new(scopes) == Set.new(another_artifact.scopes)
107
+
108
+ # XXX: this is not a reliable way to compare.
109
+ if scopes.size > another_artifact.scopes.size
110
+ return 1
111
+ else
112
+ return -1
113
+ end
114
+ else
115
+ to_urn <=> another_artifact.to_urn
116
+ end
117
+ else
118
+ super
119
+ end
120
+ end
121
+ end
122
+
123
+ end
124
124
  end