Esempio n. 1
1
 private static ClassLoader toolsClassLoader() {
   File javaHome = new File(System.getProperty("java.home"));
   File classesDir = new File(javaHome, "classes");
   File libDir = new File(javaHome.getParentFile(), "lib");
   File toolsJar = new File(libDir, "tools.jar");
   try {
     return new URLClassLoader(new URL[] {classesDir.toURL(), toolsJar.toURL()});
   } catch (MalformedURLException e) {
     throw new AssertionError(e);
   }
 }
 private static void loadPlatformZipPropertiesFromFile() {
   File installLocation = getInstallLocation();
   if (installLocation != null) {
     // parent will be "eclipse" and the parent's parent will be "eclipse-testing"
     File parent = installLocation.getParentFile();
     if (parent != null) {
       parent = parent.getParentFile();
       if (parent != null) {
         File propertiesFile = new File(parent, "equinoxp2tests.properties");
         if (!propertiesFile.exists()) return;
         archiveAndRepositoryProperties = new Properties();
         try {
           InputStream is = null;
           try {
             is = new BufferedInputStream(new FileInputStream(propertiesFile));
             archiveAndRepositoryProperties.load(is);
           } finally {
             is.close();
           }
         } catch (IOException e) {
           return;
         }
       }
     }
   }
 }
Esempio n. 3
0
 public static File directoryOf(Class clazz) {
   File location = locationOf(clazz);
   if (location.isDirectory()) {
     return location;
   }
   return location.getParentFile();
 }
Esempio n. 4
0
  private void loadObjects() throws ConfigurationException {
    if (!isExecutionMode()) {
      // Import objects from file system
      File objectsDirectory = new File(tangaraPath.getParentFile(), "objects");
      System.out.println("using path " + objectsDirectory.getAbsolutePath());

      // 1st Load libraries
      File libDirectory = new File(objectsDirectory, "lib");
      File libraries[] = libDirectory.listFiles();
      for (int i = 0; i < libraries.length; i++) {
        if (libraries[i].getName().endsWith(".jar")) {
          System.out.println("Loading library " + libraries[i].getName());
          addClassPathToScriptEngine(libraries[i]);
        }
      }

      // 2nd load objects
      File objects[] = objectsDirectory.listFiles();
      for (int i = 0; i < objects.length; i++) {
        if (objects[i].getName().endsWith(".jar")) {
          System.out.println("Loading object " + objects[i].getName());
          addClassPathToScriptEngine(objects[i]);
        }
      }
    }
    // import the localized objects package
    importLocalizedObjectsPackage();
  }
Esempio n. 5
0
  public void resolve(Unmarshaller u) throws JAXBException {
    Object obj = null;

    try {
      obj = u.unmarshal(new URL(getSchemaLocation()));
    } catch (MalformedURLException e) {
    }

    File file = new File(getSchemaLocation());

    if (!file.exists()) {
      if (!file.getName().startsWith("/")) {
        file = new File(_location.getSystemId());

        file = file.getParentFile();

        if (file == null) throw new JAXBException("File not found: " + getSchemaLocation());

        file = new File(file, getSchemaLocation());
      }
    }

    obj = u.unmarshal(file);

    if (obj instanceof Schema) _schema = (Schema) obj;
  }
Esempio n. 6
0
  public static File[] getSystemLibs() {
    File javaHome = new File(System.getProperty("java.home"));
    File libDir = new File(javaHome, "lib");
    File extDir = new File(libDir, "ext");
    File osxDir = new File(javaHome.getParentFile(), "Classes");

    File[][] libsArray =
        new File[][] {
          getLibraryFiles(libDir), getLibraryFiles(osxDir), getLibraryFiles(extDir),
        };

    int nLibs = 0;
    for (int i = 0; i < libsArray.length; i++) {
      if (libsArray[i] != null) {
        nLibs += libsArray[i].length;
      }
    }

    File[] libs = new File[nLibs];
    int destPos = 0;
    for (int i = 0; i < libsArray.length; i++) {
      if (libsArray[i] != null) {
        System.arraycopy(libsArray[i], 0, libs, destPos, libsArray[i].length);
        destPos += libsArray[i].length;
      }
    }
    return libs;
  }
