Project Report: fawkez

Packagesummary org.jcoderz.phoenix.report

org.jcoderz.phoenix.report.FindBugsFindingType

LineHitsNoteSource
1  /*
2   * $Id: FindBugsFindingType.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  
36  import java.util.Iterator;
37  import java.util.logging.Logger;
38  
39  import javax.xml.bind.JAXBContext;
40  import javax.xml.bind.JAXBException;
41  import javax.xml.bind.Unmarshaller;
42  
43  import org.jcoderz.phoenix.findbugs.message.jaxb.BugPatternType;
44  import org.jcoderz.phoenix.findbugs.message.jaxb.MessageCollection;
45  
46  
47  /**
48   * Holds and registers findbugs specific detectors.
49   * 
50   * @author Michael Griffel
51   */
52  public final class FindBugsFindingType extends FindingType
53  {
54100     private static final String CLASSNAME
55          = FindBugsFindingType.class.getName();
56  
57100     private static final Logger logger = Logger.getLogger(CLASSNAME);
58  
59      private static final String FINDBUGS_MESSAGE_JAXB_CONTEXT
60          = "org.jcoderz.phoenix.findbugs.message.jaxb";
61  
62      /** FindBugs coreplugin. */
63      private static final String FINDBUGS_MESSAGE_FILE
64          = "org/jcoderz/phoenix/findbugs/messages.xml";
65  
66      /** FindBugs fb-contrib plugin. */
67      private static final String FB_CONTRIB_MESSAGE_FILE
68          = "org/jcoderz/phoenix/findbugs/fb-contrib-messages.xml";
69  
70      private final String mMessagePattern;
71  
72      private FindBugsFindingType (String symbol, String shortText,
73              String description, String messagePattern)
74      {
75100         super(symbol, shortText, description);
76100         mMessagePattern = messagePattern;
77100     }
78  
79      private FindBugsFindingType (BugPatternType e)
80      {
81100         this(e.getType(), e.getShortDescription(), e.getDetails(),
82                  e.getLongDescription());
83100     }
84  
85      /**
86       * Call this method to register all findbugs detectors.
87       */
88      public static void initialize ()
89      {
90          try
91          {
92100             registerDetectors(FINDBUGS_MESSAGE_FILE);
93100             registerDetectors(FB_CONTRIB_MESSAGE_FILE);
94          }
950         catch (JAXBException e)
96          {
970             throw new RuntimeException(
98                      "Cannot initialize FindBugsFindingTypes", e);
99100         }
100100     }
101  
102      /**
103       * @return the message pattern associated to this finding type.
104       */
105      public String getMessagePattern ()
106      {
1070         return mMessagePattern;
108      }
109  
110      private static void registerDetectors (String messagesFile)
111              throws JAXBException
112      {
113100         final JAXBContext jaxbContext
114              = JAXBContext.newInstance(FINDBUGS_MESSAGE_JAXB_CONTEXT,
115                      FindBugsFindingType.class.getClassLoader());
116  
117100         logger.finest("Try to unmarshalling " + messagesFile);
118  
119100         final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
120100         final MessageCollection messageCollection
121              = (MessageCollection) unmarshaller.unmarshal(
122                      FindBugsFindingType.class.getClassLoader()
123                          .getResourceAsStream(messagesFile));
124  
125100         for (final Iterator iter = messageCollection.getContent().iterator();
126100                 iter.hasNext();)
127          {
128100             final Object obj = iter.next();
129100             if (obj instanceof BugPatternType)
130              {
131100                 new FindBugsFindingType((BugPatternType) obj);
132              }
133100         }
134100     }
135  }

Findings in this File

w (1) org.jcoderz.phoenix.report.FindBugsFindingType doesn't override FindingType.equals(Object)