Skip to content

Commit

Permalink
Merge pull request #298 from nils-a/release/4.1.0
Browse files Browse the repository at this point in the history
Release/4.1.0
  • Loading branch information
nils-a authored Jan 16, 2024
2 parents a93a25b + b3f58d2 commit 222d609
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
uses: actions/checkout@v4
- name: Fetch all tags and branches
run: git fetch --prune --unshallow
- uses: actions/setup-dotnet@v3.2.0
- uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: |
2.1.818
Expand All @@ -69,15 +69,15 @@ jobs:
verbosity: Diagnostic
cake-version: tool-manifest
- name: Upload Issues
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
if-no-files-found: warn
name: ${{ matrix.os }} Issues
path: |
BuildArtifacts/report.html
BuildArtifacts/**/coverlet/*.xml
- name: Upload Packages
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: runner.os == 'Windows'
with:
if-no-files-found: warn
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v3.2.0
- uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: |
5.0.x
Expand All @@ -48,7 +48,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -68,10 +68,10 @@ jobs:
COMPlus_DbgMiniDumpName: BuildArtifacts/coredump.dmp

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3

- name: Upload CoreDump
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: failure()
with:
if-no-files-found: warn
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.100",
"version": "8.0.101",
"rollForward": "latestFeature"
}
}
8 changes: 4 additions & 4 deletions src/Cake.7zip.Tests/Cake.7zip.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.analyzers" Version="1.6.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.analyzers" Version="1.10.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
41 changes: 40 additions & 1 deletion src/Cake.7zip.Tests/FluentBuilder/AddCommandBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,45 @@ public void Add_can_use_CompressionMethod()
actual.ShouldBe(expected);
}

[Fact]
public void Add_can_use_CompressionMethod_additional_options()
{
var fixture = new FluentBuilderFixture();
fixture.Context
.InAddMode()
.WithArchive(new FilePath("out.zip"))
.WithFiles(new FilePath("in.txt"))
.WithCompressionMethodDictionarySize(26)
.WithCompressionMethodSortFilesByType(true);

const string expected = @"a -md=26 -mqs=on ""out.zip"" ""in.txt""";

var actual = fixture.EvaluateArgs();

actual.ShouldBe(expected);
}

[Fact]
public void Add_can_use_CompressionMethod_additional_options2()
{
var fixture = new FluentBuilderFixture();
fixture.Context
.InAddMode()
.WithArchive(new FilePath("out.zip"))
.WithFiles(new FilePath("in.txt"))
.WithCompressionMethod(m =>
{
m.DictionarySize = 25; // 32MB
m.SortFilesByType = false;
});

const string expected = @"a -md=25 -mqs=off ""out.zip"" ""in.txt""";

var actual = fixture.EvaluateArgs();

actual.ShouldBe(expected);
}

[Fact]
public void Add_can_use_CompressionMethod_multiple_times()
{
Expand Down Expand Up @@ -557,4 +596,4 @@ public void Add_can_use_FullQualifiedPaths_without_driveletter()

actual.ShouldBe(expected);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,30 @@ public void WithCompressionMethodMethod_returns_the_builder()

actual.ShouldBe(expected.Object);
}
}

[Fact]
public void WithCompressionMethodDictionarySize_returns_the_builder()
{
var expected = new Mock<ISupportSwitchBuilder<ISupportSwitchCompressionMethod>>();
var command = new Mock<ISupportSwitchCompressionMethod>();
command.SetupProperty(c => c.CompressionMethod);
expected.Setup(x => x.Command).Returns(command.Object);

var actual = expected.Object.WithCompressionMethodDictionarySize(default!);

actual.ShouldBe(expected.Object);
}

[Fact]
public void WithCompressionMethodSortFilesByType_returns_the_builder()
{
var expected = new Mock<ISupportSwitchBuilder<ISupportSwitchCompressionMethod>>();
var command = new Mock<ISupportSwitchCompressionMethod>();
command.SetupProperty(c => c.CompressionMethod);
expected.Setup(x => x.Command).Returns(command.Object);

var actual = expected.Object.WithCompressionMethodSortFilesByType(default!);

actual.ShouldBe(expected.Object);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,36 @@ public void CompressionMethod_method_works()
actual.ShouldBe(expected);
}

[Fact]
public void CompressionMethod_dictionarysize_works()
{
var fixture = new SevenZipSettingsFixture();
var sut = new SwitchCompressionMethod
{
DictionarySize = 24
};
const string expected = "-md=24";

var actual = fixture.Parse(b => sut.BuildArguments(ref b));

actual.ShouldBe(expected);
}

[Fact]
public void CompressionMethod_sortbyfiletype_works()
{
var fixture = new SevenZipSettingsFixture();
var sut = new SwitchCompressionMethod
{
SortFilesByType = true
};
const string expected = "-mqs=on";

var actual = fixture.Parse(b => sut.BuildArguments(ref b));

actual.ShouldBe(expected);
}

[Fact]
public void CompressionMethod_combining_method_and_level()
{
Expand All @@ -54,4 +84,22 @@ public void CompressionMethod_combining_method_and_level()

actual.ShouldBe(expected);
}
}

[Fact]
public void CompressionMethod_combining_all_options()
{
var fixture = new SevenZipSettingsFixture();
var sut = new SwitchCompressionMethod
{
Level = 9,
Method = "Copy",
DictionarySize = 23,
SortFilesByType = false
};
const string expected = "-mx=9 -mm=Copy -md=23 -mqs=off";

var actual = fixture.Parse(b => sut.BuildArguments(ref b));

actual.ShouldBe(expected);
}
}
28 changes: 27 additions & 1 deletion src/Cake.7zip/Builder/SwitchCompressionMethodBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,30 @@ public static T WithCompressionMethodLevel<T>(this T @this, int level)
{
return @this.WithCompressionMethod(x => x.Level = level);
}
}

/// <summary>
/// fluent setter for the method of <see cref="ISupportSwitchCompressionMethod"/>.
/// </summary>
/// <typeparam name="T">the builder to support the <see cref="ISupportSwitchCompressionMethod"/>.</typeparam>
/// <param name="this">The this.</param>
/// <param name="dictionarySize">Size of the dictionary.</param>
/// <returns>The builder-instance for fluent re-use.</returns>
public static T WithCompressionMethodDictionarySize<T>(this T @this, int dictionarySize)
where T : ISupportSwitchBuilder<ISupportSwitchCompressionMethod>
{
return @this.WithCompressionMethod(x => x.DictionarySize = dictionarySize);
}

/// <summary>
/// fluent setter for the method of <see cref="ISupportSwitchCompressionMethod"/>.
/// </summary>
/// <typeparam name="T">the builder to support the <see cref="ISupportSwitchCompressionMethod"/>.</typeparam>
/// <param name="this">The this.</param>
/// <param name="sortFilesByType">enable / disable the sorting files by type in solid archives.</param>
/// <returns>The builder-instance for fluent re-use.</returns>
public static T WithCompressionMethodSortFilesByType<T>(this T @this, bool sortFilesByType)
where T : ISupportSwitchBuilder<ISupportSwitchCompressionMethod>
{
return @this.WithCompressionMethod(x => x.SortFilesByType = sortFilesByType);
}
}
32 changes: 31 additions & 1 deletion src/Cake.7zip/Switches/SwitchCompressionMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ public class SwitchCompressionMethod : ISwitch
// TODO: Better use Enum or static Props instead of the free string?
public string? Method { private get; set; }

/// <summary>
/// Gets or sets the size of the dictionary.
///
/// Dictionary size in bytes will be calculated as 2 ^ DictionarySize (24 -> 2 ^ 24 -> 16MB).
/// </summary>
/// <value>
/// The size of the dictionary.
/// </value>
public int? DictionarySize { get; set; }

/// <summary>
/// Gets or sets the sorting files by type in solid archives.
///
/// The default mode is qs=off.
/// </summary>
/// <value>
/// The size of the dictionary.
/// </value>
public bool? SortFilesByType { get; set; }

/// <inheritdoc/>
public void BuildArguments(ref ProcessArgumentBuilder builder)
{
Expand All @@ -53,5 +73,15 @@ public void BuildArguments(ref ProcessArgumentBuilder builder)
{
builder.Append($"-mm={Method}");
}

if (DictionarySize.HasValue)
{
builder.Append($"-md={DictionarySize.Value}");
}

if (SortFilesByType.HasValue)
{
builder.Append($"-mqs={(SortFilesByType.Value ? "on" : "off")}");
}
}
}
}

0 comments on commit 222d609

Please sign in to comment.