/**
   * Handles a next log entry producing corresponding xml.
   *
   * @param logEntry log entry
   * @throws SVNException
   */
  public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {

    if (logEntry.getChangedPaths() != null && relativePath != null) {
      // convert external path reference to local relative path
      Map<String, SVNLogEntryPath> changedPaths = new HashMap<String, SVNLogEntryPath>();
      for (SVNLogEntryPath entry : logEntry.getChangedPaths().values()) {
        String localPath = entry.getPath().substring(1); // path in svn log start with a '/'
        if (localPath.startsWith(relativeUrl)) {
          localPath = relativePath + localPath.substring(relativeUrl.length());
        }
        // can't use entry.setPath(localPath) as FSPathChange duplicate myPath attribute then
        // setPath().getPath() don't return same value
        changedPaths.put(
            localPath,
            new SVNLogEntryPath(
                localPath, entry.getType(), entry.getCopyPath(), entry.getCopyRevision()));
      }
      logEntry.getChangedPaths().clear();
      logEntry.getChangedPaths().putAll(changedPaths);
    }

    try {
      if (filter == null || !filter.hasExclusionRule() || filter.isIncluded(logEntry)) {
        sendToHandler(logEntry);
      }
    } catch (SAXException e) {
      SVNErrorMessage err =
          SVNErrorMessage.create(SVNErrorCode.XML_MALFORMED, e.getLocalizedMessage());
      SVNErrorManager.error(err, e, SVNLogType.DEFAULT);
    }
  }
 protected SvnFileRevision createRevision(final SVNLogEntry logEntry, final String copyPath)
     throws SVNException {
   Date date = logEntry.getDate();
   String author = logEntry.getAuthor();
   String message = logEntry.getMessage();
   SVNRevision rev = SVNRevision.create(logEntry.getRevision());
   final SVNURL url = myRepositoryRoot.appendPath(myLastPath, true);
   return new SvnFileRevision(
       myVcs, myPegRevision, rev, url.toString(), author, date, message, copyPath, myCharset);
 }
Example #3
0
  /**
   * Method setLog
   *
   * @param history
   */
  public void setLog(List<SVNLogEntry> history) {
    data.clear();

    minRevision = Long.MAX_VALUE;
    maxRevision = Long.MIN_VALUE;

    for (SVNLogEntry entry : history) {
      minRevision = Math.min(minRevision, entry.getRevision());
      maxRevision = Math.max(maxRevision, entry.getRevision());

      data.add(entry);
    }

    tableModel.fireTableDataChanged();
  }
 @SuppressWarnings("unchecked")
 private List<ChangeInfo> logEntryToChangeInfos(
     final String rootPath,
     final String loggedPath,
     final SVNLogEntry entry,
     final boolean pathOnly) {
   final String fullLoggedPathFromAppend = SVNPathUtil.append(rootPath, loggedPath);
   final String fullLoggedPath =
       (!fullLoggedPathFromAppend.startsWith("/"))
           ? "/" + fullLoggedPathFromAppend
           : fullLoggedPathFromAppend;
   final List<ChangeInfo> results = new LinkedList<ChangeInfo>();
   for (String changedPath : (Iterable<String>) entry.getChangedPaths().keySet()) {
     if (SVNPathUtil.isAncestor(rootPath, changedPath)
         && (!pathOnly || fullLoggedPath.equals(changedPath))) {
       ChangeInfo change = classifiedChange(entry, rootPath, changedPath);
       // Might want to put this at a higher level if we can ever do
       // something useful with 'other' changes.
       if (change.getKind() != StoreKind.OTHER) {
         results.add(change);
       }
     }
   }
   return results;
 }
 public void testGetAndAdd() throws Exception {
   final ObjectCache cache = createMemoryCache();
   final RevisionCacheImpl revisionCache = new RevisionCacheImpl(cache);
   try {
     assertNull(revisionCache.get(123));
     revisionCache.add(TestUtils.getLogEntryStub());
     final SVNLogEntry result = revisionCache.get(123);
     assertNotNull(result);
     assertEquals(123, result.getRevision());
     assertEquals("TestAuthor", result.getAuthor());
     assertNotNull(result.getDate());
     assertEquals("TestMessage", result.getMessage());
   } finally {
     cache.shutdown();
   }
 }
    public void consume(Pair<SVNLogEntry, Integer> svnLogEntryIntegerPair) throws SVNException {
      final SVNLogEntry logEntry = svnLogEntryIntegerPair.getFirst();
      final Integer mergeLevel = svnLogEntryIntegerPair.getSecond();

      if (mergeLevel < 0) {
        if (myCurrentHierarchy != null) {
          myConsumer.consume(myCurrentHierarchy);
        }
        if (logEntry.hasChildren()) {
          myCurrentHierarchy = new TreeStructureNode<SVNLogEntry>(logEntry);
        } else {
          // just pass
          myCurrentHierarchy = null;
          myConsumer.consume(new TreeStructureNode<SVNLogEntry>(logEntry));
        }
      } else {
        addToLevel(myCurrentHierarchy, logEntry, mergeLevel);
      }
    }
