doubleshot 0.1.0-java → 0.2.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.
- 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/doubleshot/compiler.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require "java"
|
2
1
|
require "ant"
|
2
|
+
require "doubleshot/compiler/classpath"
|
3
3
|
|
4
4
|
class Doubleshot
|
5
5
|
class Compiler
|
@@ -7,27 +7,30 @@ class Doubleshot
|
|
7
7
|
def initialize(source, target)
|
8
8
|
@source = Pathname(source.to_s)
|
9
9
|
@target = Pathname(target.to_s)
|
10
|
+
@classpath = Classpath.new
|
10
11
|
end
|
11
12
|
|
12
|
-
attr_reader :source, :target
|
13
|
+
attr_reader :source, :target, :classpath
|
13
14
|
|
14
|
-
def
|
15
|
+
def pending?
|
16
|
+
sources = Pathname::glob(@source + "**/*.java")
|
17
|
+
targets = Pathname::glob(@target + "**/*.class")
|
18
|
+
!sources.empty? && (targets.empty? || sources.map(&:mtime).max > targets.map(&:mtime).max)
|
19
|
+
end
|
20
|
+
|
21
|
+
def build!(add_target_to_current_classpath = false)
|
15
22
|
@target.mkdir unless @target.exist?
|
16
|
-
|
23
|
+
|
17
24
|
# The JRuby ant integration throws JRuby Persistence
|
18
25
|
# warnings that you can't supress, so we run it
|
19
26
|
# inside of a Kernel#silence block.
|
20
27
|
silence do
|
21
|
-
ant.path
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
path.exist?
|
28
|
-
end.map do |path|
|
29
|
-
(path.directory? ? path : path.dirname).to_s.ensure_ends_with("/")
|
30
|
-
end.uniq.each do |path|
|
28
|
+
# Since the ant.path block is instance_evaled,
|
29
|
+
# the following line is a hack to ensure we have
|
30
|
+
# access to the contents of @classpath.
|
31
|
+
classpath = @classpath
|
32
|
+
ant.path id: "classpath" do
|
33
|
+
classpath.each do |path|
|
31
34
|
fileset dir: path
|
32
35
|
end
|
33
36
|
end
|
@@ -39,9 +42,9 @@ class Doubleshot
|
|
39
42
|
classpathref: "classpath"
|
40
43
|
end
|
41
44
|
|
42
|
-
|
43
|
-
|
45
|
+
$CLASSPATH << @target.to_url if add_target_to_current_classpath
|
46
|
+
self
|
44
47
|
end
|
45
48
|
|
46
49
|
end # class Compiler
|
47
|
-
end # class Doubleshot
|
50
|
+
end # class Doubleshot
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "set"
|
2
|
+
|
3
|
+
class Doubleshot
|
4
|
+
class Compiler
|
5
|
+
class Classpath
|
6
|
+
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@set = Set.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def add(path)
|
14
|
+
path = Pathname(path.to_s).expand_path
|
15
|
+
|
16
|
+
if path.directory?
|
17
|
+
@set << path
|
18
|
+
elsif path.file?
|
19
|
+
@set << path.dirname
|
20
|
+
else
|
21
|
+
raise ArgumentError.new("+path+ must be a file or directory with read permission: #{path}")
|
22
|
+
end
|
23
|
+
|
24
|
+
self
|
25
|
+
end
|
26
|
+
alias :<< :add
|
27
|
+
|
28
|
+
def size
|
29
|
+
@set.size
|
30
|
+
end
|
31
|
+
alias :length :size
|
32
|
+
|
33
|
+
def empty?
|
34
|
+
@set.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
def each
|
38
|
+
@set.each { |entry| yield entry }
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_s
|
42
|
+
"CLASSPATH: #{@set.entries.sort.join(", ")}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -12,12 +12,42 @@ class Doubleshot
|
|
12
12
|
.erb .haml .rxml .builder .html
|
13
13
|
]
|
14
14
|
|
15
|
+
PROJECT_MESSAGE = <<-EOS.margin
|
16
|
+
# The project name will be used as your JAR's
|
17
|
+
# artifactId and your Gem's name.
|
18
|
+
EOS
|
19
|
+
|
20
|
+
GROUP_MESSAGE = <<-EOS.margin
|
21
|
+
# The groupId of your JAR. This will default to
|
22
|
+
# the project name if not supplied.
|
23
|
+
#
|
24
|
+
# NOTE: You are strongly encouraged to set this
|
25
|
+
# to something meaningful if you are planning to
|
26
|
+
# package your project as a JAR.
|
27
|
+
EOS
|
28
|
+
|
29
|
+
VERSION_MESSAGE = <<-EOS.margin
|
30
|
+
# Version number that obeys the constraints of
|
31
|
+
# Gem::Version:
|
32
|
+
#
|
33
|
+
# If any part contains letters, then the version
|
34
|
+
# is considered pre-release.
|
35
|
+
EOS
|
36
|
+
|
37
|
+
GEM_REPOSITORY_MESSAGE = <<-EOS.margin
|
38
|
+
# TODO
|
39
|
+
EOS
|
40
|
+
|
41
|
+
MVN_REPOSITORY_MESSAGE = <<-EOS.margin
|
42
|
+
# TODO
|
43
|
+
EOS
|
44
|
+
|
15
45
|
SOURCE_RUBY_MESSAGE = <<-EOS.margin
|
16
46
|
# Relative path to the folder containing your
|
17
47
|
# Ruby source code (.rb files).
|
18
48
|
# The default is "lib".
|
19
49
|
EOS
|
20
|
-
|
50
|
+
|
21
51
|
SOURCE_JAVA_MESSAGE = <<-EOS.margin
|
22
52
|
# Relative path to the folder containing your
|
23
53
|
# Java source code (.java files).
|
@@ -40,6 +70,11 @@ class Doubleshot
|
|
40
70
|
# The default is "target".
|
41
71
|
EOS
|
42
72
|
|
73
|
+
JAVA_MAIN_MESSAGE = <<-EOS.margin
|
74
|
+
# Class to use for Ant's Main-Class attribute for
|
75
|
+
# a manifest. The default is "org.jruby.Main".
|
76
|
+
EOS
|
77
|
+
|
43
78
|
WHITELIST_MESSAGE = <<-EOS.margin
|
44
79
|
# List of file extensions within source folders
|
45
80
|
# that will be included during packaging.
|
@@ -85,12 +120,15 @@ class Doubleshot
|
|
85
120
|
# file as it's added during the build process for you.
|
86
121
|
EOS
|
87
122
|
|
123
|
+
attr_accessor :java_main
|
124
|
+
|
88
125
|
def initialize
|
89
126
|
@defaults = {}
|
90
127
|
@gemspec = Gem::Specification.new
|
91
128
|
@gemspec.platform = Gem::Platform.new("java")
|
92
129
|
@source = SourceLocations.new
|
93
130
|
@target = default :target, Pathname("target")
|
131
|
+
@java_main = default :java_main, "org.jruby.Main"
|
94
132
|
|
95
133
|
@runtime_dependencies = Dependencies.new
|
96
134
|
@development_dependencies = Dependencies.new
|
@@ -98,6 +136,59 @@ class Doubleshot
|
|
98
136
|
|
99
137
|
@paths = default :paths, DEFAULT_PATHS.dup
|
100
138
|
@whitelist = default :whitelist, DEFAULT_WHITELIST.dup
|
139
|
+
|
140
|
+
@project = default :project, "hello_world"
|
141
|
+
@group = default :group, "org.world.hello"
|
142
|
+
@version = default :version, "0.1"
|
143
|
+
|
144
|
+
@gem_repositories = default :gem_repositories, Set.new
|
145
|
+
@mvn_repositories = default :mvn_repositories, Set.new
|
146
|
+
end
|
147
|
+
|
148
|
+
def group
|
149
|
+
@group || @project
|
150
|
+
end
|
151
|
+
|
152
|
+
def group=(name)
|
153
|
+
@group = name
|
154
|
+
end
|
155
|
+
|
156
|
+
def project
|
157
|
+
@project
|
158
|
+
end
|
159
|
+
|
160
|
+
def project=(name)
|
161
|
+
@gemspec.name = name
|
162
|
+
@project = name
|
163
|
+
@group = default :group, @project unless __changes__.include? :group
|
164
|
+
@project
|
165
|
+
end
|
166
|
+
|
167
|
+
def version
|
168
|
+
@version
|
169
|
+
end
|
170
|
+
|
171
|
+
def version=(version)
|
172
|
+
@gemspec.version = version
|
173
|
+
@version = version
|
174
|
+
end
|
175
|
+
|
176
|
+
def gem_repository(uri)
|
177
|
+
@gem_repositories << uri
|
178
|
+
uri
|
179
|
+
end
|
180
|
+
|
181
|
+
def gem_repositories
|
182
|
+
ReadonlyCollection.new(@gem_repositories)
|
183
|
+
end
|
184
|
+
|
185
|
+
def mvn_repository(uri)
|
186
|
+
@mvn_repositories << uri
|
187
|
+
uri
|
188
|
+
end
|
189
|
+
|
190
|
+
def mvn_repositories
|
191
|
+
ReadonlyCollection.new(@mvn_repositories)
|
101
192
|
end
|
102
193
|
|
103
194
|
def source
|
@@ -117,6 +208,14 @@ class Doubleshot
|
|
117
208
|
self
|
118
209
|
end
|
119
210
|
|
211
|
+
def classpath
|
212
|
+
@classpath
|
213
|
+
end
|
214
|
+
|
215
|
+
def classpath=(value)
|
216
|
+
@classpath = value
|
217
|
+
end
|
218
|
+
|
120
219
|
def development
|
121
220
|
if block_given?
|
122
221
|
@development_environment = true
|
@@ -133,7 +232,7 @@ class Doubleshot
|
|
133
232
|
|
134
233
|
dependency = dependencies.gems.fetch(name)
|
135
234
|
dependencies.gems.add(dependency)
|
136
|
-
|
235
|
+
|
137
236
|
requirements.each do |requirement|
|
138
237
|
dependency.add_requirement(requirement)
|
139
238
|
end
|
@@ -141,6 +240,17 @@ class Doubleshot
|
|
141
240
|
dependency
|
142
241
|
end
|
143
242
|
|
243
|
+
def jar(coordinate)
|
244
|
+
dependencies = @development_environment ?
|
245
|
+
@development_dependencies :
|
246
|
+
@runtime_dependencies
|
247
|
+
|
248
|
+
dependency = dependencies.jars.fetch(coordinate)
|
249
|
+
dependencies.jars.add(dependency)
|
250
|
+
|
251
|
+
dependency
|
252
|
+
end
|
253
|
+
|
144
254
|
def runtime
|
145
255
|
@runtime_dependencies
|
146
256
|
end
|
@@ -170,11 +280,11 @@ class Doubleshot
|
|
170
280
|
yield @gemspec
|
171
281
|
else
|
172
282
|
@gemspec.rdoc_options = rdoc_options
|
173
|
-
@gemspec.require_paths = [ @source.ruby.to_s ]
|
283
|
+
@gemspec.require_paths = [ @source.ruby.to_s, @target.to_s ]
|
174
284
|
|
175
285
|
test_files = []
|
176
286
|
@source.tests.find do |path|
|
177
|
-
test_files << path.to_s if path.file?
|
287
|
+
test_files << path.to_s if path.file? && @whitelist.include?(path.extname)
|
178
288
|
end
|
179
289
|
@gemspec.test_files = test_files
|
180
290
|
|
@@ -196,7 +306,7 @@ class Doubleshot
|
|
196
306
|
|
197
307
|
if @target.exist?
|
198
308
|
@target.find do |path|
|
199
|
-
files << path.to_s if path.file?
|
309
|
+
files << path.to_s if path.file? && path.extname != ".class"
|
200
310
|
end
|
201
311
|
end
|
202
312
|
|
@@ -210,6 +320,13 @@ class Doubleshot
|
|
210
320
|
@gemspec.add_development_dependency dependency.name, *dependency.requirements
|
211
321
|
end
|
212
322
|
|
323
|
+
bin = Pathname("bin").expand_path
|
324
|
+
if bin.directory?
|
325
|
+
bin.find do |path|
|
326
|
+
@gemspec.executables << path.relative_path_from(bin).to_s if path.file? && path.executable?
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
213
330
|
@gemspec.add_development_dependency "doubleshot"
|
214
331
|
|
215
332
|
@gemspec
|
@@ -218,7 +335,7 @@ class Doubleshot
|
|
218
335
|
|
219
336
|
def to_ruby
|
220
337
|
<<-EOS.margin
|
221
|
-
# encoding:
|
338
|
+
# encoding: utf-8
|
222
339
|
|
223
340
|
Doubleshot.new do |config|
|
224
341
|
#{
|
@@ -248,6 +365,41 @@ class Doubleshot
|
|
248
365
|
source_changes = @source.__changes__
|
249
366
|
|
250
367
|
<<-EOS.margin
|
368
|
+
#{Doubleshot::Configuration::PROJECT_MESSAGE}
|
369
|
+
#{"# " unless config_changes.include? :project}config.project = #{@project.inspect}
|
370
|
+
|
371
|
+
#{Doubleshot::Configuration::GROUP_MESSAGE}
|
372
|
+
#{"# " unless config_changes.include? :group}config.group = #{@group.inspect}
|
373
|
+
|
374
|
+
#{Doubleshot::Configuration::VERSION_MESSAGE}
|
375
|
+
#{"# " unless config_changes.include? :version}config.version = #{@version.to_s.inspect}
|
376
|
+
|
377
|
+
|
378
|
+
#{Doubleshot::Configuration::GEM_REPOSITORY_MESSAGE}
|
379
|
+
#{
|
380
|
+
if config_changes.include? :gem_repositories
|
381
|
+
(@gem_repositories).map do |repository|
|
382
|
+
"config.gem_repository #{repository.inspect}"
|
383
|
+
end.join("\n ")
|
384
|
+
else
|
385
|
+
"# config.gem_repository \"https://rubygems.org\"\n" +
|
386
|
+
"# config.gem_repository \"http://gems.example.com\""
|
387
|
+
end
|
388
|
+
}
|
389
|
+
|
390
|
+
#{Doubleshot::Configuration::MVN_REPOSITORY_MESSAGE}
|
391
|
+
#{
|
392
|
+
if config_changes.include? :mvn_repositories
|
393
|
+
(@mvn_repositories).map do |repository|
|
394
|
+
"config.mvn_repository #{repository.inspect}"
|
395
|
+
end.join("\n ")
|
396
|
+
else
|
397
|
+
"# config.mvn_repository \"http://repo1.maven.org/maven2\"\n" +
|
398
|
+
"# config.mvn_repository \"http://repository.jboss.com/maven2\""
|
399
|
+
end
|
400
|
+
}
|
401
|
+
|
402
|
+
|
251
403
|
#{Doubleshot::Configuration::SOURCE_RUBY_MESSAGE}
|
252
404
|
#{"# " unless source_changes.include? :ruby}config.source.ruby = #{@source.ruby.to_s.inspect}
|
253
405
|
|
@@ -321,8 +473,6 @@ class Doubleshot
|
|
321
473
|
|
322
474
|
#{Doubleshot::Configuration::GEMSPEC_MESSAGE}
|
323
475
|
config.gemspec do |spec|
|
324
|
-
spec.name = #{spec.name.inspect}
|
325
|
-
spec.version = #{spec.version.to_s.inspect}
|
326
476
|
spec.summary = #{spec.summary.inspect}
|
327
477
|
spec.description = <<-DESCRIPTION
|
328
478
|
#{spec.description.strip}
|
@@ -5,21 +5,10 @@ class Doubleshot
|
|
5
5
|
|
6
6
|
def initialize(name)
|
7
7
|
@name = name.dup.freeze
|
8
|
-
@requirements = Set.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def requirements
|
12
|
-
ReadonlyCollection.new(@requirements)
|
13
|
-
end
|
14
|
-
|
15
|
-
def add_requirement(requirement)
|
16
|
-
requirement = Gem::Requirement.new(requirement)
|
17
|
-
@requirements << requirement
|
18
|
-
requirement
|
19
8
|
end
|
20
9
|
|
21
10
|
def eql?(other)
|
22
|
-
other.is_a?(
|
11
|
+
other.is_a?(self.class) and other.name == @name
|
23
12
|
end
|
24
13
|
|
25
14
|
def hash
|
@@ -27,11 +16,23 @@ class Doubleshot
|
|
27
16
|
end
|
28
17
|
|
29
18
|
def ==(other)
|
30
|
-
eql?(other)
|
19
|
+
eql?(other)
|
20
|
+
end
|
21
|
+
|
22
|
+
def lock(version)
|
23
|
+
@version = version
|
24
|
+
end
|
25
|
+
|
26
|
+
def locked?
|
27
|
+
!!@version
|
31
28
|
end
|
32
29
|
|
33
|
-
def to_s
|
34
|
-
@
|
30
|
+
def to_s(long_form = false)
|
31
|
+
if long_form && @version
|
32
|
+
"#{name} (#{@version})"
|
33
|
+
else
|
34
|
+
@name
|
35
|
+
end
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
@@ -1,8 +1,12 @@
|
|
1
|
+
require "doubleshot/dependencies/dependency"
|
2
|
+
|
1
3
|
class Doubleshot
|
2
4
|
class Dependencies
|
3
5
|
class DependencyList
|
4
6
|
include Enumerable
|
5
7
|
|
8
|
+
DEPENDENCY_CLASS = Dependency
|
9
|
+
|
6
10
|
def initialize
|
7
11
|
@dependencies = Set.new
|
8
12
|
end
|
@@ -12,6 +16,17 @@ class Doubleshot
|
|
12
16
|
end
|
13
17
|
alias :== :eql?
|
14
18
|
|
19
|
+
def +(other)
|
20
|
+
if other.class == self.class
|
21
|
+
list = self.class.new
|
22
|
+
(entries + other.entries).each { |item| list.add item }
|
23
|
+
list
|
24
|
+
else
|
25
|
+
raise ArgumentError.new("Only DependencyLists of the same type may be concatenated." +
|
26
|
+
"Expected +other+ to be a #{self.class.inspect} but was a #{other.class.inspect}.")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
15
30
|
def add(dependency)
|
16
31
|
unless dependency.is_a? Dependency
|
17
32
|
raise ArgumentError.new("+dependency+ must be a Doubleshot::Dependencies::Dependency")
|
@@ -22,24 +37,24 @@ class Doubleshot
|
|
22
37
|
|
23
38
|
def fetch(name)
|
24
39
|
raise ArgumentError.new("+name+ must be a String") unless name.is_a? String
|
25
|
-
|
40
|
+
|
26
41
|
unless dependency = @dependencies.detect { |entry| entry.name == name }
|
27
|
-
dependency =
|
42
|
+
dependency = self.class::DEPENDENCY_CLASS.new(name)
|
28
43
|
add dependency
|
29
44
|
end
|
30
|
-
|
45
|
+
|
31
46
|
dependency
|
32
47
|
end
|
33
48
|
|
34
49
|
def size
|
35
50
|
@dependencies.size
|
36
51
|
end
|
37
|
-
alias :length :size
|
52
|
+
alias :length :size
|
38
53
|
|
39
54
|
def empty?
|
40
55
|
@dependencies.empty?
|
41
56
|
end
|
42
|
-
|
57
|
+
|
43
58
|
def each
|
44
59
|
@dependencies.each do |dependency|
|
45
60
|
yield dependency
|