Adam Lesinski | a1ad4a8 | 2015-06-08 11:41:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef AAPT_PROGUARD_RULES_H |
| 18 | #define AAPT_PROGUARD_RULES_H |
| 19 | |
| 20 | #include "Resource.h" |
| 21 | #include "Source.h" |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 22 | #include "xml/XmlDom.h" |
Adam Lesinski | a1ad4a8 | 2015-06-08 11:41:09 -0700 | [diff] [blame] | 23 | |
| 24 | #include <map> |
| 25 | #include <ostream> |
| 26 | #include <set> |
| 27 | #include <string> |
| 28 | |
| 29 | namespace aapt { |
| 30 | namespace proguard { |
| 31 | |
| 32 | class KeepSet { |
| 33 | public: |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 34 | inline void addClass(const Source& source, const std::u16string& className) { |
Adam Lesinski | a1ad4a8 | 2015-06-08 11:41:09 -0700 | [diff] [blame] | 35 | mKeepSet[className].insert(source); |
| 36 | } |
| 37 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 38 | inline void addMethod(const Source& source, const std::u16string& methodName) { |
Adam Lesinski | a1ad4a8 | 2015-06-08 11:41:09 -0700 | [diff] [blame] | 39 | mKeepMethodSet[methodName].insert(source); |
| 40 | } |
| 41 | |
| 42 | private: |
| 43 | friend bool writeKeepSet(std::ostream* out, const KeepSet& keepSet); |
| 44 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 45 | std::map<std::u16string, std::set<Source>> mKeepSet; |
| 46 | std::map<std::u16string, std::set<Source>> mKeepMethodSet; |
Adam Lesinski | a1ad4a8 | 2015-06-08 11:41:09 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
Rohit Agrawal | e49bb30 | 2016-04-22 12:27:55 -0700 | [diff] [blame] | 49 | bool collectProguardRulesForManifest(const Source& source, xml::XmlResource* res, KeepSet* keepSet, |
| 50 | bool mainDexOnly = false); |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 51 | bool collectProguardRules(const Source& source, xml::XmlResource* res, KeepSet* keepSet); |
Adam Lesinski | a1ad4a8 | 2015-06-08 11:41:09 -0700 | [diff] [blame] | 52 | |
| 53 | bool writeKeepSet(std::ostream* out, const KeepSet& keepSet); |
| 54 | |
| 55 | } // namespace proguard |
| 56 | } // namespace aapt |
| 57 | |
| 58 | #endif // AAPT_PROGUARD_RULES_H |