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);
}
}
}
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 };
}
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);
}
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);
}
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;
}
Aggregations