| package org.eclipse.epp.installer.europa.javapackage; |
| |
| import java.io.File; |
| import java.text.MessageFormat; |
| |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.Status; |
| import org.eclipse.epp.installer.core.InstallOptions; |
| import org.eclipse.epp.installer.core.model.Context; |
| import org.eclipse.epp.installer.core.model.InstallOperation; |
| |
| /** |
| * <p> |
| * Copyright (c) 2006, Instantiations, Inc.<br> |
| * All Rights Reserved |
| */ |
| public class DeleteFileOperation extends InstallOperation { |
| |
| private File file; |
| private InstallOptions options; |
| |
| private boolean doBackupOption; |
| private boolean tempBackupOption; |
| |
| public DeleteFileOperation(InstallOptions options, File file) { |
| this(options, file, IBackupOptions.OPTION_DO_BACKUP); |
| } |
| |
| public DeleteFileOperation(InstallOptions options, File file, int settings) { |
| if (options == null || file == null) { |
| throw new IllegalArgumentException("file can't be null"); |
| } |
| this.file = file; |
| this.options = options; |
| |
| doBackupOption = ((settings & IBackupOptions.OPTION_DO_BACKUP) == IBackupOptions.OPTION_DO_BACKUP); |
| tempBackupOption = ((settings & IBackupOptions.OPTION_TEMP_BACKUP) == IBackupOptions.OPTION_TEMP_BACKUP); |
| } |
| |
| /** |
| * Method getErrorMessage. |
| * |
| * @return String |
| */ |
| private String getErrorMessage() { |
| String message = "Failed to delete file: " + file.getAbsolutePath(); |
| return message; |
| } |
| |
| |
| protected void prepare() throws Exception { |
| // if (!options.isNobackup()) |
| // |
| // if (file.exists()) |
| // if (doBackupOption) |
| // if (tempBackupOption || options.isNorestore()) { |
| // add(new BackupFileOperation(options, file, BackupManager.getBackupManager(), true)); |
| // } else { |
| // add(new BackupFileOperation(options, file, BackupManager.getBackupManager(), false)); |
| // } |
| } |
| |
| /** |
| * Method run. |
| * |
| * @param installer |
| * Context |
| * @return IStatus |
| */ |
| protected IStatus run(Context installer) { |
| if (file.exists()) |
| if (!file.delete()) |
| return new Status(Status.WARNING, Context.PLUGIN_ID, 0, |
| getErrorMessage(), null); |
| |
| return Status.OK_STATUS; |
| } |
| |
| /** |
| * Method toString. |
| * @return String |
| */ |
| public String toString() { |
| return MessageFormat.format("Deleting file {0}.", |
| new String[] { file.getAbsolutePath() }); |
| } |
| |
| public boolean equals(Object o) { |
| if(o instanceof DeleteFileOperation) { |
| DeleteFileOperation dfo = (DeleteFileOperation)o; |
| return file.equals(dfo.file); |
| } |
| return false; |
| } |
| |
| public int hashCode() { |
| return file.hashCode(); |
| } |
| } |