8N/A/*
8N/A * CDDL HEADER START
8N/A *
8N/A * The contents of this file are subject to the terms of the
8N/A * Common Development and Distribution License (the "License").
8N/A * You may not use this file except in compliance with the License.
8N/A *
8N/A * See LICENSE.txt included in this distribution for the specific
8N/A * language governing permissions and limitations under the License.
8N/A *
8N/A * When distributing Covered Code, include this CDDL HEADER in each
8N/A * file and include the License file at LICENSE.txt.
8N/A * If applicable, add the following below this CDDL HEADER, with the
8N/A * fields enclosed by brackets "[]" replaced with your own identifying
8N/A * information: Portions Copyright [yyyy] [name of copyright owner]
8N/A *
8N/A * CDDL HEADER END
8N/A */
8N/A
8N/A/*
1054N/A * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
8N/A * Copyright 2006 Trond Norbye. All rights reserved.
8N/A * Use is subject to license terms.
8N/A */
8N/Apackage org.opensolaris.opengrok.history;
8N/A
50N/Aimport java.util.ArrayList;
25N/Aimport java.util.Date;
50N/Aimport java.util.List;
802N/Aimport java.util.SortedSet;
802N/Aimport java.util.TreeSet;
416N/Aimport java.util.logging.Level;
416N/Aimport java.util.logging.Logger;
25N/A
8N/A/**
8N/A * Collect all information of a given revision
8N/A *
8N/A * @author Trond Norbye
8N/A */
8N/Apublic class HistoryEntry {
8N/A private String revision;
1481N/A private String oldRevision;
25N/A private Date date;
8N/A private String author;
457N/A
457N/A @SuppressWarnings("PMD.AvoidStringBufferField")
456N/A private final StringBuffer message;
457N/A
25N/A private boolean active;
802N/A private SortedSet<String> files;
306N/A private List<String> changeRequests;
1190N/A
8N/A /** Creates a new instance of HistoryEntry */
8N/A public HistoryEntry() {
8N/A message = new StringBuffer();
802N/A files = new TreeSet<String>();
306N/A changeRequests = new ArrayList<String>();
8N/A }
1190N/A
1481N/A /**
1481N/A * Convinience constructor to create a more or less fully populated entry.
1481N/A * @param revision revision ID of the changeset.
1481N/A * @param oldRevision revision ID of the changeset in the non-hybrid repo.
1481N/A * Use {@code null} if not available.
1481N/A * @param date change timestamp
1481N/A * @param author the authors name and email-address (if available).
1481N/A * @param message the changeset description.
1481N/A * @param active Use {@code true} to indicate, that this entry is
1481N/A * fully populated and thus usable by other consumers.
1481N/A */
1481N/A public HistoryEntry(String revision, String oldRevision, Date date,
1481N/A String author, String message, boolean active)
1481N/A {
8N/A this.revision = revision;
1481N/A this.oldRevision = oldRevision;
380N/A setDate(date);
8N/A this.author = author;
8N/A this.message = new StringBuffer(message);
25N/A this.active = active;
802N/A this.files = new TreeSet<String>();
306N/A this.changeRequests = new ArrayList<String>();
8N/A }
1190N/A
8N/A public String getLine() {
8N/A return revision + " " + date + " " + author + " " + message + "\n";
8N/A }
306N/A
306N/A public void dump() {
1327N/A Logger log = Logger.getLogger(HistoryEntry.class.getName());
1327N/A if (!log.isLoggable(Level.FINE)) {
1327N/A return;
1327N/A }
1054N/A log.log(Level.FINE, "HistoryEntry : revision = {0}", revision);
1481N/A log.log(Level.FINE, "HistoryEntry : old revision = {0}",
1481N/A oldRevision == null ? "" : oldRevision);
1054N/A log.log(Level.FINE, "HistoryEntry : date = {0}", date);
1054N/A log.log(Level.FINE, "HistoryEntry : author = {0}", author);
1054N/A log.log(Level.FINE, "HistoryEntry : active = {0}", (active ? "True" : "False"));
306N/A String[] lines = message.toString().split("\n");
306N/A String separator = "=";
416N/A for (String line : lines) {
1054N/A log.log(Level.FINE, "HistoryEntry : message {0} {1}", new Object[]{separator, line});
306N/A separator = ">";
306N/A }
306N/A separator = "=";
416N/A for (String cr : changeRequests) {
1054N/A log.log(Level.FINE, "HistoryEntry : changeRequests {0} {1}", new Object[]{separator, cr});
306N/A separator = ">";
306N/A }
306N/A separator = "=";
416N/A for (String file : files) {
1054N/A log.log(Level.FINE, "HistoryEntry : files {0} {1}", new Object[]{separator, file});
306N/A separator = ">";
306N/A }
306N/A }
306N/A
8N/A public String getAuthor() {
8N/A return author;
8N/A }
1190N/A
25N/A public Date getDate() {
460N/A return (date == null) ? null : (Date) date.clone();
8N/A }
1190N/A
8N/A public String getMessage() {
8N/A return message.toString().trim();
8N/A }
1190N/A
8N/A public String getRevision() {
8N/A return revision;
8N/A }
1190N/A
1481N/A /**
1481N/A * <p>Get the revision of this changeset in the non-hybrid repository.</p>
1481N/A * <p>E.g. If hgsubversion is used to "mirror/sync" a svn
1481N/A * repository into a mercurial repository and this entry belongs to a
1481N/A * mercurial repository - this method returns the svn based revision number,
1481N/A * whereby {@link #getRevision()} returns the mercurial revision number.
1481N/A *</p>
1481N/A * @return {@code null} if not available (e.g. if this is not a hybrid
1481N/A * repo), the non-hybrid revision number otherwise.
1481N/A * @see #setOldRevision()
1481N/A */
1481N/A public String getOldRevision() {
1481N/A return oldRevision;
1481N/A }
1481N/A
8N/A public void setAuthor(String author) {
8N/A this.author = author;
8N/A }
1190N/A
439N/A public final void setDate(Date date) {
460N/A if (date == null) {
460N/A this.date = null;
460N/A } else {
382N/A this.date = (Date) date.clone();
382N/A }
8N/A }
1190N/A
25N/A public boolean isActive() {
25N/A return active;
25N/A }
1190N/A
25N/A public void setActive(boolean active) {
25N/A this.active = active;
25N/A }
1190N/A
8N/A public void setMessage(String message) {
8N/A this.message.setLength(0);
8N/A this.message.append(message);
8N/A }
1190N/A
8N/A public void setRevision(String revision) {
8N/A this.revision = revision;
8N/A }
1190N/A
1481N/A /**
1481N/A * Set the revision of this changeset in the non-hybrid repository.
1481N/A * @param revision revision to set.
1481N/A * @see #getOldRevision()
1481N/A */
1481N/A public void setOldRevision(String revision) {
1481N/A this.oldRevision = revision;
1481N/A }
1481N/A
8N/A public void appendMessage(String message) {
8N/A this.message.append(message);
8N/A this.message.append("\n");
8N/A }
1190N/A
50N/A public void addFile(String file) {
802N/A files.add(file);
50N/A }
1190N/A
802N/A public SortedSet<String> getFiles() {
50N/A return files;
50N/A }
1190N/A
802N/A public void setFiles(SortedSet<String> files) {
50N/A this.files = files;
50N/A }
1190N/A
306N/A @Override
8N/A public String toString() {
8N/A return getLine();
8N/A }
1190N/A
306N/A public void addChangeRequest(String changeRequest) {
796N/A if (!changeRequests.contains(changeRequest)) {
796N/A changeRequests.add(changeRequest);
796N/A }
306N/A }
1190N/A
306N/A public List<String> getChangeRequests() {
306N/A return changeRequests;
306N/A }
1190N/A
306N/A public void setChangeRequests(List<String> changeRequests) {
306N/A this.changeRequests = changeRequests;
306N/A }
170N/A
58N/A /**
58N/A * Remove "unneeded" info such as multiline history and files list
58N/A */
58N/A public void strip() {
58N/A files.clear();
58N/A }
8N/A}