コード例 #1
0
ファイル: Trampoline2.java プロジェクト: afdreher/Field
 public void addJar(String n) {
   System.out.println(" add jar :" + n);
   try {
     loader.addURL(new URL("file://" + n));
   } catch (MalformedURLException e) {
     e.printStackTrace();
   }
 }
コード例 #2
0
ファイル: Trampoline2.java プロジェクト: afdreher/Field
  public void addWildcardPathRecursively(String aa) throws MalformedURLException {

    if (aa.contains("examples")) return;

    File dir = new File(aa.replace("**", ""));
    if (dir.exists()) {

      extendLibraryPath(dir.getAbsolutePath());

      String[] ll =
          dir.list(
              new FilenameFilter() {

                public boolean accept(File dir, String name) {
                  return name.endsWith(".jar");
                }
              });
      if (ll != null)
        for (String l : ll) {; // System.out.println(" l = " + l);

          String fp = new File(dir.getAbsolutePath() + "/" + l).getAbsolutePath();

          URL url = new URL("file://" + fp + (fp.endsWith(".jar") ? "" : "/"));

          loader.addURL(url);

          extendedClassPaths.add(fp);
        }
      File[] f =
          dir.listFiles(
              new FileFilter() {

                public boolean accept(File pathname) {
                  return pathname.isDirectory();
                }
              });
      if (f != null) {
        for (File ff : f) {
          addWildcardPathRecursively(ff.getAbsolutePath());
        }
      }
    } else {
      System.err.println(
          " warning: wildcard path <" + aa + "> is not a directory or does not exist ");
    }
  }
コード例 #3
0
ファイル: Trampoline2.java プロジェクト: afdreher/Field
  public void addWildcardPath(String aa) throws MalformedURLException {

    File dir = new File(aa.replace("**", ""));
    if (dir.exists()) {

      loader.addURL(new URL("file://" + dir.getAbsolutePath() + "/"));

      extendedClassPaths.add(dir.getAbsolutePath());

      extendLibraryPath(dir.getAbsolutePath());

      String[] ll =
          dir.list(
              new FilenameFilter() {

                public boolean accept(File dir, String name) {
                  return name.endsWith(".jar");
                }
              });
      if (ll != null)
        for (String l : ll) {

          String fp = new File(dir.getAbsolutePath() + "/" + l).getAbsolutePath();

          URL url = new URL("file://" + fp + (fp.endsWith(".jar") ? "" : "/"));

          loader.addURL(url);

          extendedClassPaths.add(fp);
        }
      File[] f =
          dir.listFiles(
              new FileFilter() {

                public boolean accept(File pathname) {
                  return pathname.isDirectory();
                }
              });
      if (f != null) {
        for (File ff : f) {
          addExtensionsDirectory(ff);
        }
      }

      System.out.println(" checking <" + dir + "> for natives ");
      File[] natives =
          dir.listFiles(
              new FileFilter() {
                public boolean accept(File file) {
                  return file.getPath().endsWith(".dylib") || file.getPath().endsWith(".jnilib");
                }
              });
      System.out.println(" found <" + natives.length + ">");
      for (File n : natives) {
        try {
          //					System.out.println(" preemptive load of <" + n + ">");
          //					System.load(n.getAbsolutePath());
        } catch (Throwable t) {
          t.printStackTrace();
        }
      }
    } else {
      System.err.println(
          " warning: wildcard path <" + aa + "> is not a directory or does not exist ");
    }
  }
