Search in sources :

Example 6 with Marker

use of org.eclipse.titanium.markers.handler.Marker 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 Marker

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

the class XlsProblemExporter method createCodeSmellSheet.

/**
 * Create a page for a code smell.
 *
 * @param workbook the workbook to work in.
 * @param mh the markerhandler object knowing the occurences of the given code smell
 * @param t the codesmell type to export
 * @param fullPath the resource names should use full path or project relative
 */
private void createCodeSmellSheet(final HSSFWorkbook workbook, final MarkerHandler mh, final CodeSmellType t, final boolean fullPath) {
    if (mh.get(t).isEmpty()) {
        return;
    }
    final String sheetName = t.name();
    final HSSFSheet sheet = workbook.createSheet(sheetName);
    Row row = sheet.createRow(0);
    row.createCell(0).setCellValue("Description");
    row.createCell(1).setCellValue("Resource");
    row.createCell(2).setCellValue("Location");
    int currentRow = 1;
    Cell label;
    for (final Marker m : mh.get(t)) {
        if (m.getLine() == -1 || m.getResource() == null) {
            // TODO this might need a second thought
            continue;
        }
        try {
            row = sheet.createRow(currentRow);
            label = row.createCell(0);
            label.setCellValue(m.getMessage());
            label = row.createCell(1);
            if (fullPath) {
                label.setCellValue(m.getResource().getFullPath().toString());
            } else {
                label.setCellValue(m.getResource().getName());
            }
            label = row.createCell(2);
            label.setCellValue(m.getLine());
            ++currentRow;
        } catch (Exception e) {
            ErrorReporter.logWarning("Only " + currentRow + " rows were written: the limit has been reached.");
            break;
        }
    }
    sheet.autoSizeColumn(0);
    sheet.autoSizeColumn(1);
    sheet.autoSizeColumn(2);
}
Also used : HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) Row(org.apache.poi.ss.usermodel.Row) IMarker(org.eclipse.core.resources.IMarker) Marker(org.eclipse.titanium.markers.handler.Marker) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) Cell(org.apache.poi.ss.usermodel.Cell) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException)

Aggregations

Marker (org.eclipse.titanium.markers.handler.Marker)7 List (java.util.List)5 MarkerHandler (org.eclipse.titanium.markers.handler.MarkerHandler)5 ArrayList (java.util.ArrayList)4 IResource (org.eclipse.core.resources.IResource)4 SubMonitor (org.eclipse.core.runtime.SubMonitor)4 HashMap (java.util.HashMap)3 IMarker (org.eclipse.core.resources.IMarker)3 IOException (java.io.IOException)2 IProject (org.eclipse.core.resources.IProject)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 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1