use of net.sf.eclipsecs.core.util.CheckstylePluginException 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.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class ProjectConfigurationWorkingCopy method storeToPersistence.
/**
* Store the audit configurations to the persistent state storage.
*/
private void storeToPersistence(ProjectConfigurationWorkingCopy config) throws CheckstylePluginException {
try {
Document docu = writeProjectConfig(config);
byte[] data = XMLUtil.toByteArray(docu);
InputStream pipeIn = new ByteArrayInputStream(data);
// create or overwrite the .checkstyle file
IProject project = config.getProject();
IFile file = project.getFile(ProjectConfigurationFactory.PROJECT_CONFIGURATION_FILE);
if (!file.exists()) {
file.create(pipeIn, true, null);
file.refreshLocal(IResource.DEPTH_INFINITE, null);
} else {
if (file.isReadOnly()) {
ResourceAttributes attrs = ResourceAttributes.fromFile(file.getFullPath().toFile());
attrs.setReadOnly(true);
file.setResourceAttributes(attrs);
}
file.setContents(pipeIn, true, true, null);
}
config.getLocalCheckConfigWorkingSet().store();
} catch (Exception e) {
CheckstylePluginException.rethrow(e, NLS.bind(Messages.errorWritingCheckConfigurations, e.getLocalizedMessage()));
}
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException 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.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class ProjectConfigurationType method isConfigurable.
@Override
public boolean isConfigurable(ICheckConfiguration checkConfiguration) {
boolean isConfigurable = true;
boolean isProtected = Boolean.valueOf(checkConfiguration.getAdditionalData().get(KEY_PROTECT_CONFIG)).booleanValue();
isConfigurable = !isProtected;
if (!isProtected) {
// file can is writable
try {
File file = URIUtil.toFile(checkConfiguration.getResolvedConfigurationFileURL().toURI());
isConfigurable = file != null && file.canWrite();
} catch (CheckstylePluginException | URISyntaxException e) {
CheckstyleLog.log(e);
isConfigurable = false;
}
}
return isConfigurable;
}
Aggregations