public SVNDirEntry info(String path, long revision) throws SVNException {
   try {
     openConnection();
     String fullPath = getFullPath(path);
     SVNURL url = getLocation().setPath(fullPath, false);
     path = getRepositoryPath(path);
     Object[] buffer = new Object[] {"stat", path, getRevisionObject(revision)};
     write("(w(s(n)))", buffer);
     authenticate();
     read("[((?F))]", buffer, true);
     SVNDirEntry entry = (SVNDirEntry) buffer[0];
     if (entry != null) {
       entry =
           new SVNDirEntry(
               url,
               SVNPathUtil.tail(path),
               entry.getKind(),
               entry.getSize(),
               entry.hasProperties(),
               entry.getRevision(),
               entry.getDate(),
               entry.getAuthor());
     }
     return entry;
   } catch (SVNException e) {
     closeSession();
     handleUnsupportedCommand(e, "'stat' not implemented");
   } finally {
     closeConnection();
   }
   return null;
 }
Пример #2
0
  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;
    }
  }
Пример #3
0
  @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;
    }
  }
Пример #4
0
 /*
  * Called recursively to obtain all entries that make up the repository tree
  * repository - an SVNRepository which interface is used to carry out the
  * request, in this case it's a request to get all entries in the directory
  * located at the path parameter;
  *
  * path is a directory path relative to the repository location path (that
  * is a part of the URL used to create an SVNRepository instance);
  *
  */
 public static void listEntries(SVNRepository repository, String path) throws SVNException {
   /*
    * Gets the contents of the directory specified by path at the latest
    * revision (for this purpose -1 is used here as the revision number to
    * mean HEAD-revision) getDir returns a Collection of SVNDirEntry
    * elements. SVNDirEntry represents information about the directory
    * entry. Here this information is used to get the entry name, the name
    * of the person who last changed this entry, the number of the revision
    * when it was last changed and the entry type to determine whether it's
    * a directory or a file. If it's a directory listEntries steps into a
    * next recursion to display the contents of this directory. The third
    * parameter of getDir is null and means that a user is not interested
    * in directory properties. The fourth one is null, too - the user
    * doesn't provide its own Collection instance and uses the one returned
    * by getDir.
    */
   Collection entries = repository.getDir(path, -1, null, (Collection) null);
   Iterator iterator = entries.iterator();
   while (iterator.hasNext()) {
     SVNDirEntry entry = (SVNDirEntry) iterator.next();
     System.out.println(
         "/"
             + (path.equals("") ? "" : path + "/")
             + entry.getName()
             + " (author: '"
             + entry.getAuthor()
             + "'; revision: "
             + entry.getRevision()
             + "; date: "
             + entry.getDate()
             + ")");
     /*
      * Checking up if the entry is a directory.
      */
     if (entry.getKind() == SVNNodeKind.DIR) {
       listEntries(repository, (path.equals("")) ? entry.getName() : path + "/" + entry.getName());
     }
   }
 }
  public SVNDirEntry getDir(
      String path, long revision, boolean includeComment, final Collection entries)
      throws SVNException {
    Long rev = getRevisionObject(revision);
    // convert path to path relative to repos root.
    SVNDirEntry parentEntry = null;
    try {
      openConnection();
      final SVNURL url = getLocation().setPath(getFullPath(path), false);
      ISVNDirEntryHandler handler =
          new ISVNDirEntryHandler() {
            public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException {
              dirEntry =
                  new SVNDirEntry(
                      url.appendPath(dirEntry.getName(), false),
                      dirEntry.getName(),
                      dirEntry.getKind(),
                      dirEntry.getSize(),
                      dirEntry.hasProperties(),
                      dirEntry.getRevision(),
                      dirEntry.getDate(),
                      dirEntry.getAuthor());
              entries.add(dirEntry);
            }
          };
      path = getRepositoryPath(path);
      // get parent
      Object[] buffer = new Object[] {"stat", path, getRevisionObject(revision)};
      write("(w(s(n)))", buffer);
      authenticate();
      read("[((?F))]", buffer, true);
      parentEntry = (SVNDirEntry) buffer[0];
      parentEntry =
          new SVNDirEntry(
              url,
              "",
              parentEntry.getKind(),
              parentEntry.getSize(),
              parentEntry.hasProperties(),
              parentEntry.getRevision(),
              parentEntry.getDate(),
              parentEntry.getAuthor());

      // get entries.
      buffer = new Object[] {"get-dir", path, rev, Boolean.FALSE, Boolean.TRUE};
      write("(w(s(n)ww))", buffer);
      authenticate();
      buffer = read("[(N(*P)", buffer, true);
      revision = buffer[0] != null ? SVNReader.getLong(buffer, 0) : revision;
      if (handler != null) {
        buffer[0] = handler;
        read("(*D)))", buffer, true);
      } else {
        read("()))", null, true);
      }
      // get comments.
      if (includeComment) {
        Map messages = new HashMap();
        for (Iterator ents = entries.iterator(); ents.hasNext(); ) {
          SVNDirEntry entry = (SVNDirEntry) ents.next();
          Long key = getRevisionObject(entry.getRevision());
          if (messages.containsKey(key)) {
            entry.setCommitMessage((String) messages.get(key));
            continue;
          }
          buffer = new Object[] {"rev-prop", key, SVNRevisionProperty.LOG};
          write("(w(ns))", buffer);
          authenticate();
          buffer = read("[((?S))]", buffer, true);
          messages.put(key, buffer[0]);
          entry.setCommitMessage((String) buffer[0]);
        }
      }
    } catch (SVNException e) {
      closeSession();
      throw e;
    } finally {
      closeConnection();
    }
    return parentEntry;
  }
