Search in sources :

Example 1 with IFilter

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

the class ProjectConfigurationWorkingCopy method writeFilter.

/**
 * Produces the sax events to write a filter to xml.
 *
 * @param filter
 *          the filter
 * @param docRoot
 *          the root element of the project configuration
 */
private void writeFilter(IFilter filter, Element docRoot) {
    // write only filters that are actually changed
    // (enabled or contain data)
    IFilter prototype = PluginFilters.getByInternalName(filter.getInternalName());
    if (prototype.equals(filter)) {
        return;
    }
    Element filterEl = docRoot.addElement(XMLTags.FILTER_TAG);
    filterEl.addAttribute(XMLTags.NAME_TAG, filter.getInternalName());
    filterEl.addAttribute(XMLTags.ENABLED_TAG, Boolean.toString(filter.isEnabled()));
    List<String> data = filter.getFilterData();
    if (data != null && !data.isEmpty()) {
        for (String item : data) {
            Element dataEl = filterEl.addElement(XMLTags.FILTER_DATA_TAG);
            dataEl.addAttribute(XMLTags.VALUE_TAG, item);
        }
    }
}
Also used : IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) Element(org.dom4j.Element)

Example 2 with IFilter

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

the class CheckstyleBuilder method build.

/**
 * {@inheritDoc}
 */
@Override
protected final IProject[] build(final int kind, @SuppressWarnings("rawtypes") final Map args, final IProgressMonitor monitor) throws CoreException {
    // get the associated project for this builder
    IProject project = getProject();
    // remove project level error markers
    project.deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_ZERO);
    if (CheckstyleNature.hasCorrectBuilderOrder(project)) {
        // 
        // get the project configuration
        // 
        IProjectConfiguration config = null;
        try {
            config = ProjectConfigurationFactory.getConfiguration(project);
        } catch (CheckstylePluginException e) {
            Status status = new Status(IStatus.ERROR, CheckstylePlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage() != null ? e.getMessage() : Messages.CheckstyleBuilder_msgErrorUnknown, e);
            throw new CoreException(status);
        }
        Collection<IResource> resources = null;
        // get the delta of the latest changes
        IResourceDelta resourceDelta = getDelta(project);
        IFilter[] filters = config.getFilters().toArray(new IFilter[config.getFilters().size()]);
        // find the files for the build
        if (resourceDelta != null) {
            resources = getResources(resourceDelta, filters);
        } else {
            resources = getResources(project, filters);
        }
        handleBuildSelection(resources, config, monitor, project, kind);
    } else {
        // the builder order is wrong. Refuse to check and create a error
        // marker.
        // remove all existing Checkstyle markers
        project.deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_INFINITE);
        Map<String, Object> markerAttributes = new HashMap<>();
        markerAttributes.put(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_HIGH));
        markerAttributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
        markerAttributes.put(IMarker.MESSAGE, NLS.bind(Messages.CheckstyleBuilder_msgWrongBuilderOrder, project.getName()));
        // enables own category under Java Problem Type
        // setting for Problems view (RFE 1530366)
        // $NON-NLS-1$
        markerAttributes.put("categoryId", new Integer(999));
        // create a marker for the actual resource
        IMarker marker = project.createMarker(CheckstyleMarker.MARKER_ID);
        marker.setAttributes(markerAttributes);
    }
    return new IProject[] { project };
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) HashMap(java.util.HashMap) IProjectConfiguration(net.sf.eclipsecs.core.projectconfig.IProjectConfiguration) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) IMarker(org.eclipse.core.resources.IMarker) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 3 with IFilter

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

the class ProjectConfigurationFactory method getProjectConfiguration.

