Search in sources :

Example 1 with ProjectConfigurationType

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

Example 2 with ProjectConfigurationType

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

the class ProjectConfigurationWorkingCopy method writeLocalConfiguration.

/**
 * Writes a local check configuration.
 *
 * @param checkConfig
 *          the local check configuration
 * @param docRoot
 *          the root element of the project configuration
 */
private void writeLocalConfiguration(ICheckConfiguration checkConfig, Element docRoot) {
    // configurations
    if (checkConfig.getType() instanceof BuiltInConfigurationType || checkConfig.isGlobal()) {
        return;
    }
    // RFE 1420212
    String location = checkConfig.getLocation();
    if (checkConfig.getType() instanceof ProjectConfigurationType) {
        IProject project = mProjectConfig.getProject();
        IWorkspaceRoot root = project.getWorkspace().getRoot();
        IFile configFile = root.getFile(new Path(location));
        IProject configFileProject = configFile.getProject();
        // path part
        if (project.equals(configFileProject)) {
            location = configFile.getProjectRelativePath().toString();
        }
    }
    Element configEl = docRoot.addElement(XMLTags.CHECK_CONFIG_TAG);
    configEl.addAttribute(XMLTags.NAME_TAG, checkConfig.getName());
    configEl.addAttribute(XMLTags.LOCATION_TAG, location);
    configEl.addAttribute(XMLTags.TYPE_TAG, checkConfig.getType().getInternalName());
    if (checkConfig.getDescription() != null) {
        configEl.addAttribute(XMLTags.DESCRIPTION_TAG, checkConfig.getDescription());
    }
    // Write resolvable properties
    for (ResolvableProperty prop : checkConfig.getResolvableProperties()) {
        Element propEl = configEl.addElement(XMLTags.PROPERTY_TAG);
        propEl.addAttribute(XMLTags.NAME_TAG, prop.getPropertyName());
        propEl.addAttribute(XMLTags.VALUE_TAG, prop.getValue());
    }
    // Write additional data
    for (Map.Entry<String, String> entry : checkConfig.getAdditionalData().entrySet()) {
        Element addEl = configEl.addElement(XMLTags.ADDITIONAL_DATA_TAG);
        addEl.addAttribute(XMLTags.NAME_TAG, entry.getKey());
        addEl.addAttribute(XMLTags.VALUE_TAG, entry.getValue());
    }
}
Also used : BuiltInConfigurationType(net.sf.eclipsecs.core.config.configtypes.BuiltInConfigurationType) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ResolvableProperty(net.sf.eclipsecs.core.config.ResolvableProperty) Element(org.dom4j.Element) ProjectConfigurationType(net.sf.eclipsecs.core.config.configtypes.ProjectConfigurationType) Map(java.util.Map) IProject(org.eclipse.core.resources.IProject)

Aggregations

ResolvableProperty (net.sf.eclipsecs.core.config.ResolvableProperty)2 ProjectConfigurationType (net.sf.eclipsecs.core.config.configtypes.ProjectConfigurationType)2 Element (org.dom4j.Element)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CheckConfiguration (net.sf.eclipsecs.core.config.CheckConfiguration)1 ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)1 BuiltInConfigurationType (net.sf.eclipsecs.core.config.configtypes.BuiltInConfigurationType)1 IConfigurationType (net.sf.eclipsecs.core.config.configtypes.IConfigurationType)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 Path (org.eclipse.core.runtime.Path)1