From 1d593585e35d4410368f9149352431dedae26107 Mon Sep 17 00:00:00 2001
From: Gabriele Contini <contini.mailing@gmail.com>
Date: 周六, 14 12月 2019 19:17:07 +0800
Subject: [PATCH] codacy warnings

---
 .travis.yml                           |    4 +-
 src/library/locate/LocatorFactory.cpp |   12 ++++--
 README.md                             |   37 ++++++++++--------
 src/library/base/CMakeLists.txt       |   10 +++++
 4 files changed, 40 insertions(+), 23 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index ff9cbd1..4cbd109 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -63,7 +63,7 @@
              - libboost-date-time-dev
              - lcov
      before_script:
-         - cd build && cmake -DCMAKE_INSTALL_PREFIX=../../install -DCMAKE_BUILD_TYPE=Debug ..
+         - cd build && cmake -DCMAKE_INSTALL_PREFIX=../../install -DCMAKE_BUILD_TYPE=Debug -DCMAKE_BUILD_TYPE=Debug -DCODE_COVERAGE=ON ..
      script: 
          - cmake --build . --target install
          - ctest
@@ -71,7 +71,7 @@
      after_success:
          # Create lcov report
          - lcov --capture --directory . --output-file coverage.info
-         - lcov --remove coverage.info '/usr/*' --output-file coverage.info # filter system-files
+         - lcov --remove coverage.info '/usr/include/*' '*/ini/*' '*/test/*' --output-file coverage.info # filter system-files
          - lcov --list coverage.info # debug info
          # Uploading report to CodeCov
          - bash <(curl -s https://codecov.io/bash) -f coverage.info || echo "Codecov did not collect coverage reports"
diff --git a/README.md b/README.md
index 9aeba93..6d490b6 100644
--- a/README.md
+++ b/README.md
@@ -14,28 +14,28 @@
 virtualized environments. It is an Open License Manager that helps to keep your 
 software closed :smirk: . A comprehensive [list of features](https://github.com/open-license-manager/open-license-manager/wiki/features), and their status is available in the project wiki.
 
-##License
+## License
 The project is donated to the community. It comes with a very large freedom of use for everyone, and it will always be. 
 It uses a [BSD 3 clauses](https://opensource.org/licenses/BSD-3-Clause) licensing schema, that allows free modification and inclusion in commercial software. 
 
 ## Project Structure
 The software is made by 2 main sub-components:
-*  a C++ library with a nice C api, `licensecc` with minimal (or no) external dependencies (the part you have to integrate in your software) that is the project you're currently in.
-*  a license generator lcc-license-generator `lcc` for customizing the library and generate the licenses.
+-    a C++ library with a nice C api, `licensecc` with minimal (or no) external dependencies (the part you have to integrate in your software) that is the project you're currently in.
+-    a license generator lcc-license-generator `lcc` for customizing the library and generate the licenses.
  
 The following modules are planned...
-*  a license [backoffice](../../issues/7) in php (in order to handle multiple licenses).
-*  a license debugger to be sent to the final customer when there are licensing problems.
-*  a [log descriptor](../../issues/8) in order to decrypt logs generated by the license system.
+-    a license [backoffice](../../issues/7) in php (in order to handle multiple licenses).
+-    a license debugger to be sent to the final customer when there are licensing problems.
+-    a [log descriptor](../../issues/8) in order to decrypt logs generated by the license system.
 
 # How to build
 Below an overview of the basic build procedure, you can find detailed instructions for [linux](https://github.com/open-license-manager/open-license-manager/wiki/Build-the-library) or [windows](https://github.com/open-license-manager/open-license-manager/wiki/Build-the-library-windows) in the wiki. 
 
 ## Prerequisites
-*  Operating system: Linux(Ubuntu, CentOS), Windows
-*  compilers       : GCC (Linux) MINGW (Linux cross compile for Windows), MINGW or MSVC (Windows) 
-*  tools           : cmake(>3.6), git, make/ninja(linux)
-*  libs            : If target is Linux Openssl is required. Windows depends only on system libraries. Boost is necessary to build license generator and to run the tests but it's NOT a dependency of the final `licensecc` library. 
+-    Operating system: Linux(Ubuntu, CentOS), Windows
+-    compilers       : GCC (Linux) MINGW (Linux cross compile for Windows), MINGW or MSVC (Windows) 
+-    tools           : cmake(>3.6), git, make/ninja(linux)
+-    libs            : If target is Linux Openssl is required. Windows depends only on system libraries. Boost is necessary to build license generator and to run the tests but it's NOT a dependency of the final `licensecc` library. 
 
 For a complete list of dependencies and supported environments see [the wiki](https://github.com/open-license-manager/open-license-manager/wiki/Dependencies)
 
@@ -48,6 +48,7 @@
 ```
 
 ## on Linux
+
 ```console
 cmake .. -DCMAKE_INSTALL_PREFIX=../install
 make
@@ -55,37 +56,39 @@
 ```
 
 ## on Windows (with MSVC 2015)
+
 ```console
 cmake .. -G "Visual Studio 14 2015 Win64" -DBOOST_ROOT="{Folder where boost is}" -DCMAKE_INSTALL_PREFIX=../install
 cmake --build . --target install --config Release
 ```
 
 ## cross compile with MINGW on Linux
+
 ```console
 x86_64-w64-mingw32.static-cmake .. -DCMAKE_INSTALL_PREFIX=../install
 make
 make install
 ```
 
-How to test
-===========
+## How to test
 
-## on Linux
+### on Linux
+
 ```console
 make test
 ```
 
-## on Windows (MSVC)
+### on Windows (MSVC)
+
 ```console
 ctest -C Release
 ```
 
-How to use
-==========
+## How to use
 
 The [examples](https://github.com/open-license-manager/examples) repository that shows various ways to integrate `open-licence-manager` into your project.
 
 
-# How to contribute
+## How to contribute
 The project is not dead but we take our time to answer. The best interaction you can have with us is through the issue system. Have a look to the [contribution guidelines](CONTRIBUTING.md)
 We use [GitFlow](https://datasift.github.io/gitflow/IntroducingGitFlow.html) (or at least a subset of it). Remember to install the gitflow git plugin and use `develop` as default branch for your pull requests. 
diff --git a/src/library/base/CMakeLists.txt b/src/library/base/CMakeLists.txt
index 9eedd07..3582cae 100644
--- a/src/library/base/CMakeLists.txt
+++ b/src/library/base/CMakeLists.txt
@@ -6,6 +6,16 @@
     base64.c
 )
 
+if(CODE_COVERAGE AND UNIX)
+	  MESSAGE(STATUS "Enabling code coverage")
+	  target_compile_options(base PUBLIC
+	    -O0        # no optimization
+	    -g         # generate debug info
+	    --coverage # sets all required flags
+	  )
+	  target_link_libraries(base PUBLIC gcov)
+endif(CODE_COVERAGE AND UNIX)
+
 add_dependencies( base project_initialize )
 
 install(TARGETS base EXPORT licensecc ARCHIVE DESTINATION lib/${PROJECT_NAME}/${LCC_PROJECT_NAME})
diff --git a/src/library/locate/LocatorFactory.cpp b/src/library/locate/LocatorFactory.cpp
index 9b77b06..c60d4d5 100644
--- a/src/library/locate/LocatorFactory.cpp
+++ b/src/library/locate/LocatorFactory.cpp
@@ -21,14 +21,18 @@
 FUNCTION_RETURN LocatorFactory::get_active_strategies(std::vector<std::unique_ptr<LocatorStrategy>> &strategies,
 													  const LicenseLocation *locationHint) {
 	if (find_license_near_moduleb) {
-		strategies.push_back(std::unique_ptr<LocatorStrategy>((LocatorStrategy *)new ApplicationFolder()));
+		strategies.push_back(
+			std::unique_ptr<LocatorStrategy>(dynamic_cast<LocatorStrategy *>(new ApplicationFolder())));
 	}
 	if (find_license_with_env_varb) {
-		strategies.push_back(std::unique_ptr<LocatorStrategy>((LocatorStrategy *)new EnvironmentVarLocation()));
-		strategies.push_back(std::unique_ptr<LocatorStrategy>((LocatorStrategy *)new EnvironmentVarData()));
+		strategies.push_back(
+			std::unique_ptr<LocatorStrategy>(dynamic_cast<LocatorStrategy *>(new EnvironmentVarLocation())));
+		strategies.push_back(
+			std::unique_ptr<LocatorStrategy>(dynamic_cast<LocatorStrategy *>(new EnvironmentVarData())));
 	}
 	if (locationHint != nullptr) {
-		strategies.push_back(std::unique_ptr<LocatorStrategy>((LocatorStrategy *)new ExternalDefinition(locationHint)));
+		strategies.push_back(
+			std::unique_ptr<LocatorStrategy>(dynamic_cast<LocatorStrategy *>(new ExternalDefinition(locationHint))));
 	}
 	return strategies.size() > 0 ? FUNC_RET_OK : FUNC_RET_NOT_AVAIL;
 }

--
Gitblit v1.9.1