| package org.eclipse.epp.installer.internal.core; |
| |
| import java.io.File; |
| |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.Status; |
| import org.eclipse.epp.installer.core.IErrorConstants; |
| import org.eclipse.epp.installer.core.eclipse.EclipseInstallation; |
| import org.eclipse.epp.installer.core.eclipse.EclipseVersion; |
| import org.eclipse.epp.installer.core.model.Context; |
| import org.eclipse.epp.installer.core.model.IRollbackAction; |
| import org.eclipse.epp.installer.core.product.IProductVersion; |
| |
| |
| /** |
| * CleanEclipseConfigurationAction used to remove Eclipse configuration |
| * information. Do almost the same what does CleanEclipseConfigurationOperation. |
| * |
| * @author bur |
| * @version $Revision: 1.3 $ |
| */ |
| public class CleanEclipseConfigurationAction implements IRollbackAction { |
| |
| private static final EclipseVersion ECLIPSE_VER_3_0_0 = new EclipseVersion(3, 0, 0, ""); |
| |
| private EclipseInstallation installation; |
| |
| /** |
| * Method getRunningErrorStatus. |
| * @return IStatus |
| */ |
| private IStatus getRunningErrorStatus() { |
| String message = "Eclipse installation '" |
| + installation.getEclipseDir() + "' is running"; |
| return new Status(IStatus.ERROR, Context.PLUGIN_ID, |
| IErrorConstants.ERROR_ECLIPSE_ERROR, message, |
| null); |
| } |
| |
| /** |
| * Method getNoEclipseErrorStatus. |
| * @return IStatus |
| */ |
| private IStatus getNoEclipseErrorStatus() { |
| String message = "Can't find Eclipse installation '" |
| + installation.getEclipseDir() + "'"; |
| return new Status(IStatus.ERROR, Context.PLUGIN_ID, |
| IErrorConstants.ERROR_ECLIPSE_ERROR, message, |
| null); |
| } |
| |
| /** |
| * Execute action. |
| * |
| * @param entry |
| * InstallLogEntry to get data from. |
| * @return IStatus <code>Status.OK_STATUS</code> failures are saved. |
| * @see org.eclipse.epp.installer.core.model.IRollbackAction#rollback(InstallLogEntry) |
| */ |
| public IStatus rollback(InstallLogEntry entry) { |
| |
| File eclipseDir = new File(entry.getArgument()); |
| installation = new EclipseInstallation(eclipseDir); |
| |
| if (!EclipseInstallation.isEclipseInstallation(eclipseDir)) |
| return getNoEclipseErrorStatus(); |
| |
| if (installation.isRunning()) |
| return getRunningErrorStatus(); |
| |
| IProductVersion version = installation.getEclipseVersion(); |
| if (version.compareTo(ECLIPSE_VER_3_0_0) >= 0) { |
| cleanEclipse3(); |
| } |
| // TODO: add clean for other Eclipse versions |
| |
| return Status.OK_STATUS; |
| } |
| |
| private void cleanEclipse3() { |
| File eclipseDir = installation.getEclipseDir(); |
| |
| File eclipseConfigDir = new File(eclipseDir, "configuration"); |
| if (eclipseConfigDir.exists()) { |
| |
| File eclipseConfigCoreDir = new File(eclipseConfigDir, |
| "org.eclipse.core.runtime"); |
| if (eclipseConfigCoreDir.exists()) { |
| String[] exclusions = { ".keyring" }; |
| // TODO: this is a temporary solution, need to improve |
| // exceptions mechanism to some kind of filter mechanism |
| cleanDirectory(eclipseConfigCoreDir, exclusions, true); |
| } |
| |
| File eclipseConfigOsgiDir = new File(eclipseConfigDir, |
| "org.eclipse.osgi"); |
| if (eclipseConfigOsgiDir.exists()) { |
| cleanDirectory(eclipseConfigOsgiDir, null, false); |
| } |
| |
| File eclipseConfigUpdateDir = new File(eclipseConfigDir, |
| "org.eclipse.update"); |
| if (eclipseConfigUpdateDir.exists()) { |
| String[] exclusions; |
| IProductVersion version = installation.getEclipseVersion(); |
| // Preserve the platform.xml file for Eclipse 3.2 and beyond... see ModifyPlatformXMLOperationrun(Context) |
| if (version.getMajor() > 3 || (version.getMajor() == 3 && version.getMinor() >= 2)) |
| exclusions = new String[]{ "platform.xml", "bookmarks.xml" }; |
| else |
| exclusions = new String[]{ }; |
| cleanDirectory(eclipseConfigUpdateDir, exclusions, false); |
| } |
| } |
| } |
| |
| private void cleanDirectory(File dir, String[] exclusions, boolean keepFolder) { |
| File[] sub = dir.listFiles(); |
| if (sub != null) { |
| for (int i = 0; i < sub.length; i++) { |
| File curFile = sub[i]; |
| if(!isExcluded(curFile, exclusions)) |
| curFile.delete(); |
| } |
| } |
| if(!keepFolder) |
| dir.delete(); |
| } |
| |
| private boolean isExcluded(File file, String[] exclusions) { |
| if(exclusions == null) return false; |
| for(int i=0;i<exclusions.length;i++) |
| if(file.getName().equals(exclusions[i])) return true; |
| return false; |
| } |
| |
| /** |
| * Return action description. |
| * |
| * @param entry |
| * InstallLogEntry entry to get data from. |
| * @return String action description. |
| * @see org.eclipse.epp.installer.core.model.IRollbackAction#getDescription(InstallLogEntry) |
| */ |
| public String getDescription(InstallLogEntry entry) { |
| return "Cleaning Eclipse installation configuration information..."; |
| } |
| } |