You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by kw...@apache.org on 2006/08/25 18:32:18 UTC
svn commit: r436845 - /incubator/tuscany/java/etc/replaceheaders.rb
Author: kwilliams
Date: Fri Aug 25 09:32:14 2006
New Revision: 436845
URL: http://svn.apache.org/viewvc?rev=436845&view=rev
Log:
Adding file header replacement script to /etc
Added:
incubator/tuscany/java/etc/replaceheaders.rb
Added: incubator/tuscany/java/etc/replaceheaders.rb
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/etc/replaceheaders.rb?rev=436845&view=auto
==============================================================================
--- incubator/tuscany/java/etc/replaceheaders.rb (added)
+++ incubator/tuscany/java/etc/replaceheaders.rb Fri Aug 25 09:32:14 2006
@@ -0,0 +1,40 @@
+
+# Scans files - with a given extension - recursively from the current
+# directory replacing the old copyright/license header statement with a
+# new version
+#
+# Example command line usage
+# >ruby replaceheaders.rb java oldheader.txt newheader.txt
+
+ def munge_file(fn, oh, nh)
+ eoh = Regexp.escape(oh)
+ new_contents = File.read(fn).gsub!(Regexp.new(eoh), nh)
+ if new_contents
+ puts " processing #{fn}"
+ File.open(fn, 'w') do |file|
+ file.puts(new_contents)
+ end
+ $num_files_processed += 1
+ else
+ puts " processing #{fn} - NO MATCH!"
+ $num_files_no_match += 1
+ end
+ end
+
+if(!ARGV[0])
+ STDERR.puts "usage: <file extension> <old header file> <new header file>"
+ exit 0
+end
+
+ext = ARGV[0]
+$num_files_processed = $num_files_no_match = 0
+puts "Scanning files with #{ext} extension"
+old_header = File.read(ARGV[1])
+new_header = File.read(ARGV[2])
+Dir["**/*.#{ext}"].each do |filename|
+ munge_file( filename, old_header, new_header)
+end
+puts "Total files matched and processed = #{$num_files_processed}"
+puts "Number of files with no match = #{$num_files_no_match}"
+
+
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org