use of org.apache.archiva.maven.model.Artifact in project archiva by apache.
the class SearchServiceTest method searchArtifactVersions.
@Test
public void searchArtifactVersions() throws Exception {
// START SNIPPET: searchservice-artifact-versions
SearchService searchService = getSearchService(authorizationHeader);
List<Artifact> artifacts = searchService.getArtifactVersions("commons-logging", "commons-logging", "jar");
// END SNIPPET: searchservice-artifact-versions
assertNotNull(artifacts);
assertTrue(" not 13 results for commons-logging search but " + artifacts.size() + ":" + artifacts, artifacts.size() == 13);
log.info("artifacts for commons-logging size {} search {}", artifacts.size(), artifacts);
for (Artifact artifact : artifacts) {
log.info("url: {}", artifact.getUrl());
String version = artifact.getVersion();
assertTrue(artifact.getUrl().contains(version));
}
}
use of org.apache.archiva.maven.model.Artifact in project archiva by apache.
the class DownloadMergedIndexNonDefaultPathTest method downloadMergedIndexWithNonDefaultPath.
@Test
public void downloadMergedIndexWithNonDefaultPath() throws Exception {
Path indexBaseDir = indexDir.resolve("remotedownloadtest");
if (!Files.exists(indexBaseDir)) {
Files.createDirectories(indexBaseDir);
}
String id = Long.toString(System.currentTimeMillis());
Path srcRep = getProjectDirectory().resolve("src/test/repositories/test-repo");
Path testRep = getBasedir().resolve("target").resolve("test-repo-" + id).toAbsolutePath();
FileUtils.copyDirectory(srcRep.toFile(), testRep.toFile());
createdPaths.add(testRep);
ManagedRepository managedRepository = new ManagedRepository(Locale.getDefault());
managedRepository.setId(id);
managedRepository.setName("name of " + id);
managedRepository.setLocation(testRep.toString());
managedRepository.setIndexDirectory(indexBaseDir.resolve("index-" + id).toString());
managedRepository.setPackedIndexDirectory(indexBaseDir.resolve("indexPacked-" + id).toString());
ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService();
if (managedRepositoriesService.getManagedRepository(id) != null) {
managedRepositoriesService.deleteManagedRepository(id, false);
}
getManagedRepositoriesService().addManagedRepository(managedRepository);
RepositoriesService repositoriesService = getRepositoriesService();
repositoriesService.scanRepositoryNow(id, true);
// wait a bit to ensure index is finished
int timeout = 20000;
while (timeout > 0 && repositoriesService.getScanStatus(id).isAlreadyScanning()) {
Thread.sleep(500);
timeout -= 500;
}
RepositoryGroupService repositoryGroupService = getRepositoryGroupService();
String repoGroupId = "test-group";
if (repositoryGroupService.getRepositoryGroup(repoGroupId) != null) {
repositoryGroupService.deleteRepositoryGroup(repoGroupId);
}
RepositoryGroup repositoryGroup = new RepositoryGroup();
repositoryGroup.setId(repoGroupId);
String path = ".fooooo";
repositoryGroup.setRepositories(Arrays.asList(id));
repositoryGroup.setMergedIndexPath(path);
repositoryGroupService.addRepositoryGroup(repositoryGroup);
// create a repo with a remote on the one with index
id = Long.toString(System.currentTimeMillis());
Path srcRep2 = getProjectDirectory().resolve("src/test/repositories/test-repo");
Path testRep2 = getBasedir().resolve("target").resolve("test-repo-" + id).toAbsolutePath();
FileUtils.copyDirectory(srcRep2.toFile(), testRep2.toFile());
createdPaths.add(testRep2);
managedRepository = new ManagedRepository(Locale.getDefault());
managedRepository.setId(id);
managedRepository.setName("name of " + id);
managedRepository.setLocation(testRep2.toString());
managedRepository.setIndexDirectory(indexBaseDir.resolve("index-" + id).toString());
managedRepository.setPackedIndexDirectory(indexBaseDir.resolve("indexpacked-" + id).toString());
if (managedRepositoriesService.getManagedRepository(id) != null) {
managedRepositoriesService.deleteManagedRepository(id, false);
}
getManagedRepositoriesService().addManagedRepository(managedRepository);
String remoteId = Long.toString(System.currentTimeMillis());
RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
remoteRepository.setId(remoteId);
remoteRepository.setName(remoteId);
remoteRepository.setDownloadRemoteIndex(true);
remoteRepository.setUrl("http://localhost:" + port + "/repository/test-group");
remoteRepository.setRemoteIndexUrl("http://localhost:" + port + "/repository/test-group/" + path);
remoteRepository.setUserName(RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME);
remoteRepository.setPassword(BaseSetup.getAdminPwd());
getRemoteRepositoriesService().addRemoteRepository(remoteRepository);
ProxyConnectorService proxyConnectorService = getProxyConnectorService();
ProxyConnector proxyConnector = new ProxyConnector();
proxyConnector.setProxyId("foo-bar2");
proxyConnector.setSourceRepoId(id);
proxyConnector.setTargetRepoId(remoteId);
proxyConnectorService.addProxyConnector(proxyConnector);
repositoriesService.scheduleDownloadRemoteIndex(remoteId, true, true);
// wait the end
while (!repositoriesService.getRunningRemoteDownloadIds().getStrings().isEmpty()) {
Thread.sleep(500);
log.debug("still running remote download");
}
SearchService searchService = getSearchService();
SearchRequest request = new SearchRequest();
request.setRepositories(Arrays.asList(id));
request.setGroupId("org.apache.felix");
List<Artifact> artifacts = searchService.searchArtifacts(request);
assertThat(artifacts).isNotNull().isNotEmpty().hasSize(1);
}
Aggregations