Skip to content

Commit 1e2f103

Browse files
committed
Add API for restricting operations for sensitive files
This change adds the following API: * org.eclipse.core.resources.IFile.isContentRestricted() * org.eclipse.core.resources.IFile.setContentRestricted(boolean) The goal of this API is to allow Eclipse-based IDEs to restrict certain platform functionality on a per-file basis, for sensitive files. The flags are not persisted, to enable restricted handling these flags must be set for each session. The restrictions will apply to following functionality: * File search * Storing file history Potentially more platform functionality will be restricted. See: #2588
1 parent e02781c commit 1e2f103

File tree

5 files changed

+102
-3
lines changed

5 files changed

+102
-3
lines changed

resources/bundles/org.eclipse.core.resources/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.core.resources; singleton:=true
5-
Bundle-Version: 3.23.300.qualifier
5+
Bundle-Version: 3.24.0.qualifier
66
Bundle-Activator: org.eclipse.core.resources.ResourcesPlugin
77
Bundle-Vendor: %providerName
88
Bundle-Localization: plugin

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/File.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -61,6 +61,8 @@
6161
*/
6262
public class File extends Resource implements IFile {
6363

64+
private volatile boolean isRestricted;
65+
6466
protected File(IPath path, Workspace container) {
6567
super(path, container);
6668
}
@@ -670,4 +672,13 @@ public String getLineSeparator(boolean checkParent) throws CoreException {
670672
return checkParent ? getProject().getDefaultLineSeparator() : null;
671673
}
672674

675+
@Override
676+
public boolean isContentRestricted() {
677+
return isRestricted;
678+
}
679+
680+
@Override
681+
public void setContentRestricted(boolean restricted) {
682+
isRestricted = restricted;
683+
}
673684
}

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/IFile.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -1414,4 +1414,32 @@ public default String readString() throws CoreException {
14141414
public default String getLineSeparator(boolean checkParent) throws CoreException {
14151415
return getProject().getDefaultLineSeparator();
14161416
}
1417+
1418+
/**
1419+
* Returns whether the current file is marked as containing restricted
1420+
* (sensitive) content, where some IDE functionality related to the file content
1421+
* might be limited.
1422+
*
1423+
* @return whether the current file is marked as containing sensitive content.
1424+
* This flag is not persisted and is {@code false} by default
1425+
* @since 3.24
1426+
*/
1427+
default boolean isContentRestricted() {
1428+
return false;
1429+
}
1430+
1431+
/**
1432+
* Marks the current file as containing restricted (sensitive) content. Some IDE
1433+
* functionality related to the file content might be limited as long as the
1434+
* file is marked as restricted. This flag is not persisted and is {@code false}
1435+
* by default.
1436+
*
1437+
* @param restricted <code>true</code> if the file should be a marked
1438+
* restricted, <code>false</code> if the file should be
1439+
* unmarked
1440+
* @since 3.24
1441+
*/
1442+
default void setContentRestricted(boolean restricted) {
1443+
throw new UnsupportedOperationException();
1444+
}
14171445
}

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/AllInternalResourcesTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
ResourceInfoTest.class, //
3333
WorkspaceConcurrencyTest.class, //
3434
WorkspacePreferencesTest.class, //
35+
RestrictedFileTests.class, //
3536
})
3637
public class AllInternalResourcesTests {
3738
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 Simeon Andreev and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Simeon Andreev - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.core.tests.internal.resources;
15+
16+
import static org.junit.jupiter.api.Assertions.assertFalse;
17+
import static org.junit.jupiter.api.Assertions.assertTrue;
18+
19+
import org.eclipse.core.resources.IFile;
20+
import org.eclipse.core.resources.IProject;
21+
import org.eclipse.core.resources.IResource;
22+
import org.eclipse.core.resources.IWorkspace;
23+
import org.eclipse.core.resources.IWorkspaceRoot;
24+
import org.eclipse.core.resources.ResourcesPlugin;
25+
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
26+
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.extension.ExtendWith;
28+
29+
@ExtendWith(WorkspaceResetExtension.class)
30+
public class RestrictedFileTests {
31+
32+
@Test
33+
public void testRestrictedFile() throws Exception {
34+
IWorkspace workspace = ResourcesPlugin.getWorkspace();
35+
IWorkspaceRoot root = workspace.getRoot();
36+
IProject project = root.getProject(RestrictedFileTests.class.getSimpleName());
37+
try {
38+
project.create(null);
39+
project.open(null);
40+
41+
IFile file1 = project.getFile("test1.txt");
42+
IFile file2 = project.getFile("test2.txt");
43+
44+
assertFalse(file1.isContentRestricted(), "Expected file to not be restricted");
45+
46+
file1.create("line 1".getBytes(), IResource.FORCE, null);
47+
file2.create("line 1".getBytes(), IResource.FORCE, null);
48+
49+
assertFalse(file1.isContentRestricted(), "Expected file to not be restricted");
50+
assertFalse(file2.isContentRestricted(), "Expected file to not be restricted");
51+
52+
file1.setContentRestricted(true);
53+
assertTrue(file1.isContentRestricted(), "Expected file to be restricted");
54+
assertFalse(file2.isContentRestricted(), "Expected file to not be restricted");
55+
} finally {
56+
project.delete(true, null);
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)