use of org.eclipse.titanium.markers.utils.RiskFactorCalculator in project titan.EclipsePlug-ins by eclipse.
the class XlsProblemExporter method exportMarkers.
/**
* Export the code smells of a project to an excel workbook.
* <p>
* The first sheet of the workbook is a summary page, showing the number of
* hits for each code smell, and an expressive bar chart of these data. The
* further sheets enumerate the specific code smells of each kind, including
* the message of the code smell, and the file name and line where it
* occurred.
* <p>
* Note: All code smell types are used in the analysis and are written in
* the output. Some code smells use external settings, which can be fine
* tuned on the preference page.
*
* @param filename
* the file to save the xls
* @param date
* the time stamp to write on the summary page
*
* @throws IOException
* when writing the file fails
*/
@Override
public // guaranteed to be initialized first.
void exportMarkers(final IProgressMonitor monitor, final String filename, final Date date) throws IOException {
final SubMonitor progress = SubMonitor.convert(monitor, 100);
final File file = new File(filename);
POIFSFileSystem fs = null;
HSSFWorkbook workbook = null;
try {
fs = new POIFSFileSystem(XlsProblemExporter.class.getResourceAsStream("ProblemMarkers.xlt"));
workbook = new HSSFWorkbook(fs, true);
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace("Error while exporting to excel", e);
// one (without the chart).
if (reportDebugInformation) {
TITANDebugConsole.println("Error on opening ProblemMarkers.xlt. Chartless xls will be generated");
}
workbook = new HSSFWorkbook(new FileInputStream(file));
workbook.createSheet("Summary");
workbook.setSheetOrder("Summary", 0);
} catch (Exception e) {
ErrorReporter.logExceptionStackTrace("Error while exporting to excel", e);
return;
}
progress.worked(10);
final List<IProject> projects = ProjectBasedBuilder.getProjectBasedBuilder(project).getAllReachableProjects();
projects.remove(project);
try {
final HSSFSheet summarySheet = workbook.getSheetAt(0);
createTimeSheet(workbook);
final Map<String, Integer> smellCount = new HashMap<String, Integer>();
int summaryRow = 4;
Cell label = null;
Cell numberCell = null;
final Map<TaskType, List<IMarker>> markers = collectMarkers();
// export the task markers:
for (final TaskType t : TaskType.values()) {
createTaskSheet(workbook, t, markers.get(t), projects.size() > 0);
final Row row1 = summarySheet.createRow(summaryRow++);
label = row1.createCell(0);
label.setCellValue(t.getHumanReadableName());
final int nofMarkers = markers.get(t).size();
numberCell = row1.createCell(1);
numberCell.setCellValue(nofMarkers);
// row-1 is the number of found markers
smellCount.put(t.name(), nofMarkers);
}
progress.worked(20);
final MarkerHandler mh = AnalyzerCache.withAll().analyzeProject(progress.newChild(30), project);
progress.setWorkRemaining(CodeSmellType.values().length + 1);
// export the semantic problem markers:
for (final CodeSmellType t : CodeSmellType.values()) {
createCodeSmellSheet(workbook, mh, t, projects.size() > 0);
final Row row1 = summarySheet.createRow(summaryRow++);
label = row1.createCell(0);
label.setCellValue(t.getHumanReadableName());
smellCount.put(t.name(), mh.numberOfOccurrences(t));
numberCell = row1.createCell(1);
numberCell.setCellValue(mh.numberOfOccurrences(t));
progress.worked(1);
}
final StringBuilder nameBuilder = new StringBuilder("Project: ");
nameBuilder.append(project.getName());
if (projects.size() > 0) {
nameBuilder.append(" including ( ");
for (int i = 0; i < projects.size(); i++) {
if (i > 0) {
nameBuilder.append(", ");
}
nameBuilder.append(projects.get(i).getName());
}
nameBuilder.append(" )");
}
final Row row0 = summarySheet.createRow(0);
row0.createCell(0).setCellValue(nameBuilder.toString());
final Row row1 = summarySheet.createRow(1);
row1.createCell(0).setCellValue("Code smell \\ date");
final CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("yyyy.mm.dd"));
label = row1.createCell(1);
label.setCellValue(date);
label.setCellStyle(cellStyle);
final Row row2 = summarySheet.createRow(2);
row2.createCell(0).setCellValue("Commulative Project Risk Factor");
final int riskFactor = new RiskFactorCalculator().measure(project, smellCount);
row2.createCell(1).setCellValue(riskFactor);
summarySheet.autoSizeColumn(0);
summarySheet.autoSizeColumn(1);
progress.worked(1);
} catch (Exception e) {
ErrorReporter.logExceptionStackTrace("Error while exporting to excel", e);
} finally {
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(file);
workbook.write(fileOutputStream);
} catch (Exception e) {
ErrorReporter.logExceptionStackTrace("Error while closing the generated excel", e);
} finally {
IOUtils.closeQuietly(fileOutputStream);
}
}
}
Aggregations