doubleshot 0.1.0-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 (47) hide show
  1. data/Doubleshot +33 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.textile +208 -0
  4. data/bin/doubleshot +7 -0
  5. data/ext/java/Empty.java +0 -0
  6. data/lib/doubleshot.rb +37 -0
  7. data/lib/doubleshot/cli.rb +84 -0
  8. data/lib/doubleshot/cli/options.rb +34 -0
  9. data/lib/doubleshot/commands/build.rb +34 -0
  10. data/lib/doubleshot/commands/gem.rb +39 -0
  11. data/lib/doubleshot/commands/init.rb +129 -0
  12. data/lib/doubleshot/commands/install.rb +35 -0
  13. data/lib/doubleshot/commands/jar.rb +7 -0
  14. data/lib/doubleshot/commands/test.rb +119 -0
  15. data/lib/doubleshot/compiler.rb +47 -0
  16. data/lib/doubleshot/configuration.rb +361 -0
  17. data/lib/doubleshot/configuration/source_locations.rb +59 -0
  18. data/lib/doubleshot/dependencies.rb +31 -0
  19. data/lib/doubleshot/dependencies/dependency.rb +38 -0
  20. data/lib/doubleshot/dependencies/dependency_list.rb +60 -0
  21. data/lib/doubleshot/dependencies/gem_dependency.rb +8 -0
  22. data/lib/doubleshot/dependencies/gem_dependency_list.rb +10 -0
  23. data/lib/doubleshot/dependencies/jar_dependency.rb +8 -0
  24. data/lib/doubleshot/dependencies/jar_dependency_list.rb +10 -0
  25. data/lib/doubleshot/jar.rb +51 -0
  26. data/lib/doubleshot/readonly_collection.rb +32 -0
  27. data/lib/doubleshot/setup.rb +49 -0
  28. data/lib/ruby/blank.rb +132 -0
  29. data/lib/ruby/gem/requirement.rb +5 -0
  30. data/lib/ruby/kernel.rb +8 -0
  31. data/lib/ruby/pathname.rb +11 -0
  32. data/lib/ruby/string.rb +42 -0
  33. data/lib/ruby/time.rb +8 -0
  34. data/test/compiler_spec.rb +44 -0
  35. data/test/configuration/source_locations_spec.rb +98 -0
  36. data/test/configuration_spec.rb +295 -0
  37. data/test/dependencies/dependency_list_spec.rb +73 -0
  38. data/test/dependencies/dependency_spec.rb +49 -0
  39. data/test/dependencies/gem_dependency_list_spec.rb +7 -0
  40. data/test/dependencies/gem_dependency_spec.rb +7 -0
  41. data/test/dependencies/jar_dependency_list_spec.rb +7 -0
  42. data/test/dependencies/jar_dependency_spec.rb +7 -0
  43. data/test/dependencies_spec.rb +42 -0
  44. data/test/doubleshot_spec.rb +51 -0
  45. data/test/helper.rb +18 -0
  46. data/test/readonly_collection_spec.rb +45 -0
  47. metadata +300 -0
