Search in sources :

Example 1 with RemoteIndexFeature

use of org.apache.archiva.repository.features.RemoteIndexFeature in project archiva by apache.

the class ArchivaIndexManagerMock method createRemoteContext.

private IndexingContext createRemoteContext(RemoteRepository remoteRepository) throws IOException {
    Path appServerBase = archivaConfiguration.getAppServerBaseDir();
    String contextKey = "remote-" + remoteRepository.getId();
    // create remote repository path
    Path repoDir = remoteRepository.getLocalPath();
    if (!Files.exists(repoDir)) {
        Files.createDirectories(repoDir);
    }
    Path indexDirectory = null;
    // is there configured indexDirectory ?
    if (remoteRepository.supportsFeature(RemoteIndexFeature.class)) {
        RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get();
        indexDirectory = getIndexPath(remoteRepository);
        String remoteIndexUrl = calculateIndexRemoteUrl(remoteRepository.getLocation(), rif);
        try {
            return getIndexingContext(remoteRepository, contextKey, repoDir, indexDirectory, remoteIndexUrl);
        } catch (IndexFormatTooOldException e) {
            // existing index with an old lucene format so we need to delete it!!!
            // delete it first then recreate it.
            // 
            log.warn(// 
            "the index of repository {} is too old we have to delete and recreate it", remoteRepository.getId());
            org.apache.archiva.common.utils.FileUtils.deleteDirectory(indexDirectory);
            return getIndexingContext(remoteRepository, contextKey, repoDir, indexDirectory, remoteIndexUrl);
        }
    } else {
        throw new IOException("No remote index defined");
    }
}
Also used : Path(java.nio.file.Path) IndexFormatTooOldException(org.apache.maven.index_shaded.lucene.index.IndexFormatTooOldException) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) IOException(java.io.IOException)

Example 2 with RemoteIndexFeature

use of org.apache.archiva.repository.features.RemoteIndexFeature in project archiva by apache.

the class MavenRepositoryProviderTest method getRemoteConfiguration.

@Test
public void getRemoteConfiguration() throws Exception {
    MavenRemoteRepository repo = new MavenRemoteRepository("test01", "My Test repo", Paths.get("target/remotes"));
    repo.setLocation(new URI("https://this.is/a/test"));
    repo.setScanned(true);
    repo.setDescription(repo.getPrimaryLocale(), "This is a description");
    repo.setLayout("maven2");
    repo.setName(repo.getPrimaryLocale(), "test0003");
    repo.setSchedulingDefinition("0 0 05 ? * WED");
    RemoteIndexFeature remoteIndexFeature = repo.getFeature(RemoteIndexFeature.class).get();
    remoteIndexFeature.setProxyId("proxyabc");
    remoteIndexFeature.setDownloadTimeout(Duration.ofSeconds(54));
    remoteIndexFeature.setDownloadRemoteIndex(false);
    remoteIndexFeature.setIndexUri(new URI("/this/remote/.index"));
    remoteIndexFeature.setDownloadRemoteIndexOnStartup(true);
    IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
    indexCreationFeature.setIndexPath(new URI("/this/local/.index"));
    RemoteRepositoryConfiguration cfg = provider.getRemoteConfiguration(repo);
    assertEquals("https://this.is/a/test", cfg.getUrl());
    assertEquals("This is a description", cfg.getDescription());
    assertEquals("maven2", cfg.getLayout());
    assertEquals("test0003", cfg.getName());
    assertEquals("0 0 05 ? * WED", cfg.getRefreshCronExpression());
    assertEquals("/this/remote/.index", cfg.getRemoteIndexUrl());
    assertEquals("proxyabc", cfg.getRemoteDownloadNetworkProxyId());
    assertEquals(54, cfg.getRemoteDownloadTimeout());
    assertFalse(cfg.isDownloadRemoteIndex());
    assertTrue(cfg.isDownloadRemoteIndexOnStartup());
    assertEquals("/this/local/.index", cfg.getIndexDir());
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) URI(java.net.URI) Test(org.junit.Test)

