Search in sources :

Example 1 with CheckConfiguration

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

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CheckConfiguration (net.sf.eclipsecs.core.config.CheckConfiguration)1 ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)1 ResolvableProperty (net.sf.eclipsecs.core.config.ResolvableProperty)1 IConfigurationType (net.sf.eclipsecs.core.config.configtypes.IConfigurationType)1 ProjectConfigurationType (net.sf.eclipsecs.core.config.configtypes.ProjectConfigurationType)1 Element (org.dom4j.Element)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1