* @return
* @throws Exception
*/
private Runnable getUpdateAction(Program program, final RevisionRef current) throws Exception {
RevisionRef candidateRef = null;
Version candidate = toVersion(current.baseline, current.qualifier);
for (RevisionRef r : program.revisions) {
Version refVersion = toVersion(r.baseline, r.qualifier);
if (eq(r.classifier, current.classifier)) {
if (refVersion.compareTo(candidate) >= 0) {
candidate = refVersion;
candidateRef = r;
}
}
}
if (candidateRef == null)
//
// We're not present anymore, should never happen ...
//
return new Runnable() {
@Override
public void run() {
try {
index.delete(current.bsn, toVersion(current.baseline, current.qualifier));
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
public String toString() {
return "[delete]";
}
};
//
// Check if we are not same revision
//
if (!candidateRef.version.equals(current.version)) {
final RevisionRef toAdd = candidateRef;
return new Runnable() {
//
// Replace the current version
//
public void run() {
try {
index.delete(current.bsn, toVersion(current.baseline, current.qualifier));
index.addRevision(toAdd);
index.save();
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
public String toString() {
return toAdd.version;
}
};
}
//
// So now we are the same, check if the phase has changed
//
if (candidateRef.phase != current.phase) {
final RevisionRef toChange = candidateRef;
return new Runnable() {
@Override
public void run() {
try {