-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from hakmart1/riderDiff
Added JetBrains Rider diff application as a diff program
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Assent.Reporters.DiffPrograms; | ||
|
||
public class RiderDiffProgram : DiffProgramBase | ||
{ | ||
static readonly IReadOnlyList<string> DefaultSearchPaths; | ||
|
||
static RiderDiffProgram() | ||
{ | ||
var riderChannelsDirectory = Environment.GetEnvironmentVariable("LocalAppData") + "\\JetBrains\\Toolbox\\apps\\Rider\\"; | ||
if (!Directory.Exists(riderChannelsDirectory)) | ||
{ | ||
DefaultSearchPaths = new List<string>(); | ||
return; | ||
} | ||
|
||
DefaultSearchPaths = Directory.GetDirectories(riderChannelsDirectory).Select(GetRiderExePathInChannel).ToList(); | ||
} | ||
|
||
public RiderDiffProgram() : base(DefaultSearchPaths) { } | ||
|
||
protected override string CreateProcessStartArgs(string receivedFile, string approvedFile) => | ||
$"\"diff\" \"{receivedFile}\" \"{approvedFile}\""; | ||
|
||
protected static string GetRiderExePathInChannel(string channelDirectory) | ||
{ | ||
var versions = Directory.GetDirectories(channelDirectory) | ||
.Where(directory => Regex.IsMatch(directory, @".*[0-9]+\.[0-9]+\.[0-9]+$")) | ||
.Select(path => GetRiderVersion(path.Replace(channelDirectory + "\\", ""))); | ||
|
||
var newestVersion = versions.MaxBy(x => x, new RiderVersionComparer()); | ||
|
||
return $"{channelDirectory}\\{newestVersion.Major}.{newestVersion.Minor}.{newestVersion.Patch}\\bin\\rider64.exe"; | ||
} | ||
|
||
protected static RiderVersion GetRiderVersion(string version) | ||
{ | ||
var split = version.Split("."); | ||
if (split.Length != 3) | ||
{ | ||
//Fallback to empty version | ||
return new RiderVersion(0, 0, 0); | ||
} | ||
|
||
return new RiderVersion(int.Parse(split[0]), int.Parse(split[1]), int.Parse(split[2])); | ||
} | ||
} | ||
|
||
public record RiderVersion(int Major, int Minor, int Patch); | ||
|
||
public class RiderVersionComparer : System.Collections.Generic.IComparer<RiderVersion> | ||
{ | ||
public int Compare(RiderVersion x, RiderVersion y) | ||
{ | ||
if (x == null) | ||
{ | ||
return -1; | ||
} | ||
|
||
if (y == null) | ||
{ | ||
return 1; | ||
} | ||
|
||
if (x.Major - y.Major != 0) | ||
{ | ||
return x.Major - y.Major; | ||
} | ||
|
||
if (x.Minor - y.Minor != 0) | ||
{ | ||
return x.Minor - y.Minor; | ||
} | ||
|
||
return x.Patch - y.Patch; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters