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.
Files changed (56) hide show
  1. data/Doubleshot +21 -10
  2. data/README.textile +13 -5
  3. data/bin/doubleshot +9 -1
  4. data/ext/java/Aether.java +199 -0
  5. data/ext/java/ManualWagonProvider.java +24 -0
  6. data/ext/java/SimpleRepositoryListener.java +77 -0
  7. data/lib/doubleshot.rb +155 -9
  8. data/lib/doubleshot/cli.rb +2 -1
  9. data/lib/doubleshot/cli/options.rb +3 -1
  10. data/lib/doubleshot/commands/build.rb +47 -9
  11. data/lib/doubleshot/commands/gem.rb +30 -9
  12. data/lib/doubleshot/commands/init.rb +41 -10
  13. data/lib/doubleshot/commands/install.rb +4 -4
  14. data/lib/doubleshot/commands/jar.rb +60 -2
  15. data/lib/doubleshot/commands/pom.rb +29 -0
  16. data/lib/doubleshot/commands/test.rb +85 -32
  17. data/lib/doubleshot/compiler.rb +20 -17
  18. data/lib/doubleshot/compiler/classpath.rb +46 -0
  19. data/lib/doubleshot/configuration.rb +158 -8
  20. data/lib/doubleshot/dependencies/dependency.rb +16 -15
  21. data/lib/doubleshot/dependencies/dependency_list.rb +20 -5
  22. data/lib/doubleshot/dependencies/gem_dependency.rb +35 -0
  23. data/lib/doubleshot/dependencies/gem_dependency_list.rb +1 -1
  24. data/lib/doubleshot/dependencies/jar_dependency.rb +64 -1
  25. data/lib/doubleshot/dependencies/jar_dependency_list.rb +1 -1
  26. data/lib/doubleshot/jar.rb +13 -2
  27. data/lib/doubleshot/lockfile.rb +108 -0
  28. data/lib/doubleshot/pom.rb +42 -0
  29. data/lib/doubleshot/readonly_collection.rb +6 -2
  30. data/lib/doubleshot/resolver.rb +22 -0
  31. data/lib/doubleshot/resolver/jar_resolver.rb +36 -0
  32. data/lib/doubleshot/setup.rb +1 -47
  33. data/lib/ruby/blank.rb +3 -3
  34. data/lib/ruby/pathname.rb +8 -4
  35. data/lib/ruby/time.rb +1 -2
  36. data/target/doubleshot.jar +0 -0
  37. data/test/compiler/classpath_spec.rb +74 -0
  38. data/test/compiler_spec.rb +89 -10
  39. data/test/configuration/source_locations_spec.rb +2 -2
  40. data/test/configuration_spec.rb +115 -17
  41. data/test/dependencies/dependency_list_spec.rb +26 -4
  42. data/test/dependencies/dependency_spec.rb +19 -18
  43. data/test/dependencies/gem_dependency_list_spec.rb +0 -0
  44. data/test/dependencies/gem_dependency_spec.rb +54 -0
  45. data/test/dependencies/jar_dependency_list_spec.rb +0 -0
  46. data/test/dependencies/jar_dependency_spec.rb +62 -1
  47. data/test/dependencies_spec.rb +4 -4
  48. data/test/doubleshot_spec.rb +34 -2
  49. data/test/helper.rb +36 -1
  50. data/test/lockfile_spec.rb +236 -0
  51. data/test/pom_spec.rb +66 -0
  52. data/test/readonly_collection_spec.rb +10 -3
  53. data/test/resolver/jar_resolver_spec.rb +34 -0
  54. data/test/resolver_spec.rb +25 -0
  55. metadata +28 -28
  56. data/ext/java/Empty.java +0 -0
@@ -81,4 +81,5 @@ require_relative "commands/test"
81
81
  require_relative "commands/build"
82
82
  require_relative "commands/gem"
83
83
  require_relative "commands/jar"
84
- require_relative "commands/install"
84
+ require_relative "commands/install"
85
+ require_relative "commands/pom"
@@ -13,7 +13,9 @@ class Doubleshot
13
13
  end
14
14
  end
