You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2018/11/13 12:11:56 UTC

celix git commit: CELIX-433: Adds container option to use the config.properties instead of the now default generated executable

Repository: celix
Updated Branches:
  refs/heads/develop 12d5caf75 -> acf87f621


CELIX-433: Adds container option to use the config.properties instead of the now default generated executable


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/acf87f62
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/acf87f62
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/acf87f62

Branch: refs/heads/develop
Commit: acf87f621ecd0416281baffa94cf4b4aac49deae
Parents: 12d5caf
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Tue Nov 13 13:11:22 2018 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Tue Nov 13 13:11:22 2018 +0100

----------------------------------------------------------------------
 cmake/cmake_celix/ContainerPackaging.cmake      | 57 +++++++++++++++-----
 documents/cmake_commands/readme.md              |  9 ++--
 .../dm_example_cxx/CMakeLists.txt               |  1 +
 libs/framework/src/celix_launcher.c             |  3 +-
 libs/utils/src/properties.c                     | 43 ++++++++-------
 5 files changed, 77 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/acf87f62/cmake/cmake_celix/ContainerPackaging.cmake
----------------------------------------------------------------------
diff --git a/cmake/cmake_celix/ContainerPackaging.cmake b/cmake/cmake_celix/ContainerPackaging.cmake
index 4c4e967..673afd6 100644
--- a/cmake/cmake_celix/ContainerPackaging.cmake
+++ b/cmake/cmake_celix/ContainerPackaging.cmake
@@ -37,7 +37,7 @@ function(add_celix_container)
     list(GET ARGN 0 CONTAINER_TARGET)
     list(REMOVE_AT ARGN 0)
 
-    set(OPTIONS COPY CXX)
+    set(OPTIONS COPY CXX USE_CONFIG)
     set(ONE_VAL_ARGS GROUP NAME LAUNCHER LAUNCHER_SRC DIR)
     set(MULTI_VAL_ARGS BUNDLES PROPERTIES EMBEDDED_PROPERTIES RUNTIME_PROPERTIES)
     cmake_parse_arguments(CONTAINER "${OPTIONS}" "${ONE_VAL_ARGS}" "${MULTI_VAL_ARGS}" ${ARGN})
@@ -132,18 +132,39 @@ $<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_EMBEDDED_PROPERTIES>,\\n\
     #generate config.properties. C
     set(CONTAINER_PROPS "${CONTAINER_LOC}/config.properties")
     set(STAGE1_PROPERTIES "${PROJECT_BINARY_DIR}/celix/gen/containers/${CONTAINER_TARGET}/container-config-stage1.properties")
-    file(GENERATE 
-        OUTPUT "${STAGE1_PROPERTIES}"
-        CONTENT "$<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_RUNTIME_PROPERTIES>,
+    if (CONTAINER_USE_CONFIG)
+        file(GENERATE
+                OUTPUT "${STAGE1_PROPERTIES}"
+                CONTENT "CELIX_CONTAINER_NAME=$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_NAME>
+CELIX_BUNDLES_PATH=bundles
+$<$<BOOL:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_BUNDLES_LEVEL_0>>:CELIX_AUTO_START_0=$<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_BUNDLES_LEVEL_0>, >>
+$<$<BOOL:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_BUNDLES_LEVEL_1>>:CELIX_AUTO_START_1=$<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_BUNDLES_LEVEL_1>, >>
+$<$<BOOL:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_BUNDLES_LEVEL_2>>:CELIX_AUTO_START_2=$<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_BUNDLES_LEVEL_2>, >>
+$<$<BOOL:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_BUNDLES_LEVEL_3>>:CELIX_AUTO_START_3=$<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_BUNDLES_LEVEL_3>, >>
+$<$<BOOL:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_BUNDLES_LEVEL_4>>:CELIX_AUTO_START_4=$<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_BUNDLES_LEVEL_4>, >>
+$<$<BOOL:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_BUNDLES_LEVEL_5>>:CELIX_AUTO_START_5=$<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_BUNDLES_LEVEL_5>, >>
+$<$<BOOL:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_BUNDLES_LEVEL_6>>:CELIX_AUTO_START_6=$<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_BUNDLES_LEVEL_6>, >>
+$<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_RUNTIME_PROPERTIES>,
+>"
+        )
+        file(GENERATE
+                OUTPUT "${CONTAINER_PROPS}"
+                INPUT "${STAGE1_PROPERTIES}"
+                )
+    else ()
+        file(GENERATE
+                OUTPUT "${STAGE1_PROPERTIES}"
+                CONTENT "$<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_RUNTIME_PROPERTIES>,
 >
 "
-    )
-    #Condition is there so that config.properties file will only be generated if there are runtime properties
-    file(GENERATE
-        OUTPUT "${CONTAINER_PROPS}"
-        INPUT "${STAGE1_PROPERTIES}"
-        CONDITION $<NOT:$<STREQUAL:,$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_RUNTIME_PROPERTIES>>>
-    )
+                )
+        #Condition is there so that config.properties file will only be generated if there are runtime properties
+        file(GENERATE
+                OUTPUT "${CONTAINER_PROPS}"
+                INPUT "${STAGE1_PROPERTIES}"
+                CONDITION $<NOT:$<STREQUAL:,$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_RUNTIME_PROPERTIES>>>
+                )
+    endif ()
 
     #needed in the release.sh & run.sh files
     #Setting CELIX_LIB_DIRS, CELIX_BIN_DIR and CELIX_LAUNCHER
