/**
   * Write the version of the metadata into a known file overwriting any existing file contents.
   * Writing the version file isn't really crucial, so the function is silent about failure
   */
  private static void writeWorkspaceVersion() {
    Location instanceLoc = Platform.getInstanceLocation();
    if (instanceLoc == null || instanceLoc.isReadOnly()) {
      return;
    }

    File versionFile = getVersionFile(instanceLoc.getURL(), true);
    if (versionFile == null) {
      return;
    }

    OutputStream output = null;
    try {
      String versionLine = WORKSPACE_VERSION_KEY + '=' + WORKSPACE_VERSION_VALUE;

      output = new FileOutputStream(versionFile);
      output.write(versionLine.getBytes(StandardCharsets.UTF_8));
    } catch (IOException e) {
      Logger logger = new WorkbenchLogger(PLUGIN_ID);
      logger.error(e);
    } finally {
      try {
        if (output != null) {
          output.close();
        }
      } catch (IOException e) {
        // do nothing
      }
    }
  }
Example #2
0
  /**
   * Write the version of the metadata into a known file overwriting any existing file contents.
   * Writing the version file isn't really crucial, so the function is silent about failure
   */
  private static void writeWorkspaceVersion() {
    if (WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION == null) {
      // no reference bundle installed, no check possible
      return;
    }

    Location instanceLoc = Platform.getInstanceLocation();
    if (instanceLoc == null || instanceLoc.isReadOnly()) {
      return;
    }

    File versionFile = getVersionFile(instanceLoc.getURL(), true);
    if (versionFile == null) {
      return;
    }

    OutputStream output = null;
    try {
      output = new FileOutputStream(versionFile);
      Properties props = new Properties();

      // write new property
      props.setProperty(
          WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME,
          WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION.toString());

      // write legacy property with an incremented version,
      // so that pre-4.4 IDEs will also warn about the workspace
      props.setProperty(
          WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME_LEGACY, WORKSPACE_CHECK_LEGACY_VERSION_INCREMENTED);

      props.store(output, null);
    } catch (IOException e) {
      IDEWorkbenchPlugin.log(
          "Could not write version file", //$NON-NLS-1$
          StatusUtil.newStatus(IStatus.ERROR, e.getMessage(), e));
    } finally {
      try {
        if (output != null) {
          output.close();
        }
      } catch (IOException e) {
        // do nothing
      }
    }
  }