JsonFileRepositoryLoader extends AbstractConfigFileRepositoryLoader { @Override protected List<Repository> load(Path filePath, Logger logger) throws LifecycleExecutionException { List<Repository> repositoryList = new ArrayList<>(); ObjectMapper mapper = new ObjectMapper(); try { JsonNode root = mapper.readTree(new StringReader(new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8))); ArrayNode repositories = (ArrayNode) root.get("repositories"); for (Object o : repositories) { ObjectNode model = (ObjectNode) o; Repository repository = new Repository(); repository.setId(model.get("id").textValue()); repository.setUrl(model.get("url").textValue()); if (model.get("name") != null) { repository.setName(model.get("name").textValue()); } if (model.get("layout") != null) { repository.setLayout(model.get("layout").textValue()); } if (model.get("releases") != null) { repository.setReleases(getRepositoryPolicy((ObjectNode) model.get("releases"))); } if (model.get("snapshots") != null) { repository.setReleases(getRepositoryPolicy((ObjectNode) model.get("snapshots"))); } logger.info(String.format("Add Repository %s=%s", repository.getId(), repository.getUrl())); repositoryList.add(repository); } } catch (IOException e) { throw new LifecycleExecutionException("Failed to read json repository config file", e); } return repositoryList; }    }
@Test public void shouldLoadFromJson() throws LifecycleExecutionException, URISyntaxException { List<Repository> repositoryList = loader.load(TestHelper.getClasspathResource("yaks.settings.json"), logger); TestHelper.verifyRepositories(repositoryList); }
@Test public void shouldHandleNonExistingJson() { Assertions.assertThatExceptionOfType(LifecycleExecutionException.class) .isThrownBy(() -> loader.load(Paths.get("doesNotExist"), logger)); }