use of net.sf.eclipsecs.core.projectconfig.IProjectConfiguration in project eclipse-cs by checkstyle.
the class CheckFileOnOpenPartListener method isFileAffected.
/**
* Checks if the given file is affected by the UnOpenedFilesFilter and needs to be handled on
* editor open/close.
*
* @param file
* the file to check
* @return <code>true</code> if the file is affected, <code>false</code> otherwise
*/
private boolean isFileAffected(IFile file) {
boolean affected = false;
IProject project = file.getProject();
try {
// check if checkstyle is enabled on the project
if (project.isAccessible() && project.hasNature(CheckstyleNature.NATURE_ID)) {
IProjectConfiguration config = ProjectConfigurationFactory.getConfiguration(project);
// now check if the UnOpenedFilesFilter is active
boolean unOpenedFilesFilterActive = false;
boolean filtered = false;
List<IFilter> filters = config.getFilters();
for (IFilter filter : filters) {
if (filter instanceof UnOpenedFilesFilter && ((UnOpenedFilesFilter) filter).isEnabled()) {
unOpenedFilesFilterActive = true;
}
// check if the file would be filtered out
if (filter.isEnabled() && !(filter instanceof UnOpenedFilesFilter)) {
filtered = filtered || !filter.accept(file);
}
}
affected = unOpenedFilesFilterActive && !filtered;
}
} catch (CoreException e) {
// should never happen, since editor cannot be open
// when project isn't
CheckstyleLog.log(e);
} catch (CheckstylePluginException e) {
CheckstyleLog.log(e);
}
return affected;
}
use of net.sf.eclipsecs.core.projectconfig.IProjectConfiguration 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