Skip to content

Commit d10a983

Browse files
committed
apachegh-685: Improve manifest json impl based on review comments
1 parent 3048050 commit d10a983

17 files changed

+175
-366
lines changed

cmake/cmake_celix/BundlePackaging.cmake

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function(add_celix_bundle)
176176

177177
set(OPTIONS NO_ACTIVATOR DO_NOT_CONFIGURE_SYMBOL_VISIBILITY)
178178
set(ONE_VAL_ARGS VERSION ACTIVATOR SYMBOLIC_NAME NAME DESCRIPTION FILENAME GROUP)
179-
set(MULTI_VAL_ARGS SOURCES PRIVATE_LIBRARIES EXPORT_LIBRARIES IMPORT_LIBRARIES HEADERS)
179+
set(MULTI_VAL_ARGS SOURCES PRIVATE_LIBRARIES HEADERS)
180180
cmake_parse_arguments(BUNDLE "${OPTIONS}" "${ONE_VAL_ARGS}" "${MULTI_VAL_ARGS}" ${ARGN})
181181

182182
##check arguments
@@ -341,8 +341,6 @@ function(add_celix_bundle)
341341
#headers
342342
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_ACTIVATOR" "") #Library containing the activator (if any)
343343
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_PRIVATE_LIBS" "") #List of private libs.
344-
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_IMPORT_LIBS" "") #List of libs to import
345-
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_EXPORT_LIBS" "") #list of libs to export
346344
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_LIB_TARGETS" "") #list of all lib targets built within the project.
347345
set_target_properties(${BUNDLE_TARGET_NAME} PROPERTIES "BUNDLE_HEADERS" "") #Additional headers will be added (new line seperated) to the manifest
348346
################################
@@ -379,22 +377,9 @@ function(add_celix_bundle)
379377

380378

381379
celix_bundle_private_libs(${BUNDLE_TARGET_NAME} ${BUNDLE_PRIVATE_LIBRARIES})
382-
celix_bundle_export_libs(${BUNDLE_TARGET_NAME} ${BUNDLE_EXPORT_LIBRARIES})
383-
celix_bundle_import_libs(${BUNDLE_TARGET_NAME} ${BUNDLE_IMPORT_LIBRARIES})
384380
celix_bundle_headers(${BUNDLE_TARGET_NAME} ${BUNDLE_HEADERS})
385381
endfunction()
386382

387-
#[[
388-
Adds a export lib to the Celix bundle.
389-
390-
NOTE: Currently export lib support is Celix is not complete and still experimental.
391-
]]
392-
function(celix_bundle_export_libs)
393-
list(GET ARGN 0 BUNDLE)
394-
list(REMOVE_AT ARGN 0)
395-
celix_bundle_libs(${BUNDLE} "EXPORT" TRUE ${ARGN})
396-
endfunction()
397-
398383
#[[
399384
Add libraries to a bundle.
400385
@@ -527,37 +512,6 @@ function(celix_bundle_libs)
527512
set_target_properties(${BUNDLE} PROPERTIES "BUNDLE_LIB_TARGETS" "${LIB_TARGETS}")
528513
endfunction()
529514

