Skip to content

Instantly share code, notes, and snippets.

@chetan
Created February 23, 2010 19:49
Show Gist options
  • Save chetan/312621 to your computer and use it in GitHub Desktop.
Save chetan/312621 to your computer and use it in GitHub Desktop.
fixed LinesOfCode buildr task
module LinesOfCode
include Extension
first_time do
# Define task not specific to any projet.
desc 'Count lines of code in current project'
Project.local_task('loc')
end
before_define do |project|
# Define the loc task for this particular project.
project.recursive_task 'loc' do |task|
lines = task.prerequisites.map { |path|
Dir["#{path}/**/*"]
}.flatten.uniq.inject(0) { |total, file|
total = 0 if total.nil?
if File.file? file then
total + File.readlines(file).count
end
}
puts "Project #{project.name} has #{lines} lines of code"
end
end
after_define do |project|
# Now that we know all the source directories, add them.
task('loc' => project.compile.sources + project.test.sources)
end
# To use this method in your project:
# loc path_1, path_2
def loc(*paths)
task( 'loc' => paths)
end
end
class Buildr::Project
include LinesOfCode
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment