Search in sources :

Example 41 with Method

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);
    }
}
Also used : FlywayException(org.flywaydb.core.api.FlywayException) URLClassLoader(java.net.URLClassLoader) Method(java.lang.reflect.Method) File(java.io.File) URL(java.net.URL) FlywayException(org.flywaydb.core.api.FlywayException) IOException(java.io.IOException)

Example 42 with Method

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;
}
Also used : Method(java.lang.reflect.Method)

Example 43 with Method

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;
}
Also used : Method(java.lang.reflect.Method)

Example 44 with Method

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.");
    }
}
Also used : Context(android.content.Context) SSLContext(javax.net.ssl.SSLContext) SSLContext(javax.net.ssl.SSLContext) Method(java.lang.reflect.Method) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Provider(java.security.Provider)

Example 45 with Method

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);
}
Also used : Field(java.lang.reflect.Field) NotificationManager(android.app.NotificationManager) Method(java.lang.reflect.Method) Notification(android.app.Notification) TargetApi(android.annotation.TargetApi)

Aggregations

Method (java.lang.reflect.Method)8797 Test (org.junit.Test)1772 InvocationTargetException (java.lang.reflect.InvocationTargetException)1084 ArrayList (java.util.ArrayList)665 Field (java.lang.reflect.Field)611 IOException (java.io.IOException)549 HashMap (java.util.HashMap)352 Map (java.util.Map)290 List (java.util.List)275 PropertyDescriptor (java.beans.PropertyDescriptor)253 Annotation (java.lang.annotation.Annotation)212 Type (java.lang.reflect.Type)202 HashSet (java.util.HashSet)199 File (java.io.File)173 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)170 BeanInfo (java.beans.BeanInfo)166 ParameterizedType (java.lang.reflect.ParameterizedType)132 Constructor (java.lang.reflect.Constructor)131 SimpleBeanInfo (java.beans.SimpleBeanInfo)128 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)128