Пример #1
0
  /** Removes old integrated component for updating the new one. */
  public void removeOldIntegration() {
    integrationService.setFileWatcherActive(false);
    String previousToolName = "";
    String toolName = (String) configurationMap.get(ToolIntegrationConstants.KEY_TOOL_NAME);
    File previousToolDir = null;
    if (previousConfiguration != null) {
      previousToolName = (String) previousConfiguration.get(ToolIntegrationConstants.KEY_TOOL_NAME);
      previousToolDir =
          new File(
              new File(
                  integrationContext.getRootPathToToolIntegrationDirectory(),
                  integrationContext.getNameOfToolIntegrationDirectory()),
              previousToolName);
    } else {
      previousToolName = toolName;
    }
    if (previousToolDir != null) {
      storeIconAndDocuInTempDir(previousToolDir);
    }
    integrationService.unregisterIntegration(previousToolName, integrationContext);
    integrationService.removeTool(previousToolName, integrationContext);
    if (!previousToolName.equals(toolName)) {

      File delete = previousToolDir;
      try {
        FileUtils.forceDelete(delete);
      } catch (IOException e) {
        LogFactory.getLog(ToolIntegrationWizard.class).error(e);
      }
    } else {
      if (configurationMap.get(ToolIntegrationConstants.KEY_DOC_FILE_PATH) == null
          || ((String) configurationMap.get(ToolIntegrationConstants.KEY_DOC_FILE_PATH))
              .isEmpty()) {
        File docDir = new File(previousToolDir, ToolIntegrationConstants.DOCS_DIR_NAME);
        if (docDir.listFiles() != null) {
          for (File f : docDir.listFiles()) {
            try {
              FileUtils.forceDelete(f);
            } catch (IOException e) {
              LOGGER.error("Could not delete file in tool docs directory: ", e);
            }
          }
        }
      }
    }
    integrationService.setFileWatcherActive(true);
  }
Пример #2
0
 /**
  * Saves the wizards configuration to the given path.
  *
  * @param folderPath where to store the configuration.
  */
 public void performSaveAs(String folderPath) {
   determineIntegrationContext();
   File toolConfigFile =
       new File(
           folderPath,
           integrationContext.getNameOfToolIntegrationDirectory()
               + File.separator
               + integrationContext.getToolDirectoryPrefix()
               + configurationMap.get(ToolIntegrationConstants.KEY_TOOL_NAME));
   try {
     integrationService.writeToolIntegrationFileToSpecifiedFolder(
         folderPath, configurationMap, integrationContext);
     MessageBox infoDialog = new MessageBox(getShell(), SWT.ICON_INFORMATION | SWT.OK);
     if (toolConfigFile.exists()) {
       infoDialog.setText("Tool saved");
       infoDialog.setMessage(
           StringUtils.format(
               "Successfully saved tool: %s\nLocation: " + toolConfigFile.getAbsolutePath(),
               configurationMap.get(ToolIntegrationConstants.KEY_TOOL_NAME)));
     } else {
       infoDialog.setText("Saving failed");
       infoDialog.setMessage(
           StringUtils.format(
               "Could not save tool: %s\nLocation tried: " + toolConfigFile.getAbsolutePath(),
               configurationMap.get(ToolIntegrationConstants.KEY_TOOL_NAME)));
     }
     infoDialog.open();
   } catch (IOException e) {
     MessageBox errorDialog = new MessageBox(getShell(), SWT.ICON_ERROR | SWT.OK);
     errorDialog.setText("Saving failed");
     errorDialog.setMessage(
         StringUtils.format(
             "Failed to save tool configuration to: "
                 + toolConfigFile.getAbsolutePath()
                 + "\nCause: "
                 + e.getMessage(),
             configurationMap.get(ToolIntegrationConstants.KEY_TOOL_NAME)));
     errorDialog.open();
   }
 }