Permalink
Browse files

Created rename_packages! method

  • Loading branch information...
Andrey Paramonov
Andrey Paramonov committed Jun 9, 2009
1 parent b914b14 commit eb7f0ee216ea4e61fdd35e17182828531bb97795
Showing with 16 additions and 2 deletions.
  1. +16 −2 rename_package.rb
View
@@ -3,6 +3,8 @@
class Refactorer
include FileUtils
+ FILE_EXTENSIONS = %{ .java .groovy .xml .properties }
+
def initialize source_pkg, dest_pkg, work_dir = Dir.pwd
@source_pkg, @dest_pkg, @work_dir = source_pkg, dest_pkg, work_dir
end
@@ -18,6 +20,8 @@ def refactor
to_path = "#{source_path[:base_path]}#{dest_subpath}"
move_path! from_path, to_path
end
+
+ rename_packages!
end
private
@@ -29,18 +33,28 @@ def pkg_to_subpath pkg_name
def restore_paths sub_path
result = []
Dir.glob("#{@work_dir}/**/*").each do |path|
- result << {:base_path => "#{$`}", :full_path => path} if path =~ /(#{sub_path})$/ and File.directory? path
+ result << {base_path: "#{$`}", full_path: path} if path =~ /(#{sub_path})$/ and File.directory? path
end
result
end
def move_path! from_path, to_path
puts "Moving #{from_path}/* to #{to_path}"
- mkdir_p to_path if !File.exists? to_path
+ mkdir_p to_path unless File.exists? to_path
mv Dir.glob("#{from_path}/*"), to_path
remove_entry from_path
end
+ def rename_packages!
+ source_pkg_pattern = @source_pkg.gsub(/\./, '\.')
+ Dir.glob("#{@work_dir}/**/*").each do |file|
+ if File.file? file and FILE_EXTENSIONS.include? File.extname(file)
+ content = File.read file
+ content.gsub! Regexp.new(source_pkg_pattern), @dest_pkg
+ File.open(file,"w") {|fw| fw << content}
+ end
+ end
+ end
end
refactorer = Refactorer.new 'apache.r.exp', 'ndpar.ruby'

0 comments on commit eb7f0ee

Please sign in to comment.