1 25 package classycle.ant; 26 27 import java.io.File ; 28 import java.io.FileWriter ; 29 import java.io.PrintWriter ; 30 import java.util.HashSet ; 31 32 import org.apache.tools.ant.BuildException; 33 34 import classycle.Analyser; 35 36 102 public class ReportTask extends ClassycleTask 103 { 104 public static final String TYPE_RAW = "raw", 105 TYPE_CSV = "csv", 106 TYPE_XML = "xml"; 107 private static final HashSet TYPES = new HashSet (); 108 109 static 110 { 111 TYPES.add(TYPE_RAW); 112 TYPES.add(TYPE_CSV); 113 TYPES.add(TYPE_XML); 114 } 115 116 private boolean _packagesOnly; 117 private String _reportFile; 118 private String _reportType = TYPE_XML; 119 private String _title; 120 121 public void setPackagesOnly(boolean packagesOnly) 122 { 123 _packagesOnly = packagesOnly; 124 } 125 126 public void setReportFile(String xmlFile) 127 { 128 _reportFile = xmlFile; 129 } 130 131 public void setReportType(String csvFile) 132 { 133 _reportType = csvFile; 134 } 135 136 public void setTitle(String title) 137 { 138 _title = title; 139 } 140 141 public void execute() throws BuildException 142 { 143 super.execute(); 144 145 if (!TYPES.contains(_reportType)) 146 { 147 throw new BuildException("invalid attribute 'reportType': " 148 + _reportType); 149 } 150 if (_reportFile == null) 151 { 152 throw new BuildException("missing attribute 'reportFile'."); 153 } 154 155 String [] classFiles = getClassFileNames(); 156 if (classFiles.length > 0 && _title == null) 157 { 158 _title = classFiles[0]; 159 } 160 Analyser analyser = new Analyser(classFiles, getPattern(), 161 getReflectionPattern(), 162 isMergeInnerClasses()); 163 try 164 { 165 analyser.readAndAnalyse(_packagesOnly); 166 File f = new File (getOwningTarget().getProject().getBaseDir(), 167 _reportFile); 168 PrintWriter writer = new PrintWriter (new FileWriter (f)); 169 if (_reportType.equals(TYPE_XML)) 170 { 171 analyser.printXML(_title, _packagesOnly, writer); 172 } else if (_reportType.equals(TYPE_CSV)) 173 { 174 analyser.printCSV(writer); 175 } else if (_reportType.equals(TYPE_RAW)) 176 { 177 analyser.printRaw(writer); 178 } 179 } catch (Exception e) 180 { 181 throw new BuildException(e); 182 } 183 } 184 } | Popular Tags |