Search in sources :

Example 6 with Configuration

use of org.apache.archiva.configuration.Configuration in project archiva by apache.

the class DefaultRemoteRepositoryAdmin method updateRemoteRepository.

@Override
public Boolean updateRemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository, AuditInformation auditInformation) throws RepositoryAdminException {
    String repositoryId = remoteRepository.getId();
    triggerAuditEvent(repositoryId, null, AuditEvent.MODIFY_REMOTE_REPO, auditInformation);
    // update means : remove and add
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    RemoteRepositoryConfiguration remoteRepositoryConfiguration = getRepositoryConfiguration(remoteRepository);
    try {
        repositoryRegistry.putRepository(remoteRepositoryConfiguration, configuration);
    } catch (RepositoryException e) {
        log.error("Could not update remote repository {}: {}", remoteRepositoryConfiguration.getId(), e.getMessage(), e);
        throw new RepositoryAdminException("Update of remote repository failed" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
    }
    saveConfiguration(configuration);
    return Boolean.TRUE;
}
Also used : 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)

Example 7 with Configuration

use of org.apache.archiva.configuration.Configuration 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)

Example 8 with Configuration

use of org.apache.archiva.configuration.Configuration in project archiva by apache.

the class DefaultRedbackRuntimeConfigurationAdmin method updateRedbackRuntimeConfiguration.

@Override
public void updateRedbackRuntimeConfiguration(RedbackRuntimeConfiguration redbackRuntimeConfiguration) throws RepositoryAdminException {
    org.apache.archiva.configuration.RedbackRuntimeConfiguration runtimeConfiguration = build(redbackRuntimeConfiguration);
    Configuration configuration = archivaConfiguration.getConfiguration();
    configuration.setRedbackRuntimeConfiguration(runtimeConfiguration);
    try {
        archivaConfiguration.save(configuration);
    } catch (RegistryException e) {
        throw new RepositoryAdminException(e.getMessage(), e);
    } catch (IndeterminateConfigurationException e) {
        throw new RepositoryAdminException(e.getMessage(), e);
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) CacheConfiguration(org.apache.archiva.admin.model.beans.CacheConfiguration) LdapConfiguration(org.apache.archiva.admin.model.beans.LdapConfiguration) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) Configuration(org.apache.archiva.configuration.Configuration) UserConfiguration(org.apache.archiva.redback.configuration.UserConfiguration) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RegistryException(org.apache.archiva.redback.components.registry.RegistryException)

Example 9 with Configuration

use of org.apache.archiva.configuration.Configuration in project archiva by apache.

the class DefaultRepositoryCommonValidator method basicValidation.

/**
 * @param abstractRepository
 * @param update             in update mode if yes already exists won't be check
 * @throws RepositoryAdminException
 */
@Override
public void basicValidation(AbstractRepository abstractRepository, boolean update) throws RepositoryAdminException {
    Configuration config = archivaConfiguration.getConfiguration();
    String repoId = abstractRepository.getId();
    if (!update) {
        if (config.getManagedRepositoriesAsMap().containsKey(repoId)) {
            throw new RepositoryAdminException("Unable to add new repository with id [" + repoId + "], that id already exists as a managed repository.");
        } else if (config.getRepositoryGroupsAsMap().containsKey(repoId)) {
            throw new RepositoryAdminException("Unable to add new repository with id [" + repoId + "], that id already exists as a repository group.");
        } else if (config.getRemoteRepositoriesAsMap().containsKey(repoId)) {
            throw new RepositoryAdminException("Unable to add new repository with id [" + repoId + "], that id already exists as a remote repository.");
        }
    }
    if (StringUtils.isBlank(repoId)) {
        throw new RepositoryAdminException("Repository ID cannot be empty.");
    }
    if (!GenericValidator.matchRegexp(repoId, REPOSITORY_ID_VALID_EXPRESSION)) {
        throw new RepositoryAdminException("Invalid repository ID. Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-).");
    }
    String name = abstractRepository.getName();
    if (StringUtils.isBlank(name)) {
        throw new RepositoryAdminException("repository name cannot be empty");
    }
    if (!GenericValidator.matchRegexp(name, REPOSITORY_NAME_VALID_EXPRESSION)) {
        throw new RepositoryAdminException("Invalid repository name. Repository Name must only contain alphanumeric characters, white-spaces(' '), " + "forward-slashes(/), open-parenthesis('('), close-parenthesis(')'),  underscores(_), dots(.), and dashes(-).");
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) Configuration(org.apache.archiva.configuration.Configuration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 10 with Configuration

use of org.apache.archiva.configuration.Configuration in project archiva by apache.

the class DefaultProxyConnectorAdmin method deleteProxyConnector.

// FIXME take care of proxyConnectorRules !
@Override
public Boolean deleteProxyConnector(ProxyConnector proxyConnector, AuditInformation auditInformation) throws RepositoryAdminException {
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    ProxyConnectorConfiguration proxyConnectorConfiguration = findProxyConnector(proxyConnector.getSourceRepoId(), proxyConnector.getTargetRepoId(), configuration);
    if (proxyConnectorConfiguration == null) {
        throw new RepositoryAdminException("unable to find ProxyConnector with source " + proxyConnector.getSourceRepoId() + " and target " + proxyConnector.getTargetRepoId());
    }
    configuration.removeProxyConnector(proxyConnectorConfiguration);
    saveConfiguration(configuration);
    triggerAuditEvent(proxyConnector.getSourceRepoId() + "-" + proxyConnector.getTargetRepoId(), null, AuditEvent.DELETE_PROXY_CONNECTOR, auditInformation);
    return Boolean.TRUE;
}
Also used : ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Aggregations

Configuration (org.apache.archiva.configuration.Configuration)63 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)30 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)29 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)21 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)19 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)18 ContextConfiguration (org.springframework.test.context.ContextConfiguration)16 NetworkConfiguration (org.apache.archiva.admin.model.beans.NetworkConfiguration)13 UiConfiguration (org.apache.archiva.admin.model.beans.UiConfiguration)13 WebappConfiguration (org.apache.archiva.configuration.WebappConfiguration)13 IndeterminateConfigurationException (org.apache.archiva.configuration.IndeterminateConfigurationException)11 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)11 RegistryException (org.apache.archiva.redback.components.registry.RegistryException)11 Before (org.junit.Before)11 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 Path (java.nio.file.Path)8 RepositoryException (org.apache.archiva.repository.RepositoryException)7 IOException (java.io.IOException)4 NetworkProxyConfiguration (org.apache.archiva.configuration.NetworkProxyConfiguration)4