use of net.sf.eclipsecs.core.config.configtypes.IContextAware in project eclipse-cs by checkstyle.
the class CheckConfigurationTester method getUnresolvedProperties.
/**
* Tests a configuration if there are unresolved properties.
*
* @return the list of unresolved properties as ResolvableProperty values.
* @throws CheckstylePluginException
* most likely the configuration file could not be found
*/
public List<ResolvableProperty> getUnresolvedProperties() throws CheckstylePluginException {
CheckstyleConfigurationFile configFile = mCheckConfiguration.getCheckstyleConfiguration();
PropertyResolver resolver = configFile.getPropertyResolver();
// context
if (mContextProject != null && resolver instanceof IContextAware) {
((IContextAware) resolver).setProjectContext(mContextProject);
}
MissingPropertyCollector collector = new MissingPropertyCollector();
if (resolver instanceof MultiPropertyResolver) {
((MultiPropertyResolver) resolver).addPropertyResolver(collector);
} else {
MultiPropertyResolver multiResolver = new MultiPropertyResolver();
multiResolver.addPropertyResolver(resolver);
multiResolver.addPropertyResolver(collector);
resolver = multiResolver;
}
InputSource in = null;
try {
in = configFile.getCheckConfigFileInputSource();
ConfigurationLoader.loadConfiguration(in, resolver, false);
} catch (CheckstyleException e) {
CheckstylePluginException.rethrow(e);
} finally {
Closeables.closeQuietly(in.getByteStream());
}
return collector.getUnresolvedProperties();
}
use of net.sf.eclipsecs.core.config.configtypes.IContextAware in project eclipse-cs by checkstyle.
the class CheckerFactory method createChecker.
/**
* Creates a checker for a given configuration file.
*
* @param config
* the check configuration data
* @param project
* the project to create the checker for
* @return the checker for the given configuration file
* @throws CheckstyleException
* the configuration file had errors
* @throws CheckstylePluginException
* the configuration could not be read
*/
public static Checker createChecker(ICheckConfiguration config, IProject project) throws CheckstyleException, CheckstylePluginException {
String cacheKey = getCacheKey(config, project);
CheckstyleConfigurationFile configFileData = config.getCheckstyleConfiguration();
Checker checker = tryCheckerCache(cacheKey, configFileData.getModificationStamp());
// clear Checkstyle internal caches upon checker reuse
if (checker != null) {
checker.clearCache();
}
// no cache hit
if (checker == null) {
PropertyResolver resolver = configFileData.getPropertyResolver();
// context
if (resolver instanceof IContextAware) {
((IContextAware) resolver).setProjectContext(project);
}
InputSource in = null;
try {
in = configFileData.getCheckConfigFileInputSource();
checker = createCheckerInternal(in, resolver, project);
} finally {
Closeables.closeQuietly(in.getByteStream());
}
// store checker in cache
Long modified = new Long(configFileData.getModificationStamp());
sCheckerMap.put(cacheKey, checker);
sModifiedMap.put(cacheKey, modified);
}
return checker;
}
use of net.sf.eclipsecs.core.config.configtypes.IContextAware 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;
}
Aggregations