Search in sources :

Example 31 with ManagedRepositoryConfiguration

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

the class ArchivaConfigurationMRM789Test method testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting.

// test for [MRM-789]
@Test
public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting() throws Exception {
    Path repo = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-classes/existing_snapshots");
    Files.createDirectories(repo);
    repo = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-classes/existing_internal");
    Files.createDirectories(repo);
    String existingTestDefaultArchivaConfigFile = FileUtils.readFileToString(getTestFile("target/test-classes/org/apache/archiva/configuration/test-default-archiva.xml").toFile(), FILE_ENCODING);
    existingTestDefaultArchivaConfigFile = StringUtils.replace(existingTestDefaultArchivaConfigFile, "${appserver.base}", org.apache.archiva.common.utils.FileUtils.getBasedir());
    Path generatedTestDefaultArchivaConfigFile = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-classes/org/apache/archiva/configuration/default-archiva.xml");
    FileUtils.writeStringToFile(generatedTestDefaultArchivaConfigFile.toFile(), existingTestDefaultArchivaConfigFile, Charset.forName(FILE_ENCODING));
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-defaults-default-repo-location-exists");
    Configuration configuration = archivaConfiguration.getConfiguration();
    assertConfiguration(configuration, 2, 2, 2);
    ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get(0);
    assertTrue("check managed repositories", repository.getLocation().endsWith("data/repositories/internal"));
    Files.deleteIfExists(generatedTestDefaultArchivaConfigFile);
    assertFalse(Files.exists(generatedTestDefaultArchivaConfigFile));
}
Also used : Path(java.nio.file.Path) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Test(org.junit.Test)

Example 32 with ManagedRepositoryConfiguration

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

the class ConfigurationTest method createManagedRepository.

private ManagedRepositoryConfiguration createManagedRepository(String id, String name, String location, boolean scanned) {
    ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
    repo.setId(id);
    repo.setName(name);
    repo.setLocation(location);
    repo.setScanned(scanned);
    return repo;
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)

Example 33 with ManagedRepositoryConfiguration

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

the class DefaultArchivaConfiguration method checkRepositoryLocations.

private Configuration checkRepositoryLocations(Configuration config) {
    // are not installed in the server installation
    for (ManagedRepositoryConfiguration repo : (List<ManagedRepositoryConfiguration>) config.getManagedRepositories()) {
        String repoPath = repo.getLocation();
        Path repoLocation = Paths.get(repoPath);
        if (Files.exists(repoLocation) && Files.isDirectory(repoLocation) && !repoPath.endsWith("/repositories/" + repo.getId())) {
            repo.setLocation(repoPath + "/data/repositories/" + repo.getId());
        }
    }
    return config;
}
Also used : Path(java.nio.file.Path) RepositoryCheckPath(org.apache.archiva.configuration.model.RepositoryCheckPath) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ArrayList(java.util.ArrayList) List(java.util.List)

Example 34 with ManagedRepositoryConfiguration

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

the class ConfigurationRegistryReader method readConfiguration.

