Example #1
0
 public static void cleanUpUnpacked(File libDir) {
   if (libDir.exists() && libDir.listFiles(new ExtFilter(".gz")).length > 0) {
     for (File gz : libDir.listFiles(new ExtFilter(".gz"))) {
       try {
         gz.delete();
       } catch (Exception e) {
       }
     }
   }
 }
  /**
   * Recursively scans given directory and load all found files by loader.
   *
   * @param clsLdr Loader that could load class from given file.
   * @param dir Directory which should be scanned.
   * @param rsrcs Set which will be filled in.
   */
  @SuppressWarnings({"UnusedCatchParameter"})
  private static void findResourcesInDirectory(
      GridUriDeploymentFileResourceLoader clsLdr,
      File dir,
      Set<Class<? extends GridTask<?, ?>>> rsrcs) {
    assert dir.isDirectory() == true;

    for (File file : dir.listFiles()) {
      if (file.isDirectory()) {
        // Recurse down into directories.
        findResourcesInDirectory(clsLdr, file, rsrcs);
      } else {
        Class<? extends GridTask<?, ?>> rsrc = null;

        try {
          rsrc = clsLdr.createResource(file.getAbsolutePath(), true);
        } catch (GridSpiException e) {
          // Must never happen because we use 'ignoreUnknownRsrc=true'.
          assert false;
        }

        if (rsrc != null) {
          rsrcs.add(rsrc);
        }
      }
    }
  }
Example #3
0
 /**
  * Deletes the directory passed as parameters
  *
  * @param dir the directory to delete
  */
 public static void deleteDir(File dir) {
   File[] list = dir.listFiles();
   for (int i = 0; i < list.length; i++) {
     if (list[i].isDirectory()) deleteDir(list[i]);
     else list[i].delete();
   }
   dir.delete();
 }
Example #4
0
  /**
   * scans for possible help directories (languages)
   *
   * @return a list of possible language directories
   */
  public List<String> getLanguages() {
    List<String> paths = new ArrayList<>();
    URL home = getClass().getResource("..");
    File local;
    if (home != null) {
      System.out.println("looks like you are not starting from a jar-package");
      try {
        local = new File(new File(home.getPath()).getParentFile().getParentFile(), helproot);
        System.out.println("local: " + local.getAbsolutePath());
        for (File s : local.listFiles()) {
          if (s.isDirectory() && (s.listFiles().length > 0)) {
            addToList(paths, s.getName());
          }
        }
      } catch (Exception e) {
        System.out.println("but not loading from the developer workbench?!");
      }

    } else {
      System.out.println("looks like you are starting from a jar-package");
      local = CommandLoader.getLocation();
      File helpDir = new File(local, helproot);
      if (helpDir.exists() && helpDir.isDirectory() && (helpDir.listFiles().length > 0)) {
        for (File s : helpDir.listFiles()) {
          if (s.isDirectory()) {
            addToList(paths, s.getName());
          }
        }
      }

      File jar = new File(CommandLoader.classPath());
      for (File file : local.listFiles()) {
        try {
          if (!jar.getCanonicalPath().equals(file.getCanonicalPath())) {
            searchJarPath(file, paths);
          }
        } catch (IOException ignored) {
        }
        searchJarPath(jar, paths);
      }
    }
    return paths;
  }
