Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleaning dependencies before update nuspec #84

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,49 @@ public void verify_the_dependencies()
verifyVersion(spec, "Something", "1.0.1.244");
}


[Test]
public void verify_the_dependencies_afer_second_update()
{
RippleOperation
.With(theSolution, false)
.Execute<CreatePackagesInput, LocalNugetCommand>(input =>
{
input.VersionFlag = "1.0.1.245";
input.UpdateDependenciesFlag = true;
});

var specFile = theSolution.Specifications.Single(x => x.Name == "SomeProject");
var spec = NugetSpec.ReadFrom(specFile.Filename);

verifyVersion(spec, "Bottles", "[1.1.0.255, 2.0.0.0)");
verifyVersion(spec, "FubuCore", "1.0.1.244");
verifyVersion(spec, "FubuLocalization", "[1.8.0.0, 1.9.0.0)");
verifyVersion(spec, "Something", "1.0.1.245");
}

[Test]
public void verify_the_dependencies_afer_second_update_with_override()
{
theSolution.RemoveDependency("Bottles");
RippleOperation
.With(theSolution, false)
.Execute<CreatePackagesInput, LocalNugetCommand>(input =>
{
input.VersionFlag = "1.0.1.244";
input.UpdateDependenciesFlag = true;
input.OverrideDependenciesFlag = true;
});

var specFile = theSolution.Specifications.Single(x => x.Name == "SomeProject");
var spec = NugetSpec.ReadFrom(specFile.Filename);

Assert.IsNull(spec.FindDependency("Bottles"));
Assert.IsNull(spec.FindDependency("FubuCore"));
Assert.IsNull(spec.FindDependency("FubuLocalization"));
verifyVersion(spec, "Something", "1.0.1.244");
}

private void verifyVersion(NugetSpec spec, string name, string version)
{
spec.FindDependency(name).VersionSpec.ToString().ShouldEqual(version);
Expand Down
5 changes: 5 additions & 0 deletions src/ripple/Commands/LocalNugetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public CreatePackagesInput()
[FlagAlias("symbols")]
public bool CreateSymbolsFlag { get; set; }


[Description("Override dependencies in the nuspec files to match only ripple dependecies")]
[FlagAlias("override-dependencies")]
public bool OverrideDependenciesFlag { get; set; }

public IEnumerable<SpecGroup> SpecsFor(Solution solution)
{
if (!UpdateDependenciesFlag)
Expand Down
34 changes: 24 additions & 10 deletions src/ripple/Local/NuspecDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,27 @@ private IEnumerable<XElement> findNugetElements(string name)
}

public void AddDependency(NuspecDependency dependency)
{
{
var dependencies = _document.XPathSelectElement("//nuspec:dependencies", _xmlNamespaceManager);
var element = _document.XPathSelectElement(string.Format("//nuspec:dependencies/nuspec:dependency[@id='{0}']", dependency.Name), _xmlNamespaceManager);
if (element == null)
{
element = new XElement(_xmlns + "dependency");
element.SetAttributeValue("id", dependency.Name);
dependencies.Add(element);
}

var element = new XElement(_xmlns + "dependency");
element.SetAttributeValue("id", dependency.Name);

if (dependency.VersionSpec != null)
{
element.SetAttributeValue("version", dependency.VersionSpec.ToString());
}
if (dependency.VersionSpec != null)
{
element.SetAttributeValue("version", dependency.VersionSpec.ToString());
}
else
{
if (element.Attribute("version") != null)
element.Attribute("version").Remove();
}

dependencies.Add(element);
}
}

public void AddPublishedAssembly(string src, string target = "lib")
{
Expand Down Expand Up @@ -167,5 +175,11 @@ public void SetVersion(string dependency, string version)

element.SetAttributeValue("version", version);
}

public void ClearAllDependencies()
{
var dependencies = _document.XPathSelectElement("//nuspec:dependencies", _xmlNamespaceManager);
dependencies.RemoveAll();
}
}
}
5 changes: 5 additions & 0 deletions src/ripple/Steps/UpdateNuspecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ private void updateSpecification(CreatePackagesInput input, SpecGroup group, IEn
var spec = group.Spec;
var local = Solution.LocalDependencies();
var nuspec = new NuspecDocument(spec.Filename);

if(input.OverrideDependenciesFlag)
nuspec.ClearAllDependencies();

nuspec.ClearAllDependencies();

group
.DetermineDependencies()
Expand Down