Search in sources :

Example 1 with ICheckConfiguration

use of net.sf.eclipsecs.core.config.ICheckConfiguration in project eclipse-cs by checkstyle.

the class CheckConfigurationWorkingSetEditor method copyCheckConfig.

/**
 * Copy an existing config.
 */
private void copyCheckConfig() {
    IStructuredSelection selection = (IStructuredSelection) mViewer.getSelection();
    ICheckConfiguration sourceConfig = (ICheckConfiguration) selection.getFirstElement();
    if (sourceConfig == null) {
        // 
        return;
    }
    try {
        // Open the properties dialog to change default name and description
        CheckConfigurationPropertiesDialog dialog = new CheckConfigurationPropertiesDialog(getShell(), null, mWorkingSet);
        dialog.setTemplateConfiguration(sourceConfig);
        dialog.setBlockOnOpen(true);
        if (Window.OK == dialog.open()) {
            CheckConfigurationWorkingCopy newConfig = dialog.getCheckConfiguration();
            // Copy the source configuration into the new internal config
            CheckConfigurationFactory.copyConfiguration(sourceConfig, newConfig);
            mWorkingSet.addCheckConfiguration(newConfig);
            mViewer.setInput(mWorkingSet.getWorkingCopies());
            mViewer.refresh();
        }
    } catch (CheckstylePluginException e) {
        CheckstyleUIPlugin.errorDialog(getShell(), e, true);
    }
}
Also used : ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) CheckConfigurationWorkingCopy(net.sf.eclipsecs.core.config.CheckConfigurationWorkingCopy) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 2 with ICheckConfiguration

use of net.sf.eclipsecs.core.config.ICheckConfiguration 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 3 with ICheckConfiguration

use of net.sf.eclipsecs.core.config.ICheckConfiguration in project eclipse-cs by checkstyle.

the class CheckConfigurationLabelProvider method getText.

/**
 * {@inheritDoc}
 */
@Override
public String getText(Object element) {
    String text = super.getText(element);
    if (element instanceof ICheckConfiguration) {
        ICheckConfiguration checkConfig = (ICheckConfiguration) element;
        text = // $NON-NLS-1$
        checkConfig.getName() + " " + (checkConfig.isGlobal() ? Messages.CheckConfigurationLabelProvider_suffixGlobal : Messages.CheckConfigurationLabelProvider_suffixLocal);
    }
    return text;
}
Also used : ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration)

Example 4 with ICheckConfiguration

use of net.sf.eclipsecs.core.config.ICheckConfiguration in project eclipse-cs by checkstyle.

the class CheckConfigurationViewerSorter method compare.

/**
 * {@inheritDoc}
 */
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    int result = 0;
    if ((e1 instanceof ICheckConfiguration) && (e2 instanceof ICheckConfiguration)) {
        ICheckConfiguration cfg1 = (ICheckConfiguration) e1;
        ICheckConfiguration cfg2 = (ICheckConfiguration) e2;
        String string1 = cfg1.getName();
        String string2 = cfg2.getName();
        result = string1.compareToIgnoreCase(string2);
    }
    return result;
}
Also used : ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration)

Example 5 with ICheckConfiguration

use of net.sf.eclipsecs.core.config.ICheckConfiguration in project eclipse-cs by checkstyle.

the class ProjectConfigurationFactory method getLocalCheckConfigs.

@SuppressWarnings("unchecked")
private static List<ICheckConfiguration> getLocalCheckConfigs(Element root, IProject project) {
    List<ICheckConfiguration> configurations = new ArrayList<>();
    List<Element> configElements = root.elements(XMLTags.CHECK_CONFIG_TAG);
    for (Element configEl : configElements) {
        final String name = configEl.attributeValue(XMLTags.NAME_TAG);
        final String description = configEl.attributeValue(XMLTags.DESCRIPTION_TAG);
        String location = configEl.attributeValue(XMLTags.LOCATION_TAG);
        String type = configEl.attributeValue(XMLTags.TYPE_TAG);
        IConfigurationType configType = ConfigurationTypes.getByInternalName(type);
        if (configType instanceof ProjectConfigurationType) {
            // RFE 1420212
            // treat config files relative to *THIS* project
            IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot();
            // test if the location contains the project name
            if (workspaceRoot.findMember(location) == null) {
                location = project.getFullPath().append(location).toString();
            }
        }
        // get resolvable properties
        List<ResolvableProperty> props = new ArrayList<>();
        List<Element> propertiesElements = configEl.elements(XMLTags.PROPERTY_TAG);
        for (Element propsEl : propertiesElements) {
            ResolvableProperty prop = new ResolvableProperty(propsEl.attributeValue(XMLTags.NAME_TAG), propsEl.attributeValue(XMLTags.VALUE_TAG));
            props.add(prop);
        }
        // get additional data
        Map<String, String> additionalData = new HashMap<>();
        List<Element> dataElements = configEl.elements(XMLTags.ADDITIONAL_DATA_TAG);
        for (Element dataEl : dataElements) {
            additionalData.put(dataEl.attributeValue(XMLTags.NAME_TAG), dataEl.attributeValue(XMLTags.VALUE_TAG));
        }
        ICheckConfiguration checkConfig = new CheckConfiguration(name, location, description, configType, false, props, additionalData);
        configurations.add(checkConfig);
    }
    return configurations;
}
Also used : ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) HashMap(java.util.HashMap) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) IConfigurationType(net.sf.eclipsecs.core.config.configtypes.IConfigurationType) CheckConfiguration(net.sf.eclipsecs.core.config.CheckConfiguration) ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ResolvableProperty(net.sf.eclipsecs.core.config.ResolvableProperty) ProjectConfigurationType(net.sf.eclipsecs.core.config.configtypes.ProjectConfigurationType)

Aggregations

ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)15 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)7 Element (org.dom4j.Element)5 ArrayList (java.util.ArrayList)3 FileSet (net.sf.eclipsecs.core.projectconfig.FileSet)3 File (java.io.File)2 HashMap (java.util.HashMap)2 CheckConfigurationWorkingCopy (net.sf.eclipsecs.core.config.CheckConfigurationWorkingCopy)2 IFilter (net.sf.eclipsecs.core.projectconfig.filters.IFilter)2 Document (org.dom4j.Document)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 FileDialog (org.eclipse.swt.widgets.FileDialog)2 PropertyResolver (com.puppycrawl.tools.checkstyle.PropertyResolver)1 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 CheckConfiguration (net.sf.eclipsecs.core.config.CheckConfiguration)1 CheckstyleConfigurationFile (net.sf.eclipsecs.core.config.CheckstyleConfigurationFile)1