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.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +16 -0
  3. data/.gitignore +59 -0
  4. data/.rubocop.yml +31 -0
  5. data/.travis.yml +21 -0
  6. data/CHANGELOG.md +80 -0
  7. data/Gemfile +13 -0
  8. data/Guardfile +8 -0
  9. data/LICENSE +176 -0
  10. data/README.md +392 -0
  11. data/Rakefile +28 -0
  12. data/bin/lockjar +6 -0
  13. data/lib/lock_jar/buildr.rb +151 -0
  14. data/lib/lock_jar/bundler.rb +68 -0
  15. data/lib/lock_jar/class_loader.rb +67 -0
  16. data/lib/lock_jar/cli.rb +92 -0
  17. data/lib/lock_jar/config.rb +41 -0
  18. data/lib/lock_jar/domain/artifact.rb +114 -0
  19. data/lib/lock_jar/domain/dsl.rb +165 -0
  20. data/lib/lock_jar/domain/dsl_merger.rb +76 -0
  21. data/lib/lock_jar/domain/gem_dsl.rb +43 -0
  22. data/lib/lock_jar/domain/jarfile_dsl.rb +35 -0
  23. data/lib/lock_jar/domain/lockfile.rb +113 -0
  24. data/lib/lock_jar/logging.rb +14 -0
  25. data/lib/lock_jar/maven.rb +112 -0
  26. data/lib/lock_jar/registry.rb +85 -0
  27. data/lib/lock_jar/resolver.rb +100 -0
  28. data/lib/lock_jar/runtime/install.rb +28 -0
  29. data/lib/lock_jar/runtime/list.rb +77 -0
  30. data/lib/lock_jar/runtime/load.rb +53 -0
  31. data/lib/lock_jar/runtime/lock.rb +152 -0
  32. data/lib/lock_jar/runtime.rb +106 -0
  33. data/lib/lock_jar/version.rb +5 -0
  34. data/lib/lock_jar.rb +203 -0
  35. data/lock_jar.gemspec +36 -0
  36. data/spec/fixtures/Jarfile +14 -0
  37. data/spec/fixtures/Jarfile2 +1 -0
  38. data/spec/fixtures/jarfile_gem/Gemfile +4 -0
  39. data/spec/fixtures/jarfile_gem/Jarfile +1 -0
  40. data/spec/fixtures/jarfile_gem/jarfile_gem.gemspec +23 -0
  41. data/spec/fixtures/jarfile_gem/lib/jarfile_gem/version.rb +3 -0
  42. data/spec/fixtures/jarfile_gem/lib/jarfile_gem.rb +5 -0
  43. data/spec/fixtures/lock_jar_config.yml +4 -0
  44. data/spec/fixtures/naether-0.13.0.jar +0 -0
  45. data/spec/lock_jar/bundler_spec.rb +34 -0
  46. data/spec/lock_jar/class_loader_spec.rb +55 -0
  47. data/spec/lock_jar/cli_spec.rb +93 -0
  48. data/spec/lock_jar/config_spec.rb +51 -0
  49. data/spec/lock_jar/domain/dsl_merger_spec.rb +51 -0
  50. data/spec/lock_jar/domain/dsl_spec.rb +55 -0
  51. data/spec/lock_jar/domain/gem_dsl_spec.rb +18 -0
  52. data/spec/lock_jar/maven_spec.rb +21 -0
  53. data/spec/lock_jar/resolver_spec.rb +69 -0
  54. data/spec/lock_jar/runtime_spec.rb +30 -0
  55. data/spec/lock_jar_spec.rb +472 -0
  56. data/spec/pom.xml +28 -0
  57. data/spec/spec_helper.rb +45 -0
  58. data/spec/support/Jarfile +1 -0
  59. data/spec/support/helper.rb +52 -0
  60. data/spec/support/shared_examples/lockfile.rb +45 -0
  61. metadata +203 -0
