| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
package net.sf.statsvn; |
| 7 | |
|
| 8 | |
import java.text.SimpleDateFormat; |
| 9 | |
import java.util.HashSet; |
| 10 | |
import java.util.Iterator; |
| 11 | |
import java.util.Set; |
| 12 | |
import java.util.SortedSet; |
| 13 | |
|
| 14 | |
import net.sf.statcvs.model.Repository; |
| 15 | |
import net.sf.statcvs.model.Revision; |
| 16 | |
import net.sf.statcvs.model.SymbolicName; |
| 17 | |
import net.sf.statcvs.model.VersionedFile; |
| 18 | |
import net.sf.statsvn.output.SvnConfigurationOptions; |
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
public class RepoDump { |
| 26 | |
private static final int WIDTH_FOR_NUMBER = 5; |
| 27 | |
|
| 28 | 0 | private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| 29 | |
|
| 30 | |
private final Repository repository; |
| 31 | |
|
| 32 | |
private int totalDelta; |
| 33 | |
|
| 34 | |
private int totalLastRev; |
| 35 | |
|
| 36 | |
private int totalNumRevision; |
| 37 | |
|
| 38 | |
private int totalMisMatch; |
| 39 | |
|
| 40 | |
private int numberMisMatch; |
| 41 | |
|
| 42 | |
private int totalCurrentLOCPerFile; |
| 43 | |
|
| 44 | 0 | public RepoDump(final Repository repo) { |
| 45 | 0 | repository = repo; |
| 46 | 0 | } |
| 47 | |
|
| 48 | |
public void dump() { |
| 49 | 0 | final SortedSet revisions = repository.getRevisions(); |
| 50 | 0 | final Set filesViaRevisions = dumpPerRevision(revisions); |
| 51 | |
|
| 52 | 0 | SvnConfigurationOptions.getTaskLogger().info("\n\n#### DUMP PER FILE ####"); |
| 53 | |
|
| 54 | 0 | final SortedSet files = repository.getFiles(); |
| 55 | 0 | dumpPerFile(files); |
| 56 | 0 | dumpPerTags(); |
| 57 | |
|
| 58 | 0 | SvnConfigurationOptions.getTaskLogger().info("----------------------------------"); |
| 59 | 0 | SvnConfigurationOptions.getTaskLogger().info("Current Repo Line Code :" + repository.getCurrentLOC()); |
| 60 | 0 | SvnConfigurationOptions.getTaskLogger().info("-----Via Files--------------------"); |
| 61 | 0 | SvnConfigurationOptions.getTaskLogger().info("Number of Files via Files :" + files.size()); |
| 62 | 0 | SvnConfigurationOptions.getTaskLogger().info( |
| 63 | |
"Sum Current LOC via File :" + totalCurrentLOCPerFile + "\tDiff with Repo LOC " + (repository.getCurrentLOC() - totalCurrentLOCPerFile) + " " |
| 64 | |
+ (repository.getCurrentLOC() - totalCurrentLOCPerFile == 0 ? "OK" : "NOT Ok")); |
| 65 | 0 | SvnConfigurationOptions.getTaskLogger().info("# of File Revision via File:" + totalNumRevision); |
| 66 | 0 | SvnConfigurationOptions.getTaskLogger().info("-----Via Revisions----------------"); |
| 67 | 0 | SvnConfigurationOptions.getTaskLogger().info( |
| 68 | |
"# of Files via Revisions :" + padIntRight(filesViaRevisions.size(), WIDTH_FOR_NUMBER) + "\tDiff with via Files:" |
| 69 | |
+ (files.size() - filesViaRevisions.size()) + (files.size() - filesViaRevisions.size() == 0 ? " OK" : "NOT Ok")); |
| 70 | 0 | SvnConfigurationOptions.getTaskLogger().info( |
| 71 | |
"# of File Revision via Revi:" + padIntRight(revisions.size(), WIDTH_FOR_NUMBER) + "\tDiff with via Files:" |
| 72 | |
+ (totalNumRevision - revisions.size()) + (totalNumRevision - revisions.size() == 0 ? " OK" : "NOT Ok")); |
| 73 | 0 | SvnConfigurationOptions.getTaskLogger().info( |
| 74 | |
"Sum Delta via Revisions :" + padIntRight(totalDelta, WIDTH_FOR_NUMBER) + "\tDiff with Repo LOC " |
| 75 | |
+ (repository.getCurrentLOC() - totalDelta) + " " + (repository.getCurrentLOC() - totalDelta == 0 ? "OK" : "NOT Ok")); |
| 76 | 0 | if (numberMisMatch > 0) { |
| 77 | 0 | SvnConfigurationOptions.getTaskLogger().info("**** PROBLEM ******"); |
| 78 | 0 | SvnConfigurationOptions.getTaskLogger().info( |
| 79 | |
"Number of Mismatches :" + padIntRight(numberMisMatch, WIDTH_FOR_NUMBER) + "\tLOC Mismatch:" + totalMisMatch); |
| 80 | |
} |
| 81 | 0 | SvnConfigurationOptions.getTaskLogger().info( |
| 82 | |
"Tot LOC via Last Rev file :" + padIntRight(totalLastRev, WIDTH_FOR_NUMBER) + "\tDiff with Repo LOC " |
| 83 | |
+ (repository.getCurrentLOC() - totalLastRev) + (repository.getCurrentLOC() - totalDelta == 0 ? " OK" : " NOT Ok")); |
| 84 | 0 | SvnConfigurationOptions.getTaskLogger().info("----------------------------------"); |
| 85 | 0 | } |
| 86 | |
|
| 87 | |
private void dumpPerTags() { |
| 88 | 0 | if (repository.getSymbolicNames() != null) { |
| 89 | 0 | SvnConfigurationOptions.getTaskLogger().info("\n\n#### DUMP PER TAG ####"); |
| 90 | 0 | for (final Iterator it = repository.getSymbolicNames().iterator(); it.hasNext();) { |
| 91 | 0 | final SymbolicName symbol = (SymbolicName) it.next(); |
| 92 | 0 | SvnConfigurationOptions.getTaskLogger().info("\nTAG: " + symbol.getName() + " / " + symbol.getDate()); |
| 93 | 0 | int loc = 0; |
| 94 | 0 | for (final Iterator rev = symbol.getRevisions().iterator(); rev.hasNext();) { |
| 95 | 0 | final Revision revision = (Revision) rev.next(); |
| 96 | 0 | SvnConfigurationOptions.getTaskLogger().info( |
| 97 | |
" LOC:" + padIntRight(revision.getLines(), WIDTH_FOR_NUMBER) + " Rev:" + padRight(revision.getRevisionNumber(), WIDTH_FOR_NUMBER) |
| 98 | |
+ " File: " + revision.getFile().getFilenameWithPath() + " dead:" + revision.isDead()); |
| 99 | 0 | loc += revision.getLines(); |
| 100 | 0 | } |
| 101 | 0 | SvnConfigurationOptions.getTaskLogger().info("Total LOC: " + loc); |
| 102 | 0 | } |
| 103 | |
} |
| 104 | 0 | } |
| 105 | |
|
| 106 | |
private void dumpPerFile(final SortedSet files) { |
| 107 | 0 | totalCurrentLOCPerFile = 0; |
| 108 | 0 | totalNumRevision = 0; |
| 109 | 0 | int fileNumber = 0; |
| 110 | 0 | totalMisMatch = 0; |
| 111 | 0 | numberMisMatch = 0; |
| 112 | 0 | for (final Iterator it = files.iterator(); it.hasNext();) { |
| 113 | 0 | final VersionedFile rev = (VersionedFile) it.next(); |
| 114 | 0 | totalCurrentLOCPerFile += rev.getCurrentLinesOfCode(); |
| 115 | 0 | totalNumRevision += rev.getRevisions().size(); |
| 116 | 0 | SvnConfigurationOptions.getTaskLogger().info("File " + ++fileNumber + "/ " + rev.getFilenameWithPath() + " \tLOC:" + rev.getCurrentLinesOfCode()); |
| 117 | 0 | int sumDelta = 0; |
| 118 | |
|
| 119 | 0 | for (final Iterator it2 = rev.getRevisions().iterator(); it2.hasNext();) { |
| 120 | 0 | final Revision revi = (Revision) it2.next(); |
| 121 | |
|
| 122 | 0 | sumDelta += revi.getLinesDelta(); |
| 123 | 0 | if (revi.isBeginOfLog()) { |
| 124 | 0 | sumDelta += revi.getLines(); |
| 125 | |
} |
| 126 | 0 | SvnConfigurationOptions.getTaskLogger() |
| 127 | |
.info( |
| 128 | |
"\tRevision:" + padRight(revi.getRevisionNumber(), WIDTH_FOR_NUMBER) + " \tDelta:" |
| 129 | |
+ padIntRight(revi.getLinesDelta(), WIDTH_FOR_NUMBER) + "\tLines:" + padIntRight(revi.getLines(), WIDTH_FOR_NUMBER) |
| 130 | |
+ "\t" + printBoolean("Ini:", revi.isInitialRevision()) + "\t" + printBoolean("BegLog", revi.isBeginOfLog()) + "\t" |
| 131 | |
+ printBoolean("Dead", revi.isDead()) + "\tSumDelta:" + padIntRight(sumDelta, WIDTH_FOR_NUMBER) + " " |
| 132 | |
+ revi.getSymbolicNames()); |
| 133 | 0 | } |
| 134 | 0 | if (sumDelta != rev.getCurrentLinesOfCode()) { |
| 135 | 0 | SvnConfigurationOptions.getTaskLogger().info( |
| 136 | |
"\t~~~~~SUM DELTA DOES NOT MATCH LOC " + rev.getCurrentLinesOfCode() + " vs " + sumDelta + " Diff:" |
| 137 | |
+ (rev.getCurrentLinesOfCode() - sumDelta) + " ~~~~~~"); |
| 138 | 0 | totalMisMatch += (rev.getCurrentLinesOfCode() - sumDelta); |
| 139 | 0 | numberMisMatch++; |
| 140 | |
} |
| 141 | 0 | } |
| 142 | 0 | } |
| 143 | |
|
| 144 | |
private Set dumpPerRevision(final SortedSet revisions) { |
| 145 | 0 | totalDelta = 0; |
| 146 | 0 | final Set filesViaRevisions = new HashSet(); |
| 147 | 0 | totalLastRev = 0; |
| 148 | 0 | SvnConfigurationOptions.getTaskLogger().info("\n\n#### DUMP PER REVISION ####"); |
| 149 | 0 | String previousRevision = ""; |
| 150 | 0 | int revTotal = -1; |
| 151 | 0 | for (final Iterator it = revisions.iterator(); it.hasNext();) { |
| 152 | 0 | final Revision rev = (Revision) it.next(); |
| 153 | 0 | if (!rev.getRevisionNumber().equals(previousRevision)) { |
| 154 | 0 | previousRevision = rev.getRevisionNumber(); |
| 155 | 0 | if (revTotal != -1) { |
| 156 | 0 | SvnConfigurationOptions.getTaskLogger().info("Total for this rev: " + totalDelta); |
| 157 | |
} |
| 158 | 0 | SvnConfigurationOptions.getTaskLogger().info( |
| 159 | |
"Revision " + padRight(rev.getRevisionNumber(), WIDTH_FOR_NUMBER) + " " + SDF.format(rev.getDate())); |
| 160 | |
} |
| 161 | 0 | SvnConfigurationOptions.getTaskLogger().info( |
| 162 | |
"\tlines:" + padIntRight(rev.getLines(), WIDTH_FOR_NUMBER) + " D:" + padIntRight(rev.getLinesDelta(), WIDTH_FOR_NUMBER) + " Rep:" |
| 163 | |
+ padIntRight(rev.getReplacedLines(), WIDTH_FOR_NUMBER) + " New:" + padIntRight(rev.getNewLines(), WIDTH_FOR_NUMBER) |
| 164 | |
+ printBoolean(" Initial", rev.isInitialRevision()) + printBoolean(" BegLog", rev.isBeginOfLog()) |
| 165 | |
+ printBoolean(" Dead", rev.isDead()) + " " + rev.getFile().getFilenameWithPath() + " tags:" + rev.getSymbolicNames()); |
| 166 | |
|
| 167 | 0 | totalDelta += rev.getLinesDelta(); |
| 168 | 0 | if (rev.isBeginOfLog()) { |
| 169 | 0 | totalDelta += rev.getLines(); |
| 170 | |
} |
| 171 | 0 | revTotal = totalDelta; |
| 172 | 0 | final VersionedFile file = rev.getFile(); |
| 173 | 0 | final Revision fileRev = file.getLatestRevision(); |
| 174 | 0 | if (!fileRev.isDead() |
| 175 | |
|
| 176 | |
|
| 177 | |
&& !filesViaRevisions.contains(file.getFilenameWithPath())) { |
| 178 | 0 | totalLastRev += file.getCurrentLinesOfCode(); |
| 179 | |
} |
| 180 | 0 | filesViaRevisions.add(file.getFilenameWithPath()); |
| 181 | 0 | } |
| 182 | 0 | SvnConfigurationOptions.getTaskLogger().info("Total for this rev: " + totalDelta); |
| 183 | 0 | return filesViaRevisions; |
| 184 | |
} |
| 185 | |
|
| 186 | |
private String padIntRight(final int str, final int size) { |
| 187 | 0 | return padRight(String.valueOf(str), size); |
| 188 | |
} |
| 189 | |
|
| 190 | |
private String printBoolean(final String title, final boolean test) { |
| 191 | 0 | return title + ":" + (test ? "Y" : "N"); |
| 192 | |
} |
| 193 | |
|
| 194 | |
private String padRight(final String str, final int size) { |
| 195 | 0 | final StringBuffer buf = new StringBuffer(str); |
| 196 | 0 | int requiredPadding = size; |
| 197 | 0 | if (str != null) { |
| 198 | 0 | requiredPadding = requiredPadding - str.length(); |
| 199 | |
} |
| 200 | 0 | if (requiredPadding > 0) { |
| 201 | 0 | for (int i = 0; i < requiredPadding; i++) { |
| 202 | 0 | buf.append(" "); |
| 203 | |
} |
| 204 | |
} |
| 205 | 0 | return buf.toString(); |
| 206 | |
} |
| 207 | |
} |