Example #5
0
 public static void removePreviousLibs(File libDir) {
   if (libDir.exists() && libDir.listFiles(new PrefixFilter("runwar")).length > 0) {
     for (File previous : libDir.listFiles(new PrefixFilter("runwar"))) {
       try {
         previous.delete();
       } catch (Exception e) {
         System.err.println("Could not delete previous lib: " + previous.getAbsolutePath());
       }
     }
   }
 }
  /**
   * Garbage collect repository
   *
   * @throws Exception
   */
  public void gc() throws Exception {
    HashSet<byte[]> deps = new HashSet<byte[]>();

    // deps.add(SERVICE_JAR_FILE);

    for (File cmd : commandDir.listFiles()) {
      CommandData data = getData(CommandData.class, cmd);
      addDependencies(deps, data);
    }

    for (File service : serviceDir.listFiles()) {
      File dataFile = new File(service, "data");
      ServiceData data = getData(ServiceData.class, dataFile);
      addDependencies(deps, data);
    }

    int count = 0;
    for (File f : repoDir.listFiles()) {
      String name = f.getName();
      if (!deps.contains(name)) {
        if (!name.endsWith(".json")
            || !deps.contains(name.substring(0, name.length() - ".json".length()))) { // Remove
          // json
          // files
          // only
          // if
          // the
          // bin
          // is
          // going
          // as
          // well
          f.delete();
          count++;
        } else {

        }
      }
    }
    System.out.format("Garbage collection done (%d file(s) removed)%n", count);
  }
  public List<CommandData> getCommands(File commandDir) throws Exception {
    List<CommandData> result = new ArrayList<CommandData>();

    if (!commandDir.exists()) {
      return result;
    }

    for (File f : commandDir.listFiles()) {
      CommandData data = getData(CommandData.class, f);
      if (data != null) result.add(data);
    }
    return result;
  }
  public List<ServiceData> getServices(File serviceDir) throws Exception {
    List<ServiceData> result = new ArrayList<ServiceData>();

    if (!serviceDir.exists()) {
      return result;
    }

    for (File sdir : serviceDir.listFiles()) {
      File dataFile = new File(sdir, "data");
      ServiceData data = getData(ServiceData.class, dataFile);
      result.add(data);
    }
    return result;
  }
 private static void scanDir(File dir, String prefix, Set<String> names) throws Exception {
   File[] files = dir.listFiles();
   if (files == null) return;
   for (int i = 0; i < files.length; i++) {
     File f = files[i];
     String name = f.getName();
     String p = (prefix.equals("")) ? name : prefix + "." + name;
     if (f.isDirectory()) scanDir(f, p, names);
     else if (name.endsWith(".class")) {
       p = p.substring(0, p.length() - 6);
       names.add(p);
     }
   }
 }
Example #10
0
  /**
   * Enumerates the resouces in a give package name. This works even if the resources are loaded
   * from a jar file!
   *
   * <p>Adapted from code by mikewse on the java.sun.com message boards.
   * http://forum.java.sun.com/thread.jsp?forum=22&thread=30984
   *
   * @param packageName The package to enumerate
   * @return A Set of Strings for each resouce in the package.
   */
  public static Set getResoucesInPackage(String packageName) throws IOException {
    String localPackageName;
    if (packageName.endsWith("/")) {
      localPackageName = packageName;
    } else {
      localPackageName = packageName + '/';
    }

    Enumeration dirEnum = ClassLoader.getSystemResources(localPackageName);

    Set names = new HashSet();

    // Loop CLASSPATH directories
    while (dirEnum.hasMoreElements()) {
      URL resUrl = (URL) dirEnum.nextElement();

      // Pointing to filesystem directory
      if (resUrl.getProtocol().equals("file")) {
        File dir = new File(resUrl.getFile());
        File[] files = dir.listFiles();
        if (files != null) {
          for (int i = 0; i < files.length; i++) {
            File file = files[i];
            if (file.isDirectory()) continue;
            names.add(localPackageName + file.getName());
          }
        }

        // Pointing to Jar file
      } else if (resUrl.getProtocol().equals("jar")) {
        JarURLConnection jconn = (JarURLConnection) resUrl.openConnection();
        JarFile jfile = jconn.getJarFile();
        Enumeration entryEnum = jfile.entries();
        while (entryEnum.hasMoreElements()) {
          JarEntry entry = (JarEntry) entryEnum.nextElement();
          String entryName = entry.getName();
          // Exclude our own directory
          if (entryName.equals(localPackageName)) continue;
          String parentDirName = entryName.substring(0, entryName.lastIndexOf('/') + 1);
          if (!parentDirName.equals(localPackageName)) continue;
          names.add(entryName);
        }
      } else {
        // Invalid classpath entry
      }
    }

    return names;
  }