Example 3 with RemoteIndexFeature

use of org.apache.archiva.repository.features.RemoteIndexFeature in project archiva by apache.

the class RepositoryProviderMock method getRemoteConfiguration.

@Override
public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException {
    RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration();
    configuration.setId(remoteRepository.getId());
    configuration.setName(remoteRepository.getName());
    configuration.setDescription(remoteRepository.getDescription());
    configuration.setLayout(remoteRepository.getLayout());
    configuration.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
    configuration.setCheckPath(remoteRepository.getCheckPath());
    configuration.setExtraHeaders(remoteRepository.getExtraHeaders());
    configuration.setExtraParameters(remoteRepository.getExtraParameters());
    configuration.setTimeout((int) remoteRepository.getTimeout().getSeconds());
    RepositoryCredentials creds = remoteRepository.getLoginCredentials();
    if (creds != null) {
        PasswordCredentials pwdCreds = (PasswordCredentials) creds;
        configuration.setUsername(pwdCreds.getUsername());
        configuration.setPassword(new String(pwdCreds.getPassword()));
    }
    configuration.setUrl(remoteRepository.getLocation() == null ? "" : remoteRepository.getLocation().toString());
    RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get();
    configuration.setDownloadRemoteIndex(rif.isDownloadRemoteIndex());
    configuration.setDownloadRemoteIndexOnStartup(rif.isDownloadRemoteIndexOnStartup());
    configuration.setIndexDir(rif.getIndexUri() == null ? "" : rif.getIndexUri().toString());
    configuration.setRemoteDownloadNetworkProxyId(rif.getProxyId());
    return configuration;
}
Also used : RepositoryCredentials(org.apache.archiva.repository.RepositoryCredentials) PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature)

Example 4 with RemoteIndexFeature

use of org.apache.archiva.repository.features.RemoteIndexFeature in project archiva by apache.

the class RepositoryProviderMock method updateRemoteInstance.

@Override
public void updateRemoteInstance(EditableRemoteRepository remoteRepository, RemoteRepositoryConfiguration configuration) throws RepositoryException {
    try {
        remoteRepository.setName(remoteRepository.getPrimaryLocale(), configuration.getName());
        remoteRepository.setBaseUri(new URI(""));
        remoteRepository.setDescription(remoteRepository.getPrimaryLocale(), configuration.getDescription());
        remoteRepository.setLayout(configuration.getLayout());
        remoteRepository.setSchedulingDefinition(configuration.getRefreshCronExpression());
        remoteRepository.setCheckPath(configuration.getCheckPath());
        remoteRepository.setExtraHeaders(configuration.getExtraHeaders());
        remoteRepository.setExtraParameters(configuration.getExtraParameters());
        remoteRepository.setTimeout(Duration.ofSeconds(configuration.getTimeout()));
        char[] pwd = configuration.getPassword() == null ? "".toCharArray() : configuration.getPassword().toCharArray();
        remoteRepository.setCredentials(new PasswordCredentials(configuration.getUsername(), pwd));
        remoteRepository.setLocation(new URI(configuration.getUrl() == null ? "" : configuration.getUrl()));
        RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get();
        rif.setDownloadRemoteIndexOnStartup(configuration.isDownloadRemoteIndexOnStartup());
        rif.setDownloadRemoteIndex(configuration.isDownloadRemoteIndex());
        rif.setIndexUri(new URI(configuration.getIndexDir()));
        rif.setDownloadTimeout(Duration.ofSeconds(configuration.getRemoteDownloadTimeout()));
        rif.setProxyId(configuration.getRemoteDownloadNetworkProxyId());
    } catch (Exception e) {
        throw new RepositoryException("Error", e);
    }
}
Also used : PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RepositoryException(org.apache.archiva.repository.RepositoryException) URI(java.net.URI) RepositoryException(org.apache.archiva.repository.RepositoryException)

