Search in sources :

Example 6 with RepositoryCheckPath

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

the class DefaultArchivaConfiguration method updateCheckPathDefaults.

/*
     * Updates the checkpath list for repositories.
     *
     * We are replacing existing ones and adding new ones. This allows to update the list with new releases.
     *
     * We are also updating existing remote repositories, if they exist already.
     *
     * This update method should only be called, if the config version changes to avoid overwriting
     * user repository settings all the time.
     */
private void updateCheckPathDefaults(Configuration config, Registry defaultConfiguration) {
    List<RepositoryCheckPath> existingCheckPathList = config.getArchivaDefaultConfiguration().getDefaultCheckPaths();
    HashMap<String, RepositoryCheckPath> existingCheckPaths = new HashMap<>();
    HashMap<String, RepositoryCheckPath> newCheckPaths = new HashMap<>();
    for (RepositoryCheckPath path : config.getArchivaDefaultConfiguration().getDefaultCheckPaths()) {
        existingCheckPaths.put(path.getUrl(), path);
    }
    List defaultCheckPathsSubsets = defaultConfiguration.getSubsetList("archivaDefaultConfiguration.defaultCheckPaths.defaultCheckPath");
    for (Iterator i = defaultCheckPathsSubsets.iterator(); i.hasNext(); ) {
        RepositoryCheckPath v = readRepositoryCheckPath((Registry) i.next());
        if (existingCheckPaths.containsKey(v.getUrl())) {
            existingCheckPathList.remove(existingCheckPaths.get(v.getUrl()));
        }
        existingCheckPathList.add(v);
        newCheckPaths.put(v.getUrl(), v);
    }
    // Remote repositories update
    for (RemoteRepositoryConfiguration remoteRepositoryConfiguration : config.getRemoteRepositories()) {
        String url = remoteRepositoryConfiguration.getUrl().toLowerCase();
        if (newCheckPaths.containsKey(url)) {
            String currentPath = remoteRepositoryConfiguration.getCheckPath();
            String newPath = newCheckPaths.get(url).getPath();
            log.info("Updating connection check path for repository {}, from '{}' to '{}'.", remoteRepositoryConfiguration.getId(), currentPath, newPath);
            remoteRepositoryConfiguration.setCheckPath(newPath);
        }
    }
}
Also used : RepositoryCheckPath(org.apache.archiva.configuration.model.RepositoryCheckPath) HashMap(java.util.HashMap) Iterator(java.util.Iterator) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

RepositoryCheckPath (org.apache.archiva.configuration.model.RepositoryCheckPath)6 Iterator (java.util.Iterator)3 List (java.util.List)2 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 ArchivaDefaultConfiguration (org.apache.archiva.configuration.model.ArchivaDefaultConfiguration)1 RepositoryException (org.apache.archiva.repository.RepositoryException)1