Search in sources :

Example 1 with ProjectAnalyzerJob

use of org.eclipse.titanium.utils.ProjectAnalyzerJob 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)

Example 2 with ProjectAnalyzerJob

use of org.eclipse.titanium.utils.ProjectAnalyzerJob in project titan.EclipsePlug-ins by eclipse.

the class ExportDataForSonarAction method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPage iwPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final List<IProject> res = SelectionUtils.getProjectsFromSelection(iwPage.getSelection());
    for (final IProject project : res) {
        new ProjectAnalyzerJob("Exporting sonar data for project " + project.getName()) {

            @Override
            public IStatus doPostWork(final IProgressMonitor monitor) {
                try {
                    final SonarDataExporter exporter = new SonarDataExporter(project);
                    exporter.exportDataForProject();
                } catch (IOException e) {
                    ErrorReporter.logExceptionStackTrace("Error while exporting data for project " + project.getName(), e);
                }
                return Status.OK_STATUS;
            }
        }.quickSchedule(project);
    }
    return null;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) SonarDataExporter(org.eclipse.titanium.utils.SonarDataExporter) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IOException(java.io.IOException) ProjectAnalyzerJob(org.eclipse.titanium.utils.ProjectAnalyzerJob) IProject(org.eclipse.core.resources.IProject)

Example 3 with ProjectAnalyzerJob

use of org.eclipse.titanium.utils.ProjectAnalyzerJob in project titan.EclipsePlug-ins by eclipse.

the class InformationExporter method start.

@Override
public Object start(final IApplicationContext context) throws Exception {
    if (!GeneralConstants.DEBUG) {
        ErrorReporter.INTERNAL_ERROR("Experimental functionaility for the Titanium project");
    }
    Platform.getBundle("org.eclipse.titan.designer").start();
    final String[] args = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
    if (!checkParameters(args)) {
        return Integer.valueOf(-1);
    }
    if (args.length >= 1) {
        final File path = new File(args[0].substring(0, args[0].lastIndexOf(File.separator)));
        if (!path.exists() && !path.mkdirs()) {
            System.err.println("Couldn't create output directory!");
            return Integer.valueOf(-1);
        }
    }
    final List<IProject> existingProjects = getProjectsToHandle();
    for (final IProject project : existingProjects) {
        final ProjectAnalyzerJob job = new ProjectAnalyzerJob("Exporting information for project " + project.getName()) {

            @Override
            public IStatus doPostWork(final IProgressMonitor monitor) {
                System.out.println("Exporting information for " + getProject().getName());
                exportInformationForProject(args, getProject(), monitor);
                return Status.OK_STATUS;
            }
        }.quickSchedule(project);
        job.join();
    }
    boolean result = true;
    try {
        ResourcesPlugin.getWorkspace().save(true, null);
    } catch (Exception e) {
        ErrorReporter.logExceptionStackTrace("Error while closing workspace", e);
        result = false;
    }
    if (result) {
        if (args.length >= 1) {
            System.out.println("All informations are successfully exported to " + args[0].substring(0, args[0].lastIndexOf(File.separator)));
        } else {
            System.out.println("All information is succesfully exported.");
        }
        return EXIT_OK;
    } else {
        System.err.println("The export wasn't successfull, see zour workspace1s errorlog for details");
        return Integer.valueOf(-1);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) ProjectAnalyzerJob(org.eclipse.titanium.utils.ProjectAnalyzerJob) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Example 4 with ProjectAnalyzerJob

use of org.eclipse.titanium.utils.ProjectAnalyzerJob in project titan.EclipsePlug-ins by eclipse.

the class MetricsView method createHead.

private void createHead(final Composite head) {
    // upper composite, the head itself
    final GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    head.setLayout(layout);
    GridData g = new GridData(SWT.DEFAULT, 25);
    g.grabExcessHorizontalSpace = true;
    g.horizontalAlignment = SWT.FILL;
    head.setLayoutData(g);
    // project selector in the head
    projectSelector = new Combo(head, SWT.READ_ONLY);
    for (final IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
        if (TITANNature.hasTITANNature(project)) {
            projectSelector.add(project.getName());
        }
    }
    projectSelector.select(0);
    g = new GridData();
    g.horizontalAlignment = SWT.FILL;
    g.grabExcessHorizontalSpace = true;
    projectSelector.setLayoutData(g);
    // refresh button in the head
    refresh = new Button(head, SWT.NONE);
    refresh.setImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "resources/icons/metrics_start_measure.gif").createImage());
    refresh.setToolTipText(REFRESH_TOOLTIP);
    refresh.setLayoutData(new GridData(SWT.DEFAULT, 25));
    refresh.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(final SelectionEvent event) {
            final String selectedProjectName = projectSelector.getText();
            if ("".equals(selectedProjectName)) {
                // Nothing is selected (probably there are no projects in
                // the project browser);
                data = null;
                refreshData();
                return;
            }
            // Analyze project.
            // To avoid further analysis requests, disable the refresh
            // button.
            refresh.setEnabled(false);
            final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(selectedProjectName);
            if (project == null) {
                data = null;
                refreshData();
                return;
            }
            new ProjectAnalyzerJob("Metrics calculations") {

                @Override
                public IStatus doPostWork(final IProgressMonitor monitor) {
                    try {
                        data = MetricData.measure(project);
                        Display.getDefault().syncExec(new Runnable() {

                            @Override
                            public void run() {
                                refreshData();
                                export.setEnabled(true);
                            }
                        });
                        return Status.OK_STATUS;
                    } finally {
                        // The view should recover from any unexpected
                        // error, so
                        // the refresh button should not remain
                        // disabled.
                        Display.getDefault().syncExec(new Runnable() {

                            @Override
                            public void run() {
                                refresh.setEnabled(true);
                            }
                        });
                    }
                }
            }.quickSchedule(project);
        }

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
        // Do nothing
        }
    });
    createExportToXlsButton(head);
    final IResourceChangeListener PROJECT_CLOSE_LISTENER = new IResourceChangeListener() {

        @Override
        public void resourceChanged(final IResourceChangeEvent event) {
            switch(event.getType()) {
                case IResourceChangeEvent.PRE_CLOSE:
                case IResourceChangeEvent.PRE_DELETE:
                    final IResource resource = event.getResource();
                    // projectSelector.getText();
                    Display.getDefault().syncExec(new Runnable() {

                        @Override
                        public void run() {
                            if (projectSelector == null || projectSelector.isDisposed()) {
                                return;
                            }
                            projectSelector.deselectAll();
                            projectSelector.removeAll();
                            for (final IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
                                if (!project.equals(resource.getProject()) && TITANNature.hasTITANNature(project)) {
                                    projectSelector.add(project.getName());
                                }
                            }
                            data = null;
                            refreshData();
                        }
                    });
                    break;
                default:
                    break;
            }
        }
    };
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    workspace.addResourceChangeListener(PROJECT_CLOSE_LISTENER);
}
Also used : Combo(org.eclipse.swt.widgets.Combo) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) ProjectAnalyzerJob(org.eclipse.titanium.utils.ProjectAnalyzerJob) IProject(org.eclipse.core.resources.IProject) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) Button(org.eclipse.swt.widgets.Button) IWorkspace(org.eclipse.core.resources.IWorkspace) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IResource(org.eclipse.core.resources.IResource) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 5 with ProjectAnalyzerJob

