AAPT2: Read config from disk

Implement the todo left from last change to read the contents of the
configuration file from disk. Since this is an operation that may fail
the API was changed to take return a Maybe to indicate errors reading
the file.

Test: unit test for error condition
Test: ran aapt2 optimize with the new code path wired in

Change-Id: I93d532b4a57af9520231225eee4fc5f2b1a046b9
diff --git a/tools/aapt2/configuration/ConfigurationParser.cpp b/tools/aapt2/configuration/ConfigurationParser.cpp
index 89618d3..303a809 100644
--- a/tools/aapt2/configuration/ConfigurationParser.cpp
+++ b/tools/aapt2/configuration/ConfigurationParser.cpp
@@ -21,10 +21,13 @@
 #include <memory>
 #include <utility>
 
+#include <android-base/file.h>
 #include <android-base/logging.h>
 
 #include "ConfigDescription.h"
 #include "Diagnostics.h"
+#include "io/File.h"
+#include "io/FileSystem.h"
 #include "util/Util.h"
 #include "xml/XmlActionExecutor.h"
 #include "xml/XmlDom.h"
@@ -42,6 +45,8 @@
 using ::aapt::configuration::GlTexture;
 using ::aapt::configuration::Group;
 using ::aapt::configuration::Locale;
+using ::aapt::io::IFile;
+using ::aapt::io::RegularFile;
 using ::aapt::util::TrimWhitespace;
 using ::aapt::xml::Element;
 using ::aapt::xml::FindRootElement;
@@ -49,6 +54,7 @@
 using ::aapt::xml::XmlActionExecutor;
 using ::aapt::xml::XmlActionExecutorPolicy;
 using ::aapt::xml::XmlNodeAction;
+using ::android::base::ReadFileToString;
 
 const std::unordered_map<std::string, Abi> kAbiMap = {
     {"armeabi", Abi::kArmeV6},
@@ -96,6 +102,17 @@
 
 }  // namespace
 
+
+
+/** Returns a ConfigurationParser for the file located at the provided path. */
+Maybe<ConfigurationParser> ConfigurationParser::ForPath(const std::string& path) {
+  std::string contents;
+  if (!ReadFileToString(path, &contents, true)) {
+    return {};
+  }
+  return ConfigurationParser(contents);
+}
+
 ConfigurationParser::ConfigurationParser(std::string contents)
     : contents_(std::move(contents)),
       diag_(&noop_) {