Skip to content

Commit

Permalink
Add fallbackRepositories to the Json configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
frengor committed Apr 16, 2024
1 parent b5451ef commit 817e044
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public Configuration readJsonFile(@NotNull InputStream data) {
}

Integer version = fetchVersion(root);
Set<String> repositories = fetchRepositories(root);
Set<String> repositories = fetchRepositories(root, false);
Set<Relocation> globalRelocations = fetchRelocations(root);
List<Library> libraries = fetchLibraries(root, globalRelocations);

Expand Down Expand Up @@ -197,11 +197,12 @@ private Integer fetchVersion(@NotNull Map<String, Object> configuration) {
* If defined, it must be an array of string representing the repository URLs.
*
* @param configuration the root object of the JSON file
* @param fallbackRepo {@code true} to fetch "fallbackRepositories" instead of "repositories"
* @return the set of repositories as strings
*/
private Set<String> fetchRepositories(@NotNull Map<String, Object> configuration) throws ReflectiveOperationException {
private Set<String> fetchRepositories(@NotNull Map<String, Object> configuration, boolean fallbackRepo) throws ReflectiveOperationException {
Set<String> repos = new HashSet<>();
ArrayList<Object> repositories = getArray(configuration, "repositories");
ArrayList<Object> repositories = getArray(configuration, fallbackRepo ? "fallbackRepositories" : "repositories");
if (repositories != null) {
for (Object repository : repositories) {
if (repository instanceof String) {
Expand Down Expand Up @@ -423,7 +424,9 @@ private List<Library> fetchLibraries(@NotNull Map<String, Object> configuration,

fetchExcludedTransitiveDependencies(library).forEach(libraryBuilder::excludeTransitiveDependency);

fetchRepositories(library).forEach(libraryBuilder::repository);
fetchRepositories(library, false).forEach(libraryBuilder::repository);

fetchRepositories(library, true).forEach(libraryBuilder::fallbackRepository);

Set<Relocation> relocations = fetchRelocations(library);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ && compareCollections(
"libraryRepo1/", // Add a '/' at the end since it is added by the Library builder
"libraryRepo2/"
)
&& compareCollections(
l.getFallbackRepositories(),
"fallbackRepo/" // Add a '/' at the end since it is added by the Library builder
)
&& compareCollections(
l.getRelocations(),
globalRelocation // Global
Expand Down
3 changes: 3 additions & 0 deletions core/src/test/resources/libby.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"repositories": [
"libraryRepo1",
"libraryRepo2"
],
"fallbackRepositories": [
"fallbackRepo"
]
},
{
Expand Down

0 comments on commit 817e044

Please sign in to comment.