doubleshot 0.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
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,59 @@
1
+ class Doubleshot
2
+ class Configuration
3
+ class SourceLocations
4
+
5
+ def initialize
6
+ @defaults = {}
7
+ @ruby = default :ruby, Pathname("lib")
8
+ @java = default :java, Pathname("ext/java")
9
+ @tests = default :tests, Pathname("test")
10
+ end
11
+
12
+ attr_reader :ruby
13
+ def ruby=(path)
14
+ @ruby = validate_path(path)
15
+ end
16
+
17
+ attr_reader :java
18
+ def java=(path)
19
+ @java = validate_path(path)
20
+ end
21
+
22
+ attr_reader :tests
23
+ def tests=(path)
24
+ @tests = validate_path(path)
25
+ end
26
+
27
+ def eql?(other)
28
+ other.is_a?(self.class) &&
29
+ other.ruby == ruby &&
30
+ other.java == java &&
31
+ other.tests == tests
32
+ end
33
+ alias :== :eql?
34
+
35
+ def __changes__
36
+ changes = []
37
+ @defaults.each_pair do |key,value|
38
+ changes << key unless instance_variable_get("@#{key}") == value
39
+ end
40
+ changes
41
+ end
42
+
43
+ private
44
+ def validate_path(path)
45
+ check = Pathname(path.to_s)
46
+
47
+ unless check.directory?
48
+ raise IOError.new("+path+ must be a directory but was #{path.inspect}")
49
+ end
50
+
51
+ check
52
+ end
53
+
54
+ def default(key, value)
55
+ @defaults[key] = value
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,31 @@
1
+ require "doubleshot/dependencies/gem_dependency_list"
2
+ require "doubleshot/dependencies/jar_dependency_list"
3
+
4
+ class Doubleshot
5
+ class Dependencies
6
+
7
+ def initialize
8
+ @gems = GemDependencyList.new
9
+ @jars = JarDependencyList.new
10
+ end
11
+
12
+ def gems
13
+ @gems
14
+ end
15
+
16
+ def jars
17
+ @jars
18
+ end
19
+
20
+ def empty?
21
+ @gems.empty? && @jars.empty?
22
+ end
23
+
24
+ def eql?(other)
25
+ other.is_a?(self.class) &&
26
+ other.gems == gems &&
27
+ other.jars == jars
28
+ end
29
+ alias :== :eql?
30
+ end
31
+ end
@@ -0,0 +1,38 @@
1
+ class Doubleshot
2
+ class Dependencies
3
+ class Dependency
4
+ attr_reader :name
5
+
6
+ def initialize(name)
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
+ end
20
+
21
+ def eql?(other)
22
+ other.is_a?(Dependency) and other.name == @name
23
+ end
24
+
25
+ def hash
26
+ @hash ||= @name.hash
27
+ end
28
+
29
+ def ==(other)
30
+ eql?(other) && requirements == other.requirements
31
+ end
32
+
33
+ def to_s
34
+ @name
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,60 @@
1
+ class Doubleshot
2
+ class Dependencies
3
+ class DependencyList
4
+ include Enumerable
5
+
6
+ def initialize
7
+ @dependencies = Set.new
8
+ end
9
+
10
+ def eql?(other)
11
+ other.is_a?(self.class) && entries == other.entries
12
+ end
13
+ alias :== :eql?
14
+
15
+ def add(dependency)
16
+ unless dependency.is_a? Dependency
17
+ raise ArgumentError.new("+dependency+ must be a Doubleshot::Dependencies::Dependency")
18
+ end
19
+ @dependencies << dependency
20
+ self
21
+ end
22
+
23
+ def fetch(name)
24
+ raise ArgumentError.new("+name+ must be a String") unless name.is_a? String
25
+
26
+ unless dependency = @dependencies.detect { |entry| entry.name == name }
27
+ dependency = Dependency.new(name)
28
+ add dependency
29
+ end
30
+
31
+ dependency
32
+ end
33
+
34
+ def size
35
+ @dependencies.size
36
+ end
37
+ alias :length :size
38
+
39
+ def empty?
40
+ @dependencies.empty?
41
+ end
42
+
43
+ def each
44
+ @dependencies.each do |dependency|
45
+ yield dependency
46
+ end
47
+ end
48
+
49
+ def include?(dependency)
50
+ if dependency.is_a? Dependency
51
+ @dependencies.include? dependency
52
+ elsif dependency.is_a? String
53
+ @dependencies.any? { |entry| entry.name == dependency }
54
+ else
55
+ raise ArgumentError.new("+dependency+ must be a Doubleshot::Dependencies::Dependency or a String")
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,8 @@
1
+ require "doubleshot/dependencies/dependency"
2
+
3
+ class Doubleshot
4
+ class Dependencies
5
+ class GemDependency < Dependency
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ require "doubleshot/dependencies/dependency_list"
2
+ require "doubleshot/dependencies/gem_dependency"
3
+
4
+ class Doubleshot
5
+ class Dependencies
6
+ class GemDependencyList < DependencyList
7
+
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ require "doubleshot/dependencies/dependency"
2
+
3
+ class Doubleshot
4
+ class Dependencies
5
+ class JarDependency < Dependency
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ require "doubleshot/dependencies/dependency_list"
2
+ require "doubleshot/dependencies/jar_dependency"
3
+
4
+ class Doubleshot
5
+ class Dependencies
6
+ class JarDependencyList < DependencyList
7
+
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,51 @@
1
+ require "pathname"
2
+
3
+ gemfile = Pathname "Gemfile"
4
+ gemfile_lock = Pathname "Gemfile.lock"
5
+
6
+ install_gems = -> do
7
+ require "bundler"
8
+ require "bundler/cli"
9
+ Bundler::CLI.new.install
10
+ end
11
+
12
+ if gemfile.exist?
13
+ begin
14
+ install_gems.call if !gemfile_lock.exist? || gemfile.mtime > gemfile_lock.mtime
15
+ require "bundler/setup"
16
+ end
17
+ end
18
+
19
+ install_jars = -> do
20
+ require "jbundler/cli"
21
+ JBundler::Cli.new.install
22
+ end
23
+
24
+ jarfile = Pathname "Jarfile"
25
+ jarfile_lock = Pathname "Jarfile.lock"
26
+
27
+ if jarfile.exist?
28
+ require "bundler" unless Object::const_defined?("Bundler")
29
+ require "jbundler"
30
+ install_jars.call if !jarfile_lock.exist? || jarfile.mtime > jarfile_lock.mtime
31
+ end
32
+
33
+ require "ant"
34
+
35
+ source = Pathname "ext/java"
36
+ target = Pathname "target"
37
+
38
+ target.mkdir unless target.exist?
39
+
40
+ ant.path id: "classpath" do
41
+ fileset dir: target.to_s
42
+ JBUNDLER_CLASSPATH.each do |jar|
43
+ fileset dir: Pathname(jar).dirname
44
+ end
45
+ end
46
+
47
+ ant.javac srcdir: source.to_s, destdir: target.to_s, debug: "yes", includeantruntime: "no", classpathref: "classpath"
48
+
49
+ $CLASSPATH << target.to_s
50
+
51
+ ant.jar jarfile: "example.jar", basedir: target.to_s
@@ -0,0 +1,32 @@
1
+ class Doubleshot
2
+
3
+ class ReadonlyCollection
4
+ include Enumerable
5
+
6
+ def initialize(collection)
7
+ unless collection.is_a? Enumerable
8
+ raise ArgumentError.new("+collection+ must be an Enumerable")
9
+ end
10
+ @collection = collection
11
+ end
12
+
13
+ def each
14
+ @collection.each { |entry| yield entry }
15
+ end
16
+
17
+ def size
18
+ entries.size
19
+ end
20
+ alias :length :size
21
+
22
+ def empty?
23
+ entries.empty?
24
+ end
25
+
26
+ def eql?(other)
27
+ other.is_a?(self.class) && entries == other.entries
28
+ end
29
+ alias :== :eql?
30
+ end
31
+
32
+ end
@@ -0,0 +1,49 @@
1
+ require_relative "../doubleshot"
2
+
3
+ gemfile = Pathname "Gemfile"
4
+ gemfile_lock = Pathname "Gemfile.lock"
5
+
6
+ install_gems = -> do
7
+ require "bundler"
8
+ require "bundler/cli"
9
+ Bundler::CLI.new.install
10
+ end
11
+
12
+ if gemfile.exist?
13
+ begin
14
+ install_gems.call if !gemfile_lock.exist? || gemfile.mtime > gemfile_lock.mtime
15
+ require "bundler/setup"
16
+ end
17
+ end
18
+
19
+ install_jars = -> do
20
+ require "jbundler/cli"
21
+ JBundler::Cli.new.install
22
+ end
23
+
24
+ jarfile = Pathname "Jarfile"
25
+ jarfile_lock = Pathname "Jarfile.lock"
26
+
27
+ if jarfile.exist?
28
+ require "bundler" unless Object::const_defined?("Bundler")
29
+ require "jbundler"
30
+ install_jars.call if !jarfile_lock.exist? || jarfile.mtime > jarfile_lock.mtime
31
+ end
32
+
33
+ require "ant"
34
+
35
+ source = Pathname "ext/java"
36
+ target = Pathname "target"
37
+
38
+ target.mkdir unless target.exist?
39
+
40
+ ant.path id: "classpath" do
41
+ fileset dir: target.to_s
42
+ JBUNDLER_CLASSPATH.each do |jar|
43
+ fileset dir: Pathname(jar).dirname
44
+ end
45
+ end
46
+
47
+ ant.javac srcdir: source.to_s, destdir: target.to_s, debug: "yes", includeantruntime: "no", classpathref: "classpath"
48
+
49
+ $CLASSPATH << target.to_s
data/lib/ruby/blank.rb ADDED
@@ -0,0 +1,132 @@
1
+ ## This file is pulled straight from ActiveSupport, MIT-LICENSE copied below for attribution purposes:
2
+ #
3
+ # Copyright (c) 2005-2011 David Heinemeier Hansson
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ class Object
25
+ # An object is blank if it's false, empty, or a whitespace string.
26
+ # For example, "", " ", +nil+, [], and {} are all blank.
27
+ #
28
+ # This simplifies:
29
+ #
30
+ # if address.nil? || address.empty?
31
+ #
32
+ # ...to:
33
+ #
34
+ # if address.blank?
35
+ def blank?
36
+ respond_to?(:empty?) ? empty? : !self
37
+ end
38
+
39
+ # An object is present if it's not <tt>blank?</tt>.
40
+ def present?
41
+ !blank?
42
+ end
43
+
44
+ # Returns object if it's <tt>present?</tt> otherwise returns +nil+.
45
+ # <tt>object.presence</tt> is equivalent to <tt>object.present? ? object : nil</tt>.
46
+ #
47
+ # This is handy for any representation of objects where blank is the same
48
+ # as not present at all. For example, this simplifies a common check for
49
+ # HTTP POST/query parameters:
50
+ #
51
+ # state = params[:state] if params[:state].present?
52
+ # country = params[:country] if params[:country].present?
53
+ # region = state || country || 'US'
54
+ #
55
+ # ...becomes:
56
+ #
57
+ # region = params[:state].presence || params[:country].presence || 'US'
58
+ def presence
59
+ self if present?
60
+ end
61
+ end
62
+
63
+ class NilClass
64
+ # +nil+ is blank:
65
+ #
66
+ # nil.blank? # => true
67
+ #
68
+ def blank?
69
+ true
70
+ end
71
+ end
72
+
73
+ class FalseClass
74
+ # +false+ is blank:
75
+ #
76
+ # false.blank? # => true
77
+ #
78
+ def blank?
79
+ true
80
+ end
81
+ end
82
+
83
+ class TrueClass
84
+ # +true+ is not blank:
85
+ #
86
+ # true.blank? # => false
87
+ #
88
+ def blank?
89
+ false
90
+ end
91
+ end
92
+
93
+ class Array
94
+ # An array is blank if it's empty:
95
+ #
96
+ # [].blank? # => true
97
+ # [1,2,3].blank? # => false
98
+ #
99
+ alias_method :blank?, :empty?
100
+ end
101
+
102
+ class Hash
103
+ # A hash is blank if it's empty:
104
+ #
105
+ # {}.blank? # => true
106
+ # {:key => 'value'}.blank? # => false
107
+ #
108
+ alias_method :blank?, :empty?
109
+ end
110
+
111
+ class String
112
+ # A string is blank if it's empty or contains whitespaces only:
113
+ #
114
+ # "".blank? # => true
115
+ # " ".blank? # => true
116
+ # " something here ".blank? # => false
117
+ #
118
+ def blank?
119
+ self !~ /\S/
120
+ end
121
+ end
122
+
123
+ class Numeric #:nodoc:
124
+ # No number is blank:
125
+ #
126
+ # 1.blank? # => false
127
+ # 0.blank? # => false
128
+ #
129
+ def blank?
130
+ false
131
+ end
132
+ end