lock_jar 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,11 +1,11 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "naether", "~> 0.7.0"
3
+ gem "naether", "~> 0.8.0"
4
4
 
5
5
  # Add dependencies to develop your gem here.
6
6
  # Include everything needed to run rake, tests, features, etc.
7
7
  group :development do
8
8
  gem "rspec", "~> 2.9.0"
9
- gem "bundler", "> 1.0.0"
9
+ gem "bundler", "~> 1.1.0"
10
10
  gem "jeweler", "~> 1.6.4"
11
11
  end
data/README.rdoc CHANGED
@@ -20,11 +20,13 @@ gem install lock_jar
20
20
  A Jarfile is a simple file using a Ruby DSL for defining a project's dependencies using the following
21
21
  methods:
22
22
 
23
- * local: Set the local Maven repository
24
- * repository: Add url of additional remote Maven repository.
25
- * jar: Add Jar dependency in artifact notation, default scope is *compile*
26
- * pom: Add local path to a Maven pom, default is to load dependencies for all scopes.
27
- * scope: Set the scope for nested jar or pom.
23
+ * local( path ): Set the local Maven repository
24
+ * repository( url ): Add url of additional remote Maven repository.
25
+ * map( notation, paths ): Map local paths to a notation.
26
+ * exclude( excludes ): Add a artifact:group that will be excluded from resolved dependencies. A single or Array of excludes can be set.
27
+ * 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 scope is *compile*, can be specified by setting opts = { :scope => <new_scope> }
28
+ * pom( pom_path, opts = {} ): Add local path to a Maven pom, default is to load dependencies for all scopes. To select the scopes to be loaded from the pom, set the opts = { :scopes => <new_scopes> }
29
+ * scope( scopes ): Set the scope for nested jar or pom. A single or Array of scopes can be set.
28
30
 
29
31
  Example Jarfile
30
32
 
@@ -44,7 +46,9 @@ Example Jarfile
44
46
 
45
47
  ==== Resolving dependencies
46
48
 
47
- When the Jarfile is locked, the transitive dependencies for the Jars and POM are resolved and saved to the Jarfile.lock file.
49
+ * LockJar.lock( jarfile = 'Jarfile', opts = {} ): Using a Jarfile, creates a lock file. Default jarfile lock is *Jarfile.lock*, can be changed by setting opts = { :lockfile => 'NewLockFile' }. The local repo defined in the Jarfile can be override by setting opts = { :local_repo => 'path/to/local/repo' }
50
+
51
+ When the Jarfile is locked, the transitive dependencies are resolved and saved to the Jarfile.lock file.
48
52
 
49
53
  Example of locking a Jarfile to a Jarfile.lock
50
54
 
@@ -92,6 +96,20 @@ The Jarfile.lock
92
96
 
93
97
  ==== Accessing Jars
94
98
 
99
+ * LockJar.list(*args): Lists all dependencies as notations for scopes from the Jarfile.lock. Defaults scopes are *compile* and *runtime*. Default lock file is *Jarfile.lock*.
100
+ * args of a String will set the Jarfile, e.g. 'Jarfile.different'
101
+ * args of an Array will set the scopes, e.g. ['compile','test']
102
+ * args of a Hash will set the options, e.g. { :local_repo => 'path' }
103
+ * :local_repo sets the local repo path
104
+ * :local_paths converts the notations to paths to jars in the local repo path
105
+
106
+ * LockJar.load(*args): Loads all dependencies to the classpath for scopes from the Jarfile.lock. Defaults scopes are *compile* and *runtime*. Default lock file is *Jarfile.lock*.
107
+ * args of a String will set the Jarfile, e.g. 'Jarfile.different'
108
+ * args of an Array will set the scopes, e.g. ['compile','test']
109
+ * args of a Hash will set the options, e.g. { :local_repo => 'path' }
110
+ * :local_repo sets the local repo path
111
+ * :resolve to true will make transitive dependences resolve before loading to classpath
112
+
95
113
  Once a Jarfile.lock is generated, you can list all resolved jars by
96
114
 
97
115
  jars = LockJar.list
@@ -173,6 +191,12 @@ and a task per project to generate the lockfile for a single project
173
191
 
174
192
  buildr <app>:<project>:lock_jar:lock
175
193
 
194
+ 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]
195
+
196
+ lock_jars()
197
+
198
+
199
+
176
200
  The compile scoped dependencies are automatically added to the classpath for compiling. The test scoped dependencies are
177
201
  automatically added to the classpath for tests. Do not forget, if you change the lock_jar
178
202
  definitions, you have to rerun the *lock_jar:lock* task.
@@ -186,7 +210,6 @@ Sample buildfile with LockJar
186
210
 
187
211
  # app definition, inherited into all projects
188
212
  lock_jar do
189
- repository 'http://repository.jboss.org/nexus/content/groups/public-jboss'
190
213
 
