• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2019 The Android Open Source Project
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 
15 
16 java_defaults {
17     name: "mimemap-defaults",
18     srcs: [
19         "java/android/content/type/DefaultMimeMapFactory.java",
20     ],
21     sdk_version: "core_platform",
22 }
23 
24 java_library {
25     name: "mimemap",
26     defaults: ["mimemap-defaults"],
27     static_libs: ["mimemap-res.jar"],
28     visibility: [
29         "//frameworks/base:__subpackages__",
30     ],
31 }
32 
33 java_library {
34     name: "mimemap-testing",
35     defaults: ["mimemap-defaults"],
36     static_libs: ["mimemap-testing-res.jar"],
37     jarjar_rules: "jarjar-rules.txt",
38     visibility: [
39         "//cts/tests/tests/mimemap:__subpackages__",
40         "//frameworks/base:__subpackages__",
41     ],
42 }
43 
44 // The mimemap-res.jar and mimemap-testing-res.jar genrules produce a .jar that
45 // has the resource file in a subdirectory res/ and testres/, respectively.
46 // They need to be in different paths because one of them ends up in a
47 // bootclasspath jar whereas the other one ends up in a test jar. Bootclasspath
48 // resources hide test or application resources under the same path because
49 // ClassLoader.getResource(String) consults the parent ClassLoader first.
50 //
51 // Further notes:
52 //  - the "cp" command will flatten any directory paths that occur in $(in),
53 //    but here they happen to already be in the root directory. If we needed
54 //    to preserve sub paths then we might want to zip the files first and then
55 //    unzip them below the new parent directory.
56 //  - the path names "res/" and "testres/" and duplicated in .java source files
57 //    (DefaultMimeMapFactory.java and MimeMapTest.java, as of October 2019).
58 java_genrule {
59     name: "mimemap-res.jar",
60     tools: [
61         "soong_zip",
62     ],
63     srcs: [":mime.types.minimized"],
64     out: ["mimemap-res.jar"],
65     cmd: "mkdir $(genDir)/res/ && cp $(in) $(genDir)/res/ && $(location soong_zip) -C $(genDir) -o $(out) -D $(genDir)/res/",
66 }
67 
68 // The same as mimemap-res.jar except that the resources are placed in a different directory.
69 // They get bundled with CTS so that CTS can compare a device's MimeMap implementation vs.
70 // the stock Android one from when CTS was built.
71 java_genrule {
72     name: "mimemap-testing-res.jar",
73     tools: [
74         "soong_zip",
75     ],
76     srcs: [":mime.types.minimized"],
77     out: ["mimemap-testing-res.jar"],
78     cmd: "mkdir $(genDir)/testres/ && cp $(in) $(genDir)/testres/ && $(location soong_zip) -C $(genDir) -o $(out) -D $(genDir)/testres/",
79 }
80 
81 // Combination of all *mime.types.minimized resources.
82 filegroup {
83     name: "mime.types.minimized",
84     visibility: [
85         "//visibility:private",
86     ],
87     srcs: [
88         ":debian.mime.types.minimized",
89         ":android.mime.types.minimized",
90         ":vendor.mime.types.minimized",
91     ],
92 }
93 
94 java_genrule {
95     name: "android.mime.types.minimized",
96     visibility: [
97         "//visibility:private",
98     ],
99     out: ["android.mime.types"],
100     srcs: [
101         "java-res/android.mime.types",
102     ],
103     //    strip comments            normalize whitepace       drop empty lines
104     cmd: "awk '{gsub(/#.*$$/,\"\"); $$1=$$1; print;}' $(in) | grep ' ' > $(out)",
105 }
106 
107 // Unlike the other *mime.types files, vendor.mime.types gets '?' prepended to
108 // every field so that its mappings will never overwrite earlier mappings by
109 // the other resource files. http://b/141842825
110 java_genrule {
111     name: "vendor.mime.types.minimized",
112     visibility: [
113         "//visibility:private",
114     ],
115     out: ["vendor.mime.types"],
116     srcs: [
117         "java-res/vendor.mime.types",
118     ],
119     //    strip comments            normalize whitepace       drop empty lines   prepend ? to fields that are missing it
120     cmd: "awk '{gsub(/#.*$$/,\"\"); $$1=$$1; print;}' $(in) | grep ' '         | awk '{for(i=1;i<=NF;i++) { sub(/^\\??/, \"?\", $$i); }; print}' > $(out)",
121 }
122