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 2009/09/28 19:36:53 UTC
svn commit: r819657 - /buildr/trunk/lib/buildr/core/compile.rb
Author: boisvert
Date: Mon Sep 28 17:36:52 2009
New Revision: 819657
URL: http://svn.apache.org/viewvc?rev=819657&view=rev
Log:
Fix BUILDR-322 timestamp check for .java, .scala and .groovy files
Modified:
buildr/trunk/lib/buildr/core/compile.rb
Modified: buildr/trunk/lib/buildr/core/compile.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/compile.rb?rev=819657&r1=819656&r2=819657&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/compile.rb (original)
+++ buildr/trunk/lib/buildr/core/compile.rb Mon Sep 28 17:36:52 2009
@@ -175,14 +175,32 @@
FileList["#{source}/**/*.{#{ext_glob}}"].reject { |file| File.directory?(file) }.
each { |file| map[file] = File.join(target, Util.relative_path(file, source).ext(target_ext)) }
else
- map[source] = target # File.join(target, File.basename(source).ext(target_ext))
+ # try to extract package name from .java or .scala files
+ if ['.java', '.scala', '.groovy'].include? File.extname(source)
+ package = findFirst(source, /^\s*package\s+(\S+)\s*;?\s*$/)
+ map[source] = package ? File.join(target, package[1].gsub('.', '/'), File.basename(source).ext(target_ext)) : target
+ elsif
+ map[source] = target
+ end
end
map
end
end
+
+ private
- end
+ def findFirst(file, pattern)
+ match = nil
+ File.open(file, "r") do |infile|
+ while (line = infile.gets)
+ match = line.match(pattern)
+ break if match
+ end
+ end
+ match
+ end
+ end
end