@@ -186,12 +207,17 @@ $<JOIN:$<TARGET_PROPERTY:${CONTAINER_TARGET},CONTAINER_EMBEDDED_PROPERTIES>,\\n\
     set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_NAME" "${CONTAINER_NAME}")
     set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_GROUP" "${CONTAINER_GROUP}")
     set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_LOC" "${CONTAINER_LOC}")
+    set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_USE_CONFIG" "${CONTAINER_USE_CONFIG}")
     set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_RUNTIME_PROPERTIES" "")
     set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_EMBEDDED_PROPERTIES" "")
     #####
 
     celix_container_bundles(${CONTAINER_TARGET} LEVEL 3 ${CONTAINER_BUNDLES})
-    celix_container_embedded_properties(${CONTAINER_TARGET} ${CONTAINER_PROPERTIES})
+    if (CONTAINER_USE_CONFIG)
+        celix_container_runtime_properties(${CONTAINER_TARGET} ${CONTAINER_PROPERTIES})
+    else ()
+        celix_container_embedded_properties(${CONTAINER_TARGET} ${CONTAINER_PROPERTIES})
+    endif ()
     celix_container_runtime_properties(${CONTAINER_TARGET} ${CONTAINER_RUNTIME_PROPERTIES})
     celix_container_embedded_properties(${CONTAINER_TARGET} ${CONTAINER_EMBEDDED_PROPERTIES})
 
@@ -390,5 +416,10 @@ function(celix_container_embedded_properties)
 endfunction()
 
 function(celix_container_properties)
-    celix_container_embedded_properties(${ARGN})
+    get_target_property(USE_CNF ${CONTAINER_TARGET} "CONTAINER_USE_CONFIG")
+    if (USE_CNF)
+        celix_container_runtime_properties(${ARGN})
+    else ()
+        celix_container_embedded_properties(${ARGN})
+    endif ()
 endfunction()

