use of java.lang.reflect.Method in project killbill by killbill.
the class Migrator method addJarOrDirectoryToClasspath.
/**
* Adds a jar or a directory with this name to the classpath.
*
* @param name The name of the jar or directory to add.
* @throws IOException when the jar or directory could not be found.
*/
private static void addJarOrDirectoryToClasspath(final String name) throws IOException {
LOG.debug("Adding location to classpath: " + name);
try {
final URL url = new File(name).toURI().toURL();
final URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
final Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
method.setAccessible(true);
method.invoke(sysloader, url);
} catch (final Exception e) {
throw new FlywayException("Unable to load " + name, e);
}
}
use of java.lang.reflect.Method in project killbill by killbill.
the class AnnotationHierarchicalResolver method findAnnotation.
// The following comes from spring-core (AnnotationUtils) to handle annotations on interfaces
/**
* Get a single {@link Annotation} of <code>annotationType</code> from the supplied {@link java.lang.reflect.Method},
* traversing its super methods if no annotation can be found on the given method itself.
* <p>Annotations on methods are not inherited by default, so we need to handle this explicitly.
*
* @param method the method to look for annotations on
* @param annotationType the annotation class to look for
* @return the annotation found, or <code>null</code> if none found
*/
public static <A extends Annotation> A findAnnotation(final Method method, final Class<A> annotationType) {
A annotation = getAnnotation(method, annotationType);
Class<?> cl = method.getDeclaringClass();
if (annotation == null) {
annotation = searchOnInterfaces(method, annotationType, cl.getInterfaces());
}
while (annotation == null) {
cl = cl.getSuperclass();
if (cl == null || cl == Object.class) {
break;
}
try {
final Method equivalentMethod = cl.getDeclaredMethod(method.getName(), method.getParameterTypes());
annotation = getAnnotation(equivalentMethod, annotationType);
if (annotation == null) {
annotation = searchOnInterfaces(method, annotationType, cl.getInterfaces());
}
} catch (NoSuchMethodException ex) {
// We're done...
}
}
return annotation;
}
use of java.lang.reflect.Method in project android-gif-drawable by koral--.
the class LibraryLoader method getContext.
private static Context getContext() {
if (sAppContext == null) {
try {
final Class<?> activityThread = Class.forName("android.app.ActivityThread");
final Method currentApplicationMethod = activityThread.getDeclaredMethod("currentApplication");
sAppContext = (Context) currentApplicationMethod.invoke(null);
} catch (Exception e) {
throw new IllegalStateException("LibraryLoader not initialized. Call LibraryLoader.initialize() before using library classes.", e);
}
}
return sAppContext;
}
use of java.lang.reflect.Method in project ion by koush.
the class ConscryptMiddleware method initialize.
public static void initialize(Context context) {
try {
synchronized (lock) {
if (initialized)
return;
initialized = true;
// GMS Conscrypt is already initialized, from outside ion. Leave it alone.
if (Security.getProvider(GMS_PROVIDER) != null) {
success = true;
return;
}
SSLContext originalDefaultContext = SSLContext.getDefault();
SSLSocketFactory originalDefaultSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
try {
Class<?> providerInstaller = Class.forName("com.google.android.gms.security.ProviderInstaller");
Method mInsertProvider = providerInstaller.getDeclaredMethod("installIfNeeded", Context.class);
mInsertProvider.invoke(null, context);
} catch (Throwable ignored) {
Context gms = context.createPackageContext("com.google.android.gms", Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
gms.getClassLoader().loadClass("com.google.android.gms.common.security.ProviderInstallerImpl").getMethod("insertProvider", Context.class).invoke(null, context);
}
Provider[] providers = Security.getProviders();
Provider provider = Security.getProvider(GMS_PROVIDER);
Security.removeProvider(GMS_PROVIDER);
Security.insertProviderAt(provider, providers.length);
SSLContext.setDefault(originalDefaultContext);
HttpsURLConnection.setDefaultSSLSocketFactory(originalDefaultSSLSocketFactory);
success = true;
}
} catch (Exception e) {
Log.w(LOGTAG, "Conscrypt initialization failed.");
}
}
use of java.lang.reflect.Method in project Lazy by l123456789jy.
the class BadgeUtil method setBadgeOfMIUI.
/**
* 设置MIUI的Badge
*
* @param context context
* @param count count
* @param icon icon
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private static void setBadgeOfMIUI(Context context, int count, int icon) {
Log.d("xys", "Launcher : MIUI");
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(context).setContentTitle("title").setContentText("text").setSmallIcon(icon);
Notification notification = builder.build();
try {
Field field = notification.getClass().getDeclaredField("extraNotification");
Object extraNotification = field.get(notification);
Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class);
method.invoke(extraNotification, count);
} catch (Exception e) {
e.printStackTrace();
}
mNotificationManager.notify(0, notification);
}
Aggregations