Skip to content

Commit

Permalink
make ISource IDisposable, fixes #33
Browse files Browse the repository at this point in the history
  • Loading branch information
bodewig committed Sep 27, 2020
1 parent 7411b5e commit 7549fb2
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 5 deletions.
9 changes: 8 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Release Notes

## XMLUnit.NET 2.8.1 - /not released, yet/
## XMLUnit.NET 2.9.0 - /not released, yet/

* `ISource` now extends `IDisposable` to allow releasing unmanaged
resources used when building sources from files or URIs.

This change is backwards incompatible if you are providing `ISource`
implementations of your own.
[#33](https://github.com/xmlunit/xmlunit.net/pull/33).

## XMLUnit.NET 2.8.0 - /Released 2020-05-12/

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 2.8.1.{build}
version: 2.9.0.{build}

image:
- Visual Studio 2013
Expand Down
2 changes: 1 addition & 1 deletion src/doc/monodoc/core/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@
under <format type="text/html"><a href="https://github.com/xmlunit/xmlunit.net/blob/main/LICENSE">the
Apache License, Version 2.0</a></format>.</para></Remarks>
<Copyright></Copyright>
<Title>XMLUnit.NET 2.8.1-alpha-01</Title>
<Title>XMLUnit.NET 2.9.0-alpha-01</Title>
</Overview>
2 changes: 1 addition & 1 deletion src/main/net-core/ISource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Org.XmlUnit {
/// Representation of the various ways to provide pieces of XML to
/// XMLUnit.
/// </summary>
public interface ISource {
public interface ISource : System.IDisposable {
/// <summary>
/// Provides the content.
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions src/main/net-core/Input/AbstractSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Org.XmlUnit.Input
/// </summary>
public abstract class AbstractSource : ISource
{
private bool disposed;
private string systemId;
private readonly XmlReader reader;
/// <summary>
Expand Down Expand Up @@ -61,5 +62,16 @@ public override string ToString()
return string.Format("{0} with systemId {1}", GetType().Name,
SystemId);
}

public void Dispose() {
Dispose(false);
}

protected virtual void Dispose(bool disposing) {
if (!disposed) {
reader.Close();
disposed = true;
}
}
}
}
2 changes: 2 additions & 0 deletions src/main/net-core/Input/ByteArraySource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ public override string ToString()
{
return string.Format("ByteArraySource with systemId {0}", SystemId);
}

public void Dispose() { }
}
}
8 changes: 8 additions & 0 deletions src/main/net-core/Input/CommentLessSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace Org.XmlUnit.Input {
/// </para>
/// </remarks>
public sealed class CommentLessSource : ISource {
private bool disposed;
private readonly XmlReader reader;
private string systemId;

Expand Down Expand Up @@ -100,6 +101,13 @@ public string SystemId
}
}

public void Dispose() {
if (!disposed) {
reader.Close();
disposed = true;
}
}

private static ISource GetStylesheet(string xsltVersion) {
return new StreamSource(new System.IO.StringReader(GetStylesheetContentCached(xsltVersion)));
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/net-core/Input/NormalizedSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace Org.XmlUnit.Input {
/// </para>
/// </remarks>
public class NormalizedSource : ISource {
private bool disposed;
private string systemId;
private readonly XmlReader reader;
private readonly XmlNode node;
Expand Down Expand Up @@ -107,5 +108,16 @@ public override string ToString()
return string.Format("{0} with systemId {1}", GetType().Name,
SystemId);
}

public void Dispose() {
Dispose(false);
}

protected virtual void Dispose(bool disposing) {
if (!disposed) {
reader.Close();
disposed = true;
}
}
}
}
2 changes: 2 additions & 0 deletions src/main/net-core/Input/StringSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@ public override string ToString()
return string.Format("StringSource with content{0} and systemId {1}", content,
SystemId);
}

public void Dispose() { }
}
}
2 changes: 1 addition & 1 deletion src/shared/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Org.XmlUnit
{
internal static class XmlUnitVersion
{
internal const string ApiVersion = "2.8.1";
internal const string ApiVersion = "2.9.0";
internal const string AssemblyVersion = ApiVersion + ".198";
internal const string Version = ApiVersion + "-alpha-01";
}
Expand Down

0 comments on commit 7549fb2

Please sign in to comment.