Search in sources :

Example 6 with RepositoryCredentials

use of org.apache.archiva.repository.RepositoryCredentials in project archiva by apache.

the class MavenRepositoryProvider method getRemoteConfiguration.

@Override
public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException {
    if (!(remoteRepository instanceof MavenRemoteRepository)) {
        log.error("Wrong remote repository type " + remoteRepository.getClass().getName());
        throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + remoteRepository.getClass().getName());
    }
    RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
    cfg.setType(remoteRepository.getType().toString());
    cfg.setId(remoteRepository.getId());
    cfg.setName(remoteRepository.getName());
    cfg.setDescription(remoteRepository.getDescription());
    cfg.setUrl(remoteRepository.getLocation().toString());
    cfg.setTimeout((int) remoteRepository.getTimeout().toMillis() / 1000);
    cfg.setCheckPath(remoteRepository.getCheckPath());
    RepositoryCredentials creds = remoteRepository.getLoginCredentials();
    if (creds != null) {
        if (creds instanceof PasswordCredentials) {
            PasswordCredentials pCreds = (PasswordCredentials) creds;
            cfg.setPassword(new String(pCreds.getPassword()));
            cfg.setUsername(pCreds.getUsername());
        }
    }
    cfg.setLayout(remoteRepository.getLayout());
    cfg.setExtraParameters(remoteRepository.getExtraParameters());
    cfg.setExtraHeaders(remoteRepository.getExtraHeaders());
    cfg.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
    IndexCreationFeature indexCreationFeature = remoteRepository.getFeature(IndexCreationFeature.class).get();
    cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
    cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
    RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class).get();
    cfg.setRemoteIndexUrl(remoteIndexFeature.getIndexUri().toString());
    cfg.setRemoteDownloadTimeout((int) remoteIndexFeature.getDownloadTimeout().get(ChronoUnit.SECONDS));
    cfg.setDownloadRemoteIndexOnStartup(remoteIndexFeature.isDownloadRemoteIndexOnStartup());
    cfg.setDownloadRemoteIndex(remoteIndexFeature.isDownloadRemoteIndex());
    cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
    return cfg;
}
Also used : RepositoryCredentials(org.apache.archiva.repository.RepositoryCredentials) PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RepositoryException(org.apache.archiva.repository.RepositoryException)

Aggregations

RepositoryCredentials (org.apache.archiva.repository.RepositoryCredentials)6 PasswordCredentials (org.apache.archiva.repository.PasswordCredentials)5 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)4 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)3 RemoteRepository (org.apache.archiva.repository.RemoteRepository)3 ManagedRepository (org.apache.archiva.repository.ManagedRepository)2 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)2 ConnectionException (org.apache.maven.wagon.ConnectionException)2 AuthenticationException (org.apache.maven.wagon.authentication.AuthenticationException)2 AuthenticationInfo (org.apache.maven.wagon.authentication.AuthenticationInfo)2 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)2 NetworkProxy (org.apache.archiva.admin.model.beans.NetworkProxy)1 RepositoryException (org.apache.archiva.repository.RepositoryException)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 Repository (org.apache.maven.model.Repository)1 Repository (org.apache.maven.wagon.repository.Repository)1