Esempio n. 1
0
  /**
   * (Compiles and) loads all custom abilities in the given directory.
   *
   * @param classDir a directory
   */
  private static void loadClasses(File classDir) {
    // Grab the class loader
    ClassLoader loader = getLoader(classDir);
    if (loader == null) return;

    for (File file : classDir.listFiles()) {
      String filename = file.getName();

      // Only load .class files.
      int dot = filename.lastIndexOf(".class");
      if (dot < 0) continue;

      // Trim off the .class extension
      String name = filename.substring(0, file.getName().lastIndexOf("."));

      try {
        // Load the class
        Class<?> cls = loader.loadClass(name);

        // Verify that it's an Ability, then register it
        if (Ability.class.isAssignableFrom(cls)) {
          register(cls.asSubclass(Ability.class), true);
        }
      } catch (Exception e) {
      }
    }
  }
 public static Map<Lang, Result> convert(
     ClassLoader loader, List<Lang> langs, String source, String fqn, String method)
     throws Exception {
   URL url = loader.getResource(source);
   if (url == null) {
     throw new Exception("Cannot resolve source " + source + "");
   }
   String file = new File(url.toURI()).getAbsolutePath();
   return convertFromFiles(loader, langs, file, fqn, method);
 }
Esempio n. 3
0
 /**
  * Loads a class in runtime using default classpath.
  *
  * @param className class name.
  * @return Class type.
  */
 public static Class loadClass(String className) throws ClassNotFoundException {
   ClassLoader classLoader = ClassLoader.getSystemClassLoader();
   return classLoader.loadClass(className);
 }