Example #11
0
 public static boolean deleteAll(File file) {
   boolean b = true;
   if ((file != null) && file.exists()) {
     if (file.isDirectory()) {
       try {
         File[] files = file.listFiles();
         for (File f : files) b &= deleteAll(f);
       } catch (Exception e) {
         return false;
       }
     }
     b &= file.delete();
   }
   return b;
 }
Example #12
0
 /**
  * load a specified directory filled with help files (outside a jar)
  *
  * @param local the directory
  */
 private void initFile(File local) {
   if (!local.exists()) {
     return;
   }
   int counter = 0;
   if (local.isDirectory()) {
     for (File file : local.listFiles()) {
       if (file.getName().toLowerCase().endsWith(".htm") && file.isFile()) {
         String mnemo = file.getName().toLowerCase().replace(".htm", "");
         if (!exists(mnemo)) {
           addToCache(file, mnemo);
           counter++;
         }
       }
     }
   }
   try {
     System.out.println(
         "+ " + String.valueOf(counter) + "\thelp text(s) from:\t" + local.getCanonicalPath());
   } catch (IOException ignored) {
   }
 }
Example #13
0
  private void cleanup(File directory) {
    // Clean up from old installations, removing or renaming files.
    // Note that directory is the parent of the CTP directory
    // unless the original installation was done by Bill Weadock's
    // all-in-one installer for Windows.

    // Get a file pointing to the CTP directory.
    // This might be the current directory, or
    // it might be the CTP child.
    File dir;
    if (directory.getName().equals("RSNA")) dir = directory;
    else dir = new File(directory, "CTP");

    // If CTP.jar exists in this directory, it is a really
    // old CTP main file - not used anymore
    File ctp = new File(dir, "CTP.jar");
    if (ctp.exists()) ctp.delete();

    // These are old names for the Launcher.jar file
    File launcher = new File(dir, "CTP-launcher.jar");
    if (launcher.exists()) launcher.delete();
    launcher = new File(dir, "TFS-launcher.jar");
    if (launcher.exists()) launcher.delete();

    // Delete the obsolete CTP-runner.jar file
    File runner = new File(dir, "CTP-runner.jar");
    if (runner.exists()) runner.delete();

    // Delete the obsolete MIRC-copier.jar file
    File copier = new File(dir, "MIRC-copier.jar");
    if (copier.exists()) copier.delete();

    // Rename the old versions of the properties files
    File oldprops = new File(dir, "CTP-startup.properties");
    File newprops = new File(dir, "CTP-launcher.properties");
    File correctprops = new File(dir, "Launcher.properties");
    if (oldprops.exists()) {
      if (newprops.exists() || correctprops.exists()) oldprops.delete();
      else oldprops.renameTo(correctprops);
    }
    if (newprops.exists()) {
      if (correctprops.exists()) newprops.delete();
      else newprops.renameTo(correctprops);
    }

    // Get rid of obsolete startup and shutdown programs
    File startup = new File(dir, "CTP-startup.jar");
    if (startup.exists()) startup.delete();
    File shutdown = new File(dir, "CTP-shutdown.jar");
    if (shutdown.exists()) shutdown.delete();

    // Get rid of the obsolete linux directory
    File linux = new File(dir, "linux");
    if (linux.exists()) {
      startup = new File(linux, "CTP-startup.jar");
      if (startup.exists()) startup.delete();
      shutdown = new File(linux, "CTP-shutdown.jar");
      if (shutdown.exists()) shutdown.delete();
      linux.delete();
    }

    // clean up the libraries directory
    File libraries = new File(dir, "libraries");
    if (libraries.exists()) {
      // remove obsolete versions of the slf4j libraries
      // and the dcm4che-imageio libraries
      File[] files = libraries.listFiles();
      for (File file : files) {
        if (file.isFile()) {
          String name = file.getName();
          if (name.startsWith("slf4j-") || name.startsWith("dcm4che-imageio-rle")) {
            file.delete();
          }
        }
      }
      // remove the email subdirectory
      File email = new File(libraries, "email");
      deleteAll(email);
      // remove the xml subdirectory
      File xml = new File(libraries, "xml");
      deleteAll(xml);
      // remove the sftp subdirectory
      File sftp = new File(libraries, "sftp");
      deleteAll(xml);
      // move edtftpj.jar to the ftp directory
      File edtftpj = new File(libraries, "edtftpj.jar");
      if (edtftpj.exists()) {
        File ftp = new File(libraries, "ftp");
        ftp.mkdirs();
        File ftpedtftpj = new File(ftp, "edtftpj.jar");
        edtftpj.renameTo(ftpedtftpj);
      }
    }

    // remove the obsolete xml library under dir
    File xml = new File(dir, "xml");
    deleteAll(xml);

    // remove the dicom profiles so any
    // obsolete files will disappear
    File profiles = new File(dir, "profiles");
    File dicom = new File(profiles, "dicom");
    deleteAll(dicom);
    dicom.mkdirs();

    // Remove the index.html file so it will be rebuilt from
    // example-index.html when the system next starts.
    File root = new File(dir, "ROOT");
    if (root.exists()) {
      File index = new File(root, "index.html");
      index.delete();
    }
  }
