Skip to content

Commit d0196ff

Browse files
committed
(#444) added a demo using cake.sdk
1 parent b2fe7be commit d0196ff

File tree

2 files changed

+204
-0
lines changed

2 files changed

+204
-0
lines changed

demo/sdk/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
output/

demo/sdk/cake.cs

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
#!/usr/bin/env dotnet
2+
#:sdk Cake.Sdk@6.0.0
3+
#:project ../../src/Cake.7zip/Cake.7zip.csproj
4+
5+
// these are only needed because we referenced the csproj above and not the nuget package
6+
using Cake.SevenZip.Builder;
7+
using Cake.SevenZip.Switches;
8+
9+
///////////////////////////////////////////////////////////////////////////////
10+
// ARGUMENTS
11+
///////////////////////////////////////////////////////////////////////////////
12+
13+
var target = Argument("target", "Default");
14+
15+
///////////////////////////////////////////////////////////////////////////////
16+
// VARIABLES
17+
///////////////////////////////////////////////////////////////////////////////
18+
19+
var output = Directory("output");
20+
var root = Directory("../..");
21+
22+
///////////////////////////////////////////////////////////////////////////////
23+
// TASKS
24+
///////////////////////////////////////////////////////////////////////////////
25+
26+
Task("Clean")
27+
.Does(() =>
28+
{
29+
CleanDirectory(output);
30+
});
31+
32+
Task("ZipIt")
33+
.Does(() =>
34+
{
35+
SevenZip(m => m
36+
.InAddMode()
37+
.WithArchive(output + File("archive.zip"))
38+
.WithFiles(root + File("README.md"))
39+
.WithFiles(root + File("CODE_OF_CONDUCT.md")));
40+
});
41+
42+
Task("ZipVolumes")
43+
.Does(() =>
44+
{
45+
SevenZip(m => m
46+
.InAddMode()
47+
.WithArchive(output + File("volume.7z"))
48+
.WithArchiveType(SwitchArchiveType.SevenZip)
49+
.WithDirectoryContents(root + Directory("src"))
50+
.WithCompressFilesOpenForWriting()
51+
.WithVolume(20, VolumeUnit.Megabytes));
52+
});
53+
54+
Task("UnzipIt")
55+
.IsDependentOn("ZipIt")
56+
.Does(() =>
57+
{
58+
var d = output + Directory("extracted");
59+
CleanDirectory(d);
60+
SevenZip(m => m
61+
.InExtractMode()
62+
.WithArchive(output + File("archive.zip"))
63+
.WithOutputDirectory(d)
64+
.WithIncludeFilenames(RecurseType.Enable, "*.cs", "*.xml"));
65+
});
66+
67+
Task("RemoveFiles")
68+
.IsDependentOn("ZipIt")
69+
.Does(() =>
70+
{
71+
SevenZip(m => m
72+
.InDeleteMode()
73+
.WithArchive(output + File("archive.zip"))
74+
.WithFiles(File("README.md")));
75+
});
76+
77+
Task("UpdateIt")
78+
.IsDependentOn("ZipIt")
79+
.Does(() =>
80+
{
81+
SevenZip(m => m
82+
.InUpdateMode()
83+
.WithArchive(output + File("archive.zip"))
84+
.WithFiles(root + File("LICENSE.txt")));
85+
});
86+
87+
Task("GetInfos")
88+
.Does(() =>
89+
{
90+
SevenZip(m => m
91+
.InInformationMode()
92+
.WithCommandOutput(o =>
93+
{
94+
Information("7Zip version is:" + o.Information);
95+
Information("7Zip supports QCOW:" + (o.Formats.Any(x => x.IndexOf("QCOW") > -1)));
96+
}));
97+
});
98+
99+
Task("TestZip")
100+
.IsDependentOn("ZipIt")
101+
.Does(() =>
102+
{
103+
SevenZip(m => m
104+
.InTestMode()
105+
.WithArchive(output + File("archive.zip"))
106+
.WithCommandOutput(o =>
107+
{
108+
Information("7Zip version is:" + o.Information);
109+
foreach (var archiveTestResult in o.Archives)
110+
{
111+
var isOk = archiveTestResult.IsOk ? "OK" : "not OK";
112+
Information($" - {archiveTestResult.FileName} test is { isOk }");
113+
}
114+
}));
115+
});
116+
117+
Task("GetHash")
118+
.IsDependentOn("ZipIt")
119+
.Does(() =>
120+
{
121+
SevenZip(m => m
122+
.InHashMode()
123+
.WithFiles(output + File("archive.zip"))
124+
.WithHashFunction(SwitchSetHashFunction.All)
125+
.WithCommandOutput(o =>
126+
{
127+
Information("7Zip version is:" + o.Information);
128+
var file = o.Files.First();
129+
foreach(var hash in file.Hashes){
130+
Information($"{hash.HashFunction} of {file.FilePath} is: {hash.Hash}");
131+
}
132+
}));
133+
});
134+
135+
Task("DoBenchmark")
136+
.Does(() =>
137+
{
138+
SevenZip(m => m
139+
.InBenchmarkMode()
140+
.WithCommandOutput(o =>
141+
{
142+
Information("7Zip version is:" + o.Information);
143+
Information("Benchmark results:");
144+
Information(o.Benchmark);
145+
}));
146+
});
147+
148+
Task("ListArchiveContent")
149+
.IsDependentOn("ZipIt")
150+
.Does(() =>
151+
{
152+
SevenZip(m => m
153+
.InListMode()
154+
.WithArchive(output + File("archive.zip"))
155+
.WithCommandOutput(o =>
156+
{
157+
Information("7Zip version is:" + o.Information);
158+
var archive = o.Archives.Single(); // only one archive given above
159+
foreach(var file in archive.Files)
160+
{
161+
Information($"{file.Name} has compressed size {file.CompressedSize} (of {file.Size})");
162+
}
163+
}));
164+
});
165+
166+
Task("RenameFile")
167+
.IsDependentOn("ZipIt")
168+
.Does(() =>
169+
{
170+
SevenZip(m => m
171+
.InRenameMode()
172+
.WithArchive(output + File("archive.zip"))
173+
.WithRenameFile(File("CODE_OF_CONDUCT.md"), File("CODE_OF_CONDUCT.txt")));
174+
});
175+
176+
Task("GH78")
177+
.IsDependentOn("Clean")
178+
.IsDependentOn("ZipVolumes")
179+
.Does(() =>
180+
{
181+
SevenZip(m => m
182+
.InExtractMode()
183+
.WithArchive(output + File("volume.7z.001"))
184+
.WithArchiveType(SwitchArchiveType.SevenZip.Volumes())
185+
.WithOutputDirectory(output + Directory("Test01")));
186+
});
187+
188+
Task("Default")
189+
.IsDependentOn("Clean")
190+
.IsDependentOn("ZipIt")
191+
.IsDependentOn("ZipVolumes")
192+
.IsDependentOn("UnzipIt")
193+
.IsDependentOn("RemoveFiles")
194+
.IsDependentOn("UpdateIt")
195+
.IsDependentOn("GetInfos")
196+
.IsDependentOn("TestZip")
197+
.IsDependentOn("GetHash")
198+
.IsDependentOn("DoBenchmark")
199+
.IsDependentOn("ListArchiveContent")
200+
.IsDependentOn("RenameFile")
201+
.IsDependentOn("GH78");
202+
203+
RunTarget(target);

0 commit comments

Comments
 (0)