diff --git a/CHANGES.md b/CHANGES.md index 881cc237c..7da716829 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -69,14 +69,17 @@ limitations under the License. - It is no longer possible to use the `celix_bundleContext_useService*` functions or `celix::BundleContxt::useService*` methods on the Celix event thread. The calls will now immediately return and log an error if called on the Celix event thread. -- Apache Celix filter now use the underlying properties value types for matching. This means that it is more important - to add service properties with the correct type. +- Apache Celix filter now uses the underlying `properties` value types for matching. + This means that it is more important to add service properties with the correct type. - Celix C++ Exception are now defined in the `celix/exceptions.h` header file. The `celix/Exception.h` and `celix/IOException.h` are removed. - The seperator for `CELIX_AUTO_START_0` .. `CELIX_AUTO_START_6` and `CELIX_AUTO_INSTALL` is now a comma instead of a space. -- The launcher now only has 2 public functions: `celix_launcher_launchAndWait` and `celix_launcher_triggerStop`. The +- The launcher now only has two public functions: `celix_launcher_launchAndWait` and `celix_launcher_triggerStop`. The other functions are removed. +- The manifest format has been changed to JSON, and the manifest attribute names have been changed. + The old manifest format is no longer supported. + The old manifest attribute names are also no longer defined in `celix_constants.h`. ## New Features diff --git a/bundles/http_admin/http_admin/CMakeLists.txt b/bundles/http_admin/http_admin/CMakeLists.txt index cb0bd29ef..931d3ffc4 100644 --- a/bundles/http_admin/http_admin/CMakeLists.txt +++ b/bundles/http_admin/http_admin/CMakeLists.txt @@ -31,9 +31,6 @@ target_include_directories(http_admin PRIVATE src) target_link_libraries(http_admin PUBLIC Celix::http_admin_api) -celix_deprecated_utils_headers(http_admin) - - install_celix_bundle(http_admin EXPORT celix COMPONENT http_admin) #Setup target aliases to match external usage add_library(Celix::http_admin ALIAS http_admin) diff --git a/bundles/http_admin/http_admin/src/http_admin.c b/bundles/http_admin/http_admin/src/http_admin.c index ee303022c..7db8e1ea5 100755 --- a/bundles/http_admin/http_admin/src/http_admin.c +++ b/bundles/http_admin/http_admin/src/http_admin.c @@ -29,8 +29,8 @@ #include "civetweb.h" -#include "celix_utils_api.h" #include "celix_compiler.h" +#include "celix_threads.h" struct http_admin_manager { diff --git a/bundles/http_admin/http_admin/src/websocket_admin.c b/bundles/http_admin/http_admin/src/websocket_admin.c index 287796835..cd8923e03 100644 --- a/bundles/http_admin/http_admin/src/websocket_admin.c +++ b/bundles/http_admin/http_admin/src/websocket_admin.c @@ -28,7 +28,7 @@ #include "celix_compiler.h" #include "celix_stdlib_cleanup.h" -#include "celix_utils_api.h" +#include "celix_threads.h" struct websocket_admin_manager { bundle_context_pt context; diff --git a/bundles/logging/log_helper/CMakeLists.txt b/bundles/logging/log_helper/CMakeLists.txt index 50fd467a5..d32099012 100644 --- a/bundles/logging/log_helper/CMakeLists.txt +++ b/bundles/logging/log_helper/CMakeLists.txt @@ -29,8 +29,6 @@ if (LOG_HELPER) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/log_helper COMPONENT logging) celix_target_hide_symbols(log_helper) - celix_deprecated_utils_headers(log_helper) - celix_deprecated_framework_headers(log_helper) add_library(Celix::log_helper ALIAS log_helper) diff --git a/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_tests.cc b/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_tests.cc index ad29905d8..8d21c445b 100644 --- a/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_tests.cc +++ b/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_tests.cc @@ -156,26 +156,9 @@ extern "C" { } static void testBundles(void) { - celix_array_list_t* bundles = nullptr; - - int rc = bundleContext_getBundles(context, &bundles); - ASSERT_EQ(0, rc); - ASSERT_EQ(3, celix_arrayList_size(bundles)); //framework, rsa_dfi & calc - - /* - int size = arrayList_size(bundles); - int i; - for (i = 0; i < size; i += 1) { - celix_bundle_t *bundle = nullptr; - module_pt module = nullptr; - char *name = nullptr; - - bundle = (celix_bundle_t *) arrayList_get(bundles, i); - bundle_getCurrentModule(bundle, &module); - module_getSymbolicName(module, &name); - printf("got bundle with symbolic name '%s'", name); - }*/ - + celix_array_list_t* bundles = celix_bundleContext_listBundles(context); + ASSERT_NE(nullptr, bundles); + ASSERT_EQ(2, celix_arrayList_size(bundles)); //rsa_dfi & calc (note framework bundle is not included) celix_arrayList_destroy(bundles); } diff --git a/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c b/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c index 425800611..d1d4fd924 100644 --- a/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c +++ b/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c @@ -28,6 +28,7 @@ #include "export_registration_dfi.h" #include "dfi_utils.h" #include "remote_interceptors_handler.h" +#include "celix_threads.h" #include diff --git a/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c index 35e5bf3d9..486b7516a 100644 --- a/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c +++ b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c @@ -32,6 +32,8 @@ #include "remote_interceptors_handler.h" #include "remote_service_admin_dfi.h" #include "remote_service_admin_dfi_constants.h" +#include "hash_map.h" +#include "celix_threads.h" struct import_registration { celix_bundle_context_t *context; diff --git a/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c b/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c index aa4224758..ee4400c95 100644 --- a/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c +++ b/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c @@ -35,6 +35,7 @@ #include "utils.h" #include "celix_utils.h" #include "celix_ref.h" +#include "hash_map.h" #include "import_registration_dfi.h" #include "export_registration_dfi.h" diff --git a/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/gtest/src/RsaShmExportRegistrationUnitTestSuite.cc b/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/gtest/src/RsaShmExportRegistrationUnitTestSuite.cc index 9c8c0d15b..154b7e635 100644 --- a/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/gtest/src/RsaShmExportRegistrationUnitTestSuite.cc +++ b/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/gtest/src/RsaShmExportRegistrationUnitTestSuite.cc @@ -26,6 +26,7 @@ #include "celix_log_helper.h" #include "celix_bundle_context_ei.h" #include "malloc_ei.h" +#include "bundle_context.h" #include "celix_threads_ei.h" #include "celix_framework.h" #include "celix_bundle_context.h" diff --git a/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/src/rsa_shm_export_registration.c b/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/src/rsa_shm_export_registration.c index 736593470..60ff66ac6 100644 --- a/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/src/rsa_shm_export_registration.c +++ b/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/src/rsa_shm_export_registration.c @@ -28,6 +28,7 @@ #include "celix_api.h" #include "celix_stdlib_cleanup.h" #include "celix_threads.h" +#include "bundle_context.h" #include #include #include diff --git a/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/src/rsa_shm_impl.c b/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/src/rsa_shm_impl.c index 9209349d7..6e524cbed 100755 --- a/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/src/rsa_shm_impl.c +++ b/bundles/remote_services/remote_service_admin_shm_v2/rsa_shm/src/rsa_shm_impl.c @@ -22,6 +22,7 @@ #include "rsa_shm_constants.h" #include "rsa_shm_export_registration.h" #include "rsa_shm_import_registration.h" +#include "bundle_context.h" #include "rsa_rpc_factory.h" #include "rsa_request_sender_service.h" #include "endpoint_description.h" diff --git a/bundles/remote_services/rsa_common/src/export_registration_impl.c b/bundles/remote_services/rsa_common/src/export_registration_impl.c index ad541e5fb..43cad1e91 100644 --- a/bundles/remote_services/rsa_common/src/export_registration_impl.c +++ b/bundles/remote_services/rsa_common/src/export_registration_impl.c @@ -32,6 +32,7 @@ #include "export_registration_impl.h" #include "remote_service_admin_impl.h" +#include "celix_bundle.h" struct export_reference { @@ -179,38 +180,33 @@ celix_status_t exportRegistration_endpointRemoved(void * handle, service_referen return status; } -celix_status_t exportRegistration_open(export_registration_t *registration) { - celix_status_t status = CELIX_SUCCESS; - const char *bundleStore = NULL; +celix_status_t exportRegistration_open(export_registration_t* registration) { + celix_status_t status = CELIX_SUCCESS; + const char* bundleStore = NULL; - bundleContext_getProperty(registration->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore); + bundleContext_getProperty(registration->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore); - if (bundleStore == NULL) { - bundleStore = DEFAULT_BUNDLE_STORE; - } - char name[256]; + if (bundleStore == NULL) { + bundleStore = DEFAULT_BUNDLE_STORE; + } + char name[256]; - snprintf(name, 256, "%s/%s_endpoint.zip", bundleStore, registration->endpointDescription->serviceName); + snprintf(name, 256, "%s/%s_endpoint.zip", bundleStore, registration->endpointDescription->serviceName); - status = bundleContext_installBundle(registration->context, name, ®istration->bundle); - if (status == CELIX_SUCCESS) { - status = bundle_start(registration->bundle); - if (status == CELIX_SUCCESS) { - } - } + status = bundleContext_installBundle(registration->context, name, ®istration->bundle); + if (status == CELIX_SUCCESS) { + status = celix_bundleContext_startBundle(registration->context, celix_bundle_getId(registration->bundle)); + } - return status; + return status; } -celix_status_t exportRegistration_close(export_registration_t *registration) { - celix_status_t status = CELIX_SUCCESS; - - exportRegistration_stopTracking(registration); +celix_status_t exportRegistration_close(export_registration_t* registration) { + celix_status_t status = CELIX_SUCCESS; - bundle_uninstall(registration->bundle); - - - return status; + exportRegistration_stopTracking(registration); + (void)celix_bundleContext_uninstallBundle(registration->context, celix_bundle_getId(registration->bundle)); + return status; } celix_status_t exportRegistration_getException(export_registration_t *registration) { diff --git a/bundles/remote_services/rsa_common/src/import_registration_impl.c b/bundles/remote_services/rsa_common/src/import_registration_impl.c index 3e377b57e..cea5ca365 100644 --- a/bundles/remote_services/rsa_common/src/import_registration_impl.c +++ b/bundles/remote_services/rsa_common/src/import_registration_impl.c @@ -33,6 +33,8 @@ #include "import_registration_impl.h" #include "remote_service_admin_impl.h" +#include "celix_bundle.h" +#include "celix_bundle_context.h" struct import_reference { endpoint_description_t *endpoint; @@ -110,53 +112,50 @@ celix_status_t importRegistrationFactory_destroy(import_registration_factory_t * return status; } +celix_status_t importRegistrationFactory_open(import_registration_factory_t* registration_factory) { + celix_status_t status; -celix_status_t importRegistrationFactory_open(import_registration_factory_t *registration_factory) -{ - celix_status_t status; + const char* bundleStore = NULL; + bundleContext_getProperty(registration_factory->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore); - const char *bundleStore = NULL; - bundleContext_getProperty(registration_factory->context, BUNDLE_STORE_PROPERTY_NAME, &bundleStore); - - if (bundleStore == NULL) { - bundleStore = DEFAULT_BUNDLE_STORE; - } + if (bundleStore == NULL) { + bundleStore = DEFAULT_BUNDLE_STORE; + } - char name[256]; - snprintf(name, 256, "%s/%s_proxy.zip", bundleStore, registration_factory->serviceName); + char name[256]; + snprintf(name, 256, "%s/%s_proxy.zip", bundleStore, registration_factory->serviceName); - status = bundleContext_installBundle(registration_factory->context, name, ®istration_factory->bundle); + status = bundleContext_installBundle(registration_factory->context, name, ®istration_factory->bundle); - if (status == CELIX_SUCCESS) { - status = bundle_start(registration_factory->bundle); - if (status == CELIX_SUCCESS) { - celix_logHelper_log(registration_factory->loghelper, CELIX_LOG_LEVEL_INFO, "%s successfully started.", name); - } - } - else { - celix_logHelper_log(registration_factory->loghelper, CELIX_LOG_LEVEL_ERROR, "%s could not be installed.", name); - } + if (status == CELIX_SUCCESS) { + status = celix_bundleContext_startBundle(registration_factory->context, + celix_bundle_getId(registration_factory->bundle)); + if (status == CELIX_SUCCESS) { + celix_logHelper_log( + registration_factory->loghelper, CELIX_LOG_LEVEL_INFO, "%s successfully started.", name); + } + } else { + celix_logHelper_log(registration_factory->loghelper, CELIX_LOG_LEVEL_ERROR, "%s could not be installed.", name); + } - return status; + return status; } -celix_status_t importRegistrationFactory_close(import_registration_factory_t *registration_factory) -{ - celix_status_t status = CELIX_SUCCESS; - +celix_status_t importRegistrationFactory_close(import_registration_factory_t* registration_factory) { + celix_status_t status = CELIX_SUCCESS; - if (registration_factory->proxyFactoryTracker != NULL) { - serviceTracker_close(registration_factory->proxyFactoryTracker); - } + if (registration_factory->proxyFactoryTracker != NULL) { + serviceTracker_close(registration_factory->proxyFactoryTracker); + } - if (registration_factory->bundle != NULL) { - bundle_uninstall(registration_factory->bundle); - } + if (registration_factory->bundle != NULL) { + (void)celix_bundleContext_uninstallBundle(registration_factory->context, + celix_bundle_getId(registration_factory->bundle)); + } - return status; + return status; } - celix_status_t importRegistration_createProxyFactoryTracker(import_registration_factory_t *registration_factory, service_tracker_t **tracker) { celix_status_t status; service_tracker_customizer_t *customizer = NULL; diff --git a/bundles/remote_services/rsa_rpc_json/gtest/src/RsaJsonRpcActivatorUnitTestSuite.cc b/bundles/remote_services/rsa_rpc_json/gtest/src/RsaJsonRpcActivatorUnitTestSuite.cc index 94dfaefa7..30020ceef 100644 --- a/bundles/remote_services/rsa_rpc_json/gtest/src/RsaJsonRpcActivatorUnitTestSuite.cc +++ b/bundles/remote_services/rsa_rpc_json/gtest/src/RsaJsonRpcActivatorUnitTestSuite.cc @@ -38,7 +38,6 @@ class RsaJsonRpcActivatorUnitTestSuite : public ::testing::Test { RsaJsonRpcActivatorUnitTestSuite() { auto* props = celix_properties_create(); celix_properties_set(props, CELIX_FRAMEWORK_CACHE_DIR, ".rsa_json_rpc_impl_cache"); - celix_properties_set(props, CELIX_FRAMEWORK_BUNDLE_VERSION, "1.0.0"); celix_properties_set(props, RSA_JSON_RPC_LOG_CALLS_KEY, "true"); celix_properties_set(props, "CELIX_FRAMEWORK_EXTENDER_PATH", RESOURCES_DIR); auto* fwPtr = celix_frameworkFactory_createFramework(props); diff --git a/bundles/remote_services/rsa_rpc_json/gtest/src/RsaJsonRpcIntegrationTestSuite.cc b/bundles/remote_services/rsa_rpc_json/gtest/src/RsaJsonRpcIntegrationTestSuite.cc index 0fcbfa776..2bfd784ea 100644 --- a/bundles/remote_services/rsa_rpc_json/gtest/src/RsaJsonRpcIntegrationTestSuite.cc +++ b/bundles/remote_services/rsa_rpc_json/gtest/src/RsaJsonRpcIntegrationTestSuite.cc @@ -23,7 +23,7 @@ #include class RsaJsonRpcIntegrationTestSuite : public ::testing::Test { -public: + public: RsaJsonRpcIntegrationTestSuite() { auto* props = celix_properties_create(); celix_properties_setBool(props, CELIX_FRAMEWORK_CLEAN_CACHE_DIR_ON_CREATE, true); @@ -44,7 +44,7 @@ class RsaJsonRpcIntegrationTestSuite : public ::testing::Test { }; TEST_F(RsaJsonRpcIntegrationTestSuite, FindRsaJsonRpcService) { -celix_bundleContext_waitForEvents(ctx.get()); -long found = celix_bundleContext_findService(ctx.get(), CELIX_RSA_RPC_FACTORY_NAME); -EXPECT_GE(found, 0); -} \ No newline at end of file + celix_bundleContext_waitForEvents(ctx.get()); + long found = celix_bundleContext_findService(ctx.get(), CELIX_RSA_RPC_FACTORY_NAME); + EXPECT_GE(found, 0); +} diff --git a/bundles/remote_services/rsa_rpc_json/gtest/src/RsaJsonRpcUnitTestSuite.cc b/bundles/remote_services/rsa_rpc_json/gtest/src/RsaJsonRpcUnitTestSuite.cc index 97c183f52..1abab93bc 100644 --- a/bundles/remote_services/rsa_rpc_json/gtest/src/RsaJsonRpcUnitTestSuite.cc +++ b/bundles/remote_services/rsa_rpc_json/gtest/src/RsaJsonRpcUnitTestSuite.cc @@ -16,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ + #include "rsa_json_rpc_impl.h" #include "rsa_json_rpc_constants.h" #include "rsa_request_sender_tracker.h" @@ -43,6 +44,7 @@ #include "dfi_ei.h" #include "celix_properties_ei.h" #include "celix_long_hash_map_ei.h" +#include "celix_framework_version.h" #include #include extern "C" { @@ -54,7 +56,6 @@ class RsaJsonRpcUnitTestSuite : public ::testing::Test { RsaJsonRpcUnitTestSuite() { auto* props = celix_properties_create(); celix_properties_set(props, CELIX_FRAMEWORK_CACHE_DIR, ".rsa_json_rpc_impl_cache"); - celix_properties_set(props, CELIX_FRAMEWORK_BUNDLE_VERSION, "1.0.0"); celix_properties_set(props, RSA_JSON_RPC_LOG_CALLS_KEY, "true"); celix_properties_set(props, "CELIX_FRAMEWORK_EXTENDER_PATH", RESOURCES_DIR); auto* fwPtr = celix_frameworkFactory_createFramework(props); @@ -67,7 +68,6 @@ class RsaJsonRpcUnitTestSuite : public ::testing::Test { ~RsaJsonRpcUnitTestSuite() override { celix_ei_expect_celix_bundle_getSymbolicName(nullptr, 0, nullptr); - celix_ei_expect_celix_bundle_getManifestValue(nullptr, 0, nullptr); celix_ei_expect_calloc(nullptr, 0, nullptr); celix_ei_expect_celixThreadMutex_create(nullptr, 0, 0); celix_ei_expect_celix_bundleContext_registerServiceFactoryAsync(nullptr, 0, 0); @@ -106,7 +106,6 @@ class RsaJsonRpcUnitTestSuite : public ::testing::Test { TEST_F(RsaJsonRpcUnitTestSuite, CreateRsaJsonRpc) { rsa_json_rpc_t *jsonRpc = nullptr; - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, "1.0.0"); auto status = rsaJsonRpc_create(ctx.get(), logHelper.get(), &jsonRpc); EXPECT_EQ(CELIX_SUCCESS, status); EXPECT_NE(nullptr, jsonRpc); @@ -116,7 +115,6 @@ TEST_F(RsaJsonRpcUnitTestSuite, CreateRsaJsonRpc) { TEST_F(RsaJsonRpcUnitTestSuite, CreateRsaJsonRpcWithInvalidParams) { rsa_json_rpc_t *jsonRpc = nullptr; - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, "1.0.0"); auto status = rsaJsonRpc_create(nullptr, logHelper.get(), &jsonRpc); EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); @@ -130,8 +128,6 @@ TEST_F(RsaJsonRpcUnitTestSuite, CreateRsaJsonRpcWithInvalidParams) { TEST_F(RsaJsonRpcUnitTestSuite, CreateRsaJsonRpcWithENOMEM) { rsa_json_rpc_t *jsonRpc = nullptr; - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, "1.0.0"); - celix_ei_expect_calloc((void*)&rsaJsonRpc_create, 0, nullptr); auto status = rsaJsonRpc_create(ctx.get(), logHelper.get(), &jsonRpc); EXPECT_EQ(CELIX_ENOMEM, status); @@ -140,18 +136,15 @@ TEST_F(RsaJsonRpcUnitTestSuite, CreateRsaJsonRpcWithENOMEM) { TEST_F(RsaJsonRpcUnitTestSuite, CreateRsaJsonRpcWithInvalidVersion) { rsa_json_rpc_t *jsonRpc = nullptr; - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, nullptr); + celix_ei_expect_celix_bundle_getVersion((void*)&rsaJsonRpc_create, 1, nullptr); auto status = rsaJsonRpc_create(ctx.get(), logHelper.get(), &jsonRpc); EXPECT_EQ(CELIX_BUNDLE_EXCEPTION, status); - - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, "abc"); - status = rsaJsonRpc_create(ctx.get(), logHelper.get(), &jsonRpc); - EXPECT_EQ(CELIX_BUNDLE_EXCEPTION, status); } TEST_F(RsaJsonRpcUnitTestSuite, CreateRsaJsonRpcWithInvalidBundleSymbolicName) { rsa_json_rpc_t *jsonRpc = nullptr; - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, "1.0.0"); + celix_autoptr(celix_version_t) version = celix_version_createVersionFromString("1.0.0"); + celix_ei_expect_celix_bundle_getVersion((void*)&rsaJsonRpc_create, 1, version); celix_ei_expect_celix_bundle_getSymbolicName((void*)&rsaJsonRpc_create, 1, nullptr); auto status = rsaJsonRpc_create(ctx.get(), logHelper.get(), &jsonRpc); @@ -160,7 +153,8 @@ TEST_F(RsaJsonRpcUnitTestSuite, CreateRsaJsonRpcWithInvalidBundleSymbolicName) { TEST_F(RsaJsonRpcUnitTestSuite, FailedToCreateThreadMutex) { rsa_json_rpc_t *jsonRpc = nullptr; - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, "1.0.0"); + celix_autoptr(celix_version_t) version = celix_version_createVersionFromString("1.0.0"); + celix_ei_expect_celix_bundle_getVersion((void*)&rsaJsonRpc_create, 1, version); celix_ei_expect_celixThreadMutex_create((void*)&rsaJsonRpc_create, 0, CELIX_ENOMEM); auto status = rsaJsonRpc_create(ctx.get(), logHelper.get(), &jsonRpc); @@ -169,8 +163,6 @@ TEST_F(RsaJsonRpcUnitTestSuite, FailedToCreateThreadMutex) { TEST_F(RsaJsonRpcUnitTestSuite, FailedToCreateRemoteInterceptorsHandler) { rsa_json_rpc_t *jsonRpc = nullptr; - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, "1.0.0"); - celix_ei_expect_calloc((void*)&remoteInterceptorsHandler_create, 0, nullptr); auto status = rsaJsonRpc_create(ctx.get(), logHelper.get(), &jsonRpc); EXPECT_EQ(CELIX_ENOMEM, status); @@ -178,8 +170,6 @@ TEST_F(RsaJsonRpcUnitTestSuite, FailedToCreateRemoteInterceptorsHandler) { TEST_F(RsaJsonRpcUnitTestSuite, FailedToCreateRsaRequestSenderTracker) { rsa_json_rpc_t *jsonRpc = nullptr; - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, "1.0.0"); - celix_ei_expect_calloc((void*)&rsaRequestSenderTracker_create, 0, nullptr); auto status = rsaJsonRpc_create(ctx.get(), logHelper.get(), &jsonRpc); EXPECT_EQ(CELIX_ENOMEM, status); @@ -187,7 +177,6 @@ TEST_F(RsaJsonRpcUnitTestSuite, FailedToCreateRsaRequestSenderTracker) { TEST_F(RsaJsonRpcUnitTestSuite, CreateRpcProxy) { rsa_json_rpc_t *jsonRpc = nullptr; - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, "1.0.0"); auto status = rsaJsonRpc_create(ctx.get(), logHelper.get(), &jsonRpc); EXPECT_EQ(CELIX_SUCCESS, status); @@ -207,7 +196,6 @@ TEST_F(RsaJsonRpcUnitTestSuite, CreateRpcProxy) { TEST_F(RsaJsonRpcUnitTestSuite, CreateRpcProxyWithInvalidParams) { rsa_json_rpc_t *jsonRpc = nullptr; - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, "1.0.0"); auto status = rsaJsonRpc_create(ctx.get(), logHelper.get(), &jsonRpc); EXPECT_EQ(CELIX_SUCCESS, status); @@ -230,7 +218,6 @@ TEST_F(RsaJsonRpcUnitTestSuite, CreateRpcProxyWithInvalidParams) { TEST_F(RsaJsonRpcUnitTestSuite, RpcProxyFailedToCreateProxyFactory) { rsa_json_rpc_t *jsonRpc = nullptr; - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, "1.0.0"); auto status = rsaJsonRpc_create(ctx.get(), logHelper.get(), &jsonRpc); EXPECT_EQ(CELIX_SUCCESS, status); @@ -255,7 +242,6 @@ TEST_F(RsaJsonRpcUnitTestSuite, DestroyRpcProxyWithInvalidParams) { TEST_F(RsaJsonRpcUnitTestSuite, CreateEndpoint) { rsa_json_rpc_t *jsonRpc = nullptr; - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, "1.0.0"); auto status = rsaJsonRpc_create(ctx.get(), logHelper.get(), &jsonRpc); EXPECT_EQ(CELIX_SUCCESS, status); @@ -274,7 +260,6 @@ TEST_F(RsaJsonRpcUnitTestSuite, CreateEndpoint) { TEST_F(RsaJsonRpcUnitTestSuite, CreateRpcEndpointWithInvalidParams) { rsa_json_rpc_t *jsonRpc = nullptr; - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, "1.0.0"); auto status = rsaJsonRpc_create(ctx.get(), logHelper.get(), &jsonRpc); EXPECT_EQ(CELIX_SUCCESS, status); @@ -296,7 +281,6 @@ TEST_F(RsaJsonRpcUnitTestSuite, CreateRpcEndpointWithInvalidParams) { TEST_F(RsaJsonRpcUnitTestSuite, RpcEndpointFailedToCreateEndpoint) { rsa_json_rpc_t *jsonRpc = nullptr; - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, "1.0.0"); auto status = rsaJsonRpc_create(ctx.get(), logHelper.get(), &jsonRpc); EXPECT_EQ(CELIX_SUCCESS, status); @@ -324,11 +308,9 @@ class RsaJsonRpcProxyUnitTestSuite : public RsaJsonRpcUnitTestSuite { public: RsaJsonRpcProxyUnitTestSuite() { rsa_json_rpc_t *jsonRpcPtr = nullptr; - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, "1.0.0"); auto status = rsaJsonRpc_create(ctx.get(), logHelper.get(), &jsonRpcPtr); EXPECT_EQ(CELIX_SUCCESS, status); EXPECT_NE(nullptr, jsonRpcPtr); - celix_ei_expect_celix_bundle_getManifestValue(nullptr, 0, nullptr);//reset for next test jsonRpc = std::shared_ptr{jsonRpcPtr, [](auto* r){rsaJsonRpc_destroy(r);}}; reqSenderSvc.handle = nullptr; @@ -648,11 +630,9 @@ class RsaJsonRpcEndPointUnitTestSuite : public RsaJsonRpcUnitTestSuite { public: RsaJsonRpcEndPointUnitTestSuite() { rsa_json_rpc_t *jsonRpcPtr = nullptr; - celix_ei_expect_celix_bundle_getManifestValue((void*)&rsaJsonRpc_create, 1, "1.0.0"); auto status = rsaJsonRpc_create(ctx.get(), logHelper.get(), &jsonRpcPtr); EXPECT_EQ(CELIX_SUCCESS, status); EXPECT_NE(nullptr, jsonRpcPtr); - celix_ei_expect_celix_bundle_getManifestValue(nullptr, 0, nullptr);//reset for next test jsonRpc = std::shared_ptr{jsonRpcPtr, [](auto* r){rsaJsonRpc_destroy(r);}}; static rsa_rpc_json_test_service_t testSvc{}; @@ -676,7 +656,7 @@ class RsaJsonRpcEndPointUnitTestSuite : public RsaJsonRpcUnitTestSuite { unsigned int GenerateSerialProtoId() {//The same as rsaJsonRpc_generateSerialProtoId const char *bundleSymName = celix_bundle_getSymbolicName(celix_bundleContext_getBundle(ctx.get())); - return celix_utils_stringHash(bundleSymName) + 1; + return celix_utils_stringHash(bundleSymName) + CELIX_FRAMEWORK_VERSION_MAJOR; } std::shared_ptr jsonRpc{}; diff --git a/bundles/remote_services/rsa_rpc_json/gtest/src/RsaRequestSenderTrackerUnitTestSuite.cc b/bundles/remote_services/rsa_rpc_json/gtest/src/RsaRequestSenderTrackerUnitTestSuite.cc index 8c46cd839..15a6b6f90 100644 --- a/bundles/remote_services/rsa_rpc_json/gtest/src/RsaRequestSenderTrackerUnitTestSuite.cc +++ b/bundles/remote_services/rsa_rpc_json/gtest/src/RsaRequestSenderTrackerUnitTestSuite.cc @@ -36,7 +36,6 @@ class RsaRequestSenderTrackerUnitTestSuite : public ::testing::Test { RsaRequestSenderTrackerUnitTestSuite() { auto* props = celix_properties_create(); celix_properties_set(props, CELIX_FRAMEWORK_CACHE_DIR, ".rsa_json_rpc_impl_cache"); - celix_properties_set(props, CELIX_FRAMEWORK_BUNDLE_VERSION, "1.0.0"); celix_properties_set(props, RSA_JSON_RPC_LOG_CALLS_KEY, "true"); celix_properties_set(props, "CELIX_FRAMEWORK_EXTENDER_PATH", RESOURCES_DIR); auto* fwPtr = celix_frameworkFactory_createFramework(props); diff --git a/bundles/remote_services/rsa_rpc_json/src/rsa_json_rpc_impl.c b/bundles/remote_services/rsa_rpc_json/src/rsa_json_rpc_impl.c index 9bb19386c..e48008150 100644 --- a/bundles/remote_services/rsa_rpc_json/src/rsa_json_rpc_impl.c +++ b/bundles/remote_services/rsa_rpc_json/src/rsa_json_rpc_impl.c @@ -52,16 +52,11 @@ struct rsa_json_rpc { static unsigned int rsaJsonRpc_generateSerialProtoId(celix_bundle_t *bnd) { const char *bundleSymName = celix_bundle_getSymbolicName(bnd); - const char *bundleVer = celix_bundle_getManifestValue(bnd, CELIX_FRAMEWORK_BUNDLE_VERSION); + const celix_version_t* bundleVer = celix_bundle_getVersion(bnd); if (bundleSymName == NULL || bundleVer == NULL) { return 0; } - celix_version_t *version = celix_version_createVersionFromString(bundleVer); - if (version == NULL) { - return 0; - } - int major = celix_version_getMajor(version); - celix_version_destroy(version); + int major = celix_version_getMajor(bundleVer); return celix_utils_stringHash(bundleSymName) + major; } diff --git a/bundles/remote_services/rsa_spi/include/remote_proxy.h b/bundles/remote_services/rsa_spi/include/remote_proxy.h index 78239d68e..a24211541 100644 --- a/bundles/remote_services/rsa_spi/include/remote_proxy.h +++ b/bundles/remote_services/rsa_spi/include/remote_proxy.h @@ -29,6 +29,7 @@ #include "endpoint_listener.h" #include "remote_service_admin.h" +#include "hash_map.h" #define CELIX_RSA_REMOTE_PROXY_FACTORY "remote_proxy_factory" #define CELIX_RSA_REMOTE_PROXY_TIMEOUT "remote_proxy_timeout" diff --git a/bundles/remote_services/topology_manager/src/topology_manager.c b/bundles/remote_services/topology_manager/src/topology_manager.c index 877280684..799017b8a 100644 --- a/bundles/remote_services/topology_manager/src/topology_manager.c +++ b/bundles/remote_services/topology_manager/src/topology_manager.c @@ -38,7 +38,7 @@ #include "bundle_context.h" #include "celix_compiler.h" #include "celix_constants.h" -#include "bundle.h" +#include "celix_bundle.h" #include "remote_service_admin.h" #include "remote_constants.h" #include "filter.h" diff --git a/bundles/remote_services/topology_manager/tms_tst/tms_tests.cpp b/bundles/remote_services/topology_manager/tms_tst/tms_tests.cpp index 235afb20c..ba6469201 100644 --- a/bundles/remote_services/topology_manager/tms_tst/tms_tests.cpp +++ b/bundles/remote_services/topology_manager/tms_tst/tms_tests.cpp @@ -81,18 +81,18 @@ extern "C" { static endpoint_listener_t *eplService = nullptr; // actually this is the topology manager static void setupFm() { + celix_status_t rc; celix_properties_t* config; ASSERT_EQ(CELIX_SUCCESS, celix_properties_load("config.properties", 0, &config)); framework = celix_frameworkFactory_createFramework(config); ASSERT_NE(nullptr, framework); - celix_bundle_t *bundle = nullptr; - celix_status_t rc = framework_getFrameworkBundle(framework, &bundle); - EXPECT_EQ(CELIX_SUCCESS, rc); + celix_bundle_t *bundle = celix_framework_getFrameworkBundle(framework); + EXPECT_NE(nullptr, bundle); - rc = bundle_getContext(bundle, &context); - EXPECT_EQ(CELIX_SUCCESS, rc); + context = celix_framework_getFrameworkContext(framework); + EXPECT_NE(nullptr, context); rc = bundleContext_getServiceReference(context, (char *)CELIX_RSA_REMOTE_SERVICE_ADMIN, &rsaRef); EXPECT_EQ(CELIX_SUCCESS, rc); @@ -172,18 +172,18 @@ extern "C" { } static void setupFmImport() { + celix_status_t rc; celix_properties_t* config; ASSERT_EQ(CELIX_SUCCESS, celix_properties_load("config_import.properties", 0, &config)); framework = celix_frameworkFactory_createFramework(config); ASSERT_NE(nullptr, framework); - celix_bundle_t *bundle = nullptr; - celix_status_t rc = framework_getFrameworkBundle(framework, &bundle); - EXPECT_EQ(CELIX_SUCCESS, rc); + celix_bundle_t *bundle = celix_framework_getFrameworkBundle(framework); + ASSERT_NE(nullptr, bundle); - rc = bundle_getContext(bundle, &context); - EXPECT_EQ(CELIX_SUCCESS, rc); + context = celix_framework_getFrameworkContext(framework); + ASSERT_NE(nullptr, context); celix_array_list_t* bundles = celix_bundleContext_listBundles(context); EXPECT_EQ(celix_arrayList_size(bundles), 4); //rsa, calculator, topman, test bundle diff --git a/bundles/shell/remote_shell/CMakeLists.txt b/bundles/shell/remote_shell/CMakeLists.txt index 51bc5e9ed..54a8912ac 100644 --- a/bundles/shell/remote_shell/CMakeLists.txt +++ b/bundles/shell/remote_shell/CMakeLists.txt @@ -37,7 +37,7 @@ if (REMOTE_SHELL) include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include") target_link_libraries(remote_shell PRIVATE Celix::shell_api) - celix_deprecated_utils_headers(remote_shell) + #celix_deprecated_utils_headers(remote_shell) celix_deprecated_framework_headers(remote_shell) install_celix_bundle(remote_shell EXPORT celix COMPONENT remote_shell) diff --git a/bundles/shell/remote_shell/src/remote_shell.c b/bundles/shell/remote_shell/src/remote_shell.c index cdff97b30..e16ef2148 100644 --- a/bundles/shell/remote_shell/src/remote_shell.c +++ b/bundles/shell/remote_shell/src/remote_shell.c @@ -16,19 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -/** - * remote_shell.c - * - * \date Nov 4, 2012 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ #include #include -#include -#include #include +#include #include "celix_log_helper.h" #include "celix_utils.h" diff --git a/bundles/shell/remote_shell/src/shell_mediator.c b/bundles/shell/remote_shell/src/shell_mediator.c index 5ad3e6212..8d6e02f32 100644 --- a/bundles/shell/remote_shell/src/shell_mediator.c +++ b/bundles/shell/remote_shell/src/shell_mediator.c @@ -16,118 +16,108 @@ * specific language governing permissions and limitations * under the License. */ -/** - * shell_mediator.c - * - * \date Nov 4, 2012 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ #include #include -#include -#include -#include #include #include "celix_log_helper.h" +#include "celix_shell.h" +#include "service_tracker.h" #include "shell_mediator.h" -static celix_status_t shellMediator_addedService(void *handler, service_reference_pt reference, void * service); -static celix_status_t shellMediator_removedService(void *handler, service_reference_pt reference, void * service); - -celix_status_t shellMediator_create(bundle_context_pt context, shell_mediator_pt *instance) { - celix_status_t status = CELIX_SUCCESS; - service_tracker_customizer_pt customizer = NULL; +static celix_status_t shellMediator_addedService(void* handler, service_reference_pt reference, void* service); +static celix_status_t shellMediator_removedService(void* handler, service_reference_pt reference, void* service); - (*instance) = (shell_mediator_pt) calloc(1, sizeof(**instance)); - if ((*instance) != NULL) { +celix_status_t shellMediator_create(bundle_context_pt context, shell_mediator_pt* instance) { + celix_status_t status = CELIX_SUCCESS; + service_tracker_customizer_pt customizer = NULL; - (*instance)->context = context; - (*instance)->tracker = NULL; - (*instance)->shellService = NULL; + (*instance) = (shell_mediator_pt)calloc(1, sizeof(**instance)); + if ((*instance) != NULL) { + (*instance)->context = context; + (*instance)->tracker = NULL; + (*instance)->shellService = NULL; (*instance)->loghelper = celix_logHelper_create(context, "celix_shell"); - status = CELIX_DO_IF(status, celixThreadMutex_create(&(*instance)->mutex, NULL)); - - status = CELIX_DO_IF(status, serviceTrackerCustomizer_create((*instance), NULL, shellMediator_addedService, - NULL, shellMediator_removedService, &customizer)); - status = CELIX_DO_IF(status, serviceTracker_create(context, (char * )CELIX_SHELL_SERVICE_NAME, customizer, &(*instance)->tracker)); - - if (status == CELIX_SUCCESS) { - serviceTracker_open((*instance)->tracker); - } - } else { - status = CELIX_ENOMEM; - } - - if ((status != CELIX_SUCCESS) && ((*instance) != NULL)){ - celix_logHelper_log((*instance)->loghelper, CELIX_LOG_LEVEL_ERROR, "Error creating shell_mediator, error code is %i\n", status); - } - return status; + status = CELIX_DO_IF(status, celixThreadMutex_create(&(*instance)->mutex, NULL)); + + status = CELIX_DO_IF( + status, + serviceTrackerCustomizer_create( + (*instance), NULL, shellMediator_addedService, NULL, shellMediator_removedService, &customizer)); + status = CELIX_DO_IF( + status, serviceTracker_create(context, (char*)CELIX_SHELL_SERVICE_NAME, customizer, &(*instance)->tracker)); + + if (status == CELIX_SUCCESS) { + serviceTracker_open((*instance)->tracker); + } + } else { + status = CELIX_ENOMEM; + } + + if ((status != CELIX_SUCCESS) && ((*instance) != NULL)) { + celix_logHelper_log( + (*instance)->loghelper, CELIX_LOG_LEVEL_ERROR, "Error creating shell_mediator, error code is %i\n", status); + } + return status; } celix_status_t shellMediator_stop(shell_mediator_pt instance) { - service_tracker_pt tracker; - celixThreadMutex_lock(&instance->mutex); - tracker = instance->tracker; - celixThreadMutex_unlock(&instance->mutex); + service_tracker_pt tracker; + celixThreadMutex_lock(&instance->mutex); + tracker = instance->tracker; + celixThreadMutex_unlock(&instance->mutex); - if (tracker != NULL) { - serviceTracker_close(tracker); - } + if (tracker != NULL) { + serviceTracker_close(tracker); + } return CELIX_SUCCESS; } celix_status_t shellMediator_destroy(shell_mediator_pt instance) { - celix_status_t status = CELIX_SUCCESS; + celix_status_t status = CELIX_SUCCESS; - instance->shellService = NULL; - serviceTracker_destroy(instance->tracker); + instance->shellService = NULL; + serviceTracker_destroy(instance->tracker); celix_logHelper_destroy(instance->loghelper); - celixThreadMutex_destroy(&instance->mutex); + celixThreadMutex_destroy(&instance->mutex); + free(instance); - free(instance); - - - return status; + return status; } -celix_status_t shellMediator_executeCommand(shell_mediator_pt instance, char *command, FILE *out, FILE *err) { - celix_status_t status = CELIX_SUCCESS; - - celixThreadMutex_lock(&instance->mutex); +celix_status_t shellMediator_executeCommand(shell_mediator_pt instance, char* command, FILE* out, FILE* err) { + celix_status_t status = CELIX_SUCCESS; + celixThreadMutex_lock(&instance->mutex); - if (instance->shellService != NULL) { - instance->shellService->executeCommand(instance->shellService->handle, command, out, err); - } + if (instance->shellService != NULL) { + instance->shellService->executeCommand(instance->shellService->handle, command, out, err); + } - celixThreadMutex_unlock(&instance->mutex); + celixThreadMutex_unlock(&instance->mutex); - return status; + return status; } -static celix_status_t shellMediator_addedService(void *handler, service_reference_pt reference, void * service) { - celix_status_t status = CELIX_SUCCESS; - shell_mediator_pt instance = (shell_mediator_pt) handler; - celixThreadMutex_lock(&instance->mutex); - instance->shellService = (celix_shell_t*) service; - celixThreadMutex_unlock(&instance->mutex); - return status; +static celix_status_t shellMediator_addedService(void* handler, service_reference_pt reference, void* service) { + celix_status_t status = CELIX_SUCCESS; + shell_mediator_pt instance = (shell_mediator_pt)handler; + celixThreadMutex_lock(&instance->mutex); + instance->shellService = (celix_shell_t*)service; + celixThreadMutex_unlock(&instance->mutex); + return status; } - -static celix_status_t shellMediator_removedService(void *handler, service_reference_pt reference, void * service) { - celix_status_t status = CELIX_SUCCESS; - shell_mediator_pt instance = (shell_mediator_pt) handler; - celixThreadMutex_lock(&instance->mutex); - instance->shellService = NULL; - celixThreadMutex_unlock(&instance->mutex); - return status; +static celix_status_t shellMediator_removedService(void* handler, service_reference_pt reference, void* service) { + celix_status_t status = CELIX_SUCCESS; + shell_mediator_pt instance = (shell_mediator_pt)handler; + celixThreadMutex_lock(&instance->mutex); + instance->shellService = NULL; + celixThreadMutex_unlock(&instance->mutex); + return status; } - diff --git a/bundles/shell/remote_shell/src/shell_mediator.h b/bundles/shell/remote_shell/src/shell_mediator.h index b8fdd4291..1e09924b4 100644 --- a/bundles/shell/remote_shell/src/shell_mediator.h +++ b/bundles/shell/remote_shell/src/shell_mediator.h @@ -33,7 +33,8 @@ #include #include "celix_log_helper.h" -#include +#include "celix_shell.h" +#include "celix_threads.h" struct shell_mediator { celix_log_helper_t *loghelper; diff --git a/bundles/shell/shell/CMakeLists.txt b/bundles/shell/shell/CMakeLists.txt index e9320e011..ed915e460 100644 --- a/bundles/shell/shell/CMakeLists.txt +++ b/bundles/shell/shell/CMakeLists.txt @@ -49,7 +49,6 @@ if (SHELL) src/bundle_command.c) target_include_directories(shell_commands PRIVATE src) target_link_libraries(shell_commands PRIVATE Celix::shell_api Celix::log_helper) - celix_deprecated_utils_headers(shell_commands) add_celix_bundle(shell SYMBOLIC_NAME "apache_celix_c_shell" diff --git a/bundles/shell/shell_tui/CMakeLists.txt b/bundles/shell/shell_tui/CMakeLists.txt index d51f36b9f..aca16ebb1 100644 --- a/bundles/shell/shell_tui/CMakeLists.txt +++ b/bundles/shell/shell_tui/CMakeLists.txt @@ -31,7 +31,6 @@ if (SHELL_TUI) target_include_directories(shell_tui PRIVATE src) target_link_libraries(shell_tui PRIVATE Celix::shell_api Celix::utils) - celix_deprecated_utils_headers(shell_tui) install_celix_bundle(shell_tui EXPORT celix) diff --git a/bundles/shell/shell_tui/src/shell_tui.c b/bundles/shell/shell_tui/src/shell_tui.c index a370ec93f..1d8e78f83 100644 --- a/bundles/shell/shell_tui/src/shell_tui.c +++ b/bundles/shell/shell_tui/src/shell_tui.c @@ -23,14 +23,13 @@ #include #include #include +#include +#include #include "celix_array_list.h" #include "celix_shell.h" #include "celix_utils.h" #include "shell_tui.h" -#include "utils.h" -#include -#include #include "history.h" #define LINE_SIZE 256 diff --git a/cmake/cmake_celix/BundlePackaging.cmake b/cmake/cmake_celix/BundlePackaging.cmake index 0bdf0f654..4be1c48f7 100644 --- a/cmake/cmake_celix/BundlePackaging.cmake +++ b/cmake/cmake_celix/BundlePackaging.cmake @@ -20,14 +20,13 @@ set(CELIX_NO_POSTFIX_BUILD_TYPES RelWithDebInfo Release CACHE STRING "The build option(CELIX_USE_COMPRESSION_FOR_BUNDLE_ZIPS "Enables bundle compression" TRUE) if (CELIX_USE_COMPRESSION_FOR_BUNDLE_ZIPS) - set(CELIX_JAR_COMMAND_ARGUMENTS -cfm) + set(CELIX_JAR_COMMAND_ARGUMENTS -cf) set(CELIX_ZIP_COMMAND_ARGUMENTS -rq) else () - set(CELIX_JAR_COMMAND_ARGUMENTS -cfm0) + set(CELIX_JAR_COMMAND_ARGUMENTS -cf0) set(CELIX_ZIP_COMMAND_ARGUMENTS -rq0) endif () - find_program(JAR_COMMAND jar NO_CMAKE_FIND_ROOT_PATH) if (JAR_COMMAND AND NOT CELIX_USE_ZIP_INSTEAD_OF_JAR) @@ -177,7 +176,7 @@ function(add_celix_bundle) set(OPTIONS NO_ACTIVATOR DO_NOT_CONFIGURE_SYMBOL_VISIBILITY) set(ONE_VAL_ARGS VERSION ACTIVATOR SYMBOLIC_NAME NAME DESCRIPTION FILENAME GROUP) - set(MULTI_VAL_ARGS SOURCES PRIVATE_LIBRARIES EXPORT_LIBRARIES IMPORT_LIBRARIES HEADERS) + set(MULTI_VAL_ARGS SOURCES PRIVATE_LIBRARIES HEADERS) cmake_parse_arguments(BUNDLE "${OPTIONS}" "${ONE_VAL_ARGS}" "${MULTI_VAL_ARGS}" ${ARGN}) ##check arguments @@ -269,7 +268,7 @@ function(add_celix_bundle) ##### MANIFEST configuration and generation ################## #Step1 configure the file so that the target name is present in in the template - configure_file(${CELIX_CMAKE_DIRECTORY}/templates/Manifest.in ${BUNDLE_GEN_DIR}/MANIFEST.step1) + configure_file(${CELIX_CMAKE_DIRECTORY}/templates/MANIFEST.json.in ${BUNDLE_GEN_DIR}/MANIFEST.step1) #Step2 replace headers with target property values. Note this is done build time file(GENERATE @@ -277,9 +276,9 @@ function(add_celix_bundle) INPUT "${BUNDLE_GEN_DIR}/MANIFEST.step1" ) - #Step3 The replaced values in step 2 can contain generator expresssion, generated again to resolve those. Note this is done build time + #Step3 The replaced values in step 2 can contain generator expression, generated again to resolve those. Note this is done build time file(GENERATE - OUTPUT "${BUNDLE_GEN_DIR}/MANIFEST.MF" + OUTPUT "${BUNDLE_GEN_DIR}/MANIFEST.json" INPUT "${BUNDLE_GEN_DIR}/MANIFEST.step2" ) ######################################################### @@ -288,19 +287,19 @@ function(add_celix_bundle) if (JAR_COMMAND) add_custom_command(OUTPUT ${BUNDLE_FILE} COMMAND ${CMAKE_COMMAND} -E make_directory ${BUNDLE_CONTENT_DIR} - COMMAND ${JAR_COMMAND} ${CELIX_JAR_COMMAND_ARGUMENTS} ${BUNDLE_FILE} ${BUNDLE_GEN_DIR}/MANIFEST.MF -C ${BUNDLE_CONTENT_DIR} . + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${BUNDLE_GEN_DIR}/MANIFEST.json ${BUNDLE_CONTENT_DIR}/META-INF/MANIFEST.json + COMMAND ${JAR_COMMAND} ${CELIX_JAR_COMMAND_ARGUMENTS} ${BUNDLE_FILE} -C ${BUNDLE_CONTENT_DIR} . COMMENT "Packaging ${BUNDLE_TARGET_NAME}" - DEPENDS ${BUNDLE_TARGET_NAME} "$" ${BUNDLE_GEN_DIR}/MANIFEST.MF + DEPENDS ${BUNDLE_TARGET_NAME} "$" ${BUNDLE_GEN_DIR}/MANIFEST.json WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) elseif (ZIP_COMMAND) - file(MAKE_DIRECTORY ${BUNDLE_CONTENT_DIR}) - + file(MAKE_DIRECTORY ${BUNDLE_CONTENT_DIR}) #Note needed because working_directory is bundle content dir add_custom_command(OUTPUT ${BUNDLE_FILE} - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${BUNDLE_GEN_DIR}/MANIFEST.MF META-INF/MANIFEST.MF + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${BUNDLE_GEN_DIR}/MANIFEST.json ${BUNDLE_CONTENT_DIR}/META-INF/MANIFEST.json COMMAND ${ZIP_COMMAND} ${CELIX_ZIP_COMMAND_ARGUMENTS} ${BUNDLE_FILE} * COMMENT "Packaging ${BUNDLE_TARGET_NAME}" - DEPENDS ${BUNDLE_TARGET_NAME} "$" ${BUNDLE_GEN_DIR}/MANIFEST.MF + DEPENDS ${BUNDLE_TARGET_NAME} "$" ${BUNDLE_GEN_DIR}/MANIFEST.json WORKING_DIRECTORY ${BUNDLE_CONTENT_DIR} ) else () @@ -340,10 +339,8 @@ function(add_celix_bundle) celix_bundle_description(${BUNDLE_TARGET_NAME} "${BUNDLE_DESCRIPTION}") #The bundle description. #headers - set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_ACTIVATOR" 1) #Library containing the activator (if any) + set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_ACTIVATOR" "") #Library containing the activator (if any) set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_PRIVATE_LIBS" "") #List of private libs. - set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_IMPORT_LIBS" "") #List of libs to import - set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_EXPORT_LIBS" "") #list of libs to export set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_LIB_TARGETS" "") #list of all lib targets built within the project. set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_HEADERS" "") #Additional headers will be added (new line seperated) to the manifest ################################ @@ -380,22 +377,9 @@ function(add_celix_bundle) celix_bundle_private_libs(${BUNDLE_TARGET_NAME} ${BUNDLE_PRIVATE_LIBRARIES}) - celix_bundle_export_libs(${BUNDLE_TARGET_NAME} ${BUNDLE_EXPORT_LIBRARIES}) - celix_bundle_import_libs(${BUNDLE_TARGET_NAME} ${BUNDLE_IMPORT_LIBRARIES}) celix_bundle_headers(${BUNDLE_TARGET_NAME} ${BUNDLE_HEADERS}) endfunction() -#[[ -Adds a export lib to the Celix bundle. - -NOTE: Currently export lib support is Celix is not complete and still experimental. -]] -function(celix_bundle_export_libs) - list(GET ARGN 0 BUNDLE) - list(REMOVE_AT ARGN 0) - celix_bundle_libs(${BUNDLE} "EXPORT" TRUE ${ARGN}) -endfunction() - #[[ Add libraries to a bundle. @@ -450,7 +434,7 @@ function(celix_bundle_libs) list(GET ARGN 0 ADD_TO_MANIFEST) list(REMOVE_AT ARGN 0) - #check if arg 0 is corrent + #check if arg 0 is correct _check_bundle(${BUNDLE}) get_target_property(BUNDLE_DIR ${BUNDLE} "BUNDLE_CONTENT_DIR") get_target_property(BUNDLE_GEN_DIR ${BUNDLE} "BUNDLE_GEN_DIR") @@ -461,6 +445,10 @@ function(celix_bundle_libs) get_target_property(LIB_TARGETS ${BUNDLE} "BUNDLE_LIB_TARGETS") foreach (LIB IN ITEMS ${ARGN}) + if (TYPE STREQUAL "EXPORT" OR TYPE STREQUAL "IMPORT") + message(WARNING "Adding bundle lib ${LIB} with type ${TYPE}. Export and Import libs in Celix is yet supported.") + endif () + string(MAKE_C_IDENTIFIER ${LIB} LIBID) if (IS_ABSOLUTE ${LIB} AND EXISTS ${LIB}) get_filename_component(LIB_NAME ${LIB} NAME) @@ -524,37 +512,6 @@ function(celix_bundle_libs) set_target_properties(${BUNDLE} PROPERTIES "BUNDLE_LIB_TARGETS" "${LIB_TARGETS}") endfunction() -#[[ -Adds a import lib to the Celix bundle. - -NOTE: Currently importing lib support is Celix is not complete and still experimental. -]] -function(celix_bundle_import_libs) - #0 is bundle TARGET - #2..n is import libs - list(GET ARGN 0 BUNDLE) - list(REMOVE_AT ARGN 0) - - #check if arg 0 is correct - _check_bundle(${BUNDLE}) - - get_target_property(LIBS ${BUNDLE} "BUNDLE_IMPORT_LIBS") - - foreach (LIB IN ITEMS ${ARGN}) - message(WARNING "Bundle with import libs in Celix is not complete and still experimental.") - if (IS_ABSOLUTE ${LIB} AND EXISTS ${LIB}) - list(APPEND LIBS ${LIB_NAME}) - else () - list(APPEND LIBS "$") - endif () - - target_link_libraries(${BUNDLE} PRIVATE ${LIB}) - endforeach () - - - set_target_properties(${BUNDLE} PROPERTIES "BUNDLE_IMPORT_LIBS" "${LIBS}") -endfunction() - #[[ Add files to the target bundle. @@ -750,13 +707,14 @@ celix_bundle_headers( ]] function(celix_bundle_headers) #0 is bundle TARGET - #1..n is header name / header value + #1..n is header "key: value" pairs list(GET ARGN 0 BUNDLE) list(REMOVE_AT ARGN 0) get_target_property(HEADERS ${BUNDLE} "BUNDLE_HEADERS") foreach (HEADER IN ITEMS ${ARGN}) + _celix_convert_keyval_to_json(${HEADER} ":" HEADER) list(APPEND HEADERS "${HEADER}") endforeach () @@ -976,7 +934,8 @@ function(install_celix_bundle) if (JAR_COMMAND) install(CODE "execute_process( - COMMAND ${JAR_COMMAND} ${CELIX_JAR_COMMAND_ARGUMENTS} ${BUNDLE_FILE_INSTALL} ${BUNDLE_GEN_DIR}/MANIFEST.MF -C ${BUNDLE_CONTENT_DIR} . + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${BUNDLE_GEN_DIR}/MANIFEST.json META-INF/MANIFEST.json + COMMAND ${JAR_COMMAND} ${CELIX_JAR_COMMAND_ARGUMENTS} ${BUNDLE_FILE_INSTALL} -C ${BUNDLE_CONTENT_DIR} . WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} )" COMPONENT ${BUNDLE} @@ -984,7 +943,7 @@ function(install_celix_bundle) elseif (ZIP_COMMAND) install(CODE "execute_process( - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${BUNDLE_GEN_DIR}/MANIFEST.MF META-INF/MANIFEST.MF + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${BUNDLE_GEN_DIR}/MANIFEST.json META-INF/MANIFEST.json COMMAND ${ZIP_COMMAND} ${CELIX_ZIP_COMMAND_ARGUMENTS} ${BUNDLE_FILE_INSTALL} . -i * WORKING_DIRECTORY ${BUNDLE_CONTENT_DIR} )" diff --git a/cmake/cmake_celix/ContainerPackaging.cmake b/cmake/cmake_celix/ContainerPackaging.cmake index 71c8c3c19..eb24178dd 100644 --- a/cmake/cmake_celix/ContainerPackaging.cmake +++ b/cmake/cmake_celix/ContainerPackaging.cmake @@ -594,38 +594,6 @@ function(_celix_container_check_duplicate_bundles) endforeach() endfunction() -#[[ -Internal function that converts a property string to a JSON field entry. -The result is stored in the OUTPUT_VAR_NAME variable. - -In the key the char `=` is not allowed and should be escaped as `\=` (in CMake this is `\\=`, because \ is already an -escape char in CMake). -In the value the char `=` is allowed. - -To handle \= string sequences the \= entries are replaced with a placeholder (____) and after the -split the placeholder is replaced with =. - -```CMake -_celix_convert_property_to_json("prop1=val1" OUTPUT_VAR_NAME) # OUTPUT_VAR_NAME will be set to "\"prop1\":\"val1\"" -_celix_convert_property_to_json("prop1=va=l1" OUTPUT_VAR_NAME) # OUTPUT_VAR_NAME will be set to "\"prop1\":\"va=l1\"" -_celix_convert_property_to_json("prop\\=1=val1" OUTPUT_VAR_NAME) # OUTPUT_VAR_NAME will be set to "\"prop=1\":\"val1\"" -``` -]] -function(_celix_convert_property_to_json INPUT_STR OUTPUT_VAR_NAME) - set(PLACEHOLDER "____") - string(REPLACE "\\=" "${PLACEHOLDER}" TEMP_INPUT_STR "${INPUT_STR}") - - string(REGEX MATCH "([^=]+)=(.*)" _ ${TEMP_INPUT_STR}) - set(KEY ${CMAKE_MATCH_1}) - set(VALUE ${CMAKE_MATCH_2}) - - #Replace replaced \= and \\ with = and \ - string(REPLACE "${PLACEHOLDER}" "=" KEY "${KEY}") - string(REPLACE "${PLACEHOLDER}" "=" VALUE "${VALUE}") - - set(${OUTPUT_VAR_NAME} "\"${KEY}\":\"${VALUE}\"" PARENT_SCOPE) -endfunction() - #[[ Add the provided properties to the target Celix container config properties. These properties will be added to the config.properties in the container build dir. @@ -640,14 +608,14 @@ celix_container_runtime_properties( ]] function(celix_container_runtime_properties) #0 is container TARGET - #1..n is bundles + #1..n is property "key=val" pairs list(GET ARGN 0 CONTAINER_TARGET) list(REMOVE_AT ARGN 0) get_target_property(PROPS ${CONTAINER_TARGET} "CONTAINER_RUNTIME_PROPERTIES") - foreach(PROP IN ITEMS ${ARGN}) - _celix_convert_property_to_json(${PROP} PROP) + foreach (PROP IN ITEMS ${ARGN}) + _celix_convert_keyval_to_json(${PROP} "=" PROP) list(APPEND PROPS ${PROP}) endforeach() @@ -668,14 +636,14 @@ celix_container_embedded_properties( ]] function(celix_container_embedded_properties) #0 is container TARGET - #1..n is bundles + #1..n is property "key=val" pairs list(GET ARGN 0 CONTAINER_TARGET) list(REMOVE_AT ARGN 0) get_target_property(PROPS ${CONTAINER_TARGET} "CONTAINER_EMBEDDED_PROPERTIES") - foreach(PROP IN ITEMS ${ARGN}) - _celix_convert_property_to_json(${PROP} PROP) + foreach (PROP IN ITEMS ${ARGN}) + _celix_convert_keyval_to_json(${PROP} "=" PROP) list(APPEND PROPS ${PROP}) endforeach() diff --git a/cmake/cmake_celix/Generic.cmake b/cmake/cmake_celix/Generic.cmake index f2a8782d7..6ea73ce15 100644 --- a/cmake/cmake_celix/Generic.cmake +++ b/cmake/cmake_celix/Generic.cmake @@ -162,3 +162,41 @@ function(celix_target_hide_symbols) VISIBILITY_INLINES_HIDDEN ON) endif () endfunction() + +#[[ +Internal function that converts a property string to a JSON field entry. +The result is stored in the OUTPUT_VAR_NAME variable. + +In the key the char `=` is not allowed and should be escaped as `\=` (in CMake this is `\\=`, because \ is already an +escape char in CMake). +In the value the char `=` is allowed. + +To handle \= string sequences the \= entries are replaced with a placeholder (____) and after the +split the placeholder is replaced with =. + +```CMake +_celix_convert_keyval_to_json("prop1=val1" "=" OUTPUT_VAR_NAME) # OUTPUT_VAR_NAME will be set to "\"prop1\":\"val1\"" +_celix_convert_keyval_to_json("prop1=va=l1" "=" OUTPUT_VAR_NAME) # OUTPUT_VAR_NAME will be set to "\"prop1\":\"va=l1\"" +_celix_convert_keyval_to_json("prop\\=1=val1" "=" OUTPUT_VAR_NAME) # OUTPUT_VAR_NAME will be set to "\"prop=1\":\"val1\"" + +_celix_convert_keyval_to_json(" prop1 = val1 " "=" OUTPUT_VAR_NAME) # OUTPUT_VAR_NAME will be set to "\"prop1\"":\"val1\"" +``` +]] +function(_celix_convert_keyval_to_json INPUT_STR SEPERATOR_CHAR OUTPUT_VAR_NAME) + set(PLACEHOLDER "____") + string(REPLACE "\\${SEPERATOR_CHAR}" "${PLACEHOLDER}" TEMP_INPUT_STR "${INPUT_STR}") + + string(REGEX MATCH "([^${SEPERATOR_CHAR}]+)${SEPERATOR_CHAR}(.*)" _ ${TEMP_INPUT_STR}) + set(KEY ${CMAKE_MATCH_1}) + set(VALUE ${CMAKE_MATCH_2}) + + #Replace replaced \= and \\ with = and \ + string(REPLACE "${PLACEHOLDER}" "${SEPERATOR_CHAR}" KEY "${KEY}") + string(REPLACE "${PLACEHOLDER}" "${SEPERATOR_CHAR}" VALUE "${VALUE}") + + #Strip leading and trailing spaces + string(STRIP "${KEY}" KEY) + string(STRIP "${VALUE}" VALUE) + + set(${OUTPUT_VAR_NAME} "\"${KEY}\":\"${VALUE}\"" PARENT_SCOPE) +endfunction() diff --git a/cmake/cmake_celix/templates/MANIFEST.json.in b/cmake/cmake_celix/templates/MANIFEST.json.in new file mode 100644 index 000000000..7c530dbdc --- /dev/null +++ b/cmake/cmake_celix/templates/MANIFEST.json.in @@ -0,0 +1,12 @@ +{ + $,$ + >$<$>:$> + "CELIX_BUNDLE_SYMBOLIC_NAME" : "$", + "CELIX_BUNDLE_VERSION" : "version<$$", + "CELIX_BUNDLE_NAME" : "$", + $<$>:"CELIX_BUNDLE_ACTIVATOR_LIBRARY": "$",> + $<$>:"CELIX_BUNDLE_PRIVATE_LIBRARIES" : [$","$">],> + $<$>:"CELIX_BUNDLE_DESCRIPTION" : "$",> + $<$>:"CELIX_BUNDLE_GROUP" : "$",> + "CELIX_BUNDLE_MANIFEST_VERSION" : "version<2.0.0$" +} diff --git a/cmake/cmake_celix/templates/Manifest.in b/cmake/cmake_celix/templates/Manifest.in deleted file mode 100644 index ce4a67f8e..000000000 --- a/cmake/cmake_celix/templates/Manifest.in +++ /dev/null @@ -1,12 +0,0 @@ -Manifest-Version: 1.0 -Bundle-SymbolicName: $ -Bundle-Group: $ -Bundle-Name: $ -Bundle-Version: $ -Bundle-Description: $ -Bundle-Activator: $ -Private-Library: $,, > -Import-Library: $,, > -Export-Library: $,, > -$, -> diff --git a/cmake/cmake_celix/templates/NOTE b/cmake/cmake_celix/templates/NOTE index 46524d549..2dcb6db86 100644 --- a/cmake/cmake_celix/templates/NOTE +++ b/cmake/cmake_celix/templates/NOTE @@ -18,6 +18,6 @@ All files in this directory are licensed to the Apache Software Foundation (as included above). Normally source/txt files should include this header but for templates this sometimes is not possible. The following templates do not include the header: -* Manifest.in +* MANIFEST.json.in This note is added to explicitly mention that the same licensing applies to these files as to any other having the header. \ No newline at end of file diff --git a/documents/bundles.md b/documents/bundles.md index d10bdb5ad..24e679042 100644 --- a/documents/bundles.md +++ b/documents/bundles.md @@ -24,10 +24,10 @@ An Apache Celix Bundle contains a collection of shared libraries, configuration an activation entry combined in a zip file. Bundles can be dynamically installed and started in an Apache Celix framework. ## The anatomy of a Celix Bundle -Technically an Apache Celix Bundle is a zip file with the following content: +Technically, an Apache Celix Bundle is a zip file with the following content: -- META-INF/MANIFEST.MF: The required bundle manifest, containing information about the bundle (name, activator library etc) -- Bundle shared libraries (so/dylib files): Optionally a bundle has 1 or more shared libraries. +- META-INF/MANIFEST.json: The required bundle manifest, containing information about the bundle (name, activator library etc) +- Bundle shared libraries (so/dylib files): Optionally, a bundle has 1 or more shared libraries. The bundle manifest configures which libraries will be loaded (private libs) and which - if any - library is used when activating the bundle. - Bundle resource files: A bundle can also contain additional resource files. @@ -36,8 +36,7 @@ Technically an Apache Celix Bundle is a zip file with the following content: Note that bundles can access other bundles resources files. If a `jar` command is available the Celix CMake commands will use that (instead of the `zip` command) to create bundle -zip files so that the MANIFEST.MF is always the first entry in the zip file. - +zip files. ```bash #unpacking celix_shell_wui.zip bundle file from a cmake build `cmake-build-debug`. @@ -52,7 +51,7 @@ unpacked_bundle_dir/resources/index.html unpacked_bundle_dir/resources/ansi_up.js unpacked_bundle_dir/resources/script.js unpacked_bundle_dir/META-INF -unpacked_bundle_dir/META-INF/MANIFEST.MF +unpacked_bundle_dir/META-INF/MANIFEST.json unpacked_bundle_dir/libcivetweb_shared.so #or dylib for OSX unpacked_bundle_dir/libshell_wui.1.so #or dylib for OSX ``` diff --git a/libs/dfi/gtest/CMakeLists.txt b/libs/dfi/gtest/CMakeLists.txt index 7e23890f9..2f61b6355 100644 --- a/libs/dfi/gtest/CMakeLists.txt +++ b/libs/dfi/gtest/CMakeLists.txt @@ -32,7 +32,6 @@ add_executable(test_dfi target_include_directories(test_dfi PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../src) target_link_libraries(test_dfi PRIVATE dfi_cut Celix::utils libffi::libffi jansson::jansson GTest::gtest GTest::gtest_main) -celix_deprecated_utils_headers(test_dfi) file(COPY ${CMAKE_CURRENT_LIST_DIR}/descriptors DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/libs/framework/CMakeLists.txt b/libs/framework/CMakeLists.txt index a1c749050..421fa20e6 100644 --- a/libs/framework/CMakeLists.txt +++ b/libs/framework/CMakeLists.txt @@ -25,8 +25,8 @@ if (FRAMEWORK) set(FRAMEWORK_SRC src/bundle.c src/bundle_archive.c src/celix_bundle_cache.c src/bundle_context.c src/bundle_revision.c - src/framework.c src/manifest.c - src/manifest_parser.c src/module.c + src/framework.c + src/module.c src/service_reference.c src/service_registration.c src/service_registry.c src/service_tracker.c src/service_tracker_customizer.c src/celix_log.c src/celix_launcher.c @@ -38,6 +38,7 @@ if (FRAMEWORK) src/celix_framework_utils.c src/celix_scheduled_event.c src/celix_framework_bundle.c + src/celix_bundle_manifest.c ) add_library(framework SHARED ${FRAMEWORK_SRC}) @@ -53,6 +54,7 @@ if (FRAMEWORK) target_include_directories(framework PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include_deprecated) target_compile_options(framework PRIVATE -DUSE_FILE32API) target_compile_options(framework PRIVATE -Wno-deprecated-declarations) #note part of the api is deprecated, ignore this warning on own api + target_compile_options(framework PRIVATE -DCELIX_FRAMEWORK_VERSION="${CELIX_MAJOR}.${CELIX_MINOR}.${CELIX_MICRO}") if (NOT FRAMEWORK_CURLINIT) target_compile_definitions(framework PRIVATE CELIX_NO_CURLINIT) endif () @@ -68,6 +70,8 @@ if (FRAMEWORK) generate_export_header(framework BASE_NAME "CELIX_FRAMEWORK" EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/celix/gen/includes/framework/celix_framework_export.h") + configure_file("${CMAKE_CURRENT_LIST_DIR}/src/celix_framework_version.h.in" + "${CMAKE_BINARY_DIR}/celix/gen/includes/framework/celix_framework_version.h") target_include_directories(framework PUBLIC $) celix_deprecated_utils_headers(framework) diff --git a/libs/framework/error_injector/celix_bundle/CMakeLists.txt b/libs/framework/error_injector/celix_bundle/CMakeLists.txt index 97eb8e2cb..3b921b210 100644 --- a/libs/framework/error_injector/celix_bundle/CMakeLists.txt +++ b/libs/framework/error_injector/celix_bundle/CMakeLists.txt @@ -24,5 +24,6 @@ target_link_libraries(bundle_ei PRIVATE Celix::framework) target_link_options(bundle_ei INTERFACE LINKER:--wrap,celix_bundle_getSymbolicName LINKER:--wrap,celix_bundle_getManifestValue + LINKER:--wrap,celix_bundle_getVersion ) add_library(Celix::bundle_ei ALIAS bundle_ei) diff --git a/libs/framework/error_injector/celix_bundle/include/celix_bundle_ei.h b/libs/framework/error_injector/celix_bundle/include/celix_bundle_ei.h index 5f8d00710..eac78c27e 100644 --- a/libs/framework/error_injector/celix_bundle/include/celix_bundle_ei.h +++ b/libs/framework/error_injector/celix_bundle/include/celix_bundle_ei.h @@ -23,11 +23,14 @@ extern "C" { #endif #include "celix_error_injector.h" +#include "celix_version_type.h" CELIX_EI_DECLARE(celix_bundle_getSymbolicName, const char*); CELIX_EI_DECLARE(celix_bundle_getManifestValue, const char*); +CELIX_EI_DECLARE(celix_bundle_getVersion, const celix_version_t*); + #ifdef __cplusplus } #endif diff --git a/libs/framework/error_injector/celix_bundle/src/celix_bundle_ei.cc b/libs/framework/error_injector/celix_bundle/src/celix_bundle_ei.cc index e2e04cf89..1aab86c42 100644 --- a/libs/framework/error_injector/celix_bundle/src/celix_bundle_ei.cc +++ b/libs/framework/error_injector/celix_bundle/src/celix_bundle_ei.cc @@ -21,18 +21,25 @@ extern "C" { -const char *__real_celix_bundle_getSymbolicName(const celix_bundle_t *bnd); +const char* __real_celix_bundle_getSymbolicName(const celix_bundle_t* bnd); CELIX_EI_DEFINE(celix_bundle_getSymbolicName, const char*) -const char *__wrap_celix_bundle_getSymbolicName(const celix_bundle_t *bnd) { +const char* __wrap_celix_bundle_getSymbolicName(const celix_bundle_t* bnd) { CELIX_EI_IMPL(celix_bundle_getSymbolicName); return __real_celix_bundle_getSymbolicName(bnd); } -const char *__real_celix_bundle_getManifestValue(const celix_bundle_t *bnd, const char *attribute); +const char* __real_celix_bundle_getManifestValue(const celix_bundle_t* bnd, const char* attribute); CELIX_EI_DEFINE(celix_bundle_getManifestValue, const char*) -const char *__wrap_celix_bundle_getManifestValue(const celix_bundle_t *bnd, const char *attribute) { +const char* __wrap_celix_bundle_getManifestValue(const celix_bundle_t* bnd, const char* attribute) { CELIX_EI_IMPL(celix_bundle_getManifestValue); return __real_celix_bundle_getManifestValue(bnd, attribute); } +const celix_version_t* __real_celix_bundle_getVersion(const celix_bundle_t* bnd); +CELIX_EI_DEFINE(celix_bundle_getVersion, const celix_version_t*) +const celix_version_t* __wrap_celix_bundle_getVersion(const celix_bundle_t* bnd) { + CELIX_EI_IMPL(celix_bundle_getVersion); + return __real_celix_bundle_getVersion(bnd); +} + } diff --git a/libs/framework/gtest/CMakeLists.txt b/libs/framework/gtest/CMakeLists.txt index 3efab0dac..3a5016756 100644 --- a/libs/framework/gtest/CMakeLists.txt +++ b/libs/framework/gtest/CMakeLists.txt @@ -19,12 +19,14 @@ add_celix_bundle(simple_test_bundle1 NO_ACTIVATOR VERSION 1.0.0) celix_bundle_name(simple_test_bundle1 "Simple Test Bundle") celix_bundle_group(simple_test_bundle1 "test/group") celix_bundle_description(simple_test_bundle1 "Test Description") +celix_bundle_headers(simple_test_bundle1 "Extra-Header1: value1" "Extra-Header2: value2") +celix_bundle_headers(simple_test_bundle1 "Extra-Header3: value3") add_celix_bundle(dup_symbolic_name_bundle NO_ACTIVATOR VERSION 1.0.0 SYMBOLIC_NAME simple_test_bundle1) 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 src/nop_activator.c VERSION 1.0.0) +add_celix_bundle(bundle_with_exception SOURCES src/activator_with_exception.c VERSION 1.0.0) add_celix_bundle(bundle_with_bad_export NO_ACTIVATOR VERSION 1.0.0) celix_bundle_headers(bundle_with_bad_export "Export-Library: $") add_celix_bundle(simple_cxx_bundle SOURCES src/HelloWorldCxxActivator.cc VERSION 1.0.0) @@ -36,7 +38,7 @@ add_subdirectory(subdir) #simple_test_bundle4, simple_test_bundle5 and sublib add_celix_bundle(celix_err_test_bundle SOURCES src/activator_with_celix_err.c VERSION 1.0.0) add_celix_bundle(immediate_stop_bundle SOURCES src/activator_stop.c VERSION 1.0.0) -add_celix_bundle(unresolvable_bundle SOURCES src/nop_activator.c VERSION 1.0.0) +add_celix_bundle(unresolvable_bundle SOURCES src/activator_with_exception.c VERSION 1.0.0) if (CMAKE_BUILD_TYPE STREQUAL "Debug") set(POSTFIX ${CMAKE_DEBUG_POSTFIX}) endif() @@ -49,7 +51,6 @@ add_dependencies(unresolvable_bundle sublib) set(CELIX_FRAMEWORK_TEST_SOURCES src/CelixFrameworkTestSuite.cc src/CelixFrameworkUtilsTestSuite.cc - src/MultipleFrameworkTestSuite.cc src/CelixBundleContextBundlesTestSuite.cc src/CelixBundleContextServicesTestSuite.cc src/DependencyManagerTestSuite.cc diff --git a/libs/framework/gtest/src/BundleArchiveTestSuite.cc b/libs/framework/gtest/src/BundleArchiveTestSuite.cc index 59cc1c1c5..1f3dd5401 100644 --- a/libs/framework/gtest/src/BundleArchiveTestSuite.cc +++ b/libs/framework/gtest/src/BundleArchiveTestSuite.cc @@ -28,8 +28,7 @@ //including private headers, which should only be used for testing #include "bundle_archive_private.h" -#include "bundle_private.h" - +#include "celix_bundle_private.h" class CxxBundleArchiveTestSuite : public ::testing::Test { public: diff --git a/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc b/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc index 47819d81e..d1b17689f 100644 --- a/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc +++ b/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc @@ -36,7 +36,7 @@ #include "bundle_revision_private.h" #include "framework_private.h" #include "malloc_ei.h" -#include "manifest.h" +#include "celix_bundle_manifest.h" #include "stat_ei.h" #include "unistd_ei.h" @@ -111,7 +111,7 @@ TEST_F(BundleArchiveWithErrorInjectionTestSuite, BundleArchiveCreatedFailedTest) teardownErrorInjectors(); // Given a mocked malloc which returns NULL from a call from manifest_create - celix_ei_expect_malloc((void*)manifest_create, 0, nullptr); + celix_ei_expect_calloc((void*)celix_bundleManifest_create, 0, nullptr); installBundleAndExpectFailure(); teardownErrorInjectors(); diff --git a/libs/framework/gtest/src/CelixBundleCacheErrorInjectionTestSuite.cc b/libs/framework/gtest/src/CelixBundleCacheErrorInjectionTestSuite.cc index 9745da35f..44a9c1d18 100644 --- a/libs/framework/gtest/src/CelixBundleCacheErrorInjectionTestSuite.cc +++ b/libs/framework/gtest/src/CelixBundleCacheErrorInjectionTestSuite.cc @@ -36,7 +36,7 @@ #include "bundle_revision_private.h" #include "framework_private.h" #include "malloc_ei.h" -#include "manifest.h" +#include "celix_bundle_manifest.h" #include "unistd_ei.h" class CelixBundleCacheErrorInjectionTestSuite : public ::testing::Test { @@ -144,7 +144,7 @@ TEST_F(CelixBundleCacheErrorInjectionTestSuite, SystemArchiveCreateErrorTest) { EXPECT_EQ(CELIX_ENOMEM, celix_bundleCache_createSystemArchive(&fw, &archive)); EXPECT_EQ(nullptr, archive); - celix_ei_expect_malloc((void*)manifest_create, 0, nullptr); + celix_ei_expect_celix_properties_create((void*)celix_bundleManifest_createFrameworkManifest, 0, nullptr); EXPECT_EQ(CELIX_ENOMEM, celix_bundleCache_createSystemArchive(&fw, &archive)); EXPECT_EQ(nullptr, archive); diff --git a/libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc b/libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc index 8a1c89336..e950ad89a 100644 --- a/libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc +++ b/libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc @@ -58,7 +58,7 @@ class CelixBundleContextBundlesTestSuite : public ::testing::Test { fw = celix_frameworkFactory_createFramework(properties); - ctx = framework_getContext(fw); + ctx = celix_framework_getFrameworkContext(fw); } ~CelixBundleContextBundlesTestSuite() override { @@ -892,7 +892,7 @@ class CelixBundleContextTempBundlesTestSuite : public ::testing::Test { celix_properties_setBool(properties, CELIX_FRAMEWORK_CACHE_USE_TMP_DIR, true); fw = celix_frameworkFactory_createFramework(properties); EXPECT_NE(fw, nullptr); - ctx = framework_getContext(fw); + ctx = celix_framework_getFrameworkContext(fw); EXPECT_NE(ctx, nullptr); } diff --git a/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc b/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc index 529c176ce..43689eaa9 100644 --- a/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc +++ b/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc @@ -50,7 +50,7 @@ class CelixBundleContextServicesTestSuite : public ::testing::Test { celix_properties_setLong(properties, CELIX_FRAMEWORK_STATIC_EVENT_QUEUE_SIZE, 256); //ensure that the floodEventLoopTest overflows the static event queue size fw = celix_frameworkFactory_createFramework(properties); - ctx = framework_getContext(fw); + ctx = celix_framework_getFrameworkContext(fw); celix_err_resetErrors(); } diff --git a/libs/framework/gtest/src/CxxBundleContextTestSuite.cc b/libs/framework/gtest/src/CxxBundleContextTestSuite.cc index b987d28b8..d8f5b9b80 100644 --- a/libs/framework/gtest/src/CxxBundleContextTestSuite.cc +++ b/libs/framework/gtest/src/CxxBundleContextTestSuite.cc @@ -696,10 +696,10 @@ TEST_F(CxxBundleContextTestSuite, CheckStandardServiceProperties) { TEST_F(CxxBundleContextTestSuite, GetBundleInformation) { - EXPECT_EQ(ctx->getBundle().getSymbolicName(), std::string{"celix_framework"}); - EXPECT_EQ(ctx->getBundle().getName(), std::string{"Celix Framework"}); + EXPECT_EQ(ctx->getBundle().getSymbolicName(), std::string{"apache_celix_framework"}); + EXPECT_EQ(ctx->getBundle().getName(), std::string{"Apache Celix Framework"}); EXPECT_EQ(ctx->getBundle().getGroup(), std::string{"Celix/Framework"}); - EXPECT_EQ(ctx->getBundle().getDescription(), std::string{"The Celix Framework System Bundle"}); + EXPECT_EQ(ctx->getBundle().getDescription(), std::string{"The Apache Celix Framework System Bundle"}); EXPECT_EQ(ctx->getBundle().getLocation(), std::string{""}); std::atomic startCalled{false}; @@ -710,10 +710,10 @@ TEST_F(CxxBundleContextTestSuite, GetBundleInformation) { EXPECT_EQ(bnd.getGroup(), std::string{"test/group"}); EXPECT_EQ(bnd.getDescription(), std::string{"Test Description"}); EXPECT_TRUE(strstr(bnd.getLocation().c_str(), ".zip") != nullptr); - EXPECT_TRUE(!bnd.getEntry("META-INF/MANIFEST.MF").empty()); - EXPECT_EQ(bnd.getEntry("/META-INF/MANIFEST.MF"), bnd.getEntry("META-INF/MANIFEST.MF")); + EXPECT_TRUE(!bnd.getEntry("META-INF/MANIFEST.json").empty()); + EXPECT_EQ(bnd.getEntry("/META-INF/MANIFEST.json"), bnd.getEntry("META-INF/MANIFEST.json")); EXPECT_EQ(bnd.getEntry("does-not-exist"), std::string{}); - EXPECT_EQ(bnd.getManifestValue("Bundle-SymbolicName"), std::string{"simple_test_bundle1"}); + EXPECT_EQ(bnd.getManifestValue("Extra-Header1"), std::string{"value1"}); EXPECT_EQ(bnd.getManifestValue("non-existing"), std::string{}); startCalled = true; }) diff --git a/libs/framework/gtest/src/DependencyManagerTestSuite.cc b/libs/framework/gtest/src/DependencyManagerTestSuite.cc index 7c9ac5dc2..726464c78 100644 --- a/libs/framework/gtest/src/DependencyManagerTestSuite.cc +++ b/libs/framework/gtest/src/DependencyManagerTestSuite.cc @@ -261,7 +261,7 @@ TEST_F(DependencyManagerTestSuite, CxxDmGetInfo) { auto info = mng.getInfo(); EXPECT_EQ(info.bndId, 0); - EXPECT_EQ(info.bndSymbolicName, "celix_framework"); + EXPECT_EQ(info.bndSymbolicName, "apache_celix_framework"); EXPECT_EQ(info.components.size(), 0); //not build yet mng.build(); diff --git a/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc b/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc index ae64656b4..7813efe63 100644 --- a/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc +++ b/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc @@ -19,158 +19,45 @@ */ #include -#include -#include #include "celix_err.h" #include "celix_properties_ei.h" -#include "celix_stdio_cleanup.h" -#include "celix_utils_ei.h" -#include "hmap_ei.h" #include "malloc_ei.h" -#include "manifest.h" -#include "stdio_ei.h" -#include "string_ei.h" +#include "celix_bundle_manifest.h" class ManifestErrorInjectionTestSuite : public ::testing::Test { public: - ManifestErrorInjectionTestSuite() { - } + ManifestErrorInjectionTestSuite() = default; ~ManifestErrorInjectionTestSuite() override { teardownErrorInjectors(); } - void teardownErrorInjectors() { - celix_ei_expect_malloc(nullptr, 0, nullptr); - celix_ei_expect_celix_properties_create(nullptr, 0, nullptr); - celix_ei_expect_celix_properties_copy(nullptr, 0, nullptr); - celix_ei_expect_hashMap_create(nullptr, 0, nullptr); - celix_ei_expect_celix_utils_strdup(nullptr, 0, nullptr); - celix_ei_expect_fseek(nullptr, 0, -1); - celix_ei_expect_ftell(nullptr, 0, -1); - celix_ei_expect_fread(nullptr, 0, 0); - celix_ei_expect_strndup(nullptr, 0, nullptr); + + static void teardownErrorInjectors() { + celix_ei_expect_calloc(nullptr, 0, nullptr); } }; TEST_F(ManifestErrorInjectionTestSuite, NoMemoryForManifestCreateTest) { - manifest_pt manifest = nullptr; - celix_ei_expect_malloc((void*)manifest_create, 0, nullptr); - celix_status_t status = manifest_create(&manifest); + celix_bundle_manifest_t* manifest = nullptr; + celix_ei_expect_calloc((void*)celix_bundleManifest_create, 0, nullptr); + celix_properties_t* attributes = celix_properties_create(); + ASSERT_NE(nullptr, attributes); + celix_status_t status = celix_bundleManifest_create(attributes, &manifest); EXPECT_EQ(CELIX_ENOMEM, status); EXPECT_EQ(nullptr, manifest); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); - teardownErrorInjectors(); + celix_err_printErrors(stdout, "Errors are expected [", "]\n"); +} - manifest = nullptr; - celix_ei_expect_celix_properties_create((void*)manifest_create, 0, nullptr); - status = manifest_create(&manifest); +TEST_F(ManifestErrorInjectionTestSuite, NoMemoryForFrameworkManifestCreateTest) { + celix_bundle_manifest_t* manifest = nullptr; + celix_ei_expect_celix_properties_create((void*)celix_bundleManifest_createFrameworkManifest, 0, nullptr); + auto status = celix_bundleManifest_createFrameworkManifest(&manifest); EXPECT_EQ(CELIX_ENOMEM, status); - EXPECT_EQ(nullptr, manifest); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); - teardownErrorInjectors(); - manifest = nullptr; - celix_ei_expect_hashMap_create((void*)manifest_create, 0, nullptr); - status = manifest_create(&manifest); + celix_ei_expect_celix_properties_set((void*)celix_bundleManifest_createFrameworkManifest, 0, CELIX_ENOMEM, 3); + status = celix_bundleManifest_createFrameworkManifest(&manifest); EXPECT_EQ(CELIX_ENOMEM, status); - EXPECT_EQ(nullptr, manifest); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); - teardownErrorInjectors(); -} - -TEST_F(ManifestErrorInjectionTestSuite, NoMemoryForManifestCloneTest) { - std::string content = "Manifest-Version: 1.0\n" - "DeploymentPackage-Icon: %icon\n" - "DeploymentPackage-SymbolicName: com.third._3d\n" - "DeploymentPacakge-Version: 1.2.3.build22032005\n" - "\n" - "Name: bundles/3dlib.jar\n" - "SHA1-Digest: MOez1l4gXHBo8ycYdAxstK3UvEg=\n" - "Bundle-SymbolicName: com.third._3d\n" - "Bundle-Version: 2.3.1\n" - "\n" - "Name: bundles/3dnative.jar\n" - "SHA1-Digest: N8Ow2UY4yjnHZv5zeq2I1Uv/+uE=\n" - "Bundle-SymbolicName: com.third._3d.native\n" - "Bundle-Version: 1.5.3\n" - "\n"; - celix_autoptr(FILE) manifestFile = fmemopen((void*)content.c_str(), content.size(), "r"); - celix_auto(manifest_pt) manifest = nullptr; - manifest_create(&manifest); - EXPECT_EQ(CELIX_SUCCESS, manifest_readFromStream(manifest, manifestFile)); - celix_ei_expect_malloc((void*)manifest_create, 0, nullptr); - EXPECT_EQ(nullptr, manifest_clone(manifest)); - teardownErrorInjectors(); - - celix_ei_expect_celix_utils_strdup((void*)manifest_clone, 0, nullptr); - EXPECT_EQ(nullptr, manifest_clone(manifest)); - teardownErrorInjectors(); - celix_ei_expect_celix_properties_copy((void*)manifest_clone, 0, nullptr); - EXPECT_EQ(nullptr, manifest_clone(manifest)); - teardownErrorInjectors(); + celix_err_printErrors(stdout, "Errors are expected [", "]\n"); } - -TEST_F(ManifestErrorInjectionTestSuite, ReadFromStreamErrorTest) { - std::string content = "Manifest-Version: 1.0\n" - "DeploymentPackage-Icon: %icon\n" - "DeploymentPackage-SymbolicName: com.third._3d\n" - "DeploymentPacakge-Version: 1.2.3.build22032005\n" - "\n" - "Name: bundles/3dlib.jar\n" - "SHA1-Digest: MOez1l4gXHBo8ycYdAxstK3UvEg=\n" - "Bundle-SymbolicName: com.third._3d\n" - "Bundle-Version: 2.3.1\n" - "\n" - "Name: bundles/3dnative.jar\n" - "SHA1-Digest: N8Ow2UY4yjnHZv5zeq2I1Uv/+uE=\n" - "Bundle-SymbolicName: com.third._3d.native\n" - "Bundle-Version: 1.5.3\n" - "\n" - "Name: bundles/3dnative1.jar\n" - "SHA1-Digest: N8Ow2UY4yjnHZv5zeq2I1Uv/+uF=\n" - "Bundle-SymbolicName: com.third._3d.native1\n" - "Bundle-Version: 1.5.4\n" - "\n"; - celix_autoptr(FILE) manifestFile = fmemopen((void*)content.c_str(), content.size(), "r"); - celix_auto(manifest_pt) manifest = nullptr; - manifest_create(&manifest); - celix_ei_expect_fseek((void*)manifest_readFromStream, 0, -1); - EXPECT_EQ(EACCES, manifest_readFromStream(manifest, manifestFile)); - teardownErrorInjectors(); - - celix_ei_expect_ftell((void*)manifest_readFromStream, 0, -1); - EXPECT_EQ(EACCES, manifest_readFromStream(manifest, manifestFile)); - teardownErrorInjectors(); - - celix_ei_expect_ftell((void*)manifest_readFromStream, 0, (long)INT_MAX+1); - EXPECT_EQ(CELIX_BUNDLE_EXCEPTION, manifest_readFromStream(manifest, manifestFile)); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); - teardownErrorInjectors(); - - celix_ei_expect_malloc((void*)manifest_readFromStream, 0, nullptr); - EXPECT_EQ(CELIX_ENOMEM, manifest_readFromStream(manifest, manifestFile)); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); - teardownErrorInjectors(); - - celix_ei_expect_fread((void*)manifest_readFromStream, 0, 1); - EXPECT_EQ(CELIX_FILE_IO_EXCEPTION, manifest_readFromStream(manifest, manifestFile)); - teardownErrorInjectors(); - - for (int i = 0; i < 3; ++i) { - celix_auto(manifest_pt) mfs = nullptr; - manifest_create(&mfs); - celix_ei_expect_celix_utils_strdup((void*)manifest_readFromStream, 0, nullptr, i+1); - EXPECT_EQ(CELIX_ENOMEM, manifest_readFromStream(mfs, manifestFile)); - teardownErrorInjectors(); - } - - for (int i = 0; i < 3; ++i) { - celix_auto(manifest_pt) mfs = nullptr; - manifest_create(&mfs); - celix_ei_expect_celix_properties_create((void*)manifest_readFromStream, 0, nullptr, i+1); - EXPECT_EQ(CELIX_ENOMEM, manifest_readFromStream(mfs, manifestFile)); - teardownErrorInjectors(); - } -} \ No newline at end of file diff --git a/libs/framework/gtest/src/ManifestTestSuite.cc b/libs/framework/gtest/src/ManifestTestSuite.cc index 7c96903be..6dbce620b 100644 --- a/libs/framework/gtest/src/ManifestTestSuite.cc +++ b/libs/framework/gtest/src/ManifestTestSuite.cc @@ -19,284 +19,219 @@ */ #include -#include -#include +#include "celix_bundle_manifest.h" #include "celix_err.h" -#include "celix_stdio_cleanup.h" -#include "manifest.h" +#include "celix_properties.h" +#include "celix_stdlib_cleanup.h" +#include "celix_framework_version.h" +#include "celix_version.h" class ManifestTestSuite : public ::testing::Test { -protected: - manifest_pt manifest = nullptr; - void SetUp() override { - ASSERT_EQ(CELIX_SUCCESS, manifest_create(&manifest)); - } - void TearDown() override { - manifest_destroy(manifest); - celix_err_resetErrors(); - } - void CheckPropertiesEqual(const celix_properties_t* prop1, const celix_properties_t* prop2) { - EXPECT_EQ(celix_properties_size(prop1), celix_properties_size(prop2)); - CELIX_PROPERTIES_ITERATE(prop1, iter) { - EXPECT_STREQ(celix_properties_get(prop1, iter.key, nullptr), celix_properties_get(prop2, iter.key, nullptr)); - } - } - void CheckManifestEqual(const manifest_pt manifest1, const manifest_pt manifest2) { - CheckPropertiesEqual(manifest_getMainAttributes(manifest1), manifest_getMainAttributes(manifest2)); - hash_map_pt entries1 = nullptr; - EXPECT_EQ(CELIX_SUCCESS, manifest_getEntries(manifest1, &entries1)); - hash_map_pt entries2 = nullptr; - EXPECT_EQ(CELIX_SUCCESS, manifest_getEntries(manifest2, &entries2)); - EXPECT_EQ(hashMap_size(entries1), hashMap_size(entries2)); - hash_map_iterator_t iter = hashMapIterator_construct(entries1); - while (hashMapIterator_hasNext(&iter)) { - hash_map_entry_pt entry = hashMapIterator_nextEntry(&iter); - celix_properties_t* value1 = (celix_properties_t*)hashMapEntry_getValue(entry); - celix_properties_t* value2 = (celix_properties_t*)hashMap_get(entries2, hashMapEntry_getKey(entry)); - CheckPropertiesEqual(value1, value2); - } + public: + ManifestTestSuite() { celix_err_resetErrors(); } + + static celix_properties_t* createAttributes(const char* manifestVersion, + const char* bundleVersion, + const char* bundleName, + const char* symbolicName) { + celix_properties_t* properties = celix_properties_create(); + auto mVer = celix_version_createVersionFromString(manifestVersion); + auto bVer = celix_version_createVersionFromString(bundleVersion); + celix_properties_assignVersion(properties, "CELIX_BUNDLE_MANIFEST_VERSION", mVer); + celix_properties_assignVersion(properties, "CELIX_BUNDLE_VERSION", bVer); + celix_properties_set(properties, "CELIX_BUNDLE_NAME", bundleName); + celix_properties_set(properties, "CELIX_BUNDLE_SYMBOLIC_NAME", symbolicName); + return properties; } }; -TEST_F(ManifestTestSuite, EmptyManifestTest) { - const celix_properties_t* mainAttr = manifest_getMainAttributes(manifest); - EXPECT_EQ(0, celix_properties_size(mainAttr)); - hash_map_pt entries = nullptr; - EXPECT_EQ(CELIX_SUCCESS, manifest_getEntries(manifest, &entries)); - EXPECT_NE(nullptr, entries); - EXPECT_EQ(0, hashMap_size(entries)); +TEST_F(ManifestTestSuite, CreateManifestTest) { + //Given a properties set with all the mandatory manifest attributes + celix_properties_t *properties = celix_properties_create(); + auto* v = celix_version_create(2, 0, 0, nullptr); + celix_properties_assignVersion(properties, "CELIX_BUNDLE_MANIFEST_VERSION", v); + auto* bv = celix_version_create(1, 0, 0, nullptr); + celix_properties_assignVersion(properties, "CELIX_BUNDLE_VERSION", bv); + celix_properties_set(properties, "CELIX_BUNDLE_NAME", "my_bundle"); + celix_properties_set(properties, "CELIX_BUNDLE_SYMBOLIC_NAME", "celix_my_bundle"); + + //When creating a manifest from the attributes + celix_autoptr(celix_bundle_manifest_t) manifest = nullptr; + celix_status_t status = celix_bundleManifest_create(properties, &manifest); + + //Then the creation is successful + ASSERT_EQ(CELIX_SUCCESS, status); + EXPECT_EQ(4, celix_properties_size(celix_bundleManifest_getAttributes(manifest))); } -TEST_F(ManifestTestSuite, ReadManifestWithoutNameSectionsTest) { - std::string content = "Manifest-Version: 1.0\n" - "DeploymentPackage-SymbolicName: com.third._3d\n" - "DeploymentPacakge-Version: 1.2.3.build22032005\n" - "DeploymentPackage-Copyright: ACME Inc. (c) 2003\n"; - celix_autoptr(FILE) manifestFile = fmemopen((void*)content.c_str(), content.size(), "r"); - EXPECT_EQ(CELIX_SUCCESS, manifest_readFromStream(manifest, manifestFile)); - const celix_properties_t* mainAttr = manifest_getMainAttributes(manifest); - EXPECT_EQ(4, celix_properties_size(mainAttr)); - EXPECT_STREQ("1.0", celix_properties_get(mainAttr, "Manifest-Version", nullptr)); - EXPECT_STREQ("com.third._3d", celix_properties_get(mainAttr, "DeploymentPackage-SymbolicName", nullptr)); - EXPECT_STREQ("1.2.3.build22032005", celix_properties_get(mainAttr, "DeploymentPacakge-Version", nullptr)); - EXPECT_STREQ("ACME Inc. (c) 2003", celix_properties_get(mainAttr, "DeploymentPackage-Copyright", nullptr)); - hash_map_pt entries = nullptr; - EXPECT_EQ(CELIX_SUCCESS, manifest_getEntries(manifest, &entries)); - EXPECT_NE(nullptr, entries); - EXPECT_EQ(0, hashMap_size(entries)); -} +TEST_F(ManifestTestSuite, InvalidArgumentTest) { + celix_bundle_manifest_t* man = nullptr; + auto status = celix_bundleManifest_create(nullptr, &man); + EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); -TEST_F(ManifestTestSuite, ReadManifestWithCarriageReturnTest) { - std::string content = "Manifest-Version: 1.0\r\n" - "DeploymentPackage-SymbolicName: com.third._3d\r\n" - "DeploymentPacakge-Version: 1.2.3.build22032005\r\n" - "DeploymentPackage-Copyright: ACME Inc. (c) 2003\r\n"; - celix_autoptr(FILE) manifestFile = fmemopen((void*)content.c_str(), content.size(), "r"); - EXPECT_EQ(CELIX_SUCCESS, manifest_readFromStream(manifest, manifestFile)); - const celix_properties_t* mainAttr = manifest_getMainAttributes(manifest); - EXPECT_EQ(4, celix_properties_size(mainAttr)); - EXPECT_STREQ("1.0", celix_properties_get(mainAttr, "Manifest-Version", nullptr)); - EXPECT_STREQ("com.third._3d", celix_properties_get(mainAttr, "DeploymentPackage-SymbolicName", nullptr)); - EXPECT_STREQ("1.2.3.build22032005", celix_properties_get(mainAttr, "DeploymentPacakge-Version", nullptr)); - EXPECT_STREQ("ACME Inc. (c) 2003", celix_properties_get(mainAttr, "DeploymentPackage-Copyright", nullptr)); - hash_map_pt entries = nullptr; - EXPECT_EQ(CELIX_SUCCESS, manifest_getEntries(manifest, &entries)); - EXPECT_NE(nullptr, entries); - EXPECT_EQ(0, hashMap_size(entries)); + status = celix_bundleManifest_createFromFile("invalid-file", &man); + EXPECT_EQ(CELIX_FILE_IO_EXCEPTION, status); } -TEST_F(ManifestTestSuite, ReadManifestWithLineContinuationTest) { - std::string content = "Manifest-Version: 1.0\n" - "DeploymentPackage-SymbolicName: com.third._3d\n" - " x\n" /* line continuation */ - "DeploymentPacakge-Version: 1.2.3.build22032005\n" - "DeploymentPackage-Copyright: ACME Inc. (c) 2003\n"; - celix_autoptr(FILE) manifestFile = fmemopen((void*)content.c_str(), content.size(), "r"); - EXPECT_EQ(CELIX_SUCCESS, manifest_readFromStream(manifest, manifestFile)); - const celix_properties_t* mainAttr = manifest_getMainAttributes(manifest); - EXPECT_EQ(4, celix_properties_size(mainAttr)); - EXPECT_STREQ("1.0", celix_properties_get(mainAttr, "Manifest-Version", nullptr)); - EXPECT_STREQ("com.third._3dx", celix_properties_get(mainAttr, "DeploymentPackage-SymbolicName", nullptr)); - EXPECT_STREQ("1.2.3.build22032005", celix_properties_get(mainAttr, "DeploymentPacakge-Version", nullptr)); - EXPECT_STREQ("ACME Inc. (c) 2003", celix_properties_get(mainAttr, "DeploymentPackage-Copyright", nullptr)); - hash_map_pt entries = nullptr; - EXPECT_EQ(CELIX_SUCCESS, manifest_getEntries(manifest, &entries)); - EXPECT_NE(nullptr, entries); - EXPECT_EQ(0, hashMap_size(entries)); -} +TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) { + //Given an empty properties set + celix_properties_t *properties = celix_properties_create(); -TEST_F(ManifestTestSuite, ReadManifestWithoutNewlineInLastLineTest) { - std::string content = "Manifest-Version: 1.0\n" - "DeploymentPackage-SymbolicName: com.third._3d\n" - "DeploymentPacakge-Version: 1.2.3.build22032005\n" - "DeploymentPackage-Copyright: ACME Inc. (c) 2003"; - celix_autoptr(FILE) manifestFile = fmemopen((void*)content.c_str(), content.size(), "r"); - EXPECT_EQ(CELIX_SUCCESS, manifest_readFromStream(manifest, manifestFile)); - const celix_properties_t* mainAttr = manifest_getMainAttributes(manifest); - EXPECT_EQ(4, celix_properties_size(mainAttr)); - EXPECT_STREQ("1.0", celix_properties_get(mainAttr, "Manifest-Version", nullptr)); - EXPECT_STREQ("com.third._3d", celix_properties_get(mainAttr, "DeploymentPackage-SymbolicName", nullptr)); - EXPECT_STREQ("1.2.3.build22032005", celix_properties_get(mainAttr, "DeploymentPacakge-Version", nullptr)); - EXPECT_STREQ("ACME Inc. (c) 2003", celix_properties_get(mainAttr, "DeploymentPackage-Copyright", nullptr)); - hash_map_pt entries = nullptr; - EXPECT_EQ(CELIX_SUCCESS, manifest_getEntries(manifest, &entries)); - EXPECT_NE(nullptr, entries); - EXPECT_EQ(0, hashMap_size(entries)); -} + //When creating a manifest from the attributes + celix_autoptr(celix_bundle_manifest_t) manifest = nullptr; + celix_status_t status = celix_bundleManifest_create(properties, &manifest); -TEST_F(ManifestTestSuite, ReadManifestWithNameSectionsTest) { - std::string content = "Manifest-Version: 1.0\n" - "DeploymentPackage-Icon: %icon\n" - "DeploymentPackage-SymbolicName: com.third._3d\n" - "DeploymentPacakge-Version: 1.2.3.build22032005\n" - "\n" - "Name: bundles/3dlib.jar\n" - "SHA1-Digest: MOez1l4gXHBo8ycYdAxstK3UvEg=\n" - "Bundle-SymbolicName: com.third._3d\n" - "Bundle-Version: 2.3.1\n" - "\n" - "Name: bundles/3dnative.jar\n" - "SHA1-Digest: N8Ow2UY4yjnHZv5zeq2I1Uv/+uE=\n" - "Bundle-SymbolicName: com.third._3d.native\n" - "Bundle-Version: 1.5.3\n" - "\n" - "Name: bundles/3dnative1.jar\n" - "SHA1-Digest: N8Ow2UY4yjnHZv5zeq2I1Uv/+uF=\n" - "Bundle-SymbolicName: com.third._3d.native1\n" - "Bundle-Version: 1.5.4\n" - "\n"; - celix_autoptr(FILE) manifestFile = fmemopen((void*)content.c_str(), content.size(), "r"); - EXPECT_EQ(CELIX_SUCCESS, manifest_readFromStream(manifest, manifestFile)); - const celix_properties_t* mainAttr = manifest_getMainAttributes(manifest); - EXPECT_EQ(4, celix_properties_size(mainAttr)); - EXPECT_STREQ("1.0", celix_properties_get(mainAttr, "Manifest-Version", nullptr)); - EXPECT_STREQ("%icon", celix_properties_get(mainAttr, "DeploymentPackage-Icon", nullptr)); - EXPECT_STREQ("com.third._3d", celix_properties_get(mainAttr, "DeploymentPackage-SymbolicName", nullptr)); - EXPECT_STREQ("1.2.3.build22032005", celix_properties_get(mainAttr, "DeploymentPacakge-Version", nullptr)); - hash_map_pt entries = nullptr; - EXPECT_EQ(CELIX_SUCCESS, manifest_getEntries(manifest, &entries)); - EXPECT_NE(nullptr, entries); - EXPECT_EQ(3, hashMap_size(entries)); - - const celix_properties_t* entry1 = (const celix_properties_t*)hashMap_get(entries, "bundles/3dlib.jar"); - EXPECT_EQ(4, celix_properties_size(entry1)); - EXPECT_STREQ("MOez1l4gXHBo8ycYdAxstK3UvEg=", celix_properties_get(entry1, "SHA1-Digest", nullptr)); - EXPECT_STREQ("com.third._3d", celix_properties_get(entry1, "Bundle-SymbolicName", nullptr)); - EXPECT_STREQ("2.3.1", celix_properties_get(entry1, "Bundle-Version", nullptr)); - - const celix_properties_t* entry2 = (const celix_properties_t*)hashMap_get(entries, "bundles/3dnative.jar"); - EXPECT_EQ(4, celix_properties_size(entry2)); - EXPECT_STREQ("N8Ow2UY4yjnHZv5zeq2I1Uv/+uE=", celix_properties_get(entry2, "SHA1-Digest", nullptr)); - EXPECT_STREQ("com.third._3d.native", celix_properties_get(entry2, "Bundle-SymbolicName", nullptr)); - EXPECT_STREQ("1.5.3", celix_properties_get(entry2, "Bundle-Version", nullptr)); -} + //Then the creation fails + EXPECT_EQ(CELIX_INVALID_SYNTAX, status); -TEST_F(ManifestTestSuite, CleanupTest) { - celix_auto(manifest_pt) manifest2 = nullptr; - EXPECT_EQ(CELIX_SUCCESS, manifest_create(&manifest2)); - celix_auto(manifest_pt) manifest3 = nullptr; - EXPECT_EQ(CELIX_SUCCESS, manifest_create(&manifest3)); - EXPECT_EQ(CELIX_SUCCESS, manifest_destroy(celix_steal_ptr(manifest3))); -} + //And 4 celix err log entries are logged (4 missing attributes) + EXPECT_EQ(celix_err_getErrorCount(), 4); + celix_err_printErrors(stdout, "Expect Errors: ", nullptr); -TEST_F(ManifestTestSuite, CloneTest) { - std::string content = "Manifest-Version: 1.0\n" - "DeploymentPackage-Icon: %icon\n" - "DeploymentPackage-SymbolicName: com.third._3d\n" - "DeploymentPacakge-Version: 1.2.3.build22032005\n" - "\n" - "Name: bundles/3dlib.jar\n" - "SHA1-Digest: MOez1l4gXHBo8ycYdAxstK3UvEg=\n" - "Bundle-SymbolicName: com.third._3d\n" - "Bundle-Version: 2.3.1\n" - "\n" - "Name: bundles/3dnative.jar\n" - "SHA1-Digest: N8Ow2UY4yjnHZv5zeq2I1Uv/+uE=\n" - "Bundle-SymbolicName: com.third._3d.native\n" - "Bundle-Version: 1.5.3\n" - "\n"; - celix_autoptr(FILE) manifestFile = fmemopen((void*)content.c_str(), content.size(), "r"); - EXPECT_EQ(CELIX_SUCCESS, manifest_readFromStream(manifest, manifestFile)); - celix_auto(manifest_pt) clone = manifest_clone(manifest); - CheckManifestEqual(manifest, clone); -} + //Given a properties set with not versions attributes for bundle/manifest version. + properties = celix_properties_create(); + celix_properties_set(properties, "CELIX_BUNDLE_VERSION", "not a version"); + celix_properties_setBool(properties, "CELIX_BUNDLE_MANIFEST_VERSION", false); + celix_properties_set(properties, "CELIX_BUNDLE_NAME", "my_bundle"); + celix_properties_set(properties, "CELIX_BUNDLE_SYMBOLIC_NAME", "celix_my_bundle"); -TEST_F(ManifestTestSuite, CreateFromNonexistingFile) { - celix_auto(manifest_pt) manifest2 = nullptr; - EXPECT_EQ(ENOENT, manifest_createFromFile("nonexisting", &manifest2)); - EXPECT_EQ(nullptr, manifest2); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); -} + //When creating a manifest from the attributes + celix_autoptr(celix_bundle_manifest_t) manifest2 = nullptr; + status = celix_bundleManifest_create(properties, &manifest2); -TEST_F(ManifestTestSuite, ManifestMissingSpaceSeparatorTest) { - std::string content = "Manifest-Version: 1.0\n" - "NoSeparator:%icon\n" - "DeploymentPackage-SymbolicName: com.third._3d\n" - "DeploymentPacakge-Version: 1.2.3.build22032005\n" - "\n"; - celix_autoptr(FILE) manifestFile = fmemopen((void*)content.c_str(), content.size(), "r"); - EXPECT_EQ(CELIX_INVALID_SYNTAX, manifest_readFromStream(manifest, manifestFile)); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); -} + //Then the creation fails + EXPECT_EQ(CELIX_INVALID_SYNTAX, status); -TEST_F(ManifestTestSuite, ManifestMissingAttributeNameTest) { - std::string content = "Manifest-Version: 1.0\n" - "%icon\n" - "DeploymentPackage-SymbolicName: com.third._3d\n" - "DeploymentPacakge-Version: 1.2.3.build22032005\n" - "\n"; - celix_autoptr(FILE) manifestFile = fmemopen((void*)content.c_str(), content.size(), "r"); - EXPECT_EQ(CELIX_INVALID_SYNTAX, manifest_readFromStream(manifest, manifestFile)); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); -} + //And 4 celix err log entries are logged (4x invalid versions) + EXPECT_EQ(celix_err_getErrorCount(), 2); + celix_err_printErrors(stdout, "Expect Errors: ", nullptr); -TEST_F(ManifestTestSuite, ManifestWithDuplicatedAttributeNameTest) { - std::string content = "Manifest-Version: 1.0\n" - "DeploymentPackage-Icon: %icon\n" - "DeploymentPackage-Icon: %icon\n" - "DeploymentPackage-SymbolicName: com.third._3d\n" - "DeploymentPacakge-Version: 1.2.3.build22032005\n" - "\n"; - celix_autoptr(FILE) manifestFile = fmemopen((void*)content.c_str(), content.size(), "r"); - EXPECT_EQ(CELIX_INVALID_SYNTAX, manifest_readFromStream(manifest, manifestFile)); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); + //Given a properties with an unsupported manifest version + properties = createAttributes("1.0.0" /* note must be 2.0.**/, "1.0.0", "my_bundle", "celix_my_bundle"); + + //When creating a manifest from the attributes + celix_autoptr(celix_bundle_manifest_t) manifest3 = nullptr; + status = celix_bundleManifest_create(properties, &manifest3); + + //Then the creation fails + EXPECT_EQ(CELIX_INVALID_SYNTAX, status); + + //And 1 celix err log entries is logged + EXPECT_EQ(celix_err_getErrorCount(), 1); + celix_err_printErrors(stdout, "Expect Errors: ", nullptr); + + //Given a properties set with an invalid private libraries list + properties = createAttributes("2.0.2", "1.0.0", "my_bundle", "celix_my_bundle"); + celix_properties_setBool(properties, "CELIX_BUNDLE_PRIVATE_LIBRARIES", true); + + //When creating a manifest from the attributes + celix_autoptr(celix_bundle_manifest_t) manifest4 = nullptr; + status = celix_bundleManifest_create(properties, &manifest4); + + //Then the creation fails + EXPECT_EQ(CELIX_INVALID_SYNTAX, status); + + //And 1 celix err log entries is logged + EXPECT_EQ(celix_err_getErrorCount(), 1); + celix_err_printErrors(stdout, "Expect Errors: ", nullptr); } -TEST_F(ManifestTestSuite, ManifestMissingNameAttributeTest) { - std::string content = "Manifest-Version: 1.0\n" - "DeploymentPackage-Icon: %icon\n" - "DeploymentPackage-SymbolicName: com.third._3d\n" - "DeploymentPacakge-Version: 1.2.3.build22032005\n" - "\n" - "SHA1-Digest: MOez1l4gXHBo8ycYdAxstK3UvEg=\n" - "Bundle-SymbolicName: com.third._3d\n" - "Bundle-Version: 2.3.1\n" - "\n" - "Name: bundles/3dnative.jar\n" - "SHA1-Digest: N8Ow2UY4yjnHZv5zeq2I1Uv/+uE=\n" - "Bundle-SymbolicName: com.third._3d.native\n" - "Bundle-Version: 1.5.3\n" - "\n"; - celix_autoptr(FILE) manifestFile = fmemopen((void*)content.c_str(), content.size(), "r"); - EXPECT_EQ(CELIX_INVALID_SYNTAX, manifest_readFromStream(manifest, manifestFile)); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); +TEST_F(ManifestTestSuite, InvalidBundleSymbolicNameTest) { + //Given a properties set with an invalid bundle symbolic name + celix_properties_t *properties = createAttributes("2.0.0", "1.0.0", "my_bundle", "celix_my_bundle$$$$"); + + //When creating a manifest from the attributes + celix_autoptr(celix_bundle_manifest_t) manifest = nullptr; + celix_status_t status = celix_bundleManifest_create(properties, &manifest); + + //Then the creation fails + EXPECT_EQ(CELIX_INVALID_SYNTAX, status); + + //And 1 celix err log entries is logged + EXPECT_EQ(celix_err_getErrorCount(), 1); + celix_err_printErrors(stdout, "Expect Errors: ", nullptr); } -TEST_F(ManifestTestSuite, ManifestMissingVersionTest) { - std::string content = /*"Manifest-Version: 1.0\n"*/ - "DeploymentPackage-Icon: %icon\n" - "DeploymentPackage-SymbolicName: com.third._3d\n" - "DeploymentPacakge-Version: 1.2.3.build22032005\n" - "\n"; - celix_autoptr(FILE) manifestFile = fmemopen((void*)content.c_str(), content.size(), "r"); - EXPECT_EQ(CELIX_INVALID_SYNTAX, manifest_readFromStream(manifest, manifestFile)); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); + +TEST_F(ManifestTestSuite, GetBuiltinAttributes) { + //Given a properties set with all the mandatory and manifest attributes + celix_properties_t *properties = createAttributes("2.0.0", "1.0.0", "my_bundle", "celix_my_bundle"); + + //When creating a manifest from the attributes + celix_autoptr(celix_bundle_manifest_t) manifest = nullptr; + celix_status_t status = celix_bundleManifest_create(properties, &manifest); + + //Then the creation is successful + EXPECT_EQ(CELIX_SUCCESS, status); + + //And the manifest contains the mandatory attributes + EXPECT_EQ(4, celix_properties_size(celix_bundleManifest_getAttributes(manifest))); + EXPECT_STREQ("my_bundle", celix_bundleManifest_getBundleName(manifest)); + EXPECT_STREQ("celix_my_bundle", celix_bundleManifest_getBundleSymbolicName(manifest)); + + const auto* mv = celix_bundleManifest_getManifestVersion(manifest); + const auto* bv = celix_bundleManifest_getBundleVersion(manifest); + ASSERT_NE(nullptr, mv); + ASSERT_NE(nullptr, bv); + + celix_autofree char* manifestVersion = celix_version_toString(mv); + celix_autofree char* bundleVersion = celix_version_toString(bv); + EXPECT_STREQ("2.0.0", manifestVersion); + EXPECT_STREQ("1.0.0", bundleVersion); + + //And the manifest does not contain optional attributes + EXPECT_EQ(nullptr, celix_bundleManifest_getBundleActivatorLibrary(manifest)); + EXPECT_EQ(nullptr, celix_bundleManifest_getBundlePrivateLibraries(manifest)); + EXPECT_EQ(nullptr, celix_bundleManifest_getBundleGroup(manifest)); + + //Given a properties set with all the mandatory and optional attributes + properties = createAttributes("2.0.0", "1.0.0", "my_bundle", "celix_my_bundle"); + celix_properties_set(properties, "CELIX_BUNDLE_ACTIVATOR_LIBRARY", "my_activator"); + auto* libs = celix_arrayList_createStringArray(); + celix_arrayList_addString(libs, "lib1"); + celix_arrayList_addString(libs, "lib2"); + celix_properties_assignArrayList(properties, "CELIX_BUNDLE_PRIVATE_LIBRARIES", libs); + celix_properties_set(properties, "CELIX_BUNDLE_GROUP", "my_group"); + celix_properties_set(properties, "CELIX_BUNDLE_DESCRIPTION", "my_description"); + + //When creating a manifest from the attributes + celix_autoptr(celix_bundle_manifest_t) manifest2 = nullptr; + status = celix_bundleManifest_create(properties, &manifest2); + + //Then the creation is successful + celix_err_printErrors(stdout, "Expect Errors: ", nullptr); + ASSERT_EQ(CELIX_SUCCESS, status); + + //And the manifest contains the optional attributes + EXPECT_STREQ("my_activator", celix_bundleManifest_getBundleActivatorLibrary(manifest2)); + const celix_array_list_t* privateLibraries = celix_bundleManifest_getBundlePrivateLibraries(manifest2); + ASSERT_NE(nullptr, privateLibraries); + EXPECT_EQ(2, celix_arrayList_size(privateLibraries)); + EXPECT_STREQ("lib1", celix_arrayList_getString(privateLibraries, 0)); + EXPECT_STREQ("lib2", celix_arrayList_getString(privateLibraries, 1)); + EXPECT_STREQ("my_group", celix_bundleManifest_getBundleGroup(manifest2)); + EXPECT_STREQ("my_description", celix_bundleManifest_getBundleDescription(manifest2)); } -TEST_F(ManifestTestSuite, ReadEmptyManifestTest) { - std::string content = "\n"; - celix_autoptr(FILE) manifestFile = fmemopen((void*)content.c_str(), content.size(), "r"); - EXPECT_EQ(CELIX_INVALID_SYNTAX, manifest_readFromStream(manifest, manifestFile)); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); +TEST_F(ManifestTestSuite, CreateFrameworkManifestTest) { + //When creating a framework manifest + celix_autoptr(celix_bundle_manifest_t) manifest = nullptr; + celix_status_t status = celix_bundleManifest_createFrameworkManifest(&manifest); + + //When the creation is successful + ASSERT_EQ(CELIX_SUCCESS, status); + + //And the manifest contains at least the mandatory attributes for a framework bundle + EXPECT_GE(celix_properties_size(celix_bundleManifest_getAttributes(manifest)), 4); + auto manifestVersion = celix_bundleManifest_getManifestVersion(manifest); + ASSERT_NE(nullptr, manifestVersion); + auto bundleVersion = celix_bundleManifest_getBundleVersion(manifest); + ASSERT_NE(nullptr, bundleVersion); + celix_autofree char* mv = celix_version_toString(manifestVersion); + celix_autofree char* bv = celix_version_toString(bundleVersion); + EXPECT_STREQ("2.0.0", mv); + EXPECT_STREQ(CELIX_FRAMEWORK_VERSION, bv); + EXPECT_STREQ("Apache Celix Framework", celix_bundleManifest_getBundleName(manifest)); + EXPECT_STREQ("apache_celix_framework", celix_bundleManifest_getBundleSymbolicName(manifest)); } diff --git a/libs/framework/gtest/src/nop_activator.c b/libs/framework/gtest/src/activator_with_exception.c similarity index 98% rename from libs/framework/gtest/src/nop_activator.c rename to libs/framework/gtest/src/activator_with_exception.c index b6760f31d..b8062cd07 100644 --- a/libs/framework/gtest/src/nop_activator.c +++ b/libs/framework/gtest/src/activator_with_exception.c @@ -19,6 +19,7 @@ #include "celix_bundle_activator.h" #include "celix_compiler.h" +#include struct bundle_act { diff --git a/libs/framework/include/celix_constants.h b/libs/framework/include/celix_constants.h index 9de3f332e..aa5929d44 100644 --- a/libs/framework/include/celix_constants.h +++ b/libs/framework/include/celix_constants.h @@ -121,22 +121,11 @@ extern "C" { */ #define CELIX_FRAMEWORK_SERVICE_VERSION "service.version" -#define CELIX_FRAMEWORK_BUNDLE_ACTIVATOR "Bundle-Activator" - #define CELIX_FRAMEWORK_BUNDLE_ACTIVATOR_CREATE "celix_bundleActivator_create" #define CELIX_FRAMEWORK_BUNDLE_ACTIVATOR_START "celix_bundleActivator_start" #define CELIX_FRAMEWORK_BUNDLE_ACTIVATOR_STOP "celix_bundleActivator_stop" #define CELIX_FRAMEWORK_BUNDLE_ACTIVATOR_DESTROY "celix_bundleActivator_destroy" -#define CELIX_FRAMEWORK_BUNDLE_SYMBOLICNAME "Bundle-SymbolicName" -#define CELIX_FRAMEWORK_BUNDLE_NAME "Bundle-Name" -#define CELIX_FRAMEWORK_BUNDLE_GROUP "Bundle-Group" -#define CELIX_FRAMEWORK_BUNDLE_DESCRIPTION "Bundle-Description" -#define CELIX_FRAMEWORK_BUNDLE_VERSION "Bundle-Version" -#define CELIX_FRAMEWORK_PRIVATE_LIBRARY "Private-Library" -#define CELIX_FRAMEWORK_EXPORT_LIBRARY "Export-Library" -#define CELIX_FRAMEWORK_IMPORT_LIBRARY "Import-Library" - /** * @brief Celix framework environment property (named "CELIX_FRAMEWORK_CACHE_DIR") specifying the cache * directory used for the bundle caches. diff --git a/libs/framework/include/celix_types.h b/libs/framework/include/celix_types.h index a73bac6f0..5ee3c32ee 100644 --- a/libs/framework/include/celix_types.h +++ b/libs/framework/include/celix_types.h @@ -65,8 +65,6 @@ typedef struct celix_bundle bundle_t CELIX_DEPRECATED_ATTR; // will be deprecated in the future typedef struct bundleArchive *bundle_archive_pt; typedef struct bundleArchive bundle_archive_t; -typedef struct bundleRevision *bundle_revision_pt; -typedef struct bundleRevision bundle_revision_t; typedef struct service_factory *service_factory_pt; typedef struct serviceReference * service_reference_pt; typedef struct serviceRegistration service_registration_t; diff --git a/libs/framework/include_deprecated/bundle.h b/libs/framework/include_deprecated/bundle.h deleted file mode 100644 index 44bf3c491..000000000 --- a/libs/framework/include_deprecated/bundle.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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. - */ - -#ifndef BUNDLE_H_ -#define BUNDLE_H_ - -#include "celix_types.h" - -#include "celix_errno.h" -#include "celix_bundle_state.h" -#include "bundle_archive.h" -#include "framework.h" -#include "module.h" -#include "service_reference.h" -#include "celix_log.h" -#include "celix_threads.h" -#include "bundle_context.h" -#include "celix_framework_export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct celix_bundle_activator; -typedef struct celix_bundle_activator celix_bundle_activator_t; - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_isSystemBundle(const celix_bundle_t *bundle, bool *systemBundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getArchive(const celix_bundle_t *bundle, bundle_archive_pt *archive); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getCurrentModule(const celix_bundle_t *bundle, module_pt *module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_array_list_t *bundle_getModules(const celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void *bundle_getHandle(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void bundle_setHandle(celix_bundle_t *bundle, void *handle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_bundle_activator_t *bundle_getActivator(const celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_setActivator(celix_bundle_t *bundle, celix_bundle_activator_t *activator); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getContext(const celix_bundle_t *bundle, celix_bundle_context_t **context); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_setContext(celix_bundle_t *bundle, celix_bundle_context_t *context); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getEntry(const celix_bundle_t *bundle, const char *name, char **entry); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_start(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_update(celix_bundle_t *bundle, const char *inputFile); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_stop(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_uninstall(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_setState(celix_bundle_t *bundle, bundle_state_e state); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_setPersistentStateInactive(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_setPersistentStateUninstalled(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void uninstallBundle(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_revise(celix_bundle_t *bundle, const char *location, const char *inputFile); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_addModule(celix_bundle_t *bundle, module_pt module); - -// Service Reference Functions -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_array_list_t *getUsingBundles(service_reference_pt reference); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT int compareTo(service_reference_pt a, service_reference_pt b); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getState(const celix_bundle_t *bundle, bundle_state_e *state); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_closeAndDelete(const celix_bundle_t *bundle); - -CELIX_FRAMEWORK_EXPORT celix_status_t bundle_close(const celix_bundle_t *bundle) - __attribute__((deprecated("bundle_close is deprecated and does nothing"))); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_refresh(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getBundleId(const celix_bundle_t *bundle, long *id); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getRegisteredServices(celix_bundle_t *bundle, celix_array_list_t **list); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getServicesInUse(celix_bundle_t *bundle, celix_array_list_t **list); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getFramework(const celix_bundle_t *bundle, celix_framework_t **framework); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_getBundleLocation(const celix_bundle_t *bundle, const char **location); - - -#ifdef __cplusplus -} -#endif - -#endif /* BUNDLE_H_ */ diff --git a/libs/framework/include_deprecated/bundle_context.h b/libs/framework/include_deprecated/bundle_context.h index b12c84ab8..aef6aa9e4 100644 --- a/libs/framework/include_deprecated/bundle_context.h +++ b/libs/framework/include_deprecated/bundle_context.h @@ -26,8 +26,9 @@ * Framework. */ -#include "celix_types.h" +#include +#include "celix_types.h" #include "celix_cleanup.h" #include "service_factory.h" #include "celix_service_factory.h" @@ -35,13 +36,10 @@ #include "bundle_listener.h" #include "framework_listener.h" #include "celix_service_listener.h" - #include "dm_dependency_manager.h" -#include - -#include "bundle_context.h" #include "celix_bundle_context.h" #include "celix_framework_export.h" +#include "celix_log.h" #ifdef __cplusplus extern "C" { diff --git a/libs/framework/include_deprecated/bundle_revision.h b/libs/framework/include_deprecated/bundle_revision.h deleted file mode 100644 index 372b9f9ef..000000000 --- a/libs/framework/include_deprecated/bundle_revision.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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. - */ - -#ifndef BUNDLE_REVISION_H_ -#define BUNDLE_REVISION_H_ - -#include - -#include "celix_types.h" - -#include "celix_errno.h" -#include "manifest.h" -#include "celix_log.h" -#include "celix_array_list.h" -#include "celix_framework_export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * - * A bundle revision represents the content of a bundle. A revision is associated with a bundle archive. - * An archive can have multiple revisions, each update of a bundle results in a new one. - * - * In a revision the content of a bundle (ZIP file) is extracted to a specified location inside the archive. - * - * @note The bundle revision is immutable and thread safe. - */ - -/** - * Retrieves the revision number of the given revision. - * - * @param revision The revision to get the number for. - * @param[out] revisionNr The revision number. - * - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_ILLEGAL_ARGUMENT If revision is illegal. - */ -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleRevision_getNumber(const bundle_revision_t* revision, long *revisionNr) __attribute__((deprecated)); - -/** - * Retrieves the location of the given revision. - * - * @param revision The revision to get the location for. - * @param[out] location The location. - * - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_ILLEGAL_ARGUMENT If revision is illegal. - */ -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleRevision_getLocation(const bundle_revision_t* revision, const char **location); - -/** - * Retrieves the root of the given revision. - * - * @param revision The revision to get the location for. - * @param[out] root The root. - * - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_ILLEGAL_ARGUMENT If revision is illegal. - */ -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleRevision_getRoot(const bundle_revision_t* revision, const char **root); - -/** - * Retrieves the manifest of the given revision. - * - * @param revision The revision to get the manifest for. - * @param[out] manifest The manifest. - * - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_ILLEGAL_ARGUMENT If revision is illegal. - */ -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleRevision_getManifest(const bundle_revision_t* revision, manifest_pt *manifest); - -/** - * Originally retrieved the handles of the installed libraries for this revision. - * Currently deprecated and will not return any handles. - * @return CELIX_SUCCESS and an empty list. - */ -CELIX_FRAMEWORK_EXPORT celix_status_t bundleRevision_getHandles(const bundle_revision_t* revision, celix_array_list_t **handles) - __attribute__((deprecated("Deprecated. Library handles are no now handled by the bundle module."))); - -#ifdef __cplusplus -} -#endif - -#endif /* BUNDLE_REVISION_H_ */ - -/** - * @} - */ diff --git a/libs/framework/include_deprecated/framework.h b/libs/framework/include_deprecated/framework.h index 3ef46bc9a..98ceafaf4 100644 --- a/libs/framework/include_deprecated/framework.h +++ b/libs/framework/include_deprecated/framework.h @@ -21,7 +21,7 @@ #define FRAMEWORK_H_ #include "celix_errno.h" -#include "bundle.h" +#include "celix_bundle.h" #include "celix_properties.h" #include "bundle_context.h" #include "celix_framework_export.h" diff --git a/libs/framework/include_deprecated/framework_event.h b/libs/framework/include_deprecated/framework_event.h index 58bf77d30..ccbb59911 100644 --- a/libs/framework/include_deprecated/framework_event.h +++ b/libs/framework/include_deprecated/framework_event.h @@ -52,7 +52,7 @@ typedef struct framework_event framework_event_t; #endif #include "service_reference.h" -#include "bundle.h" +#include "celix_bundle.h" #ifdef __cplusplus extern "C" { diff --git a/libs/framework/include_deprecated/manifest.h b/libs/framework/include_deprecated/manifest.h deleted file mode 100644 index 60da8dedf..000000000 --- a/libs/framework/include_deprecated/manifest.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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. - */ -/** - * manifest.h - * - * \date Jul 5, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef MANIFEST_H_ -#define MANIFEST_H_ - -#include -#include - -#include "celix_cleanup.h" -#include "celix_errno.h" -#include "celix_framework_export.h" -#include "celix_properties.h" -#include "hash_map.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct manifest { - celix_properties_t *mainAttributes; - hash_map_pt attributes; -}; - -typedef struct manifest *manifest_pt; - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t manifest_create(manifest_pt *manifest); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT manifest_pt manifest_clone(manifest_pt manifest); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t manifest_createFromFile(const char *filename, manifest_pt *manifest); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t manifest_destroy(manifest_pt manifest); - -CELIX_DEFINE_AUTO_CLEANUP_FREE_FUNC(manifest_pt, manifest_destroy, NULL) - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void manifest_clear(manifest_pt manifest); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_properties_t *manifest_getMainAttributes(manifest_pt manifest); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t manifest_getEntries(manifest_pt manifest, hash_map_pt *map); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t manifest_read(manifest_pt manifest, const char *filename); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t manifest_readFromStream(manifest_pt manifest, FILE* stream); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void manifest_write(manifest_pt manifest, const char *filename); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT const char *manifest_getValue(manifest_pt manifest, const char *name); - -#ifdef __cplusplus -} -#endif - -#endif /* MANIFEST_H_ */ diff --git a/libs/framework/include_deprecated/module.h b/libs/framework/include_deprecated/module.h deleted file mode 100644 index 4cef2d970..000000000 --- a/libs/framework/include_deprecated/module.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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. - */ -/** - * module.h - * - * \date Jul 12, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef MODULE_H_ -#define MODULE_H_ - -typedef struct module *module_pt; -typedef struct module celix_module_t; - -#include - -#include "manifest.h" -#include "bundle.h" -#include "celix_framework_export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -CELIX_FRAMEWORK_DEPRECATED_EXPORT module_pt module_create(manifest_pt headerMap, const char *moduleId, celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT module_pt module_createFrameworkModule(celix_framework_t* fw, celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void module_destroy(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT unsigned int module_hash(void *module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT int module_equals(void *module, void *compare); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_version_t* module_getVersion(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t module_getSymbolicName(module_pt module, const char **symbolicName); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT char *module_getId(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT bool module_isResolved(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void module_setResolved(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_bundle_t *module_getBundle(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_array_list_t *module_getDependentImporters(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void module_addDependentImporter(module_pt module, module_pt importer); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void module_removeDependentImporter(module_pt module, module_pt importer); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_array_list_t *module_getDependentRequirers(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void module_addDependentRequirer(module_pt module, module_pt requirer); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT void module_removeDependentRequirer(module_pt module, module_pt requirer); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_array_list_t *module_getDependents(module_pt module); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t module_getGroup(module_pt module, const char **group); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t module_getName(module_pt module, const char **name); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t module_getDescription(module_pt module, const char **description); - -#ifdef __cplusplus -} -#endif - -#endif /* MODULE_H_ */ diff --git a/libs/framework/include_deprecated/service_factory.h b/libs/framework/include_deprecated/service_factory.h index 494f81f1b..8265153d1 100644 --- a/libs/framework/include_deprecated/service_factory.h +++ b/libs/framework/include_deprecated/service_factory.h @@ -23,7 +23,7 @@ #include "celix_types.h" #include "celix_errno.h" #include "service_registration.h" -#include "bundle.h" +#include "celix_bundle.h" #ifdef __cplusplus extern "C" { diff --git a/libs/framework/include_deprecated/service_reference.h b/libs/framework/include_deprecated/service_reference.h index 35068cca5..c3acec020 100644 --- a/libs/framework/include_deprecated/service_reference.h +++ b/libs/framework/include_deprecated/service_reference.h @@ -24,7 +24,7 @@ #include "celix_types.h" #include "service_registration.h" -#include "bundle.h" +#include "celix_bundle.h" #include "celix_framework_export.h" #ifdef __cplusplus diff --git a/libs/framework/include_deprecated/service_registration.h b/libs/framework/include_deprecated/service_registration.h index 256d7db03..cf648c05b 100644 --- a/libs/framework/include_deprecated/service_registration.h +++ b/libs/framework/include_deprecated/service_registration.h @@ -23,7 +23,7 @@ #include #include "celix_types.h" -#include "bundle.h" +#include "celix_properties_type.h" #include "celix_framework_export.h" #ifdef __cplusplus diff --git a/libs/framework/include_deprecated/service_registry.h b/libs/framework/include_deprecated/service_registry.h index 7cdb785d7..155c8ee72 100644 --- a/libs/framework/include_deprecated/service_registry.h +++ b/libs/framework/include_deprecated/service_registry.h @@ -28,7 +28,7 @@ #include "service_registration.h" #include "celix_service_factory.h" #include "celix_framework_export.h" - +#include "celix_service_listener.h" #ifdef __cplusplus extern "C" { diff --git a/libs/framework/src/bundle.c b/libs/framework/src/bundle.c index 033a3541e..054b9bd56 100644 --- a/libs/framework/src/bundle.c +++ b/libs/framework/src/bundle.c @@ -17,15 +17,13 @@ * under the License. */ -#include "bundle_private.h" - -#include -#include -#include -#include -#include -#include +#include "bundle_revision_private.h" +#include "celix_bundle_manifest.h" +#include "celix_bundle_private.h" +#include "celix_module.h" +#include "celix_properties.h" +#include "celix_properties_type.h" #include "framework_private.h" #include "utils.h" #include "celix_file_utils.h" @@ -33,9 +31,13 @@ #include "bundle_context_private.h" #include "service_tracker_private.h" +#include +#include +#include +#include static char* celix_bundle_getBundleOrPersistentStoreEntry(const celix_bundle_t* bnd, bool bundleEntry, const char* name); -celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module); +celix_status_t bundle_createModule(bundle_pt bundle, celix_module_t** module); celix_status_t bundle_closeRevisions(const_bundle_pt bundle); celix_status_t celix_bundle_createFromArchive(celix_framework_t *framework, bundle_archive_pt archive, celix_bundle_t **bundleOut) { @@ -55,10 +57,6 @@ celix_status_t celix_bundle_createFromArchive(celix_framework_t *framework, bund bundle->handle = NULL; bundle->activator = NULL; bundle->context = NULL; - bundle->symbolicName = NULL; - bundle->name = NULL; - bundle->group = NULL; - bundle->description = NULL; if (bundle->modules == NULL) { status = CELIX_ENOMEM; @@ -67,7 +65,7 @@ celix_status_t celix_bundle_createFromArchive(celix_framework_t *framework, bund return status; } - module_pt module; + celix_module_t* module; status = bundle_createModule(bundle, &module); if (status != CELIX_SUCCESS) { fw_logCode(framework->logger, CELIX_LOG_LEVEL_ERROR, status, "Cannot create bundle from archive, cannot create module."); @@ -84,15 +82,11 @@ celix_status_t celix_bundle_createFromArchive(celix_framework_t *framework, bund celix_status_t bundle_destroy(bundle_pt bundle) { for (int i = 0; i < celix_arrayList_size(bundle->modules); ++i) { - module_pt module = celix_arrayList_get(bundle->modules, i); + celix_module_t* module = celix_arrayList_get(bundle->modules, i); module_destroy(module); } celix_arrayList_destroy(bundle->modules); - free(bundle->symbolicName); - free(bundle->name); - free(bundle->group); - free(bundle->description); free(bundle); return CELIX_SUCCESS; @@ -108,7 +102,7 @@ celix_status_t bundle_getArchive(const_bundle_pt bundle, bundle_archive_pt *arch return status; } -celix_status_t bundle_getCurrentModule(const_bundle_pt bundle, module_pt *module) { +celix_status_t bundle_getCurrentModule(const_bundle_pt bundle, celix_module_t** module) { celix_status_t status = CELIX_SUCCESS; if (bundle == NULL || celix_arrayList_size(bundle->modules)==0 ) { @@ -120,10 +114,6 @@ celix_status_t bundle_getCurrentModule(const_bundle_pt bundle, module_pt *module return status; } -celix_array_list_t* bundle_getModules(const_bundle_pt bundle) { - return bundle->modules; -} - void * bundle_getHandle(bundle_pt bundle) { return bundle->handle; } @@ -141,20 +131,9 @@ celix_status_t bundle_setActivator(bundle_pt bundle, celix_bundle_activator_t *a return CELIX_SUCCESS; } -celix_status_t bundle_getContext(const_bundle_pt bundle, bundle_context_pt *context) { - *context = bundle->context; - return CELIX_SUCCESS; -} +celix_bundle_context_t* celix_bundle_getContext(const_bundle_pt bundle) { return bundle->context; } -celix_status_t bundle_setContext(bundle_pt bundle, bundle_context_pt context) { - bundle->context = context; - return CELIX_SUCCESS; -} - -celix_status_t bundle_getEntry(const_bundle_pt bundle, const char* name, char** entry) { - *entry = celix_bundle_getBundleOrPersistentStoreEntry(bundle, true, name); - return *entry == NULL ? CELIX_ILLEGAL_ARGUMENT : CELIX_SUCCESS; -} +void celix_bundle_setContext(bundle_pt bundle, bundle_context_pt context) { bundle->context = context; } celix_status_t bundle_getState(const_bundle_pt bundle, bundle_state_e *state) { if (bundle==NULL) { @@ -170,40 +149,17 @@ celix_status_t bundle_setState(bundle_pt bundle, bundle_state_e state) { return CELIX_SUCCESS; } -celix_status_t bundle_createModule(bundle_pt bundle, module_pt* moduleOut) { - celix_status_t status = CELIX_SUCCESS; - bundle_archive_pt archive = NULL; - bundle_revision_pt revision = NULL; - manifest_pt headerMap = NULL; - long bundleId = 0; - - status = CELIX_DO_IF(status, bundle_getArchive(bundle, &archive)); - status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision)); - status = CELIX_DO_IF(status, bundleRevision_getManifest(revision, &headerMap)); - status = bundleArchive_getId(bundle->archive, &bundleId); - - if (status != CELIX_SUCCESS) { - fw_logCode(bundle->framework->logger, CELIX_LOG_LEVEL_ERROR, status, "Cannot create module, cannot get bundle archive, revision, manifest or bundle id."); - return status; - } +celix_status_t bundle_createModule(bundle_pt bundle, celix_module_t** moduleOut) { + celix_status_t status = CELIX_SUCCESS; - module_pt module = NULL; - if (bundleId == CELIX_FRAMEWORK_BUNDLE_ID) { - module = module_createFrameworkModule(bundle->framework, bundle); - } else { - int revision_no = 0; - char moduleId[512]; - snprintf(moduleId, sizeof(moduleId), "%ld.%d", bundleId, revision_no); - module = module_create(headerMap, moduleId, bundle); - } + celix_module_t* module = module_create(bundle); if (!module) { status = CELIX_BUNDLE_EXCEPTION; fw_logCode(bundle->framework->logger, CELIX_LOG_LEVEL_ERROR, status, "Cannot create module."); return status; } - - const char * symName = NULL; + const char* symName = NULL; status = module_getSymbolicName(module, &symName); assert(status == CELIX_SUCCESS); /* @@ -214,7 +170,11 @@ celix_status_t bundle_createModule(bundle_pt bundle, module_pt* moduleOut) { bool alreadyInstalled = celix_framework_isBundleAlreadyInstalled(bundle->framework, symName); if (alreadyInstalled) { status = CELIX_BUNDLE_EXCEPTION; - fw_logCode(bundle->framework->logger, CELIX_LOG_LEVEL_ERROR, status, "Cannot create module, bundle with symbolic name '%s' already installed.", symName); + fw_logCode(bundle->framework->logger, + CELIX_LOG_LEVEL_ERROR, + status, + "Cannot create module, bundle with symbolic name '%s' already installed.", + symName); } if (status == CELIX_SUCCESS) { *moduleOut = module; @@ -225,71 +185,8 @@ celix_status_t bundle_createModule(bundle_pt bundle, module_pt* moduleOut) { return status; } -celix_status_t bundle_start(celix_bundle_t* bundle) { - //note deprecated call use celix_bundleContext_startBundle instead - return celix_framework_startBundle(bundle->framework, celix_bundle_getId(bundle)); -} - -celix_status_t bundle_update(bundle_pt bundle, const char* updatedBundleUrl) { - return celix_framework_updateBundle(bundle->framework, celix_bundle_getId(bundle), updatedBundleUrl); -} - -celix_status_t bundle_stop(bundle_pt bundle) { - //note deprecated call use celix_bundleContext_stopBundle instead - return celix_framework_stopBundle(bundle->framework, celix_bundle_getId(bundle)); -} - -celix_status_t bundle_uninstall(bundle_pt bundle) { - //note deprecated call use celix_bundleContext_uninstallBundle instead - return celix_framework_uninstallBundle(bundle->framework, celix_bundle_getId(bundle)); -} - -celix_status_t bundle_setPersistentStateInactive(bundle_pt bundle) { - celix_status_t status; - bool systemBundle; - - status = bundle_isSystemBundle(bundle, &systemBundle); - if (status == CELIX_SUCCESS) { - if (!systemBundle) { - status = bundleArchive_setPersistentState(bundle->archive, CELIX_BUNDLE_STATE_INSTALLED); - } - } - - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to set persistent state to inactive"); - - return status; -} - -celix_status_t bundle_setPersistentStateUninstalled(bundle_pt bundle) { - celix_status_t status; - bool systemBundle; - - status = bundle_isSystemBundle(bundle, &systemBundle); - if (status == CELIX_SUCCESS) { - if (!systemBundle) { - status = bundleArchive_setPersistentState(bundle->archive, CELIX_BUNDLE_STATE_UNINSTALLED); - } - } - - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to set persistent state to uninstalled"); - - return status; -} - -celix_status_t bundle_revise(bundle_pt bundle, const char * location, const char *inputFile) { - fw_log(bundle->framework->logger, CELIX_LOG_LEVEL_DEBUG, "Usage of bundle_revise is deprecated and no longer needed. Called for bundle %s", bundle->symbolicName); - return CELIX_SUCCESS; -} - -celix_status_t bundle_addModule(bundle_pt bundle, module_pt module) { - celix_arrayList_add(bundle->modules, module); - - //free previous module info - free(bundle->symbolicName); - free(bundle->name); - free(bundle->group); - free(bundle->description); - +celix_status_t bundle_addModule(bundle_pt bundle, celix_module_t* module) { + celix_arrayList_add(bundle->modules, module); //set new module info const char *sn = NULL; @@ -300,12 +197,8 @@ celix_status_t bundle_addModule(bundle_pt bundle, module_pt module) { module_getGroup(module, &g); module_getName(module, &n); module_getDescription(module, &d); - bundle->symbolicName = celix_utils_strdup(sn); - bundle->name = celix_utils_strdup(n); - bundle->group = celix_utils_strdup(g); - bundle->description = celix_utils_strdup(d); - return CELIX_SUCCESS; + return CELIX_SUCCESS; } celix_status_t bundle_isSystemBundle(const_bundle_pt bundle, bool *systemBundle) { @@ -326,36 +219,6 @@ celix_status_t bundle_isSystemBundle(const_bundle_pt bundle, bool *systemBundle) return status; } -celix_status_t bundle_close(const_bundle_pt bundle) { - fw_log(bundle->framework->logger, CELIX_LOG_LEVEL_DEBUG, "Usage of bundle_close is deprecated and no longer needed. Called for bundle %s", bundle->symbolicName); - return CELIX_SUCCESS; -} - -celix_status_t bundle_closeAndDelete(const_bundle_pt bundle) { - fw_log(bundle->framework->logger, CELIX_LOG_LEVEL_DEBUG, "Usage of bundle_closeAndDelete is deprecated and no longer needed. Called for bundle %s", bundle->symbolicName); - return CELIX_SUCCESS; -} - -celix_status_t bundle_closeRevisions(const_bundle_pt bundle) { - celix_status_t status = CELIX_SUCCESS; - return status; -} - -celix_status_t bundle_refresh(bundle_pt bundle) { - module_pt module; - celix_arrayList_clear(bundle->modules); - celix_status_t status = bundle_createModule(bundle, &module); - if (status == CELIX_SUCCESS) { - status = bundle_addModule(bundle, module); - if (status == CELIX_SUCCESS) { - __atomic_store_n(&bundle->state, CELIX_BUNDLE_STATE_INSTALLED, __ATOMIC_RELEASE); - } - } - - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to refresh bundle"); - return status; -} - celix_status_t bundle_getBundleId(const bundle_t *bundle, long *bndId) { celix_status_t status = CELIX_SUCCESS; long id = celix_bundle_getId(bundle); @@ -368,26 +231,6 @@ celix_status_t bundle_getBundleId(const bundle_t *bundle, long *bndId) { return status; } -celix_status_t bundle_getRegisteredServices(bundle_pt bundle, celix_array_list_t** list) { - celix_status_t status; - - status = fw_getBundleRegisteredServices(bundle->framework, bundle, list); - - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to get registered services"); - - return status; -} - -celix_status_t bundle_getServicesInUse(bundle_pt bundle, celix_array_list_t** list) { - celix_status_t status; - - status = fw_getBundleServicesInUse(bundle->framework, bundle, list); - - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to get in use services"); - - return status; -} - celix_status_t bundle_getFramework(const_bundle_pt bundle, framework_pt *framework) { if (bundle == NULL || framework == NULL) { return CELIX_ILLEGAL_ARGUMENT; @@ -494,40 +337,37 @@ char* celix_bundle_getDataFile(const celix_bundle_t* bnd, const char *path) { return entry; } +static celix_bundle_manifest_t* celix_bundle_getManifest(const celix_bundle_t* bnd) { + celix_bundle_manifest_t* man = celix_bundleArchive_getManifest(bnd->archive); + assert(man); //bundles always have a manifest + return man; +} + const char* celix_bundle_getManifestValue(const celix_bundle_t* bnd, const char* attribute) { - const char* header = NULL; - if (bnd != NULL) { - bundle_archive_t* arch = NULL; - bundle_getArchive(bnd, &arch); - if (arch != NULL) { - bundle_revision_t* rev = NULL; - bundleArchive_getCurrentRevision(arch, &rev); - if (rev != NULL) { - manifest_pt man = NULL; - bundleRevision_getManifest(rev, &man); - if (man != NULL ) { - header = manifest_getValue(man, attribute); - } - } - } - } - return header; + celix_bundle_manifest_t* man = celix_bundle_getManifest(bnd); + assert(man); //bundle always has a manifest + const celix_properties_t* attr = celix_bundleManifest_getAttributes(man); + return celix_properties_getAsString(attr, attribute, NULL); } const char* celix_bundle_getGroup(const celix_bundle_t *bnd) { - return bnd->group; + celix_bundle_manifest_t* man = celix_bundle_getManifest(bnd); + return celix_bundleManifest_getBundleGroup(man); } const char* celix_bundle_getSymbolicName(const celix_bundle_t *bnd) { - return bnd->symbolicName; + celix_bundle_manifest_t* man = celix_bundle_getManifest(bnd); + return celix_bundleManifest_getBundleSymbolicName(man); } const char* celix_bundle_getName(const celix_bundle_t* bnd) { - return bnd->name; + celix_bundle_manifest_t* man = celix_bundle_getManifest(bnd); + return celix_bundleManifest_getBundleName(man); } const char* celix_bundle_getDescription(const celix_bundle_t* bnd) { - return bnd->description; + celix_bundle_manifest_t* man = celix_bundle_getManifest(bnd); + return celix_bundleManifest_getBundleDescription(man); } char* celix_bundle_getLocation(const celix_bundle_t *bnd) { @@ -539,7 +379,7 @@ char* celix_bundle_getLocation(const celix_bundle_t *bnd) { } const celix_version_t* celix_bundle_getVersion(const celix_bundle_t *bnd) { - celix_version_t* result = NULL; + const celix_version_t* result = NULL; celix_module_t* mod = NULL; bundle_getCurrentModule(bnd, &mod); if (mod != NULL) { diff --git a/libs/framework/src/bundle_archive.c b/libs/framework/src/bundle_archive.c index 8867e8038..bc140dd69 100644 --- a/libs/framework/src/bundle_archive.c +++ b/libs/framework/src/bundle_archive.c @@ -26,16 +26,19 @@ #include #include +#include "celix_bundle_manifest.h" +#include "celix_bundle_manifest_type.h" #include "celix_constants.h" #include "celix_compiler.h" #include "celix_file_utils.h" #include "celix_framework_utils_private.h" #include "celix_utils_api.h" #include "celix_log.h" - #include "bundle_archive_private.h" #include "bundle_revision_private.h" +#include "celix_version.h" #include "framework_private.h" +#include "celix_stdlib_cleanup.h" /** * The bundle archive which is used to store the bundle data and can be reused when a framework is restarted. @@ -51,9 +54,7 @@ struct bundleArchive { char* savedBundleStatePropertiesPath; char* storeRoot; char* resourceCacheRoot; - char* bundleSymbolicName; // read from the manifest - char* bundleVersion; // read from the manifest - bundle_revision_t* revision; // the current revision + celix_bundle_revision_t* revision; // the current revision char* location; bool cacheValid; // is the cache valid (e.g. not deleted) bool valid; // is the archive valid (e.g. not deleted) @@ -72,6 +73,11 @@ static celix_status_t celix_bundleArchive_storeBundleStateProperties(bundle_arch if (!bundleStateProperties) { bundleStateProperties = celix_properties_create(); } + + celix_bundle_manifest_t* man = celix_bundleArchive_getManifest(archive); + const char* bndVersion = celix_properties_getAsString(celix_bundleManifest_getAttributes(man), + CELIX_BUNDLE_VERSION, ""); + if (!bundleStateProperties) { return CELIX_ENOMEM; } @@ -88,21 +94,25 @@ static celix_status_t celix_bundleArchive_storeBundleStateProperties(bundle_arch needUpdate = true; } if (strcmp(celix_properties_get(bundleStateProperties, CELIX_BUNDLE_ARCHIVE_SYMBOLIC_NAME_PROPERTY_NAME, ""), - archive->bundleSymbolicName) != 0) { + celix_bundleManifest_getBundleSymbolicName(man)) != 0) { celix_properties_set( - bundleStateProperties, CELIX_BUNDLE_ARCHIVE_SYMBOLIC_NAME_PROPERTY_NAME, archive->bundleSymbolicName); + bundleStateProperties, + CELIX_BUNDLE_ARCHIVE_SYMBOLIC_NAME_PROPERTY_NAME, + celix_bundleManifest_getBundleSymbolicName(man)); needUpdate = true; } if (strcmp(celix_properties_get(bundleStateProperties, CELIX_BUNDLE_ARCHIVE_VERSION_PROPERTY_NAME, ""), - archive->bundleVersion) != 0) { - celix_properties_set(bundleStateProperties, CELIX_BUNDLE_ARCHIVE_VERSION_PROPERTY_NAME, archive->bundleVersion); + bndVersion) != 0) { + celix_properties_set(bundleStateProperties, CELIX_BUNDLE_ARCHIVE_VERSION_PROPERTY_NAME, bndVersion); needUpdate = true; } // save bundle cache state properties if (needUpdate) { celix_status_t status = celix_properties_save( - bundleStateProperties, archive->savedBundleStatePropertiesPath, CELIX_PROPERTIES_ENCODE_PRETTY); + bundleStateProperties, + archive->savedBundleStatePropertiesPath, + CELIX_PROPERTIES_ENCODE_PRETTY); if (status != CELIX_SUCCESS) { return status; } @@ -184,7 +194,8 @@ celix_bundleArchive_extractBundle(bundle_archive_t* archive, const char* bundleU * Initialize archive by creating the bundle cache directory, optionally extracting the bundle from the bundle file, * reading the bundle state properties, reading the bundle manifest and updating the bundle state properties. */ -static celix_status_t celix_bundleArchive_createCacheDirectory(bundle_archive_pt archive, manifest_pt* manifestOut) { +static celix_status_t celix_bundleArchive_createCacheDirectory(bundle_archive_pt archive, celix_bundle_manifest_t** manifestOut) { + *manifestOut = NULL; if (celix_utils_fileExists(archive->archiveRoot)) { fw_log(archive->fw->logger, CELIX_LOG_LEVEL_TRACE, "Bundle archive root for bundle id %li already exists.", archive->id); @@ -213,14 +224,14 @@ static celix_status_t celix_bundleArchive_createCacheDirectory(bundle_archive_pt } //read manifest from extracted bundle zip - *manifestOut = NULL; + celix_autoptr(celix_bundle_manifest_t) manifest = NULL; char pathBuffer[512]; char* manifestPath = celix_utils_writeOrCreateString(pathBuffer, sizeof(pathBuffer), "%s/%s", archive->resourceCacheRoot, CELIX_BUNDLE_MANIFEST_REL_PATH); if (manifestPath == NULL) { fw_log(archive->fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to initialize archive. Failed to create manifest path."); return CELIX_ENOMEM; } - status = manifest_createFromFile(manifestPath, manifestOut); + status = celix_bundleManifest_createFromFile(manifestPath, &manifest); celix_utils_freeStringIfNotEqual(pathBuffer, manifestPath); if (status != CELIX_SUCCESS) { celix_framework_logTssErrors(archive->fw->logger, CELIX_LOG_LEVEL_ERROR); @@ -228,20 +239,7 @@ static celix_status_t celix_bundleArchive_createCacheDirectory(bundle_archive_pt return status; } - //populate bundle symbolic name and version from manifest - archive->bundleSymbolicName = celix_utils_strdup(manifest_getValue(*manifestOut, CELIX_FRAMEWORK_BUNDLE_SYMBOLICNAME)); - if (archive->bundleSymbolicName == NULL) { - fw_log(archive->fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to initialize archive. Cannot read bundle symbolic name."); - manifest_destroy(*manifestOut); - return CELIX_BUNDLE_EXCEPTION; - } - archive->bundleVersion = celix_utils_strdup(manifest_getValue(*manifestOut, CELIX_FRAMEWORK_BUNDLE_VERSION)); - if (archive->bundleVersion == NULL) { - fw_log(archive->fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to initialize archive. Cannot read bundle version."); - manifest_destroy(*manifestOut); - return CELIX_BUNDLE_EXCEPTION; - } - + *manifestOut = celix_steal_ptr(manifest); return status; } @@ -249,7 +247,7 @@ celix_status_t celix_bundleArchive_create(celix_framework_t* fw, const char *arc celix_status_t status = CELIX_SUCCESS; const char* error = NULL; bundle_archive_pt archive = calloc(1, sizeof(*archive)); - bool isSystemBundle = id == CELIX_FRAMEWORK_BUNDLE_ID; + bool isFrameworkBundle = id == CELIX_FRAMEWORK_BUNDLE_ID; if (archive == NULL) { status = CELIX_ENOMEM; @@ -259,7 +257,7 @@ celix_status_t celix_bundleArchive_create(celix_framework_t* fw, const char *arc archive->fw = fw; archive->id = id; - if (isSystemBundle) { + if (isFrameworkBundle) { archive->resourceCacheRoot = getcwd(NULL, 0); archive->storeRoot = getcwd(NULL, 0); if (archive->resourceCacheRoot == NULL || archive->storeRoot == NULL) { @@ -294,9 +292,9 @@ celix_status_t celix_bundleArchive_create(celix_framework_t* fw, const char *arc goto init_failed; } - manifest_pt manifest = NULL; - if (isSystemBundle) { - status = manifest_create(&manifest); + celix_bundle_manifest_t* manifest = NULL; + if (isFrameworkBundle) { + status = celix_bundleManifest_createFrameworkManifest(&manifest); } else { status = celix_bundleArchive_createCacheDirectory(archive, &manifest); } @@ -311,7 +309,7 @@ celix_status_t celix_bundleArchive_create(celix_framework_t* fw, const char *arc goto revision_failed; } - if (!isSystemBundle) { + if (!isFrameworkBundle) { status = celix_bundleArchive_storeBundleStateProperties(archive); if (status != CELIX_SUCCESS) { error = "Could not store properties."; @@ -325,7 +323,7 @@ celix_status_t celix_bundleArchive_create(celix_framework_t* fw, const char *arc store_prop_failed: revision_failed: dir_failed: - if (!isSystemBundle) { + if (!isFrameworkBundle) { celix_utils_deleteDirectory(archive->archiveRoot, NULL); } init_failed: @@ -343,9 +341,7 @@ void celix_bundleArchive_destroy(bundle_archive_pt archive) { free(archive->archiveRoot); free(archive->resourceCacheRoot); free(archive->storeRoot); - free(archive->bundleSymbolicName); - free(archive->bundleVersion); - bundleRevision_destroy(archive->revision); + celix_bundleRevision_destroy(archive->revision); free(archive); } } @@ -359,8 +355,14 @@ long celix_bundleArchive_getId(bundle_archive_pt archive) { return archive->id; } -const char* celix_bundleArchive_getSymbolicName(bundle_archive_pt archive) { - return archive->bundleSymbolicName; +celix_bundle_manifest_t* celix_bundleArchive_getManifest(bundle_archive_pt archive) { + celix_bundle_manifest_t* man = celix_bundleRevision_getManifest(archive->revision); + assert(man); //bundle archives always have a manifest + return man; +} + +const char* celix_bundleArchive_getSymbolicName(bundle_archive_t* archive) { + return celix_bundleManifest_getBundleSymbolicName(celix_bundleArchive_getManifest(archive)); } celix_status_t bundleArchive_getLocation(bundle_archive_pt archive, const char **location) { @@ -388,13 +390,13 @@ celix_status_t bundleArchive_getCurrentRevisionNumber(bundle_archive_pt archive, } //LCOV_EXCL_STOP -celix_status_t bundleArchive_getCurrentRevision(bundle_archive_pt archive, bundle_revision_pt* revision) { +celix_status_t bundleArchive_getCurrentRevision(bundle_archive_pt archive, celix_bundle_revision_t** revision) { *revision = archive->revision; return CELIX_SUCCESS; } //LCOV_EXCL_START -celix_status_t bundleArchive_getRevision(bundle_archive_pt archive, long revNr CELIX_UNUSED, bundle_revision_pt *revision) { +celix_status_t bundleArchive_getRevision(bundle_archive_pt archive, long revNr CELIX_UNUSED, celix_bundle_revision_t** revision) { return bundleArchive_getCurrentRevision(archive, revision); } @@ -461,14 +463,6 @@ celix_status_t bundleArchive_close(bundle_archive_pt archive) { // not yet needed/possible return CELIX_SUCCESS; } - -celix_status_t bundleArchive_closeAndDelete(bundle_archive_pt archive) { - fw_log(archive->fw->logger, - CELIX_LOG_LEVEL_DEBUG, - "Usage of bundleArchive_closeAndDelete is deprecated and no longer needed. Called for bundle %s", - archive->bundleSymbolicName); - return CELIX_SUCCESS; -} //LCOV_EXCL_STOP const char* celix_bundleArchive_getPersistentStoreRoot(bundle_archive_t* archive) { diff --git a/libs/framework/include_deprecated/bundle_archive.h b/libs/framework/src/bundle_archive.h similarity index 54% rename from libs/framework/include_deprecated/bundle_archive.h rename to libs/framework/src/bundle_archive.h index d53518a1d..e11f0a75c 100644 --- a/libs/framework/include_deprecated/bundle_archive.h +++ b/libs/framework/src/bundle_archive.h @@ -31,12 +31,12 @@ #include #include +#include -#include "bundle_revision.h" +#include "bundle_revision_private.h" #include "celix_bundle_state.h" #include "celix_errno.h" #include "celix_log.h" -#include #include "bundle_context.h" #include "celix_bundle_context.h" @@ -46,46 +46,43 @@ extern "C" { #endif -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getId(bundle_archive_pt archive, long *id); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getId(bundle_archive_pt archive, long *id); /** * Return the current location of the bundle. * @warning Not safe, because location can change during bundle revise. * @return */ -CELIX_FRAMEWORK_EXPORT celix_status_t bundleArchive_getLocation(bundle_archive_pt archive, const char **location) - __attribute__((deprecated("use celix_bundle_getLocation instead"))); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getLocation(bundle_archive_pt archive, const char **location); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getArchiveRoot(bundle_archive_pt archive, const char **archiveRoot); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getArchiveRoot(bundle_archive_pt archive, const char **archiveRoot); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_revise(bundle_archive_pt archive, const char *location, const char *inputFile); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_rollbackRevise(bundle_archive_pt archive, bool *rolledback); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t -bundleArchive_getRevision(bundle_archive_pt archive, long revNr, bundle_revision_pt *revision); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_rollbackRevise(bundle_archive_pt archive, bool *rolledback); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t -bundleArchive_getCurrentRevision(bundle_archive_pt archive, bundle_revision_pt *revision); +CELIX_FRAMEWORK_DEPRECATED celix_status_t +bundleArchive_getRevision(bundle_archive_pt archive, long revNr, celix_bundle_revision_t** revision); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getCurrentRevisionNumber(bundle_archive_pt archive, long *revisionNumber) __attribute__((deprecated)); +CELIX_FRAMEWORK_DEPRECATED celix_status_t +bundleArchive_getCurrentRevision(bundle_archive_pt archive, celix_bundle_revision_t** revision); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getRefreshCount(bundle_archive_pt archive, long *refreshCount); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getCurrentRevisionNumber(bundle_archive_pt archive, long *revisionNumber); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_setRefreshCount(bundle_archive_pt archive); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getRefreshCount(bundle_archive_pt archive, long *refreshCount); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_close(bundle_archive_pt archive); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_setRefreshCount(bundle_archive_pt archive); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_closeAndDelete(bundle_archive_pt archive); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_close(bundle_archive_pt archive); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_setLastModified(bundle_archive_pt archive, time_t lastModifiedTime); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_setLastModified(bundle_archive_pt archive, time_t lastModifiedTime); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getLastModified(bundle_archive_pt archive, time_t *lastModified); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getLastModified(bundle_archive_pt archive, time_t *lastModified); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_setPersistentState(bundle_archive_pt archive, bundle_state_e state); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_setPersistentState(bundle_archive_pt archive, bundle_state_e state); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getPersistentState(bundle_archive_pt archive, bundle_state_e *state); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getPersistentState(bundle_archive_pt archive, bundle_state_e *state); /** * @brief Return the last modified time of the bundle archive. @@ -102,14 +99,14 @@ CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getPersistentStat * Check errno for more specific error information.when root of the archive is not a directory. * - CELIX_ENOMEM not enough memory for manifest file path. */ -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t celix_bundleArchive_getLastModified(bundle_archive_pt archive, struct timespec* lastModified); +CELIX_FRAMEWORK_DEPRECATED celix_status_t celix_bundleArchive_getLastModified(bundle_archive_pt archive, struct timespec* lastModified); /** * @brief Return the location of the bundle archive.b * @param[in] archive The bundle archive. * @return The location of the bundle archive. The caller is responsible for freeing the returned string. */ -CELIX_FRAMEWORK_DEPRECATED_EXPORT char* celix_bundleArchive_getLocation(bundle_archive_pt archive); +CELIX_FRAMEWORK_DEPRECATED char* celix_bundleArchive_getLocation(bundle_archive_pt archive); #ifdef __cplusplus diff --git a/libs/framework/src/bundle_archive_private.h b/libs/framework/src/bundle_archive_private.h index e0d86acb7..0ebef174e 100644 --- a/libs/framework/src/bundle_archive_private.h +++ b/libs/framework/src/bundle_archive_private.h @@ -39,7 +39,7 @@ extern "C" { #define CELIX_BUNDLE_ARCHIVE_RESOURCE_CACHE_NAME "resources" #define CELIX_BUNDLE_ARCHIVE_STORE_DIRECTORY_NAME "storage" -#define CELIX_BUNDLE_MANIFEST_REL_PATH "META-INF/MANIFEST.MF" +#define CELIX_BUNDLE_MANIFEST_REL_PATH "META-INF/MANIFEST.json" /** * @brief Create bundle archive. @@ -59,11 +59,14 @@ void celix_bundleArchive_destroy(bundle_archive_pt archive); long celix_bundleArchive_getId(bundle_archive_pt archive); /** - * @brief Returns the bundle symbolic name of the bundle archive. - * @param archive The bundle archive. - * @return The bundle symbolic name. + * @brief Return the manifest for the bundle archive. All bundle archives have a manifest. + */ +celix_bundle_manifest_t* celix_bundleArchive_getManifest(bundle_archive_t* archive); + +/** + * @brief Return the bundle symbolic name (from the manifest) */ -const char* celix_bundleArchive_getSymbolicName(bundle_archive_pt archive); +const char* celix_bundleArchive_getSymbolicName(bundle_archive_t* archive); /** * Returns the root of the bundle persistent store. diff --git a/libs/framework/src/bundle_context.c b/libs/framework/src/bundle_context.c index 4f126101d..0cd0d621e 100644 --- a/libs/framework/src/bundle_context.c +++ b/libs/framework/src/bundle_context.c @@ -26,22 +26,21 @@ #include #include -#include "celix_utils.h" -#include "celix_constants.h" #include "bundle_context_private.h" -#include "framework_private.h" -#include "bundle.h" +#include "celix_bundle_private.h" +#include "celix_array_list.h" #include "celix_bundle.h" -#include "celix_log.h" -#include "service_tracker.h" +#include "celix_constants.h" +#include "celix_convert_utils.h" #include "celix_dependency_manager.h" +#include "celix_log.h" +#include "celix_module.h" +#include "celix_utils.h" #include "dm_dependency_manager_impl.h" -#include "celix_array_list.h" -#include "module.h" -#include "service_tracker_private.h" +#include "framework_private.h" #include "service_reference_private.h" -#include "celix_array_list.h" -#include "celix_convert_utils.h" +#include "service_tracker.h" +#include "service_tracker_private.h" #define TRACKER_WARN_THRESHOLD_SEC 5 @@ -729,7 +728,7 @@ bool celix_bundleContext_useBundle( } static void bundleContext_cleanupBundleTrackers(bundle_context_t* ctx) { - module_pt module; + celix_module_t* module; const char* symbolicName; bundle_getCurrentModule(ctx->bundle, &module); module_getSymbolicName(module, &symbolicName); @@ -762,7 +761,7 @@ static void bundleContext_cleanupBundleTrackers(bundle_context_t* ctx) { } static void bundleContext_cleanupServiceTrackers(bundle_context_t* ctx) { - module_pt module; + celix_module_t* module; const char* symbolicName; bundle_getCurrentModule(ctx->bundle, &module); module_getSymbolicName(module, &symbolicName); @@ -797,7 +796,7 @@ static void bundleContext_cleanupServiceTrackers(bundle_context_t* ctx) { } static void bundleContext_cleanupServiceTrackerTrackers(bundle_context_t* ctx) { - module_pt module; + celix_module_t* module; const char* symbolicName; bundle_getCurrentModule(ctx->bundle, &module); module_getSymbolicName(module, &symbolicName); @@ -832,7 +831,7 @@ static void bundleContext_cleanupServiceTrackerTrackers(bundle_context_t* ctx) { } static void bundleContext_cleanupServiceRegistration(bundle_context_t* ctx) { - module_pt module; + celix_module_t* module; const char *symbolicName; bundle_getCurrentModule(ctx->bundle, &module); module_getSymbolicName(module, &symbolicName); diff --git a/libs/framework/src/bundle_context_private.h b/libs/framework/src/bundle_context_private.h index 0bc1b5ea3..fcd41d44d 100644 --- a/libs/framework/src/bundle_context_private.h +++ b/libs/framework/src/bundle_context_private.h @@ -29,6 +29,7 @@ #include "celix_long_hash_map.h" #include "listener_hook_service.h" #include "service_tracker.h" +#include "celix_threads.h" #ifdef __cplusplus extern "C" { diff --git a/libs/framework/src/bundle_revision.c b/libs/framework/src/bundle_revision.c index a8e76ff28..a0e7c78f2 100644 --- a/libs/framework/src/bundle_revision.c +++ b/libs/framework/src/bundle_revision.c @@ -24,9 +24,17 @@ #include "bundle_revision_private.h" #include "framework_private.h" -celix_status_t celix_bundleRevision_create(celix_framework_t* fw, const char *root, const char *location, manifest_pt manifest, bundle_revision_pt *bundle_revision) { +struct celix_bundle_revision { + celix_framework_t* fw; + char* root; + char* location; + celix_bundle_manifest_t* manifest; +}; + +celix_status_t celix_bundleRevision_create(celix_framework_t* fw, const char *root, const char *location, celix_bundle_manifest_t* manifest, + celix_bundle_revision_t** bundle_revision) { celix_status_t status = CELIX_SUCCESS; - bundle_revision_pt revision = calloc(1, sizeof(*revision)); + celix_bundle_revision_t* revision = calloc(1, sizeof(*revision)); if (revision != NULL) { revision->fw = fw; if (root != NULL) { @@ -42,9 +50,9 @@ celix_status_t celix_bundleRevision_create(celix_framework_t* fw, const char *ro status = CELIX_ENOMEM; fw_logCode(fw->logger, CELIX_LOG_LEVEL_ERROR, status, "Cannot create bundle revision, out of memory"); if (revision != NULL) { - bundleRevision_destroy(revision); + celix_bundleRevision_destroy(revision); } else { - manifest_destroy(manifest); + celix_bundleManifest_destroy(manifest); } return status; } @@ -53,9 +61,9 @@ celix_status_t celix_bundleRevision_create(celix_framework_t* fw, const char *ro return status; } -celix_status_t bundleRevision_destroy(bundle_revision_pt revision) { +celix_status_t celix_bundleRevision_destroy(celix_bundle_revision_t* revision) { if (revision != NULL) { - manifest_destroy(revision->manifest); + celix_bundleManifest_destroy(revision->manifest); free(revision->root); free(revision->location); free(revision); @@ -63,39 +71,6 @@ celix_status_t bundleRevision_destroy(bundle_revision_pt revision) { return CELIX_SUCCESS; } -celix_status_t bundleRevision_getManifest(const bundle_revision_t* revision, manifest_pt* manifest) { - *manifest = revision->manifest; - return CELIX_SUCCESS; -} - -//LCOV_EXCL_START -bundle_revision_t* bundleRevision_revise(const bundle_revision_t* rev, const char* updatedBundleUrl) { - fw_log(rev->fw->logger, CELIX_LOG_LEVEL_ERROR, "Revision revise unsupported."); - return NULL; -} - - -celix_status_t bundleRevision_getNumber(const bundle_revision_t* revision, long *revisionNr) { - *revisionNr = 1; //note revision nr is deprecated - return CELIX_SUCCESS; +celix_bundle_manifest_t* celix_bundleRevision_getManifest(celix_bundle_revision_t* revision) { + return revision->manifest; } - -celix_status_t bundleRevision_getLocation(const bundle_revision_t* revision, const char **location) { - *location = revision->location; - return CELIX_SUCCESS; -} - -celix_status_t bundleRevision_getRoot(const bundle_revision_t* revision, const char **root) { - *root = revision->root; - return CELIX_SUCCESS; -} - -celix_status_t bundleRevision_getHandles(const bundle_revision_t* revision CELIX_UNUSED, celix_array_list_t** handles) { - //nop, usage deprecated - if (handles) { - *handles = celix_arrayList_create(); - } - return CELIX_SUCCESS; -} -//LCOV_EXCL_STOP - diff --git a/libs/framework/src/bundle_revision_private.h b/libs/framework/src/bundle_revision_private.h index 0eb2106a5..d09836993 100644 --- a/libs/framework/src/bundle_revision_private.h +++ b/libs/framework/src/bundle_revision_private.h @@ -27,8 +27,9 @@ #ifndef BUNDLE_REVISION_PRIVATE_H_ #define BUNDLE_REVISION_PRIVATE_H_ -#include "bundle_revision.h" #include "celix_threads.h" +#include "celix_framework.h" +#include "celix_bundle_manifest.h" #ifdef __cplusplus extern "C" { @@ -38,13 +39,7 @@ extern "C" { * The bundle revision structure represents a revision of a bundle. * A bundle can have multiple revisions. A bundle revision is immutable. */ -struct bundleRevision { - celix_framework_t *fw; - long revisionNr; - char *root; - char *location; - manifest_pt manifest; -}; +typedef struct celix_bundle_revision celix_bundle_revision_t; /** * Creates a new revision for the given inputFile or location. @@ -60,11 +55,19 @@ struct bundleRevision { * - CELIX_SUCCESS when no errors are encountered. * - CELIX_ENOMEM If allocating memory for bundle_revision failed. */ -celix_status_t celix_bundleRevision_create(celix_framework_t* fw, const char *root, const char *location, manifest_pt manifest, bundle_revision_pt *bundle_revision); +celix_status_t celix_bundleRevision_create(celix_framework_t* fw, + const char* root, + const char* location, + celix_bundle_manifest_t* manifest, + celix_bundle_revision_t** bundle_revision); -bundle_revision_t* bundleRevision_revise(const bundle_revision_t* revision, const char* updatedBundleUrl); +celix_status_t celix_bundleRevision_destroy(celix_bundle_revision_t* revision); -celix_status_t bundleRevision_destroy(bundle_revision_pt revision); + +/** + * @brief Get the bundle manifest of the given revision. + */ +celix_bundle_manifest_t* celix_bundleRevision_getManifest(celix_bundle_revision_t* revision); #ifdef __cplusplus } diff --git a/libs/framework/src/celix_bundle_manifest.c b/libs/framework/src/celix_bundle_manifest.c new file mode 100644 index 000000000..d70e9bf1a --- /dev/null +++ b/libs/framework/src/celix_bundle_manifest.c @@ -0,0 +1,217 @@ +/* + * 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 "celix_bundle_manifest.h" + +#include "celix_cleanup.h" +#include "celix_errno.h" +#include "celix_array_list_type.h" +#include "celix_err.h" +#include "celix_properties.h" +#include "celix_properties_type.h" +#include "celix_version.h" +#include "celix_framework_version.h" +#include "celix_version_type.h" + +#include +#include +#include + +#define CELIX_BUNDLE_SYMBOLIC_NAME_ALLOWED_SPECIAL_CHARS "-_:." +#define CELIX_FRAMEWORK_MANIFEST_VERSION "2.0.0" + +struct celix_bundle_manifest { + celix_properties_t* attributes; +}; + +/** + * @brief Set and validate the provided manifest by checking if all mandatory attributes are present and of the correct + * type and checking if the optional attributes, when present, are of the correct type. + */ +static celix_status_t celix_bundleManifest_checkAttributes(celix_bundle_manifest_t* manifest); + +celix_status_t celix_bundleManifest_create(celix_properties_t* attributes, celix_bundle_manifest_t** manifestOut) { + if (!attributes) { + return CELIX_ILLEGAL_ARGUMENT; + } + + celix_autoptr(celix_bundle_manifest_t) manifest = calloc(1, sizeof(*manifest)); + if (!manifest) { + celix_properties_destroy(attributes); + celix_err_push("Failed to allocate memory for manifest"); + return ENOMEM; + } + manifest->attributes = attributes; + + celix_status_t status = celix_bundleManifest_checkAttributes(manifest); + if (status != CELIX_SUCCESS) { + return status; + } + + *manifestOut = celix_steal_ptr(manifest); + return CELIX_SUCCESS; +} + +celix_status_t celix_bundleManifest_createFromFile(const char* filename, celix_bundle_manifest_t** manifestOut) { + celix_properties_t* properties = NULL; + celix_status_t status = celix_properties_load(filename, 0, &properties); + if (status != CELIX_SUCCESS) { + return status; + } + return celix_bundleManifest_create(properties, manifestOut); +} + +celix_status_t celix_bundleManifest_createFrameworkManifest(celix_bundle_manifest_t** manifest) { + celix_autoptr(celix_properties_t) properties = celix_properties_create(); + if (!properties) { + celix_err_push("Failed to create properties for framework manifest"); + return ENOMEM; + } + + celix_version_t* fwVersion; + celix_version_t* manifestVersion; + celix_status_t status = celix_version_parse(CELIX_FRAMEWORK_MANIFEST_VERSION, &manifestVersion); + status = CELIX_DO_IF(status, + celix_properties_assignVersion(properties, CELIX_BUNDLE_MANIFEST_VERSION, manifestVersion)); + status = CELIX_DO_IF(status, + celix_properties_set(properties, CELIX_BUNDLE_SYMBOLIC_NAME, "apache_celix_framework")); + status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_NAME, "Apache Celix Framework")); + status = CELIX_DO_IF(status, celix_version_parse(CELIX_FRAMEWORK_VERSION, &fwVersion)); + status = CELIX_DO_IF(status, celix_properties_assignVersion(properties, CELIX_BUNDLE_VERSION, fwVersion)); + status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_GROUP, "Celix/Framework")); + status = CELIX_DO_IF( + status, + celix_properties_set(properties, CELIX_BUNDLE_DESCRIPTION, "The Apache Celix Framework System Bundle")); + + if (status != CELIX_SUCCESS) { + celix_err_push("Failed to set properties for framework manifest"); + return status; + } + + return celix_bundleManifest_create(celix_steal_ptr(properties), manifest); +} + +void celix_bundleManifest_destroy(celix_bundle_manifest_t* manifest) { + if (manifest) { + celix_properties_destroy(manifest->attributes); + free(manifest); + } +} + +const celix_properties_t* celix_bundleManifest_getAttributes(const celix_bundle_manifest_t* manifest) { + return manifest->attributes; +} + +static celix_status_t celix_bundleManifest_checkMandatoryAttributes(celix_bundle_manifest_t* manifest) { + const char* symbolicName = celix_properties_get(manifest->attributes, CELIX_BUNDLE_SYMBOLIC_NAME, NULL); + const char* bundleName = celix_properties_get(manifest->attributes, CELIX_BUNDLE_NAME, NULL); + const celix_version_t* manifestVersion = celix_properties_getVersion( + manifest->attributes, + CELIX_BUNDLE_MANIFEST_VERSION); + const celix_version_t* bundleVersion = celix_properties_getVersion(manifest->attributes, CELIX_BUNDLE_VERSION); + + celix_status_t status = CELIX_SUCCESS; + if (!bundleName) { + celix_err_push(CELIX_BUNDLE_NAME " is missing"); + status = CELIX_INVALID_SYNTAX; + } + if (!symbolicName) { + celix_err_push(CELIX_BUNDLE_SYMBOLIC_NAME " is missing"); + status = CELIX_INVALID_SYNTAX; + } else { + // check if bundle symbolic name only contains the following characters: [a-zA-Z0-9_-:] + for (size_t i = 0; symbolicName[i] != '\0'; ++i) { + if (!isalnum(symbolicName[i]) && + strchr(CELIX_BUNDLE_SYMBOLIC_NAME_ALLOWED_SPECIAL_CHARS, symbolicName[i]) == NULL) { + celix_err_pushf( + CELIX_BUNDLE_SYMBOLIC_NAME " '%s' contains invalid character '%c'", symbolicName, symbolicName[i]); + status = CELIX_INVALID_SYNTAX; + break; + } + } + } + if (!manifestVersion) { + celix_err_push(CELIX_BUNDLE_MANIFEST_VERSION " is missing or not a version"); + status = CELIX_INVALID_SYNTAX; + } + if (!bundleVersion) { + celix_err_push(CELIX_BUNDLE_VERSION " is missing or not a version"); + status = CELIX_INVALID_SYNTAX; + } + + if (manifestVersion && celix_version_compareToMajorMinor(manifestVersion, 2, 0) != 0) { + celix_err_push(CELIX_BUNDLE_MANIFEST_VERSION " is not 2.0.*"); + status = CELIX_INVALID_SYNTAX; + } + + return status; +} + +static celix_status_t celix_bundleManifest_checkOptionalAttributes(celix_bundle_manifest_t* manifest) { + if (celix_properties_hasKey(manifest->attributes, CELIX_BUNDLE_PRIVATE_LIBRARIES)) { + //if a private libraries manifest entry exist, this should be a string array list. + const celix_array_list_t* libs = celix_properties_getStringArrayList( + manifest->attributes, + CELIX_BUNDLE_PRIVATE_LIBRARIES); + if (!libs) { + celix_err_push(CELIX_BUNDLE_PRIVATE_LIBRARIES " exists, but is not a array of strings"); + return CELIX_INVALID_SYNTAX; + } + } + + return CELIX_SUCCESS; +} + +static celix_status_t celix_bundleManifest_checkAttributes(celix_bundle_manifest_t* manifest) { + const celix_status_t mStatus = celix_bundleManifest_checkMandatoryAttributes(manifest); + const celix_status_t oStatus = celix_bundleManifest_checkOptionalAttributes(manifest); + return mStatus != CELIX_SUCCESS ? mStatus : oStatus; +} + +const char* celix_bundleManifest_getBundleName(const celix_bundle_manifest_t* manifest) { + return celix_properties_getString(manifest->attributes, CELIX_BUNDLE_NAME); +} + +const char* celix_bundleManifest_getBundleSymbolicName(const celix_bundle_manifest_t* manifest) { + return celix_properties_getString(manifest->attributes, CELIX_BUNDLE_SYMBOLIC_NAME); +} + +const celix_version_t* celix_bundleManifest_getBundleVersion(const celix_bundle_manifest_t* manifest) { + return celix_properties_getVersion(manifest->attributes, CELIX_BUNDLE_VERSION); +} + +const celix_version_t* celix_bundleManifest_getManifestVersion(const celix_bundle_manifest_t* manifest) { + return celix_properties_getVersion(manifest->attributes, CELIX_BUNDLE_MANIFEST_VERSION); +} + +const char* celix_bundleManifest_getBundleActivatorLibrary(const celix_bundle_manifest_t* manifest) { + return celix_properties_getString(manifest->attributes, CELIX_BUNDLE_ACTIVATOR_LIBRARY); +} + +const celix_array_list_t* celix_bundleManifest_getBundlePrivateLibraries(const celix_bundle_manifest_t* manifest) { + return celix_properties_getStringArrayList(manifest->attributes, CELIX_BUNDLE_PRIVATE_LIBRARIES); +} + +const char* celix_bundleManifest_getBundleDescription(const celix_bundle_manifest_t* manifest) { + return celix_properties_getString(manifest->attributes, CELIX_BUNDLE_DESCRIPTION); +} + +const char* celix_bundleManifest_getBundleGroup(const celix_bundle_manifest_t* manifest) { + return celix_properties_getString(manifest->attributes, CELIX_BUNDLE_GROUP); +} diff --git a/libs/framework/src/celix_bundle_manifest.h b/libs/framework/src/celix_bundle_manifest.h new file mode 100644 index 000000000..adb7aac3d --- /dev/null +++ b/libs/framework/src/celix_bundle_manifest.h @@ -0,0 +1,203 @@ +/* + * 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. + */ + +#ifndef CELIX_MANIFEST_H_ +#define CELIX_MANIFEST_H_ + +#include "celix_array_list.h" +#include "celix_cleanup.h" +#include "celix_errno.h" +#include "celix_properties_type.h" +#include "celix_version_type.h" +#include "celix_array_list_type.h" +#include "celix_bundle_manifest_type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Mandatory manifest attributes +#define CELIX_BUNDLE_MANIFEST_VERSION "CELIX_BUNDLE_MANIFEST_VERSION" +#define CELIX_BUNDLE_SYMBOLIC_NAME "CELIX_BUNDLE_SYMBOLIC_NAME" +#define CELIX_BUNDLE_VERSION "CELIX_BUNDLE_VERSION" +#define CELIX_BUNDLE_NAME "CELIX_BUNDLE_NAME" + +// Optional manifest attributes +#define CELIX_BUNDLE_ACTIVATOR_LIBRARY "CELIX_BUNDLE_ACTIVATOR_LIBRARY" +#define CELIX_BUNDLE_PRIVATE_LIBRARIES "CELIX_BUNDLE_PRIVATE_LIBRARIES" +#define CELIX_BUNDLE_DESCRIPTION "CELIX_BUNDLE_DESCRIPTION" +#define CELIX_BUNDLE_GROUP "CELIX_BUNDLE_GROUP" + +/** + * @file celix_bundle_manifest.h + * @brief Header file for celix_bundle_manifest_t. + * + * + * The bundle manifest consists of a set of attributes, including a set of mandatory attributes. + * A bundle manifest is used to describe the contents of a bundle. + * + * A bundle manifest must contain the following attributes: + * - CELIX_BUNDLE_MANIFEST_VERSION, type celix_version_t, the version of the manifest. + * - CELIX_BUNDLE_SYMBOLIC_NAME, type string, the symbolic name of the bundle. + * - CELIX_BUNDLE_VERSION, type celix_version_t, the version of the bundle. + * - CELIX_BUNDLE_NAME, type string, the name of the bundle. + * + * The bundle manifest may contain the following attributes: + * - CELIX_BUNDLE_ACTIVATOR_LIBRARY, type string, the activator library of the bundle. + * - CELIX_BUNDLE_PRIVATE_LIBRARIES, type string array, the private libraries of the bundle. + * - CELIX_BUNDLE_GROUP, type string, the group of the bundle. Helps in grouping sets of bundles. + * + * And a manifest may contain any other attributes of any type, this can be retrieved using + * celix_bundleManifest_getAttributes. + * + * A bundle symbolic name can only contain the following characters: [a-zA-Z0-9_-:] + */ + +/** + * Create a new manifest using the provided properties. + * + * If an error occurs, an error message is logged on celix_err and in case of an CELIX_ILLEGAL_ARGUMENT error, there + * can be multiple error messages. + * + * @param[in] properties The properties to use for the manifest. Takes ownership of the properties. + * @param[out] manifest The created manifest. + * @return CELIX_SUCCESS if no errors occurred, ENOMEM if memory allocation failed and CELIX_INVALID_SYNTAX if the + * provided attributes is incorrect. In case of an error, the provided attributes are destroyed. + */ +celix_status_t celix_bundleManifest_create(celix_properties_t* attributes, celix_bundle_manifest_t** manifest); + +/** + * Create a new manifest by reading the manifest from the provided file. + * + * If an error occurs, an error message is logged on celix_err. + * + * @param[in] filename The file to read the manifest from. + * @param[out] manifest The created manifest. + * @return CELIX_SUCCESS if no errors occurred, ENOMEM if memory allocation failed, CELIX_FILE_IO_EXCEPTION if the file + * could not be read and CELIX_INVALID_SYNTAX if the manifest file is invalid. + */ +celix_status_t celix_bundleManifest_createFromFile(const char* filename, celix_bundle_manifest_t** manifest); + +/** + * @brief Create a new framework manifest. + * + * The framework manifest is a special manifest that contains the following manifest attributes: + * - CELIX_BUNDLE_SYMBOLIC_NAME="celix.framework" + * - CELIX_BUNDLE_NAME="Celix Framework" + * - CELIX_BUNDLE_VERSION=CELIX_FRAMEWORK_VERSION + * - CELIX_BUNDLE_MANIFEST_VERSION="2.0.0" + * - CELIX_BUNDLE_GROUP="Celix" + * - CELIX_BUNDLE_DESCRIPTION="Celix Framework" + * + * @param manifest The created framework manifest. + * @return CELIX_SUCCESS if no errors occurred, ENOMEM if memory allocation failed. If an error occurs, an error message + * is logged on celix_err. + */ +celix_status_t celix_bundleManifest_createFrameworkManifest(celix_bundle_manifest_t** manifest); + +/** + * @brief Destroy the provided manifest. + */ +void celix_bundleManifest_destroy(celix_bundle_manifest_t* manifest); + +/** + * Define the cleanup function for a celix_bundleManifest_t, so that it can be used with celix_autoptr. + */ +CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC(celix_bundle_manifest_t, celix_bundleManifest_destroy) + +/** + * @brief Get the manifest attributes. + * The manifest attributes are valid as long as the manifest is valid. + * + * @param[in] manifest The bundle manifest to get the manifest version from. Cannot be NULL. + * @return The manifest attributes. Will never be NULL. + */ +const celix_properties_t* celix_bundleManifest_getAttributes(const celix_bundle_manifest_t* manifest); + +/** + * @brief Get the manifest version. Returned value is valid as long as the manifest is valid. + * + * @param[in] manifest The bundle manifest to get the bundle name from. Cannot be NULL. + * @return The bundle name. Will never be NULL. + */ +const char* celix_bundleManifest_getBundleName(const celix_bundle_manifest_t* manifest); + +/** + * @brief Get the manifest version. Returned value is valid as long as the manifest is valid. + * + * @param[in] manifest The bundle manifest to get the bundle symbolic name from. Cannot be NULL. + * @return The bundle symbolic name. Will never be NULL. + */ +const char* celix_bundleManifest_getBundleSymbolicName(const celix_bundle_manifest_t* manifest); + +/** + * @brief Get the bundle version. Returned value is valid as long as the manifest is valid. + * + * @param[in] manifest The bundle manifest to get the bundle version from. Cannot be NULL. + * @return The bundle version. Will never be NULL. + */ +const celix_version_t* celix_bundleManifest_getBundleVersion(const celix_bundle_manifest_t* manifest); + +/** + * @brief Get the bundle version. Returned value is valid as long as the manifest is valid. + * + * @param[in] manifest The bundle manifest to get the manifest version from. Cannot be NULL. + * @return The manifest version. Will never be NULL. + */ +const celix_version_t* celix_bundleManifest_getManifestVersion(const celix_bundle_manifest_t* manifest); + +/** + * @brief Get the bundle activator library. Returned value is valid as long as the manifest is valid. + * + * @param[in] manifest The bundle manifest to get the bundle private library from. Cannot be NULL. + * @return The bundle activator library. Will be NULL if the manifest does not contain the attribute. + */ +const char* celix_bundleManifest_getBundleActivatorLibrary(const celix_bundle_manifest_t* manifest); + +/** + * @brief Get the bundle private libraries. Returned value is valid as long as the manifest is valid. + * + * @param[in] manifest The bundle manifest to get the bundle private libraries from. Cannot be NULL. + * @return The bundle private libraries as a celix_array_list_t* with strings. Will be NULL if the manifest does not + * contain the attribute. + */ +const celix_array_list_t* celix_bundleManifest_getBundlePrivateLibraries(const celix_bundle_manifest_t* manifest); + +/** + * @brief Get the bundle description. Returned value is valid as long as the manifest is valid. + * + * @param[in] manifest The bundle manifest to get the bundle description from. Cannot be NULL. + * @return The bundle description. Will be NULL if the manifest does not contain the attribute. + */ +const char* celix_bundleManifest_getBundleDescription(const celix_bundle_manifest_t* manifest); + +/** + * @brief Get the bundle group. Returned value is valid as long as the manifest is valid. + * + * @param[in] manifest The bundle manifest to get the bundle group from. Cannot be NULL. + * @return The bundle group. Will be NULL if the manifest does not contain the attribute. + */ +const char* celix_bundleManifest_getBundleGroup(const celix_bundle_manifest_t* manifest); + + +#ifdef __cplusplus +} +#endif + +#endif /* CELIX_MANIFEST_H_ */ diff --git a/libs/framework/gtest/src/MultipleFrameworkTestSuite.cc b/libs/framework/src/celix_bundle_manifest_type.h similarity index 66% rename from libs/framework/gtest/src/MultipleFrameworkTestSuite.cc rename to libs/framework/src/celix_bundle_manifest_type.h index 393ce42cc..affea1f3b 100644 --- a/libs/framework/gtest/src/MultipleFrameworkTestSuite.cc +++ b/libs/framework/src/celix_bundle_manifest_type.h @@ -17,13 +17,25 @@ * under the License. */ -#include +#ifndef CELIX_MANIFEST_TYPE_H_ +#define CELIX_MANIFEST_TYPE_H_ -#include "celix_launcher.h" +#ifdef __cplusplus +extern "C" { +#endif +/** + * @file celix_bundle_manifest_type.h + * @brief Header file for celix_bundle_manifest_t type. + */ + +/** + * @brief The definition of the celix_bundleManifest_t* abstract data type. + */ +typedef struct celix_bundle_manifest celix_bundle_manifest_t; + +#ifdef __cplusplus +} +#endif -class MultipleFrameworkTestSuite : public ::testing::Test { -public: - MultipleFrameworkTestSuite() = default; - ~MultipleFrameworkTestSuite() noexcept override = default; -}; +#endif /* CELIX_MANIFEST_TYPE_H_ */ diff --git a/libs/framework/src/bundle_private.h b/libs/framework/src/celix_bundle_private.h similarity index 52% rename from libs/framework/src/bundle_private.h rename to libs/framework/src/celix_bundle_private.h index f061a9015..17e6eec68 100644 --- a/libs/framework/src/bundle_private.h +++ b/libs/framework/src/celix_bundle_private.h @@ -20,8 +20,8 @@ #ifndef BUNDLE_PRIVATE_H_ #define BUNDLE_PRIVATE_H_ -#include "bundle.h" #include "celix_bundle.h" +#include "celix_module.h" #ifdef __cplusplus extern "C" { @@ -29,10 +29,6 @@ extern "C" { struct celix_bundle { bundle_context_pt context; - char *symbolicName; - char *name; - char *group; - char *description; struct celix_bundle_activator *activator; bundle_state_e state; void *handle; @@ -42,6 +38,10 @@ struct celix_bundle { celix_framework_t *framework; }; +typedef struct celix_bundle_activator celix_bundle_activator_t; + + + /** * Creates a bundle from the given archive. * @param[in] framework The framework. @@ -67,6 +67,43 @@ bundle_archive_t *celix_bundle_getArchive(const celix_bundle_t *bundle); */ celix_status_t bundle_destroy(celix_bundle_t *bundle); +/** + * @brief Get the bundle context. + */ +celix_bundle_context_t* celix_bundle_getContext(const celix_bundle_t *bundle); + +/** + * @brief Set the bundle context. + */ +void celix_bundle_setContext(celix_bundle_t *bundle, celix_bundle_context_t *context); + + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_isSystemBundle(const celix_bundle_t *bundle, bool *systemBundle); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getArchive(const celix_bundle_t *bundle, bundle_archive_pt *archive); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getCurrentModule(const celix_bundle_t *bundle, celix_module_t** module); + +CELIX_FRAMEWORK_DEPRECATED void *bundle_getHandle(celix_bundle_t *bundle); + +CELIX_FRAMEWORK_DEPRECATED void bundle_setHandle(celix_bundle_t *bundle, void *handle); + +CELIX_FRAMEWORK_DEPRECATED celix_bundle_activator_t *bundle_getActivator(const celix_bundle_t *bundle); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_setActivator(celix_bundle_t *bundle, celix_bundle_activator_t *activator); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_setState(celix_bundle_t *bundle, bundle_state_e state); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_addModule(celix_bundle_t *bundle, celix_module_t* celix_module); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getState(const celix_bundle_t *bundle, bundle_state_e *state); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getBundleId(const celix_bundle_t *bundle, long *id); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getFramework(const celix_bundle_t *bundle, celix_framework_t **framework); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getBundleLocation(const celix_bundle_t *bundle, const char **location); + #ifdef __cplusplus } #endif diff --git a/libs/framework/src/celix_framework_version.h.in b/libs/framework/src/celix_framework_version.h.in new file mode 100644 index 000000000..cffd8a236 --- /dev/null +++ b/libs/framework/src/celix_framework_version.h.in @@ -0,0 +1,48 @@ +/* +* 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. +*/ + +#ifndef CELIX_CELIX_FRAMEWORK_VERSION_H +#define CELIX_CELIX_FRAMEWORK_VERSION_H + +/** + * @file celix_framework_version.h + * @brief Celix framework version macros + */ + +/*! + * The Celix framework version. + */ +#define CELIX_FRAMEWORK_VERSION "${CELIX_MAJOR}.${CELIX_MINOR}.${CELIX_MICRO}" + +/*! + * The major part of the Celix framework version. + */ +#define CELIX_FRAMEWORK_VERSION_MAJOR ${CELIX_MAJOR} + +/*! + * The minor part of the Celix framework version. + */ +#define CELIX_FRAMEWORK_VERSION_MINOR ${CELIX_MINOR} + +/*! + * The micro part of the Celix framework version. + */ +#define CELIX_FRAMEWORK_VERSION_MICRO ${CELIX_MICRO} + +#endif // CELIX_CELIX_FRAMEWORK_VERSION_H diff --git a/libs/framework/src/celix_module.h b/libs/framework/src/celix_module.h new file mode 100644 index 000000000..321d90c5b --- /dev/null +++ b/libs/framework/src/celix_module.h @@ -0,0 +1,68 @@ +/* + * 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. + */ + +#ifndef CELIX_MODULE_H_ +#define CELIX_MODULE_H_ + +typedef struct celix_module celix_module_t; + +#include + +#include "celix_bundle_manifest.h" +#include "celix_framework_export.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create a new module based on the provided manifest. + * @return A new module or NULL if the module could not be created. If NULL is returned, an error log is written to + * celix err. + */ +celix_module_t* module_create(celix_bundle_t* bundle); + +void module_destroy(celix_module_t* module); + +/** + * Define the cleanup function for a celix_bundleManifest_t, so that it can be used with celix_autoptr. + */ +CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC(celix_module_t, module_destroy) + +const celix_version_t* module_getVersion(celix_module_t* module); + +celix_status_t module_getSymbolicName(celix_module_t* module, const char **symbolicName); + +bool module_isResolved(celix_module_t* module); + +void module_setResolved(celix_module_t* module); + +celix_bundle_t *module_getBundle(celix_module_t* module); + +celix_status_t module_getGroup(celix_module_t* module, const char **group); + +celix_status_t module_getName(celix_module_t* module, const char **name); + +celix_status_t module_getDescription(celix_module_t* module, const char **description); + +#ifdef __cplusplus +} +#endif + +#endif /* CELIX_MODULE_H_ */ diff --git a/libs/framework/src/celix_module_private.h b/libs/framework/src/celix_module_private.h index 10756d83b..d56ae22ef 100644 --- a/libs/framework/src/celix_module_private.h +++ b/libs/framework/src/celix_module_private.h @@ -20,7 +20,7 @@ #ifndef CELIX_CELIX_MODULE_PRIVATE_H #define CELIX_CELIX_MODULE_PRIVATE_H -#include "module.h" +#include "celix_module.h" #ifdef __cplusplus extern "C" { @@ -31,8 +31,6 @@ celix_status_t celix_module_loadLibraries(celix_module_t *module); celix_status_t celix_module_closeLibraries(celix_module_t *module); -void *celix_module_getBundleActivatorHandler(celix_module_t *module); - #ifdef __cplusplus } #endif diff --git a/libs/framework/src/dm_component_impl.c b/libs/framework/src/dm_component_impl.c index 7c204e04d..f41c0f7f0 100644 --- a/libs/framework/src/dm_component_impl.c +++ b/libs/framework/src/dm_component_impl.c @@ -29,6 +29,7 @@ #include "celix_filter.h" #include "dm_component_impl.h" #include "celix_framework.h" +#include "hash_map.h" static const char * const CELIX_DM_PRINT_OK_COLOR = "\033[92m"; static const char * const CELIX_DM_PRINT_WARNING_COLOR = "\033[93m"; diff --git a/libs/framework/src/dm_dependency_manager_impl.c b/libs/framework/src/dm_dependency_manager_impl.c index d4e40f465..4c27305c4 100644 --- a/libs/framework/src/dm_dependency_manager_impl.c +++ b/libs/framework/src/dm_dependency_manager_impl.c @@ -23,14 +23,15 @@ #include #include -#include "bundle_context.h" -#include "dm_component_impl.h" -#include "dm_dependency_manager_impl.h" -#include "celix_dependency_manager.h" +#include "celix_bundle_context.h" +#include "celix_array_list.h" #include "celix_bundle.h" +#include "celix_bundle_private.h" #include "celix_compiler.h" +#include "celix_dependency_manager.h" #include "celix_framework.h" -#include "celix_array_list.h" +#include "dm_component_impl.h" +#include "dm_dependency_manager_impl.h" celix_dependency_manager_t* celix_private_dependencyManager_create(celix_bundle_context_t *context) { celix_dependency_manager_t *manager = calloc(1, sizeof(*manager)); @@ -184,8 +185,7 @@ celix_status_t celix_dependencyManager_removeAllComponentsAsync(celix_dependency static void celix_dm_getInfoCallback(void *handle, const celix_bundle_t *bnd) { celix_dependency_manager_info_t **out = handle; - celix_bundle_context_t *context = NULL; - bundle_getContext((celix_bundle_t*)bnd, &context); + celix_bundle_context_t *context = celix_bundle_getContext(bnd); celix_dependency_manager_t *mng = celix_bundleContext_getDependencyManager(context); celix_dependency_manager_info_t *info = calloc(1, sizeof(*info)); @@ -218,8 +218,7 @@ celix_dependency_manager_info_t* celix_dependencyManager_createInfo(celix_depend static void celix_dm_getInfosCallback(void* handle, const celix_bundle_t* bnd) { celix_array_list_t* infos = handle; - celix_bundle_context_t* context = NULL; - bundle_getContext((celix_bundle_t*)bnd, &context); + celix_bundle_context_t* context = celix_bundle_getContext(bnd); celix_dependency_manager_t* mng = celix_bundleContext_getDependencyManager(context); celix_dependency_manager_info_t* info = calloc(1, sizeof(*info)); @@ -265,8 +264,7 @@ static void celix_dm_allComponentsActiveCallback(void *handle, const celix_bundl return; } - celix_bundle_context_t *context = NULL; - bundle_getContext((celix_bundle_t*)bnd, &context); + celix_bundle_context_t *context = celix_bundle_getContext(bnd); celix_dependency_manager_t *mng = celix_bundleContext_getDependencyManager(context); bool allActive = celix_dependencyManager_areComponentsActive(mng); if (!allActive) { diff --git a/libs/framework/src/framework.c b/libs/framework/src/framework.c index 4848a7bcc..0bf7bda14 100644 --- a/libs/framework/src/framework.c +++ b/libs/framework/src/framework.c @@ -41,7 +41,7 @@ #include "bundle_archive_private.h" #include "bundle_context_private.h" -#include "bundle_private.h" +#include "celix_bundle_private.h" #include "celix_err.h" #include "celix_scheduled_event.h" #include "celix_stdlib_cleanup.h" @@ -147,7 +147,7 @@ static inline bool fw_bundleEntry_removeBundleEntry(celix_framework_t *fw, celix return found; } -static celix_status_t framework_markBundleResolved(framework_pt framework, module_pt module); +static celix_status_t framework_markBundleResolved(framework_pt framework, celix_module_t* module); long framework_getNextBundleId(framework_pt framework); @@ -267,7 +267,7 @@ celix_status_t framework_create(framework_pt *out, celix_properties_t* config) { framework->registry = celix_serviceRegistry_create(framework); bundle_context_t *context = NULL; status = CELIX_DO_IF(status, bundleContext_create(framework, framework->logger, framework->bundle, &context)); - status = CELIX_DO_IF(status, bundle_setContext(framework->bundle, context)); + CELIX_DO_IF(status, celix_bundle_setContext(framework->bundle, context)); //create framework bundle entry celix_bundle_entry_t*entry = fw_bundleEntry_create(framework->bundle); @@ -322,8 +322,7 @@ celix_status_t framework_destroy(framework_pt framework) { bool systemBundle = false; bundle_isSystemBundle(bnd, &systemBundle); if (systemBundle) { - bundle_context_t *context = NULL; - bundle_getContext(framework->bundle, &context); + bundle_context_t *context = celix_bundle_getContext(framework->bundle); bundleContext_destroy(context); } @@ -413,7 +412,9 @@ celix_status_t fw_init(framework_pt framework) { activator->stop = celix_frameworkBundle_stop; activator->destroy = celix_frameworkBundle_destroy; status = CELIX_DO_IF(status, bundle_setActivator(framework->bundle, activator)); - status = CELIX_DO_IF(status, bundle_getContext(framework->bundle, &validateContext)); + if (status == CELIX_SUCCESS) { + validateContext = celix_bundle_getContext(framework->bundle); + } status = CELIX_DO_IF(status, activator->create(validateContext, &activator->userData)); bool fwBundleCreated = status == CELIX_SUCCESS; status = CELIX_DO_IF(status, activator->start(activator->userData, validateContext)); @@ -572,14 +573,15 @@ static bool framework_autoStartConfiguredBundlesForList(celix_framework_t* fw, fw_log(fw->logger, CELIX_LOG_LEVEL_ERROR, "Could not start bundle %s (bnd id = %li)\n", - bnd->symbolicName, + celix_bundle_getSymbolicName(bnd), bndId); allStarted = false; } } else { fw_log(fw->logger, CELIX_LOG_LEVEL_WARNING, - "Cannot start bundle %s (bnd id = %li) again, already started\n", bnd->symbolicName, + "Cannot start bundle %s (bnd id = %li) again, already started\n", + celix_bundle_getSymbolicName(bnd), bndId); } } @@ -723,8 +725,9 @@ bool celix_framework_isBundleAlreadyInstalled(celix_framework_t* fw, const char* bool alreadyExists = false; celixThreadMutex_lock(&fw->installedBundles.mutex); for (int i = 0; i < celix_arrayList_size(fw->installedBundles.entries); ++i) { - celix_bundle_entry_t*entry = celix_arrayList_get(fw->installedBundles.entries, i); - if (celix_utils_stringEquals(entry->bnd->symbolicName, bundleSymbolicName)) { + celix_bundle_entry_t* entry = celix_arrayList_get(fw->installedBundles.entries, i); + const char* symb = celix_bundle_getSymbolicName(entry->bnd); + if (celix_utils_stringEquals(symb, bundleSymbolicName)) { alreadyExists = true; break; } @@ -733,62 +736,6 @@ bool celix_framework_isBundleAlreadyInstalled(celix_framework_t* fw, const char* return alreadyExists; } -celix_status_t fw_getDependentBundles(framework_pt framework, bundle_pt exporter, celix_array_list_t** list) { - celix_status_t status = CELIX_SUCCESS; - - if (*list != NULL || exporter == NULL || framework == NULL) { - return CELIX_ILLEGAL_ARGUMENT; - } - - celix_array_list_t* modules; - unsigned int modIdx = 0; - *list = celix_arrayList_create(); - - modules = bundle_getModules(exporter); - for (modIdx = 0; modIdx < celix_arrayList_size(modules); modIdx++) { - module_pt module = (module_pt)celix_arrayList_get(modules, modIdx); - celix_array_list_t* dependents = module_getDependents(module); - if (dependents != NULL) { - unsigned int depIdx = 0; - for (depIdx = 0; depIdx < celix_arrayList_size(dependents); depIdx++) { - module_pt dependent = (module_pt)celix_arrayList_get(dependents, depIdx); - celix_arrayList_add(*list, module_getBundle(dependent)); - } - celix_arrayList_destroy(dependents); - } - } - - framework_logIfError(framework->logger, status, NULL, "Cannot get dependent bundles"); - - return status; -} - -celix_status_t fw_populateDependentGraph(framework_pt framework, bundle_pt exporter, hash_map_pt* map) { - celix_status_t status = CELIX_SUCCESS; - - if (framework == NULL || exporter == NULL) { - return CELIX_ILLEGAL_ARGUMENT; - } - - celix_array_list_t* dependents = NULL; - if ((status = fw_getDependentBundles(framework, exporter, &dependents)) == CELIX_SUCCESS) { - if (dependents != NULL) { - unsigned int depIdx = 0; - for (depIdx = 0; depIdx < celix_arrayList_size(dependents); depIdx++) { - if (!hashMap_containsKey(*map, celix_arrayList_get(dependents, depIdx))) { - hashMap_put(*map, celix_arrayList_get(dependents, depIdx), celix_arrayList_get(dependents, depIdx)); - fw_populateDependentGraph(framework, (bundle_pt)celix_arrayList_get(dependents, depIdx), map); - } - } - celix_arrayList_destroy(dependents); - } - } - - framework_logIfError(framework->logger, status, NULL, "Cannot populate dependent graph"); - - return status; -} - celix_status_t fw_registerService(framework_pt framework, service_registration_pt *registration, long bndId, const char* serviceName, const void* svcObj, celix_properties_t *properties) { celix_status_t status = CELIX_SUCCESS; char *error = NULL; @@ -1016,7 +963,7 @@ long framework_getNextBundleId(framework_pt framework) { return nextId; } -static celix_status_t framework_markBundleResolved(framework_pt framework, module_pt module) { +static celix_status_t framework_markBundleResolved(framework_pt framework, celix_module_t* module) { celix_status_t status = CELIX_SUCCESS; bundle_pt bundle = module_getBundle(module); bundle_state_e state; @@ -1935,7 +1882,8 @@ static long celix_framework_installAndStartBundleInternal(celix_framework_t *fw, if (!forcedAsync) { celix_framework_waitForBundleEvents(fw, bundleId); } - framework_logIfError(fw->logger, status, NULL, "Failed to install bundle '%s'", bundleLoc); + const char* action = autoStart ? "install and start" : "install"; + framework_logIfError(fw->logger, status, NULL, "Failed to %s bundle '%s'", action, bundleLoc); return bundleId; } @@ -1997,7 +1945,7 @@ static celix_status_t celix_framework_uninstallBundleEntryImpl(celix_framework_t celix_status_t status = CELIX_SUCCESS; celix_bundle_t *bnd = bndEntry->bnd; bundle_archive_t *archive = NULL; - bundle_revision_t *revision = NULL; + celix_bundle_revision_t*revision = NULL; celix_module_t* module = NULL; status = CELIX_DO_IF(status, bundle_getArchive(bnd, &archive)); status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision)); @@ -2020,7 +1968,7 @@ static celix_status_t celix_framework_uninstallBundleEntryImpl(celix_framework_t fw_bundleEntry_destroy(bndEntry, true); //wait till use count is 0 -> e.g. not used if (status == CELIX_SUCCESS) { - celix_framework_waitForEmptyEventQueue(framework); //to ensure that the uninstall event is triggered and handled + celix_framework_waitForEmptyEventQueue(framework); //to ensure that the uninstalled event is triggered and handled (void)bundle_destroy(bnd); if(permanent) { celix_bundleArchive_invalidate(archive); @@ -2109,8 +2057,8 @@ static celix_status_t celix_framework_stopBundleEntryInternal(celix_framework_t* CELIX_DO_IF(status, fw_fireBundleEvent(framework, OSGI_FRAMEWORK_BUNDLE_EVENT_STOPPING, bndEntry)); activator = bundle_getActivator(bndEntry->bnd); - status = CELIX_DO_IF(status, bundle_getContext(bndEntry->bnd, &context)); if (status == CELIX_SUCCESS) { + context = celix_bundle_getContext(bndEntry->bnd); if (activator->stop != NULL) { status = CELIX_DO_IF(status, activator->stop(activator->userData, context)); if (status == CELIX_SUCCESS) { @@ -2133,7 +2081,7 @@ static celix_status_t celix_framework_stopBundleEntryInternal(celix_framework_t* if (bndEntry->bndId > CELIX_FRAMEWORK_BUNDLE_ID) { //"normal" bundle if (status == CELIX_SUCCESS) { - module_pt module = NULL; + celix_module_t* module = NULL; const char *symbolicName = NULL; long id = 0; bundle_getCurrentModule(bndEntry->bnd, &module); @@ -2143,7 +2091,7 @@ static celix_status_t celix_framework_stopBundleEntryInternal(celix_framework_t* if (context != NULL) { status = CELIX_DO_IF(status, bundleContext_destroy(context)); - status = CELIX_DO_IF(status, bundle_setContext(bndEntry->bnd, NULL)); + CELIX_DO_IF(status, celix_bundle_setContext(bndEntry->bnd, NULL)); } status = CELIX_DO_IF(status, bundle_setState(bndEntry->bnd, CELIX_BUNDLE_STATE_RESOLVED)); @@ -2161,7 +2109,7 @@ static celix_status_t celix_framework_stopBundleEntryInternal(celix_framework_t* } if (status != CELIX_SUCCESS) { - module_pt module = NULL; + celix_module_t* module = NULL; const char *symbolicName = NULL; long id = 0; bundle_getCurrentModule(bndEntry->bnd, &module); @@ -2230,9 +2178,9 @@ static void celix_framework_printCelixErrForBundleEntry(celix_framework_t* frame celix_status_t celix_framework_startBundleEntry(celix_framework_t* framework, celix_bundle_entry_t* bndEntry) { assert(!celix_framework_isCurrentThreadTheEventLoop(framework)); celix_status_t status = CELIX_SUCCESS; - const char* error = ""; + const char* error = NULL; const char* name = ""; - module_pt module = NULL; + celix_module_t* module = NULL; celix_bundle_context_t* context = NULL; celix_bundle_activator_t* activator = NULL; @@ -2276,7 +2224,7 @@ celix_status_t celix_framework_startBundleEntry(celix_framework_t* framework, ce bundle_getCurrentModule(bndEntry->bnd, &module); module_getSymbolicName(module, &name); status = CELIX_DO_IF(status, bundleContext_create(framework, framework->logger, bndEntry->bnd, &context)); - status = CELIX_DO_IF(status, bundle_setContext(bndEntry->bnd, context)); + CELIX_DO_IF(status, celix_bundle_setContext(bndEntry->bnd, context)); if (status == CELIX_SUCCESS) { activator = calloc(1,(sizeof(*activator))); @@ -2296,9 +2244,8 @@ celix_status_t celix_framework_startBundleEntry(celix_framework_t* framework, ce status = CELIX_DO_IF(status, bundle_setState(bndEntry->bnd, CELIX_BUNDLE_STATE_STARTING)); CELIX_DO_IF(status, fw_fireBundleEvent(framework, OSGI_FRAMEWORK_BUNDLE_EVENT_STARTING, bndEntry)); - status = CELIX_DO_IF(status, bundle_getContext(bndEntry->bnd, &context)); - if (status == CELIX_SUCCESS) { + context = celix_bundle_getContext(bndEntry->bnd); if (activator->create != NULL) { status = CELIX_DO_IF(status, activator->create(context, &userData)); if (status == CELIX_SUCCESS) { @@ -2322,7 +2269,7 @@ celix_status_t celix_framework_startBundleEntry(celix_framework_t* framework, ce if (createCalled && activator->destroy) { activator->destroy(activator->userData, context); } - bundle_setContext(bndEntry->bnd, NULL); + celix_bundle_setContext(bndEntry->bnd, NULL); bundle_setActivator(bndEntry->bnd, NULL); bundleContext_destroy(context); free(activator); diff --git a/libs/framework/src/framework_bundle_lifecycle_handler.c b/libs/framework/src/framework_bundle_lifecycle_handler.c index 907b18ce0..9d0b57cd7 100644 --- a/libs/framework/src/framework_bundle_lifecycle_handler.c +++ b/libs/framework/src/framework_bundle_lifecycle_handler.c @@ -17,11 +17,11 @@ * under the License. */ -#include +#include "celix_bundle_private.h" +#include "celix_log.h" #include "celix_utils.h" #include "framework_private.h" -#include "celix_log.h" -#include "bundle.h" +#include static void celix_framework_cleanupBundleLifecycleHandler(celix_framework_t* fw, celix_framework_bundle_lifecycle_handler_t *handler) { celixThreadMutex_lock(&fw->bundleLifecycleHandling.mutex); diff --git a/libs/framework/src/framework_private.h b/libs/framework/src/framework_private.h index 457e16944..7de0d844f 100644 --- a/libs/framework/src/framework_private.h +++ b/libs/framework/src/framework_private.h @@ -24,7 +24,7 @@ #include "celix_framework.h" #include "framework.h" -#include "manifest.h" +#include "celix_bundle_manifest.h" #include "hash_map.h" #include "celix_array_list.h" #include "celix_errno.h" diff --git a/libs/framework/src/manifest.c b/libs/framework/src/manifest.c deleted file mode 100644 index 709d94351..000000000 --- a/libs/framework/src/manifest.c +++ /dev/null @@ -1,313 +0,0 @@ -/* - * 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. - */ -/** - * manifest.c - * - * \date Jul 5, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include -#include -#include -#include - -#include "celix_err.h" -#include "celix_errno.h" -#include "celix_stdio_cleanup.h" -#include "celix_stdlib_cleanup.h" -#include "celix_utils.h" -#include "manifest.h" -#include "utils.h" - -celix_status_t manifest_create(manifest_pt *manifest) { - celix_status_t status = CELIX_SUCCESS; - do { - celix_autofree manifest_pt manifestPtr = NULL; - manifestPtr = malloc(sizeof(**manifest)); - if (manifestPtr == NULL) { - status = CELIX_ENOMEM; - break; - } - celix_autoptr(celix_properties_t) mainAttributes = celix_properties_create(); - if (mainAttributes == NULL) { - status = CELIX_ENOMEM; - break; - } - manifestPtr->attributes = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); - if (manifestPtr->attributes == NULL) { - status = CELIX_ENOMEM; - break; - } - manifestPtr->mainAttributes = celix_steal_ptr(mainAttributes); - *manifest = celix_steal_ptr(manifestPtr); - } while(false); - - if (status != CELIX_SUCCESS) { - celix_err_pushf("Cannot create manifest: %s", celix_strerror(status)); - } - return status; -} - -manifest_pt manifest_clone(manifest_pt manifest) { - celix_status_t status = CELIX_SUCCESS; - - celix_auto(manifest_pt) clone = NULL; - status = manifest_create(&clone); - if (status == CELIX_SUCCESS) { - CELIX_PROPERTIES_ITERATE(manifest->mainAttributes, visit) { - celix_properties_set(clone->mainAttributes, visit.key, visit.entry.value); - } - hash_map_iterator_t iter = hashMapIterator_construct(manifest->attributes); - while (hashMapIterator_hasNext(&iter)) { - hash_map_entry_pt entry = hashMapIterator_nextEntry(&iter); - celix_autofree char* attrKey = celix_utils_strdup(hashMapEntry_getKey(entry)); - if (attrKey == NULL) { - return NULL; - } - celix_properties_t* value = hashMapEntry_getValue(entry); - celix_properties_t* cloneValue = celix_properties_copy(value); - if (cloneValue == NULL) { - return NULL; - } - hashMap_put(clone->attributes, celix_steal_ptr(attrKey), cloneValue); - } - } - - return celix_steal_ptr(clone); -} - -celix_status_t manifest_destroy(manifest_pt manifest) { - if (manifest != NULL) { - celix_properties_destroy(manifest->mainAttributes); - hash_map_iterator_t iter = hashMapIterator_construct(manifest->attributes); - while (hashMapIterator_hasNext(&iter)) { - hash_map_entry_pt entry = hashMapIterator_nextEntry(&iter); - celix_properties_t* value = hashMapEntry_getValue(entry); - celix_properties_destroy(value); - } - hashMap_destroy(manifest->attributes, true, false); - manifest->mainAttributes = NULL; - manifest->attributes = NULL; - free(manifest); - manifest = NULL; - } - return CELIX_SUCCESS; -} - -celix_status_t manifest_createFromFile(const char *filename, manifest_pt *manifest) { - celix_status_t status; - - celix_auto(manifest_pt) manifestNew = NULL; - status = manifest_create(&manifestNew); - - status = CELIX_DO_IF(status, manifest_read(manifestNew, filename)); - if (status == CELIX_SUCCESS) { - *manifest = celix_steal_ptr(manifestNew); - } else { - celix_err_pushf("Cannot create manifest from file: %s", celix_strerror(status)); - } - return status; -} - -//LCOV_EXCL_START -void manifest_clear(manifest_pt manifest) { - -} -//LCOV_EXCL_STOP - - celix_properties_t* manifest_getMainAttributes(manifest_pt manifest) { - return manifest->mainAttributes; -} - -celix_status_t manifest_getEntries(manifest_pt manifest, hash_map_pt *map) { - *map = manifest->attributes; - return CELIX_SUCCESS; -} - -celix_status_t manifest_read(manifest_pt manifest, const char *filename) { - celix_status_t status = CELIX_SUCCESS; - - celix_autoptr(FILE) file = fopen(filename, "r"); - if (file != NULL) { - status = manifest_readFromStream(manifest, file); - } else { - status = CELIX_ERROR_MAKE(CELIX_FACILITY_CERRNO,errno); - } - - if (status != CELIX_SUCCESS) { - celix_err_pushf("Cannot read manifest %s: %s", filename, celix_strerror(status)); - } - - return status; -} - -celix_status_t manifest_readFromStream(manifest_pt manifest, FILE* stream) { - char stackBuf[512]; - char *bytes = stackBuf; - - // get file size - if (fseek(stream, 0L, SEEK_END) == -1) { - return CELIX_ERROR_MAKE(CELIX_FACILITY_CERRNO, errno); - } - long int size = ftell(stream); - if (size < 0) { - return CELIX_ERROR_MAKE(CELIX_FACILITY_CERRNO,errno); - } else if (size >= INT_MAX) { - celix_err_pushf("Manifest error: file too large - %ld", size); - return CELIX_BUNDLE_EXCEPTION; - } - rewind(stream); - - celix_autofree char* heapBuf = NULL; - if (size+1 > sizeof(stackBuf)) { - heapBuf = bytes = malloc(size+1); - if (heapBuf == NULL) { - celix_err_pushf("Manifest error: failed to allocate %ld bytes", size); - return CELIX_ENOMEM; - } - } - - if(fread(bytes, 1, size, stream) != (size_t)size) { - return CELIX_FILE_IO_EXCEPTION; - } - // Force a new line at the end of the manifest to deal with broken manifest without any line-ending - bytes[size++] = '\n'; - - const char* key = NULL; - int last = 0; - int current = 0; - celix_properties_t *headers = manifest->mainAttributes; - for (int i = 0; i < size; i++) - { - // skip \r and \n if it is followed by another \n - // (we catch the blank line case in the next iteration) - if (bytes[i] == '\r') - { - if ((i + 1 < size) && (bytes[i + 1] == '\n')) - { - continue; - } - } - if (bytes[i] == '\n') - { - if ((i + 1 < size) && (bytes[i + 1] == ' ')) - { - i++; - continue; - } - } - // If we don't have a key yet and see the first : we parse it as the key - // and skip the : that follows it. - if ((key == NULL) && (bytes[i] == ':')) - { - key = &bytes[last]; - // precondition: current <= i - bytes[current++] = '\0'; - if ((i + 1 < size) && (bytes[i + 1] == ' ')) - { - last = current + 1; - continue; - } - else - { - celix_err_pushf("Manifest error: Missing space separator - %s", key); - return CELIX_INVALID_SYNTAX; - } - } - // if we are at the end of a line - if (bytes[i] == '\n') - { - // and it is a blank line stop parsing (main attributes are done) - if ((last == current) && (key == NULL)) - { - headers = NULL; - continue; - } - // Otherwise, parse the value and add it to the map (we return - // if we don't have a key or the key already exist). - const char* value = &bytes[last]; - // precondition: current <= i - bytes[current++] = '\0'; - - if (key == NULL) - { - celix_err_pushf("Manifest error: Missing attribute name - %s", value); - return CELIX_INVALID_SYNTAX; - } - else if (headers != NULL && celix_properties_get(headers, key, NULL) != NULL) - { - celix_err_pushf("Manifest error: Duplicate attribute name - %s", key); - return CELIX_INVALID_SYNTAX; - } - if (headers == NULL) { - // beginning of individual-section - if (strcasecmp(key, "Name")) { - celix_err_push("Manifest error: individual-section missing Name attribute"); - return CELIX_INVALID_SYNTAX; - } - headers = hashMap_get(manifest->attributes, value); - if (headers == NULL) { - celix_autofree char* name = celix_utils_strdup(value); - if (name == NULL) { - return CELIX_ENOMEM; - } - headers = celix_properties_create(); - if (headers == NULL) { - return CELIX_ENOMEM; - } - hashMap_put(manifest->attributes, (void*)celix_steal_ptr(name), headers); - } - } else if (headers == manifest->mainAttributes && celix_properties_size(headers) == 0) { - // beginning of main-section - if (strcasecmp(key, "Manifest-Version")) { - celix_err_push("Manifest error: main-section must start with Manifest-Version"); - return CELIX_INVALID_SYNTAX; - } - } - celix_properties_set(headers, key, value); - last = current; - key = NULL; - } - else - { - // precondition: current <= i - // write back the byte if it needs to be included in the key or the value. - bytes[current++] = bytes[i]; - } - } - if (celix_properties_size(manifest->mainAttributes) == 0) { - celix_err_push("Manifest error: Empty"); - return CELIX_INVALID_SYNTAX; - } - return CELIX_SUCCESS; -} - -//LCOV_EXCL_START -void manifest_write(manifest_pt manifest, const char * filename) { - -} -//LCOV_EXCL_STOP - -const char* manifest_getValue(manifest_pt manifest, const char* name) { - const char* val = celix_properties_get(manifest->mainAttributes, name, NULL); - bool isEmpty = utils_isStringEmptyOrNull(val); - return isEmpty ? NULL : val; -} diff --git a/libs/framework/src/manifest_parser.c b/libs/framework/src/manifest_parser.c deleted file mode 100644 index 1b1e38954..000000000 --- a/libs/framework/src/manifest_parser.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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. - */ -/** - * manifest_parser.c - * - * \date Jul 12, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#include -#include - -#include "celix_utils.h" -#include "celix_constants.h" -#include "manifest_parser.h" -#include "celix_errno.h" -#include "celix_log.h" - -struct manifestParser { - module_pt owner; - manifest_pt manifest; - celix_version_t* bundleVersion; - // TODO: Implement Requirement-Capability-Model using RCM library -}; - -celix_status_t manifestParser_create(module_pt owner, manifest_pt manifest, manifest_parser_pt *manifest_parser) { - celix_status_t status; - manifest_parser_pt parser; - - status = CELIX_SUCCESS; - parser = (manifest_parser_pt) malloc(sizeof(*parser)); - if (parser) { - const char * bundleVersion = NULL; - parser->manifest = manifest; - parser->owner = owner; - - bundleVersion = manifest_getValue(manifest, CELIX_FRAMEWORK_BUNDLE_VERSION); - if (bundleVersion != NULL) { - parser->bundleVersion = celix_version_createVersionFromString(bundleVersion); - } else { - parser->bundleVersion = celix_version_createEmptyVersion(); - } - - *manifest_parser = parser; - - status = CELIX_SUCCESS; - } else { - status = CELIX_ENOMEM; - } - - framework_logIfError(celix_frameworkLogger_globalLogger(), status, NULL, "Cannot create manifest parser"); - - return status; -} - -celix_status_t manifestParser_destroy(manifest_parser_pt mp) { - celix_version_destroy(mp->bundleVersion); - mp->bundleVersion = NULL; - mp->manifest = NULL; - mp->owner = NULL; - - free(mp); - - return CELIX_SUCCESS; -} - -static celix_status_t manifestParser_getDuplicateEntry(manifest_parser_pt parser, const char* entryName, char **result) { - const char *val = manifest_getValue(parser->manifest, entryName); - if (result != NULL && val == NULL) { - *result = NULL; - } else if (result != NULL) { - *result = celix_utils_strdup(val); - } - return CELIX_SUCCESS; -} - -celix_status_t manifestParser_getAndDuplicateGroup(manifest_parser_pt parser, char **group) { - return manifestParser_getDuplicateEntry(parser, CELIX_FRAMEWORK_BUNDLE_GROUP, group); -} - -celix_status_t manifestParser_getAndDuplicateSymbolicName(manifest_parser_pt parser, char **symbolicName) { - return manifestParser_getDuplicateEntry(parser, CELIX_FRAMEWORK_BUNDLE_SYMBOLICNAME, symbolicName); -} - -celix_status_t manifestParser_getAndDuplicateName(manifest_parser_pt parser, char **name) { - return manifestParser_getDuplicateEntry(parser, CELIX_FRAMEWORK_BUNDLE_NAME, name); -} - -celix_status_t manifestParser_getAndDuplicateDescription(manifest_parser_pt parser, char **description) { - return manifestParser_getDuplicateEntry(parser, CELIX_FRAMEWORK_BUNDLE_DESCRIPTION, description); -} - -celix_status_t manifestParser_getBundleVersion(manifest_parser_pt parser, celix_version_t **version) { - *version = celix_version_copy(parser->bundleVersion); - return *version == NULL ? CELIX_ENOMEM : CELIX_SUCCESS; -} \ No newline at end of file diff --git a/libs/framework/src/manifest_parser.h b/libs/framework/src/manifest_parser.h deleted file mode 100644 index 0f9954067..000000000 --- a/libs/framework/src/manifest_parser.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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. - */ -/** - * manifest_parser.h - * - * \date Jul 13, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ - -#ifndef MANIFEST_PARSER_H_ -#define MANIFEST_PARSER_H_ - -#include "module.h" -#include "celix_version.h" -#include "manifest.h" - -typedef struct manifestParser * manifest_parser_pt; - -celix_status_t manifestParser_create(module_pt owner, manifest_pt manifest, manifest_parser_pt *manifest_parser); -celix_status_t manifestParser_destroy(manifest_parser_pt mp); - -celix_status_t manifestParser_getAndDuplicateSymbolicName(manifest_parser_pt parser, char **symbolicName); -celix_status_t manifestParser_getAndDuplicateName(manifest_parser_pt parser, char **name); -celix_status_t manifestParser_getAndDuplicateDescription(manifest_parser_pt parser, char **description); -celix_status_t manifestParser_getBundleVersion(manifest_parser_pt parser, celix_version_t **version); -celix_status_t manifestParser_getAndDuplicateGroup(manifest_parser_pt parser, char **group); - -#endif /* MANIFEST_PARSER_H_ */ diff --git a/libs/framework/src/module.c b/libs/framework/src/module.c index 33b888312..cae9dd9e3 100644 --- a/libs/framework/src/module.c +++ b/libs/framework/src/module.c @@ -17,21 +17,22 @@ * under the License. */ +#include #include #include #include #include -#include "celix_utils.h" -#include "utils.h" -#include "module.h" -#include "manifest_parser.h" -#include "celix_libloader.h" -#include "celix_framework.h" +#include "bundle_archive_private.h" +#include "celix_bundle_manifest.h" #include "celix_constants.h" +#include "celix_framework.h" +#include "celix_libloader.h" +#include "celix_module.h" +#include "celix_utils.h" #include "framework_private.h" -#include "bundle_archive_private.h" - +#include "utils.h" +#include "celix_bundle_private.h" #ifdef __linux__ #define CELIX_LIBRARY_PREFIX "lib" @@ -44,183 +45,121 @@ #define CELIX_LIBRARY_EXTENSION = ".dll"; #endif -struct module { +struct celix_module { celix_framework_t* fw; - - celix_version_t* version; - char* symbolicName; - char* group; - char* name; - char* description; bool resolved; - - char* id; - celix_bundle_t* bundle; - - celix_thread_mutex_t handlesLock; // protects libraryHandles and bundleActivatorHandle + celix_thread_mutex_t handlesLock; // protects libraryHandles celix_array_list_t* libraryHandles; - void* bundleActivatorHandle; }; -module_pt module_create(manifest_pt headerMap, const char * moduleId, bundle_pt bundle) { - module_pt module = NULL; - manifest_parser_pt mp; - celix_framework_t* fw = NULL; - bundle_getFramework(bundle, &fw); - - if (headerMap != NULL && fw != NULL) { - module = (module_pt) calloc(1, sizeof(*module)); - module->fw = fw; - module->id = strdup(moduleId); - module->bundle = bundle; - module->resolved = false; - celixThreadMutex_create(&module->handlesLock, NULL); - module->libraryHandles = celix_arrayList_create(); - - - if (manifestParser_create(module, headerMap, &mp) == CELIX_SUCCESS) { - module->symbolicName = NULL; - manifestParser_getAndDuplicateSymbolicName(mp, &module->symbolicName); - - module->group = NULL; - manifestParser_getAndDuplicateGroup(mp, &module->group); - - module->name = NULL; - manifestParser_getAndDuplicateName(mp, &module->name); +static celix_bundle_manifest_t* celix_module_getManifestFromBundle(celix_bundle_t* bundle) { + bundle_archive_t* archive = celix_bundle_getArchive(bundle); + celix_bundle_revision_t* revision = NULL; + (void)bundleArchive_getCurrentRevision(archive, &revision); + return celix_bundleRevision_getManifest(revision); +} - module->description = NULL; - manifestParser_getAndDuplicateDescription(mp, &module->description); +celix_module_t* module_create(celix_bundle_t* bundle) { + assert(bundle != NULL); - module->version = NULL; - manifestParser_getBundleVersion(mp, &module->version); + celix_framework_t* fw; + bundle_getFramework(bundle, &fw); - manifestParser_destroy(mp); - } + celix_autoptr(celix_module_t) module = calloc(1, sizeof(*module)); + celix_autoptr(celix_array_list_t) libraryHandles = celix_arrayList_createPointerArray(); + if (!module || !libraryHandles) { + fw_log(fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to create module, out of memory"); + return NULL; } - return module; -} + celix_status_t status = celixThreadMutex_create(&module->handlesLock, NULL); + if (status != CELIX_SUCCESS) { + fw_log(fw->logger, + CELIX_LOG_LEVEL_ERROR, + "Failed to create module, error creating mutex: %s", + celix_strerror(errno)); + celix_framework_logTssErrors(fw->logger, CELIX_LOG_LEVEL_ERROR); + return NULL; + } -module_pt module_createFrameworkModule(celix_framework_t* fw, bundle_pt bundle) { - module_pt module; + module->fw = fw; + module->bundle = bundle; + module->resolved = false; + module->libraryHandles = celix_steal_ptr(libraryHandles); - module = (module_pt)calloc(1, sizeof(*module)); - char modId[2]; - snprintf(modId, 2, "%li", CELIX_FRAMEWORK_BUNDLE_ID); - if (module) { - module->fw = fw; - module->id = celix_utils_strdup(modId); - module->symbolicName = celix_utils_strdup("celix_framework"); - module->group = celix_utils_strdup("Celix/Framework"); - module->name = celix_utils_strdup("Celix Framework"); - module->description = celix_utils_strdup("The Celix Framework System Bundle"); - module->version = celix_version_create(1, 0, 0, ""); - module->resolved = false; - module->bundle = bundle; - celixThreadMutex_create(&module->handlesLock, NULL); - module->libraryHandles = celix_arrayList_create(); - } - return module; + return celix_steal_ptr(module); } -void module_destroy(module_pt module) { - celix_version_destroy(module->version); - free(module->id); - free(module->symbolicName); - free(module->name); - free(module->group); - free(module->description); +void module_destroy(celix_module_t* module) { + if (module) { celix_arrayList_destroy(module->libraryHandles); celixThreadMutex_destroy(&module->handlesLock); free(module); + } } -celix_version_t* module_getVersion(module_pt module) { return module->version; } - -celix_status_t module_getSymbolicName(module_pt module, const char **symbolicName) { - celix_status_t status = CELIX_SUCCESS; - if (module == NULL) { - status = CELIX_ILLEGAL_ARGUMENT; - } else { - *symbolicName = module->symbolicName; - } - return status; +const celix_version_t* module_getVersion(celix_module_t* module) { + celix_bundle_manifest_t* man = celix_module_getManifestFromBundle(module->bundle); + return celix_bundleManifest_getBundleVersion(man); } -celix_status_t module_getName(module_pt module, const char **symbolicName) { +celix_status_t module_getSymbolicName(celix_module_t* module, const char** symbolicName) { celix_status_t status = CELIX_SUCCESS; if (module == NULL) { status = CELIX_ILLEGAL_ARGUMENT; } else { - *symbolicName = module->name; + celix_bundle_manifest_t* man = celix_module_getManifestFromBundle(module->bundle); + *symbolicName = celix_bundleManifest_getBundleSymbolicName(man); } return status; } -celix_status_t module_getGroup(module_pt module, const char **symbolicName) { +celix_status_t module_getName(celix_module_t* module, const char **name) { celix_status_t status = CELIX_SUCCESS; if (module == NULL) { status = CELIX_ILLEGAL_ARGUMENT; } else { - *symbolicName = module->group; + celix_bundle_manifest_t* man = celix_module_getManifestFromBundle(module->bundle); + *name = celix_bundleManifest_getBundleName(man); } return status; } -celix_status_t module_getDescription(module_pt module, const char **description) { +celix_status_t module_getGroup(celix_module_t* module, const char **group) { celix_status_t status = CELIX_SUCCESS; if (module == NULL) { status = CELIX_ILLEGAL_ARGUMENT; } else { - *description = module->description; + celix_bundle_manifest_t* man = celix_module_getManifestFromBundle(module->bundle); + *group = celix_bundleManifest_getBundleGroup(man); } return status; } -char * module_getId(module_pt module) { - return module->id; +celix_status_t module_getDescription(celix_module_t* module, const char **description) { + celix_status_t status = CELIX_SUCCESS; + if (module == NULL) { + status = CELIX_ILLEGAL_ARGUMENT; + } else { + celix_bundle_manifest_t* man = celix_module_getManifestFromBundle(module->bundle); + *description = celix_bundleManifest_getBundleDescription(man); + } + return status; } -bool module_isResolved(module_pt module) { +bool module_isResolved(celix_module_t* module) { return module->resolved; } -void module_setResolved(module_pt module) { +void module_setResolved(celix_module_t* module) { module->resolved = true; } -bundle_pt module_getBundle(module_pt module) { +bundle_pt module_getBundle(celix_module_t* module) { return module->bundle; } -celix_array_list_t* module_getDependentImporters(module_pt module) { - return NULL; -} - -void module_addDependentImporter(module_pt module, module_pt importer) { -} - -void module_removeDependentImporter(module_pt module, module_pt importer) { -} - -//---------------------------------------------------- -//TODO add implementation (functions not implemented but already exported) -celix_array_list_t* module_getDependentRequirers(module_pt module) { - return NULL; -} - -void module_addDependentRequirer(module_pt module, module_pt requirer) { -} - -void module_removeDependentRequirer(module_pt module, module_pt requirer) { -} -//---------------------------------------------------- - -celix_array_list_t* module_getDependents(module_pt module) { - return NULL; -} - celix_status_t celix_module_closeLibraries(celix_module_t* module) { celix_status_t status = CELIX_SUCCESS; celix_bundle_context_t *fwCtx = celix_framework_getFrameworkContext(module->fw); @@ -231,7 +170,6 @@ celix_status_t celix_module_closeLibraries(celix_module_t* module) { celix_libloader_close(fwCtx, handle); } celix_arrayList_clear(module->libraryHandles); - module->bundleActivatorHandle = NULL; celixThreadMutex_unlock(&module->handlesLock); return status; } @@ -253,11 +191,13 @@ static celix_status_t celix_module_loadLibrary(celix_module_t* module, const cha return status; } - -static celix_status_t celix_module_loadLibraryForManifestEntry(celix_module_t* module, const char *library, bundle_archive_pt archive, void **handle) { +static celix_status_t celix_module_loadLibraryForManifestEntry(celix_module_t* module, + const char* library, + bundle_archive_pt archive, + void** handle) { celix_status_t status = CELIX_SUCCESS; - const char *error = NULL; + const char* error = NULL; char libraryPath[512]; const char* revRoot = celix_bundleArchive_getCurrentRevisionRoot(archive); @@ -270,7 +210,13 @@ static celix_status_t celix_module_loadLibraryForManifestEntry(celix_module_t* m if (strstr(library, CELIX_LIBRARY_EXTENSION)) { path = celix_utils_writeOrCreateString(libraryPath, sizeof(libraryPath), "%s/%s", revRoot, library); } else { - path = celix_utils_writeOrCreateString(libraryPath, sizeof(libraryPath), "%s/%s%s%s", revRoot, CELIX_LIBRARY_PREFIX, library, CELIX_LIBRARY_EXTENSION); + path = celix_utils_writeOrCreateString(libraryPath, + sizeof(libraryPath), + "%s/%s%s%s", + revRoot, + CELIX_LIBRARY_PREFIX, + library, + CELIX_LIBRARY_EXTENSION); } if (!path) { @@ -284,87 +230,53 @@ static celix_status_t celix_module_loadLibraryForManifestEntry(celix_module_t* m return status; } -static celix_status_t celix_module_loadLibrariesInManifestEntry(celix_module_t* module, const char *librariesIn, const char *activator, bundle_archive_pt archive, void **activatorHandle) { +static celix_status_t celix_module_loadLibrariesInManifestEntry(celix_module_t* module, + const celix_array_list_t* libraries, + const char* activator, + bundle_archive_pt archive, + void** activatorHandle) { + assert(libraries != NULL); + assert(celix_arrayList_getElementType(libraries) == CELIX_ARRAY_LIST_ELEMENT_TYPE_STRING); celix_status_t status = CELIX_SUCCESS; - char* libraries = strndup(librariesIn, 1024*10); - char* saveptr1; - for (char* str1 = libraries; status == CELIX_SUCCESS; str1 = NULL) { - char* token = strtok_r(str1, ",", &saveptr1); - char* saveptr2; - if (token == NULL) { + for (int i = 0; i < celix_arrayList_size(libraries); i++) { + const char* library = celix_arrayList_getString(libraries, i); + void* handle = NULL; + status = celix_module_loadLibraryForManifestEntry(module, library, archive, &handle); + if (status != CELIX_SUCCESS) { break; } - char *pathToken = strtok_r(token, ";", &saveptr2); - if (pathToken == NULL) { - continue; - } - - void *handle = NULL; - char lib[128]; - lib[127] = '\0'; - strncpy(lib, pathToken, 127); - char *trimmedLib = celix_utils_trimInPlace(lib); - status = celix_module_loadLibraryForManifestEntry(module, trimmedLib, archive, &handle); - - if ( (status == CELIX_SUCCESS) && (activator != NULL) && (strcmp(trimmedLib, activator) == 0) ) { + if (activator != NULL && strcmp(library, activator) == 0) { *activatorHandle = handle; } } - free(libraries); return status; } celix_status_t celix_module_loadLibraries(celix_module_t* module) { celix_status_t status = CELIX_SUCCESS; celix_library_handle_t* activatorHandle = NULL; - bundle_archive_pt archive = NULL; - bundle_revision_pt revision = NULL; - manifest_pt manifest = NULL; - - status = CELIX_DO_IF(status, bundle_getArchive(module->bundle, &archive)); - status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision)); - status = CELIX_DO_IF(status, bundleRevision_getManifest(revision, &manifest)); - if (status == CELIX_SUCCESS) { - const char *privateLibraries = NULL; - const char *exportLibraries = NULL; - const char *activator = NULL; - - privateLibraries = manifest_getValue(manifest, CELIX_FRAMEWORK_PRIVATE_LIBRARY); - exportLibraries = manifest_getValue(manifest, CELIX_FRAMEWORK_EXPORT_LIBRARY); - //@note not import yet - activator = manifest_getValue(manifest, CELIX_FRAMEWORK_BUNDLE_ACTIVATOR); - - if (exportLibraries != NULL) { - status = CELIX_DO_IF(status, celix_module_loadLibrariesInManifestEntry(module, exportLibraries, activator, archive, &activatorHandle)); - } + bundle_archive_t* archive = celix_bundle_getArchive(module->bundle); - if (privateLibraries != NULL) { - status = CELIX_DO_IF(status, - celix_module_loadLibrariesInManifestEntry(module, privateLibraries, activator, archive, &activatorHandle)); - } + celix_bundle_manifest_t* man = celix_module_getManifestFromBundle(module->bundle); + const char* activator = celix_bundleManifest_getBundleActivatorLibrary(man); + const celix_array_list_t* privateLibraries = celix_bundleManifest_getBundlePrivateLibraries(man); - if (status == CELIX_SUCCESS) { - bundle_setHandle(module->bundle, activatorHandle); //note deprecated - celixThreadMutex_lock(&module->handlesLock); - module->bundleActivatorHandle = activatorHandle; - celixThreadMutex_unlock(&module->handlesLock); - } + if (privateLibraries != NULL && celix_arrayList_size(privateLibraries) > 0) { + status = CELIX_DO_IF( + status, + celix_module_loadLibrariesInManifestEntry(module, privateLibraries, activator, archive, &activatorHandle)); } - if (status != CELIX_SUCCESS) { - fw_logCode(module->fw->logger, CELIX_LOG_LEVEL_ERROR, status, "Could not load libraries for bundle %s", + fw_logCode(module->fw->logger, + CELIX_LOG_LEVEL_ERROR, + status, + "Could not load libraries for bundle %s", celix_bundle_getSymbolicName(module->bundle)); (void)celix_module_closeLibraries(module); } + bundle_setHandle(module->bundle, activatorHandle); return status; } - -void* celix_module_getBundleActivatorHandler(celix_module_t* module) { - celixThreadMutex_lock(&module->handlesLock); - void* handle = module->bundleActivatorHandle; - celixThreadMutex_unlock(&module->handlesLock); - return handle; -} diff --git a/libs/framework/src/service_reference.c b/libs/framework/src/service_reference.c index 58557f70e..9a8b52a7d 100644 --- a/libs/framework/src/service_reference.c +++ b/libs/framework/src/service_reference.c @@ -16,27 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -/** - * service_reference.c - * - * \date Jul 20, 2010 - * \author Apache Celix Project Team - * \copyright Apache License, Version 2.0 - */ #include #include -#include "celix_compiler.h" -#include "celix_constants.h" #include #include #include #include "service_reference.h" - +#include "celix_compiler.h" +#include "celix_constants.h" +#include "celix_build_assert.h" +#include "celix_log.h" #include "service_reference_private.h" #include "service_registration_private.h" -#include "celix_build_assert.h" static bool serviceReference_doRelease(struct celix_ref *); static void serviceReference_destroy(service_reference_pt); diff --git a/libs/framework/src/service_reference_private.h b/libs/framework/src/service_reference_private.h index 79b11152d..14cee2fce 100644 --- a/libs/framework/src/service_reference_private.h +++ b/libs/framework/src/service_reference_private.h @@ -30,7 +30,7 @@ #include "registry_callback_private.h" #include "service_reference.h" #include "celix_ref.h" - +#include "celix_threads.h" struct serviceReference { struct celix_ref refCount; diff --git a/libs/framework/src/service_registration.c b/libs/framework/src/service_registration.c index 5744bd1e3..40364964e 100644 --- a/libs/framework/src/service_registration.c +++ b/libs/framework/src/service_registration.c @@ -18,13 +18,14 @@ */ #include -#include #include #include "celix_build_assert.h" #include "celix_constants.h" #include "celix_err.h" #include "service_registration_private.h" +#include "celix_log.h" +#include "service_factory.h" static bool serviceRegistration_destroy(struct celix_ref *); static celix_status_t serviceRegistration_initializeProperties(service_registration_t*registration, diff --git a/libs/framework/src/service_registration_private.h b/libs/framework/src/service_registration_private.h index 8f00b7541..34a561138 100644 --- a/libs/framework/src/service_registration_private.h +++ b/libs/framework/src/service_registration_private.h @@ -24,6 +24,8 @@ #include "registry_callback_private.h" #include "service_registration.h" #include "celix_ref.h" +#include "celix_service_factory.h" +#include "celix_threads.h" enum celix_service_type { CELIX_PLAIN_SERVICE, diff --git a/libs/framework/src/service_registry.c b/libs/framework/src/service_registry.c index 0afcd4ae4..b7e8e7dd7 100644 --- a/libs/framework/src/service_registry.c +++ b/libs/framework/src/service_registry.c @@ -23,14 +23,15 @@ #include #include -#include "service_registry_private.h" -#include "service_registration_private.h" -#include "listener_hook_service.h" +#include "celix_bundle_private.h" #include "celix_constants.h" #include "celix_stdlib_cleanup.h" #include "celix_version_range.h" -#include "service_reference_private.h" #include "framework_private.h" +#include "listener_hook_service.h" +#include "service_reference_private.h" +#include "service_registration_private.h" +#include "service_registry_private.h" static celix_status_t serviceRegistry_registerServiceInternal(service_registry_pt registry, bundle_pt bundle, const char* serviceName, const void * serviceObject, celix_properties_t* dictionary, long reservedId, enum celix_service_type svcType, service_registration_pt *registration); static celix_status_t serviceRegistry_unregisterService(service_registry_pt registry, bundle_pt bundle, service_registration_pt registration); @@ -570,7 +571,7 @@ static celix_status_t serviceRegistry_addHooks(service_registry_pt registry, con for (int i = 0; i < celix_arrayList_size(listeners); ++i) { celix_service_registry_service_listener_entry_t *listenerEntry = celix_arrayList_get(listeners, i); - bundle_getContext(listenerEntry->bundle, &info.context); + info.context = celix_bundle_getContext(listenerEntry->bundle); info.filter = celix_filter_getFilterString(listenerEntry->filter); entry->hook->added(entry->hook->handle, infos); celix_decreaseCountServiceListener(listenerEntry); @@ -617,7 +618,7 @@ static celix_status_t serviceRegistry_removeHook(service_registry_pt registry, s if (removedEntry != NULL) { for (int i = 0; i < celix_arrayList_size(listeners); ++i) { celix_service_registry_service_listener_entry_t *listenerEntry = celix_arrayList_get(listeners, i); - bundle_getContext(listenerEntry->bundle, &info.context); + info.context = celix_bundle_getContext(listenerEntry->bundle); info.filter = celix_filter_getFilterString(listenerEntry->filter); removedEntry->hook->removed(removedEntry->hook->handle, infos); celix_decreaseCountServiceListener(listenerEntry); @@ -633,8 +634,7 @@ static celix_status_t serviceRegistry_removeHook(service_registry_pt registry, s } static void serviceRegistry_callHooksForListenerFilter(service_registry_pt registry, celix_bundle_t *owner, const celix_filter_t *filter, bool removed) { - celix_bundle_context_t *ctx; - bundle_getContext(owner, &ctx); + celix_bundle_context_t *ctx = celix_bundle_getContext(owner); struct listener_hook_info info; info.context = ctx; diff --git a/libs/utils/gtest/src/ConvertUtilsTestSuite.cc b/libs/utils/gtest/src/ConvertUtilsTestSuite.cc index 9aeb0cc67..95a683c64 100644 --- a/libs/utils/gtest/src/ConvertUtilsTestSuite.cc +++ b/libs/utils/gtest/src/ConvertUtilsTestSuite.cc @@ -349,6 +349,12 @@ TEST_F(ConvertUtilsTestSuite, ConvertToLongArrayTest) { EXPECT_EQ(2L, celix_arrayList_getLong(result, 1)); celix_arrayList_destroy(result); + convertState = celix_utils_convertStringToLongArrayList("", nullptr, &result); + EXPECT_EQ(CELIX_SUCCESS, convertState); + EXPECT_TRUE(result != nullptr); + EXPECT_EQ(0, celix_arrayList_size(result)); + celix_arrayList_destroy(result); + convertState = celix_utils_convertStringToLongArrayList(nullptr, defaultList, &result); EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, convertState); EXPECT_TRUE(result != nullptr); //copy of default list @@ -479,6 +485,13 @@ TEST_F(ConvertUtilsTestSuite, ConvertToStringArrayList) { EXPECT_STREQ("", celix_arrayList_getString(result, 3)); celix_arrayList_destroy(result); + //empty string -> empty list + convertState = celix_utils_convertStringToStringArrayList("", nullptr, &result); + EXPECT_EQ(CELIX_SUCCESS, convertState); + EXPECT_TRUE(result != nullptr); + EXPECT_EQ(0, celix_arrayList_size(result)); + celix_arrayList_destroy(result); + //invalid escape sequence convertState = celix_utils_convertStringToStringArrayList(R"(a,b\c,d)", nullptr, &result); EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, convertState); @@ -492,6 +505,7 @@ TEST_F(ConvertUtilsTestSuite, ConvertToStringArrayList) { // tested, we only test a few cases here. } + TEST_F(ConvertUtilsTestSuite, StringArrayToStringTest) { celix_autoptr(celix_array_list_t) list = celix_arrayList_createStringArray(); celix_arrayList_addString(list, "a"); diff --git a/libs/utils/gtest/src/PropertiesTestSuite.cc b/libs/utils/gtest/src/PropertiesTestSuite.cc index 391488c4c..bfb908783 100644 --- a/libs/utils/gtest/src/PropertiesTestSuite.cc +++ b/libs/utils/gtest/src/PropertiesTestSuite.cc @@ -494,6 +494,13 @@ TEST_F(PropertiesTestSuite, GetVersionTest) { celix_version_destroy(ver3); celix_version_destroy(ver4); + celix_properties_setBool(properties, "bool", true); + celix_version_t* ver5; + status = celix_properties_getAsVersion(properties, "bool", nullptr, &ver5); + EXPECT_EQ(ver5, nullptr); + EXPECT_EQ(status, CELIX_SUCCESS); + celix_version_destroy(ver5); + celix_version_destroy(emptyVersion); celix_properties_destroy(properties); } diff --git a/libs/utils/include/celix_array_list.h b/libs/utils/include/celix_array_list.h index 6c41f2af2..8393bc238 100644 --- a/libs/utils/include/celix_array_list.h +++ b/libs/utils/include/celix_array_list.h @@ -19,6 +19,7 @@ #include +#include "celix_array_list_type.h" #include "celix_utils_export.h" #include "celix_cleanup.h" #include "celix_errno.h" @@ -41,6 +42,11 @@ extern "C" { #endif +/** + * @file celix_array_list.h + * @brief Header file for celix_array_list_t functions and celix_array_list_t specific types. + */ + /** * @enum celix_array_list_element_type_t * @brief An enumeration of the types of elements that can be stored in a Celix array list. @@ -77,11 +83,6 @@ typedef union celix_array_list_entry { CELIX_ARRAY_LIST_ELEMENT_TYPE_VERSION or CELIX_ARRAY_LIST_ELEMENT_TYPE_UNDEFINED. */ } celix_array_list_entry_t; -/** - * @brief A celix array list, which can store a list of undefined elements. - */ -typedef struct celix_array_list celix_array_list_t; - /** * @brief Equals function for array list entries, can be provided when creating a array list. */ diff --git a/libs/utils/include/celix_array_list_type.h b/libs/utils/include/celix_array_list_type.h new file mode 100644 index 000000000..a7e4e60a6 --- /dev/null +++ b/libs/utils/include/celix_array_list_type.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef CELIX_ARRAY_LIST_TYPE_H_ +#define CELIX_ARRAY_LIST_TYPE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file celix_array_list_type.h + * @brief Header file for celix_array_list_t type. + */ + +/** + * @brief A celix array list, which can store a list of undefined elements. + */ +typedef struct celix_array_list celix_array_list_t; + +#ifdef __cplusplus +} +#endif + +#undef CELIX_OPTS_INIT + +#endif /* CELIX_ARRAY_LIST_TYPE_H_ */ diff --git a/libs/utils/include/celix_errno.h b/libs/utils/include/celix_errno.h index 8189192b3..15937fc36 100644 --- a/libs/utils/include/celix_errno.h +++ b/libs/utils/include/celix_errno.h @@ -67,17 +67,6 @@ extern "C" { } \ } while (0) -/*! - * \defgroup celix_errno Error Codes - * \ingroup framework - * \{ - */ - -struct __attribute__((deprecated("use celix_status_t instead"))) celix_status { - int code; - char *error; -}; - /*! * Status type returned by all functions in Celix */ diff --git a/libs/utils/include/celix_properties.h b/libs/utils/include/celix_properties.h index b145fc72d..08a2d773b 100644 --- a/libs/utils/include/celix_properties.h +++ b/libs/utils/include/celix_properties.h @@ -450,7 +450,8 @@ CELIX_UTILS_EXPORT const celix_version_t* celix_properties_getVersion(const celi * @brief Get a value of a property as a copied Celix version. * * If the property value is a Celix version, a copy of the found version will be returned. - * If the property value is a string, this function will attempt to convert it to a new Celix version. + * If the property value is present, but not a Celix version, this function will attempt to convert the property value + * to a new Celix version. * If the property is not set or is not a valid Celix version string, a copy of the provided defaultValue is returned. * * @note The caller is responsible for deallocating the memory of the returned version. diff --git a/libs/utils/src/celix_convert_utils.c b/libs/utils/src/celix_convert_utils.c index 32bbbcbfd..2182335aa 100644 --- a/libs/utils/src/celix_convert_utils.c +++ b/libs/utils/src/celix_convert_utils.c @@ -157,6 +157,11 @@ static celix_status_t celix_utils_convertStringToArrayList(const char* val, return CELIX_ILLEGAL_ARGUMENT; } + if (celix_utils_isStringNullOrEmpty(val)) { + *listOut = celix_steal_ptr(list); + return CELIX_SUCCESS; // empty string -> empty list + } + char* buf = NULL; size_t bufSize = 0; FILE* entryStream = NULL; diff --git a/libs/utils/src/properties.c b/libs/utils/src/properties.c index 3ec19a2f7..f48c1eb31 100644 --- a/libs/utils/src/properties.c +++ b/libs/utils/src/properties.c @@ -616,9 +616,8 @@ celix_status_t celix_properties_getAsVersion(const celix_properties_t* propertie } *version = copy; return CELIX_SUCCESS; - } - if (entry != NULL && entry->valueType == CELIX_PROPERTIES_VALUE_TYPE_STRING) { - celix_status_t parseStatus = celix_version_parse(entry->value, version); + } else if (entry != NULL) { + celix_status_t parseStatus = celix_version_tryParse(entry->value, version); if (parseStatus != CELIX_ILLEGAL_ARGUMENT) { return parseStatus; } diff --git a/misc/experimental/bundles/config_admin/service/private/include/configuration_admin_factory.h b/misc/experimental/bundles/config_admin/service/private/include/configuration_admin_factory.h index 34ca59470..89e9cae26 100644 --- a/misc/experimental/bundles/config_admin/service/private/include/configuration_admin_factory.h +++ b/misc/experimental/bundles/config_admin/service/private/include/configuration_admin_factory.h @@ -30,12 +30,12 @@ #include /* celix.framework */ -#include "bundle.h" #include "bundle_context.h" +#include "bundle_private.h" #include "celix_errno.h" -#include "service_reference.h" -#include "service_factory.h" #include "properties.h" +#include "service_factory.h" +#include "service_reference.h" /* celix.config_admin.public*/ #include "configuration_admin.h" diff --git a/misc/experimental/bundles/config_admin/service/private/include/configuration_admin_impl.h b/misc/experimental/bundles/config_admin/service/private/include/configuration_admin_impl.h index aa129937d..c5a1c6304 100644 --- a/misc/experimental/bundles/config_admin/service/private/include/configuration_admin_impl.h +++ b/misc/experimental/bundles/config_admin/service/private/include/configuration_admin_impl.h @@ -32,7 +32,7 @@ #include "configuration_admin.h" /* celix.framework */ -#include "bundle.h" +#include "bundle_private.h" /* celix.config_admin.public */ #include "configuration.h" /* celix.config_admin.private */ diff --git a/misc/experimental/bundles/config_admin/service/private/include/configuration_store.h b/misc/experimental/bundles/config_admin/service/private/include/configuration_store.h index b3e0dfb9d..3bd9091da 100644 --- a/misc/experimental/bundles/config_admin/service/private/include/configuration_store.h +++ b/misc/experimental/bundles/config_admin/service/private/include/configuration_store.h @@ -31,8 +31,8 @@ /* celix.utils.public*/ #include "array_list.h" /* celix.framework */ -#include "bundle.h" #include "bundle_context.h" +#include "bundle_private.h" #include "filter.h" /* celix.config_admin.public */ #include "configuration.h" diff --git a/misc/experimental/bundles/config_admin/service/private/include/framework_patch.h b/misc/experimental/bundles/config_admin/service/private/include/framework_patch.h index 450eb5840..b16e69ee7 100644 --- a/misc/experimental/bundles/config_admin/service/private/include/framework_patch.h +++ b/misc/experimental/bundles/config_admin/service/private/include/framework_patch.h @@ -28,8 +28,8 @@ #define BUNDLE_PATCH_H_ /* celix.framework.public */ +#include "bundle_private.h" #include "celix_errno.h" -#include "bundle.h" #include "service_reference.h" celix_status_t bundle_getBundleLocation(bundle_pt bundle, const char **location);