Search in sources :

Example 6 with CheckstyleConfigurationFile

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

the class CheckerFactory method getAdditionalData.

/**
 * Determines the additional data for a given configuration file.
 *
 * @param config
 *          the check configuration
 * @param project
 *          the project to create the checker for
 * @return the checker for the given configuration file
 * @throws CheckstylePluginException
 *           the configuration could not be read
 */
public static ConfigurationReader.AdditionalConfigData getAdditionalData(ICheckConfiguration config, IProject project) throws CheckstylePluginException {
    String cacheKey = getCacheKey(config, project);
    AdditionalConfigData additionalData = sAdditionalDataMap.get(cacheKey);
    // no cache hit - create the additional data
    if (additionalData == null) {
        CheckstyleConfigurationFile configFileData = config.getCheckstyleConfiguration();
        InputSource in = null;
        try {
            in = configFileData.getCheckConfigFileInputSource();
            additionalData = ConfigurationReader.getAdditionalConfigData(in);
        } finally {
            Closeables.closeQuietly(in.getByteStream());
        }
        sAdditionalDataMap.put(cacheKey, additionalData);
    }
    return additionalData;
}
Also used : AdditionalConfigData(net.sf.eclipsecs.core.config.ConfigurationReader.AdditionalConfigData) InputSource(org.xml.sax.InputSource) CheckstyleConfigurationFile(net.sf.eclipsecs.core.config.CheckstyleConfigurationFile)

Example 7 with CheckstyleConfigurationFile

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

CheckstyleConfigurationFile (net.sf.eclipsecs.core.config.CheckstyleConfigurationFile)7 PropertyResolver (com.puppycrawl.tools.checkstyle.PropertyResolver)4 InputSource (org.xml.sax.InputSource)3 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 URLConnection (java.net.URLConnection)2 IContextAware (net.sf.eclipsecs.core.config.configtypes.IContextAware)2 Checker (com.puppycrawl.tools.checkstyle.Checker)1 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 Authenticator (java.net.Authenticator)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 PropertyResourceBundle (java.util.PropertyResourceBundle)1 ResourceBundle (java.util.ResourceBundle)1 AdditionalConfigData (net.sf.eclipsecs.core.config.ConfigurationReader.AdditionalConfigData)1