Search in sources :

Example 11 with ICheckConfiguration

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

the class TransformCheckstyleRulesJob method runInWorkspace.

/**
 * {@inheritDoc}
 */
@Override
public IStatus runInWorkspace(final IProgressMonitor arg0) throws CoreException {
    try {
        final IProjectConfiguration conf = ProjectConfigurationFactory.getConfiguration(mProject);
        final List<Configuration> rules = new ArrayList<Configuration>();
        // collect rules from all configured filesets
        for (FileSet fs : conf.getFileSets()) {
            ICheckConfiguration checkConfig = fs.getCheckConfig();
            CheckstyleConfigurationFile configFile = checkConfig.getCheckstyleConfiguration();
            PropertyResolver resolver = configFile.getPropertyResolver();
            // context
            if (resolver instanceof IContextAware) {
                ((IContextAware) resolver).setProjectContext(mProject);
            }
            InputSource in = null;
            try {
                in = configFile.getCheckConfigFileInputSource();
                Configuration configuration = ConfigurationLoader.loadConfiguration(in, resolver, true);
                // flatten the nested configuration tree into a list
                recurseConfiguration(configuration, rules);
            } finally {
                Closeables.closeQuietly(in.getByteStream());
            }
        }
        if (rules.isEmpty()) {
            return Status.CANCEL_STATUS;
        }
        final CheckstyleTransformer transformer = new CheckstyleTransformer(mProject, rules);
        transformer.transformRules();
    } catch (CheckstyleException e) {
        Status status = new Status(IStatus.ERROR, CheckstylePlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
        throw new CoreException(status);
    } catch (CheckstylePluginException e) {
        Status status = new Status(IStatus.ERROR, CheckstylePlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
        throw new CoreException(status);
    }
    return Status.OK_STATUS;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) InputSource(org.xml.sax.InputSource) Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) IProjectConfiguration(net.sf.eclipsecs.core.projectconfig.IProjectConfiguration) ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) FileSet(net.sf.eclipsecs.core.projectconfig.FileSet) ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) IProjectConfiguration(net.sf.eclipsecs.core.projectconfig.IProjectConfiguration) ArrayList(java.util.ArrayList) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) PropertyResolver(com.puppycrawl.tools.checkstyle.PropertyResolver) IContextAware(net.sf.eclipsecs.core.config.configtypes.IContextAware) CoreException(org.eclipse.core.runtime.CoreException) CheckstyleConfigurationFile(net.sf.eclipsecs.core.config.CheckstyleConfigurationFile) CheckstyleTransformer(net.sf.eclipsecs.core.transformer.CheckstyleTransformer) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException)

Example 12 with ICheckConfiguration

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

the class ProjectConfigurationWorkingCopy method getLocalCheckConfigByName.

/**
 * Returns a project local check configuration by its name.
 *
 * @param name
 *          the configurations name
 * @return the check configuration or <code>null</code>, if no local configuration with this name
 *         exists
 */
public ICheckConfiguration getLocalCheckConfigByName(String name) {
    ICheckConfiguration config = null;
    ICheckConfiguration[] configs = mLocalConfigWorkingSet.getWorkingCopies();
    for (int i = 0; i < configs.length; i++) {
        if (configs[i].getName().equals(name)) {
            config = configs[i];
            break;
        }
    }
    return config;
}
Also used : ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration)

Example 13 with ICheckConfiguration

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

the class ProjectConfigurationWorkingCopy method getGlobalCheckConfigByName.

/**
 * Returns a project local check configuration by its name.
 *
 * @param name
 *          the configurations name
 * @return the check configuration or <code>null</code>, if no local configuration with this name
 *         exists
 */
public ICheckConfiguration getGlobalCheckConfigByName(String name) {
    ICheckConfiguration config = null;
    ICheckConfiguration[] configs = mGlobalConfigWorkingSet.getWorkingCopies();
    for (int i = 0; i < configs.length; i++) {
        if (configs[i].getName().equals(name)) {
            config = configs[i];
            break;
        }
    }
    return config;
}
Also used : ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration)

Example 14 with ICheckConfiguration

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

