JsonFileDependencyLoader extends AbstractConfigFileDependencyLoader { @Override protected List<Dependency> load(Path filePath, Properties properties, Logger logger) throws LifecycleExecutionException { List<Dependency> dependencyList = new ArrayList<>(); ObjectMapper mapper = new ObjectMapper(); try { JsonNode root = mapper.readTree(new StringReader(new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8))); ArrayNode dependencies = (ArrayNode) root.get("dependencies"); for (Object o : dependencies) { ObjectNode coordinates = (ObjectNode) o; Dependency dependency = new Dependency(); dependency.setGroupId(coordinates.get("groupId").textValue()); dependency.setArtifactId(coordinates.get("artifactId").textValue()); dependency.setVersion(resolveVersionProperty(coordinates.get("version").textValue(), properties)); logger.info(String.format("Add %s", dependency)); dependencyList.add(dependency); } } catch (IOException e) { throw new LifecycleExecutionException("Failed to read json dependency config file", e); } return dependencyList; }    }
@Test public void shouldLoadFromJson() throws LifecycleExecutionException, URISyntaxException { List<Dependency> dependencyList = loader.load(TestHelper.getClasspathResource("yaks.settings.json"), properties, logger); TestHelper.verifyDependencies(dependencyList); }
@Test public void shouldHandleNonExistingJson() { Assertions.assertThatExceptionOfType(LifecycleExecutionException.class) .isThrownBy(() -> loader.load(Paths.get("doesNotExist"), properties, logger)); }