* @return <code>null</code> if a valid instance location has been set and an exit code
* otherwise
*/
private Object checkInstanceLocation(Shell shell, Map applicationArguments) {
// -data @none was specified but an ide requires workspace
Location instanceLoc = Platform.getInstanceLocation();
if (instanceLoc == null) {
MessageDialog
.openError(
shell,
IDEWorkbenchMessages.IDEApplication_workspaceMandatoryTitle,
IDEWorkbenchMessages.IDEApplication_workspaceMandatoryMessage);
return EXIT_OK;
}
// -data "/valid/path", workspace already set
if (instanceLoc.isSet()) {
// make sure the meta data version is compatible (or the user has
// chosen to overwrite it).
if (!checkValidWorkspace(shell, instanceLoc.getURL())) {
return EXIT_OK;
}
// at this point its valid, so try to lock it and update the
// metadata version information if successful
try {
if (instanceLoc.lock()) {
writeWorkspaceVersion();
return null;
}
// we failed to create the directory.
// Two possibilities:
// 1. directory is already in use
// 2. directory could not be created
File workspaceDirectory = new File(instanceLoc.getURL().getFile());
if (workspaceDirectory.exists()) {
if (isDevLaunchMode(applicationArguments)) {
return EXIT_WORKSPACE_LOCKED;
}
MessageDialog.openError(
shell,
IDEWorkbenchMessages.IDEApplication_workspaceCannotLockTitle,
IDEWorkbenchMessages.IDEApplication_workspaceCannotLockMessage);
} else {
MessageDialog.openError(
shell,
IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetTitle,
IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetMessage);
}
} catch (IOException e) {
IDEWorkbenchPlugin.log("Could not obtain lock for workspace location", //$NON-NLS-1$
e);
MessageDialog
.openError(
shell,
IDEWorkbenchMessages.InternalError,
e.getMessage());
}
return EXIT_OK;
}
// -data @noDefault or -data not specified, prompt and set
ChooseWorkspaceData launchData = new ChooseWorkspaceData(instanceLoc
.getDefault());
boolean force = false;
while (true) {
URL workspaceUrl = promptForWorkspace(shell, launchData, force);
if (workspaceUrl == null) {
return EXIT_OK;
}
// if there is an error with the first selection, then force the
// dialog to open to give the user a chance to correct
force = true;
try {
// the operation will fail if the url is not a valid
// instance data area, so other checking is unneeded
if (instanceLoc.setURL(workspaceUrl, true)) {
launchData.writePersistedData();
writeWorkspaceVersion();
return null;
}
} catch (IllegalStateException e) {