Given a class generates a manifest file with main-class as class.

@param klass to set as Main-Class in manifest file.
@return An instance {@link java.util.jar.Manifest}
422207
public static Manifest getManifestWithMainClass(Class<?> klass) {
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(ManifestFields.MANIFEST_VERSION, "1.0");
    manifest.getMainAttributes().put(ManifestFields.MAIN_CLASS, klass.getName());
    return manifest;
  }
887789
public InternalRunner createStrict(Class<?> klass) throws InvocationTargetException {
        return create(klass, new Supplier<MockitoTestListener>() {
            public MockitoTestListener get() {
                return new MismatchReportingTestListener(Plugins.getMockitoLogger());
            }
        });
    }
725915
public InternalRunner createStrictStubs(Class<?> klass) throws InvocationTargetException {
        return create(klass, new Supplier<MockitoTestListener>() {
            public MockitoTestListener get() {
                return new StrictStubsRunnerTestListener();
            }
        });
    }
511621
public Action build(Class<?> cls) {
        EdmAction edmAction = cls.getAnnotation(EdmAction.class);
        EdmReturnType edmReturnType = cls.getAnnotation(EdmReturnType.class);
        Set<Parameter> parameters = new HashSet<>();
        for (Field field : cls.getDeclaredFields()) {
            EdmParameter parameterAnnotation = field.getAnnotation(EdmParameter.class);
            if (parameterAnnotation != null) {

                String parameterName = isNullOrEmpty(parameterAnnotation.name())
                        ? field.getName() : parameterAnnotation.name();
                String parameterType = isNullOrEmpty(parameterAnnotation.type())
                        ? field.getType().getSimpleName() : parameterAnnotation.type();
                parameters.add(new ParameterImpl.Builder()
                        .setMaxLength(parameterAnnotation.maxLength())
                        .setName(parameterName)
                        .setNullable(parameterAnnotation.nullable())
                        .setPrecision(parameterAnnotation.precision())
                        .setScale(parameterAnnotation.scale())
                        .setSRID(parameterAnnotation.srid())
                        .setType(parameterType)
                        .setUnicode(parameterAnnotation.unicode())
                        .setJavaField(field)
                        .build());
            }
        }

        return new ActionImpl.Builder()
                .setName(getTypeName(edmAction, cls))
                .setNamespace(getNamespace(edmAction, cls))
                .setBound(edmAction.isBound())
                .setEntitySetPath(edmAction.entitySetPath())
                .setParameters(parameters)
                .setReturnType(edmReturnType.type())
                .setJavaClass(cls)
                .build();
    }
615806
protected PluginClassLoader createPluginClassLoader(final File pluginFile) throws IOException {
        return new PluginClassLoader(pluginFile, Thread.currentThread().getContextClassLoader()) {
            @Override
            protected File createWorkDir(File pluginArtifactFile) throws IOException {
                File workDir = new File(pluginFile.getParentFile(), ".work"); //$NON-NLS-1$
                workDir.mkdirs();
                return workDir;
            }
        };
    }
261464
public <C extends Controller> AbstractModule controller(Class<C> klass) {
        String name = klass.getName();
        JSClosure constructor = JSClosure.create(new DefaultControllerConstructor<C>(name, klass));
        ControllerDependencyInspector inspector = GWT.create(ControllerDependencyInspector.class);
        JSArray<String> dependencies = JSArray.create(inspector.inspect(klass));
        dependencies.unshift("$scope");
        ngo.controller(name, dependencies, constructor);
        return this;
    }
40605
private void createClassLoader() {
        if (!Utils.isNullOrEmpty(settings.getJarFiles())) {
            try {
                String[] files = settings.getJarFiles().split(";");
                List<URL> urls = newArrayList();
                for (String path : files) {
                    File file = new File(path);
                    if (file.isFile()) {
                        urls.add(file.toURI().toURL());
                    }
                }
                classLoader = new Java4CppClassLoader(urls.toArray(new URL[files.length]), classLoader);
            } catch (Exception e) {
                throw new RuntimeException("Failed to load jar " + e.getMessage());
            }
        }
    }
