mbien commented on code in PR #5637:
URL: https://github.com/apache/netbeans/pull/5637#discussion_r1130405791


##########
java/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/SdkManJavaPlatformDetector.java:
##########
@@ -18,49 +18,42 @@
  */
 package org.netbeans.modules.java.j2seplatform;
 
-import java.io.File;
 import java.io.IOException;
-import java.util.Collection;
-import 
org.netbeans.modules.java.j2seplatform.platformdefinition.J2SEPlatformImpl;
-import org.netbeans.spi.java.platform.JavaPlatformFactory;
-import org.openide.filesystems.FileObject;
-import org.openide.filesystems.FileUtil;
-import org.openide.util.Lookup;
+import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  *
  * @author lkishalmi
  */
 public class SdkManJavaPlatformDetector implements Runnable {
 
-    static final File SDKMAN_JAVA_DIR = new 
File(System.getProperty("user.home"), ".sdkman/candidates/java"); //NOI18N
+    static final Path SDKMAN_JAVA_DIR = 
Paths.get(System.getProperty("user.home"), ".sdkman", "candidates", "java"); 
//NOI18N
 
     @Override
     public void run() {
-        if (SDKMAN_JAVA_DIR.isDirectory()) {
-            File[] platformDirs = SDKMAN_JAVA_DIR.listFiles((File f) -> 
f.isDirectory() && !"current".equals(f.getName())); //NOI18N
-            Collection<? extends JavaPlatformFactory.Provider> providers = 
Lookup.getDefault().lookupAll(JavaPlatformFactory.Provider.class);
-            for (JavaPlatformFactory.Provider provider : providers) {
-                JavaPlatformFactory platformFactory = 
provider.forType(J2SEPlatformImpl.PLATFORM_J2SE);
-                if (platformFactory != null) {
-                    for (File platformDir : platformDirs) {
-                        try {
-                            FileObject installFolder = 
FileUtil.toFileObject(platformDir);
-                            platformFactory.create(installFolder, 
getDisplayName(installFolder), true);
-                        } catch (IOException ex) {
-                            //It seems we was not suceeding to add this
-                        } catch(IllegalArgumentException ex) {
-                            //Thrown if the platform is already persisted and 
added to the system.
-                        }
 
-                    }
-                    break;
-                }
+        if (Files.isDirectory(SDKMAN_JAVA_DIR)) {
+            try (Stream<Path> files = Files.list(SDKMAN_JAVA_DIR)) {
+
+                List<Path> jdks = files.filter(p -> Files.isDirectory(p, 
LinkOption.NOFOLLOW_LINKS))
+                                       .filter(p -> 
!p.getFileName().toString().equals("current"))
+                                       .collect(Collectors.toList());
+
+                JDKDetectorUtils.registerJDKs(jdks, jdk -> 
getDisplayName(jdk));

Review Comment:
   ok, old code used File::isDirectory which returns true on symlinks. So maybe 
I should simply remove `NOFOLLOW_LINKS` to be sure that it works just like 
before.



-- 
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