Search in sources :

Example 1 with Configuration

use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.

the class Maven2RepositoryMergerTest method testMergeWithOutConflictArtifacts.

@Test
public void testMergeWithOutConflictArtifacts() throws Exception {
    String sourceRepoId = "source-repo";
    ArtifactMetadata artifact1 = new ArtifactMetadata();
    artifact1.setNamespace("org.testng");
    artifact1.setProject("testng");
    artifact1.setVersion("5.8");
    artifact1.setProjectVersion("5.8");
    artifact1.setId("testng-5.8-jdk15.jar");
    artifact1.setRepositoryId(sourceRepoId);
    List<ArtifactMetadata> sourceRepoArtifactsList = getArtifacts();
    sourceRepoArtifactsList.add(artifact1);
    List<ArtifactMetadata> targetRepoArtifactsList = getArtifacts();
    Configuration c = new Configuration();
    ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
    testRepo.setId(TEST_REPO_ID);
    testRepo.setLocation("target/test-repository");
    String sourceRepo = "src/test/resources/test-repository-with-conflict-artifacts";
    ManagedRepositoryConfiguration testRepoWithConflicts = new ManagedRepositoryConfiguration();
    testRepoWithConflicts.setId(sourceRepoId);
    testRepoWithConflicts.setLocation(sourceRepo);
    RepositoryScanningConfiguration repoScanConfig = new RepositoryScanningConfiguration();
    List<String> knownContentConsumers = new ArrayList<>();
    knownContentConsumers.add("metadata-updater");
    repoScanConfig.setKnownContentConsumers(knownContentConsumers);
    c.setRepositoryScanning(repoScanConfig);
    c.addManagedRepository(testRepo);
    c.addManagedRepository(testRepoWithConflicts);
    configuration.save(c);
    Path targetRepoFile = Paths.get("/target/test-repository/com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar");
    targetRepoFile.toFile().setReadOnly();
    when(metadataRepository.getArtifacts(session, sourceRepoId)).thenReturn(sourceRepoArtifactsList);
    when(metadataRepository.getArtifacts(session, TEST_REPO_ID)).thenReturn(targetRepoArtifactsList);
    assertEquals(1, repositoryMerger.getConflictingArtifacts(metadataRepository, sourceRepoId, TEST_REPO_ID).size());
    verify(metadataRepository).getArtifacts(session, TEST_REPO_ID);
}
Also used : Path(java.nio.file.Path) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ArrayList(java.util.ArrayList) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 2 with Configuration

use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.

the class Maven2RepositoryMergerTest method testMerge.

@Test
public void testMerge() throws Exception {
    String targetRepoPath = "target/test-repository-target";
    Path mergedArtifact = Paths.get(targetRepoPath, "com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar");
    Path mavenMetadata = Paths.get(targetRepoPath, "com/example/test/test-artifact/maven-metadata.xml");
    Path pom = Paths.get(targetRepoPath, "com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.pom");
    for (Path testArtifact : new Path[] { mergedArtifact, mavenMetadata, pom }) {
        Files.deleteIfExists(testArtifact);
    }
    assertFalse("Artifact file exists already", Files.exists(mergedArtifact));
    assertFalse("Metadata file exists already", Files.exists(mavenMetadata));
    assertFalse("Pom File exists already", Files.exists(pom));
    Configuration c = new Configuration();
    ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
    testRepo.setId(TEST_REPO_ID);
    testRepo.setLocation("target/test-repository");
    RepositoryScanningConfiguration repoScanConfig = new RepositoryScanningConfiguration();
    List<String> knownContentConsumers = new ArrayList<>();
    knownContentConsumers.add("metadata-updater12");
    repoScanConfig.setKnownContentConsumers(knownContentConsumers);
    c.setRepositoryScanning(repoScanConfig);
    ManagedRepositoryConfiguration targetRepo = new ManagedRepositoryConfiguration();
    targetRepo.setId("target-rep");
    targetRepo.setLocation(targetRepoPath);
    c.addManagedRepository(testRepo);
    c.addManagedRepository(targetRepo);
    configuration.save(c);
    when(metadataRepository.getArtifacts(session, TEST_REPO_ID)).thenReturn(getArtifacts());
    repositoryMerger.merge(metadataRepository, TEST_REPO_ID, "target-rep");
    verify(metadataRepository).getArtifacts(session, TEST_REPO_ID);
    assertTrue(Files.exists(mergedArtifact));
    assertTrue(Files.exists(mavenMetadata));
    assertTrue(Files.exists(pom));
}
Also used : Path(java.nio.file.Path) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ArrayList(java.util.ArrayList) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) Test(org.junit.Test)

