Java Code Examples for org.eclipse.core.resources.IFile#setResourceAttributes()
The following examples show how to use
org.eclipse.core.resources.IFile#setResourceAttributes() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: xtext-eclipse File: IntegrationTest.java License: Eclipse Public License 2.0 | 6 votes |
@Test public void testBug342875() throws Exception { IJavaProject project = createJavaProject("foo"); addNature(project.getProject(), XtextProjectHelper.NATURE_ID); IFile file = createFile("foo/src/foo" + F_EXT, "objekt Foo "); ResourceAttributes resourceAttributes = file.getResourceAttributes(); resourceAttributes.setReadOnly(true); file.setResourceAttributes(resourceAttributes); try { build(); assertTrue(file.isReadOnly()); assertEquals(1, countMarkers(file)); } finally { resourceAttributes.setReadOnly(false); file.setResourceAttributes(resourceAttributes); } }
Example 2
Source Project: eclipse-cs File: CheckstyleNature.java License: GNU Lesser General Public License v2.1 | 5 votes |
private void ensureProjectFileWritable() throws CoreException { IFile projectFile = mProject.getFile(".project"); if (projectFile.isReadOnly()) { ResourceAttributes attrs = ResourceAttributes.fromFile(projectFile.getFullPath().toFile()); attrs.setReadOnly(true); projectFile.setResourceAttributes(attrs); } }
Example 3
Source Project: eclipse-cs File: ProjectConfigurationWorkingCopy.java License: GNU Lesser General Public License v2.1 | 5 votes |
/** * 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())); } }
Example 4
Source Project: xtext-eclipse File: XtextProjectCreator.java License: Eclipse Public License 2.0 | 5 votes |
private void addExecutableFlag(IFile file) { ResourceAttributes attributes = file.getResourceAttributes(); if (attributes != null) { attributes.setExecutable(true); try { file.setResourceAttributes(attributes); } catch (CoreException e) { LOG.warn("Failed to set executable flag for " + file.getFullPath().toOSString(), e); } } }
Example 5
Source Project: xtext-eclipse File: SingleProjectTest.java License: Eclipse Public License 2.0 | 5 votes |
@Test public void testBug342875() throws Exception { IFile file = createFile("sample/first" + F_EXT, "Hello A"); ResourceAttributes resourceAttributes = file.getResourceAttributes(); resourceAttributes.setReadOnly(true); file.setResourceAttributes(resourceAttributes); try { build(); assertTrue(file.isReadOnly()); assertEquals(1, countMarkers(file)); } finally { resourceAttributes.setReadOnly(false); file.setResourceAttributes(resourceAttributes); } }