Project Report: fawkez

Packagesummary org.jcoderz.phoenix.report

org.jcoderz.phoenix.report.CoberturaReportReader

LineHitsNoteSource
1  /*
2   * $Id: CoberturaReportReader.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.coverage.jaxb.ClassType;
48  import org.jcoderz.phoenix.coverage.jaxb.Coverage;
49  import org.jcoderz.phoenix.coverage.jaxb.LineType;
50  import org.jcoderz.phoenix.coverage.jaxb.MethodType;
51  import org.jcoderz.phoenix.coverage.jaxb.PackageType;
52  import org.jcoderz.phoenix.report.jaxb.Item;
53  import org.jcoderz.phoenix.report.jaxb.ObjectFactory;
54  
55  /**
56   * Reads the coverage report generated by cobertura.
57   *
58   * @author Michael Griffel
59   */
60  public class CoberturaReportReader
61          extends AbstractReportReader
62  {
63      /** JAXB context path. */
64      public static final String JCOVERAGE_JAXB_CONTEXT_PATH
65              = "org.jcoderz.phoenix.coverage.jaxb";
66  
670     private static final String CLASSNAME
68              = CoberturaReportReader.class.getName();
69  
700     private static final Logger logger = Logger.getLogger(CLASSNAME);
71  
72      private Coverage mReportDocument;
73  
74  
75      CoberturaReportReader ()
76              throws JAXBException
77      {
780         super(JCOVERAGE_JAXB_CONTEXT_PATH);
790     }
80  
81      /** {@inheritDoc} */
82      public final void parse (File f)
83              throws JAXBException
84      {
85          try
86          {
870(1)            mReportDocument = (Coverage) unmarshall(new FileInputStream(f));
88          }
890         catch (IOException e)
90          {
910(2)            throw new JAXBException("Cannot read JCoverage report", e);
920         }
930     }
94  
95      /** {@inheritDoc} */
96 (3)    public final Map getItems ()
97          throws JAXBException
98      {
990         final Map itemMap = new HashMap();
100  
1010         final String baseDir = mReportDocument.getSources().getSource().get(0)
102                  + File.separator;
103  
1040         for (final Iterator pkgIterator = mReportDocument.getPackages()
1050                 .getPackage().iterator(); pkgIterator.hasNext();)
106          {
1070             final PackageType currentPackage = (PackageType) pkgIterator.next();
1080             for (final Iterator clazzIterator
109                      = currentPackage.getClasses().getClazzes().iterator();
1100                     clazzIterator.hasNext();)
111              {
1120                 final ClassType clazz = (ClassType) clazzIterator.next();
1130                 processClazz(itemMap, baseDir, clazz);
1140             }
1150         }
116  
1170         return itemMap;
118      }
119  
120      private void processClazz (Map itemMap, final String baseDir,
121              final ClassType clazz)
122              throws JAXBException
123      {
1240         logger.finer("Processing class '" + clazz.getName() + "'");
125  
1260         final String javaFile = clazzname2Filename(clazz.getName());
1270         final List itemList = new ArrayList();
128  
1290         for (final Iterator methodIterator = clazz.getMethods().getMethod()
1300                 .iterator(); methodIterator.hasNext();)
131          {
1320             final MethodType method = (MethodType) methodIterator.next();
1330             for (final Iterator lineIterator = method.getLines().getLine()
1340                     .iterator(); lineIterator.hasNext();)
135              {
1360                 final LineType line = (LineType) lineIterator.next();
137  
1380                 final Item item = new ObjectFactory().createItem();
1390                 item.setOrigin(Origin.COVERAGE);
1400                 item.setCounter(line.getHits());
1410                 item.setLine(line.getNumber());
1420                 item.setSeverity(Severity.COVERAGE);
1430(4)                item.setFindingType("coverage"); // FIXME: use type
144  
1450(5)                itemList.add(item);
1460             }
1470         }
1480         final ResourceInfo info = ResourceInfo.lookup(
149                  normalizeFileName(baseDir + javaFile));
150  
1510         if (info != null)
152          {
1530             if (itemMap.containsKey(info))
154              {
1550                 final List l = (List) itemMap.get(info);
1560(6)                l.addAll(itemList);
1570             }
158              else
159              {
1600(7)                itemMap.put(info, itemList);
161              }
162          }
163          else
164          {
1650             logger.finer(
166                      "Ignoring findings for resource " + baseDir + javaFile);
167          }
1680     }
169  
170      private final String clazzname2Filename (String c)
171      {
1720         return c.replaceAll("\\.", "/") + ".java";
173      }
174  
175  }

Findings in this File

w (1) 87 : 0 Method org.jcoderz.phoenix.report.CoberturaReportReader.parse(File) may fail to clean up stream or resource of type java.io.InputStream
i (2) 91 : 0 method org.jcoderz.phoenix.report.CoberturaReportReader.parse(File) throws exception with static message string
d (3) 96 : 22 getItems() in org.jcoderz.phoenix.report.CoberturaReportReader 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) 143 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.
d (5) 145 : 29 [unchecked] unchecked call to add(E) as a member of the raw type java.util.List
d (6) 156 : 25 [unchecked] unchecked call to addAll(java.util.Collection<? extends E>) as a member of the raw type java.util.List
d (7) 160 : 28 [unchecked] unchecked call to put(K,V) as a member of the raw type java.util.Map