191
214
  scope 'test' do
192
215
  jar 'junit:junit:jar:4.10'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.3.0
@@ -18,13 +18,15 @@ require 'lock_jar/dsl'
18
18
 
19
19
  module Buildr
20
20
 
21
+ @@global_lockjar_dsl = nil
22
+
21
23
  class << self
22
24
  def project_to_lockfile( project )
23
25
  "#{project.name.gsub(/:/,'-')}.lock"
24
26
  end
25
27
 
26
28
  def global_lockjar_dsl
27
- @@global_lockjar_dsl
29
+ @@global_lockjar_dsl
28
30
  end
29
31
  end
30
32
 
@@ -37,6 +39,10 @@ module Buildr
37
39
  task("lock") do
38
40
  projects.each do |project|
39
41
  if project.lockjar_dsl
42
+ # add buildr repos
43
+ repositories.remote.each do |repo|
44
+ project.lockjar_dsl.repository repo
45
+ end
40
46
  ::LockJar.lock( project.lockjar_dsl, :lockfile => Buildr.project_to_lockfile(project) )
41
47
  end
42
48
  end
@@ -81,11 +87,18 @@ module Buildr
81
87
  task :compile => 'lock_jar:compile'
82
88
  task 'test:compile' => 'lock_jar:test:compile'
83
89
 
90
+ task 'eclipse' => 'lock_jar:eclipse'
91
+
84
92
  namespace "lock_jar" do
85
93
  desc "Lock dependencies to JarFile"
86
94
  task("lock") do
87
95
  dsl = project.lockjar_dsl
88
96
  if dsl
97
+ # add buildr repos
98
+ repositories.remote do |repo|
99
+ puts repo
100
+ dsl.repository repo
101
+ end
89
102
  ::LockJar.lock( dsl, :lockfile => "#{project.name}.lock" )
90
103
  else
91
104
  # XXX: output that there were not dependencies to lock
@@ -110,6 +123,17 @@ module Buildr
110
123
  project.test.compile.with( jars )
111
124
  project.test.with( jars )
112
125
  end
126
+
127
+ task("eclipse") do
128
+ if project.lockjar_dsl && !File.exists?( Buildr.project_to_lockfile(project) )
129
+ raise "#{Buildr.project_to_lockfile(project)} does not exist, run #{project.name}:lockjar:lock first"
130
+ end
131
+ jars = ::LockJar.list( Buildr.project_to_lockfile(project), ['compile', 'runtime'] )
132
+ project.compile.with( jars )
133
+
134
+ jars = ::LockJar.list( Buildr.project_to_lockfile(project), ['compile', 'test', 'runtime'] )
135
+ project.test.compile.with( jars )
136
+ end
113
137
  end
114
138
  end
115
139
  end
@@ -15,7 +15,7 @@
15
15
 
16
16
  require 'rubygems'
17
17
  require 'naether'
18
- require 'tmpdir'
18
+ require 'fileutils'
19
19
 
20
20
  module LockJar
21
21
  class Resolver
@@ -25,27 +25,39 @@ module LockJar
25
25
 
26
26
  def initialize( opts = {} )
27
27
  @opts = opts
28
- local_repo = opts[:local_repo]
28
+ local_repo = opts[:local_repo] || Naether::Bootstrap.default_local_repo
29
29
 
30
30
  # Bootstrap Naether
31
31
  jars = []
32
+ temp_jar_dir = File.join(local_repo, '.lock_jar', 'naether' )
32
33
  deps = Naether::Bootstrap.check_local_repo_for_deps( local_repo )
33
34
  if deps[:missing].size > 0
34
- Dir.mktmpdir do |dir|
35
- deps = Naether::Bootstrap.download_dependencies( dir, deps.merge( :local_repo => local_repo ) )
36
- if deps[:downloaded].size > 0
37
- Naether::Bootstrap.install_dependencies_to_local_repo( dir, :local_repo => local_repo )
38
- jars = deps[:downloaded].map{ |jar| jar.values[0] }
39
- else
40
- # XXX: download failed?
35
+ deps = Naether::Bootstrap.download_dependencies( temp_jar_dir, deps.merge( :local_repo => local_repo ) )
36
+ if deps[:downloaded].size > 0
37
+
38
+ unless Dir.exists?( temp_jar_dir )
39
+ FileUtils.mkdir_p jar_dir
41
40
  end
41
+
42
+ @naether = Naether::Bootstrap.install_dependencies_to_local_repo( temp_jar_dir, :local_repo => local_repo )
43
+ jars = jars + deps[:downloaded].map{ |jar| jar.values[0] }
44
+ else
45
+ # XXX: download failed?
42
46
  end
