/** * Splits a comma-separated list of locations (names or specs) into an explicit list. * The splitting is very careful to handle commas embedded within specs, to split correctly. */ public static List<String> expandCommaSeparateLocations(String locations) { return WildcardGlobs.getGlobsAfterBraceExpansion("{"+locations+"}", false, PhraseTreatment.INTERIOR_NOT_EXPANDABLE, PhraseTreatment.INTERIOR_NOT_EXPANDABLE); // don't do this, it tries to expand commas inside parentheses which is not good! // QuotedStringTokenizer.builder().addDelimiterChars(",").buildList((String)id); }
/** returns a list with no curly braces in any entries, * and guaranteeing order such that any {..,X,..,Y,..} will result in X being before Y in the resulting list; * e.g. given a{,b,c} gives a ab and ac; no special treatment of numeric ranges, quotes, or parentheses * (see SpecialistGlobExpander for that) */ public static List<String> getGlobsAfterBraceExpansion(String pattern) throws InvalidPatternException { return getGlobsAfterBraceExpansion(pattern, false, PhraseTreatment.NOT_A_SPECIAL_CHAR, PhraseTreatment.NOT_A_SPECIAL_CHAR); }
/** expands glob, including custom syntax for numeric part */ public List<String> expand(String glob) throws InvalidPatternException { return getGlobsAfterBraceExpansion(glob, expandNumericRanges, quoteTreatment, parenthesesTreatment); }
public Builder addAddresses(String address1, String ...others) { List<String> addrs = new ArrayList<String>(); addrs.addAll(WildcardGlobs.getGlobsAfterBraceExpansion("{"+address1+"}", true /* numeric */, /* no quote support though */ PhraseTreatment.NOT_A_SPECIAL_CHAR, PhraseTreatment.NOT_A_SPECIAL_CHAR)); for (String address: others) addrs.addAll(WildcardGlobs.getGlobsAfterBraceExpansion("{"+address+"}", true /* numeric */, /* no quote support though */ PhraseTreatment.NOT_A_SPECIAL_CHAR, PhraseTreatment.NOT_A_SPECIAL_CHAR)); for (String addr: addrs) add(createMachine(addr)); return this; } protected SshMachineLocation createMachine(String addr) {
/** returns true iff the target matches the given pattern, * under simplified bash rules -- viz permitting * and ? and comma delimited patterns inside curly braces * @throws InvalidPatternException */ public static boolean isGlobMatched(String globPattern, String targetText) throws InvalidPatternException { List<String> patterns = getGlobsAfterBraceExpansion(globPattern); for (String p : patterns) { if (isNoBraceGlobMatched(p, targetText)) return true; } return false; }
List<String> hostAddresses = WildcardGlobs.getGlobsAfterBraceExpansion("{"+hosts+"}", true /* numeric */, /* no quote support though */ PhraseTreatment.NOT_A_SPECIAL_CHAR, PhraseTreatment.NOT_A_SPECIAL_CHAR); List<SshMachineLocation> machines = Lists.newArrayList();
List<String> hostIdentifiers = WildcardGlobs.getGlobsAfterBraceExpansion("{"+hosts+"}", true /* numeric */, /* no quote support though */ PhraseTreatment.NOT_A_SPECIAL_CHAR, PhraseTreatment.NOT_A_SPECIAL_CHAR); List<JcloudsSshMachineLocation> machines = Lists.newArrayList();