コード例 #4
0
ファイル: Trampoline2.java プロジェクト: afdreher/Field
  public void addExtensionsDirectory(File path) {
    if (path.getName().endsWith("**"))
      path = new File(path.getAbsolutePath().substring(0, path.getAbsolutePath().length() - 2));

    if (path.exists()) {

      // ;//System.out.println(" adding extenions dir <" +
      // path +
      // ">");

      try {

        System.out.println(" adding to loader <" + "file://" + path.getAbsolutePath() + "/" + ">");

        loader.addURL(new URL("file://" + path.getCanonicalPath() + "/"));

        // URL[] uu = loader.getURLs();
        // for(URL uuu : uu)
        // ;//System.out.println("     "+uuu);

      } catch (MalformedURLException e1) {
        e1.printStackTrace();
      } catch (IOException e1) {
        e1.printStackTrace();
      }
      extendedClassPaths.add(path.getAbsolutePath());

      String[] jars =
          path.list(
              new FilenameFilter() {
                public boolean accept(File dir, String name) {
                  return (name.endsWith(".jar"));
                }
              });

      if (jars != null)
        for (String j : jars) {
          try {
            loader.addURL(new URL("file://" + path.getCanonicalPath() + "/" + j));

            extendedClassPaths.add(path.getCanonicalPath() + "/" + j);

            JarFile m = new JarFile(new File(path.getCanonicalFile() + "/" + j));
            Manifest manifest = m.getManifest();
            if (manifest != null) {
              String a =
                  (String)
                      manifest.getMainAttributes().get(new Attributes.Name("Field-PluginClass"));
              ; // System.out.println(" jar <"
              // + path +
              // "> declares plugin <"
              // + a + ">");
              if (a != null) {
                plugins.add(a);
              }

              injectManifestProperties(manifest);
            }
          } catch (MalformedURLException e) {
            e.printStackTrace();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      System.out.println(" checking <" + path + "> for natives ");
      File[] natives =
          path.listFiles(
              new FileFilter() {
                public boolean accept(File file) {
                  return file.getPath().endsWith(".dylib") || file.getPath().endsWith(".jnilib");
                }
              });
      System.out.println(" found <" + natives.length + ">");
      for (File n : natives) {
        try {
          //					System.load(n.getAbsolutePath());
        } catch (Throwable t) {
          t.printStackTrace();
        }
      }

      File[] dirs =
          path.listFiles(
              new FileFilter() {
                public boolean accept(File file) {
                  return file.isDirectory() && !file.getName().endsWith("_");
                }
              });
      for (File j : dirs) {
        // ;//System.out.println(" adding next dir <" +
        // j +
        // ">");
        addExtensionsDirectory(j);
        // try {
        // loader.addURL(new URL("file://" +
        // j.getAbsolutePath()));
        // extendedClassPaths.add(j.getAbsolutePath());
        // } catch (MalformedURLException e) {
        // e.printStackTrace();
        // }
      }

      File[] rawManifests =
          path.listFiles(
              new FileFilter() {
                public boolean accept(File file) {
                  return (file.getAbsolutePath().endsWith(".mf")
                          && !prohibitExtension(
                              file.getName().substring(0, file.getName().length() - 3)))
                      || ((file.getAbsolutePath().endsWith(".mf_"))
                          && alsoAcceptExtension(
                              file.getName().substring(0, file.getName().length() - 4)));
                }
              });
      for (File j : rawManifests) {
        // ;//System.out.println(" adding raw manifest <"
        // +
        // j + ">");
        try {
          Manifest m = new Manifest(new BufferedInputStream(new FileInputStream(j)));
          String aa =
              (String) m.getMainAttributes().get(new Attributes.Name("Field-RedirectionPath"));
          ; // System.out.println(aa + " " + j);

          if (aa != null && aa.endsWith("**")) {

            addWildcardPath(aa);
          } else if (aa != null) {
            for (String a : aa.split(":")) {
              a = a.trim();
              String fp =
                  (new File(a).isAbsolute()
                      ? new File(a).getAbsolutePath()
                      : new File(j.getParent(), a).getAbsolutePath());
              if (!extendedClassPaths.contains(fp)) {

                if (!new File(fp).exists()) {
                  System.err.println(
                      " warning, path <"
                          + new File(fp).getAbsolutePath()
                          + ">added to classpath through Field-RedirectionPath inside extension "
                          + j
                          + " doesn't exist");
                } else {

                  URL url = new URL("file://" + fp + (fp.endsWith(".jar") ? "" : "/"));

                  ; // System.out.println(" adding url to main classloader <"
                  // + url
                  // +
                  // "> <"
                  // + new
                  // File(url.getPath()).exists()
                  // +
                  // ">");

                  loader.addURL(url);

                  extendedClassPaths.add(fp);
                }
              }
            }
          } else {
          }
          String b = (String) m.getMainAttributes().get(new Attributes.Name("Field-PluginClass"));
          if (b != null) {
            plugins.add(b);
          }

          injectManifestProperties(m);

        } catch (FileNotFoundException e) {
          // TODO
          // Auto-generated
          // catch
          // block
          e.printStackTrace();
        } catch (IOException e) {
          // TODO
          // Auto-generated
          // catch
          // block
          e.printStackTrace();
        }
      }
    }
  }