43
- else
44
- jars = deps[:exists].map{ |jar| jar.values[0] }
47
+
48
+ # Remove bootstrap jars, they have been installed to the local repo
49
+ elsif File.exists?( temp_jar_dir )
50
+ FileUtils.rm_rf temp_jar_dir
45
51
  end
46
52
 
47
- jars << Naether::JAR_PATH
48
- @naether = Naether.create_from_jars( jars )
53
+ jars = jars + deps[:exists].map{ |jar| jar.values[0] }
54
+
55
+ # Bootstrapping naether will create an instance from downloaded jars.
56
+ # If jars exist locally already, create manually
57
+ if @naether.nil?
58
+ jars << Naether::JAR_PATH
59
+ @naether = Naether.create_from_jars( jars )
60
+ end
49
61
 
50
62
  @naether.local_repo_path = opts[:local_repo] if opts[:local_repo]
51
63
 
@@ -35,16 +35,28 @@ module LockJar
35
35
  @current_resolver
36
36
  end
37
37
 
38
- def lock( jarfile, opts = {} )
38
+ def lock( jarfile, opts = {}, &blk )
39
39
 
40
40
  lock_jar_file = nil
41
41
 
42
- if jarfile.is_a? LockJar::Dsl
43
- lock_jar_file = jarfile
44
- else
45
- lock_jar_file = LockJar::Dsl.evaluate( jarfile )
42
+ if jarfile
43
+ if jarfile.is_a? LockJar::Dsl
44
+ lock_jar_file = jarfile
45
+ else
46
+ lock_jar_file = LockJar::Dsl.evaluate( jarfile )
47
+ end
46
48
  end
47
49
 
50
+ unless blk.nil?
51
+ dsl = LockJar::Dsl.evaluate(&blk)
52
+ if lock_jar_file.nil?
53
+ lock_jar_file = dsl
54
+ else
55
+ lock_jar_file.merge( dsl )
56
+ end
57
+ end
58
+
59
+
48
60
  # If not set in opts, and is set in dsl
49
61
  if opts[:local_repo].nil? && lock_jar_file.local_repository
50
62
  opts[:local_repo] = lock_jar_file.local_repository
@@ -119,6 +131,8 @@ module LockJar
119
131
  File.open( opts[:lockfile] || "Jarfile.lock", "w") do |f|
120
132
  f.write( lock_data.to_yaml )
121
133
  end
134
+
135
+ lock_data
122
136
  end
123
137
 
124
138
  def list( jarfile_lock, scopes = ['compile', 'runtime'], opts = {}, &blk )
@@ -181,7 +195,7 @@ module LockJar
181
195
  end
182
196
  end
183
197
 
184
- dependencies = list( jarfile_lock, scopes, &blk )
198
+ dependencies = list( jarfile_lock, scopes, opts, &blk )
185
199
 
186
200
  if opts[:resolve]
187
201
  dependencies = resolver(opts).resolve( dependencies )
data/lib/lock_jar.rb CHANGED
@@ -28,8 +28,24 @@ module LockJar
28
28
  # Lock a Jarfile and generate a Jarfile.lock
29
29
  #
30
30
  # Accepts path to the jarfile and hash of options to configure LockJar
31
- def self.lock( jarfile = 'Jarfile', opts = {} )
32
- Runtime.instance.lock( jarfile, opts )
31
+ def self.lock( *args, &blk )
32
+ jarfile = nil
33
+ opts = {}
34
+
35
+ args.each do |arg|
36
+ if arg.is_a?(Hash)
37
+ opts.merge!( arg )
38
+ elsif arg.is_a?( String ) || arg.is_a?( LockJar::Dsl )
39
+ jarfile = arg
40
+ end
41
+ end
42
+
43
+ # default to Jarfile
44
+ if blk.nil? && jarfile.nil?
45
+ jarfile = 'Jarfile'
46
+ end
47
+
48
+ Runtime.instance.lock( jarfile, opts, &blk )
33
49
  end
34
50
 
35
51
  # List jars for an array of scope in a lockfile
data/lock_jar.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "lock_jar"
8
- s.version = "0.2.2"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Guymon"]
12
- s.date = "2012-05-10"
12
+ s.date = "2012-05-14"
13
13
  s.description = "Manage Jar files for Ruby. In the spirit of Bundler, a Jarfile\n is used to generate a Jarfile.lock that contains all the resolved jar dependencies for scopes runtime, compile, and test.\n The Jarfile.lock can be used to populate the classpath"
14
14
  s.email = "michael.guymon@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -45,27 +45,27 @@ Gem::Specification.new do |s|
45
45
  s.homepage = "http://github.com/mguymon/lock_jar"
46
46
  s.licenses = ["Apache"]
47
47
  s.require_paths = ["lib"]
48
- s.rubygems_version = "1.8.24"
48
+ s.rubygems_version = "1.8.15"
49
49
  s.summary = "Manage Jar files for Ruby"
50
50
 