530-
#[[
531-
Adds a import lib to the Celix bundle.
532-
533-
NOTE: Currently importing lib support is Celix is not complete and still experimental.
534-
]]
535-
function(celix_bundle_import_libs)
536-
#0 is bundle TARGET
537-
#2..n is import libs
538-
list(GET ARGN 0 BUNDLE)
539-
list(REMOVE_AT ARGN 0)
540-
541-
#check if arg 0 is correct
542-
_check_bundle(${BUNDLE})
543-
544-
get_target_property(LIBS ${BUNDLE} "BUNDLE_IMPORT_LIBS")
545-
546-
foreach (LIB IN ITEMS ${ARGN})
547-
message(WARNING "Bundle with import libs in Celix is not complete and still experimental.")
548-
if (IS_ABSOLUTE ${LIB} AND EXISTS ${LIB})
549-
list(APPEND LIBS ${LIB_NAME})
550-
else ()
551-
list(APPEND LIBS "$<TARGET_SONAME_FILE_NAME:${LIB}>")
552-
endif ()
553-
554-
target_link_libraries(${BUNDLE} PRIVATE ${LIB})
555-
endforeach ()
556-
557-
558-
set_target_properties(${BUNDLE} PROPERTIES "BUNDLE_IMPORT_LIBS" "${LIBS}")
559-
endfunction()
560-
561515
#[[
562516
Add files to the target bundle.
563517
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
{
22
$<JOIN:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_HEADERS>,$<COMMA>
33
>$<$<BOOL:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_HEADERS>>:$<COMMA>>
4-
"CELIX_BUNDLE_MANIFEST_VERSION" : "2.0.0",
54
"CELIX_BUNDLE_SYMBOLIC_NAME" : "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_SYMBOLIC_NAME>",
6-
"CELIX_BUNDLE_VERSION" : "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_VERSION>",
5+
"CELIX_BUNDLE_VERSION" : "version<$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_VERSION>$<ANGLE-R>",
76
"CELIX_BUNDLE_NAME" : "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_NAME>",
8-
"CELIX_BUNDLE_ACTIVATOR_LIBRARY": "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_ACTIVATOR>",
9-
"CELIX_BUNDLE_PRIVATE_LIBRARIES" : "$<JOIN:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_PRIVATE_LIBS>,$<COMMA>>",
10-
"CELIX_BUNDLE_DESCRIPTION" : "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_DESCRIPTION>",
11-
"CELIX_BUNDLE_GROUP" : "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_GROUP>",
12-
"CELIX_BUNDLE_IMPORT_LIBRARIES" : "$<JOIN:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_IMPORT_LIBS>,$<COMMA>>",
13-
"CELIX_BUNDLE_EXPORT_LIBRARIES" : "$<JOIN:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_EXPORT_LIBS>,$<COMMA>>"
7+
$<$<BOOL:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_ACTIVATOR>>:"CELIX_BUNDLE_ACTIVATOR_LIBRARY": "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_ACTIVATOR>",>
8+
$<$<BOOL:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_PRIVATE_LIBS>>:"CELIX_BUNDLE_PRIVATE_LIBRARIES" : [$<JOIN:"$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_PRIVATE_LIBS>","$<COMMA>">],>
9+
$<$<BOOL:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_DESCRIPTION>>:"CELIX_BUNDLE_DESCRIPTION" : "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_DESCRIPTION>",>
10+
$<$<BOOL:$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_GROUP>>:"CELIX_BUNDLE_GROUP" : "$<TARGET_PROPERTY:${BUNDLE_TARGET_NAME},BUNDLE_GROUP>",>
11+
"CELIX_BUNDLE_MANIFEST_VERSION" : "version<2.0.0$<ANGLE-R>"
1412
}

