/**
  * Check if specified checkout rules are supported
  *
  * @param root root for which rules are checked
  * @param rules rules to check
  * @throws VcsException rules are not supported
  */
 private void validateCheckoutRules(
     @NotNull final VcsRoot root, @NotNull final CheckoutRules rules) throws VcsException {
   if (rules.getExcludeRules().size() != 0) {
     throw new VcsException(
         "Exclude rules are not supported for agent checkout for the git ("
             + rules.getExcludeRules().size()
             + " rule(s) detected) for VCS Root '"
             + root.getName()
             + "'");
   }
   if (rules.getIncludeRules().size() > 1) {
     throw new VcsException(
         "At most one include rule is supported for agent checkout for the git ("
             + rules.getIncludeRules().size()
             + " rule(s) detected) for VCS Root '"
             + root.getName()
             + "'");
   }
   if (rules.getIncludeRules().size() == 1) {
     IncludeRule ir = rules.getIncludeRules().get(0);
     if (!".".equals(ir.getFrom()) && ir.getFrom().length() != 0) {
       throw new VcsException(
           "Agent checkout for the git supports only include rule of form '. => subdir', rule '"
               + ir.toDescriptiveString()
               + "' for VCS Root '"
               + root.getName()
               + "' is not supported");
     }
   }
 }
  /**
   * Get the destination directory creating it if it is missing
   *
   * @param root VCS root
   * @param rules checkout rules
   * @param checkoutDirectory checkout directory for the build
   * @return the directory where vcs root should be checked out according to checkout rules
   * @throws VcsException if the directory could not be located or created
   */
  private File getTargetDir(
      @NotNull final VcsRoot root,
      @NotNull final CheckoutRules rules,
      @NotNull final File checkoutDirectory)
      throws VcsException {
    String path = rules.map("");
    if (path == null)
      throw new VcsException(
          "The root path could not be mapped for VCS root '" + root.getName() + "'");

    File directory =
        path.length() == 0
            ? checkoutDirectory
            : new File(checkoutDirectory, path.replace('/', File.separatorChar));
    if (!directory.exists()) {
      //noinspection ResultOfMethodCallIgnored
      directory.mkdirs();
      if (!directory.exists())
        throw new VcsException(
            "The destination directory '" + directory + "' could not be created.");
    }
    return directory;
  }