-
Notifications
You must be signed in to change notification settings - Fork 2
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 #5 from seesharper/feature-nuspec
Feature nuspec
- Loading branch information
Showing
12 changed files
with
280 additions
and
12 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
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
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
20 changes: 20 additions & 0 deletions
20
src/Dotnet.Deps.Core/ProjectSystem/NuspecPackageReference.cs
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,20 @@ | ||
using System.Xml.Linq; | ||
using NuGet.Versioning; | ||
|
||
namespace Dotnet.Deps.Core.ProjectSystem | ||
{ | ||
public class NuspecPackageReference : NuGetPackageReference | ||
{ | ||
private readonly XElement packageElement; | ||
|
||
public NuspecPackageReference(string name, string versionString, FloatRange floatRange, XElement packageElement) : base(name, versionString, floatRange) | ||
{ | ||
this.packageElement = packageElement; | ||
} | ||
|
||
public override void Update(string newVersion) | ||
{ | ||
packageElement.Attribute("version").Value = newVersion; | ||
} | ||
} | ||
} |
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,29 @@ | ||
using System.Xml.Linq; | ||
|
||
namespace Dotnet.Deps.Core.ProjectSystem | ||
{ | ||
/// <summary> | ||
/// Represents a MsBuild SDK-style project file. | ||
/// </summary> | ||
public class NuspecProjectFile : IProjectFile<NuspecPackageReference> | ||
{ | ||
private readonly XDocument msBuildProjectFile; | ||
|
||
|
||
public NuspecProjectFile(XDocument msBuildProjectFile, string path) | ||
{ | ||
this.msBuildProjectFile = msBuildProjectFile; | ||
Path = path; | ||
} | ||
|
||
public NuspecPackageReference[] PackageReferences { get; set; } | ||
|
||
public string Path { get; } | ||
|
||
public void Save() | ||
{ | ||
msBuildProjectFile.Save(Path); | ||
} | ||
} | ||
|
||
} |
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,58 @@ | ||
using System.Collections.Generic; | ||
using System.Xml.Linq; | ||
using NuGet.Versioning; | ||
|
||
namespace Dotnet.Deps.Core.ProjectSystem | ||
{ | ||
public class NuspecProjectLoader : IProjectLoader | ||
{ | ||
private readonly AppConsole console; | ||
|
||
public NuspecProjectLoader(AppConsole console) | ||
{ | ||
this.console = console; | ||
} | ||
|
||
public string FileExtensions { get => "nuspec"; } | ||
|
||
public IProjectFile<NuGetPackageReference> Load(string path) | ||
{ | ||
var projectFile = XDocument.Load(path); | ||
var nameSpace = projectFile.Root.Name.Namespace; | ||
var nugetSpecProjectFile = new NuspecProjectFile(projectFile, path); | ||
var packageReferenceElements = projectFile.Descendants(nameSpace + "dependency"); | ||
var packageReferences = new List<NuspecPackageReference>(); | ||
foreach (var packageReferenceElement in packageReferenceElements) | ||
{ | ||
var packageName = packageReferenceElement.Attribute("id")?.Value; | ||
if (string.IsNullOrWhiteSpace(packageName)) | ||
{ | ||
continue; | ||
} | ||
|
||
var packageVersion = packageReferenceElement.Attribute("version")?.Value; | ||
if (packageVersion == null) | ||
{ | ||
continue; | ||
} | ||
|
||
if (FloatRange.TryParse(packageVersion, out var floatRange)) | ||
{ | ||
var nugetVersion = floatRange.MinVersion; | ||
var nugetPackageReference = new NuspecPackageReference(packageName, packageVersion, floatRange, packageReferenceElement); | ||
packageReferences.Add(nugetPackageReference); | ||
} | ||
else | ||
{ | ||
console.WriteError($"Warning: The package '{packageName}' has an invalid version number '{packageVersion}'"); | ||
} | ||
} | ||
|
||
nugetSpecProjectFile.PackageReferences = packageReferences.ToArray(); | ||
|
||
|
||
return nugetSpecProjectFile; | ||
} | ||
} | ||
|
||
} |
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
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
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
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,75 @@ | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Dotnet.Deps.Tests | ||
{ | ||
public partial class NuspecTests | ||
{ | ||
[Fact] | ||
public void ShouldListOutdatedDependency() | ||
{ | ||
var result = new NuspecTestCase() | ||
.AddPackage("LightInject", "5.1.0") | ||
.Execute(); | ||
result.StandardOut.Should().Contain("LightInject 5.1.0 =>"); | ||
result.ProjectFile.ShouldHaveNuspecPackageReference("LightInject", "5.1.0"); | ||
result.ExitCode.Should().Be(0); | ||
} | ||
|
||
[Fact] | ||
public void ShouldUpdateToLatestVersion() | ||
{ | ||
var result = new NuspecTestCase() | ||
.AddPackage("LightInject", "5.1.0") | ||
.Execute("--update"); | ||
result.ProjectFile.ShouldHaveNuspecPackageReferenceWithLatestVersion("LightInject", "5.1.0"); | ||
} | ||
|
||
[Fact] | ||
public void ShouldListFloatingDependency() | ||
{ | ||
var result = new NuspecTestCase() | ||
.AddPackage("LightInject", "6.*") | ||
.Execute(); | ||
} | ||
|
||
|
||
[Fact] | ||
public void ShouldHandleInvalidVersionNumber() | ||
{ | ||
var result = new NuspecTestCase() | ||
.AddPackage("LightInject", "Rubbish") | ||
.Execute(); | ||
result.StandardOut.Should().Contain("Warning"); | ||
} | ||
|
||
[Fact] | ||
public void ShouldIgnorePackageWithMissingVersionNumber() | ||
{ | ||
var result = new NuspecTestCase() | ||
.AddPackage("LightInject") | ||
.Execute(); | ||
result.StandardOut.Should().NotContain("LightInject 5.1.0 =>"); | ||
} | ||
|
||
[Fact] | ||
public void ShouldExcludeFilteredPackages() | ||
{ | ||
var result = new NuspecTestCase() | ||
.AddPackage("LightInject", "5.1.0") | ||
.WithFilter("Microsoft") | ||
.Execute(); | ||
result.StandardOut.Should().NotContain("LightInject 5.1.0 =>"); | ||
} | ||
|
||
[Fact] | ||
public void ShouldIncludeFilteredPackages() | ||
{ | ||
var result = new NuspecTestCase() | ||
.AddPackage("LightInject", "5.1.0") | ||
.WithFilter("LightInject") | ||
.Execute(); | ||
result.StandardOut.Should().Contain("LightInject 5.1.0 =>"); | ||
} | ||
} | ||
} |
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
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