blob: 0724d6203e8ff8d7152b5eeea2c14992b3a4a193 [file] [log] [blame]
Ryan Mitchell833a1a62018-07-10 13:51:36 -07001/*
2 * Copyright (C) 2018 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 AAPT2_DUMP_H
18#define AAPT2_DUMP_H
19
20#include "Command.h"
21#include "Debug.h"
22
23namespace aapt {
24
Ryan Mitchell5d275512018-07-19 14:29:00 -070025/** Command the contents of files generated from the compilation stage. */
26class DumpAPCCommand : public Command {
Ryan Mitchell833a1a62018-07-10 13:51:36 -070027 public:
Ryan Mitchell5d275512018-07-19 14:29:00 -070028 explicit DumpAPCCommand(IDiagnostics* diag) : Command("apc"), diag_(diag) {
29 SetDescription("Print the contents of the AAPT2 Container (APC) generated fom compilation.");
Ryan Mitchell833a1a62018-07-10 13:51:36 -070030 AddOptionalSwitch("--no-values", "Suppresses output of values when displaying resource tables.",
Ryan Mitchell5d275512018-07-19 14:29:00 -070031 &no_values_);
32 AddOptionalSwitch("-v", "Enables verbose logging.", &verbose_);
Ryan Mitchell833a1a62018-07-10 13:51:36 -070033 }
34
35 int Action(const std::vector<std::string>& args) override;
36
37 private:
Ryan Mitchell5d275512018-07-19 14:29:00 -070038 IDiagnostics* diag_;
Ryan Mitchell833a1a62018-07-10 13:51:36 -070039 bool verbose_ = false;
40 bool no_values_ = false;
41};
42
Ryan Mitchell5d275512018-07-19 14:29:00 -070043/** Prints every configuration used by a resource in an APK. */
44class DumpConfigsCommand : public Command {
45 public:
46 explicit DumpConfigsCommand(IDiagnostics* diag) : Command("configurations"), diag_(diag) {
47 SetDescription("Print every configuration used by a resource in the APK.");
48 }
49
50 int Action(const std::vector<std::string>& args) override;
51
52 private:
53 IDiagnostics* diag_;
54};
55
56/** Prints the contents of the resource table string pool in the APK. */
57class DumpStringsCommand : public Command {
58 public:
59 explicit DumpStringsCommand(IDiagnostics* diag) : Command("strings"), diag_(diag) {
60 SetDescription("Print the contents of the resource table string pool in the APK.");
61 }
62
63 int Action(const std::vector<std::string>& args) override;
64
65 private:
66 IDiagnostics* diag_;
67};
68
69/** Prints the contents of the resource table from the APK. */
70class DumpTableCommand : public Command {
71 public:
72 explicit DumpTableCommand(IDiagnostics* diag) : Command("resources"), diag_(diag) {
73 SetDescription("Print the contents of the resource table from the APK.");
74 AddOptionalSwitch("--no-values", "Suppresses output of values when displaying resource tables.",
75 &no_values_);
76 AddOptionalSwitch("-v", "Enables verbose logging.", &verbose_);
77 }
78
79 int Action(const std::vector<std::string>& args) override;
80
81 private:
82 IDiagnostics* diag_;
83 bool verbose_ = false;
84 bool no_values_ = false;
85};
86
87/** Prints the string pool of a compiled xml in an APK. */
88class DumpXmlStringsCommand : public Command {
89public:
90 explicit DumpXmlStringsCommand(IDiagnostics* diag) : Command("xmlstrings"), diag_(diag) {
91 SetDescription("Print the string pool of a compiled xml in an APK.");
92 AddRequiredFlagList("--file", "A compiled xml file to print", &files_);
93 }
94
95 int Action(const std::vector<std::string>& args) override;
96
97private:
98 IDiagnostics* diag_;
99 std::vector<std::string> files_;
100};
101
102
103/** Prints the tree of a compiled xml in an APK. */
104class DumpXmlTreeCommand : public Command {
105 public:
106 explicit DumpXmlTreeCommand(IDiagnostics* diag) : Command("xmltree"), diag_(diag) {
107 SetDescription("Print the tree of a compiled xml in an APK.");
108 AddRequiredFlagList("--file", "A compiled xml file to print", &files_);
109 }
110
111 int Action(const std::vector<std::string>& args) override;
112
113 private:
114 IDiagnostics* diag_;
115 std::vector<std::string> files_;
116};
117
Todd Kennedy908b7fc2018-08-24 10:11:21 -0700118/** Prints the contents of the resource table from the APK. */
119class DumpPackageNameCommand : public Command {
120 public:
121 explicit DumpPackageNameCommand(IDiagnostics* diag) : Command("packagename"), diag_(diag) {
122 SetDescription("Print the package name of the APK.");
123 }
124
125 int Action(const std::vector<std::string>& args) override;
126
127 private:
128 IDiagnostics* diag_;
129};
130
131/** The default dump command. Performs no action because a subcommand is required. */
Ryan Mitchell5d275512018-07-19 14:29:00 -0700132class DumpCommand : public Command {
133 public:
134 explicit DumpCommand(IDiagnostics* diag) : Command("dump", "d"), diag_(diag) {
135 AddOptionalSubcommand(util::make_unique<DumpAPCCommand>(diag_));
136 AddOptionalSubcommand(util::make_unique<DumpConfigsCommand>(diag_));
Todd Kennedy908b7fc2018-08-24 10:11:21 -0700137 AddOptionalSubcommand(util::make_unique<DumpPackageNameCommand>(diag_));
Ryan Mitchell5d275512018-07-19 14:29:00 -0700138 AddOptionalSubcommand(util::make_unique<DumpStringsCommand>(diag_));
139 AddOptionalSubcommand(util::make_unique<DumpTableCommand>(diag_));
140 AddOptionalSubcommand(util::make_unique<DumpXmlStringsCommand>(diag_));
141 AddOptionalSubcommand(util::make_unique<DumpXmlTreeCommand>(diag_));
142 }
143
144 int Action(const std::vector<std::string>& args) override;
145
146 private:
147 IDiagnostics* diag_;
148};
149
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700150}// namespace aapt
151
152#endif //AAPT2_DUMP_H