예제 #1
0
  /**
   * Cleans the WAR file of all files relating to the currently installed version of the the AMP.
   *
   * @param warFileLocatio the war file location
   * @param moduleId the module id
   * @param preview indicates whether this is a preview installation
   */
  private void cleanWAR(String warFileLocation, String moduleId, boolean preview) {
    InstalledFiles installedFiles = new InstalledFiles(warFileLocation, moduleId);
    installedFiles.load();

    for (String add : installedFiles.getAdds()) {
      // Remove file
      removeFile(warFileLocation, add, preview);
    }
    for (String mkdir : installedFiles.getMkdirs()) {
      // Remove folder
      removeFile(warFileLocation, mkdir, preview);
    }
    for (Map.Entry<String, String> update : installedFiles.getUpdates().entrySet()) {
      if (preview == false) {
        // Recover updated file and delete backups
        File modified = new File(warFileLocation + update.getKey(), DETECTOR_AMP_AND_WAR);
        File backup = new File(warFileLocation + update.getValue(), DETECTOR_AMP_AND_WAR);
        modified.copyFrom(backup);
        backup.delete();
      }

      outputMessage(
          "Recovering file '" + update.getKey() + "' from backup '" + update.getValue() + "'",
          true);
    }
    // Now remove the installed files list
    String installedFilesPathInWar = installedFiles.getFilePathInWar();
    removeFile(warFileLocation, installedFilesPathInWar, preview);
    // Remove the module properties
    String modulePropertiesFileLocationInWar =
        ModuleDetailsHelper.getModulePropertiesFilePathInWar(moduleId);
    removeFile(warFileLocation, modulePropertiesFileLocationInWar, preview);
  }
예제 #2
0
 /**
  * Removes a file from the given location in the war file.
  *
  * @param warLocation the war file location
  * @param filePath the path to the file that is to be deleted
  * @param preview indicates whether this is a preview install
  */
 private void removeFile(String warLocation, String filePath, boolean preview) {
   File removeFile = new File(warLocation + filePath, DETECTOR_AMP_AND_WAR);
   if (removeFile.exists() == true) {
     outputMessage("Removing file '" + filePath + "' from war", true);
     if (preview == false) {
       removeFile.delete();
     }
   } else {
     outputMessage(
         "The file '" + filePath + "' was expected for removal but was not present in the war",
         true);
   }
 }