private Configuration readConfiguration(String prefix, Registry registry) {
    Configuration value = new Configuration();
    // String version = registry.getString( prefix + "version", value.getVersion() );
    List<String> versionList = registry.getList(prefix + "version");
    String version = value.getVersion();
    if (versionList != null && !versionList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = versionList.size(); i < size; i++) {
            sb.append(versionList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        version = sb.toString();
    }
    value.setVersion(version);
    // String metadataStore = registry.getString( prefix + "metadataStore", value.getMetadataStore() );
    List<String> metadataStoreList = registry.getList(prefix + "metadataStore");
    String metadataStore = value.getMetadataStore();
    if (metadataStoreList != null && !metadataStoreList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = metadataStoreList.size(); i < size; i++) {
            sb.append(metadataStoreList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        metadataStore = sb.toString();
    }
    value.setMetadataStore(metadataStore);
    java.util.List repositoryGroups = new java.util.ArrayList();
    List repositoryGroupsSubsets = registry.getSubsetList(prefix + "repositoryGroups.repositoryGroup");
    for (Iterator i = repositoryGroupsSubsets.iterator(); i.hasNext(); ) {
        RepositoryGroupConfiguration v = readRepositoryGroupConfiguration("", (Registry) i.next());
        repositoryGroups.add(v);
    }
    value.setRepositoryGroups(repositoryGroups);
    java.util.List managedRepositories = new java.util.ArrayList();
    List managedRepositoriesSubsets = registry.getSubsetList(prefix + "managedRepositories.managedRepository");
    for (Iterator i = managedRepositoriesSubsets.iterator(); i.hasNext(); ) {
        ManagedRepositoryConfiguration v = readManagedRepositoryConfiguration("", (Registry) i.next());
        managedRepositories.add(v);
    }
    value.setManagedRepositories(managedRepositories);
    java.util.List remoteRepositories = new java.util.ArrayList();
    List remoteRepositoriesSubsets = registry.getSubsetList(prefix + "remoteRepositories.remoteRepository");
    for (Iterator i = remoteRepositoriesSubsets.iterator(); i.hasNext(); ) {
        RemoteRepositoryConfiguration v = readRemoteRepositoryConfiguration("", (Registry) i.next());
        remoteRepositories.add(v);
    }
    value.setRemoteRepositories(remoteRepositories);
    java.util.List proxyConnectors = new java.util.ArrayList();
    List proxyConnectorsSubsets = registry.getSubsetList(prefix + "proxyConnectors.proxyConnector");
    for (Iterator i = proxyConnectorsSubsets.iterator(); i.hasNext(); ) {
        ProxyConnectorConfiguration v = readProxyConnectorConfiguration("", (Registry) i.next());
        proxyConnectors.add(v);
    }
    value.setProxyConnectors(proxyConnectors);
    java.util.List networkProxies = new java.util.ArrayList();
    List networkProxiesSubsets = registry.getSubsetList(prefix + "networkProxies.networkProxy");
    for (Iterator i = networkProxiesSubsets.iterator(); i.hasNext(); ) {
        NetworkProxyConfiguration v = readNetworkProxyConfiguration("", (Registry) i.next());
        networkProxies.add(v);
    }
    value.setNetworkProxies(networkProxies);
    java.util.List legacyArtifactPaths = new java.util.ArrayList();
    List legacyArtifactPathsSubsets = registry.getSubsetList(prefix + "legacyArtifactPaths.legacyArtifactPath");
    for (Iterator i = legacyArtifactPathsSubsets.iterator(); i.hasNext(); ) {
        LegacyArtifactPath v = readLegacyArtifactPath("", (Registry) i.next());
        legacyArtifactPaths.add(v);
    }
    value.setLegacyArtifactPaths(legacyArtifactPaths);
    RepositoryScanningConfiguration repositoryScanning = readRepositoryScanningConfiguration(prefix + "repositoryScanning.", registry);
    value.setRepositoryScanning(repositoryScanning);
    WebappConfiguration webapp = readWebappConfiguration(prefix + "webapp.", registry);
    value.setWebapp(webapp);
    OrganisationInformation organisationInfo = readOrganisationInformation(prefix + "organisationInfo.", registry);
    value.setOrganisationInfo(organisationInfo);
    NetworkConfiguration networkConfiguration = readNetworkConfiguration(prefix + "networkConfiguration.", registry);
    value.setNetworkConfiguration(networkConfiguration);
    RedbackRuntimeConfiguration redbackRuntimeConfiguration = readRedbackRuntimeConfiguration(prefix + "redbackRuntimeConfiguration.", registry);
    value.setRedbackRuntimeConfiguration(redbackRuntimeConfiguration);
    ArchivaRuntimeConfiguration archivaRuntimeConfiguration = readArchivaRuntimeConfiguration(prefix + "archivaRuntimeConfiguration.", registry);
    value.setArchivaRuntimeConfiguration(archivaRuntimeConfiguration);
    java.util.List proxyConnectorRuleConfigurations = new java.util.ArrayList();
    List proxyConnectorRuleConfigurationsSubsets = registry.getSubsetList(prefix + "proxyConnectorRuleConfigurations.proxyConnectorRuleConfiguration");
    for (Iterator i = proxyConnectorRuleConfigurationsSubsets.iterator(); i.hasNext(); ) {
        ProxyConnectorRuleConfiguration v = readProxyConnectorRuleConfiguration("", (Registry) i.next());
        proxyConnectorRuleConfigurations.add(v);
    }
    value.setProxyConnectorRuleConfigurations(proxyConnectorRuleConfigurations);
    ArchivaDefaultConfiguration archivaDefaultConfiguration = readArchivaDefaultConfiguration(prefix + "archivaDefaultConfiguration.", registry);
    value.setArchivaDefaultConfiguration(archivaDefaultConfiguration);
    return value;
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) LdapConfiguration(org.apache.archiva.configuration.model.LdapConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) NetworkConfiguration(org.apache.archiva.configuration.model.NetworkConfiguration) RedbackRuntimeConfiguration(org.apache.archiva.configuration.model.RedbackRuntimeConfiguration) AbstractRepositoryConfiguration(org.apache.archiva.configuration.model.AbstractRepositoryConfiguration) ArchivaRuntimeConfiguration(org.apache.archiva.configuration.model.ArchivaRuntimeConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) AbstractRepositoryConnectorConfiguration(org.apache.archiva.configuration.model.AbstractRepositoryConnectorConfiguration) FileLockConfiguration(org.apache.archiva.configuration.model.FileLockConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) CacheConfiguration(org.apache.archiva.configuration.model.CacheConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) SyncConnectorConfiguration(org.apache.archiva.configuration.model.SyncConnectorConfiguration) ArchivaDefaultConfiguration(org.apache.archiva.configuration.model.ArchivaDefaultConfiguration) WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.model.ProxyConnectorRuleConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.model.ProxyConnectorRuleConfiguration) Iterator(java.util.Iterator) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) List(java.util.List) NetworkConfiguration(org.apache.archiva.configuration.model.NetworkConfiguration) ArchivaDefaultConfiguration(org.apache.archiva.configuration.model.ArchivaDefaultConfiguration) ArchivaRuntimeConfiguration(org.apache.archiva.configuration.model.ArchivaRuntimeConfiguration) List(java.util.List) LegacyArtifactPath(org.apache.archiva.configuration.model.LegacyArtifactPath) OrganisationInformation(org.apache.archiva.configuration.model.OrganisationInformation) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) RedbackRuntimeConfiguration(org.apache.archiva.configuration.model.RedbackRuntimeConfiguration)

