コード例 #1
0
ファイル: SVNRepository.java プロジェクト: ryuneeee/yobi
  @Override
  public List<Commit> getHistory(int page, int limit, String until)
      throws AmbiguousObjectException, IOException, NoHeadException, GitAPIException, SVNException {
    // Get the repository
    SVNURL svnURL = SVNURL.fromFile(new File(repoPrefix + ownerName + "/" + projectName));
    org.tmatesoft.svn.core.io.SVNRepository repository = SVNRepositoryFactory.create(svnURL);

    // path to get log
    String[] paths = {"/"};

    // Determine revisions
    long startRevision = repository.getLatestRevision() - page * limit;
    long endRevision = startRevision - limit;
    if (endRevision < 1) {
      endRevision = 1;
    }

    // No log to return.
    if (startRevision < endRevision) {
      return new ArrayList<>();
    }

    // Get the logs
    List<Commit> result = new ArrayList<>();
    for (Object entry : repository.log(paths, null, startRevision, endRevision, false, false)) {
      result.add(new SvnCommit((SVNLogEntry) entry));
    }

    return result;
  }
コード例 #2
0
ファイル: SVNRepository.java プロジェクト: ryuneeee/yobi
 @Override
 public byte[] getRawFile(String path) throws SVNException {
   org.tmatesoft.svn.core.io.SVNRepository repository = getSVNRepository();
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   repository.getFile(path, -1l, null, baos);
   return baos.toByteArray();
 }
コード例 #3
0
ファイル: SVNRepository.java プロジェクト: ryuneeee/yobi
  @Override
  public Commit getCommit(String revNumber) throws IOException, SVNException {
    long rev = Integer.parseInt(revNumber);
    String[] paths = {"/"};
    SVNURL svnURL = SVNURL.fromFile(new File(getRepoPrefix() + ownerName + "/" + projectName));
    org.tmatesoft.svn.core.io.SVNRepository repository = SVNRepositoryFactory.create(svnURL);

    for (Object entry : repository.log(paths, null, rev, rev, false, false)) {
      return new SvnCommit((SVNLogEntry) entry);
    }

    return null;
  }
コード例 #4
0
ファイル: SVNRepository.java プロジェクト: hoyajigi/yobi
  @Override
  public byte[] getRawFile(String revision, String path)
      throws SVNException, FileNotFoundException {
    Long revId = (revision.equals("HEAD") ? -1l : Long.parseLong(revision));
    org.tmatesoft.svn.core.io.SVNRepository repository = getSVNRepository();

    if (!repository.checkPath(path, revId).equals(SVNNodeKind.FILE)) {
      throw new FileNotFoundException();
    }

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    repository.getFile(path, revId, null, baos); // revId=-1l
    return baos.toByteArray();
  }
コード例 #5
0
ファイル: SVNRepository.java プロジェクト: hoyajigi/yobi
  private ObjectNode getMetaDataFromPath(int revision, String path)
      throws SVNException, IOException {
    org.tmatesoft.svn.core.io.SVNRepository repository = getSVNRepository();

    SVNNodeKind nodeKind = repository.checkPath(path, revision);

    if (nodeKind == SVNNodeKind.DIR) {
      ObjectNode result = Json.newObject();
      ObjectNode listData = Json.newObject();
      SVNProperties prop = new SVNProperties();
      Collection<SVNDirEntry> entries =
          repository.getDir(path, -1, prop, SVNDirEntry.DIRENT_ALL, (Collection) null);

      result.put("type", "folder");

      for (SVNDirEntry entry : entries) {
        ObjectNode data = Json.newObject();
        String author = entry.getAuthor();
        User user = User.findByLoginId(author);
        Long commitTime = entry.getDate().getTime();

        data.put("type", entry.getKind() == SVNNodeKind.DIR ? "folder" : "file");
        data.put("msg", entry.getCommitMessage());
        data.put("author", author);
        data.put("avatar", getAvatar(user));
        data.put("userName", user.name);
        data.put("userLoginId", user.loginId);
        data.put("createdDate", commitTime);
        data.put("commitMessage", entry.getCommitMessage());
        data.put("commiter", author);
        data.put("commitDate", commitTime);
        data.put("commitId", entry.getRevision());
        data.put(
            "commitUrl",
            routes.CodeHistoryApp.show(ownerName, projectName, String.valueOf(entry.getRevision()))
                .url());
        data.put("size", entry.getSize());

        listData.put(entry.getName(), data);
      }
      result.put("data", listData);

      return result;
    } else if (nodeKind == SVNNodeKind.FILE) {
      return fileAsJson(path, repository);
    } else {
      return null;
    }
  }