15
15
 
16
- __forward__ :banner, :separator, :on
16
+ OptionParser.instance_methods(false).each do |method_name|
17
+ __forward__ method_name
18
+ end
17
19
 
18
20
  def initialize
19
21
  super
@@ -13,6 +13,18 @@ class Doubleshot::CLI::Commands::Build < Doubleshot::CLI
13
13
  def self.options
14
14
  Options.new do |options|
15
15
  options.banner = "Usage: doubleshot build"
16
+ options.separator ""
17
+ options.separator "Options"
18
+
19
+ options.classpath = []
20
+ options.on "--classpath CLASSPATH", "Manually set the CLASSPATH the compiler should use." do |classpath|
21
+ options.classpath = classpath.to_s.split(":")
22
+ end
23
+
24
+ options.conditional = false
25
+ options.on "--conditional", "Perform a conditional build (determine if there are pending files)." do
26
+ options.conditional = true
27
+ end
16
28
 
17
29
  options.separator ""
18
30
  options.separator "Summary: #{summary}"
@@ -20,15 +32,41 @@ class Doubleshot::CLI::Commands::Build < Doubleshot::CLI
20
32
  end
21
33
 
22
34
  def self.start(args)
23
- config = Doubleshot::current.config
35
+ options = self.options.parse!(args)
36
+ doubleshot = Doubleshot::current
37
+
38
+ if options.conditional && doubleshot.config.target.exist?
39
+ doubleshot.config.target.rmtree
40
+ end
41
+
42
+ compiler = Doubleshot::Compiler.new(doubleshot.config.source.java, doubleshot.config.target)
24
43
 
25
- # TODO:
26
- # download JAR dependencies
27
- # setup correct class-path
28
- # download Gem dependencies
29
- # compile Java
30
- # exit
44
+ if doubleshot.config.project == "doubleshot"
45
+ puts "Bootstrapping Doubleshot build with Maven..."
46
+ doubleshot.bootstrap!
47
+ else
48
+ puts "Performing Doubleshot setup to resolve dependencies..."
49
+ doubleshot.setup!
50
+ end
51
+
52
+ if options.classpath.empty?
53
+ doubleshot.classpath
54
+ else
55
+ options.classpath
56
+ end.each do |path|
57
+ compiler.classpath << path
58
+ end
59
+
60
+ puts "[INFO] Using #{compiler.classpath}"
61
+ puts
62
+
63
+ if compiler.pending? || !options.conditional
64
+ puts "Compiling..."
65
+ compiler.build!
66
+ else
67
+ puts "Conditional build: No source changes."
68
+ end
31
69
 
32
- return true
70
+ return 0
33
71
  end
34
- end
72
+ end
@@ -14,7 +14,7 @@ class Doubleshot::CLI::Commands::Gem < Doubleshot::CLI
14
14
  options.separator "Options"
15
15
 
16
16
  options.test = true
17
- options.on "--no-test", "Disable testing as a build prerequisite." do
17
+ options.on "--no-test", "Disable testing as a packaging prerequisite." do
18
18
  options.test = false
19
19
  end
20
20
 
@@ -25,15 +25,36 @@ class Doubleshot::CLI::Commands::Gem < Doubleshot::CLI
25
25
 
26
26
  def self.start(args)
27
27
  options = self.options.parse!(args)
28
+ doubleshot = Doubleshot::current
28
29
 
29
- # TODO:
30
- # compile Java
31
- # download Jars and add them to the gemspec require_paths (I THINK).
32
- config = Doubleshot::current.config
30
+ if options.test
31
+ puts "Executing tests..."
32
+ if Doubleshot::CLI::Commands::Test.start([ "--ci" ]) != 0
33
+ STDERR.puts "Test failed, aborting Gem creation."
34
+ return 1
35
+ end
36
+ else
37
+ Doubleshot::CLI::Commands::Build.start(args)
38
+ end
39
+
40
+ unless Pathname::glob(doubleshot.config.source.java + "**/*.java").empty?
41
+ target = doubleshot.config.target
42
+
43
+ jarfile = (target + "#{doubleshot.config.project}.jar")
44
+ jarfile.delete if jarfile.exist?
45
+
46
+ ant.jar jarfile: jarfile, basedir: target do
47
+ doubleshot.lockfile.jars.each do |jar|
48
+ zipfileset src: jar.path.expand_path, excludes: "META-INF/*.SF"
49
+ end
50
+ end
51
+ end
52
+
53
+ # WARN: This is version specific since in HEAD they've changed this to Gem::Package::build.
54
+ ::Gem::Builder.new(doubleshot.config.gemspec).build
33
55
 
