1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * See LICENSE.txt included in this distribution for the specific 9 * language governing permissions and limitations under the License. 10 * 11 * When distributing Covered Code, include this CDDL HEADER in each 12 * file and include the License file at LICENSE.txt. 13 * If applicable, add the following below this CDDL HEADER, with the 14 * fields enclosed by brackets "[]" replaced with your own identifying 15 * information: Portions Copyright [yyyy] [name of copyright owner] 16 * 17 * CDDL HEADER END 18 */ 19 20 /* 21 * Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved. 22 */ 23 /* 24 * Copyright 2006 Trond Norbye. All rights reserved. 25 */ 26 package org.opengrok.indexer.history; 27 28 import java.util.Date; 29 import java.util.SortedSet; 30 import java.util.TreeSet; 31 import java.util.logging.Level; 32 import java.util.logging.Logger; 33 import org.opengrok.indexer.logger.LoggerFactory; 34 35 /** 36 * Collect all information of a given revision. 37 * 38 * @author Trond Norbye 39 */ 40 public class HistoryEntry { 41 42 private static final Logger LOGGER = LoggerFactory.getLogger(HistoryEntry.class); 43 44 private String revision; 45 private Date date; 46 private String author; 47 private String tags; 48 49 @SuppressWarnings("PMD.AvoidStringBufferField") 50 private final StringBuffer message; 51 52 private boolean active; 53 private SortedSet<String> files; 54 55 /** Creates a new instance of HistoryEntry. */ HistoryEntry()56 public HistoryEntry() { 57 message = new StringBuffer(); 58 files = new TreeSet<>(); 59 } 60 61 /** 62 * Copy constructor. 63 * @param that HistoryEntry object 64 */ HistoryEntry(HistoryEntry that)65 public HistoryEntry(HistoryEntry that) { 66 this.revision = that.revision; 67 this.date = that.date; 68 this.author = that.author; 69 this.tags = that.tags; 70 this.message = that.message; 71 this.active = that.active; 72 this.files = that.files; 73 } 74 HistoryEntry(String revision, Date date, String author, String tags, String message, boolean active)75 public HistoryEntry(String revision, Date date, String author, 76 String tags, String message, boolean active) { 77 this.revision = revision; 78 setDate(date); 79 this.author = author; 80 this.tags = tags; 81 this.message = new StringBuffer(message); 82 this.active = active; 83 this.files = new TreeSet<>(); 84 } 85 getLine()86 public String getLine() { 87 return revision + " " + date + " " + author + " " + message + "\n"; 88 } 89 dump()90 public void dump() { 91 92 LOGGER.log(Level.FINE, "HistoryEntry : revision = {0}", revision); 93 LOGGER.log(Level.FINE, "HistoryEntry : tags = {0}", tags); 94 LOGGER.log(Level.FINE, "HistoryEntry : date = {0}", date); 95 LOGGER.log(Level.FINE, "HistoryEntry : author = {0}", author); 96 LOGGER.log(Level.FINE, "HistoryEntry : active = {0}", (active ? 97 "True" : "False")); 98 String[] lines = message.toString().split("\n"); 99 String separator = "="; 100 for (String line : lines) { 101 LOGGER.log(Level.FINE, "HistoryEntry : message {0} {1}", 102 new Object[]{separator, line}); 103 separator = ">"; 104 } 105 separator = "="; 106 for (String file : files) { 107 LOGGER.log(Level.FINE, "HistoryEntry : files {0} {1}", 108 new Object[]{separator, file}); 109 separator = ">"; 110 } 111 } 112 getAuthor()113 public String getAuthor() { 114 return author; 115 } 116 getTags()117 public String getTags() { 118 return tags; 119 } 120 getDate()121 public Date getDate() { 122 return (date == null) ? null : (Date) date.clone(); 123 } 124 getMessage()125 public String getMessage() { 126 return message.toString().trim(); 127 } 128 getRevision()129 public String getRevision() { 130 return revision; 131 } 132 setAuthor(String author)133 public void setAuthor(String author) { 134 this.author = author; 135 } 136 setTags(String tags)137 public void setTags(String tags) { 138 this.tags = tags; 139 } 140 setDate(Date date)141 public final void setDate(Date date) { 142 if (date == null) { 143 this.date = null; 144 } else { 145 this.date = (Date) date.clone(); 146 } 147 } 148 isActive()149 public boolean isActive() { 150 return active; 151 } 152 setActive(boolean active)153 public void setActive(boolean active) { 154 this.active = active; 155 } 156 setMessage(String message)157 public void setMessage(String message) { 158 this.message.setLength(0); 159 this.message.append(message); 160 } 161 setRevision(String revision)162 public void setRevision(String revision) { 163 this.revision = revision; 164 } 165 appendMessage(String message)166 public void appendMessage(String message) { 167 this.message.append(message); 168 this.message.append("\n"); 169 } 170 addFile(String file)171 public void addFile(String file) { 172 files.add(file); 173 } 174 getFiles()175 public SortedSet<String> getFiles() { 176 return files; 177 } 178 setFiles(SortedSet<String> files)179 public void setFiles(SortedSet<String> files) { 180 this.files = files; 181 } 182 183 @Override toString()184 public String toString() { 185 return getLine(); 186 } 187 188 /** 189 * Remove list of files and tags. 190 */ strip()191 public void strip() { 192 stripFiles(); 193 stripTags(); 194 } 195 196 /** 197 * Remove list of files. 198 */ stripFiles()199 public void stripFiles() { 200 files.clear(); 201 } 202 203 /** 204 * Remove tags. 205 */ stripTags()206 public void stripTags() { 207 tags = null; 208 } 209 } 210