Example #14
0
 private File getFile(File dir, String nameStart, String nameEnd) {
   File[] files = dir.listFiles(new NameFilter(nameStart, nameEnd));
   if (files.length == 0) return null;
   return files[0];
 }
Example #15
0
  /**
   * Creates the java help
   *
   * @param path the path where to create the java help
   * @param lang the spoken language
   */
  private void createJavaHelp(File path, String lang) {
    File pages = new File(path, "pages");
    if (pages.exists()) deleteDir(pages);
    pages.mkdir();

    File javahelpsearch = new File(path, SEARCH_DIR);
    if (javahelpsearch.exists()) deleteDir(javahelpsearch);

    File helpset_file = new File(path, HELPSET_NAME_BASE + lang + HELPSET_NAME_SUFFIX);
    File config_file = null;
    File map_file = null;
    File tam_file = null;

    String underscore = "";

    if (helpset_file.exists()) {
      // There is a helpset corresponding to the current language
      map_file = new File(path, MAP_NAME_BASE + lang + MAP_NAME_SUFFIX);
      tam_file = new File(path, TAM_NAME_BASE + lang + TAM_NAME_SUFFIX);
      underscore = "_" + lang;
    } else {
      // There is no helpset : we use the default one
      map_file = new File(path + "Map.jhm");
      tam_file = new File(path + "TAM.xml");
    }

    config_file = new File(path, CONFIG_FILE);

    if (config_file.exists()) config_file.delete();
    if (map_file.exists()) map_file.delete();
    if (tam_file.exists()) tam_file.delete();

    boolean test = true;

    try {
      // Generates the jhm and copy the file for objects
      // Generates the TAM.xml file
      test = test && map_file.createNewFile();
      test = test && tam_file.createNewFile();
      File lang_dir = new File(path, "Main_pages/" + lang);
      test = test && lang_dir.exists();
      if (test) {
        print = new PrintWriter(new BufferedWriter(new FileWriter(map_file)));
        // debut  + images
        print.println(
            "<?xml version='1.0' encoding='ISO-8859-1' ?>\n "
                + "<!DOCTYPE map\n"
                + "PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN\"\n"
                + "\"http://java.sun.com/products/javahelp/map_1_0.dtd\">\n"
                + "\n"
                + "<map version=\"1.0\">\n"
                + "<mapID target=\"image\" url=\"Main_pages/logo_cbs_petit.gif\" />\n"
                + "<mapID target=\"tamicon\" url=\"Main_pages/tam.gif\" />\n"
                + "<mapID target=\"fileicon\" url=\"Main_pages/file.gif\" />\n"
                + "<mapID target=\""
                + FIRST_PAGE
                + "\" url=\"pages/"
                + FIRST_PAGE
                + ".html\" />");

        print2 = new PrintWriter(new BufferedWriter(new FileWriter(tam_file)));
        print2.println(
            " <?xml version='1.0' encoding='ISO-8859-1'  ?> \n "
                + "<!DOCTYPE toc \n"
                + "PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp TOC Version 2.0//EN\"\n"
                + "\"../dtd/toc_2_0.dtd\">\n"
                + "<toc version=\"2.0\"> \n<tocitem text=\""
                + getTitle(new File(path, "Main_pages/" + lang + "/" + FIRST_PAGE + ".html"))
                + "\" target=\""
                + FIRST_PAGE
                + "\" image=\"image\">");
        copyFile(
            new File(path, "Main_pages/" + lang + "/" + FIRST_PAGE + ".html"),
            new File(path, "pages/" + FIRST_PAGE + ".html"));

        // generation of the tree
        File[] list_lang_dir = lang_dir.listFiles();
        for (int a = 0; a < list_lang_dir.length; a++) {
          if (!list_lang_dir[a].getName().equals("CVS")
              && list_lang_dir[a].isFile()
              && !list_lang_dir[a].getName().equals(FIRST_PAGE + ".html")) {
            mapAndTocForFile(list_lang_dir[a], path, underscore);
          }
        }

        // Ends
        print.println("</map>");
        print.close();

        print2.println("</tocitem>\n</toc>");
        print2.close();

        test = test && config_file.createNewFile();
        if (test) {
          // Generates the config file
          print = new PrintWriter(new BufferedWriter(new FileWriter(config_file)));
          print.print("IndexRemove " + path.getAbsolutePath());
          print.close();
        }
      }
    } catch (Exception e) {
      LOG.error("Error getHelp " + e);
    }
    // Generates the search database
    String[] args =
        new String[] {
          pages.getAbsolutePath(),
          "-c",
          config_file.getAbsolutePath(),
          "-db",
          javahelpsearch.getAbsolutePath(),
          "-locale",
          lang
        };
    // Indexer indexer=new Indexer();
    // FIXME help desactived
    //		Indexer.main(args);

    Calendar c = GregorianCalendar.getInstance();
    c.setTime(new Date());
    int day = c.get(Calendar.DAY_OF_MONTH);
    int month = c.get(Calendar.MONTH) + 1;
    int year = c.get(Calendar.YEAR);
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    int seconds = c.get(Calendar.SECOND);

    File log = new File(path, LOG_FILE);
    try {
      log.createNewFile();
      PrintWriter printlog = new PrintWriter(new BufferedWriter(new FileWriter(log)));
      printlog.println("Language " + lang);
      printlog.println(
          "Date : " + year + " " + month + " " + day + " " + hour + " " + minute + " " + seconds);
      printlog.close();
    } catch (Exception e) {
      LOG.error("Error while creating log " + e);
    }
  }