Example 3 with Configuration

use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.

the class DefaultRemoteRepositoryAdmin method updateRemoteRepository.

@Override
public Boolean updateRemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository remoteRepository, AuditInformation auditInformation) throws RepositoryAdminException {
    String repositoryId = remoteRepository.getId();
    triggerAuditEvent(repositoryId, null, AuditEvent.MODIFY_REMOTE_REPO, auditInformation);
    // update means : remove and add
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    RemoteRepositoryConfiguration remoteRepositoryConfiguration = getRepositoryConfiguration(remoteRepository);
    try {
        repositoryRegistry.putRepository(remoteRepositoryConfiguration);
    } catch (RepositoryException e) {
        log.error("Could not update remote repository {}: {}", remoteRepositoryConfiguration.getId(), e.getMessage(), e);
        throw new RepositoryAdminException("Update of remote repository failed" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
    }
    return Boolean.TRUE;
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryException(org.apache.archiva.repository.RepositoryException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 4 with Configuration

use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.

the class DefaultRedbackRuntimeConfigurationAdmin method updateRedbackRuntimeConfiguration.

@Override
public void updateRedbackRuntimeConfiguration(RedbackRuntimeConfiguration redbackRuntimeConfiguration) throws RepositoryAdminException {
    org.apache.archiva.configuration.model.RedbackRuntimeConfiguration runtimeConfiguration = build(redbackRuntimeConfiguration);
    Configuration configuration = archivaConfiguration.getConfiguration();
    configuration.setRedbackRuntimeConfiguration(runtimeConfiguration);
    try {
        archivaConfiguration.save(configuration);
    } catch (RegistryException e) {
        throw new RepositoryAdminException(e.getMessage(), e);
    } catch (IndeterminateConfigurationException e) {
        throw new RepositoryAdminException(e.getMessage(), e);
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) CacheConfiguration(org.apache.archiva.admin.model.beans.CacheConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) LdapConfiguration(org.apache.archiva.admin.model.beans.LdapConfiguration) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) UserConfiguration(org.apache.archiva.redback.configuration.UserConfiguration) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RegistryException(org.apache.archiva.components.registry.RegistryException)

Example 5 with Configuration

use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.

the class ArchivaDavResourceFactoryTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    request = mock(DavServletRequest.class);
    response = mock(DavServletResponse.class);
    // responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
    archivaConfiguration = mock(ArchivaConfiguration.class);
    config = new Configuration();
    when(archivaConfiguration.getConfiguration()).thenReturn(config);
    when(archivaConfiguration.getDefaultLocale()).thenReturn(Locale.getDefault());
    archivaConfiguration.addListener(any());
    archivaConfiguration.save(eq(config));
    archivaConfiguration.save(eq(config), anyString());
    defaultManagedRepositoryAdmin.setArchivaConfiguration(archivaConfiguration);
    repositoryRegistry.setArchivaConfiguration(archivaConfiguration);
    repositoryRegistry.reload();
    ((DefaultRepositoryCommonValidator) defaultManagedRepositoryAdmin.getRepositoryCommonValidator()).setArchivaConfiguration(archivaConfiguration);
    if (defaultManagedRepositoryAdmin.getManagedRepository(RELEASES_REPO) == null) {
        defaultManagedRepositoryAdmin.addManagedRepository(createManagedRepository(RELEASES_REPO, getProjectBase().resolve("target/test-classes/" + RELEASES_REPO).toString(), "default"), false, null);
    }
    if (defaultManagedRepositoryAdmin.getManagedRepository(INTERNAL_REPO) == null) {
        defaultManagedRepositoryAdmin.addManagedRepository(createManagedRepository(INTERNAL_REPO, getProjectBase().resolve("target/test-classes/" + INTERNAL_REPO).toString(), "default"), false, null);
    }
    RepositoryGroup repoGroupConfig = new RepositoryGroup();
    repoGroupConfig.setId(LOCAL_REPO_GROUP);
    repoGroupConfig.addRepository(RELEASES_REPO);
    repoGroupConfig.addRepository(INTERNAL_REPO);
    defaultRepositoryGroupAdmin.setArchivaConfiguration(archivaConfiguration);
    if (defaultManagedRepositoryAdmin.getManagedRepository(LOCAL_REPO_GROUP) == null) {
        defaultRepositoryGroupAdmin.addRepositoryGroup(repoGroupConfig, null);
    }
    repoFactory = mock(RepositoryContentFactory.class);
    repoRequest = mock(MavenRepositoryRequestInfo.class);
    resourceFactory = new OverridingArchivaDavResourceFactory(applicationContext, archivaConfiguration);
    resourceFactory.setArchivaConfiguration(archivaConfiguration);
    proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).clear();
    proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).add(new OverridingRepositoryProxyHandler(this));
    resourceFactory.setProxyRegistry(proxyRegistry);
    resourceFactory.setRemoteRepositoryAdmin(remoteRepositoryAdmin);
    resourceFactory.setManagedRepositoryAdmin(defaultManagedRepositoryAdmin);
    resourceFactory.setRepositoryRegistry(repositoryRegistry);
    verify(archivaConfiguration, atLeast(2)).getConfiguration();
    verify(archivaConfiguration, atMost(25)).getConfiguration();
    verify(archivaConfiguration, atMost(4)).addListener(any());
    verify(archivaConfiguration, atMost(5)).save(eq(config));
    verify(archivaConfiguration, atMost(5)).save(eq(config), anyString());
}
Also used : DavServletRequest(org.apache.jackrabbit.webdav.DavServletRequest) MavenRepositoryRequestInfo(org.apache.archiva.maven.repository.content.MavenRepositoryRequestInfo) Configuration(org.apache.archiva.configuration.model.Configuration) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) RepositoryGroup(org.apache.archiva.admin.model.beans.RepositoryGroup) DavServletResponse(org.apache.jackrabbit.webdav.DavServletResponse) DefaultRepositoryCommonValidator(org.apache.archiva.admin.repository.DefaultRepositoryCommonValidator) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) RepositoryContentFactory(org.apache.archiva.repository.RepositoryContentFactory) Before(org.junit.Before)

Aggregations

Configuration (org.apache.archiva.configuration.model.Configuration)94 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)56 ContextConfiguration (org.springframework.test.context.ContextConfiguration)45 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)42 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)34 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)34 WebappConfiguration (org.apache.archiva.configuration.model.WebappConfiguration)32 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)29 Path (java.nio.file.Path)27 Test (org.junit.Test)26 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)23 RepositoryScanningConfiguration (org.apache.archiva.configuration.model.RepositoryScanningConfiguration)23 RepositoryException (org.apache.archiva.repository.RepositoryException)22 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)14 ManagedRepository (org.apache.archiva.repository.ManagedRepository)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)12 RemoteRepository (org.apache.archiva.repository.RemoteRepository)12 Test (org.junit.jupiter.api.Test)12 LegacyArtifactPath (org.apache.archiva.configuration.model.LegacyArtifactPath)11