.append(ReversionLauncher.REVERT_ARCHIVE_OPTION_LONG)
.append(", -")
.append(ReversionLauncher.REVERT_MOST_RECENT_OPTION_SHORT)
.append("/--")
.append(ReversionLauncher.REVERT_MOST_RECENT_OPTION_LONG);
throw new UserDataException(null,
INFO_REVERT_ERROR_NO_DIR.get(sb.toString()));
} else {
CliUserInteraction ui = new CliUserInteraction();
Message[] options = new Message[] {
INFO_REVERSION_TYPE_PROMPT_RECENT.get(),
INFO_REVERSION_TYPE_PROMPT_FILE.get()};
if (options[0].equals(ui.confirm(
INFO_REVERT_CONFIRM_TITLE.get(),
INFO_REVERSION_TYPE_PROMPT.get(),
INFO_REVERT_CONFIRM_TITLE.get(),
UserInteraction.MessageType.QUESTION,
options, options[0])))
{
ud.setRevertMostRecent(true);
} else {
ud.setRevertMostRecent(false);
// Present a list of reversion archive choices to the user.
// In the future perhaps we might also allow them to type
// freehand.
File historyDir = getInstallation().getHistoryDirectory();
if (historyDir != null && historyDir.exists()) {
// Print a wait message, this could take a while
System.out.println(formatter.getFormattedWithPoints(
INFO_REVERSION_DIR_WAIT.get()));
String[] historyChildren = historyDir.list();
Arrays.sort(historyChildren);
List<File> raDirList = new ArrayList<File>();
for (int i = historyChildren.length - 1; i >=0; i--) {
File raDirCandidate = new File(historyDir, historyChildren[i]);
if (isReversionFilesDirectory(raDirCandidate)) {
raDirList.add(raDirCandidate);
}
}
File[] raDirs = raDirList.toArray(new File[raDirList.size()]);
List<Message> raDirChoiceList = new ArrayList<Message>();
for (File raDir : raDirs) {
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()) {