Search in sources :

Example 1 with FileSet

use of net.sf.eclipsecs.core.projectconfig.FileSet in project eclipse-cs by checkstyle.

the class CheckstyleBuilder method handleBuildSelection.

/**
 * Builds the selected resources.
 *
 * @param resources
 *          the resourcesto build
 * @param configuration
 *          the project configuration
 * @param monitor
 *          the progress monitor
 * @param project
 *          the built project
 * @param kind
 *          the kind of build
 * @param <T>
 *          the resource type parameter
 * @throws CoreException
 *           if the build fails
 */
public final <T extends IResource> void handleBuildSelection(final Collection<T> resources, final IProjectConfiguration configuration, final IProgressMonitor monitor, final IProject project, final int kind) throws CoreException {
    // on full build remove all previous checkstyle markers
    if (kind == IncrementalProjectBuilder.FULL_BUILD) {
        project.deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_INFINITE);
    }
    boolean backgroundFullBuild = CheckstylePluginPrefs.getBoolean(CheckstylePluginPrefs.PREF_BACKGROUND_FULL_BUILD);
    try {
        // 
        // Build a set of auditors from the file sets of this project
        // configuration.
        // File sets that share the same check configuration merge into
        // one Auditor.
        // 
        List<FileSet> fileSets = configuration.getFileSets();
        Map<ICheckConfiguration, Auditor> audits = new HashMap<>();
        for (FileSet fileSet : fileSets) {
            // skip not enabled filesets
            if (!fileSet.isEnabled()) {
                continue;
            }
            ICheckConfiguration checkConfig = fileSet.getCheckConfig();
            if (checkConfig == null) {
                throw new CheckstylePluginException(NLS.bind(Messages.errorNoCheckConfig, project.getName()));
            }
            // get an already created audit from the map
            Auditor audit = audits.get(checkConfig);
            // create the audit with the file sets check configuration
            if (audit == null) {
                audit = new Auditor(checkConfig);
                audits.put(checkConfig, audit);
            }
            // check which files belong to the file set
            for (IResource resource : resources) {
                if (resource instanceof IFile) {
                    IFile file = (IFile) resource;
                    // if file set includes file add to the audit
                    if (fileSet.includesFile(file)) {
                        audit.addFile(file);
                        // remove markers on this file
                        file.deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_ZERO);
                        // remove markers from package to prevent
                        // packagehtml messages from accumulatin
                        file.getParent().deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_ZERO);
                    }
                }
            }
        }
        // run all auditors
        for (Auditor audit : audits.values()) {
            if (monitor.isCanceled()) {
                throw new OperationCanceledException();
            }
            if (backgroundFullBuild && kind == FULL_BUILD) {
                AuditorJob j = new AuditorJob(project, audit);
                j.schedule();
            } else {
                audit.runAudit(project, monitor);
            }
        }
    } catch (CheckstylePluginException e) {
        Status status = new Status(IStatus.ERROR, CheckstylePlugin.PLUGIN_ID, IStatus.ERROR, e.getLocalizedMessage(), e);
        throw new CoreException(status);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IFile(org.eclipse.core.resources.IFile) FileSet(net.sf.eclipsecs.core.projectconfig.FileSet) ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) HashMap(java.util.HashMap) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) AuditorJob(net.sf.eclipsecs.core.jobs.AuditorJob) CoreException(org.eclipse.core.runtime.CoreException) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) IResource(org.eclipse.core.resources.IResource)

Example 2 with FileSet

use of net.sf.eclipsecs.core.projectconfig.FileSet in project eclipse-cs by checkstyle.

the class ComplexFileSetsEditor method editFileSet.

private void editFileSet() {
    IStructuredSelection selection = (IStructuredSelection) mViewer.getSelection();
    FileSet fileSet = (FileSet) selection.getFirstElement();
    if (fileSet == null) {
        // 
        return;
    }
    try {
        FileSetEditDialog dialog = new FileSetEditDialog(mComposite.getShell(), fileSet.clone(), mProject, mPropertyPage);
        if (Window.OK == dialog.open()) {
            FileSet newFileSet = dialog.getFileSet();
            mFileSets.remove(fileSet);
            mFileSets.add(newFileSet);
            mViewer.refresh();
            mViewer.setChecked(newFileSet, newFileSet.isEnabled());
            mPropertyPage.getContainer().updateButtons();
        }
    } catch (CheckstylePluginException e) {
        CheckstyleUIPlugin.errorDialog(mComposite.getShell(), NLS.bind(Messages.errorFailedEditFileset, e.getMessage()), e, true);
    }
}
Also used : FileSet(net.sf.eclipsecs.core.projectconfig.FileSet) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 3 with FileSet

use of net.sf.eclipsecs.core.projectconfig.FileSet in project eclipse-cs by checkstyle.

the class ComplexFileSetsEditor method createContents.

/**
 * {@inheritDoc}
 */
