| package org.eclipse.epp.installer.internal.core; |
| |
| import java.io.File; |
| import java.text.MessageFormat; |
| import java.util.ArrayList; |
| import java.util.List; |
| |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.Status; |
| import org.eclipse.epp.installer.core.model.IRollbackAction; |
| |
| |
| /** |
| * RemoveFileAction used to remove files and directories. |
| * |
| * @author andrey |
| * @version $Revision: 1.1 $ |
| */ |
| public class RemoveFileAction implements IRollbackAction { |
| |
| /** |
| * List of delete failures. For each failure may be used |
| * {@link org.eclipse.epp.installer.internal.core.OS#DeleteFileOnReboot(String) } |
| * operation to delete files on reboot. |
| */ |
| private List failures = new ArrayList(); |
| |
| /** |
| * 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 file = new File(entry.getArgument()); |
| if (file.exists()) { |
| File[] list = file.listFiles(); |
| if (list != null && list.length > 0) { |
| failures.add(file); |
| } else { |
| if (!file.delete()) { |
| failures.add(file); |
| } |
| } |
| } |
| return Status.OK_STATUS; |
| /* |
| * return new Status(IStatus.INFO, Installer.PLUGIN_ID, 0, "Can't remove |
| * file or directory: " + file.getAbsolutePath(), null); |
| */ |
| } |
| |
| /** |
| * 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 MessageFormat.format("Removing file {0}.", new Object[] { entry |
| .getArgument() }); |
| } |
| |
| /** |
| * Return failure files list. |
| * |
| * @return List of failure files. |
| */ |
| public List getFailures() { |
| return failures; |
| } |
| } |