diff --git a/cmake/cmake_celix/BundlePackaging.cmake b/cmake/cmake_celix/BundlePackaging.cmake index f5eec25af..4be1c48f7 100644 --- a/cmake/cmake_celix/BundlePackaging.cmake +++ b/cmake/cmake_celix/BundlePackaging.cmake @@ -176,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 @@ -341,8 +341,6 @@ function(add_celix_bundle) #headers 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 ################################ @@ -379,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. @@ -527,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. diff --git a/cmake/cmake_celix/templates/MANIFEST.json.in b/cmake/cmake_celix/templates/MANIFEST.json.in index 1ebec9df2..7c530dbdc 100644 --- a/cmake/cmake_celix/templates/MANIFEST.json.in +++ b/cmake/cmake_celix/templates/MANIFEST.json.in @@ -1,14 +1,12 @@ { $,$ >$<$>:$> - "CELIX_BUNDLE_MANIFEST_VERSION" : "2.0.0", "CELIX_BUNDLE_SYMBOLIC_NAME" : "$", - "CELIX_BUNDLE_VERSION" : "$", + "CELIX_BUNDLE_VERSION" : "version<$$", "CELIX_BUNDLE_NAME" : "$", - "CELIX_BUNDLE_ACTIVATOR_LIBRARY": "$", - "CELIX_BUNDLE_PRIVATE_LIBRARIES" : "$,$>", - "CELIX_BUNDLE_DESCRIPTION" : "$", - "CELIX_BUNDLE_GROUP" : "$", - "CELIX_BUNDLE_IMPORT_LIBRARIES" : "$,$>", - "CELIX_BUNDLE_EXPORT_LIBRARIES" : "$,$>" + $<$>:"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/libs/framework/gtest/src/CxxBundleContextTestSuite.cc b/libs/framework/gtest/src/CxxBundleContextTestSuite.cc index 0598d5f4b..d8f5b9b80 100644 --- a/libs/framework/gtest/src/CxxBundleContextTestSuite.cc +++ b/libs/framework/gtest/src/CxxBundleContextTestSuite.cc @@ -710,8 +710,8 @@ 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("Extra-Header1"), std::string{"value1"}); EXPECT_EQ(bnd.getManifestValue("non-existing"), std::string{}); diff --git a/libs/framework/gtest/src/ManifestTestSuite.cc b/libs/framework/gtest/src/ManifestTestSuite.cc index 73fe5f9eb..6dbce620b 100644 --- a/libs/framework/gtest/src/ManifestTestSuite.cc +++ b/libs/framework/gtest/src/ManifestTestSuite.cc @@ -25,6 +25,7 @@ #include "celix_properties.h" #include "celix_stdlib_cleanup.h" #include "celix_framework_version.h" +#include "celix_version.h" class ManifestTestSuite : public ::testing::Test { public: @@ -35,8 +36,10 @@ class ManifestTestSuite : public ::testing::Test { const char* bundleName, const char* symbolicName) { celix_properties_t* properties = celix_properties_create(); - celix_properties_set(properties, "CELIX_BUNDLE_MANIFEST_VERSION", manifestVersion); - celix_properties_set(properties, "CELIX_BUNDLE_VERSION", bundleVersion); + 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; @@ -46,9 +49,10 @@ class ManifestTestSuite : public ::testing::Test { TEST_F(ManifestTestSuite, CreateManifestTest) { //Given a properties set with all the mandatory manifest attributes celix_properties_t *properties = celix_properties_create(); - celix_version_t* v = celix_version_create(2, 0, 0, nullptr); + auto* v = celix_version_create(2, 0, 0, nullptr); celix_properties_assignVersion(properties, "CELIX_BUNDLE_MANIFEST_VERSION", v); - celix_properties_set(properties, "CELIX_BUNDLE_VERSION", "1.0.0"); + 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"); @@ -79,7 +83,7 @@ TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) { celix_status_t status = celix_bundleManifest_create(properties, &manifest); //Then the creation fails - EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); + EXPECT_EQ(CELIX_INVALID_SYNTAX, status); //And 4 celix err log entries are logged (4 missing attributes) EXPECT_EQ(celix_err_getErrorCount(), 4); @@ -97,7 +101,7 @@ TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) { status = celix_bundleManifest_create(properties, &manifest2); //Then the creation fails - EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); + EXPECT_EQ(CELIX_INVALID_SYNTAX, status); //And 4 celix err log entries are logged (4x invalid versions) EXPECT_EQ(celix_err_getErrorCount(), 2); @@ -111,7 +115,7 @@ TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) { status = celix_bundleManifest_create(properties, &manifest3); //Then the creation fails - EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); + EXPECT_EQ(CELIX_INVALID_SYNTAX, status); //And 1 celix err log entries is logged EXPECT_EQ(celix_err_getErrorCount(), 1); @@ -126,7 +130,7 @@ TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) { status = celix_bundleManifest_create(properties, &manifest4); //Then the creation fails - EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); + EXPECT_EQ(CELIX_INVALID_SYNTAX, status); //And 1 celix err log entries is logged EXPECT_EQ(celix_err_getErrorCount(), 1); @@ -142,7 +146,7 @@ TEST_F(ManifestTestSuite, InvalidBundleSymbolicNameTest) { celix_status_t status = celix_bundleManifest_create(properties, &manifest); //Then the creation fails - EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); + EXPECT_EQ(CELIX_INVALID_SYNTAX, status); //And 1 celix err log entries is logged EXPECT_EQ(celix_err_getErrorCount(), 1); @@ -184,7 +188,10 @@ TEST_F(ManifestTestSuite, GetBuiltinAttributes) { //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"); - celix_properties_set(properties, "CELIX_BUNDLE_PRIVATE_LIBRARIES", "lib1,lib2"); + 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"); diff --git a/libs/framework/gtest/src/activator_with_exception.c b/libs/framework/gtest/src/activator_with_exception.c index b6760f31d..b8062cd07 100644 --- a/libs/framework/gtest/src/activator_with_exception.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_deprecated/bundle_context.h b/libs/framework/include_deprecated/bundle_context.h index 9a6f63bd3..aef6aa9e4 100644 --- a/libs/framework/include_deprecated/bundle_context.h +++ b/libs/framework/include_deprecated/bundle_context.h @@ -28,8 +28,6 @@ #include -#include "bundle_context.h" - #include "celix_types.h" #include "celix_cleanup.h" #include "service_factory.h" diff --git a/libs/framework/src/bundle.c b/libs/framework/src/bundle.c index ef0d9e5bb..054b9bd56 100644 --- a/libs/framework/src/bundle.c +++ b/libs/framework/src/bundle.c @@ -17,16 +17,13 @@ * under the License. */ -#include "celix_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" @@ -34,6 +31,10 @@ #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, celix_module_t** module); @@ -56,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; @@ -90,10 +87,6 @@ celix_status_t bundle_destroy(bundle_pt bundle) { } celix_arrayList_destroy(bundle->modules); - free(bundle->symbolicName); - free(bundle->name); - free(bundle->group); - free(bundle->description); free(bundle); return CELIX_SUCCESS; @@ -158,14 +151,8 @@ celix_status_t bundle_setState(bundle_pt bundle, bundle_state_e state) { celix_status_t bundle_createModule(bundle_pt bundle, celix_module_t** moduleOut) { celix_status_t status = CELIX_SUCCESS; - long bundleId = celix_bundle_getId(bundle); - celix_module_t* module = NULL; - if (bundleId == CELIX_FRAMEWORK_BUNDLE_ID) { - module = module_createFrameworkModule(bundle->framework, bundle); - } else { - module = module_create(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."); @@ -199,14 +186,7 @@ celix_status_t bundle_createModule(bundle_pt bundle, celix_module_t** moduleOut) } celix_status_t bundle_addModule(bundle_pt bundle, celix_module_t* module) { - celix_arrayList_add(bundle->modules, module); - - //free previous module info - free(bundle->symbolicName); - free(bundle->name); - free(bundle->group); - free(bundle->description); - + celix_arrayList_add(bundle->modules, module); //set new module info const char *sn = NULL; @@ -217,12 +197,8 @@ celix_status_t bundle_addModule(bundle_pt bundle, celix_module_t* 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) { @@ -361,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) { - celix_bundle_revision_t* rev = NULL; - bundleArchive_getCurrentRevision(arch, &rev); - if (rev != NULL) { - celix_bundle_manifest_t* man = celix_bundleRevision_getManifest(rev); - if (man != NULL) { - const celix_properties_t* attr = celix_bundleManifest_getAttributes(man); - header = celix_properties_getAsString(attr, attribute, NULL); - } - } - } - } - 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) { diff --git a/libs/framework/src/bundle_archive.c b/libs/framework/src/bundle_archive.c index 67d2fe552..5e73f6fff 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,8 +54,6 @@ struct bundleArchive { char* savedBundleStatePropertiesPath; char* storeRoot; char* resourceCacheRoot; - char* bundleSymbolicName; // read from the manifest - char* bundleVersion; // read from the manifest celix_bundle_revision_t* revision; // the current revision char* location; bool cacheValid; // is the cache valid (e.g. not deleted) @@ -72,7 +73,11 @@ static celix_status_t celix_bundleArchive_storeBundleStateProperties(bundle_arch if (!bundleStateProperties) { bundleStateProperties = celix_properties_create(); } - if (!bundleStateProperties) { + + celix_bundle_manifest_t* man = celix_bundleArchive_getManifest(archive); + celix_autofree char* bndVersion = celix_version_toString(celix_bundleManifest_getBundleVersion(man)); + + if (!bundleStateProperties || !bndVersion) { return CELIX_ENOMEM; } @@ -88,21 +93,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; } @@ -229,18 +238,6 @@ 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(celix_bundleManifest_getBundleSymbolicName(manifest)); - if (archive->bundleSymbolicName == NULL) { - fw_log(archive->fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to initialize archive. Cannot read bundle symbolic name."); - return CELIX_BUNDLE_EXCEPTION; - } - archive->bundleVersion = celix_version_toString(celix_bundleManifest_getBundleVersion(manifest)); - if (archive->bundleVersion == NULL) { - fw_log(archive->fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to initialize archive. Cannot read bundle version."); - return CELIX_BUNDLE_EXCEPTION; - } - *manifestOut = celix_steal_ptr(manifest); return status; } @@ -343,8 +340,6 @@ void celix_bundleArchive_destroy(bundle_archive_pt archive) { free(archive->archiveRoot); free(archive->resourceCacheRoot); free(archive->storeRoot); - free(archive->bundleSymbolicName); - free(archive->bundleVersion); celix_bundleRevision_destroy(archive->revision); free(archive); } @@ -359,8 +354,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) { @@ -461,14 +462,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/src/bundle_archive.h b/libs/framework/src/bundle_archive.h index bccee8efb..e11f0a75c 100644 --- a/libs/framework/src/bundle_archive.h +++ b/libs/framework/src/bundle_archive.h @@ -53,8 +53,7 @@ CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getId(bundle_archive_pt * @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 celix_status_t bundleArchive_getArchiveRoot(bundle_archive_pt archive, const char **archiveRoot); @@ -69,7 +68,7 @@ bundleArchive_getRevision(bundle_archive_pt archive, long revNr, celix_bundle_re CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getCurrentRevision(bundle_archive_pt archive, celix_bundle_revision_t** revision); -CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getCurrentRevisionNumber(bundle_archive_pt archive, long *revisionNumber) __attribute__((deprecated)); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getCurrentRevisionNumber(bundle_archive_pt archive, long *revisionNumber); CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getRefreshCount(bundle_archive_pt archive, long *refreshCount); @@ -77,8 +76,6 @@ CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_setRefreshCount(bundle_a CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_close(bundle_archive_pt archive); -CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_closeAndDelete(bundle_archive_pt archive); - CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_setLastModified(bundle_archive_pt archive, time_t lastModifiedTime); CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getLastModified(bundle_archive_pt archive, time_t *lastModified); diff --git a/libs/framework/src/bundle_archive_private.h b/libs/framework/src/bundle_archive_private.h index dcb1a326a..0ebef174e 100644 --- a/libs/framework/src/bundle_archive_private.h +++ b/libs/framework/src/bundle_archive_private.h @@ -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/celix_bundle_manifest.c b/libs/framework/src/celix_bundle_manifest.c index 91eee7334..21e43e756 100644 --- a/libs/framework/src/celix_bundle_manifest.c +++ b/libs/framework/src/celix_bundle_manifest.c @@ -18,15 +18,20 @@ */ #include "celix_bundle_manifest.h" -#include -#include +#include "celix_cleanup.h" +#include "celix_errno.h" +#include "celix_array_list_type.h" #include "celix_err.h" #include "celix_properties.h" -#include "celix_stdlib_cleanup.h" -#include "celix_utils.h" +#include "celix_properties_type.h" #include "celix_version.h" #include "celix_framework_version.h" +#include "celix_version_type.h" + +#include +#include +#include // Mandatory manifest attributes #define CELIX_BUNDLE_MANIFEST_VERSION "CELIX_BUNDLE_MANIFEST_VERSION" @@ -45,25 +50,13 @@ struct celix_bundle_manifest { celix_properties_t* attributes; - - //Mandatory fields - celix_version_t* manifestVersion; - celix_version_t* bundleVersion; - char* symbolicName; - char* bundleName; - - //Optional fields - char* bundleGroup; - char* description; - char* activatorLibrary; - celix_array_list_t* privateLibraries; }; /** * @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_setAttributes(celix_bundle_manifest_t* manifest); +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) { @@ -78,7 +71,7 @@ celix_status_t celix_bundleManifest_create(celix_properties_t* attributes, celix } manifest->attributes = attributes; - celix_status_t status = celix_bundleManifest_setAttributes(manifest); + celix_status_t status = celix_bundleManifest_checkAttributes(manifest); if (status != CELIX_SUCCESS) { return status; } @@ -103,14 +96,20 @@ celix_status_t celix_bundleManifest_createFrameworkManifest(celix_bundle_manifes return ENOMEM; } - celix_status_t status = - celix_properties_set(properties, CELIX_BUNDLE_MANIFEST_VERSION, CELIX_FRAMEWORK_MANIFEST_VERSION); - status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_SYMBOLIC_NAME, "apache_celix_framework")); + 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_properties_set(properties, CELIX_BUNDLE_VERSION, CELIX_FRAMEWORK_VERSION)); + 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")); + 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"); @@ -123,46 +122,30 @@ celix_status_t celix_bundleManifest_createFrameworkManifest(celix_bundle_manifes void celix_bundleManifest_destroy(celix_bundle_manifest_t* manifest) { if (manifest) { celix_properties_destroy(manifest->attributes); - - free(manifest->symbolicName); - free(manifest->bundleName); - celix_version_destroy(manifest->manifestVersion); - celix_version_destroy(manifest->bundleVersion); - - free(manifest->activatorLibrary); - free(manifest->bundleGroup); - free(manifest->description); - celix_arrayList_destroy(manifest->privateLibraries); - free(manifest); } } -const celix_properties_t* celix_bundleManifest_getAttributes(celix_bundle_manifest_t* manifest) { +const celix_properties_t* celix_bundleManifest_getAttributes(const celix_bundle_manifest_t* manifest) { return manifest->attributes; } -static celix_status_t celix_bundleManifest_setMandatoryAttributes(celix_bundle_manifest_t* manifest) { +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); - - celix_autoptr(celix_version_t) manifestVersion = NULL; - celix_status_t getVersionStatus = - celix_properties_getAsVersion(manifest->attributes, CELIX_BUNDLE_MANIFEST_VERSION, NULL, &manifestVersion); - CELIX_RETURN_IF_ENOMEM(getVersionStatus); - - celix_autoptr(celix_version_t) bundleVersion = NULL; - getVersionStatus = celix_properties_getAsVersion(manifest->attributes, CELIX_BUNDLE_VERSION, NULL, &bundleVersion); - CELIX_RETURN_IF_ENOMEM(getVersionStatus); + 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_ILLEGAL_ARGUMENT; + status = CELIX_INVALID_SYNTAX; } if (!symbolicName) { celix_err_push(CELIX_BUNDLE_SYMBOLIC_NAME " is missing"); - status = CELIX_ILLEGAL_ARGUMENT; + 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) { @@ -170,115 +153,77 @@ static celix_status_t celix_bundleManifest_setMandatoryAttributes(celix_bundle_m 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; + status = CELIX_INVALID_SYNTAX; break; } } } if (!manifestVersion) { celix_err_push(CELIX_BUNDLE_MANIFEST_VERSION " is missing or not a version"); - status = CELIX_ILLEGAL_ARGUMENT; + status = CELIX_INVALID_SYNTAX; } if (!bundleVersion) { celix_err_push(CELIX_BUNDLE_VERSION " is missing or not a version"); - status = CELIX_ILLEGAL_ARGUMENT; + 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_ILLEGAL_ARGUMENT; - } - - if (status == CELIX_SUCCESS) { - manifest->symbolicName = celix_utils_strdup(symbolicName); - CELIX_RETURN_IF_NULL(manifest->symbolicName); - manifest->bundleName = celix_utils_strdup(bundleName); - CELIX_RETURN_IF_NULL(manifest->bundleName); - manifest->manifestVersion = celix_steal_ptr(manifestVersion); - manifest->bundleVersion = celix_steal_ptr(bundleVersion); + status = CELIX_INVALID_SYNTAX; } return status; } -static celix_status_t celix_bundleManifest_setOptionalAttributes(celix_bundle_manifest_t* manifest) { - celix_status_t status = CELIX_SUCCESS; - - const char* lib = celix_properties_getAsString(manifest->attributes, CELIX_BUNDLE_ACTIVATOR_LIBRARY, NULL); - celix_autofree char* activatorLib = NULL; - if (lib) { - activatorLib = celix_utils_strdup(lib); - CELIX_RETURN_IF_NULL(activatorLib); - } - - const char* group = celix_properties_getAsString(manifest->attributes, CELIX_BUNDLE_GROUP, NULL); - celix_autofree char* bundleGroup = NULL; - if (group) { - bundleGroup = celix_utils_strdup(group); - CELIX_RETURN_IF_NULL(bundleGroup); - } - - const char* desc = celix_properties_getAsString(manifest->attributes, CELIX_BUNDLE_DESCRIPTION, NULL); - celix_autofree char* description = NULL; - if (desc) { - description = celix_utils_strdup(desc); - CELIX_RETURN_IF_NULL(description); - } - - celix_autoptr(celix_array_list_t) privateLibraries = NULL; - celix_status_t getStatus = celix_properties_getAsStringArrayList( - manifest->attributes, CELIX_BUNDLE_PRIVATE_LIBRARIES, NULL, &privateLibraries); - CELIX_RETURN_IF_ENOMEM(getStatus); - if (celix_properties_hasKey(manifest->attributes, CELIX_BUNDLE_PRIVATE_LIBRARIES) && !privateLibraries) { - celix_err_pushf(CELIX_BUNDLE_PRIVATE_LIBRARIES " is not a string array. Got: '%s'", - celix_properties_get(manifest->attributes, CELIX_BUNDLE_PRIVATE_LIBRARIES, NULL)); - status = CELIX_ILLEGAL_ARGUMENT; - } - - 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); +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 status; + return CELIX_SUCCESS; } -static celix_status_t celix_bundleManifest_setAttributes(celix_bundle_manifest_t* manifest) { - celix_status_t mStatus = celix_bundleManifest_setMandatoryAttributes(manifest); - celix_status_t oStatus = celix_bundleManifest_setOptionalAttributes(manifest); +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(celix_bundle_manifest_t* manifest) { - return manifest->bundleName; +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(celix_bundle_manifest_t* manifest) { - return manifest->symbolicName; +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(celix_bundle_manifest_t* manifest) { - return manifest->bundleVersion; +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(celix_bundle_manifest_t* manifest) { - return manifest->manifestVersion; +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(celix_bundle_manifest_t* manifest) { - return manifest->activatorLibrary; +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(celix_bundle_manifest_t* manifest) { - return manifest->privateLibraries; +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(celix_bundle_manifest_t* manifest) { - return manifest->description; +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(celix_bundle_manifest_t* manifest) { - return manifest->bundleGroup; +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 index 9badb1680..d80710bff 100644 --- a/libs/framework/src/celix_bundle_manifest.h +++ b/libs/framework/src/celix_bundle_manifest.h @@ -65,7 +65,7 @@ extern "C" { * * @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_ILLEGAL_ARGUMENT if the + * @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); @@ -78,7 +78,7 @@ celix_status_t celix_bundleManifest_create(celix_properties_t* attributes, celix * @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_ILLEGAL_ARGUMENT if the manifest file is invalid. + * 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); @@ -116,7 +116,7 @@ CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC(celix_bundle_manifest_t, celix_bundleManifest_ * @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(celix_bundle_manifest_t* manifest); +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. @@ -124,7 +124,7 @@ const celix_properties_t* celix_bundleManifest_getAttributes(celix_bundle_manife * @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); +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. @@ -132,7 +132,7 @@ const char* celix_bundleManifest_getBundleName(celix_bundle_manifest_t* manifest * @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); +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. @@ -140,7 +140,7 @@ const char* celix_bundleManifest_getBundleSymbolicName(celix_bundle_manifest_t* * @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); +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. @@ -148,7 +148,7 @@ const celix_version_t* celix_bundleManifest_getBundleVersion(celix_bundle_manife * @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(celix_bundle_manifest_t* manifest); +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. @@ -156,7 +156,7 @@ const celix_version_t* celix_bundleManifest_getManifestVersion(celix_bundle_mani * @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); +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. @@ -165,7 +165,7 @@ const char* celix_bundleManifest_getBundleActivatorLibrary(celix_bundle_manifest * @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(celix_bundle_manifest_t* manifest); +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. @@ -173,7 +173,7 @@ const celix_array_list_t* celix_bundleManifest_getBundlePrivateLibraries(celix_b * @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); +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. @@ -181,7 +181,7 @@ const char* celix_bundleManifest_getBundleDescription(celix_bundle_manifest_t* m * @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); +const char* celix_bundleManifest_getBundleGroup(const celix_bundle_manifest_t* manifest); #ifdef __cplusplus diff --git a/libs/framework/src/celix_bundle_private.h b/libs/framework/src/celix_bundle_private.h index 9bad00dde..17e6eec68 100644 --- a/libs/framework/src/celix_bundle_private.h +++ b/libs/framework/src/celix_bundle_private.h @@ -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; @@ -72,7 +68,7 @@ bundle_archive_t *celix_bundle_getArchive(const celix_bundle_t *bundle); celix_status_t bundle_destroy(celix_bundle_t *bundle); /** - * @brief Get the bundle symbolic name. + * @brief Get the bundle context. */ celix_bundle_context_t* celix_bundle_getContext(const celix_bundle_t *bundle); diff --git a/libs/framework/src/celix_module.h b/libs/framework/src/celix_module.h index 189d61bd0..321d90c5b 100644 --- a/libs/framework/src/celix_module.h +++ b/libs/framework/src/celix_module.h @@ -38,8 +38,6 @@ extern "C" { */ celix_module_t* module_create(celix_bundle_t* bundle); -celix_module_t* module_createFrameworkModule(celix_framework_t* fw, celix_bundle_t *bundle); - void module_destroy(celix_module_t* module); /** @@ -47,24 +45,16 @@ void module_destroy(celix_module_t* module); */ CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC(celix_module_t, module_destroy) -unsigned int module_hash(void *module); - -int module_equals(void *module, void *compare); - const celix_version_t* module_getVersion(celix_module_t* module); celix_status_t module_getSymbolicName(celix_module_t* module, const char **symbolicName); -char *module_getId(celix_module_t* module); - bool module_isResolved(celix_module_t* module); void module_setResolved(celix_module_t* module); celix_bundle_t *module_getBundle(celix_module_t* module); -celix_array_list_t *module_getDependents(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); diff --git a/libs/framework/src/framework.c b/libs/framework/src/framework.c index 507e52008..0bf7bda14 100644 --- a/libs/framework/src/framework.c +++ b/libs/framework/src/framework.c @@ -573,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); } } @@ -724,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; } diff --git a/libs/framework/src/module.c b/libs/framework/src/module.c index 269d711fa..cae9dd9e3 100644 --- a/libs/framework/src/module.c +++ b/libs/framework/src/module.c @@ -91,32 +91,6 @@ celix_module_t* module_create(celix_bundle_t* bundle) { return celix_steal_ptr(module); } -celix_module_t* module_createFrameworkModule(celix_framework_t* fw, bundle_pt bundle) { - 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; - } - - 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->fw = fw; - module->bundle = bundle; - module->resolved = false; - module->libraryHandles = celix_steal_ptr(libraryHandles); - - return celix_steal_ptr(module); -} - void module_destroy(celix_module_t* module) { if (module) { celix_arrayList_destroy(module->libraryHandles); @@ -288,7 +262,7 @@ celix_status_t celix_module_loadLibraries(celix_module_t* module) { const char* activator = celix_bundleManifest_getBundleActivatorLibrary(man); const celix_array_list_t* privateLibraries = celix_bundleManifest_getBundlePrivateLibraries(man); - if (privateLibraries != NULL) { + if (privateLibraries != NULL && celix_arrayList_size(privateLibraries) > 0) { status = CELIX_DO_IF( status, celix_module_loadLibrariesInManifestEntry(module, privateLibraries, activator, archive, &activatorHandle)); diff --git a/libs/utils/include/celix_err.h b/libs/utils/include/celix_err.h index 51f30f435..95ce0d612 100644 --- a/libs/utils/include/celix_err.h +++ b/libs/utils/include/celix_err.h @@ -94,28 +94,6 @@ CELIX_UTILS_EXPORT void celix_err_printErrors(FILE* stream, const char* prefix, */ CELIX_UTILS_EXPORT int celix_err_dump(char* buf, size_t size, const char* prefix, const char* postfix); -/*! - * Helper macro that returns with ENOMEM if the status is ENOMEM and logs an ": Out of memory" error to celix_err. - */ -#define CELIX_RETURN_IF_ENOMEM(status) \ - do { \ - if ((status) == ENOMEM) { \ - celix_err_pushf("%s: Out of memory", __func__); \ - return status; \ - } \ - } while (0) - -/*! - * Helper macro that returns with ENOMEM if the arg is NULL and logs an ": Out of memory" error to celix_err. - */ -#define CELIX_RETURN_IF_NULL(arg) \ - do { \ - if ((arg) == NULL) { \ - celix_err_pushf("%s: Out of memory", __func__); \ - return status; \ - } \ - } while (0) - #ifdef __cplusplus } #endif