Services.getMessage("nature.alias.not.found", alias));
}
String interpreterPath = commandLine.getValue(Options.PATH_OPTION);
IInterpreterInstallType type = getInterpreterInstallType(nature, commandLine);
if (type == null){
throw new RuntimeException(
Services.getMessage("interpreter.type.not.found"));
}
IEnvironment env = EnvironmentManager.getLocalEnvironment();
IFileHandle file = PlatformFileUtils
.findAbsoluteOrEclipseRelativeFile(env, new Path(interpreterPath));
if (!file.exists()){
throw new RuntimeException(
Services.getMessage("interpreter.path.not.found", interpreterPath));
}
EnvironmentVariableContentProvider envVarsProvider =
new EnvironmentVariableContentProvider();
EnvironmentVariable[] envVars = envVarsProvider.getVariables();
LibraryLocation[] libs = type.getDefaultLibraryLocations(
file, envVars, new NullProgressMonitor());
IStatus status = type.validateInstallLocation(
file, envVars, libs, new NullProgressMonitor());
if (!status.isOK()){
throw new RuntimeException(status.getMessage());
}
IInterpreterInstall deflt =
ScriptRuntime.getDefaultInterpreterInstall(
new ScriptRuntime.DefaultInterpreterEntry(nature, env.getId()));
if (deflt != null && deflt.getInstallLocation().equals(file)){
throw new RuntimeException(
Services.getMessage("interpreter.already.exists", interpreterPath));
}
ArrayList<IInterpreterInstall> interpreters =
new ArrayList<IInterpreterInstall>();
IInterpreterInstallType[] types =
ScriptRuntime.getInterpreterInstallTypes(nature);
for (IInterpreterInstallType iit : types){
IInterpreterInstall[] installs = iit.getInterpreterInstalls();
for (IInterpreterInstall install : installs){
if (install.getInstallLocation().equals(file)){
throw new RuntimeException(
Services.getMessage("interpreter.already.exists", interpreterPath));
}
interpreters.add(install);
}
}
String name = commandLine.getValue(Options.NAME_OPTION);
if (name == null){
name = generateInterpreterName(file, nature);
}
String id = null;
do {
id = String.valueOf(System.currentTimeMillis());
} while (type.findInterpreterInstall(id) != null);
IInterpreterInstall install = new InterpreterStandin(type, id);
install.setInstallLocation(
new LazyFileHandle(env.getId(), new Path(interpreterPath)));
install.setName(name);