use of org.apache.archiva.configuration.RepositoryCheckPath in project archiva by apache.
the class DefaultRemoteRepositoryAdmin method addRemoteRepository.
@Override
public Boolean addRemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository, AuditInformation auditInformation) throws RepositoryAdminException {
triggerAuditEvent(remoteRepository.getId(), null, AuditEvent.ADD_REMOTE_REPO, auditInformation);
getRepositoryCommonValidator().basicValidation(remoteRepository, false);
// TODO we can validate it's a good uri/url
if (StringUtils.isEmpty(remoteRepository.getUrl())) {
throw new RepositoryAdminException("url cannot be null");
}
// MRM-752 - url needs trimming
// MRM-1940 - URL should not end with a slash
remoteRepository.setUrl(StringUtils.stripEnd(StringUtils.trim(remoteRepository.getUrl()), "/"));
if (StringUtils.isEmpty(remoteRepository.getCheckPath())) {
String checkUrl = remoteRepository.getUrl().toLowerCase();
for (RepositoryCheckPath path : getArchivaConfiguration().getConfiguration().getArchivaDefaultConfiguration().getDefaultCheckPaths()) {
log.debug("Checking path for urls: {} <-> {}", checkUrl, path.getUrl());
if (checkUrl.startsWith(path.getUrl())) {
remoteRepository.setCheckPath(path.getPath());
break;
}
}
}
Configuration configuration = getArchivaConfiguration().getConfiguration();
RemoteRepositoryConfiguration remoteRepositoryConfiguration = getRepositoryConfiguration(remoteRepository);
log.debug("Adding remote repo {}", remoteRepositoryConfiguration);
try {
repositoryRegistry.putRepository(remoteRepositoryConfiguration, configuration);
} catch (RepositoryException e) {
log.error("Could not add remote repository {}: {}", remoteRepositoryConfiguration.getId(), e.getMessage(), e);
throw new RepositoryAdminException("Adding of remote repository failed" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
}
saveConfiguration(configuration);
return Boolean.TRUE;
}
Aggregations