if (ivy == null) {
IvySettings ivySettings = createIvySettings();
try {
ivySettings.loadDefault();
} catch (ParseException e) {
IvyDEException ex = new IvyDEException(
"Parsing error of the default Ivy settings",
"The default Ivy settings file could not be parsed: "
+ e.getMessage(), e);
setConfStatus(ex);
throw ex;
} catch (IOException e) {
IvyDEException ex = new IvyDEException(
"Read error of the default Ivy settings",
"The default Ivy settings file could not be read: "
+ e.getMessage(), e);
setConfStatus(ex);
throw ex;
}
ivy = Ivy.newInstance(ivySettings);
}
setConfStatus(null);
return ivy;
}
if (settingsPath.startsWith(PROJECT_SCHEME_PREFIX)) {
int pathIndex = settingsPath.indexOf("/", PROJECT_SCHEME_PREFIX_LENGTH);
String projectName = settingsPath.substring(PROJECT_SCHEME_PREFIX_LENGTH, pathIndex);
String path = settingsPath.substring(pathIndex + 1);
if (projectName.equals("")) {
File file = javaProject.getProject().getFile(path).getLocation().toFile();
if (!file.exists()) {
IvyDEException ex = new IvyDEException("Ivy settings file not found",
"The Ivy settings file '" + settingsPath + "' cannot be found", null);
setConfStatus(ex);
throw ex;
}
return getIvy(file);
} else {
IResource p = ResourcesPlugin.getWorkspace().getRoot().findMember(projectName);
if (p == null) {
IvyDEException ex = new IvyDEException("Project '" + projectName
+ "' not found", "The project name '" + projectName + "' from '"
+ settingsPath + "' was not found", null);
setConfStatus(ex);
throw ex;
}
File file = p.getProject().getFile(path).getLocation().toFile();
if (!file.exists()) {
IvyDEException ex = new IvyDEException("Ivy settings file not found",
"The Ivy settings file '" + path + "' cannot be found in project '"
+ projectName + "'", null);
setConfStatus(ex);
throw ex;
}
return getIvy(file);
}
}
// before returning the found ivy, try to refresh it if the settings changed
URL url;
try {
url = new URL(settingsPath);
} catch (MalformedURLException e) {
IvyDEException ex = new IvyDEException("Incorrect url of the Ivy settings",
"The Ivy settings url '" + settingsPath + "' is incorrect: "
+ e.getMessage(), e);
setConfStatus(ex);
throw ex;
}
if (url.getProtocol().startsWith("file")) {
File file = new File(url.getPath());
return getIvy(file);
} else {
// an URL but not a file
if (ivy == null || ivySettingsLastModified == -1) {
IvySettings ivySettings = createIvySettings();
try {
ivySettings.load(url);
ivySettingsLastModified = 0;
} catch (ParseException e) {
IvyDEException ex = new IvyDEException("Parsing error of the Ivy settings",
"The ivy settings file '" + settingsPath + "' could not be parsed: "
+ e.getMessage(), e);
setConfStatus(ex);
throw ex;
} catch (IOException e) {
IvyDEException ex = new IvyDEException("Read error of the Ivy settings",
"The ivy settings file '" + settingsPath + "' could not be read: "
+ e.getMessage(), e);
setConfStatus(ex);
throw ex;
}