Changeset 1319

Show
Ignore:
Timestamp:
03/28/09 14:15:26 (3 years ago)
Author:
amandel
Message:

#2 Quick implementation to detect new findings. The new findings will
get an increased severity level.

Location:
trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/config/build-report.xml

    r1317 r1319  
    9494      </path> 
    9595 
     96           
     97         
    9698      <delete dir="${base.dir}/build/jcreport"/> 
    9799      <jcreport name="fawkez" 
     
    106108                maxheap="128" 
    107109                encoding="US-ASCII" 
    108                 cpus="0"> <!-- Increase to speed up --> 
     110                cpus="0" 
     111                oldReportFile="${env.CRUISECONTROL_HOME}/artifacts/${name}/global/jcoderz-report.xml">  
    109112         <classpath refid="jcreport.classpath"/> 
    110113         <reports>    
     
    152155         </filters> 
    153156      </jcreport>    
     157        <!-- TODO: Only do this on the cc machine. --> 
     158        <copy  
     159        file="${base.dir}/build/doc/findings-report/jcoderz-report.xml" 
     160        tofile="${env.CRUISECONTROL_HOME}/artifacts/${name}/global/jcoderz-report.xml" /> 
    154161   </target>    
    155162 
  • trunk/config/jcoderz-report-filter.xsl

    r1011 r1319  
    267267   </xs:template> 
    268268 
     269   <xs:template 
     270      match="/report/file[@classname = 'LogViewer'][@package = 'org.jcoderz.commons.logging']/ 
     271              item[@finding-type = 'SMII_STATIC_METHOD_INSTANCE_INVOCATION']"> 
     272      <item> 
     273         <xs:apply-templates select="@*"/> 
     274         <xs:attribute name="severity">filtered</xs:attribute> 
     275         <xs:attribute name="severity-reason">Intended use of return value.</xs:attribute> 
     276      </item> 
     277   </xs:template> 
    269278 
    270279</xs:stylesheet> 
  • trunk/src/java/org/jcoderz/phoenix/report/JcReportAntTask.java

    r1237 r1319  
    9494   private String mName = null; 
    9595   private File mDest = null; 
     96   private File mOldReportFile = null; 
    9697   private String mWikiBase = null; 
    9798   private String mWebRcsBase = null; 
     
    120121    } 
    121122 
    122  
    123123    /** 
    124124     * @param cpus the cpus to set 
     
    129129    } 
    130130 
    131  
    132 /** 
     131    /** 
    133132     * @return the sourceEncoding 
    134133     */ 
     
    137136        return mSourceEncoding.name(); 
    138137    } 
    139  
    140138 
    141139    /** 
     
    147145    } 
    148146 
    149  
    150 /** 
     147    /** 
    151148    * Returns the working directory. 
    152149    * 
     
    157154      return mWorkingDir; 
    158155   } 
    159  
    160156 
    161157   /** 
     
    223219   } 
    224220 
     221   public void setOldReportsFile (String oldReportsFile) 
     222   { 
     223      mOldReportFile = new File(oldReportsFile); 
     224   } 
    225225 
    226226   /** 
     
    594594         final NestedFilterElement filterElement = filterIter.next(); 
    595595         merger.addFilter(filterElement.getFile()); 
     596      } 
     597      if (mOldReportFile != null) 
     598      { 
     599          merger.setOldFile(mOldReportFile); 
    596600      } 
    597601      merger.merge(); 
  • trunk/src/java/org/jcoderz/phoenix/report/ReportMerger.java

    r1011 r1319  
    5252 
    5353import org.jcoderz.commons.ArgumentMalformedException; 
     54import org.jcoderz.commons.util.Assert; 
    5455import org.jcoderz.commons.util.FileUtils; 
    5556import org.jcoderz.commons.util.IoUtil; 
    5657import org.jcoderz.commons.util.LoggingUtils; 
     58import org.jcoderz.phoenix.report.jaxb.Item; 
    5759import org.jcoderz.phoenix.report.jaxb.ObjectFactory; 
    5860import org.jcoderz.phoenix.report.jaxb.Report; 
     
    8587   private final List<File> mFilters = new ArrayList<File>(); 
    8688 
     89   /** The old Report. */ 
     90   private File mOldReport; 
     91 
    8792 
    8893   /** 
     
    135140           logger.log(Level.FINE, "Filter: " + filterFile); 
    136141           final TransformerFactory tFactory 
    137            = TransformerFactory.newInstance(); 
    138  
    139            final Transformer transformer = tFactory.newTransformer( 
    140                new StreamSource(filterFile)); 
    141  
    142            final File tempOutputFile = new File( 
    143                mOutFile.getCanonicalPath() + ".tmp"); 
     142               = TransformerFactory.newInstance(); 
     143 
     144           final Transformer transformer  
     145               = tFactory.newTransformer(new StreamSource(filterFile)); 
     146 
     147           final File tempOutputFile  
     148               = new File(mOutFile.getCanonicalPath() + ".tmp"); 
    144149           tempOutputFile.createNewFile(); 
    145150 
     
    153158   } 
    154159 
    155  
    156160   /** 
     161    * Searches for new findings based on the old jcReport and increases the 
     162    * severity of such findings to NEW.  
     163    */ 
     164   public void flagNewFindings ()  
     165       throws JAXBException, FileNotFoundException 
     166   { 
     167       logger.log(Level.FINE, "Searching for NEW findings..."); 
     168       final Report currentReport  
     169           = (Report) new ObjectFactory().createUnmarshaller().unmarshal(mOutFile); 
     170       final Report oldReport  
     171           = (Report) new ObjectFactory().createUnmarshaller().unmarshal(mOldReport); 
     172       for(org.jcoderz.phoenix.report.jaxb.File newFile :  
     173           (List<org.jcoderz.phoenix.report.jaxb.File>) currentReport.getFile()) 
     174       { 
     175           final org.jcoderz.phoenix.report.jaxb.File oldFile  
     176               = findFile(newFile, oldReport); 
     177           for(Item item:(List<Item>) newFile.getItem()) 
     178           { 
     179               if (findItem(item, oldFile) == null) 
     180               { 
     181                   flagAsNew(item); 
     182               } 
     183           } 
     184       } 
     185        
     186       final FileOutputStream out = new FileOutputStream(mOutFile); 
     187       try 
     188       { 
     189           new ObjectFactory().createMarshaller().marshal(currentReport, out); 
     190       } 
     191       finally 
     192       { 
     193           IoUtil.close(out); 
     194       } 
     195   } 
     196 
     197    // be more smart in finding matching items... (eg if the file was edited) 
     198    private Item findItem ( 
     199        Item newItem, org.jcoderz.phoenix.report.jaxb.File oldFile) 
     200    { 
     201        Item result = null; 
     202        for(Item item:(List<Item>) oldFile.getItem()) 
     203        { 
     204            if (item.getLine() == newItem.getLine() 
     205                && item.getColumn() == newItem.getColumn() 
     206                && item.getFindingType().equals(newItem.getFindingType()) 
     207                && item.getCounter() <= newItem.getCounter()) 
     208            { 
     209                result = item; 
     210                break; 
     211            } 
     212        } 
     213        return result; 
     214    } 
     215 
     216 
     217    private void flagAsNew (Item item) 
     218    { 
     219        final Severity oldSeverity = item.getSeverity(); 
     220        item.setSeverity(Severity.NEW); 
     221        item.setMessage( 
     222            item.getMessage() + " Severity " + oldSeverity + "."); 
     223    } 
     224 
     225 
     226// This could be done faster, might be restructure the data first for  
     227   // faster lookup. 
     228   private org.jcoderz.phoenix.report.jaxb.File findFile ( 
     229       org.jcoderz.phoenix.report.jaxb.File newFile, Report oldReport) 
     230   { 
     231       final String className = newFile.getClassname(); 
     232       final String packageName = newFile.getPackage(); 
     233       final String fileName = newFile.getName(); 
     234       org.jcoderz.phoenix.report.jaxb.File result = null; 
     235       for(org.jcoderz.phoenix.report.jaxb.File file :  
     236           (List<org.jcoderz.phoenix.report.jaxb.File>) oldReport.getFile()) 
     237       { 
     238           if (file.getName().equals(fileName)  
     239               || (file.getClassname().equals(className)  
     240                   && file.getPackage().equals(packageName))) 
     241           { 
     242               result = file; 
     243               break; 
     244           } 
     245       } 
     246       return result; 
     247   } 
     248 
     249 
     250/** 
    157251    * Parses the arguments. 
    158252    * 
     
    175269            { 
    176270               addFilter(new File(args[i + 1])); 
     271            } 
     272            else if ("-old".equals(args[i])) 
     273            { 
     274               setOldFile(new File(args[i + 1])); 
    177275            } 
    178276            else if ("-loglevel".equals(args[i])) 
     
    210308   } 
    211309 
    212  
    213310   /** 
    214311    * The main method. 
     
    280377 
    281378    /** 
     379     * Set the old report to compare with. 
     380     * @param file old report file. 
     381     */ 
     382    public void setOldFile (File file) 
     383        throws IOException 
     384    { 
     385        Assert.notNull(file, "file"); 
     386        if (mOldReport != null) 
     387        { 
     388            throw new ArgumentMalformedException("old", file, 
     389                "Old Report File has already set to '" + mOldReport + "'."); 
     390        } 
     391        mOldReport = file.getCanonicalFile(); 
     392    } 
     393     
     394    /** 
    282395     * Sets the out file. 
    283396     * 
  • trunk/src/java/org/jcoderz/phoenix/report/Severity.java

    r217 r1319  
    172172    public static final Severity ERROR = new Severity("error", 100); 
    173173 
     174    /** 
     175     * New findings of this build. 
     176     * <p>Findings of this level are new in this build and because of that 
     177     * rated at higher severity level in this one build.</p> 
     178     * <p>A severity of this level marks 10 lines as bad.</p> 
     179     */ 
     180    public static final Severity NEW = new Severity("new", 100); 
     181     
    174182    /**  
    175183     * The maximum possible severity.  
    176      * Is {@link #ERROR}. 
    177      */ 
    178     public static final Severity MAX_SEVERITY = ERROR; 
     184     * Is {@link #NEW}. 
     185     */ 
     186    public static final Severity MAX_SEVERITY = NEW; 
    179187 
    180188    /** The maximum possible severity as int. */ 
    181     public static final int MAX_SEVERITY_INT = ERROR.toInt(); 
     189    public static final int MAX_SEVERITY_INT = MAX_SEVERITY.toInt(); 
    182190 
    183191    /** Internal list of all available severities. */ 
     
    192200        Severity.WARNING, 
    193201        Severity.CPD, 
    194         Severity.ERROR 
     202        Severity.ERROR, 
     203        Severity.NEW 
    195204    }; 
    196205 
  • trunk/src/xml/schema/report-types.xsd

    r1011 r1319  
    2828         <xsd:enumeration value='cpd'/> 
    2929         <xsd:enumeration value='error'/> 
     30         <xsd:enumeration value='new'/> 
    3031      </xsd:restriction> 
    3132   </xsd:simpleType>