blob: 757862b998b478d28a5d62e88e84ff1bd365c232 [file] [log] [blame]
Tobias Thierer878c77b2019-08-18 15:19:45 +01001// 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
Bob Badour051ef782021-02-12 17:07:05 -080015package {
16 // See: http://go/android-license-faq
17 // A large-scale-change added 'default_applicable_licenses' to import
18 // all of the 'license_kinds' from "frameworks_base_license"
19 // to get the below license kinds:
20 // SPDX-license-identifier-Apache-2.0
21 default_applicable_licenses: ["frameworks_base_license"],
22}
23
Tobias Thiereradeea592019-09-27 20:27:29 +010024java_defaults {
25 name: "mimemap-defaults",
26 srcs: [
27 "java/android/content/type/DefaultMimeMapFactory.java",
28 ],
29 sdk_version: "core_platform",
30}
31
Tobias Thierer878c77b2019-08-18 15:19:45 +010032java_library {
33 name: "mimemap",
Tobias Thiereradeea592019-09-27 20:27:29 +010034 defaults: ["mimemap-defaults"],
35 static_libs: ["mimemap-res.jar"],
36 visibility: [
37 "//frameworks/base:__subpackages__",
38 ],
39}
40
41java_library {
42 name: "mimemap-testing",
43 defaults: ["mimemap-defaults"],
44 static_libs: ["mimemap-testing-res.jar"],
45 jarjar_rules: "jarjar-rules.txt",
Tobias Thierer878c77b2019-08-18 15:19:45 +010046 visibility: [
47 "//cts/tests/tests/mimemap:__subpackages__",
48 "//frameworks/base:__subpackages__",
49 ],
Tobias Thiereradeea592019-09-27 20:27:29 +010050}
Tobias Thierer878c77b2019-08-18 15:19:45 +010051
Tobias Thiereradeea592019-09-27 20:27:29 +010052// The mimemap-res.jar and mimemap-testing-res.jar genrules produce a .jar that
53// has the resource file in a subdirectory res/ and testres/, respectively.
Tobias Thierer9a3c4432019-10-02 20:54:35 +010054// They need to be in different paths because one of them ends up in a
55// bootclasspath jar whereas the other one ends up in a test jar. Bootclasspath
56// resources hide test or application resources under the same path because
57// ClassLoader.getResource(String) consults the parent ClassLoader first.
Tobias Thiereradeea592019-09-27 20:27:29 +010058//
59// Further notes:
60// - the "cp" command will flatten any directory paths that occur in $(in),
61// but here they happen to already be in the root directory. If we needed
62// to preserve sub paths then we might want to zip the files first and then
63// unzip them below the new parent directory.
64// - the path names "res/" and "testres/" and duplicated in .java source files
65// (DefaultMimeMapFactory.java and MimeMapTest.java, as of October 2019).
66java_genrule {
67 name: "mimemap-res.jar",
68 tools: [
69 "soong_zip",
Tobias Thierer878c77b2019-08-18 15:19:45 +010070 ],
Tobias Thierer8e1c1f42019-10-08 16:27:35 +010071 srcs: [":mime.types.minimized"],
Tobias Thiereradeea592019-09-27 20:27:29 +010072 out: ["mimemap-res.jar"],
73 cmd: "mkdir $(genDir)/res/ && cp $(in) $(genDir)/res/ && $(location soong_zip) -C $(genDir) -o $(out) -D $(genDir)/res/",
74}
Tobias Thierer878c77b2019-08-18 15:19:45 +010075
Tobias Thiereradeea592019-09-27 20:27:29 +010076// The same as mimemap-res.jar except that the resources are placed in a different directory.
77// They get bundled with CTS so that CTS can compare a device's MimeMap implementation vs.
78// the stock Android one from when CTS was built.
79java_genrule {
80 name: "mimemap-testing-res.jar",
81 tools: [
82 "soong_zip",
83 ],
Tobias Thierer8e1c1f42019-10-08 16:27:35 +010084 srcs: [":mime.types.minimized"],
Tobias Thiereradeea592019-09-27 20:27:29 +010085 out: ["mimemap-testing-res.jar"],
86 cmd: "mkdir $(genDir)/testres/ && cp $(in) $(genDir)/testres/ && $(location soong_zip) -C $(genDir) -o $(out) -D $(genDir)/testres/",
87}
88
Tobias Thierer8e1c1f42019-10-08 16:27:35 +010089// Combination of all *mime.types.minimized resources.
Tobias Thiereradeea592019-09-27 20:27:29 +010090filegroup {
Tobias Thierer8e1c1f42019-10-08 16:27:35 +010091 name: "mime.types.minimized",
Tobias Thiereradeea592019-09-27 20:27:29 +010092 visibility: [
93 "//visibility:private",
94 ],
95 srcs: [
Tobias Thierer8e1c1f42019-10-08 16:27:35 +010096 ":debian.mime.types.minimized",
97 ":android.mime.types.minimized",
98 ":vendor.mime.types.minimized",
Tobias Thierer878c77b2019-08-18 15:19:45 +010099 ],
Tobias Thierer878c77b2019-08-18 15:19:45 +0100100}
101
Tobias Thierer8e1c1f42019-10-08 16:27:35 +0100102java_genrule {
103 name: "android.mime.types.minimized",
Tobias Thierer878c77b2019-08-18 15:19:45 +0100104 visibility: [
105 "//visibility:private",
106 ],
Tobias Thierer8e1c1f42019-10-08 16:27:35 +0100107 out: ["android.mime.types"],
Tobias Thierer878c77b2019-08-18 15:19:45 +0100108 srcs: [
109 "java-res/android.mime.types",
110 ],
Tobias Thierer8e1c1f42019-10-08 16:27:35 +0100111 // strip comments normalize whitepace drop empty lines
112 cmd: "awk '{gsub(/#.*$$/,\"\"); $$1=$$1; print;}' $(in) | grep ' ' > $(out)",
Tobias Thierer878c77b2019-08-18 15:19:45 +0100113}
Tobias Thierer32434912019-09-27 19:22:39 +0100114
Tobias Thierer8e1c1f42019-10-08 16:27:35 +0100115// Unlike the other *mime.types files, vendor.mime.types gets '?' prepended to
116// every field so that its mappings will never overwrite earlier mappings by
117// the other resource files. http://b/141842825
118java_genrule {
119 name: "vendor.mime.types.minimized",
Tobias Thierer32434912019-09-27 19:22:39 +0100120 visibility: [
121 "//visibility:private",
122 ],
Tobias Thierer8e1c1f42019-10-08 16:27:35 +0100123 out: ["vendor.mime.types"],
Tobias Thierer32434912019-09-27 19:22:39 +0100124 srcs: [
125 "java-res/vendor.mime.types",
126 ],
Liz Kammer2b0640132023-09-07 16:57:08 -0400127 // strip comments normalize whitepace drop empty lines prepend ? to fields that are missing it
128 cmd: "awk '{gsub(/#.*$$/,\"\"); $$1=$$1; print;}' $(in) | (grep ' ' || echo -n '') | awk '{for(i=1;i<=NF;i++) { sub(/^\\??/, \"?\", $$i); }; print}' > $(out)",
Tobias Thierer32434912019-09-27 19:22:39 +0100129}