You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by bo...@apache.org on 2010/02/28 03:11:48 UTC
svn commit: r917091 - /buildr/trunk/doc/extending.textile
Author: boisvert
Date: Sun Feb 28 02:11:48 2010
New Revision: 917091
URL: http://svn.apache.org/viewvc?rev=917091&view=rev
Log:
Update LinesOfCode example to work (Chetan Sarva)
Modified:
buildr/trunk/doc/extending.textile
Modified: buildr/trunk/doc/extending.textile
URL: http://svn.apache.org/viewvc/buildr/trunk/doc/extending.textile?rev=917091&r1=917090&r2=917091&view=diff
==============================================================================
--- buildr/trunk/doc/extending.textile (original)
+++ buildr/trunk/doc/extending.textile Sun Feb 28 02:11:48 2010
@@ -91,6 +91,7 @@
{% highlight ruby %}
module LinesOfCode
+
include Extension
first_time do
@@ -101,28 +102,34 @@
before_define do |project|
# Define the loc task for this particular project.
- define_task 'loc' do |task|
- lines = task.prerequisites.map { |path| Dir["#{path}/**/*"] }.flatten.uniq.
- inject(0) { |total, file| total + File.readlines(file).count }
+ 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
end
after_define do |project|
# Now that we know all the source directories, add them.
- task('loc'=>compile.sources + compile.test.sources)
+ task('loc' => project.compile.sources + project.test.sources)
end
# To use this method in your project:
- # loc path_1, path_2
+ # loc path_1, path_2
def loc(*paths)
- task('loc'=>paths)
+ task('loc' => paths)
end
end
class Buildr::Project
- include LinesOfCode
+ include LinesOfCode
end
{% endhighlight %}