blob: a2c9dbf31fe13cd63c93943b9217ca56b1ed9fe7 [file] [log] [blame]
Adam Lesinski1ab598f2015-08-14 14:26:04 -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_TABLEMERGER_H
18#define AAPT_TABLEMERGER_H
19
20#include "ResourceTable.h"
21#include "ResourceValues.h"
22#include "util/Util.h"
23
24#include "process/IResourceTableConsumer.h"
25
26#include <queue>
27#include <set>
28
29namespace aapt {
30
31struct FileToMerge {
32 ResourceTable* srcTable;
33 std::u16string srcPath;
34 std::u16string dstPath;
35};
36
37/**
38 * TableMerger takes resource tables and merges all packages within the tables that have the same
39 * package ID.
40 *
41 * If a package has a different name, all the entries in that table have their names mangled
42 * to include the package name. This way there are no collisions. In order to do this correctly,
43 * the TableMerger needs to also mangle any FileReference paths. Once these are mangled,
44 * the original source path of the file, along with the new destination path is recorded in the
45 * queue returned from getFileMergeQueue().
46 *
47 * Once the merging is complete, a separate process can go collect the files from the various
48 * source APKs and either copy or process their XML and put them in the correct location in
49 * the final APK.
50 */
51class TableMerger {
52public:
53 TableMerger(IAaptContext* context, ResourceTable* outTable);
54
55 inline std::queue<FileToMerge>* getFileMergeQueue() {
56 return &mFilesToMerge;
57 }
58
59 inline const std::set<std::u16string>& getMergedPackages() const {
60 return mMergedPackages;
61 }
62
Adam Lesinski83f22552015-11-07 11:51:23 -080063 /**
64 * Merges resources from the same or empty package. This is for local sources.
65 */
Adam Lesinskifb48d292015-11-07 15:52:13 -080066 bool merge(const Source& src, ResourceTable* table, bool overrideExisting);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070067
Adam Lesinski83f22552015-11-07 11:51:23 -080068 /**
69 * Merges resources from the given package, mangling the name. This is for static libraries.
70 */
71 bool mergeAndMangle(const Source& src, const StringPiece16& package, ResourceTable* table);
72
Adam Lesinski1ab598f2015-08-14 14:26:04 -070073private:
74 IAaptContext* mContext;
75 ResourceTable* mMasterTable;
76 ResourceTablePackage* mMasterPackage;
77
78 std::set<std::u16string> mMergedPackages;
79 std::queue<FileToMerge> mFilesToMerge;
80
81 bool doMerge(const Source& src, ResourceTable* srcTable, ResourceTablePackage* srcPackage,
Adam Lesinskifb48d292015-11-07 15:52:13 -080082 const bool manglePackage, const bool overrideExisting);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070083
84 std::unique_ptr<Value> cloneAndMangle(ResourceTable* table, const std::u16string& package,
85 Value* value);
86 std::unique_ptr<Value> clone(Value* value);
87};
88
89} // namespace aapt
90
91#endif /* AAPT_TABLEMERGER_H */