@@ -19,15 +19,21 @@ private static String getPath()
1919 {
2020 try
2121 {
22- return findJetBrainsIDEs ();
22+ return findJetBrainsIdes ();
2323 }
2424 catch (Throwable e )
2525 {
2626 // requires Java 9+
2727 return "" ;
2828 }
2929 }
30- public static String findJetBrainsIDEs ()
30+ public static String findJetBrainsIdes ()
31+ {
32+ String [] commands = ProcessHandle .allProcesses ().map (p -> p .info ().command ()).filter (Optional ::isPresent )
33+ .map (c -> c .get ()).toArray (String []::new );
34+ return findJetBrainsIdes (commands );
35+ }
36+ public static String findJetBrainsIdes (String [] commands )
3137 {
3238 Set <String > seenPaths = new HashSet <>();
3339 String [] keywords = {"idea" ,
@@ -40,34 +46,27 @@ public static String findJetBrainsIDEs()
4046 "rubymine" ,
4147 "appcode" ,
4248 "datagrip" };
43- ProcessHandle [] list = ProcessHandle .allProcesses ().toArray (ProcessHandle []::new );
44- for (ProcessHandle process : list )
49+ for (String command : commands )
4550 {
46- Optional < String > commandOpt = process . info (). command ();
47- if ( commandOpt . isPresent () )
51+ String lowerCommand = command . toLowerCase ();
52+ for ( String keyword : keywords )
4853 {
49- String command = commandOpt .get ();
50- String lowerCommand = command .toLowerCase ();
51- for (String keyword : keywords )
54+ if (lowerCommand .contains (keyword ) && isMainExecutable (command , keyword ))
5255 {
53- if (lowerCommand .contains (keyword ) && isMainExecutable ( command , keyword ))
56+ if (! seenPaths .contains (command ))
5457 {
55- if (!seenPaths .contains (command ))
56- {
57- seenPaths .add (command );
58- return command ;
59- }
60- break ;
58+ seenPaths .add (command );
59+ return command ;
6160 }
61+ break ;
6262 }
6363 }
64- } ;
64+ }
6565 return "" ;
6666 }
67- private static boolean isMainExecutable (String path , String keyword )
67+ public static boolean isMainExecutable (String path , String keyword )
6868 {
6969 String lowerPath = path .toLowerCase ();
70- return lowerPath .endsWith ("macos/" + keyword ) || lowerPath .endsWith (keyword + ".exe" )
71- || lowerPath .endsWith ("bin/" + keyword );
70+ return lowerPath .endsWith ("macos/" + keyword ) || lowerPath .contains ("bin\\ " + keyword );
7271 }
7372}
0 commit comments