001: /*
002: * @(#)TestLogger.java
003: *
004: * Copyright (C) 2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.codecoverage.v2.logger;
028:
029: import java.util.ArrayList;
030: import java.util.HashMap;
031: import java.util.Iterator;
032: import java.util.List;
033:
034: import net.sourceforge.groboutils.codecoverage.v2.compiler.ParseCoverageLogger;
035:
036: /**
037: * Replacement logger.
038: *
039: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
040: * @version $Date: 2004/04/15 05:48:28 $
041: * @since January 27, 2003
042: */
043: public class TestLogger {
044: public static class MarkData {
045: public String classSig;
046: public short measureIndex;
047: public short methodIndex;
048: public short markIndex;
049:
050: public MarkData(String sig, short meaI, short metI, short marI) {
051: this .classSig = sig;
052: this .measureIndex = meaI;
053: this .methodIndex = metI;
054: this .markIndex = marI;
055: }
056:
057: public String toString() {
058: return "[Class Sig=" + this .classSig + ";measure="
059: + this .measureIndex + ";method=" + this .methodIndex
060: + ";mark=" + this .markIndex + "]";
061: }
062: }
063:
064: private static HashMap marksPerThread = new HashMap();
065:
066: public static ParseCoverageLogger createPCL() {
067: return new ParseCoverageLogger(TestLogger.class, "cover");
068: }
069:
070: public static void cover(String classSig, short methodIndex,
071: short channel, short markIndex) {
072: //DOC.getLog().info( "Inside cover" );
073: List list = getThreadList();
074: MarkData md = new MarkData(classSig, channel, methodIndex,
075: markIndex);
076: synchronized (list) {
077: //DOC.getLog().info( "adding mark: "+md );
078: list.add(md);
079: }
080: }
081:
082: public static void reset() {
083: List list = getThreadList();
084: synchronized (list) {
085: list.clear();
086: }
087: }
088:
089: public static int size() {
090: return getThreadList().size();
091: }
092:
093: public static Iterator getMarkData() {
094: return getThreadList().iterator();
095: }
096:
097: private static List getThreadList() {
098: List list;
099: synchronized (TestLogger.class) {
100: list = (List) marksPerThread.get(Thread.currentThread());
101: if (list == null) {
102: list = new ArrayList();
103: marksPerThread.put(Thread.currentThread(), list);
104: }
105: }
106: return list;
107: }
108: }
|