doubleshot 0.1.0-java → 0.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/Doubleshot +21 -10
- data/README.textile +13 -5
- data/bin/doubleshot +9 -1
- data/ext/java/Aether.java +199 -0
- data/ext/java/ManualWagonProvider.java +24 -0
- data/ext/java/SimpleRepositoryListener.java +77 -0
- data/lib/doubleshot.rb +155 -9
- data/lib/doubleshot/cli.rb +2 -1
- data/lib/doubleshot/cli/options.rb +3 -1
- data/lib/doubleshot/commands/build.rb +47 -9
- data/lib/doubleshot/commands/gem.rb +30 -9
- data/lib/doubleshot/commands/init.rb +41 -10
- data/lib/doubleshot/commands/install.rb +4 -4
- data/lib/doubleshot/commands/jar.rb +60 -2
- data/lib/doubleshot/commands/pom.rb +29 -0
- data/lib/doubleshot/commands/test.rb +85 -32
- data/lib/doubleshot/compiler.rb +20 -17
- data/lib/doubleshot/compiler/classpath.rb +46 -0
- data/lib/doubleshot/configuration.rb +158 -8
- data/lib/doubleshot/dependencies/dependency.rb +16 -15
- data/lib/doubleshot/dependencies/dependency_list.rb +20 -5
- data/lib/doubleshot/dependencies/gem_dependency.rb +35 -0
- data/lib/doubleshot/dependencies/gem_dependency_list.rb +1 -1
- data/lib/doubleshot/dependencies/jar_dependency.rb +64 -1
- data/lib/doubleshot/dependencies/jar_dependency_list.rb +1 -1
- data/lib/doubleshot/jar.rb +13 -2
- data/lib/doubleshot/lockfile.rb +108 -0
- data/lib/doubleshot/pom.rb +42 -0
- data/lib/doubleshot/readonly_collection.rb +6 -2
- data/lib/doubleshot/resolver.rb +22 -0
- data/lib/doubleshot/resolver/jar_resolver.rb +36 -0
- data/lib/doubleshot/setup.rb +1 -47
- data/lib/ruby/blank.rb +3 -3
- data/lib/ruby/pathname.rb +8 -4
- data/lib/ruby/time.rb +1 -2
- data/target/doubleshot.jar +0 -0
- data/test/compiler/classpath_spec.rb +74 -0
- data/test/compiler_spec.rb +89 -10
- data/test/configuration/source_locations_spec.rb +2 -2
- data/test/configuration_spec.rb +115 -17
- data/test/dependencies/dependency_list_spec.rb +26 -4
- data/test/dependencies/dependency_spec.rb +19 -18
- data/test/dependencies/gem_dependency_list_spec.rb +0 -0
- data/test/dependencies/gem_dependency_spec.rb +54 -0
- data/test/dependencies/jar_dependency_list_spec.rb +0 -0
- data/test/dependencies/jar_dependency_spec.rb +62 -1
- data/test/dependencies_spec.rb +4 -4
- data/test/doubleshot_spec.rb +34 -2
- data/test/helper.rb +36 -1
- data/test/lockfile_spec.rb +236 -0
- data/test/pom_spec.rb +66 -0
- data/test/readonly_collection_spec.rb +10 -3
- data/test/resolver/jar_resolver_spec.rb +34 -0
- data/test/resolver_spec.rb +25 -0
- metadata +28 -28
- data/ext/java/Empty.java +0 -0
data/lib/ruby/pathname.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
class Pathname
|
2
2
|
def touch(path)
|
3
3
|
file = self + path
|
4
|
-
file.open("w+") { nil }
|
4
|
+
file.open("w+") { nil } unless file.exist?
|
5
5
|
file
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def child_of?(p2)
|
9
|
-
expand_path.to_s.include?
|
9
|
+
expand_path.to_s.include?(p2.expand_path.to_s)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
|
+
def to_url
|
13
|
+
java.io.File.new(to_s).to_url.to_s
|
14
|
+
end
|
15
|
+
end
|
data/lib/ruby/time.rb
CHANGED
Binary file
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
|
3
|
+
require_relative "../helper"
|
4
|
+
|
5
|
+
describe Doubleshot::Compiler::Classpath do
|
6
|
+
before do
|
7
|
+
@classpath = Doubleshot::Compiler::Classpath.new
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "add" do
|
11
|
+
it "must return self" do
|
12
|
+
Helper::tmp do |tmp|
|
13
|
+
@classpath.add(tmp.to_s).must_be_same_as @classpath
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "must raise an exception if the file does not exist" do
|
18
|
+
Helper::tmp do |tmp|
|
19
|
+
-> do
|
20
|
+
@classpath.add(tmp + "asdf")
|
21
|
+
end.must_raise(ArgumentError)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "must alias to <<" do
|
26
|
+
@classpath.must_respond_to :<<
|
27
|
+
Helper::tmp do |tmp|
|
28
|
+
@classpath << tmp
|
29
|
+
@classpath.wont_be_empty
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "must return Pathnames" do
|
35
|
+
Helper::tmp do |tmp|
|
36
|
+
@classpath.add tmp
|
37
|
+
|
38
|
+
@classpath.entries.wont_be_empty
|
39
|
+
@classpath.each do |path|
|
40
|
+
path.must_be_kind_of Pathname
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "must return unique paths" do
|
46
|
+
Helper::tmp do |tmp|
|
47
|
+
@classpath.add(tmp.to_s)
|
48
|
+
@classpath.add(tmp.to_s)
|
49
|
+
|
50
|
+
@classpath.size.must_equal 1
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "must return only directories" do
|
55
|
+
Helper::tmp do |tmp|
|
56
|
+
dir1 = tmp + "dir1"
|
57
|
+
dir2 = tmp + "dir2"
|
58
|
+
|
59
|
+
dir1.mkdir
|
60
|
+
dir2.mkdir
|
61
|
+
|
62
|
+
jar1 = dir1.touch "some.jar"
|
63
|
+
jar2 = dir2.touch "other.jar"
|
64
|
+
|
65
|
+
@classpath.add dir1
|
66
|
+
@classpath.add jar1
|
67
|
+
@classpath.add jar2
|
68
|
+
|
69
|
+
@classpath.size.must_equal 2
|
70
|
+
@classpath.must_include(dir1.expand_path)
|
71
|
+
@classpath.must_include(dir2.expand_path)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/test/compiler_spec.rb
CHANGED
@@ -4,13 +4,7 @@ require_relative "helper"
|
|
4
4
|
|
5
5
|
describe Doubleshot::Compiler do
|
6
6
|
|
7
|
-
|
8
|
-
compiler = Doubleshot::Compiler.new "ext/java", "target"
|
9
|
-
compiler.source.must_equal Pathname("ext/java")
|
10
|
-
compiler.target.must_equal Pathname("target")
|
11
|
-
end
|
12
|
-
|
13
|
-
it "must compile a cow" do
|
7
|
+
def compile
|
14
8
|
Helper::tmp do |tmp|
|
15
9
|
source = tmp + "java"
|
16
10
|
source.mkdir
|
@@ -32,13 +26,98 @@ describe Doubleshot::Compiler do
|
|
32
26
|
EOS
|
33
27
|
end
|
34
28
|
|
35
|
-
|
29
|
+
sleep 1 # Sleep because file mtime does not
|
30
|
+
# have enough resolution to allow us to accurately
|
31
|
+
# detect changes quickly enough in tests. It's
|
32
|
+
# very unlikely you'd ever run into this in your
|
33
|
+
# actual work.
|
34
|
+
yield Doubleshot::Compiler.new(source, target)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "must accept source and target paths" do
|
39
|
+
compiler = Doubleshot::Compiler.new "ext/java", "target"
|
40
|
+
compiler.source.must_equal Pathname("ext/java")
|
41
|
+
compiler.target.must_equal Pathname("target")
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#pending?" do
|
45
|
+
|
46
|
+
it "wont be pending after a build" do
|
47
|
+
compile do |compiler|
|
48
|
+
compiler.build!
|
49
|
+
compiler.wont_be :pending
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "must be pending if target has not been built" do
|
54
|
+
compile do |compiler|
|
55
|
+
compiler.must_be :pending
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "must be pending if existing source is modified" do
|
60
|
+
compile do |compiler|
|
61
|
+
compiler.build!
|
62
|
+
sleep 1 # Refer to comment for 'sleep 1' in #compile helper
|
63
|
+
(compiler.source + "Cow.java").open("w+") do |cow|
|
64
|
+
cow << <<-EOS.margin
|
65
|
+
package org.sam.doubleshot;
|
66
|
+
|
67
|
+
public class Cow {
|
68
|
+
public Cow() {}
|
36
69
|
|
37
|
-
|
38
|
-
|
70
|
+
public String moo() {
|
71
|
+
return "FRANCIS!";
|
72
|
+
}
|
73
|
+
}
|
74
|
+
EOS
|
75
|
+
end
|
76
|
+
|
77
|
+
compiler.must_be :pending
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it "must be pending if a new source file is added" do
|
82
|
+
compile do |compiler|
|
83
|
+
compiler.build!
|
84
|
+
sleep 1 # Refer to comment for 'sleep 1' in #compile helper
|
85
|
+
(compiler.source + "Moo.java").open("w+") do |cow|
|
86
|
+
cow << <<-EOS.margin
|
87
|
+
package org.sam.doubleshot;
|
88
|
+
|
89
|
+
public class Moo {
|
90
|
+
public Moo() {}
|
91
|
+
|
92
|
+
public String moo() {
|
93
|
+
return "COW!";
|
94
|
+
}
|
95
|
+
}
|
96
|
+
EOS
|
97
|
+
end
|
98
|
+
|
99
|
+
compiler.must_be :pending
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "must compile a cow" do
|
105
|
+
compile do |compiler|
|
106
|
+
# We pass the add_target_to_current_classpath=true option
|
107
|
+
# so that we can then load a Cow instance a few lines
|
108
|
+
# further down.
|
109
|
+
compiler.build!(true).must_be_same_as compiler
|
110
|
+
|
111
|
+
cow = compiler.target + "org/sam/doubleshot/Cow.class"
|
112
|
+
cow.must :exist
|
39
113
|
|
40
114
|
org.sam.doubleshot.Cow.new.moo.must_equal "MOO!"
|
41
115
|
end
|
42
116
|
end
|
43
117
|
|
118
|
+
it "must have a classpath" do
|
119
|
+
compiler = Doubleshot::Compiler.new "ext/java", "target"
|
120
|
+
compiler.classpath.must_be_kind_of Doubleshot::Compiler::Classpath
|
121
|
+
end
|
122
|
+
|
44
123
|
end
|
@@ -37,7 +37,7 @@ describe Doubleshot::Configuration::SourceLocations do
|
|
37
37
|
Doubleshot::Configuration::SourceLocations.send(:private, :validate_path)
|
38
38
|
end
|
39
39
|
|
40
|
-
describe "validate_path" do
|
40
|
+
describe "validate_path" do
|
41
41
|
it "must call to_s on any passed object" do
|
42
42
|
mock = MockWrapper.new
|
43
43
|
mock.expect(:to_string, "test")
|
@@ -50,7 +50,7 @@ describe Doubleshot::Configuration::SourceLocations do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it "must return a valid path" do
|
53
|
-
@source.validate_path("lib").exist
|
53
|
+
@source.validate_path("lib").must :exist
|
54
54
|
|
55
55
|
assert_raises(IOError) do
|
56
56
|
@source.validate_path "nothing"
|
data/test/configuration_spec.rb
CHANGED
@@ -8,6 +8,43 @@ describe Doubleshot::Configuration do
|
|
8
8
|
@config = Doubleshot::Configuration.new
|
9
9
|
end
|
10
10
|
|
11
|
+
describe "project" do
|
12
|
+
it "must accept a project name" do
|
13
|
+
@config.project = "doubleshot"
|
14
|
+
@config.project.must_equal "doubleshot"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "must default the gem name to the project name" do
|
18
|
+
@config.project = "doubleshot"
|
19
|
+
@config.gemspec.name.must_equal "doubleshot"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "group" do
|
24
|
+
it "must allow you to set a group (for JAR packaging)" do
|
25
|
+
@config.group = "org.sam.doubleshot"
|
26
|
+
@config.group.must_equal "org.sam.doubleshot"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "must default to the project name if none is provided" do
|
30
|
+
@config.project = "doubleshot"
|
31
|
+
@config.group.must_equal "doubleshot"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "version" do
|
36
|
+
it "must allow you to set the version" do
|
37
|
+
@config.version = "1.0"
|
38
|
+
@config.version.must_equal "1.0"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "must default the gem version to the project version" do
|
42
|
+
@config.version = "1.0"
|
43
|
+
@config.gemspec.version.to_s.must_equal "1.0"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
11
48
|
describe "gem" do
|
12
49
|
it "must accept a gem name" do
|
13
50
|
@config.gem "listen"
|
@@ -17,9 +54,42 @@ describe Doubleshot::Configuration do
|
|
17
54
|
it "must accept a list of requirements" do
|
18
55
|
@config.gem "listen", ">0.4.0"
|
19
56
|
end
|
20
|
-
|
57
|
+
|
58
|
+
it "must return a dependency" do
|
59
|
+
@config.gem("listen").must_be_kind_of Doubleshot::Dependencies::GemDependency
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "repositories" do
|
64
|
+
it "must add Maven repositories" do
|
65
|
+
@config.mvn_repository "http://repository.jboss.com/maven2/"
|
66
|
+
@config.mvn_repositories.must_include "http://repository.jboss.com/maven2/"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "must return the passed value from mvn_repository" do
|
70
|
+
example = "http://repository.jboss.com/maven2/"
|
71
|
+
@config.mvn_repository(example).must_be_same_as example
|
72
|
+
end
|
73
|
+
|
74
|
+
it "must add Rubygems repositories" do
|
75
|
+
@config.gem_repository "http://rubyforge.org"
|
76
|
+
@config.gem_repositories.must_include "http://rubyforge.org"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "must return the passed value from gem_repository" do
|
80
|
+
example = "http://rubyforge.org"
|
81
|
+
@config.gem_repository(example).must_be_same_as example
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "jar" do
|
86
|
+
it "must accept a Buildr style JAR dependency string" do
|
87
|
+
@config.jar "org.sonatype.aether:aether-api:jar:1.13.1"
|
88
|
+
@config.runtime.jars.must_include "org.sonatype.aether:aether-api:jar:1.13.1"
|
89
|
+
end
|
90
|
+
|
21
91
|
it "must return a dependency" do
|
22
|
-
@config.
|
92
|
+
@config.jar("org.sonatype.aether:aether-api:jar:1.13.1").must_be_kind_of Doubleshot::Dependencies::JarDependency
|
23
93
|
end
|
24
94
|
end
|
25
95
|
|
@@ -45,13 +115,16 @@ describe Doubleshot::Configuration do
|
|
45
115
|
spec.email = "ssmoot@gmail.com"
|
46
116
|
spec.version = "1.0"
|
47
117
|
spec.license = "MIT-LICENSE"
|
48
|
-
spec.executables = [ "doubleshot" ]
|
49
118
|
end
|
50
119
|
rescue Exception => e
|
51
120
|
fail e
|
52
121
|
end
|
53
122
|
|
54
|
-
@config.gemspec.validate
|
123
|
+
@config.gemspec.must :validate
|
124
|
+
end
|
125
|
+
|
126
|
+
it "must include executables from your bin folder" do
|
127
|
+
@config.gemspec.executables.must_equal [ "doubleshot" ]
|
55
128
|
end
|
56
129
|
|
57
130
|
it "must add dependencies to the gemspec" do
|
@@ -69,7 +142,7 @@ describe Doubleshot::Configuration do
|
|
69
142
|
end
|
70
143
|
|
71
144
|
it "must provide sane defaults for rdoc" do
|
72
|
-
@config.
|
145
|
+
@config.project = "Doubleshot"
|
73
146
|
@config.gemspec.rdoc_options.must_equal([
|
74
147
|
"--line-numbers",
|
75
148
|
"--main", "README.textile",
|
@@ -77,13 +150,13 @@ describe Doubleshot::Configuration do
|
|
77
150
|
"lib", "README.textile" ])
|
78
151
|
end
|
79
152
|
|
80
|
-
it "require_paths must
|
81
|
-
@config.gemspec.require_paths.
|
153
|
+
it "require_paths must include the ruby source location" do
|
154
|
+
@config.gemspec.require_paths.must_include "lib"
|
82
155
|
end
|
83
156
|
|
84
157
|
it "require_paths must be updated when ruby source location is modified" do
|
85
158
|
@config.source.ruby = "test"
|
86
|
-
@config.gemspec.require_paths.must_equal [ "test" ]
|
159
|
+
@config.gemspec.require_paths.must_equal [ "test", "target" ]
|
87
160
|
end
|
88
161
|
|
89
162
|
it "should include test_files if present" do
|
@@ -102,6 +175,12 @@ describe Doubleshot::Configuration do
|
|
102
175
|
end
|
103
176
|
end
|
104
177
|
|
178
|
+
describe "java_main" do
|
179
|
+
it 'must default to "org.jruby.Main"' do
|
180
|
+
@config.java_main.must_equal "org.jruby.Main"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
105
184
|
describe "paths" do
|
106
185
|
it "must return a readonly collection of paths" do
|
107
186
|
@config.paths.must_be_kind_of Doubleshot::ReadonlyCollection
|
@@ -122,6 +201,7 @@ describe Doubleshot::Configuration do
|
|
122
201
|
it "files must contain Ruby sources, Java sources, Doubleshot, LICENSE, README and any build files" do
|
123
202
|
@config.gemspec.files.sort.must_equal(
|
124
203
|
Dir[
|
204
|
+
"bin/doubleshot",
|
125
205
|
"lib/**/*.rb",
|
126
206
|
"ext/java/**/*.java",
|
127
207
|
"Doubleshot",
|
@@ -129,7 +209,10 @@ describe Doubleshot::Configuration do
|
|
129
209
|
"README*",
|
130
210
|
"target/**/*",
|
131
211
|
"test/**/*"
|
132
|
-
].select
|
212
|
+
].select do |path|
|
213
|
+
path = Pathname(path)
|
214
|
+
path.file? && path.extname != ".class"
|
215
|
+
end.sort
|
133
216
|
)
|
134
217
|
end
|
135
218
|
|
@@ -192,8 +275,9 @@ describe Doubleshot::Configuration do
|
|
192
275
|
|
193
276
|
describe "to_ruby" do
|
194
277
|
before do
|
278
|
+
@config.project = "doubleshot"
|
279
|
+
@config.version = "9000.1"
|
195
280
|
@config.gemspec do |spec|
|
196
|
-
spec.name = "doubleshot"
|
197
281
|
spec.summary = "This is my summary."
|
198
282
|
spec.description = <<-DESCRIPTION.margin
|
199
283
|
A very detailed description.
|
@@ -202,12 +286,10 @@ describe Doubleshot::Configuration do
|
|
202
286
|
spec.author = "Sam Smoot"
|
203
287
|
spec.homepage = "http://example.com/doubleshot"
|
204
288
|
spec.email = "ssmoot@gmail.com"
|
205
|
-
spec.version = "9000.1"
|
206
289
|
spec.license = "MIT-LICENSE"
|
207
|
-
spec.executables = [ "doubleshot" ]
|
208
290
|
end
|
209
291
|
end
|
210
|
-
|
292
|
+
|
211
293
|
it "must equal generated output" do
|
212
294
|
@config.must_equal eval(@config.to_ruby).config
|
213
295
|
end
|
@@ -215,6 +297,25 @@ describe Doubleshot::Configuration do
|
|
215
297
|
describe "to_ruby_body" do
|
216
298
|
before do
|
217
299
|
@output = <<-EOS.margin
|
300
|
+
#{Doubleshot::Configuration::PROJECT_MESSAGE}
|
301
|
+
config.project = "doubleshot"
|
302
|
+
|
303
|
+
#{Doubleshot::Configuration::GROUP_MESSAGE}
|
304
|
+
# config.group = "doubleshot"
|
305
|
+
|
306
|
+
#{Doubleshot::Configuration::VERSION_MESSAGE}
|
307
|
+
config.version = "9000.1"
|
308
|
+
|
309
|
+
|
310
|
+
#{Doubleshot::Configuration::GEM_REPOSITORY_MESSAGE}
|
311
|
+
# config.gem_repository "https://rubygems.org"
|
312
|
+
# config.gem_repository "http://gems.example.com"
|
313
|
+
|
314
|
+
#{Doubleshot::Configuration::MVN_REPOSITORY_MESSAGE}
|
315
|
+
# config.mvn_repository "http://repo1.maven.org/maven2"
|
316
|
+
# config.mvn_repository "http://repository.jboss.com/maven2"
|
317
|
+
|
318
|
+
|
218
319
|
#{Doubleshot::Configuration::SOURCE_RUBY_MESSAGE}
|
219
320
|
# config.source.ruby = "lib"
|
220
321
|
|
@@ -244,8 +345,6 @@ describe Doubleshot::Configuration do
|
|
244
345
|
|
245
346
|
#{Doubleshot::Configuration::GEMSPEC_MESSAGE}
|
246
347
|
config.gemspec do |spec|
|
247
|
-
spec.name = "doubleshot"
|
248
|
-
spec.version = "9000.1"
|
249
348
|
spec.summary = "This is my summary."
|
250
349
|
spec.description = <<-DESCRIPTION
|
251
350
|
A very detailed description.
|
@@ -291,5 +390,4 @@ describe Doubleshot::Configuration do
|
|
291
390
|
end
|
292
391
|
end
|
293
392
|
end
|
294
|
-
|
295
|
-
end
|
393
|
+
end
|