@Test public void testParseBootFeatures() throws Exception { String features = "foo, jim, (ssh, shell, jaas, feature, framework), (system, bundle, management, service), (instance, package, log, deployer, diagnostic, config, kar), bar, zad"; BootFeaturesInstaller bootFeatures = new BootFeaturesInstaller(null, null, null, null, false); List<Set<String>> stages = bootFeatures.parseBootFeatures(features); Assert.assertEquals(5, stages.size()); for (String f : Arrays.asList("foo", "jim")) { Assert.assertTrue("Should contain '" + f + "'", stages.get(0).contains(f)); } for (String f : Arrays.asList("ssh", "shell", "jaas", "feature", "framework")) { Assert.assertTrue("Should contain '" + f + "'", stages.get(1).contains(f)); } for (String f : Arrays.asList("system", "bundle", "management", "service")) { Assert.assertTrue("Should contain '" + f + "'", stages.get(2).contains(f)); } for (String f : Arrays.asList("instance", "package", "log", "deployer", "diagnostic", "config", "kar")) { Assert.assertTrue("Should contain '" + f + "'", stages.get(3).contains(f)); } for (String f : Arrays.asList("bar", "zad")) { Assert.assertTrue("Should contain '" + f + "'", stages.get(4).contains(f)); } }
protected List<Set<String>> parseBootFeatures(String bootFeatures) { List<Set<String>> stages = new ArrayList<>(); StringTokenizer tokenizer = new StringTokenizer(bootFeatures, " \t\r\n,()", true); int paren = 0; Set<String> stage = new LinkedHashSet<>(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (token.equals("(")) { if (paren == 0) { if (!stage.isEmpty()) { stages.add(stage); stage = new LinkedHashSet<>(); } paren++; } else { throw new IllegalArgumentException("Bad syntax in boot features: '" + bootFeatures + "'"); } } else if (token.equals(")")) { if (paren == 1) { if (!stage.isEmpty()) { stages.add(stage); stage = new LinkedHashSet<>(); } paren--; } else { throw new IllegalArgumentException("Bad syntax in boot features: '" + bootFeatures + "'"); } } else if (!token.matches("[ \t\r\n]+|,")) { stage.add(token); } } if (!stage.isEmpty()) { stages.add(stage); } return stages; }
BootFeaturesInstaller { protected List<Set<String>> parseBootFeatures(String bootFeatures) { List<Set<String>> stages = new ArrayList<>(); StringTokenizer tokenizer = new StringTokenizer(bootFeatures, " \t\r\n,()", true); int paren = 0; Set<String> stage = new LinkedHashSet<>(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (token.equals("(")) { if (paren == 0) { if (!stage.isEmpty()) { stages.add(stage); stage = new LinkedHashSet<>(); } paren++; } else { throw new IllegalArgumentException("Bad syntax in boot features: '" + bootFeatures + "'"); } } else if (token.equals(")")) { if (paren == 1) { if (!stage.isEmpty()) { stages.add(stage); stage = new LinkedHashSet<>(); } paren--; } else { throw new IllegalArgumentException("Bad syntax in boot features: '" + bootFeatures + "'"); } } else if (!token.matches("[ \t\r\n]+|,")) { stage.add(token); } } if (!stage.isEmpty()) { stages.add(stage); } return stages; } }
BootFeaturesInstaller { protected List<Set<String>> parseBootFeatures(String bootFeatures) { List<Set<String>> stages = new ArrayList<>(); StringTokenizer tokenizer = new StringTokenizer(bootFeatures, " \t\r\n,()", true); int paren = 0; Set<String> stage = new LinkedHashSet<>(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (token.equals("(")) { if (paren == 0) { if (!stage.isEmpty()) { stages.add(stage); stage = new LinkedHashSet<>(); } paren++; } else { throw new IllegalArgumentException("Bad syntax in boot features: '" + bootFeatures + "'"); } } else if (token.equals(")")) { if (paren == 1) { if (!stage.isEmpty()) { stages.add(stage); stage = new LinkedHashSet<>(); } paren--; } else { throw new IllegalArgumentException("Bad syntax in boot features: '" + bootFeatures + "'"); } } else if (!token.matches("[ \t\r\n]+|,")) { stage.add(token); } } if (!stage.isEmpty()) { stages.add(stage); } return stages; } BootFeaturesInstaller(BundleContext bundleContext,
                                 FeaturesServiceImpl featuresService,
                                 String[] repositories,
                                 String features,
                                 boolean asynchronous); }
BootFeaturesInstaller { protected List<Set<String>> parseBootFeatures(String bootFeatures) { List<Set<String>> stages = new ArrayList<>(); StringTokenizer tokenizer = new StringTokenizer(bootFeatures, " \t\r\n,()", true); int paren = 0; Set<String> stage = new LinkedHashSet<>(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (token.equals("(")) { if (paren == 0) { if (!stage.isEmpty()) { stages.add(stage); stage = new LinkedHashSet<>(); } paren++; } else { throw new IllegalArgumentException("Bad syntax in boot features: '" + bootFeatures + "'"); } } else if (token.equals(")")) { if (paren == 1) { if (!stage.isEmpty()) { stages.add(stage); stage = new LinkedHashSet<>(); } paren--; } else { throw new IllegalArgumentException("Bad syntax in boot features: '" + bootFeatures + "'"); } } else if (!token.matches("[ \t\r\n]+|,")) { stage.add(token); } } if (!stage.isEmpty()) { stages.add(stage); } return stages; } BootFeaturesInstaller(BundleContext bundleContext,
                                 FeaturesServiceImpl featuresService,
                                 String[] repositories,
                                 String features,
                                 boolean asynchronous); void start(); }
BootFeaturesInstaller { protected List<Set<String>> parseBootFeatures(String bootFeatures) { List<Set<String>> stages = new ArrayList<>(); StringTokenizer tokenizer = new StringTokenizer(bootFeatures, " \t\r\n,()", true); int paren = 0; Set<String> stage = new LinkedHashSet<>(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (token.equals("(")) { if (paren == 0) { if (!stage.isEmpty()) { stages.add(stage); stage = new LinkedHashSet<>(); } paren++; } else { throw new IllegalArgumentException("Bad syntax in boot features: '" + bootFeatures + "'"); } } else if (token.equals(")")) { if (paren == 1) { if (!stage.isEmpty()) { stages.add(stage); stage = new LinkedHashSet<>(); } paren--; } else { throw new IllegalArgumentException("Bad syntax in boot features: '" + bootFeatures + "'"); } } else if (!token.matches("[ \t\r\n]+|,")) { stage.add(token); } } if (!stage.isEmpty()) { stages.add(stage); } return stages; } BootFeaturesInstaller(BundleContext bundleContext,
                                 FeaturesServiceImpl featuresService,
                                 String[] repositories,
                                 String features,
                                 boolean asynchronous); void start();  }