String name = raDir.getName();
Message buildInfo = INFO_UPGRADE_BUILD_ID_UNKNOWN.get();
Message date = INFO_GENERAL_UNKNOWN.get();
try {
File f = appendFilesDirIfNeccessary(raDir);
Installation i =
new Installation(f,f);
BuildInformation bi = i.getBuildInformation();
buildInfo = Message.raw(bi.toString());
} catch (Exception e) {
LOG.log(Level.INFO,
"Error determining archive version for " + name);
}
try {
Date d = new Date(Long.valueOf(name));
DateFormat df = DateFormat.getInstance();
date = Message.raw(df.format(d));
} catch (Exception e) {
LOG.log(Level.INFO, "Error converting reversion archive " +
"name " + name + " to date helper");
}
MessageBuilder mb = new MessageBuilder(name);
mb.append(" (");
mb.append(INFO_REVERSION_DIR_FROM_UPGRADE.get(buildInfo, date));
mb.append(")");
raDirChoiceList.add(mb.toMessage());
}
Message[] raDirChoices =
raDirChoiceList.toArray(new Message[0]);
if (raDirChoices.length > 0) {
MenuBuilder<Integer> builder = new MenuBuilder<Integer>(ui);
builder.setPrompt(INFO_REVERSION_DIR_PROMPT.get());
for (int i=0; i<raDirChoices.length; i++)
{
builder.addNumberedOption(raDirChoices[i],
MenuResult.success(i+1));
}
builder.setDefault(Message.raw(String.valueOf("1")),
MenuResult.success(1));
Menu<Integer> menu = builder.toMenu();
int resp;
try
{
MenuResult<Integer> m = menu.run();
if (m.isSuccess())
{
resp = m.getValue();
}
else
{
// Should never happen.
throw new RuntimeException();
}
}
catch (CLIException ce)
{
resp = 1;
LOG.log(Level.WARNING, "Error reading input: "+ce, ce);
}
File raDir = raDirs[resp - 1];
raDir = appendFilesDirIfNeccessary(raDir);
try {
ud.setReversionArchiveDirectory(
validateReversionArchiveDirectory(raDir));
} catch (UserDataException ude) {
System.err.println(ude.getMessageObject());
}
} else {
LOG.log(Level.INFO, "No archives in history dir");
throw new UserDataException(null,
INFO_REVERT_ERROR_NO_HISTORY_DIR.get());
}
} else {
LOG.log(Level.INFO, "History dir does not exist");
throw new UserDataException(null,
INFO_REVERT_ERROR_NO_HISTORY_DIR.get());
}
}
}
} else if (rl.isRevertMostRecent()) {
ud.setRevertMostRecent(true);
} else {
filesDir = rl.getReversionArchiveDirectory();
filesDir = appendFilesDirIfNeccessary(filesDir);
ud.setReversionArchiveDirectory(
validateReversionArchiveDirectory(filesDir));
}
if (ud.isRevertMostRecent()) {
Installation install = getInstallation();
File historyDir = install.getHistoryDirectory();
if (historyDir.exists()) {
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return !HISTORY_LOG_FILE_NAME.equals(name);
}