ivySettings.setBaseDir(javaProject.getProject().getLocation().toFile());
}
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 (" + this.toString()
+ ")", 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 (" + this.toString()
+ ")", 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("")) {
IFile f = javaProject.getProject().getFile(path);
File file = f.getLocation().toFile();
return getIvy(file);
} else {
try {
IJavaProject[] javaProjects = JavaCore.create(
ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects();
int i;
for (i = 0; i < javaProjects.length; i++) {
if (javaProjects[i].getProject().getName().equals(projectName)) {
break;
}
}
if (i == javaProjects.length) {
IvyDEException ex = new IvyDEException("Project '" + projectName
+ "' not found", "The project name '" + projectName + "' from '"
+ settingsPath + "' was not found (" + this.toString() + ")", null);
setConfStatus(ex);
throw ex;
}
IFile f = javaProjects[i].getProject().getFile(path);
File file = new File(f.getLocation().toOSString());
return getIvy(file);
} catch (JavaModelException e) {
IvyDEException ex = new IvyDEException("The workspace is broken",
"The projects in the workspace could not be listed when resolving the settings ("
+ this.toString() + ")", null);
setConfStatus(ex);
throw ex;
}
}
}
// 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 (" + this.toString()
+ ")", 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 = new IvySettings();
if (javaProject != null) {
ivySettings.setBaseDir(javaProject.getProject().getLocation().toFile());
}
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 ("
+ this.toString() + ")", 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 ("
+ this.toString() + ")", e);
setConfStatus(ex);
throw ex;
}