Project Report: fawkez

Packagesummary org.jcoderz.phoenix.report

org.jcoderz.phoenix.report.JcoderzReport

LineHitsNoteSource
1  /*
2   * $Id: JcoderzReport.java 1454 2009-05-10 11:06: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.OutputStream;
37  import java.util.Collections;
38 (1)import java.util.Iterator;
39  import java.util.List;
40  import java.util.Map;
41  import java.util.Map.Entry;
42  import java.util.logging.Logger;
43  
44  import javax.xml.bind.JAXBException;
45  
46  import org.jcoderz.phoenix.report.jaxb.Item;
47  import org.jcoderz.phoenix.report.jaxb.ObjectFactory;
48  import org.jcoderz.phoenix.report.jaxb.Report;
49  
50  /**
51   * This class implements writing of <code>jcoderz-report.xml</code> files.
52   *
53   * @author Michael Griffel
54   */
55  public final class JcoderzReport
56     extends AbstractReportReader
57  {
58      /** JAXB context path. */
59      public static final String JCODERZ_JAXB_CONTEXT_PATH
60         = "org.jcoderz.phoenix.report.jaxb";
61  
62  
630     private static final String CLASSNAME = JcoderzReport.class.getName();
64  
650     private static final Logger logger = Logger.getLogger(CLASSNAME);
66  
670     private final Report mReport = new ObjectFactory().createReport();
68  
69      /** The report level. */
700     private ReportLevel mLevel = ReportLevel.PROD;
71  
72  
73     JcoderzReport ()
74           throws JAXBException
75     {
760       super(JCODERZ_JAXB_CONTEXT_PATH);
770    }
78  
79  
80     /** {@inheritDoc} */
81 (2)   public Map getItems ()
82        throws JAXBException
83     {
840       throw new NoSuchMethodError();
85     }
86  
87  
88     /**
89      * Sets the report level.
90      *
91      * @param level The level of the report
92      */
93     public void setLevel (ReportLevel level)
94     {
950       mLevel = level;
960    }
97  
98  
99     /** {@inheritDoc} */
100     public void parse (File f)
101        throws JAXBException
102     {
103 (3)      // TODO
1040(4)      throw new RuntimeException("Method not implemented. (TODO)");
105     }
106  
107  
108     /**
109      * Writes the report to the specified stream by using JAXB.
110      *
111      * @param out where to write the jCoderZ report to.
112      * @param items the file items. The items are a Map of ResourceInfo and
113      *    a List of the type jCoderZ Item (org.jcoderz.phoenix.report.jaxb.Item)
114      * @throws JAXBException for JAXB errors
115      */
116     public void write (OutputStream out, Map<ResourceInfo, List<Item>> items)
117        throws JAXBException
118     {
1190       addItems(mLevel, items);
1200       writeReport(out);
1210    }
122  
123  
124     /**
125      * Just add items of a specific level to the report, do not write the file
126      * to persistent storage yet.
127      *
128      * @param level The level under which to add the items.
129      * @param items A map of items.
130      * @throws JAXBException When the JAXB file representation can not
131      *      be created.
132      */
133     public void addItems (ReportLevel level, Map<ResourceInfo, List<Item>> items)
134        throws JAXBException
135     {
1360       final Map<ResourceInfo, List<Item>> files = items;
137  
1380       for (Entry<ResourceInfo, List<Item>> entry : files.entrySet())
139        {
1400          final ResourceInfo info = entry.getKey();
1410          final List<Item> itemList = entry.getValue();
1420          final org.jcoderz.phoenix.report.jaxb.File f
143              = new org.jcoderz.phoenix.report.jaxb.ObjectFactory().createFile();
1440          if (info != null)
145           {
1460              f.setName(info.getResourceName());
1470              f.setClassname(info.getClassname());
1480              f.setPackage(info.getPackage());
1490              f.setSrcDir(info.getSourcDir());
1500              f.setLoc(info.getLinesOfCode());
151           }
1520          f.setLevel(level);
1530(5)         f.getItem().addAll(itemList);
154  
1550(6)         mReport.getFile().add(f);
1560       }
1570    }
158  
159  
160     /**
161      * Write the report to persistent storage.
162      *
163      * @param out The output stream to write the report to.
164      * @throws JAXBException In case a marshalling exception occurs.
165      */
166     public void writeReport (OutputStream out)
167        throws JAXBException
168     {
1690       getMarshaller().marshal(mReport, out);
1700    }
171  
172  
173     /**
174      * Sets the project's home folder.
175      *
176      * @param s the home folder
177      */
178     public void setProjectHome (String s)
179     {
1800       mReport.setProjectHome(s);
1810    }
182  
183  
184     /**
185      * Gets the project's home folder.
186      *
187      * @return the home folder
188      */
189     public String getProjectHome ()
190     {
1910       return mReport.getProjectHome();
192     }
193  
194  
195     /**
196      * Sets the project name.
197      *
198      * @param s the name of the project
199      */
200     public void setProjectName (String s)
201     {
2020       mReport.setName(s);
2030    }
204  
205  
206     /**
207      * Gets the project name.
208      *
209      * @return the name of the project
210      */
211     public String getProjectName ()
212     {
2130       return mReport.getName();
214     }
215  
216 (7)   public void addSystemLevelIssue (String message, Throwable e,
217         ResourceInfo res)
218     {
219         try
220         {
2210            final Item item = new ObjectFactory().createItem();
2220            item.setMessage(message);
2230            item.setSeverity(Severity.ERROR);
2240            item.setFindingType(SystemFindingType.SYS_ERROR.getSymbol());
2250            item.setOrigin(Origin.SYSTEM);
2260            addItems(ReportLevel.PROD, Collections.singletonMap(res,
227                 Collections.singletonList(item)));
228         }
2290        catch (JAXBException ex)
230         {
231             // give up.. it is about time
2320            throw new RuntimeException(
233                 "Failed to add detail for " + e, ex);
2340        }
2350    }
236  
237  }

Findings in this File

c (1) 38 : 8 Unused import - java.util.Iterator.
d (2) 81 : 15 getItems() in org.jcoderz.phoenix.report.JcoderzReport 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 (3) 103 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.
i (4) 104 : 0 method org.jcoderz.phoenix.report.JcoderzReport.parse(File) throws exception with static message string
d (5) 153 : 28 [unchecked] unchecked call to addAll(java.util.Collection<? extends E>) as a member of the raw type java.util.List
d (6) 155 : 31 [unchecked] unchecked call to add(E) as a member of the raw type java.util.List
c (7) 216 : 4 Missing a Javadoc comment.