http://git-wip-us.apache.org/repos/asf/celix/blob/acf87f62/documents/cmake_commands/readme.md
----------------------------------------------------------------------
diff --git a/documents/cmake_commands/readme.md b/documents/cmake_commands/readme.md
index 4fc1b24..89d7759 100644
--- a/documents/cmake_commands/readme.md
+++ b/documents/cmake_commands/readme.md
@@ -186,13 +186,14 @@ add_celix_container(<celix_container_name>
 ```
 
 - If the COPY option is provided the selected bundles will be copied in a bundles dir and the generated config.properties will use relative paths to the bundle locations. Default bundles will not be copied and the generated config.properties will use absolute references to the bundle locations.
-- If CXX option is provided the celix container launcher will be build as C++ executable and as result be linked with the required C++ libraries of the used compiler
+- If CXX option is provided the celix container launcher will be build as C++ executable and as result be linked with the required C++ libraries of the used compiler.
+- If USE_CONFIG option is provided a config.properties file will be generated next to the executable. The config.properties contains the configuration for provided BUNDLES and PROPERTIES.
 - If GROUP is provided the celix container will be grouped in the provided group name. 
 - If NAME is provided that name will be used for the celix container dir. Default the Celix container target name will be used.
 - If LAUNCHER is provided that path or target will be used as launcher executable for the Celix container. If no LAUNCHER is not provided the celix executable will be used.
-- If DIR is provided, the specified dir is used instead of `<cmake_build_dir>/deploy` as deploy dir 
-- If BUNDLES is provided the list of bundles will be added the the generated config.properties for startup. Combined with COPY the bundles will also be copied to a bundles dir.
-- If PROPERTIES is provided the list of properties will be appended to the generated config.properties
+- If DIR is provided, the specified dir is used instead of `<cmake_build_dir>/deploy` as deploy dir .
+- If BUNDLES is provided the list of bundles will be added the the generated executable/config.properties for startup. Combined with COPY the bundles will also be copied to a bundles dir.
+- If PROPERTIES is provided the list of properties will be appended to the generated executable/config.properties.
 
 ## celix_container_bundles
 Add the selected bundles to the container.

http://git-wip-us.apache.org/repos/asf/celix/blob/acf87f62/examples/celix-examples/dm_example_cxx/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/celix-examples/dm_example_cxx/CMakeLists.txt b/examples/celix-examples/dm_example_cxx/CMakeLists.txt
index 17e4192..2714fa7 100644
--- a/examples/celix-examples/dm_example_cxx/CMakeLists.txt
+++ b/examples/celix-examples/dm_example_cxx/CMakeLists.txt
@@ -38,6 +38,7 @@ add_celix_container("dm_example_cxx"
         dm_example_cxx_phase3_locking
     PROPERTIES
         LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+    USE_CONFIG
 )
 
 

http://git-wip-us.apache.org/repos/asf/celix/blob/acf87f62/libs/framework/src/celix_launcher.c
----------------------------------------------------------------------
diff --git a/libs/framework/src/celix_launcher.c b/libs/framework/src/celix_launcher.c
index 9fa5c48..693e95d 100644
--- a/libs/framework/src/celix_launcher.c
+++ b/libs/framework/src/celix_launcher.c
@@ -73,8 +73,9 @@ int celixLauncher_launchAndWaitForShutdown(int argc, char *argv[], properties_pt
 	for (int i = 1; i < argc; ++i) {
 		opt = argv[i];
 		// Check whether the user wants some help...
-		if (strncmp("-h", opt, strlen("-h")) == 0 || strncmp("--help", opt, strlen("--help")) == 0) {
+		if (strncmp("-?", opt, strlen("-?")) == 0 || strncmp("-h", opt, strlen("-h")) == 0 || strncmp("--help", opt, strlen("--help")) == 0) {
 			show_usage(argv[0]);
+			celix_properties_destroy(packedConfig);
 			return 0;
 		} else if (strncmp("-p", opt, strlen("-p")) == 0 || strncmp("--props", opt, strlen("--props")) == 0) {
 			showProps = true;

http://git-wip-us.apache.org/repos/asf/celix/blob/acf87f62/libs/utils/src/properties.c
----------------------------------------------------------------------
diff --git a/libs/utils/src/properties.c b/libs/utils/src/properties.c
index 1519ecc..40ee25d 100644
--- a/libs/utils/src/properties.c
+++ b/libs/utils/src/properties.c
@@ -220,14 +220,16 @@ celix_properties_t* celix_properties_create(void) {
 }
 
 void celix_properties_destroy(celix_properties_t *properties) {
-	hash_map_iterator_pt iter = hashMapIterator_create(properties);
-	while (hashMapIterator_hasNext(iter)) {
-		hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
-		free(hashMapEntry_getKey(entry));
-		free(hashMapEntry_getValue(entry));
+	if (properties != NULL) {
+		hash_map_iterator_pt iter = hashMapIterator_create(properties);
+		while (hashMapIterator_hasNext(iter)) {
+			hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+			free(hashMapEntry_getKey(entry));
+			free(hashMapEntry_getValue(entry));
+		}
+		hashMapIterator_destroy(iter);
+		hashMap_destroy(properties, false, false);
 	}
-	hashMapIterator_destroy(iter);
-	hashMap_destroy(properties, false, false);
 }
 
 celix_properties_t* celix_properties_load(const char *filename) {
@@ -357,22 +359,27 @@ celix_properties_t* celix_properties_copy(const celix_properties_t *properties)
 }
 
 const char* celix_properties_get(const celix_properties_t *properties, const char *key, const char *defaultValue) {
-	const char* value = hashMap_get((hash_map_t*)properties, (void*)key);
+	const char *value = NULL;
+	if (properties != NULL) {
+		value = hashMap_get((hash_map_t *) properties, (void *) key);
+	}
 	return value == NULL ? defaultValue : value;
 }
 
 void celix_properties_set(celix_properties_t *properties, const char *key, const char *value) {
-	hash_map_entry_pt entry = hashMap_getEntry(properties, key);
-	char* oldVal = NULL;
-	char *newVal = value == NULL ? NULL : strndup(value, 1024*1024);
-	if (entry != NULL) {
-		char* oldKey = hashMapEntry_getKey(entry);
-        oldVal = hashMapEntry_getValue(entry);
-		hashMap_put(properties, oldKey, newVal);
-	} else {
-		hashMap_put(properties, strndup(key, 1024*1024), newVal);
+	if (properties != NULL) {
+		hash_map_entry_pt entry = hashMap_getEntry(properties, key);
+		char *oldVal = NULL;
+		char *newVal = value == NULL ? NULL : strndup(value, 1024 * 1024);
+		if (entry != NULL) {
+			char *oldKey = hashMapEntry_getKey(entry);
+			oldVal = hashMapEntry_getValue(entry);
+			hashMap_put(properties, oldKey, newVal);
+		} else {
+			hashMap_put(properties, strndup(key, 1024 * 1024), newVal);
+		}
+		free(oldVal);
 	}
-	free(oldVal);
 }
 
 void celix_properties_unset(celix_properties_t *properties, const char *key) {