[Refactoring] The main() method contains too many lines of code (#534)
author최종헌/MDE Lab(SR)/삼성전자 <j-h.choi@samsung.com>
Wed, 29 May 2024 07:44:28 +0000 (16:44 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 29 May 2024 07:44:28 +0000 (16:44 +0900)
Change-Id: Ie516bd6f22177c78eb99075d9082b209e3a82503

NativeLauncher/tool/dotnettool.cc

index d4fcf1a348f1505c998c755b2ecffc2f0e5fbdd4..75111a4d8791f8f99d384579198739e780113e59 100644 (file)
@@ -97,6 +97,227 @@ void DisplayUsage() {
                "   # dotnettool --rm-app-profile org.tizen.FormsGallery\n"
                "\n");
 }
+static std::vector<std::string> args;
+static std::vector<std::string>::iterator it;
+
+//sh-3.2# dotnettool --ni-system [AssemblyDirectory] [AssemblyDirectory] ...
+static void dotnettool_ni_system(NIOption* opt)
+{
+       std::string inputs;
+       while (it != args.end()) {
+               std::string dir = std::string(*it);
+               inputs = inputs + ":" + dir;
+               it = args.erase(it);
+       }
+       if (createNIPlatform(inputs, opt) != NI_ERROR_NONE) {
+               _SERR("Failed to generate system NI");
+       }
+}
+
+//sh-3.2# dotnettool --ni-dll [assemblyPath] [assemblyPath] ...
+static void dotnettool_ni_dll(NIOption* opt)
+{
+       if (args.size() < 1) {
+               _SERR("DLL path is missing");
+       }
+       std::vector<std::string> inputs;
+       while (it != args.end()) {
+               std::string dll = std::string(*it);
+               inputs.push_back(dll);
+               opt->refFiles.push_back(dll);
+               if (opt->flags & NI_FLAGS_INPUT_BUBBLE) {
+                       opt->inputBubbleRefFiles.push_back(dll);
+               }
+               it = args.erase(it);
+       }
+       for (auto &dll : inputs) {
+               int ret = createNIDll(dll, opt);
+               if (ret != NI_ERROR_NONE && ret != NI_ERROR_ALREADY_EXIST) {
+                       _SERR("Failed to generate NI file [%s]", dll.c_str());
+                       break;
+               }
+       }
+}
+
+//sh-3.2# dotnettool --ni-pkg [pkgId] [pkgId] ...
+static void dotnettool_ni_pkg(NIOption* opt)
+{
+       if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
+               _SERR("App AOTC options cannot be used with --rm-origin-after-ni option");
+               DisplayUsage();
+               return;
+       }
+       if (args.size() < 1) {
+               _SERR("Package name is missing");
+       }
+       while (it != args.end()) {
+               std::string pkg = std::string(*it);
+               if (createNIUnderPkgRoot(pkg, opt) != NI_ERROR_NONE) {
+                       _SERR("Failed to generate app NI [%s]", pkg.c_str());
+                       break;
+               }
+               it = args.erase(it);
+       }
+}
+
+//sh-3.2# dotnettool --ni-dir [AssemblyDirectory] [AssemblyDirectory] ...
+static void dotnettool_ni_dir(NIOption* opt)
+{
+       if (args.size() < 1) {
+               _SERR("Directory path is missing");
+       }
+       std::string dir;
+       while (it != args.end()) {
+               if (!dir.empty()) {
+                       dir += std::string(":");
+               }
+               dir += std::string(*it);
+               it = args.erase(it);
+       }
+       if (createNIUnderDirs(dir, opt) != NI_ERROR_NONE) {
+               _SERR("Failed to generate NI directory");
+       }
+}
+
+//sh-3.2# dotnettool --ni-reset-all-app
+static void dotnettool_ni_reset_all_app(NIOption* opt)
+{
+       if (regeneratePkgNI(opt, true) != NI_ERROR_NONE) {
+               _SERR("Failed to reseet all app NI");
+       }
+}
+
+//sh-3.2# dotnettool --ni-reset-pkg [pkgId] [pkgId] ...
+static void dotnettool_ni_reset_pkg(NIOption* opt)
+{
+       if (args.size() < 1) {
+               _SERR("Package name is missing");
+       }
+       while (it != args.end()) {
+               std::string pkg = std::string(*it);
+               if (removeNIUnderPkgRoot(pkg) != NI_ERROR_NONE) {
+                       _SERR("Failed to remove dlls for given package [%s]", pkg.c_str());
+                       break;
+               }
+               it = args.erase(it);
+       }
+}
+
+//sh-3.2# dotnettool --ni-reset-dir [AssemblyDirectory] [AssemblyDirectory] ...
+static void dotnettool_ni_reset_dir(NIOption* opt)
+{
+       if (args.size() < 1) {
+               _SERR("Directory path is missing");
+       }
+       while (it != args.end()) {
+               std::string dir = std::string(*it);
+               removeNIUnderDirs(dir);
+               it = args.erase(it);
+       }
+}
+
+//sh-3.2# dotnettool --ni-regen-all-app
+static void dotnettool_ni_regen_all_app(NIOption* opt)
+{
+       if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
+               _SERR("App AOTC options cannot be used with --rm-origin-after-ni option");
+               DisplayUsage();
+               return;
+       }
+       if (regeneratePkgNI(opt) != NI_ERROR_NONE) {
+               _SERR("Failed to regenerate all app NI");
+       }
+}
+
+//sh-3.2# dotnettool --tac-reset-all
+static void dotnettool_tac_reset_all(NIOption* opt)
+{
+       if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
+               _SERR("App AOTC options cannot be used with --rm-origin-after-ni option");
+               DisplayUsage();
+               return;
+       }
+       if (regenerateTACNI(opt, true) != NI_ERROR_NONE) {
+               _SERR("Failed to remove all TAC NI files");
+       }
+}
+
+//sh-3.2# dotnettool --tac-regen-all
+static void dotnettool_tac_regen_all(NIOption* opt)
+{
+       if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
+               _SERR("App AOTC options cannot be used with --rm-origin-after-ni option");
+               DisplayUsage();
+               return;
+       }
+       if (regenerateTACNI(opt) != NI_ERROR_NONE) {
+               _SERR("Failed to regenerate all TAC");
+       }
+}
+
+//sh-3.2# dotnettool --tac-restore-db
+static void dotnettool_tac_restore_db(NIOption* opt)
+{
+       if (tac_restoreDB(false) != TAC_ERROR_NONE) {
+               _SERR("Failed to restore TAC db of RW");
+       }
+       if (tlc_restoreDB(false) != TAC_ERROR_NONE) {
+               _SERR("Failed to restore TLC db of RW");
+       }
+       if (tac_restoreDB(true) != TAC_ERROR_NONE) {
+               _SERR("Failed to restore TAC db of RO");
+       }
+       if (tlc_restoreDB(true) != TAC_ERROR_NONE) {
+               _SERR("Failed to restore TLC db of RO");
+       }
+}
+
+//sh-3.2# dotnettool --tac-enable-pkg [pkgId] [pkgId] ...
+static void dotnettool_tac_enable_pkg(NIOption* opt)
+{
+       if (args.size() < 1) {
+               _SERR("Package name is missing");
+       }
+       while (it != args.end()) {
+               std::string pkg = std::string(*it);
+               if (enableTACPackage(pkg) != TAC_ERROR_NONE) {
+                       _SERR("Failed to enable tac [%s]", pkg.c_str());
+                       break;
+               }
+               it = args.erase(it);
+       }
+}
+
+//sh-3.2# dotnettool --tac-disable-pkg [pkgId] [pkgId] ...
+static void dotnettool_tac_disable_pkg(NIOption* opt)
+{
+       if (args.size() < 1) {
+               _SERR("Package name is missing");
+       }
+       while (it != args.end()) {
+               std::string pkg = std::string(*it);
+               if (disableTACPackage(pkg) != TAC_ERROR_NONE) {
+                       _SERR("Failed to disable tac [%s]", pkg.c_str());
+                       break;
+               }
+               it = args.erase(it);
+       }
+}
+
+//sh-3.2# dotnettool --rm-app-profile [pkgId] [pkgId] ...
+static void dotnettool_rm_app_profile(NIOption* opt)
+{
+       if (args.size() < 1) {
+               _SERR("Package name is missing");
+       }
+       while (it != args.end()) {
+               std::string pkg = std::string(*it);
+               if (removeAppProfileData(pkg) != PROFILE_ERROR_NONE) {
+                       _SERR("Failed to remove [%s] profile data", pkg.c_str());
+               }
+               it = args.erase(it);
+       }
+}
 
 int main(int argc, char* argv[])
 {
@@ -120,13 +341,12 @@ int main(int argc, char* argv[])
                return -1;
        }
 