51
51
  if s.respond_to? :specification_version then
52
52
  s.specification_version = 3
53
53
 
54
54
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
- s.add_runtime_dependency(%q<naether>, ["~> 0.7.0"])
55
+ s.add_runtime_dependency(%q<naether>, ["~> 0.8.0"])
56
56
  s.add_development_dependency(%q<rspec>, ["~> 2.9.0"])
57
- s.add_development_dependency(%q<bundler>, ["> 1.0.0"])
57
+ s.add_development_dependency(%q<bundler>, ["~> 1.1.0"])
58
58
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
59
59
  else
60
- s.add_dependency(%q<naether>, ["~> 0.7.0"])
60
+ s.add_dependency(%q<naether>, ["~> 0.8.0"])
61
61
  s.add_dependency(%q<rspec>, ["~> 2.9.0"])
62
- s.add_dependency(%q<bundler>, ["> 1.0.0"])
62
+ s.add_dependency(%q<bundler>, ["~> 1.1.0"])
63
63
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
64
64
  end
65
65
  else
66
- s.add_dependency(%q<naether>, ["~> 0.7.0"])
66
+ s.add_dependency(%q<naether>, ["~> 0.8.0"])
67
67
  s.add_dependency(%q<rspec>, ["~> 2.9.0"])
68
- s.add_dependency(%q<bundler>, ["> 1.0.0"])
68
+ s.add_dependency(%q<bundler>, ["~> 1.1.0"])
69
69
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
70
70
  end
71
71
  end
@@ -71,6 +71,8 @@ describe Bundler do
71
71
  end
72
72
 
73
73
  it "should load Jarfile.lock with Bundle.setup" do
74
+ LockJar.list( :resolve => true, :local_repo => tmp('test-repo') ) # ensure jars are already downloaded
75
+
74
76
  ruby <<-RUBY
75
77
  require 'rubygems'
76
78
  require 'bundler'
@@ -83,7 +85,7 @@ describe Bundler do
83
85
 
84
86
  puts Naether::Java.create('com.slackworks.modelcitizen.ModelFactory').getClass().toString()
85
87
  RUBY
86
- # err.should eq("") # 1.9.3 has a IConv error that outputs to std err
88
+ #err.should eq("") # 1.9.3 has a IConv error that outputs to std err
87
89
  out.should match("class com.slackworks.modelcitizen.ModelFactory")
88
90
  end
89
91
 
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper'))
2
2
 
3
3
  describe LockJar::Dsl do
4
4
  context "Instance" do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper'))
2
2
  require 'lib/lock_jar'
3
3
  require 'lib/lock_jar/maven'
4
4
  require 'naether'
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper'))
2
2
  require 'lib/lock_jar/resolver'
3
3
  require 'fileutils'
4
4
  require 'naether'
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper'))
2
2
  require 'lib/lock_jar/runtime'
3
3
 
4
4
  describe LockJar::Runtime do
@@ -3,121 +3,134 @@ require 'rubygems'
3
3
  require 'lib/lock_jar'
4
4
  require 'naether'
5
5
 
6
- describe LockJar do
7
- context "Module" do
8
- context "lock" do
9
- it "should create a lock file" do
10
- File.delete( 'tmp/Jarfile.lock' ) if File.exists?( 'tmp/Jarfile.lock' )
11
- Dir.mkdir( 'tmp' ) unless File.exists?( 'tmp' )
12
-
13
- LockJar.lock( "spec/Jarfile", :local_repo => 'tmp/test-repo', :lockfile => 'tmp/Jarfile.lock' )
14
- File.exists?( 'tmp/Jarfile.lock' ).should be_true
15
- end
16
-
17
- it "should not replace dependencies with maps" do
18
- dsl = LockJar::Dsl.evaluate do
19
- map 'junit:junit:4.10', 'tmp'
20
- jar 'junit:junit:4.10'
21
- end
22
-
23
- LockJar.lock( dsl, :local_repo => 'tmp/test-repo', :lockfile => 'tmp/Jarfile.lock' )
24
- lockfile = LockJar.read('tmp/Jarfile.lock')
25
- lockfile.should eql( {
26
- "maps"=>{"junit:junit:4.10"=>["tmp"]},
27
- "scopes"=>{
28
- "compile"=>{
29
- "dependencies"=>["junit:junit:4.10"], "resolved_dependencies"=>["junit:junit:jar:4.10", "org.hamcrest:hamcrest-core:jar:1.1"]}}} )
30
- end
31
-
32
- it "should exclude excludes from dependencies" do
33
- dsl = LockJar::Dsl.evaluate do
34
- exclude 'commons-logging', 'logkit'
35
- jar 'opensymphony:oscache:jar:2.4.1'
36
- end
37
-
38
- LockJar.lock( dsl, :local_repo => 'tmp/test-repo', :lockfile => 'tmp/Jarfile.lock' )
39
- lockfile = LockJar.read('tmp/Jarfile.lock')
40
- lockfile.should eql( {
41
- "excludes"=>["commons-logging", "logkit"],
42
- "scopes"=>{
43
- "compile"=>{
44
- "dependencies"=>["opensymphony:oscache:jar:2.4.1"],
45
- "resolved_dependencies"=>["opensymphony:oscache:jar:2.4.1", "log4j:log4j:jar:1.2.12", "avalon-framework:avalon-framework:jar:4.1.3", "javax.jms:jms:jar:1.1", "javax.servlet:servlet-api:jar:2.3"]}}} )
46
-
47
- end
6
+ describe LockJar, "#lock" do
7
+ it "should create a lock file" do
8
+ File.delete( 'tmp/Jarfile.lock' ) if File.exists?( 'tmp/Jarfile.lock' )
9
+ Dir.mkdir( 'tmp' ) unless File.exists?( 'tmp' )
10
+
11
+ LockJar.lock( "spec/Jarfile", :local_repo => 'tmp/test-repo', :lockfile => 'tmp/Jarfile.lock' )
12
+ File.exists?( 'tmp/Jarfile.lock' ).should be_true
13
+ end
14
+
15
+ it "should not replace dependencies with maps" do
16
+ dsl = LockJar::Dsl.evaluate do
17
+ map 'junit:junit:4.10', 'tmp'
18
+ jar 'junit:junit:4.10'
48
19
  end