コード例 #6
0
ファイル: SVNRepository.java プロジェクト: hoyajigi/yobi
 @Override
 public boolean isEmpty() {
   SVNURL svnURL;
   org.tmatesoft.svn.core.io.SVNRepository repository = null;
   try {
     svnURL = SVNURL.fromFile(getDirectory());
     repository = SVNRepositoryFactory.create(svnURL);
     return repository.getLatestRevision() == 0;
   } catch (SVNException e) {
     throw new RuntimeException(e);
   } finally {
     if (repository != null) {
       repository.closeSession();
     }
   }
 }
コード例 #7
0
ファイル: SVNRepository.java プロジェクト: ryuneeee/yobi
  @Override
  public ObjectNode findFileInfo(String path) throws SVNException {
    org.tmatesoft.svn.core.io.SVNRepository repository = getSVNRepository();

    SVNNodeKind nodeKind = repository.checkPath(path, -1);

    if (nodeKind == SVNNodeKind.DIR) {
      // 폴더 내용 출력
      ObjectNode result = Json.newObject();

      result.put("type", "folder");
      ObjectNode listData = Json.newObject();

      SVNProperties prop = new SVNProperties();

      Collection<SVNDirEntry> entries =
          repository.getDir(path, -1, prop, SVNDirEntry.DIRENT_ALL, (Collection) null);

      Iterator<SVNDirEntry> iterator = entries.iterator();
      while (iterator.hasNext()) {
        SVNDirEntry entry = iterator.next();

        ObjectNode data = Json.newObject();
        String author = entry.getAuthor();
        User user = User.findByLoginId(author);

        data.put("type", entry.getKind() == SVNNodeKind.DIR ? "folder" : "file");
        data.put("msg", entry.getCommitMessage());
        data.put("author", author);
        data.put("avatar", getAvatar(user));
        data.put("userName", user.name);
        data.put("userLoginId", user.loginId);
        data.put("createdDate", entry.getDate().getTime());

        listData.put(entry.getName(), data);
      }
      result.put("data", listData);

      return result;

    } else if (nodeKind == SVNNodeKind.FILE) {
      // 파일 내용 출력
      return fileAsJson(path, repository);
    } else {
      return null;
    }
  }
コード例 #8
0
ファイル: SVNRepository.java プロジェクト: hoyajigi/yobi
  private ObjectNode fileAsJson(String path, org.tmatesoft.svn.core.io.SVNRepository repository)
      throws SVNException, IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    SVNProperties prop = new SVNProperties();
    repository.getFile(path, -1l, prop, baos);
    SVNDirEntry entry = repository.info(path, -1l);
    long size = entry.getSize();
    boolean isBinary;
    String mimeType;
    String data = null;

    if (size > MAX_FILE_SIZE_CAN_BE_VIEWED) {
      isBinary = true;
      mimeType = "application/octet-stream";
    } else {
      byte[] bytes = baos.toByteArray();
      isBinary = RawText.isBinary(bytes);
      if (!isBinary) {
        data = new String(bytes, FileUtil.detectCharset(bytes));
      }
      mimeType = new Tika().detect(bytes, path);
    }

    String author = prop.getStringValue(SVNProperty.LAST_AUTHOR);
    User user = User.findByLoginId(author);

    String commitDate = prop.getStringValue(SVNProperty.COMMITTED_DATE);
    DateTimeFormatter dateFormatter = ISODateTimeFormat.dateTime();
    Long commitTime = dateFormatter.parseMillis(commitDate);

    ObjectNode result = Json.newObject();
    result.put("type", "file");
    result.put("revisionNo", prop.getStringValue(SVNProperty.COMMITTED_REVISION));
    result.put("author", author);
    result.put("avatar", getAvatar(user));
    result.put("userName", user.name);
    result.put("userLoginId", user.loginId);
    result.put("createdDate", commitTime);
    result.put("commitMessage", entry.getCommitMessage());
    result.put("commiter", author);
    result.put("size", size);
    result.put("isBinary", isBinary);
    result.put("mimeType", mimeType);
    result.put("data", data);

    return result;
  }