Coverage Report - net.objectlab.qalab.parser.CheckstyleOrPMDBaseMerge
 
Classes in this File Line Coverage Branch Coverage Complexity
CheckstyleOrPMDBaseMerge
100%
22/22
100%
6/6
2
 
 1  
 ////////////////////////////////////////////////////////////////////////////////
 2  
 //
 3  
 //                  ObjectLab is sponsoring QALab
 4  
 // 
 5  
 // Based in London, we are world leaders in the design and development 
 6  
 // of bespoke applications for the Securities Financing markets.
 7  
 // 
 8  
 // <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
 9  
 //           ___  _     _           _   _          _
 10  
 //          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
 11  
 //         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
 12  
 //         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
 13  
 //          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
 14  
 //                   |__/
 15  
 //
 16  
 //                   http://www.ObjectLab.co.uk
 17  
 // ---------------------------------------------------------------------------
 18  
 //
 19  
 //QALab is released under the GNU General Public License.
 20  
 //
 21  
 //QALab: Collects QA Statistics from your build over time.
 22  
 //2005+, ObjectLab Ltd
 23  
 //
 24  
 //This library is free software; you can redistribute it and/or
 25  
 //modify it under the terms of the GNU General Public
 26  
 //License as published by the Free Software Foundation; either
 27  
 //version 2.1 of the License, or (at your option) any later version.
 28  
 //
 29  
 //This library is distributed in the hope that it will be useful,
 30  
 //but WITHOUT ANY WARRANTY; without even the implied warranty of
 31  
 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 32  
 //General Public License for more details.
 33  
 //
 34  
 //You should have received a copy of the GNU General Public
 35  
 //License along with this library; if not, write to the Free Software
 36  
 //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 37  
 //
 38  
 ////////////////////////////////////////////////////////////////////////////////
 39  
 package net.objectlab.qalab.parser;
 40  
 
 41  
 import net.objectlab.qalab.util.FilenameUtil;
 42  
 import net.objectlab.qalab.util.Util;
 43  
 
 44  
 import org.xml.sax.Attributes;
 45  
 import org.xml.sax.SAXException;
 46  
 
 47  
 /**
 48  
  * This abstract class defines most common code between the handling of
 49  
  * Checkstyle and PMD XML.
 50  
  *
 51  
  * @author Benoit Xhenseval
 52  
  * @version $Revision: 187 $
 53  
  */
 54  66
 public abstract class CheckstyleOrPMDBaseMerge extends BaseStatMerge {
 55  
     /**
 56  
      * At the start of a new element, capture the filename and if the element
 57  
      * is a result one, create a SingleStat to store for the given type.
 58  
      * @param ignoreNamespaceURI ignore (present for interface implementation).
 59  
      * @param localname name of the current element.
 60  
      * @param qualifiedname element name.
 61  
      * @param attrs the XML attribute of the current element.
 62  
      * @throws SAXException any SAX issue
 63  
      */
 64  
     public final void startElement(final String ignoreNamespaceURI, // NOPMD
 65  
         final String localname, final String qualifiedname,
 66  
         final Attributes attrs)
 67  
         throws SAXException {
 68  4053
         String local = localname;
 69  
 
 70  4053
         if ("".equals(local)) {
 71  4053
             local = qualifiedname;
 72  
         }
 73  
 
 74  
 //        if (!isQuiet()) {
 75  
 //            getTaskLogger().log("Start :" + local);
 76  
 //        }
 77  
 
 78  4053
         if (getFileTag().equals(local)) {
 79  
             // this is the start of a new file.
 80  762
             resetFileStatistics();
 81  762
             incrementFileCount(1);
 82  762
             setFileName(attrs);
 83  4053
         } if (getViolationTag().equals(local)) {
 84  
             // this is the start of a new error
 85  3210
             addFileStatistics(1);
 86  
         }
 87  4053
     }
 88  
 
 89  
     /**
 90  
      * At the end of an element, check if it is a file one and add the
 91  
      * results found.
 92  
      * @param ignoreNamespaceURI ignore (present for interface implementation).
 93  
      * @param ignoreSimplename ignore (present for interface implementation).
 94  
      * @param qualifiedname the name of the element.
 95  
      * @throws SAXException any SAX issue
 96  
      */
 97  
     public final void endElement(final String ignoreNamespaceURI, // NOPMD
 98  
         final String ignoreSimplename, final String qualifiedname) // NOPMD
 99  
         throws SAXException {
 100  
 //        if (!isQuiet()) {
 101  
 //            getTaskLogger().log("End :" + qualifiedname);
 102  
 //        }
 103  
 
 104  4053
         if (getFileTag().equals(qualifiedname)) {
 105  762
             addNewResults();
 106  
         }
 107  4053
     }
 108  
 
 109  
     /**
 110  
      * @return the tag for "file"
 111  
      */
 112  
     protected abstract String getFileTag();
 113  
 
 114  
     /**
 115  
      * @return the attribute name for fileName
 116  
      */
 117  
     protected abstract String getFileNameAttribute();
 118  
 
 119  
     /**
 120  
      * @return tag for a violation/error
 121  
      */
 122  
     protected abstract String getViolationTag();
 123  
 
 124  
     /**
 125  
      * set the file name from the attributes from Checkstyle/Findbugs XML.
 126  
      * @param att xml attributes
 127  
      */
 128  
     protected void setFileName(final Attributes att) {
 129  732
         String fileName = Util.getAttributeValue(att, getFileNameAttribute(),
 130  
                 isQuiet(), getTaskLogger());
 131  
 
 132  732
         if (!isQuiet()) {
 133  732
             getTaskLogger().log("File:" + fileName);
 134  
         }
 135  
 
 136  732
         fileName = FilenameUtil.trimFilename(fileName, getSrcDir());
 137  
 
 138  732
         if (!isQuiet()) {
 139  732
             getTaskLogger().log("setCurrentFileName FILE [" + fileName
 140  
                 + "] srcDir [" + getSrcDir() + "]");
 141  
         }
 142  
 
 143  732
         setCurrentFile(fileName);
 144  732
     }
 145  
 }
 146  
 /*
 147  
  *                   ObjectLab is sponsoring QALab
 148  
  * 
 149  
  * Based in London, we are world leaders in the design and development 
 150  
  * of bespoke applications for the securities financing markets.
 151  
  * 
 152  
  * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
 153  
  *           ___  _     _           _   _          _
 154  
  *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
 155  
  *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
 156  
  *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
 157  
  *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
 158  
  *                   |__/
 159  
  *
 160  
  *                     www.ObjectLab.co.uk
 161  
  */