Example #7
0
  /**
   * 获取svn日志
   *
   * @param repository repos对象
   * @param path svn目录(相对与repos根目录)
   * @param datumRevision 基准版本
   * @param expectRevision 目标版本
   * @return 日志记录集合
   * @throws Exception
   */
  private static Collection<SVNLog> getLog(
      SVNRepository repository, String path, long datumRevision, long expectRevision)
      throws Exception {
    Collection<SVNLogEntry> coll = new LinkedList<SVNLogEntry>();
    repository.log(new String[] {path}, coll, datumRevision + 1, expectRevision, true, true);
    Map<String, SVNLog> logMap = new HashMap<String, SVNLog>();
    for (SVNLogEntry e : coll) {
      Map<String, SVNLogEntryPath> map = e.getChangedPaths();
      if (map != null) {
        for (SVNLogEntryPath p : map.values()) {
          String sPath = p.getPath();
          if (sPath.startsWith(path)) {
            sPath = sPath.substring(path.length());
          }
          // 操作类型
          String opt = null;

          if (p.getType() == SVNLogEntryPath.TYPE_DELETED) {
            opt = "-";
          }

          if (p.getType() == SVNLogEntryPath.TYPE_ADDED
              || p.getType() == SVNLogEntryPath.TYPE_MODIFIED
              || p.getType() == SVNLogEntryPath.TYPE_REPLACED) {
            opt = "+";
          }

          int entryKind = 0;

          if (p.getKind() == SVNNodeKind.DIR) {
            entryKind = SVNLog.ENTRY_DIR;
          }

          if (p.getKind() == SVNNodeKind.FILE) {
            entryKind = SVNLog.ENTRY_FILE;
          }

          logMap.put(sPath, new SVNLog(e.getRevision(), sPath, opt, entryKind));
        }
      }
    }
    return logMap.values();
  }
 static ChangeInfo classifiedChange(final SVNLogEntry entry, String rootPath, final String path) {
   StoreKind kind = StoreKind.OTHER;
   // Be sure the root path ends with a slash because the 'path' will always have the slash.
   if (!rootPath.endsWith("/")) {
     rootPath = rootPath + "/";
   }
   String name = path.length() > rootPath.length() ? path.substring(rootPath.length()) : path;
   String page = null;
   Matcher matcher = PAGE_PATH.matcher(name);
   if (matcher.matches() && !name.endsWith("-attachments")) {
     kind = StoreKind.PAGE;
     page = name;
   } else {
     matcher = ATTACHMENT_PATH.matcher(name);
     if (matcher.matches()) {
       kind = StoreKind.ATTACHMENT;
       page = matcher.group(1);
       name = matcher.group(2);
     }
   }
   String user = entry.getAuthor();
   Date date = entry.getDate();
   SVNLogEntryPath logForPath = (SVNLogEntryPath) entry.getChangedPaths().get(path);
   String copiedFrom = logForPath.getCopyPath();
   long copiedFromRevision = -1;
   if (SVNPathUtil.isAncestor(rootPath, copiedFrom)) {
     copiedFrom = SVNPathUtil.tail(copiedFrom);
     copiedFromRevision = logForPath.getCopyRevision();
   } else {
     copiedFrom = null;
   }
   return new ChangeInfo(
       page,
       name,
       user,
       date,
       entry.getRevision(),
       entry.getMessage(),
       kind,
       ChangeType.forCode(logForPath.getType()),
       copiedFrom,
       copiedFromRevision);
 }