-       std::vector<std::string> args;
        for (int i = 0; i < argc; ++i) {
                std::string arg = argv[i];
 
                if ((arg == "-?") || (arg == "-h") || (arg == "--h")) {
                        DisplayUsage();
-                       return 0;
+                       return -1;
                } else if (arg == "--verbose") {
                        opt->flags |= NI_FLAGS_VERBOSE;
                } else if (arg == "--inputbubble") {
@@ -144,7 +364,7 @@ int main(int argc, char* argv[])
                        if (i >= argc) {
                                _SOUT("Priority value(-20 ~ 19) should be followed for --set-priority option");
                                DisplayUsage();
-                               return 0;
+                               return -1;
                        }
 
                        opt->flags |= NI_FLAGS_SET_PRIORITY;
@@ -154,14 +374,14 @@ int main(int argc, char* argv[])
                        } catch (...) {
                                _SERR("Invalid argument: %s", argv[i]);
                                DisplayUsage();
-                               return 0;
+                               return -1;
                        }
                } else if (arg == "--mibc") {
                        ++i;
                        if (i >= argc) {
                                _SOUT("File path containing Mibc files should be followed for --mibc option");
                                DisplayUsage();
-                               return 0;
+                               return -1;
                        }
 
                        opt->flags |= NI_FLAGS_MIBC;
@@ -171,6 +391,7 @@ int main(int argc, char* argv[])
                        for (const auto &path : paths) {
                                if (!isFile(path) || isDirectory(path)) {
                                        _SERR("Mibc file path is missing or does not exist");
+                                       DisplayUsage();
                                        return -1;
                                }
                                opt->mibcPath.push_back(path);
@@ -180,7 +401,7 @@ int main(int argc, char* argv[])
                        if (i >= argc) {
                                _SOUT("Path for references should be followed for --inputbubbleref option");
                                DisplayUsage();
-                               return 0;
+                               return -1;
                        }
 
                        opt->flags |= NI_FLAGS_INPUT_BUBBLE_REF;
@@ -195,7 +416,7 @@ int main(int argc, char* argv[])
                        if (i >= argc) {
                                _SOUT("Path for references should be followed for --ref option");
                                DisplayUsage();
-                               return 0;
+                               return -1;
                        }
 
                        std::vector<std::string> files;
@@ -224,222 +445,61 @@ int main(int argc, char* argv[])
                return -1;
        }
 
-       std::vector<std::string>::iterator it = args.begin();
+       it = args.begin();
        std::string cmd = std::string(*it);
        it = args.erase(it);
 
-       //sh-3.2# dotnettool --ni-system [AssemblyDirectory] [AssemblyDirectory] ...
        if (cmd == "--ni-system") {
-               std::string inputs;
-               while (it != args.end()) {
-                       const std::string dir = std::string(*it);
-                       inputs = inputs + ":" + dir;
-                       it = args.erase(it);
-               }
-               int ret = createNIPlatform(inputs, opt);
-               if (ret != NI_ERROR_NONE) {
-                       _SERR("Failed to generate system NI");
-               }
+               dotnettool_ni_system(opt);
        }
-       //sh-3.2# dotnettool --ni-dll [assemblyPath] [assemblyPath] ...
        else if (cmd == "--ni-dll") {
-               if (args.size() < 1) {
-                       _SERR("DLL path is missing");
-               }
-               std::vector<std::string> inputs;
-               while (it != args.end()) {
-                       std::string dll = std::string(*it);
-                       inputs.push_back(dll);
-                       opt->refFiles.push_back(dll);
-                       if (opt->flags & NI_FLAGS_INPUT_BUBBLE) {
-                               opt->inputBubbleRefFiles.push_back(dll);
-                       }
-                       it = args.erase(it);
-               }
-
-               for (auto &dll : inputs) {
-                       int ret = createNIDll(dll, opt);
-                       if (ret != NI_ERROR_NONE && ret != NI_ERROR_ALREADY_EXIST) {
-                               _SERR("Failed to generate NI file [%s]", dll.c_str());
-                               break;
-                       }
-               }
+               dotnettool_ni_dll(opt);
        }
-       //sh-3.2# dotnettool --ni-pkg [pkgId] [pkgId] ...
        else if (cmd == "--ni-pkg") {
-               if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
-                       _SERR("App AOTC options cannot be used with --rm-origin-after-ni option");
-                       DisplayUsage();
-                       return -1;
-               }
-
-               if (args.size() < 1) {
-                       _SERR("Package name is missing");
-               }
-               while (it != args.end()) {
-                       std::string pkg = std::string(*it);
-                       int ret = createNIUnderPkgRoot(pkg, opt);
-                       if (ret != NI_ERROR_NONE) {
-                               _SERR("Failed to generate app NI [%s]", pkg.c_str());
-                               break;
-                       }
-                       it = args.erase(it);
-               }
+               dotnettool_ni_pkg(opt);
        }
