blob: a5e508de5dd0f03829ad048e469d7749bb3a0f48 [file] [log] [blame]
package org.eclipse.epp.installer.internal.console.steps;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.epp.installer.core.model.IInstallStep;
import org.eclipse.epp.installer.core.model.InstallOperation;
import org.eclipse.epp.installer.core.operations.UndoInstallOperation;
import org.eclipse.epp.installer.core.steps.RunOperationsStep;
import org.eclipse.epp.installer.internal.console.Console;
import org.eclipse.epp.installer.internal.console.ConsoleInstaller;
import org.eclipse.epp.installer.internal.console.ConsoleStep;
;
public class RunOperationsConsoleStep extends ConsoleStep{
public RunOperationsConsoleStep(IInstallStep step) {
super(step);
}
public IStatus prompt(Console console) throws Exception {
final IStatus[] status = new IStatus[1];
RunOperationsStep step = (RunOperationsStep) getInstallStep();
step.aboutToStep();
if(step.getTitle()!=null) console.writeln(step.getTitle());
if(step.getDescription()!=null)console.writeln(step.getDescription());
try {
status[0] = step.verifyStep();
} catch(Exception e) {
status[0] = new Status(IStatus.ERROR, ConsoleInstaller.PLUGIN_ID, 0,
"error running operations", e);
}
if(status[0].getSeverity() >= IStatus.ERROR) {
if(status[0].getSeverity() == IStatus.CANCEL ) {
console.writeln("Installing canceled.");
}
else {
}
if (step.canRollback()) {
InstallOperation rollback = new UndoInstallOperation(step.getInstaller().getInstallLog());
try {
getOperationRunnable(rollback).run(null);
}
catch (Exception e) {
return new Status(IStatus.ERROR, ConsoleInstaller.PLUGIN_ID, 0, "error running operations", e);
}
}
}
return Status.OK_STATUS;
}
private RunnableWithProgress getOperationRunnable(final InstallOperation operation) {
return new RunnableWithProgress() {
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
RunOperationsStep step = (RunOperationsStep) getInstallStep();
step.run(operation, monitor);
}
};
}
private interface RunnableWithProgress{
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException;
}
}