Ejemplo n.º 1
0
 public static void deleteRecursive(File file) {
   if (!file.exists()) {
     return;
   }
   if (file.isFile()) {
     file.delete();
   } else if (file.isDirectory()) {
     File[] files = file.listFiles();
     for (int i = 0; i < files.length; i++) {
       deleteRecursive(files[i]);
     }
     file.delete();
   }
 }
Ejemplo n.º 2
0
 public static void doCompilation(
     CompilerConfiguration configuration,
     CompilationUnit unit,
     String[] filenames,
     boolean lookupUnnamedFiles)
     throws Exception {
   File tmpDir = null;
   // if there are any joint compilation options set stubDir if not set
   try {
     if ((configuration.getJointCompilationOptions() != null)
         && !configuration.getJointCompilationOptions().containsKey("stubDir")) {
       tmpDir =
           DefaultGroovyStaticMethods.createTempDir(null, "groovy-generated-", "-java-source");
       configuration.getJointCompilationOptions().put("stubDir", tmpDir);
     }
     FileSystemCompiler compiler = new FileSystemCompiler(configuration, unit);
     if (lookupUnnamedFiles) {
       for (String filename : filenames) {
         File file = new File(filename);
         if (file.isFile()) {
           URL url = file.getAbsoluteFile().getParentFile().toURI().toURL();
           compiler.unit.getClassLoader().addURL(url);
         }
       }
     } else {
       compiler
           .unit
           .getClassLoader()
           .setResourceLoader(
               new GroovyResourceLoader() {
                 public URL loadGroovySource(String filename) throws MalformedURLException {
                   return null;
                 }
               });
     }
     compiler.compile(filenames);
   } finally {
     try {
       if (tmpDir != null) deleteRecursive(tmpDir);
     } catch (Throwable t) {
       System.err.println("error: could not delete temp files - " + tmpDir.getPath());
     }
   }
 }
Ejemplo n.º 3
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();
    }
  }