20
+
21
+ LockJar.lock( dsl, :local_repo => 'tmp/test-repo', :lockfile => 'tmp/Jarfile.lock' )
22
+ lockfile = LockJar.read('tmp/Jarfile.lock')
23
+ lockfile.should eql( {
24
+ "maps"=>{"junit:junit:4.10"=>["tmp"]},
25
+ "scopes"=>{
26
+ "compile"=>{
27
+ "dependencies"=>["junit:junit:4.10"], "resolved_dependencies"=>["junit:junit:jar:4.10", "org.hamcrest:hamcrest-core:jar:1.1"]}}} )
28
+ end
49
29
 
50
- context "list" do
51
- it "should list jars" do
52
- LockJar.lock( "spec/Jarfile", :local_repo => 'tmp/test-repo', :lockfile => 'tmp/Jarfile.lock' )
53
-
54
- jars = LockJar.list( 'tmp/Jarfile.lock', ['compile', 'runtime', 'bad scope'], :local_repo => 'tmp/test-repo' )
55
- jars.should eql( ["org.apache.mina:mina-core:jar:2.0.4", "org.slf4j:slf4j-api:jar:1.6.1", "com.slackworks:modelcitizen:jar:0.2.2", "commons-lang:commons-lang:jar:2.6", "commons-beanutils:commons-beanutils:jar:1.8.3", "commons-logging:commons-logging:jar:1.1.1", "ch.qos.logback:logback-classic:jar:0.9.24", "ch.qos.logback:logback-core:jar:0.9.24", "com.metapossum:metapossum-scanner:jar:1.0", "commons-io:commons-io:jar:1.4", "junit:junit:jar:4.7", "org.apache.tomcat:servlet-api:jar:6.0.35"] )
56
- end
57
-
58
- it "should replace dependencies with maps" do
59
- dsl = LockJar::Dsl.evaluate do
60
- map 'junit:junit', 'tmp'
61
- jar 'junit:junit:4.10'
62
- end
63
-
64
- LockJar.lock( dsl, :local_repo => 'tmp/test-repo', :lockfile => 'tmp/ListJarfile.lock' )
65
- paths = LockJar.list( 'tmp/ListJarfile.lock', :local_repo => 'tmp/test-repo' )
66
- paths.should eql( [ "tmp", "org.hamcrest:hamcrest-core:jar:1.1"] )
67
- end
68
-
69
- it "should replace dependencies with maps and get local paths" do
70
- dsl = LockJar::Dsl.evaluate do
71
- map 'junit:junit', 'tmp'
72
- jar 'junit:junit:4.10'
73
- end
74
-
75
- LockJar.lock( dsl, :local_repo => 'tmp/test-repo', :lockfile => 'tmp/ListJarfile.lock' )
76
- paths = LockJar.list( 'tmp/ListJarfile.lock', :local_repo => 'tmp/test-repo' )
77
- paths.should eql( [ "tmp", "org.hamcrest:hamcrest-core:jar:1.1"] )
78
- end
30
+ it "should exclude excludes from dependencies" do
31
+ dsl = LockJar::Dsl.evaluate do
32
+ exclude 'commons-logging', 'logkit'
33
+ jar 'opensymphony:oscache:jar:2.4.1'
79
34
  end
80
35
 
