| 1 | |
package net.sf.statcvs.pages; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.Calendar; |
| 5 | |
import java.util.Collection; |
| 6 | |
import java.util.Collections; |
| 7 | |
import java.util.Date; |
| 8 | |
import java.util.GregorianCalendar; |
| 9 | |
import java.util.HashSet; |
| 10 | |
import java.util.Iterator; |
| 11 | |
import java.util.List; |
| 12 | |
import java.util.Set; |
| 13 | |
|
| 14 | |
import net.sf.statcvs.model.Commit; |
| 15 | |
import net.sf.statcvs.model.SymbolicName; |
| 16 | |
import net.sf.statcvs.output.ReportConfig; |
| 17 | |
|
| 18 | |
public class LogPageMaker { |
| 19 | 0 | private final static String[] MONTH_TWO_CHARACTERS = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" }; |
| 20 | 0 | private final static String[] MONTH_NAME = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", |
| 21 | |
"December" }; |
| 22 | |
|
| 23 | |
public static String getAnchor(final SymbolicName tag) { |
| 24 | 0 | return "tag-" + tag.getName().replace('.', '_'); |
| 25 | |
} |
| 26 | |
|
| 27 | |
public static String getURL(final Date date) { |
| 28 | 0 | final Calendar calendar = new GregorianCalendar(); |
| 29 | 0 | calendar.setTime(date); |
| 30 | 0 | return getFileName(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)) + ".html"; |
| 31 | |
} |
| 32 | |
|
| 33 | |
private static String getFileName(final int year, final int month) { |
| 34 | 0 | return year + "-" + MONTH_TWO_CHARACTERS[month]; |
| 35 | |
} |
| 36 | |
|
| 37 | |
private final ReportConfig config; |
| 38 | |
private final int year; |
| 39 | |
private final int month; |
| 40 | 0 | private final boolean firstLogPage; |
| 41 | 0 | private final List commits = new ArrayList(); |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | 0 | |
| 51 | 0 | public LogPageMaker(final ReportConfig config, final int year, final int month, final Collection commits, final boolean firstLogPage) { |
| 52 | 0 | this.config = config; |
| 53 | 0 | this.year = year; |
| 54 | 0 | this.month = month; |
| 55 | 0 | this.firstLogPage = firstLogPage; |
| 56 | 0 | final Calendar calendar = new GregorianCalendar(); |
| 57 | 0 | final Iterator it = commits.iterator(); |
| 58 | 0 | while (it.hasNext()) { |
| 59 | 0 | final Commit commit = (Commit) it.next(); |
| 60 | 0 | calendar.setTime(commit.getDate()); |
| 61 | 0 | if (calendar.get(Calendar.YEAR) != year || calendar.get(Calendar.MONTH) != month) { |
| 62 | 0 | continue; |
| 63 | 0 | } |
| 64 | 0 | this.commits.add(commit); |
| 65 | 0 | } |
| 66 | 0 | } |
| 67 | 0 | |
| 68 | 0 | public NavigationNode toFile() { |
| 69 | 0 | final Page result = this.config.createPage(getFileName(), getTitle(), getTitle() + " Commit Log"); |
| 70 | 0 | result.addAttribute("Number of Commits", this.commits.size()); |
| 71 | 0 | result.addAttribute("Number of Active Developers", countActiveDevelopers()); |
| 72 | 0 | if (!this.commits.isEmpty()) { |
| 73 | 0 | result.addRawContent(new CommitListFormatter(this.config, this.commits, getTags(), true).render()); |
| 74 | |
} |
| 75 | 0 | return result; |
| 76 | |
} |
| 77 | 0 | |
| 78 | |
private String getFileName() { |
| 79 | 0 | if (!firstLogPage) { |
| 80 | 0 | return getFileName(this.year, this.month); |
| 81 | 0 | } |
| 82 | 0 | return "commitlog"; |
| 83 | |
} |
| 84 | |
|
| 85 | 0 | private String getTitle() { |
| 86 | 0 | return MONTH_NAME[this.month] + " " + year; |
| 87 | 0 | } |
| 88 | 0 | |
| 89 | 0 | private int countActiveDevelopers() { |
| 90 | 0 | final Set developers = new HashSet(); |
| 91 | 0 | final Iterator it = this.commits.iterator(); |
| 92 | 0 | while (it.hasNext()) { |
| 93 | 0 | final Commit commit = (Commit) it.next(); |
| 94 | 0 | developers.add(commit.getAuthor()); |
| 95 | 0 | } |
| 96 | 0 | return developers.size(); |
| 97 | 0 | } |
| 98 | 0 | |
| 99 | 0 | private List getTags() { |
| 100 | 0 | final List tags = new ArrayList(); |
| 101 | 0 | final Calendar calendar = new GregorianCalendar(); |
| 102 | 0 | final Iterator it = this.config.getRepository().getSymbolicNames().iterator(); |
| 103 | 0 | while (it.hasNext()) { |
| 104 | 0 | final SymbolicName tag = (SymbolicName) it.next(); |
| 105 | 0 | calendar.setTime(tag.getDate()); |
| 106 | 0 | if (calendar.get(Calendar.YEAR) == this.year && calendar.get(Calendar.MONTH) == this.month) { |
| 107 | 0 | tags.add(tag); |
| 108 | |
} |
| 109 | 0 | } |
| 110 | 0 | Collections.reverse(tags); |
| 111 | 0 | return tags; |
| 112 | |
} |
| 113 | |
} |