lock_jar 0.6.2 → 0.7.0
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.
- data/Gemfile +4 -2
- data/README.md +101 -54
- data/VERSION +1 -1
- data/lib/lock_jar/buildr.rb +8 -8
- data/lib/lock_jar/bundler.rb +155 -0
- data/lib/lock_jar/domain/artifact.rb +117 -0
- data/lib/lock_jar/domain/dsl.rb +177 -0
- data/lib/lock_jar/domain/dsl_helper.rb +66 -0
- data/lib/lock_jar/domain/gem_dsl.rb +45 -0
- data/lib/lock_jar/domain/jarfile_dsl.rb +37 -0
- data/lib/lock_jar/domain/lockfile.rb +114 -0
- data/lib/lock_jar/maven.rb +13 -1
- data/lib/lock_jar/registry.rb +46 -5
- data/lib/lock_jar/resolver.rb +5 -1
- data/lib/lock_jar/runtime.rb +230 -165
- data/lib/lock_jar.rb +22 -19
- data/lock_jar.gemspec +17 -12
- data/spec/Jarfile +3 -3
- data/spec/lock_jar/class_loader_spec.rb +47 -43
- data/spec/lock_jar/domain/dsl_helper_spec.rb +52 -0
- data/spec/lock_jar/domain/dsl_spec.rb +54 -0
- data/spec/lock_jar_spec.rb +155 -81
- metadata +15 -10
- data/lib/lock_jar/dsl.rb +0 -184
- data/lib/lock_jar/rubygems.rb +0 -21
- data/spec/lock_jar/dsl_spec.rb +0 -84
- data/spec/lock_jar/rubygems_spec.rb +0 -43
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
#require 'lib/lock_jar/bundler'
|
2
|
+
|
1
3
|
source "http://rubygems.org"
|
2
4
|
|
3
|
-
gem "naether", "~> 0.
|
5
|
+
gem "naether", "~> 0.10.0"
|
4
6
|
gem "thor", "~> 0.14.6"
|
5
7
|
|
6
8
|
# Add dependencies to develop your gem here.
|
@@ -9,6 +11,6 @@ group :development do
|
|
9
11
|
gem "rspec", "~> 2.9.0"
|
10
12
|
gem "jeweler", "~> 1.8.4"
|
11
13
|
gem "yard", "~> 0.8.0"
|
12
|
-
gem 'solr_sail', '~>0.0
|
14
|
+
gem 'solr_sail', '~>0.1.0', :platforms => :jruby
|
13
15
|
gem 'jruby-openssl', :platforms => :jruby
|
14
16
|
end
|
data/README.md
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
# LockJar
|
2
2
|
|
3
|
-
LockJar manages Java Jars for Ruby. Powered by [Naether](https://github.com/mguymon/naether) to
|
3
|
+
LockJar manages Java Jars for Ruby. Powered by [Naether](https://github.com/mguymon/naether) to
|
4
|
+
create a frankenstein of Bundler and Maven. A Jarfile ([example](https://github.com/mguymon/lock_jar/blob/master/spec/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.
|
4
5
|
|
5
|
-
LockJar can
|
6
|
+
LockJar can:
|
7
|
+
* Be Use directly in MRI 1.8.7, 1.9.3, and JRuby 1.6.7, 1.6.8
|
8
|
+
* From the [command line](https://github.com/mguymon/lock_jar/blob/master/README.md#command-line)
|
9
|
+
* [Triggered from a Gem install](https://github.com/mguymon/lock_jar/blob/master/README.md#gem-integration)
|
10
|
+
* [Integrated into Buildr](https://github.com/mguymon/lock_jar/blob/master/README.md#buildr-integration)
|
11
|
+
* Experimental [tntegration with Bundler](https://github.com/mguymon/lock_jar/blob/master/README.md#bundler-integration)
|
6
12
|
|
7
13
|
https://github.com/mguymon/lock_jar
|
8
14
|
|
@@ -14,31 +20,33 @@ https://github.com/mguymon/lock_jar
|
|
14
20
|
|
15
21
|
## Ruby Usage
|
16
22
|
|
23
|
+
JRuby is natively supported. Ruby 1.8.7 and 1.9.3 uses [Rjb](http://rjb.rubyforge.org/) to proxy over JNI.
|
24
|
+
|
17
25
|
### Jarfile
|
18
26
|
|
19
27
|
A Jarfile is a simple file using a Ruby DSL for defining a project's dependencies using the following
|
20
28
|
methods:
|
21
29
|
|
22
|
-
* **
|
23
|
-
* **
|
24
|
-
* **
|
25
|
-
* **jar( notations, opts = {} )**: Add Jar dependency in artifact notation, artifact:group:version as the bare minimum. A single or Array of notations can be passed. Default
|
26
|
-
* **pom( pom_path, opts = {} )**: Add a local Maven pom, default is to load dependencies for
|
27
|
-
* **scope( scopes )**: Set the scope for nested jar or pom. A single or Array of scopes can be set.
|
30
|
+
* **local_repo( path )**: Set the local Maven repository, this were dependencies are downloaded to.
|
31
|
+
* **remote_repo( url )**: Add additional url of remote Maven repository.
|
32
|
+
* **group( groups )**: Set the group for nested jar or pom. A single or Array of groups can be set.
|
33
|
+
* **jar( notations, opts = {} )**: Add Jar dependency in artifact notation, artifact:group:version as the bare minimum. A single or Array of notations can be passed. Default group is _default_, can be specified by setting _opts = { :group => ['group_name'] }_
|
34
|
+
* **pom( pom_path, opts = {} )**: Add a local Maven pom, default is to load dependencies for `runtime` and `compile` scopes. To select the scopes to be loaded from the pom, set the _opts = { :scopes => ['test'] }_
|
28
35
|
|
29
36
|
#### Example Jarfile
|
30
37
|
|
31
38
|
repository 'http://repository.jboss.org/nexus/content/groups/public-jboss'
|
32
39
|
|
33
|
-
// Default
|
40
|
+
// Default group is default
|
34
41
|
jar "org.apache.mina:mina-core:2.0.4"
|
35
42
|
|
36
|
-
|
43
|
+
group 'runtime' do
|
37
44
|
jar 'org.apache.tomcat:servlet-api:jar:6.0.35'
|
38
45
|
end
|
39
46
|
|
40
|
-
|
41
|
-
|
47
|
+
group 'test' do
|
48
|
+
jar 'junit:junit:jar:4.10', :group => 'test'
|
49
|
+
end
|
42
50
|
|
43
51
|
### Resolving dependencies
|
44
52
|
|
@@ -58,60 +66,79 @@ Example of locking a Jarfile to a Jarfile.lock
|
|
58
66
|
|
59
67
|
### Jarfile.lock
|
60
68
|
|
61
|
-
The _Jarfile.lock_ generated is a YAML file containing the
|
69
|
+
The _Jarfile.lock_ generated is a YAML file containing information on how to handle the classpath for grouped dependencies and their nested transitive dependencies.
|
62
70
|
|
63
71
|
#### The Jarfile.lock
|
72
|
+
|
73
|
+
---
|
74
|
+
version: 0.7.0
|
75
|
+
groups:
|
76
|
+
default:
|
77
|
+
dependencies:
|
78
|
+
- ch.qos.logback:logback-classic:jar:0.9.24
|
79
|
+
- ch.qos.logback:logback-core:jar:0.9.24
|
80
|
+
- com.metapossum:metapossum-scanner:jar:1.0
|
81
|
+
- com.slackworks:modelcitizen:jar:0.2.2
|
82
|
+
- commons-beanutils:commons-beanutils:jar:1.8.3
|
83
|
+
- commons-io:commons-io:jar:1.4
|
84
|
+
- commons-lang:commons-lang:jar:2.6
|
85
|
+
- commons-logging:commons-logging:jar:1.1.1
|
86
|
+
- junit:junit:jar:4.7
|
87
|
+
- org.apache.mina:mina-core:jar:2.0.4
|
88
|
+
- org.slf4j:slf4j-api:jar:1.6.1
|
89
|
+
artifacts:
|
90
|
+
- jar:org.apache.mina:mina-core:jar:2.0.4:
|
91
|
+
transitive:
|
92
|
+
org.slf4j:slf4j-api:jar:1.6.1: {}
|
93
|
+
- pom:spec/pom.xml:
|
94
|
+
scopes:
|
95
|
+
- runtime
|
96
|
+
- compile
|
97
|
+
transitive:
|
98
|
+
com.metapossum:metapossum-scanner:jar:1.0:
|
99
|
+
junit:junit:jar:4.7: {}
|
100
|
+
commons-io:commons-io:jar:1.4: {}
|
101
|
+
commons-beanutils:commons-beanutils:jar:1.8.3:
|
102
|
+
commons-logging:commons-logging:jar:1.1.1: {}
|
103
|
+
ch.qos.logback:logback-classic:jar:0.9.24:
|
104
|
+
ch.qos.logback:logback-core:jar:0.9.24: {}
|
105
|
+
commons-lang:commons-lang:jar:2.6: {}
|
106
|
+
development:
|
107
|
+
dependencies:
|
108
|
+
- com.typesafe:config:jar:0.5.0
|
109
|
+
artifacts:
|
110
|
+
- jar:com.typesafe:config:jar:0.5.0:
|
111
|
+
transitive: {}
|
112
|
+
test:
|
113
|
+
dependencies:
|
114
|
+
- junit:junit:jar:4.10
|
115
|
+
- org.hamcrest:hamcrest-core:jar:1.1
|
116
|
+
artifacts:
|
117
|
+
- jar:junit:junit:jar:4.10:
|
118
|
+
transitive:
|
119
|
+
org.hamcrest:hamcrest-core:jar:1.1: {}
|
120
|
+
...
|
64
121
|
|
65
|
-
---
|
66
|
-
repositories:
|
67
|
-
- http://repository.jboss.org/nexus/content/groups/public-jboss
|
68
|
-
scopes:
|
69
|
-
compile:
|
70
|
-
dependencies:
|
71
|
-
- org.apache.mina:mina-core:2.0.4
|
72
|
-
resolved_dependencies:
|
73
|
-
- org.apache.mina:mina-core:jar:2.0.4
|
74
|
-
- org.slf4j:slf4j-api:jar:1.6.1
|
75
|
-
- com.slackworks:modelcitizen:jar:0.2.2
|
76
|
-
- commons-lang:commons-lang:jar:2.6
|
77
|
-
- commons-beanutils:commons-beanutils:jar:1.8.3
|
78
|
-
- commons-logging:commons-logging:jar:1.1.1
|
79
|
-
- ch.qos.logback:logback-classic:jar:0.9.24
|
80
|
-
- ch.qos.logback:logback-core:jar:0.9.24
|
81
|
-
- com.metapossum:metapossum-scanner:jar:1.0
|
82
|
-
- commons-io:commons-io:jar:1.4
|
83
|
-
- junit:junit:jar:4.7
|
84
|
-
runtime:
|
85
|
-
dependencies:
|
86
|
-
- org.apache.tomcat:servlet-api:jar:6.0.35
|
87
|
-
resolved_dependencies:
|
88
|
-
- org.apache.tomcat:servlet-api:jar:6.0.35
|
89
|
-
test:
|
90
|
-
dependencies:
|
91
|
-
- junit:junit:jar:4.10
|
92
|
-
resolved_dependencies:
|
93
|
-
- junit:junit:jar:4.10
|
94
|
-
- org.hamcrest:hamcrest-core:jar:1.1
|
95
122
|
|
96
123
|
|
97
124
|
### Accessing Jars
|
98
125
|
**LockJar.install(*args)**: Download Jars in the Jarfile.lock
|
99
126
|
* _[String]_ will set the Jarfile.lock path, e.g. `'Better.lock'`. Default lock file is `'Jarfile.lock'`.
|
100
|
-
* _[Array<String>]_ will set the
|
127
|
+
* _[Array<String>]_ will set the groups, e.g. `['compile','test']`. Defaults group is _default_.
|
101
128
|
* _[Hash]_ will set the options, e.g. `{ :local_repo => 'path' }`
|
102
129
|
* **:local_repo** _[String]_ sets the local repo path. Defaults to `ENV['M2_REPO']` or `'~/.m2/repository'`
|
103
130
|
|
104
|
-
**LockJar.list(*args)**: Lists all dependencies as notations for
|
131
|
+
**LockJar.list(*args)**: Lists all dependencies as notations for groups from the Jarfile.lock. Depending on the type of arg, a different configuration is set.
|
105
132
|
* _[String]_ will set the Jarfile.lock path, e.g. `'Better.lock'`. Default lock file is `'Jarfile.lock'`.
|
106
|
-
* _[Array<String>]_ will set the
|
133
|
+
* _[Array<String>]_ will set the groups, e.g. `['default', 'runtime']`. Defaults group is _default_.
|
107
134
|
* _[Hash]_ will set the options, e.g. `{ :local_repo => 'path' }`
|
108
135
|
* **:local_repo** _[String]_ sets the local repo path. Defaults to `ENV['M2_REPO']` or `'~/.m2/repository'`
|
109
136
|
* **:local_paths** _[Boolean]_ converts the notations to paths of jars in the local repo
|
110
137
|
* **:resolve** _[Boolean]_ to true will make transitive dependences resolve before returning list of jars
|
111
138
|
|
112
|
-
**LockJar.load(*args)**: Loads all dependencies to the classpath for
|
139
|
+
**LockJar.load(*args)**: Loads all dependencies to the classpath for groups from the Jarfile.lock. Default group is _default_. Default lock file is _Jarfile.lock_.
|
113
140
|
* _[String]_ will set the Jarfile.lock, e.g. `'Better.lock'`
|
114
|
-
* _[Array<String>]_ will set the
|
141
|
+
* _[Array<String>]_ will set the groups, e.g. `['default', 'runtime']`
|
115
142
|
* _[Hash]_ will set the options, e.g. `{ :local_repo => 'path' }`
|
116
143
|
* **:local_repo** _[String]_ sets the local repo path
|
117
144
|
* **:resolve** _[Boolean]_ to true will make transitive dependences resolve before loading to classpath
|
@@ -176,7 +203,7 @@ _lockjar_ _--help_ will give you list of all commands and their options.
|
|
176
203
|
|
177
204
|
## Gem Integration
|
178
205
|
|
179
|
-
### Installing
|
206
|
+
### Installing Jars with a Gem
|
180
207
|
|
181
208
|
LockJar can be triggered when a Gem is installed by using a [Gem extension](http://docs.rubygems.org/read/chapter/20#extensions)
|
182
209
|
of type _Rakefile_. The cavaet is the task to install the jars must be the default for the Rakefile.
|
@@ -208,16 +235,30 @@ point at the task to download the jars (from the example Rakefile,
|
|
208
235
|
_PostInstallRakefile_ to handle the `task :prepare`. When packaging the gem, _PostInstallRakefile_ is
|
209
236
|
renamed to `Rakefile`.
|
210
237
|
|
238
|
+
### Manually installing Jars
|
239
|
+
|
240
|
+
Instead of rely in a Rakefile to install Jars when the Gem is installed, Jars can be manually installed. The following
|
241
|
+
Ruby needs to be called before calling `LockJar.load`. Only Jars that are missing are downloaded.
|
242
|
+
|
243
|
+
#get jarfile relative the gem dir
|
244
|
+
lockfile = File.expand_path( "../Jarfile.lock", __FILE__ )
|
245
|
+
|
246
|
+
# Download any missing Jars
|
247
|
+
LockJar.install( lockfile )
|
248
|
+
|
211
249
|
### Loading
|
212
250
|
|
213
|
-
With the Jars
|
251
|
+
With the Jars installed, loading the classpath for the Gem is simple.
|
214
252
|
As part of the load process for the Gem (an entry file that is required, etc) use the following:
|
215
253
|
|
216
254
|
#get jarfile relative the gem dir
|
217
255
|
lockfile = File.expand_path( "../Jarfile.lock", __FILE__ )
|
218
256
|
|
257
|
+
# Loads the ClassPath with Jars from the lockfile
|
219
258
|
LockJar.load( :lockfile => lockfile )
|
220
259
|
|
260
|
+
See also [loading Jars into a custom ClassLoader](https://github.com/mguymon/lock_jar/wiki/ClassLoader).
|
261
|
+
|
221
262
|
## Buildr Integration
|
222
263
|
|
223
264
|
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.
|
@@ -235,7 +276,7 @@ In a project, you can access an Array of notations using the **lock_jars** metho
|
|
235
276
|
lock_jars()
|
236
277
|
|
237
278
|
|
238
|
-
The
|
279
|
+
The _default_ group dependencies are automatically added to the classpath for compiling. The _test_ group dependencies are automatically added to the classpath for tests. Do not forget, if you change the LockJar definitions, you have to rerun the **lock_jar:lock** task.
|
239
280
|
|
240
281
|
|
241
282
|
### Example
|
@@ -247,7 +288,7 @@ Sample buildfile with LockJar
|
|
247
288
|
# app definition, inherited into all projects
|
248
289
|
lock_jar do
|
249
290
|
|
250
|
-
|
291
|
+
group 'test' do
|
251
292
|
jar 'junit:junit:jar:4.10'
|
252
293
|
end
|
253
294
|
end
|
@@ -275,8 +316,14 @@ Generated the following lock files using **lock_jar:lock**
|
|
275
316
|
|
276
317
|
## Bundler Integration
|
277
318
|
|
278
|
-
|
279
|
-
|
319
|
+
Bundler integration is **experimental** right now. [LockJar patches Bundler](https://github.com/mguymon/lock_jar/blob/master/lib/lock_jar/bundler.rb)
|
320
|
+
to allow creation of a _Jarfile.lock_ when Bundler calls `install` and `update`. The dependencies from the _Jarfile.lock_ are automatically loaded when
|
321
|
+
Bundler calls `setup` and `require`. To enable this support, add this require to your _Gemfile_
|
322
|
+
|
323
|
+
require 'lock_jar/bundler'
|
324
|
+
|
325
|
+
You can optionally create a _Jarfile_ that will automatically be included when you `bundle install` or `bundle update`. Otherwise
|
326
|
+
Gems with a Jarfile will be merge to generate a _Jarfile.lock_. The Jarfile.lock will be loaded when Bundler calls `setup` or `require`.
|
280
327
|
|
281
328
|
## License
|
282
329
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/lib/lock_jar/buildr.rb
CHANGED
@@ -64,7 +64,7 @@ module Buildr
|
|
64
64
|
def lock_jars( *args )
|
65
65
|
lockfile = Buildr.project_to_lockfile(project)
|
66
66
|
opts = {}
|
67
|
-
|
67
|
+
groups = ['default']
|
68
68
|
|
69
69
|
args.each do |arg|
|
70
70
|
if arg.is_a?(Hash)
|
@@ -72,11 +72,11 @@ module Buildr
|
|
72
72
|
elsif arg.is_a?( String )
|
73
73
|
lockfile = arg
|
74
74
|
elsif arg.is_a?( Array )
|
75
|
-
|
75
|
+
groups = arg
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
::LockJar.list( lockfile,
|
79
|
+
::LockJar.list( lockfile, groups, opts )
|
80
80
|
end
|
81
81
|
|
82
82
|
def lockjar_dsl
|
@@ -101,7 +101,7 @@ module Buildr
|
|
101
101
|
end
|
102
102
|
::LockJar.lock( dsl, :lockfile => "#{project.name}.lock" )
|
103
103
|
else
|
104
|
-
# XXX: output that there were
|
104
|
+
# XXX: output that there were no dependencies to lock
|
105
105
|
puts "No lock_jar dependencies to lock for #{project.name}"
|
106
106
|
end
|
107
107
|
end
|
@@ -110,7 +110,7 @@ module Buildr
|
|
110
110
|
if project.lockjar_dsl && !File.exists?( Buildr.project_to_lockfile(project) )
|
111
111
|
raise "#{project.name}.lock does not exist, run #{project.name}:lockjar:lock first"
|
112
112
|
end
|
113
|
-
jars = ::LockJar.list( Buildr.project_to_lockfile(project), ['
|
113
|
+
jars = ::LockJar.list( Buildr.project_to_lockfile(project), ['default'] )
|
114
114
|
project.compile.with( jars )
|
115
115
|
end
|
116
116
|
|
@@ -118,7 +118,7 @@ module Buildr
|
|
118
118
|
if project.lockjar_dsl && !File.exists?( Buildr.project_to_lockfile(project) )
|
119
119
|
raise "#{Buildr.project_to_lockfile(project)} does not exist, run #{project.name}:lockjar:lock first"
|
120
120
|
end
|
121
|
-
jars = ::LockJar.list( Buildr.project_to_lockfile(project), ['
|
121
|
+
jars = ::LockJar.list( Buildr.project_to_lockfile(project), ['test'] )
|
122
122
|
|
123
123
|
project.test.compile.with( jars )
|
124
124
|
project.test.with( jars )
|
@@ -128,10 +128,10 @@ module Buildr
|
|
128
128
|
if project.lockjar_dsl && !File.exists?( Buildr.project_to_lockfile(project) )
|
129
129
|
raise "#{Buildr.project_to_lockfile(project)} does not exist, run #{project.name}:lockjar:lock first"
|
130
130
|
end
|
131
|
-
jars = ::LockJar.list( Buildr.project_to_lockfile(project), ['
|
131
|
+
jars = ::LockJar.list( Buildr.project_to_lockfile(project), ['default'] )
|
132
132
|
project.compile.with( jars )
|
133
133
|
|
134
|
-
jars = ::LockJar.list( Buildr.project_to_lockfile(project), ['
|
134
|
+
jars = ::LockJar.list( Buildr.project_to_lockfile(project), ['test'] )
|
135
135
|
project.test.compile.with( jars )
|
136
136
|
end
|
137
137
|
end
|
@@ -0,0 +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 )
|
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
|
+
end
|
@@ -0,0 +1,117 @@
|
|
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
|
+
end
|
37
|
+
|
38
|
+
class Jar < Artifact
|
39
|
+
attr_reader :notation
|
40
|
+
|
41
|
+
def initialize( notation )
|
42
|
+
@type = 'jar'
|
43
|
+
@notation = Naether::Notation.new( notation ).to_notation
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_urn
|
47
|
+
"jar:#{notation}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_dep
|
51
|
+
notation
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Local < Artifact
|
56
|
+
attr_reader :path
|
57
|
+
def initialize( path )
|
58
|
+
@type = 'local'
|
59
|
+
@path = path
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_urn
|
63
|
+
"local:#{path}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_dep
|
67
|
+
path
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class Pom < Artifact
|
72
|
+
attr_reader :path, :scopes
|
73
|
+
|
74
|
+
def initialize( _path, _scopes = ['compile','runtime'] )
|
75
|
+
@type = 'pom'
|
76
|
+
@path = _path
|
77
|
+
@scopes = _scopes
|
78
|
+
end
|
79
|
+
|
80
|
+
def to_urn
|
81
|
+
"pom:#{path}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def to_dep
|
85
|
+
{ path => scopes }
|
86
|
+
end
|
87
|
+
|
88
|
+
def notations
|
89
|
+
LockJar::Maven.dependencies( path, scopes )
|
90
|
+
end
|
91
|
+
|
92
|
+
def ==(another_artifact)
|
93
|
+
self.<=>(another_artifact) == 0
|
94
|
+
end
|
95
|
+
|
96
|
+
def <=>(another_artifact)
|
97
|
+
if another_artifact.is_a? Pom
|
98
|
+
if to_urn == another_artifact.to_urn
|
99
|
+
return 0 if Set.new(scopes) == Set.new(another_artifact.scopes)
|
100
|
+
|
101
|
+
# XXX: this is not a reliable way to compare.
|
102
|
+
if scopes.size > another_artifact.scopes.size
|
103
|
+
return 1
|
104
|
+
else
|
105
|
+
return -1
|
106
|
+
end
|
107
|
+
else
|
108
|
+
to_urn <=> another_artifact.to_urn
|
109
|
+
end
|
110
|
+
else
|
111
|
+
super
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|