Esempio n. 7
0
 public void init() throws IOException {
   URL s = getClass().getClassLoader().getResource(SERVICE_JAR_FILE);
   if (s == null)
     if (underTest) return;
     else throw new Error("No " + SERVICE_JAR_FILE + " resource in jar");
   service.getParentFile().mkdirs();
   IO.copy(s, service);
 }
Esempio n. 8
0
File: Macro.java Progetto: bramk/bnd
 public String _dir(String args[]) {
   if (args.length < 2) {
     domain.warning("Need at least one file name for ${dir;...}");
     return null;
   }
   String del = "";
   StringBuilder sb = new StringBuilder();
   for (int i = 1; i < args.length; i++) {
     File f = domain.getFile(args[i]);
     if (f.exists() && f.getParentFile().exists()) {
       sb.append(del);
       sb.append(f.getParentFile().getAbsolutePath());
       del = ",";
     }
   }
   return sb.toString();
 }
Esempio n. 9
0
  public void download(URI address, File destination) throws Exception {
    if (destination.exists()) {
      return;
    }
    destination.getParentFile().mkdirs();

    downloadInternal(address, destination);
  }
Esempio n. 10
0
 private File fileReallyExists(URL ret, String fileWithoutPackage) {
   File path;
   try {
     /* fix for GROOVY-5809 */
     path = new File(ret.toURI());
   } catch (URISyntaxException e) {
     path = new File(decodeFileName(ret.getFile()));
   }
   path = path.getParentFile();
   if (path.exists() && path.isDirectory()) {
     File file = new File(path, fileWithoutPackage);
     if (file.exists()) {
       // file.exists() might be case insensitive. Let's do
       // case sensitive match for the filename
       File parent = file.getParentFile();
       for (String child : parent.list()) {
         if (child.equals(fileWithoutPackage)) return file;
       }
     }
   }
   // file does not exist!
   return null;
 }
Esempio n. 11
0
 /**
  * Converts a dir string to a linked dir string
  *
  * @param dir the directory string (e.g. /usr/local/httpd)
  * @param browserLink web-path to Browser.jsp
  */
 public static String dir2linkdir(String dir, String browserLink, int sortMode) {
   File f = new File(dir);
   StringBuffer buf = new StringBuffer();
   while (f.getParentFile() != null) {
     if (f.canRead()) {
       String encPath = URLEncoder.encode(f.getAbsolutePath());
       buf.insert(
           0,
           "<a href=\""
               + browserLink
               + "?sort="
               + sortMode
               + "&amp;dir="
               + encPath
               + "\">"
               + conv2Html(f.getName())
               + File.separator
               + "</a>");
     } else buf.insert(0, conv2Html(f.getName()) + File.separator);
     f = f.getParentFile();
   }
   if (f.canRead()) {
     String encPath = URLEncoder.encode(f.getAbsolutePath());
     buf.insert(
         0,
         "<a href=\""
             + browserLink
             + "?sort="
             + sortMode
             + "&amp;dir="
             + encPath
             + "\">"
             + conv2Html(f.getAbsolutePath())
             + "</a>");
   } else buf.insert(0, f.getAbsolutePath());
   return buf.toString();
 }
