Project Report: fawkez

Packagesummary org.jcoderz.phoenix.report

org.jcoderz.phoenix.report.PmdReportReader

LineHitsNoteSource
1  /*
2   * $Id: PmdReportReader.java 627 2008-03-16 11:11:43Z 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.FileNotFoundException;
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.pmd.jaxb.FileType;
48  import org.jcoderz.phoenix.pmd.jaxb.Pmd;
49  import org.jcoderz.phoenix.pmd.jaxb.Violation;
50  import org.jcoderz.phoenix.report.jaxb.Item;
51  import org.jcoderz.phoenix.report.jaxb.ObjectFactory;
52  
53  /**
54   * PMD Report Reader.
55   *
56   * @author Michael Griffel
57   */
58  public final class PmdReportReader
59        extends AbstractReportReader
60  {
61      /** JAXB context path. */
62      public static final String PMD_JAXB_CONTEXT_PATH
63              = "org.jcoderz.phoenix.pmd.jaxb";
64  
650     private static final String CLASSNAME = PmdReportReader.class.getName();
660     private static final Logger logger = Logger.getLogger(CLASSNAME);
67  
68      private static final int PRIORITY_HIGH = 1;
69      private static final int PRIORITY_MEDIUM_HIGH = 2;
70      private static final int PRIORITY_MEDIUM = 3;
71      private static final int PRIORITY_MEDIUM_LOW = 4;
72      private static final int PRIORITY_LOW = 5;
73  
74      private Pmd mReportDocument;
75  
76      /**
77       * Constructor.
78       *
79       * @throws JAXBException
80    */
81      public PmdReportReader ()
82 (1)            throws JAXBException
83      {
840         super(PMD_JAXB_CONTEXT_PATH);
850     }
86  
87      /** {@inheritDoc} */
88      public void parse (File f)
89              throws JAXBException, FileNotFoundException
90      {
910         logger.entering(CLASSNAME, "parse", f);
920(2)        mReportDocument = (Pmd) getUnmarshaller().unmarshal(
93                  new FileInputStream(f));
940         logger.exiting(CLASSNAME, "parse");
950     }
96  
97      /** {@inheritDoc} */
98      protected Map<ResourceInfo, List<Item>> getItems ()
99              throws JAXBException
100      {
1010         logger.entering(CLASSNAME, "getItems()");
1020         final Map<ResourceInfo, List<Item>> result
103              = new HashMap<ResourceInfo, List<Item>>();
104  
1050(3)(4)        for (final Iterator<FileType> iterator = mReportDocument.getFile().iterator();
1060                 iterator.hasNext();)
107          {
1080             final FileType file = iterator.next();
109  
1100             final String key = normalizeFileName(file.getName());
1110             final List<Item> items = createItemMap(file);
1120             final ResourceInfo info = ResourceInfo.lookup(key);
1130             if (info != null)
114              {
1150                 result.put(info, items);
116              }
117              else
118              {
1190                 logger.finer("Ingoring findings for resource " + key);
120              }
1210         }
1220         logger.exiting(CLASSNAME, "getItems()", result);
1230         return result;
124      }
125  
126 (5)    private List<Item> createItemMap (org.jcoderz.phoenix.pmd.jaxb.FileType file)
127              throws JAXBException
128      {
1290         final List<Item> items = new ArrayList<Item>();
1300(6)(7)        for (final Iterator<Violation> iterator = file.getViolation().iterator(); iterator
1310                 .hasNext();)
132          {
1330             final Violation violation = iterator.next();
134  
1350             final Item item = new ObjectFactory().createItem();
1360             item.setMessage(violation.getValue().trim());
1370             item.setOrigin(Origin.PMD);
1380             item.setSeverity(mapPriority(violation));
1390             item.setFindingType(violation.getRule());
1400             item.setLine(violation.getBeginline());
1410             item.setEndLine(violation.getEndline());
1420             item.setColumn(violation.getBegincolumn());
1430             item.setEndColumn(violation.getEndcolumn());
1440             items.add(item);
1450         }
1460         return items;
147      }
148  
149      private Severity mapPriority (Violation violation)
150      {
151          final Severity ret;
152  
1530         switch (violation.getPriority())
154          {
155              case PRIORITY_HIGH:
1560                 ret = Severity.ERROR;
1570                 break;
158              case PRIORITY_MEDIUM_HIGH:
1590(8)                ret = Severity.WARNING;
1600                 break;
161              case PRIORITY_MEDIUM:
1620                 ret = Severity.DESIGN;
1630                 break;
164              case PRIORITY_MEDIUM_LOW:
1650                 ret = Severity.CODE_STYLE;
1660                 break;
167              case PRIORITY_LOW:
1680                 ret = Severity.INFO;
1690                 break;
170              default:
1710                 ret = Severity.WARNING;
172          }
1730         return ret;
174      }
175  }

Findings in this File

c (1) 82 : 20 Expected @throws tag for 'JAXBException'.
w (2) 92 : 0 Method org.jcoderz.phoenix.report.PmdReportReader.parse(File) may fail to clean up stream or resource of type java.io.InputStream
c (3) 105 : 0 Line is longer than 80 characters.
d (4) 105 : 84 [unchecked] unchecked conversion found : java.util.Iterator required: java.util.Iterator<org.jcoderz.phoenix.pmd.jaxb.FileType>
c (5) 126 : 0 Line is longer than 80 characters.
c (6) 130 : 0 Line is longer than 80 characters.
d (7) 130 : 79 [unchecked] unchecked conversion found : java.util.Iterator required: java.util.Iterator<org.jcoderz.phoenix.pmd.jaxb.Violation>
i (8) 159 : 0 Method org.jcoderz.phoenix.report.PmdReportReader.mapPriority(Violation) uses the same code for two switch clauses