Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 369   Methods: 12
NCLOC: 257   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Report.java 83.8% 94.2% 100% 91.5%
coverage coverage
 1    /*
 2    * Copyright (c) 2001-2009, Jean Tessier
 3    * All rights reserved.
 4    *
 5    * Redistribution and use in source and binary forms, with or without
 6    * modification, are permitted provided that the following conditions
 7    * are met:
 8    *
 9    * * Redistributions of source code must retain the above copyright
 10    * notice, this list of conditions and the following disclaimer.
 11    *
 12    * * Redistributions in binary form must reproduce the above copyright
 13    * notice, this list of conditions and the following disclaimer in the
 14    * documentation and/or other materials provided with the distribution.
 15    *
 16    * * Neither the name of Jean Tessier nor the names of his contributors
 17    * may be used to endorse or promote products derived from this software
 18    * without specific prior written permission.
 19    *
 20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 21    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 22    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 23    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 24    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 25    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 26    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 27    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 28    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 29    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 30    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31    */
 32   
 33    package com.jeantessier.diff;
 34   
 35    import java.util.*;
 36   
 37    import com.jeantessier.classreader.*;
 38   
 39    public class Report extends Printer {
 40    public static final String DEFAULT_ENCODING = "utf-8";
 41    public static final String DEFAULT_DTD_PREFIX = "http://depfind.sourceforge.net/dtd";
 42   
 43    private String name;
 44    private String oldVersion;
 45    private String newVersion;
 46   
 47    private Collection<Differences> removedPackages = new TreeSet<Differences>();
 48   
 49    private Collection<ClassDifferences> removedInterfaces = new TreeSet<ClassDifferences>();
 50    private Collection<ClassDifferences> removedClasses = new TreeSet<ClassDifferences>();
 51   
 52    private Collection<ClassDifferences> deprecatedInterfaces = new TreeSet<ClassDifferences>();
 53    private Collection<ClassDifferences> deprecatedClasses = new TreeSet<ClassDifferences>();
 54   
 55    private Collection<ClassReport> modifiedInterfaces = new TreeSet<ClassReport>();
 56    private Collection<ClassReport> modifiedClasses = new TreeSet<ClassReport>();
 57   
 58    private Collection<ClassDifferences> undeprecatedInterfaces = new TreeSet<ClassDifferences>();
 59    private Collection<ClassDifferences> undeprecatedClasses = new TreeSet<ClassDifferences>();
 60   
 61    private Collection<Differences> newPackages = new TreeSet<Differences>();
 62   
 63    private Collection<ClassDifferences> newInterfaces = new TreeSet<ClassDifferences>();
 64    private Collection<ClassDifferences> newClasses = new TreeSet<ClassDifferences>();
 65   
 66  2 public Report() {
 67  2 this(DEFAULT_ENCODING, DEFAULT_DTD_PREFIX);
 68    }
 69   
 70  6 public Report(String encoding, String dtdPrefix) {
 71  6 appendHeader(encoding, dtdPrefix);
 72    }
 73   
 74  2 public void setName(String name) {
 75  2 this.name = name;
 76    }
 77   
 78  2 public void setOldVersion(String oldVersion) {
 79  2 this.oldVersion = oldVersion;
 80    }
 81   
 82  2 public void setNewVersion(String newVersion) {
 83  2 this.newVersion = newVersion;
 84    }
 85   
 86  6 private void appendHeader(String encoding, String dtdPrefix) {
 87  6 append("<?xml version=\"1.0\" encoding=\"").append(encoding).append("\" ?>").eol();
 88  6 eol();
 89  6 append("<!DOCTYPE differences SYSTEM \"").append(dtdPrefix).append("/differences.dtd\">").eol();
 90  6 eol();
 91    }
 92   
 93  2 public void visitProjectDifferences(ProjectDifferences differences) {
 94  2 setName(differences.getName());
 95  2 setOldVersion(differences.getOldVersion());
 96  2 setNewVersion(differences.getNewVersion());
 97   
 98  2 for (Differences packageDifference : differences.getPackageDifferences()) {
 99  4 packageDifference.accept(this);
 100    }
 101    }
 102   
 103  4 public void visitPackageDifferences(PackageDifferences differences) {
 104  4 if (differences.isRemoved()) {
 105  1 removedPackages.add(differences);
 106    }
 107   
 108  4 for (Differences classDiffenrence : differences.getClassDifferences()) {
 109  14 classDiffenrence.accept(this);
 110    }
 111   
 112  4 if (differences.isNew()) {
 113  1 newPackages.add(differences);
 114    }
 115    }
 116   
 117  8 public void visitClassDifferences(ClassDifferences differences) {
 118  8 if (differences.isRemoved()) {
 119  1 removedClasses.add(differences);
 120    }
 121   
 122  8 if (differences.isModified()) {
 123  4 ClassReport visitor = new ClassReport();
 124  4 visitor.setIndentText(getIndentText());
 125  4 differences.accept(visitor);
 126  4 modifiedClasses.add(visitor);
 127    }
 128   
 129  8 if (differences.isNew()) {
 130  1 newClasses.add(differences);
 131    }
 132   
 133  8 if (isDeprecated()) {
 134  1 deprecatedClasses.add(differences);
 135    }
 136   
 137  8 if (isUndeprecated()) {
 138  1 undeprecatedClasses.add(differences);
 139    }
 140    }
 141   
 142  6 public void visitInterfaceDifferences(InterfaceDifferences differences) {
 143  6 if (differences.isRemoved()) {
 144  1 removedInterfaces.add(differences);
 145    }
 146   
 147  6 if (differences.isModified()) {
 148  2 ClassReport classReport = new ClassReport();
 149  2 classReport.setIndentText(getIndentText());
 150  2 differences.accept(classReport);
 151  2 modifiedInterfaces.add(classReport);
 152    }
 153   
 154  6 if (differences.isNew()) {
 155  1 newInterfaces.add(differences);
 156    }
 157   
 158  6 if (isDeprecated()) {
 159  1 deprecatedInterfaces.add(differences);
 160    }
 161   
 162  6 if (isUndeprecated()) {
 163  1 undeprecatedInterfaces.add(differences);
 164    }
 165    }
 166   
 167  6 public String render() {
 168  6 indent().append("<differences>").eol();
 169  6 raiseIndent();
 170   
 171  6 indent().append("<name>").append(name).append("</name>").eol();
 172  6 indent().append("<old>").append(oldVersion).append("</old>").eol();
 173  6 indent().append("<new>").append(newVersion).append("</new>").eol();
 174   
 175  6 if (removedPackages.size() !=0) {
 176  1 indent().append("<removed-packages>").eol();
 177  1 raiseIndent();
 178   
 179  1 for (Differences removedPackage : removedPackages) {
 180  1 indent().append("<name>").append(removedPackage).append("</name>").eol();
 181    }
 182   
 183  1 lowerIndent();
 184  1 indent().append("</removed-packages>").eol();
 185    }
 186   
 187  6 if (removedInterfaces.size() !=0) {
 188  1 indent().append("<removed-interfaces>").eol();
 189  1 raiseIndent();
 190   
 191  1 for (ClassDifferences cd : removedInterfaces) {
 192  1 indent().append("<name").append(breakdownDeclaration(cd.getOldClass())).append(">").append(cd).append("</name>").eol();
 193    }
 194   
 195  1 lowerIndent();
 196  1 indent().append("</removed-interfaces>").eol();
 197    }
 198   
 199  6 if (removedClasses.size() !=0) {
 200  1 indent().append("<removed-classes>").eol();
 201  1 raiseIndent();
 202   
 203  1 for (ClassDifferences cd : removedClasses) {
 204  1 indent().append("<name").append(breakdownDeclaration(cd.getOldClass())).append(">").append(cd).append("</name>").eol();
 205    }
 206   
 207  1 lowerIndent();
 208  1 indent().append("</removed-classes>").eol();
 209    }
 210   
 211  6 if (deprecatedInterfaces.size() !=0) {
 212  1 indent().append("<deprecated-interfaces>").eol();
 213  1 raiseIndent();
 214   
 215  1 for (ClassDifferences cd : deprecatedInterfaces) {
 216  1 indent().append("<name").append(breakdownDeclaration(cd.getNewClass())).append(">").append(cd).append("</name>").eol();
 217    }
 218   
 219  1 lowerIndent();
 220  1 indent().append("</deprecated-interfaces>").eol();
 221    }
 222   
 223  6 if (deprecatedClasses.size() !=0) {
 224  1 indent().append("<deprecated-classes>").eol();
 225  1 raiseIndent();
 226   
 227  1 for (ClassDifferences cd : deprecatedClasses) {
 228  1 indent().append("<name").append(breakdownDeclaration(cd.getNewClass())).append(">").append(cd).append("</name>").eol();
 229    }
 230   
 231  1 lowerIndent();
 232  1 indent().append("</deprecated-classes>").eol();
 233    }
 234   
 235  6 if (modifiedInterfaces.size() !=0) {
 236  1 indent().append("<modified-interfaces>").eol();
 237  1 raiseIndent();
 238   
 239  1 for (ClassReport modifiedInterface : modifiedInterfaces) {
 240  2 append(modifiedInterface.render());
 241    }
 242   
 243  1 lowerIndent();
 244  1 indent().append("</modified-interfaces>").eol();
 245    }
 246   
 247  6 if (modifiedClasses.size() !=0) {
 248  2 indent().append("<modified-classes>").eol();
 249  2 raiseIndent();
 250   
 251  2 for (ClassReport modifiedClass : modifiedClasses) {
 252  4 append(modifiedClass.render());
 253    }
 254   
 255  2 lowerIndent();
 256  2 indent().append("</modified-classes>").eol();
 257    }
 258   
 259  6 if (undeprecatedInterfaces.size() !=0) {
 260  1 indent().append("<undeprecated-interfaces>").eol();
 261  1 raiseIndent();
 262   
 263  1 for (ClassDifferences cd : undeprecatedInterfaces) {
 264  1 indent().append("<name").append(breakdownDeclaration(cd.getNewClass())).append(">").append(cd).append("</name>").eol();
 265    }
 266   
 267  1 lowerIndent();
 268  1 indent().append("</undeprecated-interfaces>").eol();
 269    }
 270   
 271  6 if (undeprecatedClasses.size() !=0) {
 272  1 indent().append("<undeprecated-classes>").eol();
 273  1 raiseIndent();
 274   
 275  1 for (ClassDifferences cd : undeprecatedClasses) {
 276  1 indent().append("<name").append(breakdownDeclaration(cd.getNewClass())).append(">").append(cd).append("</name>").eol();
 277    }
 278   
 279  1 lowerIndent();
 280  1 indent().append("</undeprecated-classes>").eol();
 281    }
 282   
 283  6 if (newPackages.size() !=0) {
 284  1 indent().append("<new-packages>").eol();
 285  1 raiseIndent();
 286   
 287  1 for (Differences newPackage : newPackages) {
 288  1 indent().append("<name>").append(newPackage).append("</name>").eol();
 289    }
 290   
 291  1 lowerIndent();
 292  1 indent().append("</new-packages>").eol();
 293    }
 294   
 295  6 if (newInterfaces.size() !=0) {
 296  1 indent().append("<new-interfaces>").eol();
 297  1 raiseIndent();
 298   
 299  1 for (ClassDifferences cd : newInterfaces) {
 300  1 indent().append("<name").append(breakdownDeclaration(cd.getNewClass())).append(">").append(cd).append("</name>").eol();
 301    }
 302   
 303  1 lowerIndent();
 304  1 indent().append("</new-interfaces>").eol();
 305    }
 306   
 307  6 if (newClasses.size() !=0) {
 308  1 indent().append("<new-classes>").eol();
 309  1 raiseIndent();
 310   
 311  1 for (ClassDifferences cd : newClasses) {
 312  1 indent().append("<name").append(breakdownDeclaration(cd.getNewClass())).append(">").append(cd).append("</name>").eol();
 313    }
 314   
 315  1 lowerIndent();
 316  1 indent().append("</new-classes>").eol();
 317    }
 318   
 319  6 lowerIndent();
 320  6 indent().append("</differences>").eol();
 321   
 322  6 return super.toString();
 323    }
 324   
 325  8 private String breakdownDeclaration(Classfile element) {
 326  8 StringBuffer result = new StringBuffer();
 327   
 328  8 if (element != null) {
 329  8 if (element.isPublic()) result.append(" visibility=\"public\"");
 330  0 if (element.isPackage()) result.append(" visibility=\"package\"");
 331  0 if (element.isFinal()) result.append(" final=\"yes\"");
 332  4 if (element.isSuper()) result.append(" super=\"yes\"");
 333  0 if (element.isSynthetic()) result.append(" synthetic=\"yes\"");
 334  2 if (element.isDeprecated()) result.append(" deprecated=\"yes\"");
 335   
 336  8 result.append(" name=\"").append(element.getClassName()).append("\"");
 337   
 338  8 if (element.isInterface()) {
 339  4 result.append(" interface=\"yes\"");
 340   
 341  4 result.append(" extends=\"");
 342  4 Iterator i = element.getAllInterfaces().iterator();
 343  4 while (i.hasNext()) {
 344  0 result.append(i.next());
 345  0 if (i.hasNext()) {
 346  0 result.append(", ");
 347    }
 348    }
 349  4 result.append("\"");
 350    } else {
 351  0 if (element.isAbstract()) result.append(" abstract=\"yes\"");
 352   
 353  4 result.append(" extends=\"").append(element.getSuperclassName()).append("\"");
 354   
 355  4 result.append(" implements=\"");
 356  4 Iterator i = element.getAllInterfaces().iterator();
 357  4 while (i.hasNext()) {
 358  0 result.append(i.next());
 359  0 if (i.hasNext()) {
 360  0 result.append(", ");
 361    }
 362    }
 363  4 result.append("\"");
 364    }
 365    }
 366   
 367  8 return result.toString();
 368    }
 369    }