AAPT2: Fix overlay support

Supports the <add-resource> tag and mimics old AAPT behavior of
not allowing new resources defined unless <add-resource> was used
or --auto-add-overlay was specified.

Change-Id: I9b461137357617ade37fd7045b418b8e6450b9c4
diff --git a/tools/aapt2/io/FileSystem.cpp b/tools/aapt2/io/FileSystem.cpp
new file mode 100644
index 0000000..76f87ae
--- /dev/null
+++ b/tools/aapt2/io/FileSystem.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Source.h"
+#include "io/FileSystem.h"
+#include "util/Files.h"
+#include "util/Maybe.h"
+#include "util/StringPiece.h"
+#include "util/Util.h"
+
+#include <utils/FileMap.h>
+
+namespace aapt {
+namespace io {
+
+RegularFile::RegularFile(const Source& source) : mSource(source) {
+}
+
+std::unique_ptr<IData> RegularFile::openAsData() {
+    android::FileMap map;
+    if (Maybe<android::FileMap> map = file::mmapPath(mSource.path, nullptr)) {
+        return util::make_unique<MmappedData>(std::move(map.value()));
+    }
+    return {};
+}
+
+const Source& RegularFile::getSource() const {
+    return mSource;
+}
+
+FileCollectionIterator::FileCollectionIterator(FileCollection* collection) :
+        mCurrent(collection->mFiles.begin()), mEnd(collection->mFiles.end()) {
+}
+
+bool FileCollectionIterator::hasNext() {
+    return mCurrent != mEnd;
+}
+
+IFile* FileCollectionIterator::next() {
+    IFile* result = mCurrent->second.get();
+    ++mCurrent;
+    return result;
+}
+
+IFile* FileCollection::insertFile(const StringPiece& path) {
+    return (mFiles[path.toString()] = util::make_unique<RegularFile>(Source(path))).get();
+}
+
+IFile* FileCollection::findFile(const StringPiece& path) {
+    auto iter = mFiles.find(path.toString());
+    if (iter != mFiles.end()) {
+        return iter->second.get();
+    }
+    return nullptr;
+}
+
+std::unique_ptr<IFileCollectionIterator> FileCollection::iterator() {
+    return util::make_unique<FileCollectionIterator>(this);
+}
+
+} // namespace io
+} // namespace aapt