@Override
public Control createContents(Composite parent) throws CheckstylePluginException {
    mComposite = parent;
    Group composite = new Group(parent, SWT.NONE);
    composite.setText(Messages.ComplexFileSetsEditor_titleAdvancedFilesetEditor);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    composite.setLayout(layout);
    // 
    // Create the table of file sets.
    // 
    Table table = new Table(composite, SWT.CHECK | SWT.BORDER | SWT.FULL_SELECTION);
    GridData data = new GridData(GridData.FILL_BOTH);
    table.setLayoutData(data);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableLayout tableLayout = new TableLayout();
    table.setLayout(tableLayout);
    TableColumn column1 = new TableColumn(table, SWT.NONE);
    column1.setText(Messages.ComplexFileSetsEditor_colEnabled);
    column1.setResizable(false);
    TableColumn column2 = new TableColumn(table, SWT.NONE);
    column2.setText(Messages.ComplexFileSetsEditor_colFilesetName);
    TableColumn column3 = new TableColumn(table, SWT.NONE);
    column3.setText(Messages.ComplexFileSetsEditor_colConfiguration);
    tableLayout.addColumnData(new ColumnWeightData(20));
    tableLayout.addColumnData(new ColumnWeightData(40));
    tableLayout.addColumnData(new ColumnWeightData(40));
    mViewer = new CheckboxTableViewer(table);
    mViewer.setLabelProvider(new FileSetLabelProvider());
    mViewer.setContentProvider(new ArrayContentProvider());
    mViewer.setComparator(new FileSetViewerSorter());
    mViewer.setInput(mFileSets);
    // 
    for (FileSet fileSet : mFileSets) {
        mViewer.setChecked(fileSet, fileSet.isEnabled());
    }
    mViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent e) {
            editFileSet();
        }
    });
    mViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            changeEnabledState(event);
        }
    });
    // 
    // Build the buttons.
    // 
    Composite buttons = new Composite(composite, SWT.NULL);
    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttons.setLayout(layout);
    mAddButton = createPushButton(buttons, Messages.ComplexFileSetsEditor_btnAdd);
    mAddButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event evt) {
            addFileSet();
        }
    });
    mEditButton = createPushButton(buttons, Messages.ComplexFileSetsEditor_btnEdit);
    mEditButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event evt) {
            editFileSet();
        }
    });
    mRemoveButton = createPushButton(buttons, Messages.ComplexFileSetsEditor_btnRemove);
    mRemoveButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event evt) {
            removeFileSet();
        }
    });
    return composite;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Group(org.eclipse.swt.widgets.Group) Table(org.eclipse.swt.widgets.Table) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Listener(org.eclipse.swt.widgets.Listener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) FileSet(net.sf.eclipsecs.core.projectconfig.FileSet) Composite(org.eclipse.swt.widgets.Composite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) TableLayout(org.eclipse.jface.viewers.TableLayout)

Example 4 with FileSet

use of net.sf.eclipsecs.core.projectconfig.FileSet in project eclipse-cs by checkstyle.

the class ComplexFileSetsEditor method removeFileSet.

private void removeFileSet() {
    IStructuredSelection selection = (IStructuredSelection) mViewer.getSelection();
    FileSet fileSet = (FileSet) selection.getFirstElement();
    if (fileSet == null) {
        // 
        return;
    }
    mFileSets.remove(fileSet);
    mViewer.refresh();
    mPropertyPage.getContainer().updateButtons();
}
Also used : FileSet(net.sf.eclipsecs.core.projectconfig.FileSet) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 5 with FileSet

use of net.sf.eclipsecs.core.projectconfig.FileSet in project eclipse-cs by checkstyle.

the class ComplexFileSetsEditor method changeEnabledState.

private void changeEnabledState(CheckStateChangedEvent event) {
    if (event.getElement() instanceof FileSet) {
        FileSet fileSet = (FileSet) event.getElement();
        fileSet.setEnabled(event.getChecked());
        mViewer.refresh();
    }
}
Also used : FileSet(net.sf.eclipsecs.core.projectconfig.FileSet)

Aggregations

FileSet (net.sf.eclipsecs.core.projectconfig.FileSet)9 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)4 ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)3 IProjectConfiguration (net.sf.eclipsecs.core.projectconfig.IProjectConfiguration)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 PropertyResolver (com.puppycrawl.tools.checkstyle.PropertyResolver)1 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CheckConfigurationWorkingCopy (net.sf.eclipsecs.core.config.CheckConfigurationWorkingCopy)1 CheckstyleConfigurationFile (net.sf.eclipsecs.core.config.CheckstyleConfigurationFile)1 IContextAware (net.sf.eclipsecs.core.config.configtypes.IContextAware)1 AuditorJob (net.sf.eclipsecs.core.jobs.AuditorJob)1 FileMatchPattern (net.sf.eclipsecs.core.projectconfig.FileMatchPattern)1 ProjectConfigurationWorkingCopy (net.sf.eclipsecs.core.projectconfig.ProjectConfigurationWorkingCopy)1 CheckstyleTransformer (net.sf.eclipsecs.core.transformer.CheckstyleTransformer)1