584295
private static BotDefinition instantiateClass(
			Class<? extends BotDefinition> klass) {
		BotDefinition definition = null;
		try {
			definition = klass.newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return definition;
	}
168747
public static File getClassFile(Class<?> clazz) {
    File dir = new File(clazz.getProtectionDomain().getCodeSource().getLocation().getPath());
    if (!dir.isDirectory()) return null; // class file might be contained in Jar
    File clazzFile = new File(dir, clazz.getName().replace('.', File.separatorChar) + ".class");
    return clazzFile.isFile() ? clazzFile : null;
  }
128125
public static Manifest readManifestFromExternalJar(File jarFile) {
        if (!jarFile.getName().endsWith(".jar")) {
            throw new IllegalArgumentException("not jar file : " + jarFile);
        }
        InputStream in = null;
        String urlStr = "jar:file:" + jarFile.getAbsolutePath() + "!/META-INF/MANIFEST.MF";
          try {
            URL inputURL = new URL(urlStr);
            JarURLConnection conn = (JarURLConnection) inputURL.openConnection();
            in = conn.getInputStream();
            return new Manifest(in);
          } catch (FileNotFoundException e) {
              return null;
          } catch (IOException e) {
              throw new RuntimeException(e);
          } finally {
              IOUtils.closeQuietly(in);
          }
    }
951740
public <T extends StoreConfigurationBuilder<?, ?>> T addStore(Class<T> klass) {
      try {
         Constructor<T> constructor = klass.getDeclaredConstructor(PersistenceConfigurationBuilder.class);
         T builder = constructor.newInstance(this);
         this.stores.add(builder);
         return builder;
      } catch (Exception e) {
         throw new CacheConfigurationException("Could not instantiate loader configuration builder '" + klass.getName()
               + "'", e);
      }
   }
1193554
public static <C extends Configurable> C getConfiguration(Class<C> klass, Properties properties) {
        //Initialize configuration object
        C configuration;
        try {
            Constructor<C> constructor = klass.getDeclaredConstructor();
            constructor.setAccessible(true);
            configuration = constructor.newInstance();
        }
        catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException ex) {
            throw new RuntimeException(ex);
        }

        configuration.load(properties);

        return configuration;
    }
1202863
public void addClass(Class<?> klass) throws Exception {
        // 只读取public的属性
        for (Field field : klass.getFields()) {
            // 只读取PROP_开头的属性
            if (!field.getName().startsWith("PROP_"))
                continue;
            // 不带@ProcDoc? 跳过
            PropDoc prop = field.getAnnotation(PropDoc.class);
            if (prop == null)
                continue;
            // 如果不设置key,那就取字段的值,通常也是这样
            String key = Strings.isBlank(prop.key()) ? (String) field.get(null) : prop.key();

            // 如果对于的key不存在,那就新建一个PropDocBean,否则就取老的
            PropDocBean doc = new PropDocBean();
            doc.key = key;
            doc.defaultValue = prop.defaultValue();
            doc.value = prop.value();
            doc.group = Strings.isBlank(prop.group()) ? doc.key.substring(0, doc.key.indexOf('.')) : prop.group();
            doc.need = prop.need();
            doc.possible = prop.possible();
            doc.users = new ArrayList<>();
            add(klass.getName(), key, doc);
        }
    }
1286817
public static String findMainClass(JarFile jarFile, String classesLocation)
			throws IOException {
		return doWithMainClasses(jarFile, classesLocation, MainClass::getName);
	}
636787
public InternalRunner create(Class<?> klass) throws InvocationTargetException {
        return create(klass, new Supplier<MockitoTestListener>() {
            public MockitoTestListener get() {
                return new NoOpTestListener();
            }
        });
    }
796309
@VisibleForTesting
  Map<String, Plugin> instantiatePluginClasses(Map<PluginClassLoaderDef, ClassLoader> classloaders) {
    // instantiate plugins
    Map<String, Plugin> instancesByPluginKey = new HashMap<>();
    for (Map.Entry<PluginClassLoaderDef, ClassLoader> entry : classloaders.entrySet()) {
      PluginClassLoaderDef def = entry.getKey();
      ClassLoader classLoader = entry.getValue();

      // the same classloader can be used by multiple plugins
      for (Map.Entry<String, String> mainClassEntry : def.getMainClassesByPluginKey().entrySet()) {
        String pluginKey = mainClassEntry.getKey();
        String mainClass = mainClassEntry.getValue();
        try {
          instancesByPluginKey.put(pluginKey, (Plugin) classLoader.loadClass(mainClass).newInstance());
        } catch (UnsupportedClassVersionError e) {
          throw new IllegalStateException(String.format("The plugin [%s] does not support Java %s",
            pluginKey, SystemUtils.JAVA_VERSION_TRIMMED), e);
        } catch (Throwable e) {
          throw new IllegalStateException(String.format(
            "Fail to instantiate class [%s] of plugin [%s]", mainClass, pluginKey), e);
        }
      }
    }
    return instancesByPluginKey;
  }
1357167
public static <T extends Tree> Matcher<T> isInstance(final java.lang.Class<?> klass) {
    return new Matcher<T>() {
      @Override
      public boolean matches(T t, VisitorState state) {
        return klass.isInstance(t);
      }
    };
  }