From afc02bed49d164131dcfc4c4739f97368549a270 Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Sat, 8 Jun 2024 20:37:35 +0200 Subject: [PATCH 01/17] gh-685: Add new manifest impl --- libs/framework/CMakeLists.txt | 1 + libs/framework/gtest/src/ManifestTestSuite.cc | 289 ++---------------- libs/framework/src/celix_manifest.c | 71 +++++ libs/framework/src/celix_manifest.h | 87 ++++++ 4 files changed, 176 insertions(+), 272 deletions(-) create mode 100644 libs/framework/src/celix_manifest.c create mode 100644 libs/framework/src/celix_manifest.h diff --git a/libs/framework/CMakeLists.txt b/libs/framework/CMakeLists.txt index a1c749050..09e739b01 100644 --- a/libs/framework/CMakeLists.txt +++ b/libs/framework/CMakeLists.txt @@ -38,6 +38,7 @@ if (FRAMEWORK) src/celix_framework_utils.c src/celix_scheduled_event.c src/celix_framework_bundle.c + src/celix_manifest.c ) add_library(framework SHARED ${FRAMEWORK_SRC}) diff --git a/libs/framework/gtest/src/ManifestTestSuite.cc b/libs/framework/gtest/src/ManifestTestSuite.cc index 7c96903be..66b4f0fa5 100644 --- a/libs/framework/gtest/src/ManifestTestSuite.cc +++ b/libs/framework/gtest/src/ManifestTestSuite.cc @@ -19,284 +19,29 @@ */ #include -#include -#include -#include "celix_err.h" -#include "celix_stdio_cleanup.h" -#include "manifest.h" +#include "celix_manifest.h" +#include "celix_properties.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); - } - } }; -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, 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, 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)); -} - -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, CreateManifestTest) { + celix_properties_t *properties = celix_properties_create(); + celix_properties_set(properties, "key", "value"); + celix_autoptr(celix_manifest_t) manifest = nullptr; + celix_status_t status = celix_manifest_create(properties, &manifest); + EXPECT_EQ(CELIX_SUCCESS, status); + EXPECT_EQ(1, celix_properties_size(celix_manifest_getAttributes(manifest))); -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)); -} - -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)); -} - -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))); -} + celix_autoptr(celix_manifest_t) manifest2 = nullptr; + status = celix_manifest_create(nullptr, &manifest2); + EXPECT_EQ(CELIX_SUCCESS, status); + EXPECT_EQ(0, celix_properties_size(celix_manifest_getAttributes(manifest2))); -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); + celix_autoptr(celix_manifest_t) manifest3 = nullptr; + status = celix_manifest_createFromFile("empty.properties", &manifest3); + EXPECT_EQ(CELIX_SUCCESS, status); + EXPECT_EQ(0, celix_properties_size(celix_manifest_getAttributes(manifest3))); } -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"); -} - -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"); -} - -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"); -} - -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"); -} - -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, 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, 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"); -} diff --git a/libs/framework/src/celix_manifest.c b/libs/framework/src/celix_manifest.c new file mode 100644 index 000000000..7dc550480 --- /dev/null +++ b/libs/framework/src/celix_manifest.c @@ -0,0 +1,71 @@ +/* + * 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_manifest.h" + +#include "celix_properties.h" +#include "celix_stdlib_cleanup.h" +#include "celix_err.h" + +struct celix_manifest{ + celix_properties_t* attributes; +}; + +celix_status_t celix_manifest_create(celix_properties_t* attributes, celix_manifest_t** manifestOut) { + celix_autofree celix_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 ? attributes : celix_properties_create(); + if (!manifest->attributes) { + return ENOMEM; + } + + *manifestOut = celix_steal_ptr(manifest); + return CELIX_SUCCESS; +} + + +celix_status_t celix_manifest_createFromFile(const char* filename, celix_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_manifest_create(properties, manifestOut); +} + +void celix_manifest_destroy(celix_manifest_t* manifest) { + if (manifest) { + celix_properties_destroy(manifest->attributes); + free(manifest); + } +} + +const celix_properties_t* celix_manifest_getAttributes(celix_manifest_t* manifest) { + return manifest->attributes; +} + +bool celix_manifest_validate(celix_manifest_t* manifest) { + return true; //TODO implement +} \ No newline at end of file diff --git a/libs/framework/src/celix_manifest.h b/libs/framework/src/celix_manifest.h new file mode 100644 index 000000000..1efdd0f6e --- /dev/null +++ b/libs/framework/src/celix_manifest.h @@ -0,0 +1,87 @@ +/* + * 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_errno.h" +#include "celix_properties_type.h" +#include "celix_cleanup.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct celix_manifest celix_manifest_t; + +/** + * Create a new manifest using the provided properties. + * + * If an error occurs, an error message is logged on celix_err. + * + * @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. In case of an error, the provided + * attributes are destroyed. + */ +celix_status_t celix_manifest_create(celix_properties_t* attributes, celix_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_ILLEGAL_ARGUMENT if the manifest file is invalid. + */ +celix_status_t celix_manifest_createFromFile(const char* filename, celix_manifest_t** manifest); + +/** + * @brief Destroy the provided manifest. + */ +void celix_manifest_destroy(celix_manifest_t* manifest); + +/** + * Define the cleanup function for a celix_manifest_t, so that it can be used with celix_autoptr. + */ +CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC(celix_manifest_t, celix_manifest_destroy) + +/** + * @brief Get the main attributes of the manifest. + * The attributes are valid as long as the manifest is valid. + */ +const celix_properties_t* celix_manifest_getAttributes(celix_manifest_t* manifest); + +/** + * @brief Validate the provided manifest. + * + * Logs an error message on celix_err if the manifest is invalid. + * + * @param[in] manifest The manifest to validate. + * @return true if the manifest is valid, false otherwise. + */ +bool celix_manifest_validate(celix_manifest_t* manifest); + +#ifdef __cplusplus +} +#endif + +#endif /* CELIX_MANIFEST_H_ */ From a40923049a569dd958355d6c2170ebee7a0e4aa4 Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Mon, 1 Jul 2024 20:09:29 +0200 Subject: [PATCH 02/17] gh-685: Add manifest validation --- libs/framework/gtest/src/ManifestTestSuite.cc | 90 ++++++++++- libs/framework/src/celix_manifest.c | 143 +++++++++++++++++- libs/framework/src/celix_manifest.h | 49 ++++-- libs/utils/include/celix_err.h | 22 +++ libs/utils/include/celix_errno.h | 12 ++ libs/utils/include/celix_properties.h | 3 +- libs/utils/src/properties.c | 5 +- 7 files changed, 290 insertions(+), 34 deletions(-) diff --git a/libs/framework/gtest/src/ManifestTestSuite.cc b/libs/framework/gtest/src/ManifestTestSuite.cc index 66b4f0fa5..9c6d64135 100644 --- a/libs/framework/gtest/src/ManifestTestSuite.cc +++ b/libs/framework/gtest/src/ManifestTestSuite.cc @@ -22,26 +22,100 @@ #include "celix_manifest.h" #include "celix_properties.h" +#include "celix_err.h" class ManifestTestSuite : public ::testing::Test { + public: + ManifestTestSuite() { celix_err_resetErrors(); } }; TEST_F(ManifestTestSuite, CreateManifestTest) { + //Given a properties set with all the mandatory manifest attributes celix_properties_t *properties = celix_properties_create(); - celix_properties_set(properties, "key", "value"); + celix_version_t* v = celix_version_create(2, 0, 0, nullptr); + celix_properties_assignVersion(properties, "CELIX_MANIFEST_VERSION", v); + celix_properties_set(properties, "CELIX_BUNDLE_VERSION", "1.0.0"); + 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_manifest_t) manifest = nullptr; celix_status_t status = celix_manifest_create(properties, &manifest); + + //Then the creation is successful EXPECT_EQ(CELIX_SUCCESS, status); - EXPECT_EQ(1, celix_properties_size(celix_manifest_getAttributes(manifest))); + EXPECT_EQ(4, celix_properties_size(celix_manifest_getAttributes(manifest))); +} + +TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) { + //Given an empty properties set + celix_properties_t *properties = celix_properties_create(); + + //When creating a manifest from the attributes + celix_autoptr(celix_manifest_t) manifest = nullptr; + celix_status_t status = celix_manifest_create(properties, &manifest); + + //Then the creation fails + EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); + + //And 4 celix err log entries are logged (4 missing attributes) + EXPECT_EQ(celix_err_getErrorCount(), 4); + celix_err_printErrors(stdout, "Expect Errors: ", nullptr); + + //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_MANIFEST_VERSION", false); + 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_manifest_t) manifest2 = nullptr; - status = celix_manifest_create(nullptr, &manifest2); - EXPECT_EQ(CELIX_SUCCESS, status); - EXPECT_EQ(0, celix_properties_size(celix_manifest_getAttributes(manifest2))); + status = celix_manifest_create(properties, &manifest2); + + //Then the creation fails + EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); + + //And 4 celix err log entries are logged (4x invalid versions) + EXPECT_EQ(celix_err_getErrorCount(), 2); + celix_err_printErrors(stdout, "Expect Errors: ", nullptr); + //Given a properties with an unsupported manifest version + properties = celix_properties_create(); + celix_properties_set(properties, "CELIX_MANIFEST_VERSION", "1.0.0"); //note must be 2.0.* + celix_properties_set(properties, "CELIX_BUNDLE_VERSION", "1.0.0"); + 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_manifest_t) manifest3 = nullptr; - status = celix_manifest_createFromFile("empty.properties", &manifest3); - EXPECT_EQ(CELIX_SUCCESS, status); - EXPECT_EQ(0, celix_properties_size(celix_manifest_getAttributes(manifest3))); + status = celix_manifest_create(properties, &manifest2); + + //Then the creation fails + EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, 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 = celix_properties_create(); + celix_properties_set(properties, "CELIX_MANIFEST_VERSION", "2.0.2"); + celix_properties_set(properties, "CELIX_BUNDLE_VERSION", "1.0.0"); + celix_properties_set(properties, "CELIX_BUNDLE_NAME", "my_bundle"); + celix_properties_set(properties, "CELIX_BUNDLE_SYMBOLIC_NAME", "celix_my_bundle"); + celix_properties_setBool(properties, "CELIX_BUNDLE_PRIVATE_LIBRARIES", true); + + //When creating a manifest from the attributes + celix_autoptr(celix_manifest_t) manifest4 = nullptr; + status = celix_manifest_create(properties, &manifest2); + + //Then the creation fails + EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); + + //And 1 celix err log entries is logged + EXPECT_EQ(celix_err_getErrorCount(), 1); + celix_err_printErrors(stdout, "Expect Errors: ", nullptr); } +//TODO check if the mandatory and optional attributes are set and can be retreived with getters diff --git a/libs/framework/src/celix_manifest.c b/libs/framework/src/celix_manifest.c index 7dc550480..31e5db809 100644 --- a/libs/framework/src/celix_manifest.c +++ b/libs/framework/src/celix_manifest.c @@ -19,26 +19,58 @@ #include "celix_manifest.h" +#include "celix_err.h" #include "celix_properties.h" #include "celix_stdlib_cleanup.h" -#include "celix_err.h" +#include "celix_utils.h" +#include "celix_version.h" + +// Mandatory manifest attributes +#define CELIX_MANIFEST_VERSION "CELIX_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_PRIVATE_LIBRARIES "CELIX_BUNDLE_PRIVATE_LIBRARIES" +#define CELIX_BUNDLE_ACTIVATOR_LIBRARY "CELIX_BUNDLE_ACTIVATOR_LIBRARY" +#define CELIX_BUNDLE_GROUP "CELIX_BUNDLE_GROUP" struct celix_manifest{ celix_properties_t* attributes; + + //Mandatory fields + celix_version_t* manifestVersion; + celix_version_t* bundleVersion; + char* symbolicName; + char* bundleName; + + //Optional fields + char* bundleGroup; + 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_manifest_setAttributes(celix_manifest_t* manifest); + celix_status_t celix_manifest_create(celix_properties_t* attributes, celix_manifest_t** manifestOut) { + if (!attributes) { + return CELIX_ILLEGAL_ARGUMENT; + } + celix_autofree celix_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; - manifest->attributes = attributes ? attributes : celix_properties_create(); - if (!manifest->attributes) { - return ENOMEM; - } + CELIX_EPROP(celix_manifest_setAttributes(manifest)); *manifestOut = celix_steal_ptr(manifest); return CELIX_SUCCESS; @@ -51,13 +83,22 @@ celix_status_t celix_manifest_createFromFile(const char* filename, celix_manifes if (status != CELIX_SUCCESS) { return status; } - return celix_manifest_create(properties, manifestOut); } void celix_manifest_destroy(celix_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); + celix_arrayList_destroy(manifest->privateLibraries); + free(manifest); } } @@ -66,6 +107,92 @@ const celix_properties_t* celix_manifest_getAttributes(celix_manifest_t* manifes return manifest->attributes; } -bool celix_manifest_validate(celix_manifest_t* manifest) { - return true; //TODO implement +static celix_status_t celix_manifest_setMandatoryAttributes(celix_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_MANIFEST_VERSION, NULL, &manifestVersion); + CELIX_ERR_RET_IF_ENOMEM(getVersionStatus); + + celix_autoptr(celix_version_t) bundleVersion = NULL; + getVersionStatus = celix_properties_getAsVersion(manifest->attributes, CELIX_BUNDLE_VERSION, NULL, &bundleVersion); + CELIX_ERR_RET_IF_ENOMEM(getVersionStatus); + + celix_status_t status = CELIX_SUCCESS; + if (!bundleName) { + celix_err_push(CELIX_BUNDLE_NAME " is missing"); + status = CELIX_ILLEGAL_ARGUMENT; + } + if (!symbolicName) { + celix_err_push(CELIX_BUNDLE_SYMBOLIC_NAME " is missing"); + status = CELIX_ILLEGAL_ARGUMENT; + } + if (!manifestVersion) { + celix_err_push(CELIX_MANIFEST_VERSION " is missing or not a version"); + status = CELIX_ILLEGAL_ARGUMENT; + } + if (!bundleVersion) { + celix_err_push(CELIX_BUNDLE_VERSION " is missing or not a version"); + status = CELIX_ILLEGAL_ARGUMENT; + } + + if (manifestVersion && celix_version_compareToMajorMinor(manifestVersion, 2, 0) != 0) { + celix_err_push(CELIX_MANIFEST_VERSION " is not 2.0.*"); + status = CELIX_ILLEGAL_ARGUMENT; + } + + if (status == CELIX_SUCCESS) { + manifest->symbolicName = celix_utils_strdup(symbolicName); + CELIX_ERR_RET_IF_NULL(manifest->symbolicName); + manifest->bundleName = celix_utils_strdup(bundleName); + CELIX_ERR_RET_IF_NULL(manifest->bundleName); + manifest->manifestVersion = celix_steal_ptr(manifestVersion); + manifest->bundleVersion = celix_steal_ptr(bundleVersion); + } + + return status; +} + +static celix_status_t celix_manifest_setOptionalAttributes(celix_manifest_t* manifest) { + celix_status_t status = CELIX_SUCCESS; + + const char* l = celix_properties_getAsString(manifest->attributes, CELIX_BUNDLE_ACTIVATOR_LIBRARY, NULL); + celix_autofree char* activatorLib = NULL; + if (l) { + activatorLib = celix_utils_strdup(l); + CELIX_ERR_RET_IF_NULL(activatorLib); + } + + const char* g = celix_properties_getAsString(manifest->attributes, CELIX_BUNDLE_GROUP, NULL); + celix_autofree char* bundleGroup = NULL; + if (g) { + bundleGroup = celix_utils_strdup(g); + CELIX_ERR_RET_IF_NULL(bundleGroup); + } + + celix_autoptr(celix_array_list_t) privateLibraries = NULL; + celix_status_t getStatus = celix_properties_getAsStringArrayList( + manifest->attributes, CELIX_BUNDLE_ACTIVATOR_LIBRARY, NULL, &privateLibraries); + CELIX_ERR_RET_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->privateLibraries = celix_steal_ptr(privateLibraries); + } + + return status; +} + +static celix_status_t celix_manifest_setAttributes(celix_manifest_t* manifest) { + celix_status_t mStatus = celix_manifest_setMandatoryAttributes(manifest); + celix_status_t oStatus = celix_manifest_setOptionalAttributes(manifest); + return mStatus != CELIX_SUCCESS ? mStatus : oStatus; } \ No newline at end of file diff --git a/libs/framework/src/celix_manifest.h b/libs/framework/src/celix_manifest.h index 1efdd0f6e..8704c645c 100644 --- a/libs/framework/src/celix_manifest.h +++ b/libs/framework/src/celix_manifest.h @@ -28,17 +28,46 @@ extern "C" { #endif +/** + * @file celix_manifest.h + * @brief Header file for celix_manifest_t. + * + * + * The manifest consists of a set of attributes, including a set of mandatory attributes. + * A manifest is used to describe the contents of a bundle. + * + * A manifest must contain the following attributes: + * - CELIX_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 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_manifest_getAttributes. + * + * A bundle symbolic name can only contain the following characters: [a-zA-Z0-9_-:] + */ + +/** + * @brief The definition of the celix_manifest_t* abstract data type. + */ typedef struct celix_manifest celix_manifest_t; /** * Create a new manifest using the provided properties. * - * If an error occurs, an error message is logged on celix_err. + * 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. In case of an error, the provided - * attributes are destroyed. + * @return CELIX_SUCCESS if no errors occurred, ENOMEM if memory allocation failed and CELIX_ILLEGAL_ARGUMENT if the + * provided attributes is incorrect. In case of an error, the provided attributes are destroyed. */ celix_status_t celix_manifest_create(celix_properties_t* attributes, celix_manifest_t** manifest); @@ -65,20 +94,12 @@ void celix_manifest_destroy(celix_manifest_t* manifest); CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC(celix_manifest_t, celix_manifest_destroy) /** - * @brief Get the main attributes of the manifest. - * The attributes are valid as long as the manifest is valid. + * @brief Get the manifest attributes. + * The manifest attributes are valid as long as the manifest is valid. */ const celix_properties_t* celix_manifest_getAttributes(celix_manifest_t* manifest); -/** - * @brief Validate the provided manifest. - * - * Logs an error message on celix_err if the manifest is invalid. - * - * @param[in] manifest The manifest to validate. - * @return true if the manifest is valid, false otherwise. - */ -bool celix_manifest_validate(celix_manifest_t* manifest); +//TODO getters for mandatory and optional attributes #ifdef __cplusplus } diff --git a/libs/utils/include/celix_err.h b/libs/utils/include/celix_err.h index 95ce0d612..d617dcec0 100644 --- a/libs/utils/include/celix_err.h +++ b/libs/utils/include/celix_err.h @@ -94,6 +94,28 @@ 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 return with ENOMEM if the status is ENOMEM and logs an ": Out of memory" error to celix_err. + */ +#define CELIX_ERR_RET_IF_ENOMEM(status) \ + do { \ + if ((status) == ENOMEM) { \ + celix_err_pushf("%s: Out of memory", __func__); \ + return status; \ + } \ + } while (0) + +/*! + * Helper macro that return with ENOMEM if the arg is NULL and logs an ": Out of memory" error to celix_err. + */ +#define CELIX_ERR_RET_IF_NULL(arg) \ + do { \ + if ((arg) == NULL) { \ + celix_err_pushf("%s: Out of memory", __func__); \ + return status; \ + } \ + } while (0) + #ifdef __cplusplus } #endif diff --git a/libs/utils/include/celix_errno.h b/libs/utils/include/celix_errno.h index 8189192b3..dcab62801 100644 --- a/libs/utils/include/celix_errno.h +++ b/libs/utils/include/celix_errno.h @@ -56,6 +56,18 @@ extern "C" { */ #define CELIX_DO_IF(status, expr) ((status) == CELIX_SUCCESS) ? (expr) : (status) +/*! + * Helper macro which helps with error propagation. It evaluates the provided expression that returns a status and + * returns the status if the status is not CELIX_SUCCESS (0). If the status is CELIX_SUCCESS (0) nothing is done. + */ +#define CELIX_EPROP(expr) \ + do { \ + celix_status_t __status = expr; \ + if (__status != CELIX_SUCCESS) { \ + return __status; \ + } \ + } while (0) + /*! * Helper macro which check the current status and executes a goto the provided label if the * status is not CELIX_SUCCESS (0) 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/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; } From f79f229011341d7366ffac84df19a27c561372e0 Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Sun, 7 Jul 2024 23:39:13 +0200 Subject: [PATCH 03/17] gh-685: Add bundle manifest getter functions --- libs/framework/CMakeLists.txt | 2 +- libs/framework/gtest/src/ManifestTestSuite.cc | 129 +++++++++++--- ...lix_manifest.c => celix_bundle_manifest.c} | 98 ++++++++--- libs/framework/src/celix_bundle_manifest.h | 166 ++++++++++++++++++ .../src/celix_bundle_manifest_type.h | 41 +++++ libs/framework/src/celix_manifest.h | 108 ------------ libs/utils/include/celix_array_list.h | 11 +- libs/utils/include/celix_array_list_type.h | 43 +++++ 8 files changed, 429 insertions(+), 169 deletions(-) rename libs/framework/src/{celix_manifest.c => celix_bundle_manifest.c} (62%) create mode 100644 libs/framework/src/celix_bundle_manifest.h create mode 100644 libs/framework/src/celix_bundle_manifest_type.h delete mode 100644 libs/framework/src/celix_manifest.h create mode 100644 libs/utils/include/celix_array_list_type.h diff --git a/libs/framework/CMakeLists.txt b/libs/framework/CMakeLists.txt index 09e739b01..3e5fff719 100644 --- a/libs/framework/CMakeLists.txt +++ b/libs/framework/CMakeLists.txt @@ -38,7 +38,7 @@ if (FRAMEWORK) src/celix_framework_utils.c src/celix_scheduled_event.c src/celix_framework_bundle.c - src/celix_manifest.c + src/celix_bundle_manifest.c ) add_library(framework SHARED ${FRAMEWORK_SRC}) diff --git a/libs/framework/gtest/src/ManifestTestSuite.cc b/libs/framework/gtest/src/ManifestTestSuite.cc index 9c6d64135..7053cd634 100644 --- a/libs/framework/gtest/src/ManifestTestSuite.cc +++ b/libs/framework/gtest/src/ManifestTestSuite.cc @@ -20,31 +20,44 @@ #include -#include "celix_manifest.h" -#include "celix_properties.h" +#include "celix_bundle_manifest.h" #include "celix_err.h" +#include "celix_properties.h" +#include "celix_stdlib_cleanup.h" class ManifestTestSuite : public ::testing::Test { 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(); + celix_properties_set(properties, "CELIX_BUNDLE_MANIFEST_VERSION", manifestVersion); + celix_properties_set(properties, "CELIX_BUNDLE_VERSION", bundleVersion); + celix_properties_set(properties, "CELIX_BUNDLE_NAME", bundleName); + celix_properties_set(properties, "CELIX_BUNDLE_SYMBOLIC_NAME", symbolicName); + return properties; + } }; 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); - celix_properties_assignVersion(properties, "CELIX_MANIFEST_VERSION", v); + celix_properties_assignVersion(properties, "CELIX_BUNDLE_MANIFEST_VERSION", v); celix_properties_set(properties, "CELIX_BUNDLE_VERSION", "1.0.0"); 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_manifest_t) manifest = nullptr; - celix_status_t status = celix_manifest_create(properties, &manifest); + 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); - EXPECT_EQ(4, celix_properties_size(celix_manifest_getAttributes(manifest))); + ASSERT_EQ(CELIX_SUCCESS, status); + EXPECT_EQ(4, celix_properties_size(celix_bundleManifest_getAttributes(manifest))); } TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) { @@ -52,8 +65,8 @@ TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) { celix_properties_t *properties = celix_properties_create(); //When creating a manifest from the attributes - celix_autoptr(celix_manifest_t) manifest = nullptr; - celix_status_t status = celix_manifest_create(properties, &manifest); + celix_autoptr(celix_bundle_manifest_t) manifest = nullptr; + celix_status_t status = celix_bundleManifest_create(properties, &manifest); //Then the creation fails EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); @@ -65,13 +78,13 @@ TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) { //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_MANIFEST_VERSION", false); + 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"); //When creating a manifest from the attributes - celix_autoptr(celix_manifest_t) manifest2 = nullptr; - status = celix_manifest_create(properties, &manifest2); + celix_autoptr(celix_bundle_manifest_t) manifest2 = nullptr; + status = celix_bundleManifest_create(properties, &manifest2); //Then the creation fails EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); @@ -81,15 +94,11 @@ TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) { celix_err_printErrors(stdout, "Expect Errors: ", nullptr); //Given a properties with an unsupported manifest version - properties = celix_properties_create(); - celix_properties_set(properties, "CELIX_MANIFEST_VERSION", "1.0.0"); //note must be 2.0.* - celix_properties_set(properties, "CELIX_BUNDLE_VERSION", "1.0.0"); - celix_properties_set(properties, "CELIX_BUNDLE_NAME", "my_bundle"); - celix_properties_set(properties, "CELIX_BUNDLE_SYMBOLIC_NAME", "celix_my_bundle"); + 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_manifest_t) manifest3 = nullptr; - status = celix_manifest_create(properties, &manifest2); + celix_autoptr(celix_bundle_manifest_t) manifest3 = nullptr; + status = celix_bundleManifest_create(properties, &manifest3); //Then the creation fails EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); @@ -99,16 +108,12 @@ TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) { celix_err_printErrors(stdout, "Expect Errors: ", nullptr); //Given a properties set with an invalid private libraries list - properties = celix_properties_create(); - celix_properties_set(properties, "CELIX_MANIFEST_VERSION", "2.0.2"); - celix_properties_set(properties, "CELIX_BUNDLE_VERSION", "1.0.0"); - celix_properties_set(properties, "CELIX_BUNDLE_NAME", "my_bundle"); - celix_properties_set(properties, "CELIX_BUNDLE_SYMBOLIC_NAME", "celix_my_bundle"); + 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_manifest_t) manifest4 = nullptr; - status = celix_manifest_create(properties, &manifest2); + celix_autoptr(celix_bundle_manifest_t) manifest4 = nullptr; + status = celix_bundleManifest_create(properties, &manifest4); //Then the creation fails EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); @@ -118,4 +123,74 @@ TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) { celix_err_printErrors(stdout, "Expect Errors: ", nullptr); } -//TODO check if the mandatory and optional attributes are set and can be retreived with getters +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_ILLEGAL_ARGUMENT, 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, 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_getSymbolicName(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"); + celix_properties_set(properties, "CELIX_BUNDLE_PRIVATE_LIBRARIES", "lib1,lib2"); + celix_properties_set(properties, "CELIX_BUNDLE_GROUP", "my_group"); + + //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)); +} diff --git a/libs/framework/src/celix_manifest.c b/libs/framework/src/celix_bundle_manifest.c similarity index 62% rename from libs/framework/src/celix_manifest.c rename to libs/framework/src/celix_bundle_manifest.c index 31e5db809..2d4c8c2d9 100644 --- a/libs/framework/src/celix_manifest.c +++ b/libs/framework/src/celix_bundle_manifest.c @@ -17,7 +17,9 @@ * under the License. */ -#include "celix_manifest.h" +#include "celix_bundle_manifest.h" +#include +#include #include "celix_err.h" #include "celix_properties.h" @@ -26,17 +28,17 @@ #include "celix_version.h" // Mandatory manifest attributes -#define CELIX_MANIFEST_VERSION "CELIX_MANIFEST_VERSION" +#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_PRIVATE_LIBRARIES "CELIX_BUNDLE_PRIVATE_LIBRARIES" #define CELIX_BUNDLE_ACTIVATOR_LIBRARY "CELIX_BUNDLE_ACTIVATOR_LIBRARY" +#define CELIX_BUNDLE_PRIVATE_LIBRARIES "CELIX_BUNDLE_PRIVATE_LIBRARIES" #define CELIX_BUNDLE_GROUP "CELIX_BUNDLE_GROUP" -struct celix_manifest{ +struct celix_bundle_manifest { celix_properties_t* attributes; //Mandatory fields @@ -55,14 +57,14 @@ struct celix_manifest{ * @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_manifest_setAttributes(celix_manifest_t* manifest); +static celix_status_t celix_bundleManifest_setAttributes(celix_bundle_manifest_t* manifest); -celix_status_t celix_manifest_create(celix_properties_t* attributes, celix_manifest_t** manifestOut) { +celix_status_t celix_bundleManifest_create(celix_properties_t* attributes, celix_bundle_manifest_t** manifestOut) { if (!attributes) { return CELIX_ILLEGAL_ARGUMENT; } - celix_autofree celix_manifest_t* manifest = calloc(1, sizeof(*manifest)); + 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"); @@ -70,23 +72,26 @@ celix_status_t celix_manifest_create(celix_properties_t* attributes, celix_manif } manifest->attributes = attributes; - CELIX_EPROP(celix_manifest_setAttributes(manifest)); + celix_status_t status = celix_bundleManifest_setAttributes(manifest); + if (status != CELIX_SUCCESS) { + return status; + } *manifestOut = celix_steal_ptr(manifest); return CELIX_SUCCESS; } -celix_status_t celix_manifest_createFromFile(const char* filename, celix_manifest_t** manifestOut) { +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_manifest_create(properties, manifestOut); + return celix_bundleManifest_create(properties, manifestOut); } -void celix_manifest_destroy(celix_manifest_t* manifest) { +void celix_bundleManifest_destroy(celix_bundle_manifest_t* manifest) { if (manifest) { celix_properties_destroy(manifest->attributes); @@ -103,17 +108,17 @@ void celix_manifest_destroy(celix_manifest_t* manifest) { } } -const celix_properties_t* celix_manifest_getAttributes(celix_manifest_t* manifest) { +const celix_properties_t* celix_bundleManifest_getAttributes(celix_bundle_manifest_t* manifest) { return manifest->attributes; } -static celix_status_t celix_manifest_setMandatoryAttributes(celix_manifest_t* manifest) { +static celix_status_t celix_bundleManifest_setMandatoryAttributes(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_MANIFEST_VERSION, NULL, &manifestVersion); + celix_properties_getAsVersion(manifest->attributes, CELIX_BUNDLE_MANIFEST_VERSION, NULL, &manifestVersion); CELIX_ERR_RET_IF_ENOMEM(getVersionStatus); celix_autoptr(celix_version_t) bundleVersion = NULL; @@ -128,9 +133,18 @@ static celix_status_t celix_manifest_setMandatoryAttributes(celix_manifest_t* ma if (!symbolicName) { 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_-:] + 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]); + status = CELIX_ILLEGAL_ARGUMENT; + break; + } + } } if (!manifestVersion) { - celix_err_push(CELIX_MANIFEST_VERSION " is missing or not a version"); + celix_err_push(CELIX_BUNDLE_MANIFEST_VERSION " is missing or not a version"); status = CELIX_ILLEGAL_ARGUMENT; } if (!bundleVersion) { @@ -139,7 +153,7 @@ static celix_status_t celix_manifest_setMandatoryAttributes(celix_manifest_t* ma } if (manifestVersion && celix_version_compareToMajorMinor(manifestVersion, 2, 0) != 0) { - celix_err_push(CELIX_MANIFEST_VERSION " is not 2.0.*"); + celix_err_push(CELIX_BUNDLE_MANIFEST_VERSION " is not 2.0.*"); status = CELIX_ILLEGAL_ARGUMENT; } @@ -155,26 +169,26 @@ static celix_status_t celix_manifest_setMandatoryAttributes(celix_manifest_t* ma return status; } -static celix_status_t celix_manifest_setOptionalAttributes(celix_manifest_t* manifest) { +static celix_status_t celix_bundleManifest_setOptionalAttributes(celix_bundle_manifest_t* manifest) { celix_status_t status = CELIX_SUCCESS; - const char* l = celix_properties_getAsString(manifest->attributes, CELIX_BUNDLE_ACTIVATOR_LIBRARY, NULL); + const char* lib = celix_properties_getAsString(manifest->attributes, CELIX_BUNDLE_ACTIVATOR_LIBRARY, NULL); celix_autofree char* activatorLib = NULL; - if (l) { - activatorLib = celix_utils_strdup(l); + if (lib) { + activatorLib = celix_utils_strdup(lib); CELIX_ERR_RET_IF_NULL(activatorLib); } - const char* g = celix_properties_getAsString(manifest->attributes, CELIX_BUNDLE_GROUP, NULL); + const char* group = celix_properties_getAsString(manifest->attributes, CELIX_BUNDLE_GROUP, NULL); celix_autofree char* bundleGroup = NULL; - if (g) { - bundleGroup = celix_utils_strdup(g); + if (group) { + bundleGroup = celix_utils_strdup(group); CELIX_ERR_RET_IF_NULL(bundleGroup); } celix_autoptr(celix_array_list_t) privateLibraries = NULL; celix_status_t getStatus = celix_properties_getAsStringArrayList( - manifest->attributes, CELIX_BUNDLE_ACTIVATOR_LIBRARY, NULL, &privateLibraries); + manifest->attributes, CELIX_BUNDLE_PRIVATE_LIBRARIES, NULL, &privateLibraries); CELIX_ERR_RET_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'", @@ -191,8 +205,36 @@ static celix_status_t celix_manifest_setOptionalAttributes(celix_manifest_t* man return status; } -static celix_status_t celix_manifest_setAttributes(celix_manifest_t* manifest) { - celix_status_t mStatus = celix_manifest_setMandatoryAttributes(manifest); - celix_status_t oStatus = celix_manifest_setOptionalAttributes(manifest); +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); return mStatus != CELIX_SUCCESS ? mStatus : oStatus; -} \ No newline at end of file +} + +const char* celix_bundleManifest_getBundleName(celix_bundle_manifest_t* manifest) { + return manifest->bundleName; +} + +const char* celix_bundleManifest_getSymbolicName(celix_bundle_manifest_t* manifest) { + return manifest->symbolicName; +} + +const celix_version_t* celix_bundleManifest_getBundleVersion(celix_bundle_manifest_t* manifest) { + return manifest->bundleVersion; +} + +const celix_version_t* celix_bundleManifest_getManifestVersion(celix_bundle_manifest_t* manifest) { + return manifest->manifestVersion; +} + +const char* celix_bundleManifest_getBundleActivatorLibrary(celix_bundle_manifest_t* manifest) { + return manifest->activatorLibrary; +} + +const celix_array_list_t* celix_bundleManifest_getBundlePrivateLibraries(celix_bundle_manifest_t* manifest) { + return manifest->privateLibraries; +} + +const char* celix_bundleManifest_getBundleGroup(celix_bundle_manifest_t* manifest) { + return manifest->bundleGroup; +} diff --git a/libs/framework/src/celix_bundle_manifest.h b/libs/framework/src/celix_bundle_manifest.h new file mode 100644 index 000000000..662f2804d --- /dev/null +++ b/libs/framework/src/celix_bundle_manifest.h @@ -0,0 +1,166 @@ +/* + * 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 + +/** + * @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_ILLEGAL_ARGUMENT 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_ILLEGAL_ARGUMENT if the manifest file is invalid. + */ +celix_status_t celix_bundleManifest_createFromFile(const char* filename, 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(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. + * @return The bundle name. Will never be NULL. + */ +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. + * @return The bundle symbolic name. Will never be NULL. + */ +const char* celix_bundleManifest_getSymbolicName(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 bundle version. Will never be NULL. + */ +const celix_version_t* celix_bundleManifest_getBundleVersion(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(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 manifest version 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); + +/** + * @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. + * @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); + +/** + * @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. + * @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); + + +#ifdef __cplusplus +} +#endif + +#endif /* CELIX_MANIFEST_H_ */ diff --git a/libs/framework/src/celix_bundle_manifest_type.h b/libs/framework/src/celix_bundle_manifest_type.h new file mode 100644 index 000000000..affea1f3b --- /dev/null +++ b/libs/framework/src/celix_bundle_manifest_type.h @@ -0,0 +1,41 @@ +/* + * 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_TYPE_H_ +#define CELIX_MANIFEST_TYPE_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 + +#endif /* CELIX_MANIFEST_TYPE_H_ */ diff --git a/libs/framework/src/celix_manifest.h b/libs/framework/src/celix_manifest.h deleted file mode 100644 index 8704c645c..000000000 --- a/libs/framework/src/celix_manifest.h +++ /dev/null @@ -1,108 +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 CELIX_MANIFEST_H_ -#define CELIX_MANIFEST_H_ - -#include "celix_errno.h" -#include "celix_properties_type.h" -#include "celix_cleanup.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @file celix_manifest.h - * @brief Header file for celix_manifest_t. - * - * - * The manifest consists of a set of attributes, including a set of mandatory attributes. - * A manifest is used to describe the contents of a bundle. - * - * A manifest must contain the following attributes: - * - CELIX_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 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_manifest_getAttributes. - * - * A bundle symbolic name can only contain the following characters: [a-zA-Z0-9_-:] - */ - -/** - * @brief The definition of the celix_manifest_t* abstract data type. - */ -typedef struct celix_manifest celix_manifest_t; - -/** - * 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_ILLEGAL_ARGUMENT if the - * provided attributes is incorrect. In case of an error, the provided attributes are destroyed. - */ -celix_status_t celix_manifest_create(celix_properties_t* attributes, celix_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_ILLEGAL_ARGUMENT if the manifest file is invalid. - */ -celix_status_t celix_manifest_createFromFile(const char* filename, celix_manifest_t** manifest); - -/** - * @brief Destroy the provided manifest. - */ -void celix_manifest_destroy(celix_manifest_t* manifest); - -/** - * Define the cleanup function for a celix_manifest_t, so that it can be used with celix_autoptr. - */ -CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC(celix_manifest_t, celix_manifest_destroy) - -/** - * @brief Get the manifest attributes. - * The manifest attributes are valid as long as the manifest is valid. - */ -const celix_properties_t* celix_manifest_getAttributes(celix_manifest_t* manifest); - -//TODO getters for mandatory and optional attributes - -#ifdef __cplusplus -} -#endif - -#endif /* CELIX_MANIFEST_H_ */ 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_ */ From 3759c1d03ad0fe43486b02d2d97eeb9ded78ad83 Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Sun, 21 Jul 2024 19:23:58 +0200 Subject: [PATCH 04/17] gh-685: Update usage of manifest to celix_bundle_manifest and removes some usage of deprecated api --- bundles/http_admin/http_admin/CMakeLists.txt | 3 - .../http_admin/http_admin/src/http_admin.c | 2 +- .../http_admin/src/websocket_admin.c | 2 +- bundles/logging/log_helper/CMakeLists.txt | 2 - .../gtest/src/rsa_tests.cc | 21 +- .../src/export_registration_dfi.c | 1 + .../src/import_registration_dfi.c | 2 + .../src/remote_service_admin_dfi.c | 1 + .../rsa_common/src/export_registration_impl.c | 1 + .../rsa_common/src/import_registration_impl.c | 1 + .../rsa_spi/include/remote_proxy.h | 1 + .../topology_manager/src/topology_manager.c | 2 +- .../topology_manager/tms_tst/tms_tests.cpp | 20 +- bundles/shell/remote_shell/CMakeLists.txt | 2 +- bundles/shell/remote_shell/src/remote_shell.c | 9 - .../shell/remote_shell/src/shell_mediator.c | 148 ++++----- .../shell/remote_shell/src/shell_mediator.h | 3 +- bundles/shell/shell/CMakeLists.txt | 1 - bundles/shell/shell_tui/CMakeLists.txt | 1 - bundles/shell/shell_tui/src/shell_tui.c | 5 +- cmake/cmake_celix/BundlePackaging.cmake | 6 +- libs/dfi/gtest/CMakeLists.txt | 1 - libs/framework/CMakeLists.txt | 5 +- .../gtest/src/BundleArchiveTestSuite.cc | 3 +- ...undleArchiveWithErrorInjectionTestSuite.cc | 4 +- ...CelixBundleCacheErrorInjectionTestSuite.cc | 4 +- .../src/CelixBundleContextBundlesTestSuite.cc | 4 +- .../CelixBundleContextServicesTestSuite.cc | 2 +- .../src/ManifestErrorInjectionTestSuite.cc | 146 +------- libs/framework/gtest/src/ManifestTestSuite.cc | 4 +- libs/framework/include_deprecated/bundle.h | 111 +------ .../include_deprecated/bundle_context.h | 10 +- libs/framework/include_deprecated/framework.h | 2 +- .../include_deprecated/framework_event.h | 2 +- libs/framework/include_deprecated/manifest.h | 78 ----- libs/framework/include_deprecated/module.h | 89 ----- .../include_deprecated/service_factory.h | 2 +- .../include_deprecated/service_reference.h | 2 +- .../include_deprecated/service_registration.h | 2 +- .../include_deprecated/service_registry.h | 2 +- libs/framework/src/bundle.c | 45 ++- libs/framework/src/bundle_archive.c | 28 +- .../bundle_archive.h | 34 +- libs/framework/src/bundle_context.c | 29 +- libs/framework/src/bundle_context_private.h | 1 + libs/framework/src/bundle_private.h | 74 ----- libs/framework/src/bundle_revision.c | 8 +- .../bundle_revision.h | 11 +- libs/framework/src/bundle_revision_private.h | 14 +- libs/framework/src/celix_bundle_manifest.c | 41 ++- libs/framework/src/celix_bundle_manifest.h | 27 +- libs/framework/src/celix_bundle_private.h | 147 ++++++++ libs/framework/src/celix_module.h | 78 +++++ libs/framework/src/celix_module_private.h | 4 +- libs/framework/src/dm_component_impl.c | 1 + .../src/dm_dependency_manager_impl.c | 20 +- libs/framework/src/framework.c | 142 ++++---- .../src/framework_bundle_lifecycle_handler.c | 6 +- libs/framework/src/framework_private.h | 2 +- libs/framework/src/manifest.c | 313 ------------------ libs/framework/src/manifest_parser.c | 113 ------- libs/framework/src/manifest_parser.h | 45 --- libs/framework/src/module.c | 286 +++++++--------- libs/framework/src/service_reference.c | 15 +- .../framework/src/service_reference_private.h | 2 +- libs/framework/src/service_registration.c | 3 +- .../src/service_registration_private.h | 2 + libs/framework/src/service_registry.c | 16 +- .../include/configuration_admin_factory.h | 6 +- .../include/configuration_admin_impl.h | 2 +- .../private/include/configuration_store.h | 2 +- .../service/private/include/framework_patch.h | 2 +- 72 files changed, 753 insertions(+), 1473 deletions(-) delete mode 100644 libs/framework/include_deprecated/manifest.h delete mode 100644 libs/framework/include_deprecated/module.h rename libs/framework/{include_deprecated => src}/bundle_archive.h (61%) delete mode 100644 libs/framework/src/bundle_private.h rename libs/framework/{include_deprecated => src}/bundle_revision.h (83%) create mode 100644 libs/framework/src/celix_bundle_private.h create mode 100644 libs/framework/src/celix_module.h delete mode 100644 libs/framework/src/manifest.c delete mode 100644 libs/framework/src/manifest_parser.c delete mode 100644 libs/framework/src/manifest_parser.h 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..6b97a505e 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); + celix_array_list_t* bundles = celix_bundleContext_listBundles(context); + ASSERT_NE(nullptr, bundles); 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_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/rsa_common/src/export_registration_impl.c b/bundles/remote_services/rsa_common/src/export_registration_impl.c index ad541e5fb..7925275dc 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 "bundle.h" struct export_reference { 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..3288489dd 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,7 @@ #include "import_registration_impl.h" #include "remote_service_admin_impl.h" +#include "bundle.h" struct import_reference { endpoint_description_t *endpoint; 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..44bc96a09 100644 --- a/bundles/shell/remote_shell/src/remote_shell.c +++ b/bundles/shell/remote_shell/src/remote_shell.c @@ -16,18 +16,9 @@ * 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 "celix_log_helper.h" diff --git a/bundles/shell/remote_shell/src/shell_mediator.c b/bundles/shell/remote_shell/src/shell_mediator.c index 636296031..c4ae07ced 100644 --- a/bundles/shell/remote_shell/src/shell_mediator.c +++ b/bundles/shell/remote_shell/src/shell_mediator.c @@ -16,120 +16,110 @@ * 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; - celixThreadMutex_lock(&instance->mutex); + celixThreadMutex_lock(&instance->mutex); - 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..33327dff5 100644 --- a/cmake/cmake_celix/BundlePackaging.cmake +++ b/cmake/cmake_celix/BundlePackaging.cmake @@ -450,7 +450,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 +461,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) 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 3e5fff719..94e031c78 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 @@ -54,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 () 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 2aeb425c3..a8ba50661 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 01616065b..d6b7ae35e 100644 --- a/libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc +++ b/libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc @@ -57,7 +57,7 @@ class CelixBundleContextBundlesTestSuite : public ::testing::Test { fw = celix_frameworkFactory_createFramework(properties); - ctx = framework_getContext(fw); + ctx = celix_framework_getFrameworkContext(fw); } ~CelixBundleContextBundlesTestSuite() override { @@ -883,7 +883,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/ManifestErrorInjectionTestSuite.cc b/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc index ae64656b4..ab7114e08 100644 --- a/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc +++ b/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc @@ -19,158 +19,32 @@ */ #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); - EXPECT_EQ(CELIX_ENOMEM, status); - EXPECT_EQ(nullptr, manifest); - celix_err_printErrors(stdout, "Errors are expected[", "]\n"); - teardownErrorInjectors(); - - manifest = nullptr; - celix_ei_expect_celix_properties_create((void*)manifest_create, 0, nullptr); - status = manifest_create(&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_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(); -} - -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(); } - -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 7053cd634..8f10dfa16 100644 --- a/libs/framework/gtest/src/ManifestTestSuite.cc +++ b/libs/framework/gtest/src/ManifestTestSuite.cc @@ -154,7 +154,7 @@ TEST_F(ManifestTestSuite, GetBuiltinAttributes) { //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_getSymbolicName(manifest)); + EXPECT_STREQ("celix_my_bundle", celix_bundleManifest_getBundleSymbolicName(manifest)); const auto* mv = celix_bundleManifest_getManifestVersion(manifest); const auto* bv = celix_bundleManifest_getBundleVersion(manifest); @@ -176,6 +176,7 @@ TEST_F(ManifestTestSuite, GetBuiltinAttributes) { celix_properties_set(properties, "CELIX_BUNDLE_ACTIVATOR_LIBRARY", "my_activator"); celix_properties_set(properties, "CELIX_BUNDLE_PRIVATE_LIBRARIES", "lib1,lib2"); 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; @@ -193,4 +194,5 @@ TEST_F(ManifestTestSuite, GetBuiltinAttributes) { 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)); } diff --git a/libs/framework/include_deprecated/bundle.h b/libs/framework/include_deprecated/bundle.h index 44bf3c491..66261e093 100644 --- a/libs/framework/include_deprecated/bundle.h +++ b/libs/framework/include_deprecated/bundle.h @@ -1,112 +1,37 @@ /* - * 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. - */ +* 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" +#include "celix_bundle.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 diff --git a/libs/framework/include_deprecated/bundle_context.h b/libs/framework/include_deprecated/bundle_context.h index b12c84ab8..9a6f63bd3 100644 --- a/libs/framework/include_deprecated/bundle_context.h +++ b/libs/framework/include_deprecated/bundle_context.h @@ -26,8 +26,11 @@ * Framework. */ -#include "celix_types.h" +#include +#include "bundle_context.h" + +#include "celix_types.h" #include "celix_cleanup.h" #include "service_factory.h" #include "celix_service_factory.h" @@ -35,13 +38,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/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 97a4f6e29..7f8342328 100644 --- a/libs/framework/src/bundle.c +++ b/libs/framework/src/bundle.c @@ -17,7 +17,7 @@ * under the License. */ -#include "bundle_private.h" +#include "celix_bundle_private.h" #include #include @@ -26,6 +26,7 @@ #include #include +#include "celix_module.h" #include "framework_private.h" #include "utils.h" #include "celix_file_utils.h" @@ -35,7 +36,7 @@ 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) { @@ -67,7 +68,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,7 +85,7 @@ 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); @@ -108,7 +109,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 ) { @@ -141,15 +142,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; -} +void celix_bundle_setContext(bundle_pt bundle, bundle_context_pt context) { bundle->context = context; } celix_status_t bundle_getEntry(const_bundle_pt bundle, const char* name, char** entry) { *entry = celix_bundle_getBundleOrPersistentStoreEntry(bundle, true, name); @@ -170,16 +165,16 @@ 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 bundle_createModule(bundle_pt bundle, celix_module_t** moduleOut) { celix_status_t status = CELIX_SUCCESS; bundle_archive_pt archive = NULL; bundle_revision_pt revision = NULL; - manifest_pt headerMap = NULL; + celix_bundle_manifest_t* manifest = 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 = CELIX_DO_IF(status, bundleRevision_getManifest(revision, &manifest)); status = bundleArchive_getId(bundle->archive, &bundleId); if (status != CELIX_SUCCESS) { @@ -187,14 +182,11 @@ celix_status_t bundle_createModule(bundle_pt bundle, module_pt* moduleOut) { return status; } - module_pt module = NULL; + celix_module_t* 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); + module = module_create(manifest, bundle); } if (!module) { status = CELIX_BUNDLE_EXCEPTION; @@ -281,7 +273,7 @@ celix_status_t bundle_revise(bundle_pt bundle, const char * location, const char return CELIX_SUCCESS; } -celix_status_t bundle_addModule(bundle_pt bundle, module_pt module) { +celix_status_t bundle_addModule(bundle_pt bundle, celix_module_t* module) { celix_arrayList_add(bundle->modules, module); //free previous module info @@ -342,7 +334,7 @@ celix_status_t bundle_closeRevisions(const_bundle_pt bundle) { } celix_status_t bundle_refresh(bundle_pt bundle) { - module_pt module; + celix_module_t* module; celix_arrayList_clear(bundle->modules); celix_status_t status = bundle_createModule(bundle, &module); if (status == CELIX_SUCCESS) { @@ -503,10 +495,11 @@ const char* celix_bundle_getManifestValue(const celix_bundle_t* bnd, const char* bundle_revision_t* rev = NULL; bundleArchive_getCurrentRevision(arch, &rev); if (rev != NULL) { - manifest_pt man = NULL; + celix_bundle_manifest_t* man = NULL; bundleRevision_getManifest(rev, &man); if (man != NULL ) { - header = manifest_getValue(man, attribute); + const celix_properties_t* attr = celix_bundleManifest_getAttributes(man); + header = celix_properties_getAsString(attr, attribute, NULL); } } } @@ -539,7 +532,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 239ef9412..df594991b 100644 --- a/libs/framework/src/bundle_archive.c +++ b/libs/framework/src/bundle_archive.c @@ -184,7 +184,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 +214,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); @@ -229,19 +230,18 @@ static celix_status_t celix_bundleArchive_createCacheDirectory(bundle_archive_pt } //populate bundle symbolic name and version from manifest - archive->bundleSymbolicName = celix_utils_strdup(manifest_getValue(*manifestOut, CELIX_FRAMEWORK_BUNDLE_SYMBOLICNAME)); + 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."); - manifest_destroy(*manifestOut); return CELIX_BUNDLE_EXCEPTION; } - archive->bundleVersion = celix_utils_strdup(manifest_getValue(*manifestOut, CELIX_FRAMEWORK_BUNDLE_VERSION)); + 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."); - manifest_destroy(*manifestOut); return CELIX_BUNDLE_EXCEPTION; } + *manifestOut = celix_steal_ptr(manifest); return status; } @@ -249,7 +249,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 +259,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 +294,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 +311,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 +325,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: diff --git a/libs/framework/include_deprecated/bundle_archive.h b/libs/framework/src/bundle_archive.h similarity index 61% rename from libs/framework/include_deprecated/bundle_archive.h rename to libs/framework/src/bundle_archive.h index d53518a1d..d6ceffd4f 100644 --- a/libs/framework/include_deprecated/bundle_archive.h +++ b/libs/framework/src/bundle_archive.h @@ -46,7 +46,7 @@ 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. @@ -56,36 +56,36 @@ CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getId(bundle_arch 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_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 celix_status_t bundleArchive_rollbackRevise(bundle_archive_pt archive, bool *rolledback); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getRevision(bundle_archive_pt archive, long revNr, bundle_revision_pt *revision); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getCurrentRevision(bundle_archive_pt archive, bundle_revision_pt *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_getCurrentRevisionNumber(bundle_archive_pt archive, long *revisionNumber) __attribute__((deprecated)); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_getRefreshCount(bundle_archive_pt archive, long *refreshCount); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getRefreshCount(bundle_archive_pt archive, long *refreshCount); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_setRefreshCount(bundle_archive_pt archive); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_setRefreshCount(bundle_archive_pt archive); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_close(bundle_archive_pt archive); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_close(bundle_archive_pt archive); -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleArchive_closeAndDelete(bundle_archive_pt archive); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_closeAndDelete(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 +102,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_context.c b/libs/framework/src/bundle_context.c index 261e7b36b..1a9fd0fe0 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_private.h b/libs/framework/src/bundle_private.h deleted file mode 100644 index f061a9015..000000000 --- a/libs/framework/src/bundle_private.h +++ /dev/null @@ -1,74 +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_PRIVATE_H_ -#define BUNDLE_PRIVATE_H_ - -#include "bundle.h" -#include "celix_bundle.h" - -#ifdef __cplusplus -extern "C" { -#endif - -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; - bundle_archive_pt archive; - celix_array_list_t* modules; - - celix_framework_t *framework; -}; - -/** - * Creates a bundle from the given archive. - * @param[in] framework The framework. - * @param[in] archive The archive. - * @param[out] bundleOut The created bundle. - * @return CELIX_SUCCESS if the bundle is created successfully. - */ -celix_status_t -celix_bundle_createFromArchive(celix_framework_t *framework, bundle_archive_pt archive, celix_bundle_t **bundleOut); - -/** - * @brief Get the bundle archive. - * - * @param[in] bundle The bundle. - * @return The bundle archive. - */ -bundle_archive_t *celix_bundle_getArchive(const celix_bundle_t *bundle); - -/** - * Destroys the bundle. - * @param[in] bundle The bundle to destroy. - * @return CELIX_SUCCESS if the bundle is destroyed successfully. - */ -celix_status_t bundle_destroy(celix_bundle_t *bundle); - -#ifdef __cplusplus -} -#endif - -#endif /* BUNDLE_PRIVATE_H_ */ diff --git a/libs/framework/src/bundle_revision.c b/libs/framework/src/bundle_revision.c index a8e76ff28..77e980bb4 100644 --- a/libs/framework/src/bundle_revision.c +++ b/libs/framework/src/bundle_revision.c @@ -24,7 +24,7 @@ #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) { +celix_status_t celix_bundleRevision_create(celix_framework_t* fw, const char *root, const char *location, celix_bundle_manifest_t* manifest, bundle_revision_pt *bundle_revision) { celix_status_t status = CELIX_SUCCESS; bundle_revision_pt revision = calloc(1, sizeof(*revision)); if (revision != NULL) { @@ -44,7 +44,7 @@ celix_status_t celix_bundleRevision_create(celix_framework_t* fw, const char *ro if (revision != NULL) { bundleRevision_destroy(revision); } else { - manifest_destroy(manifest); + celix_bundleManifest_destroy(manifest); } return status; } @@ -55,7 +55,7 @@ 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) { - manifest_destroy(revision->manifest); + celix_bundleManifest_destroy(revision->manifest); free(revision->root); free(revision->location); free(revision); @@ -63,7 +63,7 @@ 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) { +celix_status_t bundleRevision_getManifest(const bundle_revision_t* revision, celix_bundle_manifest_t** manifest) { *manifest = revision->manifest; return CELIX_SUCCESS; } diff --git a/libs/framework/include_deprecated/bundle_revision.h b/libs/framework/src/bundle_revision.h similarity index 83% rename from libs/framework/include_deprecated/bundle_revision.h rename to libs/framework/src/bundle_revision.h index 372b9f9ef..50f41fe85 100644 --- a/libs/framework/include_deprecated/bundle_revision.h +++ b/libs/framework/src/bundle_revision.h @@ -25,7 +25,7 @@ #include "celix_types.h" #include "celix_errno.h" -#include "manifest.h" +#include "celix_bundle_manifest.h" #include "celix_log.h" #include "celix_array_list.h" #include "celix_framework_export.h" @@ -54,7 +54,7 @@ extern "C" { * - 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)); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleRevision_getNumber(const bundle_revision_t* revision, long *revisionNr) __attribute__((deprecated)); /** * Retrieves the location of the given revision. @@ -66,7 +66,7 @@ CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleRevision_getNumber(const * - 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); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleRevision_getLocation(const bundle_revision_t* revision, const char **location); /** * Retrieves the root of the given revision. @@ -78,7 +78,7 @@ CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleRevision_getLocation(cons * - 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); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleRevision_getRoot(const bundle_revision_t* revision, const char **root); /** * Retrieves the manifest of the given revision. @@ -90,7 +90,8 @@ CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundleRevision_getRoot(const bu * - 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); +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleRevision_getManifest(const bundle_revision_t* revision, + celix_bundle_manifest_t** manifest); /** * Originally retrieved the handles of the installed libraries for this revision. diff --git a/libs/framework/src/bundle_revision_private.h b/libs/framework/src/bundle_revision_private.h index 0eb2106a5..f0e18073f 100644 --- a/libs/framework/src/bundle_revision_private.h +++ b/libs/framework/src/bundle_revision_private.h @@ -39,11 +39,11 @@ extern "C" { * A bundle can have multiple revisions. A bundle revision is immutable. */ struct bundleRevision { - celix_framework_t *fw; + celix_framework_t* fw; long revisionNr; - char *root; - char *location; - manifest_pt manifest; + char* root; + char* location; + celix_bundle_manifest_t* manifest; }; /** @@ -60,7 +60,11 @@ 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, + bundle_revision_pt* bundle_revision); bundle_revision_t* bundleRevision_revise(const bundle_revision_t* revision, const char* updatedBundleUrl); diff --git a/libs/framework/src/celix_bundle_manifest.c b/libs/framework/src/celix_bundle_manifest.c index 2d4c8c2d9..c0e98b75f 100644 --- a/libs/framework/src/celix_bundle_manifest.c +++ b/libs/framework/src/celix_bundle_manifest.c @@ -36,6 +36,7 @@ // 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" struct celix_bundle_manifest { @@ -49,6 +50,7 @@ struct celix_bundle_manifest { //Optional fields char* bundleGroup; + char* description; char* activatorLibrary; celix_array_list_t* privateLibraries; }; @@ -81,7 +83,6 @@ celix_status_t celix_bundleManifest_create(celix_properties_t* attributes, celix 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); @@ -91,6 +92,30 @@ celix_status_t celix_bundleManifest_createFromFile(const char* filename, celix_b return celix_bundleManifest_create(properties, manifestOut); } +celix_status_t celix_bundleManifest_createFrameworkManifest(celix_bundle_manifest_t** manifest) { + celix_properties_t* properties = celix_properties_create(); + if (!properties) { + celix_err_push("Failed to create properties for framework manifest"); + return ENOMEM; + } + + celix_status_t status = celix_properties_set(properties, CELIX_BUNDLE_MANIFEST_VERSION, "2.0.0"); + status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_SYMBOLIC_NAME, "celix.framework")); + status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_NAME, "Celix Framework")); + //status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_VERSION, CELIX_FRAMEWORK_VERSION)); + status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_VERSION, "3.0.0")); //TODO + status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_GROUP, "Celix")); + status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_DESCRIPTION, "Celix Framework")); + + 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); +} + void celix_bundleManifest_destroy(celix_bundle_manifest_t* manifest) { if (manifest) { celix_properties_destroy(manifest->attributes); @@ -102,6 +127,7 @@ void celix_bundleManifest_destroy(celix_bundle_manifest_t* manifest) { free(manifest->activatorLibrary); free(manifest->bundleGroup); + free(manifest->description); celix_arrayList_destroy(manifest->privateLibraries); free(manifest); @@ -186,6 +212,13 @@ static celix_status_t celix_bundleManifest_setOptionalAttributes(celix_bundle_ma CELIX_ERR_RET_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_ERR_RET_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); @@ -215,7 +248,7 @@ const char* celix_bundleManifest_getBundleName(celix_bundle_manifest_t* manifest return manifest->bundleName; } -const char* celix_bundleManifest_getSymbolicName(celix_bundle_manifest_t* manifest) { +const char* celix_bundleManifest_getBundleSymbolicName(celix_bundle_manifest_t* manifest) { return manifest->symbolicName; } @@ -235,6 +268,10 @@ const celix_array_list_t* celix_bundleManifest_getBundlePrivateLibraries(celix_b return manifest->privateLibraries; } +const char* celix_bundleManifest_getBundleDescription(celix_bundle_manifest_t* manifest) { + return manifest->description; +} + const char* celix_bundleManifest_getBundleGroup(celix_bundle_manifest_t* manifest) { return manifest->bundleGroup; } diff --git a/libs/framework/src/celix_bundle_manifest.h b/libs/framework/src/celix_bundle_manifest.h index 662f2804d..21b1c8679 100644 --- a/libs/framework/src/celix_bundle_manifest.h +++ b/libs/framework/src/celix_bundle_manifest.h @@ -82,6 +82,23 @@ celix_status_t celix_bundleManifest_create(celix_properties_t* attributes, celix */ 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. */ @@ -115,7 +132,7 @@ const char* celix_bundleManifest_getBundleName(celix_bundle_manifest_t* manifest * @param[in] manifest The bundle manifest to get the manifest version from. Cannot be NULL. * @return The bundle symbolic name. Will never be NULL. */ -const char* celix_bundleManifest_getSymbolicName(celix_bundle_manifest_t* manifest); +const char* celix_bundleManifest_getBundleSymbolicName(celix_bundle_manifest_t* manifest); /** * @brief Get the bundle version. Returned value is valid as long as the manifest is valid. @@ -150,6 +167,14 @@ const char* celix_bundleManifest_getBundleActivatorLibrary(celix_bundle_manifest */ const celix_array_list_t* celix_bundleManifest_getBundlePrivateLibraries(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 manifest version 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); + /** * @brief Get the bundle group. Returned value is valid as long as the manifest is valid. * diff --git a/libs/framework/src/celix_bundle_private.h b/libs/framework/src/celix_bundle_private.h new file mode 100644 index 000000000..d866f3119 --- /dev/null +++ b/libs/framework/src/celix_bundle_private.h @@ -0,0 +1,147 @@ +/* + * 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_PRIVATE_H_ +#define BUNDLE_PRIVATE_H_ + +#include "celix_bundle.h" +#include "celix_module.h" + +#ifdef __cplusplus +extern "C" { +#endif + +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; + bundle_archive_pt archive; + celix_array_list_t* modules; + + 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. + * @param[in] archive The archive. + * @param[out] bundleOut The created bundle. + * @return CELIX_SUCCESS if the bundle is created successfully. + */ +celix_status_t +celix_bundle_createFromArchive(celix_framework_t *framework, bundle_archive_pt archive, celix_bundle_t **bundleOut); + +/** + * @brief Get the bundle archive. + * + * @param[in] bundle The bundle. + * @return The bundle archive. + */ +bundle_archive_t *celix_bundle_getArchive(const celix_bundle_t *bundle); + +/** + * Destroys the bundle. + * @param[in] bundle The bundle to destroy. + * @return CELIX_SUCCESS if the bundle is destroyed successfully. + */ +celix_status_t bundle_destroy(celix_bundle_t *bundle); + +/** + * @brief Get the bundle symbolic name. + */ +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 celix_array_list_t *bundle_getModules(const celix_bundle_t *bundle); + +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_getEntry(const celix_bundle_t *bundle, const char *name, char **entry); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_update(celix_bundle_t *bundle, const char *inputFile); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_stop(celix_bundle_t *bundle); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_setState(celix_bundle_t *bundle, bundle_state_e state); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_setPersistentStateInactive(celix_bundle_t *bundle); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_setPersistentStateUninstalled(celix_bundle_t *bundle); + +CELIX_FRAMEWORK_DEPRECATED void uninstallBundle(celix_bundle_t *bundle); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_revise(celix_bundle_t *bundle, const char *location, const char *inputFile); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_addModule(celix_bundle_t *bundle, celix_module_t* celix_module); + +// Service Reference Functions +CELIX_FRAMEWORK_DEPRECATED celix_array_list_t *getUsingBundles(service_reference_pt reference); + +CELIX_FRAMEWORK_DEPRECATED int compareTo(service_reference_pt a, service_reference_pt b); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getState(const celix_bundle_t *bundle, bundle_state_e *state); + +CELIX_FRAMEWORK_DEPRECATED 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 celix_status_t bundle_refresh(celix_bundle_t *bundle); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getBundleId(const celix_bundle_t *bundle, long *id); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getRegisteredServices(celix_bundle_t *bundle, celix_array_list_t **list); + +CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getServicesInUse(celix_bundle_t *bundle, celix_array_list_t **list); + +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 + +#endif /* BUNDLE_PRIVATE_H_ */ diff --git a/libs/framework/src/celix_module.h b/libs/framework/src/celix_module.h new file mode 100644 index 000000000..af83623b2 --- /dev/null +++ b/libs/framework/src/celix_module.h @@ -0,0 +1,78 @@ +/* + * 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_manifest_t* manifest, celix_bundle_t* bundle); + +celix_module_t* module_createFrameworkModule(celix_framework_t* fw, 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) + +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); + +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 5d2044a8b..1aff73adb 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" @@ -146,7 +146,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); @@ -262,7 +262,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_framework_bundle_entry_t *entry = fw_bundleEntry_create(framework->bundle); @@ -317,8 +317,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); } @@ -408,7 +407,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)); @@ -729,61 +730,61 @@ 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_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++) { +// celix_module_t* module = 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++) { +// celix_module_t* dependent = 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; @@ -1012,7 +1013,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; @@ -2106,8 +2107,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) { @@ -2130,7 +2131,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); @@ -2140,7 +2141,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)); @@ -2158,7 +2159,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,7 +2231,7 @@ celix_status_t celix_framework_startBundleEntry(celix_framework_t* framework, ce celix_status_t status = CELIX_SUCCESS; const char* error = ""; const char* name = ""; - module_pt module = NULL; + celix_module_t* module = NULL; celix_bundle_context_t* context = NULL; celix_bundle_activator_t* activator = NULL; @@ -2274,7 +2275,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))); @@ -2294,9 +2295,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) { @@ -2320,7 +2320,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 40caeb283..1686e7340 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 a00d6d8c6..572cab485 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..a389a9130 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,142 @@ #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_bundle_manifest_t* manifest; celix_thread_mutex_t handlesLock; // protects libraryHandles and bundleActivatorHandle 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(); +celix_module_t* module_create(celix_bundle_manifest_t* manifest, celix_bundle_t* bundle) { + assert(manifest != NULL); + assert(bundle != NULL); + celix_framework_t* fw; + bundle_getFramework(bundle, &fw); - if (manifestParser_create(module, headerMap, &mp) == CELIX_SUCCESS) { - module->symbolicName = NULL; - manifestParser_getAndDuplicateSymbolicName(mp, &module->symbolicName); + celix_autoptr(celix_module_t) module = calloc(1, sizeof(*module)); + celix_autoptr(celix_array_list_t) libraryHandles = celix_arrayList_createStringArray(); + if (!module || !libraryHandles) { + fw_log(fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to create module, out of memory"); + return NULL; + } - module->group = NULL; - manifestParser_getAndDuplicateGroup(mp, &module->group); + 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"); + celix_framework_logTssErrors(fw->logger, CELIX_LOG_LEVEL_ERROR); + return NULL; + } - module->name = NULL; - manifestParser_getAndDuplicateName(mp, &module->name); + module->fw = fw; + module->bundle = bundle; + module->resolved = false; + module->manifest = manifest; + module->libraryHandles = celix_steal_ptr(libraryHandles); - module->description = NULL; - manifestParser_getAndDuplicateDescription(mp, &module->description); + return celix_steal_ptr(module); +} - module->version = NULL; - manifestParser_getBundleVersion(mp, &module->version); +celix_module_t* module_createFrameworkModule(celix_framework_t* fw, bundle_pt bundle) { + celix_autoptr(celix_bundle_manifest_t) manifest = NULL; + celix_status_t status = celix_bundleManifest_createFrameworkManifest(&manifest); + if (status != CELIX_SUCCESS) { + celix_framework_logTssErrors(fw->logger, CELIX_LOG_LEVEL_ERROR); + return NULL; + } - manifestParser_destroy(mp); - } + celix_autoptr(celix_module_t) module = calloc(1, sizeof(*module)); + celix_autoptr(celix_array_list_t) libraryHandles = celix_arrayList_createStringArray(); + if (!module || !libraryHandles) { + fw_log(fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to create module, out of memory"); + return NULL; } - return module; -} + status = celixThreadMutex_create(&module->handlesLock, NULL); + if (!status) { + fw_log(fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to create module, error creating mutex"); + 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->manifest = celix_steal_ptr(manifest); + 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; } -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_bundleManifest_destroy(module->manifest); 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) { + return celix_bundleManifest_getBundleVersion(module->manifest); } -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; + *symbolicName = celix_bundleManifest_getBundleSymbolicName(module->manifest); } 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; + *name = celix_bundleManifest_getBundleName(module->manifest); } 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; + *group = celix_bundleManifest_getBundleGroup(module->manifest); } 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 { + *description = celix_bundleManifest_getBundleDescription(module->manifest); + } + 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); @@ -253,11 +213,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 +232,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,34 +252,26 @@ 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_get(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; } @@ -320,51 +280,37 @@ celix_status_t celix_module_loadLibraries(celix_module_t* module) { celix_library_handle_t* activatorHandle = NULL; bundle_archive_pt archive = NULL; bundle_revision_pt revision = NULL; - manifest_pt manifest = NULL; + celix_bundle_manifest_t* 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)); - } + const char* activator = celix_bundleManifest_getBundleActivatorLibrary(manifest); + const celix_array_list_t* privateLibraries = celix_bundleManifest_getBundlePrivateLibraries(manifest); if (privateLibraries != NULL) { status = CELIX_DO_IF(status, - celix_module_loadLibrariesInManifestEntry(module, privateLibraries, activator, archive, &activatorHandle)); + celix_module_loadLibrariesInManifestEntry( + module, privateLibraries, activator, archive, &activatorHandle)); } if (status == CELIX_SUCCESS) { - bundle_setHandle(module->bundle, activatorHandle); //note deprecated + bundle_setHandle(module->bundle, activatorHandle); // note deprecated celixThreadMutex_lock(&module->handlesLock); module->bundleActivatorHandle = activatorHandle; celixThreadMutex_unlock(&module->handlesLock); } } - 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); } 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/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); From c44bbe60612e122a7150c3b4eb0791ae5b33cfe4 Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Sun, 21 Jul 2024 20:56:24 +0200 Subject: [PATCH 05/17] 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(-) create mode 100644 cmake/cmake_celix/templates/MANIFEST.json.in delete mode 100644 cmake/cmake_celix/templates/Manifest.in 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} "$" ${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,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 @@ +{ +$, +> + "CELIX_BUNDLE_MANIFEST_VERSION" : "2.0.0", + "CELIX_BUNDLE_SYMBOLIC_NAME" : "$", + "CELIX_BUNDLE_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" : "$,$>" +} \ 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: $ -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/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; From 4678197b9693fa6cbf11dfa421de7daa0ec18ed3 Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Sun, 21 Jul 2024 22:58:40 +0200 Subject: [PATCH 06/17] gh-685: Add cmake generated celix_framework_version.h --- cmake/celix_project/CelixProject.cmake | 38 +++++++++++++++ cmake/cmake_celix/BundlePackaging.cmake | 3 +- cmake/cmake_celix/ContainerPackaging.cmake | 44 +++-------------- cmake/cmake_celix/templates/MANIFEST.json.in | 4 +- libs/framework/CMakeLists.txt | 2 + libs/framework/gtest/CMakeLists.txt | 3 +- .../gtest/src/CxxBundleContextTestSuite.cc | 8 ++-- .../gtest/src/DependencyManagerTestSuite.cc | 2 +- .../gtest/src/MultipleFrameworkTestSuite.cc | 29 ----------- libs/framework/src/celix_bundle_manifest.c | 17 ++++--- .../src/celix_framework_version.h.in | 48 +++++++++++++++++++ 11 files changed, 115 insertions(+), 83 deletions(-) delete mode 100644 libs/framework/gtest/src/MultipleFrameworkTestSuite.cc create mode 100644 libs/framework/src/celix_framework_version.h.in diff --git a/cmake/celix_project/CelixProject.cmake b/cmake/celix_project/CelixProject.cmake index 9812155e6..ddb7db240 100644 --- a/cmake/celix_project/CelixProject.cmake +++ b/cmake/celix_project/CelixProject.cmake @@ -85,6 +85,44 @@ MACRO(celix_subproject) ENDIF (${NAME}) ENDMACRO(celix_subproject) +#[[ +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() + #[[ Custom target which list the Celix CMake targets that are still using deprecated headers. ]] diff --git a/cmake/cmake_celix/BundlePackaging.cmake b/cmake/cmake_celix/BundlePackaging.cmake index c2f6863cf..f5eec25af 100644 --- a/cmake/cmake_celix/BundlePackaging.cmake +++ b/cmake/cmake_celix/BundlePackaging.cmake @@ -753,13 +753,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 () diff --git a/cmake/cmake_celix/ContainerPackaging.cmake b/cmake/cmake_celix/ContainerPackaging.cmake index 77044884c..501c7ca56 100644 --- a/cmake/cmake_celix/ContainerPackaging.cmake +++ b/cmake/cmake_celix/ContainerPackaging.cmake @@ -595,38 +595,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. @@ -641,14 +609,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() @@ -669,14 +637,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/templates/MANIFEST.json.in b/cmake/cmake_celix/templates/MANIFEST.json.in index 0770d4765..8abe223a1 100644 --- a/cmake/cmake_celix/templates/MANIFEST.json.in +++ b/cmake/cmake_celix/templates/MANIFEST.json.in @@ -1,6 +1,6 @@ { -$, -> + $,$ + >$<$>:$> "CELIX_BUNDLE_MANIFEST_VERSION" : "2.0.0", "CELIX_BUNDLE_SYMBOLIC_NAME" : "$", "CELIX_BUNDLE_VERSION" : "$", diff --git a/libs/framework/CMakeLists.txt b/libs/framework/CMakeLists.txt index 94e031c78..421fa20e6 100644 --- a/libs/framework/CMakeLists.txt +++ b/libs/framework/CMakeLists.txt @@ -70,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/gtest/CMakeLists.txt b/libs/framework/gtest/CMakeLists.txt index af3f60c0a..bd0c62c86 100644 --- a/libs/framework/gtest/CMakeLists.txt +++ b/libs/framework/gtest/CMakeLists.txt @@ -19,6 +19,8 @@ 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(simple_test_bundle2 NO_ACTIVATOR VERSION 1.0.0) add_celix_bundle(simple_test_bundle3 NO_ACTIVATOR VERSION 1.0.0) @@ -46,7 +48,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/CxxBundleContextTestSuite.cc b/libs/framework/gtest/src/CxxBundleContextTestSuite.cc index b987d28b8..0598d5f4b 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}; @@ -713,7 +713,7 @@ TEST_F(CxxBundleContextTestSuite, GetBundleInformation) { EXPECT_TRUE(!bnd.getEntry("META-INF/MANIFEST.MF").empty()); EXPECT_EQ(bnd.getEntry("/META-INF/MANIFEST.MF"), bnd.getEntry("META-INF/MANIFEST.MF")); 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/MultipleFrameworkTestSuite.cc b/libs/framework/gtest/src/MultipleFrameworkTestSuite.cc deleted file mode 100644 index 393ce42cc..000000000 --- a/libs/framework/gtest/src/MultipleFrameworkTestSuite.cc +++ /dev/null @@ -1,29 +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. - */ - -#include - -#include "celix_launcher.h" - - -class MultipleFrameworkTestSuite : public ::testing::Test { -public: - MultipleFrameworkTestSuite() = default; - ~MultipleFrameworkTestSuite() noexcept override = default; -}; diff --git a/libs/framework/src/celix_bundle_manifest.c b/libs/framework/src/celix_bundle_manifest.c index f07e8f310..38330e578 100644 --- a/libs/framework/src/celix_bundle_manifest.c +++ b/libs/framework/src/celix_bundle_manifest.c @@ -26,6 +26,7 @@ #include "celix_stdlib_cleanup.h" #include "celix_utils.h" #include "celix_version.h" +#include "celix_framework_version.h" // Mandatory manifest attributes #define CELIX_BUNDLE_MANIFEST_VERSION "CELIX_BUNDLE_MANIFEST_VERSION" @@ -40,6 +41,7 @@ #define CELIX_BUNDLE_GROUP "CELIX_BUNDLE_GROUP" #define CELIX_BUNDLE_SYMBOLIC_NAME_ALLOWED_SPECIAL_CHARS "-_:." +#define CELIX_FRAMEWORK_MANIFEST_VERSION "2.0.0" struct celix_bundle_manifest { celix_properties_t* attributes; @@ -101,13 +103,14 @@ celix_status_t celix_bundleManifest_createFrameworkManifest(celix_bundle_manifes return ENOMEM; } - celix_status_t status = celix_properties_set(properties, CELIX_BUNDLE_MANIFEST_VERSION, "2.0.0"); - status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_SYMBOLIC_NAME, "celix.framework")); - status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_NAME, "Celix Framework")); - //status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_VERSION, CELIX_FRAMEWORK_VERSION)); - status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_VERSION, "3.0.0")); //TODO - status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_GROUP, "Celix")); - status = CELIX_DO_IF(status, celix_properties_set(properties, CELIX_BUNDLE_DESCRIPTION, "Celix Framework")); + 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")); + 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_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"); 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 From 26d14ff5970fbeddf5d65abdf647908b1469c860 Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Mon, 22 Jul 2024 12:22:22 +0200 Subject: [PATCH 07/17] gh-685: Refactor bundle manifest storage --- cmake/celix_project/CelixProject.cmake | 38 ------ cmake/cmake_celix/Generic.cmake | 38 ++++++ libs/framework/gtest/CMakeLists.txt | 4 +- ...activator.c => activator_with_exception.c} | 0 libs/framework/include/celix_types.h | 2 - libs/framework/src/bundle.c | 43 +++---- libs/framework/src/bundle_archive.c | 8 +- libs/framework/src/bundle_archive.h | 8 +- libs/framework/src/bundle_revision.c | 56 +++------ libs/framework/src/bundle_revision.h | 112 ------------------ libs/framework/src/bundle_revision_private.h | 21 ++-- libs/framework/src/celix_module.h | 2 +- libs/framework/src/framework.c | 2 +- libs/framework/src/module.c | 74 +++++------- 14 files changed, 121 insertions(+), 287 deletions(-) rename libs/framework/gtest/src/{nop_activator.c => activator_with_exception.c} (100%) delete mode 100644 libs/framework/src/bundle_revision.h diff --git a/cmake/celix_project/CelixProject.cmake b/cmake/celix_project/CelixProject.cmake index ddb7db240..9812155e6 100644 --- a/cmake/celix_project/CelixProject.cmake +++ b/cmake/celix_project/CelixProject.cmake @@ -85,44 +85,6 @@ MACRO(celix_subproject) ENDIF (${NAME}) ENDMACRO(celix_subproject) -#[[ -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() - #[[ Custom target which list the Celix CMake targets that are still using deprecated headers. ]] 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/libs/framework/gtest/CMakeLists.txt b/libs/framework/gtest/CMakeLists.txt index bd0c62c86..6770f7e03 100644 --- a/libs/framework/gtest/CMakeLists.txt +++ b/libs/framework/gtest/CMakeLists.txt @@ -24,7 +24,7 @@ celix_bundle_headers(simple_test_bundle1 "Extra-Header3: value3") 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) @@ -35,7 +35,7 @@ add_celix_bundle(cond_test_bundle SOURCES src/CondTestBundleActivator.cc VERSION 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(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() diff --git a/libs/framework/gtest/src/nop_activator.c b/libs/framework/gtest/src/activator_with_exception.c similarity index 100% rename from libs/framework/gtest/src/nop_activator.c rename to libs/framework/gtest/src/activator_with_exception.c 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/src/bundle.c b/libs/framework/src/bundle.c index 7f8342328..c02ef2551 100644 --- a/libs/framework/src/bundle.c +++ b/libs/framework/src/bundle.c @@ -166,27 +166,14 @@ 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; - bundle_archive_pt archive = NULL; - bundle_revision_pt revision = NULL; - celix_bundle_manifest_t* manifest = 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, &manifest)); - 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 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(manifest, bundle); + module = module_create(bundle); } if (!module) { status = CELIX_BUNDLE_EXCEPTION; @@ -194,8 +181,7 @@ celix_status_t bundle_createModule(bundle_pt bundle, celix_module_t** moduleOut) return status; } - - const char * symName = NULL; + const char* symName = NULL; status = module_getSymbolicName(module, &symName); assert(status == CELIX_SUCCESS); /* @@ -206,7 +192,11 @@ celix_status_t bundle_createModule(bundle_pt bundle, celix_module_t** 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; @@ -487,24 +477,23 @@ char* celix_bundle_getDataFile(const celix_bundle_t* bnd, const char *path) { } const char* celix_bundle_getManifestValue(const celix_bundle_t* bnd, const char* attribute) { - const char* header = NULL; - if (bnd != NULL) { + const char* header = NULL; + if (bnd != NULL) { bundle_archive_t* arch = NULL; bundle_getArchive(bnd, &arch); if (arch != NULL) { - bundle_revision_t* rev = NULL; + celix_bundle_revision_t* rev = NULL; bundleArchive_getCurrentRevision(arch, &rev); if (rev != NULL) { - celix_bundle_manifest_t* man = NULL; - bundleRevision_getManifest(rev, &man); - if (man != 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; + } + return header; } const char* celix_bundle_getGroup(const celix_bundle_t *bnd) { diff --git a/libs/framework/src/bundle_archive.c b/libs/framework/src/bundle_archive.c index df594991b..bf6c1bbb7 100644 --- a/libs/framework/src/bundle_archive.c +++ b/libs/framework/src/bundle_archive.c @@ -53,7 +53,7 @@ struct bundleArchive { 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) @@ -345,7 +345,7 @@ void bundleArchive_destroy(bundle_archive_pt archive) { free(archive->storeRoot); free(archive->bundleSymbolicName); free(archive->bundleVersion); - bundleRevision_destroy(archive->revision); + celix_bundleRevision_destroy(archive->revision); free(archive); } } @@ -388,13 +388,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); } diff --git a/libs/framework/src/bundle_archive.h b/libs/framework/src/bundle_archive.h index d6ceffd4f..bccee8efb 100644 --- a/libs/framework/src/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" @@ -64,10 +64,10 @@ bundleArchive_revise(bundle_archive_pt archive, const char *location, const char CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_rollbackRevise(bundle_archive_pt archive, bool *rolledback); CELIX_FRAMEWORK_DEPRECATED celix_status_t -bundleArchive_getRevision(bundle_archive_pt archive, long revNr, bundle_revision_pt *revision); +bundleArchive_getRevision(bundle_archive_pt archive, long revNr, celix_bundle_revision_t** revision); CELIX_FRAMEWORK_DEPRECATED celix_status_t -bundleArchive_getCurrentRevision(bundle_archive_pt archive, bundle_revision_pt *revision); +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)); diff --git a/libs/framework/src/bundle_revision.c b/libs/framework/src/bundle_revision.c index 80707296a..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, celix_bundle_manifest_t* 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,7 +50,7 @@ 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 { celix_bundleManifest_destroy(manifest); } @@ -53,10 +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) { - // TODO who is owner of the manifest?, for now treating this as a weak reference - // celix_bundleManifest_destroy(revision->manifest); + celix_bundleManifest_destroy(revision->manifest); free(revision->root); free(revision->location); free(revision); @@ -64,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, celix_bundle_manifest_t** 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.h b/libs/framework/src/bundle_revision.h deleted file mode 100644 index 50f41fe85..000000000 --- a/libs/framework/src/bundle_revision.h +++ /dev/null @@ -1,112 +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 "celix_bundle_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 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 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 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 celix_status_t bundleRevision_getManifest(const bundle_revision_t* revision, - celix_bundle_manifest_t** 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/src/bundle_revision_private.h b/libs/framework/src/bundle_revision_private.h index f0e18073f..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; - celix_bundle_manifest_t* manifest; -}; +typedef struct celix_bundle_revision celix_bundle_revision_t; /** * Creates a new revision for the given inputFile or location. @@ -64,11 +59,15 @@ celix_status_t celix_bundleRevision_create(celix_framework_t* fw, const char* root, const char* location, celix_bundle_manifest_t* manifest, - bundle_revision_pt* bundle_revision); + 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_module.h b/libs/framework/src/celix_module.h index af83623b2..189d61bd0 100644 --- a/libs/framework/src/celix_module.h +++ b/libs/framework/src/celix_module.h @@ -36,7 +36,7 @@ extern "C" { * @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_manifest_t* manifest, celix_bundle_t* bundle); +celix_module_t* module_create(celix_bundle_t* bundle); celix_module_t* module_createFrameworkModule(celix_framework_t* fw, celix_bundle_t *bundle); diff --git a/libs/framework/src/framework.c b/libs/framework/src/framework.c index ee64f89fe..459834532 100644 --- a/libs/framework/src/framework.c +++ b/libs/framework/src/framework.c @@ -1996,7 +1996,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)); diff --git a/libs/framework/src/module.c b/libs/framework/src/module.c index 56512660c..269d711fa 100644 --- a/libs/framework/src/module.c +++ b/libs/framework/src/module.c @@ -49,14 +49,18 @@ struct celix_module { celix_framework_t* fw; bool resolved; celix_bundle_t* bundle; - celix_bundle_manifest_t* manifest; - celix_thread_mutex_t handlesLock; // protects libraryHandles and bundleActivatorHandle + celix_thread_mutex_t handlesLock; // protects libraryHandles celix_array_list_t* libraryHandles; - void* bundleActivatorHandle; }; -celix_module_t* module_create(celix_bundle_manifest_t* manifest, celix_bundle_t* bundle) { - assert(manifest != NULL); +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); +} + +celix_module_t* module_create(celix_bundle_t* bundle) { assert(bundle != NULL); celix_framework_t* fw; @@ -82,20 +86,12 @@ celix_module_t* module_create(celix_bundle_manifest_t* manifest, celix_bundle_t* module->fw = fw; module->bundle = bundle; module->resolved = false; - module->manifest = manifest; module->libraryHandles = celix_steal_ptr(libraryHandles); return celix_steal_ptr(module); } celix_module_t* module_createFrameworkModule(celix_framework_t* fw, bundle_pt bundle) { - celix_autoptr(celix_bundle_manifest_t) manifest = NULL; - celix_status_t status = celix_bundleManifest_createFrameworkManifest(&manifest); - if (status != CELIX_SUCCESS) { - celix_framework_logTssErrors(fw->logger, CELIX_LOG_LEVEL_ERROR); - return NULL; - } - celix_autoptr(celix_module_t) module = calloc(1, sizeof(*module)); celix_autoptr(celix_array_list_t) libraryHandles = celix_arrayList_createPointerArray(); if (!module || !libraryHandles) { @@ -103,7 +99,7 @@ celix_module_t* module_createFrameworkModule(celix_framework_t* fw, bundle_pt bu return NULL; } - status = celixThreadMutex_create(&module->handlesLock, NULL); + celix_status_t status = celixThreadMutex_create(&module->handlesLock, NULL); if (status != CELIX_SUCCESS) { fw_log(fw->logger, CELIX_LOG_LEVEL_ERROR, @@ -116,7 +112,6 @@ celix_module_t* module_createFrameworkModule(celix_framework_t* fw, bundle_pt bu module->fw = fw; module->bundle = bundle; module->resolved = false; - module->manifest = celix_steal_ptr(manifest); module->libraryHandles = celix_steal_ptr(libraryHandles); return celix_steal_ptr(module); @@ -124,7 +119,6 @@ celix_module_t* module_createFrameworkModule(celix_framework_t* fw, bundle_pt bu void module_destroy(celix_module_t* module) { if (module) { - celix_bundleManifest_destroy(module->manifest); celix_arrayList_destroy(module->libraryHandles); celixThreadMutex_destroy(&module->handlesLock); free(module); @@ -132,7 +126,8 @@ void module_destroy(celix_module_t* module) { } const celix_version_t* module_getVersion(celix_module_t* module) { - return celix_bundleManifest_getBundleVersion(module->manifest); + celix_bundle_manifest_t* man = celix_module_getManifestFromBundle(module->bundle); + return celix_bundleManifest_getBundleVersion(man); } celix_status_t module_getSymbolicName(celix_module_t* module, const char** symbolicName) { @@ -140,7 +135,8 @@ celix_status_t module_getSymbolicName(celix_module_t* module, const char** symbo if (module == NULL) { status = CELIX_ILLEGAL_ARGUMENT; } else { - *symbolicName = celix_bundleManifest_getBundleSymbolicName(module->manifest); + celix_bundle_manifest_t* man = celix_module_getManifestFromBundle(module->bundle); + *symbolicName = celix_bundleManifest_getBundleSymbolicName(man); } return status; } @@ -150,7 +146,8 @@ celix_status_t module_getName(celix_module_t* module, const char **name) { if (module == NULL) { status = CELIX_ILLEGAL_ARGUMENT; } else { - *name = celix_bundleManifest_getBundleName(module->manifest); + celix_bundle_manifest_t* man = celix_module_getManifestFromBundle(module->bundle); + *name = celix_bundleManifest_getBundleName(man); } return status; } @@ -160,7 +157,8 @@ celix_status_t module_getGroup(celix_module_t* module, const char **group) { if (module == NULL) { status = CELIX_ILLEGAL_ARGUMENT; } else { - *group = celix_bundleManifest_getBundleGroup(module->manifest); + celix_bundle_manifest_t* man = celix_module_getManifestFromBundle(module->bundle); + *group = celix_bundleManifest_getBundleGroup(man); } return status; } @@ -170,7 +168,8 @@ celix_status_t module_getDescription(celix_module_t* module, const char **descri if (module == NULL) { status = CELIX_ILLEGAL_ARGUMENT; } else { - *description = celix_bundleManifest_getBundleDescription(module->manifest); + celix_bundle_manifest_t* man = celix_module_getManifestFromBundle(module->bundle); + *description = celix_bundleManifest_getBundleDescription(man); } return status; } @@ -197,7 +196,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; } @@ -284,29 +282,16 @@ static celix_status_t celix_module_loadLibrariesInManifestEntry(celix_module_t* 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; - celix_bundle_manifest_t* 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* activator = celix_bundleManifest_getBundleActivatorLibrary(manifest); - const celix_array_list_t* privateLibraries = celix_bundleManifest_getBundlePrivateLibraries(manifest); - - if (privateLibraries != NULL) { - status = CELIX_DO_IF(status, - celix_module_loadLibrariesInManifestEntry( - module, privateLibraries, activator, archive, &activatorHandle)); - } + bundle_archive_t* archive = celix_bundle_getArchive(module->bundle); - if (status == CELIX_SUCCESS) { - bundle_setHandle(module->bundle, activatorHandle); // note deprecated - celixThreadMutex_lock(&module->handlesLock); - module->bundleActivatorHandle = activatorHandle; - celixThreadMutex_unlock(&module->handlesLock); - } + 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 (privateLibraries != NULL) { + status = CELIX_DO_IF( + status, + celix_module_loadLibrariesInManifestEntry(module, privateLibraries, activator, archive, &activatorHandle)); } if (status != CELIX_SUCCESS) { @@ -318,5 +303,6 @@ celix_status_t celix_module_loadLibraries(celix_module_t* module) { (void)celix_module_closeLibraries(module); } + bundle_setHandle(module->bundle, activatorHandle); return status; } From 75aafbcf6ae656e58d29aa89f7970ffb3fb8227f Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Fri, 26 Jul 2024 16:09:22 +0200 Subject: [PATCH 08/17] gh-685: Add missing includes --- .../rsa_shm/gtest/src/RsaShmExportRegistrationUnitTestSuite.cc | 1 + .../rsa_shm/src/rsa_shm_export_registration.c | 1 + .../remote_service_admin_shm_v2/rsa_shm/src/rsa_shm_impl.c | 1 + 3 files changed, 3 insertions(+) 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" From 7b4b0cc56d0198935e848b0e2de6e46146d3e847 Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Fri, 26 Jul 2024 16:19:43 +0200 Subject: [PATCH 09/17] gh-685: Add additional manifest tests --- .../src/ManifestErrorInjectionTestSuite.cc | 15 ++++++++- libs/framework/gtest/src/ManifestTestSuite.cc | 32 +++++++++++++++++++ libs/framework/src/celix_bundle_manifest.c | 16 +++++----- libs/utils/include/celix_err.h | 8 ++--- 4 files changed, 58 insertions(+), 13 deletions(-) diff --git a/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc b/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc index ab7114e08..7813efe63 100644 --- a/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc +++ b/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc @@ -46,5 +46,18 @@ TEST_F(ManifestErrorInjectionTestSuite, NoMemoryForManifestCreateTest) { 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"); + celix_err_printErrors(stdout, "Errors are expected [", "]\n"); +} + +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); + + celix_ei_expect_celix_properties_set((void*)celix_bundleManifest_createFrameworkManifest, 0, CELIX_ENOMEM, 3); + status = celix_bundleManifest_createFrameworkManifest(&manifest); + EXPECT_EQ(CELIX_ENOMEM, status); + + celix_err_printErrors(stdout, "Errors are expected [", "]\n"); } diff --git a/libs/framework/gtest/src/ManifestTestSuite.cc b/libs/framework/gtest/src/ManifestTestSuite.cc index 8f10dfa16..73fe5f9eb 100644 --- a/libs/framework/gtest/src/ManifestTestSuite.cc +++ b/libs/framework/gtest/src/ManifestTestSuite.cc @@ -24,6 +24,7 @@ #include "celix_err.h" #include "celix_properties.h" #include "celix_stdlib_cleanup.h" +#include "celix_framework_version.h" class ManifestTestSuite : public ::testing::Test { public: @@ -60,6 +61,15 @@ TEST_F(ManifestTestSuite, CreateManifestTest) { EXPECT_EQ(4, celix_properties_size(celix_bundleManifest_getAttributes(manifest))); } +TEST_F(ManifestTestSuite, InvalidArgumentTest) { + celix_bundle_manifest_t* man = nullptr; + auto status = celix_bundleManifest_create(nullptr, &man); + EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); + + status = celix_bundleManifest_createFromFile("invalid-file", &man); + EXPECT_EQ(CELIX_FILE_IO_EXCEPTION, status); +} + TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) { //Given an empty properties set celix_properties_t *properties = celix_properties_create(); @@ -196,3 +206,25 @@ TEST_F(ManifestTestSuite, GetBuiltinAttributes) { EXPECT_STREQ("my_group", celix_bundleManifest_getBundleGroup(manifest2)); EXPECT_STREQ("my_description", celix_bundleManifest_getBundleDescription(manifest2)); } + +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/src/celix_bundle_manifest.c b/libs/framework/src/celix_bundle_manifest.c index 38330e578..91eee7334 100644 --- a/libs/framework/src/celix_bundle_manifest.c +++ b/libs/framework/src/celix_bundle_manifest.c @@ -149,11 +149,11 @@ static celix_status_t celix_bundleManifest_setMandatoryAttributes(celix_bundle_m celix_autoptr(celix_version_t) manifestVersion = NULL; celix_status_t getVersionStatus = celix_properties_getAsVersion(manifest->attributes, CELIX_BUNDLE_MANIFEST_VERSION, NULL, &manifestVersion); - CELIX_ERR_RET_IF_ENOMEM(getVersionStatus); + CELIX_RETURN_IF_ENOMEM(getVersionStatus); celix_autoptr(celix_version_t) bundleVersion = NULL; getVersionStatus = celix_properties_getAsVersion(manifest->attributes, CELIX_BUNDLE_VERSION, NULL, &bundleVersion); - CELIX_ERR_RET_IF_ENOMEM(getVersionStatus); + CELIX_RETURN_IF_ENOMEM(getVersionStatus); celix_status_t status = CELIX_SUCCESS; if (!bundleName) { @@ -191,9 +191,9 @@ static celix_status_t celix_bundleManifest_setMandatoryAttributes(celix_bundle_m if (status == CELIX_SUCCESS) { manifest->symbolicName = celix_utils_strdup(symbolicName); - CELIX_ERR_RET_IF_NULL(manifest->symbolicName); + CELIX_RETURN_IF_NULL(manifest->symbolicName); manifest->bundleName = celix_utils_strdup(bundleName); - CELIX_ERR_RET_IF_NULL(manifest->bundleName); + CELIX_RETURN_IF_NULL(manifest->bundleName); manifest->manifestVersion = celix_steal_ptr(manifestVersion); manifest->bundleVersion = celix_steal_ptr(bundleVersion); } @@ -208,27 +208,27 @@ static celix_status_t celix_bundleManifest_setOptionalAttributes(celix_bundle_ma celix_autofree char* activatorLib = NULL; if (lib) { activatorLib = celix_utils_strdup(lib); - CELIX_ERR_RET_IF_NULL(activatorLib); + 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_ERR_RET_IF_NULL(bundleGroup); + 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_ERR_RET_IF_NULL(description); + 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_ERR_RET_IF_ENOMEM(getStatus); + 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)); diff --git a/libs/utils/include/celix_err.h b/libs/utils/include/celix_err.h index d617dcec0..51f30f435 100644 --- a/libs/utils/include/celix_err.h +++ b/libs/utils/include/celix_err.h @@ -95,9 +95,9 @@ 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 return with ENOMEM if the status is ENOMEM and logs an ": Out of memory" error to celix_err. + * Helper macro that returns with ENOMEM if the status is ENOMEM and logs an ": Out of memory" error to celix_err. */ -#define CELIX_ERR_RET_IF_ENOMEM(status) \ +#define CELIX_RETURN_IF_ENOMEM(status) \ do { \ if ((status) == ENOMEM) { \ celix_err_pushf("%s: Out of memory", __func__); \ @@ -106,9 +106,9 @@ CELIX_UTILS_EXPORT int celix_err_dump(char* buf, size_t size, const char* prefix } while (0) /*! - * Helper macro that return with ENOMEM if the arg is NULL and logs an ": Out of memory" error to celix_err. + * Helper macro that returns with ENOMEM if the arg is NULL and logs an ": Out of memory" error to celix_err. */ -#define CELIX_ERR_RET_IF_NULL(arg) \ +#define CELIX_RETURN_IF_NULL(arg) \ do { \ if ((arg) == NULL) { \ celix_err_pushf("%s: Out of memory", __func__); \ From 4822eed89f8d0d166644ba99d1d8f0cb8414ddb2 Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Fri, 26 Jul 2024 18:48:48 +0200 Subject: [PATCH 10/17] gh-685: Removing manifest attribute name from celix_constants.h --- libs/framework/include/celix_constants.h | 11 ----------- 1 file changed, 11 deletions(-) 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. From 150c3dc769c587b77834a3c8101c20eb3923d344 Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Fri, 26 Jul 2024 18:52:38 +0200 Subject: [PATCH 11/17] gh-685: Remove commented out code --- CHANGES.md | 9 +++-- libs/framework/src/framework.c | 61 ++-------------------------------- 2 files changed, 9 insertions(+), 61 deletions(-) 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/libs/framework/src/framework.c b/libs/framework/src/framework.c index 11dcd1574..507e52008 100644 --- a/libs/framework/src/framework.c +++ b/libs/framework/src/framework.c @@ -734,62 +734,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++) { -// celix_module_t* module = 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++) { -// celix_module_t* dependent = 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; @@ -1936,7 +1880,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; } @@ -2231,7 +2176,7 @@ 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 = ""; celix_module_t* module = NULL; celix_bundle_context_t* context = NULL; From a123d961fe1a5e39f9c0b76d052a91a43bd8f9c7 Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Fri, 26 Jul 2024 18:53:30 +0200 Subject: [PATCH 12/17] gh-685: Fix tests which were broken after the manifest format refactor --- .../gtest/src/rsa_tests.cc | 2 +- .../src/RsaJsonRpcActivatorUnitTestSuite.cc | 1 - .../src/RsaJsonRpcIntegrationTestSuite.cc | 10 +++--- .../gtest/src/RsaJsonRpcUnitTestSuite.cc | 36 +++++-------------- .../RsaRequestSenderTrackerUnitTestSuite.cc | 1 - .../rsa_rpc_json/src/rsa_json_rpc_impl.c | 9 ++--- 6 files changed, 16 insertions(+), 43 deletions(-) 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 6b97a505e..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 @@ -158,7 +158,7 @@ extern "C" { static void testBundles(void) { celix_array_list_t* bundles = celix_bundleContext_listBundles(context); ASSERT_NE(nullptr, bundles); - ASSERT_EQ(3, celix_arrayList_size(bundles)); //framework, rsa_dfi & calc + 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/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; } From 28ee4a11c428d35a67cbfd5372fdae718a22a1cb Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Fri, 26 Jul 2024 18:54:01 +0200 Subject: [PATCH 13/17] gh-685: Add celix_bundle_getVersion error injection wrapper --- cmake/cmake_celix/templates/MANIFEST.json.in | 2 +- .../celix_bundle/CMakeLists.txt | 1 + .../celix_bundle/include/celix_bundle_ei.h | 3 +++ .../celix_bundle/src/celix_bundle_ei.cc | 15 ++++++++---- libs/utils/include/celix_errno.h | 23 ------------------- 5 files changed, 16 insertions(+), 28 deletions(-) diff --git a/cmake/cmake_celix/templates/MANIFEST.json.in b/cmake/cmake_celix/templates/MANIFEST.json.in index 8abe223a1..1ebec9df2 100644 --- a/cmake/cmake_celix/templates/MANIFEST.json.in +++ b/cmake/cmake_celix/templates/MANIFEST.json.in @@ -11,4 +11,4 @@ "CELIX_BUNDLE_GROUP" : "$", "CELIX_BUNDLE_IMPORT_LIBRARIES" : "$,$>", "CELIX_BUNDLE_EXPORT_LIBRARIES" : "$,$>" -} \ No newline at end of file +} 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/utils/include/celix_errno.h b/libs/utils/include/celix_errno.h index dcab62801..15937fc36 100644 --- a/libs/utils/include/celix_errno.h +++ b/libs/utils/include/celix_errno.h @@ -56,18 +56,6 @@ extern "C" { */ #define CELIX_DO_IF(status, expr) ((status) == CELIX_SUCCESS) ? (expr) : (status) -/*! - * Helper macro which helps with error propagation. It evaluates the provided expression that returns a status and - * returns the status if the status is not CELIX_SUCCESS (0). If the status is CELIX_SUCCESS (0) nothing is done. - */ -#define CELIX_EPROP(expr) \ - do { \ - celix_status_t __status = expr; \ - if (__status != CELIX_SUCCESS) { \ - return __status; \ - } \ - } while (0) - /*! * Helper macro which check the current status and executes a goto the provided label if the * status is not CELIX_SUCCESS (0) @@ -79,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 */ From 297a4372a8417fb4cf7aff9ec6bf2acb5a0fc104 Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Fri, 26 Jul 2024 19:55:04 +0200 Subject: [PATCH 14/17] gh-685: Add missing sys/select.h include --- bundles/shell/remote_shell/src/remote_shell.c | 1 + 1 file changed, 1 insertion(+) diff --git a/bundles/shell/remote_shell/src/remote_shell.c b/bundles/shell/remote_shell/src/remote_shell.c index 44bc96a09..e16ef2148 100644 --- a/bundles/shell/remote_shell/src/remote_shell.c +++ b/bundles/shell/remote_shell/src/remote_shell.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "celix_log_helper.h" #include "celix_utils.h" From dc90776246684e314cf3c9e455cbb19fb745f9ad Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Fri, 26 Jul 2024 22:39:51 +0200 Subject: [PATCH 15/17] gh-685: Remove unused deprecated bundle api --- .../rsa_common/src/export_registration_impl.c | 45 +++---- .../rsa_common/src/import_registration_impl.c | 68 +++++------ libs/framework/include_deprecated/bundle.h | 39 ------ libs/framework/src/bundle.c | 115 ------------------ libs/framework/src/celix_bundle_private.h | 32 ----- 5 files changed, 53 insertions(+), 246 deletions(-) delete mode 100644 libs/framework/include_deprecated/bundle.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 7925275dc..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,7 +32,7 @@ #include "export_registration_impl.h" #include "remote_service_admin_impl.h" -#include "bundle.h" +#include "celix_bundle.h" struct export_reference { @@ -180,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 3288489dd..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,7 +33,8 @@ #include "import_registration_impl.h" #include "remote_service_admin_impl.h" -#include "bundle.h" +#include "celix_bundle.h" +#include "celix_bundle_context.h" struct import_reference { endpoint_description_t *endpoint; @@ -111,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/libs/framework/include_deprecated/bundle.h b/libs/framework/include_deprecated/bundle.h deleted file mode 100644 index 66261e093..000000000 --- a/libs/framework/include_deprecated/bundle.h +++ /dev/null @@ -1,39 +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_errno.h" -#include "celix_framework_export.h" -#include "celix_bundle.h" - -#ifdef __cplusplus -extern "C" { -#endif - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_start(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t bundle_uninstall(celix_bundle_t *bundle); - -#ifdef __cplusplus -} -#endif - -#endif /* BUNDLE_H_ */ diff --git a/libs/framework/src/bundle.c b/libs/framework/src/bundle.c index b739998de..ef0d9e5bb 100644 --- a/libs/framework/src/bundle.c +++ b/libs/framework/src/bundle.c @@ -121,10 +121,6 @@ celix_status_t bundle_getCurrentModule(const_bundle_pt bundle, celix_module_t** return status; } -celix_array_list_t* bundle_getModules(const_bundle_pt bundle) { - return bundle->modules; -} - void * bundle_getHandle(bundle_pt bundle) { return bundle->handle; } @@ -146,11 +142,6 @@ celix_bundle_context_t* celix_bundle_getContext(const_bundle_pt bundle) { return void celix_bundle_setContext(bundle_pt bundle, bundle_context_pt context) { bundle->context = context; } -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; -} - celix_status_t bundle_getState(const_bundle_pt bundle, bundle_state_e *state) { if (bundle==NULL) { *state = CELIX_BUNDLE_STATE_UNKNOWN; @@ -207,62 +198,6 @@ celix_status_t bundle_createModule(bundle_pt bundle, celix_module_t** 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, celix_module_t* module) { celix_arrayList_add(bundle->modules, module); @@ -308,36 +243,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) { - celix_module_t* 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); @@ -350,26 +255,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; diff --git a/libs/framework/src/celix_bundle_private.h b/libs/framework/src/celix_bundle_private.h index d866f3119..9bad00dde 100644 --- a/libs/framework/src/celix_bundle_private.h +++ b/libs/framework/src/celix_bundle_private.h @@ -88,8 +88,6 @@ CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getArchive(const celix_bundle_t CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getCurrentModule(const celix_bundle_t *bundle, celix_module_t** module); -CELIX_FRAMEWORK_DEPRECATED celix_array_list_t *bundle_getModules(const celix_bundle_t *bundle); - CELIX_FRAMEWORK_DEPRECATED void *bundle_getHandle(celix_bundle_t *bundle); CELIX_FRAMEWORK_DEPRECATED void bundle_setHandle(celix_bundle_t *bundle, void *handle); @@ -98,44 +96,14 @@ CELIX_FRAMEWORK_DEPRECATED celix_bundle_activator_t *bundle_getActivator(const c CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_setActivator(celix_bundle_t *bundle, celix_bundle_activator_t *activator); -CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getEntry(const celix_bundle_t *bundle, const char *name, char **entry); - -CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_update(celix_bundle_t *bundle, const char *inputFile); - -CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_stop(celix_bundle_t *bundle); - CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_setState(celix_bundle_t *bundle, bundle_state_e state); -CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_setPersistentStateInactive(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_setPersistentStateUninstalled(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED void uninstallBundle(celix_bundle_t *bundle); - -CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_revise(celix_bundle_t *bundle, const char *location, const char *inputFile); - CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_addModule(celix_bundle_t *bundle, celix_module_t* celix_module); -// Service Reference Functions -CELIX_FRAMEWORK_DEPRECATED celix_array_list_t *getUsingBundles(service_reference_pt reference); - -CELIX_FRAMEWORK_DEPRECATED int compareTo(service_reference_pt a, service_reference_pt b); - CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getState(const celix_bundle_t *bundle, bundle_state_e *state); -CELIX_FRAMEWORK_DEPRECATED 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 celix_status_t bundle_refresh(celix_bundle_t *bundle); - CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getBundleId(const celix_bundle_t *bundle, long *id); -CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getRegisteredServices(celix_bundle_t *bundle, celix_array_list_t **list); - -CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getServicesInUse(celix_bundle_t *bundle, celix_array_list_t **list); - 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); From 30480501ad604c59c77c993ff5cf0da451d8440d Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Sat, 27 Jul 2024 11:25:37 +0200 Subject: [PATCH 16/17] gh-685: Adjust documentation for MANIFEST.MF to MANIFEST.json refactor --- documents/bundles.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 ``` From d10a9839047b7a9939b5073e475b39c750d31fce Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Sun, 10 Nov 2024 19:52:50 +0100 Subject: [PATCH 17/17] gh-685: Improve manifest json impl based on review comments --- cmake/cmake_celix/BundlePackaging.cmake | 48 +---- cmake/cmake_celix/templates/MANIFEST.json.in | 14 +- .../gtest/src/CxxBundleContextTestSuite.cc | 4 +- libs/framework/gtest/src/ManifestTestSuite.cc | 27 ++- .../gtest/src/activator_with_exception.c | 1 + .../include_deprecated/bundle_context.h | 2 - libs/framework/src/bundle.c | 87 +++------ libs/framework/src/bundle_archive.c | 59 +++--- libs/framework/src/bundle_archive.h | 7 +- libs/framework/src/bundle_archive_private.h | 11 +- libs/framework/src/celix_bundle_manifest.c | 183 ++++++------------ libs/framework/src/celix_bundle_manifest.h | 22 +-- libs/framework/src/celix_bundle_private.h | 6 +- libs/framework/src/celix_module.h | 10 - libs/framework/src/framework.c | 10 +- libs/framework/src/module.c | 28 +-- libs/utils/include/celix_err.h | 22 --- 17 files changed, 175 insertions(+), 366 deletions(-) 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