Search in sources :

Example 26 with ResourceAttributes

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()));
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Document(org.dom4j.Document) IProject(org.eclipse.core.resources.IProject) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException)

Aggregations

ResourceAttributes (org.eclipse.core.resources.ResourceAttributes)26 IFile (org.eclipse.core.resources.IFile)10 CoreException (org.eclipse.core.runtime.CoreException)9 IResource (org.eclipse.core.resources.IResource)7 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IFolder (org.eclipse.core.resources.IFolder)4 InputStream (java.io.InputStream)3 IProject (org.eclipse.core.resources.IProject)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 IPath (org.eclipse.core.runtime.IPath)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 Activity (com.centurylink.mdw.plugin.designer.model.Activity)1 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)1 ArtifactResourceListener (com.centurylink.mdw.plugin.workspace.ArtifactResourceListener)1 TempFileRemover (com.centurylink.mdw.plugin.workspace.TempFileRemover)1 BufferedInputStream (java.io.BufferedInputStream)1