Example #16
0
  private void mapAndTocForFile(File f, File path, String underscore) {
    // we get the single name of the file and the urlname
    int under_index2 = f.getName().indexOf("_");
    int point_index2 = f.getName().indexOf(".");
    String named = f.getName().substring(under_index2 + 1, point_index2);
    String tmp = path.getAbsolutePath() + "Main_pages/fr/";
    String url_name = f.getPath().replace("\\", "/").substring(tmp.length());
    String targetName = url_name.substring(0, url_name.lastIndexOf(".html"));

    // now we will add into the map and the toc
    print.println("<mapID target=\"" + targetName + "\" url=\"pages/" + url_name + "\"/>");
    File dir_associated = new File(f.getParent(), named);

    if ((dir_associated.exists() && dir_associated.isDirectory()) || named.equals("objects")) {
      print2.println(
          "<tocitem text=\"" + getTitle(f) + "\" target=\"" + targetName + "\" image=\"tamicon\">");
      if (dir_associated.exists()) {
        // Apres on fait pareil pour tous les sous fichiers
        File[] sub_files = dir_associated.listFiles();
        for (int i = 0; i < sub_files.length; i++) {
          if (!sub_files[i].getName().equals("CVS") && sub_files[i].isFile()) {
            if (sub_files[i].getName().endsWith(".html"))
              mapAndTocForFile(sub_files[i], path, underscore);
            else {
              try {
                copyFile(
                    sub_files[i], new File(path, "pages/" + named + "/" + sub_files[i].getName()));
              } catch (IOException e) {
                LOG.error("Error while copying normal files in help " + e);
              }
            }
          }
        }
      }
      if (named.equals("objects")) {
        // Specialement pour les objets on les rajoute tous
        File objects_dir =
            new File(
                Configuration.instance()
                        .getTangaraPath()
                        .getParentFile()
                        .getAbsolutePath()
                        .replace("\\", "/")
                    + "/objects/");
        File[] listfiles = objects_dir.listFiles();
        Vector<String> list_names = new Vector<String>();
        HashMap<String, String> map = new HashMap<String, String>();
        for (int i = 0; i < listfiles.length; i++) {
          try {
            if (listfiles[i].getName().endsWith(".jar")) {
              int point_index = listfiles[i].getName().lastIndexOf(".");
              String name = listfiles[i].getName().substring(0, point_index);

              // Copy the pages in the right directory
              File object_dir = new File(path, "pages/" + name);
              object_dir.mkdir();
              File object_ressource =
                  new File(
                      Configuration.instance()
                              .getTangaraPath()
                              .getParentFile()
                              .getAbsolutePath()
                              .replace("\\", "/")
                          + "/objects/resources/"
                          + name
                          + "/Help");
              if (object_ressource.exists()) {
                File[] list_html_object = object_ressource.listFiles();
                for (int e = 0; e < list_html_object.length; e++) {
                  if (list_html_object[e].getName().endsWith(".html")) {
                    int under_index = list_html_object[e].getName().lastIndexOf("_");
                    if (underscore.equals("") && under_index == -1)
                      copyFile(
                          list_html_object[e],
                          new File(path, "pages/" + name + "/" + list_html_object[e].getName()));
                    else if (!underscore.equals("")) {
                      if (list_html_object[e].getName().contains(underscore))
                        copyFile(
                            list_html_object[e],
                            new File(path, "pages/" + name + "/" + list_html_object[e].getName()));
                    }
                  } else
                    copyFile(
                        list_html_object[e],
                        new File(path, "pages/" + name + "/" + list_html_object[e].getName()));
                }
                // Gets the name of the object in the selected language
                String name_lang = null;
                if (underscore.equals("")) name_lang = name;
                else {
                  name_lang = getLangName(listfiles[i]);
                }
                if (name_lang != null) {
                  list_names.add(name_lang);
                  map.put(name_lang, name);
                  // Add to the map file
                  print.println(
                      "<mapID target=\""
                          + name
                          + "\" url=\"pages/"
                          + name
                          + "/index"
                          + underscore
                          + ".html\" />");
                }
              }
            }
          } catch (Exception e2) {
            LOG.error("Error2 getHelp " + e2);
          }
        }
        // Add to the tam file
        Collections.sort(list_names);
        for (String s : list_names) {
          print2.println(
              "<tocitem text=\"" + s + "\" target=\"" + map.get(s) + "\" image=\"fileicon\" />");
        }
      }
      print2.println("</tocitem>");
    } else {
      // pas de sous fichiers
      print2.println(
          "<tocitem text=\""
              + getTitle(f)
              + "\" target=\""
              + targetName
              + "\" image=\"fileicon\"/>");
    }

    File parent = new File(path, "pages/" + url_name.substring(0, url_name.lastIndexOf(named) - 3));
    if (!parent.exists()) parent.mkdirs();
    File in_pages = new File(path, "pages/" + url_name);
    try {
      in_pages.createNewFile();
      copyFile(f, in_pages);
    } catch (IOException e3) {
      LOG.error("Error 3 getHelp " + e3 + " " + f.getName());
    }
  }
Example #17
0
 // where
 void findFiles(File dir, Set<File> files) {
   for (File f : dir.listFiles()) {
     if (f.isDirectory()) findFiles(f, files);
     else files.add(f);
   }
 }