WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/diffr/diffr.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"fmt"
"io"
"strings"

"github.com/google/oss-rebuild/internal/gitdiff"
"github.com/pkg/errors"
Expand Down Expand Up @@ -122,7 +123,11 @@ func compareFiles(ctx compareContext, node *DiffNode, file1, file2 File) (bool,
case TypeGzip:
match, err = compareGzip(ctx, &typedNode, file1, file2)
case TypeZip:
match, err = compareZip(ctx, &typedNode, file1, file2)
if ctx.depth == 0 && strings.HasSuffix(file1.Name, ".jar") && strings.HasSuffix(file2.Name, ".jar") {
match, err = compareJar(ctx, &typedNode, file1, file2)
} else {
match, err = compareZip(ctx, &typedNode, file1, file2)
}
case TypeTar:
match, err = compareTar(ctx, &typedNode, file1, file2)
case TypeText:
Expand Down
59 changes: 59 additions & 0 deletions pkg/diffr/diffr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,65 @@ func TestDiff(t *testing.T) {
"source1": "file.txt.gz",
"source2": "file.txt.gz",
"comments": ["Bytes differ but no semantic diff generated"]
}`,
},
{
name: "jar_content_diff",
description: "JAR with different class file version should show diff",
left: func() ([]byte, error) {
// public class A {
// public static void main(String[] args) {
// System.out.println("hello world");
// }
// }
return createZip([]archive.ZipEntry{
{FileHeader: &zip.FileHeader{Name: "A.class"}, Body: []byte{0xca, 0xfe, 0xba, 0xbe, 0x0, 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0x0, 0x1b, 0x0, 0x0, 0x0, 0x2, 0x0, 0x1c}},
})
},
right: func() ([]byte, error) {
// public class A {
// public static void main(String[] args) {
// System.out.println("hello test");
// }
// }
return createZip([]archive.ZipEntry{
{FileHeader: &zip.FileHeader{Name: "A.class"}, Body: []byte{0xca, 0xfe, 0xba, 0xbe, 0x0, 0x0, 0x0, 0x3d, 0x0, 0x1d, 0xa, 0x0, 0x2, 0x0, 0x3, 0x7, 0x0, 0x4, 0xc, 0x0, 0x5, 0x0, 0x6, 0x1, 0x0, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, 0x61, 0x6e, 0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x1, 0x0, 0x6, 0x3c, 0x69, 0x6e, 0x69, 0x74, 0x3e, 0x1, 0x0, 0x3, 0x28, 0x29, 0x56, 0x9, 0x0, 0x8, 0x0, 0x9, 0x7, 0x0, 0xa, 0xc, 0x0, 0xb, 0x0, 0xc, 0x1, 0x0, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, 0x61, 0x6e, 0x67, 0x2f, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x1, 0x0, 0x3, 0x6f, 0x75, 0x74, 0x1, 0x0, 0x15, 0x4c, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x69, 0x6f, 0x2f, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x3b, 0x8, 0x0, 0xe, 0x1, 0x0, 0xa, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x74, 0x65, 0x73, 0x74, 0xa, 0x0, 0x10, 0x0, 0x11, 0x7, 0x0, 0x12, 0xc, 0x0, 0x13, 0x0, 0x14, 0x1, 0x0, 0x13, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x69, 0x6f, 0x2f, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x53, 0x74, 0x72, 0x65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 0x0, 0x9, 0xb2, 0x0, 0x7, 0x12, 0xd, 0xb6, 0x0, 0xf, 0xb1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x18, 0x0, 0x0, 0x0, 0xa, 0x0, 0x2, 0x0, 0x0, 0x0, 0x3, 0x0, 0x8, 0x0, 0x4, 0x0, 0x1, 0x0, 0x1b, 0x0, 0x0, 0x0, 0x2, 0x0, 0x1c}},
})
},
leftName: "archive.jar",
rightName: "archive.jar",
expectTextDiff: `--- archive.jar
+++ archive.jar
├── file list
│ @@ -1 +1 @@
│ --rw-rw-rw- Store 407 1979-11-30 00:00:00.000000 A.class
│ +-rw-rw-rw- Store 406 1979-11-30 00:00:00.000000 A.class
├── A.class
│ @@ -6,7 +6,7 @@ ()V
│ java/lang/System
│ out
│ Ljava/io/PrintStream;
│ - hello world
│ + hello test
│ java/io/PrintStream
│ println
│ (Ljava/lang/String;)V
`,
expectJSONDiff: `{
"details": [
{
"source1": "file list",
"source2": "file list",
"unified_diff": "@@ -1 +1 @@\n--rw-rw-rw- Store 407 1979-11-30 00:00:00.000000 A.class\n+-rw-rw-rw- Store 406 1979-11-30 00:00:00.000000 A.class\n"
},
{
"source1": "A.class",
"source2": "A.class",
"unified_diff": "@@ -6,7 +6,7 @@ ()V\n java/lang/System\n out\n Ljava/io/PrintStream;\n- hello world\n+ hello test\n java/io/PrintStream\n println\n (Ljava/lang/String;)V\n"
}
],
"source1": "archive.jar",
"source2": "archive.jar"
}`,
},
}
Expand Down
Loading