Project Report: fawkez

Packagesummary org.jcoderz.phoenix.report

org.jcoderz.phoenix.report.CheckstyleReportReader

LineHitsNoteSource
1  /*
2   * $Id: CheckstyleReportReader.java 1404 2009-04-14 12:34:34Z 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.Level;
44  import java.util.logging.Logger;
45  
46  import javax.xml.bind.JAXBException;
47  
48  import org.jcoderz.commons.util.IoUtil;
49  import org.jcoderz.phoenix.checkstyle.jaxb.Checkstyle;
50  import org.jcoderz.phoenix.report.jaxb.Item;
51  import org.jcoderz.phoenix.report.jaxb.ObjectFactory;
52  
53  /**
54   * This class is used to read the XML report from checkstyle.
55   *
56   * The checkstyle report is also transformed to the jCoderZ.org format.
57   *
58   * @author Michael Griffel
59   */
60  public final class CheckstyleReportReader
61        extends AbstractReportReader
62  {
63     /** JAXB context path. */
64     public static final String CHECKSTYLE_JAXB_CONTEXT_PATH
65        = "org.jcoderz.phoenix.checkstyle.jaxb";
66  
67100    private static final String CLASSNAME
68         = CheckstyleReportReader.class.getName();
69  
70100    private static final Logger logger = Logger.getLogger(CLASSNAME);
71  
72     private Checkstyle mReportDocument;
73  
74     CheckstyleReportReader ()
75           throws JAXBException
76     {
77100       super(CHECKSTYLE_JAXB_CONTEXT_PATH);
78100    }
79  
80     /** {@inheritDoc} */
81     public void parse (File f)
82           throws FileNotFoundException, JAXBException
83     {
840       final FileInputStream is = new FileInputStream(f);
85        try
86        {
870           mReportDocument 
88                = (Checkstyle) getUnmarshaller().unmarshal(is);
89        }
90        finally
91        {
920           IoUtil.close(is);
930       }
940    }
95  
96 (1)   protected Map getItems ()
97           throws JAXBException
98     {
990       if (logger.isLoggable(Level.FINE))
100        {
1010          logger.entering(CLASSNAME, "getItems");
102        }
103  
1040       final Map itemMap = new HashMap();
105  
1060       final List files = mReportDocument.getFileOrErrorOrException();
107  
1080       for (final Iterator iterator = files.iterator(); iterator.hasNext(); )
109        {
1100          final Object o = iterator.next();
111  
1120          if (o instanceof org.jcoderz.phoenix.checkstyle.jaxb.File)
113           {
1140             final org.jcoderz.phoenix.checkstyle.jaxb.File f
115                 = (org.jcoderz.phoenix.checkstyle.jaxb.File) o;
1160             final String resourceFilename = normalizeFileName(f.getName());
117  
1180             final List errors = f.getErrorOrException();
1190             final List items = createReportItems(resourceFilename, errors);
120  
1210             addItemsToResource(itemMap, resourceFilename, items);
122           }
1230       }
124  
1250       if (logger.isLoggable(Level.FINE))
126        {
1270          logger.exiting(CLASSNAME, "getItems", itemMap);
128        }
1290       return itemMap;
130     }
131  
132     private void addItemsToResource (
133           Map itemMap, String resourceFilename, List items)
134     {
1350       final ResourceInfo info = ResourceInfo.lookup(resourceFilename);
1360       if (info != null)
137        {
1380          if (itemMap.get(info) != null)
139           {
1400             final List l = (List) itemMap.get(info);
1410(2)            l.addAll(items);
1420          }
143           else
144           {
1450(3)            itemMap.put(info, items);
146           }
147        }
148        else
149        {
1500          logger.finer("Ignore findings for resource " + resourceFilename);
151        }
1520    }
153  
154     private List createReportItems (String resourceFilename, List errors)
155           throws JAXBException
156     {
1570       final List ret = new ArrayList();
158  
1590       for (final Iterator iterator = errors.iterator(); iterator.hasNext(); )
160        {
1610          final Object o = iterator.next();
162  
1630          if (o instanceof org.jcoderz.phoenix.checkstyle.jaxb.Error)
164           {
1650             final org.jcoderz.phoenix.checkstyle.jaxb.Error error
166                 = (org.jcoderz.phoenix.checkstyle.jaxb.Error) o;
167  
1680             final Item item = new ObjectFactory().createItem();
169  
1700             if (error.isSetSeverity())
171              {
1720                item.setSeverity(error.getSeverity());
173              }
1740             item.setMessage(error.getMessage());
1750             item.setLine(error.getLine());
1760             item.setColumn(error.getColumn());
1770             item.setOrigin(Origin.CHECKSTYLE);
178  
1790             final FindingType type = CheckstyleFindingType.
180                 detectFindingTypeForMessage(error.getMessage());
1810             if (type == null)
182              {
1830                item.setFindingType(sourceToClass(error.getSource()));
1840                logger.log(Level.INFO, "Could not find finding type for "
185                     + "Checkstyle finding with message '" + error.getMessage()
186                     + "'.");
187              }
188              else
189              {
1900                item.setFindingType(type.getSymbol());
1910                item.setSeverity(((CheckstyleFindingType) type).getSeverity());
192              }
193  
1940(4)            ret.add(item);
195           }
1960       }
197  
1980       return ret;
199     }
200  
201     private static String sourceToClass (String source)
202     {
2030        final int i = source.lastIndexOf('.');
2040        return source.substring(i + 1);
205     }
206  
207  }

Findings in this File

d (1) 96 : 18 getItems() in org.jcoderz.phoenix.report.CheckstyleReportReader 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>>
d (2) 141 : 21 [unchecked] unchecked call to addAll(java.util.Collection<? extends E>) as a member of the raw type java.util.List
d (3) 145 : 24 [unchecked] unchecked call to put(K,V) as a member of the raw type java.util.Map
d (4) 194 : 20 [unchecked] unchecked call to add(E) as a member of the raw type java.util.List