Example 5 with RemoteIndexFeature

use of org.apache.archiva.repository.features.RemoteIndexFeature in project archiva by apache.

the class DefaultRemoteRepositoryAdmin method convertRepo.

/*
 * Conversion between the repository from the registry and the serialized DTO for the admin API
 */
private org.apache.archiva.admin.model.beans.RemoteRepository convertRepo(RemoteRepository repo) {
    if (repo == null) {
        return null;
    }
    org.apache.archiva.admin.model.beans.RemoteRepository adminRepo = new org.apache.archiva.admin.model.beans.RemoteRepository(getArchivaConfiguration().getDefaultLocale());
    setBaseRepoAttributes(adminRepo, repo);
    adminRepo.setUrl(convertUriToString(repo.getLocation()));
    adminRepo.setCronExpression(repo.getSchedulingDefinition());
    adminRepo.setCheckPath(repo.getCheckPath());
    adminRepo.setExtraHeaders(repo.getExtraHeaders());
    adminRepo.setExtraParameters(repo.getExtraParameters());
    adminRepo.setTimeout((int) repo.getTimeout().getSeconds());
    RepositoryCredentials creds = repo.getLoginCredentials();
    if (creds != null && creds instanceof PasswordCredentials) {
        PasswordCredentials pCreds = (PasswordCredentials) creds;
        adminRepo.setUserName(pCreds.getUsername());
        adminRepo.setPassword(new String(pCreds.getPassword() != null ? pCreds.getPassword() : new char[0]));
    }
    if (repo.supportsFeature(RemoteIndexFeature.class)) {
        RemoteIndexFeature rif = repo.getFeature(RemoteIndexFeature.class).get();
        adminRepo.setRemoteIndexUrl(convertUriToString(rif.getIndexUri()));
        adminRepo.setDownloadRemoteIndex(rif.isDownloadRemoteIndex());
        adminRepo.setRemoteDownloadNetworkProxyId(rif.getProxyId());
        adminRepo.setDownloadRemoteIndexOnStartup(rif.isDownloadRemoteIndexOnStartup());
        adminRepo.setRemoteDownloadTimeout((int) rif.getDownloadTimeout().getSeconds());
    }
    if (repo.supportsFeature(IndexCreationFeature.class)) {
        IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
        adminRepo.setIndexDirectory(PathUtil.getPathFromUri(icf.getIndexPath()).toString());
    }
    adminRepo.setDescription(repo.getDescription());
    return adminRepo;
}
Also used : RepositoryCredentials(org.apache.archiva.repository.RepositoryCredentials) PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) RemoteRepository(org.apache.archiva.repository.RemoteRepository) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature)

Aggregations

RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)20 PasswordCredentials (org.apache.archiva.repository.PasswordCredentials)12 URI (java.net.URI)8 Path (java.nio.file.Path)8 IOException (java.io.IOException)7 RemoteRepository (org.apache.archiva.repository.RemoteRepository)7 RepositoryException (org.apache.archiva.repository.RepositoryException)6 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)5 NetworkProxy (org.apache.archiva.admin.model.beans.NetworkProxy)5 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)5 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)5 WagonFactoryRequest (org.apache.archiva.proxy.common.WagonFactoryRequest)4 RepositoryCredentials (org.apache.archiva.repository.RepositoryCredentials)4 IndexUpdateRequest (org.apache.maven.index.updater.IndexUpdateRequest)4 ResourceFetcher (org.apache.maven.index.updater.ResourceFetcher)4 StreamWagon (org.apache.maven.wagon.StreamWagon)4 AuthenticationInfo (org.apache.maven.wagon.authentication.AuthenticationInfo)4 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)4 AbstractHttpClientWagon (org.apache.maven.wagon.shared.http.AbstractHttpClientWagon)4 HttpConfiguration (org.apache.maven.wagon.shared.http.HttpConfiguration)4