Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Change Gem::Analyzer to not raise exceptions

For performance reasons.
  • Loading branch information...
commit d511ebdd3370873e511d4346b3186502efe62ce5 1 parent aa0ddf4
@ferrous26 authored
Showing with 21 additions and 10 deletions.
  1. +17 −4 lib/rubygems-compile/analyzer.rb
  2. +4 −6 lib/rubygems-compile/compiler.rb
View
21 lib/rubygems-compile/analyzer.rb
@@ -7,16 +7,29 @@
class Gem::Analyzer < Ripper::SexpBuilder
##
- # Raised in any case that the given code might display bad
- # behaviours that were not intended.
+ # Cache of issues found for the current session.
- class Warning < Exception
+ attr_reader :warnings
+
+ ##
+ # Check the given string of code for potential issues when compiled.
+ # Returns the analyzer instance afterwards.
+
+ def check code
+ @parser ||= Gem::Analyzer.new(code)
+ parser.parse
+ parser
+ end
+
+ def parse
+ @warnings = []
+ super
end
def on_kw token
# Related to MacRuby ticket #721
if token == '__FILE__'
- raise Warning, '__FILE__ keyword is used (MacRuby ticket #721)'
+ @warnings << '__FILE__ keyword is used (MacRuby ticket #721)'
end
end
View
10 lib/rubygems-compile/compiler.rb
@@ -26,8 +26,8 @@ def call gem
gem_files.each do |file|
message = compile_file_message(file)
full_path = absolute_path(file)
- if warning = unsafe?(full_path)
- message << "\t\t\tSKIPPED: #{warning.message}"
+ if unsafe? full_path
+ message << "\t\t\tSKIPPED: #{@parser.warnings.join(', ')}"
else
MacRuby::Compiler.compile_file(full_path)
end
@@ -41,10 +41,8 @@ def call gem
# any potential issues when compiled.
def unsafe? file
- Gem::Analyzer.new(File.read(file)).parse
- false
- rescue Gem::Analyzer::Warning => e
- e
+ @parser = Gem::Analyzer.check File.read(file)
+ !@parser.warnings.empty?
end
def gem_compilation_message
Please sign in to comment.
Something went wrong with that request. Please try again.