guard-java 0.0.3

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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzdmZTEwNzgxN2I1ZmNiZGZmMTQ1NzJhZmYyNjE0ZmJhOGZkNzI0NA==
5
+ data.tar.gz: !binary |-
6
+ NDEwOWE5MzA4MTM5NjQ1YzVkYTdmMjM0ZTk5MTIxNWE3NTNiZWNlYw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OTRjMDgwOWVmZGE4N2QwMTE2MWY5NjgyNmFiMmI1NGQ1NzY3NzhkODJmZWVh
10
+ ZWMxN2I4ZDdlZmVmNjFkYjdiZmZjNjhkZmM5ZjcwZjU4MTQ5NmM2YTExMTQw
11
+ NGFlZjY4OGJlMmU2NDVkNGNlZTk2Y2QxNjQ1NjE2YWVmNWEzYTg=
12
+ data.tar.gz: !binary |-
13
+ NWI1YmQxYWE3ZmIyNDE4YWUxZWU3MjQ5OGRlNDE2NjdlMjNiYzQ5OWVhNzlk
14
+ MGNmNGI1NTI2YzNlZGVmNmZiMjc5Mzg0ZjRmOWU0ZGQzYjZjMTMzNThlZDVk
15
+ ZmFiZTk4Njg2M2I5ZjNhMzNiOTBhNjI0Yjk0Yjc4MjZjODRiMjA=
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Tony Heupel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # Guard::Java
2
+
3
+ This guard allows you to build and test your Java code automatically when files are altered.
4
+
5
+
6
+ ## Install
7
+
8
+ Install the gem with:
9
+
10
+ gem install guard-java
11
+
12
+ Or add it to your Gemfile:
13
+
14
+ gem 'guard-java'
15
+
16
+ And then add a basic setup to your Guardfile:
17
+
18
+ guard init java
19
+
20
+
21
+ ## Usage
22
+
23
+ If you can do something in your shell, or in Ant, you can do it when a file changes
24
+ with guard-java.
25
+
26
+ You simply provide paths to watch, including how to map a class to it's unit-test class name
27
+ and some other options.
28
+
29
+
30
+ ### Examples
31
+
32
+ ``` ruby
33
+ require 'guard/java_translator'
34
+
35
+ guard :java, :project_name => 'My Java Project',
36
+ :all_after_pass => false, # run the all_cli command if the specific test class passes (true/false)
37
+ :focused_cli => 'ant clean debug', # (required) command-line to run before running a specific test class
38
+ :all_cli => 'ant package-and-test', # (required) command-line to run that executes the "build and run all tests" concept
39
+ :classpath => './bin/classes.jar:./libs/*:/usr/share/java/junit.jar' # (required) don't forget junit and your own jars here
40
+ # :all_on_start => true # run all on startup of guard
41
+ # :test_runner_class => 'org.junit.runner.JUnitCore' # just in case you're using junit 3 or something other than 4
42
+ do
43
+
44
+ watch (%r{^tests/src/*/(.+)\.java$}) { |m| ::Guard::JavaTranslator.filename_to_classname(m[0]) } # test file changes
45
+
46
+ watch(%r{^src/*/(.+)\.java$}) { |m|
47
+ test_filename = "tests/src/#{m[1]}Test.java"
48
+ ::Guard::JavaTranslator.filename_to_classname(test_filename)
49
+ } # when source files change, run the test for that file
50
+
51
+ # ignore(path) will ignore files that change automatically, such as generated code files
52
+ end
53
+ ```
54
+
55
+
56
+ ### Using Guard
57
+
58
+ From the project's root directory, simply run:
59
+
60
+ ```shell
61
+ $ guard
62
+ 20:28:01 - INFO - Guard uses GNTP to send notifications.
63
+ 20:28:01 - INFO - Guard uses Tmux to send notifications.
64
+ 20:28:01 - INFO - Guard uses TerminalTitle to send notifications.
65
+ 20:28:01 - INFO - Guard::Java is running
66
+ 20:28:01 - INFO - Guard is now watching at '/Users/tchype/Projects/some_java_project'
67
+ [1] guard(main)>
68
+ ```
69
+
70
+ It tells you what notification methods it will use to tell you when it has detected changes,
71
+ when it is building/testing, and whether those things have succeeded or failed. In the example
72
+ above, I am running Growl as my system notifier and Tmux as my Terminal Multiplexer within
73
+ Mac OSX's Terminal program.
74
+
75
+ You can see that it detected those things and is using GNTP to send Growl notifications
76
+ (popups with detailed messages), Tmux color coding (Yellow for building/testing, Red for
77
+ failures, and Green for success), as well as updating the Terminal window/tab's title
78
+ when guard detects a change.
79
+
80
+
81
+
82
+ ### Other Useful Tips
83
+ #### Working with Android
84
+ The template Guardfile you get when you run ```guard init``` has some samples in it. You will want to include your Android SDK jar
85
+ file in the ```classpath``` argument. You can write a ruby function that reads it from a local or project
86
+ properites file that you call when setting your classpath. For example:
87
+
88
+ ```ruby
89
+ require 'guard/java_translator'
90
+
91
+ def android_sdk_dir
92
+ sdk_dir = ''
93
+ %w{project.properties local.properties}.each do |prop_file|
94
+ File.open(File.join(File.dirname(__FILE__), prop_file)).each do |line|
95
+ sdk_dir = line[8..-1] if line[0..7] == 'sdk.dir='
96
+ end
97
+ end
98
+
99
+ sdk_dir.strip
100
+ end
101
+
102
+ guard :java, :project_name => 'Search SDK',
103
+ :all_on_start => false,
104
+ :all_after_pass => false,
105
+ :focused_cli => 'ant guard-debug',
106
+ :all_cli => 'ant clean debug',
107
+ :classpath => "#{android_sdk_dir}:./bin/classes.jar:./libs/*:/usr/share/java/junit.jar" do
108
+
109
+ ignore(%r{^src/com/infospace/some_project/BuildTimeUpdatedFile.java}) # Build-time code-gen
110
+
111
+ watch (%r{^tests/src/com/infospace/some_project/*/(.+)\.java$}) { |m|
112
+ ::Guard::JavaTranslator.filename_to_classname(m[0])
113
+ } # Test file changes
114
+
115
+ watch(%r{^src/com/infospace/some_project/*/(.+)\.java$}) { |m|
116
+ test_filename = "tests/src/com/infospace/some_project/#{m[1]}Test.java"
117
+ ::Guard::JavaTranslator.filename_to_classname(test_filename)
118
+ } # when source files change, run the test for that file
119
+ end
120
+ ```
121
+
122
+ #### Latency
123
+ In the case where many files are changing close together (e.g., saving a test file and saving the class under test), you can tell
124
+ guard to wait a certain number of seconds when it detects a file change before triggering a test cycle using the
125
+ ```--latency``` (or ```-l```) command line option. For example, to wait 10 seconds after a change is detected for other changes
126
+ to also accumulate:
127
+
128
+
129
+ ```shell
130
+ $ guard -l 10
131
+ ```
@@ -0,0 +1,18 @@
1
+ guard :java, :project_name => 'My Java Project',
2
+ :all_after_pass => false, # run the all_cli command if the specific test class passes (true/false)
3
+ :focused_cli => 'ant clean debug', # (required) command-line to run before running a specific test class
4
+ :all_cli => 'ant package-and-test', # (required) command-line to run that executes the "build and run all tests" concept
5
+ :classpath => './bin/classes.jar:./libs/*:/usr/share/java/junit.jar' # (required) don't forget junit and your own jars here
6
+ # :all_on_start => true # run all on startup of guard
7
+ # test_runner_class => 'org.junit.runner.JUnitCore' # just in case you're using junit 3 or something other than 4
8
+ do
9
+
10
+ watch (%r{^src/test/java/*/(.+)\.java$}) { |m| ::Guard::JavaTranslator.filename_to_classname(m[0], 'src/test/java/') } # test file changes
11
+
12
+ watch(%r{^src/main/java/*/(.+)\.java$}) { |m|
13
+ test_filename = "tests/src/#{m[1]}Test.java"
14
+ ::Guard::JavaTranslator.filename_to_classname(test_filename)
15
+ } # when source files change, run the test for that file
16
+
17
+ # ignore(path) will ignore files that change automatically, such as generated code filesjt
18
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module JavaVersion
3
+ VERSION = "0.0.3"
4
+ end
5
+ end
data/lib/guard/java.rb ADDED
@@ -0,0 +1,89 @@
1
+ require 'guard/guard'
2
+
3
+ module ::Guard
4
+ class Java < ::Guard::Guard
5
+ def initialize(watchers=[], options={})
6
+ super
7
+ @options = {
8
+ :all_after_pass => true,
9
+ :all_on_start => true,
10
+ :test_runner_class => 'org.junit.runner.JUnitCore',
11
+ :project_name => 'Java Project',
12
+ :focused_cli => nil,
13
+ :all_cli => nil,
14
+ :classpath => '.'
15
+ }.merge(options)
16
+ end
17
+
18
+ def start
19
+ UI.info 'Guard::Java is running'
20
+ raise ArgumentError, ":focused_cli and :all_cli options must be set" if @options[:focused_cli].nil? || @options[:all_cli].nil?
21
+
22
+ run_all if @options[:all_on_start]
23
+ end
24
+
25
+ def run_all
26
+ project_name = @options[:project_name]
27
+ notify project_name, "Build and run all", :pending
28
+ result = do_shell(all_command)
29
+ result_description = "#{project_name} build results"
30
+ notify result_description, "Build #{result.to_s.capitalize}", result # Notify of success or failure
31
+ end
32
+
33
+ def run_on_changes(classes)
34
+ run_focused_tests(classes)
35
+ end
36
+
37
+ def stop
38
+ end
39
+
40
+ def run_focused_tests(classes)
41
+ project_name = @options[:project_name]
42
+ klass = classes[0]
43
+
44
+ notify "Running tests in #{klass}", "#{project_name} file change detected", :pending # notify any interested listeners
45
+ result = do_shell(focused_command)
46
+ result = run_test_class(klass) unless result == :failed
47
+ result_description = "#{project_name}: test run for #{klass}"
48
+
49
+ notify result_description, "Build #{result.to_s.capitalize}", result # Notify of success or failure
50
+
51
+ if result == :success && @options[:all_after_pass]
52
+ run_all
53
+ end
54
+ nil
55
+ end
56
+
57
+ def focused_command
58
+ @options[:focused_cli]
59
+ end
60
+
61
+ def all_command
62
+ @options[:all_cli]
63
+ end
64
+
65
+ def notify(msg, title='', image=nil)
66
+ Notifier.notify(msg, title: title, image: image)
67
+ end
68
+
69
+ def do_shell(command)
70
+ IO.popen(command) do |out|
71
+ until out.eof?
72
+ puts out.gets
73
+ end
74
+ end
75
+
76
+ code = $? # Get the status code of the last-finished process
77
+ (code == 0) ? :success : :failed
78
+ end
79
+
80
+
81
+ def run_test_class(klass)
82
+ test_command = "java -cp #{options[:classpath]} #{options[:test_runner_class]} #{klass}"
83
+ puts test_command
84
+ do_shell test_command
85
+ end
86
+ end
87
+
88
+ end
89
+
@@ -0,0 +1,12 @@
1
+ module ::Guard
2
+ class JavaTranslator
3
+ class << self
4
+ def filename_to_classname(filename_path, src_root_path='src/')
5
+ klass = filename_path.gsub(src_root_path, '').gsub('/', '.').gsub('.java', '')
6
+ klass = klass[1..-1] if klass[0] == '.'
7
+ klass
8
+ end
9
+ end
10
+ end
11
+ end
12
+
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-java
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Tony C. Heupel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: guard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.11'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.11'
69
+ description: Guard::Java automatically run your unit tests when you save files (much
70
+ like Eclipse's Build on Save
71
+ email:
72
+ - tony@heupel.net
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - lib/guard/java/templates/Guardfile
78
+ - lib/guard/java/version.rb
79
+ - lib/guard/java.rb
80
+ - lib/guard/java_translator.rb
81
+ - LICENSE
82
+ - README.md
83
+ homepage: http://github.com/infospace/guard-java
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: 1.3.6
101
+ requirements: []
102
+ rubyforge_project: guard-rspec
103
+ rubygems_version: 2.0.3
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Guard gem for Java
107
+ test_files: []