Example #1
0
 public void checkOut() {
   try {
     SvnRepository.runSvnCommand(
         ImmutableList.of(
             "co", "-r", revision.revId, config.getUrl(), rootDirectory.getAbsolutePath()),
         "");
   } catch (CommandRunner.CommandException e) {
     throw new MoeProblem("Could not check out from svn: " + e.stderr);
   }
 }
Example #2
0
  /**
   * Put file from c into this writer. (Helper function.)
   *
   * @param relativeFilename the filename to put
   * @param c the Codebase to take the file from
   */
  void putFile(String relativeFilename, Codebase c) {
    try {
      FileSystem fs = AppContext.RUN.fileSystem;
      File dest = new File(rootDirectory.getAbsolutePath(), relativeFilename);
      File src = c.getFile(relativeFilename);
      boolean srcExists = fs.exists(src);
      boolean destExists = fs.exists(dest);

      boolean srcExecutable = fs.isExecutable(src);
      boolean destExecutable = fs.isExecutable(dest);

      if (!srcExists && !destExists) {
        throw new MoeProblem(
            String.format(
                "Neither src nor dests exists. Unreachable code:%n%s%n%s%n%s",
                relativeFilename, src, dest));
      }

      if (!srcExists) {
        SvnRepository.runSvnCommand(
            ImmutableList.of("rm", relativeFilename), rootDirectory.getAbsolutePath());
        // TODO(dbentley): handle newly-empty directories
        return;
      }

      try {
        fs.makeDirsForFile(dest);
        fs.copyFile(src, dest);
      } catch (IOException e) {
        throw new MoeProblem(e.getMessage());
      }

      if (!destExists) {
        SvnRepository.runSvnCommand(
            ImmutableList.of("add", "--parents", relativeFilename),
            rootDirectory.getAbsolutePath());
      }

      String mimeType = guessMimeType(relativeFilename);
      if (mimeType != null) {
        try {
          SvnRepository.runSvnCommand(
              ImmutableList.of("propset", "svn:mime-type", mimeType, relativeFilename),
              rootDirectory.getAbsolutePath());
        } catch (CommandRunner.CommandException e) {
          // If the mime type setting fails, it's not really a big deal.
          // Just log it and keep going.
          AppContext.RUN.ui.info(String.format("Error setting mime-type for %s", relativeFilename));
        }
      }

      if (destExecutable != srcExecutable) {
        if (srcExecutable) {
          SvnRepository.runSvnCommand(
              ImmutableList.of("propset", "svn:executable", "*", relativeFilename),
              rootDirectory.getAbsolutePath());
        } else {
          SvnRepository.runSvnCommand(
              ImmutableList.of("propdel", "svn:executable", relativeFilename),
              rootDirectory.getAbsolutePath());
        }
      }
    } catch (CommandRunner.CommandException e) {
      throw new MoeProblem("problem occurred while running svn: " + e.stderr);
    }
  }