Skip to content

Commit 8b56975

Browse files
committed
gh-685: Remove bundle revision and refactor bundle archive
1 parent db14807 commit 8b56975

20 files changed

+279
-694
lines changed

libs/framework/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ if (FRAMEWORK)
2323
find_package(CURL REQUIRED)
2424
endif ()
2525
set(FRAMEWORK_SRC
26-
src/bundle.c src/bundle_archive.c src/celix_bundle_cache.c
27-
src/bundle_context.c src/bundle_revision.c
26+
src/bundle.c src/celix_bundle_archive.c src/celix_bundle_cache.c
27+
src/bundle_context.c
2828
src/framework.c
2929
src/module.c
3030
src/service_reference.c src/service_registration.c

libs/framework/gtest/src/BundleArchiveTestSuite.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
#include "celix_file_utils.h"
2525
#include "celix_framework_utils.h"
2626
#include "framework.h"
27-
#include "bundle_archive.h"
2827

2928
//including private headers, which should only be used for testing
30-
#include "bundle_archive_private.h"
29+
#include "celix_bundle_archive.h"
3130
#include "celix_bundle_private.h"
3231

3332
class CxxBundleArchiveTestSuite : public ::testing::Test {

libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
#include "celix/FrameworkFactory.h"
3333

3434
#include "asprintf_ei.h"
35-
#include "bundle_archive_private.h"
36-
#include "bundle_revision_private.h"
35+
#include "celix_bundle_archive.h"
3736
#include "framework_private.h"
3837
#include "malloc_ei.h"
3938
#include "celix_bundle_manifest.h"
@@ -113,19 +112,6 @@ TEST_F(BundleArchiveWithErrorInjectionTestSuite, BundleArchiveCreatedFailedTest)
113112
// Given a mocked malloc which returns NULL from a call from manifest_create
114113
celix_ei_expect_calloc((void*)celix_bundleManifest_create, 0, nullptr);
115114
installBundleAndExpectFailure();
116-
117-
teardownErrorInjectors();
118-
// Given a mocked calloc which returns NULL from a call from bundleRevision_create
119-
celix_ei_expect_calloc((void*)celix_bundleRevision_create, 0, nullptr);
120-
installBundleAndExpectFailure();
121-
122-
teardownErrorInjectors();
123-
// Given a mocked celix_utils_strdup which returns NULL from a call from bundleRevision_create
124-
celix_ei_expect_celix_utils_strdup((void*)celix_bundleRevision_create, 0, nullptr);
125-
installBundleAndExpectFailure();
126-
127-
celix_ei_expect_celix_utils_strdup((void*)celix_bundleRevision_create, 0, nullptr, 2);
128-
installBundleAndExpectFailure();
129115
}
130116

131117
TEST_F(BundleArchiveWithErrorInjectionTestSuite, BundleArchiveCreateCacheDirectoryFailedTest) {
@@ -142,13 +128,13 @@ TEST_F(BundleArchiveWithErrorInjectionTestSuite, BundleArchiveCreateCacheDirecto
142128
installBundleAndExpectFailure();
143129

144130
teardownErrorInjectors();
145-
// Given a mocked celix_utils_strdup which returns NULL from a (indirect) call from bundleArchive_create
146-
celix_ei_expect_celix_utils_strdup((void*)celix_bundleArchive_create, 1, nullptr);
131+
// Given a mocked celix_utils_strdup which returns NULL from a call from bundleArchive_create
132+
celix_ei_expect_celix_utils_strdup((void*)celix_bundleArchive_create, 0, nullptr);
147133
installBundleAndExpectFailure();
148134

149135
teardownErrorInjectors();
150-
// Given a mocked celix_utils_strdup which returns NULL from a second (indirect) call from bundleArchive_create
151-
celix_ei_expect_celix_utils_strdup((void*)celix_bundleArchive_create, 1, nullptr, 2);
136+
// Given a mocked celix_utils_strdup which returns NULL from a second call from bundleArchive_create
137+
celix_ei_expect_celix_utils_strdup((void*)celix_bundleArchive_create, 0, nullptr, 2);
152138
installBundleAndExpectFailure();
153139
}
154140

@@ -189,7 +175,7 @@ class CelixBundleArchiveErrorInjectionTestSuite : public ::testing::Test {
189175
TEST_F(CelixBundleArchiveErrorInjectionTestSuite, ArchiveCreateErrorTest) {
190176
celix_bundle_cache_t* cache = nullptr;
191177
createCache(&cache);
192-
bundle_archive_t* archive = nullptr;
178+
celix_bundle_archive_t* archive = nullptr;
193179

194180
// archive directory creation failures not covered by other tests
195181
celix_ei_expect_celix_utils_getLastModified((void*)celix_bundleArchive_create, 2, CELIX_FILE_IO_EXCEPTION);
@@ -241,22 +227,6 @@ TEST_F(CelixBundleArchiveErrorInjectionTestSuite, ArchiveCreateErrorTest) {
241227
EXPECT_FALSE(celix_utils_directoryExists(TEST_ARCHIVE_ROOT));
242228
teardownErrorInjectors();
243229

244-
// revision creation failure
245-
celix_ei_expect_calloc((void*)celix_bundleRevision_create, 0, nullptr);
246-
EXPECT_EQ(CELIX_ENOMEM,
247-
celix_bundleArchive_create(&fw, TEST_ARCHIVE_ROOT, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive));
248-
EXPECT_EQ(nullptr, archive);
249-
EXPECT_FALSE(celix_utils_directoryExists(TEST_ARCHIVE_ROOT));
250-
teardownErrorInjectors();
251-
252-
// bundle state persistence failure
253-
celix_ei_expect_celix_properties_create((void*)celix_bundleArchive_create, 1, nullptr);
254-
EXPECT_EQ(CELIX_ENOMEM,
255-
celix_bundleArchive_create(&fw, TEST_ARCHIVE_ROOT, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive));
256-
EXPECT_EQ(nullptr, archive);
257-
EXPECT_FALSE(celix_utils_directoryExists(TEST_ARCHIVE_ROOT));
258-
teardownErrorInjectors();
259-
260230
EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_destroy(cache));
261231
}
262232

libs/framework/gtest/src/CelixBundleCacheErrorInjectionTestSuite.cc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
#include "celix_properties_ei.h"
3333

3434
#include "asprintf_ei.h"
35-
#include "bundle_archive_private.h"
36-
#include "bundle_revision_private.h"
35+
#include "celix_bundle_archive.h"
3736
#include "framework_private.h"
3837
#include "malloc_ei.h"
3938
#include "celix_bundle_manifest.h"
@@ -106,7 +105,7 @@ TEST_F(CelixBundleCacheErrorInjectionTestSuite, ArchiveCreateErrorTest) {
106105
celix_bundle_cache_t* cache = nullptr;
107106
createCache(&cache);
108107

109-
bundle_archive_t* archive = nullptr;
108+
celix_bundle_archive_t* archive = nullptr;
110109
celix_ei_expect_celix_utils_writeOrCreateString((void*)celix_bundleCache_createArchive, 0, nullptr);
111110
EXPECT_EQ(CELIX_ENOMEM, celix_bundleCache_createArchive(cache, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive));
112111
EXPECT_EQ(nullptr, archive);
@@ -131,7 +130,7 @@ TEST_F(CelixBundleCacheErrorInjectionTestSuite, SystemArchiveCreateErrorTest) {
131130
celix_bundle_cache_t* cache = nullptr;
132131
createCache(&cache);
133132

134-
bundle_archive_t* archive = nullptr;
133+
celix_bundle_archive_t* archive = nullptr;
135134
celix_ei_expect_calloc((void*)celix_bundleArchive_create, 0, nullptr);
136135
EXPECT_EQ(CELIX_ENOMEM, celix_bundleCache_createSystemArchive(&fw, &archive));
137136
EXPECT_EQ(nullptr, archive);
@@ -148,10 +147,6 @@ TEST_F(CelixBundleCacheErrorInjectionTestSuite, SystemArchiveCreateErrorTest) {
148147
EXPECT_EQ(CELIX_ENOMEM, celix_bundleCache_createSystemArchive(&fw, &archive));
149148
EXPECT_EQ(nullptr, archive);
150149

151-
celix_ei_expect_calloc((void*)celix_bundleRevision_create, 0, nullptr);
152-
EXPECT_EQ(CELIX_ENOMEM, celix_bundleCache_createSystemArchive(&fw, &archive));
153-
EXPECT_EQ(nullptr, archive);
154-
155150
EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_destroy(cache));
156151
}
157152

libs/framework/gtest/src/CelixBundleCacheTestSuite.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
under the License.
1818
*/
1919

20-
#include "bundle_archive_private.h"
20+
#include "celix_bundle_archive.h"
2121
#include "celix_bundle_cache.h"
2222
#include "celix_constants.h"
2323
#include "celix_file_utils.h"
@@ -48,12 +48,11 @@ class CelixBundleCacheTestSuite : public ::testing::Test {
4848
};
4949

5050
TEST_F(CelixBundleCacheTestSuite, ArchiveCreateDestroyTest) {
51-
bundle_archive_t* archive = nullptr;
51+
celix_bundle_archive_t* archive = nullptr;
5252
EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_createArchive(fw.cache, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive));
5353
EXPECT_NE(nullptr, archive);
5454
auto location = celix_bundleArchive_getLocation(archive);
5555
EXPECT_STREQ(SIMPLE_TEST_BUNDLE1_LOCATION, location);
56-
free(location);
5756
long bndId;
5857
auto status = celix_bundleCache_findBundleIdForLocation(fw.cache, SIMPLE_TEST_BUNDLE1_LOCATION, &bndId);
5958
EXPECT_EQ(CELIX_SUCCESS, status);
@@ -71,7 +70,7 @@ TEST_F(CelixBundleCacheTestSuite, ArchiveCreateDestroyTest) {
7170
}
7271

7372
TEST_F(CelixBundleCacheTestSuite, NonPermanentDestroyTest) {
74-
bundle_archive_t* archive = nullptr;
73+
celix_bundle_archive_t* archive = nullptr;
7574
EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_createArchive(fw.cache, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive));
7675
EXPECT_NE(nullptr, archive);
7776
std::string loc = celix_bundleArchive_getPersistentStoreRoot(archive);
@@ -86,13 +85,11 @@ TEST_F(CelixBundleCacheTestSuite, NonPermanentDestroyTest) {
8685
}
8786

8887
TEST_F(CelixBundleCacheTestSuite, SystemArchiveCreateDestroyTest) {
89-
bundle_archive_t* archive = nullptr;
90-
const char* archiveRoot = nullptr;
88+
celix_bundle_archive_t* archive = nullptr;
9189
EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_createSystemArchive(&fw, &archive));
9290
EXPECT_NE(nullptr, archive);
9391
EXPECT_EQ(0, celix_bundleArchive_getId(archive));
94-
EXPECT_EQ(CELIX_SUCCESS, bundleArchive_getArchiveRoot(archive, &archiveRoot));
95-
EXPECT_EQ(nullptr, archiveRoot);
92+
EXPECT_EQ(nullptr, celix_bundleArchive_getArchiveRoot(archive));
9693
EXPECT_EQ(nullptr, celix_bundleArchive_getLocation(archive));
9794
celix_bundleArchive_invalidate(archive);
9895
celix_bundleCache_destroyArchive(fw.cache, archive);

libs/framework/include/celix_types.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern "C" {
4141

4242
typedef struct celix_framework celix_framework_t;
4343
typedef struct celix_bundle celix_bundle_t;
44+
typedef struct celix_bundle_archive celix_bundle_archive_t;
4445
typedef struct celix_dependency_manager celix_dependency_manager_t;
4546
typedef struct celix_dm_component_struct celix_dm_component_t;
4647
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;
6364
typedef struct celix_bundle bundle_t CELIX_DEPRECATED_ATTR;
6465

6566
// will be deprecated in the future
66-
typedef struct bundleArchive *bundle_archive_pt;
67-
typedef struct bundleArchive bundle_archive_t;
6867
typedef struct service_factory *service_factory_pt;
6968
typedef struct serviceReference * service_reference_pt;
7069
typedef struct serviceRegistration service_registration_t;

libs/framework/src/bundle.c

Lines changed: 33 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
#include "bundle_revision_private.h"
21-
2220
#include "celix_bundle_manifest.h"
2321
#include "celix_bundle_private.h"
2422
#include "celix_module.h"
@@ -27,20 +25,20 @@
2725
#include "framework_private.h"
2826
#include "utils.h"
2927
#include "celix_file_utils.h"
30-
#include "bundle_archive_private.h"
3128
#include "bundle_context_private.h"
3229
#include "service_tracker_private.h"
3330

3431
#include <stdlib.h>
3532
#include <string.h>
3633
#include <assert.h>
34+
#include <celix_constants.h>
3735
#include <unistd.h>
3836

3937
static char* celix_bundle_getBundleOrPersistentStoreEntry(const celix_bundle_t* bnd, bool bundleEntry, const char* name);
4038
celix_status_t bundle_createModule(bundle_pt bundle, celix_module_t** module);
4139
celix_status_t bundle_closeRevisions(const_bundle_pt bundle);
4240

43-
celix_status_t celix_bundle_createFromArchive(celix_framework_t *framework, bundle_archive_pt archive, celix_bundle_t **bundleOut) {
41+
celix_status_t celix_bundle_createFromArchive(celix_framework_t *framework, celix_bundle_archive_t* archive, celix_bundle_t **bundleOut) {
4442
celix_status_t status = CELIX_SUCCESS;
4543
celix_bundle_t* bundle = calloc(1, sizeof(*bundle));
4644

@@ -92,7 +90,7 @@ celix_status_t bundle_destroy(bundle_pt bundle) {
9290
return CELIX_SUCCESS;
9391
}
9492

95-
celix_status_t bundle_getArchive(const_bundle_pt bundle, bundle_archive_pt *archive) {
93+
celix_status_t bundle_getArchive(const_bundle_pt bundle, celix_bundle_archive_t** archive) {
9694
celix_status_t status = CELIX_SUCCESS;
9795
if (bundle != NULL && *archive == NULL) {
9896
*archive = bundle->archive;
@@ -201,22 +199,16 @@ celix_status_t bundle_addModule(bundle_pt bundle, celix_module_t* module) {
201199
return CELIX_SUCCESS;
202200
}
203201

204-
celix_status_t bundle_isSystemBundle(const_bundle_pt bundle, bool *systemBundle) {
205-
celix_status_t status;
206-
long bundleId;
207-
bundle_archive_pt archive = NULL;
208-
209-
status = bundle_getArchive(bundle, &archive);
210-
if (status == CELIX_SUCCESS) {
211-
status = bundleArchive_getId(archive, &bundleId);
212-
if (status == CELIX_SUCCESS) {
213-
*systemBundle = (bundleId == 0);
214-
}
215-
}
216-
217-
framework_logIfError(bundle->framework->logger, status, NULL, "Failed to check if bundle is the systembundle");
218-
219-
return status;
202+
celix_status_t bundle_isSystemBundle(const_bundle_pt bundle, bool* systemBundle) {
203+
celix_bundle_archive_t* archive = celix_bundle_getArchive(bundle);
204+
if (archive) {
205+
long bundleId = celix_bundleArchive_getId(archive);
206+
*systemBundle = (bundleId == CELIX_FRAMEWORK_BUNDLE_ID);
207+
} else {
208+
fw_log(bundle->framework->logger, CELIX_LOG_LEVEL_ERROR, "Failed to check if bundle is the systembundle");
209+
return CELIX_BUNDLE_EXCEPTION;
210+
}
211+
return CELIX_SUCCESS;
220212
}
221213

222214
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
239231
return CELIX_SUCCESS;
240232
}
241233

242-
celix_status_t bundle_getBundleLocation(const_bundle_pt bundle, const char **location){
243-
244-
celix_status_t status;
245-
246-
bundle_archive_pt archive = NULL;
247-
248-
status = bundle_getArchive(bundle, &archive);
249-
if (status != CELIX_SUCCESS){
250-
printf("[ ERROR ]: Bundle - getBundleLocation (BundleArchive) \n");
251-
return status;
252-
}
253-
254-
status = bundleArchive_getLocation(archive, location);
255-
if (status != CELIX_SUCCESS){
256-
printf("[ ERROR ]: Bundle - getBundleLocation (BundleArchiveLocation) \n");
257-
return status;
258-
}
259-
260-
return CELIX_SUCCESS;
261-
}
262-
263-
264-
265-
266-
267234

268235
/**********************************************************************************************************************
269236
**********************************************************************************************************************
@@ -272,25 +239,25 @@ celix_status_t bundle_getBundleLocation(const_bundle_pt bundle, const char **loc
272239
**********************************************************************************************************************/
273240

274241
long celix_bundle_getId(const bundle_t* bnd) {
275-
long bndId = -1;
276-
bundle_archive_pt archive = NULL;
277-
bundle_getArchive((bundle_t*)bnd, &archive);
278-
if (archive != NULL) {
279-
bundleArchive_getId(archive, &bndId);
280-
}
281-
282-
if (bndId < 0) {
283-
framework_logIfError(celix_frameworkLogger_globalLogger(), CELIX_BUNDLE_EXCEPTION, NULL, "Failed to get bundle id");
284-
}
285-
return bndId;
242+
long bndId = -1;
243+
celix_bundle_archive_t* archive = celix_bundle_getArchive(bnd);
244+
if (archive) {
245+
bndId = celix_bundleArchive_getId(archive);
246+
} else {
247+
framework_logIfError(celix_frameworkLogger_globalLogger(),
248+
CELIX_BUNDLE_EXCEPTION,
249+
NULL,
250+
"Failed to get bundle id");
251+
}
252+
return bndId;
286253
}
287254

288255
celix_bundle_state_e celix_bundle_getState(const celix_bundle_t *bnd) {
289256
return __atomic_load_n(&bnd->state, __ATOMIC_ACQUIRE);
290257
}
291258

292259
static char* celix_bundle_getBundleOrPersistentStoreEntry(const celix_bundle_t* bnd, bool bundleEntry, const char* name) {
293-
bundle_archive_pt archive = NULL;
260+
celix_bundle_archive_t* archive = NULL;
294261
celix_status_t status = bundle_getArchive(bnd, &archive);
295262
if (status != CELIX_SUCCESS) {
296263
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) {
373340
char* celix_bundle_getLocation(const celix_bundle_t *bnd) {
374341
char* result = NULL;
375342
if (bnd->archive != NULL) {
376-
result = celix_bundleArchive_getLocation(bnd->archive);
343+
const char* loc = celix_bundleArchive_getLocation(bnd->archive);
344+
result = celix_utils_strdup(loc);
345+
if (!result) {
346+
fw_log(bnd->framework->logger, CELIX_BUNDLE_EXCEPTION, "Failed to allocate memory for bundle location");
347+
}
377348
}
378349
return result;
379350
}
@@ -454,8 +425,8 @@ celix_array_list_t* celix_bundle_listServiceTrackers(const celix_bundle_t *bnd)
454425
return result;
455426
}
456427

457-
bundle_archive_t* celix_bundle_getArchive(const celix_bundle_t *bundle) {
458-
bundle_archive_t* archive = NULL;
459-
bundle_getArchive(bundle, &archive);
428+
celix_bundle_archive_t* celix_bundle_getArchive(const celix_bundle_t *bundle) {
429+
celix_bundle_archive_t* archive = NULL;
430+
(void)bundle_getArchive(bundle, &archive);
460431
return archive;
461432
}

0 commit comments

Comments
 (0)