use of org.eclipse.titanium.utils.ProjectAnalyzerJob in project titan.EclipsePlug-ins by eclipse.

the class TopView method createHead.

private void createHead(final Composite head) {
    // upper composite, the head itself
    final GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    head.setLayout(layout);
    GridData g = new GridData(SWT.DEFAULT, 35);
    g.grabExcessHorizontalSpace = true;
    g.horizontalAlignment = SWT.FILL;
    head.setLayoutData(g);
    // project selector in the head
    projectSelector = new Combo(head, SWT.READ_ONLY);
    for (final IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
        if (TITANNature.hasTITANNature(project)) {
            projectSelector.add(project.getName());
        }
    }
    projectSelector.select(0);
    g = new GridData();
    g.horizontalAlignment = SWT.FILL;
    g.grabExcessHorizontalSpace = true;
    projectSelector.setLayoutData(g);
    // refresh button in the head
    refresh = new Button(head, SWT.NONE);
    refresh.setImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "resources/icons/metrics_start_measure.gif").createImage());
    refresh.setToolTipText(REFRESH_TOOLTIP);
    refresh.setLayoutData(new GridData(SWT.DEFAULT, 25));
    refresh.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(final SelectionEvent event) {
            final String selectedProjectName = projectSelector.getText();
            if ("".equals(selectedProjectName)) {
                // the project browser);
                return;
            }
            // Analyze project.
            // To avoid further analysis requests, disable the refresh
            // button.
            final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(selectedProjectName);
            if (project != null) {
                refresh.setEnabled(false);
                new ProjectAnalyzerJob("Metrics calculations") {

                    private Set<IMetricEnum> metrics;

                    @Override
                    public IStatus doPreWork(final IProgressMonitor monitor) {
                        // choose metrics
                        final MetricSelectorDialog mst = new MetricSelectorDialog();
                        Display.getDefault().syncExec(mst);
                        metrics = mst.getUsed();
                        return Status.OK_STATUS;
                    }

                    @Override
                    public IStatus doPostWork(final IProgressMonitor monitor) {
                        try {
                            mw = WrapperStore.getWrapper(getProject());
                            if (!moduleTable.isDisposed()) {
                                Display.getDefault().syncExec(new Runnable() {

                                    @Override
                                    public void run() {
                                        createTable(metrics);
                                    }
                                });
                            }
                            return Status.OK_STATUS;
                        } finally {
                            // disabled.
                            if (!refresh.isDisposed()) {
                                Display.getDefault().syncExec(new Runnable() {

                                    @Override
                                    public void run() {
                                        refresh.setEnabled(true);
                                    }
                                });
                            }
                        }
                    }
                }.quickSchedule(project);
            }
        }

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
        // Do nothing
        }
    });
}
Also used : Set(java.util.Set) Combo(org.eclipse.swt.widgets.Combo) ProjectAnalyzerJob(org.eclipse.titanium.utils.ProjectAnalyzerJob) IProject(org.eclipse.core.resources.IProject) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

IProject (org.eclipse.core.resources.IProject)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 ProjectAnalyzerJob (org.eclipse.titanium.utils.ProjectAnalyzerJob)5 IStatus (org.eclipse.core.runtime.IStatus)3 File (java.io.File)2 IOException (java.io.IOException)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Combo (org.eclipse.swt.widgets.Combo)2 Calendar (java.util.Calendar)1 Set (java.util.Set)1 IResource (org.eclipse.core.resources.IResource)1 IResourceChangeEvent (org.eclipse.core.resources.IResourceChangeEvent)1 IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IPath (org.eclipse.core.runtime.IPath)1 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)1