You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2019/10/08 13:21:47 UTC
[celix] 01/02: #80: Updates error handling of failed lib loading
for bundles.
This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a commit to branch feature/#80_bundle_start_with_exception
in repository https://gitbox.apache.org/repos/asf/celix.git
commit 402e9f538ce59da6ca05614ddb2deb365360cb8c
Author: Pepijn Noltes <pe...@gmail.com>
AuthorDate: Tue Oct 8 15:18:32 2019 +0200
#80: Updates error handling of failed lib loading for bundles.
---
libs/framework/src/framework.c | 32 +++++++++++-----------
libs/framework/tst/CMakeLists.txt | 9 ++++--
.../framework/tst/bundle_context_bundles_tests.cpp | 13 +++++++++
libs/framework/tst/subdir/CMakeLists.txt | 2 ++
libs/framework/tst/subdir/src/foo.c | 26 ++++++++++++++++++
5 files changed, 64 insertions(+), 18 deletions(-)
diff --git a/libs/framework/src/framework.c b/libs/framework/src/framework.c
index 17d56f3..34363ca 100644
--- a/libs/framework/src/framework.c
+++ b/libs/framework/src/framework.c
@@ -912,8 +912,10 @@ celix_status_t fw_startBundle(framework_pt framework, bundle_pt bundle, int opti
if (wires == NULL) {
return CELIX_BUNDLE_EXCEPTION;
}
- framework_markResolvedModules(framework, wires);
-
+ status = framework_markResolvedModules(framework, wires);
+ if (status != CELIX_SUCCESS) {
+ break;
+ }
}
/* no break */
case OSGI_FRAMEWORK_BUNDLE_RESOLVED:
@@ -1867,6 +1869,7 @@ long framework_getNextBundleId(framework_pt framework) {
}
celix_status_t framework_markResolvedModules(framework_pt framework, linked_list_pt resolvedModuleWireMap) {
+ celix_status_t status = CELIX_SUCCESS;
if (resolvedModuleWireMap != NULL) {
// hash_map_iterator_pt iterator = hashMapIterator_create(resolvedModuleWireMap);
linked_list_iterator_pt iterator = linkedListIterator_create(resolvedModuleWireMap, linkedList_size(resolvedModuleWireMap));
@@ -1923,21 +1926,21 @@ celix_status_t framework_markResolvedModules(framework_pt framework, linked_list
// printf("Module %s imports library %s:%s from %s\n", importerName, name, versionString, exporterName);
// }
- module_setWires(module, wires);
-
- module_setResolved(module);
- resolver_moduleResolved(module);
-
- const char *mname = NULL;
- module_getSymbolicName(module, &mname);
- framework_markBundleResolved(framework, module);
+ if (status == CELIX_SUCCESS) {
+ module_setWires(module, wires);
+ module_setResolved(module);
+ resolver_moduleResolved(module);
+ const char *mname = NULL;
+ module_getSymbolicName(module, &mname);
+ status = framework_markBundleResolved(framework, module);
+ }
linkedListIterator_remove(iterator);
free(iw);
}
linkedListIterator_destroy(iterator);
linkedList_destroy(resolvedModuleWireMap);
}
- return CELIX_SUCCESS;
+ return status;
}
celix_status_t framework_markBundleResolved(framework_pt framework, module_pt module) {
@@ -1984,7 +1987,7 @@ celix_status_t framework_markBundleResolved(framework_pt framework, module_pt mo
fw_bundleEntry_decreaseUseCount(framework, bndId);
}
- return CELIX_SUCCESS;
+ return status;
}
array_list_pt framework_getBundles(framework_pt framework) {
@@ -2425,8 +2428,7 @@ static celix_status_t framework_loadBundleLibraries(framework_pt framework, bund
if (status == CELIX_SUCCESS) {
bundle_setHandle(bundle, handle);
- }
- else if(handle != NULL){
+ } else if (handle != NULL) {
celix_libloader_close(handle);
}
}
@@ -2480,8 +2482,6 @@ static celix_status_t framework_loadLibraries(framework_pt framework, const char
token = strtok_r(NULL, ",", &last);
}
- framework_logIfError(framework->logger, status, NULL, "Could not load all libraries");
-
free(libraries);
return status;
}
diff --git a/libs/framework/tst/CMakeLists.txt b/libs/framework/tst/CMakeLists.txt
index 4466761..33a5efd 100644
--- a/libs/framework/tst/CMakeLists.txt
+++ b/libs/framework/tst/CMakeLists.txt
@@ -19,7 +19,12 @@ add_celix_bundle(simple_test_bundle1 NO_ACTIVATOR VERSION 1.0.0)
add_celix_bundle(simple_test_bundle2 NO_ACTIVATOR VERSION 1.0.0)
add_celix_bundle(simple_test_bundle3 NO_ACTIVATOR VERSION 1.0.0)
add_celix_bundle(bundle_with_exception SOURCES nop_activator.c VERSION 1.0.0)
-add_subdirectory(subdir) #simple_test_bundle4 and simeple_test_bundle5
+add_subdirectory(subdir) #simple_test_bundle4, simple_test_bundle5 and sublib
+
+add_celix_bundle(unresolveable_bundle SOURCES nop_activator.c VERSION 1.0.0)
+target_link_directories(unresolveable_bundle PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/subdir)
+target_link_libraries(unresolveable_bundle PRIVATE "-lsublib")
+add_dependencies(unresolveable_bundle sublib)
add_executable(test_framework
run_tests.cpp
@@ -31,7 +36,7 @@ add_executable(test_framework
)
target_link_libraries(test_framework Celix::framework CURL::libcurl ${CPPUTEST_LIBRARY})
-add_dependencies(test_framework simple_test_bundle1_bundle simple_test_bundle2_bundle simple_test_bundle3_bundle simple_test_bundle4_bundle simple_test_bundle5_bundle bundle_with_exception)
+add_dependencies(test_framework simple_test_bundle1_bundle simple_test_bundle2_bundle simple_test_bundle3_bundle simple_test_bundle4_bundle simple_test_bundle5_bundle bundle_with_exception_bundle unresolveable_bundle_bundle)
target_include_directories(test_framework PRIVATE ../src)
configure_file(config.properties.in config.properties @ONLY)
diff --git a/libs/framework/tst/bundle_context_bundles_tests.cpp b/libs/framework/tst/bundle_context_bundles_tests.cpp
index f193173..f173c96 100644
--- a/libs/framework/tst/bundle_context_bundles_tests.cpp
+++ b/libs/framework/tst/bundle_context_bundles_tests.cpp
@@ -42,6 +42,7 @@ TEST_GROUP(CelixBundleContextBundlesTests) {
const char * const TEST_BND4_LOC = "simple_test_bundle4.zip";
const char * const TEST_BND5_LOC = "simple_test_bundle5.zip";
const char * const TEST_BND_WITH_EXCEPTION_LOC = "bundle_with_exception.zip";
+ const char * const TEST_BND_UNRESOLVEABLE_LOC = "unresolveable_bundle.zip";
void setup() {
properties = properties_create();
@@ -102,6 +103,18 @@ TEST(CelixBundleContextBundlesTests, startBundleWithException) {
CHECK_TRUE(called);
}
+
+TEST(CelixBundleContextBundlesTests, startUnresolveableBundle) {
+ long bndId = celix_bundleContext_installBundle(ctx, TEST_BND_UNRESOLVEABLE_LOC, true);
+ CHECK(bndId > 0); //bundle is installed, but not resolved
+
+ bool called = celix_framework_useBundle(fw, false, bndId, nullptr, [](void */*handle*/, const celix_bundle_t *bnd) {
+ auto state = celix_bundle_getState(bnd);
+ CHECK_EQUAL(state, OSGI_FRAMEWORK_BUNDLE_INSTALLED);
+ });
+ CHECK_TRUE(called);
+}
+
TEST(CelixBundleContextBundlesTests, useBundleTest) {
int count = 0;
diff --git a/libs/framework/tst/subdir/CMakeLists.txt b/libs/framework/tst/subdir/CMakeLists.txt
index 5853a86..4956e3e 100644
--- a/libs/framework/tst/subdir/CMakeLists.txt
+++ b/libs/framework/tst/subdir/CMakeLists.txt
@@ -17,3 +17,5 @@
add_celix_bundle(simple_test_bundle4 NO_ACTIVATOR VERSION 1.0.0)
add_celix_bundle(simple_test_bundle5 NO_ACTIVATOR VERSION 1.0.0)
+
+add_library(sublib SHARED src/foo.c)
diff --git a/libs/framework/tst/subdir/src/foo.c b/libs/framework/tst/subdir/src/foo.c
new file mode 100644
index 0000000..6f56eb7
--- /dev/null
+++ b/libs/framework/tst/subdir/src/foo.c
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+#include <stdio.h>
+
+void foo(void);
+
+void foo(void) {
+ printf("nop\n");
+}