Search in sources :

Example 1 with RemoteRepositoryConfiguration

use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.

the class ConfigurationRegistryReader method readRemoteRepositoryConfiguration.

private RemoteRepositoryConfiguration readRemoteRepositoryConfiguration(String prefix, Registry registry) {
    RemoteRepositoryConfiguration value = new RemoteRepositoryConfiguration();
    // String url = registry.getString( prefix + "url", value.getUrl() );
    List<String> urlList = registry.getList(prefix + "url");
    String url = value.getUrl();
    if (urlList != null && !urlList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = urlList.size(); i < size; i++) {
            sb.append(urlList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        url = sb.toString();
    }
    value.setUrl(url);
    // String username = registry.getString( prefix + "username", value.getUsername() );
    List<String> usernameList = registry.getList(prefix + "username");
    String username = value.getUsername();
    if (usernameList != null && !usernameList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = usernameList.size(); i < size; i++) {
            sb.append(usernameList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        username = sb.toString();
    }
    value.setUsername(username);
    // String password = registry.getString( prefix + "password", value.getPassword() );
    List<String> passwordList = registry.getList(prefix + "password");
    String password = value.getPassword();
    if (passwordList != null && !passwordList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = passwordList.size(); i < size; i++) {
            sb.append(passwordList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        password = sb.toString();
    }
    value.setPassword(password);
    int timeout = registry.getInt(prefix + "timeout", value.getTimeout());
    value.setTimeout(timeout);
    // String refreshCronExpression = registry.getString( prefix + "refreshCronExpression", value.getRefreshCronExpression() );
    List<String> refreshCronExpressionList = registry.getList(prefix + "refreshCronExpression");
    String refreshCronExpression = value.getRefreshCronExpression();
    if (refreshCronExpressionList != null && !refreshCronExpressionList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = refreshCronExpressionList.size(); i < size; i++) {
            sb.append(refreshCronExpressionList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        refreshCronExpression = sb.toString();
    }
    value.setRefreshCronExpression(refreshCronExpression);
    boolean downloadRemoteIndex = registry.getBoolean(prefix + "downloadRemoteIndex", value.isDownloadRemoteIndex());
    value.setDownloadRemoteIndex(downloadRemoteIndex);
    // String remoteIndexUrl = registry.getString( prefix + "remoteIndexUrl", value.getRemoteIndexUrl() );
    List<String> remoteIndexUrlList = registry.getList(prefix + "remoteIndexUrl");
    String remoteIndexUrl = value.getRemoteIndexUrl();
    if (remoteIndexUrlList != null && !remoteIndexUrlList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = remoteIndexUrlList.size(); i < size; i++) {
            sb.append(remoteIndexUrlList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        remoteIndexUrl = sb.toString();
    }
    value.setRemoteIndexUrl(remoteIndexUrl);
    // String remoteDownloadNetworkProxyId = registry.getString( prefix + "remoteDownloadNetworkProxyId", value.getRemoteDownloadNetworkProxyId() );
    List<String> remoteDownloadNetworkProxyIdList = registry.getList(prefix + "remoteDownloadNetworkProxyId");
    String remoteDownloadNetworkProxyId = value.getRemoteDownloadNetworkProxyId();
    if (remoteDownloadNetworkProxyIdList != null && !remoteDownloadNetworkProxyIdList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = remoteDownloadNetworkProxyIdList.size(); i < size; i++) {
            sb.append(remoteDownloadNetworkProxyIdList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        remoteDownloadNetworkProxyId = sb.toString();
    }
    value.setRemoteDownloadNetworkProxyId(remoteDownloadNetworkProxyId);
    int remoteDownloadTimeout = registry.getInt(prefix + "remoteDownloadTimeout", value.getRemoteDownloadTimeout());
    value.setRemoteDownloadTimeout(remoteDownloadTimeout);
    boolean downloadRemoteIndexOnStartup = registry.getBoolean(prefix + "downloadRemoteIndexOnStartup", value.isDownloadRemoteIndexOnStartup());
    value.setDownloadRemoteIndexOnStartup(downloadRemoteIndexOnStartup);
    java.util.Map extraParameters = registry.getProperties(prefix + "extraParameters");
    value.setExtraParameters(extraParameters);
    java.util.Map extraHeaders = registry.getProperties(prefix + "extraHeaders");
    value.setExtraHeaders(extraHeaders);
    // String checkPath = registry.getString( prefix + "checkPath", value.getCheckPath() );
    List<String> checkPathList = registry.getList(prefix + "checkPath");
    String checkPath = value.getCheckPath();
    if (checkPathList != null && !checkPathList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = checkPathList.size(); i < size; i++) {
            sb.append(checkPathList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        checkPath = sb.toString();
    }
    value.setCheckPath(checkPath);
    // String id = registry.getString( prefix + "id", value.getId() );
    List<String> idList = registry.getList(prefix + "id");
    String id = value.getId();
    if (idList != null && !idList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = idList.size(); i < size; i++) {
            sb.append(idList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        id = sb.toString();
    }
    value.setId(id);
    // String type = registry.getString( prefix + "type", value.getType() );
    List<String> typeList = registry.getList(prefix + "type");
    String type = value.getType();
    if (typeList != null && !typeList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = typeList.size(); i < size; i++) {
            sb.append(typeList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        type = sb.toString();
    }
    value.setType(type);
    // String name = registry.getString( prefix + "name", value.getName() );
    List<String> nameList = registry.getList(prefix + "name");
    String name = value.getName();
    if (nameList != null && !nameList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = nameList.size(); i < size; i++) {
            sb.append(nameList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        name = sb.toString();
    }
    value.setName(name);
    // String layout = registry.getString( prefix + "layout", value.getLayout() );
    List<String> layoutList = registry.getList(prefix + "layout");
    String layout = value.getLayout();
    if (layoutList != null && !layoutList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = layoutList.size(); i < size; i++) {
            sb.append(layoutList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        layout = sb.toString();
    }
    value.setLayout(layout);
    // String indexDir = registry.getString( prefix + "indexDir", value.getIndexDir() );
    List<String> indexDirList = registry.getList(prefix + "indexDir");
    String indexDir = value.getIndexDir();
    if (indexDirList != null && !indexDirList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = indexDirList.size(); i < size; i++) {
            sb.append(indexDirList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        indexDir = sb.toString();
    }
    value.setIndexDir(indexDir);
    // String packedIndexDir = registry.getString( prefix + "packedIndexDir", value.getPackedIndexDir() );
    List<String> packedIndexDirList = registry.getList(prefix + "packedIndexDir");
    String packedIndexDir = value.getPackedIndexDir();
    if (packedIndexDirList != null && !packedIndexDirList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = packedIndexDirList.size(); i < size; i++) {
            sb.append(packedIndexDirList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        packedIndexDir = sb.toString();
    }
    value.setPackedIndexDir(packedIndexDir);
    // String description = registry.getString( prefix + "description", value.getDescription() );
    List<String> descriptionList = registry.getList(prefix + "description");
    String description = value.getDescription();
    if (descriptionList != null && !descriptionList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = descriptionList.size(); i < size; i++) {
            sb.append(descriptionList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        description = sb.toString();
    }
    value.setDescription(description);
    return value;
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)

Example 2 with RemoteRepositoryConfiguration

use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration 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;
            }
        }
    }
    RemoteRepositoryConfiguration remoteRepositoryConfiguration = getRepositoryConfiguration(remoteRepository);
    log.debug("Adding remote repo {}", remoteRepositoryConfiguration);
    try {
        repositoryRegistry.putRepository(remoteRepositoryConfiguration);
    } 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()));
    }
    return Boolean.TRUE;
}
Also used : RepositoryCheckPath(org.apache.archiva.configuration.model.RepositoryCheckPath) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryException(org.apache.archiva.repository.RepositoryException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 3 with RemoteRepositoryConfiguration

use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.

the class DefaultRemoteRepositoryAdmin method getRepositoryConfiguration.

private RemoteRepositoryConfiguration getRepositoryConfiguration(org.apache.archiva.admin.model.beans.RemoteRepository repo) {
    RemoteRepositoryConfiguration repoConfig = new RemoteRepositoryConfiguration();
    setBaseRepoAttributes(repoConfig, repo);
    repoConfig.setUrl(getRepositoryCommonValidator().removeExpressions(repo.getUrl()));
    repoConfig.setRefreshCronExpression(repo.getCronExpression());
    repoConfig.setCheckPath(repo.getCheckPath());
    repoConfig.setExtraHeaders(repo.getExtraHeaders());
    repoConfig.setExtraParameters(repo.getExtraParameters());
    repoConfig.setUsername(repo.getUserName());
    repoConfig.setPassword(repo.getPassword());
    repoConfig.setTimeout(repo.getTimeout());
    repoConfig.setRemoteIndexUrl(repo.getRemoteIndexUrl());
    repoConfig.setDownloadRemoteIndex(repo.isDownloadRemoteIndex());
    repoConfig.setRemoteDownloadNetworkProxyId(repo.getRemoteDownloadNetworkProxyId());
    repoConfig.setDownloadRemoteIndexOnStartup(repo.isDownloadRemoteIndexOnStartup());
    repoConfig.setRemoteDownloadTimeout(repo.getRemoteDownloadTimeout());
    repoConfig.setDescription(repo.getDescription());
    repoConfig.setIndexDir(repo.getIndexDirectory());
    return repoConfig;
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)

Example 4 with RemoteRepositoryConfiguration

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

Example 5 with RemoteRepositoryConfiguration

use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.

the class AbstractRepositoryServletProxiedTestCase method setupCentralRemoteRepo.

protected void setupCentralRemoteRepo() throws Exception {
    remoteCentral = createServer("central");
    assertServerSetupCorrectly(remoteCentral);
    RemoteRepositoryConfiguration remoteRepositoryConfiguration = archivaConfiguration.getConfiguration().getRemoteRepositoriesAsMap().get(remoteCentral.id);
    if (remoteRepositoryConfiguration != null) {
        archivaConfiguration.getConfiguration().removeRemoteRepository(remoteRepositoryConfiguration);
    }
    archivaConfiguration.getConfiguration().addRemoteRepository(remoteCentral.config);
    setupCleanRepo(remoteCentral.root);
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)

Aggregations

RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)46 Configuration (org.apache.archiva.configuration.model.Configuration)17 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)14 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)14 RemoteRepository (org.apache.archiva.repository.RemoteRepository)12 ContextConfiguration (org.springframework.test.context.ContextConfiguration)11 ArrayList (java.util.ArrayList)9 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)9 EditableRemoteRepository (org.apache.archiva.repository.EditableRemoteRepository)9 RepositoryException (org.apache.archiva.repository.RepositoryException)8 Test (org.junit.Test)8 Path (java.nio.file.Path)7 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)7 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)7 Test (org.junit.jupiter.api.Test)7 HashMap (java.util.HashMap)6 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)6 PasswordCredentials (org.apache.archiva.repository.base.PasswordCredentials)6 Iterator (java.util.Iterator)5 List (java.util.List)5