Example 35 with ManagedRepositoryConfiguration

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

the class ConfigurationRegistryReader method readManagedRepositoryConfiguration.

private ManagedRepositoryConfiguration readManagedRepositoryConfiguration(String prefix, Registry registry) {
    ManagedRepositoryConfiguration value = new ManagedRepositoryConfiguration();
    // String location = registry.getString( prefix + "location", value.getLocation() );
    List<String> locationList = registry.getList(prefix + "location");
    String location = value.getLocation();
    if (locationList != null && !locationList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = locationList.size(); i < size; i++) {
            sb.append(locationList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        location = sb.toString();
    }
    value.setLocation(location);
    boolean releases = registry.getBoolean(prefix + "releases", value.isReleases());
    value.setReleases(releases);
    boolean blockRedeployments = registry.getBoolean(prefix + "blockRedeployments", value.isBlockRedeployments());
    value.setBlockRedeployments(blockRedeployments);
    boolean snapshots = registry.getBoolean(prefix + "snapshots", value.isSnapshots());
    value.setSnapshots(snapshots);
    boolean scanned = registry.getBoolean(prefix + "scanned", value.isScanned());
    value.setScanned(scanned);
    // String refreshCronExpression = registry.getString( prefix + "refreshCronExpression", value.getRefreshCronExpression() );
    List<String> refreshCronExpressionList = registry.getList(prefix + "refreshCronExpression");
    String refreshCronExpression = value.getRefreshCronExpression();
    if (refreshCronExpressionList != null && !refreshCronExpressionList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = refreshCronExpressionList.size(); i < size; i++) {
            sb.append(refreshCronExpressionList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        refreshCronExpression = sb.toString();
    }
    value.setRefreshCronExpression(refreshCronExpression);
    int retentionCount = registry.getInt(prefix + "retentionCount", value.getRetentionCount());
    value.setRetentionCount(retentionCount);
    int retentionPeriod = registry.getInt(prefix + "retentionPeriod", value.getRetentionPeriod());
    value.setRetentionPeriod(retentionPeriod);
    boolean deleteReleasedSnapshots = registry.getBoolean(prefix + "deleteReleasedSnapshots", value.isDeleteReleasedSnapshots());
    value.setDeleteReleasedSnapshots(deleteReleasedSnapshots);
    boolean skipPackedIndexCreation = registry.getBoolean(prefix + "skipPackedIndexCreation", value.isSkipPackedIndexCreation());
    value.setSkipPackedIndexCreation(skipPackedIndexCreation);
    boolean stageRepoNeeded = registry.getBoolean(prefix + "stageRepoNeeded", value.isStageRepoNeeded());
    value.setStageRepoNeeded(stageRepoNeeded);
    // String id = registry.getString( prefix + "id", value.getId() );
    List<String> idList = registry.getList(prefix + "id");
    String id = value.getId();
    if (idList != null && !idList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = idList.size(); i < size; i++) {
            sb.append(idList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        id = sb.toString();
    }
    value.setId(id);
    // String type = registry.getString( prefix + "type", value.getType() );
    List<String> typeList = registry.getList(prefix + "type");
    String type = value.getType();
    if (typeList != null && !typeList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = typeList.size(); i < size; i++) {
            sb.append(typeList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        type = sb.toString();
    }
    value.setType(type);
    // String name = registry.getString( prefix + "name", value.getName() );
    List<String> nameList = registry.getList(prefix + "name");
    String name = value.getName();
    if (nameList != null && !nameList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = nameList.size(); i < size; i++) {
            sb.append(nameList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        name = sb.toString();
    }
    value.setName(name);
    // String layout = registry.getString( prefix + "layout", value.getLayout() );
    List<String> layoutList = registry.getList(prefix + "layout");
    String layout = value.getLayout();
    if (layoutList != null && !layoutList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = layoutList.size(); i < size; i++) {
            sb.append(layoutList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        layout = sb.toString();
    }
    value.setLayout(layout);
    // String indexDir = registry.getString( prefix + "indexDir", value.getIndexDir() );
    List<String> indexDirList = registry.getList(prefix + "indexDir");
    String indexDir = value.getIndexDir();
    if (indexDirList != null && !indexDirList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = indexDirList.size(); i < size; i++) {
            sb.append(indexDirList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        indexDir = sb.toString();
    }
    value.setIndexDir(indexDir);
    // String packedIndexDir = registry.getString( prefix + "packedIndexDir", value.getPackedIndexDir() );
    List<String> packedIndexDirList = registry.getList(prefix + "packedIndexDir");
    String packedIndexDir = value.getPackedIndexDir();
    if (packedIndexDirList != null && !packedIndexDirList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = packedIndexDirList.size(); i < size; i++) {
            sb.append(packedIndexDirList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        packedIndexDir = sb.toString();
    }
    value.setPackedIndexDir(packedIndexDir);
    // String description = registry.getString( prefix + "description", value.getDescription() );
    List<String> descriptionList = registry.getList(prefix + "description");
    String description = value.getDescription();
    if (descriptionList != null && !descriptionList.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0, size = descriptionList.size(); i < size; i++) {
            sb.append(descriptionList.get(i));
            if (i < size - 1) {
                sb.append(',');
            }
        }
        description = sb.toString();
    }
    value.setDescription(description);
    return value;
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)

Aggregations

ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)72 Configuration (org.apache.archiva.configuration.model.Configuration)27 ManagedRepository (org.apache.archiva.repository.ManagedRepository)18 ContextConfiguration (org.springframework.test.context.ContextConfiguration)18 Path (java.nio.file.Path)17 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)14 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)14 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)14 Test (org.junit.Test)14 StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)13 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)11 RepositoryScanningConfiguration (org.apache.archiva.configuration.model.RepositoryScanningConfiguration)10 Test (org.junit.jupiter.api.Test)10 ArrayList (java.util.ArrayList)9 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)9 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)9 RepositoryException (org.apache.archiva.repository.RepositoryException)9 Before (org.junit.Before)8 IOException (java.io.IOException)7 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)7