81
- context "load" do
82
- it "by Jarfile.lock" do
83
- if Naether.platform == 'java'
84
- lambda { include_class 'org.apache.mina.core.IoUtil' }.should raise_error
85
- else
86
- lambda { Rjb::import('org.apache.mina.core.IoUtil') }.should raise_error
87
- end
88
-
89
- LockJar.lock( "spec/Jarfile", :local_repo => 'tmp/test-repo', :lockfile => 'tmp/Jarfile.lock' )
90
-
91
- jars = LockJar.load( 'tmp/Jarfile.lock', ['compile', 'runtime'], :local_repo => 'tmp/test-repo' )
92
-
93
- jars.should eql( [File.expand_path("tmp/test-repo/org/apache/mina/mina-core/2.0.4/mina-core-2.0.4.jar"), File.expand_path("tmp/test-repo/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar"), File.expand_path("tmp/test-repo/com/slackworks/modelcitizen/0.2.2/modelcitizen-0.2.2.jar"), File.expand_path("tmp/test-repo/commons-lang/commons-lang/2.6/commons-lang-2.6.jar"), File.expand_path("tmp/test-repo/commons-beanutils/commons-beanutils/1.8.3/commons-beanutils-1.8.3.jar"), File.expand_path("tmp/test-repo/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"), File.expand_path("tmp/test-repo/ch/qos/logback/logback-classic/0.9.24/logback-classic-0.9.24.jar"), File.expand_path("tmp/test-repo/ch/qos/logback/logback-core/0.9.24/logback-core-0.9.24.jar"), File.expand_path("tmp/test-repo/com/metapossum/metapossum-scanner/1.0/metapossum-scanner-1.0.jar"), File.expand_path("tmp/test-repo/commons-io/commons-io/1.4/commons-io-1.4.jar"), File.expand_path("tmp/test-repo/junit/junit/4.7/junit-4.7.jar"), File.expand_path("tmp/test-repo/org/apache/tomcat/servlet-api/6.0.35/servlet-api-6.0.35.jar")] )
36
+ LockJar.lock( dsl, :local_repo => 'tmp/test-repo', :lockfile => 'tmp/Jarfile.lock' )
37
+ File.exists?( 'tmp/Jarfile.lock' ).should be_true
38
+ lockfile = LockJar.read('tmp/Jarfile.lock')
39
+ lockfile.should eql( {
40
+ "excludes"=>["commons-logging", "logkit"],
41
+ "scopes"=>{
42
+ "compile"=>{
43
+ "dependencies"=>["opensymphony:oscache:jar:2.4.1"],
44
+ "resolved_dependencies"=>["opensymphony:oscache:jar:2.4.1", "log4j:log4j:jar:1.2.12", "avalon-framework:avalon-framework:jar:4.1.3", "javax.jms:jms:jar:1.1", "javax.servlet:servlet-api:jar:2.3"]}}} )
45
+
46
+ end
47
+
48
+
49
+ it "should lock using a block" do
50
+ LockJar.lock( :local_repo => 'tmp/test-repo', :lockfile => 'tmp/NoRepoJarfile.lock' ) do
51
+ jar "org.eclipse.jetty:jetty-servlet:8.1.3.v20120416"
52
+ end
53
+
54
+ File.exists?( 'tmp/NoRepoJarfile.lock' ).should be_true
55
+
56
+ lockfile = LockJar.read('tmp/NoRepoJarfile.lock')
57
+ lockfile.should eql( {
58
+ "scopes"=>{
59
+ "compile"=>{
60
+ "dependencies"=>["org.eclipse.jetty:jetty-servlet:8.1.3.v20120416"],
61
+ "resolved_dependencies"=>["org.eclipse.jetty:jetty-servlet:jar:8.1.3.v20120416", "org.eclipse.jetty:jetty-security:jar:8.1.3.v20120416", "org.eclipse.jetty:jetty-server:jar:8.1.3.v20120416", "org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016", "org.eclipse.jetty:jetty-continuation:jar:8.1.3.v20120416", "org.eclipse.jetty:jetty-http:jar:8.1.3.v20120416", "org.eclipse.jetty:jetty-io:jar:8.1.3.v20120416", "org.eclipse.jetty:jetty-util:jar:8.1.3.v20120416"]}}} )
62
+ end
63
+ end
64
+
65
+ describe LockJar, "#list" do
66
+ it "should list jars" do
67
+ LockJar.lock( "spec/Jarfile", :local_repo => 'tmp/test-repo', :lockfile => 'tmp/Jarfile.lock' )
94
68
 