34
- # TODO: This is version specific since in HEAD they've changed this to Gem::Package::build.
35
- ::Gem::Builder.new(config.gemspec).build
56
+ puts(" Size: %.2fM" % (Pathname(doubleshot.config.gemspec.file_name).size.to_f / 1024 / 1024))
36
57
 
37
- return true
58
+ return 0
38
59
  end
39
- end
60
+ end
@@ -1,3 +1,5 @@
1
+ require 'rexml/document'
2
+
1
3
  class Doubleshot::CLI::Commands::Init < Doubleshot::CLI
2
4
 
3
5
  def self.summary
@@ -19,6 +21,7 @@ class Doubleshot::CLI::Commands::Init < Doubleshot::CLI
19
21
 
20
22
  def self.start(args)
21
23
  session = new(args)
24
+
22
25
  if session.doubleshot_file.exist?
23
26
  return puts <<-EOS.margin
24
27
  ERROR: A Doubleshot file already exists.
@@ -27,6 +30,9 @@ class Doubleshot::CLI::Commands::Init < Doubleshot::CLI
27
30
  end
28
31
  session.import_gemspec!
29
32
  session.mark_gemspec_for_deletion!
33
+
34
+ session.import_pom! if session.pom_file.exist?
35
+
30
36
  session.generate_doubleshot_file!
31
37
 
32
38
  puts <<-EOS.margin
@@ -35,7 +41,7 @@ class Doubleshot::CLI::Commands::Init < Doubleshot::CLI
35
41
  Please review it and make changes as you see fit. It will
36
42
  be used for all the things.
37
43
  EOS
38
- return true
44
+ return 0
39
45
  end
40
46
 
41
47
  def initialize(args)
@@ -47,6 +53,10 @@ class Doubleshot::CLI::Commands::Init < Doubleshot::CLI
47
53
  Pathname(@path + "Doubleshot")
48
54
  end
49
55
 
56
+ def pom_file
57
+ Pathname(@path + "pom.xml")
58
+ end
59
+
50
60
  def gemspec
51
61
  @gemspec ||= Pathname::glob(@path + "*.gemspec").first
52
62
  end
@@ -54,16 +64,17 @@ class Doubleshot::CLI::Commands::Init < Doubleshot::CLI
54
64
  def import_gemspec!
55
65
  original = gemspec ? eval_gemspec(gemspec.read) : ::Gem::Specification.new
56
66
 
67
+ @config.project = default original.name, "THE PROJECT NAME"
68
+ @config.version = default original.version, "9000.1"
69
+
57
70
  @config.gemspec do |spec|
58
- spec.name = default original.name, "THE PROJECT NAME"
59
- spec.summary = default original.summary, "SUMMARIZE ME"
60
- spec.description = default original.description, "A VERY DETAILED DESCRIPTION"
61
- spec.author = default original.author, "WHOAMI"
62
- spec.homepage = default original.homepage, "I AM FROM THE INTERNET"
63
- spec.email = default original.email, "ME@EXAMPLE.COM"
64
- spec.version = default original.version, "9000.1"
65
- spec.license = default original.license, "MIT-LICENSE"
66
- spec.executables = original.executables
71
+ spec.summary = default original.summary, "SUMMARIZE ME"
72
+ spec.description = default original.description, "A VERY DETAILED DESCRIPTION"
73
+ spec.author = default original.author, "WHOAMI"
74
+ spec.homepage = default original.homepage, "I AM FROM THE INTERNET"
75
+ spec.email = default original.email, "ME@EXAMPLE.COM"
76
+ spec.license = default original.license, "MIT-LICENSE"
77
+ spec.executables = original.executables
67
78
  end
