|
From: <be...@us...> - 2007-05-03 16:29:29
|
Revision: 298
http://svn.sourceforge.net/qalab/?rev=298&view=rev
Author: benoitx
Date: 2007-05-03 09:29:24 -0700 (Thu, 03 May 2007)
Log Message:
-----------
For some reason Eclipse did not see my changes... and refused to check them in...
Added Paths:
-----------
trunk/qalab/src/main/java/net/objectlab/qalab/parser/FindBugsStatMerge.java
Removed Paths:
-------------
trunk/qalab/src/main/java/net/objectlab/qalab/parser/FindBugsStatMerge.java
Deleted: trunk/qalab/src/main/java/net/objectlab/qalab/parser/FindBugsStatMerge.java
===================================================================
--- trunk/qalab/src/main/java/net/objectlab/qalab/parser/FindBugsStatMerge.java 2007-04-29 08:31:15 UTC (rev 297)
+++ trunk/qalab/src/main/java/net/objectlab/qalab/parser/FindBugsStatMerge.java 2007-05-03 16:29:24 UTC (rev 298)
@@ -1,131 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////
-//
-// ObjectLab is sponsoring QALab
-//
-// Based in London, we are world leaders in the design and development
-// of bespoke applications for the Securities Financing markets.
-//
-// <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
-// ___ _ _ _ _ _
-// / _ \| |__ (_) ___ ___| |_| | __ _| |__
-// | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
-// | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
-// \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
-// |__/
-//
-// http://www.ObjectLab.co.uk
-// ---------------------------------------------------------------------------
-//
-//QALab is released under the GNU General Public License.
-//
-//QALab: Collects QA Statistics from your build over time.
-//2005+, ObjectLab Ltd
-//
-//This library is free software; you can redistribute it and/or
-//modify it under the terms of the GNU General Public
-//License as published by the Free Software Foundation; either
-//version 2.1 of the License, or (at your option) any later version.
-//
-//This library is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-//General Public License for more details.
-//
-//You should have received a copy of the GNU General Public
-//License along with this library; if not, write to the Free Software
-//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-////////////////////////////////////////////////////////////////////////////////
-package net.objectlab.qalab.parser;
-
-import net.objectlab.qalab.util.Util;
-
-import org.xml.sax.Attributes;
-
-/**
- * This class is able to read the XDOC output from FindBugs and integrate the
- * violation results into our qalab.xml format.
- *
- * @see <a href="http://findbugs.sourceforge.net/">FindBugs at SourceForge</a>
- * @author Benoit Xhenseval
- * @version $Revision$
- */
-public class FindBugsStatMerge extends CheckstyleOrPMDBaseMerge {
- // ~ Methods
- // ------------------------------------------------------------------------
-
- /**
- * @return "file"
- */
- protected final String getFileTag() {
- return "file";
- }
-
- /**
- * @return classname
- */
- protected final String getFileNameAttribute() {
- return "classname";
- }
-
- /**
- * @return BugInstance
- */
- protected final String getViolationTag() {
- return "BugInstance";
- }
-
- /**
- * @return findbugs
- */
- public final String getType() {
- return "findbugs";
- }
-
- /**
- * Given the different ways that files can be stored on file system, this
- * method will remove anything part of the path up to the 'srcDir' given, it
- * should only retain the package name in java. For instance, for Findbugs
- * classname="net.objectlab.X" will be stored in the compiled stats as:
- * net/objectlab/A.java
- *
- * @param att
- * the XML attribute
- */
- protected final void setFileName(final Attributes att) {
- String fileName = Util.getAttributeValue(att, getFileNameAttribute(),
- isQuiet(), getTaskLogger());
-
- fileName = fileName.replace('.', '/');
-
- final int embeddedClass = fileName.indexOf("$");
-
- if (embeddedClass > 0) {
- fileName = fileName.substring(0, embeddedClass);
- }
-
- fileName += ".java";
-
- if (!isQuiet()) {
- getTaskLogger().log("setCurrentFileName FILE [" + fileName + "]");
- }
-
- setCurrentFile(fileName);
- }
-}
-/*
- * ObjectLab is sponsoring QALab
- *
- * Based in London, we are world leaders in the design and development
- * of bespoke applications for the securities financing markets.
- *
- * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
- * ___ _ _ _ _ _
- * / _ \| |__ (_) ___ ___| |_| | __ _| |__
- * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
- * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
- * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
- * |__/
- *
- * www.ObjectLab.co.uk
- */
Added: trunk/qalab/src/main/java/net/objectlab/qalab/parser/FindBugsStatMerge.java
===================================================================
--- trunk/qalab/src/main/java/net/objectlab/qalab/parser/FindBugsStatMerge.java (rev 0)
+++ trunk/qalab/src/main/java/net/objectlab/qalab/parser/FindBugsStatMerge.java 2007-05-03 16:29:24 UTC (rev 298)
@@ -0,0 +1,209 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// ObjectLab is sponsoring QALab
+//
+// Based in London, we are world leaders in the design and development
+// of bespoke applications for the Securities Financing markets.
+//
+// <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
+// ___ _ _ _ _ _
+// / _ \| |__ (_) ___ ___| |_| | __ _| |__
+// | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
+// | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
+// \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
+// |__/
+//
+// http://www.ObjectLab.co.uk
+// ---------------------------------------------------------------------------
+//
+//QALab is released under the GNU General Public License.
+//
+//QALab: Collects QA Statistics from your build over time.
+//2005+, ObjectLab Ltd
+//
+//This library is free software; you can redistribute it and/or
+//modify it under the terms of the GNU General Public
+//License as published by the Free Software Foundation; either
+//version 2.1 of the License, or (at your option) any later version.
+//
+//This library is distributed in the hope that it will be useful,
+//but WITHOUT ANY WARRANTY; without even the implied warranty of
+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+//General Public License for more details.
+//
+//You should have received a copy of the GNU General Public
+//License along with this library; if not, write to the Free Software
+//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+////////////////////////////////////////////////////////////////////////////////
+package net.objectlab.qalab.parser;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import net.objectlab.qalab.util.Util;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+/**
+ * This is the new FindBugs Stat merger, able to handle BOTH xdoc and xml output from FindBugs.
+ *
+ * @author Benoit Xhenseval
+ * @version $Revision$
+ */
+public class FindBugsStatMerge extends BaseStatMerge {
+ private static final String TAG_BUG_COLLECTION = "BugCollection";
+ private static final String TAG_BUG_INSTANCE = "BugInstance";
+ private static final String TAG_CLASS_STATS = "ClassStats";
+ private static final String TAG_FILE = "file";
+ private static final String ATT_CLASSNAME = "classname";
+ private static final String ATT_CLASS_IN_SUMMARY = "class";
+ private static final String ATT_BUGS = "bugs";
+ private Map violationPerFile = new HashMap();
+
+ // used by the old XDOC format.
+ private String currentFile;
+ private boolean xdocFormatDetected = false;
+
+
+ /**
+ * At the start of a new element, capture the filename and if the element
+ * is a result one, create a SingleStat to store for the given type.
+ * @param ignoreNamespaceURI ignore (present for interface implementation).
+ * @param localname name of the current element.
+ * @param qualifiedname element name.
+ * @param attrs the XML attribute of the current element.
+ * @throws SAXException any SAX issue
+ */
+ public final void startElement(final String ignoreNamespaceURI, // NOPMD
+ final String localname, final String qualifiedname, final Attributes attrs) throws SAXException {
+ String local = localname;
+
+ if ("".equals(local)) {
+ local = qualifiedname;
+ }
+
+ //if (!isQuiet()) {
+ // getTaskLogger().log("Start :" + local);
+ //}
+
+ if (TAG_FILE.equals(local)) {
+ currentFile = getFileName(attrs, ATT_CLASSNAME);
+ if (!violationPerFile.containsKey(currentFile)) {
+ violationPerFile.put(currentFile, new Integer(0));
+ }
+ xdocFormatDetected = true;
+ } else if (TAG_CLASS_STATS.equals(local)) {
+ // new XML format
+ String fileName = getFileName(attrs, ATT_CLASS_IN_SUMMARY);
+ String bugs = Util.getAttributeValue(attrs, ATT_BUGS, isQuiet(), getTaskLogger());
+ int bug = Integer.parseInt(bugs);
+ if (bug > 0) {
+ Integer issue = (Integer) violationPerFile.get(fileName);
+ if (issue != null) {
+ bug += issue.intValue();
+ }
+ violationPerFile.put(fileName, new Integer(bug));
+ }
+ }
+
+ // for the XDOC, there is no summary, we need to COUNT the number of violations
+ if (xdocFormatDetected && TAG_BUG_INSTANCE.equals(local)) {
+ Integer issue = (Integer) violationPerFile.get(currentFile);
+ if (issue != null) {
+ violationPerFile.put(currentFile, new Integer(issue.intValue() + 1));
+ } else {
+ violationPerFile.put(currentFile, new Integer(1));
+ }
+ }
+ }
+
+ /**
+ * At the end of an element, check if it is a BugCollection one and add the
+ * all results found.
+ * @param ignoreNamespaceURI ignore (present for interface implementation).
+ * @param ignoreSimplename ignore (present for interface implementation).
+ * @param qualifiedname the name of the element.
+ * @throws SAXException any SAX issue
+ */
+ public final void endElement(final String ignoreNamespaceURI, // NOPMD
+ final String ignoreSimplename, final String qualifiedname) // NOPMD
+ throws SAXException {
+ // if (!isQuiet()) {
+ // getTaskLogger().log("End :" + qualifiedname);
+ // }
+
+ if (TAG_BUG_COLLECTION.equals(qualifiedname)) {
+ // now publish all statistics one file at a time.
+ setTotalStatistics(0);
+ incrementFileCount(violationPerFile.size());
+ for (Iterator it = violationPerFile.entrySet().iterator(); it.hasNext();) {
+ Map.Entry entry = (Entry) it.next();
+ resetFileStatistics();
+ setCurrentFile((String) entry.getKey());
+ addFileStatistics(((Integer) entry.getValue()).intValue());
+ addNewResults();
+ }
+ }
+ }
+
+ /**
+ * @return findbugs
+ */
+ public final String getType() {
+ return "findbugs";
+ }
+
+ /**
+ * Given the different ways that files can be stored on file system, this
+ * method will remove anything part of the path up to the 'srcDir' given, it
+ * should only retain the package name in java. For instance, for Findbugs
+ * classname="net.objectlab.X" will be stored in the compiled stats as:
+ * net/objectlab/A.java
+ *
+ * Please note that FindBugs may refer to internal classes too like
+ * net.objectlab.A$Key but we shall consider them to be in the same file
+ * net/objectlab/A.java
+ *
+ * @param att
+ * the XML attribute
+ */
+ protected final String getFileName(final Attributes att, final String attributeName) {
+ String fileName = Util.getAttributeValue(att, attributeName, isQuiet(), getTaskLogger());
+
+ fileName = fileName.replace('.', '/');
+
+ final int embeddedClass = fileName.indexOf("$");
+
+ if (embeddedClass > 0) {
+ fileName = fileName.substring(0, embeddedClass);
+ }
+
+ fileName += ".java";
+
+ if (!isQuiet()) {
+ getTaskLogger().log("setCurrentFileName FILE [" + fileName + "]");
+ }
+
+ return fileName;
+ }
+}
+/*
+ * ObjectLab is sponsoring QALab
+ *
+ * Based in London, we are world leaders in the design and development
+ * of bespoke applications for the securities financing markets.
+ *
+ * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
+ * ___ _ _ _ _ _
+ * / _ \| |__ (_) ___ ___| |_| | __ _| |__
+ * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
+ * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
+ * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
+ * |__/
+ *
+ * www.ObjectLab.co.uk
+ */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|