the class ProjectConfigurationWorkingCopy method writeFileSet.

/**
 * Produces the sax events to write a file set to xml.
 *
 * @param fileSet
 *          the file set
 * @param project
 *          the project
 * @param docRoot
 *          the root element of the project configuration
 */
private void writeFileSet(FileSet fileSet, IProject project, Element docRoot) throws CheckstylePluginException {
    if (fileSet.getCheckConfig() == null) {
        throw new CheckstylePluginException(NLS.bind(Messages.errorFilesetWithoutCheckConfig, fileSet.getName(), project.getName()));
    }
    Element fileSetEl = docRoot.addElement(XMLTags.FILESET_TAG);
    fileSetEl.addAttribute(XMLTags.NAME_TAG, fileSet.getName());
    fileSetEl.addAttribute(XMLTags.ENABLED_TAG, Boolean.toString(fileSet.isEnabled()));
    ICheckConfiguration checkConfig = fileSet.getCheckConfig();
    if (checkConfig != null) {
        fileSetEl.addAttribute(XMLTags.CHECK_CONFIG_NAME_TAG, checkConfig.getName());
        fileSetEl.addAttribute(XMLTags.LOCAL_TAG, Boolean.toString(!checkConfig.isGlobal()));
    }
    // write patterns
    for (FileMatchPattern pattern : fileSet.getFileMatchPatterns()) {
        Element patternEl = fileSetEl.addElement(XMLTags.FILE_MATCH_PATTERN_TAG);
        patternEl.addAttribute(XMLTags.MATCH_PATTERN_TAG, pattern.getMatchPattern() != null ? pattern.getMatchPattern() : "");
        patternEl.addAttribute(XMLTags.INCLUDE_PATTERN_TAG, Boolean.toString(pattern.isIncludePattern()));
    }
}
Also used : ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) Element(org.dom4j.Element) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException)

Example 15 with ICheckConfiguration

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

the class ProjectConfigurationWorkingCopy method writeProjectConfig.

/**
 * Produces the sax events to write a project configuration.
 *
 * @param config
 *          the configuration
 */
private Document writeProjectConfig(ProjectConfigurationWorkingCopy config) throws CheckstylePluginException {
    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement(XMLTags.FILESET_CONFIG_TAG);
    root.addAttribute(XMLTags.FORMAT_VERSION_TAG, ProjectConfigurationFactory.CURRENT_FILE_FORMAT_VERSION);
    root.addAttribute(XMLTags.SIMPLE_CONFIG_TAG, Boolean.toString(config.isUseSimpleConfig()));
    root.addAttribute(XMLTags.SYNC_FORMATTER_TAG, Boolean.toString(config.isSyncFormatter()));
    ICheckConfiguration[] workingCopies = config.getLocalCheckConfigWorkingSet().getWorkingCopies();
    for (int i = 0; i < workingCopies.length; i++) {
        writeLocalConfiguration(workingCopies[i], root);
    }
    for (FileSet fileSet : config.getFileSets()) {
        writeFileSet(fileSet, config.getProject(), root);
    }
    // write filters
    for (IFilter filter : config.getFilters()) {
        writeFilter(filter, root);
    }
    return doc;
}
Also used : ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) Element(org.dom4j.Element) Document(org.dom4j.Document)

Aggregations

ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)15 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)7 Element (org.dom4j.Element)5 ArrayList (java.util.ArrayList)3 FileSet (net.sf.eclipsecs.core.projectconfig.FileSet)3 File (java.io.File)2 HashMap (java.util.HashMap)2 CheckConfigurationWorkingCopy (net.sf.eclipsecs.core.config.CheckConfigurationWorkingCopy)2 IFilter (net.sf.eclipsecs.core.projectconfig.filters.IFilter)2 Document (org.dom4j.Document)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 FileDialog (org.eclipse.swt.widgets.FileDialog)2 PropertyResolver (com.puppycrawl.tools.checkstyle.PropertyResolver)1 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 CheckConfiguration (net.sf.eclipsecs.core.config.CheckConfiguration)1 CheckstyleConfigurationFile (net.sf.eclipsecs.core.config.CheckstyleConfigurationFile)1