Exemplo n.º 1
0
  protected void writeWebApps() throws IOException {
    // write to a subdirectory of the default temp directory
    File deployDir = new File(RunUtil.getRunDir(), getWebappDir());
    deployDir.mkdirs();

    // figure out the set of files to add or remove
    List<String> addFiles = new ArrayList<String>();
    List<String> removeFiles = new ArrayList<String>();
    FileListUtil.compareDirs("META-INF/" + getWebappDir(), deployDir, addFiles, removeFiles);

    // remove the files to remove
    for (String removeFile : removeFiles) {
      File remove = new File(deployDir, removeFile);

      // files have been extracted into directories
      if (remove.isDirectory()) {
        RunUtil.deleteDir(remove);
      }
    }

    for (String addFile : addFiles) {
      String fullPath = "/" + getWebappDir() + "/" + addFile;

      // make sure to clear the directory before we write to it
      File existingDir = new File(deployDir, addFile);
      if (existingDir.exists() && existingDir.isDirectory()) {
        RunUtil.deleteDir(existingDir);
      }

      RunUtil.extractJar(getClass(), fullPath, deployDir);
    }

    // write the updated checksum list
    RunUtil.extract(getClass(), "/META-INF/" + getWebappDir() + "/files.list", deployDir);
  }
Exemplo n.º 2
0
  protected void writeDocumentRoot() throws IOException {
    File docDir = new File(RunUtil.getRunDir(), "docRoot");
    docDir.mkdirs();

    // figure out the set of files to add or remove
    List<String> addFiles = new ArrayList<String>();
    List<String> removeFiles = new ArrayList<String>();
    FileListUtil.compareDirs("META-INF/docroot", docDir, addFiles, removeFiles);

    for (String removeFile : removeFiles) {
      File file = new File(docDir, removeFile);
      file.delete();
    }

    for (String addFile : addFiles) {
      String fullPath = "/docroot/" + addFile;
      InputStream fileIs = WebServerLauncher.class.getResourceAsStream(fullPath);

      RunUtil.writeToFile(fileIs, new File(docDir, addFile));
      fileIs.close();
    }

    // write the updated checksum list
    RunUtil.extract(getClass(), "/META-INF/docroot/files.list", docDir);
  }
Exemplo n.º 3
0
  /**
   * Update any system-installed module to be the latest version from the Wonderland.jar file.
   *
   * @throws IOException if there is an error reading or writing modules
   */
  protected void updateModules() throws IOException {
    ModuleManager mm = ModuleManager.getModuleManager();

    // create the directory to extract modules to, if it doesn't already
    // exist
    File moduleDir = RunUtil.createTempDir("module", ".jar");

    // read the list of modules and their checksums from the jar file
    Map<String, String> checksums = FileListUtil.readChecksums("META-INF/modules");

    // get the list of all installed module with the "system-installed"
    // key set.  This is set on all modules installed by the system
    Map<String, Module> installed = mm.getInstalledModulesByKey(ModuleAttributes.SYSTEM_MODULE);

    // get the checksum of any module that has a checksum.  As a
    // side-effect, any module with a checksum is removed from the
    // list of installed modules, so that list can be used to decide
    // which modules to uninstall
    Map<String, String[]> installedChecksums = getChecksums(installed);

    // add all modules remaining in the installed list to the
    // uninstall list.  These are modules that were installed by an
    // old version of Wonderland and do not have a filename or
    // checksum attribute set.
    Collection<String> uninstall = new ArrayList<String>(installed.keySet());

    // now go through the checksums of old and new modules to determine
    // which modules need to be installed and which are unchanged
    List<TaggedModule> install = new ArrayList<TaggedModule>();
    for (Map.Entry<String, String> checksum : checksums.entrySet()) {

      // compare an existing checksum to an old checksum. If the
      // old checksum doesn't exist or is different than the new
      // checksum, install the new file.  This will overwrite the old
      // checksum in the process.
      String[] installedChecksum = installedChecksums.remove(checksum.getKey());
      if (installedChecksum == null || !installedChecksum[0].equals(checksum.getValue())) {
        install.add(createTaggedModule(checksum.getKey(), checksum.getValue(), moduleDir));
      }
    }

    // any modules not removed from the installedChecksums list are
    // old modules that were installed by a previous version of Wonderland
    // (not by the user) and aren't in the new module list.  We need to
    // remove these modules
    for (String[] moduleDesc : installedChecksums.values()) {
      uninstall.add(moduleDesc[1]);
    }

    // uninstall any modules on the uninstall list
    logger.warning("Uninstall: " + uninstall);
    mm.addToUninstall(uninstall);

    // install any modules on the install list
    String installList = "";
    for (TaggedModule tm : install) {
      installList += " " + tm.getFile().getName();
    }
    logger.warning("Install: " + installList);
    mm.addTaggedToInstall(install);
  }