Search in sources :

Example 1 with BaseProblemExporter

use of org.eclipse.titanium.markers.export.BaseProblemExporter in project titan.EclipsePlug-ins by eclipse.

the class SonarDataExporter method exportCodeSmells.

private void exportCodeSmells(final URI exportDir) throws IOException {
    final URI filePath = URIUtil.append(exportDir, "code_smells.csv");
    final File file = new File(filePath);
    FileUtils.delete(file);
    final BaseProblemExporter exporter = new SingleCsvProblemExporter(project);
    exporter.exportMarkers(new NullProgressMonitor(), filePath.getPath(), Calendar.getInstance().getTime());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) BaseProblemExporter(org.eclipse.titanium.markers.export.BaseProblemExporter) SingleCsvProblemExporter(org.eclipse.titanium.markers.export.SingleCsvProblemExporter) URI(java.net.URI) File(java.io.File)

Example 2 with BaseProblemExporter

use of org.eclipse.titanium.markers.export.BaseProblemExporter in project titan.EclipsePlug-ins by eclipse.

the class ExportProblems method doExportProblems.

private void doExportProblems() {
    if (!(selection instanceof IStructuredSelection)) {
        return;
    }
    final IStructuredSelection structSelection = (IStructuredSelection) selection;
    if (structSelection.isEmpty()) {
        return;
    }
    final Object firstElement = structSelection.getFirstElement();
    if (!(firstElement instanceof IProject)) {
        ErrorReporter.logError("The export problems command needs to be called on a project ");
        return;
    }
    final IProject project = (IProject) firstElement;
    final IPreferencesService preferencesService = Platform.getPreferencesService();
    final boolean reportDebugInformation = preferencesService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    if (reportDebugInformation) {
        TITANDebugConsole.println("Problem markers are to export from " + project.getName());
    }
    boolean write = false;
    String fileName;
    final Shell shell = Display.getCurrent().getActiveShell();
    do {
        final FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        dialog.setText("Export problem markers to xls");
        dialog.setFilterExtensions(new String[] { "*.xls" });
        final IPath path = project.getLocation();
        if (path != null) {
            dialog.setFilterPath(path.toPortableString());
        }
        final Calendar now = Calendar.getInstance();
        dialog.setFileName("Problems--" + project.getName() + "--" + now.get(Calendar.YEAR) + "-" + (1 + now.get(Calendar.MONTH)) + "-" + now.get(Calendar.DAY_OF_MONTH));
        fileName = dialog.open();
        if (fileName != null) {
            if (new File(fileName).exists()) {
                write = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "File exist", "This file already exists. Please confirm overwrite.");
            } else {
                write = true;
            }
        } else {
            // User cancelled the file dialog, so we have nothing to do
            return;
        }
    } while (!write);
    final String fileName2 = fileName;
    new ProjectAnalyzerJob("Exporting reported code smells") {

        @Override
        public IStatus doPostWork(final IProgressMonitor monitor) {
            final BaseProblemExporter exporter = new XlsProblemExporter(getProject());
            try {
                exporter.exportMarkers(monitor, fileName2, Calendar.getInstance().getTime());
                if (reportDebugInformation) {
                    TITANDebugConsole.println("Successfully exported markers to xls");
                }
            } catch (IOException e) {
                ErrorReporter.logExceptionStackTrace("Error while exporting", e);
                if (reportDebugInformation) {
                    TITANDebugConsole.println("Failed to write xls");
                }
            }
            return Status.OK_STATUS;
        }
    }.quickSchedule(project);
}
Also used : XlsProblemExporter(org.eclipse.titanium.markers.export.XlsProblemExporter) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) Calendar(java.util.Calendar) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) ProjectAnalyzerJob(org.eclipse.titanium.utils.ProjectAnalyzerJob) IProject(org.eclipse.core.resources.IProject) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) BaseProblemExporter(org.eclipse.titanium.markers.export.BaseProblemExporter) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Aggregations

File (java.io.File)2 BaseProblemExporter (org.eclipse.titanium.markers.export.BaseProblemExporter)2 IOException (java.io.IOException)1 URI (java.net.URI)1 Calendar (java.util.Calendar)1 IProject (org.eclipse.core.resources.IProject)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 Shell (org.eclipse.swt.widgets.Shell)1 SingleCsvProblemExporter (org.eclipse.titanium.markers.export.SingleCsvProblemExporter)1 XlsProblemExporter (org.eclipse.titanium.markers.export.XlsProblemExporter)1 ProjectAnalyzerJob (org.eclipse.titanium.utils.ProjectAnalyzerJob)1