lock_jar 0.10.0 → 0.10.2

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 (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,3 +1,3 @@
1
- module LockJar
2
- VERSION = '0.10.0'
3
- end
1
+ module LockJar
2
+ VERSION = '0.10.2'
3
+ end
data/lib/lock_jar.rb CHANGED
@@ -1,177 +1,172 @@
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 "yaml"
17
- require 'rubygems'
18
- require 'lock_jar/resolver'
19
- require 'lock_jar/runtime'
20
- require 'lock_jar/version'
21
- require 'lock_jar/domain/lockfile'
22
- require 'lock_jar/domain/dsl'
23
-
24
- #
25
- # LockJar manages Java Jars for Ruby.
26
- #
27
- # @author Michael Guymon
28
- #
29
- module LockJar
30
-
31
- #
32
- # Override LockJar configuration
33
- #
34
- def self.config( opts )
35
- Runtime.instance.resolver( opts )
36
- end
37
-
38
- def self.install( *args, &blk )
39
- lockfile = nil
40
- opts = {}
41
- groups = ['default']
42
-
43
- args.each do |arg|
44
- if arg.is_a?(Hash)
45
- opts.merge!( arg )
46
- elsif arg.is_a?( String )
47
- lockfile = arg
48
- elsif arg.is_a?( Array )
49
- groups = arg
50
- end
51
- end
52
-
53
- # default to Jarfile.lock
54
- if blk.nil? && lockfile.nil?
55
- lockfile = 'Jarfile.lock'
56
- end
57
-
58
- Runtime.instance.install( lockfile, groups, opts, &blk )
59
- end
60
-
61
-
62
- # Lists all dependencies as notations for groups from the Jarfile.lock. Depending on the type of arg, a different configuration is set.
63
- #
64
- # * An arg of a String will set the Jarfile.lock, e.g. 'Better.lock'. Default lock file is *Jarfile.lock*.
65
- # * An arg of an Array will set the groups, e.g. ['development','test']. Defaults group is *default*
66
- # * An arg of a Hash will set the options, e.g. { :local_repo => 'path' }
67
- # * :local_repo [String] sets the local repo path
68
- # * :local_paths [Boolean] to true converts the notations to paths to jars in the local repo path
69
- # * :resolve [Boolean] to true will make transitive dependences resolve before loading to classpath
70
- #
71
- # A block can be passed in, overriding values from a Jarfile.lock.
72
- #
73
- # @return [Array] of jar and mapped path
74
- def self.list( *args, &blk )
75
- lockfile = nil
76
- opts = {}
77
- groups = ['default']
78
-
79
- args.each do |arg|
80
- if arg.is_a?(Hash)
81
- opts.merge!( arg )
82
- elsif arg.is_a?( String )
83
- lockfile = arg
84
- elsif arg.is_a?( Array )
85
- groups = arg
86
- elsif arg.is_a?( LockJar::Domain::Lockfile )
87
- lockfile = arg
88
- end
89
- end
90
-
91
- # default to Jarfile.lock
92
- if blk.nil? && lockfile.nil?
93
- lockfile = 'Jarfile.lock'
94
- end
95
-
96
- Runtime.instance.list( lockfile, groups, opts, &blk )
97
- end
98
-
99
- # LockJar.load(*args): Loads all dependencies to the classpath for groups from the Jarfile.lock. Depending on the type of arg, a different configuration is set.
100
- # * An arg of a String will set the Jarfile.lock, e.g. 'Better.lock'. Default lock file is *Jarfile.lock*.
101
- # * An arg of an Array will set the groups, e.g. ['development','test'].Defaults group is *default*.
102
- # * An arg of a Hash will set the options, e.g. { :local_repo => 'path' }
103
- # * :local_repo sets the local repo path
104
- # * :resolve to true will make transitive dependences resolve before loading to classpath
105
- #
106
- # A block can be passed in, overriding values from a Jarfile.lock.
107
- #
108
- # @return [Array] of absolute paths of jars and mapped paths loaded into claspath
109
- def self.load( *args, &blk )
110
- lockfile = nil
111
- opts = {}
112
- groups = ['default']
113
-
114
- args.each do |arg|
115
- if arg.is_a?(Hash)
116
- opts.merge!( arg )
117
- elsif arg.is_a?( String )
118
- lockfile = arg
119
- elsif arg.is_a?( Array )
120
- groups = arg
121
- elsif arg.is_a?( LockJar::Domain::Lockfile )
122
- lockfile = arg
123
- end
124
- end
125
-
126
- # default to Jarfile.lock
127
- if blk.nil? && lockfile.nil?
128
- lockfile = 'Jarfile.lock'
129
- end
130
-
131
- Runtime.instance.load( lockfile, groups, opts, &blk )
132
- end
133
-
134
- # Lock a Jarfile and generate a Jarfile.lock.
135
- #
136
- # LockJar.lock accepts an Array for parameters. Depending on the type of arg, a different configuration is set.
137
- #
138
- # * An arg of a String will set the Jarfile, e.g. 'Jarfile.different'. Default Jarfile is *Jarfile*.
139
- # * An arg of a Hash will set the options, e.g. { :local_repo => 'path' }
140
- # * :download_artifacts if true, will download jars to local repo. Defaults to true.
141
- # * :local_repo sets the local repo path
142
- # * :lockfile sets the Jarfile.lock path. Default lockfile is *Jarfile.lock*.
143
- #
144
- # A block can be passed in, overriding values from a Jarfile.
145
- #
146
- # @return [Hash] Lock data
147
- def self.lock( *args, &blk )
148
- jarfile = nil
149
- opts = {}
150
-
151
- args.each do |arg|
152
- if arg.is_a?(Hash)
153
- opts.merge!( arg )
154
- elsif arg.is_a?( String ) || arg.is_a?( LockJar::Domain::Dsl )
155
- jarfile = arg
156
- end
157
- end
158
-
159
- # default to Jarfile
160
- if blk.nil? && jarfile.nil?
161
- jarfile = 'Jarfile'
162
- end
163
-
164
- Runtime.instance.lock( jarfile, opts, &blk )
165
- end
166
-
167
- #
168
- # Read a Jafile.lock and convert it to a LockJar::Domain::Lockfile
169
- #
170
- # @param [String] lockfile path to lockfile
171
- # @return [Hash] Lock Data
172
- def self.read( lockfile )
173
- LockJar::Domain::Lockfile.read( lockfile )
174
- end
175
-
176
- end
177
-
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 "yaml"
17
+ require 'rubygems'
18
+ require 'lock_jar/resolver'
19
+ require 'lock_jar/runtime'
20
+ require 'lock_jar/version'
21
+ require 'lock_jar/domain/lockfile'
22
+ require 'lock_jar/domain/dsl'
23
+
24
+ #
25
+ # LockJar manages Java Jars for Ruby.
26
+ #
27
+ # @author Michael Guymon
28
+ #
29
+ module LockJar
30
+
31
+ #
32
+ # Override LockJar configuration
33
+ #
34
+ def self.config( opts )
35
+ Runtime.instance.resolver( opts )
36
+ end
37
+
38
+ def self.install( *args, &blk )
39
+ lockfile, groups, opts = extract_args :lockfile, args, &blk
40
+ Runtime.instance.install( lockfile, groups, opts, &blk )
41
+ end
42
+
43
+
44
+ # Lists all dependencies as notations for groups from the Jarfile.lock. Depending on the type of arg, a different configuration is set.
45
+ #
46
+ # * An arg of a String will set the Jarfile.lock, e.g. 'Better.lock'. Default lock file is *Jarfile.lock*.
47
+ # * An arg of an Array will set the groups, e.g. ['development','test']. Defaults group is *default*
48
+ # * An arg of a Hash will set the options, e.g. { :local_repo => 'path' }
49
+ # * :local_repo [String] sets the local repo path
50
+ # * :local_paths [Boolean] to true converts the notations to paths to jars in the local repo path
51
+ # * :resolve [Boolean] to true will make transitive dependences resolve before loading to classpath
52
+ #
53
+ # A block can be passed in, overriding values from a Jarfile.lock.
54
+ #
55
+ # @return [Array] of jar and mapped path
56
+ def self.list( *args, &blk )
57
+ lockfile, groups, opts = extract_args :lockfile, args, &blk
58
+ Runtime.instance.list( lockfile, groups, opts, &blk )
59
+ end
60
+
61
+ # LockJar.load(*args): Loads all dependencies to the classpath for groups from the Jarfile.lock. Depending on the type of arg, a different configuration is set.
62
+ # * An arg of a String will set the Jarfile.lock, e.g. 'Better.lock'. Default lock file is *Jarfile.lock*.
63
+ # * An arg of an Array will set the groups, e.g. ['development','test'].Defaults group is *default*.
64
+ # * An arg of a Hash will set the options, e.g. { :local_repo => 'path' }
65
+ # * :local_repo sets the local repo path
66
+ # * :resolve to true will make transitive dependences resolve before loading to classpath
67
+ #
68
+ # A block can be passed in, overriding values from a Jarfile.lock.
69
+ #
70
+ # @return [Array] of absolute paths of jars and mapped paths loaded into claspath
71
+ def self.load( *args, &blk )
72
+ lockfile, groups, opts = extract_args :lockfile, args, &blk
73
+ Runtime.instance.load( lockfile, groups, opts, &blk )
74
+ end
75
+
76
+ # Lock a Jarfile and generate a Jarfile.lock.
77
+ #
78
+ # LockJar.lock accepts an Array for parameters. Depending on the type of arg, a different configuration is set.
79
+ #
80
+ # * An arg of a String will set the Jarfile, e.g. 'Jarfile.different'. Default Jarfile is *Jarfile*.
81
+ # * An arg of a Hash will set the options, e.g. { :local_repo => 'path' }
82
+ # * :download_artifacts if true, will download jars to local repo. Defaults to true.
83
+ # * :local_repo sets the local repo path
84
+ # * :lockfile sets the Jarfile.lock path. Default lockfile is *Jarfile.lock*.
85
+ #
86
+ # A block can be passed in, overriding values from a Jarfile.
87
+ #
88
+ # @return [Hash] Lock data
89
+ def self.lock( *args, &blk )
90
+ jarfile, groups, opts = extract_args :jarfile, args, &blk
91
+ Runtime.instance.lock( jarfile, opts, &blk )
92
+ end
93
+
94
+ #
95
+ # Read a Jafile.lock and convert it to a LockJar::Domain::Lockfile
96
+ #
97
+ # @param [String] lockfile path to lockfile
98
+ # @return [Hash] Lock Data
99
+ def self.read( lockfile )
100
+ LockJar::Domain::Lockfile.read( lockfile )
101
+ end
102
+
103
+ # Add a Jarfile to be included when LockJar.lock_registered_jarfiles is called.
104
+ #
105
+ # @param [String] jarfile path to register
106
+ # @return [Array] All registered jarfiles
107
+ def self.register_jarfile( jarfile )
108
+ fail "Jarfile not found: #{ jarfile }" unless File.exists? jarfile
109
+ registered_jarfiles << jarfile
110
+ end
111
+
112
+ def self.reset_registered_jarfiles
113
+ @@registered_jarfiles = []
114
+ end
115
+
116
+ def self.registered_jarfiles
117
+ @@registered_jarfiles ||= []
118
+ end
119
+
120
+ # Lock the registered Jarfiles and generate a Jarfile.lock.
121
+ #
122
+ # Options and groups are passed through to the LockJar.lock method, but
123
+ # if a Jarfile is specified, it will be ignored. Use LockJar.register_jarfile
124
+ # to add dependencies.
125
+ #
126
+ # A block can be passed in, overriding values from the Jarfiles.
127
+ #
128
+ # @return [Hash] Lock data
129
+ def self.lock_registered_jarfiles( *args, &blk )
130
+ jarfiles = registered_jarfiles
131
+ return if jarfiles.empty?
132
+ instances = jarfiles.map do |jarfile|
133
+ LockJar::Domain::JarfileDsl.create jarfile
134
+ end
135
+ combined = instances.reduce do |result, inst|
136
+ LockJar::Domain::DslHelper.merge result, inst
137
+ end
138
+ args = args.reject { |arg| arg.is_a? String }
139
+ lock combined, *args, &blk
140
+ end
141
+
142
+ private
143
+
144
+ def self.extract_args(type, args, &blk )
145
+ lockfile_or_path = nil
146
+ opts = {}
147
+ groups = ['default']
148
+ args.each do |arg|
149
+ case arg
150
+ when Hash
151
+ opts.merge!( arg )
152
+ when String
153
+ lockfile_or_path = arg
154
+ when LockJar::Domain::Lockfile
155
+ lockfile_or_path = arg if type == :lockfile
156
+ when LockJar::Domain::Dsl
157
+ lockfile_or_path = arg if type == :jarfile
158
+ when Array
159
+ groups = arg
160
+ end
161
+ end
162
+ if blk.nil? && lockfile_or_path.nil?
163
+ if type == :lockfile
164
+ lockfile_or_path = opts.fetch(:lockfile, 'Jarfile.lock')
165
+ elsif type == :jarfile
166
+ lockfile_or_path = 'Jarfile'
167
+ end
168
+ end
169
+ [lockfile_or_path, groups, opts]
170
+ end
171
+ end
172
+
data/lock_jar.gemspec CHANGED
@@ -1,27 +1,27 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
-
5
- require 'lock_jar/version'
6
-
7
- Gem::Specification.new do |s|
8
- s.name = 'lock_jar'
9
- s.version = LockJar::VERSION
10
- s.authors = ['Michael Guymon']
11
- s.date = '2014-03-06'
12
- s.description = 'Manage Jar files for Ruby. In the spirit of Bundler, a Jarfile is used to generate a Jarfile.lock that contains all the resolved jar dependencies for scopes runtime, compile, and test. The Jarfile.lock can be used to populate the classpath'
13
- s.email = 'michael@tobedevoured.com'
14
- s.files = `git ls-files -z`.split("\x0")
15
- s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
- s.test_files = s.files.grep(%r{^(test|spec|features)/})
17
- s.extra_rdoc_files = %w(LICENSE README.md)
18
- s.homepage = 'http://github.com/mguymon/lock_jar'
19
- s.licenses = %w(Apache)
20
- s.require_paths = %w(lib)
21
- s.summary = 'Manage Jar files for Ruby'
22
-
23
- s.add_dependency(%q<naether>, ['~> 0.13.1'])
24
- s.add_dependency(%q<thor>, ['>= 0.18.1'])
25
-
26
- end
27
-
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'lock_jar/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'lock_jar'
9
+ s.version = LockJar::VERSION
10
+ s.authors = ['Michael Guymon']
11
+ s.date = '2014-03-06'
12
+ s.description = 'Manage Jar files for Ruby. In the spirit of Bundler, a Jarfile is used to generate a Jarfile.lock that contains all the resolved jar dependencies for scopes runtime, compile, and test. The Jarfile.lock can be used to populate the classpath'
13
+ s.email = 'michael@tobedevoured.com'
14
+ s.files = `git ls-files -z`.split("\x0")
15
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
17
+ s.extra_rdoc_files = %w(LICENSE README.md)
18
+ s.homepage = 'http://github.com/mguymon/lock_jar'
19
+ s.licenses = %w(Apache)
20
+ s.require_paths = %w(lib)
21
+ s.summary = 'Manage Jar files for Ruby'
22
+
23
+ s.add_dependency(%q<naether>, ['~> 0.13.1'])
24
+ s.add_dependency(%q<thor>, ['>= 0.18.1'])
25
+
26
+ end
27
+
@@ -1,14 +1,14 @@
1
- local_repo '~/.m2/repository'
2
- repository 'http://mirrors.ibiblio.org/pub/mirrors/maven2'
3
-
4
- jar "org.apache.mina:mina-core:2.0.4"
5
- local "spec/fixtures/naether-0.13.0.jar"
6
- pom 'spec/pom.xml'
7
-
8
- group 'development' do
9
- jar 'com.typesafe:config:jar:0.5.0'
10
- end
11
-
12
- group 'test' do
13
- jar 'junit:junit:jar:4.10'
1
+ local_repo '~/.m2/repository'
2
+ repository 'http://mirrors.ibiblio.org/pub/mirrors/maven2'
3
+
4
+ jar "org.apache.mina:mina-core:2.0.4"
5
+ local "spec/fixtures/naether-0.13.0.jar"
6
+ pom 'spec/pom.xml'
7
+
8
+ group 'development' do
9
+ jar 'com.typesafe:config:jar:0.5.0'
10
+ end
11
+
12
+ group 'test' do
13
+ jar 'junit:junit:jar:4.10'
14
14
  end
@@ -0,0 +1 @@
1
+ jar "org.eclipse.jetty:jetty-servlet:8.1.3.v20120416"
@@ -1,57 +1,57 @@
1
- require 'spec_helper'
2
- require 'lock_jar/class_loader'
3
-
4
-
5
- describe LockJar::ClassLoader, "#isolate" do
6
-
7
- if Naether.platform != 'java'
8
- pending "need tests for RJB backed classloader"
9
- else
10
- it "should create a SimpleEmail" do
11
- # Generate the IsolateJarfile.lock
12
- LockJar.lock( :lockfile => "#{TEMP_DIR}/IsolateJarfile.lock" ) do
13
- jar 'org.apache.commons:commons-email:1.2'
14
- end
15
-
16
- email = LockJar::ClassLoader.new( "#{TEMP_DIR}/IsolateJarfile.lock" ).isolate do
17
- email = new_instance( 'org.apache.commons.mail.SimpleEmail' )
18
- email.setSubject( 'test subject' )
19
-
20
- email
21
- end
22
-
23
- email.getSubject().should eql 'test subject'
24
-
25
- unless $CLASSPATH.nil?
26
- $CLASSPATH.to_a.join(' ').should_not =~ /commons-email-1\.2\.jar/
27
- end
28
-
29
- expect { org.apache.commons.mail.SimpleEmail.new }.to raise_error
30
- end
31
-
32
- it "should create a JsonFactory and ObjectMapper" do
33
- # Generate the IsolateJarfile.lock
34
- LockJar.lock( :lockfile => "#{TEMP_DIR}/IsolateJarfile.lock" ) do
35
- jar 'com.fasterxml.jackson.core:jackson-core:2.0.6'
36
- jar 'com.fasterxml.jackson.core:jackson-databind:2.0.6'
37
- end
38
-
39
- json = '{ "test1": "1test1", "test2": "2test2"}'
40
-
41
- map = LockJar::ClassLoader.new( "#{TEMP_DIR}/IsolateJarfile.lock" ).isolate do
42
- factory = new_instance( 'com.fasterxml.jackson.core.JsonFactory' )
43
- mapper = new_instance( 'com.fasterxml.jackson.databind.ObjectMapper', factory)
44
- mapper.readValue(json, java.util.Map.java_class)
45
- end
46
-
47
- map.get('test1').should eql "1test1"
48
- map.get('test2').should eql "2test2"
49
-
50
- unless $CLASSPATH.nil?
51
- $CLASSPATH.to_a.join(' ').should_not =~ /jackson-databind-2\.0\.6\.jar/
52
- end
53
-
54
- expect { com.fasterxml.jackson.core.JsonFactory.new }.to raise_error
55
- end
56
- end
57
- end
1
+ require 'spec_helper'
2
+ require 'lock_jar/class_loader'
3
+
4
+
5
+ describe LockJar::ClassLoader, "#isolate" do
6
+
7
+ if Naether.platform != 'java'
8
+ pending "need tests for RJB backed classloader"
9
+ else
10
+ it "should create a SimpleEmail" do
11
+ # Generate the IsolateJarfile.lock
12
+ LockJar.lock( :lockfile => "#{TEMP_DIR}/IsolateJarfile.lock" ) do
13
+ jar 'org.apache.commons:commons-email:1.2'
14
+ end
15
+
16
+ email = LockJar::ClassLoader.new( "#{TEMP_DIR}/IsolateJarfile.lock" ).isolate do
17
+ email = new_instance( 'org.apache.commons.mail.SimpleEmail' )
18
+ email.setSubject( 'test subject' )
19
+
20
+ email
21
+ end
22
+
23
+ email.getSubject().should eql 'test subject'
24
+
25
+ unless $CLASSPATH.nil?
26
+ $CLASSPATH.to_a.join(' ').should_not =~ /commons-email-1\.2\.jar/
27
+ end
28
+
29
+ expect { org.apache.commons.mail.SimpleEmail.new }.to raise_error
30
+ end
31
+
32
+ it "should create a JsonFactory and ObjectMapper" do
33
+ # Generate the IsolateJarfile.lock
34
+ LockJar.lock( :lockfile => "#{TEMP_DIR}/IsolateJarfile.lock" ) do
35
+ jar 'com.fasterxml.jackson.core:jackson-core:2.0.6'
36
+ jar 'com.fasterxml.jackson.core:jackson-databind:2.0.6'
37
+ end
38
+
39
+ json = '{ "test1": "1test1", "test2": "2test2"}'
40
+
41
+ map = LockJar::ClassLoader.new( "#{TEMP_DIR}/IsolateJarfile.lock" ).isolate do
42
+ factory = new_instance( 'com.fasterxml.jackson.core.JsonFactory' )
43
+ mapper = new_instance( 'com.fasterxml.jackson.databind.ObjectMapper', factory)
44
+ mapper.readValue(json, java.util.Map.java_class)
45
+ end
46
+
47
+ map.get('test1').should eql "1test1"
48
+ map.get('test2').should eql "2test2"
49
+
50
+ unless $CLASSPATH.nil?
51
+ $CLASSPATH.to_a.join(' ').should_not =~ /jackson-databind-2\.0\.6\.jar/
52
+ end
53
+
54
+ expect { com.fasterxml.jackson.core.JsonFactory.new }.to raise_error
55
+ end
56
+ end
57
+ end