Example #9
0
  /**
   * @param logEntry Log entry
   * @param repositoryName Name
   * @param mailTemplate Template
   * @return Message
   * @throws MessagingException If a message exception occurs.
   * @throws IOException if a IO exception occurs while creating the data source.
   */
  private Message createMessage(
      final SVNLogEntry logEntry, RepositoryName repositoryName, String mailTemplate)
      throws MessagingException, IOException {
    final Message msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(from));
    msg.setRecipients(
        Message.RecipientType.BCC, receivers.toArray(new InternetAddress[receivers.size()]));
    msg.setSubject(formatSubject(subject, logEntry.getRevision(), repositoryName));

    msg.setDataHandler(
        new DataHandler(
            new ByteArrayDataSource(
                HTMLCreator.createRevisionDetailBody(
                    mailTemplate, logEntry, baseUrl, repositoryName, dateFormat, null),
                "text/html")));

    msg.setHeader("X-Mailer", "sventon");
    msg.setSentDate(new Date());
    return msg;
  }
    public void accept(final SVNLogEntry entry) {
      final Map changedPaths = entry.getChangedPaths();
      if (changedPaths == null) return;

      for (Object o : changedPaths.values()) {
        final SVNLogEntryPath entryPath = (SVNLogEntryPath) o;
        if (entryPath != null && 'A' == entryPath.getType() && entryPath.getCopyPath() != null) {
          if (myCurrentPath.equals(entryPath.getPath())) {
            myHadChanged = true;
            myCurrentPath = entryPath.getCopyPath();
            return;
          } else if (SVNPathUtil.isAncestor(entryPath.getPath(), myCurrentPath)) {
            final String relativePath =
                SVNPathUtil.getRelativePath(entryPath.getPath(), myCurrentPath);
            myCurrentPath = SVNPathUtil.append(entryPath.getCopyPath(), relativePath);
            myHadChanged = true;
            return;
          }
        }
      }
    }
  public void getCommits(SVNLogEntry svnlogEntry) {
    this.type = "SVN";
    this.date = Calendar.getInstance();
    if (svnlogEntry.getDate() != null) this.date.setTime(svnlogEntry.getDate());
    this.author = svnlogEntry.getAuthor();
    this.message = svnlogEntry.getMessage();
    if (this.message != null) this.message = this.message.replace(",", ".").replace("\n", "|");
    this.revision = svnlogEntry.getRevision();

    Map myChangedPaths = svnlogEntry.getChangedPaths();

    if (myChangedPaths != null && !myChangedPaths.isEmpty()) {
      for (Iterator paths = myChangedPaths.values().iterator(); paths.hasNext(); ) {
        SVNLogEntryPath path = (SVNLogEntryPath) paths.next();
        getDiff(this.revision, path.getPath(), path.getType(), 0);
      }
    }
    System.out.println("");
  }
  @Override
  public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
    Map<String, SVNLogEntryPath> map = logEntry.getChangedPaths();

    if (map != null && map.size() > 0) {
      getDBUtil()
          .insertIntoRevision(
              logEntry.getRevision(),
              logEntry.getAuthor(),
              sdfdb.format(logEntry.getDate()),
              logEntry.getMessage());
      for (String key : map.keySet()) {
        SVNLogEntryPath entry = map.get(key);
        if (isNeedStore(key)) {
          getDBUtil()
              .insertIntoFileInfo(
                  entry.getPath(),
                  logEntry.getRevision(),
                  getType(entry.getType()),
                  entry.getCopyPath());
        }
      }
    }
  }
  // unfortunately, the original method is private, so we need to copy / paste it
  // copied from SVNXMLLogHandler
  //
  protected void sendToHandler(SVNLogEntry logEntry) throws SAXException {
    if (logEntry.getRevision() == 0 && logEntry.getMessage() == null) {
      return;
    }
    addAttribute(REVISION_ATTR, logEntry.getRevision() + "");
    openTag(LOGENTRY_TAG);
    if (logEntry.getAuthor() != null) {
      addTag(AUTHOR_TAG, logEntry.getAuthor());
    }
    if (logEntry.getDate() != null && logEntry.getDate().getTime() != 0) {
      addTag(DATE_TAG, SVNDate.formatDate(logEntry.getDate()));
    }
    if (logEntry.getChangedPaths() != null && !logEntry.getChangedPaths().isEmpty()) {
      openTag(PATHS_TAG);
      for (Iterator<String> paths = logEntry.getChangedPaths().keySet().iterator();
          paths.hasNext(); ) {
        String key = paths.next();
        SVNLogEntryPath path = (SVNLogEntryPath) logEntry.getChangedPaths().get(key);
        addAttribute(ACTION_ATTR, path.getType() + "");
        if (path.getCopyPath() != null) {
          addAttribute(COPYFROM_PATH_ATTR, path.getCopyPath());
          addAttribute(COPYFROM_REV_ATTR, path.getCopyRevision() + "");
        }
        if (path.getKind() != null) {
          addAttribute(KIND_ATTR, path.getKind().toString());
        }
        addTag(PATH_TAG, path.getPath());
      }
      closeTag(PATHS_TAG);
    }

    if (!myIsOmitLogMessage) {
      String message = logEntry.getMessage();
      message = message == null ? "" : message;
      addTag(MSG_TAG, message);
    }

    if (myMergeStack != null && !myMergeStack.isEmpty()) {
      MergeFrame frame = (MergeFrame) myMergeStack.getLast();
      frame.myNumberOfChildrenRemaining--;
    }

    if (logEntry.hasChildren()) {
      MergeFrame frame = new MergeFrame();
      if (myMergeStack == null) {
        myMergeStack = new LinkedList<MergeFrame>();
      }
      myMergeStack.addLast(frame);
    } else {
      while (myMergeStack != null && !myMergeStack.isEmpty()) {
        MergeFrame frame = (MergeFrame) myMergeStack.getLast();
        if (frame.myNumberOfChildrenRemaining == 0) {
          closeTag(LOGENTRY_TAG);
          myMergeStack.removeLast();
        } else {
          break;
        }
      }
      closeTag(LOGENTRY_TAG);
    }
  }
  public ArrayList<SVNCommit> getAllRevisions() {
    if (latestRevision < 1l) return revisions;
    try {
      final Collection<SVNLogEntry> logEntries =
          repository.log(
              new String[] {""}, null, lastSeenRevision + 1l, latestRevision, true, true);

      for (final SVNLogEntry logEntry : logEntries) {
        final SVNCommit revision = new SVNCommit(repository, this, logEntry);

        revision.setId("" + logEntry.getRevision());
        if (logEntry.getAuthor() == null) revision.setCommitter(logEntry.getAuthor());
        else revision.setCommitter("anonymous");
        revision.setDate(logEntry.getDate());
        revision.setMessage(logEntry.getMessage());

        if (logEntry.getChangedPaths() != null && logEntry.getChangedPaths().size() > 0) {
          final HashMap<String, String> rChangedPaths = new HashMap<String, String>();
          final HashMap<String, String> rRemovedPaths = new HashMap<String, String>();
          final HashMap<String, String> rAddedPaths = new HashMap<String, String>();
          for (final Iterator changedPaths = logEntry.getChangedPaths().keySet().iterator();
              changedPaths.hasNext(); ) {
            final SVNLogEntryPath entryPath =
                (SVNLogEntryPath) logEntry.getChangedPaths().get(changedPaths.next());
            if (repository.checkPath(entryPath.getPath(), logEntry.getRevision())
                == SVNNodeKind.FILE) {
              if (entryPath.getType() == SVNLogEntryPath.TYPE_DELETED)
                rRemovedPaths.put(entryPath.getPath(), entryPath.getCopyPath());
              else if (entryPath.getType() == SVNLogEntryPath.TYPE_ADDED)
                rAddedPaths.put(entryPath.getPath(), entryPath.getCopyPath());
              else rChangedPaths.put(entryPath.getPath(), entryPath.getCopyPath());
            }
          }
          revision.setChangedPaths(rChangedPaths);
          revision.setRemovedPaths(rRemovedPaths);
          revision.setAddedPaths(rAddedPaths);
        }

        this.revisions.add(revision);
      }
    } catch (final SVNException e) {
      e.printStackTrace();
    }
    return revisions;
  }
  @Override
  protected String getChangeFileNames(String lastFinishDateTimeString) throws Exception {
    /*
     * Default values:
     */
    String url = Globals.getProperty("svn.url");
    String name = Globals.getProperty("svn.user");
    String password = Globals.getProperty("svn.password");

    long startRevision = 0;
    long endRevision = -1; // HEAD (the latest) revision

    setupLibrary();

    SVNRepository repository = null;

    try {
      repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
    } catch (SVNException svne) {
      /*
       * Perhaps a malformed URL is the cause of this exception.
       */
      System.err.println(
          "error while creating an SVNRepository for the location '"
              + url
              + "': "
              + svne.getMessage());
      System.exit(1);
    }

    ISVNAuthenticationManager authManager =
        SVNWCUtil.createDefaultAuthenticationManager(name, password);
    repository.setAuthenticationManager(authManager);

    /*
     * Gets the latest revision number of the repository
     */
    try {
      endRevision = repository.getLatestRevision();
      startRevision = endRevision;
    } catch (SVNException svne) {
      System.err.println(
          "error while fetching the latest repository revision: " + svne.getMessage());
      System.exit(1);
    }

    Collection logEntries = null;
    try {
      /*
       * Collects SVNLogEntry objects for all revisions in the range
       * defined by its start and end points [startRevision, endRevision].
       * For each revision commit information is represented by
       * SVNLogEntry.
       *
       * the 1st parameter (targetPaths - an array of path strings) is set
       * when restricting the [startRevision, endRevision] range to only
       * those revisions when the paths in targetPaths were changed.
       *
       * the 2nd parameter if non-null - is a user's Collection that will
       * be filled up with found SVNLogEntry objects; it's just another
       * way to reach the scope.
       *
       * startRevision, endRevision - to define a range of revisions you are
       * interested in; by default in this program - startRevision=0, endRevision=
       * the latest (HEAD) revision of the repository.
       *
       * the 5th parameter - a boolean flag changedPath - if true then for
       * each revision a corresponding SVNLogEntry will contain a map of
       * all paths which were changed in that revision.
       *
       * the 6th parameter - a boolean flag strictNode - if false and a
       * changed path is a copy (branch) of an existing one in the repository
       * then the history for its origin will be traversed; it means the
       * history of changes of the target URL (and all that there's in that
       * URL) will include the history of the origin path(s).
       * Otherwise if strictNode is true then the origin path history won't be
       * included.
       *
       * The return value is a Collection filled up with SVNLogEntry Objects.
       */
      logEntries = repository.log(new String[] {""}, null, startRevision, endRevision, true, true);

    } catch (SVNException svne) {
      System.out.println(
          "error while collecting log information for '" + url + "': " + svne.getMessage());
      System.exit(1);
    }
    for (Iterator entries = logEntries.iterator(); entries.hasNext(); ) {
      /*
       * gets a next SVNLogEntry
       */
      SVNLogEntry logEntry = (SVNLogEntry) entries.next();
      System.out.println("---------------------------------------------");
      /*
       * gets the revision number
       */
      System.out.println("revision: " + logEntry.getRevision());
      /*
       * gets the author of the changes made in that revision
       */
      System.out.println("author: " + logEntry.getAuthor());
      /*
       * gets the time moment when the changes were committed
       */
      System.out.println("date: " + logEntry.getDate());
      /*
       * gets the commit log message
       */
      System.out.println("log message: " + logEntry.getMessage());
      /*
       * displaying all paths that were changed in that revision; cahnged
       * path information is represented by SVNLogEntryPath.
       */
      if (logEntry.getChangedPaths().size() > 0) {
        System.out.println();
        System.out.println("changed paths:");
        /*
         * keys are changed paths
         */
        Set changedPathsSet = logEntry.getChangedPaths().keySet();

        for (Iterator changedPaths = changedPathsSet.iterator(); changedPaths.hasNext(); ) {
          /*
           * obtains a next SVNLogEntryPath
           */
          SVNLogEntryPath entryPath =
              (SVNLogEntryPath) logEntry.getChangedPaths().get(changedPaths.next());
          /*
           * SVNLogEntryPath.getPath returns the changed path itself;
           *
           * SVNLogEntryPath.getType returns a charecter describing
           * how the path was changed ('A' - added, 'D' - deleted or
           * 'M' - modified);
           *
           * If the path was copied from another one (branched) then
           * SVNLogEntryPath.getCopyPath &
           * SVNLogEntryPath.getCopyRevision tells where it was copied
           * from and what revision the origin path was at.
           */
          System.out.println(
              " "
                  + entryPath.getType()
                  + "	"
                  + entryPath.getPath()
                  + ((entryPath.getCopyPath() != null)
                      ? " (from "
                          + entryPath.getCopyPath()
                          + " revision "
                          + entryPath.getCopyRevision()
                          + ")"
                      : ""));
        }
      }
    }
    return "";
  }