Search in sources :

Example 1 with RepositoryScanningConfiguration

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

the class ConfigurationRegistryReader method readRepositoryScanningConfiguration.

private RepositoryScanningConfiguration readRepositoryScanningConfiguration(String prefix, Registry registry) {
    RepositoryScanningConfiguration value = new RepositoryScanningConfiguration();
    java.util.List fileTypes = new java.util.ArrayList();
    List fileTypesSubsets = registry.getSubsetList(prefix + "fileTypes.fileType");
    for (Iterator i = fileTypesSubsets.iterator(); i.hasNext(); ) {
        FileType v = readFileType("", (Registry) i.next());
        fileTypes.add(v);
    }
    value.setFileTypes(fileTypes);
    java.util.List knownContentConsumers = new java.util.ArrayList();
    knownContentConsumers.addAll(registry.getList(prefix + "knownContentConsumers.knownContentConsumer"));
    value.setKnownContentConsumers(knownContentConsumers);
    java.util.List invalidContentConsumers = new java.util.ArrayList();
    invalidContentConsumers.addAll(registry.getList(prefix + "invalidContentConsumers.invalidContentConsumer"));
    value.setInvalidContentConsumers(invalidContentConsumers);
    return value;
}
Also used : List(java.util.List) FileType(org.apache.archiva.configuration.model.FileType) Iterator(java.util.Iterator) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) List(java.util.List)

Example 2 with RepositoryScanningConfiguration

use of org.apache.archiva.configuration.model.RepositoryScanningConfiguration 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 3 with RepositoryScanningConfiguration

use of org.apache.archiva.configuration.model.RepositoryScanningConfiguration 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 4 with RepositoryScanningConfiguration

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

the class MockConfiguration method initialize.

@PostConstruct
public void initialize() throws Exception {
    configuration.setRepositoryScanning(new RepositoryScanningConfiguration() {

        @Override
        public List<FileType> getFileTypes() {
            FileType fileType = new FileType();
            fileType.setId(FileTypes.ARTIFACTS);
            fileType.setPatterns(Collections.singletonList("**/*"));
            return Collections.singletonList(fileType);
        }
    });
    ArchivaRuntimeConfiguration rt = new ArchivaRuntimeConfiguration();
    List<String> checksums = new ArrayList<>();
    checksums.add("MD5");
    checksums.add("SHA1");
    checksums.add("SHA256");
    rt.setChecksumTypes(checksums);
    configuration.setArchivaRuntimeConfiguration(rt);
}
Also used : ArchivaRuntimeConfiguration(org.apache.archiva.configuration.model.ArchivaRuntimeConfiguration) FileType(org.apache.archiva.configuration.model.FileType) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) PostConstruct(javax.annotation.PostConstruct)

Example 5 with RepositoryScanningConfiguration

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

the class ArchivaConfigurationTest method testRemoveLastElements.

@Test
public void testRemoveLastElements() throws Exception {
    Path baseFile = getTestFile("target/test/test-file.xml");
    Files.deleteIfExists(baseFile);
    assertFalse(Files.exists(baseFile));
    Path userFile = getTestFile("target/test/test-file-user.xml");
    Files.deleteIfExists(userFile);
    assertFalse(Files.exists(userFile));
    Files.createDirectories(baseFile.getParent());
    FileUtils.copyFile(getTestFile("src/test/conf/conf-single-list-elements.xml").toFile(), baseFile.toFile());
    Files.createDirectories(userFile.getParent());
    FileUtils.writeStringToFile(userFile.toFile(), "<configuration/>", Charset.forName("UTF-8"));
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-remove-central");
    archivaConfiguration.reload();
    Configuration configuration = archivaConfiguration.getConfiguration();
    RepositoryGroupConfiguration repositoryGroup = configuration.getRepositoryGroups().get(0);
    assertNotNull(repositoryGroup);
    configuration.removeRepositoryGroup(repositoryGroup);
    assertTrue(configuration.getRepositoryGroups().isEmpty());
    RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get("central");
    assertNotNull(repository);
    configuration.removeRemoteRepository(repository);
    assertTrue(configuration.getRemoteRepositories().isEmpty());
    ManagedRepositoryConfiguration managedRepository = configuration.getManagedRepositoriesAsMap().get("snapshots");
    assertNotNull(managedRepository);
    configuration.removeManagedRepository(managedRepository);
    assertTrue(configuration.getManagedRepositories().isEmpty());
    ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors().get(0);
    assertNotNull(proxyConnector);
    configuration.removeProxyConnector(proxyConnector);
    assertTrue(configuration.getProxyConnectors().isEmpty());
    NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get("proxy");
    assertNotNull(networkProxy);
    configuration.removeNetworkProxy(networkProxy);
    assertTrue(configuration.getNetworkProxies().isEmpty());
    LegacyArtifactPath path = configuration.getLegacyArtifactPaths().get(0);
    assertNotNull(path);
    configuration.removeLegacyArtifactPath(path);
    assertTrue(configuration.getLegacyArtifactPaths().isEmpty());
    RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
    String consumer = scanning.getKnownContentConsumers().get(0);
    assertNotNull(consumer);
    scanning.removeKnownContentConsumer(consumer);
    // default values
    assertFalse(scanning.getKnownContentConsumers().isEmpty());
    consumer = scanning.getInvalidContentConsumers().get(0);
    assertNotNull(consumer);
    scanning.removeInvalidContentConsumer(consumer);
    assertTrue(scanning.getInvalidContentConsumers().isEmpty());
    archivaConfiguration.save(configuration);
    archivaConfiguration = lookup(ArchivaConfiguration.class, "test-read-saved");
    configuration = archivaConfiguration.getConfiguration();
    assertNull(configuration.getRemoteRepositoriesAsMap().get("central"));
    assertTrue(configuration.getRepositoryGroups().isEmpty());
    assertNull(configuration.getManagedRepositoriesAsMap().get("snapshots"));
    assertTrue(configuration.getProxyConnectors().isEmpty());
    assertNull(configuration.getNetworkProxiesAsMap().get("proxy"));
    assertTrue(configuration.getLegacyArtifactPaths().isEmpty());
    scanning = configuration.getRepositoryScanning();
    assertFalse(scanning.getKnownContentConsumers().isEmpty());
    assertTrue(scanning.getInvalidContentConsumers().isEmpty());
}
Also used : Path(java.nio.file.Path) LegacyArtifactPath(org.apache.archiva.configuration.model.LegacyArtifactPath) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) LegacyArtifactPath(org.apache.archiva.configuration.model.LegacyArtifactPath) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Test(org.junit.Test)

Aggregations

RepositoryScanningConfiguration (org.apache.archiva.configuration.model.RepositoryScanningConfiguration)10 Configuration (org.apache.archiva.configuration.model.Configuration)6 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)5 WebappConfiguration (org.apache.archiva.configuration.model.WebappConfiguration)4 ContextConfiguration (org.springframework.test.context.ContextConfiguration)4 Path (java.nio.file.Path)3 FileType (org.apache.archiva.configuration.model.FileType)3 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)3 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)3 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 ArchivaRuntimeConfiguration (org.apache.archiva.configuration.model.ArchivaRuntimeConfiguration)2 LegacyArtifactPath (org.apache.archiva.configuration.model.LegacyArtifactPath)2 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)2 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)2 UserInterfaceOptions (org.apache.archiva.configuration.model.UserInterfaceOptions)2 PostConstruct (javax.annotation.PostConstruct)1