-       //sh-3.2# dotnettool --ni-dir [AssemblyDirectory] [AssemblyDirectory] ...
        else if (cmd == "--ni-dir") {
-               if (args.size() < 1) {
-                       _SERR("Directory path is missing");
-               }
-               std::string dir;
-               while (it != args.end()) {
-                       if (!dir.empty()) {
-                               dir += std::string(":");
-                       }
-                       dir += std::string(*it);
-                       it = args.erase(it);
-               }
-               if (createNIUnderDirs(dir, opt) != NI_ERROR_NONE) {
-                       _SERR("Failed to generate NI directory");
-               }
+               dotnettool_ni_dir(opt);
        }
-       //sh-3.2# dotnettool --ni-reset-system
        else if (cmd == "--ni-reset-system") {
                removeNIPlatform();
        }
-       //sh-3.2# dotnettool --ni-reset-all-app
        else if (cmd == "--ni-reset-all-app") {
-               int ret = regeneratePkgNI(opt, true);
-               if (ret != NI_ERROR_NONE) {
-                       _SERR("Failed to reset all app NI");
-               }
+               dotnettool_ni_reset_all_app(opt);
        }
-       //sh-3.2# dotnettool --ni-reset-pkg [pkgId] [pkgId] ...
        else if (cmd == "--ni-reset-pkg") {
-               if (args.size() < 1) {
-                       _SERR("Package name is missing");
-               }
-               while (it != args.end()) {
-                       std::string pkg = std::string(*it);
-                       int ret = removeNIUnderPkgRoot(pkg);
-                       if (ret != NI_ERROR_NONE) {
-                               _SERR("Failed to remove dlls for given package [%s]", pkg.c_str());
-                               break;
-                       }
-                       it = args.erase(it);
-               }
+               dotnettool_ni_reset_pkg(opt);
        }
