From ae38d196d0a4cc5ea1c367c430b0b81308115d59 Mon Sep 17 00:00:00 2001
From: Artur Kordowski <9746197+akordowski@users.noreply.github.com>
Date: Tue, 15 Jul 2025 19:27:58 +0200
Subject: [PATCH] Refactor project and tests, update Cake and target frameworks
---
.config/dotnet-tools.json | 13 -
.editorconfig | 43 +
.gitattributes | 31 -
.../build-and-test-solution/action.yml | 32 +
.github/workflows/build-and-test.yml | 40 +
.github/workflows/dotnet.yml | 25 -
.github/workflows/publish-nuget.yml | 29 +
.gitignore | 203 ++-
Cake.Compression.sln | 39 +
README.md | 6 +-
RELEASENOTES.md | 47 +-
appveyor.yml | 17 -
build.bat | 2 -
build.cake | 31 -
build.ps1 | 13 -
build.sh | 12 -
nuget.config | 20 +
nuget/NUGET.md | 21 +
nuget/NuGet.Package.props | 56 +
{assets => nuget}/cake-contrib-medium.png | Bin
.../Cake.Compression.Tests.csproj | 17 -
.../Classes/BZip2Tests.cs | 190 ---
.../Classes/GZipTests.cs | 190 ---
src/Cake.Compression.Tests/Classes/ZipTest.cs | 190 ---
src/Cake.Compression.sln | 48 -
src/Cake.Compression/Cake.Compression.csproj | 37 +-
src/Cake.Compression/Classes/Bzip2.cs | 167 +--
.../Classes/CompressionBase.cs | 150 +-
src/Cake.Compression/Classes/GZip.cs | 169 +--
src/Cake.Compression/Classes/Zip.cs | 201 +--
src/Cake.Compression/CompressionAliases.cs | 1314 +++++++++--------
src/Cake.Compression/Precondition.cs | 66 -
src/Directory.Build.props | 21 +
src/Directory.Build.targets | 6 +
src/Directory.Packages.props | 15 +
.../Cake.Compression.Tests.csproj | 35 +
.../CompressionTests.cs | 185 +++
tests/Directory.Build.props | 9 +
tests/Directory.Build.targets | 6 +
tests/Directory.Packages.props | 20 +
tools/packages.config | 4 -
41 files changed, 1842 insertions(+), 1878 deletions(-)
delete mode 100644 .config/dotnet-tools.json
create mode 100644 .editorconfig
delete mode 100644 .gitattributes
create mode 100644 .github/actions/build-and-test-solution/action.yml
create mode 100644 .github/workflows/build-and-test.yml
delete mode 100644 .github/workflows/dotnet.yml
create mode 100644 .github/workflows/publish-nuget.yml
create mode 100644 Cake.Compression.sln
delete mode 100644 appveyor.yml
delete mode 100644 build.bat
delete mode 100644 build.cake
delete mode 100644 build.ps1
delete mode 100644 build.sh
create mode 100644 nuget.config
create mode 100644 nuget/NUGET.md
create mode 100644 nuget/NuGet.Package.props
rename {assets => nuget}/cake-contrib-medium.png (100%)
delete mode 100644 src/Cake.Compression.Tests/Cake.Compression.Tests.csproj
delete mode 100644 src/Cake.Compression.Tests/Classes/BZip2Tests.cs
delete mode 100644 src/Cake.Compression.Tests/Classes/GZipTests.cs
delete mode 100644 src/Cake.Compression.Tests/Classes/ZipTest.cs
delete mode 100644 src/Cake.Compression.sln
delete mode 100644 src/Cake.Compression/Precondition.cs
create mode 100644 src/Directory.Build.props
create mode 100644 src/Directory.Build.targets
create mode 100644 src/Directory.Packages.props
create mode 100644 tests/Cake.Compression.Tests/Cake.Compression.Tests.csproj
create mode 100644 tests/Cake.Compression.Tests/CompressionTests.cs
create mode 100644 tests/Directory.Build.props
create mode 100644 tests/Directory.Build.targets
create mode 100644 tests/Directory.Packages.props
delete mode 100644 tools/packages.config
diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json
deleted file mode 100644
index b6554f3..0000000
--- a/.config/dotnet-tools.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "version": 1,
- "isRoot": true,
- "tools": {
- "cake.tool": {
- "version": "5.0.0",
- "commands": [
- "dotnet-cake"
- ],
- "rollForward": false
- }
- }
-}
\ No newline at end of file
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..6ed2e0b
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,43 @@
+##########################################
+# Common Settings
+##########################################
+
+# This file is the top-most EditorConfig file
+root = true
+
+# All Files
+[*]
+charset = utf-8
+indent_style = space
+indent_size = 4
+insert_final_newline = true
+trim_trailing_whitespace = true
+
+# JSON
+[*.{json,json5,webmanifest}]
+indent_size = 2
+
+# Markdown
+[*.{md,mdx}]
+trim_trailing_whitespace = false
+
+# Visual Studio
+[*.{csproj}]
+indent_size = 2
+
+[*.cs]
+# https://learn.microsoft.com/de-de/dotnet/fundamentals/code-analysis/style-rules/ide0063
+dotnet_diagnostic.IDE0063.severity = none
+csharp_prefer_simple_using_statement = false
+
+# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0290
+dotnet_diagnostic.IDE0290.severity = none
+csharp_style_prefer_primary_constructors = false
+
+# ReSharper
+# https://www.jetbrains.com/help/rider/ConvertToPrimaryConstructor.html
+resharper_convert_to_primary_constructor_highlighting = none
+
+resharper_convert_to_using_declaration_highlighting = none
+
+resharper_foreach_can_be_converted_to_query_using_another_get_enumerator_highlighting = none
diff --git a/.gitattributes b/.gitattributes
deleted file mode 100644
index feed56d..0000000
--- a/.gitattributes
+++ /dev/null
@@ -1,31 +0,0 @@
-# Auto detect text files and perform LF normalization
-* text=auto
-*.cs diff=csharp
-
-# Documents
-*.doc diff=astextplain
-*.DOC diff=astextplain
-*.docx diff=astextplain
-*.DOCX diff=astextplain
-*.dot diff=astextplain
-*.DOT diff=astextplain
-*.pdf diff=astextplain
-*.PDF diff=astextplain
-*.rtf diff=astextplain
-*.RTF diff=astextplain
-*.md text
-*.adoc text
-*.textile text
-*.mustache text
-*.csv text
-*.tab text
-*.tsv text
-*.sql text
-
-# Graphics
-*.png binary
-*.jpg binary
-*.jpeg binary
-*.gif binary
-*.ico binary
-*.svg text
\ No newline at end of file
diff --git a/.github/actions/build-and-test-solution/action.yml b/.github/actions/build-and-test-solution/action.yml
new file mode 100644
index 0000000..9ce4cbb
--- /dev/null
+++ b/.github/actions/build-and-test-solution/action.yml
@@ -0,0 +1,32 @@
+name: Build and test solution
+description: Build and test solution
+inputs:
+ dotnet-version:
+ description: 'The dotnet version'
+ default: '9.0.x'
+ configuration:
+ description: 'The dotnet build configuration'
+ default: 'Release'
+runs:
+ using: "composite"
+ steps:
+ - name: Setup dotnet
+ uses: actions/setup-dotnet@v4
+ with:
+ dotnet-version: ${{ inputs.dotnet-version }}
+
+ - name: Restore dependencies
+ shell: bash
+ run: dotnet restore
+
+ - name: Build solution
+ shell: bash
+ run: dotnet build --configuration ${{ inputs.configuration }} --no-restore
+
+ - name: Run unit tests
+ shell: bash
+ run: |
+ export TEST_PROJECTS=$(find ./tests -type f -name "*.Tests.csproj")
+ for project in $TEST_PROJECTS; do
+ dotnet test --configuration ${{ inputs.configuration }} $project --no-build --verbosity Normal --logger trx --collect:"XPlat Code Coverage" --results-directory:"test-results/coverage/" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.ExcludeByAttribute=GeneratedCodeAttribute,CompilerGeneratedAttribute,ExcludeFromCodeCoverageAttribute
+ done
diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml
new file mode 100644
index 0000000..9e0fe72
--- /dev/null
+++ b/.github/workflows/build-and-test.yml
@@ -0,0 +1,40 @@
+name: Build and test
+
+on:
+ push:
+ branches:
+ - main
+ paths:
+ - 'src/**'
+ - 'tests/**'
+ pull_request:
+ branches:
+ - main
+
+# Permissions for the 'Publish test results' action
+permissions:
+ contents: read
+ issues: read
+ checks: write
+ pull-requests: write
+
+jobs:
+ build-and-test:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [windows-latest, ubuntu-latest, macos-latest]
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+
+ - name: Build and test solution
+ uses: ./.github/actions/build-and-test-solution
+
+ - name: Publish test results
+ if: matrix.os == 'ubuntu-latest'
+ uses: EnricoMi/publish-unit-test-result-action@v2
+ with:
+ files: |
+ test-results/**/*.trx
diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml
deleted file mode 100644
index daca051..0000000
--- a/.github/workflows/dotnet.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-name: .NET
-
-on:
- push:
-
-jobs:
- build:
-
- runs-on: ${{ matrix.os }}
- strategy:
- matrix:
- os: [windows-latest, ubuntu-latest, macos-latest]
-
- steps:
- - uses: actions/checkout@v2
- - name: Setup .NET
- uses: actions/setup-dotnet@v1
- with:
- dotnet-version: 8.0.x
- - name: Restore dependencies
- run: dotnet restore ./src/Cake.Compression.sln
- - name: Build
- run: dotnet build ./src/Cake.Compression.sln --no-restore
- - name: Test
- run: dotnet test ./src/Cake.Compression.sln --no-build --verbosity normal
\ No newline at end of file
diff --git a/.github/workflows/publish-nuget.yml b/.github/workflows/publish-nuget.yml
new file mode 100644
index 0000000..0cca910
--- /dev/null
+++ b/.github/workflows/publish-nuget.yml
@@ -0,0 +1,29 @@
+name: Publish NuGet
+
+on:
+ push:
+ tags:
+ - v*.*.*
+
+env:
+ NUGET_PACKAGE_DIR: ./nupkg
+ NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
+ NUGET_SOURCE: ${{ vars.NUGET_SOURCE }}
+
+jobs:
+ publish-nuget:
+ if: github.event.base_ref == 'refs/heads/main'
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+
+ - name: Build and test solution
+ uses: ./.github/actions/build-and-test-solution
+
+ - name: Pack NuGet packages
+ run: dotnet pack --configuration Release --no-build --output $NUGET_PACKAGE_DIR
+
+ - name: Publish NuGet packages and symbols
+ run: dotnet nuget push $NUGET_PACKAGE_DIR/*.nupkg --api-key $NUGET_API_KEY --source $NUGET_SOURCE
diff --git a/.gitignore b/.gitignore
index 119b008..26f53b8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,10 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
+##
+## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
# User-specific files
+*.rsuser
*.suo
*.user
*.userosscache
@@ -10,6 +13,9 @@
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
+# Mono auto generated files
+mono_crash.*
+
# Build results
[Dd]ebug/
[Dd]ebugPublic/
@@ -17,41 +23,62 @@
[Rr]eleases/
x64/
x86/
+[Ww][Ii][Nn]32/
+[Aa][Rr][Mm]/
+[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
+[Ll]ogs/
-# Visual Studio 2015 cache/options directory
+# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
+# Visual Studio 2017 auto generated files
+Generated\ Files/
+
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
-# NUNIT
+# NUnit
*.VisualState.xml
TestResult.xml
+nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
-# DNX
+# Benchmark Results
+BenchmarkDotNet.Artifacts/
+
+# .NET Core
project.lock.json
+project.fragment.lock.json
artifacts/
+# ASP.NET Scaffolding
+ScaffoldingReadMe.txt
+
+# StyleCop
+StyleCopReport.xml
+
+# Files built by Visual Studio
*_i.c
*_p.c
-*_i.h
+*_h.h
*.ilk
*.meta
*.obj
+*.iobj
*.pch
*.pdb
+*.ipdb
*.pgc
*.pgd
*.rsp
@@ -61,7 +88,9 @@ artifacts/
*.tlh
*.tmp
*.tmp_proj
+*_wpftmp.csproj
*.log
+*.tlog
*.vspscc
*.vssscc
.builds
@@ -80,6 +109,8 @@ ipch/
*.opensdf
*.sdf
*.cachefile
+*.VC.db
+*.VC.VC.opendb
# Visual Studio profiler
*.psess
@@ -87,6 +118,9 @@ ipch/
*.vspx
*.sap
+# Visual Studio Trace Files
+*.e2e
+
# TFS 2012 Local Workspace
$tf/
@@ -98,15 +132,25 @@ _ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
-# JustCode is a .NET coding add-in
-.JustCode
-
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
+# AxoCover is a Code Coverage Tool
+.axoCover/*
+!.axoCover/settings.json
+
+# Coverlet is a free, cross platform Code Coverage Tool
+coverage*.json
+coverage*.xml
+coverage*.info
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
# NCrunch
_NCrunch_*
.*crunch*.local.xml
@@ -138,20 +182,27 @@ publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
-# TODO: Comment the next line if you want to checkin your web deploy settings
+# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
# NuGet Packages
*.nupkg
+# NuGet Symbol Packages
+*.snupkg
# The packages folder can be ignored because of Package Restore
-**/packages/*
+**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
-!**/packages/build/
+!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
-#!**/packages/repositories.config
-# NuGet v3's project.json files produces more ignoreable files
+#!**/[Pp]ackages/repositories.config
+# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
@@ -163,18 +214,20 @@ csx/
ecf/
rcf/
-# Microsoft Azure ApplicationInsights config file
-ApplicationInsights.config
-
-# Windows Store app package directory
+# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+*.appx
+*.appxbundle
+*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
-!*.[Cc]ache/
+!?*.[Cc]ache/
# Others
ClientBin/
@@ -182,11 +235,19 @@ ClientBin/
*~
*.dbmdl
*.dbproj.schemaview
+*.jfm
*.pfx
*.publishsettings
-node_modules/
orleans.codegen.cs
+# Including strong name files can present a security risk
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
+#*.snk
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
# RIA/Silverlight projects
Generated_Code/
@@ -197,15 +258,22 @@ _UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
+ServiceFabricBackup/
+*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
+*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
+*.rptproj.rsuser
+*- [Bb]ackup.rdl
+*- [Bb]ackup ([0-9]).rdl
+*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
@@ -215,6 +283,7 @@ FakesAssemblies/
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
+node_modules/
# Visual Studio 6 build log
*.plg
@@ -222,6 +291,20 @@ FakesAssemblies/
# Visual Studio 6 workspace options file
*.opt
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+*.vbw
+
+# Visual Studio 6 auto-generated project file (contains which files were open etc.)
+*.vbp
+
+# Visual Studio 6 workspace and project file (working project files containing files to include in project)
+*.dsw
+*.dsp
+
+# Visual Studio 6 technical files
+*.ncb
+*.aps
+
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
@@ -232,17 +315,85 @@ _Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
+paket-files/
# FAKE - F# Make
.fake/
-# SandCastle Docs
-**/[Dd]ocs/[Hh]elp
+# CodeRush personal settings
+.cr/personal
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config
+
+# Tabs Studio
+*.tss
+
+# Telerik's JustMock configuration file
+*.jmconfig
+
+# BizTalk build output
+*.btp.cs
+*.btm.cs
+*.odx.cs
+*.xsd.cs
+
+# OpenCover UI analysis results
+OpenCover/
+
+# Azure Stream Analytics local run output
+ASALocalRun/
+
+# MSBuild Binary and Structured Log
+*.binlog
+
+# NVidia Nsight GPU debugger configuration file
+*.nvuser
+
+# MFractors (Xamarin productivity tool) working folder
+.mfractor/
+
+# Local History for Visual Studio
+.localhistory/
+
+# Visual Studio History (VSHistory) files
+.vshistory/
+
+# BeatPulse healthcheck temp database
+healthchecksdb
+
+# Backup folder for Package Reference Convert tool in Visual Studio 2017
+MigrationBackup/
+
+# Ionide (cross platform F# VS Code tools) working folder
+.ionide/
+
+# Fody - auto-generated XML schema
+FodyWeavers.xsd
+
+# VS Code files for those working on multiple tools
+.vscode/*
+!.vscode/settings.json
+!.vscode/tasks.json
+!.vscode/launch.json
+!.vscode/extensions.json
+*.code-workspace
+
+# Local History for Visual Studio Code
+.history/
-# Cake
-**/artifacts/*
-**/tools/*
-!**/tools/packages.config
+# Windows Installer files from build outputs
+*.cab
+*.msi
+*.msix
+*.msm
+*.msp
-# Rider
-.idea/
\ No newline at end of file
+# JetBrains Rider
+.idea/
+*.sln.iml
diff --git a/Cake.Compression.sln b/Cake.Compression.sln
new file mode 100644
index 0000000..64cd80b
--- /dev/null
+++ b/Cake.Compression.sln
@@ -0,0 +1,39 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.14.36301.6
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.Compression", "src\Cake.Compression\Cake.Compression.csproj", "{978AD8C9-1363-4C75-A51E-205FEE4A9376}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{683DB8BF-2DC6-4334-97CA-FF99043FD9FD}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.Compression.Tests", "tests\Cake.Compression.Tests\Cake.Compression.Tests.csproj", "{08B15274-DDDD-4407-9280-5940AC3D3CC5}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {978AD8C9-1363-4C75-A51E-205FEE4A9376}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {978AD8C9-1363-4C75-A51E-205FEE4A9376}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {978AD8C9-1363-4C75-A51E-205FEE4A9376}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {978AD8C9-1363-4C75-A51E-205FEE4A9376}.Release|Any CPU.Build.0 = Release|Any CPU
+ {08B15274-DDDD-4407-9280-5940AC3D3CC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {08B15274-DDDD-4407-9280-5940AC3D3CC5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {08B15274-DDDD-4407-9280-5940AC3D3CC5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {08B15274-DDDD-4407-9280-5940AC3D3CC5}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ {978AD8C9-1363-4C75-A51E-205FEE4A9376} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
+ {08B15274-DDDD-4407-9280-5940AC3D3CC5} = {683DB8BF-2DC6-4334-97CA-FF99043FD9FD}
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {A2EBF436-64E6-43E6-9C30-C55788575F35}
+ EndGlobalSection
+EndGlobal
diff --git a/README.md b/README.md
index 37cad7b..922778f 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Cake.Compression
-[](LICENSE.txt)
-[](https://ci.appveyor.com/project/ArturKordowski/cake-compression/branch/master)
+[](https://github.com/akordowski/Cake.Compression/LICENSE)
+[](https://github.com/akordowski/Cake.Compression/actions/workflows/build-and-test.yml)
[](https://www.nuget.org/packages/Cake.Compression/)
A Cake AddIn which provides compression functionality for BZip2, GZip and Zip.
@@ -18,4 +18,4 @@ or directly in your build script via a Cake `#addin` directive:
```csharp
#addin nuget:?package=SharpZipLib
#addin nuget:?package=Cake.Compression
-```
\ No newline at end of file
+```
diff --git a/RELEASENOTES.md b/RELEASENOTES.md
index 1b8067a..610f54e 100644
--- a/RELEASENOTES.md
+++ b/RELEASENOTES.md
@@ -1,56 +1,57 @@
### 0.4.0
-Update to Cake 5.0.0
-Add framework support for `net8.0`
-Drop framework support for `netcoreapp3.1`, `net5.0`, `net6.0`
+Refactor project and tests
+Update to `Cake 5.0.0`
+Add framework support for `net8.0` and `net9.0`
+Drop framework support for `netcoreapp3.1`, `net5.0`, `net6.0`
### 0.3.0
-Update to Cake 2.0.0
-Add framework support for `netcoreapp3.1`, `net6.0`
-Drop framework support for `net461`, `netstandard2.0`
-Update contrib icon
-Update dependencies
+Update to `Cake 2.0.0`
+Add framework support for `netcoreapp3.1`, `net6.0`
+Drop framework support for `net461`, `netstandard2.0`
+Update contrib icon
+Update dependencies
Add GitHub Action
### 0.2.6
Add framework support for `net461`, `netstandard2.0`, `net5.0`
### 0.2.5
-Update to Cake 1.0.
-Update dependencies.
+Update to `Cake 1.0`
+Update dependencies
### 0.2.4
-Update dependencies.
+Update dependencies
### 0.2.3
-Update dependencies.
+Update dependencies
### 0.2.2
-Update dependencies.
+Update dependencies
### 0.2.1
-Fix nuspec to target SharpZipLib 1.0.0-rc1.
+Fix nuspec to target `SharpZipLib 1.0.0-rc1`
### 0.2.0
-Update to target .netstandard2.0.
-Update SharpZipLib to version 1.0.0-rc1.
+Update to target `.netstandard2.0`
+Update to `SharpZipLib 1.0.0-rc1`
### 0.1.7
-Update to Cake 0.29.0.
+Update to `Cake 0.29.0`
### 0.1.6
-* #13 Bugfix
+#13 Bugfix
### 0.1.5
-Update to Cake 0.26.1.
+Update to `Cake 0.26.1`
### 0.1.4
-Update to Cake 0.22.0.
+Update to `Cake 0.22.0`
### 0.1.2
-* #8 Sets date on zip entries
+#8 Sets date on zip entries
### 0.1.1
-Update to Cake 0.18.0.
+Update to `Cake 0.18.0`
### 0.1.0
-Initial Release.
\ No newline at end of file
+Initial release
diff --git a/appveyor.yml b/appveyor.yml
deleted file mode 100644
index 3de3c51..0000000
--- a/appveyor.yml
+++ /dev/null
@@ -1,17 +0,0 @@
-image: Visual Studio 2022
-
-skip_commits:
- files:
- - nuspec/*
- - tools/*
- - '**/*.cake'
- - '**/*.md'
- - '**/*.yml'
-
-init:
- - git config --global core.autocrlf true
-
-build_script:
- - ps: .\build.ps1 -settings_skipverification=true -target AppVeyor
-
-test: off
\ No newline at end of file
diff --git a/build.bat b/build.bat
deleted file mode 100644
index 2ff2176..0000000
--- a/build.bat
+++ /dev/null
@@ -1,2 +0,0 @@
-@echo off
-powershell ./build.ps1 --settings_skipverification=true %CAKE_ARGS% %*
\ No newline at end of file
diff --git a/build.cake b/build.cake
deleted file mode 100644
index 6d6dbdb..0000000
--- a/build.cake
+++ /dev/null
@@ -1,31 +0,0 @@
-#load nuget:https://www.myget.org/F/arkord/api/v2?package=Cake.Baker
-
-var twitterMessage = Messages.DefaultMessage + "\n#cakebuild #nuget #csharp #dotnet";
-
-Task("CreateImage")
- .IsDependeeOf("Image")
- .Does(() =>
- {
- var pathTarget = Build.Paths.Directories.Image.Combine("lib/net8.0");
- var pathSource = string.Format("{0}/{1}/**/{1}.*", Build.Paths.Directories.PublishedLibraries, Build.Parameters.Title);
- var files = GetFiles(pathSource).Where(fileSystemInfo =>
- {
- var fullPath = fileSystemInfo.FullPath;
- return fullPath.EndsWith(".dll") || fullPath.EndsWith(".pdb") || fullPath.EndsWith(".xml");
- });
-
- CleanDirectory(pathTarget);
- CopyFiles(Build.Paths.Files.License.ToString(), Build.Paths.Directories.Image);
- CopyFiles(files, pathTarget);
- });
-
-Build
- .SetParameters(
- "Cake.Compression",
- "akordowski",
- shouldPublishToNuGet:true,
- shouldPublishToGitHub:true,
- shouldPostToTwitter:true)
- .SetMessages(
- twitterMessage: twitterMessage)
- .Run();
\ No newline at end of file
diff --git a/build.ps1 b/build.ps1
deleted file mode 100644
index 21821d2..0000000
--- a/build.ps1
+++ /dev/null
@@ -1,13 +0,0 @@
-$ErrorActionPreference = 'Stop'
-
-Set-Location -LiteralPath $PSScriptRoot
-
-$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1'
-$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1'
-$env:DOTNET_NOLOGO = '1'
-
-dotnet tool restore
-if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
-
-dotnet cake @args
-if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
diff --git a/build.sh b/build.sh
deleted file mode 100644
index 31be886..0000000
--- a/build.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/env bash
-set -euox pipefail
-
-cd "$(dirname "${BASH_SOURCE[0]}")"
-
-export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
-export DOTNET_CLI_TELEMETRY_OPTOUT=1
-export DOTNET_NOLOGO=1
-
-dotnet tool restore
-
-dotnet cake "$@"
diff --git a/nuget.config b/nuget.config
new file mode 100644
index 0000000..a63a3ea
--- /dev/null
+++ b/nuget.config
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/nuget/NUGET.md b/nuget/NUGET.md
new file mode 100644
index 0000000..922778f
--- /dev/null
+++ b/nuget/NUGET.md
@@ -0,0 +1,21 @@
+# Cake.Compression
+[](https://github.com/akordowski/Cake.Compression/LICENSE)
+[](https://github.com/akordowski/Cake.Compression/actions/workflows/build-and-test.yml)
+[](https://www.nuget.org/packages/Cake.Compression/)
+
+A Cake AddIn which provides compression functionality for BZip2, GZip and Zip.
+
+## Referencing
+
+Cake.Compression is available as a nuget package from the package manager console:
+
+```csharp
+Install-Package Cake.Compression
+```
+
+or directly in your build script via a Cake `#addin` directive:
+
+```csharp
+#addin nuget:?package=SharpZipLib
+#addin nuget:?package=Cake.Compression
+```
diff --git a/nuget/NuGet.Package.props b/nuget/NuGet.Package.props
new file mode 100644
index 0000000..143891e
--- /dev/null
+++ b/nuget/NuGet.Package.props
@@ -0,0 +1,56 @@
+
+
+ Debug;Release
+ true
+ true
+ $(NoWarn);NU5104
+
+
+ 0.4.0
+
+ $(VersionPrefix)-$(VersionSuffix)
+ $(VersionPrefix)
+
+
+ 0.1.0
+
+
+ Artur Kordowski
+ Cake.Compression
+ A Cake AddIn which provides compression functionality for BZip2, GZip and Zip.
+ cake-addin cake build compression bzip2 gzip tar zip
+ $(AssemblyName)
+
+
+ MIT
+ Copyright (c) 2016-present Artur Kordowski. All rights reserved.
+ https://github.com/akordowski/Cake.Compression
+ https://github.com/akordowski/Cake.Compression
+ true
+
+
+ cake-contrib-medium.png
+ cake-contrib-medium.png
+ NUGET.md
+
+
+ true
+ snupkg
+
+
+ bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/assets/cake-contrib-medium.png b/nuget/cake-contrib-medium.png
similarity index 100%
rename from assets/cake-contrib-medium.png
rename to nuget/cake-contrib-medium.png
diff --git a/src/Cake.Compression.Tests/Cake.Compression.Tests.csproj b/src/Cake.Compression.Tests/Cake.Compression.Tests.csproj
deleted file mode 100644
index 1f297b5..0000000
--- a/src/Cake.Compression.Tests/Cake.Compression.Tests.csproj
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
- net8.0
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Cake.Compression.Tests/Classes/BZip2Tests.cs b/src/Cake.Compression.Tests/Classes/BZip2Tests.cs
deleted file mode 100644
index ad61746..0000000
--- a/src/Cake.Compression.Tests/Classes/BZip2Tests.cs
+++ /dev/null
@@ -1,190 +0,0 @@
-using Cake.Compression.Classes;
-using Cake.Core;
-using Cake.Core.Diagnostics;
-using Cake.Core.IO;
-using Cake.Testing;
-using NSubstitute;
-using NUnit.Framework;
-using System;
-using System.Collections.Generic;
-
-namespace Cake.Compression.Tests.Classes
-{
- [TestFixture]
- public class BZip2Test
- {
- #region Private Fields
- private readonly DirectoryPath rootPath = "/Root";
- private readonly FilePath outputPath = "/archive.tar.bz2";
- private readonly IEnumerable filePaths = new FilePath[] { "/Root/file.txt" };
- private readonly int level = 6;
- #endregion
-
- #region Constructor Tests
- [Test]
- public void Constructor_Should_Throw_If_FileSystem_Is_Null()
- {
- // Given
- var environment = Substitute.For();
- var log = Substitute.For();
-
- // Then
- Assert.That(() => new BZip2(null, environment, log),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("fileSystem"));
- }
-
- [Test]
- public void Constructor_Should_Throw_If_Environment_Is_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var log = Substitute.For();
-
- // Then
- Assert.That(() => new BZip2(fileSystem, null, log),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("environment"));
- }
-
- [Test]
- public void Constructor_Should_Throw_If_Log_Is_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
-
- // Then
- Assert.That(() => new BZip2(fileSystem, environment, null),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("log"));
- }
- #endregion
-
- #region Methods Tests
- [Test]
- public void Compress_Should_Throw_If_RootPath_Is_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
- var log = Substitute.For();
- var zip = new BZip2(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(null, outputPath, filePaths, level),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("rootPath"));
- }
-
- [Test]
- public void Compress_Should_Throw_If_OutputPath_Is_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
- var log = Substitute.For();
- var zip = new BZip2(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(rootPath, null, filePaths, level),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("outputPath"));
- }
-
- [Test]
- public void Compress_Should_Throw_If_FilePaths_Are_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
- var log = Substitute.For();
- var zip = new BZip2(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(rootPath, outputPath, null, level),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("filePaths"));
- }
-
- [TestCase(0)]
- [TestCase(10)]
- public void Compress_Should_Throw_If_Level_Is_Invalid(int compressLevel)
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
- var log = Substitute.For();
- var zip = new BZip2(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(rootPath, outputPath, filePaths, compressLevel),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("level"));
- }
-
- [Test]
- public void Compress_Should_Throw_If_File_Is_Not_Relative_To_Root()
- {
- // Given
- var environment = FakeEnvironment.CreateUnixEnvironment();
- var fileSystem = new FakeFileSystem(environment);
- fileSystem.CreateFile("/NotRoot/file.txt");
- var log = Substitute.For();
- var zip = new BZip2(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(rootPath, outputPath, new FilePath[] { "/NotRoot/file.txt" }, level),
- Throws.InstanceOf()
- .And.Message.EqualTo("File '/NotRoot/file.txt' is not relative to root path '/Root'."));
- }
-
- [Test]
- public void Compress_Creates_BZip2_File()
- {
- // Given
- var environment = FakeEnvironment.CreateUnixEnvironment();
- var fileSystem = new FakeFileSystem(environment);
- fileSystem.CreateFile("/Root/file.txt");
- var log = Substitute.For();
- var zip = new BZip2(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(rootPath, outputPath, filePaths, level), Throws.Nothing);
- Assert.That(fileSystem.Exist(outputPath), Is.True);
- }
-
- [Test]
- public void Uncompress_Should_Throw_If_FilePath_Is_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
- var log = Substitute.For();
- var zip = new BZip2(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Uncompress(null, "/Uncompress"),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("filePath"));
- }
-
- [Test]
- public void Uncompress_Should_Throw_If_OutputPath_Is_Null()
- {
- // Given
- var filePath = "/archive.tar.bz2";
- var environment = FakeEnvironment.CreateUnixEnvironment();
- var fileSystem = new FakeFileSystem(environment);
- fileSystem.CreateFile(filePath);
- var log = Substitute.For();
- var zip = new BZip2(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Uncompress(filePath, null),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("outputPath"));
- }
- #endregion
- }
-}
\ No newline at end of file
diff --git a/src/Cake.Compression.Tests/Classes/GZipTests.cs b/src/Cake.Compression.Tests/Classes/GZipTests.cs
deleted file mode 100644
index 8b965e6..0000000
--- a/src/Cake.Compression.Tests/Classes/GZipTests.cs
+++ /dev/null
@@ -1,190 +0,0 @@
-using Cake.Compression.Classes;
-using Cake.Core;
-using Cake.Core.Diagnostics;
-using Cake.Core.IO;
-using Cake.Testing;
-using NSubstitute;
-using NUnit.Framework;
-using System;
-using System.Collections.Generic;
-
-namespace Cake.Compression.Tests.Classes
-{
- [TestFixture]
- public class GZipTest
- {
- #region Private Fields
- private readonly DirectoryPath rootPath = "/Root";
- private readonly FilePath outputPath = "/archive.tar.gz";
- private readonly IEnumerable filePaths = new FilePath[] { "/Root/file.txt" };
- private readonly int level = 6;
- #endregion
-
- #region Constructor Tests
- [Test]
- public void Constructor_Should_Throw_If_FileSystem_Is_Null()
- {
- // Given
- var environment = Substitute.For();
- var log = Substitute.For();
-
- // Then
- Assert.That(() => new GZip(null, environment, log),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("fileSystem"));
- }
-
- [Test]
- public void Constructor_Should_Throw_If_Environment_Is_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var log = Substitute.For();
-
- // Then
- Assert.That(() => new GZip(fileSystem, null, log),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("environment"));
- }
-
- [Test]
- public void Constructor_Should_Throw_If_Log_Is_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
-
- // Then
- Assert.That(() => new GZip(fileSystem, environment, null),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("log"));
- }
- #endregion
-
- #region Methods Tests
- [Test]
- public void Compress_Should_Throw_If_RootPath_Is_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
- var log = Substitute.For();
- var zip = new GZip(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(null, outputPath, filePaths, level),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("rootPath"));
- }
-
- [Test]
- public void Compress_Should_Throw_If_OutputPath_Is_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
- var log = Substitute.For();
- var zip = new GZip(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(rootPath, null, filePaths, level),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("outputPath"));
- }
-
- [Test]
- public void Compress_Should_Throw_If_FilePaths_Are_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
- var log = Substitute.For();
- var zip = new GZip(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(rootPath, outputPath, null, level),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("filePaths"));
- }
-
- [TestCase(0)]
- [TestCase(10)]
- public void Compress_Should_Throw_If_Level_Is_Invalid(int compressLevel)
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
- var log = Substitute.For();
- var zip = new GZip(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(rootPath, outputPath, filePaths, compressLevel),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("level"));
- }
-
- [Test]
- public void Compress_Should_Throw_If_File_Is_Not_Relative_To_Root()
- {
- // Given
- var environment = FakeEnvironment.CreateUnixEnvironment();
- var fileSystem = new FakeFileSystem(environment);
- fileSystem.CreateFile("/NotRoot/file.txt");
- var log = Substitute.For();
- var zip = new GZip(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(rootPath, outputPath, new FilePath[] { "/NotRoot/file.txt" }, level),
- Throws.InstanceOf()
- .And.Message.EqualTo("File '/NotRoot/file.txt' is not relative to root path '/Root'."));
- }
-
- [Test]
- public void Compress_Creates_GZip_File()
- {
- // Given
- var environment = FakeEnvironment.CreateUnixEnvironment();
- var fileSystem = new FakeFileSystem(environment);
- fileSystem.CreateFile("/Root/file.txt");
- var log = Substitute.For();
- var zip = new GZip(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(rootPath, outputPath, filePaths, level), Throws.Nothing);
- Assert.That(fileSystem.Exist(outputPath), Is.True);
- }
-
- [Test]
- public void Uncompress_Should_Throw_If_FilePath_Is_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
- var log = Substitute.For();
- var zip = new GZip(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Uncompress(null, "/Uncompress"),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("filePath"));
- }
-
- [Test]
- public void Uncompress_Should_Throw_If_OutputPath_Is_Null()
- {
- // Given
- var filePath = "/archive.tar.gz";
- var environment = FakeEnvironment.CreateUnixEnvironment();
- var fileSystem = new FakeFileSystem(environment);
- fileSystem.CreateFile(filePath);
- var log = Substitute.For();
- var zip = new GZip(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Uncompress(filePath, null),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("outputPath"));
- }
- #endregion
- }
-}
\ No newline at end of file
diff --git a/src/Cake.Compression.Tests/Classes/ZipTest.cs b/src/Cake.Compression.Tests/Classes/ZipTest.cs
deleted file mode 100644
index 529bef4..0000000
--- a/src/Cake.Compression.Tests/Classes/ZipTest.cs
+++ /dev/null
@@ -1,190 +0,0 @@
-using Cake.Compression.Classes;
-using Cake.Core;
-using Cake.Core.Diagnostics;
-using Cake.Core.IO;
-using Cake.Testing;
-using NSubstitute;
-using NUnit.Framework;
-using System;
-using System.Collections.Generic;
-
-namespace Cake.Compression.Tests.Classes
-{
- [TestFixture]
- public class ZipTest
- {
- #region Private Fields
- private readonly DirectoryPath rootPath = "/Root";
- private readonly FilePath outputPath = "/archive.zip";
- private readonly IEnumerable filePaths = new FilePath[] { "/Root/file.txt" };
- private readonly int level = 6;
- #endregion
-
- #region Constructor Tests
- [Test]
- public void Constructor_Should_Throw_If_FileSystem_Is_Null()
- {
- // Given
- var environment = Substitute.For();
- var log = Substitute.For();
-
- // Then
- Assert.That(() => new Zip(null, environment, log),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("fileSystem"));
- }
-
- [Test]
- public void Constructor_Should_Throw_If_Environment_Is_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var log = Substitute.For();
-
- // Then
- Assert.That(() => new Zip(fileSystem, null, log),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("environment"));
- }
-
- [Test]
- public void Constructor_Should_Throw_If_Log_Is_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
-
- // Then
- Assert.That(() => new Zip(fileSystem, environment, null),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("log"));
- }
- #endregion
-
- #region Methods Tests
- [Test]
- public void Compress_Should_Throw_If_RootPath_Is_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
- var log = Substitute.For();
- var zip = new Zip(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(null, outputPath, filePaths, level),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("rootPath"));
- }
-
- [Test]
- public void Compress_Should_Throw_If_OutputPath_Is_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
- var log = Substitute.For();
- var zip = new Zip(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(rootPath, null, filePaths, level),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("outputPath"));
- }
-
- [Test]
- public void Compress_Should_Throw_If_FilePaths_Are_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
- var log = Substitute.For();
- var zip = new Zip(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(rootPath, outputPath, null, level),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("filePaths"));
- }
-
- [TestCase(0)]
- [TestCase(10)]
- public void Compress_Should_Throw_If_Level_Is_Invalid(int compressLevel)
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
- var log = Substitute.For();
- var zip = new Zip(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(rootPath, outputPath, filePaths, compressLevel),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("level"));
- }
-
- [Test]
- public void Compress_Should_Throw_If_File_Is_Not_Relative_To_Root()
- {
- // Given
- var environment = FakeEnvironment.CreateUnixEnvironment();
- var fileSystem = new FakeFileSystem(environment);
- fileSystem.CreateFile("/NotRoot/file.txt");
- var log = Substitute.For();
- var zip = new Zip(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(rootPath, outputPath, new FilePath[] { "/NotRoot/file.txt" }, level),
- Throws.InstanceOf()
- .And.Message.EqualTo("File '/NotRoot/file.txt' is not relative to root path '/Root'."));
- }
-
- [Test]
- public void Compress_Creates_Zip_File()
- {
- // Given
- var environment = FakeEnvironment.CreateUnixEnvironment();
- var fileSystem = new FakeFileSystem(environment);
- fileSystem.CreateFile("/Root/file.txt");
- var log = Substitute.For();
- var zip = new Zip(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Compress(rootPath, outputPath, filePaths, level), Throws.Nothing);
- Assert.That(fileSystem.Exist(outputPath), Is.True);
- }
-
- [Test]
- public void Uncompress_Should_Throw_If_FilePath_Is_Null()
- {
- // Given
- var fileSystem = Substitute.For();
- var environment = Substitute.For();
- var log = Substitute.For();
- var zip = new Zip(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Uncompress(null, "/Uncompress"),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("filePath"));
- }
-
- [Test]
- public void Uncompress_Should_Throw_If_OutputPath_Is_Null()
- {
- // Given
- var filePath = "/archive.zip";
- var environment = FakeEnvironment.CreateUnixEnvironment();
- var fileSystem = new FakeFileSystem(environment);
- fileSystem.CreateFile(filePath);
- var log = Substitute.For();
- var zip = new Zip(fileSystem, environment, log);
-
- // Then
- Assert.That(() => zip.Uncompress(filePath, null),
- Throws.InstanceOf()
- .And.Property("ParamName").EqualTo("outputPath"));
- }
- #endregion
- }
-}
\ No newline at end of file
diff --git a/src/Cake.Compression.sln b/src/Cake.Compression.sln
deleted file mode 100644
index af22471..0000000
--- a/src/Cake.Compression.sln
+++ /dev/null
@@ -1,48 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 17
-VisualStudioVersion = 17.1.32421.90
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.Compression", "Cake.Compression\Cake.Compression.csproj", "{DFCE574D-731A-4C89-9B74-9FF2A93ED966}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{5CF45611-BAAE-42E7-BD9C-3910A7DEB68C}"
- ProjectSection(SolutionItems) = preProject
- ..\build.bat = ..\build.bat
- ..\build.cake = ..\build.cake
- ..\build.ps1 = ..\build.ps1
- ..\build.sh = ..\build.sh
- ..\.github\workflows\dotnet.yml = ..\.github\workflows\dotnet.yml
- EndProjectSection
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Project", "Project", "{8CF42A9F-2A6F-4E2B-9495-A90E3A0A3032}"
- ProjectSection(SolutionItems) = preProject
- ..\appveyor.yml = ..\appveyor.yml
- ..\LICENSE = ..\LICENSE
- ..\README.md = ..\README.md
- ..\RELEASENOTES.md = ..\RELEASENOTES.md
- EndProjectSection
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.Compression.Tests", "Cake.Compression.Tests\Cake.Compression.Tests.csproj", "{3BBE9E87-073D-4191-9A4B-13ED553FA7DA}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {DFCE574D-731A-4C89-9B74-9FF2A93ED966}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {DFCE574D-731A-4C89-9B74-9FF2A93ED966}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {DFCE574D-731A-4C89-9B74-9FF2A93ED966}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {DFCE574D-731A-4C89-9B74-9FF2A93ED966}.Release|Any CPU.Build.0 = Release|Any CPU
- {3BBE9E87-073D-4191-9A4B-13ED553FA7DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {3BBE9E87-073D-4191-9A4B-13ED553FA7DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {3BBE9E87-073D-4191-9A4B-13ED553FA7DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {3BBE9E87-073D-4191-9A4B-13ED553FA7DA}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {FFF88EAA-356D-491C-A3DA-3037CCE6EA6F}
- EndGlobalSection
-EndGlobal
diff --git a/src/Cake.Compression/Cake.Compression.csproj b/src/Cake.Compression/Cake.Compression.csproj
index d0672eb..9ee0250 100644
--- a/src/Cake.Compression/Cake.Compression.csproj
+++ b/src/Cake.Compression/Cake.Compression.csproj
@@ -1,32 +1,15 @@
+
- net8.0
- true
- 0.4.0
- Copyright (c) $([System.DateTime]::Now.Year) Artur Kordowski
- A Cake AddIn which provides compression functionality for BZip2, GZip and Zip.
- Artur Kordowski
- https://github.com/akordowski/Cake.Compression
- https://github.com/akordowski/Cake.Compression
- cake-addin cake build compression bzip2 gzip tar zip
- cake-contrib-medium.png
- LICENSE
+ net8.0;net9.0
+ $(NoWarn);CA1062;CA1724
-
- bin\Release\net8.0\Cake.Compression.xml
-
-
-
-
-
+
-
- True
-
-
-
- True
-
-
+
+
-
\ No newline at end of file
+
+
+
+
diff --git a/src/Cake.Compression/Classes/Bzip2.cs b/src/Cake.Compression/Classes/Bzip2.cs
index 66bf5ec..2fb4ffe 100644
--- a/src/Cake.Compression/Classes/Bzip2.cs
+++ b/src/Cake.Compression/Classes/Bzip2.cs
@@ -1,109 +1,110 @@
-using Cake.Core;
+using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using ICSharpCode.SharpZipLib.BZip2;
using ICSharpCode.SharpZipLib.Tar;
-using System.Collections.Generic;
-using System.IO;
using System.Text;
-namespace Cake.Compression.Classes
+namespace Cake.Compression.Classes;
+
+///
+/// Provides a class.
+///
+public sealed class BZip2 : CompressionBase
{
///
- /// Provides a class.
+ /// Initializes a new instance of the class.
///
- public class BZip2 : CompressionBase
+ public BZip2(
+ IFileSystem fileSystem,
+ ICakeEnvironment environment,
+ ICakeLog log)
+ : base(fileSystem, environment, log)
{
- #region Constructor
- ///
- /// Initializes a new instance of the class.
- ///
- public BZip2(IFileSystem fileSystem, ICakeEnvironment environment, ICakeLog log)
- : base(fileSystem, environment, log)
- {
- }
- #endregion
-
- #region Public Methods
- ///
- /// Create a BZip2 Tar archive of the specified files.
- ///
- /// The root path.
- /// The output path.
- /// The file paths.
- /// The compression level (1-9).
- public override void Compress(DirectoryPath rootPath, FilePath outputPath, IEnumerable filePaths, int level)
- {
- Precondition.IsNotNull(rootPath, nameof(rootPath));
- Precondition.IsNotNull(outputPath, nameof(outputPath));
- Precondition.IsNotNull(filePaths, nameof(filePaths));
- Precondition.IsBetween(level, 1, 9, nameof(level));
+ }
+
+ ///
+ /// Create a BZip2 Tar archive of the specified files.
+ ///
+ /// The root path.
+ /// The output path.
+ /// The file paths.
+ /// The compression level (1-9).
+ public override void Compress(
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths,
+ int level)
+ {
+ ArgumentNullException.ThrowIfNull(rootPath, nameof(rootPath));
+ ArgumentNullException.ThrowIfNull(outputPath, nameof(outputPath));
+ ArgumentNullException.ThrowIfNull(filePaths, nameof(filePaths));
+ ArgumentOutOfRangeException.ThrowIfLessThan(level, 1, nameof(level));
+ ArgumentOutOfRangeException.ThrowIfGreaterThan(level, 9, nameof(level));
- // Make root path and output file path absolute.
- rootPath = rootPath.MakeAbsolute(environment);
- outputPath = outputPath.MakeAbsolute(environment);
+ // Make root path and output file path absolute.
+ rootPath = rootPath.MakeAbsolute(Environment);
+ outputPath = outputPath.MakeAbsolute(Environment);
- // Get the output file.
- var outputFile = fileSystem.GetFile(outputPath);
+ // Get the output file.
+ var outputFile = FileSystem.GetFile(outputPath);
- // Open up a stream to the output file.
- log.Verbose("Creating BZip2 file: {0}", outputPath.FullPath);
+ // Open up a stream to the output file.
+ Log.Verbose("Creating BZip2 file: {0}", outputPath.FullPath);
- using (var outputStream = outputFile.Open(FileMode.Create, FileAccess.Write, FileShare.None))
- using (var bzip2OutputStream = new BZip2OutputStream(outputStream, level))
- using (var tarOutputStream = new TarOutputStream(bzip2OutputStream, Encoding.UTF8))
+ using (var outputStream = outputFile.Open(FileMode.Create, FileAccess.Write, FileShare.None))
+ using (var bzip2OutputStream = new BZip2OutputStream(outputStream, level))
+ using (var tarOutputStream = new TarOutputStream(bzip2OutputStream, Encoding.UTF8))
+ {
+ foreach (var inputPath in filePaths)
{
- foreach (var inputPath in filePaths)
+ var absoluteInputPath = inputPath.MakeAbsolute(Environment);
+ var file = FileSystem.GetFile(absoluteInputPath);
+
+ using (var inputStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
{
- var absoluteInputPath = inputPath.MakeAbsolute(environment);
- var file = fileSystem.GetFile(absoluteInputPath);
-
- using (var inputStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
- {
- // Get the relative filename to the rootPath.
- var relativeFilePath = GetRelativeFilePath(rootPath, absoluteInputPath);
- log.Verbose("Compressing file {0}", absoluteInputPath);
-
- // Create the tar archive entry.
- TarEntry entry = TarEntry.CreateTarEntry(relativeFilePath.FullPath);
- entry.Size = inputStream.Length;
-
- tarOutputStream.PutNextEntry(entry);
- inputStream.CopyTo(tarOutputStream);
- tarOutputStream.CloseEntry();
- }
+ // Get the relative filename to the rootPath.
+ var relativeFilePath = GetRelativeFilePath(rootPath, absoluteInputPath);
+ Log.Verbose("Compressing file {0}", absoluteInputPath);
+
+ // Create the tar archive entry.
+ var entry = TarEntry.CreateTarEntry(relativeFilePath.FullPath);
+ entry.Size = inputStream.Length;
+
+ tarOutputStream.PutNextEntry(entry);
+ inputStream.CopyTo(tarOutputStream);
+ tarOutputStream.CloseEntry();
}
}
-
- log.Verbose("BZip2 file successfully created: {0}", outputPath.FullPath);
}
- ///
- /// Uncompress the specified BZip2 Tar file.
- ///
- /// BZip2 file to uncompress.
- /// Output path to uncompress into.
- public override void Uncompress(FilePath filePath, DirectoryPath outputPath)
- {
- Precondition.IsNotNull(filePath, nameof(filePath));
- Precondition.IsNotNull(outputPath, nameof(outputPath));
+ Log.Verbose("BZip2 file successfully created: {0}", outputPath.FullPath);
+ }
- // Make root path and output file path absolute.
- filePath = filePath.MakeAbsolute(environment);
- outputPath = outputPath.MakeAbsolute(environment);
+ ///
+ /// Decompress the specified BZip2 Tar file.
+ ///
+ /// BZip2 file to decompress.
+ /// Output path to decompress into.
+ public override void Decompress(FilePath filePath, DirectoryPath outputPath)
+ {
+ ArgumentNullException.ThrowIfNull(filePath, nameof(filePath));
+ ArgumentNullException.ThrowIfNull(outputPath, nameof(outputPath));
- var file = fileSystem.GetFile(filePath);
+ // Make root path and output file path absolute.
+ filePath = filePath.MakeAbsolute(Environment);
+ outputPath = outputPath.MakeAbsolute(Environment);
- log.Verbose("Uncompress BZip2 file {0} to {1}", filePath.FullPath, outputPath.FullPath);
+ var file = FileSystem.GetFile(filePath);
- using (Stream inputStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
- using (Stream bzip2InputStream = new BZip2InputStream(inputStream))
- {
- TarArchive archive = TarArchive.CreateInputTarArchive(bzip2InputStream, Encoding.UTF8);
- archive.ExtractContents(outputPath.FullPath);
- archive.Close();
- }
+ Log.Verbose("Decompress BZip2 file {0} to {1}", filePath.FullPath, outputPath.FullPath);
+
+ using (var inputStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
+ using (var bzip2InputStream = new BZip2InputStream(inputStream))
+ {
+ var archive = TarArchive.CreateInputTarArchive(bzip2InputStream, Encoding.UTF8);
+ archive.ExtractContents(outputPath.FullPath);
+ archive.Close();
}
- #endregion
}
-}
\ No newline at end of file
+}
diff --git a/src/Cake.Compression/Classes/CompressionBase.cs b/src/Cake.Compression/Classes/CompressionBase.cs
index 5afb9f0..8545ba7 100644
--- a/src/Cake.Compression/Classes/CompressionBase.cs
+++ b/src/Cake.Compression/Classes/CompressionBase.cs
@@ -1,94 +1,90 @@
-using Cake.Core;
+using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-namespace Cake.Compression.Classes
+namespace Cake.Compression.Classes;
+
+///
+/// Provides a class.
+///
+public abstract class CompressionBase
{
///
- /// Provides a class.
+ /// Gets the file system.
///
- public abstract class CompressionBase
- {
- #region Protected Fields
- ///
- /// Gets the file system.
- ///
- protected readonly IFileSystem fileSystem;
+ protected IFileSystem FileSystem { get; }
- ///
- /// Gets the environment.
- ///
- protected readonly ICakeEnvironment environment;
+ ///
+ /// Gets the environment.
+ ///
+ protected ICakeEnvironment Environment { get; }
- ///
- /// Gets the log.
- ///
- protected readonly ICakeLog log;
+ ///
+ /// Gets the log.
+ ///
+ protected ICakeLog Log { get; }
- ///
- /// Gets the string comparison.
- ///
- protected readonly StringComparison comparison;
- #endregion
+ ///
+ /// Gets the string comparison.
+ ///
+ protected StringComparison Comparison { get; }
- #region Constructor
- ///
- /// Initializes a new instance of the class.
- ///
- /// The file system.
- /// The environment.
- /// The log.
- protected CompressionBase(IFileSystem fileSystem, ICakeEnvironment environment, ICakeLog log)
- {
- Precondition.IsNotNull(fileSystem, nameof(fileSystem));
- Precondition.IsNotNull(environment, nameof(environment));
- Precondition.IsNotNull(log, nameof(log));
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The file system.
+ /// The environment.
+ /// The log.
+ protected CompressionBase(
+ IFileSystem fileSystem,
+ ICakeEnvironment environment,
+ ICakeLog log)
+ {
+ ArgumentNullException.ThrowIfNull(fileSystem, nameof(fileSystem));
+ ArgumentNullException.ThrowIfNull(environment, nameof(environment));
+ ArgumentNullException.ThrowIfNull(log, nameof(log));
- this.fileSystem = fileSystem;
- this.environment = environment;
- this.log = log;
- this.comparison = environment.Platform.IsUnix() ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
- }
- #endregion
+ FileSystem = fileSystem;
+ Environment = environment;
+ Log = log;
+ Comparison = environment.Platform.IsUnix()
+ ? StringComparison.Ordinal
+ : StringComparison.OrdinalIgnoreCase;
+ }
- #region Public Methods
- ///
- /// Create a archive of the specified files.
- ///
- /// The root path.
- /// The output path.
- /// The file paths.
- /// The compression level (1-9).
- public abstract void Compress(DirectoryPath rootPath, FilePath outputPath, IEnumerable filePaths, int level);
+ ///
+ /// Create a archive of the specified files.
+ ///
+ /// The root path.
+ /// The output path.
+ /// The file paths.
+ /// The compression level (1-9).
+ public abstract void Compress(
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths,
+ int level);
- ///
- /// Uncompress the specified archive.
- ///
- /// Archive to uncompress.
- /// Output path to uncompress into.
- public abstract void Uncompress(FilePath filePath, DirectoryPath outputPath);
- #endregion
+ ///
+ /// Decompress the specified archive.
+ ///
+ /// Archive to decompress.
+ /// Output path to decompress into.
+ public abstract void Decompress(FilePath filePath, DirectoryPath outputPath);
- #region Protected Methods
- ///
- /// Gets a relative file path.
- ///
- /// A directory path.
- /// A file path.
- /// Returns a relative file path.
- protected FilePath GetRelativeFilePath(DirectoryPath root, FilePath file)
+ ///
+ /// Gets a relative file path.
+ ///
+ /// A directory path.
+ /// A file path.
+ /// Returns a relative file path.
+ protected FilePath GetRelativeFilePath(DirectoryPath root, FilePath file)
+ {
+ if (file.FullPath.StartsWith(root.FullPath, Comparison))
{
- if (!file.FullPath.StartsWith(root.FullPath, comparison))
- {
- const string format = "File '{0}' is not relative to root path '{1}'.";
- throw new CakeException(string.Format(CultureInfo.InvariantCulture, format, file.FullPath, root.FullPath));
- }
-
- return file.FullPath.Substring(root.FullPath.Length + 1);
+ return file.FullPath[(root.FullPath.Length + 1)..];
}
- #endregion
+
+ throw new CakeException($"File '{file.FullPath}' is not relative to root path '{root.FullPath}'.");
}
-}
\ No newline at end of file
+}
diff --git a/src/Cake.Compression/Classes/GZip.cs b/src/Cake.Compression/Classes/GZip.cs
index 8853ddf..1167ea6 100644
--- a/src/Cake.Compression/Classes/GZip.cs
+++ b/src/Cake.Compression/Classes/GZip.cs
@@ -1,111 +1,112 @@
-using Cake.Core;
+using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.Tar;
-using System.Collections.Generic;
-using System.IO;
using System.Text;
-namespace Cake.Compression.Classes
+namespace Cake.Compression.Classes;
+
+///
+/// Provides a class.
+///
+public sealed class GZip : CompressionBase
{
///
- /// Provides a class.
+ /// Initializes a new instance of the class.
///
- public class GZip : CompressionBase
+ public GZip(
+ IFileSystem fileSystem,
+ ICakeEnvironment environment,
+ ICakeLog log)
+ : base(fileSystem, environment, log)
{
- #region Constructor
- ///
- /// Initializes a new instance of the class.
- ///
- public GZip(IFileSystem fileSystem, ICakeEnvironment environment, ICakeLog log)
- : base(fileSystem, environment, log)
- {
- }
- #endregion
-
- #region Public Methods
- ///
- /// Create a GZip Tar archive of the specified files.
- ///
- /// The root path.
- /// The output path.
- /// The file paths.
- /// The compression level (1-9).
- public override void Compress(DirectoryPath rootPath, FilePath outputPath, IEnumerable filePaths, int level)
- {
- Precondition.IsNotNull(rootPath, nameof(rootPath));
- Precondition.IsNotNull(outputPath, nameof(outputPath));
- Precondition.IsNotNull(filePaths, nameof(filePaths));
- Precondition.IsBetween(level, 1, 9, nameof(level));
+ }
+
+ ///
+ /// Create a GZip Tar archive of the specified files.
+ ///
+ /// The root path.
+ /// The output path.
+ /// The file paths.
+ /// The compression level (1-9).
+ public override void Compress(
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths,
+ int level)
+ {
+ ArgumentNullException.ThrowIfNull(rootPath, nameof(rootPath));
+ ArgumentNullException.ThrowIfNull(outputPath, nameof(outputPath));
+ ArgumentNullException.ThrowIfNull(filePaths, nameof(filePaths));
+ ArgumentOutOfRangeException.ThrowIfLessThan(level, 1, nameof(level));
+ ArgumentOutOfRangeException.ThrowIfGreaterThan(level, 9, nameof(level));
- // Make root path and output file path absolute.
- rootPath = rootPath.MakeAbsolute(environment);
- outputPath = outputPath.MakeAbsolute(environment);
+ // Make root path and output file path absolute.
+ rootPath = rootPath.MakeAbsolute(Environment);
+ outputPath = outputPath.MakeAbsolute(Environment);
- // Get the output file.
- var outputFile = fileSystem.GetFile(outputPath);
+ // Get the output file.
+ var outputFile = FileSystem.GetFile(outputPath);
- // Open up a stream to the output file.
- log.Verbose("Creating Zip file: {0}", outputPath.FullPath);
+ // Open up a stream to the output file.
+ Log.Verbose("Creating Zip file: {0}", outputPath.FullPath);
- using (var outputStream = outputFile.Open(FileMode.Create, FileAccess.Write, FileShare.None))
- using (var gzipOutputStream = new GZipOutputStream(outputStream))
- using (var tarOutputStream = new TarOutputStream(gzipOutputStream, Encoding.UTF8))
+ using (var outputStream = outputFile.Open(FileMode.Create, FileAccess.Write, FileShare.None))
+ using (var gzipOutputStream = new GZipOutputStream(outputStream))
+ using (var tarOutputStream = new TarOutputStream(gzipOutputStream, Encoding.UTF8))
+ {
+ gzipOutputStream.SetLevel(level);
+
+ foreach (var inputPath in filePaths)
{
- gzipOutputStream.SetLevel(level);
+ var absoluteInputPath = inputPath.MakeAbsolute(Environment);
+ var file = FileSystem.GetFile(absoluteInputPath);
- foreach (var inputPath in filePaths)
+ using (var inputStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
{
- var absoluteInputPath = inputPath.MakeAbsolute(environment);
- var file = fileSystem.GetFile(absoluteInputPath);
-
- using (var inputStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
- {
- // Get the relative filename to the rootPath.
- var relativeFilePath = GetRelativeFilePath(rootPath, absoluteInputPath);
- log.Verbose("Compressing file {0}", absoluteInputPath);
-
- // Create the tar archive entry.
- TarEntry entry = TarEntry.CreateTarEntry(relativeFilePath.FullPath);
- entry.Size = inputStream.Length;
-
- tarOutputStream.PutNextEntry(entry);
- inputStream.CopyTo(tarOutputStream);
- tarOutputStream.CloseEntry();
- }
+ // Get the relative filename to the rootPath.
+ var relativeFilePath = GetRelativeFilePath(rootPath, absoluteInputPath);
+ Log.Verbose("Compressing file {0}", absoluteInputPath);
+
+ // Create the tar archive entry.
+ var entry = TarEntry.CreateTarEntry(relativeFilePath.FullPath);
+ entry.Size = inputStream.Length;
+
+ tarOutputStream.PutNextEntry(entry);
+ inputStream.CopyTo(tarOutputStream);
+ tarOutputStream.CloseEntry();
}
}
-
- log.Verbose("GZip file successfully created: {0}", outputPath.FullPath);
}
- ///
- /// Uncompress the specified GZip Tar file.
- ///
- /// GZip file to uncompress.
- /// Output path to uncompress into.
- public override void Uncompress(FilePath filePath, DirectoryPath outputPath)
- {
- Precondition.IsNotNull(filePath, nameof(filePath));
- Precondition.IsNotNull(outputPath, nameof(outputPath));
+ Log.Verbose("GZip file successfully created: {0}", outputPath.FullPath);
+ }
- // Make root path and output file path absolute.
- filePath = filePath.MakeAbsolute(environment);
- outputPath = outputPath.MakeAbsolute(environment);
+ ///
+ /// Decompress the specified GZip Tar file.
+ ///
+ /// GZip file to decompress.
+ /// Output path to decompress into.
+ public override void Decompress(FilePath filePath, DirectoryPath outputPath)
+ {
+ ArgumentNullException.ThrowIfNull(filePath, nameof(filePath));
+ ArgumentNullException.ThrowIfNull(outputPath, nameof(outputPath));
- var file = fileSystem.GetFile(filePath);
+ // Make root path and output file path absolute.
+ filePath = filePath.MakeAbsolute(Environment);
+ outputPath = outputPath.MakeAbsolute(Environment);
- log.Verbose("Uncompress GZip file {0} to {1}", filePath.FullPath, outputPath.FullPath);
+ var file = FileSystem.GetFile(filePath);
- using (Stream inputStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
- using (Stream gzipInputStream = new GZipInputStream(inputStream))
- {
- TarArchive archive = TarArchive.CreateInputTarArchive(gzipInputStream, Encoding.UTF8);
- archive.ExtractContents(outputPath.FullPath);
- archive.Close();
- }
+ Log.Verbose("Decompress GZip file {0} to {1}", filePath.FullPath, outputPath.FullPath);
+
+ using (var inputStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
+ using (var gzipInputStream = new GZipInputStream(inputStream))
+ {
+ var archive = TarArchive.CreateInputTarArchive(gzipInputStream, Encoding.UTF8);
+ archive.ExtractContents(outputPath.FullPath);
+ archive.Close();
}
- #endregion
}
-}
\ No newline at end of file
+}
diff --git a/src/Cake.Compression/Classes/Zip.cs b/src/Cake.Compression/Classes/Zip.cs
index 9eab41c..db819b7 100644
--- a/src/Cake.Compression/Classes/Zip.cs
+++ b/src/Cake.Compression/Classes/Zip.cs
@@ -1,137 +1,138 @@
-using Cake.Core;
+using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.Zip;
-using System.Collections.Generic;
-using System.IO;
-namespace Cake.Compression.Classes
+namespace Cake.Compression.Classes;
+
+///
+/// Provides a class.
+///
+public sealed class Zip : CompressionBase
{
///
- /// Provides a class.
+ /// Initializes a new instance of the class.
///
- public class Zip : CompressionBase
+ public Zip(
+ IFileSystem fileSystem,
+ ICakeEnvironment environment,
+ ICakeLog log)
+ : base(fileSystem, environment, log)
{
- #region Constructor
- ///
- /// Initializes a new instance of the class.
- ///
- public Zip(IFileSystem fileSystem, ICakeEnvironment environment, ICakeLog log)
- : base(fileSystem, environment, log)
- {
- }
- #endregion
-
- #region Public Methods
- ///
- /// Create a Zip archive of the specified files.
- ///
- /// The root path.
- /// The output path.
- /// The file paths.
- /// The compression level (1-9).
- public override void Compress(DirectoryPath rootPath, FilePath outputPath, IEnumerable filePaths, int level)
- {
- Precondition.IsNotNull(rootPath, nameof(rootPath));
- Precondition.IsNotNull(outputPath, nameof(outputPath));
- Precondition.IsNotNull(filePaths, nameof(filePaths));
- Precondition.IsBetween(level, 1, 9, nameof(level));
+ }
+
+ ///
+ /// Create a Zip archive of the specified files.
+ ///
+ /// The root path.
+ /// The output path.
+ /// The file paths.
+ /// The compression level (1-9).
+ public override void Compress(
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths,
+ int level)
+ {
+ ArgumentNullException.ThrowIfNull(rootPath, nameof(rootPath));
+ ArgumentNullException.ThrowIfNull(outputPath, nameof(outputPath));
+ ArgumentNullException.ThrowIfNull(filePaths, nameof(filePaths));
+ ArgumentOutOfRangeException.ThrowIfLessThan(level, 1, nameof(level));
+ ArgumentOutOfRangeException.ThrowIfGreaterThan(level, 9, nameof(level));
- // Make root path and output file path absolute.
- rootPath = rootPath.MakeAbsolute(environment);
- outputPath = outputPath.MakeAbsolute(environment);
+ // Make root path and output file path absolute.
+ rootPath = rootPath.MakeAbsolute(Environment);
+ outputPath = outputPath.MakeAbsolute(Environment);
- // Get the output file.
- var outputFile = fileSystem.GetFile(outputPath);
+ // Get the output file.
+ var outputFile = FileSystem.GetFile(outputPath);
- // Open up a stream to the output file.
- log.Verbose("Creating Zip file: {0}", outputPath.FullPath);
+ // Open up a stream to the output file.
+ Log.Verbose("Creating Zip file: {0}", outputPath.FullPath);
+
+ using (var outputStream = outputFile.Open(FileMode.Create, FileAccess.Write, FileShare.None))
+ using (var zipOutputStream = new ZipOutputStream(outputStream))
+ {
+ zipOutputStream.SetLevel(level);
- using (var outputStream = outputFile.Open(FileMode.Create, FileAccess.Write, FileShare.None))
- using (var zipOutputStream = new ZipOutputStream(outputStream))
+ foreach (var inputPath in filePaths)
{
- zipOutputStream.SetLevel(level);
+ var absoluteInputPath = inputPath.MakeAbsolute(Environment);
+ var file = FileSystem.GetFile(absoluteInputPath);
- foreach (var inputPath in filePaths)
+ using (var inputStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
{
- var absoluteInputPath = inputPath.MakeAbsolute(environment);
- var file = fileSystem.GetFile(absoluteInputPath);
+ // Get the relative filename to the rootPath.
+ var relativeFilePath = GetRelativeFilePath(rootPath, absoluteInputPath);
+ Log.Verbose("Compressing file {0}", absoluteInputPath);
- using (var inputStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
+ var entryName = relativeFilePath.FullPath;
+ entryName = ZipEntry.CleanName(entryName);
+
+ // Create the tar archive entry.
+ var entry = new ZipEntry(entryName)
{
- // Get the relative filename to the rootPath.
- var relativeFilePath = GetRelativeFilePath(rootPath, absoluteInputPath);
- log.Verbose("Compressing file {0}", absoluteInputPath);
-
- string entryName = relativeFilePath.FullPath;
- entryName = ZipEntry.CleanName(entryName);
-
- // Create the tar archive entry.
- ZipEntry entry = new ZipEntry(entryName)
- {
- DateTime = File.GetLastWriteTime(absoluteInputPath.FullPath),
- Size = inputStream.Length
- };
-
- zipOutputStream.PutNextEntry(entry);
- inputStream.CopyTo(zipOutputStream);
- zipOutputStream.CloseEntry();
- }
+ DateTime = File.GetLastWriteTime(absoluteInputPath.FullPath),
+ Size = inputStream.Length
+ };
+
+ zipOutputStream.PutNextEntry(entry);
+ inputStream.CopyTo(zipOutputStream);
+ zipOutputStream.CloseEntry();
}
}
-
- log.Verbose("Zip file successfully created: {0}", outputPath.FullPath);
}
- ///
- /// Uncompress the specified Zip file.
- ///
- /// Zip file to uncompress.
- /// Output path to uncompress into.
- public override void Uncompress(FilePath filePath, DirectoryPath outputPath)
- {
- Precondition.IsNotNull(filePath, nameof(filePath));
- Precondition.IsNotNull(outputPath, nameof(outputPath));
+ Log.Verbose("Zip file successfully created: {0}", outputPath.FullPath);
+ }
- // Make root path and output file path absolute.
- filePath = filePath.MakeAbsolute(environment);
- outputPath = outputPath.MakeAbsolute(environment);
+ ///
+ /// Decompress the specified Zip file.
+ ///
+ /// Zip file to decompress.
+ /// Output path to decompress into.
+ public override void Decompress(FilePath filePath, DirectoryPath outputPath)
+ {
+ ArgumentNullException.ThrowIfNull(filePath, nameof(filePath));
+ ArgumentNullException.ThrowIfNull(outputPath, nameof(outputPath));
+
+ // Make root path and output file path absolute.
+ filePath = filePath.MakeAbsolute(Environment);
+ outputPath = outputPath.MakeAbsolute(Environment);
- var file = fileSystem.GetFile(filePath);
+ var file = FileSystem.GetFile(filePath);
- log.Verbose("Uncompress Zip file {0} to {1}", filePath.FullPath, outputPath.FullPath);
+ Log.Verbose("Decompress Zip file {0} to {1}", filePath.FullPath, outputPath.FullPath);
- using (Stream inputStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
- using (ZipFile zipFile = new ZipFile(inputStream))
+ using (var inputStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
+ using (var zipFile = new ZipFile(inputStream))
+ {
+ foreach (ZipEntry zipEntry in zipFile)
{
- foreach (ZipEntry zipEntry in zipFile)
+ if (!zipEntry.IsFile)
{
- if (!zipEntry.IsFile)
- {
- continue; // Ignore directories
- }
+ continue; // Ignore directories
+ }
- string entryFileName = zipEntry.Name;
+ var entryFileName = zipEntry.Name;
- byte[] buffer = new byte[4096]; // 4K is optimum
- Stream zipStream = zipFile.GetInputStream(zipEntry);
+ var buffer = new byte[4096]; // 4K is optimum
+ var zipStream = zipFile.GetInputStream(zipEntry);
- string fullZipToPath = System.IO.Path.Combine(outputPath.FullPath, entryFileName);
- string directoryName = System.IO.Path.GetDirectoryName(fullZipToPath);
+ var fullZipToPath = System.IO.Path.Combine(outputPath.FullPath, entryFileName);
+ var directoryName = System.IO.Path.GetDirectoryName(fullZipToPath)!;
- if (directoryName.Length > 0)
- {
- Directory.CreateDirectory(directoryName);
- }
+ if (directoryName.Length > 0)
+ {
+ Directory.CreateDirectory(directoryName);
+ }
- using (FileStream streamWriter = File.Create(fullZipToPath))
- {
- StreamUtils.Copy(zipStream, streamWriter, buffer);
- }
+ using (var streamWriter = File.Create(fullZipToPath))
+ {
+ StreamUtils.Copy(zipStream, streamWriter, buffer);
}
}
}
- #endregion
}
-}
\ No newline at end of file
+}
diff --git a/src/Cake.Compression/CompressionAliases.cs b/src/Cake.Compression/CompressionAliases.cs
index a279bdc..6683fcf 100644
--- a/src/Cake.Compression/CompressionAliases.cs
+++ b/src/Cake.Compression/CompressionAliases.cs
@@ -1,653 +1,755 @@
-using Cake.Common.IO;
+using Cake.Common.IO;
using Cake.Compression.Classes;
using Cake.Core;
using Cake.Core.Annotations;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-namespace Cake.Compression
+namespace Cake.Compression;
+
+///
+/// Contains functionality related to compress files.
+///
+[CakeAliasCategory("Compression")]
+public static class CompressionAliases
{
+ private const int Level = 6;
+
///
- /// Contains functionality related to compress files.
+ /// Create a BZip2 Tar archive of the specified directory.
///
- [CakeAliasCategory("Compression")]
- public static class CompressionAliases
- {
- #region Private Constants
- private const int Level = 6;
- #endregion
-
- #region BZip2
- ///
- /// Create a BZip2 Tar archive of the specified directory.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- ///
- ///
- /// BZip2Compress("./publish", "publish.tar.bz2");
- ///
- ///
- [CakeMethodAlias]
- public static void BZip2Compress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath)
- {
- Compress(context, rootPath, outputPath, Level);
- }
+ /// The context.
+ /// The root path.
+ /// The output path.
+ ///
+ ///
+ /// BZip2Compress("./publish", "publish.tar.bz2");
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void BZip2Compress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath) =>
+ Compress(context, rootPath, outputPath, Level);
- ///
- /// Create a BZip2 Tar archive of the specified directory.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The compression level (1-9).
- ///
- ///
- /// BZip2Compress("./publish", "publish.tar.bz2", 6);
- ///
- ///
- [CakeMethodAlias]
- public static void BZip2Compress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, int level)
- {
- Compress(context, rootPath, outputPath, level);
- }
+ ///
+ /// Create a BZip2 Tar archive of the specified directory.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The compression level (1-9).
+ ///
+ ///
+ /// BZip2Compress("./publish", "publish.tar.bz2", 6);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void BZip2Compress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ int level) =>
+ Compress(context, rootPath, outputPath, level);
- ///
- /// Create a BZip2 Tar archive of the files matching the specified pattern.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The pattern.
- ///
- ///
- /// BZip2Compress("./", "xmlfiles.tar.bz2", "./*.xml");
- ///
- ///
- [CakeMethodAlias]
- public static void BZip2Compress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, string pattern)
- {
- Compress(context, rootPath, outputPath, pattern, Level);
- }
+ ///
+ /// Create a BZip2 Tar archive of the files matching the specified pattern.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The pattern.
+ ///
+ ///
+ /// BZip2Compress("./", "xmlfiles.tar.bz2", "./*.xml");
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void BZip2Compress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ string pattern) =>
+ Compress(context, rootPath, outputPath, pattern, Level);
- ///
- /// Create a BZip2 Tar archive of the files matching the specified pattern.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The pattern.
- /// The compression level (1-9).
- ///
- ///
- /// BZip2Compress("./", "xmlfiles.tar.bz2", "./*.xml", 6);
- ///
- ///
- [CakeMethodAlias]
- public static void BZip2Compress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, string pattern, int level)
- {
- Compress(context, rootPath, outputPath, pattern, level);
- }
+ ///
+ /// Create a BZip2 Tar archive of the files matching the specified pattern.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The pattern.
+ /// The compression level (1-9).
+ ///
+ ///
+ /// BZip2Compress("./", "xmlfiles.tar.bz2", "./*.xml", 6);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void BZip2Compress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ string pattern,
+ int level) =>
+ Compress(context, rootPath, outputPath, pattern, level);
- ///
- /// Create a BZip2 Tar archive of the specified files.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The file paths.
- ///
- ///
- /// var files = GetFiles("./**/Cake.*.dll");
- /// BZip2Compress("./", "cakeassemblies.tar.bz2", files);
- ///
- ///
- [CakeMethodAlias]
- public static void BZip2Compress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, IEnumerable filePaths)
- {
- Compress(context, rootPath, outputPath, filePaths, Level);
- }
+ ///
+ /// Create a BZip2 Tar archive of the specified files.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The file paths.
+ ///
+ ///
+ /// var files = GetFiles("./**/Cake.*.dll");
+ /// BZip2Compress("./", "cakeassemblies.tar.bz2", files);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void BZip2Compress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths) =>
+ Compress(context, rootPath, outputPath, filePaths, Level);
- ///
- /// Create a BZip2 Tar archive of the specified files.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The file paths.
- /// The compression level (1-9).
- ///
- ///
- /// var files = GetFiles("./**/Cake.*.dll");
- /// BZip2Compress("./", "cakeassemblies.tar.bz2", files, 6);
- ///
- ///
- [CakeMethodAlias]
- public static void BZip2Compress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, IEnumerable filePaths, int level)
- {
- Compress(context, rootPath, outputPath, filePaths, level);
- }
+ ///
+ /// Create a BZip2 Tar archive of the specified files.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The file paths.
+ /// The compression level (1-9).
+ ///
+ ///
+ /// var files = GetFiles("./**/Cake.*.dll");
+ /// BZip2Compress("./", "cakeassemblies.tar.bz2", files, 6);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void BZip2Compress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths,
+ int level) =>
+ Compress(context, rootPath, outputPath, filePaths, level);
- ///
- /// Create a BZip2 Tar archive of the specified files.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The file paths.
- ///
- ///
- /// var files = new [] {
- /// "./src/Cake/bin/Debug/Autofac.dll",
- /// "./src/Cake/bin/Debug/Cake.Common.dll",
- /// "./src/Cake/bin/Debug/Cake.Core.dll",
- /// "./src/Cake/bin/Debug/Cake.exe"
- /// };
- /// BZip2Compress("./", "cakebinaries.tar.bz2", files);
- ///
- ///
- [CakeMethodAlias]
- public static void BZip2Compress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, IEnumerable filePaths)
- {
- Compress(context, rootPath, outputPath, filePaths, Level);
- }
+ ///
+ /// Create a BZip2 Tar archive of the specified files.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The file paths.
+ ///
+ ///
+ /// var files = new [] {
+ /// "./src/Cake/bin/Debug/Autofac.dll",
+ /// "./src/Cake/bin/Debug/Cake.Common.dll",
+ /// "./src/Cake/bin/Debug/Cake.Core.dll",
+ /// "./src/Cake/bin/Debug/Cake.exe"
+ /// };
+ /// BZip2Compress("./", "cakebinaries.tar.bz2", files);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void BZip2Compress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths) =>
+ Compress(context, rootPath, outputPath, filePaths, Level);
- ///
- /// Create a BZip2 Tar archive of the specified files.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The file paths.
- /// The compression level (1-9).
- ///
- ///
- /// var files = new [] {
- /// "./src/Cake/bin/Debug/Autofac.dll",
- /// "./src/Cake/bin/Debug/Cake.Common.dll",
- /// "./src/Cake/bin/Debug/Cake.Core.dll",
- /// "./src/Cake/bin/Debug/Cake.exe"
- /// };
- /// BZip2Compress("./", "cakebinaries.tar.bz2", files, 6);
- ///
- ///
- [CakeMethodAlias]
- public static void BZip2Compress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, IEnumerable filePaths, int level)
- {
- Compress(context, rootPath, outputPath, filePaths, level);
- }
+ ///
+ /// Create a BZip2 Tar archive of the specified files.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The file paths.
+ /// The compression level (1-9).
+ ///
+ ///
+ /// var files = new [] {
+ /// "./src/Cake/bin/Debug/Autofac.dll",
+ /// "./src/Cake/bin/Debug/Cake.Common.dll",
+ /// "./src/Cake/bin/Debug/Cake.Core.dll",
+ /// "./src/Cake/bin/Debug/Cake.exe"
+ /// };
+ /// BZip2Compress("./", "cakebinaries.tar.bz2", files, 6);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void BZip2Compress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths,
+ int level) =>
+ Compress(context, rootPath, outputPath, filePaths, level);
- ///
- /// Uncompress the specified BZip2 Tar file.
- ///
- /// The context.
- /// BZip2 file to uncompress.
- /// Output path to uncompress into.
- ///
- ///
- /// BZip2Uncompress("Cake.tar.bz2", "./cake");
- ///
- ///
- [CakeMethodAlias]
- public static void BZip2Uncompress(this ICakeContext context, FilePath filePath, DirectoryPath outputPath)
- {
- Uncompress(context, filePath, outputPath);
- }
- #endregion
-
- #region GZip
- ///
- /// Create a GZip Tar archive of the specified directory.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- ///
- ///
- /// GZipCompress("./publish", "publish.tar.gz");
- ///
- ///
- [CakeMethodAlias]
- public static void GZipCompress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath)
- {
- Compress(context, rootPath, outputPath, Level);
- }
+ ///
+ /// Decompress the specified BZip2 Tar file.
+ ///
+ /// The context.
+ /// BZip2 file to decompress.
+ /// Output path to decompress into.
+ ///
+ ///
+ /// BZip2Decompress("Cake.tar.bz2", "./cake");
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void BZip2Decompress(
+ this ICakeContext context,
+ FilePath filePath,
+ DirectoryPath outputPath) =>
+ Decompress(context, filePath, outputPath);
- ///
- /// Create a GZip Tar archive of the specified directory.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The compression level (1-9).
- ///
- ///
- /// GZipCompress("./publish", "publish.tar.gz", 6);
- ///
- ///
- [CakeMethodAlias]
- public static void GZipCompress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, int level)
- {
- Compress(context, rootPath, outputPath, level);
- }
+ ///
+ /// Decompress the specified BZip2 Tar file.
+ ///
+ /// The context.
+ /// BZip2 file to decompress.
+ /// Output path to decompress into.
+ ///
+ ///
+ /// BZip2Uncompress("Cake.tar.bz2", "./cake");
+ ///
+ ///
+ [CakeMethodAlias]
+ [Obsolete($"Use the '{nameof(BZip2Decompress)}' method instead.")]
+ public static void BZip2Uncompress(
+ this ICakeContext context,
+ FilePath filePath,
+ DirectoryPath outputPath) =>
+ Decompress(context, filePath, outputPath);
- ///
- /// Create a GZip Tar archive of the files matching the specified pattern.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The pattern.
- ///
- ///
- /// GZipCompress("./", "xmlfiles.tar.gz", "./*.xml");
- ///
- ///
- [CakeMethodAlias]
- public static void GZipCompress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, string pattern)
- {
- Compress(context, rootPath, outputPath, pattern, Level);
- }
+ ///
+ /// Create a GZip Tar archive of the specified directory.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ ///
+ ///
+ /// GZipCompress("./publish", "publish.tar.gz");
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void GZipCompress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath) =>
+ Compress(context, rootPath, outputPath, Level);
- ///
- /// Create a GZip Tar archive of the files matching the specified pattern.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The pattern.
- /// The compression level (1-9).
- ///
- ///
- /// GZipCompress("./", "xmlfiles.tar.gz", "./*.xml", 6);
- ///
- ///
- [CakeMethodAlias]
- public static void GZipCompress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, string pattern, int level)
- {
- Compress(context, rootPath, outputPath, pattern, level);
- }
+ ///
+ /// Create a GZip Tar archive of the specified directory.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The compression level (1-9).
+ ///
+ ///
+ /// GZipCompress("./publish", "publish.tar.gz", 6);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void GZipCompress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ int level) =>
+ Compress(context, rootPath, outputPath, level);
- ///
- /// Create a GZip Tar archive of the specified files.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The file paths.
- ///
- ///
- /// var files = GetFiles("./**/Cake.*.dll");
- /// GZipCompress("./", "cakeassemblies.tar.gz", files);
- ///
- ///
- [CakeMethodAlias]
- public static void GZipCompress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, IEnumerable filePaths)
- {
- Compress(context, rootPath, outputPath, filePaths, Level);
- }
+ ///
+ /// Create a GZip Tar archive of the files matching the specified pattern.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The pattern.
+ ///
+ ///
+ /// GZipCompress("./", "xmlfiles.tar.gz", "./*.xml");
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void GZipCompress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ string pattern) =>
+ Compress(context, rootPath, outputPath, pattern, Level);
- ///
- /// Create a GZip Tar archive of the specified files.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The file paths.
- /// The compression level (1-9).
- ///
- ///
- /// var files = GetFiles("./**/Cake.*.dll");
- /// GZipCompress("./", "cakeassemblies.tar.gz", files, 6);
- ///
- ///
- [CakeMethodAlias]
- public static void GZipCompress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, IEnumerable filePaths, int level)
- {
- Compress(context, rootPath, outputPath, filePaths, level);
- }
+ ///
+ /// Create a GZip Tar archive of the files matching the specified pattern.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The pattern.
+ /// The compression level (1-9).
+ ///
+ ///
+ /// GZipCompress("./", "xmlfiles.tar.gz", "./*.xml", 6);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void GZipCompress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ string pattern,
+ int level) =>
+ Compress(context, rootPath, outputPath, pattern, level);
- ///
- /// Create a GZip Tar archive of the specified files.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The file paths.
- ///
- ///
- /// var files = new [] {
- /// "./src/Cake/bin/Debug/Autofac.dll",
- /// "./src/Cake/bin/Debug/Cake.Common.dll",
- /// "./src/Cake/bin/Debug/Cake.Core.dll",
- /// "./src/Cake/bin/Debug/Cake.exe"
- /// };
- /// GZipCompress("./", "cakebinaries.tar.gz", files);
- ///
- ///
- [CakeMethodAlias]
- public static void GZipCompress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, IEnumerable filePaths)
- {
- Compress(context, rootPath, outputPath, filePaths, Level);
- }
+ ///
+ /// Create a GZip Tar archive of the specified files.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The file paths.
+ ///
+ ///
+ /// var files = GetFiles("./**/Cake.*.dll");
+ /// GZipCompress("./", "cakeassemblies.tar.gz", files);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void GZipCompress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths) =>
+ Compress(context, rootPath, outputPath, filePaths, Level);
- ///
- /// Create a GZip Tar archive of the specified files.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The file paths.
- /// The compression level (1-9).
- ///
- ///
- /// var files = new [] {
- /// "./src/Cake/bin/Debug/Autofac.dll",
- /// "./src/Cake/bin/Debug/Cake.Common.dll",
- /// "./src/Cake/bin/Debug/Cake.Core.dll",
- /// "./src/Cake/bin/Debug/Cake.exe"
- /// };
- /// GZipCompress("./", "cakebinaries.tar.gz", files, 6);
- ///
- ///
- [CakeMethodAlias]
- public static void GZipCompress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, IEnumerable filePaths, int level)
- {
- Compress(context, rootPath, outputPath, filePaths, level);
- }
+ ///
+ /// Create a GZip Tar archive of the specified files.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The file paths.
+ /// The compression level (1-9).
+ ///
+ ///
+ /// var files = GetFiles("./**/Cake.*.dll");
+ /// GZipCompress("./", "cakeassemblies.tar.gz", files, 6);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void GZipCompress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths,
+ int level) =>
+ Compress(context, rootPath, outputPath, filePaths, level);
- ///
- /// Uncompress the specified GZip Tar file.
- ///
- /// The context.
- /// GZip file to uncompress.
- /// Output path to uncompress into.
- ///
- ///
- /// GZipUncompress("Cake.tar.gz", "./cake");
- ///
- ///
- [CakeMethodAlias]
- public static void GZipUncompress(this ICakeContext context, FilePath filePath, DirectoryPath outputPath)
- {
- Uncompress(context, filePath, outputPath);
- }
- #endregion
-
- #region Zip
- ///
- /// Create a Zip archive of the specified directory.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- ///
- ///
- /// ZipCompress("./publish", "publish.zip");
- ///
- ///
- [CakeMethodAlias]
- public static void ZipCompress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath)
- {
- Compress(context, rootPath, outputPath, Level);
- }
+ ///
+ /// Create a GZip Tar archive of the specified files.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The file paths.
+ ///
+ ///
+ /// var files = new [] {
+ /// "./src/Cake/bin/Debug/Autofac.dll",
+ /// "./src/Cake/bin/Debug/Cake.Common.dll",
+ /// "./src/Cake/bin/Debug/Cake.Core.dll",
+ /// "./src/Cake/bin/Debug/Cake.exe"
+ /// };
+ /// GZipCompress("./", "cakebinaries.tar.gz", files);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void GZipCompress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths) =>
+ Compress(context, rootPath, outputPath, filePaths, Level);
- ///
- /// Create a Zip archive of the specified directory.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The compression level (1-9).
- ///
- ///
- /// ZipCompress("./publish", "publish.zip", 6);
- ///
- ///
- [CakeMethodAlias]
- public static void ZipCompress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, int level)
- {
- Compress(context, rootPath, outputPath, level);
- }
+ ///
+ /// Create a GZip Tar archive of the specified files.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The file paths.
+ /// The compression level (1-9).
+ ///
+ ///
+ /// var files = new [] {
+ /// "./src/Cake/bin/Debug/Autofac.dll",
+ /// "./src/Cake/bin/Debug/Cake.Common.dll",
+ /// "./src/Cake/bin/Debug/Cake.Core.dll",
+ /// "./src/Cake/bin/Debug/Cake.exe"
+ /// };
+ /// GZipCompress("./", "cakebinaries.tar.gz", files, 6);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void GZipCompress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths,
+ int level) =>
+ Compress(context, rootPath, outputPath, filePaths, level);
- ///
- /// Create a Zip archive of the files matching the specified pattern.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The pattern.
- ///
- ///
- /// ZipCompress("./", "xmlfiles.zip", "./*.xml");
- ///
- ///
- [CakeMethodAlias]
- public static void ZipCompress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, string pattern)
- {
- Compress(context, rootPath, outputPath, pattern, Level);
- }
+ ///
+ /// Decompress the specified GZip Tar file.
+ ///
+ /// The context.
+ /// GZip file to decompress.
+ /// Output path to decompress into.
+ ///
+ ///
+ /// GZipDecompress("Cake.tar.gz", "./cake");
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void GZipDecompress(
+ this ICakeContext context,
+ FilePath filePath,
+ DirectoryPath outputPath) =>
+ Decompress(context, filePath, outputPath);
- ///
- /// Create a Zip archive of the files matching the specified pattern.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The pattern.
- /// The compression level (1-9).
- ///
- ///
- /// ZipCompress("./", "xmlfiles.zip", "./*.xml", 6);
- ///
- ///
- [CakeMethodAlias]
- public static void ZipCompress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, string pattern, int level)
- {
- Compress(context, rootPath, outputPath, pattern, level);
- }
+ ///
+ /// Decompress the specified GZip Tar file.
+ ///
+ /// The context.
+ /// GZip file to decompress.
+ /// Output path to decompress into.
+ ///
+ ///
+ /// GZipUncompress("Cake.tar.gz", "./cake");
+ ///
+ ///
+ [CakeMethodAlias]
+ [Obsolete($"Use the '{nameof(GZipDecompress)}' method instead.")]
+ public static void GZipUncompress(
+ this ICakeContext context,
+ FilePath filePath,
+ DirectoryPath outputPath) =>
+ Decompress(context, filePath, outputPath);
- ///
- /// Create a Zip archive of the specified files.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The file paths.
- ///
- ///
- /// var files = GetFiles("./**/Cake.*.dll");
- /// ZipCompress("./", "cakeassemblies.zip", files);
- ///
- ///
- [CakeMethodAlias]
- public static void ZipCompress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, IEnumerable filePaths)
- {
- Compress(context, rootPath, outputPath, filePaths, Level);
- }
+ ///
+ /// Create a Zip archive of the specified directory.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ ///
+ ///
+ /// ZipCompress("./publish", "publish.zip");
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void ZipCompress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath) =>
+ Compress(context, rootPath, outputPath, Level);
- ///
- /// Create a Zip archive of the specified files.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The file paths.
- /// The compression level (1-9).
- ///
- ///
- /// var files = GetFiles("./**/Cake.*.dll");
- /// ZipCompress("./", "cakeassemblies.zip", files, 6);
- ///
- ///
- [CakeMethodAlias]
- public static void ZipCompress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, IEnumerable filePaths, int level)
- {
- Compress(context, rootPath, outputPath, filePaths, level);
- }
+ ///
+ /// Create a Zip archive of the specified directory.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The compression level (1-9).
+ ///
+ ///
+ /// ZipCompress("./publish", "publish.zip", 6);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void ZipCompress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ int level) =>
+ Compress(context, rootPath, outputPath, level);
- ///
- /// Create a Zip archive of the specified files.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The file paths.
- ///
- ///
- /// var files = new [] {
- /// "./src/Cake/bin/Debug/Autofac.dll",
- /// "./src/Cake/bin/Debug/Cake.Common.dll",
- /// "./src/Cake/bin/Debug/Cake.Core.dll",
- /// "./src/Cake/bin/Debug/Cake.exe"
- /// };
- /// ZipCompress("./", "cakebinaries.zip", files);
- ///
- ///
- [CakeMethodAlias]
- public static void ZipCompress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, IEnumerable filePaths)
- {
- Compress(context, rootPath, outputPath, filePaths, Level);
- }
+ ///
+ /// Create a Zip archive of the files matching the specified pattern.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The pattern.
+ ///
+ ///
+ /// ZipCompress("./", "xmlfiles.zip", "./*.xml");
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void ZipCompress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ string pattern) =>
+ Compress(context, rootPath, outputPath, pattern, Level);
- ///
- /// Create a Zip archive of the specified files.
- ///
- /// The context.
- /// The root path.
- /// The output path.
- /// The file paths.
- /// The compression level (1-9).
- ///
- ///
- /// var files = new [] {
- /// "./src/Cake/bin/Debug/Autofac.dll",
- /// "./src/Cake/bin/Debug/Cake.Common.dll",
- /// "./src/Cake/bin/Debug/Cake.Core.dll",
- /// "./src/Cake/bin/Debug/Cake.exe"
- /// };
- /// ZipCompress("./", "cakebinaries.zip", files, 6);
- ///
- ///
- [CakeMethodAlias]
- public static void ZipCompress(this ICakeContext context, DirectoryPath rootPath, FilePath outputPath, IEnumerable filePaths, int level)
- {
- Compress(context, rootPath, outputPath, filePaths, level);
- }
+ ///
+ /// Create a Zip archive of the files matching the specified pattern.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The pattern.
+ /// The compression level (1-9).
+ ///
+ ///
+ /// ZipCompress("./", "xmlfiles.zip", "./*.xml", 6);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void ZipCompress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ string pattern,
+ int level) =>
+ Compress(context, rootPath, outputPath, pattern, level);
- ///
- /// Uncompress the specified Zip Tar file.
- ///
- /// The context.
- /// Zip file to uncompress.
- /// Output path to uncompress into.
- ///
- ///
- /// ZipUncompress("Cake.zip", "./cake");
- ///
- ///
- [CakeMethodAlias]
- public static void ZipUncompress(this ICakeContext context, FilePath filePath, DirectoryPath outputPath)
- {
- Uncompress(context, filePath, outputPath);
- }
- #endregion
+ ///
+ /// Create a Zip archive of the specified files.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The file paths.
+ ///
+ ///
+ /// var files = GetFiles("./**/Cake.*.dll");
+ /// ZipCompress("./", "cakeassemblies.zip", files);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void ZipCompress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths) =>
+ Compress(context, rootPath, outputPath, filePaths, Level);
- #region Private Static Methods
- private static T CreateInstance(params object[] args)
- {
- return (T)Activator.CreateInstance(typeof(T), args);
- }
+ ///
+ /// Create a Zip archive of the specified files.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The file paths.
+ /// The compression level (1-9).
+ ///
+ ///
+ /// var files = GetFiles("./**/Cake.*.dll");
+ /// ZipCompress("./", "cakeassemblies.zip", files, 6);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void ZipCompress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths,
+ int level) =>
+ Compress(context, rootPath, outputPath, filePaths, level);
- private static void Compress(
- ICakeContext context,
- DirectoryPath rootPath,
- FilePath outputPath,
- int level) where T : CompressionBase
- {
- Precondition.IsNotNull(context, nameof(context));
- Precondition.IsNotNull(rootPath, nameof(rootPath));
- Precondition.IsNotNull(outputPath, nameof(outputPath));
- Precondition.IsBetween(level, 1, 9, nameof(level));
+ ///
+ /// Create a Zip archive of the specified files.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The file paths.
+ ///
+ ///
+ /// var files = new [] {
+ /// "./src/Cake/bin/Debug/Autofac.dll",
+ /// "./src/Cake/bin/Debug/Cake.Common.dll",
+ /// "./src/Cake/bin/Debug/Cake.Core.dll",
+ /// "./src/Cake/bin/Debug/Cake.exe"
+ /// };
+ /// ZipCompress("./", "cakebinaries.zip", files);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void ZipCompress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths) =>
+ Compress(context, rootPath, outputPath, filePaths, Level);
- FilePathCollection filePaths = context.GetFiles(string.Concat(rootPath, "/**/*"));
- Compress(context, rootPath, outputPath, filePaths, level);
- }
+ ///
+ /// Create a Zip archive of the specified files.
+ ///
+ /// The context.
+ /// The root path.
+ /// The output path.
+ /// The file paths.
+ /// The compression level (1-9).
+ ///
+ ///
+ /// var files = new [] {
+ /// "./src/Cake/bin/Debug/Autofac.dll",
+ /// "./src/Cake/bin/Debug/Cake.Common.dll",
+ /// "./src/Cake/bin/Debug/Cake.Core.dll",
+ /// "./src/Cake/bin/Debug/Cake.exe"
+ /// };
+ /// ZipCompress("./", "cakebinaries.zip", files, 6);
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void ZipCompress(
+ this ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths,
+ int level) =>
+ Compress(context, rootPath, outputPath, filePaths, level);
- private static void Compress(
- ICakeContext context,
- DirectoryPath rootPath,
- FilePath outputPath,
- string pattern,
- int level) where T : CompressionBase
- {
- Precondition.IsNotNull(context, nameof(context));
- Precondition.IsNotNull(rootPath, nameof(rootPath));
- Precondition.IsNotNull(outputPath, nameof(outputPath));
- Precondition.IsNotNullOrEmpty(pattern, nameof(pattern));
- Precondition.IsBetween(level, 1, 9, nameof(level));
+ ///
+ /// Decompress the specified Zip Tar file.
+ ///
+ /// The context.
+ /// Zip file to decompress.
+ /// Output path to decompress into.
+ ///
+ ///
+ /// ZipDecompress("Cake.zip", "./cake");
+ ///
+ ///
+ [CakeMethodAlias]
+ public static void ZipDecompress(
+ this ICakeContext context,
+ FilePath filePath,
+ DirectoryPath outputPath) =>
+ Decompress(context, filePath, outputPath);
- FilePathCollection filePaths = context.GetFiles(pattern);
+ ///
+ /// Decompress the specified Zip Tar file.
+ ///
+ /// The context.
+ /// Zip file to decompress.
+ /// Output path to decompress into.
+ ///
+ ///
+ /// ZipUncompress("Cake.zip", "./cake");
+ ///
+ ///
+ [CakeMethodAlias]
+ [Obsolete($"Use the '{nameof(ZipDecompress)}' method instead.")]
+ public static void ZipUncompress(
+ this ICakeContext context,
+ FilePath filePath,
+ DirectoryPath outputPath) =>
+ Decompress(context, filePath, outputPath);
+
+ private static T CreateInstance(params object[] args) =>
+ (T)Activator.CreateInstance(typeof(T), args)!;
+
+ private static void Compress(
+ ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ int level) where T : CompressionBase
+ {
+ ArgumentNullException.ThrowIfNull(context, nameof(context));
+ ArgumentNullException.ThrowIfNull(rootPath, nameof(rootPath));
+ ArgumentNullException.ThrowIfNull(outputPath, nameof(outputPath));
+ ArgumentOutOfRangeException.ThrowIfLessThan(level, 1, nameof(level));
+ ArgumentOutOfRangeException.ThrowIfGreaterThan(level, 9, nameof(level));
+
+ var filePaths = context.GetFiles(string.Concat(rootPath, "/**/*"));
+ Compress(context, rootPath, outputPath, filePaths, level);
+ }
- if (filePaths.Count == 0)
- {
- context.Log.Verbose("The provided pattern did not match any files.");
- return;
- }
+ private static void Compress(
+ ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ string pattern,
+ int level) where T : CompressionBase
+ {
+ ArgumentNullException.ThrowIfNull(context, nameof(context));
+ ArgumentNullException.ThrowIfNull(rootPath, nameof(rootPath));
+ ArgumentNullException.ThrowIfNull(outputPath, nameof(outputPath));
+ ArgumentException.ThrowIfNullOrWhiteSpace(pattern, nameof(pattern));
+ ArgumentOutOfRangeException.ThrowIfLessThan(level, 1, nameof(level));
+ ArgumentOutOfRangeException.ThrowIfGreaterThan(level, 9, nameof(level));
- Compress(context, rootPath, outputPath, filePaths, level);
- }
+ var filePaths = context.GetFiles(pattern);
- private static void Compress(
- ICakeContext context,
- DirectoryPath rootPath,
- FilePath outputPath,
- IEnumerable filePaths,
- int level) where T : CompressionBase
+ if (filePaths.Count == 0)
{
- Precondition.IsNotNull(context, nameof(context));
- Precondition.IsNotNull(rootPath, nameof(rootPath));
- Precondition.IsNotNull(outputPath, nameof(outputPath));
- Precondition.IsNotNull(filePaths, nameof(filePaths));
- Precondition.IsBetween(level, 1, 9, nameof(level));
-
- T zip = CreateInstance(context.FileSystem, context.Environment, context.Log);
- zip.Compress(rootPath, outputPath, filePaths, level);
+ context.Log.Verbose("The provided pattern did not match any files.");
+ return;
}
- private static void Compress(
- ICakeContext context,
- DirectoryPath rootPath,
- FilePath outputPath,
- IEnumerable filePaths,
- int level) where T : CompressionBase
- {
- Precondition.IsNotNull(context, nameof(context));
- Precondition.IsNotNull(rootPath, nameof(rootPath));
- Precondition.IsNotNull(outputPath, nameof(outputPath));
- Precondition.IsNotNull(filePaths, nameof(filePaths));
- Precondition.IsBetween(level, 1, 9, nameof(level));
-
- List paths = filePaths.Select(path => new FilePath(path)).ToList();
- Compress(context, rootPath, outputPath, paths, level);
- }
+ Compress(context, rootPath, outputPath, filePaths, level);
+ }
- private static void Uncompress(
- ICakeContext context,
- FilePath zipPath,
- DirectoryPath outputPath) where T : CompressionBase
- {
- Precondition.IsNotNull(context, nameof(context));
- Precondition.IsNotNull(zipPath, nameof(zipPath));
- Precondition.IsNotNull(outputPath, nameof(outputPath));
+ private static void Compress(
+ ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths,
+ int level) where T : CompressionBase
+ {
+ ArgumentNullException.ThrowIfNull(context, nameof(context));
+ ArgumentNullException.ThrowIfNull(rootPath, nameof(rootPath));
+ ArgumentNullException.ThrowIfNull(outputPath, nameof(outputPath));
+ ArgumentNullException.ThrowIfNull(filePaths, nameof(filePaths));
+ ArgumentOutOfRangeException.ThrowIfLessThan(level, 1, nameof(level));
+ ArgumentOutOfRangeException.ThrowIfGreaterThan(level, 9, nameof(level));
+
+ var zip = CreateInstance(context.FileSystem, context.Environment, context.Log);
+ zip.Compress(rootPath, outputPath, filePaths, level);
+ }
- T zip = CreateInstance(context.FileSystem, context.Environment, context.Log);
- zip.Uncompress(zipPath, outputPath);
- }
- #endregion
+ private static void Compress(
+ ICakeContext context,
+ DirectoryPath rootPath,
+ FilePath outputPath,
+ IEnumerable filePaths,
+ int level) where T : CompressionBase
+ {
+ ArgumentNullException.ThrowIfNull(context, nameof(context));
+ ArgumentNullException.ThrowIfNull(rootPath, nameof(rootPath));
+ ArgumentNullException.ThrowIfNull(outputPath, nameof(outputPath));
+ ArgumentNullException.ThrowIfNull(filePaths, nameof(filePaths));
+ ArgumentOutOfRangeException.ThrowIfLessThan(level, 1, nameof(level));
+ ArgumentOutOfRangeException.ThrowIfGreaterThan(level, 9, nameof(level));
+
+ var paths = filePaths.Select(path => new FilePath(path)).ToList();
+ Compress(context, rootPath, outputPath, paths, level);
+ }
+
+ private static void Decompress(
+ ICakeContext context,
+ FilePath zipPath,
+ DirectoryPath outputPath) where T : CompressionBase
+ {
+ ArgumentNullException.ThrowIfNull(context, nameof(context));
+ ArgumentNullException.ThrowIfNull(zipPath, nameof(zipPath));
+ ArgumentNullException.ThrowIfNull(outputPath, nameof(outputPath));
+
+ var zip = CreateInstance(context.FileSystem, context.Environment, context.Log);
+ zip.Decompress(zipPath, outputPath);
}
-}
\ No newline at end of file
+}
diff --git a/src/Cake.Compression/Precondition.cs b/src/Cake.Compression/Precondition.cs
deleted file mode 100644
index 7a86e9d..0000000
--- a/src/Cake.Compression/Precondition.cs
+++ /dev/null
@@ -1,66 +0,0 @@
-using System;
-
-namespace Cake.Compression
-{
- ///
- /// Provides static methods that help a constructor or method to verify correct arguments and
- /// state.
- ///
- internal static class Precondition
- {
- #region Public Static Methods
- ///
- /// Checks whether the value is between a minimum and maximum value.
- ///
- /// The value to test.
- /// The minimum value to test.
- /// The maximum value to test.
- /// The name of the parameter that caused the exception.
- /// value is out of
- /// range.
- public static void IsBetween(IComparable value, IComparable min, IComparable max, string paramName)
- {
- if (value.CompareTo(min) == -1 || value.CompareTo(max) == 1)
- {
- throw new ArgumentOutOfRangeException(paramName);
- }
- }
-
- ///
- /// Checks whether the specified object is not null.
- ///
- /// The object to test.
- /// The name of the parameter that caused the exception.
- /// obj is
- /// null.
- public static void IsNotNull(object obj, string paramName)
- {
- if (obj == null)
- {
- throw new ArgumentNullException(paramName);
- }
- }
-
- ///
- /// Checks whether the specified string is not null or an empty string.
- ///
- /// The string to test.
- /// The name of the parameter that caused the exception.
- /// str is
- /// null.
- /// str is empty.
- public static void IsNotNullOrEmpty(string str, string paramName)
- {
- if (str == null)
- {
- throw new ArgumentNullException(paramName);
- }
- else if (string.IsNullOrEmpty(str))
- {
- string message = "The parameter cannot be empty.";
- throw new ArgumentException(message, paramName);
- }
- }
- #endregion
- }
-}
\ No newline at end of file
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
new file mode 100644
index 0000000..ab8e34a
--- /dev/null
+++ b/src/Directory.Build.props
@@ -0,0 +1,21 @@
+
+
+
+ enable
+ enable
+ $(NoWarn)
+
+ true
+ true
+ AllEnabledByDefault
+ latest
+
+ false
+
+ $([System.IO.Path]::GetDirectoryName($([MSBuild]::GetPathOfFileAbove('.gitignore', '$(MSBuildThisFileDirectory)'))))
+
+
+
+ True
+
+
diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets
new file mode 100644
index 0000000..a4884e7
--- /dev/null
+++ b/src/Directory.Build.targets
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props
new file mode 100644
index 0000000..5269d3d
--- /dev/null
+++ b/src/Directory.Packages.props
@@ -0,0 +1,15 @@
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/Cake.Compression.Tests/Cake.Compression.Tests.csproj b/tests/Cake.Compression.Tests/Cake.Compression.Tests.csproj
new file mode 100644
index 0000000..bc9a082
--- /dev/null
+++ b/tests/Cake.Compression.Tests/Cake.Compression.Tests.csproj
@@ -0,0 +1,35 @@
+
+
+
+ net8.0;net9.0
+ enable
+ enable
+ false
+ CA1806
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/Cake.Compression.Tests/CompressionTests.cs b/tests/Cake.Compression.Tests/CompressionTests.cs
new file mode 100644
index 0000000..793c273
--- /dev/null
+++ b/tests/Cake.Compression.Tests/CompressionTests.cs
@@ -0,0 +1,185 @@
+using Cake.Compression.Classes;
+using Cake.Core;
+using Cake.Core.Diagnostics;
+using Cake.Core.IO;
+using Cake.Testing;
+using FluentAssertions;
+using NSubstitute;
+
+// ReSharper disable ObjectCreationAsStatement
+
+namespace Cake.Compression.Tests;
+
+public class CompressionTests
+{
+ private static readonly Type TypeArgumentNullException = typeof(ArgumentNullException);
+ private static readonly Type TypeArgumentOutOfRangeException = typeof(ArgumentOutOfRangeException);
+ private static readonly Type TypeCakeException = typeof(CakeException);
+
+ private static readonly DirectoryPath RootPath = "/Root";
+ private static readonly DirectoryPath OutputPath = "/Decompressed";
+ private static readonly FilePath OutputArchivePath = "/archive.ext";
+ private static readonly IEnumerable FilePaths = ["/Root/file.txt"];
+ private const int Level = 6;
+
+ public static TheoryData ConstructWithNullParameters
+ {
+ get
+ {
+ var fileSystem = Substitute.For();
+ var environment = Substitute.For();
+ var log = Substitute.For();
+
+ return new TheoryData
+ {
+ { () => new BZip2(null!, environment, log), "fileSystem" },
+ { () => new BZip2(fileSystem, null!, log), "environment" },
+ { () => new BZip2(fileSystem, environment, null!), "log" },
+
+ { () => new GZip(null!, environment, log), "fileSystem" },
+ { () => new GZip(fileSystem, null!, log), "environment" },
+ { () => new GZip(fileSystem, environment, null!), "log" },
+
+ { () => new Zip(null!, environment, log), "fileSystem" },
+ { () => new Zip(fileSystem, null!, log), "environment" },
+ { () => new Zip(fileSystem, environment, null!), "log" }
+ };
+ }
+ }
+
+ public static TheoryData CompressWithInvalidParameters
+ {
+ get
+ {
+ var environment = FakeEnvironment.CreateUnixEnvironment();
+ var fileSystem = new FakeFileSystem(environment);
+ fileSystem.CreateFile("/NotRoot/file.txt");
+ var log = Substitute.For();
+
+ var bzip = new BZip2(fileSystem, environment, log);
+ var gzip = new GZip(fileSystem, environment, log);
+ var zip = new Zip(fileSystem, environment, log);
+
+ FilePath bzipOutputPath = "/archive.tar.bz2";
+ FilePath gzipOutputPath = "/archive.tar.gz";
+ FilePath zipOutputPath = "/archive.zip";
+ IEnumerable filePathsNotRoot = ["/NotRoot/file.txt"];
+
+ const string message = "File '/NotRoot/file.txt' is not relative to root path '/Root'.";
+
+ return new TheoryData
+ {
+ { () => bzip.Compress(null!, bzipOutputPath, FilePaths, Level), "rootPath", null, TypeArgumentNullException },
+ { () => bzip.Compress(RootPath, null!, FilePaths, Level), "outputPath", null, TypeArgumentNullException },
+ { () => bzip.Compress(RootPath, bzipOutputPath, null!, Level), "filePaths", null, TypeArgumentNullException },
+ { () => bzip.Compress(RootPath, bzipOutputPath, FilePaths, 0), "level", null, TypeArgumentOutOfRangeException },
+ { () => bzip.Compress(RootPath, bzipOutputPath, FilePaths, 10), "level", null, TypeArgumentOutOfRangeException },
+ { () => bzip.Compress(RootPath, bzipOutputPath, filePathsNotRoot, Level), null, message, TypeCakeException },
+
+ { () => gzip.Compress(null!, gzipOutputPath, FilePaths, Level), "rootPath", null, TypeArgumentNullException },
+ { () => gzip.Compress(RootPath, null!, FilePaths, Level), "outputPath", null, TypeArgumentNullException },
+ { () => gzip.Compress(RootPath, gzipOutputPath, null!, Level), "filePaths", null, TypeArgumentNullException },
+ { () => gzip.Compress(RootPath, gzipOutputPath, FilePaths, 0), "level", null, TypeArgumentOutOfRangeException },
+ { () => gzip.Compress(RootPath, gzipOutputPath, FilePaths, 10), "level", null, TypeArgumentOutOfRangeException },
+ { () => gzip.Compress(RootPath, gzipOutputPath, filePathsNotRoot, Level), null, message, TypeCakeException },
+
+ { () => zip.Compress(null!, zipOutputPath, FilePaths, Level), "rootPath", null, TypeArgumentNullException },
+ { () => zip.Compress(RootPath, null!, FilePaths, Level), "outputPath", null, TypeArgumentNullException },
+ { () => zip.Compress(RootPath, zipOutputPath, null!, Level), "filePaths", null, TypeArgumentNullException },
+ { () => zip.Compress(RootPath, zipOutputPath, FilePaths, 0), "level", null, TypeArgumentOutOfRangeException },
+ { () => zip.Compress(RootPath, zipOutputPath, FilePaths, 10), "level", null, TypeArgumentOutOfRangeException },
+ { () => zip.Compress(RootPath, zipOutputPath, filePathsNotRoot, Level), null, message, TypeCakeException },
+ };
+ }
+ }
+
+ public static TheoryData DecompressWithNullParameters
+ {
+ get
+ {
+ var environment = FakeEnvironment.CreateUnixEnvironment();
+ var fileSystem = new FakeFileSystem(environment);
+ var log = Substitute.For();
+
+ var bzip = new BZip2(fileSystem, environment, log);
+ var gzip = new GZip(fileSystem, environment, log);
+ var zip = new Zip(fileSystem, environment, log);
+
+ return new TheoryData
+ {
+ { () => bzip.Decompress(null!, OutputPath), "filePath" },
+ { () => bzip.Decompress("/archive.tar.bz2", null!), "outputPath" },
+
+ { () => gzip.Decompress(null!, OutputPath), "filePath" },
+ { () => gzip.Decompress("/archive.tar.gz", null!), "outputPath" },
+
+ { () => zip.Decompress(null!, OutputPath), "filePath" },
+ { () => zip.Decompress("/archive.zip", null!), "outputPath" }
+ };
+ }
+ }
+
+ public static TheoryData CompressionBaseInstances
+ {
+ get
+ {
+ var environment = FakeEnvironment.CreateUnixEnvironment();
+ var fileSystem = new FakeFileSystem(environment);
+ fileSystem.CreateFile("/Root/file.txt");
+ var log = Substitute.For();
+
+ return new TheoryData
+ {
+ { new BZip2(fileSystem, environment, log), fileSystem },
+ { new GZip(fileSystem, environment, log), fileSystem },
+ { new Zip(fileSystem, environment, log), fileSystem },
+ };
+ }
+ }
+
+ [Theory]
+ [MemberData(nameof(ConstructWithNullParameters))]
+ public void Should_Throw_On_Construct_With_Null_Parameters(Action act, string parameterName)
+ {
+ // Assert
+ act.Should().Throw().WithParameterName(parameterName);
+ }
+
+ [Theory]
+ [MemberData(nameof(CompressWithInvalidParameters))]
+ public void Should_Throw_On_Compress_With_Invalid_Parameters(Action act, string? parameterName, string? message, Type exceptionType)
+ {
+ // Assert
+ if (exceptionType == TypeArgumentNullException)
+ {
+ act.Should().Throw().WithParameterName(parameterName);
+ }
+ else if (exceptionType == TypeArgumentOutOfRangeException)
+ {
+ act.Should().Throw().WithParameterName(parameterName);
+ }
+ else if (exceptionType == TypeCakeException)
+ {
+ act.Should().Throw().WithMessage(message);
+ }
+ }
+
+ [Theory]
+ [MemberData(nameof(DecompressWithNullParameters))]
+ public void Should_Throw_On_Decompress_With_Null_Parameters(Action act, string parameterName)
+ {
+ // Assert
+ act.Should().Throw().WithParameterName(parameterName);
+ }
+
+ [Theory]
+ [MemberData(nameof(CompressionBaseInstances))]
+ public void Should_Compress_Files(CompressionBase zip, FakeFileSystem fileSystem)
+ {
+ // Act
+ zip.Compress(RootPath, OutputArchivePath, FilePaths, Level);
+
+ // Assert
+ fileSystem.Exist(OutputArchivePath).Should().BeTrue();
+ }
+}
diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props
new file mode 100644
index 0000000..7c03f27
--- /dev/null
+++ b/tests/Directory.Build.props
@@ -0,0 +1,9 @@
+
+
+
+ enable
+ enable
+ $(NoWarn)
+ false
+
+
diff --git a/tests/Directory.Build.targets b/tests/Directory.Build.targets
new file mode 100644
index 0000000..a4884e7
--- /dev/null
+++ b/tests/Directory.Build.targets
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/tests/Directory.Packages.props b/tests/Directory.Packages.props
new file mode 100644
index 0000000..9be5b9e
--- /dev/null
+++ b/tests/Directory.Packages.props
@@ -0,0 +1,20 @@
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tools/packages.config b/tools/packages.config
deleted file mode 100644
index f27ab48..0000000
--- a/tools/packages.config
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-