Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.deephacks.tools4j.cli;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.deephacks.tools4j.cli.Command.Argument;
import org.deephacks.tools4j.cli.Command.Option;
/**
* Utility code are kept here to avoid distorting readability of other
* classes with code that is irrelevant to their domain.
*/
final class Utils {
/** name of the validator class */
public static final String VALIDATOR_CLASSNAME = "org.deephacks.tools4j.cli.Validator";
/** API class for JSR 303 1.0 bean validation */
public static final String JSR303_1_0_CLASSNAME = "javax.validation.Validation";
/** API class for JSR 303 1.1 bean validation, class only exist in 1.1 */
public static final String JSR303_1_1_CLASSNAME = "javax.validation.metadata.MethodDescriptor";
/** the instance of the Validator object */
private static Object validator;
/** new line character */
public static final String NEWLINE = System.getProperty("line.separator");
static final String AVAILABLE_CMDS_MSG = "Available commands are:";
static Object newInstance(String className) {
try {
Class> type = Thread.currentThread().getContextClassLoader().loadClass(className);
Class> enclosing = type.getEnclosingClass();
if (enclosing == null) {
Constructor> c = type.getDeclaredConstructor();
c.setAccessible(true);
return type.cast(c.newInstance());
}
Object o = enclosing.newInstance();
Constructor> cc = type.getDeclaredConstructor(enclosing);
cc.setAccessible(true);
return type.cast(cc.newInstance(o));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
static String stripTrailingWhitespace(String str) {
if (str == null || "".equals(str.trim())) {
return "";
}
StringBuffer sb = new StringBuffer(str);
int pos = str.length() - 1;
while (true) {
if (Character.isWhitespace(sb.charAt(pos))) {
sb.deleteCharAt(pos--);
} else {
break;
}
}
return sb.toString();
}
/**
* Validate that the method parameters if Bean Validation 1.1 is available
* on classpath.
*/
static void validateArgs(List