This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/685-refactor-manifest-format in repository https://gitbox.apache.org/repos/asf/celix.git
commit c44bbe60612e122a7150c3b4eb0791ae5b33cfe4 Author: Pepijn Noltes <pnol...@apache.org> AuthorDate: Sun Jul 21 20:56:24 2024 +0200 gh-685: Update bundle zip generation for MANIFEST.json instead of MANIFEST.MF --- cmake/cmake_celix/BundlePackaging.cmake | 30 +++++++++++++-------------- cmake/cmake_celix/templates/MANIFEST.json.in | 14 +++++++++++++ cmake/cmake_celix/templates/Manifest.in | 12 ----------- cmake/cmake_celix/templates/NOTE | 2 +- libs/framework/src/bundle_archive_private.h | 2 +- libs/framework/src/bundle_revision.c | 3 ++- libs/framework/src/celix_bundle_manifest.c | 16 ++++++++------ libs/framework/src/celix_bundle_manifest.h | 14 ++++++------- libs/framework/src/framework.c | 2 +- libs/framework/src/module.c | 22 +++++++++++++------- libs/utils/gtest/src/ConvertUtilsTestSuite.cc | 14 +++++++++++++ libs/utils/src/celix_convert_utils.c | 5 +++++ 12 files changed, 84 insertions(+), 52 deletions(-) diff --git a/cmake/cmake_celix/BundlePackaging.cmake b/cmake/cmake_celix/BundlePackaging.cmake index 33327dff5..c2f6863cf 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) @@ -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} "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_DEPEND_TARGETS>" ${BUNDLE_GEN_DIR}/MANIFEST.MF + DEPENDS ${BUNDLE_TARGET_NAME} "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_DEPEND_TARGETS>" ${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} "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_DEPEND_TARGETS>" ${BUNDLE_GEN_DIR}/MANIFEST.MF + DEPENDS ${BUNDLE_TARGET_NAME} "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_DEPEND_TARGETS>" ${BUNDLE_GEN_DIR}/MANIFEST.json WORKING_DIRECTORY ${BUNDLE_CONTENT_DIR} ) else () @@ -340,7 +339,7 @@ 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 @@ -980,7 +979,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} @@ -988,7 +988,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/templates/MANIFEST.json.in b/cmake/cmake_celix/templates/MANIFEST.json.in new file mode 100644 index 000000000..0770d4765 --- /dev/null +++ b/cmake/cmake_celix/templates/MANIFEST.json.in @@ -0,0 +1,14 @@ +{ +$<JOIN:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_HEADERS>, +> + "CELIX_BUNDLE_MANIFEST_VERSION" : "2.0.0", + "CELIX_BUNDLE_SYMBOLIC_NAME" : "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_SYMBOLIC_NAME>", + "CELIX_BUNDLE_VERSION" : "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_VERSION>", + "CELIX_BUNDLE_NAME" : "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_NAME>", + "CELIX_BUNDLE_ACTIVATOR_LIBRARY": "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_ACTIVATOR>", + "CELIX_BUNDLE_PRIVATE_LIBRARIES" : "$<JOIN:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_PRIVATE_LIBS>,$<COMMA>>", + "CELIX_BUNDLE_DESCRIPTION" : "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_DESCRIPTION>", + "CELIX_BUNDLE_GROUP" : "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_GROUP>", + "CELIX_BUNDLE_IMPORT_LIBRARIES" : "$<JOIN:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_IMPORT_LIBS>,$<COMMA>>", + "CELIX_BUNDLE_EXPORT_LIBRARIES" : "$<JOIN:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_EXPORT_LIBS>,$<COMMA>>" +} \ No newline at end of file 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: $<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_SYMBOLIC_NAME> -Bundle-Group: $<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_GROUP> -Bundle-Name: $<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_NAME> -Bundle-Version: $<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_VERSION> -Bundle-Description: $<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_DESCRIPTION> -Bundle-Activator: $<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_ACTIVATOR> -Private-Library: $<JOIN:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_PRIVATE_LIBS>,, > -Import-Library: $<JOIN:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_IMPORT_LIBS>,, > -Export-Library: $<JOIN:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_EXPORT_LIBS>,, > -$<JOIN:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_HEADERS>, -> 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/libs/framework/src/bundle_archive_private.h b/libs/framework/src/bundle_archive_private.h index 7a2c774a8..20a838636 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. diff --git a/libs/framework/src/bundle_revision.c b/libs/framework/src/bundle_revision.c index 77e980bb4..80707296a 100644 --- a/libs/framework/src/bundle_revision.c +++ b/libs/framework/src/bundle_revision.c @@ -55,7 +55,8 @@ celix_status_t celix_bundleRevision_create(celix_framework_t* fw, const char *ro celix_status_t bundleRevision_destroy(bundle_revision_pt revision) { if (revision != NULL) { - celix_bundleManifest_destroy(revision->manifest); + // TODO who is owner of the manifest?, for now treating this as a weak reference + // celix_bundleManifest_destroy(revision->manifest); free(revision->root); free(revision->location); free(revision); diff --git a/libs/framework/src/celix_bundle_manifest.c b/libs/framework/src/celix_bundle_manifest.c index c0e98b75f..f07e8f310 100644 --- a/libs/framework/src/celix_bundle_manifest.c +++ b/libs/framework/src/celix_bundle_manifest.c @@ -39,6 +39,8 @@ #define CELIX_BUNDLE_DESCRIPTION "CELIX_BUNDLE_DESCRIPTION" #define CELIX_BUNDLE_GROUP "CELIX_BUNDLE_GROUP" +#define CELIX_BUNDLE_SYMBOLIC_NAME_ALLOWED_SPECIAL_CHARS "-_:." + struct celix_bundle_manifest { celix_properties_t* attributes; @@ -93,7 +95,7 @@ celix_status_t celix_bundleManifest_createFromFile(const char* filename, celix_b } celix_status_t celix_bundleManifest_createFrameworkManifest(celix_bundle_manifest_t** manifest) { - celix_properties_t* properties = celix_properties_create(); + celix_autoptr(celix_properties_t) properties = celix_properties_create(); if (!properties) { celix_err_push("Failed to create properties for framework manifest"); return ENOMEM; @@ -109,11 +111,10 @@ celix_status_t celix_bundleManifest_createFrameworkManifest(celix_bundle_manifes if (status != CELIX_SUCCESS) { celix_err_push("Failed to set properties for framework manifest"); - celix_properties_destroy(properties); return status; } - return celix_bundleManifest_create(properties, manifest); + return celix_bundleManifest_create(celix_steal_ptr(properties), manifest); } void celix_bundleManifest_destroy(celix_bundle_manifest_t* manifest) { @@ -160,10 +161,12 @@ static celix_status_t celix_bundleManifest_setMandatoryAttributes(celix_bundle_m celix_err_push(CELIX_BUNDLE_SYMBOLIC_NAME " is missing"); status = CELIX_ILLEGAL_ARGUMENT; } else { - //check if bundle symbolic name only contains the following characters: [a-zA-Z0-9_-:] + // 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("-_:", symbolicName[i]) == NULL) { - celix_err_pushf(CELIX_BUNDLE_SYMBOLIC_NAME " contains invalid character '%c'", symbolicName[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_ILLEGAL_ARGUMENT; break; } @@ -232,6 +235,7 @@ static celix_status_t celix_bundleManifest_setOptionalAttributes(celix_bundle_ma if (status == CELIX_SUCCESS) { manifest->activatorLibrary = celix_steal_ptr(activatorLib); manifest->bundleGroup = celix_steal_ptr(bundleGroup); + manifest->description = celix_steal_ptr(description); manifest->privateLibraries = celix_steal_ptr(privateLibraries); } diff --git a/libs/framework/src/celix_bundle_manifest.h b/libs/framework/src/celix_bundle_manifest.h index 21b1c8679..9badb1680 100644 --- a/libs/framework/src/celix_bundle_manifest.h +++ b/libs/framework/src/celix_bundle_manifest.h @@ -121,7 +121,7 @@ const celix_properties_t* celix_bundleManifest_getAttributes(celix_bundle_manife /** * @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 manifest version from. Cannot be NULL. + * @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(celix_bundle_manifest_t* manifest); @@ -129,7 +129,7 @@ const char* celix_bundleManifest_getBundleName(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 manifest version from. Cannot be NULL. + * @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(celix_bundle_manifest_t* manifest); @@ -137,7 +137,7 @@ const char* celix_bundleManifest_getBundleSymbolicName(celix_bundle_manifest_t* /** * @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. + * @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(celix_bundle_manifest_t* manifest); @@ -153,7 +153,7 @@ const celix_version_t* celix_bundleManifest_getManifestVersion(celix_bundle_mani /** * @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 manifest version from. Cannot be NULL. + * @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(celix_bundle_manifest_t* manifest); @@ -161,7 +161,7 @@ const char* celix_bundleManifest_getBundleActivatorLibrary(celix_bundle_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 manifest version from. Cannot be NULL. + * @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. */ @@ -170,7 +170,7 @@ const celix_array_list_t* celix_bundleManifest_getBundlePrivateLibraries(celix_b /** * @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 manifest version from. Cannot be NULL. + * @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(celix_bundle_manifest_t* manifest); @@ -178,7 +178,7 @@ const char* celix_bundleManifest_getBundleDescription(celix_bundle_manifest_t* m /** * @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 manifest version from. Cannot be NULL. + * @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(celix_bundle_manifest_t* manifest); diff --git a/libs/framework/src/framework.c b/libs/framework/src/framework.c index 1aff73adb..ee64f89fe 100644 --- a/libs/framework/src/framework.c +++ b/libs/framework/src/framework.c @@ -2019,7 +2019,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); diff --git a/libs/framework/src/module.c b/libs/framework/src/module.c index a389a9130..56512660c 100644 --- a/libs/framework/src/module.c +++ b/libs/framework/src/module.c @@ -63,15 +63,18 @@ celix_module_t* module_create(celix_bundle_manifest_t* manifest, celix_bundle_t* bundle_getFramework(bundle, &fw); celix_autoptr(celix_module_t) module = calloc(1, sizeof(*module)); - celix_autoptr(celix_array_list_t) libraryHandles = celix_arrayList_createStringArray(); + 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; } celix_status_t status = celixThreadMutex_create(&module->handlesLock, NULL); - if (!status) { - fw_log(fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to create module, error creating mutex"); + 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; } @@ -94,15 +97,18 @@ celix_module_t* module_createFrameworkModule(celix_framework_t* fw, bundle_pt bu } celix_autoptr(celix_module_t) module = calloc(1, sizeof(*module)); - celix_autoptr(celix_array_list_t) libraryHandles = celix_arrayList_createStringArray(); + 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; } status = celixThreadMutex_create(&module->handlesLock, NULL); - if (!status) { - fw_log(fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to create module, error creating mutex"); + 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; } @@ -113,7 +119,7 @@ celix_module_t* module_createFrameworkModule(celix_framework_t* fw, bundle_pt bu module->manifest = celix_steal_ptr(manifest); module->libraryHandles = celix_steal_ptr(libraryHandles); - return module; + return celix_steal_ptr(module); } void module_destroy(celix_module_t* module) { @@ -262,7 +268,7 @@ static celix_status_t celix_module_loadLibrariesInManifestEntry(celix_module_t* celix_status_t status = CELIX_SUCCESS; for (int i = 0; i < celix_arrayList_size(libraries); i++) { - const char* library = celix_arrayList_get(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) { 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/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;