Project Report: fawkez

Packagesummary org.jcoderz.phoenix.report

org.jcoderz.phoenix.report.Report2Console

LineHitsNoteSource
1  /*
2   * $Id: Java2Html.java 816 2008-05-01 20:04:04Z 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  /*
34   * Java2HTML v0.1 alpha converts a java source code into HTML with
35   * syntax highlighting for keywords, comments, strings and chars
36   *
37   * The contents of this file are subject to the
38   * Mozilla Public License Version 1.1 (the "License");
39   * you may not use this file except in compliance with the License.
40   * You may obtain a copy of the License at http://www.mozilla.org/MPL/
41   *
42   * Software distributed under the License is distributed on an
43   * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
44   * See the License for the specific language governing rights
45   * and limitations under the License.
46   *
47   * The Original Code is Java2HTML Converter v0.1 alpha.
48   * The Initial Developer of the Original Code is Borislav Manolov.
49   * Portions created by Borislav Manolov are Copyright (C) 2003,
50   * Borislav Manolov. All Rights Reserved.
51   *
52   * Submit bugs and comments at manfear@web.de
53   * 03/03/03
54   */
55  package org.jcoderz.phoenix.report;
56  
57  import java.io.IOException;
58  import java.io.PrintStream;
59  import java.util.List;
60  import java.util.logging.Level;
61  import java.util.logging.Logger;
62  
63  import javax.xml.bind.JAXBContext;
64  import javax.xml.bind.JAXBException;
65  import javax.xml.bind.Unmarshaller;
66  
67  import org.jcoderz.commons.util.LoggingUtils;
68  import org.jcoderz.phoenix.report.jaxb.Report;
69  
70  /**
71   * Read the report and output this to the console in a eclipse
72   * friendly way.
73   *
74   * This is a early 'prototype' version.
75   *
76   * @author Andreas Mandel
77   */
780 public final class Report2Console
79  {
80     /** Name of this class. */
810    private static final String CLASSNAME = Report2Console.class.getName();
82  
83     /** The logger used for technical logging inside this class. */
840    private static final Logger logger = Logger.getLogger(CLASSNAME);
85  
86     private static final int SEVERITY_INDENT = 12;
87     private java.io.File mInputData;
880(1)   private Level mLogLevel = Level.INFO;
89  
90     /**
91      * Main entry point.
92      *
93      * @param args The command line arguments.
94      * @throws IOException an io exception occurs.
95      * @throws JAXBException if the xml can not be parsed.
96      */
97     public static void main (String[] args)
98           throws IOException, JAXBException
99     {
1000       final Report2Console engine = new Report2Console();
101  
1020       engine.parseArguments(args);
103        // Turn on logging
1040       Logger.getLogger("org.jcoderz.phoenix.report").setLevel(Level.FINEST);
1050       engine.process();
1060    }
107  
108     /**
109      * The input file containing the jcoderz report.
110      * @param file input file containing the jcoderz report.
111      * @throws IOException if access to the file fails.
112      */
113     public void setInputFile (java.io.File file) throws IOException
114     {
1150      mInputData = file.getCanonicalFile();
1160      if (!mInputData.canRead())
117       {
1180         throw new RuntimeException("Can not read report file '"
119                + mInputData + "'.");
120       }
1210      logger.config("Using report file " + mInputData + ".");
1220    }
123  
124     /**
125      * Starts the actual generation process.
126      * @throws JAXBException if the xmp parsing fails.
127      * @throws IOException if a IO problem occurs.
128      */
129     public void process ()
130           throws JAXBException, IOException
131     {
1320       final JAXBContext jaxbContext
133              = JAXBContext.newInstance("org.jcoderz.phoenix.report.jaxb",
134                    this.getClass().getClassLoader());
1350       final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
1360(2)      unmarshaller.setValidating(true);
1370       final Report report = (Report) unmarshaller.unmarshal(mInputData);
138  
139        for (final org.jcoderz.phoenix.report.jaxb.File file
1400(3)          : (List<org.jcoderz.phoenix.report.jaxb.File>) report.getFile())
141        {
142           try
143           {
1440             outputForFile(file);
145           }
1460          catch (Exception ex)
147           {
1480             logger.log(Level.SEVERE,
149                    "Failed to generate report for '" + file.getName() + "'.",
150                    ex);
1510          }
152        }
153  
1540       logger.fine("Done.");
1550    }
156  
157     private void outputForFile (org.jcoderz.phoenix.report.jaxb.File file)
158     {
1590        final String locatorStart
160             = file.getPackage() + "." + file.getClassname() + ".";
1610(4)       final String locatorFile
162             = "(" + file.getName().substring(
163 (5)               file.getName().lastIndexOf("\\") +1);
1640        final String filler = " ";
165         for (final org.jcoderz.phoenix.report.jaxb.Item item
1660(6)           : (List<org.jcoderz.phoenix.report.jaxb.Item>) file.getItem())
167         {
1680            final Severity severity = item.getSeverity();
1690(7)           PrintStream out = System.out;
1700            if (Severity.FILTERED.equals(severity)
171                 || Severity.OK.equals(severity))
172             {
1730                continue;
174             }
1750            else if (Severity.INFO.compareTo(severity) < 0)
176             {
1770                out = System.out;
178             }
179             else
180             {
1810                out = System.err;
182             }
1830(8)           String severityString = item.getSeverity().toString();
1840            out.println(severityString
185                 + filler.substring(0, SEVERITY_INDENT - severityString.length())
186                 + ": " + item.getMessage());
1870            out.println(
188 (9)               " at " + locatorStart +
189                 item.getFindingType() + locatorFile + ":"
190                 + item.getLine() + ")");
1910            out.flush();
1920        }
1930    }
194  
195     private void parseArguments (String[] args)
196     {
197        try
198        {
1990          for (int i = 0; i < args.length; )
200           {
2010             if ("-report".equals(args[i]))
202              {
2030                setInputFile(new java.io.File(args[i + 1]));
204              }
2050             else if ("-loglevel".equals(args[i]))
206              {
2070                setLoglevel(args[i + 1]);
208              }
209              else
210              {
2110                throw new IllegalArgumentException(
212                         "Invalid argument '" + args[i] + "'");
213              }
2140             i += 1 /* command */ + 1 /* argument */;
215           }
216        }
2170       catch (IndexOutOfBoundsException e)
218        {
2190          final IllegalArgumentException ex
220                 = new IllegalArgumentException("Missing value for "
221                    + args[args.length - 1]);
2220          ex.initCause(e);
2230          throw ex;
224        }
2250       catch (Exception e)
226        {
2270          final IllegalArgumentException ex = new IllegalArgumentException(
228                 "Problem with argument value for " + args[args.length - 1]);
2290          ex.initCause(e);
2300          throw ex;
2310       }
2320    }
233  
234     private void setLoglevel (String loglevel)
235     {
2360        mLogLevel = Level.parse(loglevel);
2370        LoggingUtils.setGlobalHandlerLogLevel(Level.ALL);
2380        logger.fine("Setting log level: " + mLogLevel);
2390        logger.setLevel(mLogLevel);
2400    }
241  
242  }

Findings in this File

w (1) 88 : 0 class org.jcoderz.phoenix.report.Report2Console defines fields that are used only as locals
d (2) 136 : 19 [deprecation] setValidating(boolean) in javax.xml.bind.Unmarshaller has been deprecated
c (3) 140 : 72 [unchecked] unchecked cast found : java.util.List required: java.util.List<org.jcoderz.phoenix.report.jaxb.File>
w (4) 161 : 0 Method org.jcoderz.phoenix.report.Report2Console.outputForFile(File) passes constant String of length 1 to character overridden method
c (5) 163 : 50 '+' is not followed by whitespace.
c (6) 166 : 71 [unchecked] unchecked cast found : java.util.List required: java.util.List<org.jcoderz.phoenix.report.jaxb.Item>
i (7) 169 : 0 Dead store to out in org.jcoderz.phoenix.report.Report2Console.outputForFile(File)
c (8) 183 : 19 Variable 'severityString' should be declared final.
c (9) 188 : 39 '+' should be on a new line.