public class MetaUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
MetaUtil.LogicTransformer
Logic transformer
|
| Modifier and Type | Field and Description |
|---|---|
static Map<String,Object> |
META_MAP
Generic meta data map
|
static List<Class<?>> |
SIMPLE_RETURN_TYPE_LIST
The simple return type list
|
| Constructor and Description |
|---|
MetaUtil() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addLogic(Instrumentation instr,
String fqcn,
String methodName,
String argLength,
String mode,
String logic) |
static void |
addSourceToJarStream(String prefix,
File source,
JarOutputStream jarStream,
String jarName)
add source to jar stream
|
static List<Class<?>> |
allExtendedClassesOf(Class<?> classz)
All classes that the given class extends
|
static List<Field> |
allFieldsOf(Class<?> classz)
All fields that can be found on an object of the given class
|
static List<Method> |
allMethodsOf(Class<?> classz)
All methods that can be invoked on an object of the given class
|
static List<Field> |
allSuperFieldsOf(Class<?> classz)
All fields that can be found on an object's hierarchy other than itself of the given class
|
static void |
assignFromHierarchy(Object obj)
For each field that the subclass has, if superclasses also have it, then fetch that value
from hierarchy and set here.
|
static int |
availablePort(int startPort,
int maxCount)
Get available server port from the given port inclusive, until the max count.
|
static Map<String,Object> |
classNameObjectMap(Object... objects)
Returns a map containing the object's class name as key with the object itself as value.
|
static void |
copyFields(Object dst,
Object src)
For each field that the destination has, if source also have it, then fetch that value from
source and set in destination.
|
static File |
createJarFromClasses(Class<?> loader,
String folder,
String jarName,
Map<String,String> attributes,
Class<?>... clazzes)
create jar from class definitions
|
static File |
createJarFromClasses(Class<?> loader,
String folder,
String jarName,
Map<String,String> attributes,
List<Class<?>> clazzes)
create jar from class definitions
|
static File |
createJarFromClasses(String folder,
String jarName,
Map<String,String> attributes,
Class<?>... clazzes)
create jar from class definitions
|
static File |
createJarFromDir(String srcDir,
String dstDir,
String name,
Map<String,String> attributes)
create jar from source dir into destination dir
|
static Map<String,Object> |
createMap(String key,
Object value)
Returns a new map which has single entry with the given key and value.
|
static <T> Map<String,T> |
createMap(String key,
Object value,
Class<T> clazz)
Returns a new map which has single entry with the given key and value.
|
static Map<String,Object> |
createParamMap(Object... params)
Create a params map from given varargs.
|
static Map<String,String> |
createPropsMap(String... args)
Create a property map from given varargs.
|
static String |
decompileClass(String className)
Decompile class
|
static void |
disableSslCertificates()
Disables SSL certificates checks
|
static int |
enableJmx()
Enable JMX
|
static void |
enableJmx(int port)
Enable JMX
|
static com.fasterxml.jackson.databind.JsonNode |
encodeForHTML(com.fasterxml.jackson.databind.JsonNode node)
Encode the json node text values for HTML
|
static String |
encodeForHTML(String text)
Encode given text
|
static void |
extractResource(Class<?> loader,
String resourceName,
String folder)
extract a resource
|
static byte[] |
fetchClassDefinitionBytes(Class<?> clazz)
Fetch the class definition bytes
|
static byte[] |
fetchClassDefinitionBytes(Class<?> loader,
Class<?> clazz)
Fetch the class definition bytes
|
static Map<String,Object> |
fieldDataMap(Object target,
boolean prependClassName,
String methodPrefix,
List<Class<?>> returnTypeList)
Get the map of all the return values of all the methods starting with given prefix with the
given return types of the given bean.
|
static List<Class<?>> |
findClasses(File directory,
String packageName)
Recursive method used to find all classes in a given directory and sub dirs.
|
static Field |
findFirstField(Class<?> clazz,
String fieldName)
Finds the first field by this name or null if not found.
|
static Field |
findFirstFieldByType(Class<?> clazz,
String typeName)
Finds the first field by its type name or null if not found.
|
static Method |
findFirstMethod(Class<?> clazz,
String methodName)
Finds the first method by this name or null if not found.
|
static Method |
findFirstMethod(Class<?> classz,
String methodName,
int totalArguments)
Find first method matching name and no.
|
static Method |
findFirstMethodEndsWithAndReturns(Class<?> clazz,
String methodName,
Class<?> returnType)
Finds the first method ending by this name and having this return type or null if not found.
|
static Method |
findFirstMethodStartsWith(Class<?> clazz,
String methodName)
Finds the first method starting by this name or null if not found.
|
static Field |
findFirstSuperField(Class<?> clazz,
String fieldName)
Finds the first super field by this name or null if not found.
|
static Method |
findSetter(Class<?> classz,
String propertyName)
Finds the setter method for the property or null if not found.
|
static boolean |
ftpUpload(org.apache.commons.net.ftp.FTPClient ftpClient,
File local,
String remote,
boolean recursive)
ftp upload recursive
|
static boolean |
ftpUpload(String ftpUrl,
String local,
String remote)
upload to ftp
|
static boolean |
ftpUpload(String ftpUrl,
String local,
String remote,
boolean recursive)
upload to ftp
|
static List<Class<?>> |
getClasses(String packageName)
Scans all classes accessible from the context class loader which belong to the given package
and sub packages.
|
static List<Class<?>> |
getLoadedClassesByName(Instrumentation instr,
String className)
get loaded classes by name from instrumentation
|
static byte[] |
getResourceAsBytes(Class<?> loader,
String resourceName)
Get the resource as bytes.
|
static byte[] |
getResourceAsBytes(String resourceName)
Get the resource as bytes.
|
static String |
getResourceAsString(String resourceName)
Get the resource as string.
|
static long |
hash(String string)
Computes a long hash for this string.
|
static void |
registerAsMBean(Object bean)
Register the instance as MBean.
|
static void |
registerAsMBean(Object bean,
String objectName)
Register the instance as MBean with given name.
|
static Object |
runNestedMethod(Object target,
String nestedMethod)
Run the nested method on the target object.
|
static Map<String,Object> |
runNestedMethodsSilently(Object target,
String nestedMethods)
Run the nested methods silently on the target object.
|
static void |
setPropertyIfExists(Object obj,
String propertyName,
Object propertyValue)
Sets the given property if exists with the given value.
|
static void |
shuffleArray(Object array)
Shuffles the given array, if it is array.
|
static Map<String,Object> |
simpleFieldDataMap(Object target,
boolean prependClassName)
Get the map of all the return values of all the methods with no arguments with simple return
types of the given bean.
|
static File |
writeClassDefinition(Class<?> loader,
String folder,
Class<?> clazz)
Write class definition to file
|
static File |
writeClassDefinition(String folder,
Class<?> clazz)
Write class definition to file
|
static void |
writeClassDefinitions(Class<?> loader,
String folder,
Class<?>... clazzes)
Write class definition to file
|
static void |
writeClassDefinitions(Class<?> loader,
String folder,
List<Class<?>> clazzes)
Write class definition to file
|
static void |
writeClassDefinitions(String folder,
Class<?>... clazzes)
Write class definition to file
|
public static Map<String,Object> createParamMap(Object... params)
params - the paramspublic static String getResourceAsString(String resourceName)
resourceName - the resource namepublic static byte[] getResourceAsBytes(String resourceName)
resourceName - the resource namepublic static byte[] getResourceAsBytes(Class<?> loader, String resourceName)
resourceName - the resource nameloader - the class loaderpublic static void registerAsMBean(Object bean) throws JMException
bean - the beanJMException - implicitpublic static void registerAsMBean(Object bean, String objectName) throws JMException
bean - the beanobjectName - the object nameJMException - implicitpublic static Method findFirstMethodStartsWith(Class<?> clazz, String methodName)
clazz - the classmethodName - the method namepublic static Method findFirstMethodEndsWithAndReturns(Class<?> clazz, String methodName, Class<?> returnType)
clazz - the classmethodName - the method namereturnType - the return typepublic static Method findFirstMethod(Class<?> clazz, String methodName)
clazz - the classmethodName - the method namepublic static Method findFirstMethod(Class<?> classz, String methodName, int totalArguments)
classz - the classmethodName - the method nametotalArguments - the total no. of argumentspublic static List<Class<?>> allExtendedClassesOf(Class<?> classz)
classz - the classpublic static List<Method> allMethodsOf(Class<?> classz)
classz - the classpublic static Field findFirstField(Class<?> clazz, String fieldName)
clazz - the classfieldName - the field namepublic static Field findFirstSuperField(Class<?> clazz, String fieldName)
clazz - the classfieldName - the field namepublic static Field findFirstFieldByType(Class<?> clazz, String typeName)
clazz - the classtypeName - the field type simple namepublic static List<Field> allFieldsOf(Class<?> classz)
classz - the classpublic static List<Field> allSuperFieldsOf(Class<?> classz)
classz - the classpublic static Method findSetter(Class<?> classz, String propertyName)
classz - the classpropertyName - the property namepublic static void setPropertyIfExists(Object obj, String propertyName, Object propertyValue)
obj - the objectpropertyName - the property namepropertyValue - the property valuepublic static Map<String,Object> fieldDataMap(Object target, boolean prependClassName, String methodPrefix, List<Class<?>> returnTypeList)
target - the target objectprependClassName - the prepend class namemethodPrefix - the method prefixreturnTypeList - the return types listpublic static Map<String,Object> simpleFieldDataMap(Object target, boolean prependClassName)
target - the target objectprependClassName - the prepend class namepublic static Map<String,Object> classNameObjectMap(Object... objects)
objects - the objectspublic static Map<String,Object> createMap(String key, Object value)
key - the keyvalue - the valuepublic static <T> Map<String,T> createMap(String key, Object value, Class<T> clazz)
T - the type of valueskey - the keyvalue - the valuepublic static Map<String,String> createPropsMap(String... args)
args - the argumentspublic static void shuffleArray(Object array)
array - the array to shufflepublic static int availablePort(int startPort,
int maxCount)
startPort - the start portmaxCount - the max countpublic static Object runNestedMethod(Object target, String nestedMethod) throws ReflectiveOperationException, ScriptException
target - the target objectnestedMethod - the nested methodScriptException - when there is a problem in scriptReflectiveOperationException - when a problem in reflectionpublic static Map<String,Object> runNestedMethodsSilently(Object target, String nestedMethods)
target - the target objectnestedMethods - the nested methods separated by ;;public static void disableSslCertificates()
throws GeneralSecurityException
GeneralSecurityException - if anything wrong happenspublic static long hash(String string)
string - the stringpublic static void assignFromHierarchy(Object obj)
obj - the objectpublic static void copyFields(Object dst, Object src)
dst - the destination objectsrc - the source objectpublic static int enableJmx()
throws IOException
IOExceptionpublic static void enableJmx(int port)
throws IOException
IOException - if anything goes wrongpublic static byte[] fetchClassDefinitionBytes(Class<?> loader, Class<?> clazz) throws IOException
loader - the loaderclazz - the classIOException - if problempublic static byte[] fetchClassDefinitionBytes(Class<?> clazz) throws IOException
clazz - the classIOException - if problempublic static File writeClassDefinition(Class<?> loader, String folder, Class<?> clazz) throws IOException
loader - the loaderclazz - the classfolder - the folderIOException - if problempublic static File writeClassDefinition(String folder, Class<?> clazz) throws IOException
clazz - the classfolder - the folderIOException - if problempublic static void writeClassDefinitions(Class<?> loader, String folder, List<Class<?>> clazzes) throws IOException
loader - the loaderclazzes - the classesfolder - the folderIOException - if problempublic static void writeClassDefinitions(Class<?> loader, String folder, Class<?>... clazzes) throws IOException
loader - the loaderclazzes - the classesfolder - the folderIOException - if problempublic static void writeClassDefinitions(String folder, Class<?>... clazzes) throws IOException
clazzes - the classesfolder - the folderIOException - if problempublic static void addSourceToJarStream(String prefix, File source, JarOutputStream jarStream, String jarName) throws IOException
source - the sourcejarStream - the streamprefix - the prefixjarName - the jar nameIOException - if problempublic static File createJarFromDir(String srcDir, String dstDir, String name, Map<String,String> attributes) throws IOException
srcDir - the sourcedstDir - the destname - the nameattributes - the attributesIOException - if problempublic static File createJarFromClasses(Class<?> loader, String folder, String jarName, Map<String,String> attributes, List<Class<?>> clazzes) throws IOException
folder - the folderjarName - the jar nameattributes - the attributesclazzes - the classesIOException - if problempublic static File createJarFromClasses(Class<?> loader, String folder, String jarName, Map<String,String> attributes, Class<?>... clazzes) throws IOException
folder - the folderjarName - the jar nameattributes - the attributesclazzes - the classesIOException - if problempublic static File createJarFromClasses(String folder, String jarName, Map<String,String> attributes, Class<?>... clazzes) throws IOException
folder - the folderjarName - the jar nameattributes - the attributesclazzes - the classesIOException - if problempublic static boolean ftpUpload(String ftpUrl, String local, String remote) throws IOException
ftpUrl - the urllocal - the localremote - the remoteIOException - if problempublic static boolean ftpUpload(String ftpUrl, String local, String remote, boolean recursive) throws IOException
ftpUrl - the urllocal - the localremote - the remoterecursive - if recursiveIOException - if problempublic static boolean ftpUpload(org.apache.commons.net.ftp.FTPClient ftpClient,
File local,
String remote,
boolean recursive)
throws IOException
ftpClient - the clientlocal - the localremote - the remoterecursive - if recursiveIOException - if problempublic static void extractResource(Class<?> loader, String resourceName, String folder) throws IOException
loader - the loaderresourceName - the namefolder - the folderIOException - if problempublic static List<Class<?>> getLoadedClassesByName(Instrumentation instr, String className)
instr - the instrumentationclassName - the namepublic static void addLogic(Instrumentation instr, String fqcn, String methodName, String argLength, String mode, String logic) throws Exception
instr - the instrumentationfqcn - the class namemethodName - the method namesargLength - the arg lengthsmode - the modeslogic - the logicsException - if problempublic static List<Class<?>> getClasses(String packageName) throws ClassNotFoundException, IOException
packageName - The base packageClassNotFoundExceptionIOException - if problempublic static List<Class<?>> findClasses(File directory, String packageName) throws ClassNotFoundException
directory - The base directorypackageName - The package name for classes found inside the base directoryClassNotFoundException - if problempublic static String encodeForHTML(String text)
text - to encodepublic static com.fasterxml.jackson.databind.JsonNode encodeForHTML(com.fasterxml.jackson.databind.JsonNode node)
node - the node to be encodedCopyright © 2017. All rights reserved.