aboutsummaryrefslogtreecommitdiffstats
path: root/jar
diff options
context:
space:
mode:
authorJeff Gaston2017-08-21 22:13:28 -0500
committerJeff Gaston2017-08-24 16:43:35 -0500
commit01547b23d26b6dcde8589add0451d87d7bf63f91 (patch)
tree4d48ff404f43c6ddb1187ef8273a2173e2a60681 /jar
parentc5eb66d16b82279d33746d312e91793970e0310f (diff)
downloadplatform-build-soong-01547b23d26b6dcde8589add0451d87d7bf63f91.tar.gz
platform-build-soong-01547b23d26b6dcde8589add0451d87d7bf63f91.tar.xz
platform-build-soong-01547b23d26b6dcde8589add0451d87d7bf63f91.zip
Extract jar-sorting to be accessible to soong_zip
Bug: 64536066 Test: m -j # which runs unit tests Change-Id: I4830bd331c9dab0b1d300a18aefaf25a6af4cfdc
Diffstat (limited to 'jar')
-rw-r--r--jar/Android.bp22
-rw-r--r--jar/jar.go55
2 files changed, 77 insertions, 0 deletions
diff --git a/jar/Android.bp b/jar/Android.bp
new file mode 100644
index 00000000..23ad5368
--- /dev/null
+++ b/jar/Android.bp
@@ -0,0 +1,22 @@
1// Copyright 2017 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15bootstrap_go_package {
16 name: "soong-jar",
17 pkgPath: "android/soong/jar",
18 srcs: [
19 "jar.go",
20 ],
21}
22
diff --git a/jar/jar.go b/jar/jar.go
new file mode 100644
index 00000000..d8f063c9
--- /dev/null
+++ b/jar/jar.go
@@ -0,0 +1,55 @@
1// Copyright 2017 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package jar
16
17import (
18 "fmt"
19 "strings"
20)
21
22// EntryNamesLess tells whether <filepathA> should precede <filepathB> in
23// the order of files with a .jar
24func EntryNamesLess(filepathA string, filepathB string) (less bool) {
25 diff := index(filepathA) - index(filepathB)
26 if diff == 0 {
27 return filepathA < filepathB
28 }
29 return diff < 0
30}
31
32// Treats trailing * as a prefix match
33func patternMatch(pattern, name string) bool {
34 if strings.HasSuffix(pattern, "*") {
35 return strings.HasPrefix(name, strings.TrimSuffix(pattern, "*"))
36 } else {
37 return name == pattern
38 }
39}
40
41var jarOrder = []string{
42 "META-INF/",
43 "META-INF/MANIFEST.MF",
44 "META-INF/*",
45 "*",
46}
47
48func index(name string) int {
49 for i, pattern := range jarOrder {
50 if patternMatch(pattern, name) {
51 return i
52 }
53 }
54 panic(fmt.Errorf("file %q did not match any pattern", name))
55}