DefaultRb { public void loadAttributes() { for (String line : contentLines) { if (line.matches(LINE_PATTERN) || line.matches(LINE_PATTERN2)) { int indx = line.indexOf("="); String key = line.substring(0, indx - 1).trim().substring(9).replaceAll("\\[\\:", "/"). replaceAll("\\[\\'", "/").replaceAll("\\]", "").replaceAll("\\'", ""). replaceAll("\\.", "/").trim(); String value = line.substring(indx + 1).trim(); Matcher m0 = ARRAY_VALUE_PATTERN.matcher(value); Matcher m1 = SIMPLE_VALUE_PATTERN.matcher(value); Matcher m2 = SKIP_VALUE_PATTERN.matcher(value); if (m0.matches() && !m2.matches()) { String sarr = m0.group(1); Matcher m921 = ATTR_DEFAULT_ARRAY_ITEMS.matcher(sarr); List<String> deflist = new ArrayList<>(); while (m921.find()) { String item = m921.group(1); deflist.add(item); } kv.put(key, deflist); } else if (m1.matches() && !m2.matches()) { value = m1.group(1); if (value.matches("^(\".*\")|('.*')$")) { value = value.substring(1, value.length() - 1); } kv.put(key, value); } } } } DefaultRb(String content); void loadAttributes(); Object getValue(String key); String getExperimentContextFormat(); static String LINE_PATTERN; static String LINE_PATTERN2; static Pattern SIMPLE_VALUE_PATTERN; static Pattern SKIP_VALUE_PATTERN; static Pattern SKIP_VALUE_PATTERN2; static Pattern ARRAY_VALUE_PATTERN; static Pattern ATTR_DEFAULT_ARRAY_ITEMS; }
@Test public void testLoadAttributes() throws CookbookUrlException, MetadataParseException, ValidationException, NoKaramelizedCookbookException { Settings.CB_CLASSPATH_MODE = true; KaramelizedCookbook cb = new KaramelizedCookbook("testorg/testrepo/tree/master/cookbooks/biobankcloud/hiway-chef", false); DefaultRb defaultRb = cb.getDefaultRb(); Object value = defaultRb.getValue("hiway/variantcall/reads/run_ids"); Assert.assertEquals(Lists.newArrayList("SRR359188", "SRR359195"), value); value = defaultRb.getValue("hiway/variantcall/reference/chromosomes"); Assert.assertEquals(Lists.newArrayList("chr22", "chrY"), value); }