68
79
 
69
80
  original.runtime_dependencies.each do |dependency|
@@ -77,6 +88,26 @@ class Doubleshot::CLI::Commands::Init < Doubleshot::CLI
77
88
  end
78
89
  end
79
90
 
91
+ def import_pom!
92
+ pom_document = REXML::Document.new pom_file.open
93
+
94
+ project = pom_document.get_text("project/artifactId")
95
+ @config.project = project if (@config.project.nil? or @config.project == "THE PROJECT NAME") and not project.nil?
96
+
97
+ @config.group = pom_document.get_text("project/groupId")
98
+
99
+ version = pom_document.get_text("project/version")
100
+ @config.version = version if (@config.version.nil? or @config.version == "9000.1") and not version.nil?
101
+
102
+ pom_document.elements.each("project/dependencies/dependency") do |pom_dependency|
103
+ group_id = pom_dependency.get_text("groupId")
104
+ artifact_id = pom_dependency.get_text("artifactId")
105
+ version = pom_dependency.get_text("version")
106
+
107
+ @config.jar "#{group_id}:#{artifact_id}:jar:#{version}"
108
+ end
109
+ end
110
+
80
111
  def eval_gemspec(contents)
81
112
  puts "Importing Gemspec..."
82
113
  begin
@@ -13,7 +13,7 @@ class Doubleshot::CLI::Commands::Install < Doubleshot::CLI
13
13
  options.separator "Options"
14
14
 
15
15
  options.test = true
16
- options.on "--no-test", "Disable testing as a build prerequisite." do
16
+ options.on "--no-test", "Disable testing as a packaging prerequisite." do
17
17
  options.test = false
18
18
  end
19
19
 
@@ -29,7 +29,7 @@ class Doubleshot::CLI::Commands::Install < Doubleshot::CLI
29
29
 
30
30
  installer = ::Gem::DependencyInstaller.new
31
31
  installer.install Doubleshot::current.config.gemspec.file_name
32
-
33
- return true
32
+
33
+ return 0
34
34
  end
35
- end
35
+ end
@@ -1,7 +1,65 @@
1
1
  class Doubleshot::CLI::Commands::Jar < Doubleshot::CLI
2
+
2
3
  def self.summary
3
4
  <<-EOS.margin
4
- TODO
5
+ Package your project as a JAR.
5
6
  EOS
6
7
  end
7
- end
8
+
9
+ def self.options
10
+ Options.new do |options|
11
+ options.banner = "Usage: doubleshot jar"
12
+ options.separator ""
13
+ options.separator "Options"
14
+
15
+ options.test = true
16
+ options.on "--no-test", "Disable testing as a packaging prerequisite." do
17
+ options.test = false
18
+ end
19
+
20
+ options.sparse = false
21
+ options.on "--sparse", "Don't include JAR dependencies in your JAR. (For example, if you want to use Maven.)" do
22
+ options.sparse = true
23
+ end
24
+
25
+ options.separator ""
26
+ options.separator "Summary: #{summary}"
27
+ end
28
+ end
29
+
30
+ def self.start(args)
31
+ options = self.options.parse!(args)
32
+ doubleshot = Doubleshot::current
33
+
34
+ if options.test
35
+ puts "Executing tests..."
36
+ if Doubleshot::CLI::Commands::Test.start([ "--ci" ]) != 0
37
+ STDERR.puts "Test failed, aborting JAR creation."
38
+ return 1
39
+ end
40
+ else
41
+ Doubleshot::CLI::Commands::Build.start(args)
42
+ end
43
+
44
+ unless Pathname::glob(doubleshot.config.source.java + "**/*.java").empty?
45
+ target = doubleshot.config.target
46
+
47
+ jarfile = (target + "#{doubleshot.config.project}.jar")
48
+ jarfile.delete if jarfile.exist?
49
+
50
+ ant.jar jarfile: jarfile, basedir: target do
51
+ manifest{
52
+ attribute(:name => "Main-Class", :value => doubleshot.config.java_main)
53
+ }
54
+ fileset dir: doubleshot.config.source.ruby.parent, includes: doubleshot.config.source.ruby.to_s + "/**/*"
55
+ unless options.sparse
56
+ doubleshot.lockfile.jars.each do |jar|
57
+ zipfileset src: jar.path.expand_path, excludes: "META-INF/*.SF"
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ return 0
64
+ end
65
+ end
@@ -0,0 +1,29 @@
1
+ class Doubleshot::CLI::Commands::Pom < Doubleshot::CLI
2
+
3
+ def self.summary
4
+ <<-EOS.margin
5
+ Generate a pom.xml based on your Doubleshot file.
6
+ EOS
7
+ end
8
+
9
+ def self.options
10
+ Options.new do |options|
11
+ options.banner = "Usage: doubleshot pom"
12
+
13
+ options.separator ""
14
+ options.separator "Summary: #{summary}"
15
+ end
16
+ end
17
+
18
+ def self.start(args)
19
+ require "doubleshot/pom"
20
+
21
+ pom = Pathname("pom.xml")
22
+ pom.rename("pom.xml.#{Time.now.to_i}") if pom.exist?
23
+ pom.open("w+") do |file|
24
+ file << Doubleshot::Pom.new(Doubleshot::current.config).to_s
25
+ end
26
+
27
+ return 0
28
+ end
29
+ end
@@ -8,26 +8,62 @@ class Doubleshot::CLI::Commands::Test < Doubleshot::CLI
8
8
  attribute of your Doubleshot configuration.
