Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomContentsStream;
import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString;
import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor;
import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnly;
import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnlySupported;
import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromFileSystem;
import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.setReadOnly;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -42,9 +44,12 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.tests.resources.ResourceTestUtil.ReadOnlyApi;
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

@ExtendWith(WorkspaceResetExtension.class)
public class IFolderTest {
Expand Down Expand Up @@ -316,8 +321,9 @@ public void testLeafFolderMove() throws Exception {
assertDoesNotExistInWorkspace(source);
}

@Test
public void testReadOnlyFolderCopy() throws Exception {
@ParameterizedTest
@EnumSource(ReadOnlyApi.class)
public void testReadOnlyFolderCopy(ReadOnlyApi apiVersion) throws Exception {
// We need to know whether or not we can unset the read-only flag
// in order to perform this test.
if (!isReadOnlySupported()) {
Expand All @@ -326,16 +332,16 @@ public void testReadOnlyFolderCopy() throws Exception {
IProject project = getWorkspace().getRoot().getProject("Project");
IFolder source = project.getFolder("Folder1");
createInWorkspace(source);
source.setReadOnly(true);
setReadOnly(source, true, apiVersion);
IFolder dest = project.getFolder("Folder2");
source.copy(dest.getFullPath(), true, createTestMonitor());
assertExistsInWorkspace(dest);
assertExistsInWorkspace(source);
assertTrue(dest.isReadOnly());
assertTrue(isReadOnly(dest, apiVersion));

// cleanup - ensure that the files can be deleted.
source.setReadOnly(false);
dest.setReadOnly(false);
setReadOnly(source, false, apiVersion);
setReadOnly(dest, true, apiVersion);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnlySupported;
import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromFileSystem;
import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.setReadOnly;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
Expand Down Expand Up @@ -73,9 +74,12 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.tests.resources.ResourceTestUtil.ReadOnlyApi;
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
Expand Down Expand Up @@ -762,8 +766,9 @@
order -> assertThat(order).containsExactly(NATURE_SIMPLE, NATURE_WATER, NATURE_SNOW));
}

@Test
public void testValidateEdit() throws CoreException {
@ParameterizedTest
@EnumSource(ReadOnlyApi.class)
public void testValidateEdit(ReadOnlyApi apiVersion) throws CoreException {
// We need to know whether or not we can unset the read-only flag
// in order to perform this test.
if (!isReadOnlySupported()) {
Expand All @@ -774,12 +779,12 @@
createInWorkspace(new IResource[] {project, file});
IStatus result = getWorkspace().validateEdit(new IFile[] {file}, null);
assertTrue(result.isOK());
file.setReadOnly(true);
setReadOnly(file, true, apiVersion);
result = getWorkspace().validateEdit(new IFile[] {file}, null);
assertEquals(IStatus.ERROR, result.getSeverity());
// assertEquals(IResourceStatus.READ_ONLY_LOCAL, result.getCode());
// remove the read-only status so test cleanup will work ok
file.setReadOnly(false);
setReadOnly(file, false, apiVersion);
}

@Test
Expand Down Expand Up @@ -1006,7 +1011,7 @@
assertTrue(workspace.validateProjectLocation(project, varPath.append("test")).isOK());
assertTrue(workspace.validateProjectLocation(project, varPath.append("test/ing")).isOK());
} finally {
workspace.getPathVariableManager().setValue(PATH_VAR_NAME, null);

Check warning on line 1014 in resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceTest.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

Deprecation

NORMAL: The method setValue(String, IPath) from the type IPathVariableManager is deprecated
}

//cannot overlap with another project's location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,4 +773,28 @@ public static boolean isLocal(IResource resource, int depth) {
return resource.isLocal(depth);
}

public enum ReadOnlyApi {
CURRENT, DEPRECATED
}

@SuppressWarnings("deprecation")
public static void setReadOnly(IResource resource, boolean value, ReadOnlyApi api) throws CoreException {
if (api == ReadOnlyApi.CURRENT) {
ResourceAttributes attributes = new ResourceAttributes();
attributes.setReadOnly(value);
resource.setResourceAttributes(attributes);
} else {
resource.setReadOnly(value);
}
}

@SuppressWarnings("deprecation")
public static boolean isReadOnly(IResource resource, ReadOnlyApi api) {
if (api == ReadOnlyApi.CURRENT) {
ResourceAttributes attributes = resource.getResourceAttributes();
return attributes.isReadOnly();
}
return resource.isReadOnly();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomContentsStream;
import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor;
import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnly;
import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnlySupported;
import static org.eclipse.core.tests.resources.ResourceTestUtil.setReadOnly;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -42,10 +44,13 @@
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.tests.resources.ResourceTestUtil.ReadOnlyApi;
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

@ExtendWith(WorkspaceResetExtension.class)
public class IFileTest {
Expand All @@ -55,9 +60,10 @@ public class IFileTest {
* you try to create a file in a read-only folder on Linux should be
* ERROR_WRITE.
*/
@Test
@ParameterizedTest
@EnumSource(ReadOnlyApi.class)
@Disabled("This test is no longer valid since the error code is dependent on whether or not the parent folder is marked as read-only. We need to write a different test to make the file.create fail.")
public void testBug25658() throws CoreException {
public void testBug25658(ReadOnlyApi apiVersion) throws CoreException {
// We need to know whether or not we can unset the read-only flag
// in order to perform this test.
assumeTrue("only relevant for platforms supporting read-only files", isReadOnlySupported());
Expand All @@ -71,13 +77,13 @@ public void testBug25658() throws CoreException {
IFile file = folder.getFile("file.txt");

try {
folder.setReadOnly(true);
assertThat(folder).matches(IResource::isReadOnly, "is read only");
setReadOnly(folder, true, apiVersion);
assertThat(folder).matches(res -> isReadOnly(res, apiVersion), "is read only");
CoreException exception = assertThrows(CoreException.class,
() -> file.create(createRandomContentsStream(), true, createTestMonitor()));
assertEquals(IResourceStatus.FAILED_WRITE_LOCAL, exception.getStatus().getCode());
} finally {
folder.setReadOnly(false);
setReadOnly(folder, false, apiVersion);
}
}

Expand All @@ -86,8 +92,9 @@ public void testBug25658() throws CoreException {
* parent to see if it is read-only so we can return a better error code and message
* to the user.
*/
@Test
public void testBug25662() throws CoreException {
@ParameterizedTest
@EnumSource(ReadOnlyApi.class)
public void testBug25662(ReadOnlyApi apiVersion) throws CoreException {

// We need to know whether or not we can unset the read-only flag
// in order to perform this test.
Expand All @@ -103,13 +110,13 @@ public void testBug25662() throws CoreException {
IFile file = folder.getFile("file.txt");

try {
folder.setReadOnly(true);
assertThat(folder).matches(IResource::isReadOnly, "is read only");
setReadOnly(folder, true, apiVersion);
assertThat(folder).matches(res -> isReadOnly(res, apiVersion), "is read only");
CoreException exception = assertThrows(CoreException.class,
() -> file.create(createRandomContentsStream(), true, createTestMonitor()));
assertEquals(IResourceStatus.PARENT_READ_ONLY, exception.getStatus().getCode());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test failure caused by this test extension indicates that the behavior on Linux expected by the test is not given when setting the read-only property for a folder via ResourceAttributes instead of using the deprecated setReadOnly() method:

AutomatedResourceTests AllRegressionTests IFileTest.testBug25662(ReadOnlyApi)[1] CURRENT
expected: <277> but was: <273>

The test is about expecting a failure with status IResourceStatus.PARENT_READ_ONLY when creating a file in a folder that was marked as read only. But this only seems to happen when the folder was marked as read only via IResource#setReadOnly() and not via IResource#setResourceAttributes().

@akurtakov do you think this is something that should be fixed for the Linux implementation or should I just revert the test extension here and keep it limited to the deprecated method IResource#setReadOnly() as it was before?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to fix the Linux implementation

} finally {
folder.setReadOnly(false);
setReadOnly(folder, false, apiVersion);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import static org.eclipse.core.tests.resources.ResourceTestUtil.createInFileSystem;
import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor;
import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnly;
import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnlySupported;
import static org.eclipse.core.tests.resources.ResourceTestUtil.setReadOnly;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -35,9 +37,12 @@
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.tests.resources.ResourceTestUtil.ReadOnlyApi;
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

@ExtendWith(WorkspaceResetExtension.class)
public class IFolderTest {
Expand All @@ -47,8 +52,9 @@ public class IFolderTest {
* the immediate parent to see if it is read-only so we can return a better
* error code and message to the user.
*/
@Test
public void testBug25662() throws CoreException {
@ParameterizedTest
@EnumSource(ReadOnlyApi.class)
public void testBug25662(ReadOnlyApi apiVersion) throws CoreException {
// We need to know whether or not we can unset the read-only flag
// in order to perform this test.
assumeTrue("only relevant for platforms supporting read-only files", isReadOnlySupported());
Expand All @@ -63,12 +69,12 @@ public void testBug25662() throws CoreException {
IFolder folder = parentFolder.getFolder("folder");

try {
parentFolder.setReadOnly(true);
assertThat(parentFolder).matches(IResource::isReadOnly, "is read only");
setReadOnly(parentFolder, true, apiVersion);
assertThat(parentFolder).matches(res -> isReadOnly(res, apiVersion), "is read only");
CoreException exception = assertThrows(CoreException.class, () -> folder.create(true, true, createTestMonitor()));
assertEquals(IResourceStatus.PARENT_READ_ONLY, exception.getStatus().getCode());
} finally {
parentFolder.setReadOnly(false);
setReadOnly(parentFolder, false, apiVersion);
}
}

Expand Down
Loading