blob: 3c349bab12179eb70e2fa714e6f3af7ec9120a84 [file] [log] [blame]
Adam Lesinskia1ad4a82015-06-08 11:41:09 -07001/*
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
Adam Lesinskia1ad4a82015-06-08 11:41:09 -070020#include <map>
21#include <ostream>
22#include <set>
23#include <string>
24
Adam Lesinskice5e56e2016-10-21 17:56:45 -070025#include "Resource.h"
26#include "Source.h"
27#include "xml/XmlDom.h"
28
Adam Lesinskia1ad4a82015-06-08 11:41:09 -070029namespace aapt {
30namespace proguard {
31
32class KeepSet {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070033 public:
Adam Lesinskice5e56e2016-10-21 17:56:45 -070034 inline void AddClass(const Source& source, const std::string& class_name) {
35 keep_set_[class_name].insert(source);
Adam Lesinskicacb28f2016-10-19 12:18:14 -070036 }
Adam Lesinskia1ad4a82015-06-08 11:41:09 -070037
Adam Lesinskice5e56e2016-10-21 17:56:45 -070038 inline void AddMethod(const Source& source, const std::string& method_name) {
39 keep_method_set_[method_name].insert(source);
Adam Lesinskicacb28f2016-10-19 12:18:14 -070040 }
Adam Lesinskia1ad4a82015-06-08 11:41:09 -070041
Adam Lesinskicacb28f2016-10-19 12:18:14 -070042 private:
Adam Lesinskice5e56e2016-10-21 17:56:45 -070043 friend bool WriteKeepSet(std::ostream* out, const KeepSet& keep_set);
Adam Lesinskia1ad4a82015-06-08 11:41:09 -070044
Adam Lesinskice5e56e2016-10-21 17:56:45 -070045 std::map<std::string, std::set<Source>> keep_set_;
46 std::map<std::string, std::set<Source>> keep_method_set_;
Adam Lesinskia1ad4a82015-06-08 11:41:09 -070047};
48
Adam Lesinskice5e56e2016-10-21 17:56:45 -070049bool CollectProguardRulesForManifest(const Source& source,
50 xml::XmlResource* res, KeepSet* keep_set,
51 bool main_dex_only = false);
52bool CollectProguardRules(const Source& source, xml::XmlResource* res,
53 KeepSet* keep_set);
Adam Lesinskia1ad4a82015-06-08 11:41:09 -070054
Adam Lesinskice5e56e2016-10-21 17:56:45 -070055bool WriteKeepSet(std::ostream* out, const KeepSet& keep_set);
Adam Lesinskia1ad4a82015-06-08 11:41:09 -070056
Adam Lesinskicacb28f2016-10-19 12:18:14 -070057} // namespace proguard
58} // namespace aapt
Adam Lesinskia1ad4a82015-06-08 11:41:09 -070059
Adam Lesinskicacb28f2016-10-19 12:18:14 -070060#endif // AAPT_PROGUARD_RULES_H