3030import org .eclipse .core .runtime .CoreException ;
3131import org .eclipse .core .runtime .IPath ;
3232import org .eclipse .core .runtime .Path ;
33- import org .eclipse .core .runtime .QualifiedName ;
3433import org .eclipse .core .runtime .preferences .IEclipsePreferences ;
3534import org .eclipse .core .runtime .preferences .InstanceScope ;
3635
5453 * property {@code search_excluded_file} on some test files and performs a search. Search matches
5554 * are not expected for the files with the session property.
5655 */
57- public class ExcludedFilesSearchTest {
56+ public class RestrictedFilesSearchTest {
5857
59- private static final String EXCLUSION_PREFERENCE_NAME = "search_exclusion_property" ;
60-
61- private static final QualifiedName SESSION_PROPERTY_QN = new QualifiedName (null , "search_excluded_file" );
62-
63- private static final String SESSION_PROPERTY = "search_excluded_file" ;
58+ private static final String DISABLE_PREFERENCE_NAME = "disableRestrictedFileSearch" ;
6459
6560 private static final String EXCLUDED_FILE_PREFIX = "excluded_" ;
6661
@@ -69,7 +64,7 @@ public class ExcludedFilesSearchTest {
6964 @ AfterEach
7065 public void cleanUp () throws Exception {
7166 ResourceHelper .deleteProject (PROJECT_NAME );
72- setExcludedSearchEnabled ( null );
67+ setDisableRestrictedFileSearch ( false );
7368 }
7469
7570 @ Test
@@ -102,10 +97,10 @@ private void doLinkTest(int n, int index) throws Exception {
10297 for (int i = 0 ; i < n ; ++i ) {
10398 IFile link = ResourceHelper .createLinkedFile (project , new Path ("link_file_" + i ), file );
10499 if (i == index ) {
105- setExcludedSearchSessionProperty ( link );
100+ link . setContentRestricted ( true );
106101 }
107102 }
108- setExcludedSearchEnabled ( SESSION_PROPERTY );
103+ setDisableRestrictedFileSearch ( true );
109104 TestResultCollector collector = new TestResultCollector (true );
110105 doSearch (project , collector , searchString );
111106 TestResult [] results = collector .getResults ();
@@ -165,7 +160,7 @@ private static void doSearchTest(int n, int m, boolean parallel, boolean session
165160 String searchString = "hello" ;
166161 IProject project = prepareProject (n , m , PROJECT_NAME , searchString );
167162 if (sessionProperty ) {
168- setExcludedSearchEnabled ( SESSION_PROPERTY );
163+ setDisableRestrictedFileSearch ( true );
169164 setSessionProperty (project );
170165 }
171166 TestResultCollector collector = new TestResultCollector (parallel );
@@ -177,8 +172,9 @@ private static void setSessionProperty(IProject project) throws CoreException {
177172 project .accept (new IResourceVisitor () {
178173 @ Override
179174 public boolean visit (IResource resource ) throws CoreException {
180- if (resource .getName ().startsWith (EXCLUDED_FILE_PREFIX )) {
181- setExcludedSearchSessionProperty (resource );
175+ if (resource .getType () == IResource .FILE && resource .getName ().startsWith (EXCLUDED_FILE_PREFIX )) {
176+ IFile file = (IFile ) resource ;
177+ file .setContentRestricted (true );
182178 }
183179 return true ;
184180 }
@@ -234,16 +230,12 @@ private static void assertMatches(TestResult[] results, int expectedCount, Strin
234230 assertEquals (expectedCount , k , "Wrong number of results in file" );
235231 }
236232
237- private static void setExcludedSearchSessionProperty (IResource resource ) throws CoreException {
238- resource .setSessionProperty (SESSION_PROPERTY_QN , "true" );
239- }
240-
241- private static void setExcludedSearchEnabled (String value ) throws BackingStoreException {
233+ private static void setDisableRestrictedFileSearch (boolean enabled ) throws BackingStoreException {
242234 IEclipsePreferences node = InstanceScope .INSTANCE .getNode (SearchCorePlugin .PLUGIN_ID );
243- if (value != null ) {
244- node .put ( EXCLUSION_PREFERENCE_NAME , value );
235+ if (enabled ) {
236+ node .putBoolean ( DISABLE_PREFERENCE_NAME , true );
245237 } else {
246- node .remove (EXCLUSION_PREFERENCE_NAME );
238+ node .remove (DISABLE_PREFERENCE_NAME );
247239 }
248240 node .flush ();
249241 }
0 commit comments