libs/framework/gtest/src/CxxBundleContextTestSuite.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,8 @@ TEST_F(CxxBundleContextTestSuite, GetBundleInformation) {
710710
EXPECT_EQ(bnd.getGroup(), std::string{"test/group"});
711711
EXPECT_EQ(bnd.getDescription(), std::string{"Test Description"});
712712
EXPECT_TRUE(strstr(bnd.getLocation().c_str(), ".zip") != nullptr);
713-
EXPECT_TRUE(!bnd.getEntry("META-INF/MANIFEST.MF").empty());
714-
EXPECT_EQ(bnd.getEntry("/META-INF/MANIFEST.MF"), bnd.getEntry("META-INF/MANIFEST.MF"));
713+
EXPECT_TRUE(!bnd.getEntry("META-INF/MANIFEST.json").empty());
714+
EXPECT_EQ(bnd.getEntry("/META-INF/MANIFEST.json"), bnd.getEntry("META-INF/MANIFEST.json"));
715715
EXPECT_EQ(bnd.getEntry("does-not-exist"), std::string{});
716716
EXPECT_EQ(bnd.getManifestValue("Extra-Header1"), std::string{"value1"});
717717
EXPECT_EQ(bnd.getManifestValue("non-existing"), std::string{});

libs/framework/gtest/src/ManifestTestSuite.cc

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "celix_properties.h"
2626
#include "celix_stdlib_cleanup.h"
2727
#include "celix_framework_version.h"
28+
#include "celix_version.h"
2829

2930
class ManifestTestSuite : public ::testing::Test {
3031
public:
@@ -35,8 +36,10 @@ class ManifestTestSuite : public ::testing::Test {
3536
const char* bundleName,
3637
const char* symbolicName) {
3738
celix_properties_t* properties = celix_properties_create();
38-
celix_properties_set(properties, "CELIX_BUNDLE_MANIFEST_VERSION", manifestVersion);
39-
celix_properties_set(properties, "CELIX_BUNDLE_VERSION", bundleVersion);
39+
auto mVer = celix_version_createVersionFromString(manifestVersion);
40+
auto bVer = celix_version_createVersionFromString(bundleVersion);
41+
celix_properties_assignVersion(properties, "CELIX_BUNDLE_MANIFEST_VERSION", mVer);
42+
celix_properties_assignVersion(properties, "CELIX_BUNDLE_VERSION", bVer);
4043
celix_properties_set(properties, "CELIX_BUNDLE_NAME", bundleName);
4144
celix_properties_set(properties, "CELIX_BUNDLE_SYMBOLIC_NAME", symbolicName);
4245
return properties;
@@ -46,9 +49,10 @@ class ManifestTestSuite : public ::testing::Test {
4649
TEST_F(ManifestTestSuite, CreateManifestTest) {
4750
//Given a properties set with all the mandatory manifest attributes
4851
celix_properties_t *properties = celix_properties_create();
49-
celix_version_t* v = celix_version_create(2, 0, 0, nullptr);
52+
auto* v = celix_version_create(2, 0, 0, nullptr);
5053
celix_properties_assignVersion(properties, "CELIX_BUNDLE_MANIFEST_VERSION", v);
51-
celix_properties_set(properties, "CELIX_BUNDLE_VERSION", "1.0.0");
54+
auto* bv = celix_version_create(1, 0, 0, nullptr);
55+
celix_properties_assignVersion(properties, "CELIX_BUNDLE_VERSION", bv);
5256
celix_properties_set(properties, "CELIX_BUNDLE_NAME", "my_bundle");
5357
celix_properties_set(properties, "CELIX_BUNDLE_SYMBOLIC_NAME", "celix_my_bundle");
5458

@@ -79,7 +83,7 @@ TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) {
7983
celix_status_t status = celix_bundleManifest_create(properties, &manifest);
8084

8185
//Then the creation fails
82-
EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status);
86+
EXPECT_EQ(CELIX_INVALID_SYNTAX, status);
8387

8488
//And 4 celix err log entries are logged (4 missing attributes)
8589
EXPECT_EQ(celix_err_getErrorCount(), 4);
@@ -97,7 +101,7 @@ TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) {
97101
status = celix_bundleManifest_create(properties, &manifest2);
98102

99103
//Then the creation fails
100-
EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status);
104+
EXPECT_EQ(CELIX_INVALID_SYNTAX, status);
101105

102106
//And 4 celix err log entries are logged (4x invalid versions)
103107
EXPECT_EQ(celix_err_getErrorCount(), 2);
@@ -111,7 +115,7 @@ TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) {
111115
status = celix_bundleManifest_create(properties, &manifest3);
112116

113117
//Then the creation fails
114-
EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status);
118+
EXPECT_EQ(CELIX_INVALID_SYNTAX, status);
115119

116120
//And 1 celix err log entries is logged
117121
EXPECT_EQ(celix_err_getErrorCount(), 1);
@@ -126,7 +130,7 @@ TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) {
126130
status = celix_bundleManifest_create(properties, &manifest4);
127131

128132
//Then the creation fails
129-
EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status);
133+
EXPECT_EQ(CELIX_INVALID_SYNTAX, status);
130134

131135
//And 1 celix err log entries is logged
132136
EXPECT_EQ(celix_err_getErrorCount(), 1);
@@ -142,7 +146,7 @@ TEST_F(ManifestTestSuite, InvalidBundleSymbolicNameTest) {
142146
celix_status_t status = celix_bundleManifest_create(properties, &manifest);
143147

144148
//Then the creation fails
145-
EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status);
149+
EXPECT_EQ(CELIX_INVALID_SYNTAX, status);
146150

147151
//And 1 celix err log entries is logged
148152
EXPECT_EQ(celix_err_getErrorCount(), 1);
@@ -184,7 +188,10 @@ TEST_F(ManifestTestSuite, GetBuiltinAttributes) {
184188
//Given a properties set with all the mandatory and optional attributes
185189
properties = createAttributes("2.0.0", "1.0.0", "my_bundle", "celix_my_bundle");
186190
celix_properties_set(properties, "CELIX_BUNDLE_ACTIVATOR_LIBRARY", "my_activator");
187-
celix_properties_set(properties, "CELIX_BUNDLE_PRIVATE_LIBRARIES", "lib1,lib2");
191+
auto* libs = celix_arrayList_createStringArray();
192+
celix_arrayList_addString(libs, "lib1");
193+
celix_arrayList_addString(libs, "lib2");
194+
celix_properties_assignArrayList(properties, "CELIX_BUNDLE_PRIVATE_LIBRARIES", libs);
188195
celix_properties_set(properties, "CELIX_BUNDLE_GROUP", "my_group");
189196
celix_properties_set(properties, "CELIX_BUNDLE_DESCRIPTION", "my_description");
190197

libs/framework/gtest/src/activator_with_exception.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "celix_bundle_activator.h"
2121
#include "celix_compiler.h"
22+
#include <stdio.h>
2223

2324
struct bundle_act {
2425

libs/framework/include_deprecated/bundle_context.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
#include <stdlib.h>
3030

31-
#include "bundle_context.h"
32-
3331
#include "celix_types.h"
3432
#include "celix_cleanup.h"
3533
#include "service_factory.h"

libs/framework/src/bundle.c

Lines changed: 30 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,24 @@
1717
* under the License.
1818
*/
1919

20-
#include "celix_bundle_private.h"
21-
22-
#include <stdlib.h>
23-
#include <string.h>
24-
#include <service_tracker.h>
25-
#include <celix_constants.h>
26-
#include <assert.h>
27-
#include <unistd.h>
20+
#include "bundle_revision_private.h"
2821

22+
#include "celix_bundle_manifest.h"
23+
#include "celix_bundle_private.h"
2924
#include "celix_module.h"
25+
#include "celix_properties.h"
26+
#include "celix_properties_type.h"
3027
#include "framework_private.h"
3128
#include "utils.h"
3229
#include "celix_file_utils.h"
3330
#include "bundle_archive_private.h"
3431
#include "bundle_context_private.h"
3532
#include "service_tracker_private.h"
3633

34+
#include <stdlib.h>
35+
#include <string.h>
36+
#include <assert.h>
37+
#include <unistd.h>
3738

3839
static char* celix_bundle_getBundleOrPersistentStoreEntry(const celix_bundle_t* bnd, bool bundleEntry, const char* name);
3940
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
5657
bundle->handle = NULL;
5758
bundle->activator = NULL;
5859
bundle->context = NULL;
59-
bundle->symbolicName = NULL;
60-
bundle->name = NULL;
61-
bundle->group = NULL;
62-
bundle->description = NULL;
6360

6461
if (bundle->modules == NULL) {
6562
status = CELIX_ENOMEM;
@@ -90,10 +87,6 @@ celix_status_t bundle_destroy(bundle_pt bundle) {
9087
}
9188
celix_arrayList_destroy(bundle->modules);
9289

93-
free(bundle->symbolicName);
94-
free(bundle->name);
95-
free(bundle->group);
96-
free(bundle->description);
9790
free(bundle);
9891

9992
return CELIX_SUCCESS;
@@ -158,14 +151,8 @@ celix_status_t bundle_setState(bundle_pt bundle, bundle_state_e state) {
158151

159152
celix_status_t bundle_createModule(bundle_pt bundle, celix_module_t** moduleOut) {
160153
celix_status_t status = CELIX_SUCCESS;
161-
long bundleId = celix_bundle_getId(bundle);
162154

163-
celix_module_t* module = NULL;
164-
if (bundleId == CELIX_FRAMEWORK_BUNDLE_ID) {
165-
module = module_createFrameworkModule(bundle->framework, bundle);
166-
} else {
167-
module = module_create(bundle);
168-
}
155+
celix_module_t* module = module_create(bundle);
169156
if (!module) {
170157
status = CELIX_BUNDLE_EXCEPTION;
171158
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)
199186
}
200187

201188
celix_status_t bundle_addModule(bundle_pt bundle, celix_module_t* module) {
202-
celix_arrayList_add(bundle->modules, module);
203-
204-
//free previous module info
205-
free(bundle->symbolicName);
206-
free(bundle->name);
207-
free(bundle->group);
208-
free(bundle->description);
209-
189+
celix_arrayList_add(bundle->modules, module);
210190

211191
//set new module info
212192
const char *sn = NULL;
@@ -217,12 +197,8 @@ celix_status_t bundle_addModule(bundle_pt bundle, celix_module_t* module) {
217197
module_getGroup(module, &g);
218198
module_getName(module, &n);
219199
module_getDescription(module, &d);
220-
bundle->symbolicName = celix_utils_strdup(sn);
221-
bundle->name = celix_utils_strdup(n);
222-
bundle->group = celix_utils_strdup(g);
223-
bundle->description = celix_utils_strdup(d);
224200

225-
return CELIX_SUCCESS;
201+
return CELIX_SUCCESS;
226202
}
227203

228204
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) {
361337
return entry;
362338
}
363339

340+
static celix_bundle_manifest_t* celix_bundle_getManifest(const celix_bundle_t* bnd) {
341+
celix_bundle_manifest_t* man = celix_bundleArchive_getManifest(bnd->archive);
342+
assert(man); //bundles always have a manifest
343+
return man;
344+
}
345+
364346
const char* celix_bundle_getManifestValue(const celix_bundle_t* bnd, const char* attribute) {
365-
const char* header = NULL;
366-
if (bnd != NULL) {
367-
bundle_archive_t* arch = NULL;
368-
bundle_getArchive(bnd, &arch);
369-
if (arch != NULL) {
370-
celix_bundle_revision_t* rev = NULL;
371-
bundleArchive_getCurrentRevision(arch, &rev);
372-
if (rev != NULL) {
373-
celix_bundle_manifest_t* man = celix_bundleRevision_getManifest(rev);
374-
if (man != NULL) {
375-
const celix_properties_t* attr = celix_bundleManifest_getAttributes(man);
376-
header = celix_properties_getAsString(attr, attribute, NULL);
377-
}
378-
}
379-
}
380-
}
381-
return header;
347+
celix_bundle_manifest_t* man = celix_bundle_getManifest(bnd);
348+
assert(man); //bundle always has a manifest
349+
const celix_properties_t* attr = celix_bundleManifest_getAttributes(man);
350+
return celix_properties_getAsString(attr, attribute, NULL);
382351
}
383352

384353
const char* celix_bundle_getGroup(const celix_bundle_t *bnd) {
385-
return bnd->group;
354+
celix_bundle_manifest_t* man = celix_bundle_getManifest(bnd);
355+
return celix_bundleManifest_getBundleGroup(man);
386356
}
387357

388358
const char* celix_bundle_getSymbolicName(const celix_bundle_t *bnd) {
389-
return bnd->symbolicName;
359+
celix_bundle_manifest_t* man = celix_bundle_getManifest(bnd);
360+
return celix_bundleManifest_getBundleSymbolicName(man);
390361
}
391362

392363
const char* celix_bundle_getName(const celix_bundle_t* bnd) {
393-
return bnd->name;
364+
celix_bundle_manifest_t* man = celix_bundle_getManifest(bnd);
365+
return celix_bundleManifest_getBundleName(man);
394366
}
395367

396368
const char* celix_bundle_getDescription(const celix_bundle_t* bnd) {
397-
return bnd->description;
369+
celix_bundle_manifest_t* man = celix_bundle_getManifest(bnd);
370+
return celix_bundleManifest_getBundleDescription(man);
398371
}
399372

400373
char* celix_bundle_getLocation(const celix_bundle_t *bnd) {

0 commit comments

Comments
 (0)