Project Report: fawkez

Packagesummary org.jcoderz.phoenix.report

org.jcoderz.phoenix.report.JCoverageReportReader

LineHitsNoteSource
1  /*
2   * $Id: JCoverageReportReader.java 1011 2008-06-16 17:57:36Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.phoenix.report;
34  
35  import java.io.File;
36  import java.io.FileInputStream;
37  import java.io.IOException;
38  import java.util.ArrayList;
39  import java.util.HashMap;
40  import java.util.Iterator;
41  import java.util.List;
42  import java.util.Map;
43  import java.util.logging.Logger;
44  
45  import javax.xml.bind.JAXBException;
46  
47  import org.jcoderz.phoenix.jcoverage.jaxb.Clazz;
48  import org.jcoderz.phoenix.jcoverage.jaxb.Coverage;
49  import org.jcoderz.phoenix.jcoverage.jaxb.LineType;
50  import org.jcoderz.phoenix.report.jaxb.Item;
51  import org.jcoderz.phoenix.report.jaxb.ObjectFactory;
52  
53  /**
54   * @author Michael Griffel
55   */
56  public class JCoverageReportReader
57        extends AbstractReportReader
58  {
59      /** JAXB context path. */
60      public static final String JCOVERAGE_JAXB_CONTEXT_PATH
61         = "org.jcoderz.phoenix.jcoverage.jaxb";
62  
63100    private static final String CLASSNAME
64             = JCoverageReportReader.class.getName();
65  
66100    private static final Logger logger = Logger.getLogger(CLASSNAME);
67  
68     private Coverage mReportDocument;
69  
70  
71     JCoverageReportReader ()
72        throws JAXBException
73     {
74100       super(JCOVERAGE_JAXB_CONTEXT_PATH);
75100    }
76  
77     /** {@inheritDoc} */
78     public final void parse (File f)
79        throws JAXBException
80     {
81        try
82        {
830(1)         mReportDocument = (Coverage) getUnmarshaller().unmarshal(
84                   new FileInputStream(f));
85        }
860       catch (IOException e)
87        {
880(2)         throw new JAXBException("Cannot read JCoverage report", e);
890       }
900    }
91  
92     /** {@inheritDoc} */
93 (3)   public final Map getItems ()
94        throws JAXBException
95     {
960       final Map itemMap = new HashMap();
970       final List files = mReportDocument.getClazzes();
980       final String baseDir = mReportDocument.getSrc() + File.separator;
99  
1000       for (final Iterator iterator = files.iterator(); iterator.hasNext(); )
101        {
1020          final Clazz clazz = (Clazz) iterator.next();
1030          logger.finer("Processing class '" + clazz.getName() + "'");
1040          final String javaFile = clazzname2Filename (clazz.getName());
1050          final List itemList = new ArrayList();
106  
1070          for (final Iterator i = clazz.getCoveredLines().iterator();
1080              i.hasNext(); )
109           {
1100             final LineType line = (LineType) i.next();
1110             final Item item = new ObjectFactory().createItem();
1120             item.setOrigin(Origin.COVERAGE);
1130             item.setCounter(line.getHits());
1140             item.setLine(line.getNumber());
1150             item.setSeverity(Severity.COVERAGE);
1160(4)            item.setFindingType("coverage"); // FIXME: use type
117  
1180(5)            itemList.add(item);
1190          }
1200          final ResourceInfo info
121                 = ResourceInfo.lookup(normalizeFileName(baseDir + javaFile));
122  
1230          if (info != null)
124           {
1250             if (itemMap.containsKey(info))
126              {
1270                final List l = (List) itemMap.get(info);
1280(6)               l.addAll(itemList);
1290             }
130              else
131              {
1320(7)               itemMap.put(info, itemList);
133              }
134           }
135           else
136           {
1370             logger.finer(
138                      "Ignoring findings for resource " + baseDir + javaFile);
139           }
1400       }
141  
1420       return itemMap;
143     }
144  
145     private final String clazzname2Filename (String c)
146     {
1470       return c.replaceAll("\\.", "/") + ".java";
148     }
149  }

Findings in this File

w (1) 83 : 0 Method org.jcoderz.phoenix.report.JCoverageReportReader.parse(File) may fail to clean up stream or resource of type java.io.InputStream
i (2) 88 : 0 method org.jcoderz.phoenix.report.JCoverageReportReader.parse(File) throws exception with static message string
d (3) 93 : 21 getItems() in org.jcoderz.phoenix.report.JCoverageReportReader overrides getItems() in org.jcoderz.phoenix.report.AbstractReportReader; return type requires unchecked conversion found : java.util.Map required: java.util.Map<org.jcoderz.phoenix.report.ResourceInfo,java.util.List<org.jcoderz.phoenix.report.jaxb.Item>>
i (4) 116 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.
d (5) 118 : 25 [unchecked] unchecked call to add(E) as a member of the raw type java.util.List
d (6) 128 : 24 [unchecked] unchecked call to addAll(java.util.Collection<? extends E>) as a member of the raw type java.util.List
d (7) 132 : 27 [unchecked] unchecked call to put(K,V) as a member of the raw type java.util.Map