guard-maven 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jeremy Baker
2
+
3
+ MIT License
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Guard::Maven
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'guard-maven'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install guard-maven
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,4 @@
1
+ guard :maven, all_on_start: false, verbose: false do
2
+ watch(%r[src/main/.*/(.*)\.java$]) { |m| "#{m[1]}Test" }
3
+ watch(%r[src/test/.*/(.*)\.java$]) { |m| m[1] }
4
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module MavenVersion
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,153 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+ module Guard
5
+ class Maven < Guard
6
+
7
+ # Initializes a Guard plugin.
8
+ # Don't do any work here, especially as Guard plugins get initialized even if they are not in an active group!
9
+ #
10
+ # @param [Array<Guard::Watcher>] watchers the Guard plugin file watchers
11
+ # @param [Hash] options the custom Guard plugin options
12
+ # @option options [Symbol] group the group this Guard plugin belongs to
13
+ # @option options [Boolean] any_return allow any object to be returned from a watcher
14
+ #
15
+ def initialize(watchers = [], options = {})
16
+ super
17
+ @options = options
18
+ end
19
+
20
+ # Called once when Guard starts. Please override initialize method to init stuff.
21
+ #
22
+ # @raise [:task_has_failed] when start has failed
23
+ # @return [Object] the task result
24
+ #
25
+ def start
26
+ run_all if @options[:all_on_start]
27
+ end
28
+
29
+ # Called when just `enter` is pressed
30
+ # This method should be principally used for long action like running all specs/tests/...
31
+ #
32
+ # @raise [:task_has_failed] when run_all has failed
33
+ # @return [Object] the task result
34
+ #
35
+ def run_all
36
+ run_maven_tests
37
+ end
38
+
39
+ # Default behaviour on file(s) changes that the Guard plugin watches.
40
+ # @param [Array<String>] paths the changes files or paths
41
+ # @raise [:task_has_failed] when run_on_change has failed
42
+ # @return [Object] the task result
43
+ #
44
+ def run_on_changes(paths)
45
+ # for now run all
46
+ if paths.include? 'all'
47
+ run_all
48
+ else
49
+ run_maven_tests :classes => paths
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def notify(success, name, data={})
56
+ title = 'Maven Tests'
57
+ message = "Maven Test Results - #{data[:total_time]}:\n"
58
+ message += "Pass: #{data[:test_counts][:pass]} Fail: #{data[:test_counts][:fail]} Error: #{data[:test_counts][:error]} Skip: #{data[:test_counts][:skip]}"
59
+ image = success ? :success : :failed
60
+ Notifier.notify(message, title: title, image: image)
61
+ end
62
+
63
+ # Parses the results of the test run and
64
+ # returns useful information for reporting:
65
+ # - number of tests
66
+ # - number of failed tests
67
+ # - number of errors
68
+ # - number of skipped tests
69
+ # - total time
70
+ #
71
+ # @param results [String] The output of the test run
72
+ #
73
+ # @return [Hash] the relevant information
74
+ def parse_test_results(results)
75
+ data = { :success => true }
76
+
77
+ time = results.match(/\[INFO\] Total time: ([sm\d\.]+)/i)
78
+ data[:total_time] = time[1] if time
79
+
80
+ counts = results.match(/Tests run: (\d+), Failures: (\d+), Errors: (\d+), Skipped: (\d+)\n/)
81
+ if counts
82
+ data[:results] = counts[0]
83
+ data[:test_counts] = {
84
+ :total => counts[1].to_i,
85
+ :fail => counts[2].to_i,
86
+ :error => counts[3].to_i,
87
+ :skip => counts[4].to_i,
88
+ :pass => counts.to_a[1..-1].inject{|sum,x| sum.to_i - x.to_i }
89
+ }
90
+
91
+ data[:success] = false if counts[3].to_i + counts[2].to_i > 0
92
+ end
93
+
94
+ failures = results.match /Failed tests:(.*)\n\nTests run/im
95
+ data[:failures] = failures ? failures[1].split("\n").compact : []
96
+
97
+ data
98
+ end
99
+
100
+ def run_maven_tests(options={})
101
+ cmds = ['mvn', 'clean', 'test']
102
+
103
+ if options[:classes]
104
+ cmds << "-Dtest=#{options[:classes].join(',')}"
105
+ options[:name] ||= options[:classes].join("\n")
106
+ puts "Preparing tests for #{options[:classes].join(', ')}..."
107
+ else
108
+ puts "Preparing all tests..."
109
+ end
110
+
111
+ # User popen so that we can capture the test
112
+ # output as well as diplay it in terminal
113
+ output = []
114
+ IO.popen(cmds.join(' ')).each do |line|
115
+ if options[:verbose]
116
+ puts line.chomp
117
+ else
118
+ clean_output(line.chomp)
119
+ end
120
+ output << line.chomp
121
+ end
122
+ results = output.join("\n")
123
+
124
+ # Did the system command return successfully?
125
+ success = $?.success?
126
+
127
+ data = parse_test_results(results)
128
+ success = false unless data[:success]
129
+
130
+ unless options[:verbose]
131
+ puts "Failed Tests:\n#{data[:failures].join("\n")}"
132
+ end
133
+
134
+ notify(success, options[:name] || '', data)
135
+ end
136
+
137
+ def clean_output(line)
138
+ if line =~ /^Running/
139
+ puts line
140
+ elsif output = line.match(/Tests run: (\d+), Failures: (\d+), Errors: (\d+), Skipped: (\d+), Time elapsed:/)
141
+ match, total, fail, error, skip = output.to_a
142
+ pass = total.to_i - fail.to_i - error.to_i - skip.to_i
143
+ print "." * pass
144
+ print "E" * error.to_i
145
+ print "F" * fail.to_i
146
+ print "S" * skip.to_i
147
+ puts ""
148
+ else
149
+ # do nothing
150
+ end
151
+ end
152
+ end
153
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-maven
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeremy Baker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: guard
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.8.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.8.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Guard for Maven runs the clean and test commands for a Maven project
63
+ email:
64
+ - jhubert@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - lib/guard/maven/templates/Guardfile
70
+ - lib/guard/maven/version.rb
71
+ - lib/guard/maven.rb
72
+ - LICENSE.txt
73
+ - README.md
74
+ homepage: https://github.com/jhubert/guard-maven
75
+ licenses:
76
+ - MIT
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.23
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Guard for Maven
99
+ test_files: []
100
+ has_rdoc: