!5 代码规范整改

Merge pull request !5 from 陈程/master
This commit is contained in:
openharmony_sig_ci
2022-03-01 09:18:24 +00:00
committed by Gitee
23 changed files with 160 additions and 113 deletions
+80
View File
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
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.
This is the configuration file template for OpenHarmony OSS Audit Tool, please copy it to your project root dir and modify it refer to OpenHarmony/tools_oat/README.
All configurations in this file will be merged to OAT-Default.xml, if you have any questions or concerns, please create issue in OpenHarmony/tools_oat and @jalenchen or chenyaxun.
licensefile:
1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule.
policylist:
1. policy: If the OAT-Default.xml policies do not meet your requirements, please add policies here.
2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is:
<policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/>
3. policyitem type:
"compatibility" is used to check license compatibility in the specified path;
"license" is used to check source license header in the specified path;
"copyright" is used to check source copyright header in the specified path;
"import" is used to check source dependency in the specified path, such as import ... ,include ...
"filetype" is used to check file type in the specified path, supported file types: archive, binary
"filename" is used to check whether the specified file exists in the specified path(projectroot means the root dir of the project), supported file names: LICENSE, README, README.OpenSource
4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license.
5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem.
6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed.
7. policyitem filefilter: Used to bind filefilter which define filter rules.
7. policyitem desc: Used to describe the reason of this policy item, committers will check this while merging the code.
8. filefilter: Filter rules, the type filename is used to filter file name, the type filepath is used to filter file path.
Note:If the text contains special characters, please escape them according to the following rules:
" == &quot;
& == &amp;
' == &apos;
< == &lt;
> == &gt;
-->
<configuration>
<oatconfig>
<licensefile></licensefile>
<policylist>
<policy name="projectPolicy" desc="">
</policy>
</policylist>
<filefilterlist>
<filefilter name="defaultFilter" desc="Files not to check">
<filteritem type="filename" name="*.iml|*.json|*.txt" desc="desc files"/>
<filteritem type="filepath" name="target/.*" desc="Compile output files"/>
<filteritem type="filepath" name="out/.*" desc="Compile output files"/>
<filteritem type="filepath" name="log/.*" desc="log files"/>
<filteritem type="filepath" name=".idea/.*" desc="IDE temp files"/>
<filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/>
<filteritem type="filepath" name="src/test/.*" desc="Test files"/>
</filefilter>
<filefilter name="defaultPolicyFilter" desc="Filters for compatibilitylicense header policies">
</filefilter>
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
</filefilter>
<filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies">
</filefilter>
<filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies">
</filefilter>
<filefilter name="readmeOpenSourcefileNamePolicyFilter" desc="Filters for README.OpenSource file policies">
</filefilter>
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
</filefilter>
</filefilterlist>
</oatconfig>
</configuration>
+3 -20
View File
@@ -7,9 +7,9 @@ OpenHarmony resource compile tool
>developtools/
>>----global_resource_tool
>>>----include
>>>----src
>>>----third_party denpence third patry lib make script
>>>----CMakeLists.txt
>>>----src
>>>----third_party denpence third patry lib make script
>>>----CMakeLists.txt
>>>----win32.cmake windows cross compile script
#### Installation
@@ -26,20 +26,3 @@ OpenHarmony resource compile tool
1. restool -v show version.
2. restool show help.
#### Contribution
1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request
#### Gitee Feature
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
+3 -20
View File
@@ -7,9 +7,9 @@ OpenHarmony 资源编译编译工具
>developtools/
>>----global_resource_tool
>>>----include
>>>----src
>>>----third_party 依赖三方库编译脚本
>>>----CMakeLists.txt
>>>----src
>>>----third_party 依赖三方库编译脚本
>>>----CMakeLists.txt
>>>----win32.cmake windows交叉编译脚本
@@ -27,20 +27,3 @@ OpenHarmony 资源编译编译工具
1. restool -v 显示版本信息
2. restool 显示帮助信息
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
#### 特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
+4 -2
View File
@@ -28,8 +28,10 @@ public:
private:
typedef bool (*parse_key_founction)(const std::string &folderName, std::vector<KeyParam> &keyparams);
static bool ParseMatch(const std::vector<std::string> &keys, std::vector<KeyParam> &keyparams, const std::vector<parse_key_founction> &founctions);
static bool ParseMatchBySeq(const std::vector<std::string> &keys, std::vector<KeyParam> &keyparams, const std::vector<parse_key_founction> &founctions);
static bool ParseMatch(const std::vector<std::string> &keys,
std::vector<KeyParam> &keyparams, const std::vector<parse_key_founction> &founctions);
static bool ParseMatchBySeq(const std::vector<std::string> &keys,
std::vector<KeyParam> &keyparams, const std::vector<parse_key_founction> &founctions);
static bool ParseMccMnc(const std::string &folderName, std::vector<KeyParam> &keyparams);
static bool ParseMcc(const std::string &folderName, std::vector<KeyParam> &keyparams);
-1
View File
@@ -24,7 +24,6 @@
namespace OHOS {
namespace Global {
namespace Restool {
class ResourceUtil {
public:
/**
-1
View File
@@ -21,7 +21,6 @@
namespace OHOS {
namespace Global {
namespace Restool {
class TaskHandle {
public:
TaskHandle() {};
+1 -1
View File
@@ -302,7 +302,7 @@ uint32_t PackageParser::ParseCommand(int argc, char *argv[])
restoolPath_ = string(argv[0]);
while (true) {
int optIndex = 0;
int c = getopt_long(argc, argv, CMD_PARAMS.c_str(), CMD_OPTS,&optIndex);
int c = getopt_long(argc, argv, CMD_PARAMS.c_str(), CMD_OPTS, &optIndex);
if (c == -1) {
break;
}
+2 -2
View File
@@ -45,12 +45,12 @@ const map<string, string> ConfigParser::JSON_ARRAY_IDS = {
bool ConfigParser::useModule_ = false;
ConfigParser::ConfigParser()
: filePath_("") ,packageName_("") ,moduleName_(""), moduleType_(ModuleType::NONE)
: filePath_(""), packageName_(""), moduleName_(""), moduleType_(ModuleType::NONE)
{
}
ConfigParser::ConfigParser(const string &filePath)
: filePath_(filePath) ,packageName_("") ,moduleName_(""), moduleType_(ModuleType::NONE)
: filePath_(filePath), packageName_(""), moduleName_(""), moduleType_(ModuleType::NONE)
{
}
+1 -1
View File
@@ -52,7 +52,7 @@ uint32_t FileManager::ScanIncrement(const string &output)
return ParseReference(output, sxmlFolders);
}
//below private founction
// below private founction
uint32_t FileManager::ScanModule(const string &input, const string &output,
map<ResType, vector<DirectoryInfo>> &resTypeOfDirs)
{
+1 -1
View File
@@ -16,8 +16,8 @@
#include "generic_compiler.h"
#include<filesystem>
#include<iostream>
#include "restool_errors.h"
#include "resource_util.h"
#include "restool_errors.h"
namespace OHOS {
namespace Global {
+1 -1
View File
@@ -16,8 +16,8 @@
#include "header.h"
#include<algorithm>
#include<fstream>
#include<iostream>
#include<iomanip>
#include<iostream>
namespace OHOS {
namespace Global {
+5 -5
View File
@@ -173,11 +173,11 @@ uint32_t IdWorker::InitIdDefined()
string idDefinedPath;
if (type_ == ResourceIdCluster::RES_ID_SYS) {
for (const auto &inputPath : packageParser.GetInputs()) {
idDefinedPath = filesystem::path(inputPath).append(RESOURCES_DIR)
.append("base").append("element").append(ID_DEFINED_FILE).string();
if (InitIdDefined(idDefinedPath) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
idDefinedPath = filesystem::path(inputPath).append(RESOURCES_DIR)
.append("base").append("element").append(ID_DEFINED_FILE).string();
if (InitIdDefined(idDefinedPath) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
}
return RESTOOL_SUCCESS;
}
+7 -7
View File
@@ -76,7 +76,7 @@ uint32_t JsonCompiler::CompileSingleFile(const FileInfo &fileInfo)
return RESTOOL_SUCCESS;
}
//below private
// below private
void JsonCompiler::InitParser()
{
using namespace placeholders;
@@ -169,12 +169,12 @@ bool JsonCompiler::HandleBoolean(const Json::Value &objectNode, ResourceItem &re
{
Json::Value valueNode = objectNode[TAG_VALUE];
if (valueNode.isString()) {
regex ref("^\\$boolean:.*");
if (!regex_match(valueNode.asString(), ref)) {
cerr << "Error: '" << valueNode.asString() << "' only refer '$boolean:xxx',";
cerr << resourceItem.GetFilePath() << endl;
return false;
}
regex ref("^\\$boolean:.*");
if (!regex_match(valueNode.asString(), ref)) {
cerr << "Error: '" << valueNode.asString() << "' only refer '$boolean:xxx',";
cerr << resourceItem.GetFilePath() << endl;
return false;
}
} else if (!valueNode.isBool()) {
cerr << "Error: '" << resourceItem.GetName() << "' value not boolean," << resourceItem.GetFilePath() << endl;
return false;
+4 -2
View File
@@ -51,7 +51,8 @@ bool KeyParser::Parse(const string &folderName, vector<KeyParam> &keyparams)
return true;
}
bool KeyParser::ParseMatch(const vector<string> &keys, vector<KeyParam> &keyparams, const vector<parse_key_founction> &founctions)
bool KeyParser::ParseMatch(const vector<string> &keys,
vector<KeyParam> &keyparams, const vector<parse_key_founction> &founctions)
{
size_t next = 0;
for (const auto &key : keys) {
@@ -71,7 +72,8 @@ bool KeyParser::ParseMatch(const vector<string> &keys, vector<KeyParam> &keypara
return true;
}
bool KeyParser::ParseMatchBySeq(const vector<string> &keys, vector<KeyParam> &keyparams, const vector<parse_key_founction> &founctions)
bool KeyParser::ParseMatchBySeq(const vector<string> &keys,
vector<KeyParam> &keyparams, const vector<parse_key_founction> &founctions)
{
for (size_t i = 0; i < keys.size(); i++) {
if (!founctions[i](keys[i], keyparams)) {
+32 -32
View File
@@ -24,35 +24,35 @@ namespace Global {
namespace Restool {
using namespace std;
const map<string, ResType> ReferenceParser::ID_REFS = {
{ "^\\$id:", ResType::ID },
{ "^\\$boolean:", ResType::BOOLEAN },
{ "^\\$color:", ResType::COLOR },
{ "^\\$float:", ResType::FLOAT },
{ "^\\$media:", ResType::MEDIA },
{ "^\\$profile:", ResType::PROF },
{ "^\\$integer:", ResType::INTEGER },
{ "^\\$string:", ResType::STRING },
{ "^\\$layout:", ResType::LAYOUT },
{ "^\\$pattern:", ResType::PATTERN },
{ "^\\$plural:", ResType::PLURAL },
{ "^\\$graphic:", ResType::GRAPHIC },
{ "^\\$theme:", ResType::THEME }
{ "^\\$id:", ResType::ID },
{ "^\\$boolean:", ResType::BOOLEAN },
{ "^\\$color:", ResType::COLOR },
{ "^\\$float:", ResType::FLOAT },
{ "^\\$media:", ResType::MEDIA },
{ "^\\$profile:", ResType::PROF },
{ "^\\$integer:", ResType::INTEGER },
{ "^\\$string:", ResType::STRING },
{ "^\\$layout:", ResType::LAYOUT },
{ "^\\$pattern:", ResType::PATTERN },
{ "^\\$plural:", ResType::PLURAL },
{ "^\\$graphic:", ResType::GRAPHIC },
{ "^\\$theme:", ResType::THEME }
};
const map<string, ResType> ReferenceParser::ID_OHOS_REFS = {
{ "^\\$ohos:id:", ResType::ID },
{ "^\\$ohos:boolean:", ResType::BOOLEAN },
{ "^\\$ohos:color:", ResType::COLOR },
{ "^\\$ohos:float:", ResType::FLOAT },
{ "^\\$ohos:media:", ResType::MEDIA },
{ "^\\$ohos:profile:", ResType::PROF },
{ "^\\$ohos:integer:", ResType::INTEGER },
{ "^\\$ohos:string:", ResType::STRING },
{ "^\\$ohos:layout:", ResType::LAYOUT },
{ "^\\$ohos:pattern:", ResType::PATTERN },
{ "^\\$ohos:plural:", ResType::PLURAL },
{ "^\\$ohos:graphic:", ResType::GRAPHIC },
{ "^\\$ohos:theme:", ResType::THEME }
{ "^\\$ohos:id:", ResType::ID },
{ "^\\$ohos:boolean:", ResType::BOOLEAN },
{ "^\\$ohos:color:", ResType::COLOR },
{ "^\\$ohos:float:", ResType::FLOAT },
{ "^\\$ohos:media:", ResType::MEDIA },
{ "^\\$ohos:profile:", ResType::PROF },
{ "^\\$ohos:integer:", ResType::INTEGER },
{ "^\\$ohos:string:", ResType::STRING },
{ "^\\$ohos:layout:", ResType::LAYOUT },
{ "^\\$ohos:pattern:", ResType::PATTERN },
{ "^\\$ohos:plural:", ResType::PLURAL },
{ "^\\$ohos:graphic:", ResType::GRAPHIC },
{ "^\\$ohos:theme:", ResType::THEME }
};
ReferenceParser::ReferenceParser() : idWorker_(IdWorker::GetInstance())
@@ -75,7 +75,7 @@ uint32_t ReferenceParser::ParseRefInSolidXml(const vector<string> &solidXmlFolde
XmlKeyNode xmlKeyNode;
if (!xmlKeyNode.LoadFromFile(filePath, [this](auto &key) -> bool {
return ParseRefString(key);
})) {
})) {
return RESTOOL_ERROR;
}
@@ -103,10 +103,10 @@ uint32_t ReferenceParser::ParseRefInElement(map<int32_t, vector<ResourceItem>> &
uint32_t ReferenceParser::ParseRefInString(string &value, bool &update) const
{
if (ParseRefString(value, update)) {
return RESTOOL_SUCCESS;
}
return RESTOOL_ERROR;
if (ParseRefString(value, update)) {
return RESTOOL_SUCCESS;
}
return RESTOOL_ERROR;
}
uint32_t ReferenceParser::ParseRefInProfile(const string &output) const
@@ -156,7 +156,7 @@ bool ReferenceParser::ParseRefResourceItem(ResourceItem &resourceItem) const
string data;
bool update = false;
if (IsStringOfResourceItem(resType)) {
data= string(reinterpret_cast<const char *>(resourceItem.GetData()), resourceItem.GetDataLength());
data = string(reinterpret_cast<const char *>(resourceItem.GetData()), resourceItem.GetDataLength());
if (!ParseRefString(data, update)) {
cerr << "Error: in " << resourceItem.GetFilePath() << endl;
return false;
+2 -2
View File
@@ -31,7 +31,7 @@ ResourceItem::ResourceItem(const ResourceItem &other)
}
ResourceItem::ResourceItem(const string &name, const vector<KeyParam> &keyparams, ResType type)
:data_(nullptr), dataLen_(0), name_(name),keyparams_(keyparams), type_(type)
: data_(nullptr), dataLen_(0), name_(name), keyparams_(keyparams), type_(type)
{
}
@@ -118,7 +118,7 @@ ResourceItem &ResourceItem::operator=(const ResourceItem &other)
return *this;
}
//below private founction
// below private founction
void ResourceItem::ReleaseData()
{
if (data_ != nullptr) {
+4 -6
View File
@@ -71,7 +71,7 @@ uint32_t ResourcePack::Package()
return RESTOOL_SUCCESS;
}
//below private founction
// below private founction
uint32_t ResourcePack::Init()
{
InitHeaderCreater();
@@ -185,7 +185,7 @@ uint32_t ResourcePack::InitConfigJson()
{
string config = packageParser_.GetConfig();
if (config.empty()) {
if( packageParser_.GetInputs().size() > 1) {
if (packageParser_.GetInputs().size() > 1) {
cerr << "Error: more input path, -j config.json empty" << endl;
return RESTOOL_ERROR;
}
@@ -234,8 +234,7 @@ uint32_t ResourcePack::GenerateCplusHeader(const string &headerPath) const
buffer << "#define RESOURCE_TABLE_H\n\n";
buffer << "#include<stdint.h>\n\n";
buffer << "namespace OHOS {\n";
},
[](stringstream &buffer, const IdWorker::ResourceId& resourceId) {
}, [](stringstream &buffer, const IdWorker::ResourceId& resourceId) {
string name = resourceId.type + "_" + resourceId.name;
transform(name.begin(), name.end(), name.begin(), ::toupper);
buffer << "const int32_t " << name << " = ";
@@ -254,8 +253,7 @@ uint32_t ResourcePack::GenerateJsHeader(const std::string &headerPath) const
uint32_t result = JsHeader.Create([](stringstream &buffer) {
buffer << Header::LICENSE_HEADER << "\n";
buffer << "export default {\n";
},
[&itemType](stringstream &buffer, const IdWorker::ResourceId& resourceId) {
}, [&itemType](stringstream &buffer, const IdWorker::ResourceId& resourceId) {
if (itemType != resourceId.type) {
if (!itemType.empty()) {
buffer << "\n" << " " << "},\n";
+1 -1
View File
@@ -15,10 +15,10 @@
#include "resource_table.h"
#include <filesystem>
#include "securec.h"
#include "cmd_parser.h"
#include "file_manager.h"
#include "resource_util.h"
#include "securec.h"
namespace OHOS {
namespace Global {
+3 -3
View File
@@ -34,7 +34,7 @@ const map<string, ResourceUtil::IgnoreType> ResourceUtil::IGNORE_FILE_REGEX = {
{ "desktop\\.ini", IgnoreType::IGNORE_ALL },
{ "picasa\\.ini", IgnoreType::IGNORE_ALL },
{ "\\..+", IgnoreType::IGNORE_ALL },
{ "_.+",IgnoreType::IGNORE_DIR },
{ "_.+", IgnoreType::IGNORE_DIR },
{ "cvs", IgnoreType::IGNORE_ALL },
{ "thumbs\\.db", IgnoreType::IGNORE_ALL },
{ ".+~", IgnoreType::IGNORE_ALL }
@@ -88,7 +88,7 @@ bool ResourceUtil::OpenJsonFile(const string &path, Json::Value &root)
readBuilder["collectComments"] = false;
readBuilder["failIfExtra"] = true;
JSONCPP_STRING errs;
if(!parseFromStream(readBuilder, ifs, &root, &errs)) {
if (!parseFromStream(readBuilder, ifs, &root, &errs)) {
cerr << "Error: parseFromStream '" << path;
cerr << "\n" << errs << endl;
ifs.close();
@@ -144,7 +144,7 @@ string ResourceUtil::ResTypeToString(ResType type)
string ResourceUtil::GetIdName(const string &name, ResType type)
{
if (type != ResType::MEDIA && type != ResType::LAYOUT && type != ResType::PROF &&
type != ResType::ANIMATION && type != ResType::GRAPHIC ) {
type != ResType::ANIMATION && type != ResType::GRAPHIC) {
return name;
}
+2 -1
View File
@@ -19,7 +19,8 @@
using namespace std;
using namespace OHOS::Global::Restool;
uint32_t ProccssHap(PackageParser &packageParser) {
uint32_t ProccssHap(PackageParser &packageParser)
{
TaskHandle taskHandle;
return taskHandle.HandlePackage(packageParser);
}
+1 -1
View File
@@ -17,8 +17,8 @@
#include<filesystem>
#include<iostream>
#include<regex>
#include "restool_errors.h"
#include "resource_util.h"
#include "restool_errors.h"
namespace OHOS {
namespace Global {
+2 -2
View File
@@ -78,7 +78,7 @@ bool SolidXml::FlushNodeKeys(const string &filePath, map<XmlKeyNode::KeyType, sh
return SaveToFile(filePath);
}
//below private
// below private
void SolidXml::Compile(const xmlNodePtr nodePtr, shared_ptr<XmlNode> &node)
{
if (nodePtr->type == XML_COMMENT_NODE) {
@@ -119,7 +119,7 @@ void SolidXml::CompileAttr(const xmlAttrPtr attrPtr, shared_ptr<XmlNode> &node)
return;
}
xmlChar * xmlValue = xmlNodeListGetString(attrPtr->doc, attrPtr->children, 1);
xmlChar *xmlValue = xmlNodeListGetString(attrPtr->doc, attrPtr->children, 1);
string value(reinterpret_cast<const char *>(xmlValue));
PretreatmentAttr(value);
xmlFree(xmlValue);
+1 -1
View File
@@ -56,7 +56,7 @@ bool XmlKeyNode::SaveToFile(const string &filePath) const
}
vector<pair<string, int32_t>> sets(keyMap_.begin(), keyMap_.end());
sort(sets.begin(), sets.end(),[](const auto &a, const auto &b) {
sort(sets.begin(), sets.end(), [](const auto &a, const auto &b) {
return a.second < b.second;
});