95
- if Naether.platform == 'java'
96
- lambda { include_class 'org.apache.mina.core.IoUtil' }.should_not raise_error
97
- else
98
- lambda { Rjb::import('org.apache.mina.core.IoUtil') }.should_not raise_error
99
- end
100
- end
101
-
102
- it "by block with resolve option" do
103
- if Naether.platform == 'java'
104
- lambda { include_class 'org.modeshape.common.math.Duration' }.should raise_error
105
- else
106
- lambda { Rjb::import('org.modeshape.common.math.Duration') }.should raise_error
107
- end
108
-
109
- jars = LockJar.load( :resolve => true ) do
110
- jar 'org.modeshape:modeshape-common:2.3.0.Final'
111
- end
112
-
113
- jars.should eql( ["/home/zinger/.m2/repository/org/modeshape/modeshape-common/2.3.0.Final/modeshape-common-2.3.0.Final.jar", "/home/zinger/.m2/repository/org/slf4j/slf4j-api/1.5.11/slf4j-api-1.5.11.jar", "/home/zinger/.m2/repository/net/jcip/jcip-annotations/1.0/jcip-annotations-1.0.jar"] )
69
+ jars = LockJar.list( 'tmp/Jarfile.lock', ['compile', 'runtime', 'bad scope'], :local_repo => 'tmp/test-repo' )
70
+ jars.should eql( ["org.apache.mina:mina-core:jar:2.0.4", "org.slf4j:slf4j-api:jar:1.6.1", "com.slackworks:modelcitizen:jar:0.2.2", "commons-lang:commons-lang:jar:2.6", "commons-beanutils:commons-beanutils:jar:1.8.3", "commons-logging:commons-logging:jar:1.1.1", "ch.qos.logback:logback-classic:jar:0.9.24", "ch.qos.logback:logback-core:jar:0.9.24", "com.metapossum:metapossum-scanner:jar:1.0", "commons-io:commons-io:jar:1.4", "junit:junit:jar:4.7", "org.apache.tomcat:servlet-api:jar:6.0.35"] )
71
+ end
72
+
73
+ it "should replace dependencies with maps" do
74
+ dsl = LockJar::Dsl.evaluate do
75
+ map 'junit:junit', 'tmp'
76
+ jar 'junit:junit:4.10'
77
+ end
78
+
79
+ LockJar.lock( dsl, :local_repo => 'tmp/test-repo', :lockfile => 'tmp/ListJarfile.lock' )
80
+ paths = LockJar.list( 'tmp/ListJarfile.lock', :local_repo => 'tmp/test-repo' )
81
+ paths.should eql( [ "tmp", "org.hamcrest:hamcrest-core:jar:1.1"] )
82
+ end
83
+
84
+ it "should replace dependencies with maps and get local paths" do
85
+ dsl = LockJar::Dsl.evaluate do
86
+ map 'junit:junit', 'tmp'
87
+ jar 'junit:junit:4.10'
88
+ end
89
+
90
+ LockJar.lock( dsl, :local_repo => 'tmp/test-repo', :lockfile => 'tmp/ListJarfile.lock' )
91
+ paths = LockJar.list( 'tmp/ListJarfile.lock', :local_repo => 'tmp/test-repo' )
92
+ paths.should eql( [ "tmp", "org.hamcrest:hamcrest-core:jar:1.1"] )
93
+ end
94
+ end
95
+
96
+ describe LockJar, "#load" do
97
+ it "by Jarfile.lock" do
98
+ if Naether.platform == 'java'
99
+ lambda { include_class 'org.apache.mina.core.IoUtil' }.should raise_error
100
+ else
101
+ lambda { Rjb::import('org.apache.mina.core.IoUtil') }.should raise_error
102
+ end
103
+
104
+ LockJar.lock( "spec/Jarfile", :local_repo => 'tmp/test-repo', :lockfile => 'tmp/Jarfile.lock' )
114
105
 
