From acedb9140bfee9888088b91c56f952e582f9067c Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Sat, 30 Dec 2023 20:02:22 +0100 Subject: [PATCH] Remove support for embedded bundles --- CHANGES.md | 1 + cmake/cmake_celix/ContainerPackaging.cmake | 129 +--------------- cmake/cmake_celix/Generic.cmake | 143 ------------------ .../templates/embed_bundle_apple.s | 27 ---- .../templates/embed_bundle_linux.s | 30 ---- documents/cmake_commands/README.md | 128 ---------------- examples/celix-examples/CMakeLists.txt | 1 - .../celix-examples/dm_example/CMakeLists.txt | 2 +- .../dm_example_cxx/CMakeLists.txt | 2 +- .../celix-examples/embedding/CMakeLists.txt | 23 --- .../celix-examples/embedding/src/launcher.c | 23 --- examples/celix-examples/embedding/src/main.c | 39 ----- examples/celix-examples/embedding/src/main.cc | 34 ----- libs/framework/gtest/CMakeLists.txt | 5 - ...ixFrameworkUtilsErrorInjectionTestSuite.cc | 29 ---- .../gtest/src/CelixFrameworkUtilsTestSuite.cc | 37 ----- .../gtest/src/CelixLauncherTestSuite.cc | 13 -- libs/framework/include/celix/FrameworkUtils.h | 43 ------ .../framework/include/celix_framework_utils.h | 32 ---- libs/framework/src/celix_framework_utils.c | 123 --------------- libs/framework/src/celix_launcher.c | 106 ++++++------- 21 files changed, 48 insertions(+), 922 deletions(-) delete mode 100644 cmake/cmake_celix/templates/embed_bundle_apple.s delete mode 100644 cmake/cmake_celix/templates/embed_bundle_linux.s delete mode 100644 examples/celix-examples/embedding/CMakeLists.txt delete mode 100644 examples/celix-examples/embedding/src/launcher.c delete mode 100644 examples/celix-examples/embedding/src/main.c delete mode 100644 examples/celix-examples/embedding/src/main.cc diff --git a/CHANGES.md b/CHANGES.md index 1b712a700..80491886e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -53,6 +53,7 @@ limitations under the License. - C Properties are no longer a direct typedef of `hashmap`. - celix_string/long_hashmap put functions now return a celix_status_t instead of bool (value replaced). THe celix_status_t is used to indicate an ENOMEM error. +- Embedded bundles are no longer supported. ## New Features diff --git a/cmake/cmake_celix/ContainerPackaging.cmake b/cmake/cmake_celix/ContainerPackaging.cmake index cb2eecd7a..78e799eb9 100644 --- a/cmake/cmake_celix/ContainerPackaging.cmake +++ b/cmake/cmake_celix/ContainerPackaging.cmake @@ -66,10 +66,6 @@ Optional Arguments: - C: With this option the generated Celix launcher (if used) will be a C source. Only one of the C or CXX options can be provided. Default is CXX -- FAT: With this option only embedded bundles are allowed to be added to the container. Ensuring a container executable - this is not dependent on external bundle zip files. - Note that this option does not change anything to the container, it just ensure that all added bundles are embedded - bundles. - USE_CONFIG: With this option the config properties are generated in a 'config.properties' instead of embedded in the Celix launcher. - GROUP: If configured the build location will be prefixed the GROUP. Default is empty. @@ -79,14 +75,8 @@ Optional Arguments: - BUNDLES: A list of bundles for the Celix container to install and start. These bundle will be configured for run level 3. See 'celix_container_bundles' for more info. - INSTALL_BUNDLES: A list of bundles for the Celix container to install (but not start). -- EMBEDDED_BUNDLES: A list of bundles to embed in the Celix container (inject as binary in the executable) and - to install and start for the Celix container. - See `celix_target_embedded_bundle` for more info about embedded bundles. -- INSTALL_EMBEDDED_BUNDLES: A list of bundles to embed in the Celix container (inject as binary in the executable) and - to install (but not start) for the Celix container. - See `celix_target_embedded_bundle` for more info about embedded bundles. - PROPERTIES: A list of configuration properties, these can be used to configure the Celix framework and/or bundles. - Normally this will be EMBEDED_PROPERTIES, but if the USE_CONFIG option is used this will be RUNTIME_PROPERTIES. + Normally this will be EMBEDDED_PROPERTIES, but if the USE_CONFIG option is used this will be RUNTIME_PROPERTIES. See the framework library or bundles documentation about the available configuration options. - EMBEDDED_PROPERTIES: A list of configuration properties which will be used in the generated Celix launcher. - RUNTIME_PROPERTIES: A list of configuration properties which will be used in the generated config.properties file. @@ -97,15 +87,12 @@ add_celix_container( [NO_COPY] [CXX] [C] - [FAT] [USE_CONFIG] [GROUP group_name] [NAME celix_container_name] [DIR dir] [BUNDLES ...] [INSTALL_BUNDLES ...] - [EMBEDDED_BUNDLES ...] - [INSTALL_EMBEDDED_BUNDLES ...] [PROPERTIES "prop1=val1" "prop2=val2" ...] [EMBEDDED_PROPERTIES "prop1=val1" "prop2=val2" ...] [RUNTIME_PROPERTIES "prop1=val1" "prop2=val2" ...] @@ -119,15 +106,12 @@ add_celix_container( [NO_COPY] [CXX] [C] - [FAT] [USE_CONFIG] [GROUP group_name] [NAME celix_container_name] [DIR dir] [BUNDLES ...] [INSTALL_BUNDLES ...] - [EMBEDDED_BUNDLES ...] - [INSTALL_EMBEDDED_BUNDLES ...] [PROPERTIES "prop1=val1" "prop2=val2" ...] [EMBEDDED_PROPERTIES "prop1=val1" "prop2=val2" ...] [RUNTIME_PROPERTIES "prop1=val1" "prop2=val2" ...] @@ -141,15 +125,12 @@ add_celix_container( [NO_COPY] [CXX] [C] - [FAT] [USE_CONFIG] [GROUP group_name] [NAME celix_container_name] [DIR dir] [BUNDLES ...] [INSTALL_BUNDLES ...] - [EMBEDDED_BUNDLES ...] - [INSTALL_EMBEDDED_BUNDLES ...] [PROPERTIES "prop1=val1" "prop2=val2" ...] [EMBEDDED_PROPERTIES "prop1=val1" "prop2=val2" ...] [RUNTIME_PROPERTIES "prop1=val1" "prop2=val2" ...] @@ -169,20 +150,6 @@ add_celix_container(simple_container CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL=debug ) ``` - -```CMake -#Creates a "fat" Celix container in ${CMAKE_BINARY_DIR}/deploy/simple_fat_container which starts 3 bundles embedded -#in the container executable. -add_celix_container(simple_fat_container - FAT - EMBEDDED_BUNDLES - Celix::shell - Celix::shell_tui - Celix::log_admin - PROPERTIES - CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL=debug -) -``` ]] function(add_celix_container) list(GET ARGN 0 CONTAINER_TARGET) @@ -190,7 +157,7 @@ function(add_celix_container) set(OPTIONS COPY NO_COPY C CXX FAT USE_CONFIG) set(ONE_VAL_ARGS GROUP NAME LAUNCHER LAUNCHER_SRC DIR) - set(MULTI_VAL_ARGS BUNDLES INSTALL_BUNDLES EMBEDDED_BUNDLES INSTALL_EMBEDDED_BUNDLES PROPERTIES EMBEDDED_PROPERTIES RUNTIME_PROPERTIES) + set(MULTI_VAL_ARGS BUNDLES INSTALL_BUNDLES PROPERTIES EMBEDDED_PROPERTIES RUNTIME_PROPERTIES) cmake_parse_arguments(CONTAINER "${OPTIONS}" "${ONE_VAL_ARGS}" "${MULTI_VAL_ARGS}" ${ARGN}) ##### Check arguments ##### @@ -370,7 +337,6 @@ $, set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_BUNDLES_LEVEL_6" "") #bundles to deploy for the container for startup level 6 set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_BUNDLES_INSTALL" "") #bundles to install for the container set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_COPY_BUNDLES" ${CONTAINER_COPY}) #copy bundles in bundle dir or link using abs paths. NOTE this cannot be changed after a add_deploy command - set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_IS_FAT" ${CONTAINER_FAT}) #Whether this is a fat container, so a container with only embedded bundles. #deploy specific set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_NAME" "${CONTAINER_NAME}") @@ -382,9 +348,7 @@ $, ##### celix_container_bundles(${CONTAINER_TARGET} LEVEL 3 ${CONTAINER_BUNDLES}) - celix_container_embedded_bundles(${CONTAINER_TARGET} LEVEL 3 ${CONTAINER_EMBEDDED_BUNDLES}) celix_container_bundles(${CONTAINER_TARGET} INSTALL ${CONTAINER_INSTALL_BUNDLES}) - celix_container_embedded_bundles(${CONTAINER_TARGET} INSTALL ${CONTAINER_INSTALL_EMBEDDED_BUNDLES}) if (CONTAINER_USE_CONFIG) celix_container_runtime_properties(${CONTAINER_TARGET} ${CONTAINER_PROPERTIES}) else () @@ -560,7 +524,6 @@ function(celix_container_bundles) get_target_property(BUNDLES ${CONTAINER_TARGET} "CONTAINER_BUNDLES_LEVEL_${BUNDLES_LEVEL}") endif () get_target_property(COPY ${CONTAINER_TARGET} "CONTAINER_COPY_BUNDLES") - get_target_property(IS_FAT ${CONTAINER_TARGET} "CONTAINER_IS_FAT") if (BUNDLES_COPY) set(COPY TRUE) @@ -569,10 +532,6 @@ function(celix_container_bundles) endif () foreach(BUNDLE IN ITEMS ${BUNDLES_LIST}) - if (IS_FAT) - message(FATAL_ERROR "Cannot add bundle ${BUNDLE} to Celix container ${CONTAINER_TARGET}. ${CONTAINER_TARGET} is configured as a fat container, so only embedded bundles are allowed. Use EMBEDDED_BUNDLES instead of BUNDLES in the add_celix_container CMake command.") - endif () - if (TARGET ${BUNDLE}) get_target_property(TARGET_TYPE ${BUNDLE} TYPE) if (TARGET_TYPE STREQUAL "INTERFACE_LIBRARY") @@ -643,90 +602,6 @@ function(_celix_container_check_duplicate_bundles) endforeach() endfunction() -#[[ -Embed a selection of bundles to the Celix container. - -```CMake -celix_container_embedded_bundles( - [LEVEL (0..6)] - [INSTALL] - bundle1 - bundle2 - ... -) -``` - -Example: -```CMake -celix_container_embedded_bundles(my_container Celix::shell Celix::shell_tui) -``` - -The selection of bundles are embedded in the container executable using the -`celix_target_embedded_bundle` Celix CMake command and are added to the configuration properties so that they are -installed and started when the Celix container is executed. - -See `celix_target_embedded_bundle` for how bundle is embedded in a executable. - -The Celix framework supports 7 (0 - 6) run levels. Run levels can be used to control the start and stop order of bundles. -Bundles in run level 0 are started first and bundles in run level 6 are started last. -When stopping bundles in run level 6 are stopped first and bundles in run level 0 are stopped last. -Within a run level the order of configured decides the start order; bundles added earlier are started first. - -Optional Arguments: -- LEVEL: The run level for the added bundles. Default is 3. -- INSTALL: If this option is present, the bundles will only be installed instead of the default install and start. - The bundles will be installed after all bundle in LEVEL 0..6 are installed and started. -]] -function(celix_container_embedded_bundles) - #0 is container TARGET - list(GET ARGN 0 CONTAINER_TARGET) - list(REMOVE_AT ARGN 0) - - set(OPTIONS INSTALL) - set(ONE_VAL_ARGS LEVEL) - set(MULTI_VAL_ARGS ) - cmake_parse_arguments(BUNDLES "${OPTIONS}" "${ONE_VAL_ARGS}" "${MULTI_VAL_ARGS}" ${ARGN}) - set(BUNDLES_LIST ${BUNDLES_UNPARSED_ARGUMENTS}) - - if (NOT DEFINED BUNDLES_LEVEL) - set(BUNDLES_LEVEL 3) - endif () - - if (BUNDLES_INSTALL) - get_target_property(BUNDLES ${CONTAINER_TARGET} "CONTAINER_BUNDLES_INSTALL") - else () #bundle level 0,1,2,3,4,5 or 6 - get_target_property(BUNDLES ${CONTAINER_TARGET} "CONTAINER_BUNDLES_LEVEL_${BUNDLES_LEVEL}") - endif () - - foreach(BUNDLE IN ITEMS ${BUNDLES_LIST}) - if (TARGET ${BUNDLE}) - celix_get_bundle_symbolic_name(${BUNDLE} NAME) - add_celix_bundle_dependencies(${CONTAINER_TARGET} ${BUNDLE}) - elseif (IS_ABSOLUTE ${BUNDLE} AND EXISTS ${BUNDLE}) - get_filename_component(RAW_NAME ${BUNDLE} NAME_WE) - string(MAKE_C_IDENTIFIER ${RAW_NAME} NAME) - else() - message(FATAL_ERROR "Cannot add bundle `${BUNDLE}` to container target ${CONTAINER_TARGET}. Argument is not a path or cmake target") - endif () - celix_target_embedded_bundle(${CONTAINER_TARGET} BUNDLE ${BUNDLE} NAME ${NAME}) - set(BUNDLE_TO_ADD "embedded://${NAME}") - - list(FIND BUNDLES ${BUNDLE_TO_ADD} INDEX) - if (INDEX EQUAL -1) #Note this ignores the same bundle for the same level - _celix_container_check_duplicate_bundles(${CONTAINER_TARGET} ${BUNDLE_TO_ADD} ${BUNDLES_LEVEL}) - list(APPEND BUNDLES ${BUNDLE_TO_ADD}) - endif () - endforeach() - - - - if (BUNDLES_INSTALL) - set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_BUNDLES_INSTALL" "${BUNDLES}") - else () #bundle level 0,1,2,3,4,5 or 6 - set_target_properties(${CONTAINER_TARGET} PROPERTIES "CONTAINER_BUNDLES_LEVEL_${BUNDLES_LEVEL}" "${BUNDLES}") - endif () -endfunction() - function(deploy_properties) celix_container_runtime_properties(${ARGN}) endfunction() diff --git a/cmake/cmake_celix/Generic.cmake b/cmake/cmake_celix/Generic.cmake index 1ffb80eab..f2a8782d7 100644 --- a/cmake/cmake_celix/Generic.cmake +++ b/cmake/cmake_celix/Generic.cmake @@ -48,149 +48,6 @@ function(install_celix_targets) install_celix_bundle_targets(${ARGN}) endfunction () -#[[ -Embeds a Celix bundle into a CMake target. - -```CMake -celix_target_embedded_bundle( - BUNDLE - [NAME ] -) -``` - -Example: -```CMake -celix_target_embedded_bundle(my_executable - BUNDLE Celix::shell - NAME celix_shell -) -# result in the symbols: -# - celix_embedded_bundle_celix_shell_start -# - celix_embedded_bundle_celix_shell_end -# - celix_embedded_bundles = "embedded://celix_shell" -# to be added to `my_executable` -``` - -The Celix bundle will be embedded into the CMake target between the symbols: `celix_embedded_bundle_${NAME}_start` and -`celix_embedded_bundle_${NAME}_end`. - -Also a `const char * const` symbol with the name `celix_embedded_bundles` will be added or updated containing a `,` -seperated list of embedded Celix bundle urls. The url will be: `embedded://${NAME}`. - -For Linux the linking flag `--export-dynamic` is added to ensure that the previous mentioned symbols can be retrieved -using `dlsym`. - -Mandatory Arguments: -- BUNDLE: The bundle target or bundle file (absolute path) to embed in the CMake target. - -Optional Arguments: -- NAME: The name to use when embedding the Celix bundle. This name is used in the _start and _end symbol, but also - for the embedded bundle url. - For a bundle CMake target the default is the bundle symbolic name and for a bundle file the default is the - bundle filename without extension. The NAME must be a valid C identifier. - -Bundles embedded in an executable can be installed/started using the bundle url: "embedded://${NAME}" in -combination with `celix_bundleContext_installBundle` (C) or `celix::BundleContext::installBundle` (C++). -All embedded bundle can be installed using the framework utils function -`celix_framework_utils_installEmbeddedBundles` (C) or `celix::installEmbeddedBundles` (C++). -]] -function(celix_target_embedded_bundle) - get_property(LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES) - if (NOT "ASM" IN_LIST LANGUAGES) - message(FATAL_ERROR "celix_target_embedded_bundle is only supported it the language ASM is enabled." - " Please add ASM as cmake project language.") - endif () - - list(GET ARGN 0 TARGET_NAME) - list(REMOVE_AT ARGN 0) - - set(OPTIONS) - set(ONE_VAL_ARGS BUNDLE NAME) - set(MULTI_VAL_ARGS) - cmake_parse_arguments(EMBED_BUNDLE "${OPTIONS}" "${ONE_VAL_ARGS}" "${MULTI_VAL_ARGS}" ${ARGN}) - - if (NOT EMBED_BUNDLE_BUNDLE) - message(FATAL_ERROR "Missing required BUNDLE argument") - endif () - - if (TARGET ${EMBED_BUNDLE_BUNDLE}) - celix_get_bundle_symbolic_name(${EMBED_BUNDLE_BUNDLE} DEFAULT_NAME) - celix_get_bundle_file(${EMBED_BUNDLE_BUNDLE} EMBED_BUNDLE_FILE) - add_celix_bundle_dependencies(${TARGET_NAME} ${EMBED_BUNDLE_BUNDLE}) - elseif (IS_ABSOLUTE ${EMBED_BUNDLE_BUNDLE} AND EXISTS ${EMBED_BUNDLE_BUNDLE}) - get_filename_component(RAW_NAME ${EMBED_BUNDLE_BUNDLE} NAME_WE) - string(MAKE_C_IDENTIFIER ${RAW_NAME} DEFAULT_NAME) - set(EMBED_BUNDLE_FILE ${EMBED_BUNDLE_BUNDLE}) - else () - message(FATAL_ERROR "Cannot embed bundle `${EMBED_BUNDLE_BUNDLE}` to target ${TARGET_NAME}. Argument is not a path or cmake target") - endif () - - if (NOT EMBED_BUNDLE_NAME) - set(EMBED_BUNDLE_NAME ${DEFAULT_NAME}) - endif() - - string(MAKE_C_IDENTIFIER ${EMBED_BUNDLE_NAME} EMBED_BUNDLE_NAME_CHECK) - if (NOT EMBED_BUNDLE_NAME STREQUAL EMBED_BUNDLE_NAME_CHECK) - message(FATAL_ERROR "Cannot embed bundle ${EMBED_BUNDLE_BUNDLE}, because the bundle symbolic name (${EMBED_BUNDLE_NAME}) is not a valid c identifier. Please specify an valid c identifier as embedded bundle name instead.") - endif () - - if (APPLE) - set(ASSEMBLY_FILE_IN ${CELIX_CMAKE_DIRECTORY}/templates/embed_bundle_apple.s) - else () - set(ASSEMBLY_FILE_IN ${CELIX_CMAKE_DIRECTORY}/templates/embed_bundle_linux.s) - endif () - set(ASSEMBLY_FILE "${CMAKE_BINARY_DIR}/celix/gen/target/${TARGET_NAME}/embed_bundle_${EMBED_BUNDLE_NAME}.s") - configure_file(${ASSEMBLY_FILE_IN} ${ASSEMBLY_FILE} @ONLY) - target_sources(${TARGET_NAME} PRIVATE ${ASSEMBLY_FILE}) - - get_target_property(CELIX_EMBEDDED_BUNDLES ${TARGET_NAME} "CELIX_EMBEDDED_BUNDLES") - if (NOT CELIX_EMBEDDED_BUNDLES) - set(CELIX_EMBEDDED_BUNDLES "embedded://${EMBED_BUNDLE_NAME}") - - #If executable also add symbol with a ; seperated list of embedded bundles urls - get_target_property(TYPE ${TARGET_NAME} TYPE) - if (TYPE STREQUAL "EXECUTABLE") - set(C_FILE "${CMAKE_BINARY_DIR}/celix/gen/target/${TARGET_NAME}/celix_embedded_bundles.c") - file(GENERATE OUTPUT ${C_FILE}.stage1 CONTENT "const char * const celix_embedded_bundles = \"$,$>\";") - file(GENERATE OUTPUT ${C_FILE} INPUT ${C_FILE}.stage1) - target_sources(${TARGET_NAME} PRIVATE ${C_FILE}) - endif () - - if (NOT APPLE) - #For linux ensure the --export-dynamic linking flag is added to that symbols in the main program can be found with dlsym. - target_link_libraries(${TARGET_NAME} PRIVATE -Wl,--export-dynamic) - endif () - else() - list(APPEND CELIX_EMBEDDED_BUNDLES "embedded://${EMBED_BUNDLE_NAME}") - endif() - list(REMOVE_DUPLICATES CELIX_EMBEDDED_BUNDLES) - set_target_properties(${TARGET_NAME} PROPERTIES "CELIX_EMBEDDED_BUNDLES" "${CELIX_EMBEDDED_BUNDLES}") -endfunction() - -#[[ -Embed multiple Celix bundles into a CMake target. - -```CMake -celix_target_embedded_bundles( [ ...]) -``` - -Example: -```CMake -celix_target_embedded_bundles(my_executable Celix::shell Celix::shell_tui) -``` - -The bundles will be embedded using their symbolic name if the bundle is a CMake target or their filename (without -extension) if the bundle is a file (absolute path). -]] -function(celix_target_embedded_bundles) - list(GET ARGN 0 TARGET_NAME) - list(REMOVE_AT ARGN 0) - - foreach (BUNDLE IN LISTS ARGN) - celix_target_embedded_bundle(${TARGET_NAME} BUNDLE ${BUNDLE}) - endforeach () -endfunction() - #[[ Add a compile-definition with a set of comma seperated bundles paths to a target and also adds the bundles as dependency to the target. diff --git a/cmake/cmake_celix/templates/embed_bundle_apple.s b/cmake/cmake_celix/templates/embed_bundle_apple.s deleted file mode 100644 index 613cf97b9..000000000 --- a/cmake/cmake_celix/templates/embed_bundle_apple.s +++ /dev/null @@ -1,27 +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. - */ - -.global _celix_embedded_bundle_@EMBED_BUNDLE_NAME@_start -.global _celix_embedded_bundle_@EMBED_BUNDLE_NAME@_end -.balign 64 -_celix_embedded_bundle_@EMBED_BUNDLE_NAME@_start: -.incbin "@EMBED_BUNDLE_FILE@" -.balign 64 -_celix_embedded_bundle_@EMBED_BUNDLE_NAME@_end: -.byte 0 diff --git a/cmake/cmake_celix/templates/embed_bundle_linux.s b/cmake/cmake_celix/templates/embed_bundle_linux.s deleted file mode 100644 index 2750a6e26..000000000 --- a/cmake/cmake_celix/templates/embed_bundle_linux.s +++ /dev/null @@ -1,30 +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. - */ - -.section .rodata -.global celix_embedded_bundle_@EMBED_BUNDLE_NAME@_start -.global celix_embedded_bundle_@EMBED_BUNDLE_NAME@_end -.section .rodata -.balign 64 -celix_embedded_bundle_@EMBED_BUNDLE_NAME@_start: -.incbin "@EMBED_BUNDLE_FILE@" -.balign 64 -celix_embedded_bundle_@EMBED_BUNDLE_NAME@_end: -.byte 0 -.section .note.GNU-stack,"",%progbits diff --git a/documents/cmake_commands/README.md b/documents/cmake_commands/README.md index 140bc1a4a..4cc99d663 100644 --- a/documents/cmake_commands/README.md +++ b/documents/cmake_commands/README.md @@ -361,10 +361,6 @@ Optional Arguments: - C: With this option the generated Celix launcher (if used) will be a C source. Only one of the C or CXX options can be provided. Default is CXX -- FAT: With this option only embedded bundles are allowed to be added to the container. Ensuring a container executable - this is not dependent on external bundle zip files. - Note that this option does not change anything to the container, it just ensure that all added bundles are embedded - bundles. - USE_CONFIG: With this option the config properties are generated in a 'config.properties' instead of embedded in the Celix launcher. - GROUP: If configured the build location will be prefixed the GROUP. Default is empty. @@ -374,12 +370,6 @@ Optional Arguments: - BUNDLES: A list of bundles for the Celix container to install and start. These bundle will be configured for run level 3. See 'celix_container_bundles' for more info. - INSTALL_BUNDLES: A list of bundles for the Celix container to install (but not start). -- EMBEDDED_BUNDLES: A list of bundles to embed in the Celix container (inject as binary in the executable) and - to install and start for the Celix container. - See `celix_target_embedded_bundle` for more info about embedded bundles. -- INSTALL_EMBEDDED_BUNDLES: A list of bundles to embed in the Celix container (inject as binary in the executable) and - to install (but not start) for the Celix container. - See `celix_target_embedded_bundle` for more info about embedded bundles. - PROPERTIES: A list of configuration properties, these can be used to configure the Celix framework and/or bundles. Normally this will be EMBEDED_PROPERTIES, but if the USE_CONFIG option is used this will be RUNTIME_PROPERTIES. See the framework library or bundles documentation about the available configuration options. @@ -392,15 +382,12 @@ add_celix_container( [NO_COPY] [CXX] [C] - [FAT] [USE_CONFIG] [GROUP group_name] [NAME celix_container_name] [DIR dir] [BUNDLES ...] [INSTALL_BUNDLES ...] - [EMBEDDED_BUNDLES ...] - [INSTALL_EMBEDDED_BUNDLES ...] [PROPERTIES "prop1=val1" "prop2=val2" ...] [EMBEDDED_PROPERTIES "prop1=val1" "prop2=val2" ...] [RUNTIME_PROPERTIES "prop1=val1" "prop2=val2" ...] @@ -414,15 +401,12 @@ add_celix_container( [NO_COPY] [CXX] [C] - [FAT] [USE_CONFIG] [GROUP group_name] [NAME celix_container_name] [DIR dir] [BUNDLES ...] [INSTALL_BUNDLES ...] - [EMBEDDED_BUNDLES ...] - [INSTALL_EMBEDDED_BUNDLES ...] [PROPERTIES "prop1=val1" "prop2=val2" ...] [EMBEDDED_PROPERTIES "prop1=val1" "prop2=val2" ...] [RUNTIME_PROPERTIES "prop1=val1" "prop2=val2" ...] @@ -436,15 +420,12 @@ add_celix_container( [NO_COPY] [CXX] [C] - [FAT] [USE_CONFIG] [GROUP group_name] [NAME celix_container_name] [DIR dir] [BUNDLES ...] [INSTALL_BUNDLES ...] - [EMBEDDED_BUNDLES ...] - [INSTALL_EMBEDDED_BUNDLES ...] [PROPERTIES "prop1=val1" "prop2=val2" ...] [EMBEDDED_PROPERTIES "prop1=val1" "prop2=val2" ...] [RUNTIME_PROPERTIES "prop1=val1" "prop2=val2" ...] @@ -465,20 +446,6 @@ add_celix_container(simple_container ) ``` -```CMake -#Creates a "fat" Celix container in ${CMAKE_BINARY_DIR}/deploy/simple_fat_container which starts 3 bundles embedded -#in the container executable. -add_celix_container(simple_fat_container - FAT - EMBEDDED_BUNDLES - Celix::shell - Celix::shell_tui - Celix::log_admin - PROPERTIES - CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL=debug - ) -``` - ## celix_container_bundles Add a selection of bundles to the Celix container. @@ -516,40 +483,6 @@ Optional Arguments: - NO_COPY: If this option is present, the install/start bundles will be configured using a absolute path to the bundle. This option overrides optional COPY option used in the add_celix_container call. -## celix_container_embedded_bundles -Embed a selection of bundles to the Celix container. - -```CMake -celix_container_embedded_bundles( - [LEVEL (0..6)] - [INSTALL] - bundle1 - bundle2 - ... -) -``` - -Example: -```CMake -celix_container_embedded_bundles(my_container Celix::shell Celix::shell_tui) -``` - -The selection of bundles are embedded in the container executable using the -`celix_target_embedded_bundle` Celix CMake command and are added to the configuration properties so that they are -installed and started when the Celix container is executed. - -See `celix_target_embedded_bundle` for how bundle is embedded in a executable. - -The Celix framework supports 7 (0 - 6) run levels. Run levels can be used to control the start and stop order of bundles. -Bundles in run level 0 are started first and bundles in run level 6 are started last. -When stopping bundles in run level 6 are stopped first and bundles in run level 0 are stopped last. -Within a run level the order of configured decides the start order; bundles added earlier are started first. - -Optional Arguments: -- LEVEL: The run level for the added bundles. Default is 3. -- INSTALL: If this option is present, the bundles will only be installed instead of the default install and start. - The bundles will be installed after all bundle in LEVEL 0..6 are installed and started. - ## celix_container_properties Add the provided properties to the target Celix container config properties. If the USE_CONFIG option is used these configuration properties will be added to the 'config.properties' file else they @@ -607,67 +540,6 @@ add_celix_bundle_dependencies( add_celix_bundle_dependencies(my_exec my_bundle1 my_bundle2) ``` -## celix_target_embedded_bundle -Embeds a Celix bundle into a CMake target. - -```CMake -celix_target_embedded_bundle( - BUNDLE - [NAME ] - ) -``` - -Example: -```CMake -celix_target_embedded_bundle(my_executable - BUNDLE Celix::shell - NAME celix_shell - ) -# result in the symbols: -# - celix_embedded_bundle_celix_shell_start -# - celix_embedded_bundle_celix_shell_end -# - celix_embedded_bundles = "embedded://celix_shell" -# to be added to `my_executable` -``` - -The Celix bundle will be embedded into the CMake target between the symbols: `celix_embedded_bundle_${NAME}_start` and -`celix_embedded_bundle_${NAME}_end`. - -Also a `const char * const` symbol with the name `celix_embedded_bundles` will be added or updated containing a `,` -seperated list of embedded Celix bundle urls. The url will be: `embedded://${NAME}`. - -For Linux the linking flag `--export-dynamic` is added to ensure that the previous mentioned symbols can be retrieved -using `dlsym`. - -Mandatory Arguments: -- BUNDLE: The bundle target or bundle file (absolute path) to embed in the CMake target. - -Optional Arguments: -- NAME: The name to use when embedding the Celix bundle. This name is used in the _start and _end symbol, but also - for the embedded bundle url. - For a bundle CMake target the default is the bundle symbolic name and for a bundle file the default is the - bundle filename without extension. The NAME must be a valid C identifier. - -Bundles embedded in an executable can be installed/started using the bundle url: "embedded://${NAME}" in -combination with `celix_bundleContext_installBundle` (C) or `celix::BundleContext::installBundle` (C++). -All embedded bundle can be installed using the framework utils function -`celix_framework_utils_installEmbeddedBundles` (C) or `celix::installEmbeddedBundles` (C++). - -## celix_target_embedded_bundles -Embed multiple Celix bundles into a CMake target. - -```CMake -celix_target_embedded_bundles( [ ...]) -``` - -Example: -```CMake -celix_target_embedded_bundles(my_executable Celix::shell Celix::shell_tui) -``` - -The bundles will be embedded using their symbolic name if the bundle is a CMake target or their filename (without -extension) if the bundle is a file (absolute path). - ## celix_target_bundle_set_definition Add a compile-definition with a set of comma seperated bundles paths to a target and also adds the bundles as dependency to the target. diff --git a/examples/celix-examples/CMakeLists.txt b/examples/celix-examples/CMakeLists.txt index 29e4b49db..034064fa6 100644 --- a/examples/celix-examples/CMakeLists.txt +++ b/examples/celix-examples/CMakeLists.txt @@ -41,7 +41,6 @@ if (EXAMPLES) endif () add_subdirectory(http_example) - add_subdirectory(embedding) add_subdirectory(track_tracker_example) add_subdirectory(log_service_example) add_subdirectory(bundle_with_private_lib) diff --git a/examples/celix-examples/dm_example/CMakeLists.txt b/examples/celix-examples/dm_example/CMakeLists.txt index 27334c116..44f19afa8 100644 --- a/examples/celix-examples/dm_example/CMakeLists.txt +++ b/examples/celix-examples/dm_example/CMakeLists.txt @@ -38,4 +38,4 @@ add_celix_container(dm_example PROP2=val2 PROP3=val3 ) -celix_target_embedded_bundles(dm_example Celix::shell) + diff --git a/examples/celix-examples/dm_example_cxx/CMakeLists.txt b/examples/celix-examples/dm_example_cxx/CMakeLists.txt index a2bf029f9..0e6a21d8c 100644 --- a/examples/celix-examples/dm_example_cxx/CMakeLists.txt +++ b/examples/celix-examples/dm_example_cxx/CMakeLists.txt @@ -25,7 +25,7 @@ add_subdirectory(phase3_locking) add_celix_container(dm_example_cxx FAT GROUP cxx_examples - EMBEDDED_BUNDLES + BUNDLES Celix::ShellCxx Celix::shell_tui diff --git a/examples/celix-examples/embedding/CMakeLists.txt b/examples/celix-examples/embedding/CMakeLists.txt deleted file mode 100644 index 641600d33..000000000 --- a/examples/celix-examples/embedding/CMakeLists.txt +++ /dev/null @@ -1,23 +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. - -add_executable(create_framework_in_c src/main.c) -target_link_libraries(create_framework_in_c PRIVATE Celix::framework) - -add_executable(embedding src/main.c) -target_link_libraries(embedding PRIVATE Celix::framework ) -celix_target_embedded_bundles(embedding Celix::shell Celix::shell_tui) \ No newline at end of file diff --git a/examples/celix-examples/embedding/src/launcher.c b/examples/celix-examples/embedding/src/launcher.c deleted file mode 100644 index 4e065c6de..000000000 --- a/examples/celix-examples/embedding/src/launcher.c +++ /dev/null @@ -1,23 +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 -int main(int argc, char** argv) { - return celixLauncher_launchAndWaitForShutdown(argc, argv, NULL); -} diff --git a/examples/celix-examples/embedding/src/main.c b/examples/celix-examples/embedding/src/main.c deleted file mode 100644 index 8997045ad..000000000 --- a/examples/celix-examples/embedding/src/main.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#include -#include - -int main() { - //create framework properties - celix_properties_t* properties = celix_properties_create(); - celix_properties_set(properties, "CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL", "debug"); - celix_properties_set(properties, "CELIX_BUNDLES_PATH", "bundles;/opt/alternative/bundles"); - - //create framework - celix_framework_t* fw = celix_frameworkFactory_createFramework(properties); - - //get framework bundle context and log hello - celix_bundle_context_t* fwContext = celix_framework_getFrameworkContext(fw); - celix_bundleContext_log(fwContext, CELIX_LOG_LEVEL_INFO, "Hello from framework bundle context"); - celix_bundleContext_installBundle(fwContext, "FooBundle.zip", true); - - //destroy framework - celix_frameworkFactory_destroyFramework(fw); -} diff --git a/examples/celix-examples/embedding/src/main.cc b/examples/celix-examples/embedding/src/main.cc deleted file mode 100644 index f01864ab5..000000000 --- a/examples/celix-examples/embedding/src/main.cc +++ /dev/null @@ -1,34 +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 -int main() { - //create framework properties - celix::Properties properties{}; - properties.set("CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL", "debug"); - properties.set("CELIX_BUNDLES_PATH", "bundles;/opt/alternative/bundles"); - - //create framework - std::shared_ptr fw = celix::createFramework(properties); - - //get framework bundle context and log hello - std::shared_ptr ctx = fw->getFrameworkBundleContext(); - ctx->installBundle("FooBundle.zip"); - ctx->logInfo("Hello from framework bundle context"); -} diff --git a/libs/framework/gtest/CMakeLists.txt b/libs/framework/gtest/CMakeLists.txt index 88debbbd8..9eca0896b 100644 --- a/libs/framework/gtest/CMakeLists.txt +++ b/libs/framework/gtest/CMakeLists.txt @@ -67,10 +67,6 @@ add_executable(test_framework ${CELIX_FRAMEWORK_TEST_SOURCES}) target_link_libraries(test_framework PRIVATE framework_cut GTest::gtest GTest::gtest_main) celix_deprecated_framework_headers(test_framework) - -#embed bundle in the test_framework executable -celix_target_embedded_bundles(test_framework simple_test_bundle1 simple_test_bundle2) - #Create bundle set definitions celix_target_bundle_set_definition(test_framework NAME BUNDLE_EMPTY_TEST_SET) celix_target_bundle_set_definition(test_framework NAME BUNDLE_TEST_SET @@ -150,7 +146,6 @@ if (EI_TESTS) SIMPLE_CXX_BUNDLE_LOC="${SIMPLE_CXX_BUNDLE_LOC}" ) add_celix_bundle_dependencies(test_framework_with_ei simple_test_bundle1 simple_cxx_bundle) - celix_target_embedded_bundles(test_framework_with_ei simple_test_bundle1) celix_deprecated_utils_headers(test_framework_with_ei) target_link_libraries(test_framework_with_ei PRIVATE framework_cut diff --git a/libs/framework/gtest/src/CelixFrameworkUtilsErrorInjectionTestSuite.cc b/libs/framework/gtest/src/CelixFrameworkUtilsErrorInjectionTestSuite.cc index d485c06fe..23c82d18a 100644 --- a/libs/framework/gtest/src/CelixFrameworkUtilsErrorInjectionTestSuite.cc +++ b/libs/framework/gtest/src/CelixFrameworkUtilsErrorInjectionTestSuite.cc @@ -57,22 +57,6 @@ class CelixFrameworkUtilsErrorInjectionTestSuite : public ::testing::Test { std::shared_ptr framework{}; }; -TEST_F(CelixFrameworkUtilsErrorInjectionTestSuite, testExtractEmbeddedBundle) { - const char* testExtractDir = "extractEmbeddedBundleTestDir"; - celix_utils_deleteDirectory(testExtractDir, nullptr); - - celix_ei_expect_celix_utils_extractZipData(CELIX_EI_UNKNOWN_CALLER, 0, CELIX_BUNDLE_EXCEPTION); - auto status = celix_framework_utils_extractBundle(framework->getCFramework(), "embedded://simple_test_bundle1", testExtractDir); - EXPECT_EQ(status, CELIX_BUNDLE_EXCEPTION); - celix_utils_deleteDirectory(testExtractDir, nullptr); - - celix_ei_expect_dlopen(CELIX_EI_UNKNOWN_CALLER, 0, nullptr, 2); - celix_ei_expect_dlerror(CELIX_EI_UNKNOWN_CALLER, 0, (char *)"Inject dl error"); - status = celix_framework_utils_extractBundle(framework->getCFramework(), "embedded://simple_test_bundle1", testExtractDir); - EXPECT_EQ(status, CELIX_FRAMEWORK_EXCEPTION); - celix_utils_deleteDirectory(testExtractDir, nullptr); -} - TEST_F(CelixFrameworkUtilsErrorInjectionTestSuite, testExtractFileBundle) { const char* testExtractDir = "extractFileBundleTestDir"; celix_utils_deleteDirectory(testExtractDir, nullptr); @@ -126,17 +110,4 @@ TEST_F(CelixFrameworkUtilsErrorInjectionTestSuite, testIsBundleUrlValid) { celix_ei_expect_celix_utils_strdup(CELIX_EI_UNKNOWN_CALLER, 0, nullptr); auto valid = celix_framework_utils_isBundleUrlValid(framework->getCFramework(), "non-existing.zip", false); EXPECT_FALSE(valid); - - celix_ei_expect_dlopen(CELIX_EI_UNKNOWN_CALLER, 0, nullptr); - celix_ei_expect_dlerror(CELIX_EI_UNKNOWN_CALLER, 0, (char *)"Inject dl error"); - valid = celix_framework_utils_isBundleUrlValid(framework->getCFramework(), "embedded://simple_test_bundle1", false); - EXPECT_FALSE(valid); - - celix_ei_expect_asprintf(CELIX_EI_UNKNOWN_CALLER, 0, -1); - valid = celix_framework_utils_isBundleUrlValid(framework->getCFramework(), "embedded://simple_test_bundle1", false); - EXPECT_FALSE(valid); - - celix_ei_expect_asprintf(CELIX_EI_UNKNOWN_CALLER, 0, -1, 2); - valid = celix_framework_utils_isBundleUrlValid(framework->getCFramework(), "embedded://simple_test_bundle1", false); - EXPECT_FALSE(valid); } diff --git a/libs/framework/gtest/src/CelixFrameworkUtilsTestSuite.cc b/libs/framework/gtest/src/CelixFrameworkUtilsTestSuite.cc index 2dbecd801..1aeea673f 100644 --- a/libs/framework/gtest/src/CelixFrameworkUtilsTestSuite.cc +++ b/libs/framework/gtest/src/CelixFrameworkUtilsTestSuite.cc @@ -62,18 +62,12 @@ TEST_F(CelixFrameworkUtilsTestSuite, IsBundleUrlValidTest) { valid = celix_framework_utils_isBundleUrlValid(framework->getCFramework(), "file://non-existing.zip", false); EXPECT_FALSE(valid); - valid = celix_framework_utils_isBundleUrlValid(framework->getCFramework(), "embedded://non_existing", false); - EXPECT_FALSE(valid); - valid = celix_framework_utils_isBundleUrlValid(framework->getCFramework(), SIMPLE_TEST_BUNDLE1_LOCATION, false); EXPECT_TRUE(valid); auto url = std::string{"file://"} + SIMPLE_TEST_BUNDLE1_LOCATION; valid = celix_framework_utils_isBundleUrlValid(framework->getCFramework(), url.c_str(), false); EXPECT_TRUE(valid); - - valid = celix_framework_utils_isBundleUrlValid(framework->getCFramework(), "embedded://simple_test_bundle1", false); - EXPECT_TRUE(valid); } TEST_F(CelixFrameworkUtilsTestSuite, ExtractBundlePathTest) { @@ -138,43 +132,12 @@ TEST_F(CelixFrameworkUtilsTestSuite, ExtractUncompressedBundleTest) { unlink(testLinkDir); } -TEST_F(CelixFrameworkUtilsTestSuite, ExtractEmbeddedBundleTest) { - const char* testExtractDir = "extractEmbeddedBundleTestDir"; - celix_utils_deleteDirectory(testExtractDir, nullptr); - - //invalid bundle symbol -> no extraction - auto status = celix_framework_utils_extractBundle(framework->getCFramework(), "embedded://nonexisting", testExtractDir); - EXPECT_NE(status, CELIX_SUCCESS); - - //valid bundle path -> extraction - status = celix_framework_utils_extractBundle(framework->getCFramework(), "embedded://simple_test_bundle1", testExtractDir); - EXPECT_EQ(status, CELIX_SUCCESS); - checkBundleCacheDir(testExtractDir); - celix_utils_deleteDirectory(testExtractDir, nullptr); -} - TEST_F(CelixFrameworkUtilsTestSuite, CheckBundleAgeTest) { struct timespec now = {0, 0}; EXPECT_TRUE(celix_framework_utils_isBundleUrlNewerThan(framework->getCFramework(), SIMPLE_TEST_BUNDLE1_LOCATION, &now)); EXPECT_TRUE(celix_framework_utils_isBundleUrlNewerThan(framework->getCFramework(), SIMPLE_TEST_BUNDLE1_LOCATION, nullptr)); } -TEST_F(CelixFrameworkUtilsTestSuite, testListEmbeddedBundles) { - auto list = celix::listEmbeddedBundles(); - ASSERT_EQ(2, list.size()); - EXPECT_EQ("embedded://simple_test_bundle1", list[0]); - EXPECT_EQ("embedded://simple_test_bundle2", list[1]); -} - -TEST_F(CelixFrameworkUtilsTestSuite, InstallEmbeddedBundlesTest) { - auto ids = framework->getFrameworkBundleContext()->listBundleIds(); - EXPECT_EQ(0, ids.size()); - - celix::installEmbeddedBundles(*framework, true); - ids = framework->getFrameworkBundleContext()->listBundleIds(); - EXPECT_EQ(2, ids.size()); -} - TEST_F(CelixFrameworkUtilsTestSuite, InstallBundleSetTest) { auto ids = framework->getFrameworkBundleContext()->listBundleIds(); EXPECT_EQ(0, ids.size()); diff --git a/libs/framework/gtest/src/CelixLauncherTestSuite.cc b/libs/framework/gtest/src/CelixLauncherTestSuite.cc index f7b22388f..b3a798902 100644 --- a/libs/framework/gtest/src/CelixLauncherTestSuite.cc +++ b/libs/framework/gtest/src/CelixLauncherTestSuite.cc @@ -63,19 +63,6 @@ TEST_F(CelixLauncherTestSuite, PrintHelpTest) { free(arg2); } -TEST_F(CelixLauncherTestSuite, PrintEmbeddedBundlesTest) { - //When I run the celixLauncher with "--embedded_bundles" argument - char* arg1 = celix_utils_strdup("programName"); - char* arg2 = celix_utils_strdup("--embedded_bundles"); - char* argv[] = {arg1, arg2}; - int rc = celixLauncher_launchAndWaitForShutdown(2, argv, nullptr); - - //Then it will print the embedded bundles and exit with 0 - EXPECT_EQ(rc, 0); - free(arg1); - free(arg2); -} - TEST_F(CelixLauncherTestSuite, ExtractBundlesTest) { //launch framework with bundle configured to start //Given a properties set with 2 bundles configured for start diff --git a/libs/framework/include/celix/FrameworkUtils.h b/libs/framework/include/celix/FrameworkUtils.h index d90c4b094..f0ea77e38 100644 --- a/libs/framework/include/celix/FrameworkUtils.h +++ b/libs/framework/include/celix/FrameworkUtils.h @@ -26,49 +26,6 @@ namespace celix { - /** - * @brief List the embedded bundles in the executable. - * - * This function will check if there are embedded bundles in the executable / program by trying to lookup - * the symbol `celix_embedded_bundles`. - * - * If present the `celix_embedded_bundles` should be a point to a const char* containing a `,` seperated list of - * embedded bundle urls. For example: - * \code - * const char * const celix_embedded_bundles = "embedded://bundle1,embedded://bundle2"; - * \endcode - * - * @return A vector of embedded bundle urls. - */ - inline std::vector listEmbeddedBundles() { - std::vector list{}; - auto* cList = celix_framework_utils_listEmbeddedBundles(); - list.reserve(celix_arrayList_size(cList)); - for (int i = 0; i< celix_arrayList_size(cList); ++i) { - auto* cStr = static_cast(celix_arrayList_get(cList, i)); - std::unique_ptr strGuard{cStr, free}; //ensure RAII if emplace_back throws - list.emplace_back(cStr); - } - celix_arrayList_destroy(cList); - return list; - } - - /** - * @brief Install the embedded bundles in the executable. - * - * Bundles will be installed in the order they appear in the return of - * `celix_framework_utils_listEmbeddedBundles`. - * - * If autStart is true, all embedded bundles will be installed first and then started in the same order. - * - * @param fw The Celix framework used to install the bundles. - * @param autoStart Whether to also start the installed bundles. - * @return The number of installed bundles. - */ - inline std::size_t installEmbeddedBundles(celix::Framework& framework, bool autoStart = true) { - return celix_framework_utils_installEmbeddedBundles(framework.getCFramework(), autoStart); - } - /** * @brief Install bundles to the provided framework using the provided bundle set. * diff --git a/libs/framework/include/celix_framework_utils.h b/libs/framework/include/celix_framework_utils.h index fede40c57..017605917 100644 --- a/libs/framework/include/celix_framework_utils.h +++ b/libs/framework/include/celix_framework_utils.h @@ -28,38 +28,6 @@ extern "C" { #endif -/** - * @brief List the embedded bundles in the executable. - * - * This function will check if there are embedded bundles in the executable / program by trying to lookup - * the symbol `celix_embedded_bundles`. - * - * If present the `celix_embedded_bundles` should be a point to a const char* containing a `,` seperated list of - * embedded bundle urls. For example: - * \code - * const char * const celix_embedded_bundles = "embedded://bundle1,embedded://bundle2"; - * \endcode - * - * @return A list of embedded bundle urls (char*). Caller is owner of the array list and the char* in the list. - * This function will always return w new array list. If no embedded bundles are found the size of the array - * list will be 0. - */ -CELIX_FRAMEWORK_EXPORT celix_array_list_t* celix_framework_utils_listEmbeddedBundles(); - -/** - * @brief Install the embedded bundles in the executable. - * - * Bundles will be installed in the order they appear in the return of - * `celix_framework_utils_listEmbeddedBundles`. - * - * If autStart is true, all embedded bundles will be installed first and then started in the same order. - * - * @param fw The Celix framework used to install the bundles. - * @param autoStart Whether to also start the installed bundles. - * @return The number of installed bundles. - */ -CELIX_FRAMEWORK_EXPORT size_t celix_framework_utils_installEmbeddedBundles(celix_framework_t* fw, bool autoStart); - /** * @brief Install bundles to the provided framework using the provided bundle set. * diff --git a/libs/framework/src/celix_framework_utils.c b/libs/framework/src/celix_framework_utils.c index a8489bb02..c49614069 100644 --- a/libs/framework/src/celix_framework_utils.c +++ b/libs/framework/src/celix_framework_utils.c @@ -38,11 +38,6 @@ #include "framework_private.h" #define FILE_URL_SCHEME "file://" -#define EMBEDDED_URL_SCHEME "embedded://" -static const char * const EMBEDDED_BUNDLES_SYMBOL = "celix_embedded_bundles"; -static const char * const EMBEDDED_BUNDLE_PREFIX = "celix_embedded_bundle_"; -static const char * const EMBEDDED_BUNDLE_START_POSTFIX = "_start"; -static const char * const EMBEDDED_BUNDLE_END_POSTFIX = "_end"; #define FW_LOG(level, ...) do { \ if (fw) { \ @@ -99,59 +94,6 @@ static char* celix_framework_utils_resolveFileBundleUrl(char* pathBuffer, size_t return result; } -static celix_status_t celix_framework_utils_locateEmbeddedBundle(celix_framework_t *fw, const char* bundleURL, void **start, void **end, bool silent) { - const char *errStr = NULL; - celix_status_t status = CELIX_SUCCESS; - char* startSymbol = NULL; - char* endSymbol = NULL; - void* prog = NULL; - size_t offset = sizeof(EMBEDDED_URL_SCHEME)-1; //offset to remove the EMBEDDED_URL_SCHEME part. - if(asprintf(&startSymbol, "%s%s%s", EMBEDDED_BUNDLE_PREFIX, bundleURL+offset, EMBEDDED_BUNDLE_START_POSTFIX) == -1) { - status = CELIX_ERROR_MAKE(CELIX_FACILITY_CERRNO,errno); - errStr = strerror(errno); - goto start_asprintf_error; - } - if(asprintf(&endSymbol, "%s%s%s", EMBEDDED_BUNDLE_PREFIX, bundleURL+offset, EMBEDDED_BUNDLE_END_POSTFIX) == -1) { - status = CELIX_ERROR_MAKE(CELIX_FACILITY_CERRNO,errno); - errStr = strerror(errno); - goto end_asprintf_error; - } - - prog = dlopen(NULL, RTLD_NOW); - if (prog == NULL) { - status = CELIX_FRAMEWORK_EXCEPTION; - errStr = dlerror(); - goto dlopen_error; - } - void *_start = dlsym(prog, startSymbol); - void *_end = dlsym(prog, endSymbol); - - if (_start == NULL || _end == NULL) { - status = CELIX_ILLEGAL_ARGUMENT; - errStr = dlerror(); - goto missing_symbol; - } - if (start != NULL) { - *start = _start; - } - if (end != NULL) { - *end = _end; - } -missing_symbol: -dlopen_error: - free(endSymbol); -end_asprintf_error: - free(startSymbol); -start_asprintf_error: - if (!silent) { - framework_logIfError(fw->logger, status, errStr, "Failed to locate embedded bundle symbols for bundle '%s'.", bundleURL); - } - if (prog) { - dlclose(prog); // dlclose() will invalidate previous `errStr = dlerror()` - } - return status; -} - static bool celix_framework_utils_isBundlePathNewerThan(celix_framework_t *fw, const char* bundlePath, const struct timespec* time) { struct timespec bundleModTime; char pathBuffer[CELIX_DEFAULT_STRING_CREATE_BUFFER_SIZE]; @@ -174,11 +116,8 @@ bool celix_framework_utils_isBundleUrlNewerThan(celix_framework_t* fw, const cha char* trimmedUrl = celix_utils_trim(bundleURL); bool newer; size_t fileSchemeLen = sizeof(FILE_URL_SCHEME)-1; - size_t embeddedSchemeLen = sizeof(EMBEDDED_URL_SCHEME)-1; if (strncasecmp(FILE_URL_SCHEME, trimmedUrl, fileSchemeLen) == 0) { newer = celix_framework_utils_isBundlePathNewerThan(fw, trimmedUrl + fileSchemeLen, time); //skip the file:// part - } else if (strncasecmp(EMBEDDED_URL_SCHEME, trimmedUrl, embeddedSchemeLen) == 0) { - newer = true; //for now embedded zip always considered newer } else { newer = celix_framework_utils_isBundlePathNewerThan(fw, trimmedUrl, time); } @@ -219,21 +158,6 @@ static celix_status_t celix_framework_utils_extractBundlePath(celix_framework_t return status; } -static celix_status_t celix_framework_utils_extractBundleEmbedded(celix_framework_t *fw, const char* embeddedBundle, const char* extractPath) { - FW_LOG(CELIX_LOG_LEVEL_TRACE, "Extracting embedded bundle `%s` to dir `%s`", embeddedBundle, extractPath); - void *start = NULL; - void *end = NULL; - const char* err = NULL; - - celix_status_t status = celix_framework_utils_locateEmbeddedBundle(fw, embeddedBundle, &start, &end, true); - status = CELIX_DO_IF(status, celix_utils_extractZipData(start, end-start, extractPath, &err)); - if (status == CELIX_SUCCESS) { - FW_LOG(CELIX_LOG_LEVEL_TRACE, "Embedded bundle zip `%s` extracted to `%s`", embeddedBundle, extractPath); - } - framework_logIfError(fw->logger, status, err, "Could not extract embedded bundle zip `%s` to `%s`", embeddedBundle, extractPath); - return status; -} - celix_status_t celix_framework_utils_extractBundle(celix_framework_t *fw, const char *bundleURL, const char* extractPath) { if (!celix_framework_utils_isBundleUrlValid(fw, bundleURL, false)) { return CELIX_ILLEGAL_ARGUMENT; @@ -242,11 +166,8 @@ celix_status_t celix_framework_utils_extractBundle(celix_framework_t *fw, const celix_status_t status; size_t fileSchemeLen = sizeof(FILE_URL_SCHEME)-1; - size_t embeddedSchemeLen = sizeof(EMBEDDED_URL_SCHEME)-1; if (strncasecmp(FILE_URL_SCHEME, trimmedUrl, fileSchemeLen) == 0) { status = celix_framework_utils_extractBundlePath(fw, trimmedUrl + fileSchemeLen, extractPath); - } else if (strncasecmp(EMBEDDED_URL_SCHEME, trimmedUrl, embeddedSchemeLen) == 0) { - status = celix_framework_utils_extractBundleEmbedded(fw, trimmedUrl, extractPath); } else { status = celix_framework_utils_extractBundlePath(fw, trimmedUrl, extractPath); } @@ -267,13 +188,10 @@ bool celix_framework_utils_isBundleUrlValid(celix_framework_t *fw, const char *b bool valid; char buffer[CELIX_DEFAULT_STRING_CREATE_BUFFER_SIZE]; size_t fileSchemeLen = sizeof(FILE_URL_SCHEME)-1; - size_t embeddedSchemeLen = sizeof(EMBEDDED_URL_SCHEME)-1; if (strncasecmp(FILE_URL_SCHEME, trimmedUrl, fileSchemeLen) == 0) { char* loc = celix_framework_utils_resolveFileBundleUrl(buffer, sizeof(buffer), fw, trimmedUrl + fileSchemeLen, silent); valid = loc != NULL; celix_utils_freeStringIfNotEqual(buffer, loc); - } else if (strncasecmp(EMBEDDED_URL_SCHEME, trimmedUrl, embeddedSchemeLen) == 0) { - valid = (celix_framework_utils_locateEmbeddedBundle(fw, trimmedUrl, NULL, NULL, silent) == CELIX_SUCCESS); } else if (strcasestr(trimmedUrl, "://")) { valid = false; if (!silent) { @@ -289,47 +207,6 @@ bool celix_framework_utils_isBundleUrlValid(celix_framework_t *fw, const char *b return valid; } -celix_array_list_t* celix_framework_utils_listEmbeddedBundles() { - celix_array_list_t* list = celix_arrayList_create(); - void* prog = dlopen(NULL, RTLD_NOW); - const char** embeddedBundles = dlsym(prog, EMBEDDED_BUNDLES_SYMBOL); - if (embeddedBundles != NULL) { - char delims[] = ","; - char *savePtr = NULL; - char *bundles = celix_utils_strdup(*embeddedBundles); - for (char *url = strtok_r(bundles, delims, &savePtr); url != NULL; url = strtok_r(NULL, delims, &savePtr)) { - celix_arrayList_add(list, celix_utils_strdup(url)); - } - free(bundles); - } - dlclose(prog); - return list; -} - -size_t celix_framework_utils_installEmbeddedBundles(celix_framework_t* fw, bool autoStart) { - size_t nrOfBundlesInstalled = 0; - celix_array_list_t* list = celix_framework_utils_listEmbeddedBundles(); - celix_array_list_t* bundleIds = celix_arrayList_create(); - for (int i = 0; i < celix_arrayList_size(list); ++i) { - char* url = celix_arrayList_get(list, i); - long bndId = celix_framework_installBundle(fw, url, false); - if (bndId > 0) { - nrOfBundlesInstalled += 1; - celix_arrayList_addLong(bundleIds, bndId); - } - free(url); - } - celix_arrayList_destroy(list); - - for (int i = 0; i < celix_arrayList_size(bundleIds) && autoStart; ++i) { - long bndId = celix_arrayList_getLong(bundleIds, i); - celix_framework_startBundle(fw, bndId); - } - celix_arrayList_destroy(bundleIds); - - return nrOfBundlesInstalled; -} - size_t celix_framework_utils_installBundleSet(celix_framework_t* fw, const char* bundleSet, bool autoStart) { size_t installed = 0; celix_array_list_t* bundleIds = celix_arrayList_create(); diff --git a/libs/framework/src/celix_launcher.c b/libs/framework/src/celix_launcher.c index 532e2c20f..8cf32a6f3 100644 --- a/libs/framework/src/celix_launcher.c +++ b/libs/framework/src/celix_launcher.c @@ -43,7 +43,6 @@ static celix_properties_t* celixLauncher_createConfig(const char* configFile, ce static void celixLauncher_printUsage(char* progName); static void celixLauncher_printProperties(celix_properties_t *embeddedProps, const char* configFile); -static void celixLauncher_printEmbeddedBundles(); static int celixLauncher_createBundleCache(celix_properties_t* embeddedProperties, const char* configFile); #define DEFAULT_CONFIG_FILE "config.properties" @@ -65,75 +64,70 @@ int celixLauncher_launchAndWaitForShutdown(int argc, char *argv[], celix_propert return rc; } -int celixLauncher_launchWithArgv(int argc, char *argv[], celix_properties_t* embeddedConfig, celix_framework_t** frameworkOut) { - celix_framework_t* framework = NULL; +int celixLauncher_launchWithArgv(int argc, + char* argv[], + celix_properties_t* embeddedConfig, + celix_framework_t** frameworkOut) { + celix_framework_t* framework = NULL; - // Perform some minimal command-line option parsing... - char *opt = NULL; - char* configFile = NULL; - bool showProps = false; - bool showEmbeddedBundles = false; + // Perform some minimal command-line option parsing... + char* opt = NULL; + char* configFile = NULL; + bool showProps = false; bool createCache = false; - for (int i = 1; i < argc; ++i) { - opt = argv[i]; - // Check whether the user wants some help... - if (strncmp("-?", opt, sizeof("-?")) == 0 || strncmp("-h", opt, sizeof("-h")) == 0 || strncmp("--help", opt, sizeof("--help")) == 0) { + for (int i = 1; i < argc; ++i) { + opt = argv[i]; + // Check whether the user wants some help... + if (strncmp("-?", opt, sizeof("-?")) == 0 || strncmp("-h", opt, sizeof("-h")) == 0 || + strncmp("--help", opt, sizeof("--help")) == 0) { celixLauncher_printUsage(argv[0]); celix_properties_destroy(embeddedConfig); return CELIX_LAUNCHER_OK_EXIT_CODE; } else if (strncmp("-p", opt, sizeof("-p")) == 0 || strncmp("--props", opt, sizeof("--props")) == 0) { showProps = true; - } else if (strncmp("-c", opt, sizeof("-c")) == 0 || strncmp("--create-bundle-cache", opt, sizeof("--create-bundle-cache")) == 0) { + } else if (strncmp("-c", opt, sizeof("-c")) == 0 || + strncmp("--create-bundle-cache", opt, sizeof("--create-bundle-cache")) == 0) { createCache = true; - } else if (strncmp("--embedded_bundles", opt, sizeof("--embedded_bundles")) == 0) { - showEmbeddedBundles = true; - } else { + } else { configFile = opt; - } - } + } + } - if (configFile == NULL) { + if (configFile == NULL) { configFile = DEFAULT_CONFIG_FILE; - } + } - if (embeddedConfig == NULL) { + if (embeddedConfig == NULL) { embeddedConfig = celix_properties_create(); - } + } - if (showProps) { + if (showProps) { celixLauncher_printProperties(embeddedConfig, configFile); - celix_properties_destroy(embeddedConfig); - return CELIX_LAUNCHER_OK_EXIT_CODE; - } + celix_properties_destroy(embeddedConfig); + return CELIX_LAUNCHER_OK_EXIT_CODE; + } if (createCache) { return celixLauncher_createBundleCache(embeddedConfig, configFile); } - if (showEmbeddedBundles) { - celixLauncher_printEmbeddedBundles(); - celix_properties_destroy(embeddedConfig); - return CELIX_LAUNCHER_OK_EXIT_CODE; + struct sigaction sigact; + memset(&sigact, 0, sizeof(sigact)); + sigact.sa_handler = celixLauncher_shutdownFramework; + sigaction(SIGINT, &sigact, NULL); + sigaction(SIGTERM, &sigact, NULL); + + memset(&sigact, 0, sizeof(sigact)); + sigact.sa_handler = celixLauncher_ignore; + sigaction(SIGUSR1, &sigact, NULL); + sigaction(SIGUSR2, &sigact, NULL); + + int rc = celixLauncher_launchWithConfigAndProps(configFile, &framework, embeddedConfig); + if (rc == CELIX_LAUNCHER_OK_EXIT_CODE) { + g_fw = framework; + *frameworkOut = framework; } - - struct sigaction sigact; - memset(&sigact, 0, sizeof(sigact)); - sigact.sa_handler = celixLauncher_shutdownFramework; - sigaction(SIGINT, &sigact, NULL); - sigaction(SIGTERM, &sigact, NULL); - - memset(&sigact, 0, sizeof(sigact)); - sigact.sa_handler = celixLauncher_ignore; - sigaction(SIGUSR1, &sigact, NULL); - sigaction(SIGUSR2, &sigact, NULL); - - - int rc = celixLauncher_launchWithConfigAndProps(configFile, &framework, embeddedConfig); - if (rc == CELIX_LAUNCHER_OK_EXIT_CODE) { - g_fw = framework; - *frameworkOut = framework; - } - return rc; + return rc; } static void celixLauncher_shutdownFramework(int signal) { @@ -243,20 +237,6 @@ static void celixLauncher_printProperties(celix_properties_t *embeddedProps, con celix_properties_destroy(keys); } -static void celixLauncher_printEmbeddedBundles() { - celix_array_list_t* embeddedBundles = celix_framework_utils_listEmbeddedBundles(); - printf("Embedded bundles:\n"); - for (int i = 0; i < celix_arrayList_size(embeddedBundles); ++i) { - char* bundle = celix_arrayList_get(embeddedBundles, i); - printf("|- %02i: %s\n", (i+1), bundle); - free(bundle); - } - if (celix_arrayList_size(embeddedBundles) == 0) { - printf("|- no embedded bundles\n"); - } - celix_arrayList_destroy(embeddedBundles); -} - static int celixLauncher_createBundleCache(celix_properties_t* embeddedProperties, const char* configFile) { celix_framework_t* fw = NULL; celix_properties_t* config = celixLauncher_createConfig(configFile, embeddedProperties);