| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
package net.sf.statcvs.input; |
| 24 | |
|
| 25 | |
import java.io.IOException; |
| 26 | |
import java.util.ArrayList; |
| 27 | |
import java.util.Date; |
| 28 | |
import java.util.HashMap; |
| 29 | |
import java.util.HashSet; |
| 30 | |
import java.util.Iterator; |
| 31 | |
import java.util.List; |
| 32 | |
import java.util.Map; |
| 33 | |
import java.util.Properties; |
| 34 | |
import java.util.Set; |
| 35 | |
import java.util.SortedSet; |
| 36 | |
import java.util.TreeSet; |
| 37 | |
import java.util.logging.Logger; |
| 38 | |
import java.util.regex.Pattern; |
| 39 | |
|
| 40 | |
import net.sf.statcvs.model.Author; |
| 41 | |
import net.sf.statcvs.model.Directory; |
| 42 | |
import net.sf.statcvs.model.Repository; |
| 43 | |
import net.sf.statcvs.model.SymbolicName; |
| 44 | |
import net.sf.statcvs.model.VersionedFile; |
| 45 | |
import net.sf.statcvs.output.ConfigurationOptions; |
| 46 | |
import net.sf.statcvs.util.FilePatternMatcher; |
| 47 | |
import net.sf.statcvs.util.FileUtils; |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
public class Builder implements CvsLogBuilder { |
| 63 | 32 | private static Logger logger = Logger.getLogger(Builder.class.getName()); |
| 64 | |
|
| 65 | |
private final RepositoryFileManager repositoryFileManager; |
| 66 | |
private final FilePatternMatcher includePattern; |
| 67 | |
private final FilePatternMatcher excludePattern; |
| 68 | |
private final Pattern tagsPattern; |
| 69 | |
|
| 70 | 156 | private final Map authors = new HashMap(); |
| 71 | 156 | private final Map directories = new HashMap(); |
| 72 | 156 | private final Map symbolicNames = new HashMap(); |
| 73 | |
|
| 74 | 156 | private final List fileBuilders = new ArrayList(); |
| 75 | 156 | private final Set atticFileNames = new HashSet(); |
| 76 | |
|
| 77 | 156 | private FileBuilder currentFileBuilder = null; |
| 78 | 156 | private Date startDate = null; |
| 79 | 156 | private String projectName = null; |
| 80 | |
|
| 81 | 156 | private int countRejectedByExclude = 0; |
| 82 | 156 | private int countAcceptedByExclude = 0; |
| 83 | 156 | private int countRejectedByInclude = 0; |
| 84 | 156 | private int countAcceptedByInclude = 0; |
| 85 | 156 | private boolean flagOutOfSync = false; |
| 86 | 156 | private boolean flagHasLocalCVSMetadata = false; |
| 87 | 156 | private int countFoundLocalFiles = 0; |
| 88 | 156 | private int countNotFoundLocalFiles = 0; |
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
public Builder(final RepositoryFileManager repositoryFileManager, final FilePatternMatcher includePattern, final FilePatternMatcher excludePattern, |
| 102 | 156 | final Pattern tagsPattern) { |
| 103 | 156 | this.repositoryFileManager = repositoryFileManager; |
| 104 | 156 | this.includePattern = includePattern; |
| 105 | 156 | this.excludePattern = excludePattern; |
| 106 | 156 | this.tagsPattern = tagsPattern; |
| 107 | 156 | directories.put("", Directory.createRoot()); |
| 108 | 156 | } |
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
public void buildModule(final String moduleName) { |
| 116 | 60 | this.projectName = moduleName; |
| 117 | 60 | } |
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
public void buildFile(final String filename, final boolean isBinary, final boolean isInAttic, final Map revBySymnames) { |
| 128 | 124 | if (currentFileBuilder != null) { |
| 129 | 40 | fileBuilders.add(currentFileBuilder); |
| 130 | |
} |
| 131 | 124 | currentFileBuilder = new FileBuilder(this, filename, isBinary, revBySymnames); |
| 132 | 124 | if (isInAttic) { |
| 133 | 12 | atticFileNames.add(filename); |
| 134 | |
} |
| 135 | 124 | } |
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
public void buildRevision(final RevisionData data) { |
| 144 | 156 | currentFileBuilder.addRevisionData(data); |
| 145 | 156 | if (startDate == null || startDate.compareTo(data.getDate()) > 0) { |
| 146 | 144 | startDate = data.getDate(); |
| 147 | |
} |
| 148 | 156 | } |
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
public Repository createCvsContent() { |
| 156 | 84 | if (currentFileBuilder != null) { |
| 157 | 76 | fileBuilders.add(currentFileBuilder); |
| 158 | 76 | currentFileBuilder = null; |
| 159 | |
} |
| 160 | |
|
| 161 | 84 | final Repository result = new Repository(); |
| 162 | 84 | final Iterator it = fileBuilders.iterator(); |
| 163 | 188 | while (it.hasNext()) { |
| 164 | 104 | final FileBuilder fileBuilder = (FileBuilder) it.next(); |
| 165 | 104 | final VersionedFile file = fileBuilder.createFile(startDate); |
| 166 | 104 | if (file == null) { |
| 167 | 20 | continue; |
| 168 | |
} |
| 169 | 84 | if (fileBuilder.hasUnexpectedLocalRevision()) { |
| 170 | 52 | this.flagOutOfSync = true; |
| 171 | |
} |
| 172 | 84 | if (fileBuilder.hasLocalCVSMetadata()) { |
| 173 | 28 | this.flagHasLocalCVSMetadata = true; |
| 174 | |
} |
| 175 | 84 | if (fileBuilder.hasLocalFileNotFound()) { |
| 176 | 40 | this.countNotFoundLocalFiles++; |
| 177 | 40 | this.flagOutOfSync = true; |
| 178 | 44 | } else if (file.getCurrentLinesOfCode() > 0) { |
| 179 | 20 | this.countFoundLocalFiles++; |
| 180 | |
} |
| 181 | 84 | result.addFile(file); |
| 182 | 84 | logger.finer("adding " + file.getFilenameWithPath() + " (" + file.getRevisions().size() + " revisions)"); |
| 183 | 84 | } |
| 184 | |
|
| 185 | |
|
| 186 | 84 | final SortedSet revisions = result.getRevisions(); |
| 187 | 84 | final List commits = new CommitListBuilder(revisions).createCommitList(); |
| 188 | 84 | result.setCommits(commits); |
| 189 | 84 | result.setSymbolicNames(getMatchingSymbolicNames()); |
| 190 | 84 | return result; |
| 191 | |
} |
| 192 | |
|
| 193 | |
public String getProjectName() { |
| 194 | 4 | return projectName; |
| 195 | |
} |
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
public Set getAtticFileNames() { |
| 202 | 12 | return atticFileNames; |
| 203 | |
} |
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
public boolean allRejectedByExcludePattern() { |
| 209 | 0 | return this.countRejectedByExclude > 0 && this.countAcceptedByExclude == 0; |
| 210 | |
} |
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
public boolean allRejectedByIncludePattern() { |
| 216 | 0 | return this.countRejectedByInclude > 0 && this.countAcceptedByInclude == 0; |
| 217 | |
} |
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
public boolean isLogAndLocalFilesOutOfSync() { |
| 226 | 0 | return this.flagHasLocalCVSMetadata && this.flagOutOfSync; |
| 227 | |
} |
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
public boolean isLocalFilesNotFound() { |
| 235 | 0 | return this.countNotFoundLocalFiles > this.countFoundLocalFiles; |
| 236 | |
} |
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
public boolean hasLocalCVSMetadata() { |
| 245 | 0 | return this.flagHasLocalCVSMetadata; |
| 246 | |
} |
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
public Author getAuthor(final String name) { |
| 255 | 164 | if (this.authors.containsKey(name.toLowerCase())) { |
| 256 | 64 | return (Author) this.authors.get(name.toLowerCase()); |
| 257 | |
} |
| 258 | 100 | final Properties p = ConfigurationOptions.getConfigProperties(); |
| 259 | 100 | final Author newAuthor = new Author(name); |
| 260 | 100 | this.authors.put(name.toLowerCase(), newAuthor); |
| 261 | 100 | if (p != null) { |
| 262 | 100 | newAuthor.setRealName(p.getProperty("user." + name.toLowerCase() + ".realName")); |
| 263 | 100 | newAuthor.setHomePageUrl(p.getProperty("user." + name.toLowerCase() + ".url")); |
| 264 | 100 | newAuthor.setImageUrl(p.getProperty("user." + name.toLowerCase() + ".image")); |
| 265 | 100 | newAuthor.setEmail(p.getProperty("user." + name.toLowerCase() + ".email")); |
| 266 | |
} |
| 267 | 100 | return newAuthor; |
| 268 | |
} |
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
|
| 276 | |
public Directory getDirectory(final String filename) { |
| 277 | 116 | final int lastSlash = filename.lastIndexOf('/'); |
| 278 | 116 | if (lastSlash == -1) { |
| 279 | 92 | return getDirectoryForPath(""); |
| 280 | |
} |
| 281 | 24 | return getDirectoryForPath(filename.substring(0, lastSlash + 1)); |
| 282 | |
} |
| 283 | |
|
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
|
| 291 | |
public SymbolicName getSymbolicName(final String name) { |
| 292 | 0 | SymbolicName sym = (SymbolicName) symbolicNames.get(name); |
| 293 | |
|
| 294 | 0 | if (sym != null) { |
| 295 | 0 | return sym; |
| 296 | |
} else { |
| 297 | 0 | sym = new SymbolicName(name); |
| 298 | 0 | symbolicNames.put(name, sym); |
| 299 | |
|
| 300 | 0 | return sym; |
| 301 | |
} |
| 302 | |
} |
| 303 | |
|
| 304 | |
public int getLOC(final String filename) throws NoLineCountException { |
| 305 | 80 | if (repositoryFileManager == null) { |
| 306 | 24 | throw new NoLineCountException("no RepositoryFileManager"); |
| 307 | |
} |
| 308 | 56 | return repositoryFileManager.getLinesOfCode(filename); |
| 309 | |
} |
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
|
| 314 | |
public String getRevision(final String filename) throws IOException { |
| 315 | 84 | if (repositoryFileManager == null) { |
| 316 | 44 | throw new IOException("no RepositoryFileManager"); |
| 317 | |
} |
| 318 | 40 | return repositoryFileManager.getRevision(filename); |
| 319 | |
} |
| 320 | |
|
| 321 | |
|
| 322 | |
|
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
|
| 327 | |
|
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
public boolean matchesPatterns(final String filename) { |
| 332 | 144 | if (excludePattern != null) { |
| 333 | 12 | if (excludePattern.matches(filename)) { |
| 334 | 8 | this.countRejectedByExclude++; |
| 335 | 8 | return false; |
| 336 | |
} else { |
| 337 | 4 | this.countAcceptedByExclude++; |
| 338 | |
} |
| 339 | |
} |
| 340 | 136 | if (includePattern != null) { |
| 341 | 4 | if (includePattern.matches(filename)) { |
| 342 | 4 | this.countAcceptedByInclude++; |
| 343 | |
} else { |
| 344 | 0 | this.countRejectedByInclude++; |
| 345 | 0 | return false; |
| 346 | |
} |
| 347 | |
} |
| 348 | 136 | return true; |
| 349 | |
} |
| 350 | |
|
| 351 | |
|
| 352 | |
|
| 353 | |
|
| 354 | |
|
| 355 | |
private Directory getDirectoryForPath(final String path) { |
| 356 | 160 | if (directories.containsKey(path)) { |
| 357 | 116 | return (Directory) directories.get(path); |
| 358 | |
} |
| 359 | 44 | final Directory parent = getDirectoryForPath(FileUtils.getParentDirectoryPath(path)); |
| 360 | 44 | final Directory newDirectory = parent.createSubdirectory(FileUtils.getDirectoryName(path)); |
| 361 | 44 | directories.put(path, newDirectory); |
| 362 | 44 | return newDirectory; |
| 363 | |
} |
| 364 | |
|
| 365 | |
private SortedSet getMatchingSymbolicNames() { |
| 366 | 84 | final TreeSet result = new TreeSet(); |
| 367 | 84 | if (this.tagsPattern == null) { |
| 368 | 84 | return result; |
| 369 | |
} |
| 370 | 0 | for (final Iterator it = this.symbolicNames.values().iterator(); it.hasNext();) { |
| 371 | 0 | final SymbolicName sn = (SymbolicName) it.next(); |
| 372 | 0 | if (sn.getDate() != null && this.tagsPattern.matcher(sn.getName()).matches()) { |
| 373 | 0 | result.add(sn); |
| 374 | |
} |
| 375 | 0 | } |
| 376 | 0 | return result; |
| 377 | |
} |
| 378 | |
} |