Skip to content

Commit 89b9955

Browse files
LarsEckartisidoressilverxollin
committed
! r cleaned up
Co-Authored-By: Llewellyn Falco <[email protected]> Co-Authored-By: ssilverx <[email protected]> Co-Authored-By: ollin <[email protected]>
1 parent 33545a5 commit 89b9955

File tree

5 files changed

+60
-41
lines changed

5 files changed

+60
-41
lines changed

approvaltests-tests/src/test/java/org/approvaltests/reporters/IntelliJResolverTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void testFindItOnMac()
1717
"Users/lars/Applications/IntelliJ IDEA Community Edition.app/Contents/MacOS/idea");
1818
for (String path : validPaths)
1919
{
20-
DiffInfo diffInfo = IntelliJMacResolver.getDiffInfo(userHome, f -> f.equals(path));
20+
DiffInfo diffInfo = IntelliJToolboxResolver.getDiffInfoMac(userHome, f -> f.equals(path));
2121
assertNotEquals("", diffInfo.diffProgram, path);
2222
}
2323
}
@@ -30,7 +30,7 @@ void testFindItOnLinux()
3030
"/home/lars/.local/share/JetBrains/Toolbox/apps/intellij-idea-ultimate/bin/idea.sh");
3131
for (String path : validPaths)
3232
{
33-
DiffInfo diffInfo = IntelliJMacResolver.getDiffInfoLinux(userHome, f -> f.equals(path));
33+
DiffInfo diffInfo = IntelliJToolboxResolver.getDiffInfoLinux(userHome, f -> f.equals(path));
3434
assertNotEquals("", diffInfo.diffProgram, path);
3535
}
3636
}

approvaltests/src/main/java/org/approvaltests/reporters/DiffInfo.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public DiffInfo(String diffProgram, String parameters, List<String> fileExtensio
1818
this.parameters = parameters;
1919
this.fileExtensions = fileExtensions;
2020
}
21+
public static DiffInfo getNull()
22+
{
23+
return new DiffInfo(null, null, null);
24+
}
2125
private static String resolveWindowsPath(String diffProgram)
2226
{
2327
diffProgram = diffProgram == null ? "" : diffProgram;
@@ -50,6 +54,10 @@ public static String getFirstWorking(String path, String[] paths, String ifNotFo
5054
}
5155
return fullPath;
5256
}
57+
public boolean isEmpty()
58+
{
59+
return "".equals(diffProgram);
60+
}
5361
public static String[] getProgramFilesPaths()
5462
{
5563
HashSet<String> paths = new HashSet<>();

approvaltests/src/main/java/org/approvaltests/reporters/DiffPrograms.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static class Mac
3030
TEXT_AND_IMAGE);
3131
public static DiffInfo TK_DIFF = new DiffInfo("/Applications/TkDiff.app/Contents/MacOS/tkdiff",
3232
TEXT);
33-
public static DiffInfo INTELLIJ = IntelliJMacResolver.findIt();
33+
public static DiffInfo INTELLIJ = IntelliJToolboxResolver.findIt();
3434
public static DiffInfo VISUAL_STUDIO_CODE = new DiffInfo(
3535
"/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code", "-d %s %s", TEXT);
3636
}

approvaltests/src/main/java/org/approvaltests/reporters/IntelliJMacResolver.java

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.approvaltests.reporters;
2+
3+
import org.lambda.functions.Function1;
4+
import org.lambda.functions.Function2;
5+
import org.lambda.query.Queryable;
6+
7+
import java.io.File;
8+
9+
import static org.lambda.query.Queryable.as;
10+
11+
public class IntelliJToolboxResolver
12+
{
13+
private interface Resolver extends Function2<String, Function1<String, Boolean>, DiffInfo>
14+
{
15+
}
16+
public static DiffInfo findIt()
17+
{
18+
for (Resolver function : new Resolver[]{IntelliJToolboxResolver::getDiffInfoMac,
19+
IntelliJToolboxResolver::getDiffInfoLinux})
20+
{
21+
DiffInfo diffInfo = function.call(System.getProperty("user.home"), f -> new File(f).exists());
22+
if (!diffInfo.isEmpty())
23+
{ return diffInfo; }
24+
}
25+
return DiffInfo.getNull();
26+
}
27+
public static DiffInfo getDiffInfoMac(String userHome, Function1<String, Boolean> fileExists)
28+
{
29+
Queryable<String> locations = as("IntelliJ IDEA Ultimate", "IntelliJ IDEA", "IntelliJ IDEA Community",
30+
"IntelliJ IDEA Community Edition");
31+
Queryable<String> applications = as("/Applications", userHome + "/Applications");
32+
String postfix = ".app/Contents/MacOS/idea";
33+
return getDiffInfo(fileExists, applications, locations, postfix);
34+
}
35+
public static DiffInfo getDiffInfoLinux(String userHome, Function1<String, Boolean> fileExists)
36+
{
37+
Queryable<String> locations = as("intellij-idea-ultimate"); // TODO community
38+
Queryable<String> applications = as(userHome + "/.local/share/JetBrains/Toolbox/apps");
39+
String postfix = "/bin/idea.sh";
40+
return getDiffInfo(fileExists, applications, locations, postfix);
41+
}
42+
private static DiffInfo getDiffInfo(Function1<String, Boolean> fileExists, Queryable<String> locations,
43+
Queryable<String> list, String postfix)
44+
{
45+
Queryable<String> paths = locations.selectMany(a -> list.select(l -> a + "/" + l + postfix));
46+
String matching = paths.first(fileExists);
47+
return new DiffInfo(matching, "diff %s %s", GenericDiffReporter.TEXT_FILE_EXTENSIONS);
48+
}
49+
}

0 commit comments

Comments
 (0)