Search in sources :

Example 21 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class DefaultMergeRepositoriesService method mergeBySkippingConflicts.

public void mergeBySkippingConflicts(String sourceRepositoryId, String targetRepositoryId) throws RepositoryMergerException, ArchivaRestServiceException {
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        List<ArtifactMetadata> conflictSourceArtifacts = repositoryMerger.getConflictingArtifacts(repositorySession.getRepository(), sourceRepositoryId, targetRepositoryId);
        MetadataRepository metadataRepository = repositorySession.getRepository();
        List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts(sourceRepositoryId);
        sourceArtifacts.removeAll(conflictSourceArtifacts);
        ManagedRepository repository = managedRepositoryAdmin.getManagedRepository(targetRepositoryId);
        if (repository.isReleases() && !repository.isSnapshots()) {
            mergeWithOutSnapshots(metadataRepository, sourceArtifacts, sourceRepositoryId, targetRepositoryId);
        } else {
            Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>(sourceArtifacts);
            repositoryMerger.merge(metadataRepository, sourceRepositoryId, targetRepositoryId, artifactsWithOutConflicts);
            for (ArtifactMetadata metadata : sourceArtifacts) {
                triggerAuditEvent(targetRepositoryId, metadata.getId(), AuditEvent.MERGING_REPOSITORIES);
            }
        }
        doScanRepository(targetRepositoryId, false);
    } catch (MetadataRepositoryException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } finally {
        repositorySession.close();
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) IncludesFilter(org.apache.archiva.metadata.repository.filter.IncludesFilter) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 22 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class DownloadMergedIndexNonDefaultPathTest method downloadMergedIndexWithNonDefaultPath.

@Test
public void downloadMergedIndexWithNonDefaultPath() throws Exception {
    Path indexBaseDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve("archiva").resolve("remotedownloadtest");
    String indexBase = indexBaseDir.toString();
    FileUtils.deleteQuietly(indexBaseDir);
    if (!Files.exists(indexBaseDir)) {
        Files.createDirectories(indexBaseDir);
    }
    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(indexBase + "/index-" + id);
    managedRepository.setPackedIndexDirectory(indexBase + "/indexPacked-" + 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);
    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());
    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(indexBaseDir + "/index-" + id);
    managedRepository.setPackedIndexDirectory(indexBase + "/tmpIndexPacked-" + id);
    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(FakeCreateAdminService.ADMIN_TEST_PWD);
    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.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 23 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository 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 24 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class ArchivaDavResourceFactoryTest method createManagedRepository.

private ManagedRepository createManagedRepository(String id, String location, String layout) {
    ManagedRepository repoConfig = new ManagedRepository(Locale.getDefault());
    repoConfig.setId(id);
    repoConfig.setName(id);
    repoConfig.setLocation(location);
    repoConfig.setLayout(layout);
    return repoConfig;
}
Also used : EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository)

Example 25 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class AbstractRepositoryServletTestCase method assertRepositoryValid.

protected void assertRepositoryValid(RepositoryServlet servlet, String repoId) throws Exception {
    ManagedRepository repository = servlet.getRepository(repoId);
    assertNotNull("Archiva Managed Repository id:<" + repoId + "> should exist.", repository);
    Path repoRoot = Paths.get(repository.getLocation());
    assertTrue("Archiva Managed Repository id:<" + repoId + "> should have a valid location on disk.", Files.exists(repoRoot) && Files.isDirectory(repoRoot));
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository)

Aggregations

ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)46 Test (org.junit.Test)23 Path (java.nio.file.Path)20 AbstractRepositoryAdminTest (org.apache.archiva.admin.repository.AbstractRepositoryAdminTest)11 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)10 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)10 RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)9 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)8 ArrayList (java.util.ArrayList)7 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)7 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)5 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)5 RepositoryException (org.apache.archiva.repository.RepositoryException)5 IOException (java.io.IOException)4 Date (java.util.Date)4 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)4 ArtifactReference (org.apache.archiva.model.ArtifactReference)4 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)3 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)3 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)3