| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
package net.sf.statcvs.model; |
| 21 | |
|
| 22 | |
import java.util.Date; |
| 23 | |
import java.util.Iterator; |
| 24 | |
import java.util.List; |
| 25 | |
import java.util.SortedMap; |
| 26 | |
import java.util.SortedSet; |
| 27 | |
import java.util.TreeMap; |
| 28 | |
import java.util.TreeSet; |
| 29 | |
|
| 30 | |
import net.sf.statcvs.Messages; |
| 31 | |
import net.sf.statcvs.util.FilePatternMatcher; |
| 32 | |
import net.sf.statcvs.util.ModuleUtil; |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | 200 | |
| 42 | 200 | |
| 43 | 200 | |
| 44 | 200 | |
| 45 | 200 | |
| 46 | 200 | |
| 47 | 200 | public class Repository { |
| 48 | 0 | private final SortedSet files = new TreeSet(); |
| 49 | 200 | private final SortedSet authors = new TreeSet(); |
| 50 | 200 | private final SortedSet revisions = new TreeSet(); |
| 51 | 0 | private final SortedMap modules = new TreeMap(); |
| 52 | 0 | private Directory root = null; |
| 53 | 0 | private Date firstDate = null; |
| 54 | 0 | private Date lastDate = null; |
| 55 | |
private List commits; |
| 56 | 0 | private SortedSet symbolicNames = new TreeSet(); |
| 57 | 296 | private final SymbolicName head = new SymbolicName("@"); |
| 58 | 296 | |
| 59 | 840 | |
| 60 | 544 | |
| 61 | 544 | |
| 62 | 544 | |
| 63 | 504 | public void addFile(final VersionedFile file) { |
| 64 | 0 | files.add(file); |
| 65 | 544 | final Iterator it = file.getRevisions().iterator(); |
| 66 | 476 | while (it.hasNext()) { |
| 67 | 296 | final Revision revision = (Revision) it.next(); |
| 68 | 176 | revisions.add(revision); |
| 69 | 0 | if (revision.getAuthor() != null) { |
| 70 | 296 | authors.add(revision.getAuthor()); |
| 71 | 272 | } |
| 72 | 0 | adjustStartAndEndDate(revision.getDate()); |
| 73 | 296 | } |
| 74 | 0 | if (root == null) { |
| 75 | 0 | initRoot(); |
| 76 | |
} |
| 77 | 0 | if (!file.isDead()) { |
| 78 | 0 | this.head.addRevision(file.getLatestRevision()); |
| 79 | |
} |
| 80 | |
|
| 81 | 0 | if (ModuleUtil.modulesPresent()) { |
| 82 | 0 | addToModule(file); |
| 83 | 168 | } |
| 84 | 168 | } |
| 85 | |
|
| 86 | |
private void addToModule(final VersionedFile file) { |
| 87 | 0 | final List moduleIds = ModuleUtil.getConfigModules(); |
| 88 | 0 | final Iterator mod = moduleIds.iterator(); |
| 89 | 0 | String modName = null; |
| 90 | 0 | while (mod.hasNext() && modName == null) { |
| 91 | 0 | final String moduleId = (String) mod.next(); |
| 92 | 0 | final String pattern = ModuleUtil.getConfigModuleRegexp(moduleId); |
| 93 | 0 | final String name = ModuleUtil.getConfigModuleName(moduleId); |
| 94 | |
|
| 95 | 0 | final FilePatternMatcher fpm = new FilePatternMatcher(pattern); |
| 96 | |
|
| 97 | 0 | if (fpm.matches(file.getFilenameWithPath())) { |
| 98 | 0 | modName = name; |
| 99 | |
} |
| 100 | |
} |
| 101 | |
|
| 102 | 0 | if (modName == null) { |
| 103 | 0 | modName = Messages.getString("PIE_MODSIZE_OTHER"); |
| 104 | |
} |
| 105 | |
|
| 106 | 0 | Module module = (Module) modules.get(modName); |
| 107 | 0 | if (module == null) { |
| 108 | 0 | module = new Module(modName); |
| 109 | 0 | modules.put(modName, module); |
| 110 | |
} |
| 111 | 0 | module.addFile(file); |
| 112 | 0 | file.setModule(module); |
| 113 | 0 | } |
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | 0 | |
| 121 | 0 | |
| 122 | 0 | public void setCommits(final List commits) { |
| 123 | 0 | this.commits = commits; |
| 124 | 0 | } |
| 125 | 0 | |
| 126 | 0 | |
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
public List getCommits() { |
| 132 | 0 | return commits; |
| 133 | |
} |
| 134 | 184 | |
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
public Date getLastDate() { |
| 142 | 16 | return lastDate; |
| 143 | |
} |
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
public Date getFirstDate() { |
| 152 | 168 | return firstDate; |
| 153 | |
} |
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
public int getCurrentLOC() { |
| 160 | 0 | int result = 0; |
| 161 | 8 | final Iterator it = files.iterator(); |
| 162 | 0 | while (it.hasNext()) { |
| 163 | 0 | final VersionedFile file = (VersionedFile) it.next(); |
| 164 | 0 | result += file.getCurrentLinesOfCode(); |
| 165 | |
} |
| 166 | 0 | return result; |
| 167 | |
} |
| 168 | |
|
| 169 | |
|
| 170 | 16 | |
| 171 | |
|
| 172 | |
|
| 173 | |
public SortedSet getFiles() { |
| 174 | 0 | return files; |
| 175 | |
} |
| 176 | |
|
| 177 | |
|
| 178 | 168 | |
| 179 | 168 | |
| 180 | |
|
| 181 | |
public boolean isEmpty() { |
| 182 | 0 | return (files.isEmpty()); |
| 183 | |
} |
| 184 | |
|
| 185 | |
|
| 186 | 0 | |
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
public SortedSet getRevisions() { |
| 192 | 0 | return revisions; |
| 193 | 0 | } |
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | 0 | public SortedSet getDirectories() { |
| 201 | 0 | return getRoot().getSubdirectoriesRecursive(); |
| 202 | 0 | } |
| 203 | 0 | |
| 204 | 0 | |
| 205 | 0 | |
| 206 | |
|
| 207 | 0 | |
| 208 | |
|
| 209 | |
public Directory getRoot() { |
| 210 | 0 | return root; |
| 211 | |
} |
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | 16 | |
| 217 | |
public void setSymbolicNames(final SortedSet symbolicNames) { |
| 218 | 0 | this.symbolicNames = symbolicNames; |
| 219 | 0 | } |
| 220 | 176 | |
| 221 | 0 | |
| 222 | |
|
| 223 | 176 | |
| 224 | 176 | |
| 225 | 216 | public SortedSet getSymbolicNames() { |
| 226 | 40 | return symbolicNames; |
| 227 | |
} |
| 228 | 176 | |
| 229 | 176 | |
| 230 | |
|
| 231 | |
|
| 232 | 544 | public SymbolicName getHead() { |
| 233 | 0 | return this.head; |
| 234 | |
} |
| 235 | 544 | |
| 236 | 192 | |
| 237 | |
|
| 238 | 544 | |
| 239 | 336 | public String toString() { |
| 240 | 0 | final StringBuffer result = new StringBuffer(); |
| 241 | 544 | final Iterator it = files.iterator(); |
| 242 | 0 | VersionedFile cf = null; |
| 243 | 0 | while (it.hasNext()) { |
| 244 | 0 | cf = (VersionedFile) it.next(); |
| 245 | 0 | result.append(cf.toString()).append("\n"); |
| 246 | |
} |
| 247 | 0 | return result.toString(); |
| 248 | |
} |
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | |
public SortedSet getAuthors() { |
| 256 | 0 | return authors; |
| 257 | |
} |
| 258 | |
|
| 259 | |
private void initRoot() { |
| 260 | 0 | if (files.isEmpty()) { |
| 261 | 0 | return; |
| 262 | |
} |
| 263 | 0 | final VersionedFile file = (VersionedFile) files.first(); |
| 264 | 0 | Directory dir = file.getDirectory(); |
| 265 | 0 | while (!dir.isRoot()) { |
| 266 | 0 | dir = dir.getParent(); |
| 267 | |
} |
| 268 | 0 | root = dir; |
| 269 | 0 | } |
| 270 | |
|
| 271 | |
private void adjustStartAndEndDate(final Date revisionDate) { |
| 272 | 0 | if (revisionDate == null) { |
| 273 | 0 | return; |
| 274 | |
} |
| 275 | 0 | if (firstDate == null || firstDate.compareTo(revisionDate) > 0) { |
| 276 | 0 | firstDate = revisionDate; |
| 277 | |
} |
| 278 | 0 | if (lastDate == null || lastDate.compareTo(revisionDate) < 0) { |
| 279 | 0 | lastDate = revisionDate; |
| 280 | |
} |
| 281 | 0 | } |
| 282 | |
|
| 283 | |
public SortedMap getModules() { |
| 284 | 0 | return modules; |
| 285 | |
} |
| 286 | |
} |