Search in sources :

Example 6 with ManagedRepositoriesService

use of org.apache.archiva.rest.api.services.ManagedRepositoriesService in project archiva by apache.

the class DownloadSnapshotTest method downloadSNAPSHOT.

@Test
public void downloadSNAPSHOT() throws Exception {
    Path tmpIndexDir = Paths.get(System.getProperty("java.io.tmpdir") + "/tmpIndex");
    if (Files.exists(tmpIndexDir)) {
        org.apache.archiva.common.utils.FileUtils.deleteDirectory(tmpIndexDir);
    }
    String id = Long.toString(System.currentTimeMillis());
    ManagedRepository managedRepository = new ManagedRepository(Locale.getDefault());
    managedRepository.setId(id);
    managedRepository.setName("name of " + id);
    managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/snapshot-repo");
    managedRepository.setIndexDirectory(System.getProperty("java.io.tmpdir") + "/tmpIndex/" + id);
    ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService();
    if (managedRepositoriesService.getManagedRepository(id) != null) {
        managedRepositoriesService.deleteManagedRepository(id, false);
    }
    getManagedRepositoriesService().addManagedRepository(managedRepository);
    RoleManagementService roleManagementService = getRoleManagementService(authorizationHeader);
    if (!roleManagementService.templatedRoleExists(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id)) {
        roleManagementService.createTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id);
    }
    getUserService(authorizationHeader).createGuestUser();
    roleManagementService.assignRole(ArchivaRoleConstants.TEMPLATE_GUEST, "guest");
    roleManagementService.assignTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id, "guest");
    getUserService(authorizationHeader).removeFromCache("guest");
    Path file = Paths.get("target/archiva-model-1.4-M4-SNAPSHOT.jar");
    Files.deleteIfExists(file);
    HttpWagon httpWagon = new HttpWagon();
    httpWagon.connect(new Repository("foo", "http://localhost:" + port));
    httpWagon.get("/repository/" + id + "/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-SNAPSHOT.jar", file.toFile());
    ZipFile zipFile = new ZipFile(file.toFile());
    List<String> entries = getZipEntriesNames(zipFile);
    ZipEntry zipEntry = zipFile.getEntry("org/apache/archiva/model/ArchivaArtifact.class");
    assertNotNull("cannot find zipEntry org/apache/archiva/model/ArchivaArtifact.class, entries: " + entries + ", content is: " + FileUtils.readFileToString(file.toFile(), Charset.forName("UTF-8")), zipEntry);
    zipFile.close();
    file.toFile().deleteOnExit();
}
Also used : Path(java.nio.file.Path) Repository(org.apache.maven.wagon.repository.Repository) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) HttpWagon(org.apache.maven.wagon.providers.http.HttpWagon) ZipFile(java.util.zip.ZipFile) RoleManagementService(org.apache.archiva.redback.rest.api.services.RoleManagementService) ZipEntry(java.util.zip.ZipEntry) Test(org.junit.Test)

Example 7 with ManagedRepositoriesService

use of org.apache.archiva.rest.api.services.ManagedRepositoriesService in project archiva by apache.

the class AbstractDownloadTest method getManagedRepositoriesService.

protected ManagedRepositoriesService getManagedRepositoriesService() {
    ManagedRepositoriesService service = JAXRSClientFactory.create(getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", ManagedRepositoriesService.class, Collections.singletonList(new JacksonJaxbJsonProvider()));
    WebClient.client(service).header("Authorization", authorizationHeader);
    WebClient.client(service).header("Referer", "http://localhost:" + port);
    WebClient.getConfig(service).getHttpConduit().getClient().setReceiveTimeout(300000L);
    return service;
}
Also used : ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) JacksonJaxbJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)

Example 8 with ManagedRepositoriesService

use of org.apache.archiva.rest.api.services.ManagedRepositoriesService in project archiva by apache.

the class DownloadArtifactFromQueryTest method createAndScanRepo.

protected String createAndScanRepo() throws Exception {
    Path tmpIndexDir = Paths.get(System.getProperty("java.io.tmpdir"), "tmpIndex");
    if (Files.exists(tmpIndexDir)) {
        FileUtils.deleteDirectory(tmpIndexDir.toFile());
    }
    String id = Long.toString(System.currentTimeMillis());
    ManagedRepository managedRepository = new ManagedRepository(Locale.getDefault());
    managedRepository.setId(id);
    managedRepository.setName("name of " + id);
    managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
    managedRepository.setIndexDirectory(System.getProperty("java.io.tmpdir") + "/tmpIndex/" + id);
    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.alreadyScanning(id)) {
        Thread.sleep(500);
        timeout -= 500;
    }
    return id;
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService)

Example 9 with ManagedRepositoriesService

use of org.apache.archiva.rest.api.services.ManagedRepositoriesService in project archiva by apache.

the class DownloadMergedIndexTest method downloadMergedIndex.

@Test
public void downloadMergedIndex() throws Exception {
    Path tmpIndexDir = Paths.get(System.getProperty("java.io.tmpdir"), "tmpIndex");
    if (Files.exists(tmpIndexDir)) {
        FileUtils.deleteDirectory(tmpIndexDir.toFile());
    }
    String id = Long.toString(System.currentTimeMillis());
    ManagedRepository managedRepository = new ManagedRepository(Locale.getDefault());
    managedRepository.setId(id);
    managedRepository.setName("name of " + id);
    managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
    managedRepository.setIndexDirectory(System.getProperty("java.io.tmpdir") + "/tmpIndex/" + id);
    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.alreadyScanning(id)) {
        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);
    repositoryGroup.setRepositories(Arrays.asList(id));
    repositoryGroupService.addRepositoryGroup(repositoryGroup);
    // create a repo with a remote on the one with index
    id = Long.toString(System.currentTimeMillis());
    managedRepository = new ManagedRepository(Locale.getDefault());
    managedRepository.setId(id);
    managedRepository.setName("name of " + id);
    managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
    managedRepository.setIndexDirectory(System.getProperty("java.io.tmpdir") + "/tmpIndex/" + id);
    if (managedRepositoriesService.getManagedRepository(id) != null) {
        managedRepositoriesService.deleteManagedRepository(id, false);
    }
    getManagedRepositoriesService().addManagedRepository(managedRepository);
    RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
    remoteRepository.setId("all-merged");
    remoteRepository.setName("all-merged");
    remoteRepository.setDownloadRemoteIndex(true);
    remoteRepository.setUrl("http://localhost:" + port + "/repository/test-group");
    remoteRepository.setRemoteIndexUrl("http://localhost:" + port + "/repository/test-group/.index");
    remoteRepository.setUserName(RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME);
    remoteRepository.setPassword(FakeCreateAdminService.ADMIN_TEST_PWD);
    if (getRemoteRepositoriesService().getRemoteRepository(remoteRepository.getId()) != null) {
        getRemoteRepositoriesService().deleteRemoteRepository(remoteRepository.getId());
    }
    getRemoteRepositoriesService().addRemoteRepository(remoteRepository);
    ProxyConnectorService proxyConnectorService = getProxyConnectorService();
    ProxyConnector proxyConnector = new ProxyConnector();
    proxyConnector.setProxyId("foo-bar1");
    proxyConnector.setSourceRepoId(id);
    proxyConnector.setTargetRepoId("all-merged");
    proxyConnectorService.addProxyConnector(proxyConnector);
    repositoriesService.scheduleDownloadRemoteIndex("all-merged", true, true);
    // wait a bit
    timeout = 20000;
    while (timeout > 0) {
        Thread.sleep(500);
        timeout -= 500;
    }
    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.maven2.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)

Example 10 with ManagedRepositoriesService

use of org.apache.archiva.rest.api.services.ManagedRepositoriesService in project archiva by apache.

the class ManagedRepositoriesServiceTest method addManagedRepo.

@Test
public void addManagedRepo() throws Exception {
    ManagedRepositoriesService service = getManagedRepositoriesService(authorizationHeader);
    ManagedRepository repo = getTestManagedRepository();
    if (service.getManagedRepository(repo.getId()) != null) {
        service.deleteManagedRepository(repo.getId(), true);
        assertNull(service.getManagedRepository(repo.getId()));
    }
    service.addManagedRepository(repo);
    repo = service.getManagedRepository(repo.getId());
    assertNotNull(repo);
    assertEquals(getTestManagedRepository().getDescription(), repo.getDescription());
    RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
    int timeout = 20000;
    while (timeout > 0 && repositoriesService.alreadyScanning(repo.getId())) {
        Thread.sleep(500);
        timeout -= 500;
    }
    service.deleteManagedRepository(repo.getId(), true);
    assertNull(service.getManagedRepository(repo.getId()));
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) Test(org.junit.Test)

Aggregations

ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)12 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)8 Test (org.junit.Test)8 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)7 Path (java.nio.file.Path)6 RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)3 RepositoryGroupService (org.apache.archiva.rest.api.services.RepositoryGroupService)3 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)2 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)2 Artifact (org.apache.archiva.maven2.model.Artifact)2 SearchRequest (org.apache.archiva.rest.api.model.SearchRequest)2 ProxyConnectorService (org.apache.archiva.rest.api.services.ProxyConnectorService)2 SearchService (org.apache.archiva.rest.api.services.SearchService)2 JacksonJaxbJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)1 Date (java.util.Date)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 RoleManagementService (org.apache.archiva.redback.rest.api.services.RoleManagementService)1 ArchivaRepositoryStatistics (org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics)1 HttpWagon (org.apache.maven.wagon.providers.http.HttpWagon)1