Created
February 19, 2009 16:35
-
-
Save anonymous/66988 to your computer and use it in GitHub Desktop.
Update cleaner for Eclipse Ganymede
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# Author: Renato Silva | |
if not ARGV[1] =~ /\A[^--]*\z/ | |
goal = "Update cleaner for Eclipse Ganymede, version 2009.2.18" | |
usage = "Usage: #{File.basename($0)} <eclipse home> <target dir> [--all]\n\n\t--all\t Show ignored plugins" | |
puts "\n\t#{goal}\n\n\t#{usage}\n\n" | |
exit | |
end | |
home, target = ARGV[0..1].map { |arg| arg.gsub(/\\/, '/') } | |
show_ignored = (ARGV[2] == "--all") | |
require 'fileutils' | |
exit if File.file?(target) | |
FileUtils.makedirs(target) | |
PLUGIN_DATE = /v(\d{8})/ | |
ignored_plugins = [ "javax.wsdl" ] | |
unique_plugins = Hash.new | |
Dir["#{home}/plugins/*"].each do |plugin| | |
plugin_name = plugin[/([^\/]*)_/, 1] | |
if unique_plugins.keys.include?(plugin_name) | |
if show_ignored or not ignored_plugins.include?(plugin_name) | |
date_unique = unique_plugins[plugin_name][PLUGIN_DATE, 1].to_i | |
date_current = plugin[PLUGIN_DATE, 1].to_i | |
new, old = date_current, date_unique | |
if date_unique > date_current | |
new, old = date_unique, date_current | |
to_move = plugin | |
relation = '>' | |
elsif date_current > date_unique | |
to_move = unique_plugins[plugin_name] | |
unique_plugins.store(plugin_name, plugin) | |
relation = '>' | |
else | |
relation = '=' | |
end | |
if ignored_plugins.include?(plugin_name) | |
status = "ignored" | |
else | |
status = "kept" | |
if relation != '=' | |
FileUtils.move(to_move, target, :force => true) | |
if not File.exist?(to_move) | |
status = "SUCCESS" | |
elsif File.directory?(to_move) | |
status = "is dir" | |
end | |
end | |
end | |
puts "#{new} #{relation} #{old}: \t#{status}\t#{plugin_name} " | |
end | |
else | |
unique_plugins.store(plugin_name, plugin) | |
end | |
end | |
profile_ids = [] | |
profiles = "#{home}/p2/org.eclipse.equinox.p2.engine/profileRegistry/PlatformProfile.profile" | |
Dir["#{profiles}/*"].each { |profile| profile_ids << profile[/(\d+).profile$/, 1].to_i } | |
useless = profile_ids.sort.reverse[1..-1] | |
puts if useless.any? | |
useless.each do |id| | |
profile = "#{profiles}/#{id}.profile" | |
FileUtils.move(profile, target, :force => true) | |
status = File.exist?(profile)? "kept" : "moved" | |
puts "#{id}.profile #{status}" | |
end | |
rollback = "#{home}/p2/org.eclipse.equinox.p2.director/rollback/content.xml" | |
units = IO.read(rollback) | |
if units[/<units\s+size=["']?(\d+)["']?/, 1].to_i > 0 | |
units.gsub!(/<units.*units>/mi, "<units size='0'></units>") | |
FileUtils.move(rollback, target, :force => true) | |
end | |
status = File.exist?(rollback)? "kept" : "moved" | |
print "\n#{rollback[/[^\/]*$/]} #{status}" | |
File.new(rollback, 'w').write(units) | |
puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment