Search in sources :

Example 1 with RepositoryContentProvider

use of org.apache.archiva.repository.RepositoryContentProvider in project archiva by apache.

the class RepositoryRequestTest method createManagedRepositoryContent.

protected ManagedRepositoryContent createManagedRepositoryContent(String id, String name, Path location, String layout) throws Exception {
    MavenManagedRepository repo = new MavenManagedRepository(id, name, archivaConfiguration.getRepositoryBaseDir());
    repo.setLocation(location.toAbsolutePath().toUri());
    repo.setLayout(layout);
    RepositoryContentProvider provider = applicationContext.getBean("repositoryContentProvider#maven", RepositoryContentProvider.class);
    ManagedRepositoryContent repoContent = provider.createManagedContent(repo);
    return repoContent;
}
Also used : RepositoryContentProvider(org.apache.archiva.repository.RepositoryContentProvider) MavenManagedRepository(org.apache.archiva.repository.maven2.MavenManagedRepository) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent)

Example 2 with RepositoryContentProvider

use of org.apache.archiva.repository.RepositoryContentProvider in project archiva by apache.

the class MetadataToolsTest method createTestRepoContent.

private ManagedRepositoryContent createTestRepoContent() throws Exception {
    Path repoRoot = Paths.get("target/metadata-tests/" + name.getMethodName());
    if (Files.exists(repoRoot)) {
        org.apache.archiva.common.utils.FileUtils.deleteDirectory(repoRoot);
    }
    Files.createDirectories(repoRoot);
    MavenManagedRepository repoConfig = createRepository("test-repo", "Test Repository: " + name.getMethodName(), repoRoot);
    RepositoryContentProvider provider = applicationContext.getBean("repositoryContentProvider#maven", RepositoryContentProvider.class);
    ManagedRepositoryContent repoContent = provider.createManagedContent(repoConfig);
    return repoContent;
}
Also used : Path(java.nio.file.Path) RepositoryContentProvider(org.apache.archiva.repository.RepositoryContentProvider) MavenManagedRepository(org.apache.archiva.repository.maven2.MavenManagedRepository) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent)

Example 3 with RepositoryContentProvider

use of org.apache.archiva.repository.RepositoryContentProvider in project archiva by apache.

the class MetadataToolsTest method assertSnapshotVersions.

private void assertSnapshotVersions(String artifactId, String version, String[] expectedVersions) throws Exception {
    Path repoRootDir = Paths.get("src/test/repositories/metadata-repository");
    VersionedReference reference = new VersionedReference();
    reference.setGroupId("org.apache.archiva.metadata.tests");
    reference.setArtifactId(artifactId);
    reference.setVersion(version);
    MavenManagedRepository repo = createRepository("test-repo", "Test Repository: " + name.getMethodName(), repoRootDir);
    RepositoryContentProvider provider = applicationContext.getBean("repositoryContentProvider#maven", RepositoryContentProvider.class);
    ManagedRepositoryContent repoContent = provider.createManagedContent(repo);
    Set<String> testedVersionSet = tools.gatherSnapshotVersions(repoContent, reference);
    // Sort the list (for asserts)
    List<String> testedVersions = new ArrayList<>();
    testedVersions.addAll(testedVersionSet);
    Collections.sort(testedVersions, new VersionComparator());
    // Test the expected array of versions, to the actual tested versions
    assertEquals("Assert Snapshot Versions: length/size", expectedVersions.length, testedVersions.size());
    for (int i = 0; i < expectedVersions.length; i++) {
        String actualVersion = testedVersions.get(i);
        assertEquals("Snapshot Versions[" + i + "]", expectedVersions[i], actualVersion);
    }
}
Also used : Path(java.nio.file.Path) VersionedReference(org.apache.archiva.model.VersionedReference) RepositoryContentProvider(org.apache.archiva.repository.RepositoryContentProvider) MavenManagedRepository(org.apache.archiva.repository.maven2.MavenManagedRepository) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ArrayList(java.util.ArrayList) VersionComparator(org.apache.archiva.common.utils.VersionComparator)

Example 4 with RepositoryContentProvider

use of org.apache.archiva.repository.RepositoryContentProvider in project archiva by apache.

the class AbstractRepositoryPurgeTest method getRepository.

