protected File getRelativeClearCaseVievRootPath()

in clearcase-agent/src/jetbrains/buildServer/vcs/clearcase/agent/RuleBasedSourceProvider.java [64:91]


  protected File getRelativeClearCaseVievRootPath(final @NotNull File checkoutRoot, final @NotNull File ruleToPath, final @NotNull File relativePathWitninAView) throws VcsValidationException {
    final String relativePathWitninAViewPath = relativePathWitninAView.getPath();
    final String checkoutRuleRightPath = ruleToPath.getPath();
    final File relativePath;
    try {
      final String fullCheckoutFolderPath = getFullCheckoutPath(checkoutRoot, checkoutRuleRightPath);
      LOG.debug(String.format("fullCheckoutFolderPath=%s", fullCheckoutFolderPath));
      if (!fullCheckoutFolderPath.endsWith(relativePathWitninAViewPath)) {
        final String errorMessage = String.format("%s Resulting checkout path (%s) should end with mandatory ClearCase-enforced path (%s) while using agent-side checkout. Please adjust checkout directory and/or right part of checkout rule correspondingly.", VALIDATION_MESSAGES_PREFIX,
            fullCheckoutFolderPath, relativePathWitninAViewPath);
        throw new VcsValidationException(String.format(errorMessage, fullCheckoutFolderPath, relativePathWitninAViewPath));
      }
      //make path relative to checkout root 
      String pathSegment = fullCheckoutFolderPath.substring(0/*checkoutRoot.getPath().length()*/, fullCheckoutFolderPath.length() - relativePathWitninAViewPath.length());
      //drop separator if exists 
      if(pathSegment.startsWith("\\") || pathSegment.startsWith("/")){
        pathSegment = pathSegment.substring(1);
      }
      LOG.debug(String.format("pathSegment=%s", pathSegment));
      relativePath = new File(pathSegment);
      LOG.debug(String.format("Relative path within checkout directory: '%s'", relativePath));
      return relativePath;

    } catch (IOException e) {
      throw new VcsValidationException(e);
    }

  }