Search in sources :

Example 36 with Artifact

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));
    }
}
Also used : SearchService(org.apache.archiva.rest.api.services.SearchService) Artifact(org.apache.archiva.maven.model.Artifact) Test(org.junit.Test)

Example 37 with Artifact

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);
}
Also used : Path(java.nio.file.Path) SearchRequest(org.apache.archiva.rest.api.model.SearchRequest) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ProxyConnectorService(org.apache.archiva.rest.api.services.ProxyConnectorService) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) Artifact(org.apache.archiva.maven.model.Artifact) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) RepositoryGroup(org.apache.archiva.admin.model.beans.RepositoryGroup) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) SearchService(org.apache.archiva.rest.api.services.SearchService) RepositoryGroupService(org.apache.archiva.rest.api.services.RepositoryGroupService) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector) Test(org.junit.Test)

Aggregations

Artifact (org.apache.archiva.maven.model.Artifact)37 Test (org.junit.Test)29 SearchService (org.apache.archiva.rest.api.services.SearchService)14 BrowseService (org.apache.archiva.rest.api.services.BrowseService)11 SearchRequest (org.apache.archiva.rest.api.model.SearchRequest)9 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)8 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)8 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)7 Path (java.nio.file.Path)6 ArrayList (java.util.ArrayList)4 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)4 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)3 VersionsList (org.apache.archiva.rest.api.model.VersionsList)3 BadRequestException (javax.ws.rs.BadRequestException)2 ForbiddenException (javax.ws.rs.ForbiddenException)2 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)2 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)2 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)2 RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)2 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)2