protected static String usage(String executableBaseName) { boolean isWindows = (SecurityActions.getSystemProperty("os.name")).toLowerCase(Locale.ENGLISH).contains("windows"); String executableName = isWindows ? executableBaseName : executableBaseName + ".sh"; if (USAGE == null) { final StringBuilder sb = new StringBuilder(); sb.append(NEW_LINE).append(MESSAGES.argUsage(executableName)).append(NEW_LINE); for (int i = 0; i < arguments.size(); i++) { sb.append(getCommand(i)).append(NEW_LINE); } USAGE = sb.toString(); } return USAGE; }
private static void segmentInstructions(String instructions, List<String> segments) { if (instructions.length() <= 40) { segments.add(instructions); } else { String testFragment = instructions.substring(0,40); int lastSpace = testFragment.lastIndexOf(' '); if (lastSpace < 0) { // degenerate case; we just have to chop not at a space lastSpace = 39; } segments.add(instructions.substring(0, lastSpace + 1)); segmentInstructions(instructions.substring(lastSpace + 1), segments); } }
private static String getCommand(int i){ segmentInstructions(instructions.get(i), segmentedInstructions); segmentArguments(arguments.get(i), segmentedArguments, 0);
private static void segmentArguments(List<String> input, List<String> output, int depth){ int width = 30; if( depth == 0 ){ width = 35; } if( input.size() > 0 ) { StringBuilder argumentsString = new StringBuilder(); for( int i = 0; i < input.size(); ){ // Trim in case an argument is too large for the width. Shouldn't happen. if( input.get(0).length() > width ){ String tooLong = input.remove(0); input.add(0, tooLong.substring(0, width-5)); } if( input.size() == 1 && (argumentsString.toString().length() + input.get(0).length() <= width)){ argumentsString.append(input.remove(0)); }else if( argumentsString.toString().length() + input.get(0).length() + 2 <= width ){ argumentsString.append(input.remove(0)).append(", "); }else{ break; } } output.add(argumentsString.toString()); segmentArguments(input, output, depth+1); } }
private static String getCommand(int i){ segmentInstructions(instructions.get(i), segmentedInstructions); segmentArguments(arguments.get(i), segmentedArguments, 0);
private static void segmentArguments(List<String> input, List<String> output, int depth){ int width = 30; if( depth == 0 ){ width = 35; } if( input.size() > 0 ) { StringBuilder argumentsString = new StringBuilder(); for( int i = 0; i < input.size(); ){ // Trim in case an argument is too large for the width. Shouldn't happen. if( input.get(0).length() > width ){ String tooLong = input.remove(0); input.add(0, tooLong.substring(0, width-5)); } if( input.size() == 1 && (argumentsString.toString().length() + input.get(0).length() <= width)){ argumentsString.append(input.remove(0)); }else if( argumentsString.toString().length() + input.get(0).length() + 2 <= width ){ argumentsString.append(input.remove(0)).append(", "); }else{ break; } } output.add(argumentsString.toString()); segmentArguments(input, output, depth+1); } }
private static String getCommand(int i){ segmentInstructions(instructions.get(i), segmentedInstructions); segmentArguments(arguments.get(i), segmentedArguments, 0);
protected static String usage(String executableBaseName) { boolean isWindows = (WildFlySecurityManager.getPropertyPrivileged("os.name", null)).toLowerCase(Locale.ENGLISH).contains("windows"); String executableName = isWindows ? executableBaseName : executableBaseName + ".sh"; if (USAGE == null) { final StringBuilder sb = new StringBuilder(); sb.append(NEW_LINE).append(ProcessLogger.ROOT_LOGGER.argUsage(executableName)).append(NEW_LINE); for (int i = 0; i < arguments.size(); i++) { sb.append(getCommand(i)).append(NEW_LINE); } USAGE = sb.toString(); } return USAGE; }
private static void segmentInstructions(String instructions, List<String> segments) { if (instructions.length() <= 40) { segments.add(instructions); } else { String testFragment = instructions.substring(0,40); int lastSpace = testFragment.lastIndexOf(' '); if (lastSpace < 0) { // degenerate case; we just have to chop not at a space lastSpace = 39; } segments.add(instructions.substring(0, lastSpace + 1)); segmentInstructions(instructions.substring(lastSpace + 1), segments); } }
private static void segmentArguments(List<String> input, List<String> output, int depth){ int width = 30; if( depth == 0 ){ width = 35; } if( input.size() == 0 ){ }else{ StringBuilder argumentsString = new StringBuilder(); for( int i = 0; i < input.size(); ){ // Trim in case an argument is too large for the width. Shouldn't happen. if( input.get(0).length() > width ){ String tooLong = input.remove(0); tooLong.substring(0, width-5); input.add("Command removed. Too long."); } if( input.size() == 1 && (argumentsString.toString().length() + input.get(0).length() <= width)){ argumentsString.append(input.remove(0)); }else if( argumentsString.toString().length() + input.get(0).length() + 2 <= width ){ argumentsString.append(input.remove(0) + ", "); }else{ break; } } output.add(argumentsString.toString()); segmentArguments(input, output, depth+1); } }
protected static String usage(String executableBaseName) { boolean isWindows = (WildFlySecurityManager.getPropertyPrivileged("os.name", null)).toLowerCase(Locale.ENGLISH).contains("windows"); String executableName = isWindows ? executableBaseName : executableBaseName + ".sh"; if (USAGE == null) { final StringBuilder sb = new StringBuilder(); sb.append(NEW_LINE).append(ProcessLogger.ROOT_LOGGER.argUsage(executableName)).append(NEW_LINE); for (int i = 0; i < arguments.size(); i++) { sb.append(getCommand(i)).append(NEW_LINE); } USAGE = sb.toString(); } return USAGE; }
private static void segmentInstructions(String instructions, List<String> segments) { if (instructions.length() <= 40) { segments.add(instructions); } else { String testFragment = instructions.substring(0,40); int lastSpace = testFragment.lastIndexOf(' '); if (lastSpace < 0) { // degenerate case; we just have to chop not at a space lastSpace = 39; } segments.add(instructions.substring(0, lastSpace + 1)); segmentInstructions(instructions.substring(lastSpace + 1), segments); } }