Java Code Examples for org.eclipse.core.resources.ResourceAttributes#setReadOnly()

The following examples show how to use org.eclipse.core.resources.ResourceAttributes#setReadOnly() . 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 File: IntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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 File: CheckstyleNature.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 File: ProjectConfigurationWorkingCopy.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 File: SingleProjectTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example 5
Source File: TarLeveledStructureProvider.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the resource attributes for this file.
 *
 * @param element the element to get the attributes from
 * @return the attributes of the file
 */
public ResourceAttributes getResourceAttributes(Object element) {
    ResourceAttributes attributes = new ResourceAttributes();
    TarArchiveEntry entry = (TarArchiveEntry) element;
    attributes.setExecutable((entry.getMode() & 0100) != 0);
    attributes.setReadOnly((entry.getMode() & 0200) == 0);
    return attributes;
}
 
Example 6
Source File: Resources.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
static void setReadOnly(IResource resource, boolean readOnly) {
	ResourceAttributes resourceAttributes = resource.getResourceAttributes();
	if (resourceAttributes == null) // not supported on this platform for this resource
		return;

	resourceAttributes.setReadOnly(readOnly);
	try {
		resource.setResourceAttributes(resourceAttributes);
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}
}