115
- if Naether.platform == 'java'
116
- lambda { include_class 'org.modeshape.common.math.Duration' }.should_not raise_error
117
- else
118
- lambda { Rjb::import('org.modeshape.common.math.Duration') }.should_not raise_error
119
- end
120
- end
106
+ jars = LockJar.load( 'tmp/Jarfile.lock', ['compile', 'runtime'], :local_repo => 'tmp/test-repo' )
107
+
108
+ jars.should eql( [File.expand_path("tmp/test-repo/org/apache/mina/mina-core/2.0.4/mina-core-2.0.4.jar"), File.expand_path("tmp/test-repo/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar"), File.expand_path("tmp/test-repo/com/slackworks/modelcitizen/0.2.2/modelcitizen-0.2.2.jar"), File.expand_path("tmp/test-repo/commons-lang/commons-lang/2.6/commons-lang-2.6.jar"), File.expand_path("tmp/test-repo/commons-beanutils/commons-beanutils/1.8.3/commons-beanutils-1.8.3.jar"), File.expand_path("tmp/test-repo/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"), File.expand_path("tmp/test-repo/ch/qos/logback/logback-classic/0.9.24/logback-classic-0.9.24.jar"), File.expand_path("tmp/test-repo/ch/qos/logback/logback-core/0.9.24/logback-core-0.9.24.jar"), File.expand_path("tmp/test-repo/com/metapossum/metapossum-scanner/1.0/metapossum-scanner-1.0.jar"), File.expand_path("tmp/test-repo/commons-io/commons-io/1.4/commons-io-1.4.jar"), File.expand_path("tmp/test-repo/junit/junit/4.7/junit-4.7.jar"), File.expand_path("tmp/test-repo/org/apache/tomcat/servlet-api/6.0.35/servlet-api-6.0.35.jar")] )
109
+
110
+ if Naether.platform == 'java'
111
+ lambda { include_class 'org.apache.mina.core.IoUtil' }.should_not raise_error
112
+ else
113
+ lambda { Rjb::import('org.apache.mina.core.IoUtil') }.should_not raise_error
114
+ end
115
+ end
116
+
117
+ it "by block with resolve option" do
118
+ if Naether.platform == 'java'
119
+ lambda { include_class 'org.modeshape.common.math.Duration' }.should raise_error
120
+ else
121
+ lambda { Rjb::import('org.modeshape.common.math.Duration') }.should raise_error
122
+ end
123
+
124
+ jars = LockJar.load( :resolve => true ) do
125
+ jar 'org.modeshape:modeshape-common:2.3.0.Final'
126
+ end
127
+
128
+ jars.should eql( ["/home/zinger/.m2/repository/org/modeshape/modeshape-common/2.3.0.Final/modeshape-common-2.3.0.Final.jar", "/home/zinger/.m2/repository/org/slf4j/slf4j-api/1.5.11/slf4j-api-1.5.11.jar", "/home/zinger/.m2/repository/net/jcip/jcip-annotations/1.0/jcip-annotations-1.0.jar"] )
129
+
130
+ if Naether.platform == 'java'
131
+ lambda { include_class 'org.modeshape.common.math.Duration' }.should_not raise_error
132
+ else
133
+ lambda { Rjb::import('org.modeshape.common.math.Duration') }.should_not raise_error
121
134
  end
122
135
  end
123
- end
136
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  $:.unshift File.expand_path('.')
2
- $:.unshift File.expand_path('..', __FILE__)
3
- $:.unshift File.expand_path('../lib', __FILE__)
2
+ $:.unshift File.expand_path(File.join('..', File.dirname(__FILE__)))
3
+ $:.unshift File.expand_path(File.join('../lib', File.dirname(__FILE__)))
4
4
 
5
5
  require 'rubygems'
6
6
  require 'rspec'
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.2.2
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,27 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-10 00:00:00.000000000 Z
12
+ date: 2012-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: naether
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &6015220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.7.0
21
+ version: 0.8.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: 0.7.0
24
+ version_requirements: *6015220
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: rspec
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &6011880 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ~>
@@ -37,31 +32,21 @@ dependencies:
37
32
  version: 2.9.0
38
33
  type: :development
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: 2.9.0
35
+ version_requirements: *6011880
46
36
  - !ruby/object:Gem::Dependency
47
37
  name: bundler
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &6132000 !ruby/object:Gem::Requirement
49
39
  none: false
50
40
  requirements:
51
- - - ! '>'
41
+ - - ~>
52
42
  - !ruby/object:Gem::Version
53
- version: 1.0.0
43
+ version: 1.1.0
54
44
  type: :development
55
45
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>'
60
- - !ruby/object:Gem::Version
61
- version: 1.0.0
46
+ version_requirements: *6132000
62
47
  - !ruby/object:Gem::Dependency
63
48
  name: jeweler
64
- requirement: !ruby/object:Gem::Requirement
49
+ requirement: &6129360 !ruby/object:Gem::Requirement
65
50
  none: false
66
51
  requirements:
67
52
  - - ~>
@@ -69,12 +54,7 @@ dependencies:
69
54
  version: 1.6.4
70
55
  type: :development
71
56
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- version: 1.6.4
57
+ version_requirements: *6129360
78
58
  description: ! "Manage Jar files for Ruby. In the spirit of Bundler, a Jarfile\n is
79
59
  used to generate a Jarfile.lock that contains all the resolved jar dependencies
80
60
  for scopes runtime, compile, and test.\n The Jarfile.lock can be used to populate
@@ -125,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
105
  version: '0'
126
106
  segments:
127
107
  - 0
128
- hash: 1069555085123622793
108
+ hash: 122660553079972418
129
109
  required_rubygems_version: !ruby/object:Gem::Requirement
130
110
  none: false
131
111
  requirements:
@@ -134,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
114
  version: '0'
135
115
  requirements: []
136
116
  rubyforge_project:
137
- rubygems_version: 1.8.24
117
+ rubygems_version: 1.8.15
138
118
  signing_key:
139
119
  specification_version: 3
140
120
  summary: Manage Jar files for Ruby