public void parse(IvySettings settings, File desc) { if (!desc.exists()) { System.out.println("~ !! " + desc.getAbsolutePath() + " does not exist"); return; } try { Yaml yaml = new Yaml(); Object o = null; // Try to parse the yaml try { o = yaml.load(new FileInputStream(desc)); } catch (Exception e) { throw new Oops(e.toString().replace("\n", "\n~ \t")); } // We expect a Map here if (!(o instanceof Map)) { throw new Oops("Unexpected format -> " + o); } Map data = (Map) o; if (data.containsKey("repositories")) { if (data.get("repositories") instanceof List) { List repositories = (List) data.get("repositories"); List<Map<String, String>> modules = new ArrayList<Map<String, String>>(); for (Object dep : repositories) { if (dep instanceof Map) { settings.addResolver(parseRepository((Map) dep, modules)); } else { throw new Oops("Unknown repository format -> " + dep); } } for (Map attributes : modules) { settings.addModuleConfiguration( attributes, settings.getMatcher(PatternMatcher.EXACT_OR_REGEXP), (String) attributes.remove("resolver"), null, null, null); } } else { throw new Oops("repositories list not found -> " + o); } } } catch (Oops e) { System.out.println("~ Oops, malformed dependencies.yml descriptor:"); System.out.println("~"); System.out.println("~ \t" + e.getMessage()); System.out.println("~"); throw new RuntimeException("Malformed dependencies.yml descriptor"); } }
@Test public void testGetName() { assertEquals("a.txt", FileNames.getName("c:\\a.txt")); assertEquals("a", FileNames.getName("c:\\a")); assertEquals("c.txt", FileNames.getName("/c.txt")); assertEquals("b.txt", FileNames.getName("https://www.sample.com/folder/b.txt")); try { FileNames.getName("/"); fail("does not have file name"); } catch (Oops e) { e.printStackTrace(); } try { FileNames.getName("a"); fail("does not have file name"); } catch (Oops e) { e.printStackTrace(); } try { FileNames.getName("http://ww.xxxxx.com/"); fail(" does not have file name"); } catch (Oops e) { e.printStackTrace(); } try { FileNames.getName("c:\\"); fail(" does not have file name"); } catch (Oops e) { e.printStackTrace(); } }