Esempio n. 12
0
  private void updateLinuxServiceInstaller() {
    try {
      File dir = new File(directory, "CTP");
      if (suppressFirstPathElement) dir = dir.getParentFile();
      Properties props = new Properties();
      String ctpHome = dir.getAbsolutePath();
      cp.appendln(Color.black, "...CTP_HOME: " + ctpHome);
      ctpHome = ctpHome.replaceAll("\\\\", "\\\\\\\\");
      props.put("CTP_HOME", ctpHome);
      File javaHome = new File(System.getProperty("java.home"));
      String javaBin = (new File(javaHome, "bin")).getAbsolutePath();
      cp.appendln(Color.black, "...JAVA_BIN: " + javaBin);
      javaBin = javaBin.replaceAll("\\\\", "\\\\\\\\");
      props.put("JAVA_BIN", javaBin);

      File linux = new File(dir, "linux");
      File install = new File(linux, "ctpService-ubuntu.sh");
      cp.appendln(Color.black, "Linux service installer:");
      cp.appendln(Color.black, "...file: " + install.getAbsolutePath());
      String bat = getFileText(install);
      bat = replace(bat, props); // do the substitutions
      bat = bat.replace("\r", "");
      setFileText(install, bat);

      // If this is an ISN installation, put the script in the correct place.
      String osName = System.getProperty("os.name").toLowerCase();
      if (programName.equals("ISN") && !osName.contains("windows")) {
        install = new File(linux, "ctpService-red.sh");
        cp.appendln(Color.black, "ISN service installer:");
        cp.appendln(Color.black, "...file: " + install.getAbsolutePath());
        bat = getFileText(install);
        bat = replace(bat, props); // do the substitutions
        bat = bat.replace("\r", "");
        File initDir = new File("/etc/init.d");
        File initFile = new File(initDir, "ctpService");
        if (initDir.exists()) {
          setOwnership(initDir, "edge", "edge");
          setFileText(initFile, bat);
          initFile.setReadable(true, false); // everybody can read //Java 1.6
          initFile.setWritable(true); // only the owner can write //Java 1.6
          initFile.setExecutable(true, false); // everybody can execute //Java 1.6
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      System.err.println("Unable to update the Linux service ctpService.sh file");
    }
  }
 protected static int run(String message, String[] commandArray, File outputFile) {
   PrintStream out = System.out;
   PrintStream err = System.err;
   PrintStream fileStream = null;
   try {
     outputFile.getParentFile().mkdirs();
     fileStream = new PrintStream(new FileOutputStream(outputFile));
     System.setErr(fileStream);
     System.setOut(fileStream);
     return run(message, commandArray);
   } catch (FileNotFoundException e) {
     return -1;
   } finally {
     System.setOut(out);
     System.setErr(err);
     if (fileStream != null) fileStream.close();
   }
 }
Esempio n. 14
0
 public static byte[] recvFile(Socket sock, File out)
     throws IOException, NoSuchAlgorithmException {
   FileOutputStream mainOut = new FileOutputStream(out);
   byte[] ret = null;
   boolean reading = true;
   MessageDigest major = MessageDigest.getInstance(SecureUtils.STD_HASH);
   int block = 0;
   while (reading) { // while there is data to be read
     long readln = readInteger(sock.getInputStream()); // read the length of the next block
     if (readln == TRANS_FINISH) { // if there are no more block
       mainOut.close();
       ret = major.digest();
       sock.getOutputStream().write(ret); // send my major hash
       long finishReply = readInteger(sock.getInputStream()); // read the reply
       if (finishReply == TRANS_FINISH) { // if the major hash was correct
         reading = false; // complete the transaction
       } else { // else the major has was incorrect
         out.delete(); // delete the file
         mainOut = new FileOutputStream(out); // reset the output streams
         // start again
         block = 0;
         major = MessageDigest.getInstance(SecureUtils.STD_HASH);
         ret = null;
       }
     } else { // else there are more blocks
       File tempOut = new File(out.getParentFile(), out.getName() + ".part" + block);
       FileOutputStream partStream = new FileOutputStream(tempOut); // spawn a temporary file
       byte[] hash =
           hashpipe(sock.getInputStream(), partStream, readln); // read the block to temp file
       partStream.close();
       sock.getOutputStream().write(hash); // send my minor hash
       long minorReply = readInteger(sock.getInputStream()); // read the reply
       if (minorReply == TRANS_SUCCESS) { // if the transfer was correct
         FileInputStream partIn = new FileInputStream(tempOut);
         hashpipe(partIn, mainOut, readln, major); // send the temp file to the main file
         block++;
       } else { // if the transfer was wrong
         // do nothing
       }
       tempOut.delete(); // delete the temp file
     }
   }
   return ret;
 }
 /*
  * Create a link file in the links folder. Point it to the given extension location.
  */
 public void createLinkFile(String message, String filename, String extensionLocation) {
   File file = new File(output, getRootFolder() + "links/" + filename + ".link");
   file.getParentFile().mkdirs();
   Properties properties = new Properties();
   properties.put("path", extensionLocation);
   OutputStream stream = null;
   try {
     stream = new BufferedOutputStream(new FileOutputStream(file));
     properties.store(stream, null);
   } catch (IOException e) {
     fail(message, e);
   } finally {
     try {
       if (stream != null) stream.close();
     } catch (IOException e) {
       // ignore
     }
   }
 }
Esempio n. 16
0
  protected static URL createURL(Properties headers) throws IOException {
    try {
      File file = new File(headers.getProperty("PATH_TRANSLATED"));

      while (file != null && !file.exists()) {
        file = file.getParentFile();
      }

      if (file.isDirectory()) {
        throw new IOException(
            "Unable to find a file in path " + headers.getProperty("PATH_TRANSLATED"));
      }

      return new URL("file", "", file.getAbsolutePath());
    } catch (MalformedURLException ex) {
      ex.printStackTrace();
      return null;
    }
  }
Esempio n. 17
0
 // If this is a new installation, ask the user for a
 // port for the server; otherwise, return the negative
 // of the configured port. If the user selects an illegal
 // port, return zero.
 private int getPort() {
   // Note: directory points to the parent of the CTP directory.
   File ctp = new File(directory, "CTP");
   if (suppressFirstPathElement) ctp = ctp.getParentFile();
   File config = new File(ctp, "config.xml");
   if (!config.exists()) {
     // No config file - must be a new installation.
     // Figure out whether this is Windows or something else.
     String os = System.getProperty("os.name").toLowerCase();
     int defPort = ((os.contains("windows") && !programName.equals("ISN")) ? 80 : 1080);
     int userPort = 0;
     while (userPort == 0) {
       String port =
           JOptionPane.showInputDialog(
               null,
               "This is a new "
                   + programName
                   + " installation.\n\n"
                   + "Select a port number for the web server.\n\n",
               Integer.toString(defPort));
       try {
         userPort = Integer.parseInt(port.trim());
       } catch (Exception ex) {
         userPort = -1;
       }
       if ((userPort < 80) || (userPort > 32767)) userPort = 0;
     }
     return userPort;
   } else {
     try {
       Document doc = getDocument(config);
       Element root = doc.getDocumentElement();
       Element server = getFirstNamedChild(root, "Server");
       String port = server.getAttribute("port");
       return -Integer.parseInt(port);
     } catch (Exception ex) {
     }
   }
   return 0;
 }
Esempio n. 18
0
  private void updateWindowsServiceInstaller() {
    try {
      File dir = new File(directory, "CTP");
      if (suppressFirstPathElement) dir = dir.getParentFile();
      File windows = new File(dir, "windows");
      File install = new File(windows, "install.bat");
      cp.appendln(Color.black, "Windows service installer:");
      cp.appendln(Color.black, "...file: " + install.getAbsolutePath());
      String bat = getFileText(install);
      Properties props = new Properties();
      String home = dir.getAbsolutePath();
      cp.appendln(Color.black, "...home: " + home);
      home = home.replaceAll("\\\\", "\\\\\\\\");
      props.put("home", home);

      bat = replace(bat, props);
      setFileText(install, bat);
    } catch (Exception ex) {
      ex.printStackTrace();
      System.err.println("Unable to update the windows service install.barfile.");
    }
  }
Esempio n. 19
0
 private void installConfigFile(int port) {
   if (port > 0) {
     System.out.println("Looking for /config/config.xml");
     InputStream is = getClass().getResourceAsStream("/config/config.xml");
     if (is != null) {
       try {
         File ctp = new File(directory, "CTP");
         if (suppressFirstPathElement) ctp = ctp.getParentFile();
         File config = new File(ctp, "config.xml");
         Document doc = getDocument(is);
         Element root = doc.getDocumentElement();
         Element server = getFirstNamedChild(root, "Server");
         System.out.println("...setting the port to " + port);
         server.setAttribute("port", Integer.toString(port));
         adjustConfiguration(root, ctp);
         setFileText(config, toString(doc));
       } catch (Exception ex) {
         System.err.println("...Error: unable to install the config.xml file");
       }
     } else System.err.println("...could not find it.");
   }
 }
Esempio n. 20
0
  public boolean doDownload(String plugin) {
    boolean downloaded = false;

    try {
      File dl = new File("plugins/VoxelUpdate/Downloads/" + plugin + ".jar");

      if (!dl.getParentFile().isDirectory()) {
        dl.getParentFile().mkdirs();
      }

      if (!dl.exists()) {
        dl.createNewFile();
      }

      if (get(plugin, "url") == null) {
        return false;
      }

      BufferedInputStream bi = new BufferedInputStream(new URL(get(plugin, "url")).openStream());
      FileOutputStream fo = new FileOutputStream(dl);
      BufferedOutputStream bo = new BufferedOutputStream(fo, 1024);

      byte[] b = new byte[1024];
      int i = 0;

      while ((i = bi.read(b, 0, 1024)) >= 0) {
        bo.write(b, 0, i);
      }

      bo.close();
      bi.close();

      if (VoxelUpdate.autoUpdate) {
        File dupe = new File("plugins/" + dl.getName());

        FileChannel ic = new FileInputStream(dl).getChannel();
        FileChannel oc = new FileOutputStream(dupe).getChannel();
        ic.transferTo(0, ic.size(), oc);
        ic.close();
        oc.close();

        VoxelUpdate.s
            .getPluginManager()
            .disablePlugin(VoxelUpdate.s.getPluginManager().getPlugin(plugin));

        try {
          VoxelUpdate.s
              .getPluginManager()
              .enablePlugin(VoxelUpdate.s.getPluginManager().loadPlugin(dl));
        } catch (Exception e) {
          VoxelUpdate.log.severe("[VoxelUpdate] Could not reload plugin \"" + plugin + "\"");
        }
      }

      downloaded = true;
    } catch (MalformedURLException e) {
      VoxelUpdate.log.severe(
          "[VoxelUpdate] Incorrectly formatted URL for download of \"" + plugin + "\"");
      return downloaded;
    } catch (FileNotFoundException e) {
      VoxelUpdate.log.severe("[VoxelUpdate] Could not save data to VoxelUpdate/Downloads");
      e.printStackTrace();
      return downloaded;
    } catch (IOException e) {
      VoxelUpdate.log.severe("[VoxelUpdate] Could not assign data to BIS");
      e.printStackTrace();
      return downloaded;
    }

    return downloaded;
  }
  /** The run method. */
  public void run() {
    instances.add(this);
    try {
      listener.startUnpack();
      String currentOs = System.getProperty("os.name").toLowerCase();
      //
      // Initialisations
      FileOutputStream out = null;
      ArrayList parsables = new ArrayList();
      ArrayList executables = new ArrayList();
      List packs = idata.selectedPacks;
      int npacks = packs.size();
      udata = UninstallData.getInstance();

      // Specific to the web installers
      if (idata.kind.equalsIgnoreCase("web") || idata.kind.equalsIgnoreCase("web-kunststoff")) {
        InputStream kin = getClass().getResourceAsStream("/res/WebInstallers.url");
        BufferedReader kreader = new BufferedReader(new InputStreamReader(kin));
        jarLocation = kreader.readLine();
      }

      // We unpack the selected packs
      for (int i = 0; i < npacks; i++) {
        // We get the pack stream
        int n = idata.allPacks.indexOf(packs.get(i));
        ObjectInputStream objIn = new ObjectInputStream(getPackAsStream(n));

        // We unpack the files
        int nfiles = objIn.readInt();
        listener.changeUnpack(0, nfiles, ((Pack) packs.get(i)).name);
        for (int j = 0; j < nfiles; j++) {
          // We read the header
          PackFile pf = (PackFile) objIn.readObject();
          if (null == pf.os || matchOS(currentOs, pf.os.toLowerCase())) {
            // We translate & build the path
            String path = translatePath(pf.targetPath);
            File pathFile = new File(path);
            String fname = pathFile.getName();
            int z = fname.length();
            File dest = pathFile.getParentFile();
            if (!dest.exists()) dest.mkdirs();

            // We add the path to the log,
            udata.addFile(path);

            listener.progressUnpack(j, path);

            // if this file exists and shouldnot override skip this file
            if (((pf.override == false) && (pathFile.exists()))) {
              objIn.skip(pf.length);
              continue;
            }

            // We copy the file
            out = new FileOutputStream(path);
            byte[] buffer = new byte[5120];
            long bytesCopied = 0;
            while (bytesCopied < pf.length) {
              int maxBytes =
                  (pf.length - bytesCopied < buffer.length
                      ? (int) (pf.length - bytesCopied)
                      : buffer.length);
              int bytesInBuffer = objIn.read(buffer, 0, maxBytes);
              if (bytesInBuffer == -1) throw new IOException("Unexpected end of stream");

              out.write(buffer, 0, bytesInBuffer);

              bytesCopied += bytesInBuffer;
            }
            // Cleanings
            out.close();

            // Empty dirs restoring
            String _n = pathFile.getName();
            if (_n.startsWith("izpack-keepme") && _n.endsWith(".tmp")) pathFile.delete();

          } else objIn.skip(pf.length);
        }

        // Load information about parsable files
        int numParsables = objIn.readInt();
        int k;
        for (k = 0; k < numParsables; k++) {
          ParsableFile pf = (ParsableFile) objIn.readObject();
          pf.path = translatePath(pf.path);
          parsables.add(pf);
        }

        // Load information about executable files
        int numExecutables = objIn.readInt();
        for (k = 0; k < numExecutables; k++) {
          ExecutableFile ef = (ExecutableFile) objIn.readObject();
          ef.path = translatePath(ef.path);
          if (null != ef.argList && !ef.argList.isEmpty()) {
            String arg = null;
            for (int j = 0; j < ef.argList.size(); j++) {
              arg = (String) ef.argList.get(j);
              arg = translatePath(arg);
              ef.argList.set(j, arg);
            }
          }
          executables.add(ef);
          if (ef.executionStage == ExecutableFile.UNINSTALL) {
            udata.addExecutable(ef);
          }
        }
        objIn.close();
      }

      // We use the scripts parser
      ScriptParser parser = new ScriptParser(parsables, vs);
      parser.parseFiles();

      // We use the file executor
      FileExecutor executor = new FileExecutor(executables);
      if (executor.executeFiles(ExecutableFile.POSTINSTALL) != 0)
        javax.swing.JOptionPane.showMessageDialog(
            null,
            "The installation was not completed.",
            "Installation warning",
            javax.swing.JOptionPane.WARNING_MESSAGE);

      // We put the uninstaller
      putUninstaller();

      // The end :-)
      listener.stopUnpack();
    } catch (Exception err) {
      listener.stopUnpack();
      listener.errorUnpack(err.toString());
    }
    instances.remove(instances.indexOf(this));
  }
Esempio n. 22
0
 public static File makeFile(String filePath) throws IOException {
   File file = new File(filePath);
   file.getParentFile().mkdirs();
   file.createNewFile();
   return file;
 }
Esempio n. 23
0
  /**
   * Class constructor; creates a new Installer object, displays a JFrame introducing the program,
   * allows the user to select an install directory, and copies files from the jar into the
   * directory.
   */
  public Installer(String args[]) {
    // Inputs are --install-dir INSTALL_DIR
    for (int k = 0; k < args.length; k = k + 2) {

      switch (args[k]) {
        case "--install-dir":
          directory = new File(args[k + 1]);
          System.out.println(directory);
          break;
        case "--port":
          port = Integer.parseInt(args[k + 1]);
          break;
      }
    }

    cp = new Stream();

    // Find the installer program so we can get to the files.
    installer = getInstallerProgramFile();
    String name = installer.getName();
    programName = (name.substring(0, name.indexOf("-"))).toUpperCase();

    // Get the installation information
    thisJava = System.getProperty("java.version");
    thisJavaBits = System.getProperty("sun.arch.data.model") + " bits";

    // Find the ImageIO Tools and get the version
    String javaHome = System.getProperty("java.home");
    File extDir = new File(javaHome);
    extDir = new File(extDir, "lib");
    extDir = new File(extDir, "ext");
    File clib = getFile(extDir, "clibwrapper_jiio", ".jar");
    File jai = getFile(extDir, "jai_imageio", ".jar");
    imageIOTools = (clib != null) && clib.exists() && (jai != null) && jai.exists();
    if (imageIOTools) {
      Hashtable<String, String> jaiManifest = getManifestAttributes(jai);
      imageIOVersion = jaiManifest.get("Implementation-Version");
    }

    // Get the CTP.jar parameters
    Hashtable<String, String> manifest = getJarManifestAttributes("/CTP/libraries/CTP.jar");
    programDate = manifest.get("Date");
    buildJava = manifest.get("Java-Version");

    // Get the util.jar parameters
    Hashtable<String, String> utilManifest = getJarManifestAttributes("/CTP/libraries/util.jar");
    utilJava = utilManifest.get("Java-Version");

    // Get the MIRC.jar parameters (if the plugin is present)
    Hashtable<String, String> mircManifest = getJarManifestAttributes("/CTP/libraries/MIRC.jar");
    if (mircManifest != null) {
      mircJava = mircManifest.get("Java-Version");
      mircDate = mircManifest.get("Date");
      mircVersion = mircManifest.get("Version");
    }

    // Set up the installation information for display
    if (imageIOVersion.equals("")) {
      imageIOVersion = "<b><font color=\"red\">not installed</font></b>";
    } else if (imageIOVersion.startsWith("1.0")) {
      imageIOVersion = "<b><font color=\"red\">" + imageIOVersion + "</font></b>";
    }
    if (thisJavaBits.startsWith("64")) {
      thisJavaBits = "<b><font color=\"red\">" + thisJavaBits + "</font></b>";
    }
    boolean javaOK = (thisJava.compareTo(buildJava) >= 0);
    javaOK &= (thisJava.compareTo(utilJava) >= 0);
    javaOK &= (thisJava.compareTo(mircJava) >= 0);
    if (!javaOK) {
      thisJava = "<b><font color=\"red\">" + thisJava + "</font></b>";
    }

    if (directory == null) exit();

    // Point to the parent of the directory in which to install the program.
    // so the copy process works correctly for directory trees.
    //
    // If the user has selected a directory named "CTP",
    // then assume that this is the directory in which
    // to install the program.
    //
    // If the directory is not CTP, see if it is called "RSNA" and contains
    // the Launcher program, in which case we can assume that it is an
    // installation that was done with Bill Weadock's all-in-one installer for Windows.
    //
    // If neither of those cases is true, then this is already the parent of the
    // directory in which to install the program
    if (directory.getName().equals("CTP")) {
      directory = directory.getParentFile();
    } else if (directory.getName().equals("RSNA")
        && (new File(directory, "Launcher.jar")).exists()) {
      suppressFirstPathElement = true;
    }

    // Cleanup old releases
    cleanup(directory);

    // Get a port for the server.
    if (port < 0) {
      if (checkServer(-port, false)) {
        System.err.println(
            "CTP appears to be running.\nPlease stop CTP and run the installer again.");
        System.exit(0);
      }
    }

    // Now install the files and report the results.
    int count =
        unpackZipFile(installer, "CTP", directory.getAbsolutePath(), suppressFirstPathElement);
    if (count > 0) {
      // Create the service installer batch files.
      updateWindowsServiceInstaller();
      updateLinuxServiceInstaller();

      // If this was a new installation, set up the config file and set the port
      installConfigFile(port);

      // Make any necessary changes in the config file to reflect schema evolution
      fixConfigSchema();

      System.out.println("Installation complete.");
      System.out.println(programName + " has been installed successfully.");
      System.out.println(count + " files were installed.");
    } else {
      System.err.println("Installation failed.");
      System.err.println(programName + " could not be fully installed.");
    }
    if (!programName.equals("ISN") && startRunner(new File(directory, "CTP"))) System.exit(0);
  }
  /*
   * Return a file handle pointing to the platform binary zip. Method never returns null because
   * it will fail an assert before that.
   */
  private File getPlatformZip() {
    String property = null;
    File file = null;
    if (propertyToPlatformArchive != null) {
      property = getValueFor(propertyToPlatformArchive);
      String message =
          "Need to set the "
              + "\""
              + propertyToPlatformArchive
              + "\" system property with a valid path to the platform binary drop or copy the archive to be a sibling of the install folder.";
      if (property == null) {
        fail(message);
      }
      file = new File(property);
      assertNotNull(message, file);
      assertTrue(message, file.exists());
      assertTrue("File is zero length: " + file.getAbsolutePath(), file.length() > 0);
      return file;
    }

    property = getValueFor("org.eclipse.equinox.p2.reconciler.tests.platform.archive");
    if (property == null) {
      // the releng test framework copies the zip so let's look for it...
      // it will be a sibling of the eclipse/ folder that we are running
      File installLocation = getInstallLocation();
      if (Platform.getWS().equals(Platform.WS_COCOA))
        installLocation = installLocation.getParentFile().getParentFile();

      if (installLocation != null) {
        // parent will be "eclipse" and the parent's parent will be "eclipse-testing"
        File parent = installLocation.getParentFile();
        if (parent != null) {
          parent = parent.getParentFile();
          if (parent != null) {
            File[] children =
                parent.listFiles(
                    new FileFilter() {
                      public boolean accept(File pathname) {
                        String name = pathname.getName();
                        return name.startsWith("eclipse-platform-");
                      }
                    });
            if (children != null && children.length == 1) file = children[0];
          }
        }
      }
    } else {
      file = new File(property);
    }
    StringBuffer detailedMessage = new StringBuffer(600);
    detailedMessage
        .append(" propertyToPlatformArchive was ")
        .append(propertyToPlatformArchive == null ? " not set " : propertyToPlatformArchive)
        .append('\n');
    detailedMessage
        .append(" org.eclipse.equinox.p2.reconciler.tests.platform.archive was ")
        .append(property == null ? " not set " : property)
        .append('\n');
    detailedMessage.append(" install location is ").append(getInstallLocation()).append('\n');
    String message =
        "Need to set the \"org.eclipse.equinox.p2.reconciler.tests.platform.archive\" system property with a valid path to the platform binary drop or copy the archive to be a sibling of the install folder.";
    assertNotNull(message + "\n" + detailedMessage, file);
    assertTrue(message, file.exists());
    assertTrue("File is zero length: " + file.getAbsolutePath(), file.length() > 0);
    return file;
  }