コード例 #1
0
  /**
   * Loads custom data like listener and lib references if exist and fills the installdata.
   *
   * @param installdata installdata into which the custom action data should be stored
   * @throws Exception
   */
  private void loadCustomData(AutomatedInstallData installdata) throws Exception {
    // Usefull variables
    InputStream in;
    ObjectInputStream objIn;
    int i;
    // Load listeners if exist.
    String[] streamNames = AutomatedInstallData.CUSTOM_ACTION_TYPES;
    List[] out = new List[streamNames.length];
    for (i = 0; i < streamNames.length; ++i) {
      out[i] = new ArrayList();
    }
    in = InstallerBase.class.getResourceAsStream("/customData");
    if (in != null) {
      objIn = new ObjectInputStream(in);
      Object listeners = objIn.readObject();
      objIn.close();
      Iterator keys = ((List) listeners).iterator();
      while (keys != null && keys.hasNext()) {
        CustomData ca = (CustomData) keys.next();

        if (ca.osConstraints != null
            && !OsConstraint.oneMatchesCurrentSystem(
                ca.osConstraints)) { // OS constraint defined, but not matched; therefore ignore
          // it.
          continue;
        }
        switch (ca.type) {
          case CustomData.INSTALLER_LISTENER:
            Class clazz = Class.forName(ca.listenerName);
            if (clazz == null) {
              throw new InstallerException("Custom action " + ca.listenerName + " not bound!");
            }
            out[ca.type].add(clazz.newInstance());
            break;
          case CustomData.UNINSTALLER_LISTENER:
          case CustomData.UNINSTALLER_JAR:
            out[ca.type].add(ca);
            break;
          case CustomData.UNINSTALLER_LIB:
            out[ca.type].add(ca.contents);
            break;
        }
      }
      // Add the current custem action data to the installdata hash map.
      for (i = 0; i < streamNames.length; ++i) {
        installdata.customData.put(streamNames[i], out[i]);
      }
    }
    // uninstallerLib list if exist

  }
コード例 #2
0
ファイル: Unpacker.java プロジェクト: alexisP/izpack
  /**
   * Returns a stream to a pack, location depending on if it's web based.
   *
   * @param uninstall true if pack must be uninstalled
   * @return The stream or null if it could not be found.
   * @throws Exception Description of the Exception
   */
  private InputStream getPackAsStream(String packid, boolean uninstall) throws Exception {
    InputStream in = null;

    String webDirURL = idata.info.getWebDirURL();

    packid = "-" + packid;

    if (webDirURL == null) // local
    {
      in = Unpacker.class.getResourceAsStream("/packs/pack" + packid);
    } else
    // web based
    {
      // TODO: Look first in same directory as primary jar
      // This may include prompting for changing of media
      // TODO: download and cache them all before starting copy process

      // See compiler.Packager#getJarOutputStream for the counterpart
      String baseName = idata.info.getInstallerBase();
      String packURL = webDirURL + "/" + baseName + ".pack" + packid + ".jar";
      String tf =
          IoHelper.translatePath(idata.info.getUninstallerPath() + Unpacker.tempSubPath, vs);
      String tempfile;
      try {
        tempfile = WebRepositoryAccessor.getCachedUrl(packURL, tf);
        udata.addFile(tempfile, uninstall);
      } catch (Exception e) {
        if ("Cancelled".equals(e.getMessage())) {
          throw new InstallerException("Installation cancelled", e);
        } else {
          throw new InstallerException("Installation failed", e);
        }
      }
      URL url = new URL("jar:" + tempfile + "!/packs/pack" + packid);

      // URL url = new URL("jar:" + packURL + "!/packs/pack" + packid);
      // JarURLConnection jarConnection = (JarURLConnection)
      // url.openConnection();
      // TODO: what happens when using an automated installer?
      in = new WebAccessor(null).openInputStream(url);
      // TODO: Fails miserably when pack jars are not found, so this is
      // temporary
      if (in == null) {
        throw new InstallerException(
            url.toString() + " not available", new FileNotFoundException(url.toString()));
      }
    }
    if (in != null && idata.info.getPackDecoderClassName() != null) {
      Class<Object> decoder = (Class<Object>) Class.forName(idata.info.getPackDecoderClassName());
      Class[] paramsClasses = new Class[1];
      paramsClasses[0] = Class.forName("java.io.InputStream");
      Constructor<Object> constructor = decoder.getDeclaredConstructor(paramsClasses);
      // Our first used decoder input stream (bzip2) reads byte for byte from
      // the source. Therefore we put a buffering stream between it and the
      // source.
      InputStream buffer = new BufferedInputStream(in);
      Object[] params = {buffer};
      Object instance = null;
      instance = constructor.newInstance(params);
      if (!InputStream.class.isInstance(instance)) {
        throw new InstallerException(
            "'"
                + idata.info.getPackDecoderClassName()
                + "' must be derived from "
                + InputStream.class.toString());
      }
      in = (InputStream) instance;
    }
    return in;
  }