sdedic commented on code in PR #7722:
URL: https://github.com/apache/netbeans/pull/7722#discussion_r1743628328


##########
ide/projectapi/src/org/netbeans/modules/projectapi/SimpleFileOwnerQueryImplementation.java:
##########
@@ -59,21 +62,25 @@ public class SimpleFileOwnerQueryImplementation implements 
FileOwnerQueryImpleme
     private static final Logger LOG = 
Logger.getLogger(SimpleFileOwnerQueryImplementation.class.getName());
     private static final URI UNOWNED_URI = URI.create("http:unowned");
     private static final Set<String> forbiddenFolders;
-    private static final String projectScanRoot;
+    private static final Set<String> projectScanRoots;
     
     static {
-        Set<String> files = new HashSet<String>();
-        String root = null;
+        Set<String> folders = Collections.emptySet();
+        Set<String> roots = Collections.emptySet();
         try {
-            root = System.getProperty("project.limitScanRoot"); // NOI18N
-            String forbidden = System.getProperty("project.forbiddenFolders", 
System.getProperty("versioning.forbiddenFolders", "")); //NOI18N
-            files.addAll(Arrays.asList(forbidden.split("\\;"))); //NOI18N
-            files.remove(""); //NOI18N
+            String limitScanRoot = 
System.getProperty("project.limitScanRoot"); //NOI18N
+            if (limitScanRoot != null && !limitScanRoot.isEmpty()) {
+                roots = extractFolderPaths(limitScanRoot, File.pathSeparator);
+            }
+            String forbidden = System.getProperty("project.forbiddenFolders", 
System.getProperty("versioning.forbiddenFolders")); //NOI18N
+            if (forbidden != null && !forbidden.isEmpty()) {
+                folders = extractFolderPaths(forbidden, ";");

Review Comment:
   `extractFolderPaths` has already a filter for `singlePath.trim().isEmpty()` 
already, so if that function short-returned `Collections.emptySet()` on `null` 
input, we can save the conditions here and on line 73



##########
ide/projectapi/src/org/netbeans/modules/projectapi/SimpleFileOwnerQueryImplementation.java:
##########
@@ -414,6 +421,18 @@ private static URI goUp(URI u) {
         assert u.toString().startsWith(nue.toString()) : "not a parent: " + 
nue + " of " + u;
         return nue;
     }
+
+    private static Set<String> extractFolderPaths(String folders, String 
pathSeparator) {
+        Set<String> paths = Arrays.stream(folders.split(pathSeparator))   
//NOI18N
+                .filter(s -> !s.trim().isEmpty())
+                .map(f -> FileUtil.toFileObject(FileUtil.normalizeFile(new 
File(f))))

Review Comment:
   in `filter()`, trimmed string is checked for emptiness ... but in `new File` 
the untrimmed string is used to create a path ?



##########
ide/projectapi/src/org/netbeans/modules/projectapi/SimpleFileOwnerQueryImplementation.java:
##########
@@ -414,6 +421,18 @@ private static URI goUp(URI u) {
         assert u.toString().startsWith(nue.toString()) : "not a parent: " + 
nue + " of " + u;
         return nue;
     }
+
+    private static Set<String> extractFolderPaths(String folders, String 
pathSeparator) {
+        Set<String> paths = Arrays.stream(folders.split(pathSeparator))   
//NOI18N
+                .filter(s -> !s.trim().isEmpty())
+                .map(f -> FileUtil.toFileObject(FileUtil.normalizeFile(new 
File(f))))
+                .filter(Objects::nonNull)
+                .map(FileObject::getPath)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+        return paths.isEmpty() ? Collections.emptySet() : paths.size() == 1 ? 
Collections.singleton(paths.iterator().next()) : paths;

Review Comment:
   I know that writing streams is modern and trendy ... but please think twice 
before coding such a cascade. If there's any issue, the code like this is 
literally undebuggable.
   
   Streams processing should be IMHO only used for larger number of items where 
internal logic could eventually parallelize/speed up the processing; not 
instread of old-school but readable cycles and conditions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to