Search in sources :

Example 1 with RepositoryCheckPath

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;
}
Also used : RepositoryCheckPath(org.apache.archiva.configuration.RepositoryCheckPath) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) RepositoryException(org.apache.archiva.repository.RepositoryException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Aggregations

RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 Configuration (org.apache.archiva.configuration.Configuration)1 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)1 RepositoryCheckPath (org.apache.archiva.configuration.RepositoryCheckPath)1 RepositoryException (org.apache.archiva.repository.RepositoryException)1