try {
repo.defaultLocalStorageUrl = defaultStorageFile.toURI().toURL().toString();
}
catch (MalformedURLException e) {
// will not happen, not user settable
throw new InvalidConfigurationException("Malformed URL for LocalRepositoryStorage!", e);
}
String localUrl;
boolean usingDefaultLocalUrl;
if (repo.getLocalStorage() != null && !Strings.isNullOrEmpty(repo.getLocalStorage().getUrl())) {
localUrl = repo.getLocalStorage().getUrl();
usingDefaultLocalUrl = false;
}
else {
localUrl = repo.defaultLocalStorageUrl;
usingDefaultLocalUrl = true;
}
if (repo.getLocalStorage() == null) {
repo.setLocalStorage(new CLocalStorage());
repo.getLocalStorage().setProvider("file");
}
LocalRepositoryStorage ls = getLocalRepositoryStorage(repo.getId(), repo.getLocalStorage().getProvider());
try {
ls.validateStorageUrl(localUrl);
if (!usingDefaultLocalUrl) {
repo.getLocalStorage().setUrl(localUrl);
}
repository.setLocalStorage(ls);
// mark local storage context dirty, if applicable
final LocalStorageContext ctx = repository.getLocalStorageContext();
if (ctx != null) {
ctx.incrementGeneration();
}
}
catch (LocalStorageException e) {
ValidationResponse response = new ApplicationValidationResponse();
ValidationMessage error =
new ValidationMessage("overrideLocalStorageUrl", "Repository has an invalid local storage URL '"
+ localUrl, "Invalid file location");
response.addValidationError(error);
throw new InvalidConfigurationException(response);
}
// clear the NotFoundCache
if (repository.getNotFoundCache() != null) {
repository.getNotFoundCache().purge();