Skip to content

Commit 9540412

Browse files
JayBazuzistagg54isidore
committed
- B find JetBrains on Windows 64
Co-Authored-By: Samuel Taggart <[email protected]> Co-Authored-By: Llewellyn Falco <[email protected]>
1 parent c766e4a commit 9540412

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.approvaltests.reporters;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.approvaltests.reporters.intellij.IntelliJReporter;
6+
import org.junit.jupiter.api.Test;
7+
8+
public class IntelliJReporterTest
9+
{
10+
@Test
11+
public void testFindJetBrainsIdes()
12+
{
13+
String[] commands = {"C:\\Program Files\\JetBrains\\PyCharm 2025.1.1.1\\bin\\pycharm64.exe"};
14+
String result = IntelliJReporter.findJetBrainsIdes(commands);
15+
assertEquals("C:\\Program Files\\JetBrains\\PyCharm 2025.1.1.1\\bin\\pycharm64.exe", result);
16+
}
17+
}

approvaltests/src/main/java/org/approvaltests/reporters/intellij/IntelliJReporter.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)