blob: 2f8c7fc24755a047057281686829985f93b2f62b [file] [log] [blame]
package org.eclipse.epp.installer.core.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.epp.installer.core.IErrorConstants;
/**
* Abstract base class for all install operations that actually install bits onto the drive.
* These operations consume information placed into {@link org.eclipse.epp.installer.core.InstallOptions}
* by {@link org.eclipse.epp.installer.core.model.IInstallStep}s.
*/
public abstract class InstallOperation implements IErrorConstants {
/**
* List of prerequisites executed before operation.
* Operation should fill with needed prerequisite operations.
*/
private List prerequisites;
/**
* Invoked by InstallModel in Prepare Phase.
*
* Why prepare? Well, installer may require relatively long steps (analyze
* files, etc) to decide (build) installation model, so it's recommended to
* add child operations in prepare method instead of constructor (etc) - to
* keep user updated with UI.
* @throws Exception
*/
protected void prepare() throws Exception {
}
/**
* Execure operation.
*
* @param installer Installation Context
* @return IStatus return operation execution status.
*/
protected IStatus run(Context installer) {
return Status.OK_STATUS;
}
/**
* Add prerequisite to list of prerequsites.
*
* If one prerequisite are added second time, if will be ignored.<br/>
* If derived class implemens {@link org.eclipse.epp.installer.core.model.ISequence} interface then
* last prerequisite before adding new will be added into <code>op</code> list of prerequisites.
*
* @param op InstallOperation prerequisite to add.
*/
protected void addPrerequisite(InstallOperation op) {
if (prerequisites == null) {
prerequisites = new ArrayList();
}
// check if operation already added.
// (we don't use Set to find last added operation for sequences)
if (prerequisites.contains(op)) {
return;
}
if (this instanceof ISequence) {
int size = prerequisites.size();
if (size > 0) {
InstallOperation last = (InstallOperation) prerequisites
.get(size - 1);
op.addPrerequisite(last);
}
}
prerequisites.add(op);
}
/**
* Return true if prerequisites list contains elements.
* @return boolean true if prerequisites not null.
*/
protected boolean hasPrerequisites() {
if( prerequisites == null ) {
return false;
}
return prerequisites.size() > 0;
}
/**
* Return current list of prerequisites.
* @return List of current prerequisites.
*/
protected List prerequisites() {
if (prerequisites == null) {
return Collections.EMPTY_LIST;
}
return prerequisites;
}
/*
* TODO think about API clearance (at this point only prerequisity type of
* relation exists)
*/
/**
* Add prerequisite operation.
* @param op InstallOperation
*/
public final void add(InstallOperation op) {
addPrerequisite(op);
}
}