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 8ebff516 Simplify startCommand_execute implementation.
8ebff516 is described below
commit 8ebff516f317cf07b2bf6e4a2d3f23c64f326b52
Author: PengZheng <[email protected]>
AuthorDate: Tue Feb 21 11:14:46 2023 +0800
Simplify startCommand_execute implementation.
---
bundles/shell/shell/gtest/src/ShellTestSuite.cc | 1 +
bundles/shell/shell/src/start_command.c | 29 ++++++++++++-------------
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/bundles/shell/shell/gtest/src/ShellTestSuite.cc
b/bundles/shell/shell/gtest/src/ShellTestSuite.cc
index 599f1925..cb29036c 100644
--- a/bundles/shell/shell/gtest/src/ShellTestSuite.cc
+++ b/bundles/shell/shell/gtest/src/ShellTestSuite.cc
@@ -100,6 +100,7 @@ TEST_F(ShellTestSuite, testAllCommandsAreCallable) {
callCommand(ctx, "q -v", true);
callCommand(ctx, "stop not-a-number", false);
callCommand(ctx, "start not-a-number", false);
+ callCommand(ctx, "start", false); // incorrect number of arguments
callCommand(ctx, "uninstall not-a-number", false);
callCommand(ctx, "update not-a-number", false);
callCommand(ctx, "stop 15", false); //non existing bundle id
diff --git a/bundles/shell/shell/src/start_command.c
b/bundles/shell/shell/src/start_command.c
index 0216dd99..3e08d111 100644
--- a/bundles/shell/shell/src/start_command.c
+++ b/bundles/shell/shell/src/start_command.c
@@ -37,22 +37,21 @@ bool startCommand_execute(void *handle, const char
*constCommandLine, FILE *outS
bool startSucceeded = false;
if (sub == NULL) {
fprintf(outStream, "Incorrect number of arguments.\n");
- } else {
- while (sub != NULL) {
- bool converted;
- long bndId = celix_utils_convertStringToLong(sub, 0, &converted);
- bool exists = celix_bundleContext_isBundleInstalled(ctx, bndId);
- if (!converted) {
- fprintf(errStream, "Cannot convert '%s' to long (bundle
id).\n", sub);
- } else if (!exists) {
- fprintf(outStream, "No bundle with id %li.\n", bndId);
- } else {
- celix_framework_t* fw = celix_bundleContext_getFramework(ctx);
- celix_framework_startBundleAsync(fw, bndId);
- startSucceeded = true;
- }
- sub = strtok_r(NULL, OSGI_SHELL_COMMAND_SEPARATOR, &savePtr);
+ }
+ for (; sub != NULL; sub = strtok_r(NULL, OSGI_SHELL_COMMAND_SEPARATOR,
&savePtr)) {
+ bool converted;
+ long bndId = celix_utils_convertStringToLong(sub, 0, &converted);
+ if (!converted) {
+ fprintf(errStream, "Cannot convert '%s' to long (bundle id).\n",
sub);
+ continue;
+ }
+ if (!celix_bundleContext_isBundleInstalled(ctx, bndId)) {
+ fprintf(outStream, "No bundle with id %li.\n", bndId);
+ continue;
}
+ celix_framework_t* fw = celix_bundleContext_getFramework(ctx);
+ celix_framework_startBundleAsync(fw, bndId);
+ startSucceeded = true;
}
free(command);
return startSucceeded;