@@ -0,0 +1,5 @@
1
+ class Gem::Requirement
2
+ def eql?(other)
3
+ self == other
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ module Kernel
2
+ def silence
3
+ $VERBOSE, old_verbosity = nil, $VERBOSE
4
+ yield
5
+ ensure
6
+ $VERBOSE = old_verbosity
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ class Pathname
2
+ def touch(path)
3
+ file = self + path
4
+ file.open("w+") { nil }
5
+ file
6
+ end
7
+
8
+ def child_of?(p2)
9
+ expand_path.to_s.include? p2.expand_path.to_s
10
+ end
11
+ end
@@ -0,0 +1,42 @@
1
+ class String
2
+
3
+ def underscore
4
+ self.gsub(/::/, '/').
5
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
6
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
7
+ tr("-", "_").
8
+ downcase
9
+ end
10
+
11
+ def camelize
12
+ self.gsub(/\/(.?)/) { "::" + $1.upcase }.
13
+ gsub(/(^|_|-)(.)/) { $2.upcase }
14
+ end
15
+
16
+ def ensure_ends_with(fragment)
17
+ end_with?(fragment) ? self.dup : self + fragment
18
+ end
19
+
20
+ def ensure_starts_with(fragment)
21
+ start_with?(fragment) ? self.dup : fragment + self
22
+ end
23
+
24
+ ##
25
+ # Remove whitespace margin.
26
+ #
27
+ # @return [String] receiver with whitespace margin removed
28
+ #
29
+ # @api public
30
+ def margin
31
+ lines = self.dup.split($/)
32
+
33
+ min_margin = 0
34
+ lines.each do |line|
35
+ if line =~ /^(\s+)/ && (min_margin == 0 || $1.size < min_margin)
36
+ min_margin = $1.size
37
+ end
38
+ end
39
+ lines.map { |line| line.sub(/^\s{#{min_margin}}/, '') }.join($/)
40
+ end
41
+
42
+ end
data/lib/ruby/time.rb ADDED
@@ -0,0 +1,8 @@
1
+ class Time
2
+
3
+ def self.measure
4
+ start = now
5
+ yield
6
+ now - start
7
+ end
8
+ end
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env jruby
2
+
3
+ require_relative "helper"
4
+
5
+ describe Doubleshot::Compiler do
6
+
7
+ it "must accept source and target paths" do
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
14
+ Helper::tmp do |tmp|
15
+ source = tmp + "java"
16
+ source.mkdir
17
+
18
+ target = tmp + "target"
19
+ target.mkdir
20
+
21
+ (source + "Cow.java").open("w+") do |cow|
22
+ cow << <<-EOS.margin
23
+ package org.sam.doubleshot;
24
+
25
+ public class Cow {
26
+ public Cow() {}
27
+
28
+ public String moo() {
29
+ return "MOO!";
30
+ }
31
+ }
32
+ EOS
33
+ end
34
+
35
+ Doubleshot::Compiler.new(source, target).build!
36
+
37
+ cow = target + "org/sam/doubleshot/Cow.class"
38
+ cow.exist?.must_equal true
39
+
40
+ org.sam.doubleshot.Cow.new.moo.must_equal "MOO!"
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env jruby
2
+
3
+ require_relative "../helper.rb"
4
+
5
+ describe Doubleshot::Configuration::SourceLocations do
6
+
7
+ # This is only necessary because you can't stub out Mock#to_s,
8
+ # So we use a wrapper to call a different method instead.
9
+ class MockWrapper
10
+ def initialize(mock = MiniTest::Mock.new)
11
+ @mock = mock
12
+ end
13
+
14
+ def mock
15
+ @mock
16
+ end
17
+
18
+ def expect(*args)
19
+ @mock.expect(*args)
20
+ end
21
+
22
+ def verify
23
+ @mock.verify
24
+ end
25
+
26
+ def to_s
27
+ @mock.to_string
28
+ end
29
+ end
30
+
31
+ before do
32
+ Doubleshot::Configuration::SourceLocations.send(:public, :validate_path)
33
+ @source = Doubleshot::Configuration::SourceLocations.new
34
+ end
35
+
36
+ after do
37
+ Doubleshot::Configuration::SourceLocations.send(:private, :validate_path)
38
+ end
39
+
40
+ describe "validate_path" do
41
+ it "must call to_s on any passed object" do
42
+ mock = MockWrapper.new
43
+ mock.expect(:to_string, "test")
44
+ @source.validate_path mock
45
+ mock.verify
46
+ end
47
+
48
+ it "must always return a Pathname" do
49
+ @source.validate_path("test").must_be_kind_of Pathname
50
+ end
51
+
52
+ it "must return a valid path" do
53
+ @source.validate_path("lib").exist?.must_equal true
54
+
55
+ assert_raises(IOError) do
56
+ @source.validate_path "nothing"
57
+ end
58
+
59
+ assert_raises(IOError) do
60
+ @source.validate_path __FILE__
61
+ end
62
+
63
+ assert_raises(IOError) do
64
+ @source.validate_path ""
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "ruby" do
70
+ it "must default to lib" do
71
+ @source.ruby.must_equal Pathname("lib")
72
+ end
73
+ end
74
+
75
+ describe "java" do
76
+ it "must default to ext/java" do
77
+ @source.java.must_equal Pathname("ext/java")
78
+ end
79
+ end
80
+
81
+ describe "tests" do
82
+ it "must default to test" do
83
+ @source.tests.must_equal Pathname("test")
84
+ end
85
+ end
86
+
87
+ describe "equality" do
88
+ before do
89
+ @other = Doubleshot::Configuration::SourceLocations.new
90
+ @other.java = "examples/jackson/ext/java"
91
+ @source.java = @other.java
92
+ end
93
+
94
+ it "must equal if all paths are the same" do
95
+ @source.must_equal @other
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,295 @@
1
+ #!/usr/bin/env jruby
2
+
3
+ require_relative "helper.rb"
4
+
5
+ describe Doubleshot::Configuration do
6
+
7
+ before do
8
+ @config = Doubleshot::Configuration.new
9
+ end
10
+
11
+ describe "gem" do
12
+ it "must accept a gem name" do
13
+ @config.gem "listen"
14
+ @config.runtime.gems.must_include "listen"
15
+ end
16
+
17
+ it "must accept a list of requirements" do
18
+ @config.gem "listen", ">0.4.0"
19
+ end
20
+
21
+ it "must return a dependency" do
22
+ @config.gem("listen").must_be_kind_of Doubleshot::Dependencies::Dependency
23
+ end
24
+ end
25
+
26
+ describe "gemspec" do
27
+ it "must be a Gem::Specification" do
28
+ @config.gemspec.must_be_kind_of Gem::Specification
29
+ end
30
+
31
+ it "must accept a block" do
32
+ @config.method(:gemspec).parameters.detect do |parameter|
33
+ parameter.first == :block
34
+ end.wont_be_nil
35
+ end
36
+
37
+ it "must allow a sample gemspec" do
38
+ begin
39
+ @config.gemspec do |spec|
40
+ spec.name = "Doubleshot"
41
+ spec.summary = "Build, Dependencies and Testing all in one!"
42
+ spec.description = "Description"
43
+ spec.author = "Sam Smoot"
44
+ spec.homepage = "https://github.com/sam/doubleshot"
45
+ spec.email = "ssmoot@gmail.com"
46
+ spec.version = "1.0"
47
+ spec.license = "MIT-LICENSE"
48
+ spec.executables = [ "doubleshot" ]
49
+ end
50
+ rescue Exception => e
51
+ fail e
52
+ end
53
+
54
+ @config.gemspec.validate.must_equal true
55
+ end
56
+
57
+ it "must add dependencies to the gemspec" do
58
+ @config.gem "listen"
59
+ @config.gemspec.runtime_dependencies.first.name.must_equal "listen"
60
+ end
61
+
62
+ it "must add requirements to dependencies" do
63
+ @config.gem "listen", "~> 0.1.0"
64
+ @config.gemspec.runtime_dependencies.first.requirements_list.must_include "~> 0.1.0"
65
+ end
66
+
67
+ it "must default the Platform to JRuby" do
68
+ @config.gemspec.platform.os.must_equal "java"
69
+ end
70
+
71
+ it "must provide sane defaults for rdoc" do
72
+ @config.gemspec.name = "Doubleshot"
73
+ @config.gemspec.rdoc_options.must_equal([
74
+ "--line-numbers",
75
+ "--main", "README.textile",
76
+ "--title", "Doubleshot Documentation",
77
+ "lib", "README.textile" ])
78
+ end
79
+
80
+ it "require_paths must default to the ruby source location" do
81
+ @config.gemspec.require_paths.must_equal [ "lib" ]
82
+ end
83
+
84
+ it "require_paths must be updated when ruby source location is modified" do
85
+ @config.source.ruby = "test"
86
+ @config.gemspec.require_paths.must_equal [ "test" ]
87
+ end
88
+
89
+ it "should include test_files if present" do
90
+ @config.gemspec.test_files.sort.must_equal Dir["test/**/*"].select { |path| Pathname(path).file? }.sort
91
+ end
92
+
93
+ describe "target" do
94
+ it "must default to target" do
95
+ @config.target.must_equal Pathname("target")
96
+ end
97
+
98
+ it "must always return a Pathname" do
99
+ @config.target = "pkg"
100
+ @config.target.must_be_kind_of Pathname
101
+ @config.target.must_equal Pathname("pkg")
102
+ end
103
+ end
104
+
105
+ describe "paths" do
106
+ it "must return a readonly collection of paths" do
107
+ @config.paths.must_be_kind_of Doubleshot::ReadonlyCollection
108
+ end
109
+
110
+ describe "add_path" do
111
+ it "must return self from add_path" do
112
+ @config.add_path(".gitignore").must_be_same_as @config
113
+ end
114
+
115
+ it "must allow you to add arbitrary paths" do
116
+ @config.add_path ".gitignore"
117
+ @config.gemspec.files.must_include(Pathname(".gitignore").to_s)
118
+ end
119
+ end
120
+ end
121
+
122
+ it "files must contain Ruby sources, Java sources, Doubleshot, LICENSE, README and any build files" do
123
+ @config.gemspec.files.sort.must_equal(
124
+ Dir[
125
+ "lib/**/*.rb",
126
+ "ext/java/**/*.java",
127
+ "Doubleshot",
128
+ "*LICENSE*",
129
+ "README*",
130
+ "target/**/*",
131
+ "test/**/*"
132
+ ].select { |path| Pathname(path).file? }.sort
133
+ )
134
+ end
135
+
136
+ describe "whitelisting" do
137
+
138
+ it "must add whitelisted files" do
139
+ Helper::tmp do |tmp|
140
+
141
+ tmp.touch "test.json"
142
+ tmp.touch "test.example"
143
+
144
+ @config.source.ruby = "tmp"
145
+ @config.gemspec.files.must_include "tmp/test.json"
146
+ @config.gemspec.files.wont_include "tmp/test.example"
147
+
148
+ @config.whitelist ".example"
149
+ @config.gemspec.files.must_include "tmp/test.json"
150
+ @config.gemspec.files.must_include "tmp/test.example"
151
+ end
152
+ end
153
+
154
+ end
155
+
156
+ describe "development" do
157
+ before do
158
+ @config.development do
159
+ @config.gem "minitest", ">= 3.0.1"
160
+ end
161
+ end
162
+
163
+ it "must add dependencies to the development list" do
164
+ @config.development.gems.must_include "minitest"
165
+ end
166
+
167
+ it "won't add dependencies to the main list" do
168
+ @config.runtime.gems.wont_include "minitest"
169
+ end
170
+
171
+ describe "gemspec" do
172
+ it "must add dependencies to the gemspec" do
173
+ @config.gemspec.development_dependencies.first.name.must_equal "minitest"
174
+ end
175
+
176
+ it "must add requirements to dependencies" do
177
+ @config.gemspec.development_dependencies.first.requirements_list.must_include ">= 3.0.1"
178
+ end
179
+ end
180
+ end
181
+ end
182
+
183
+ describe "equality" do
184
+ before do
185
+ @other = Doubleshot::Configuration.new
186
+ end
187
+
188
+ it "must equal if attributes are the same" do
189
+ @config.must_be :==, @other
190
+ end
191
+ end
192
+
193
+ describe "to_ruby" do
194
+ before do
195
+ @config.gemspec do |spec|
196
+ spec.name = "doubleshot"
197
+ spec.summary = "This is my summary."
198
+ spec.description = <<-DESCRIPTION.margin
199
+ A very detailed description.
200
+ Indeed.
201
+ DESCRIPTION
202
+ spec.author = "Sam Smoot"
203
+ spec.homepage = "http://example.com/doubleshot"
204
+ spec.email = "ssmoot@gmail.com"
205
+ spec.version = "9000.1"
206
+ spec.license = "MIT-LICENSE"
207
+ spec.executables = [ "doubleshot" ]
208
+ end
209
+ end
210
+
211
+ it "must equal generated output" do
212
+ @config.must_equal eval(@config.to_ruby).config
213
+ end
214
+
215
+ describe "to_ruby_body" do
216
+ before do
217
+ @output = <<-EOS.margin
218
+ #{Doubleshot::Configuration::SOURCE_RUBY_MESSAGE}
219
+ # config.source.ruby = "lib"
220
+
221
+ #{Doubleshot::Configuration::SOURCE_JAVA_MESSAGE}
222
+ # config.source.java = "ext/java"
223
+
224
+ #{Doubleshot::Configuration::SOURCE_TESTS_MESSAGE}
225
+ # config.source.tests = "test"
226
+
227
+
228
+ #{Doubleshot::Configuration::TARGET_MESSAGE}
229
+ # config.target = "target"
230
+
231
+
232
+ #{Doubleshot::Configuration::WHITELIST_MESSAGE}
233
+ # config.whitelist ".ext"
234
+
235
+
236
+ #{Doubleshot::Configuration::GEM_DEPENDENCY_MESSAGE}
237
+ # config.gem "bcrypt-ruby", "~> 3.0"
238
+
239
+ #{Doubleshot::Configuration::JAR_DEPENDENCY_MESSAGE}
240
+ # config.jar "ch.qos.logback:logback:jar:0.5"
241
+
242
+ #{Doubleshot::Configuration::DEVELOPMENT_MESSAGE}
243
+
244
+
245
+ #{Doubleshot::Configuration::GEMSPEC_MESSAGE}
246
+ config.gemspec do |spec|
247
+ spec.name = "doubleshot"
248
+ spec.version = "9000.1"
249
+ spec.summary = "This is my summary."
250
+ spec.description = <<-DESCRIPTION
251
+ A very detailed description.
252
+ Indeed.
253
+ DESCRIPTION
254
+ spec.homepage = "http://example.com/doubleshot"
255
+ spec.author = "Sam Smoot"
256
+ spec.email = "ssmoot@gmail.com"
257
+ spec.license = "MIT-LICENSE"
258
+ spec.executables = ["doubleshot"]
259
+ end
260
+ EOS
261
+ end
262
+
263
+ it "must match the defined format" do
264
+ @config.to_ruby_body.must_equal @output
265
+ end
266
+
267
+ describe "non-default attributes" do
268
+ it "must include ruby" do
269
+ @config.source.ruby = "lib/doubleshot"
270
+ @config.to_ruby_body.must_include <<-EOS.margin
271
+ #{Doubleshot::Configuration::SOURCE_RUBY_MESSAGE}
272
+ config.source.ruby = "lib/doubleshot"
273
+ EOS
274
+ end
275
+
276
+ it "must include java" do
277
+ @config.source.java = "ext"
278
+ @config.to_ruby_body.must_include <<-EOS.margin
279
+ #{Doubleshot::Configuration::SOURCE_JAVA_MESSAGE}
280
+ config.source.java = "ext"
281
+ EOS
282
+ end
283
+
284
+ it "must include tests" do
285
+ @config.source.tests = "test/configuration"
286
+ @config.to_ruby_body.must_include <<-EOS.margin
287
+ #{Doubleshot::Configuration::SOURCE_TESTS_MESSAGE}
288
+ config.source.tests = "test/configuration"
289
+ EOS
290
+ end
291
+ end
292
+ end
293
+ end
294
+
295
+ end