9
9
  EOS
10
10
  end
11
-
11
+
12
12
  def self.options
13
13
  Options.new do |options|
14
- options.banner = "Usage: doubleshot test"
15
-
14
+ options.banner = "Usage: doubleshot test [options]"
15
+
16
+ options.separator ""
17
+ options.separator "Options:"
18
+
19
+ options.ci_test = false
20
+ options.on "--ci", "Run all tests, then exit. (No continuous listening for file changes.)" do
21
+ options.ci_test = true
22
+ options.build = true
23
+ end
24
+
16
25
  options.separator ""
17
26
  options.separator "Summary: #{summary}"
18
27
  end
19
28
  end
20
-
29
+
21
30
  def self.start(args)
31
+ options = self.options.parse!(args)
32
+ doubleshot = Doubleshot::current
33
+
34
+ if Pathname::glob(doubleshot.config.source.tests + "**/*_{spec,test}.rb").empty?
35
+ puts "No tests found"
36
+ return 0
37
+ end
38
+
39
+ if options.ci_test
40
+ if doubleshot.lockfile.exist?
41
+ puts "--ci: Removing lockfile"
42
+ doubleshot.lockfile.delete
43
+ end
44
+
45
+ if doubleshot.classpath_cache.exist?
46
+ puts "--ci: Removing .classpath.cache"
47
+ doubleshot.classpath_cache.delete
48
+ end
49
+
50
+ if doubleshot.config.target.exist?
51
+ puts "--ci: Removing target build directory"
52
+ doubleshot.config.target.rmtree
53
+ end
54
+ end
55
+
22
56
  require "listen"
23
- watcher = new(Doubleshot::current.config)
57
+
58
+ watcher = new(doubleshot.config, options.ci_test)
24
59
  watcher.run
25
60
  end
26
-
27
- def initialize(config)
61
+
62
+ def initialize(config, ci_test)
28
63
  @config = config
29
64
  @interrupted = false
30
-
65
+ @ci_test = ci_test
66
+
31
67
  # Hit Ctrl-C once to re-run all specs; twice to exit the program.
32
68
  Signal.trap("INT") do
33
69
  if @interrupted
@@ -38,42 +74,56 @@ class Doubleshot::CLI::Commands::Test < Doubleshot::CLI
38
74
  run_all_specs
39
75
  @interrupted = false
40
76
  end
41
- end
77
+ end
42
78
  end
43
-
79
+
44
80
  def run
