Mercurial > projects > dwt2
diff packageimport.rb @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children | a6998d2a84b3 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/packageimport.rb Sat Mar 14 18:23:29 2009 +0100 @@ -0,0 +1,61 @@ +require 'find' +require 'fileutils' +require 'set' + +def ProcessModule( path, modName, modList ) + puts "ProcessModule #{path}" + identifiers = Set.new + File.open(path).each_line do |s| + if s =~ /^[ \t]*\*/ then + next + end + s.split( /[^0-9A-Za-z_]/ ).each do |tok| + if tok =~ /^[_A-Z][_A-Za-z0-9]*$/ then + identifiers << tok + end + end + end + w=File.new(path+".new","w+") + File.open(path).each_line do |s| + if s =~/\/\/ packageimport$/ then + else + w.puts s + end + if s =~ /^module +((([a-zA-Z0-9_]+)\.)*)([a-zA-Z0-9_]+);/ then + packname = $1 + (modList-modName).intersection(identifiers).each do|id| + w.puts "import #{packname}#{id};" + end + end + end +end + +def ProcessDirectory( path ) + puts path + modList = Set.new + Dir.foreach(path) do |entry| + filename = File.join(path,entry) + if FileTest.file?(filename) && filename =~ /\.d$/ then + modList << entry[ 0 .. -3 ] + end + end + Dir.foreach(path) do |entry| + filename = File.join(path,entry) + if FileTest.file?(filename) && filename =~ /\.d$/ then + ProcessModule( filename, entry[ 0 .. -3 ], modList ) + end + end +end + +ARGV.each do|startpath| + puts "processing #{startpath}" + if !FileTest.directory?(startpath) then + raise "Argument is not a directory" + end + Find.find( startpath ) do |path| + if FileTest.directory?(path) then + ProcessDirectory(path) + end + end +end +