Search in sources :

Example 6 with PropertyResolver

use of com.puppycrawl.tools.checkstyle.PropertyResolver 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)

Aggregations

PropertyResolver (com.puppycrawl.tools.checkstyle.PropertyResolver)6 CheckstyleConfigurationFile (net.sf.eclipsecs.core.config.CheckstyleConfigurationFile)4 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)3 IContextAware (net.sf.eclipsecs.core.config.configtypes.IContextAware)3 InputSource (org.xml.sax.InputSource)3 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 URLConnection (java.net.URLConnection)2 Checker (com.puppycrawl.tools.checkstyle.Checker)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 FileNotFoundException (java.io.FileNotFoundException)1 Authenticator (java.net.Authenticator)1 HttpURLConnection (java.net.HttpURLConnection)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)1 MultiPropertyResolver (net.sf.eclipsecs.core.config.configtypes.MultiPropertyResolver)1 FileSet (net.sf.eclipsecs.core.projectconfig.FileSet)1 IProjectConfiguration (net.sf.eclipsecs.core.projectconfig.IProjectConfiguration)1 CheckstyleTransformer (net.sf.eclipsecs.core.transformer.CheckstyleTransformer)1