Skip to content

Commit 817e044

Browse files
committed
Add fallbackRepositories to the Json configuration
1 parent b5451ef commit 817e044

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

core/src/main/java/com/alessiodp/libby/configuration/ConfigurationFetcher.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public Configuration readJsonFile(@NotNull InputStream data) {
160160
}
161161

162162
Integer version = fetchVersion(root);
163-
Set<String> repositories = fetchRepositories(root);
163+
Set<String> repositories = fetchRepositories(root, false);
164164
Set<Relocation> globalRelocations = fetchRelocations(root);
165165
List<Library> libraries = fetchLibraries(root, globalRelocations);
166166

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

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

426-
fetchRepositories(library).forEach(libraryBuilder::repository);
427+
fetchRepositories(library, false).forEach(libraryBuilder::repository);
428+
429+
fetchRepositories(library, true).forEach(libraryBuilder::fallbackRepository);
427430

428431
Set<Relocation> relocations = fetchRelocations(library);
429432

core/src/test/java/com/alessiodp/libby/ConfigurationFetcherTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ && compareCollections(
7777
"libraryRepo1/", // Add a '/' at the end since it is added by the Library builder
7878
"libraryRepo2/"
7979
)
80+
&& compareCollections(
81+
l.getFallbackRepositories(),
82+
"fallbackRepo/" // Add a '/' at the end since it is added by the Library builder
83+
)
8084
&& compareCollections(
8185
l.getRelocations(),
8286
globalRelocation // Global

core/src/test/resources/libby.json

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
"repositories": [
2222
"libraryRepo1",
2323
"libraryRepo2"
24+
],
25+
"fallbackRepositories": [
26+
"fallbackRepo"
2427
]
2528
},
2629
{

0 commit comments

Comments
 (0)