Search in sources :

Example 6 with MarkerHandler

use of org.eclipse.titanium.markers.handler.MarkerHandler in project titan.EclipsePlug-ins by eclipse.

the class SingleCsvProblemExporter method exportMarkers.

/**
 * @param monitor : The monitor that we use for feedback
 * @param path : The path of the file to be saved
 * @param date : The time stamp (not used currently)
 *
 * @see BaseProblemExporter#exportMarkers(IProgressMonitor, String, Date)
 */
@Override
public void exportMarkers(final IProgressMonitor monitor, final String path, final Date date) {
    final SubMonitor progress = SubMonitor.convert(monitor, 100);
    BufferedWriter summaryFile = null;
    try {
        summaryFile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(path)), "UTF-8"));
        final MarkerHandler mh = AnalyzerCache.withAll().analyzeProject(progress.newChild(30), project);
        for (final Map.Entry<IResource, List<Marker>> entry : mh.getMarkersByResource().entrySet()) {
            final IResource resource = entry.getKey();
            for (final Marker marker : entry.getValue()) {
                summaryFile.write(resource.getProjectRelativePath().toString());
                summaryFile.write(SEPARATOR);
                summaryFile.write(String.valueOf(marker.getLine()));
                summaryFile.write(SEPARATOR);
                summaryFile.write(marker.getProblemType().name());
                summaryFile.write(SEPARATOR);
                summaryFile.write(SEPARATOR);
                summaryFile.write(SEPARATOR);
                summaryFile.newLine();
            }
        }
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace("Error while exporting to CSV file: " + path, e);
    } finally {
        if (summaryFile != null) {
            try {
                summaryFile.close();
            } catch (IOException e) {
                ErrorReporter.logExceptionStackTrace("Error while closing the file: " + path, e);
            }
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) SubMonitor(org.eclipse.core.runtime.SubMonitor) OutputStreamWriter(java.io.OutputStreamWriter) List(java.util.List) Marker(org.eclipse.titanium.markers.handler.Marker) IOException(java.io.IOException) MarkerHandler(org.eclipse.titanium.markers.handler.MarkerHandler) File(java.io.File) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource) BufferedWriter(java.io.BufferedWriter)

Example 7 with MarkerHandler

use of org.eclipse.titanium.markers.handler.MarkerHandler 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);
        }
    }
}
Also used : HashMap(java.util.HashMap) TaskType(org.eclipse.titanium.markers.types.TaskType) List(java.util.List) MarkerHandler(org.eclipse.titanium.markers.handler.MarkerHandler) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) Cell(org.apache.poi.ss.usermodel.Cell) SubMonitor(org.eclipse.core.runtime.SubMonitor) IOException(java.io.IOException) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) FileInputStream(java.io.FileInputStream) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) CodeSmellType(org.eclipse.titanium.markers.types.CodeSmellType) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) FileOutputStream(java.io.FileOutputStream) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) Row(org.apache.poi.ss.usermodel.Row) CellStyle(org.apache.poi.ss.usermodel.CellStyle) File(java.io.File) RiskFactorCalculator(org.eclipse.titanium.markers.utils.RiskFactorCalculator)

Example 8 with MarkerHandler

use of org.eclipse.titanium.markers.handler.MarkerHandler in project titan.EclipsePlug-ins by eclipse.

the class ExecuteAnalyzer method workOnProject.

@Override
public void workOnProject(final IProgressMonitor monitor, final IProject project) {
    // If it is not enabled, do nothing
    if (!onTheFlyEnabled) {
        return;
    }
    // Otherwise analyze the project for code smells
    MarkerHandler mh;
    synchronized (project) {
        mh = AnalyzerCache.withPreference().analyzeProject(monitor, project);
    }
    // and show them
    mh.showAll(project);
}
Also used : MarkerHandler(org.eclipse.titanium.markers.handler.MarkerHandler)

Aggregations

MarkerHandler (org.eclipse.titanium.markers.handler.MarkerHandler)8 List (java.util.List)6 SubMonitor (org.eclipse.core.runtime.SubMonitor)5 Marker (org.eclipse.titanium.markers.handler.Marker)5 HashMap (java.util.HashMap)4 IProject (org.eclipse.core.resources.IProject)4 IResource (org.eclipse.core.resources.IResource)4 ArrayList (java.util.ArrayList)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 IMarker (org.eclipse.core.resources.IMarker)2 CoreException (org.eclipse.core.runtime.CoreException)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 Module (org.eclipse.titan.designer.AST.Module)2 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)2 CodeSmellType (org.eclipse.titanium.markers.types.CodeSmellType)2 TaskType (org.eclipse.titanium.markers.types.TaskType)2 BufferedWriter (java.io.BufferedWriter)1 FileInputStream (java.io.FileInputStream)1