Пример #6
0
  private static void list(
      SVNRepository repository,
      String path,
      long rev,
      SVNDepth depth,
      int entryFields,
      Map<SVNURL, SVNPropertyValue> externals,
      SVNURL externalParentUrl,
      String externalTarget,
      ISVNDirEntryHandler handler)
      throws SVNException {
    if (depth == SVNDepth.EMPTY) {
      return;
    }
    Collection entries = new TreeSet();
    SVNProperties properties;
    try {
      properties = externals == null ? null : new SVNProperties();
      entries = repository.getDir(path, rev, properties, entryFields, entries);
    } catch (SVNAuthenticationException e) {
      return;
    } catch (SVNException e) {
      if (e.getErrorMessage().getErrorCode() == SVNErrorCode.RA_NOT_AUTHORIZED) {
        return;
      }
      throw e;
    }

    SVNPropertyValue svnExternalsVaule =
        properties == null ? null : properties.getSVNPropertyValue(SVNProperty.EXTERNALS);
    if (svnExternalsVaule != null) {
      SVNURL location = repository.getLocation();
      externals.put(location.appendPath(path, false), svnExternalsVaule);
    }

    for (Iterator iterator = entries.iterator(); iterator.hasNext(); ) {
      SVNDirEntry entry = (SVNDirEntry) iterator.next();
      String childPath = SVNPathUtil.append(path, entry.getName());
      entry.setRelativePath(childPath);
      if (entry.getKind() == SVNNodeKind.FILE
          || depth == SVNDepth.IMMEDIATES
          || depth == SVNDepth.INFINITY) {
        entry.setExternalParentUrl(externalParentUrl);
        entry.setExternalTarget(externalTarget);
        handler.handleDirEntry(entry);
      }
      if (entry.getKind() == SVNNodeKind.DIR
          && entry.getDate() != null
          && depth == SVNDepth.INFINITY) {
        list(
            repository,
            childPath,
            rev,
            depth,
            entryFields,
            externals,
            externalParentUrl,
            externalTarget,
            handler);
      }
    }
  }