Coverage Report - net.sf.statcvs.pages.DeveloperPageMaker
 
Classes in this File Line Coverage Branch Coverage Complexity
DeveloperPageMaker
0%
0/125
0%
0/98
2.857
 
 1  
 package net.sf.statcvs.pages;
 2  
 
 3  
 import java.text.NumberFormat;
 4  
 import java.util.ArrayList;
 5  
 import java.util.Collection;
 6  
 import java.util.Collections;
 7  
 import java.util.Iterator;
 8  
 import java.util.List;
 9  
 
 10  
 import net.sf.statcvs.Messages;
 11  
 import net.sf.statcvs.charts.ChartImage;
 12  
 import net.sf.statcvs.charts.DirectoryPieChartMaker.CodeDistributionChartMaker;
 13  
 import net.sf.statcvs.charts.TimeBarChartMaker.HourBarChartMaker;
 14  
 import net.sf.statcvs.charts.TimeBarChartMaker.WeekdayBarChartMaker;
 15  
 import net.sf.statcvs.model.Author;
 16  
 import net.sf.statcvs.model.Commit;
 17  
 import net.sf.statcvs.model.Repository;
 18  
 import net.sf.statcvs.model.Revision;
 19  
 import net.sf.statcvs.output.ConfigurationOptions;
 20  
 import net.sf.statcvs.output.ReportConfig;
 21  
 import net.sf.statcvs.reports.DirectoriesForAuthorTableReport;
 22  
 import net.sf.statcvs.util.StringUtils;
 23  
 
 24  
 /**
 25  
  * @author anja
 26  
  * @author Richard Cyganiak (richard@cyganiak.de)
 27  
  * @version $Id: DeveloperPageMaker.java,v 1.18 2009/08/20 08:57:00 benoitx Exp $
 28  
  */
 29  0
 public class DeveloperPageMaker {
 30  0
     private final static int RECENT_COMMITS_LENGTH = 20;
 31  0
     private final static NumberFormat PERCENT_FORMAT = NumberFormat.getPercentInstance();
 32  0
 
 33  0
     static {
 34  0
         PERCENT_FORMAT.setMinimumFractionDigits(1);
 35  0
         PERCENT_FORMAT.setMaximumFractionDigits(1);
 36  0
     }
 37  0
 
 38  0
     public static String getURL(final Author developer) {
 39  0
         return getFilename(developer) + ".html";
 40  
     }
 41  0
 
 42  0
     private static String getFilename(final Author developer) {
 43  0
         return "user_" + HTML.escapeAuthorName(developer.getName());
 44  
     }
 45  
 
 46  
     private final ReportConfig config;
 47  
     private final Author developer;
 48  0
     private final Repository repository;
 49  0
 
 50  0
     public DeveloperPageMaker(final ReportConfig config, final Author developer) {
 51  0
         this.config = config;
 52  0
         this.developer = developer;
 53  0
         this.repository = config.getRepository();
 54  0
     }
 55  0
 
 56  0
     public Page toFile() {
 57  0
         final ChartImage hourChart = new HourBarChartMaker("activity_time", this.config, this.developer.getRevisions(), Messages
 58  
                 .getString("ACTIVITY_TIME_FOR_AUTHOR_TITLE")
 59  0
                 + " " + this.developer.getRealName(), "activity_time_" + HTML.escapeAuthorName(this.developer.getName()) + ".png").toFile();
 60  0
         final ChartImage weekdayChart = new WeekdayBarChartMaker("activity_day", this.config, this.developer.getRevisions(), Messages
 61  
                 .getString("ACTIVITY_DAY_FOR_AUTHOR_TITLE")
 62  0
                 + " " + this.developer.getRealName(), "activity_day_" + HTML.escapeAuthorName(this.developer.getName()) + ".png").toFile();
 63  0
         final ChartImage codeDistributionChart = new CodeDistributionChartMaker(this.config, this.developer).toFile();
 64  0
 
 65  0
         String title;
 66  0
         if (this.config.isDeveloper(this.developer)) {
 67  0
             title = this.config.getProjectName() + " Developers: " + this.developer.getRealName();
 68  0
         } else {
 69  0
             title = "Non-developer Login: " + this.developer.getRealName();
 70  0
         }
 71  0
         final Page page = this.config.createPage(getFilename(this.developer), this.developer.getRealName(), title);
 72  0
         page.addAttribute("Login name", this.developer.getName());
 73  0
         if (this.developer.getRealName() != null && !this.developer.getRealName().equals(this.developer.getName())) {
 74  0
             page.addAttribute("Real name", this.developer.getRealName());
 75  0
         }
 76  0
         if (StringUtils.isNotEmpty(this.developer.getTwitterUserName())) {
 77  0
             page.addRawAttribute("Twitter", "@<a href=\"http://twitter.com/" + this.developer.getTwitterUserName() + "\">"
 78  
                     + this.developer.getTwitterUserName() + "</a>");
 79  0
         }
 80  0
         if (StringUtils.isNotEmpty(this.developer.getEmail())) {
 81  0
             page.addRawAttribute("Email", "<a href=\"mailto:" + this.developer.getEmail() + "\">" + this.developer.getEmail() + "</a>");
 82  0
         }
 83  0
         if (StringUtils.isNotEmpty(this.developer.getHomePageUrl())) {
 84  0
             page.addRawAttribute("Home Page", "<a href=\"" + this.developer.getHomePageUrl() + "\">" + this.developer.getHomePageUrl() + "</a>");
 85  0
         }
 86  0
         if (StringUtils.isNotEmpty(this.developer.getImageUrl())) {
 87  0
             page.addRawAttribute("Image", "<img src=\"" + this.developer.getImageUrl() + "\" alt=\"" + this.developer.getRealName() + "\"/>");
 88  0
         }
 89  0
         
 90  0
         page.addAttribute("Total Commits", getNumberAndPercentage(this.developer.getRevisions().size(), this.repository.getRevisions().size()));
 91  0
         String loc = getNumberAndPercentage(countContributedLines(this.developer.getRevisions()), countContributedLines(this.repository.getRevisions()));
 92  0
         page.addAttribute("Lines of Code", loc);
 93  0
         page.addAttribute("Most Recent Commit", ((Revision) this.developer.getRevisions().last()).getDate());
 94  0
         if (ConfigurationOptions.isEnableTwitterButton()) {
 95  0
             page.addRawAttribute("Tweet this", TwitterHelp.buildDeveloperLink(developer, loc, repository, config));
 96  0
         }
 97  0
         page.addSection(Messages.getString("ACTIVITY_TITLE"));
 98  0
         page.add(hourChart);
 99  0
         page.add(weekdayChart);
 100  0
 
 101  0
         if (StringUtils.isNotEmpty(this.developer.getTwitterUserName()) && this.developer.isTwitterIncludeHtml()) {
 102  0
             page.addSection("Twitter");
 103  0
             page.addRawContent("<div id=\"twitter_div\">");
 104  0
             page.addRawContent("<ul id=\"twitter_update_list\"/>");
 105  0
             page.addRawContent("<a href=\"http://twitter.com/" + developer.getTwitterUserName()
 106  0
                     + "\" id=\"twitter-link\" style=\"display:block;text-align:right;\">follow me on Twitter</a>");
 107  0
             page.addRawContent("</div>");
 108  0
             page.addRawContent("<script type=\"text/javascript\" src=\"http://twitter.com/javascripts/blogger.js\"></script>");
 109  0
             page.addRawContent("<script type=\"text/javascript\" src=\"http://twitter.com/statuses/user_timeline/" + developer.getTwitterUserName()
 110  
                     + ".json?callback=twitterCallback2&amp;count=5\"></script>");
 111  0
         }
 112  0
         if (StringUtils.isNotEmpty(this.developer.getTwitterUserId()) && this.developer.isTwitterIncludeFlash()) {
 113  0
             page.addSection("Twitter");
 114  0
             page
 115  0
                     .addRawContent("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0\" width=\"550\" height=\"350\" id=\"TwitterWidget\" align=\"middle\">");
 116  0
             page.addRawContent("<param name=\"allowScriptAccess\" value=\"sameDomain\" />");
 117  0
             page.addRawContent("<param name=\"allowFullScreen\" value=\"false\" />");
 118  0
             page.addRawContent("<param name=\"movie\" value=\"http://static.twitter.com/flash/widgets/profile/TwitterWidget.swf\" />");
 119  0
             page.addRawContent("<param name=\"quality\" value=\"high\" />");
 120  0
             page.addRawContent("<param name=\"bgcolor\" value=\"#000000\" />");
 121  0
             page.addRawContent("<param name=\"FlashVars\" value=\"userID=" + developer.getTwitterUserId()
 122  0
                     + "&amp;styleURL=http://static.twitter.com/flash/widgets/profile/velvetica.xml\"/>");
 123  0
             page
 124  0
                     .addRawContent("<embed src=\"http://static.twitter.com/flash/widgets/profile/TwitterWidget.swf\" quality=\"high\" bgcolor=\"#000000\" width=\"550\" height=\"350\" name=\"TwitterWidget\" align=\"middle\" allowScriptAccess=\"sameDomain\" allowFullScreen=\"false\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" FlashVars=\"userID="
 125  0
                             + developer.getTwitterUserId() + "&amp;styleURL=http://static.twitter.com/flash/widgets/profile/velvetica.xml\"/></object>");
 126  0
         }
 127  0
 
 128  0
         page.addSection("Activity in Directories");
 129  0
         page.add(new DirectoriesForAuthorTableReport(this.config, this.developer));
 130  0
         if (codeDistributionChart != null) {
 131  0
             page.add(codeDistributionChart);
 132  0
         }
 133  0
         page.addSection(Messages.getString("MOST_RECENT_COMMITS"));
 134  0
         page.addRawContent(new CommitListFormatter(this.config, getRecentCommits(), Collections.EMPTY_LIST, RECENT_COMMITS_LENGTH, false).render());
 135  0
         return page;
 136  0
     }
 137  0
 
 138  0
     private List getRecentCommits() {
 139  0
         final List results = new ArrayList();
 140  0
         final Iterator it = this.repository.getCommits().iterator();
 141  0
         while (it.hasNext()) {
 142  0
             final Commit commit = (Commit) it.next();
 143  0
             if (this.developer.equals(commit.getAuthor())) {
 144  0
                 results.add(commit);
 145  0
             }
 146  0
         }
 147  0
         return results;
 148  0
     }
 149  0
 
 150  0
     private int countContributedLines(final Collection revisions) {
 151  0
         int result = 0;
 152  0
         final Iterator it = revisions.iterator();
 153  0
         while (it.hasNext()) {
 154  0
             final Revision element = (Revision) it.next();
 155  0
             result += element.getNewLines();
 156  0
         }
 157  0
         return result;
 158  
     }
 159  
 
 160  
     /**
 161  
      * returns the percentage of a given total count and the count.
 162  
      * This will work, because division by zero is not a problem with doubles:
 163  
      * you get NaN (and the formatter will format that too).
 164  
      * @author Jan Dockx
 165  0
      * @param value
 166  0
      * @param total
 167  
      * @return String percentage string
 168  
      */
 169  0
     private String getNumberAndPercentage(final int value, final int total) {
 170  0
         final double factor = (double) value / (double) total;
 171  0
         return NumberFormat.getNumberInstance().format(value) + " (" + PERCENT_FORMAT.format(factor) + ")";
 172  
     }
 173  
 }