use of org.eclipse.core.resources.ResourceAttributes 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()));
}
}
Aggregations