Search in sources :

Example 1 with ResourceAttributes

use of org.eclipse.core.resources.ResourceAttributes in project che by eclipse.

the class RenamePackageTest method testReadOnly.

@Test
public void testReadOnly() throws Exception {
    if (BUG_6054) {
        printTestDisabledMessage("see bug#6054 (renaming a read-only package resets the read-only flag)");
        return;
    }
    fIsPreDeltaTest = true;
    String[] packageNames = new String[] { "r" };
    String[][] packageFileNames = new String[][] { { "A" } };
    String newPackageName = "p1";
    IPackageFragment[] packages = new IPackageFragment[packageNames.length];
    ICompilationUnit[][] cus = new ICompilationUnit[packageFileNames.length][packageFileNames[0].length];
    for (int i = 0; i < packageNames.length; i++) {
        packages[i] = getRoot().createPackageFragment(packageNames[i], true, null);
        for (int j = 0; j < packageFileNames[i].length; j++) {
            cus[i][j] = createCUfromTestFile(packages[i], packageFileNames[i][j], packageNames[i].replace('.', '/') + "/");
        }
    }
    IPackageFragment thisPackage = packages[0];
    final IResource resource = thisPackage.getCorrespondingResource();
    final ResourceAttributes attributes = resource.getResourceAttributes();
    if (attributes != null)
        attributes.setReadOnly(true);
    RefactoringStatus result = performRefactoring(createRefactoringDescriptor(thisPackage, newPackageName));
    TestCase.assertEquals("preconditions were supposed to pass", null, result);
    assertTrue("package not renamed", !getRoot().getPackageFragment(packageNames[0]).exists());
    IPackageFragment newPackage = getRoot().getPackageFragment(newPackageName);
    assertTrue("new package does not exist", newPackage.exists());
    assertTrue("new package should be read-only", attributes == null || attributes.isReadOnly());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IResource(org.eclipse.core.resources.IResource) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes) Test(org.junit.Test)

Example 2 with ResourceAttributes

use of org.eclipse.core.resources.ResourceAttributes in project che by eclipse.

the class Resources method setReadOnly.

static void setReadOnly(IResource resource, boolean readOnly) {
    ResourceAttributes resourceAttributes = resource.getResourceAttributes();
    if (// not supported on this platform for this resource
    resourceAttributes == null)
        return;
    resourceAttributes.setReadOnly(readOnly);
    try {
        resource.setResourceAttributes(resourceAttributes);
    } catch (CoreException e) {
        JavaPlugin.log(e);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes)

Example 3 with ResourceAttributes

use of org.eclipse.core.resources.ResourceAttributes in project che by eclipse.

the class DocumentAdapter method isReadOnly.

/*
	 * @see IBuffer#isReadOnly()
	 */
public boolean isReadOnly() {
    //		if (fTextFileBuffer != null)
    //			return !fTextFileBuffer.isCommitable();
    IResource resource = getUnderlyingResource();
    if (resource == null)
        return true;
    final ResourceAttributes attributes = resource.getResourceAttributes();
    return attributes == null ? false : attributes.isReadOnly();
}
Also used : IResource(org.eclipse.core.resources.IResource) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes)

Example 4 with ResourceAttributes

use of org.eclipse.core.resources.ResourceAttributes in project che by eclipse.

the class Checks method isReadOnly.

public static boolean isReadOnly(IResource res) throws JavaModelException {
    ResourceAttributes attributes = res.getResourceAttributes();
    if (attributes != null && attributes.isReadOnly())
        return true;
    if (!(res instanceof IContainer))
        return false;
    IContainer container = (IContainer) res;
    try {
        IResource[] children = container.members();
        for (int i = 0; i < children.length; i++) {
            if (isReadOnly(children[i]))
                return true;
        }
        return false;
    } catch (JavaModelException e) {
        throw e;
    } catch (CoreException e) {
        throw new JavaModelException(e);
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes) IResource(org.eclipse.core.resources.IResource)

Example 5 with ResourceAttributes

use of org.eclipse.core.resources.ResourceAttributes in project che by eclipse.

the class Resources method setReadOnly.

static void setReadOnly(IResource resource, boolean readOnly) {
    ResourceAttributes resourceAttributes = resource.getResourceAttributes();
    if (// not supported on this platform for this resource
    resourceAttributes == null)
        return;
    resourceAttributes.setReadOnly(readOnly);
    try {
        resource.setResourceAttributes(resourceAttributes);
    } catch (CoreException e) {
        RefactoringCorePlugin.log(e);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes)

Aggregations

ResourceAttributes (org.eclipse.core.resources.ResourceAttributes)6 CoreException (org.eclipse.core.runtime.CoreException)4 IResource (org.eclipse.core.resources.IResource)3 IContainer (org.eclipse.core.resources.IContainer)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)1 Test (org.junit.Test)1