private static IProjectConfiguration getProjectConfiguration(InputStream in, IProject project) throws DocumentException, CheckstylePluginException {
    SAXReader reader = new SAXReader();
    Document document = reader.read(in);
    Element root = document.getRootElement();
    String version = root.attributeValue(XMLTags.FORMAT_VERSION_TAG);
    if (!SUPPORTED_VERSIONS.contains(version)) {
        throw new CheckstylePluginException(NLS.bind(Messages.errorUnknownFileFormat, version));
    }
    boolean useSimpleConfig = Boolean.valueOf(root.attributeValue(XMLTags.SIMPLE_CONFIG_TAG)).booleanValue();
    boolean syncFormatter = Boolean.valueOf(root.attributeValue(XMLTags.SYNC_FORMATTER_TAG)).booleanValue();
    List<ICheckConfiguration> checkConfigs = getLocalCheckConfigs(root, project);
    List<FileSet> fileSets = getFileSets(root, checkConfigs);
    List<IFilter> filters = getFilters(root);
    return new ProjectConfiguration(project, checkConfigs, fileSets, filters, useSimpleConfig, syncFormatter);
}
Also used : ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) Document(org.dom4j.Document) IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException)

Example 4 with IFilter

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

the class ProjectConfigurationFactory method createDefaultProjectConfiguration.

/**
 * Creates a default project configuration for the given projects, using the default globbal check
 * configuration.
 *
 * @param project
 *          the project
 * @return the default project configuration
 */
public static IProjectConfiguration createDefaultProjectConfiguration(IProject project) {
    FileSet standardFileSet = new FileSet(Messages.SimpleFileSetsEditor_nameAllFileset, CheckConfigurationFactory.getDefaultCheckConfiguration());
    try {
        standardFileSet.getFileMatchPatterns().add(new FileMatchPattern(".*"));
    } catch (CheckstylePluginException e) {
        throw new RuntimeException(e);
    }
    List<FileSet> fileSets = Arrays.asList(standardFileSet);
    IFilter[] filters = PluginFilters.getConfiguredFilters();
    List<IFilter> defaultFilters = new ArrayList<>();
    for (IFilter filter : filters) {
        if (filter.isEnabled()) {
            defaultFilters.add(filter);
        }
    }
    return new ProjectConfiguration(project, null, fileSets, defaultFilters, true, false);
}
Also used : IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) ArrayList(java.util.ArrayList) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException)

Example 5 with IFilter

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

the class ProjectConfigurationFactory method getFilters.

@SuppressWarnings("unchecked")
private static List<IFilter> getFilters(Element root) {
    List<IFilter> filters = new ArrayList<>();
    List<Element> filterElements = root.elements(XMLTags.FILTER_TAG);
    for (Element filterEl : filterElements) {
        IFilter filter = PluginFilters.getByInternalName(filterEl.attributeValue(XMLTags.NAME_TAG));
        // guard against unknown/retired filters
        if (filter != null) {
            filter.setEnabled(Boolean.valueOf(filterEl.attributeValue(XMLTags.ENABLED_TAG)).booleanValue());
            // get the filter data
            List<String> filterData = new ArrayList<>();
            List<Element> dataElements = filterEl.elements(XMLTags.FILTER_DATA_TAG);
            for (Element dataEl : dataElements) {
                filterData.add(dataEl.attributeValue(XMLTags.VALUE_TAG));
            }
            filter.setFilterData(filterData);
            filters.add(filter);
        }
    }
    return filters;
}
Also used : IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) Element(org.dom4j.Element) ArrayList(java.util.ArrayList)

Aggregations

IFilter (net.sf.eclipsecs.core.projectconfig.filters.IFilter)10 ArrayList (java.util.ArrayList)4 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)4 Element (org.dom4j.Element)4 ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)2 IProjectConfiguration (net.sf.eclipsecs.core.projectconfig.IProjectConfiguration)2 Document (org.dom4j.Document)2 IProject (org.eclipse.core.resources.IProject)2 CoreException (org.eclipse.core.runtime.CoreException)2 HashMap (java.util.HashMap)1 UnOpenedFilesFilter (net.sf.eclipsecs.core.projectconfig.filters.UnOpenedFilesFilter)1 SAXReader (org.dom4j.io.SAXReader)1 IMarker (org.eclipse.core.resources.IMarker)1 IResource (org.eclipse.core.resources.IResource)1 IResourceDelta (org.eclipse.core.resources.IResourceDelta)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1