-       //sh-3.2# dotnettool --ni-reset-dir [AssemblyDirectory] [AssemblyDirectory] ...
        else if (cmd == "--ni-reset-dir") {
-               if (args.size() < 1) {
-                       _SERR("Directory path is missing");
-               }
-               while (it != args.end()) {
-                       const std::string dir = std::string(*it);
-                       removeNIUnderDirs(dir);
-                       it = args.erase(it);
-               }
+               dotnettool_ni_reset_dir(opt);
        }
-       //sh-3.2# dotnettool --ni-regen-all-app
        else if (cmd == "--ni-regen-all-app") {
-               if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
-                       _SERR("App AOTC options cannot be used with --rm-origin-after-ni option");
-                       DisplayUsage();
-                       return -1;
-               }
-
-               int ret = regeneratePkgNI(opt);
-               if (ret != NI_ERROR_NONE) {
-                       _SERR("Failed to regenerate all app NI");
-               }
+               dotnettool_ni_regen_all_app(opt);
        }
-       //sh-3.2# dotnettool --tac-reset-all
        else if (cmd == "--tac-reset-all") {
-               int ret = regenerateTACNI(opt, true);
-               if (ret != NI_ERROR_NONE) {
-                       _SERR("Failed to remove all TAC NI files");
-               }
+               dotnettool_tac_reset_all(opt);
        }
