Skip to content

Commit

Permalink
Merge pull request #35 from daghsentinel/master
Browse files Browse the repository at this point in the history
Updated to .NET 8
  • Loading branch information
bjorkstromm authored Sep 14, 2024
2 parents 3c9f1f8 + 5267a73 commit e12e4f6
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 63 deletions.
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": {
"version": "7.0.201",
"rollForward": "latestPatch",
"version": "8.0.400",
"rollForward": "latestFeature",
"allowPrerelease": false
}
}
26 changes: 10 additions & 16 deletions src/Depends.Core/DependencyAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ static DependencyAnalyzer()
_ = typeof(NuGet.Common.LogLevel);
}

private ILogger _logger;
private ILoggerFactory _loggerFactory;
private readonly ILogger _logger;
private readonly ILoggerFactory _loggerFactory;

public DependencyAnalyzer(ILoggerFactory loggerFactory)
{
Expand Down Expand Up @@ -115,7 +115,7 @@ public DependencyGraph Analyze(string packageId, string version, string framewor
}
}

private async Task ResolvePackage(PackageIdentity package,
private static async Task ResolvePackage(PackageIdentity package,
NuGetFramework framework,
SourceCacheContext cacheContext,
NuGet.Common.ILogger logger,
Expand Down Expand Up @@ -152,7 +152,7 @@ private async Task ResolvePackage(PackageIdentity package,
{
await Task.WhenAll(dependencyInfo.Dependencies.Select(dependency =>
{
return ResolvePackage(new PackageIdentity(dependency.Id, dependency.VersionRange.MinVersion),
return DependencyAnalyzer.ResolvePackage(new PackageIdentity(dependency.Id, dependency.VersionRange.MinVersion),
framework, cacheContext, logger, repositories, availablePackages);
}));
}
Expand All @@ -170,7 +170,7 @@ public DependencyGraph AnalyzeSolution(string solution, string framework = null)
var builder = new DependencyGraph.Builder(solutionNode);
foreach (var project in analyzerManager.Projects.Where(p => p.Value.ProjectInSolution.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat))
{
builder = CreateBuilder(project.Value, project.Key, builder, framework);
builder = DependencyAnalyzer.CreateBuilder(project.Value, project.Key, builder, framework);
}

return builder.Build();
Expand All @@ -185,7 +185,7 @@ public DependencyGraph Analyze(string projectPath, string framework = null)

if (string.IsNullOrWhiteSpace(projectPath))
{
throw new ArgumentException(nameof(projectPath));
throw new ArgumentException("Empty parameter", nameof(projectPath));
}

if (!File.Exists(projectPath))
Expand All @@ -194,22 +194,16 @@ public DependencyGraph Analyze(string projectPath, string framework = null)
}

var projectAnalyzer = analyzerManager.GetProject(projectPath);
return CreateBuilder(projectAnalyzer, projectPath, null, framework).Build();
return DependencyAnalyzer.CreateBuilder(projectAnalyzer, projectPath, null, framework).Build();
}

private DependencyGraph.Builder CreateBuilder(IProjectAnalyzer projectAnalyzer, string projectPath, DependencyGraph.Builder builder = null, string framework = null)
private static DependencyGraph.Builder CreateBuilder(IProjectAnalyzer projectAnalyzer, string projectPath, DependencyGraph.Builder builder = null, string framework = null)
{
var analyzeResults = string.IsNullOrEmpty(framework) ?
projectAnalyzer.Build() : projectAnalyzer.Build(framework);

var analyzerResult = string.IsNullOrEmpty(framework) ?
analyzeResults.FirstOrDefault() : analyzeResults[framework];

if (analyzerResult == null)
{
// Todo: Something went wrong, log and return better exception.
throw new InvalidOperationException("Unable to load project.");
}
var analyzerResult = (string.IsNullOrEmpty(framework) ?
analyzeResults.FirstOrDefault() : analyzeResults[framework]) ?? throw new InvalidOperationException("Unable to load project.");
var projectNode = new ProjectReferenceNode(projectPath);
if (builder == null)
{
Expand Down
12 changes: 6 additions & 6 deletions src/Depends.Core/Depends.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Buildalyzer" Version="5.0.0" />
<PackageReference Include="MinVer" Version="4.3.0">
<PackageReference Include="Buildalyzer" Version="7.0.2" />
<PackageReference Include="MinVer" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="NuGet.ProjectModel" Version="6.5.0" />
<PackageReference Include="NuGet.Resolver" Version="6.5.0" />
<PackageReference Include="NuGet.ProjectModel" Version="6.11.0" />
<PackageReference Include="NuGet.Resolver" Version="6.11.0" />

<!--
Explicitly disable warning for implicit dependency as done in the parent library (Buildalyzer) here:
https://github.com/daveaglick/Buildalyzer/blob/e30d44755ad17e8abf3efb53acc4a5d4f5a77ea7/src/Buildalyzer/Buildalyzer.csproj#L22-L24 -->
<PackageReference Include="Microsoft.Build" Version="17.3.2">
<PackageReference Include="Microsoft.Build" Version="17.11.4">
<NoWarn>NU1701</NoWarn>
</PackageReference>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ internal static class LockFileTargetLibraryExtensions
{
public static bool IsPackage(this LockFileTargetLibrary library)
{
return library.Type.Equals("package", StringComparison.OrdinalIgnoreCase);
return library.Type != null && library.Type.Equals("package", StringComparison.OrdinalIgnoreCase);
}

public static PackageReferenceNode ToNode(this LockFileTargetLibrary library)
{
if (!library.IsPackage())
{
throw new ArgumentException(nameof(library));
throw new ArgumentException("Empty parameter", nameof(library));
}

return new PackageReferenceNode(library.Name, library.Version.ToNormalizedString());
return new PackageReferenceNode(library.Name, library.Version?.ToNormalizedString());
}
}
}
6 changes: 3 additions & 3 deletions src/Depends.Core/Extensions/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public static ILogger AsNuGetLogger(this MEL.ILogger logger)

private class NuGetLogger : ILogger
{
private MEL.ILogger _logger;
private Dictionary<LogLevel, MEL.LogLevel> _logLevelMap = new Dictionary<LogLevel, MEL.LogLevel>
private readonly MEL.ILogger _logger;
private readonly Dictionary<LogLevel, MEL.LogLevel> _logLevelMap = new()
{
[LogLevel.Debug] = MEL.LogLevel.Debug,
[LogLevel.Error] = MEL.LogLevel.Error,
Expand All @@ -27,7 +27,7 @@ private class NuGetLogger : ILogger
[LogLevel.Warning] = MEL.LogLevel.Warning
};

public NuGetLogger(Microsoft.Extensions.Logging.ILogger logger)
public NuGetLogger(MEL.ILogger logger)
{
_logger = logger;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Depends.Core/Graph/DependencyGraph.Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public sealed partial class DependencyGraph
public sealed class Builder
{
private readonly Node _root;
private HashSet<Node> _nodes = new HashSet<Node>();
private HashSet<Edge> _edges = new HashSet<Edge>();
private readonly HashSet<Node> _nodes = new();
private readonly HashSet<Edge> _edges = new();

public Node Root => _root;

Expand Down
20 changes: 7 additions & 13 deletions src/Depends.Core/Graph/Edge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,23 @@ public Edge(Node start, Node end, string label)

public bool Equals(Edge other)
{
if (ReferenceEquals(null, other)) return false;
if (other is null) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(Start, other.Start) && Equals(End, other.End) && string.Equals(Label, other.Label);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (obj is null) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is Edge edge && Equals(edge);
}

public override int GetHashCode()
{
unchecked
{
var hashCode = (Start != null ? Start.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (End != null ? End.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Label != null ? Label.GetHashCode() : 0);
return hashCode;
}
}

public override int GetHashCode()
{
return HashCode.Combine(Start, End, Label);
}

public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "{0} -{2}-> {1}", Start, End,
Expand Down
6 changes: 3 additions & 3 deletions src/Depends.Core/Graph/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ protected Node(string id)
{
if (string.IsNullOrWhiteSpace(id))
{
throw new ArgumentException(nameof(id));
throw new ArgumentException("Empty parameter", nameof(id));
}

Id = id;
}

public bool Equals(Node other)
{
if (ReferenceEquals(null, other)) return false;
if (other is null) return false;
if (ReferenceEquals(this, other)) return true;
return string.Equals(Id, other.Id, StringComparison.OrdinalIgnoreCase);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (obj is null) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is Node node && Equals(node);
}
Expand Down
5 changes: 1 addition & 4 deletions src/Depends.Core/Output/DotFileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ public void Write(DependencyGraph graph, TextWriter writer)

private static void Write(Node root, ImmutableHashSet<Edge> edges, TextWriter writer, IDictionary<Node, int> ranks, ISet<Edge> visited = null, int depth = 0)
{
if (visited == null)
{
visited = new HashSet<Edge>();
}
visited ??= new HashSet<Edge>();

if (ranks.TryGetValue(root, out var currentRank))
{
Expand Down
14 changes: 7 additions & 7 deletions src/Depends/Depends.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<ToolCommandName>dotnet-depends</ToolCommandName>
<PackAsTool>True</PackAsTool>
<OutputType>Exe</OutputType>
<PackageId>dotnet-depends</PackageId>
<Title>dotnet-depends</Title>
<Authors>mholo65</Authors>
<Authors>bjorkstromm and contributors</Authors>
<Description>Dependency explorer for .NET</Description>
<Copyright>2018 Martin Björkström</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/mholo65/depends</PackageProjectUrl>
<PackageProjectUrl>https://github.com/bjorkstromm/depends</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.0.2" />
<PackageReference Include="Terminal.Gui" Version="1.9.0" />
<PackageReference Include="MinVer" Version="4.3.0">
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.1.1" />
<PackageReference Include="Terminal.Gui" Version="1.17.1" />
<PackageReference Include="MinVer" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
10 changes: 6 additions & 4 deletions src/Depends/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ internal class Program
// SOFTWARE.
//
// https://github.com/jerriep/dotnet-outdated/blob/b2c9e99c530a64e246ac529bbdc42ddde19b1e1a/src/DotNetOutdated.Core/Services/ProjectDiscoveryService.cs
// ReSharper disable once UnusedMember.Local
#pragma warning disable IDE0051
private ValidationResult OnValidate()
#pragma warning restore IDE0051
{
if (!(File.Exists(Project) || Directory.Exists(Project)))
{
Expand Down Expand Up @@ -104,8 +105,9 @@ private ValidationResult OnValidate()
return ValidationResult.Success;
}

// ReSharper disable once UnusedMember.Local
#pragma warning disable IDE0051
private void OnExecute()
#pragma warning restore IDE0051
{
var loggerFactory = LoggerFactory.Create(builder => builder
.SetMinimumLevel(Verbosity)
Expand Down Expand Up @@ -172,7 +174,7 @@ public AppWindow(DependencyGraph graph) : base("Depends", 0)
{
_graph = graph ?? throw new ArgumentNullException(nameof(graph));
_dependencies = _graph.Nodes.OrderBy(x => x.Id).ToImmutableList();
_visibleDependencies = _dependencies.Where(d => !(d is AssemblyReferenceNode)).ToImmutableList();
_visibleDependencies = _dependencies.Where(d => d is not AssemblyReferenceNode).ToImmutableList();
_assembliesVisible = false;
_lastSelectedDependencyIndex = -1;

Expand Down Expand Up @@ -268,7 +270,7 @@ public override bool ProcessKey(KeyEvent keyEvent)
_assembliesVisible = !_assembliesVisible;
_visibleDependencies = _assembliesVisible ?
_dependencies :
_dependencies.Where(d => !(d is AssemblyReferenceNode)).ToImmutableList();
_dependencies.Where(d => d is not AssemblyReferenceNode).ToImmutableList();

_dependenciesView.SetSource(_visibleDependencies);
_lastSelectedDependencyIndex = -1;
Expand Down

0 comments on commit e12e4f6

Please sign in to comment.