Add jar sorting to zip2zip

Jars have a strange sorting order; the META-INF/ directory should
come first, then META-INF/MANIFEST.MF, then any other files in
META-INF/, and then any files outside META-INF.  Add a -j argument
to zip2zip that sorts using jar ordering.

Test: zip2zip_test
Change-Id: I80e2bc7e284ef74f6561c26cb6541298834db1bc
This commit is contained in:
Colin Cross
2017-06-23 13:00:17 -07:00
parent 3e3e72da90
commit 8936b02b58
2 changed files with 79 additions and 10 deletions

View File

@@ -28,6 +28,7 @@ var testCases = []struct {
inputFiles []string
sortGlobs bool
sortJava bool
args []string
outputFiles []string
@@ -115,6 +116,35 @@ var testCases = []struct {
"RADIO/a",
},
},
{
name: "sort jar",
inputFiles: []string{
"MANIFEST.MF",
"META-INF/MANIFEST.MF",
"META-INF/aaa/",
"META-INF/aaa/aaa",
"META-INF/AAA",
"META-INF.txt",
"META-INF/",
"AAA",
"aaa",
},
sortJava: true,
args: nil,
outputFiles: []string{
"META-INF/",
"META-INF/MANIFEST.MF",
"META-INF/AAA",
"META-INF/aaa/",
"META-INF/aaa/aaa",
"AAA",
"MANIFEST.MF",
"META-INF.txt",
"aaa",
},
},
{
name: "double input",
@@ -161,7 +191,7 @@ func TestZip2Zip(t *testing.T) {
}
outputWriter := zip.NewWriter(outputBuf)
err = zip2zip(inputReader, outputWriter, testCase.sortGlobs, false, testCase.args)
err = zip2zip(inputReader, outputWriter, testCase.sortGlobs, testCase.sortJava, false, testCase.args)
if errorString(testCase.err) != errorString(err) {
t.Fatalf("Unexpected error:\n got: %q\nwant: %q", errorString(err), errorString(testCase.err))
}