-       //sh-3.2# dotnettool --tac-regen-all
        else if (cmd == "--tac-regen-all") {
-               if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
-                       _SERR("App AOTC options cannot be used with --rm-origin-after-ni option");
-                       DisplayUsage();
-                       return -1;
-               }
-
-               int ret = regenerateTACNI(opt);
-               if (ret != NI_ERROR_NONE) {
-                       _SERR("Failed to regenerate all TAC");
-               }
+               dotnettool_tac_regen_all(opt);
        }
-       //sh-3.2# dotnettool --tac-restore-db
        else if (cmd == "--tac-restore-db") {
-               if (tac_restoreDB(false) != TAC_ERROR_NONE) {
-                       _SERR("Failed to restore TAC db of RW");
-               }
-               if (tlc_restoreDB(false) != TAC_ERROR_NONE) {
-                       _SERR("Failed to restore TLC db of RW");
-               }
-               if (tac_restoreDB(true) != TAC_ERROR_NONE) {
-                       _SERR("Failed to restore TAC db of RO");
-               }
-               if (tlc_restoreDB(true) != TAC_ERROR_NONE) {
-                       _SERR("Failed to restore TLC db of RO");
-               }
+               dotnettool_tac_restore_db(opt);
        }
-       //sh-3.2# dotnettool --tac-enable-pkg [pkgId] [pkgId] ...
        else if (cmd == "--tac-enable-pkg") {
-               if (args.size() < 1) {
-                       _SERR("Package name is missing");
-               }
-               while (it != args.end()) {
-                       std::string pkg = std::string(*it);
-                       int ret = enableTACPackage(pkg);
-                       if (ret != TAC_ERROR_NONE) {
-                               _SERR("Failed to enable tac [%s]", pkg.c_str());
-                               break;
-                       }
-                       it = args.erase(it);
-               }
+               dotnettool_tac_enable_pkg(opt);
        }
-       //sh-3.2# dotnettool --tac-disable-pkg [pkgId] [pkgId] ...
        else if (cmd == "--tac-disable-pkg") {
-               if (args.size() < 1) {
-                       _SERR("Package name is missing");
-               }
-               while (it != args.end()) {
-                       std::string pkg = std::string(*it);
-                       int ret = disableTACPackage(pkg);
-                       if (ret != TAC_ERROR_NONE) {
-                               _SERR("Failed to disable tac [%s]", pkg.c_str());
-                               break;
-                       }
-                       it = args.erase(it);
-               }
+               dotnettool_tac_disable_pkg(opt);
        }
-       //sh-3.2# dotnettool --resolve-all-app
        else if (cmd == "--resolve-all-app") {
                resolveAllApps();
        }
-       //sh-3.2# dotnettool --rm-app-profile [pkgId] [pkgId] ...
        else if (cmd == "--rm-app-profile") {
-               if (args.size() < 1) {
-                       _SERR("Package name is missing");
-               }
-               while (it != args.end()) {
-                       std::string pkg = std::string(*it);
-                       if (removeAppProfileData(pkg) != PROFILE_ERROR_NONE) {
-                               _SERR("Failed to remove [%s] profile data", pkg.c_str());
-                       }
-                       it = args.erase(it);
-               }
+               dotnettool_rm_app_profile(opt);
        }
-       //sh-3.2# dotnettool --rm-all-app-profile
        else if (cmd == "--rm-all-app-profile") {
                removeAllAppProfileData();
        }
-       //sh-3.2# dotnettool --check-all-app-privilege
        else if (cmd == "--check-all-app-privilege") {
                checkAllAppPrivilege();
        }