data/README.md ADDED
@@ -0,0 +1,392 @@
1
+ # LockJar
2
+
3
+ [![Build Status](https://secure.travis-ci.org/mguymon/lock_jar.png?branch=master)](http://travis-ci.org/mguymon/lock_jar)
4
+ [![Code Climate](https://codeclimate.com/github/mguymon/lock_jar/badges/gpa.svg)](https://codeclimate.com/github/mguymon/lock_jar)
5
+
6
+ LockJar manages Java Jars for Ruby. Powered by [Naether](https://github.com/mguymon/naether) to
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
+
9
+ LockJar can:
10
+ * Be used directly in MRI 2.x and JRuby 1.7, 9.0
11
+ * From the [command line](https://github.com/mguymon/lock_jar/blob/master/README.md#command-line)
12
+ * [Triggered from a Gem install](https://github.com/mguymon/lock_jar/blob/master/README.md#gem-integration)
13
+ * [Integrated into Buildr](https://github.com/mguymon/lock_jar/blob/master/README.md#buildr-integration)
14
+ * [Integrated into Bundler](https://github.com/mguymon/lock_jar/blob/master/README.md#bundler-integration)
15
+
16
+ https://github.com/mguymon/lock_jar
17
+
18
+ [RDoc](http://rubydoc.info/gems/lock_jar/frames)
19
+
20
+ ## Install
21
+
22
+ gem install lock_jar
23
+
24
+ ## Ruby Usage
25
+
26
+ JRuby is natively supported. Ruby 2.x uses [Rjb](http://rjb.rubyforge.org/) to proxy over JNI.
27
+
28
+ ### Jarfile
29
+
30
+ A Jarfile is a simple file using a Ruby DSL for defining a project's dependencies using the following
31
+ methods:
32
+
33
+ * **local_repo(path)**: Set the local Maven repository, this were dependencies are downloaded to.
34
+ * **remote_repo(url)**: Add additional url of remote Maven repository.
35
+ * **group(groups)**: Set the group for nested jar or pom. A single or Array of groups can be set.
36
+ * **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'] }_
37
+ * **local(path)**: Add a local path to a Jar
38
+ * **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'] }_
39
+ * **without_default_maven_repo**: Do not use the default maven repo.
40
+
41
+ #### Example Jarfile
42
+
43
+ repository 'http://repository.jboss.org/nexus/content/groups/public-jboss'
44
+
45
+ // Default group is default
46
+ jar "org.apache.mina:mina-core:2.0.4"
47
+ local 'spec/fixtures/naether-0.13.0.jar'
48
+
49
+ group 'runtime' do
50
+ jar 'org.apache.tomcat:servlet-api:jar:6.0.35'
51
+ end
52
+
53
+ group 'test' do
54
+ jar 'junit:junit:jar:4.12', :group => 'test'
55
+ end
56
+
57
+ ### Resolving dependencies
58
+
59
+ **LockJar.lock(*args)**: Using a Jarfile, creates a lock file. Depending on the type of arg, a different configuration is set.
60
+ * _[String]_ will set the Jarfile path, e.g. `'/somewhere/Jarfile.different'`. Default jarfile is `'Jarfile'`
61
+ * _[Hash]_ will set the options, e.g. `{ :local_repo => 'path' }`
62
+ * **:download** _[Boolean]_ if true, will download jars to local repo. Defaults to true.
63
+ * **:local_repo** _[String]_ sets the local repo path. Defaults to `ENV['M2_REPO']` or `'~/.m2/repository'`
64
+ * **:lockfile** _[String]_ sets the Jarfile.lock path. Default lockfile is `'Jarfile.lock'`.
65
+
66
+ When the Jarfile is locked, the transitive dependencies are resolved and saved to the Jarfile.lock file.
67
+
68
+ Example of locking a Jarfile to a Jarfile.lock
69
+
70
+ LockJar.lock
71
+
72
+ #### Default Remote Repository
73
+
74
+ LockJar uses Naether's default remote repository, http://repo1.maven.org/maven2/.
75
+
76
+ Jarfile.lock pior to _0.12.0_ did not write the default remote repository. As of version _0.12.0_, only repositories in the Jarfile.lock are used. This means older Jarfile.lock will need to be updated to include the default maven repo if they rely on it.
77
+
78
+
79
+ ### Jarfile.lock
80
+
81
+ The _Jarfile.lock_ generated is a YAML file containing information on how to handle the classpath for grouped dependencies and their nested transitive dependencies.
82
+
83
+ #### The Jarfile.lock
84
+
85
+ ---
86
+ version: 0.7.0
87
+ groups:
88
+ default:
89
+ dependencies:
90
+ - ch.qos.logback:logback-classic:jar:0.9.24
91
+ - ch.qos.logback:logback-core:jar:0.9.24
92
+ - com.metapossum:metapossum-scanner:jar:1.0
93
+ - com.tobedevoured.modelcitizen:core:jar:0.8.1
94
+ - commons-beanutils:commons-beanutils:jar:1.8.3
95
+ - commons-io:commons-io:jar:1.4
96
+ - commons-lang:commons-lang:jar:2.6
97
+ - commons-logging:commons-logging:jar:1.1.1
98
+ - junit:junit:jar:4.7
99
+ - org.apache.mina:mina-core:jar:2.0.4
100
+ - org.slf4j:slf4j-api:jar:1.6.1
101
+ artifacts:
102
+ - jar:org.apache.mina:mina-core:jar:2.0.4:
103
+ transitive:
104
+ org.slf4j:slf4j-api:jar:1.6.1: {}
105
+ - pom:spec/pom.xml:
106
+ scopes:
107
+ - runtime
108
+ - compile
109
+ transitive:
110
+ com.metapossum:metapossum-scanner:jar:1.0:
111
+ junit:junit:jar:4.7: {}
112
+ commons-io:commons-io:jar:1.4: {}
113
+ commons-beanutils:commons-beanutils:jar:1.8.3:
114
+ commons-logging:commons-logging:jar:1.1.1: {}
115
+ ch.qos.logback:logback-classic:jar:0.9.24:
116
+ ch.qos.logback:logback-core:jar:0.9.24: {}
117
+ commons-lang:commons-lang:jar:2.6: {}
118
+ development:
119
+ dependencies:
120
+ - com.typesafe:config:jar:0.5.0
121
+ artifacts:
122
+ - jar:com.typesafe:config:jar:0.5.0:
123
+ transitive: {}
124
+ test:
125
+ dependencies:
126
+ - junit:junit:jar:4.12
127
+ - org.hamcrest:hamcrest-core:jar:1.1
128
+ artifacts:
129
+ - jar:junit:junit:jar:4.12:
130
+ transitive:
131
+ org.hamcrest:hamcrest-core:jar:1.1: {}
132
+ ...
133
+
134
+
135
+
136
+ ### Accessing Jars
137
+ **LockJar.install(*args)**: Download Jars in the Jarfile.lock
138
+ * _[String]_ will set the Jarfile.lock path, e.g. `'Better.lock'`. Default lock file is `'Jarfile.lock'`.
139
+ * _[Array<String>]_ will set the groups, e.g. `['compile','test']`. Defaults group is _default_.
140
+ * _[Hash]_ will set the options, e.g. `{ :local_repo => 'path' }`
141
+ * **:local_repo** _[String]_ sets the local repo path. Defaults to `ENV['M2_REPO']` or `'~/.m2/repository'`
142
+
143
+ **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.
144
+ * _[String]_ will set the Jarfile.lock path, e.g. `'Better.lock'`. Default lock file is `'Jarfile.lock'`.
145
+ * _[Array<String>]_ will set the groups, e.g. `['default', 'runtime']`. Defaults group is _default_.
146
+ * _[Hash]_ will set the options, e.g. `{ :local_repo => 'path' }`
147
+ * **:local_repo** _[String]_ sets the local repo path. Defaults to `ENV['M2_REPO']` or `'~/.m2/repository'`
148
+ * **:local_paths** _[Boolean]_ converts the notations to paths of jars in the local repo
149
+ * **:resolve** _[Boolean]_ to `true` will make transitive dependences resolve before returning list of jars. Setting to `false` will list dependencies, excluding transitive dependencies.
150
+
151
+ **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_.
152
+ * _[String]_ will set the Jarfile.lock, e.g. `'Better.lock'`
153
+ * _[Array<String>]_ will set the groups, e.g. `['default', 'runtime']`
154
+ * _[Hash]_ will set the options, e.g. `{ :local_repo => 'path' }`
155
+ * **:local_repo** _[String]_ sets the local repo path
156
+ * **:resolve** _[Boolean]_ to true will make transitive dependences resolve before loading to classpath
157
+
158
+ Once a _Jarfile.lock_ is generated, you can list all resolved jars by
159
+
160
+ jars = LockJar.list
161
+
162
+ or directly load all Jars into the classpath
163
+
164
+ jars = LockJar.load
165
+
166
+ Do not forget, if you change your _Jarfile_, you have to re-generate the _Jarfile.lock_.
167
+
168
+ See also [loading Jars into a custom ClassLoader](https://github.com/mguymon/lock_jar/wiki/ClassLoader).
169
+
170
+ ### Shortcuts
171
+
172
+ #### Skipping the Jarfile
173
+
174
+ You can skip the _Jarfile_ and _Jarfile.lock_ to directly play with dependencies by passing a block to _LockJar.lock_, _LockJar.list_, and _LockJar.load_
175
+
176
+ #### Lock without a Jarfile
177
+
178
+ LockJar.lock do
179
+ jar 'org.eclipse.jetty:example-jetty-embedded:jar:8.1.2.v20120308'
180
+ end
181
+
182
+ #### List without a Jarfile.lock
183
+
184
+ LockJar.list do
185
+ jar 'org.eclipse.jetty:example-jetty-embedded:jar:8.1.2.v20120308'
186
+ end
187
+
188
+ #### Load without a Jarfile.lock
189
+
190
+ LockJar.load do
191
+ jar 'org.eclipse.jetty:example-jetty-embedded:jar:8.1.2.v20120308'
192
+ end
193
+
194
+ Since you skipped the locking part, mostly likely you will need to resolve the dependences in the block, just pass the _:resolve => true_ option to enable dependency resolution (also works for _LockJar.list_).
195
+
196
+ LockJar.load(:resolve => true) do
197
+ jar 'org.eclipse.jetty:example-jetty-embedded:jar:8.1.2.v20120308'
198
+ end
199
+
200
+ ## Command line
201
+
202
+ There is a simple command line helper. You can lock a _Jarfile_ with the following command
203
+
204
+ lockjar lock
205
+
206
+ List jars in a _Jarfile.lock_ with
207
+
208
+ lockjar list
209
+
210
+ Download all jars in a _Jarfile.lock_ with
211
+
212
+ lockjar install
213
+
214
+ _lockjar_ _--help_ will give you list of all commands and their options.
215
+
216
+ ## Gem Integration
217
+
218
+ ### Installing Jars with a Gem
219
+
220
+ LockJar can be triggered when a Gem is installed by using a [Gem extension](http://docs.rubygems.org/read/chapter/20#extensions)
221
+ of type _Rakefile_. The cavaet is the task to install the jars must be the default for the Rakefile.
222
+
223
+ A Gem spec with _Rakefile_ extension:
224
+
225
+ Gem::Specification.new do |s|
226
+ s.extensions = ["Rakefile"]
227
+ end
228
+
229
+ Rakefile with default to install Jars using LockJar:
230
+
231
+ task :default => :prepare
232
+
233
+ task :prepare do
234
+ require 'lock_jar'
235
+
236
+ # get jarfile relative the gem dir
237
+ lockfile = File.expand_path("../Jarfile.lock", __FILE__)
238
+
239
+ LockJar.install(lockfile)
240
+ end
241
+
242
+ #### Work around for Rakefile default
243
+
244
+ The downside of using the Gem extension Rakefile is it requires the default to
245
+ point at the task to download the jars (from the example Rakefile,
246
+ `task :default => :prepare`). To get around this, I used a Rakefile called
247
+ _PostInstallRakefile_ to handle the `task :prepare`. When packaging the gem, _PostInstallRakefile_ is
248
+ renamed to `Rakefile`.
249
+
250
+ ### Manually installing Jars
251
+
252
+ Instead of rely in a Rakefile to install Jars when the Gem is installed, Jars can be manually installed. The following
253
+ Ruby needs to be called before calling `LockJar.load`. Only Jars that are missing are downloaded.
254
+
255
+ #get jarfile relative the gem dir
256
+ lockfile = File.expand_path("../Jarfile.lock", __FILE__)
257
+
258
+ # Download any missing Jars
259
+ LockJar.install(lockfile)
260
+
261
+ ### Loading
262
+
263
+ With the Jars installed, loading the classpath for the Gem is simple.
264
+ As part of the load process for the Gem (an entry file that is required, etc) use the following:
265
+
266
+ #get jarfile relative the gem dir
267
+ lockfile = File.expand_path("../Jarfile.lock", __FILE__)
268
+
269
+ # Loads the ClassPath with Jars from the lockfile
270
+ LockJar.load(lockfile)
271
+
272
+ See also [loading Jars into a custom ClassLoader](https://github.com/mguymon/lock_jar/wiki/ClassLoader).
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
+
285
+ ## Buildr Integration
286
+
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.
288
+
289
+ A new Buildr task is added to generate the lockfile for all projects
290
+
291
+ buildr lock_jar:lock
292
+
293
+ and a task per project to generate the lockfile for a single project
294
+
295
+ buildr <app>:<project>:lock_jar:lock
296
+
297
+ In a project, you can access an Array of notations using the **lock_jars** method, accepts same parameters as [LockJar.list](https://github.com/mguymon/lock_jar#accessing-jars)
298
+
299
+ lock_jars()
300
+
301
+
302
+ 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.
303
+
304
+
305
+ ### Example
306
+
307
+ Sample buildfile with LockJar
308
+
309
+ require 'lock_jar/buildr'
310
+
311
+ # app definition, inherited into all projects
312
+ lock_jar do
313
+ group 'test' do
314
+ jar 'junit:junit:jar:4.12'
315
+ end
316
+ end
317
+
318
+ define 'app' do
319
+ define 'project1' do
320
+ lock_jar do
321
+ jar "org.apache.mina:mina-core:2.0.4"
322
+ end
323
+ end
324
+
325
+ define 'project2' do
326
+ lock_jar do
327
+ pom 'pom.xml'
328
+ end
329
+ end
330
+ end
331
+
332
+ Generated the following lock files using **lock_jar:lock**
333
+
334
+ * _project1.lock_ - contains _junit_ and _mina_ jars.
335
+ * _project2.lock_ - contains _junit_ and _pom.xml_ jars.
336
+
337
+ ## Bundler Integration
338
+
339
+ [LockJar patches Bundler](https://github.com/mguymon/lock_jar/blob/master/lib/lock_jar/bundler.rb)
340
+ to allow creation of a _Jarfile.lock_ when Bundler calls `install` and `update`. To enable this support, add this exit callback your _Gemfile_
341
+
342
+ @@check ||= at_exit do
343
+ require 'lock_jar/bundler'
344
+ LockJar::Bundler.lock!
345
+ end
346
+
347
+ You can optionally create a _Jarfile_ that will automatically be included when you `bundle install` or `bundle update`. Otherwise
348
+ Gems with a Jarfile will be merge to generate a _Jarfile.lock_.
349
+
350
+ ### Bundler to LockJar groups
351
+
352
+ LockJar will merge the dependencies from the `default` and `runtime` group of a Gem's _Jarfile_. These will be placed in the
353
+ lockfile under Gem's corresponding Bundler group. For example, the following Gemfile:
354
+
355
+ group :development do
356
+ gem 'solr_sail', '~>0.1.0'
357
+ end
358
+
359
+ Would produce the follow _Jarfile.lock_ excerpt:
360
+
361
+ ---
362
+ version: 0.7.0
363
+ merged:
364
+ - gem:solr_sail:gems/solr_sail-0.1.0-java/Jarfile
365
+ groups:
366
+ default:
367
+ dependencies: []
368
+ artifacts: []
369
+ development:
370
+ dependencies:
371
+ - ch.qos.logback:logback-classic:jar:1.0.6
372
+ - ch.qos.logback:logback-core:jar:1.0.6
373
+ - com.google.guava:guava:jar:r05
374
+
375
+ Since `solr_sail` is defined in the _Gemfile's_ `development` group, the corresponding _Jarfile.lock_ dependencies are also under the `development` group.
376
+
377
+ ## License
378
+
379
+ Licensed to the Apache Software Foundation (ASF) under one or more
380
+ contributor license agreements. See the NOTICE file distributed with this
381
+ work for additional information regarding copyright ownership. The ASF
382
+ licenses this file to you under the Apache License, Version 2.0 (the
383
+ "License"); you may not use this file except in compliance with the License.
384
+ You may obtain a copy of the License at
385
+
386
+ http://www.apache.org/licenses/LICENSE-2.0
387
+
388
+ Unless required by applicable law or agreed to in writing, software
389
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
390
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
391
+ License for the specific language governing permissions and limitations under
392
+ the License.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bundler'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+ require 'bundler/gem_tasks'
7
+ require 'rdoc/task'
8
+
9
+ begin
10
+ Bundler.setup(:default, :development)
11
+ rescue Bundler::BundlerError => e
12
+ $stderr.puts e.message
13
+ $stderr.puts 'Run `bundle install` to install missing gems'
14
+ exit e.status_code
15
+ end
16
+
17
+ RSpec::Core::RakeTask.new
18
+ RuboCop::RakeTask.new
19
+
20
+ Rake::RDocTask.new do |rdoc|
21
+ version = File.exist?('VERSION') ? File.read('VERSION') : ''
22
+ rdoc.rdoc_dir = 'rdoc'
23
+ rdoc.title = "lockjar #{version}"
24
+ rdoc.rdoc_files.include('README*')
25
+ rdoc.rdoc_files.include('lib/**/*.rb')
26
+ end
27
+
28
+ task default: [:spec, :rubocop]
data/bin/lockjar ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'thor'
4
+ require 'lock_jar/cli'
5
+
6
+ LockJar::CLI.start
@@ -0,0 +1,151 @@
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 'lock_jar'
17
+ require 'lock_jar/domain/dsl'
18
+
19
+ #
20
+ module Buildr
21
+ class << self
22
+ attr_accessor :global_lockjar_dsl
23
+
24
+ def project_to_lockfile(project)
25
+ "#{project.name.tr(':', '-')}.lock"
26
+ end
27
+ end
28
+
29
+ def lock_jar(&blk)
30
+ Buildr.global_lockjar_dsl = ::LockJar::Domain::Dsl.create(&blk)
31
+ end
32
+
33
+ namespace 'lock_jar' do
34
+ desc 'Lock dependencies for each project'
35
+ task('lock') do
36
+ projects.each do |project|
37
+ next if project.lockjar_dsl.nil?
38
+
39
+ # add buildr repos
40
+ repositories.remote.each do |repo|
41
+ project.lockjar_dsl.repository repo
42
+ end
43
+ ::LockJar.lock(project.lockjar_dsl, lockfile: Buildr.project_to_lockfile(project))
44
+ end
45
+ end
46
+ end
47
+
48
+ module LockJar
49
+ #
50
+ module ProjectExtension
51
+ include Extension
52
+
53
+ def lock_jar(&blk)
54
+ @lockjar_dsl = ::LockJar::Domain::Dsl.create(&blk)
55
+ @lockjar_dsl.merge(Buildr.global_lockjar_dsl) unless Buildr.global_lockjar_dsl.nil?
56
+ end
57
+
58
+ def lock_jars(*args)
59
+ lockfile = Buildr.project_to_lockfile(project)
60
+ opts = {}
61
+ groups = ['default']
62
+
63
+ args.each do |arg|
64
+ if arg.is_a?(Hash)
65
+ opts.merge!(arg)
66
+ elsif arg.is_a?(String)
67
+ lockfile = arg
68
+ elsif arg.is_a?(Array)
69
+ groups = arg
70
+ end
71
+ end
72
+
73
+ ::LockJar.list(lockfile, groups, opts)
74
+ end
75
+
76
+ def lockjar_dsl
77
+ @lockjar_dsl || Buildr.global_lockjar_dsl
78
+ end
79
+
80
+ after_define do |project|
81
+ task compile: 'lock_jar:compile'
82
+ task 'test:compile' => 'lock_jar:test:compile'
83
+
84
+ task 'eclipse' => 'lock_jar:eclipse'
85
+
86
+ namespace 'lock_jar' do
87
+ desc 'Lock dependencies to JarFile'
88
+ task('lock') do
89
+ dsl = project.lockjar_dsl
90
+ if dsl
91
+ # add buildr repos
92
+ repositories.remote do |repo|
93
+ puts repo
94
+ dsl.repository repo
95
+ end
96
+ ::LockJar.lock(dsl, lockfile: "#{project.name}.lock")
97
+ else
98
+ # XXX: output that there were no dependencies to lock
99
+ puts "No lock_jar dependencies to lock for #{project.name}"
100
+ end
101
+ end
102
+
103
+ task('compile') do
104
+ if project.lockjar_dsl && !File.exist?(Buildr.project_to_lockfile(project))
105
+ fail(
106
+ "#{project.name}.lock does not exist, run "\
107
+ "#{project.name}:lockjar:lock first"
108
+ )
109
+ end
110
+ jars = ::LockJar.list(Buildr.project_to_lockfile(project), ['default'])
111
+ project.compile.with(jars)
112
+ end
113
+
114
+ task('test:compile') do
115
+ if project.lockjar_dsl && !File.exist?(Buildr.project_to_lockfile(project))
116
+ fail(
117
+ "#{Buildr.project_to_lockfile(project)} does not exist, run"\
118
+ " #{project.name}:lockjar:lock first"
119
+ )
120
+ end
121
+ jars = ::LockJar.list(Buildr.project_to_lockfile(project), ['test'])
122
+
123
+ project.test.compile.with(jars)
124
+ project.test.with(jars)
125
+ end
126
+
127
+ task('eclipse') do
128
+ if project.lockjar_dsl && !File.exist?(Buildr.project_to_lockfile(project))
129
+ fail(
130
+ "#{Buildr.project_to_lockfile(project)} does not exist, run "\
131
+ "#{project.name}:lockjar:lock first"
132
+ )
133
+ end
134
+ jars = ::LockJar.list(Buildr.project_to_lockfile(project), ['default'])
135
+ project.compile.with(jars)
136
+
137
+ jars = ::LockJar.list(Buildr.project_to_lockfile(project), ['test'])
138
+ project.test.compile.with(jars)
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
145
+
146
+ module Buildr
147
+ # Patch Builder::Project to include Buildr::LockJar::ProjectExtension
148
+ class Project
149
+ include Buildr::LockJar::ProjectExtension
150
+ end
151
+ end
@@ -0,0 +1,68 @@
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_merger'
8
+
9
+ module LockJar
10
+ #
11
+ class Bundler
12
+ class << self
13
+ # Create a lock file from bundled gems
14
+ #
15
+ # rubocop:disable Metrics/PerceivedComplexity
16
+ def lock!(*opts)
17
+ # check if Bundler has already run
18
+ return unless ::Bundler.instance_variable_get('@setup').nil?
19
+
20
+ dsl = nil
21
+
22
+ jarfile_opt = opts.find { |option| option.is_a? String }
23
+
24
+ jarfile = File.expand_path(jarfile_opt || 'Jarfile')
25
+
26
+ # load local Jarfile
27
+ dsl = if File.exist?(jarfile)
28
+ LockJar::Domain::JarfileDsl.create(jarfile)
29
+
30
+ # Create new Dsl
31
+ else
32
+ LockJar::Domain::Dsl.new
33
+ end
34
+
35
+ gems_with_jars = []
36
+ ::Bundler.definition.groups.each do |group|
37
+ puts "[LockJar] Group #{group}:" if ENV['DEBUG']
38
+
39
+ ::Bundler.definition.specs_for([group]).each do |spec|
40
+ next unless File.exist? File.join(spec.gem_dir, 'Jarfile')
41
+
42
+ merged_dsl = merge_gem_dsl(dsl, spec, group)
43
+ if merged_dsl
44
+ gems_with_jars << "gem:#{spec.name}"
45
+ dsl = merged_dsl
46
+ end
47
+ end
48
+ end
49
+
50
+ puts "[LockJar] Locking Jars for: #{gems_with_jars.inspect}" unless gems_with_jars.empty?
51
+ LockJar.lock(*([dsl] + opts))
52
+ end
53
+ # rubocop:enable Metrics/PerceivedComplexity
54
+
55
+ private
56
+
57
+ def merge_gem_dsl(dsl, spec, group)
58
+ jarfile = File.join(spec.gem_dir, 'Jarfile')
59
+
60
+ return unless File.exist?(jarfile)
61
+
62
+ puts "[LockJar] #{spec.name} has Jarfile" if ENV['DEBUG']
63
+ spec_dsl = LockJar::Domain::GemDsl.create(spec, jarfile)
64
+ LockJar::Domain::DslMerger.new(dsl, spec_dsl, [group.to_s]).merge
65
+ end
66
+ end
67
+ end
68
+ end