YamlFileDependencyLoader extends AbstractConfigFileDependencyLoader { @Override protected List<Dependency> load(Path filePath, Properties properties, Logger logger) throws LifecycleExecutionException { try { List<Dependency> dependencyList = new ArrayList<>(); Yaml yaml = new Yaml(); HashMap<String, List<Map<String, Object>>> root = yaml.load(new StringReader(new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8))); if (root.containsKey("dependencies")) { for (Map<String, Object> coordinates : root.get("dependencies")) { Dependency dependency = new Dependency(); dependency.setGroupId(Objects.toString(coordinates.get("groupId"))); dependency.setArtifactId(Objects.toString(coordinates.get("artifactId"))); dependency.setVersion(resolveVersionProperty(Objects.toString(coordinates.get("version")), properties)); logger.info(String.format("Add %s", dependency)); dependencyList.add(dependency); } } return dependencyList; } catch (IOException e) { throw new LifecycleExecutionException("Failed to read dependency configuration file", e); } }    }
@Test public void shouldLoadFromYaml() throws LifecycleExecutionException, URISyntaxException { List<Dependency> dependencyList = loader.load(TestHelper.getClasspathResource("yaks.settings.yaml"), properties, logger); TestHelper.verifyDependencies(dependencyList); }
@Test public void shouldHandleNonExistingYaml() { Assertions.assertThatExceptionOfType(LifecycleExecutionException.class) .isThrownBy(() -> loader.load(Paths.get("doesNotExist"), properties, logger)); }