private static GeoWaveBaseConverter<?> getParameterBaseConverter( Parameter parameter ) { GeoWaveBaseConverter<?> converter = null; try { Constructor<?> ctor = parameter.converter().getConstructor( String.class); if (ctor != null) { converter = (GeoWaveBaseConverter<?>) ctor.newInstance(new Object[] { "" }); } } catch (Exception e) { LOGGER.error( "An error occurred getting converter from parameter: " + e.getLocalizedMessage(), e); } return converter; }
@Override public IStringConverter<?> getConverterInstance(Parameter parameter, Class<?> forType, String optionName) { if (Path.class.equals(forType)) { return new CustomPathConverter(); } return null; }
private void appendPullRequestsCommentArguments(StringBuilder builder, List<Field> fields, boolean namedArguments) { for (Field field : fields) { Parameter parameter = field.getAnnotation(Parameter.class); String[] names = parameter.names(); if (names.length > 0) { String name = names[0]; if (!namedArguments) { continue; } builder.append(" "); builder.append(name); } else { if (namedArguments) { continue; } } Object value = getFieldValue(field, this); if (value != null) { builder.append(" "); if (value instanceof Collection) { builder.append(Strings.join((Collection) value, " ")); } else if (value instanceof Object[]) { builder.append(Strings.join(" ", (Object[]) value)); } else { builder.append(value); } } } }
private CharSequence generateFlagsInfo(Element classElement) throws ElementException { StringBuilder sb = new StringBuilder(); AnnotationHelper<UsesFlags> annotation = annotationHelper(classElement, UsesFlags.class); if (annotation == null) { return sb; } StringBuilder flagsString = new StringBuilder(); for (DeclaredType flag : annotation.getClassListValue("value")) { Element flagClass = flag.asElement(); for (Element member : flagClass.getEnclosedElements()) { Parameter flagAnnotation = member.getAnnotation(Parameter.class); if (flagAnnotation == null || !(member instanceof VariableElement) || flagAnnotation.hidden()) { continue; } VariableElement field = (VariableElement) member; flagsString.append(Joiner.on(", ").join(flagAnnotation.names())); flagsString.append(" | *"); flagsString.append(simplerJavaTypes(field)); flagsString.append("* | "); flagsString.append(flagAnnotation.description()); flagsString.append("\n"); } } if (flagsString.length() > 0) { sb.append("\n\n**Command line flags:**\n\n"); sb.append("Name | Type | Description\n"); sb.append("---- | ----------- | -----------\n"); sb.append(flagsString); sb.append("\n"); } return sb; }
@Parameter( names = {"-l", "--log"}, converter = LogLevelConverter.class, description = "Set the log level of the CLI." ) public void setLog(Level log) { GlobalOptions.getGlobalOptions().setLog(log); }
@Override @Parameter(names = { "-c", "--testcase" }, arity = 1, description = "Test case for running conformance against test data. Possible values: [testcase0, testcase1a, testcase1b, testcase2, testcase3, testcase4]") public void setTestcaseId(String testcaseId) { this.testcaseId = testcaseId; }
public ParameterRestFieldValue( final Field field, final Parameter parameter, final Object instance ) { super( field, parameter); this.instance = instance; }
private static void printConfig(Class configClass) throws IllegalAccessException, InstantiationException { Field[] fields = configClass.getDeclaredFields(); System.out.println(); System.out.println("### " + configClass.getSimpleName()); System.out.println(); Object defaultConfig = configClass.newInstance(); System.out.println("|Name|Default|Description|"); System.out.println("|---|---|---|"); try { for (Field field : fields) { field.setAccessible(true); StringBuilder sb = new StringBuilder(); sb.append("|"); Parameter param = field.getDeclaredAnnotation(Parameter.class); if (param != null) { String names = Stream.of(param.names()) .collect(Collectors.joining(", ")); // name sb.append(names).append("|"); // default sb.append(param.required() ? "**required**" : field.get(defaultConfig) + " ").append("|"); // description sb.append(param.description()).append("|"); System.out.println(sb.toString()); } ParametersDelegate delegate = field.getDeclaredAnnotation(ParametersDelegate.class); if (delegate != null) { printConfig(field.getType()); } } } catch (IllegalAccessException e) { e.printStackTrace(); } }
/** * Appends any command specific parameters */ protected void appendPullRequestCommentArguments(StringBuilder builder) { List<Field> fields = findFieldsAnnotatedWith(getClass(), Parameter.class); appendPullRequestsCommentArguments(builder, fields, true); appendPullRequestsCommentArguments(builder, fields, false); }
@Parameter(names = { "-o", "--output" }, converter = FormatConverter.class, help = true, description = "Format the CLIs output.") public void setOutput(AnsiFormatUtils.Format output) { GlobalOptions.getGlobalOptions().setOutput(output); }
@Parameter(names = {"-d", "--debug"}, description = "Show detailed network traffic with halyard daemon.") public void setDebug(boolean debug) { GlobalOptions.getGlobalOptions().setDebug(debug); }
@Parameter(names = {"-a", "--alpha"}, description = "Enable alpha halyard features.") public void setAlpha(boolean alpha) { GlobalOptions.getGlobalOptions().setAlpha(alpha); }
@Parameter(names = {"-q", "--quiet"}, description = "Show no task information or messages. When set, ANSI formatting will be disabled, and all prompts will be accepted.") public void setQuiet(boolean quiet) { GlobalOptions.getGlobalOptions().setQuiet(quiet); GlobalOptions.getGlobalOptions().setColor(!quiet); }
@Parameter(names = { "-c", "--color" }, description = "Enable terminal color output.", arity = 1) public void setColor(boolean color) { GlobalOptions.getGlobalOptions().setColor(color); }
@Parameter(names = { "--daemon-endpoint"}, description = "If supplied, connect to the daemon at this address.") public void setDaemonEndpoint(String address) { GlobalOptions.getGlobalOptions().setDaemonEndpoint(address); }
@Parameter(names = { "--deployment" }, description = "If supplied, use this Halyard deployment. This will _not_ create a new deployment.") public void setDeployment(String deployment) { GlobalConfigOptions.getGlobalConfigOptions().setDeployment(deployment); }
@Parameter public void setParameters(List<String> p) { parameters = p; }
@Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity", required = true) public void setVerbose(Integer v) { verbose = v; }
@Parameter(names = "-groups", description = "Comma-separated list of group names to be run") public void setGroups(String g) { groups = g; }
@Parameter(names = "-debug", description = "Debug mode") public void setDebug(boolean d) { debug = d; }
@Parameter(names = "-long", description = "A long number") public void setLong(long ll) { l = ll; }
@Parameter(names = "-double", description = "A double number") public void setDouble(double d) { doub = d; }
@Parameter(names = "-float", description = "A float number") public void setFloat(float f) { floa = f; }
@Parameter(names = "-bigdecimal", description = "A BigDecimal number") public void setBigDecimal(BigDecimal bd) { bigd = bd; }
@Parameter(names = "-date", description = "An ISO 8601 formatted date.") public void setDate(Date d) { date = d; }
@Override @Parameter(names = { "-f", "--format" }, description = "Flag for whether to format the output.") public void setFormat(boolean format) { this.format = format; }
@Override @Parameter(names = { "-i", "--in-file" }, required = true, arity = 1, description = "Input file or \"-\" for standard input.") public void setInputFile(Resource inFile) { this.inFile = inFile; }
@Override @Parameter(names = { "-n", "--in-file-name" }, arity = 1, description = "Input file name.") public void setInputFileName(@Nullable String inFileName) { this.inFileName = inFileName; }
@Override @Parameter(names = { "-d", "--out-dir" }, arity = 1, description = "Output directory.") public void setOutputDirectory(File outDir) { this.outDir = outDir; }
@Override @Parameter(names = { "-o", "--out-file" }, arity = 1, description = "Output file or \"-\" for standard output.") public void setOutputFile(@Nullable WritableResource outFile) { this.outFile = outFile; }
@Override @Parameter(names = { "-t", "--type" }, required = true, arity = 1, description = "Output render type.") public void setType(ValidatorRenderType type) { this.type = type; }
@Parameter(names={"-p", "-port"}, description="List of SMSC ports", required=true, variableArity=true) public void setSmscPorts(List<String> smscPorts) { this.smscPorts = smscPorts; }
@Parameter(names="-ll", description="Log level, one of: ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF, TRACE", required=false) public void setLogLevel(String logLevel) { this.logLevel = logLevel; }
public ParameterRestField( final Field field, final Parameter parameter ) { this.field = field; this.parameter = parameter; }
public T apply( Field field, Parameter parameter, Object instance );
/** * Attempt to load the datastore configuration from the config file. * * @param configFile * @return */ public boolean loadFromConfig( Properties props, String namespace, File configFile ) { dataStorePlugin = new DataStorePluginOptions(); // load all plugin options and initialize dataStorePlugin with type and // options if (!dataStorePlugin.load( props, namespace)) { return false; } // knowing the datastore plugin options and class type, get all fields // and parameters in order to detect which are password fields if (configFile != null && dataStorePlugin.getFactoryOptions() != null) { File tokenFile = SecurityUtils.getFormattedTokenKeyFileForConfig(configFile); Field[] fields = dataStorePlugin.getFactoryOptions().getClass().getDeclaredFields(); for (Field field : fields) { for (Annotation annotation : field.getAnnotations()) { if (annotation.annotationType() == Parameter.class) { Parameter parameter = (Parameter) annotation; if (JCommanderParameterUtils.isPassword(parameter)) { String storeFieldName = (namespace != null && !"".equals(namespace.trim())) ? namespace + "." + DataStorePluginOptions.OPTS + "." + field.getName() : field.getName(); if (props.containsKey(storeFieldName)) { String value = props.getProperty(storeFieldName); String decryptedValue = value; try { decryptedValue = SecurityUtils.decryptHexEncodedValue( value, tokenFile.getAbsolutePath()); } catch (Exception e) { LOGGER.error( "An error occurred encrypting specified password value: " + e.getLocalizedMessage(), e); } props.setProperty( storeFieldName, decryptedValue); } } } } } tokenFile = null; } // reload datastore plugin with new password-encrypted properties if (!dataStorePlugin.load( props, namespace)) { return false; } return true; }
/** * Method to perform global validation for all plugin options * * @throws Exception */ public void validatePluginOptions( Properties properties ) throws ParameterException { LOGGER.trace("ENTER :: validatePluginOptions()"); PropertiesUtils propsUtils = new PropertiesUtils( properties); boolean defaultEchoEnabled = propsUtils.getBoolean( Constants.CONSOLE_DEFAULT_ECHO_ENABLED_KEY, false); boolean passwordEchoEnabled = propsUtils.getBoolean( Constants.CONSOLE_PASSWORD_ECHO_ENABLED_KEY, defaultEchoEnabled); LOGGER.debug( "Default console echo is {}, Password console echo is {}", new Object[] { defaultEchoEnabled ? "enabled" : "disabled", passwordEchoEnabled ? "enabled" : "disabled" }); for (Field field : this.getClass().getDeclaredFields()) { for (Annotation annotation : field.getAnnotations()) { if (annotation.annotationType() == Parameter.class) { Parameter parameter = (Parameter) annotation; if (JCommanderParameterUtils.isRequired(parameter)) { field.setAccessible(true); // HPFortify // "Access Specifier Manipulation" // False Positive: These // fields are being modified // by trusted code, // in a way that is not // influenced by user input Object value = null; try { value = field.get(this); if (value == null) { JCommander.getConsole().println( "Field [" + field.getName() + "] is required: " + Arrays.toString(parameter.names()) + ": " + parameter.description()); JCommander.getConsole().print( "Enter value for [" + field.getName() + "]: "); boolean echoEnabled = JCommanderParameterUtils.isPassword(parameter) ? passwordEchoEnabled : defaultEchoEnabled; char[] password = JCommander.getConsole().readPassword( echoEnabled); String strPassword = new String( password); password = null; if (!"".equals(strPassword.trim())) { value = (strPassword != null && !"".equals(strPassword.trim())) ? strPassword .trim() : null; } if (value == null) { throw new ParameterException( "Value for [" + field.getName() + "] cannot be null"); } else { field.set( this, value); } } } catch (Exception ex) { LOGGER.error( "An error occurred validating plugin options for [" + this.getClass().getName() + "]: " + ex.getLocalizedMessage(), ex); } } } } } }