1 9 package com.vladium.emma.report; 10 11 import java.util.Iterator ; 12 import java.util.Set ; 13 import java.util.TreeSet ; 14 15 import com.vladium.logging.Logger; 16 import com.vladium.util.Descriptors; 17 import com.vladium.util.IProperties; 18 import com.vladium.util.IntIntMap; 19 import com.vladium.util.IntVector; 20 import com.vladium.util.ObjectIntMap; 21 import com.vladium.emma.EMMARuntimeException; 22 import com.vladium.emma.data.ClassDescriptor; 23 import com.vladium.emma.data.ICoverageData; 24 import com.vladium.emma.data.IMetaData; 25 26 30 public 31 abstract class AbstractReportGenerator extends AbstractItemVisitor 32 implements IReportGenerator 33 { 34 36 37 public static IReportGenerator create (final String type) 38 { 39 if ((type == null) || (type.length () == 0)) 40 throw new IllegalArgumentException ("null/empty input: type"); 41 42 44 if ("html".equals (type)) 45 return new com.vladium.emma.report.html.ReportGenerator (); 46 else if ("txt".equals (type)) 47 return new com.vladium.emma.report.txt.ReportGenerator (); 48 else if ("xml".equals (type)) 49 return new com.vladium.emma.report.xml.ReportGenerator (); 50 else throw new EMMARuntimeException ("no report generator class found for type [" + type + "]"); 52 } 53 54 55 public void initialize (final IMetaData mdata, final ICoverageData cdata, 56 final SourcePathCache cache, final IProperties properties) 57 throws EMMARuntimeException 58 { 59 m_log = Logger.getLogger (); 60 m_verbose = m_log.atVERBOSE (); 61 62 m_settings = ReportProperties.parseProperties (properties, getType ()); 63 64 m_cache = cache; 65 66 m_hasSrcFileInfo = mdata.hasSrcFileData (); 67 m_hasLineNumberInfo = mdata.hasLineNumberData (); 68 69 boolean debugInfoWarning = false; 70 boolean bailOut = false; 71 72 if (! mdata.hasSrcFileData () && (m_settings.getViewType () == IReportDataView.HIER_SRC_VIEW)) 74 { 75 debugInfoWarning = true; 76 77 m_log.warning ("not all instrumented classes were compiled with source file"); 78 m_log.warning ("debug data: no sources will be embedded in the report."); 79 80 m_settings.setViewType (IReportDataView.HIER_CLS_VIEW); 81 } 82 83 if (! m_hasLineNumberInfo) 85 { 86 final int [] userColumnIDs = m_settings.getColumnOrder (); 87 final IntVector columnIDs = new IntVector (); 88 89 boolean removed = false; 90 for (int c = 0; c < userColumnIDs.length; ++ c) 91 { 92 if (userColumnIDs [c] == IItemAttribute.ATTRIBUTE_LINE_COVERAGE_ID) 93 removed = true; 94 else 95 columnIDs.add (userColumnIDs [c]); 96 } 97 98 if (removed) 100 { 101 debugInfoWarning = true; 102 103 if (columnIDs.size () == 0) 104 { 105 m_log.warning ("line coverage requested in a report of type [" + getType () + "] but"); 106 m_log.warning ("not all instrumented classes were compiled with line number"); 107 m_log.warning ("debug data: since this was the only requested column, no report will be generated."); 108 109 bailOut = true; 110 } 111 else 112 { 113 m_log.warning ("line coverage requested in a report of type [" + getType () + "] but"); 114 m_log.warning ("not all instrumented classes were compiled with line number"); 115 m_log.warning ("debug data: this column will be removed from the report."); 116 117 m_settings.setColumnOrder (columnIDs.values ()); 118 119 final int [] userSort = m_settings.getSortOrder (); 120 final IntVector sort = new IntVector (); 121 122 for (int c = 0; c < userSort.length; c += 2) 123 { 124 if (Math.abs (userSort [c]) != IItemAttribute.ATTRIBUTE_LINE_COVERAGE_ID) 125 { 126 sort.add (userSort [c]); 127 sort.add (userSort [c + 1]); 128 } 129 } 130 131 m_settings.setSortOrder (sort.values ()); 132 } 133 } 134 } 135 137 if (debugInfoWarning && m_log.atINFO ()) 139 { 140 final Set sampleClassNames = new TreeSet (); 141 final ObjectIntMap countMap = new ObjectIntMap (); 142 final int [] _count = new int [1]; 143 144 for (Iterator descriptors = mdata.iterator (); descriptors.hasNext (); ) 145 { 146 final ClassDescriptor cls = (ClassDescriptor) descriptors.next (); 147 148 if (! cls.hasCompleteLineNumberInfo () || ! cls.hasSrcFileInfo ()) 150 { 151 final String packageVMName = cls.getPackageVMName (); 152 final int count = countMap.get (packageVMName, _count) 153 ? _count [0] 154 : 0; 155 156 if (count < MAX_DEBUG_INFO_WARNING_COUNT) 157 { 158 sampleClassNames.add (Descriptors.vmNameToJavaName (cls.getClassVMName ())); 159 countMap.put (packageVMName, count + 1); 160 } 161 } 162 } 163 164 m_log.info ("showing up to " + MAX_DEBUG_INFO_WARNING_COUNT + " classes without full debug info per package:"); 165 for (Iterator names = sampleClassNames.iterator (); names.hasNext (); ) 166 { 167 m_log.info (" " + names.next ()); 168 } 169 } 170 171 if (bailOut) 172 { 173 throw new EMMARuntimeException ("BAILED OUT"); 175 } 176 177 final IItemMetadata [] allTypes = IItemMetadata.Factory.getAllTypes (); 178 m_typeSortComparators = new ItemComparator [allTypes.length]; 179 180 for (int t = 0; t < allTypes.length; ++ t) 181 { 182 final IntVector orderedAttrIDsWithDir = new IntVector (); 183 final long typeAttrIDSet = allTypes [t].getAttributeIDs (); 184 185 for (int s = 0; s < m_settings.getSortOrder ().length; s += 2) 186 { 187 final int attrID = m_settings.getSortOrder () [s]; 188 189 if ((typeAttrIDSet & (1 << attrID)) != 0) 190 { 191 orderedAttrIDsWithDir.add (attrID); 192 193 final int dir = m_settings.getSortOrder () [s + 1]; 194 orderedAttrIDsWithDir.add (dir); 195 } 196 } 197 198 m_typeSortComparators [t] = ItemComparator.Factory.create (orderedAttrIDsWithDir.values (), m_settings.getUnitsType ()); 199 } 200 201 m_metrics = new int [allTypes.length]; 202 final IntIntMap metrics = m_settings.getMetrics (); 203 for (int t = 0; t < m_metrics.length; ++ t) 204 { 205 m_metrics [t] = -1; 206 metrics.get (t, m_metrics, t); 207 } 208 209 final IReportDataModel model = IReportDataModel.Factory.create (mdata, cdata); 210 m_view = model.getView (m_settings.getViewType ()); 211 212 m_srcView = (m_settings.getViewType () == IReportDataView.HIER_SRC_VIEW); 213 } 214 215 public void cleanup () 216 { 217 reset (); 218 } 219 220 222 223 protected void reset () 224 { 225 m_settings = null; 226 m_cache = null; 227 m_view = null; 228 m_srcView = false; 229 230 m_typeSortComparators = null; 232 m_metrics = null; 233 234 m_log = null; 235 } 236 237 238 protected ReportProperties.ParsedProperties m_settings; 239 protected SourcePathCache m_cache; 240 protected IReportDataView m_view; 241 protected boolean m_srcView; 242 243 protected boolean m_hasSrcFileInfo, m_hasLineNumberInfo; 244 protected ItemComparator [] m_typeSortComparators; protected int [] m_metrics; 247 protected Logger m_log; protected boolean m_verbose; 249 250 252 254 255 private static final int MAX_DEBUG_INFO_WARNING_COUNT = 3; 257 } | Popular Tags |