This is an automated email from the ASF dual-hosted git repository.
pengzheng pushed a commit to branch feature/refactor_bundle_cache
in repository https://gitbox.apache.org/repos/asf/celix.git
The following commit(s) were added to refs/heads/feature/refactor_bundle_cache
by this push:
new c2cf1e4c Minor code improvement for launcher.
new 1a0e6d97 Merge remote-tracking branch
'apache/feature/refactor_bundle_cache' into feature/refactor_bundle_cache
c2cf1e4c is described below
commit c2cf1e4c8b9811e69ada52aa60e3b0a74fadfae4
Author: PengZheng <[email protected]>
AuthorDate: Sat Feb 25 20:22:53 2023 +0800
Minor code improvement for launcher.
* Remove useless code.
* use sizeof instead of strlen to avoid runtime overhead.
---
libs/framework/gtest/src/CelixLauncherTestSuite.cc | 8 ++++++--
libs/framework/src/celix_launcher.c | 18 ++++++------------
2 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/libs/framework/gtest/src/CelixLauncherTestSuite.cc
b/libs/framework/gtest/src/CelixLauncherTestSuite.cc
index abb9315c..201a3f0b 100644
--- a/libs/framework/gtest/src/CelixLauncherTestSuite.cc
+++ b/libs/framework/gtest/src/CelixLauncherTestSuite.cc
@@ -47,11 +47,15 @@ TEST_F(CelixLauncherTestSuite, PrintPropertiesTest) {
}
TEST_F(CelixLauncherTestSuite, PrintHelpTest) {
+ // props should be released by launcher
+ auto* props = celix_properties_create();
+ celix_properties_set(props, CELIX_AUTO_START_0,
SIMPLE_TEST_BUNDLE1_LOCATION);
+ celix_properties_set(props, CELIX_AUTO_INSTALL,
SIMPLE_TEST_BUNDLE2_LOCATION);
//When I run the celixLauncher with "-h" argument
char* arg1 = celix_utils_strdup("programName");
char* arg2 = celix_utils_strdup("-h");
char* argv[] = {arg1, arg2};
- int rc = celixLauncher_launchAndWaitForShutdown(2, argv, nullptr);
+ int rc = celixLauncher_launchAndWaitForShutdown(2, argv, props);
//Then it will print the usage and exit with 0
EXPECT_EQ(rc, 0);
@@ -81,7 +85,7 @@ TEST_F(CelixLauncherTestSuite, ExtractBundlesTest) {
//When I run the celixLauncher with "-c" argument
char* arg1 = celix_utils_strdup("programName");
- char* arg2 = celix_utils_strdup("--embedded_bundles");
+ char* arg2 = celix_utils_strdup("-c");
char* argv[] = {arg1, arg2};
int rc = celixLauncher_launchAndWaitForShutdown(2, argv, props);
diff --git a/libs/framework/src/celix_launcher.c
b/libs/framework/src/celix_launcher.c
index 608710b5..433f1eb4 100644
--- a/libs/framework/src/celix_launcher.c
+++ b/libs/framework/src/celix_launcher.c
@@ -69,13 +69,8 @@ int celixLauncher_launchAndWaitForShutdown(int argc, char
*argv[], celix_propert
int celixLauncher_launchWithArgv(int argc, char *argv[], celix_properties_t*
embeddedConfig, celix_framework_t** frameworkOut) {
celix_framework_t* framework = NULL;
-
// Perform some minimal command-line option parsing...
char *opt = NULL;
- if (argc > 1) {
- opt = argv[1];
- }
-
char* configFile = NULL;
bool showProps = false;
bool showEmbeddedBundles = false;
@@ -83,15 +78,15 @@ int celixLauncher_launchWithArgv(int argc, char *argv[],
celix_properties_t* emb
for (int i = 1; i < argc; ++i) {
opt = argv[i];
// Check whether the user wants some help...
- if (strncmp("-?", opt, strlen("-?")) == 0 || strncmp("-h", opt,
strlen("-h")) == 0 || strncmp("--help", opt, strlen("--help")) == 0) {
+ if (strncmp("-?", opt, sizeof("-?")) == 0 || strncmp("-h", opt,
sizeof("-h")) == 0 || strncmp("--help", opt, sizeof("--help")) == 0) {
celixLauncher_printUsage(argv[0]);
- celix_properties_destroy(embeddedConfig);
- return 0;
- } else if (strncmp("-p", opt, strlen("-p")) == 0 ||
strncmp("--props", opt, strlen("--props")) == 0) {
+ celix_properties_destroy(embeddedConfig);
+ return 0;
+ } else if (strncmp("-p", opt, sizeof("-p")) == 0 || strncmp("--props",
opt, sizeof("--props")) == 0) {
showProps = true;
- } else if (strncmp("-c", opt, strlen("-c")) == 0 ||
strncmp("--create-bundle-cache", opt, strlen("--create-bundle-cache")) == 0) {
+ } else if (strncmp("-c", opt, sizeof("-c")) == 0 ||
strncmp("--create-bundle-cache", opt, sizeof("--create-bundle-cache")) == 0) {
createCache = true;
- } else if (strncmp("--embedded_bundles", opt,
strlen("--embedded_bundles")) == 0) {
+ } else if (strncmp("--embedded_bundles", opt,
sizeof("--embedded_bundles")) == 0) {
showEmbeddedBundles = true;
} else {
configFile = opt;
@@ -231,7 +226,6 @@ static void
celixLauncher_printProperties(celix_properties_t *embeddedProps, con
printf("\n");
//combined result
- celixLauncher_combineProperties(embeddedProps, runtimeProps);
printf("Resolved (env, runtime and embedded) properties:\n");
if (celix_properties_size(keys) == 0) {
printf("|- Empty!\n");