ThinArchiveUtils { public static Set<Dependency> parseStartupDependencies(final String rawJson) throws IOException, InvalidHashException { if (rawJson.isEmpty()) { return new HashSet<>(); } List<Map<String, String>> rawParseResult = ((HashMap<String, List<Map<String, String>>>) JSONUtils.parseJSONFromString(rawJson)).get("dependencies"); if (rawParseResult == null) { throw new IOException("Could not find 'dependencies' key in startup-dependencies.json file."); } Set<Dependency> finalDependencies = new HashSet<>(); for (Map<String, String> rawDependency : rawParseResult) { if (rawDependency != null) { finalDependencies.add(new Dependency(rawDependency)); } } return finalDependencies; }  static File getStartupDependenciesFile(final File projectFolder); static DependencyFile getDependencyFile(final File projectFolder, final Dependency d); static Set<Dependency> parseStartupDependencies(final String rawJson); static Set<Dependency> parseStartupDependencies(final File f); static void writeStartupDependencies(final File f,
      final Set<Dependency> dependencies); static String convertIvyCoordinateToPath(final Dependency dep); static String replaceLocalPathsWithStoragePaths(final File projectFolder,
      String localJarSpec, final Props jobProps, final Logger log); static void validateDependencyHash(final DependencyFile f); static void validateDependencyHash(final File f, final Dependency d); static Set<Dependency> filterNullFromDeps(Set<Dependency> dependencies); static final String DEPENDENCY_STORAGE_ROOT_PATH_PROP; }
@Test public void testReadStartupDependencies() throws Exception { File inFile = TEMP_DIR.newFile("startup-dependencies.json"); FileUtils.writeStringToFile(inFile, ThinArchiveTestUtils.getRawJSONDepsAB()); Set<Dependency> parsedDependencies = ThinArchiveUtils.parseStartupDependencies(inFile); assertEquals(ThinArchiveTestUtils.getDepSetAB(), parsedDependencies); }
@Test public void testReadEmptyStartupDependencies() throws Exception { File inFile = TEMP_DIR.newFile("startup-dependencies.json"); FileUtils.writeStringToFile(inFile, ""); Set<Dependency> parsedDependencies = ThinArchiveUtils.parseStartupDependencies(inFile); assertEquals(Collections.emptySet(), parsedDependencies); }
@Test(expected = IOException.class) public void testReadInvalidMissingKeyStartupDependencies() throws Exception { File inFile = TEMP_DIR.newFile("startup-dependencies.json"); FileUtils.writeStringToFile(inFile, "{}"); ThinArchiveUtils.parseStartupDependencies(inFile); }
@Test(expected = IOException.class) public void testReadInvalidMalformedJsonStartupDependencies() throws Exception { File inFile = TEMP_DIR.newFile("startup-dependencies.json"); FileUtils.writeStringToFile(inFile, "{]ugh!thisisn'tjson"); ThinArchiveUtils.parseStartupDependencies(inFile); }