add canonical URL as first item in ordered mirror list

This makes it display nicely in RepoDetails, and is natural, since it is
the canonical URL.  This also maintains the order as received from the
mirror entries in the index file.
This commit is contained in:
Hans-Christoph Steiner 2019-02-14 10:39:00 +01:00
parent 421270ad5f
commit aebf7efc10

View File

@ -65,9 +65,9 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeSet;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
@ -294,11 +294,10 @@ public class IndexV1Updater extends IndexUpdater {
repo.icon = getStringRepoValue(repoMap, "icon"); repo.icon = getStringRepoValue(repoMap, "icon");
repo.description = getStringRepoValue(repoMap, "description"); repo.description = getStringRepoValue(repoMap, "description");
// ensure the canonical URL is included in the "mirrors" list // ensure the canonical URL is included in the "mirrors" list as the first entry
List<String> mirrorsList = getStringListRepoValue(repoMap, "mirrors"); TreeSet<String> mirrors = new TreeSet<>();
HashSet<String> mirrors = new HashSet<>(mirrorsList.size() + 1);
mirrors.addAll(mirrorsList);
mirrors.add(repo.address); mirrors.add(repo.address);
mirrors.addAll(getStringListRepoValue(repoMap, "mirrors"));
repo.mirrors = mirrors.toArray(new String[mirrors.size()]); repo.mirrors = mirrors.toArray(new String[mirrors.size()]);
// below are optional, can be default value // below are optional, can be default value