From ea8428ce6eefcfe3109d5ac73d2277fbe41fa445 Mon Sep 17 00:00:00 2001 From: AlexeyGamov Date: Thu, 12 Jan 2017 18:06:18 +0200 Subject: [PATCH] KAA-1320 Remove avrogen.sh(bat) --- client/client-multi/client-cpp/CMakeLists.txt | 22 +------ .../Modules/AvroStructGenerator.cmake | 65 ++++++++++++++++++ .../client-cpp/assembly/client-cpp-sdk.xml | 2 - client/client-multi/client-cpp/avrogen.bat | 39 ----------- client/client-multi/client-cpp/avrogen.sh | 39 ----------- .../event/AvroStructGenerator.cmake.template | 66 +++++++++++++++++++ .../templates/event/avrogen.bat_template | 39 ----------- .../templates/event/avrogen.sh_template | 39 ----------- pom.xml | 4 -- .../sdk/event/CppEventSourcesGenerator.java | 34 +++------- 10 files changed, 143 insertions(+), 206 deletions(-) create mode 100644 client/client-multi/client-cpp/Modules/AvroStructGenerator.cmake delete mode 100755 client/client-multi/client-cpp/avrogen.bat delete mode 100755 client/client-multi/client-cpp/avrogen.sh create mode 100644 client/client-multi/client-cpp/templates/event/AvroStructGenerator.cmake.template delete mode 100755 client/client-multi/client-cpp/templates/event/avrogen.bat_template delete mode 100644 client/client-multi/client-cpp/templates/event/avrogen.sh_template diff --git a/client/client-multi/client-cpp/CMakeLists.txt b/client/client-multi/client-cpp/CMakeLists.txt index e894402698..2519125fed 100644 --- a/client/client-multi/client-cpp/CMakeLists.txt +++ b/client/client-multi/client-cpp/CMakeLists.txt @@ -178,25 +178,9 @@ set(CMAKE_MODULE_PATH #Checks whether avrogen script exists set(WORKDIR ${CMAKE_CURRENT_SOURCE_DIR}) message("==================================") -if(WIN32) - set(AVROGEN "avrogen.bat") - if(NOT EXISTS "${WORKDIR}/${AVROGEN}") - message("Error: avrogen.bat hasn't been found.") - else() - execute_process(COMMAND "${AVROGEN}" - WORKING_DIRECTORY ${WORKDIR}) - endif() -else() - set(AVROGEN "avrogen.sh") - if(NOT EXISTS "${WORKDIR}/${AVROGEN}") - message("Error: avrogen.sh hasn't been found.") - else() - execute_process(COMMAND chmod +x ./${AVROGEN} - WORKING_DIRECTORY ${WORKDIR}) - execute_process(COMMAND "./${AVROGEN}" - WORKING_DIRECTORY ${WORKDIR}) - endif() -endif() + +# Generate structures according to avro schemas. +include(${CMAKE_CURRENT_SOURCE_DIR}/Modules/AvroStructGenerator.cmake) # # Sets common compilation flags. diff --git a/client/client-multi/client-cpp/Modules/AvroStructGenerator.cmake b/client/client-multi/client-cpp/Modules/AvroStructGenerator.cmake new file mode 100644 index 0000000000..d289bf960e --- /dev/null +++ b/client/client-multi/client-cpp/Modules/AvroStructGenerator.cmake @@ -0,0 +1,65 @@ +# +# Copyright 2014-2016 CyberVision, Inc. +# +# Licensed 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. +# +# This file is generated by CppEventSourcesGenerator.java +# from client-cpp/templates/event/AvroStructGenerator.cmake.template + +find_program(avrogen avrogencpp) + +if (${avrogen} STREQUAL "avrogen-NOTFOUND") + message(FATAL_ERROR "avrogen is NOT found") +else() + message("Generating necessary files according to Avro schemas") +endif() + +if (WIN32) + set(directory_separator "\\") +else() + set(directory_separator "/") +endif() + +set(avro_schemas ${CMAKE_CURRENT_SOURCE_DIR}${directory_separator}avro${directory_separator}) +set(kaa_headers ${CMAKE_CURRENT_SOURCE_DIR}${directory_separator}kaa${directory_separator}) + +file(MAKE_DIRECTORY ${avro_schemas}event ${kaa_headers}gen) + +execute_process(COMMAND ${avrogen} + -i ${avro_schemas}endpoint.avsc + -o ${kaa_headers}gen${directory_separator}EndpointGen.hpp + -n kaa) +execute_process(COMMAND ${avrogen} + -i ${avro_schemas}profile.avsc + -o ${kaa_headers}profile${directory_separator}gen${directory_separator}ProfileGen.hpp + -n kaa_profile) +execute_process(COMMAND ${avrogen} + -i ${avro_schemas}notification.avsc + -o ${kaa_headers}notification${directory_separator}gen${directory_separator}NotificationGen.hpp + -n kaa_notification) +execute_process(COMMAND ${avrogen} + -i ${avro_schemas}log.avsc + -o ${kaa_headers}log${directory_separator}gen${directory_separator}LogGen.hpp -n kaa_log) +execute_process(COMMAND ${avrogen} + -i ${avro_schemas}configuration.avsc + -o ${kaa_headers}configuration${directory_separator}gen${directory_separator}ConfigurationGen.hpp + -n kaa_configuration) + +set(event_family_classes "") + +foreach(family ${event_family_classes}) + execute_process(COMMAND ${avrogen} + -i ${avro_schemas}event${directory_separator}${family}.avsc + -o ${kaa_headers}event${directory_separator}gen${directory_separator}${family}Gen.hpp + -n ns${family}) +endforeach(family) diff --git a/client/client-multi/client-cpp/assembly/client-cpp-sdk.xml b/client/client-multi/client-cpp/assembly/client-cpp-sdk.xml index 88b78b051c..7610b8787d 100644 --- a/client/client-multi/client-cpp/assembly/client-cpp-sdk.xml +++ b/client/client-multi/client-cpp/assembly/client-cpp-sdk.xml @@ -51,8 +51,6 @@ ${project.basedir} / - avrogen.bat - avrogen.sh CMakeLists.txt README diff --git a/client/client-multi/client-cpp/avrogen.bat b/client/client-multi/client-cpp/avrogen.bat deleted file mode 100755 index 5d605ab40c..0000000000 --- a/client/client-multi/client-cpp/avrogen.bat +++ /dev/null @@ -1,39 +0,0 @@ -@REM -@REM Copyright 2014-2016 CyberVision, Inc. -@REM -@REM Licensed under the Apache License, Version 2.0 (the "License"); -@REM you may not use this file except in compliance with the License. -@REM You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, software -@REM distributed under the License is distributed on an "AS IS" BASIS, -@REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@REM See the License for the specific language governing permissions and -@REM limitations under the License. -@REM - -@echo off - -setlocal EnableDelayedExpansion - -md avro\event - -avrogencpp.exe -i avro\endpoint.avsc -o kaa\gen\EndpointGen.hpp -n kaa -avrogencpp.exe -i avro\profile.avsc -o kaa\profile\gen\ProfileGen.hpp -n kaa_profile -avrogencpp.exe -i avro\notification.avsc -o kaa\notification\gen\NotificationGen.hpp -n kaa_notification -avrogencpp.exe -i avro\log.avsc -o kaa\log\gen\LogGen.hpp -n kaa_log -avrogencpp.exe -i avro\configuration.avsc -o kaa\configuration\gen\ConfigurationGen.hpp -n kaa_configuration - -@rem List items must be sepated by space. Empty string is applicable as well. -set EVENT_CLASS_FAMILY_LIST= - -:nextVar - for /F "tokens=1* delims= " %%a in ("%EVENT_CLASS_FAMILY_LIST%") do ( - avrogencpp.exe -i avro\event\%%a.avsc -o kaa\event\gen\%%aGen.hpp -n ns%%a - set EVENT_CLASS_FAMILY_LIST=%%b - ) -if defined EVENT_CLASS_FAMILY_LIST goto nextVar - -endlocal \ No newline at end of file diff --git a/client/client-multi/client-cpp/avrogen.sh b/client/client-multi/client-cpp/avrogen.sh deleted file mode 100755 index 0b2a7fce37..0000000000 --- a/client/client-multi/client-cpp/avrogen.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/sh -# -# Copyright 2014-2016 CyberVision, Inc. -# -# Licensed 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. -# - -if (! (which avrogencpp > /dev/null)); then - echo "Error: Avrogen hasn't been installed" - exit -fi -echo "Generating necessary files according to Avro schemas" - -mkdir -p avro/event -mkdir -p kaa/gen - -avrogencpp -i avro/endpoint.avsc -o kaa/gen/EndpointGen.hpp -n kaa -avrogencpp -i avro/profile.avsc -o kaa/profile/gen/ProfileGen.hpp -n kaa_profile -avrogencpp -i avro/notification.avsc -o kaa/notification/gen/NotificationGen.hpp -n kaa_notification -avrogencpp -i avro/log.avsc -o kaa/log/gen/LogGen.hpp -n kaa_log -avrogencpp -i avro/configuration.avsc -o kaa/configuration/gen/ConfigurationGen.hpp -n kaa_configuration - -# List items must be sepated by space. Empty string is applicable as well. -EVENT_CLASS_FAMILY_LIST="" - -for FAMILY in $EVENT_CLASS_FAMILY_LIST -do - avrogencpp -i avro/event/"$FAMILY".avsc -o kaa/event/gen/"$FAMILY"Gen.hpp -n ns"$FAMILY" -done diff --git a/client/client-multi/client-cpp/templates/event/AvroStructGenerator.cmake.template b/client/client-multi/client-cpp/templates/event/AvroStructGenerator.cmake.template new file mode 100644 index 0000000000..df8a475425 --- /dev/null +++ b/client/client-multi/client-cpp/templates/event/AvroStructGenerator.cmake.template @@ -0,0 +1,66 @@ +# +# Copyright 2014-2016 CyberVision, Inc. +# +# Licensed 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. +# +# This file is generated by CppEventSourcesGenerator.java +# from client-cpp/templates/event/AvroStructGenerator.cmake.template + +find_program(avrogen avrogencpp) + +if (${avrogen} STREQUAL "avrogen-NOTFOUND") + message(FATAL_ERROR "avrogen is NOT found") +else() + message("Generating necessary files according to Avro schemas") +endif() + +if (WIN32) + set(directory_separator "\\") +else() + set(directory_separator "/") +endif() + +set(avro_schemas ${CMAKE_CURRENT_SOURCE_DIR}${directory_separator}avro${directory_separator}) +set(kaa_headers ${CMAKE_CURRENT_SOURCE_DIR}${directory_separator}kaa${directory_separator}) + +file(MAKE_DIRECTORY ${avro_schemas}event ${kaa_headers}gen) + +execute_process(COMMAND ${avrogen} + -i ${avro_schemas}endpoint.avsc + -o ${kaa_headers}gen${directory_separator}EndpointGen.hpp + -n kaa) +execute_process(COMMAND ${avrogen} + -i ${avro_schemas}profile.avsc + -o ${kaa_headers}profile${directory_separator}gen${directory_separator}ProfileGen.hpp + -n kaa_profile) +execute_process(COMMAND ${avrogen} + -i ${avro_schemas}notification.avsc + -o ${kaa_headers}notification${directory_separator}gen${directory_separator}NotificationGen.hpp + -n kaa_notification) +execute_process(COMMAND ${avrogen} + -i ${avro_schemas}log.avsc + -o ${kaa_headers}log${directory_separator}gen${directory_separator}LogGen.hpp -n kaa_log) +execute_process(COMMAND ${avrogen} + -i ${avro_schemas}configuration.avsc + -o ${kaa_headers}configuration${directory_separator}gen${directory_separator}ConfigurationGen.hpp + -n kaa_configuration) + +# [event_family_class_list] is substituted with a real list of event families during sdk generation. +set(event_family_classes [event_family_class_list]) + +foreach(family ${event_family_classes}) + execute_process(COMMAND ${avrogen} + -i ${avro_schemas}event${directory_separator}${family}.avsc + -o ${kaa_headers}event${directory_separator}gen${directory_separator}${family}Gen.hpp + -n ns${family}) +endforeach(family) diff --git a/client/client-multi/client-cpp/templates/event/avrogen.bat_template b/client/client-multi/client-cpp/templates/event/avrogen.bat_template deleted file mode 100755 index 1a7a22dba2..0000000000 --- a/client/client-multi/client-cpp/templates/event/avrogen.bat_template +++ /dev/null @@ -1,39 +0,0 @@ -@REM -@REM Copyright 2014-2016 CyberVision, Inc. -@REM -@REM Licensed under the Apache License, Version 2.0 (the "License"); -@REM you may not use this file except in compliance with the License. -@REM You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, software -@REM distributed under the License is distributed on an "AS IS" BASIS, -@REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@REM See the License for the specific language governing permissions and -@REM limitations under the License. -@REM - -@echo off - -setlocal EnableDelayedExpansion - -md avro\event - -avrogencpp.exe -i avro\endpoint.avsc -o kaa\gen\EndpointGen.hpp -n kaa -avrogencpp.exe -i avro\profile.avsc -o kaa\profile\gen\ProfileGen.hpp -n kaa_profile -avrogencpp.exe -i avro\notification.avsc -o kaa\notification\gen\NotificationGen.hpp -n kaa_notification -avrogencpp.exe -i avro\log.avsc -o kaa\log\gen\LogGen.hpp -n kaa_log -avrogencpp.exe -i avro\configuration.avsc -o kaa\configuration\gen\ConfigurationGen.hpp -n kaa_configuration - -@rem List items must be sepated by space. Empty string is applicable as well. -set EVENT_CLASS_FAMILY_LIST=${event_family_class_list} - -:nextVar - for /F "tokens=1* delims= " %%a in ("%EVENT_CLASS_FAMILY_LIST%") do ( - avrogencpp.exe -i avro\event\%%a.avsc -o kaa\event\gen\%%aGen.hpp -n ns%%a - set EVENT_CLASS_FAMILY_LIST=%%b - ) -if defined EVENT_CLASS_FAMILY_LIST goto nextVar - -endlocal \ No newline at end of file diff --git a/client/client-multi/client-cpp/templates/event/avrogen.sh_template b/client/client-multi/client-cpp/templates/event/avrogen.sh_template deleted file mode 100644 index 68c56216e3..0000000000 --- a/client/client-multi/client-cpp/templates/event/avrogen.sh_template +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -# -# Copyright 2014-2016 CyberVision, Inc. -# -# Licensed 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. -# - -if (! (which avrogencpp > /dev/null)); then - echo "Error: Avrogen hasn't been installed" - exit -fi -echo "Generating necessary files according to Avro schemas" - -mkdir -p avro/event -mkdir -p kaa/gen - -avrogencpp -i avro/endpoint.avsc -o kaa/gen/EndpointGen.hpp -n kaa -avrogencpp -i avro/profile.avsc -o kaa/profile/gen/ProfileGen.hpp -n kaa_profile -avrogencpp -i avro/notification.avsc -o kaa/notification/gen/NotificationGen.hpp -n kaa_notification -avrogencpp -i avro/log.avsc -o kaa/log/gen/LogGen.hpp -n kaa_log -avrogencpp -i avro/configuration.avsc -o kaa/configuration/gen/ConfigurationGen.hpp -n kaa_configuration - -# List items must be sepated by space. Empty string is applicable as well. -EVENT_CLASS_FAMILY_LIST="${event_family_class_list}" - -for FAMILY in $EVENT_CLASS_FAMILY_LIST -do - avrogencpp -i avro/event/"$FAMILY".avsc -o kaa/event/gen/"$FAMILY"Gen.hpp -n ns"$FAMILY" -done diff --git a/pom.xml b/pom.xml index 5e53a58cd0..a5356a6624 100644 --- a/pom.xml +++ b/pom.xml @@ -322,8 +322,6 @@ Copyright 2014-2016 CyberVision, Inc. PHP PHP PHP - BATCH - SCRIPT_STYLE @@ -347,8 +345,6 @@ Copyright 2014-2016 CyberVision, Inc. **/*.cvm **/*.hvm **/*.template - **/*.sh_template - **/*.bat_template **/sonar-project.properties diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/control/service/sdk/event/CppEventSourcesGenerator.java b/server/node/src/main/java/org/kaaproject/kaa/server/control/service/sdk/event/CppEventSourcesGenerator.java index 19487b5b54..c272ca2a3e 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/control/service/sdk/event/CppEventSourcesGenerator.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/control/service/sdk/event/CppEventSourcesGenerator.java @@ -78,11 +78,7 @@ public class CppEventSourcesGenerator { "sdk/cpp/event/eventFamilyFactoryGetConcreteEventFamily.template"; - private static final String AVROGEN_SH_TEMPLATE = "sdk/cpp/event/avrogen.sh_template"; - - - private static final String AVROGEN_BAT_TEMPLATE = "sdk/cpp/event/avrogen.bat_template"; - + private static final String AVRO_STRUCT_GENERATOR_TEMPLATE = "sdk/cpp/event/AvroStructGenerator.cmake.template"; private static final String EVENT_FAMILY_FACTORY_SET_CONCRETE_EVENT_FAMILY_NAMES_TEMPLATE = "sdk/cpp/event/eventFamilyFactorySetEventFamilyClassNames.template"; @@ -118,11 +114,9 @@ public class CppEventSourcesGenerator { private static final String EVENT_FAMILY_FACTORY_ADD_CONCRETE_EVENT_FAMILY_VAR = "\\$\\{event_family_factory_add_concrete_event_family\\}"; - private static final String EVENT_FAMILY_CLASS_LIST_VAR = "\\$\\{event_family_class_list\\}"; + private static final String EVENT_FAMILY_CLASS_LIST_VAR = "\\[event_family_class_list\\]"; private static final String EVENT_FAMILY_FACTORY_PATH = "kaa/event/gen/EventFamilyFactory.hpp"; - private static final String AVROGEN_SH_PATH = "avrogen.sh"; - private static final String AVROGEN_BAT_PATH = "avrogen.bat"; private static final String EVENT_FAMILY_PATH_TEMPLATE = "kaa/event/gen/${event_family_class_name}.hpp"; @@ -130,6 +124,8 @@ public class CppEventSourcesGenerator { private static final String EVENT_FAMILY_SCHEMA_PATH_TEMPLATE = "avro/event/${event_family_class_name}.avsc"; + private static final String AVRO_STRUCT_GENERATOR = "Modules/AvroStructGenerator.cmake"; + private static final Pattern CLASS_NAME_PATTERN = Pattern.compile(".*?([^.]+)$"); private static String eventFamilyHpp; @@ -143,8 +139,7 @@ public class CppEventSourcesGenerator { private static String eventFamilyFactoryGetEventFamily; private static String eventFamilyFactorySetEventFamilyNames; private static String eventFamilyFactoryAddEventFamily; - private static String avrogenSh; - private static String avrogenBat; + private static String avrogen; static { try { @@ -172,8 +167,7 @@ public class CppEventSourcesGenerator { eventFamilyFactoryAddEventFamily = SdkGenerator .readResource(EVENT_FAMILY_FACTORY_ADD_EVENT_FAMILY_TEMPLATE); - avrogenSh = SdkGenerator.readResource(AVROGEN_SH_TEMPLATE); - avrogenBat = SdkGenerator.readResource(AVROGEN_BAT_TEMPLATE); + avrogen = SdkGenerator.readResource(AVRO_STRUCT_GENERATOR_TEMPLATE); } catch (IOException ex) { LOG.error("Unable to initialize CppEventSourcesGenerator", ex); } @@ -313,20 +307,10 @@ public static List generateEventSources(List TarEntryData tarEntry = new TarEntryData(entry, data); eventSources.add(tarEntry); - String avrogenShSource = avrogenSh - .replaceAll(EVENT_FAMILY_CLASS_LIST_VAR, eventFamilyClassList); - - entry = new TarArchiveEntry(AVROGEN_SH_PATH); - data = avrogenShSource.getBytes(); - entry.setSize(data.length); - tarEntry = new TarEntryData(entry, data); - eventSources.add(tarEntry); - - String avrogenBatSource = avrogenBat - .replaceAll(EVENT_FAMILY_CLASS_LIST_VAR, eventFamilyClassList); + String avrogenSource = avrogen.replaceAll(EVENT_FAMILY_CLASS_LIST_VAR, eventFamilyClassList); - entry = new TarArchiveEntry(AVROGEN_BAT_PATH); - data = avrogenBatSource.getBytes(); + entry = new TarArchiveEntry(AVRO_STRUCT_GENERATOR); + data = avrogenSource.getBytes(); entry.setSize(data.length); tarEntry = new TarEntryData(entry, data); eventSources.add(tarEntry);