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


##########
java/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/JDKDetectorUtils.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.j2seplatform;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.netbeans.api.java.platform.JavaPlatform;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import 
org.netbeans.modules.java.j2seplatform.platformdefinition.J2SEPlatformImpl;
+import org.netbeans.spi.java.platform.JavaPlatformFactory;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Lookup;
+
+/**
+ *
+ * @author mbien
+ */
+class JDKDetectorUtils {
+
+    /**
+     * Registers new JDKs if they aren't registered yet.
+     * @param jdks List of paths to the JDKs.
+     * @param namer Converts a Path to the display name of the JDK.
+     */
+    static void registerJDKs(List<Path> jdks, Function<Path, String> namer) {
+
+        List<JavaPlatform> platforms = 
Stream.of(JavaPlatformManager.getDefault().getInstalledPlatforms())
+                                             .filter(JavaPlatform::isValid)
+                                             .collect(Collectors.toList());
+
+        Set<String> registeredJDKNames = platforms.stream()
+                                                  
.map(JavaPlatform::getDisplayName)
+                                                  .collect(Collectors.toSet());
+
+        Set<Path> registeredPaths = platforms.stream()
+                                             .flatMap(p -> 
p.getInstallFolders().stream())
+                                             .map(f -> Paths.get(f.getPath()))
+                                             .collect(Collectors.toSet());
+
+        for (JavaPlatformFactory.Provider provider : 
Lookup.getDefault().lookupAll(JavaPlatformFactory.Provider.class)) {
+
+            JavaPlatformFactory platformFactory = 
provider.forType(J2SEPlatformImpl.PLATFORM_J2SE);
+            if (platformFactory != null) {
+                for (Path jdk : jdks) {
+                    try {
+                        String jdkName = namer.apply(jdk);
+                        // don't register if something with the same name or 
same path exists

Review Comment:
   > Why is the lack of a reset button an issue? If a JDK registration has been 
manually removed, shouldn't it need to be manually re-added?
   
   the longer I thought about it the more I liked the idea of skipping those 
folders. I think it is the safest option to get auto detection in.
   
   step 1: don't ever override already registered JDKs
   step 2: don't annoy the user by registering stuff the user potentially just 
removed
   
   having a growing "block list" without reset button was intuitively wrong to 
me, but it is probably completely fine in this particular case - and the better 
option to not having it.



##########
java/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/JDKDetectorUtils.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.j2seplatform;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.netbeans.api.java.platform.JavaPlatform;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import 
org.netbeans.modules.java.j2seplatform.platformdefinition.J2SEPlatformImpl;
+import org.netbeans.spi.java.platform.JavaPlatformFactory;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Lookup;
+
+/**
+ *
+ * @author mbien
+ */
+class JDKDetectorUtils {
+
+    /**
+     * Registers new JDKs if they aren't registered yet.
+     * @param jdks List of paths to the JDKs.
+     * @param namer Converts a Path to the display name of the JDK.
+     */
+    static void registerJDKs(List<Path> jdks, Function<Path, String> namer) {
+
+        List<JavaPlatform> platforms = 
Stream.of(JavaPlatformManager.getDefault().getInstalledPlatforms())
+                                             .filter(JavaPlatform::isValid)
+                                             .collect(Collectors.toList());
+
+        Set<String> registeredJDKNames = platforms.stream()
+                                                  
.map(JavaPlatform::getDisplayName)
+                                                  .collect(Collectors.toSet());
+
+        Set<Path> registeredPaths = platforms.stream()
+                                             .flatMap(p -> 
p.getInstallFolders().stream())
+                                             .map(f -> Paths.get(f.getPath()))
+                                             .collect(Collectors.toSet());
+
+        for (JavaPlatformFactory.Provider provider : 
Lookup.getDefault().lookupAll(JavaPlatformFactory.Provider.class)) {
+
+            JavaPlatformFactory platformFactory = 
provider.forType(J2SEPlatformImpl.PLATFORM_J2SE);
+            if (platformFactory != null) {
+                for (Path jdk : jdks) {
+                    try {
+                        String jdkName = namer.apply(jdk);
+                        // don't register if something with the same name or 
same path exists

Review Comment:
   > Why is the lack of a reset button an issue? If a JDK registration has been 
manually removed, shouldn't it need to be manually re-added?
   
   the longer I thought about it the more I liked the idea of skipping those 
folders. I think it is the safest option to get auto detection in.
   
   step 1: don't ever override already registered JDKs
   step 2: don't annoy the user by registering stuff the user potentially just 
removed
   
   having a growing "block list" without reset button sounded intuitively wrong 
to me, but it is probably completely fine in this particular case - and the 
better option to not having it.



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