Class: SyntaxCheckAction
- Inherits:
-
BuildAction
- Object
- BuildAction
- SyntaxCheckAction
- Defined in:
- lib/kwala/actions/syntax_check.rb
Overview
Copyright © 2006, Ubiquitous Business Technology (ubit.com) All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Ubit nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author
Zev Blut ([email protected])
Instance Method Summary collapse
- #build_action(context) ⇒ Object
- #check_ruby_syntax(ruby_files) ⇒ Object
- #detailed_display(context) ⇒ Object
- #expand_syntax_check_template(data) ⇒ Object
-
#initialize ⇒ SyntaxCheckAction
constructor
A new instance of SyntaxCheckAction.
- #score ⇒ Object
- #summary_display(context) ⇒ Object
Methods inherited from BuildAction
command_line_action_name, command_line_action_names, create_action_from_command_line_name, detailed_template_file, summary_template_file
Methods included from InheritanceTracker
Constructor Details
#initialize ⇒ SyntaxCheckAction
Returns a new instance of SyntaxCheckAction.
43 44 45 |
# File 'lib/kwala/actions/syntax_check.rb', line 43 def initialize @syntax_results = nil end |
Instance Method Details
#build_action(context) ⇒ Object
47 48 49 |
# File 'lib/kwala/actions/syntax_check.rb', line 47 def build_action(context) @syntax_results = check_ruby_syntax(context.ruby_files) end |
#check_ruby_syntax(ruby_files) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/kwala/actions/syntax_check.rb', line 97 def check_ruby_syntax(ruby_files) # need kcode addition results = Array.new ruby_files.each do |f| entry = Hash.new #STDERR.puts "Checking with command:\nruby -KS -c #{f}" Open3.popen3("/usr/bin/env ruby -c #{f}") do |stdin, stdout, stderr| stdout_data = time_out_readlines(stdout) stderr_data = time_out_readlines(stderr) if stdout_data.first !~ /Syntax OK/ || stderr_data.size > 0 warnings, errors = stderr_data.partition {|r| r =~ /: warning:/} entry[:file_name] = f entry[:warnings] = warnings entry[:warning_count] = warnings.size entry[:errors] = errors entry[:error_count] = errors.size results << entry end end end results end |
#detailed_display(context) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/kwala/actions/syntax_check.rb', line 75 def detailed_display(context) context.amrita_data[:syntax_results] = { :entry => @syntax_results } det_res = (context.amrita_data[:syntax_results]) det_file = "#{context.output_directory}/#{context.project_name}_syntax.html" [det_file, det_res] end |
#expand_syntax_check_template(data) ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'lib/kwala/actions/syntax_check.rb', line 120 def (data) template = TemplateFile.new(self.class.detailed_template_file) data[:entry].each do |entry| entry[:file_name_ref] = Amrita::a(:name => entry[:file_name]) { entry[:file_name] } entry[:errors] = entry[:errors].to_a.map {|d| {:error => d} } entry[:warnings] = entry[:warnings].to_a.map {|d| {:warning => d} } end ProjectBuilderUtils.(template, data) end |
#score ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/kwala/actions/syntax_check.rb', line 84 def score return 10 if @syntax_results.empty? errors = @syntax_results.map { |e| e[:error_count] }.inject(0) { |s,v| s + v} if errors > 0 #errors > 10 ? -10 : 10 - errors # For now any sytnax error is bad. -100 else # must have warnings 3 is an arbitrary choice at the moment. 3 end end |
#summary_display(context) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/kwala/actions/syntax_check.rb', line 51 def summary_display(context) template = TemplateFile.new(self.class.summary_template_file) if @syntax_results.empty? context.amrita_data[:syntax_details] = "Syntax Check" context.amrita_data[:syntax_results] = "There are no syntax errors." else context.amrita_data[:syntax_results] = { :entry => @syntax_results } syntax_base = "#{context.project_name}_syntax.html" if context.amrita_data[:syntax_results][:entry] context.amrita_data[:syntax_results][:entry].each do |entry| entry[:file_name_link] = Amrita::a(:href => "#{syntax_base}\##{entry[:file_name]}") { entry[:file_name] } end end context.amrita_data[:syntax_details] = (Amrita::e(:a, :href=>syntax_base) { "Syntax Check Details" }) end (template, context) end |