This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/685-remove-bundle-revision in repository https://gitbox.apache.org/repos/asf/celix.git
commit 8b56975f717ab50cc4ff3c4e489810871de7ed83 Author: Pepijn Noltes <pnol...@apache.org> AuthorDate: Fri Jan 3 21:14:13 2025 +0100 gh-685: Remove bundle revision and refactor bundle archive --- libs/framework/CMakeLists.txt | 4 +- libs/framework/gtest/src/BundleArchiveTestSuite.cc | 3 +- .../BundleArchiveWithErrorInjectionTestSuite.cc | 42 +--- .../src/CelixBundleCacheErrorInjectionTestSuite.cc | 11 +- .../gtest/src/CelixBundleCacheTestSuite.cc | 13 +- libs/framework/include/celix_types.h | 3 +- libs/framework/src/bundle.c | 95 ++++----- libs/framework/src/bundle_archive.h | 116 ----------- libs/framework/src/bundle_archive_private.h | 105 ---------- libs/framework/src/bundle_revision.c | 76 -------- libs/framework/src/bundle_revision_private.h | 76 -------- .../{bundle_archive.c => celix_bundle_archive.c} | 212 +++++---------------- libs/framework/src/celix_bundle_archive.h | 153 +++++++++++++++ libs/framework/src/celix_bundle_cache.c | 14 +- libs/framework/src/celix_bundle_cache.h | 8 +- libs/framework/src/celix_bundle_private.h | 10 +- libs/framework/src/celix_framework_utils.c | 2 +- libs/framework/src/framework.c | 15 +- libs/framework/src/framework_private.h | 2 +- libs/framework/src/module.c | 13 +- 20 files changed, 279 insertions(+), 694 deletions(-) diff --git a/libs/framework/CMakeLists.txt b/libs/framework/CMakeLists.txt index 421fa20e6..9c2ba3341 100644 --- a/libs/framework/CMakeLists.txt +++ b/libs/framework/CMakeLists.txt @@ -23,8 +23,8 @@ if (FRAMEWORK) find_package(CURL REQUIRED) endif () set(FRAMEWORK_SRC - src/bundle.c src/bundle_archive.c src/celix_bundle_cache.c - src/bundle_context.c src/bundle_revision.c + src/bundle.c src/celix_bundle_archive.c src/celix_bundle_cache.c + src/bundle_context.c src/framework.c src/module.c src/service_reference.c src/service_registration.c diff --git a/libs/framework/gtest/src/BundleArchiveTestSuite.cc b/libs/framework/gtest/src/BundleArchiveTestSuite.cc index 1f3dd5401..d2350b270 100644 --- a/libs/framework/gtest/src/BundleArchiveTestSuite.cc +++ b/libs/framework/gtest/src/BundleArchiveTestSuite.cc @@ -24,10 +24,9 @@ #include "celix_file_utils.h" #include "celix_framework_utils.h" #include "framework.h" -#include "bundle_archive.h" //including private headers, which should only be used for testing -#include "bundle_archive_private.h" +#include "celix_bundle_archive.h" #include "celix_bundle_private.h" class CxxBundleArchiveTestSuite : public ::testing::Test { diff --git a/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc b/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc index d1b17689f..452fa2bf1 100644 --- a/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc +++ b/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc @@ -32,8 +32,7 @@ #include "celix/FrameworkFactory.h" #include "asprintf_ei.h" -#include "bundle_archive_private.h" -#include "bundle_revision_private.h" +#include "celix_bundle_archive.h" #include "framework_private.h" #include "malloc_ei.h" #include "celix_bundle_manifest.h" @@ -113,19 +112,6 @@ TEST_F(BundleArchiveWithErrorInjectionTestSuite, BundleArchiveCreatedFailedTest) // Given a mocked malloc which returns NULL from a call from manifest_create celix_ei_expect_calloc((void*)celix_bundleManifest_create, 0, nullptr); installBundleAndExpectFailure(); - - teardownErrorInjectors(); - // Given a mocked calloc which returns NULL from a call from bundleRevision_create - celix_ei_expect_calloc((void*)celix_bundleRevision_create, 0, nullptr); - installBundleAndExpectFailure(); - - teardownErrorInjectors(); - // Given a mocked celix_utils_strdup which returns NULL from a call from bundleRevision_create - celix_ei_expect_celix_utils_strdup((void*)celix_bundleRevision_create, 0, nullptr); - installBundleAndExpectFailure(); - - celix_ei_expect_celix_utils_strdup((void*)celix_bundleRevision_create, 0, nullptr, 2); - installBundleAndExpectFailure(); } TEST_F(BundleArchiveWithErrorInjectionTestSuite, BundleArchiveCreateCacheDirectoryFailedTest) { @@ -142,13 +128,13 @@ TEST_F(BundleArchiveWithErrorInjectionTestSuite, BundleArchiveCreateCacheDirecto installBundleAndExpectFailure(); teardownErrorInjectors(); - // Given a mocked celix_utils_strdup which returns NULL from a (indirect) call from bundleArchive_create - celix_ei_expect_celix_utils_strdup((void*)celix_bundleArchive_create, 1, nullptr); + // Given a mocked celix_utils_strdup which returns NULL from a call from bundleArchive_create + celix_ei_expect_celix_utils_strdup((void*)celix_bundleArchive_create, 0, nullptr); installBundleAndExpectFailure(); teardownErrorInjectors(); - // Given a mocked celix_utils_strdup which returns NULL from a second (indirect) call from bundleArchive_create - celix_ei_expect_celix_utils_strdup((void*)celix_bundleArchive_create, 1, nullptr, 2); + // Given a mocked celix_utils_strdup which returns NULL from a second call from bundleArchive_create + celix_ei_expect_celix_utils_strdup((void*)celix_bundleArchive_create, 0, nullptr, 2); installBundleAndExpectFailure(); } @@ -189,7 +175,7 @@ class CelixBundleArchiveErrorInjectionTestSuite : public ::testing::Test { TEST_F(CelixBundleArchiveErrorInjectionTestSuite, ArchiveCreateErrorTest) { celix_bundle_cache_t* cache = nullptr; createCache(&cache); - bundle_archive_t* archive = nullptr; + celix_bundle_archive_t* archive = nullptr; // archive directory creation failures not covered by other tests celix_ei_expect_celix_utils_getLastModified((void*)celix_bundleArchive_create, 2, CELIX_FILE_IO_EXCEPTION); @@ -241,22 +227,6 @@ TEST_F(CelixBundleArchiveErrorInjectionTestSuite, ArchiveCreateErrorTest) { EXPECT_FALSE(celix_utils_directoryExists(TEST_ARCHIVE_ROOT)); teardownErrorInjectors(); - // revision creation failure - celix_ei_expect_calloc((void*)celix_bundleRevision_create, 0, nullptr); - EXPECT_EQ(CELIX_ENOMEM, - celix_bundleArchive_create(&fw, TEST_ARCHIVE_ROOT, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive)); - EXPECT_EQ(nullptr, archive); - EXPECT_FALSE(celix_utils_directoryExists(TEST_ARCHIVE_ROOT)); - teardownErrorInjectors(); - - // bundle state persistence failure - celix_ei_expect_celix_properties_create((void*)celix_bundleArchive_create, 1, nullptr); - EXPECT_EQ(CELIX_ENOMEM, - celix_bundleArchive_create(&fw, TEST_ARCHIVE_ROOT, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive)); - EXPECT_EQ(nullptr, archive); - EXPECT_FALSE(celix_utils_directoryExists(TEST_ARCHIVE_ROOT)); - teardownErrorInjectors(); - EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_destroy(cache)); } diff --git a/libs/framework/gtest/src/CelixBundleCacheErrorInjectionTestSuite.cc b/libs/framework/gtest/src/CelixBundleCacheErrorInjectionTestSuite.cc index 44a9c1d18..591f11cbc 100644 --- a/libs/framework/gtest/src/CelixBundleCacheErrorInjectionTestSuite.cc +++ b/libs/framework/gtest/src/CelixBundleCacheErrorInjectionTestSuite.cc @@ -32,8 +32,7 @@ #include "celix_properties_ei.h" #include "asprintf_ei.h" -#include "bundle_archive_private.h" -#include "bundle_revision_private.h" +#include "celix_bundle_archive.h" #include "framework_private.h" #include "malloc_ei.h" #include "celix_bundle_manifest.h" @@ -106,7 +105,7 @@ TEST_F(CelixBundleCacheErrorInjectionTestSuite, ArchiveCreateErrorTest) { celix_bundle_cache_t* cache = nullptr; createCache(&cache); - bundle_archive_t* archive = nullptr; + celix_bundle_archive_t* archive = nullptr; celix_ei_expect_celix_utils_writeOrCreateString((void*)celix_bundleCache_createArchive, 0, nullptr); EXPECT_EQ(CELIX_ENOMEM, celix_bundleCache_createArchive(cache, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive)); EXPECT_EQ(nullptr, archive); @@ -131,7 +130,7 @@ TEST_F(CelixBundleCacheErrorInjectionTestSuite, SystemArchiveCreateErrorTest) { celix_bundle_cache_t* cache = nullptr; createCache(&cache); - bundle_archive_t* archive = nullptr; + celix_bundle_archive_t* archive = nullptr; celix_ei_expect_calloc((void*)celix_bundleArchive_create, 0, nullptr); EXPECT_EQ(CELIX_ENOMEM, celix_bundleCache_createSystemArchive(&fw, &archive)); EXPECT_EQ(nullptr, archive); @@ -148,10 +147,6 @@ TEST_F(CelixBundleCacheErrorInjectionTestSuite, SystemArchiveCreateErrorTest) { EXPECT_EQ(CELIX_ENOMEM, celix_bundleCache_createSystemArchive(&fw, &archive)); EXPECT_EQ(nullptr, archive); - celix_ei_expect_calloc((void*)celix_bundleRevision_create, 0, nullptr); - EXPECT_EQ(CELIX_ENOMEM, celix_bundleCache_createSystemArchive(&fw, &archive)); - EXPECT_EQ(nullptr, archive); - EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_destroy(cache)); } diff --git a/libs/framework/gtest/src/CelixBundleCacheTestSuite.cc b/libs/framework/gtest/src/CelixBundleCacheTestSuite.cc index a9393adfd..a76739388 100644 --- a/libs/framework/gtest/src/CelixBundleCacheTestSuite.cc +++ b/libs/framework/gtest/src/CelixBundleCacheTestSuite.cc @@ -17,7 +17,7 @@ under the License. */ -#include "bundle_archive_private.h" +#include "celix_bundle_archive.h" #include "celix_bundle_cache.h" #include "celix_constants.h" #include "celix_file_utils.h" @@ -48,12 +48,11 @@ public: }; TEST_F(CelixBundleCacheTestSuite, ArchiveCreateDestroyTest) { - bundle_archive_t* archive = nullptr; + celix_bundle_archive_t* archive = nullptr; EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_createArchive(fw.cache, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive)); EXPECT_NE(nullptr, archive); auto location = celix_bundleArchive_getLocation(archive); EXPECT_STREQ(SIMPLE_TEST_BUNDLE1_LOCATION, location); - free(location); long bndId; auto status = celix_bundleCache_findBundleIdForLocation(fw.cache, SIMPLE_TEST_BUNDLE1_LOCATION, &bndId); EXPECT_EQ(CELIX_SUCCESS, status); @@ -71,7 +70,7 @@ TEST_F(CelixBundleCacheTestSuite, ArchiveCreateDestroyTest) { } TEST_F(CelixBundleCacheTestSuite, NonPermanentDestroyTest) { - bundle_archive_t* archive = nullptr; + celix_bundle_archive_t* archive = nullptr; EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_createArchive(fw.cache, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive)); EXPECT_NE(nullptr, archive); std::string loc = celix_bundleArchive_getPersistentStoreRoot(archive); @@ -86,13 +85,11 @@ TEST_F(CelixBundleCacheTestSuite, NonPermanentDestroyTest) { } TEST_F(CelixBundleCacheTestSuite, SystemArchiveCreateDestroyTest) { - bundle_archive_t* archive = nullptr; - const char* archiveRoot = nullptr; + celix_bundle_archive_t* archive = nullptr; EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_createSystemArchive(&fw, &archive)); EXPECT_NE(nullptr, archive); EXPECT_EQ(0, celix_bundleArchive_getId(archive)); - EXPECT_EQ(CELIX_SUCCESS, bundleArchive_getArchiveRoot(archive, &archiveRoot)); - EXPECT_EQ(nullptr, archiveRoot); + EXPECT_EQ(nullptr, celix_bundleArchive_getArchiveRoot(archive)); EXPECT_EQ(nullptr, celix_bundleArchive_getLocation(archive)); celix_bundleArchive_invalidate(archive); celix_bundleCache_destroyArchive(fw.cache, archive); diff --git a/libs/framework/include/celix_types.h b/libs/framework/include/celix_types.h index 5ee3c32ee..1505ec88b 100644 --- a/libs/framework/include/celix_types.h +++ b/libs/framework/include/celix_types.h @@ -41,6 +41,7 @@ extern "C" { typedef struct celix_framework celix_framework_t; typedef struct celix_bundle celix_bundle_t; +typedef struct celix_bundle_archive celix_bundle_archive_t; typedef struct celix_dependency_manager celix_dependency_manager_t; typedef struct celix_dm_component_struct celix_dm_component_t; typedef struct celix_dm_service_dependency celix_dm_service_dependency_t; @@ -63,8 +64,6 @@ typedef const struct celix_bundle * const_bundle_pt CELIX_DEPRECATED_ATTR; 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 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 054b9bd56..96ab4270b 100644 --- a/libs/framework/src/bundle.c +++ b/libs/framework/src/bundle.c @@ -17,8 +17,6 @@ * under the License. */ -#include "bundle_revision_private.h" - #include "celix_bundle_manifest.h" #include "celix_bundle_private.h" #include "celix_module.h" @@ -27,20 +25,20 @@ #include "framework_private.h" #include "utils.h" #include "celix_file_utils.h" -#include "bundle_archive_private.h" #include "bundle_context_private.h" #include "service_tracker_private.h" #include <stdlib.h> #include <string.h> #include <assert.h> +#include <celix_constants.h> #include <unistd.h> 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); 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) { +celix_status_t celix_bundle_createFromArchive(celix_framework_t *framework, celix_bundle_archive_t* archive, celix_bundle_t **bundleOut) { celix_status_t status = CELIX_SUCCESS; celix_bundle_t* bundle = calloc(1, sizeof(*bundle)); @@ -92,7 +90,7 @@ celix_status_t bundle_destroy(bundle_pt bundle) { return CELIX_SUCCESS; } -celix_status_t bundle_getArchive(const_bundle_pt bundle, bundle_archive_pt *archive) { +celix_status_t bundle_getArchive(const_bundle_pt bundle, celix_bundle_archive_t** archive) { celix_status_t status = CELIX_SUCCESS; if (bundle != NULL && *archive == NULL) { *archive = bundle->archive; @@ -201,22 +199,16 @@ celix_status_t bundle_addModule(bundle_pt bundle, celix_module_t* module) { return CELIX_SUCCESS; } -celix_status_t bundle_isSystemBundle(const_bundle_pt bundle, bool *systemBundle) { - celix_status_t status; - long bundleId; - bundle_archive_pt archive = NULL; - - status = bundle_getArchive(bundle, &archive); - if (status == CELIX_SUCCESS) { - status = bundleArchive_getId(archive, &bundleId); - if (status == CELIX_SUCCESS) { - *systemBundle = (bundleId == 0); - } - } - - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to check if bundle is the systembundle"); - - return status; +celix_status_t bundle_isSystemBundle(const_bundle_pt bundle, bool* systemBundle) { + celix_bundle_archive_t* archive = celix_bundle_getArchive(bundle); + if (archive) { + long bundleId = celix_bundleArchive_getId(archive); + *systemBundle = (bundleId == CELIX_FRAMEWORK_BUNDLE_ID); + } else { + fw_log(bundle->framework->logger, CELIX_LOG_LEVEL_ERROR, "Failed to check if bundle is the systembundle"); + return CELIX_BUNDLE_EXCEPTION; + } + return CELIX_SUCCESS; } celix_status_t bundle_getBundleId(const bundle_t *bundle, long *bndId) { @@ -239,31 +231,6 @@ celix_status_t bundle_getFramework(const_bundle_pt bundle, framework_pt *framewo return CELIX_SUCCESS; } -celix_status_t bundle_getBundleLocation(const_bundle_pt bundle, const char **location){ - - celix_status_t status; - - bundle_archive_pt archive = NULL; - - status = bundle_getArchive(bundle, &archive); - if (status != CELIX_SUCCESS){ - printf("[ ERROR ]: Bundle - getBundleLocation (BundleArchive) \n"); - return status; - } - - status = bundleArchive_getLocation(archive, location); - if (status != CELIX_SUCCESS){ - printf("[ ERROR ]: Bundle - getBundleLocation (BundleArchiveLocation) \n"); - return status; - } - - return CELIX_SUCCESS; -} - - - - - /********************************************************************************************************************** ********************************************************************************************************************** @@ -272,17 +239,17 @@ celix_status_t bundle_getBundleLocation(const_bundle_pt bundle, const char **loc **********************************************************************************************************************/ long celix_bundle_getId(const bundle_t* bnd) { - long bndId = -1; - bundle_archive_pt archive = NULL; - bundle_getArchive((bundle_t*)bnd, &archive); - if (archive != NULL) { - bundleArchive_getId(archive, &bndId); - } - - if (bndId < 0) { - framework_logIfError(celix_frameworkLogger_globalLogger(), CELIX_BUNDLE_EXCEPTION, NULL, "Failed to get bundle id"); - } - return bndId; + long bndId = -1; + celix_bundle_archive_t* archive = celix_bundle_getArchive(bnd); + if (archive) { + bndId = celix_bundleArchive_getId(archive); + } else { + framework_logIfError(celix_frameworkLogger_globalLogger(), + CELIX_BUNDLE_EXCEPTION, + NULL, + "Failed to get bundle id"); + } + return bndId; } celix_bundle_state_e celix_bundle_getState(const celix_bundle_t *bnd) { @@ -290,7 +257,7 @@ celix_bundle_state_e celix_bundle_getState(const celix_bundle_t *bnd) { } static char* celix_bundle_getBundleOrPersistentStoreEntry(const celix_bundle_t* bnd, bool bundleEntry, const char* name) { - bundle_archive_pt archive = NULL; + celix_bundle_archive_t* archive = NULL; celix_status_t status = bundle_getArchive(bnd, &archive); if (status != CELIX_SUCCESS) { fw_logCode(bnd->framework->logger, CELIX_BUNDLE_EXCEPTION, status, "Failed to get bundle archive"); @@ -373,7 +340,11 @@ const char* celix_bundle_getDescription(const celix_bundle_t* bnd) { char* celix_bundle_getLocation(const celix_bundle_t *bnd) { char* result = NULL; if (bnd->archive != NULL) { - result = celix_bundleArchive_getLocation(bnd->archive); + const char* loc = celix_bundleArchive_getLocation(bnd->archive); + result = celix_utils_strdup(loc); + if (!result) { + fw_log(bnd->framework->logger, CELIX_BUNDLE_EXCEPTION, "Failed to allocate memory for bundle location"); + } } return result; } @@ -454,8 +425,8 @@ celix_array_list_t* celix_bundle_listServiceTrackers(const celix_bundle_t *bnd) return result; } -bundle_archive_t* celix_bundle_getArchive(const celix_bundle_t *bundle) { - bundle_archive_t* archive = NULL; - bundle_getArchive(bundle, &archive); +celix_bundle_archive_t* celix_bundle_getArchive(const celix_bundle_t *bundle) { + celix_bundle_archive_t* archive = NULL; + (void)bundle_getArchive(bundle, &archive); return archive; } diff --git a/libs/framework/src/bundle_archive.h b/libs/framework/src/bundle_archive.h deleted file mode 100644 index e11f0a75c..000000000 --- a/libs/framework/src/bundle_archive.h +++ /dev/null @@ -1,116 +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. - */ -/** - * bundle_archive.h - * - * \date Aug 8, 2010 - * \author <a href="mailto:d...@celix.apache.org">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#ifndef BUNDLE_ARCHIVE_H_ -#define BUNDLE_ARCHIVE_H_ - -#include "celix_types.h" - -#include <time.h> -#include <stdbool.h> -#include <stdlib.h> - -#include "bundle_revision_private.h" -#include "celix_bundle_state.h" -#include "celix_errno.h" -#include "celix_log.h" - -#include "bundle_context.h" -#include "celix_bundle_context.h" -#include "celix_framework_export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getId(bundle_archive_pt archive, long *id); - -/** - * Return the current location of the bundle. - * @warning Not safe, because location can change during bundle revise. - * @return - */ -CELIX_FRAMEWORK_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); - -CELIX_FRAMEWORK_DEPRECATED celix_status_t -bundleArchive_revise(bundle_archive_pt archive, const char *location, const char *inputFile); - -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, celix_bundle_revision_t** revision); - -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); - -CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_getRefreshCount(bundle_archive_pt archive, long *refreshCount); - -CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_setRefreshCount(bundle_archive_pt archive); - -CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_close(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); - -CELIX_FRAMEWORK_DEPRECATED celix_status_t bundleArchive_setPersistentState(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. - * - * The last modified time is based on the last modified time of the bundle archive cache directory. - * - * If the bundle archive cache directory does not exist, lastModified will be set to 0. - * - * @param[in] archive The bundle archive. - * @param[out] lastModified The last modified time of the bundle archive. - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_FILE_IO_EXCEPTION if the last modified time could not be retrieved. - * 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 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 char* celix_bundleArchive_getLocation(bundle_archive_pt archive); - - -#ifdef __cplusplus -} -#endif - -#endif /* BUNDLE_ARCHIVE_H_ */ diff --git a/libs/framework/src/bundle_archive_private.h b/libs/framework/src/bundle_archive_private.h deleted file mode 100644 index 0ebef174e..000000000 --- a/libs/framework/src/bundle_archive_private.h +++ /dev/null @@ -1,105 +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_ARCHIVE_PRIVATE_H_ -#define BUNDLE_ARCHIVE_PRIVATE_H_ - -#include <time.h> - -#include "bundle_archive.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define CELIX_BUNDLE_ARCHIVE_STATE_PROPERTIES_FILE_NAME "bundle_state.properties" - -#define CELIX_BUNDLE_ARCHIVE_SYMBOLIC_NAME_PROPERTY_NAME "bundle.symbolic_name" -#define CELIX_BUNDLE_ARCHIVE_VERSION_PROPERTY_NAME "bundle.version" -#define CELIX_BUNDLE_ARCHIVE_BUNDLE_ID_PROPERTY_NAME "bundle.id" -#define CELIX_BUNDLE_ARCHIVE_LOCATION_PROPERTY_NAME "bundle.location" - -#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.json" - -/** - * @brief Create bundle archive. - * Create a bundle archive for the given root, id, location and revision nr. - * Also create the bundle cache dir and if will reuse a existing bundle resource cache dir if the provided - * bundle zip location is older then the existing bundle resource cache dir. - */ -celix_status_t celix_bundleArchive_create(celix_framework_t* fw, const char *archiveRoot, long id, const char *location, bundle_archive_pt *bundle_archive); - -void celix_bundleArchive_destroy(bundle_archive_pt archive); - -/** - * @brief Returns the bundle id of the bundle archive. - * @param archive The bundle archive. - * @return The bundle id. - */ -long celix_bundleArchive_getId(bundle_archive_pt archive); - -/** - * @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_t* archive); - -/** - * Returns the root of the bundle persistent store. - */ -const char* celix_bundleArchive_getPersistentStoreRoot(bundle_archive_t *archive); - - /** - * Returns the root of the current revision. - */ -const char* celix_bundleArchive_getCurrentRevisionRoot(bundle_archive_pt archive); - -/** - * @brief Invalidate the whole bundle archive. - */ -void celix_bundleArchive_invalidate(bundle_archive_pt archive); - -/** - * @brief Invalidate the bundle archive's bundle cache. - */ -void celix_bundleArchive_invalidateCache(bundle_archive_pt archive); - -/** - * @brief Return if the bundle cache is valid. - */ -bool celix_bundleArchive_isCacheValid(bundle_archive_pt archive); - -/** - * @brief Remove all valid directories of the bundle archive. - */ -void celix_bundleArchive_removeInvalidDirs(bundle_archive_pt archive); - -#ifdef __cplusplus -} -#endif - -#endif /* BUNDLE_ARCHIVE_PRIVATE_H_ */ diff --git a/libs/framework/src/bundle_revision.c b/libs/framework/src/bundle_revision.c deleted file mode 100644 index a0e7c78f2..000000000 --- a/libs/framework/src/bundle_revision.c +++ /dev/null @@ -1,76 +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 <stdlib.h> - -#include "celix_compiler.h" -#include "celix_utils.h" -#include "bundle_revision_private.h" -#include "framework_private.h" - -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; - celix_bundle_revision_t* revision = calloc(1, sizeof(*revision)); - if (revision != NULL) { - revision->fw = fw; - if (root != NULL) { - revision->root = celix_utils_strdup(root); - } - if (location != NULL) { - revision->location = celix_utils_strdup(location); - } - revision->manifest = manifest; - } - - if (revision == NULL || (root != NULL && revision->root == NULL) || (location != NULL && revision->location == NULL)) { - status = CELIX_ENOMEM; - fw_logCode(fw->logger, CELIX_LOG_LEVEL_ERROR, status, "Cannot create bundle revision, out of memory"); - if (revision != NULL) { - celix_bundleRevision_destroy(revision); - } else { - celix_bundleManifest_destroy(manifest); - } - return status; - } - - *bundle_revision = revision; - return status; -} - -celix_status_t celix_bundleRevision_destroy(celix_bundle_revision_t* revision) { - if (revision != NULL) { - celix_bundleManifest_destroy(revision->manifest); - free(revision->root); - free(revision->location); - free(revision); - } - return CELIX_SUCCESS; -} - -celix_bundle_manifest_t* celix_bundleRevision_getManifest(celix_bundle_revision_t* revision) { - return revision->manifest; -} diff --git a/libs/framework/src/bundle_revision_private.h b/libs/framework/src/bundle_revision_private.h deleted file mode 100644 index d09836993..000000000 --- a/libs/framework/src/bundle_revision_private.h +++ /dev/null @@ -1,76 +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. - */ -/** - * bundle_revision_private.h - * - * \date Feb 12, 2013 - * \author <a href="mailto:d...@celix.apache.org">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#ifndef BUNDLE_REVISION_PRIVATE_H_ -#define BUNDLE_REVISION_PRIVATE_H_ - -#include "celix_threads.h" -#include "celix_framework.h" -#include "celix_bundle_manifest.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * The bundle revision structure represents a revision of a bundle. - * A bundle can have multiple revisions. A bundle revision is immutable. - */ -typedef struct celix_bundle_revision celix_bundle_revision_t; - -/** - * Creates a new revision for the given inputFile or location. - * The location parameter is used to identify the bundle. - * - * @param fw The Celix framework where to create the bundle revision. - * @param root The root for this revision in which the bundle is extracted and state is stored. - * @param location The location associated with the revision. - * @param manifest The manifest for the revision. - * @param[out] bundle_revision The output parameter for the created revision. - * - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_ENOMEM If allocating memory for <code>bundle_revision</code> failed. - */ -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 celix_bundleRevision_destroy(celix_bundle_revision_t* revision); - - -/** - * @brief Get the bundle manifest of the given revision. - */ -celix_bundle_manifest_t* celix_bundleRevision_getManifest(celix_bundle_revision_t* revision); - -#ifdef __cplusplus -} -#endif - -#endif /* BUNDLE_REVISION_PRIVATE_H_ */ diff --git a/libs/framework/src/bundle_archive.c b/libs/framework/src/celix_bundle_archive.c similarity index 63% rename from libs/framework/src/bundle_archive.c rename to libs/framework/src/celix_bundle_archive.c index bc140dd69..b69e44496 100644 --- a/libs/framework/src/bundle_archive.c +++ b/libs/framework/src/celix_bundle_archive.c @@ -17,13 +17,14 @@ * under the License. */ +#include "celix_bundle_archive.h" + #include <assert.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> -#include <time.h> #include <unistd.h> #include "celix_bundle_manifest.h" @@ -32,13 +33,10 @@ #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" +#include "celix_utils.h" +#include "celix_properties.h" /** * The bundle archive which is used to store the bundle data and can be reused when a framework is restarted. @@ -46,7 +44,7 @@ * * @note The bundle archive is thread safe. */ -struct bundleArchive { +struct celix_bundle_archive { // initialed during creation and immutable celix_framework_t* fw; long id; @@ -54,13 +52,13 @@ struct bundleArchive { char* savedBundleStatePropertiesPath; char* storeRoot; char* resourceCacheRoot; - celix_bundle_revision_t* revision; // the current revision char* location; + celix_bundle_manifest_t* manifest; bool cacheValid; // is the cache valid (e.g. not deleted) bool valid; // is the archive valid (e.g. not deleted) }; -static celix_status_t celix_bundleArchive_storeBundleStateProperties(bundle_archive_pt archive) { +static celix_status_t celix_bundleArchive_storeBundleStateProperties(celix_bundle_archive_t* archive) { bool needUpdate = false; celix_autoptr(celix_properties_t) bundleStateProperties = NULL; if (celix_utils_fileExists(archive->savedBundleStatePropertiesPath)) { @@ -74,8 +72,7 @@ static celix_status_t celix_bundleArchive_storeBundleStateProperties(bundle_arch bundleStateProperties = celix_properties_create(); } - celix_bundle_manifest_t* man = celix_bundleArchive_getManifest(archive); - const char* bndVersion = celix_properties_getAsString(celix_bundleManifest_getAttributes(man), + const char* bndVersion = celix_properties_getAsString(celix_bundleManifest_getAttributes(archive->manifest), CELIX_BUNDLE_VERSION, ""); if (!bundleStateProperties) { @@ -94,11 +91,11 @@ static celix_status_t celix_bundleArchive_storeBundleStateProperties(bundle_arch needUpdate = true; } if (strcmp(celix_properties_get(bundleStateProperties, CELIX_BUNDLE_ARCHIVE_SYMBOLIC_NAME_PROPERTY_NAME, ""), - celix_bundleManifest_getBundleSymbolicName(man)) != 0) { + celix_bundleManifest_getBundleSymbolicName(archive->manifest)) != 0) { celix_properties_set( bundleStateProperties, CELIX_BUNDLE_ARCHIVE_SYMBOLIC_NAME_PROPERTY_NAME, - celix_bundleManifest_getBundleSymbolicName(man)); + celix_bundleManifest_getBundleSymbolicName(archive->manifest)); needUpdate = true; } if (strcmp(celix_properties_get(bundleStateProperties, CELIX_BUNDLE_ARCHIVE_VERSION_PROPERTY_NAME, ""), @@ -120,7 +117,7 @@ static celix_status_t celix_bundleArchive_storeBundleStateProperties(bundle_arch return CELIX_SUCCESS; } -static celix_status_t celix_bundleArchive_removeResourceCache(bundle_archive_t* archive) { +static celix_status_t celix_bundleArchive_removeResourceCache(celix_bundle_archive_t* archive) { celix_status_t status = CELIX_SUCCESS; const char* error = NULL; struct stat st; @@ -150,7 +147,7 @@ static celix_status_t celix_bundleArchive_removeResourceCache(bundle_archive_t* } static celix_status_t -celix_bundleArchive_extractBundle(bundle_archive_t* archive, const char* bundleUrl) { +celix_bundleArchive_extractBundle(celix_bundle_archive_t* archive, const char* bundleUrl) { celix_status_t status = CELIX_SUCCESS; bool extractBundle = true; @@ -194,7 +191,7 @@ 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, celix_bundle_manifest_t** manifestOut) { +static celix_status_t celix_bundleArchive_createCacheDirectory(celix_bundle_archive_t* 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.", @@ -243,15 +240,14 @@ static celix_status_t celix_bundleArchive_createCacheDirectory(bundle_archive_pt return status; } -celix_status_t celix_bundleArchive_create(celix_framework_t* fw, const char *archiveRoot, long id, const char *location, bundle_archive_pt *bundle_archive) { +celix_status_t celix_bundleArchive_create(celix_framework_t* fw, const char *archiveRoot, long id, const char *location, celix_bundle_archive_t** bundle_archive) { celix_status_t status = CELIX_SUCCESS; - const char* error = NULL; - bundle_archive_pt archive = calloc(1, sizeof(*archive)); + celix_autoptr(celix_bundle_archive_t) archive = calloc(1, sizeof(*archive)); bool isFrameworkBundle = id == CELIX_FRAMEWORK_BUNDLE_ID; - if (archive == NULL) { - status = CELIX_ENOMEM; - goto calloc_failed; + if (!archive) { + fw_log(fw->logger, CELIX_LOG_LEVEL_ERROR, "Could not allocate memory for the bundle archive."); + return ENOMEM; } archive->fw = fw; @@ -288,206 +284,94 @@ celix_status_t celix_bundleArchive_create(celix_framework_t* fw, const char *arc } while (0); } if (status != CELIX_SUCCESS) { - error = "Failed to setup archive paths."; - goto init_failed; + fw_log(fw->logger, CELIX_LOG_LEVEL_ERROR, "Failed to create bundle archive; Out of memory."); + return status; } - celix_bundle_manifest_t* manifest = NULL; if (isFrameworkBundle) { - status = celix_bundleManifest_createFrameworkManifest(&manifest); + status = celix_bundleManifest_createFrameworkManifest(&archive->manifest); } else { - status = celix_bundleArchive_createCacheDirectory(archive, &manifest); + status = celix_bundleArchive_createCacheDirectory(archive, &archive->manifest); } if (status != CELIX_SUCCESS) { - error = "Failed to initialize archive or create manifest."; - goto dir_failed; - } - - status = celix_bundleRevision_create(fw, archive->archiveRoot, archive->location, manifest, &archive->revision); - if (status != CELIX_SUCCESS) { - error = "Could not create bundle revision."; - goto revision_failed; + fw_logCode(fw->logger, CELIX_LOG_LEVEL_ERROR, status, "Failed to create bundle archive."); + if (!isFrameworkBundle) { + celix_utils_deleteDirectory(archive->archiveRoot, NULL); + } + return status; } if (!isFrameworkBundle) { status = celix_bundleArchive_storeBundleStateProperties(archive); if (status != CELIX_SUCCESS) { - error = "Could not store properties."; - goto store_prop_failed; + fw_logCode(fw->logger, CELIX_LOG_LEVEL_ERROR, status, "Failed to store bundle state properties."); + return status; } } archive->cacheValid = true; archive->valid = true; - *bundle_archive = archive; + *bundle_archive = celix_steal_ptr(archive); return CELIX_SUCCESS; -store_prop_failed: -revision_failed: -dir_failed: - if (!isFrameworkBundle) { - celix_utils_deleteDirectory(archive->archiveRoot, NULL); - } -init_failed: - celix_bundleArchive_destroy(archive); -calloc_failed: - celix_framework_logTssErrors(fw->logger, CELIX_LOG_LEVEL_ERROR); - framework_logIfError(fw->logger, status, error, "Could not create archive."); - return status; } -void celix_bundleArchive_destroy(bundle_archive_pt archive) { +void celix_bundleArchive_destroy(celix_bundle_archive_t* archive) { if (archive != NULL) { free(archive->location); free(archive->savedBundleStatePropertiesPath); free(archive->archiveRoot); free(archive->resourceCacheRoot); free(archive->storeRoot); - celix_bundleRevision_destroy(archive->revision); + celix_bundleManifest_destroy(archive->manifest); free(archive); } } -celix_status_t bundleArchive_getId(bundle_archive_pt archive, long* id) { - *id = archive->id; - return CELIX_SUCCESS; -} - -long celix_bundleArchive_getId(bundle_archive_pt archive) { +long celix_bundleArchive_getId(const celix_bundle_archive_t* archive) { return archive->id; } -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; +celix_bundle_manifest_t* celix_bundleArchive_getManifest(const celix_bundle_archive_t* archive) { + return archive->manifest; } -const char* celix_bundleArchive_getSymbolicName(bundle_archive_t* archive) { +const char* celix_bundleArchive_getSymbolicName(const celix_bundle_archive_t* archive) { return celix_bundleManifest_getBundleSymbolicName(celix_bundleArchive_getManifest(archive)); } -celix_status_t bundleArchive_getLocation(bundle_archive_pt archive, const char **location) { - *location = archive->location; - return CELIX_SUCCESS; -} - -char* celix_bundleArchive_getLocation(bundle_archive_pt archive) { - char* result = NULL; - if (archive->location) { - result = celix_utils_strdup(archive->location); - } - return result; -} - -celix_status_t bundleArchive_getArchiveRoot(bundle_archive_pt archive, const char** archiveRoot) { - *archiveRoot = archive->archiveRoot; - return CELIX_SUCCESS; -} - -//LCOV_EXCL_START -celix_status_t bundleArchive_getCurrentRevisionNumber(bundle_archive_pt archive, long* revisionNumber) { - *revisionNumber = 1; // NOTE bundle revision is deprecated - return CELIX_SUCCESS; -} -//LCOV_EXCL_STOP - -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, celix_bundle_revision_t** revision) { - return bundleArchive_getCurrentRevision(archive, revision); -} - -celix_status_t bundleArchive_getPersistentState(bundle_archive_pt archive CELIX_UNUSED, bundle_state_e *state) { - fw_log(archive->fw->logger, CELIX_LOG_LEVEL_DEBUG, "Bundle archive persistent state no longer supported"); - *state = CELIX_BUNDLE_STATE_UNKNOWN; - return CELIX_SUCCESS; +const char* celix_bundleArchive_getLocation(const celix_bundle_archive_t* archive) { + return archive->location; } -celix_status_t bundleArchive_setPersistentState(bundle_archive_pt archive CELIX_UNUSED, bundle_state_e state CELIX_UNUSED) { - fw_log(archive->fw->logger, CELIX_LOG_LEVEL_DEBUG, "Bundle archive persistent state no longer supported"); - return CELIX_SUCCESS; +const char* celix_bundleArchive_getArchiveRoot(const celix_bundle_archive_t* archive) { + return archive->archiveRoot; } -celix_status_t bundleArchive_getRefreshCount(bundle_archive_pt archive CELIX_UNUSED, long *refreshCount) { - fw_log(archive->fw->logger, CELIX_LOG_LEVEL_DEBUG, "Bundle archive refresh count is no longer supported"); - *refreshCount = 0; - return CELIX_SUCCESS; -} - -celix_status_t bundleArchive_setRefreshCount(bundle_archive_pt archive CELIX_UNUSED) { - fw_log(archive->fw->logger, CELIX_LOG_LEVEL_DEBUG, "Bundle archive refresh count is no longer supported"); - return CELIX_SUCCESS; -} - -celix_status_t bundleArchive_getLastModified(bundle_archive_pt archive, time_t* lastModified) { - struct timespec mod; - celix_status_t status = celix_bundleArchive_getLastModified(archive, &mod); - if (status == CELIX_SUCCESS) { - *lastModified = mod.tv_sec; - } - return status; +celix_status_t celix_bundleArchive_getLastModified(const celix_bundle_archive_t* archive, struct timespec* lastModified) { + return celix_utils_getLastModified(archive->resourceCacheRoot, lastModified); } -//LCOV_EXCL_STOP -celix_status_t celix_bundleArchive_getLastModified(bundle_archive_pt archive, struct timespec* lastModified) { - celix_status_t status; - status = celix_utils_getLastModified(archive->resourceCacheRoot, lastModified); - return status; -} - -//LCOV_EXCL_START -celix_status_t bundleArchive_setLastModified(bundle_archive_pt archive CELIX_UNUSED, time_t lastModifiedTime CELIX_UNUSED) { - celix_status_t status = CELIX_SUCCESS; - char manifestPathBuffer[CELIX_DEFAULT_STRING_CREATE_BUFFER_SIZE]; - char* manifestPath = celix_utils_writeOrCreateString(manifestPathBuffer, sizeof(manifestPathBuffer), "%s/%s", archive->resourceCacheRoot, CELIX_BUNDLE_MANIFEST_REL_PATH); - status = celix_utils_touch(manifestPath); - celix_utils_freeStringIfNotEqual(manifestPathBuffer, manifestPath); - return status; -} - -celix_status_t bundleArchive_revise(bundle_archive_pt archive, const char * location CELIX_UNUSED, const char *updatedBundleUrl) { - fw_log(archive->fw->logger, CELIX_LOG_LEVEL_ERROR, "Revise not supported."); - return CELIX_BUNDLE_EXCEPTION; -} -celix_status_t bundleArchive_rollbackRevise(bundle_archive_pt archive, bool* rolledback) { - *rolledback = true; - fw_log(archive->fw->logger, CELIX_LOG_LEVEL_ERROR, "Revise rollback not supported."); - return CELIX_BUNDLE_EXCEPTION; -} - -celix_status_t bundleArchive_close(bundle_archive_pt archive) { - // close revision - // not yet needed/possible - return CELIX_SUCCESS; -} -//LCOV_EXCL_STOP - -const char* celix_bundleArchive_getPersistentStoreRoot(bundle_archive_t* archive) { +const char* celix_bundleArchive_getPersistentStoreRoot(const celix_bundle_archive_t* archive) { return archive->storeRoot; } -const char* celix_bundleArchive_getCurrentRevisionRoot(bundle_archive_t* archive) { +const char* celix_bundleArchive_getCurrentRevisionRoot(const celix_bundle_archive_t* archive) { return archive->resourceCacheRoot; } - -void celix_bundleArchive_invalidate(bundle_archive_pt archive) { +void celix_bundleArchive_invalidate(celix_bundle_archive_t* archive) { archive->valid = false; archive->cacheValid = false; } -void celix_bundleArchive_invalidateCache(bundle_archive_pt archive) { +void celix_bundleArchive_invalidateCache(celix_bundle_archive_t* archive) { archive->cacheValid = false; } -bool celix_bundleArchive_isCacheValid(bundle_archive_pt archive) { +bool celix_bundleArchive_isCacheValid(const celix_bundle_archive_t* archive) { return archive->cacheValid; } -void celix_bundleArchive_removeInvalidDirs(bundle_archive_pt archive) { +void celix_bundleArchive_removeInvalidDirs(celix_bundle_archive_t* archive) { if (archive->id == CELIX_FRAMEWORK_BUNDLE_ID) { return; } diff --git a/libs/framework/src/celix_bundle_archive.h b/libs/framework/src/celix_bundle_archive.h new file mode 100644 index 000000000..d226c72e5 --- /dev/null +++ b/libs/framework/src/celix_bundle_archive.h @@ -0,0 +1,153 @@ +/* + * 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. + */ +/** + * celix_bundle_archive.h + * + * \date Aug 8, 2010 + * \author <a href="mailto:d...@celix.apache.org">Apache Celix Project Team</a> + * \copyright Apache License, Version 2.0 + */ + +#ifndef BUNDLE_ARCHIVE_H_ +#define BUNDLE_ARCHIVE_H_ + +#include "celix_types.h" +#include <stdbool.h> +#include <stdlib.h> + +#include "celix_bundle_state.h" +#include "celix_errno.h" +#include "celix_framework_export.h" +#include "celix_bundle_manifest_type.h" +#include "celix_cleanup.h" + +#define CELIX_BUNDLE_ARCHIVE_STATE_PROPERTIES_FILE_NAME "bundle_state.properties" + +#define CELIX_BUNDLE_ARCHIVE_SYMBOLIC_NAME_PROPERTY_NAME "bundle.symbolic_name" +#define CELIX_BUNDLE_ARCHIVE_VERSION_PROPERTY_NAME "bundle.version" +#define CELIX_BUNDLE_ARCHIVE_BUNDLE_ID_PROPERTY_NAME "bundle.id" +#define CELIX_BUNDLE_ARCHIVE_LOCATION_PROPERTY_NAME "bundle.location" + +#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.json" + +#ifdef __cplusplus +extern "C" { +#endif + + /** + * @brief Create bundle archive. + * Create a bundle archive for the given root, id, location and revision nr. + * Also create the bundle cache dir and if will reuse a existing bundle resource cache dir if the provided + * bundle zip location is older then the existing bundle resource cache dir. + */ +celix_status_t celix_bundleArchive_create(celix_framework_t* fw, const char *archiveRoot, long id, const char *location, celix_bundle_archive_t** bundle_archive); + +void celix_bundleArchive_destroy(celix_bundle_archive_t* archive); + + /** + * Define the cleanup function for a bundle_archive_t, so that it can be used with celix_autoptr. + */ + CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC(celix_bundle_archive_t, celix_bundleArchive_destroy); + +/** + * @brief Returns the bundle id of the bundle archive. + * @param archive The bundle archive. + * @return The bundle id. + */ +long celix_bundleArchive_getId(const celix_bundle_archive_t* archive); + +/** + * @brief Return the manifest for the bundle archive. All bundle archives have a manifest. + */ +celix_bundle_manifest_t* celix_bundleArchive_getManifest(const celix_bundle_archive_t* archive); + +/** + * @brief Return the bundle symbolic name (from the manifest) + */ +const char* celix_bundleArchive_getSymbolicName(const celix_bundle_archive_t* archive); + +/** + * Returns the root of the bundle persistent store. + */ +const char* celix_bundleArchive_getPersistentStoreRoot(const celix_bundle_archive_t *archive); + + /** + * Returns the root of the current revision. + */ +const char* celix_bundleArchive_getCurrentRevisionRoot(const celix_bundle_archive_t* archive); + +/** + * @brief Invalidate the whole bundle archive. + */ +void celix_bundleArchive_invalidate(celix_bundle_archive_t* archive); + +/** + * @brief Invalidate the bundle archive's bundle cache. + */ +void celix_bundleArchive_invalidateCache(celix_bundle_archive_t* archive); + +/** + * @brief Return if the bundle cache is valid. + */ +bool celix_bundleArchive_isCacheValid(const celix_bundle_archive_t* archive); + +/** + * @brief Remove all valid directories of the bundle archive. + */ +void celix_bundleArchive_removeInvalidDirs(celix_bundle_archive_t* archive); + + /** + * @brief Return the location of the bundle archive.b + * @param[in] archive The bundle archive. + * @return The location of the bundle archive. The location is valid as long as the archive is valid. + */ +const char* celix_bundleArchive_getLocation(const celix_bundle_archive_t* archive); + +/** + * @brief Return the archive root for this bundle archive. + * @param[in] archive The bundle archive. + * @return The archive root of the bundle archive. The archive root is valid as long as the archive is valid. + */ +const char* celix_bundleArchive_getArchiveRoot(const celix_bundle_archive_t* archive); + +/** + * @brief Return the last modified time of the bundle archive. + * + * The last modified time is based on the last modified time of the bundle archive cache directory. + * + * If the bundle archive cache directory does not exist, lastModified will be set to 0. + * + * @param[in] archive The bundle archive. + * @param[out] lastModified The last modified time of the bundle archive. + * @return Status code indication failure or success: + * - CELIX_SUCCESS when no errors are encountered. + * - CELIX_FILE_IO_EXCEPTION if the last modified time could not be retrieved. + * 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_status_t celix_bundleArchive_getLastModified(const celix_bundle_archive_t* archive, struct timespec* lastModified); + +#ifdef __cplusplus +} +#endif + +#endif /* BUNDLE_ARCHIVE_H_ */ diff --git a/libs/framework/src/celix_bundle_cache.c b/libs/framework/src/celix_bundle_cache.c index d401ac432..b63f16473 100644 --- a/libs/framework/src/celix_bundle_cache.c +++ b/libs/framework/src/celix_bundle_cache.c @@ -33,7 +33,6 @@ #include "celix_utils.h" #include "celix_bundle_context.h" #include "framework_private.h" -#include "bundle_archive_private.h" #include "celix_string_hash_map.h" #include "celix_stdio_cleanup.h" @@ -173,9 +172,9 @@ celix_status_t celix_bundleCache_deleteCacheDir(celix_bundle_cache_t* cache) { } celix_status_t -celix_bundleCache_createArchive(celix_bundle_cache_t* cache, long id, const char* location, bundle_archive_t** archiveOut) { +celix_bundleCache_createArchive(celix_bundle_cache_t* cache, long id, const char* location, celix_bundle_archive_t** archiveOut) { celix_status_t status = CELIX_SUCCESS; - bundle_archive_t* archive = NULL; + celix_bundle_archive_t* archive = NULL; char archiveRootBuffer[CELIX_DEFAULT_STRING_CREATE_BUFFER_SIZE]; char* archiveRoot = celix_utils_writeOrCreateString(archiveRootBuffer, sizeof(archiveRootBuffer), @@ -199,15 +198,14 @@ celix_bundleCache_createArchive(celix_bundle_cache_t* cache, long id, const char return status; } -celix_status_t celix_bundleCache_createSystemArchive(celix_framework_t* fw, bundle_archive_pt* archive) { +celix_status_t celix_bundleCache_createSystemArchive(celix_framework_t* fw, celix_bundle_archive_t** archive) { return celix_bundleCache_createArchive(fw->cache, CELIX_FRAMEWORK_BUNDLE_ID, NULL, archive); } -void celix_bundleCache_destroyArchive(celix_bundle_cache_t* cache, bundle_archive_pt archive) { +void celix_bundleCache_destroyArchive(celix_bundle_cache_t* cache, celix_bundle_archive_t* archive) { celixThreadMutex_lock(&cache->mutex); if (!celix_bundleArchive_isCacheValid(archive)) { - const char* loc = NULL; - (void) bundleArchive_getLocation(archive, &loc); + const char* loc = celix_bundleArchive_getLocation(archive); (void) celix_stringHashMap_remove(cache->locationToBundleIdLookupMap, loc); } (void)celix_bundleArchive_removeInvalidDirs(archive); @@ -298,7 +296,7 @@ celix_bundleCache_createBundleArchivesForSpaceSeparatedList(celix_framework_t* f if (zipFileList) { char* location = strtok_r(zipFileList, delims, &savePtr); while (location != NULL) { - bundle_archive_t* archive = NULL; + celix_bundle_archive_t* archive = NULL; status = celix_bundleCache_createArchive(fw->cache, (*bndId)++, location, &archive); if (status != CELIX_SUCCESS) { fw_logCode(fw->logger, CELIX_LOG_LEVEL_ERROR, status, diff --git a/libs/framework/src/celix_bundle_cache.h b/libs/framework/src/celix_bundle_cache.h index c6b559716..997dcf9a6 100644 --- a/libs/framework/src/celix_bundle_cache.h +++ b/libs/framework/src/celix_bundle_cache.h @@ -26,7 +26,7 @@ #include "celix_framework.h" #include "celix_long_hash_map.h" -#include "bundle_archive.h" +#include "celix_bundle_archive.h" #ifdef __cplusplus extern "C" { @@ -74,7 +74,7 @@ celix_status_t celix_bundleCache_destroy(celix_bundle_cache_t* cache); * - CELIX_ENOMEM If allocating memory for <code>bundle_archive</code> failed. */ celix_status_t -celix_bundleCache_createArchive(celix_bundle_cache_t* cache, long id, const char* location, bundle_archive_pt* archive); +celix_bundleCache_createArchive(celix_bundle_cache_t* cache, long id, const char* location, celix_bundle_archive_t** archive); /** * @@brief Creates a new system archive for framework bundle. @@ -87,7 +87,7 @@ celix_bundleCache_createArchive(celix_bundle_cache_t* cache, long id, const char * - CELIX_FILE_IO_EXCEPTION If the cache cannot be opened or read. * - CELIX_BUNDLE_EXCEPTION If the bundle cannot be created. */ -celix_status_t celix_bundleCache_createSystemArchive(celix_framework_t* fw, bundle_archive_pt* archive); +celix_status_t celix_bundleCache_createSystemArchive(celix_framework_t* fw, celix_bundle_archive_t** archive); /** * @brief Destroy the archive from the cache. @@ -95,7 +95,7 @@ celix_status_t celix_bundleCache_createSystemArchive(celix_framework_t* fw, bund * @param [in] cache The bundle cache to destroy archive from. * @param [in] archive The archive to destroy. */ -void celix_bundleCache_destroyArchive(celix_bundle_cache_t* cache, bundle_archive_pt archive); +void celix_bundleCache_destroyArchive(celix_bundle_cache_t* cache, celix_bundle_archive_t* archive); /** * @brief Deletes the entire bundle cache. diff --git a/libs/framework/src/celix_bundle_private.h b/libs/framework/src/celix_bundle_private.h index 17e6eec68..0026f2f8d 100644 --- a/libs/framework/src/celix_bundle_private.h +++ b/libs/framework/src/celix_bundle_private.h @@ -32,7 +32,7 @@ struct celix_bundle { struct celix_bundle_activator *activator; bundle_state_e state; void *handle; - bundle_archive_pt archive; + celix_bundle_archive_t* archive; celix_array_list_t* modules; celix_framework_t *framework; @@ -50,7 +50,7 @@ typedef struct celix_bundle_activator celix_bundle_activator_t; * @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); +celix_bundle_createFromArchive(celix_framework_t *framework, celix_bundle_archive_t* archive, celix_bundle_t **bundleOut); /** * @brief Get the bundle archive. @@ -58,7 +58,7 @@ celix_bundle_createFromArchive(celix_framework_t *framework, bundle_archive_pt a * @param[in] bundle The bundle. * @return The bundle archive. */ -bundle_archive_t *celix_bundle_getArchive(const celix_bundle_t *bundle); +celix_bundle_archive_t *celix_bundle_getArchive(const celix_bundle_t *bundle); /** * Destroys the bundle. @@ -80,7 +80,7 @@ void celix_bundle_setContext(celix_bundle_t *bundle, celix_bundle_context_t *con 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_getArchive(const celix_bundle_t *bundle, celix_bundle_archive_t** archive); CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getCurrentModule(const celix_bundle_t *bundle, celix_module_t** module); @@ -102,8 +102,6 @@ CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getBundleId(const celix_bundle_ CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getFramework(const celix_bundle_t *bundle, celix_framework_t **framework); -CELIX_FRAMEWORK_DEPRECATED celix_status_t bundle_getBundleLocation(const celix_bundle_t *bundle, const char **location); - #ifdef __cplusplus } #endif diff --git a/libs/framework/src/celix_framework_utils.c b/libs/framework/src/celix_framework_utils.c index c49614069..b790e92c0 100644 --- a/libs/framework/src/celix_framework_utils.c +++ b/libs/framework/src/celix_framework_utils.c @@ -28,7 +28,7 @@ #include <string.h> #include <unistd.h> -#include "bundle_archive.h" +#include "celix_bundle_archive.h" #include "celix_bundle_context.h" #include "celix_constants.h" #include "celix_file_utils.h" diff --git a/libs/framework/src/framework.c b/libs/framework/src/framework.c index 0bf7bda14..3f4a784a9 100644 --- a/libs/framework/src/framework.c +++ b/libs/framework/src/framework.c @@ -39,7 +39,6 @@ #include "celix_module_private.h" #include "celix_framework_bundle.h" -#include "bundle_archive_private.h" #include "bundle_context_private.h" #include "celix_bundle_private.h" #include "celix_err.h" @@ -49,6 +48,7 @@ #include "service_reference_private.h" #include "service_registration_private.h" #include "utils.h" +#include "celix_bundle_archive.h" struct celix_bundle_activator { void * userData; @@ -260,7 +260,7 @@ celix_status_t framework_create(framework_pt *out, celix_properties_t* config) { framework->logger = celix_frameworkLogger_create(celix_logUtils_logLevelFromString(logStr, CELIX_LOG_LEVEL_INFO)); celix_status_t status = celix_bundleCache_create(framework, &framework->cache); - bundle_archive_t* systemArchive = NULL; + celix_bundle_archive_t* systemArchive = NULL; status = CELIX_DO_IF(status, celix_bundleCache_createSystemArchive(framework, &systemArchive)); status = CELIX_DO_IF(status, celix_bundle_createFromArchive(framework, systemArchive, &framework->bundle)); status = CELIX_DO_IF(status, bundle_getBundleId(framework->bundle, &framework->bundleId)); @@ -326,7 +326,7 @@ celix_status_t framework_destroy(framework_pt framework) { bundleContext_destroy(context); } - bundle_archive_t *archive = NULL; + celix_bundle_archive_t *archive = NULL; bundle_getArchive(bnd, &archive); celix_module_t* module = NULL; bundle_getCurrentModule(bnd, &module); @@ -688,7 +688,7 @@ celix_framework_installBundleInternalImpl(celix_framework_t* framework, const ch id = *bndId; } - bundle_archive_t* archive = NULL; + celix_bundle_archive_t* archive = NULL; celix_bundle_t* bundle = NULL; celix_status_t status = celix_bundleCache_createArchive(framework->cache, id, bndLoc, &archive); if (status != CELIX_SUCCESS) { @@ -1025,8 +1025,7 @@ long framework_getBundle(framework_pt framework, const char* location) { int size = celix_arrayList_size(framework->installedBundles.entries); for (int i = 0; i < size; ++i) { celix_bundle_entry_t*entry = celix_arrayList_get(framework->installedBundles.entries, i); - const char *loc = NULL; - bundle_getBundleLocation(entry->bnd, &loc); + const char *loc = celix_bundleArchive_getLocation(celix_bundle_getArchive(entry->bnd)); if (loc != NULL && location != NULL && strncmp(loc, location, strlen(loc)) == 0) { id = entry->bndId; break; @@ -1944,11 +1943,9 @@ 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; - celix_bundle_revision_t*revision = NULL; + celix_bundle_archive_t *archive = NULL; celix_module_t* module = NULL; status = CELIX_DO_IF(status, bundle_getArchive(bnd, &archive)); - status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision)); status = CELIX_DO_IF(status, bundle_getCurrentModule(bnd, &module)); if (module) { diff --git a/libs/framework/src/framework_private.h b/libs/framework/src/framework_private.h index 7de0d844f..5f7fcebc8 100644 --- a/libs/framework/src/framework_private.h +++ b/libs/framework/src/framework_private.h @@ -29,7 +29,7 @@ #include "celix_array_list.h" #include "celix_errno.h" #include "service_factory.h" -#include "bundle_archive.h" +#include "celix_bundle_archive.h" #include "celix_service_listener.h" #include "bundle_listener.h" #include "framework_listener.h" diff --git a/libs/framework/src/module.c b/libs/framework/src/module.c index cae9dd9e3..08f0a4211 100644 --- a/libs/framework/src/module.c +++ b/libs/framework/src/module.c @@ -23,7 +23,6 @@ #include <stdlib.h> #include <string.h> -#include "bundle_archive_private.h" #include "celix_bundle_manifest.h" #include "celix_constants.h" #include "celix_framework.h" @@ -54,10 +53,8 @@ struct celix_module { }; 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_bundle_archive_t* archive = celix_bundle_getArchive(bundle); + return celix_bundleArchive_getManifest(archive); } celix_module_t* module_create(celix_bundle_t* bundle) { @@ -193,7 +190,7 @@ static celix_status_t celix_module_loadLibrary(celix_module_t* module, const cha static celix_status_t celix_module_loadLibraryForManifestEntry(celix_module_t* module, const char* library, - bundle_archive_pt archive, + celix_bundle_archive_t* archive, void** handle) { celix_status_t status = CELIX_SUCCESS; @@ -233,7 +230,7 @@ static celix_status_t celix_module_loadLibraryForManifestEntry(celix_module_t* m static celix_status_t celix_module_loadLibrariesInManifestEntry(celix_module_t* module, const celix_array_list_t* libraries, const char* activator, - bundle_archive_pt archive, + celix_bundle_archive_t* archive, void** activatorHandle) { assert(libraries != NULL); assert(celix_arrayList_getElementType(libraries) == CELIX_ARRAY_LIST_ELEMENT_TYPE_STRING); @@ -256,7 +253,7 @@ 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_t* archive = celix_bundle_getArchive(module->bundle); + celix_bundle_archive_t* archive = celix_bundle_getArchive(module->bundle); celix_bundle_manifest_t* man = celix_module_getManifestFromBundle(module->bundle); const char* activator = celix_bundleManifest_getBundleActivatorLibrary(man);