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 @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.core.resources; singleton:=true
Bundle-Version: 3.23.300.qualifier
Bundle-Version: 3.24.0.qualifier
Bundle-Activator: org.eclipse.core.resources.ResourcesPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ public class Workspace extends PlatformObject implements IWorkspace, ICoreConsta
*/
protected IFileModificationValidator validator = null;

private volatile boolean enableRestrictedContent;

/**
* Data structure for holding the multi-part outcome of
* <code>IWorkspace.computeProjectBuildConfigOrder</code>.
Expand Down Expand Up @@ -2945,4 +2947,14 @@ private void createMultiple(ConcurrentMap<File, byte[]> filesToCreate, int updat
subMonitor.done();
}
}

@Override
public boolean isRestrictedContentEnabled() {
return enableRestrictedContent;
}

@Override
public void setRestrictedContentEnabled(boolean enabled) {
this.enableRestrictedContent = enabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@
* @noextend This interface is not intended to be extended by clients.
*/
public interface IFile extends IResource, IEncodedStorage, IAdaptable {

/**
* Session property used to mark a file as containing restricted content
*
* @since 3.24
*/
QualifiedName RESTRICTED_CONTENT = new QualifiedName(ResourcesPlugin.PI_RESOURCES, "restrictedContent"); //$NON-NLS-1$

/**
* Character encoding constant (value 0) which identifies
* files that have an unknown character encoding scheme.
Expand Down Expand Up @@ -1414,4 +1422,38 @@ public default String readString() throws CoreException {
public default String getLineSeparator(boolean checkParent) throws CoreException {
return getProject().getDefaultLineSeparator();
}

/**
* Returns whether the current file is marked as containing restricted
* (sensitive) content, where some IDE functionality related to the file content
* might be limited. The file must exist.
*
* @return whether the current file is marked as containing sensitive content.
* This flag is not persisted and is {@code false} by default.
* @throws CoreException if the file doesn't exist or if its session properties
* cannot be read
* @since 3.24
*/
default boolean isContentRestricted() throws CoreException {
IWorkspace workspace = getWorkspace();
return workspace != null && workspace.isRestrictedContentEnabled()
&& getSessionProperty(RESTRICTED_CONTENT) != null;
}

/**
* Marks the current file as containing restricted (sensitive) content. Some IDE
* functionality related to the file content might be limited as long as the
* file is marked as restricted. This flag is not persisted and is {@code false}
* by default. The file must exist.
*
* @param restricted <code>true</code> if the file should be a marked
* restricted, <code>false</code> if the file should be
* unmarked
* @throws CoreException if the file doesn't exist or if its session properties
* cannot be read
* @since 3.24
*/
default void setContentRestricted(boolean restricted) throws CoreException {
setSessionProperty(RESTRICTED_CONTENT, restricted ? Boolean.TRUE : null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1861,4 +1861,37 @@ public default void write(Map<IFile, byte[]> contentMap, boolean force, boolean
e.getKey().write(e.getValue(), force, derived, keepHistory, subMon.split(1));
}
}

/**
* Returns whether certain IDE functionality should be disabled for restricted
* (sensitive) files. Examples are file history and search. Default is
* <code>false</code>.
* <p>
* Restricted files are marked with: {@link IFile#setContentRestricted(boolean)}
* </p>
*
* @return <code>true</code> if restricted (sensitive) files handling is enabled
* by the IDE, <code>false</code> otherwise
* @see IFile#setContentRestricted(boolean)
* @see IFile#isContentRestricted()
* @since 3.24
*/
boolean isRestrictedContentEnabled();

/**
* Specifies whether certain IDE functionality should be disabled for restricted
* (sensitive) files. Examples are file history and search. This flag is not
* persisted and must be set for every new session that requires file
* restrictions.
* <p>
* Restricted files are marked with: {@link IFile#setContentRestricted(boolean)}
* </p>
*
* @param enabled <code>true</code> to enable restricted (sensitive) files
* handling, <code>false</code> otherwise
* @see IFile#setContentRestricted(boolean)
* @see IFile#isContentRestricted()
* @since 3.24
*/
void setRestrictedContentEnabled(boolean enabled);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
ResourceInfoTest.class, //
WorkspaceConcurrencyTest.class, //
WorkspacePreferencesTest.class, //
RestrictedFileTests.class, //
})
public class AllInternalResourcesTests {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*******************************************************************************
* Copyright (c) 2026 Simeon Andreev and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Simeon Andreev - initial API and implementation
*******************************************************************************/
package org.eclipse.core.tests.internal.resources;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(WorkspaceResetExtension.class)
public class RestrictedFileTests {

@Test
public void testRestrictedFile() throws Exception {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IProject project = root.getProject(RestrictedFileTests.class.getSimpleName());
try {
assertFalse(workspace.isRestrictedContentEnabled(),
"Expected file content to not be restricted by default");
workspace.setRestrictedContentEnabled(true);

project.create(null);
project.open(null);

IFile file1 = project.getFile("test1.txt");
IFile file2 = project.getFile("test2.txt");

try {
file1.isContentRestricted();
fail("Should not work on not existing files");
} catch (CoreException e) {
// expected, file should not exist
}

file1.create("line 1".getBytes(), IResource.FORCE, null);
file2.create("line 1".getBytes(), IResource.FORCE, null);

assertFalse(file1.isContentRestricted(), "Expected file to not be restricted");
assertFalse(file2.isContentRestricted(), "Expected file to not be restricted");

file1.setContentRestricted(true);
assertTrue(file1.isContentRestricted(), "Expected file to be restricted");
assertFalse(file2.isContentRestricted(), "Expected file to not be restricted");

workspace.setRestrictedContentEnabled(false);

assertFalse(file1.isContentRestricted(), "Expected file to not be restricted");
assertFalse(file2.isContentRestricted(), "Expected file to not be restricted");
} finally {
workspace.setRestrictedContentEnabled(false);
project.delete(true, null);
}
}
}
Loading