/** * Give a string which represents a series of shell commands (the output of ndk-build -n). * Token each command by splitting on spaces while observing quoting rules on the specified * platform. * * The result is a list of {@link CommandLine} structures. One for each command in the original * ndk-build output. */ static List<CommandLine> parse(String commands, boolean isWin32) { String[] lines = commands.split("[\r\n]+"); List<CommandLine> commandLines = new ArrayList<>(); for (String line : lines) { List<String> commandList = isWin32 ? StringHelperWindows.splitCommandLine(line) : StringHelperPOSIX.splitCommandLine(line); for (String commandString : commandList) { List<String> split = isWin32 ? StringHelperWindows.tokenizeString(commandString) : StringHelperPOSIX.tokenizeString(commandString); String command = split.get(0); split.remove(0); commandLines.add(new CommandLine(command, split)); } } return commandLines; } }
/** * Quote and join a list of tokens with platform specific rules. * * @param tokens the token to be quoted and joined * @return the string */ @NonNull public static String quoteAndJoinTokens(@NonNull List<String> tokens) { if (System.getProperty("os.name").startsWith("Windows")) return StringHelperWindows.quoteAndJoinTokens(tokens); else return StringHelperPOSIX.quoteAndJoinTokens(tokens); }
/** * Split a single command line into individual commands with platform specific rules. * * @param commandLine the command line to be split * @return the list of individual commands */ @NonNull public static List<String> splitCommandLine(@NonNull String commandLine) { if (System.getProperty("os.name").startsWith("Windows")) return StringHelperWindows.splitCommandLine(commandLine); else return StringHelperPOSIX.splitCommandLine(commandLine); }
/** * Tokenize a string with platform specific rules. * * @param string the string to be tokenized * @return the list of tokens */ @NonNull public static List<String> tokenizeString(@NonNull String string) { if (System.getProperty("os.name").startsWith("Windows")) return StringHelperWindows.tokenizeString(string); else return StringHelperPOSIX.tokenizeString(string); } }