You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "mbien (via GitHub)" <gi...@apache.org> on 2023/03/09 02:15:29 UTC

[GitHub] [netbeans] mbien commented on a diff in pull request #5637: improved JDK detection startup tasks

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


##########
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:
   @lkishalmi the SDKMAN folder contains the actual JDKs, not symlinks, right? In other words: I haven't tested this but i think this should work just like it did 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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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