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");
}
}
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());
}
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;
}
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);
}
}
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;
}
Aggregations