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;
}
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;
}
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;
}
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()));
}
}
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;
}
Aggregations