Changeset 32b8775b009de9d239164d3cc6d90cb12be2a4c5

Show
Ignore:
Timestamp:
07/08/2008 06:29:37 PM (1 month ago)
Author:
Jason Allen <jason@Macintosh-2.local>
git-committer:
Jason Allen <jason@Macintosh-2.local> 1215566977 -0700
git-parent:

[6f1f0318fd023239d33f93651669587fde208981]

git-author:
Jason Allen <jason@Macintosh-2.local> 1215566977 -0700
Message:

[FIX] Added a OHCOUNT_ROOT global so that included libs always work. We can now run tests just by calling 'ruby test/unit/xxx.rb'
[FIX] Added an exception to be thrown on Ohcount::parse if the polyglot passed is nil
[NEW] Ported the ohloh LicenseSniffer? to ohcount. Made it easy to add/edit test files.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • bin/ohcount

    r1fabcc0 r32b8775  
    9090  end 
    9191 
     92  # Licenses 
     93  def licenses 
     94    STDOUT.write "Examining #{files.size} file(s)" 
     95 
     96    puts 
     97    puts "File License Info" 
     98    puts "-----------------" 
     99 
     100    files.each do |file| 
     101      sfc = Ohcount::SimpleFileContext.new(file, files) 
     102      polyglot = Ohcount::Detector.detect(sfc) || next 
     103      comments = '' 
     104      Ohcount::parse(sfc.contents, polyglot) do |language, semantic, line| 
     105        comments << line if semantic == :comment 
     106      end 
     107      licenses = LicenseSniffer.sniff(comments) 
     108      if licenses.any? 
     109        license_names = licenses.collect { |l| LicenseSniffer::LicenseMap.instance.map[l].nice_name }.join(",") 
     110        puts "#{license_names} found in #{file}" 
     111      end 
     112    end 
     113  end 
     114 
    92115  def raw_entities 
    93116    files.each do |file| 
     
    134157   Prints the number of entities found for each language parsed. 
    135158 
    136 -re 
    137  
    138    Prints raw entity information to the screen (mainly for debugging). 
    139  
    140159-h, --help                      Display this message 
    141160 
     
    145164   emit a report of the lines of code, comments, and blanks in each 
    146165   language per file. 
     166 
     167-l, --license 
     168 
     169   Displays detected licensing information contained in each source 
     170   code file. 
     171 
     172-re 
     173 
     174   Prints raw entity information to the screen (mainly for debugging). 
    147175 
    148176-s, --summary                   Count lines of code (default) 
     
    288316    when '-i', '--individual' 
    289317      self.subcommand = :individual 
     318    when '-l', '--licenses' 
     319      self.subcommand = :licenses 
    290320    when '-e', '--entities' 
    291321      self.subcommand = :entities 
  • ext/ohcount_native/ruby_binding.c

    radfc63c r32b8775  
    123123static VALUE _ohcount_parse(VALUE self, VALUE buffer, VALUE polyglot_name_value) { 
    124124  ParseResult pr; 
     125 
     126  if (NIL_P(polyglot_name_value)) { 
     127    rb_raise(rb_eStandardError, "Polyglot name required."); 
     128  } 
    125129 
    126130  char *polyglot_name = RSTRING(polyglot_name_value)->ptr; 
  • lib/ohcount.rb

    rb4f9575 r32b8775  
    44require 'rbconfig' 
    55 
     6OHCOUNT_ROOT = File.dirname(__FILE__) + "/.." 
     7 
    68begin 
    79  require 'ohcount_native' 
    810rescue LoadError 
    9   require "#{Config::CONFIG['arch']}/ohcount_native" 
     11  require OHCOUNT_ROOT + "/lib/#{Config::CONFIG['arch']}/ohcount_native" 
    1012end 
    1113 
    12 require "ohcount/detector" 
    13 require "ohcount/parser" 
    14 require "ohcount/language_breakdown" 
    15 require "ohcount/sloc_info" 
    16 require "ohcount/scratch_dir" 
    17 require "ohcount/diff" 
    18 require "ohcount/simple_file_context" 
     14require OHCOUNT_ROOT + "/lib/ohcount/detector" 
     15require OHCOUNT_ROOT + "/lib/ohcount/parser" 
     16require OHCOUNT_ROOT + "/lib/ohcount/language_breakdown" 
     17require OHCOUNT_ROOT + "/lib/ohcount/sloc_info" 
     18require OHCOUNT_ROOT + "/lib/ohcount/scratch_dir" 
     19require OHCOUNT_ROOT + "/lib/ohcount/diff" 
     20require OHCOUNT_ROOT + "/lib/ohcount/simple_file_context" 
     21 
     22require OHCOUNT_ROOT + "/lib/licenses/license_sniffer" 
  • lib/ohcount/diff.rb

    r101d05d r32b8775  
    4747    langs = {} 
    4848    Dir.foreach(dir) do |l| 
     49      next unless File.directory?(dir + "/" + l) 
    4950      next if [".", ".."].include?(l) 
    5051      langs[l] ||= {} 
  • lib/ohcount/parser.rb

    rb4f9575 r32b8775  
     1require 'yaml' 
     2 
    13class Ohcount::Parser 
    24  # Parses a file, and store the results in files on disk. 
     
    1214  # file contains a count of the number of blank lines in the file. 
    1315  def self.parse_to_dir(args) 
    14     arg_keys = [ 
     16    required_arg_keys = [ 
    1517      :dir,       # directory to parse to 
    1618      :buffer,    # buffer contents of the what we're parsing 
    1719      :polyglot   # the polyglot name of what we're parsing 
    1820    ] 
    19     raise ArgumentError.new('Missing required args') unless (arg_keys - args.keys).empty? 
     21    raise ArgumentError.new('Missing required args') unless (required_arg_keys - args.keys).empty? 
    2022 
    2123    polyglot = args[:polyglot].to_s 
    2224    dir = args[:dir] 
    2325    buffer = args[:buffer].to_s 
     26    find_licenses = args[:find_licenses].to_s 
    2427 
    25     language_breakdowns = Ohcount::parse(buffer, polyglot) 
    26     language_breakdowns.each do |lb| 
     28    licenses = [] 
     29    Ohcount::parse(buffer, polyglot).each do |lb| 
    2730      lb_dest_dir = dir + "/" + lb.name 
    2831      Dir.mkdir(lb_dest_dir) 
     
    4043          io.write "\n" unless (comment.size == 0 || comment[-1,1] == "\n") 
    4144        end 
     45 
     46        # find licenses if required 
     47        licenses += LicenseSniffer.sniff(lb.comment) if find_licenses 
    4248      end 
    4349      File.open(lb_dest_dir + "/blanks", "w") do |io| 
    4450        io.write lb.blanks.to_s 
    4551      end 
    46     end 
    47   end 
     52    end 
     53 
     54    if licenses.any? 
     55      licenses.uniq! 
     56      File.open(dir + "/licenses.yaml", "w") do |io| 
     57        io.write licenses.to_yaml 
     58      end 
     59    end 
     60 
     61  end 
    4862end