• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef STAGE_CONTEXT_H
17 #define STAGE_CONTEXT_H
18 
19 #include <string>
20 #include <vector>
21 #include <optional>
22 #include <map>
23 
24 namespace Json2 {
25     class Value;
26 }
27 
28 namespace OHOS::Ide {
29 class StageContext {
30 public:
31     static StageContext& GetInstance();
32     const std::optional<std::vector<uint8_t>> ReadFileContents(const std::string& filePath) const;
33     // for Previewer
34     void SetLoaderJsonPath(const std::string& assetPath);
35     void SetHosSdkPath(const std::string& hosSdkPathValue);
36     void GetModulePathMapFromLoaderJson();
37     std::string GetHspAceModuleBuild(const std::string& hspConfigPath);
38     void ReleaseHspBuffers();
39     std::map<std::string, std::string> ParseMockJsonFile(const std::string& mockJsonFilePath);
40     // for ArkUI and Ability
41     std::vector<uint8_t>* GetModuleBuffer(const std::string& inputPath);
42     std::vector<uint8_t>* GetLocalModuleBuffer(const std::string& moduleName);
43     std::vector<uint8_t>* GetCloudModuleBuffer(const std::string& moduleName);
44     std::vector<uint8_t>* GetSystemModuleBuffer(const std::string& inputPath, const std::string& moduleName);
45     std::vector<uint8_t>* GetModuleBufferFromHsp(const std::string& hspFilePath, const std::string& fileName);
46     void SetPkgContextInfo(std::map<std::string, std::string>& pkgContextInfoJsonStringMap,
47         std::map<std::string, std::string>& packageNameList);
48 private:
49     StageContext() = default;
50     ~StageContext() = default;
51     bool ContainsRelativePath(const std::string& path) const;
52     std::map<std::string, std::string> GetModulePathMap() const;
53     std::string GetCloudHspPath(const std::string& hspDir, const std::string& moduleName);
54     std::string ReplaceLastStr(const std::string& str, const std::string& find, const std::string& replace);
55     int GetHspActualName(const std::string& input, std::string& ret);
56     std::string GetActualCloudHspDir(const std::string& actualName);
57     std::string GetCloudModuleHspPath(const std::string& actualName);
58     std::string GetCloudProjectHspPath(const std::string& actualName);
59     std::string GetCloudHspVersion(const std::string& hspPath, const std::string& actualName);
60     std::vector<int> SplitHspVersion(const std::string& version);
61     int CompareHspVersion(const std::string& version1, const std::string& version2);
62     std::string loaderJsonPath;
63     std::map<std::string, std::string> modulePathMap;
64     std::map<std::string, std::string> hspNameOhmMap;
65     std::string projectRootPath;
66     std::string buildConfigPath;
67     std::vector<std::vector<uint8_t>*> hspBufferPtrsVec;
68     int GetUpwardDirIndex(const std::string& path, const int upwardLevel) const;
69     std::string localBundleName = "bundle";
70     std::string hosSdkPath = "";
71 };
72 }
73 #endif // STAGE_CONTEXT_H