diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 7e525adb..acc996b2 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -71,7 +71,7 @@ jobs: run: | mkdir build cd build - cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DENABLE_QPID_CLIENT=OFF -DENABLE_QPID_MESSAGING=ON -DENABLE_QPID_PROTON=ON -DBUILD_WITH_UNIT_TESTS=ON + cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DENABLE_MODERN=ON -DENABLE_QPID_CLIENT=OFF -DENABLE_QPID_MESSAGING=ON -DENABLE_QPID_PROTON=ON -DBUILD_WITH_UNIT_TESTS=ON make - name: Perform CodeQL Analysis diff --git a/CMakeLists.txt b/CMakeLists.txt index 9270a76d..c9977213 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,7 @@ endif (WIN32) set(ENABLE_QPID_PROTON ON CACHE BOOL "Enable qpid proton clients") set(ENABLE_QPID_MESSAGING ON CACHE BOOL "Enable qpid messaging clients") +set(ENABLE_MODERN ON CACHE BOOL "Enable usage of refactored code") set(BUILD_WITH_UNIT_TESTS OFF CACHE BOOL "Build unit tests for the CPP client code") if (NOT WIN32) @@ -168,6 +169,14 @@ if (BUILD_WITH_UNIT_TESTS) set (CTEST_BINARY_DIRECTORY ${CMAKE_BINARY_DIR}/target/tests/bin) endif (BUILD_WITH_UNIT_TESTS) +if (ENABLE_MODERN) + add_definitions(-DENABLE_MODERN) +else (ENABLE_MODERN) + if (ENABLE_QPID_PROTON) + message(FATAL_ERROR "Modern code is a requirement for proton code") + endif(ENABLE_QPID_PROTON) +endif(ENABLE_MODERN) + add_subdirectory(src/contrib) add_subdirectory(src/common) @@ -185,7 +194,7 @@ set(CPPCHECK_EXECUTABLE "/usr/bin/cppcheck" CACHE STRING "Path to cppcheck") set(CPPCHECK_FLAGS "--report-progress" "-v" "--enable=all" "--xml" CACHE STRING "Options for cppcheck") -set(CPPCHECK_DEFS "-DENABLE_PROTON" "-DENABLE_QPID_MESSAGING" +set(CPPCHECK_DEFS "-DENABLE_MODERN" "-DENABLE_PROTON" "-DENABLE_QPID_MESSAGING" "-DQPIDSYSEPOCH" CACHE STRING "Defines for cppcheck") add_custom_target(check diff --git a/README.md b/README.md index 8aaae532..854b2670 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,9 @@ sudo make install ; These variables apply to all code base and may affect what code is built with along with the project. For example, they may enable refactored code. +* ENABLE_MODERN: Enable new and/or refactored code. It is a requirement for -DENABLE_QPID_PROTON. +Default: off + #### Boost libraries @@ -93,7 +96,7 @@ for some older RHEL/qpid versions. Default: false. These variables affect only the QPID Proton clients. * ENABLE_QPID_PROTON: Enable qpid proton messaging/reactor clients (eg.: aac3 -and aac4). +and aac4). This variable requires ENABLE_MODERN. * PROTON_DIR: QPID Proton base directory. @@ -106,14 +109,14 @@ RHEL >= 6, with QPID Proton clients, using a non-standard QPID Proton directory ``` cmake -DENABLE_QPID_PROTON=ON -DPROTON_DIR=/opt/devel/qpid-proton \ - -DCMAKE_CXX_COMPILER=`which c++` . + -DENABLE_MODERN=ON -DCMAKE_CXX_COMPILER=`which c++` . ``` RHEL 5.11 without QPID Proton and disabled unit tests ``` cmake -DENABLE_QPID_PROTON=ON -DPROTON_DIR=/opt/devel/qpid-proton \ - -DCMAKE_CXX_COMPILER=`which c++` \ + -DENABLE_MODERN=ON -DCMAKE_CXX_COMPILER=`which c++` \ -DCMAKE_VERBOSE_MAKEFILE=OFF -DBUILD_WITH_UNIT_TESTS=OFF \ -DQPID_WITH_GET_CONTENT_OBJECT=ON \ -DBoost_INCLUDE_DIRS=/usr/include/boost141/ \ @@ -124,7 +127,7 @@ RHEL 5.11 with QPID Proton and disabled unit tests ``` cmake -DENABLE_QPID_PROTON=ON -DPROTON_DIR=/opt/devel/qpid-proton \ - -DCMAKE_CXX_COMPILER=`which c++` ` + -DENABLE_MODERN=ON -DCMAKE_CXX_COMPILER=`which c++` ` -DCMAKE_VERBOSE_MAKEFILE=OFF -DBUILD_WITH_UNIT_TESTS=OFF ` -DQPID_WITH_GET_CONTENT_OBJECT=ON ` -DBoost_INCLUDE_DIRS=/usr/include/boost141/ ` diff --git a/dist/dtests-rhel-cpp.spec b/dist/dtests-rhel-cpp.spec index 2c79f29b..a7aaaa16 100644 --- a/dist/dtests-rhel-cpp.spec +++ b/dist/dtests-rhel-cpp.spec @@ -35,9 +35,9 @@ C++ clients, tools and runtime libraries %build %ifarch x86_64 -cmake -DCMAKE_BUILD_TYPE=RELEASE -DENABLE_QPID_CLIENT=OFF -DENABLE_QPID_MESSAGING=ON -DENABLE_QPID_PROTON=ON -DBUILD_WITH_UNIT_TESTS=ON -DCMAKE_INSTALL_PREFIX=%{buildroot}/opt/dtests +cmake -DCMAKE_BUILD_TYPE=RELEASE -DENABLE_MODERN=ON -DENABLE_QPID_CLIENT=OFF -DENABLE_QPID_MESSAGING=ON -DENABLE_QPID_PROTON=ON -DBUILD_WITH_UNIT_TESTS=ON -DCMAKE_INSTALL_PREFIX=%{buildroot}/opt/dtests %else -cmake -DCMAKE_BUILD_TYPE=RELEASE -DENABLE_QPID_CLIENT=OFF -DENABLE_QPID_MESSAGING=OFF -DENABLE_QPID_PROTON=ON -DBUILD_WITH_UNIT_TESTS=ON -DCMAKE_INSTALL_PREFIX=%{buildroot}/opt/dtests +cmake -DCMAKE_BUILD_TYPE=RELEASE -DENABLE_MODERN=ON -DENABLE_QPID_CLIENT=OFF -DENABLE_QPID_MESSAGING=OFF -DENABLE_QPID_PROTON=ON -DBUILD_WITH_UNIT_TESTS=ON -DCMAKE_INSTALL_PREFIX=%{buildroot}/opt/dtests %endif make diff --git a/src/api/qpid/CMakeLists.txt b/src/api/qpid/CMakeLists.txt index c952a212..23dcdda8 100644 --- a/src/api/qpid/CMakeLists.txt +++ b/src/api/qpid/CMakeLists.txt @@ -65,7 +65,6 @@ target_link_libraries( dtests-qpid-messaging-common ${Qpid_LIBRARIES} - ${ProtonCpp_LIBRARIES} dtests-cpp-legacy boost_regex # would be `Boost::regex` in new CMake ${qpid_client_link_libraries} @@ -127,9 +126,11 @@ foreach(client ${qpid_messaging_clients}) endforeach(client) -if (BUILD_WITH_UNIT_TESTS) - add_subdirectory(common/formatter/test) -endif (BUILD_WITH_UNIT_TESTS) +if (ENABLE_MODERN) + if (BUILD_WITH_UNIT_TESTS) + add_subdirectory(common/formatter/test) + endif (BUILD_WITH_UNIT_TESTS) +endif (ENABLE_MODERN) install(TARGETS diff --git a/src/api/qpid/common/formatter/FormatUtil.cpp b/src/api/qpid/common/formatter/FormatUtil.cpp index 7b42ece1..6063b653 100644 --- a/src/api/qpid/common/formatter/FormatUtil.cpp +++ b/src/api/qpid/common/formatter/FormatUtil.cpp @@ -7,20 +7,30 @@ namespace messaging { using std::cout; void printMessageUpstream(const Message &message, bool verbose) { - QpidDecoder decoder = QpidDecoder(message); - - std::ostringstream stream; - UpstreamWriter writer = UpstreamWriter(&stream); - - UpstreamFormatter formatter = UpstreamFormatter(); - formatter.printMessage(&decoder, &writer); - - writer.endLine(); - std::cout << writer.toString(); +#ifdef ENABLE_MODERN + QpidDecoder decoder = QpidDecoder(message); + + std::ostringstream stream; + UpstreamWriter writer = UpstreamWriter(&stream); + + UpstreamFormatter formatter = UpstreamFormatter(); + formatter.printMessage(&decoder, &writer); + + writer.endLine(); + std::cout << writer.toString(); + +#else + Formatter formatter; + + Message tmp = const_cast(message); + + formatter.printMessage(tmp, verbose); +#endif // ENABLE_MODERN } void printMessageDict(const Message &message) { +#ifdef ENABLE_MODERN QpidDecoder decoder = QpidDecoder(message); std::ostringstream stream; @@ -31,6 +41,13 @@ void printMessageDict(const Message &message) { writer.endLine(); std::cout << writer.toString(); +#else + Formatter formatter; + + Message tmp = const_cast(message); + + formatter.printMessageAsDict(tmp); +#endif // ENABLE_MODERN } std::string formatBool(const bool b) { @@ -337,6 +354,7 @@ void printMessageInterop(const Message &message) { } void printStatistics(const Message &message, const Variant::Map &stats) { +#ifdef ENABLE_MODERN /* * NOTE: this is *not* the best way to solve this problem and I will * implement a more elegant design in the future @@ -348,6 +366,13 @@ void printStatistics(const Message &message, const Variant::Map &stats) { DictFormatter formatter = DictFormatter(); formatter.printStatistics(&decoder, &writer, stats); +#else + Formatter formatter; + + Variant::Map tmp = const_cast(stats); + + formatter.printStatistics(tmp); +#endif // ENABLE_MODERN } }}} diff --git a/src/api/qpid/common/formatter/FormatUtil.h b/src/api/qpid/common/formatter/FormatUtil.h index f385ef47..55b110db 100644 --- a/src/api/qpid/common/formatter/FormatUtil.h +++ b/src/api/qpid/common/formatter/FormatUtil.h @@ -21,6 +21,7 @@ #include #include +#ifdef ENABLE_MODERN #include "formatter/DictFormatter.h" #include "formatter/DictWriter.h" @@ -28,6 +29,9 @@ #include "formatter/UpstreamWriter.h" #include "QpidDecoder.h" +#else + #include "Formatter.h" +#endif // ENABLE_MODERN using qpid::messaging::Message; using qpid::types::Variant; diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index ca1f9ff9..2ceed631 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -13,40 +13,43 @@ include_directories( common/options/modern ) -set(COMMON_MODERN_SRC - output/Printer.cpp - exceptions/BaseException.cpp - exceptions/IOException.cpp - exceptions/TimerExpiredException.cpp - options/BaseOptionsParser.cpp - options/OptionsHelper.cpp - formatter/Writer.cpp - formatter/DictWriter.cpp - formatter/UpstreamWriter.cpp - formatter/AbstractDecoder.cpp - formatter/AbstractFormatter.cpp - formatter/DictFormatter.cpp - formatter/UpstreamFormatter.cpp - logger/Logger.cpp - logger/LoggerWrapper.cpp - - Timer.cpp - UriParser.cpp - Client.cpp - ContentType.cpp - MessageHeader.cpp -) - -if (BUILD_WITH_UNIT_TESTS) - set(TEST_SUPPORT_SRC - TestUtils.cpp +if (ENABLE_MODERN) + set(COMMON_MODERN_SRC + output/Printer.cpp + exceptions/BaseException.cpp + exceptions/IOException.cpp + exceptions/TimerExpiredException.cpp + options/BaseOptionsParser.cpp + options/OptionsHelper.cpp + formatter/Writer.cpp + formatter/DictWriter.cpp + formatter/UpstreamWriter.cpp + formatter/AbstractDecoder.cpp + formatter/AbstractFormatter.cpp + formatter/DictFormatter.cpp + formatter/UpstreamFormatter.cpp + logger/Logger.cpp + logger/LoggerWrapper.cpp + + Timer.cpp + UriParser.cpp + Client.cpp + ContentType.cpp + MessageHeader.cpp ) + if (BUILD_WITH_UNIT_TESTS) + set(TEST_SUPPORT_SRC + TestUtils.cpp + ) + add_subdirectory(test) - add_subdirectory(output/test) - add_subdirectory(logger/test) - add_subdirectory(options/test) -endif (BUILD_WITH_UNIT_TESTS) + add_subdirectory(output/test) + add_subdirectory(logger/test) + add_subdirectory(options/test) + endif (BUILD_WITH_UNIT_TESTS) + +endif (ENABLE_MODERN) add_library(dtests-cpp-common ${COMMON_MODERN_SRC} @@ -55,9 +58,6 @@ add_library(dtests-cpp-common Utils.cpp ) -target_include_directories(dtests-cpp-common - PRIVATE ${PROTON_INCLUDE_DIR} -) if (WIN32) target_link_libraries(dtests-cpp-common) else (WIN32)