public ManagedRepositoryContent getRepository() throws Exception {
    if (repo == null) {
        org.apache.archiva.repository.ManagedRepository repoCfg = getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME);
        RepositoryContentProvider provider = applicationContext.getBean("repositoryContentProvider#maven", RepositoryContentProvider.class);
        repo = provider.createManagedContent(repoCfg);
    }
    return repo;
}
Also used : RepositoryContentProvider(org.apache.archiva.repository.RepositoryContentProvider)

Example 5 with RepositoryContentProvider

use of org.apache.archiva.repository.RepositoryContentProvider in project archiva by apache.

the class ArchivaDavResourceFactoryTest method testRequestMetadataRepoIsLegacy.

@Test
public void testRequestMetadataRepoIsLegacy() throws Exception {
    ManagedRepositoryContent legacyRepo = createManagedRepositoryContent(LEGACY_REPO);
    ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
    RepositoryContentProvider provider = createRepositoryContentProvider(legacyRepo);
    beanFactory.registerSingleton("repositoryContentProvider#legacy", provider);
    RepositoryContentFactory repoContentFactory = applicationContext.getBean("repositoryContentFactory#default", RepositoryContentFactory.class);
    repoContentFactory.getRepositoryContentProviders().add(provider);
    defaultManagedRepositoryAdmin.addManagedRepository(createManagedRepository(LEGACY_REPO, Paths.get("target/test-classes/" + LEGACY_REPO).toString(), "legacy"), false, null);
    DavResourceLocator locator = new ArchivaDavResourceLocator("", "/repository/" + LEGACY_REPO + "/eclipse/maven-metadata.xml", LEGACY_REPO, new ArchivaDavLocatorFactory());
    // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
    RepositoryRequest repoRequest = new RepositoryRequest();
    resourceFactory.setRepositoryRequest(repoRequest);
    try {
        archivaConfigurationControl.reset();
        expect(archivaConfiguration.getConfiguration()).andReturn(config).times(2);
        expect(repoFactory.getManagedRepositoryContent(LEGACY_REPO)).andReturn(legacyRepo);
        expect(request.getMethod()).andReturn("GET").times(3);
        expect(request.getRemoteAddr()).andReturn("http://localhost:8080").times(3);
        expect(request.getDavSession()).andReturn(new ArchivaDavSession()).times(2);
        expect(request.getContextPath()).andReturn("").times(2);
        archivaConfigurationControl.replay();
        repoContentFactoryControl.replay();
        requestControl.replay();
        resourceFactory.createResource(locator, request, response);
        archivaConfigurationControl.verify();
        repoContentFactoryControl.verify();
        requestControl.verify();
        fail("A 404 error should have been thrown!");
    } catch (DavException e) {
        assertEquals(404, e.getErrorCode());
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) RepositoryContentProvider(org.apache.archiva.repository.RepositoryContentProvider) DavException(org.apache.jackrabbit.webdav.DavException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) RepositoryRequest(org.apache.archiva.repository.content.maven2.RepositoryRequest) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) RepositoryContentFactory(org.apache.archiva.repository.RepositoryContentFactory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator) Test(org.junit.Test)

Aggregations

RepositoryContentProvider (org.apache.archiva.repository.RepositoryContentProvider)7 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)6 MavenManagedRepository (org.apache.archiva.repository.maven2.MavenManagedRepository)5 Path (java.nio.file.Path)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ManagedRepositoryAdmin (org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin)1 DefaultManagedRepositoryAdmin (org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin)1 VersionComparator (org.apache.archiva.common.utils.VersionComparator)1 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)1 NetworkProxyConfiguration (org.apache.archiva.configuration.NetworkProxyConfiguration)1 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)1 VersionedReference (org.apache.archiva.model.VersionedReference)1 RepositoryProxyConnectors (org.apache.archiva.proxy.model.RepositoryProxyConnectors)1 RepositoryContentFactory (org.apache.archiva.repository.RepositoryContentFactory)1 RepositoryRegistry (org.apache.archiva.repository.RepositoryRegistry)1 RepositoryRequest (org.apache.archiva.repository.content.maven2.RepositoryRequest)1 DavException (org.apache.jackrabbit.webdav.DavException)1