45
- # Output here just so you know when changes will be
46
- # picked up after you start the program.
47
- puts "Listening for changes..."
48
- listener.start
81
+ if @ci_test
82
+ run_all_specs
83
+ else
84
+ Doubleshot::CLI::Commands::Build.start([ "--conditional" ])
85
+ # Output here just so you know when changes will be
86
+ # picked up after you start the program.
87
+ puts "Listening for changes..."
88
+ listener.start
89
+ end
49
90
  end
50
-
91
+
51
92
  private
52
93
  def listener
53
94
  # This creates a MultiListener
54
- Listen.to(@config.source.tests.to_s, @config.source.ruby.to_s).change do |modified, added, removed|
95
+ Listen.to(@config.source.tests.to_s, @config.source.ruby.to_s, @config.source.java.to_s).change do |modified, added, removed|
55
96
  modified.each do |location|
56
97
  path = Pathname(location)
57
- next unless path.extname == ".rb"
58
98
 
59
- test = if path.child_of? @config.source.tests
99
+ next unless path.extname == ".rb" or path.extname == ".java"
100
+
101
+ test = if path.basename.to_s =~ /_(spec|test).rb/ && path.child_of?(@config.source.tests)
60
102
  path
61
103
  else
62
- relative_path = path.relative_path_from(@config.source.ruby.expand_path)
63
- matcher = relative_path.sub(/(\w+)\.rb/, "\\1_{spec,test}.rb")
104
+ relative_path = if path.extname == ".rb"
105
+ path.relative_path_from(@config.source.ruby.expand_path)
106
+ else
107
+ path.relative_path_from(@config.source.java.expand_path)
108
+ end
109
+ matcher = relative_path.sub(/(\w+)\.(rb|java)/, "\\1_{spec,test}.rb")
64
110
  matchers = [ matcher, Pathname(matcher.to_s.split("/")[1..-1].join("/")) ]
65
-
111
+
66
112
  match = matchers.detect do |matcher|
67
113
  if match = Pathname::glob(@config.source.tests + matcher).first
68
- break match
114
+ break match
69
115
  end
70
116
  end
71
117
  end
72
-
118
+
73
119
  if test && test.exist?
120
+ if path.extname == ".java"
121
+ Doubleshot::CLI::Commands::Build.start([])
122
+ end
123
+
74
124
  duration = Time::measure do
75
125
  puts "\n --- Running test for #{test.to_s} ---\n\n"
76
-
126
+
77
127
  org.jruby.Ruby.newInstance.executeScript <<-RUBY, test.to_s
78
128
  begin
79
129
  require #{test.to_s.inspect}
@@ -83,7 +133,7 @@ class Doubleshot::CLI::Commands::Test < Doubleshot::CLI
83
133
  end
84
134
  RUBY
85
135
  end
86
-
136
+
87
137
  puts "Completed in #{duration}s"
88
138
  else
89
139
  puts "\nNo matching test for #{path.relative_path_from(@config.source.ruby.expand_path).to_s}"
@@ -91,12 +141,14 @@ class Doubleshot::CLI::Commands::Test < Doubleshot::CLI
91
141
  end
92
142
  end
93
143
  end
94
-
144
+
95
145
  def run_all_specs
146
+ exit_status = false
96
147
  duration = Time::measure do
97
-
98
148
  puts "\n --- Running all tests ---\n\n"
99
-
149
+
150
+ Doubleshot::CLI::Commands::Build.start([ "--conditional" ])
151
+
100
152
  script = <<-RUBY
101
153
  begin
102
154
  #{
@@ -110,10 +162,11 @@ class Doubleshot::CLI::Commands::Test < Doubleshot::CLI
110
162
  end
111
163
  RUBY
112
164
  # puts "SCRIPT:", script
113
- org.jruby.Ruby.newInstance.executeScript script, "all-specs"
165
+ exit_status = org.jruby.Ruby.newInstance.executeScript script, "all-specs"
114
166
  end
115
-
167
+
116
168
  puts "Completed in #{duration}s"
169
+ return exit_status
117
170
  end
118
-
119
- end # class Doubleshot::CLI::Commands::Test < Doubleshot::CLI
171
+
172
+ end # class Doubleshot::CLI::Commands::Test < Doubleshot::CLI