Search in sources :

Example 1 with BuiltInConfigurationType

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

the class GlobalCheckConfigurationWorkingSet method createCheckConfigurationsDocument.

/**
 * Transforms the check configurations to a document.
 */
private static Document createCheckConfigurationsDocument(List<CheckConfigurationWorkingCopy> configurations, ICheckConfiguration defaultConfig) {
    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement(XMLTags.CHECKSTYLE_ROOT_TAG);
    root.addAttribute(XMLTags.VERSION_TAG, CheckConfigurationFactory.CURRENT_CONFIG_FILE_FORMAT_VERSION);
    if (defaultConfig != null) {
        root.addAttribute(XMLTags.DEFAULT_CHECK_CONFIG_TAG, defaultConfig.getName());
    }
    for (ICheckConfiguration config : configurations) {
        // configurations
        if (config.getType() instanceof BuiltInConfigurationType || !config.isGlobal()) {
            continue;
        }
        Element configEl = root.addElement(XMLTags.CHECK_CONFIG_TAG);
        configEl.addAttribute(XMLTags.NAME_TAG, config.getName());
        configEl.addAttribute(XMLTags.LOCATION_TAG, config.getLocation());
        configEl.addAttribute(XMLTags.TYPE_TAG, config.getType().getInternalName());
        if (config.getDescription() != null) {
            configEl.addAttribute(XMLTags.DESCRIPTION_TAG, config.getDescription());
        }
        // Write resolvable properties
        for (ResolvableProperty prop : config.getResolvableProperties()) {
            Element propEl = configEl.addElement(XMLTags.PROPERTY_TAG);
            propEl.addAttribute(XMLTags.NAME_TAG, prop.getPropertyName());
            propEl.addAttribute(XMLTags.VALUE_TAG, prop.getValue());
        }
        for (Map.Entry<String, String> entry : config.getAdditionalData().entrySet()) {
            Element addEl = configEl.addElement(XMLTags.ADDITIONAL_DATA_TAG);
            addEl.addAttribute(XMLTags.NAME_TAG, entry.getKey());
            addEl.addAttribute(XMLTags.VALUE_TAG, entry.getValue());
        }
    }
    return doc;
}
Also used : BuiltInConfigurationType(net.sf.eclipsecs.core.config.configtypes.BuiltInConfigurationType) Element(org.dom4j.Element) Document(org.dom4j.Document) Map(java.util.Map)

Example 2 with BuiltInConfigurationType

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

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