This is an automated email from the ASF dual-hosted git repository.

aldrin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git


The following commit(s) were added to refs/heads/master by this push:
     new 48484e7  MINIFICPP-280: Adding extension linters
48484e7 is described below

commit 48484e7fa4015dcafb9321e14a103f3fdbbaf1f3
Author: Marc Parisi <[email protected]>
AuthorDate: Thu May 16 09:20:36 2019 -0400

    MINIFICPP-280: Adding extension linters
    
    Based entirely upon prior work of calebj in
    https://github.com/apache/nifi-minifi-cpp/pull/168
    
    He gets full credit for this, but since I'm applying the work to a
    different branch we can't just pull the commits. Original message:
    
    MINIFI-280 Move extension tests and headers, lint extensions
    
        move extension tests into their respective folders
        separate source and header files
        remove unnecessary or nonexisting include directories
        run linter on extension source files as part of linter target
        clean up extensions according to linter
        add ability to specify more than one include and source folder for 
linter
    
    This closes #555.
    This closes #168.
    
    Signed-off-by: Aldrin Piri <[email protected]>
---
 CMakeLists.txt                                     |  14 ++-
 cmake/Extensions.cmake                             |  13 +++
 extensions/standard-processors/CMakeLists.txt      |   3 +
 .../processors/GenerateFlowFile.cpp                |   4 +-
 .../processors/LogAttribute.cpp                    |   4 +-
 .../standard-processors/processors/PutFile.cpp     |   3 +-
 .../tests/integration/SecureSocketGetTCPTest.cpp   |   4 +-
 .../tests/integration/TailFileCronTest.cpp         |   4 +-
 .../tests/integration/TailFileTest.cpp             |   4 +-
 .../tests/integration/TestExecuteProcess.cpp       |  11 ++-
 .../tests/unit/ManifestTests.cpp                   |   1 -
 .../tests/unit/ProcessorTests.cpp                  | 102 ++++++++++-----------
 .../tests/unit/TailFileTests.cpp                   |   3 +-
 .../tests/unit/YamlConfigurationTests.cpp          |   2 +-
 thirdparty/google-styleguide/run_linter.sh         |  32 +++++--
 15 files changed, 122 insertions(+), 82 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8066a33..3f74bfa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -708,10 +708,18 @@ include(BuildDocs)
 
 include(DockerConfig)
 
+if(NOT WIN32)
 # Create a custom build target that will run the linter.
-add_custom_target(
-        linter
-        COMMAND ${CMAKE_SOURCE_DIR}/thirdparty/google-styleguide/run_linter.sh 
${CMAKE_SOURCE_DIR}/libminifi )
+get_property(extensions GLOBAL PROPERTY EXTENSION-LINTERS)
+add_custom_target(linter
+    COMMAND ${CMAKE_SOURCE_DIR}/thirdparty/google-styleguide/run_linter.sh
+            ${CMAKE_SOURCE_DIR}/libminifi/include/ --
+            ${CMAKE_SOURCE_DIR}/libminifi/src/
+    COMMAND ${CMAKE_SOURCE_DIR}/thirdparty/google-styleguide/run_linter.sh
+            ${CMAKE_SOURCE_DIR}/libminifi/include/ --
+            ${CMAKE_SOURCE_DIR}/libminifi/test/
+    DEPENDS ${extensions})
+endif(NOT WIN32)
 
 # Custom target to download and run Apache Release Audit Tool (RAT)
 add_custom_target(
diff --git a/cmake/Extensions.cmake b/cmake/Extensions.cmake
index 05daeea..02816d8 100644
--- a/cmake/Extensions.cmake
+++ b/cmake/Extensions.cmake
@@ -64,3 +64,16 @@ function(createExtension extensionGuard extensionName 
description dirName)
                endif()
     endif()
 endfunction()
+
+
+macro(register_extension_linter target-name)
+if (NOT WIN32)
+    get_property(extensions GLOBAL PROPERTY EXTENSION-LINTERS)
+    set_property(GLOBAL APPEND PROPERTY EXTENSION-LINTERS "${target-name}")
+    add_custom_target(${target-name}
+    COMMAND ${CMAKE_SOURCE_DIR}/thirdparty/google-styleguide/run_linter.sh
+            ${CMAKE_SOURCE_DIR}/libminifi/include/
+            ${CMAKE_CURRENT_LIST_DIR}/ --
+            ${CMAKE_CURRENT_LIST_DIR}/)
+endif(NOT WIN32)
+endmacro()
\ No newline at end of file
diff --git a/extensions/standard-processors/CMakeLists.txt 
b/extensions/standard-processors/CMakeLists.txt
index dcba19a..7691c78 100644
--- a/extensions/standard-processors/CMakeLists.txt
+++ b/extensions/standard-processors/CMakeLists.txt
@@ -35,3 +35,6 @@ endif()
 
 SET (STANDARD-PROCESSORS minifi-standard-processors PARENT_SCOPE)
 register_extension(minifi-standard-processors)
+
+
+register_extension_linter(minifi-standard-processors-linter)
diff --git a/extensions/standard-processors/processors/GenerateFlowFile.cpp 
b/extensions/standard-processors/processors/GenerateFlowFile.cpp
index 8a2e03b..f4b8f20 100644
--- a/extensions/standard-processors/processors/GenerateFlowFile.cpp
+++ b/extensions/standard-processors/processors/GenerateFlowFile.cpp
@@ -19,14 +19,14 @@
  */
 #include "GenerateFlowFile.h"
 #include <time.h>
+#include <chrono>
+#include <thread>
 #include <vector>
 #include <queue>
 #include <map>
 #include <memory>
 #include <string>
 #include <set>
-#include <chrono>
-#include <thread>
 #include <random>
 #ifdef WIN32
 #define srandom srand
diff --git a/extensions/standard-processors/processors/LogAttribute.cpp 
b/extensions/standard-processors/processors/LogAttribute.cpp
index a02bafe..2309d0e 100644
--- a/extensions/standard-processors/processors/LogAttribute.cpp
+++ b/extensions/standard-processors/processors/LogAttribute.cpp
@@ -39,8 +39,8 @@ namespace nifi {
 namespace minifi {
 namespace processors {
 
-core::Property 
LogAttribute::LogLevel(core::PropertyBuilder::createProperty("Log 
Level")->withDescription("The Log Level to use when logging the 
Attributes")->withAllowableValues<std::string>( {
-    "info", "trace", "error", "warn", "debug" })->build());
+core::Property 
LogAttribute::LogLevel(core::PropertyBuilder::createProperty("Log 
Level")->withDescription("The Log Level to use when logging the 
Attributes")->withAllowableValues<std::string>(
+    {"info", "trace", "error", "warn", "debug" })->build());
 
 core::Property LogAttribute::AttributesToLog(
     core::PropertyBuilder::createProperty("Attributes to 
Log")->withDescription("A comma-separated list of Attributes to Log. If not 
specified, all attributes will be logged.")->build());
diff --git a/extensions/standard-processors/processors/PutFile.cpp 
b/extensions/standard-processors/processors/PutFile.cpp
index acd0442..a7adaa1 100644
--- a/extensions/standard-processors/processors/PutFile.cpp
+++ b/extensions/standard-processors/processors/PutFile.cpp
@@ -19,7 +19,6 @@
  */
 
 #include "PutFile.h"
-#include "utils/file/FileUtils.h"
 #include <sys/stat.h>
 #include <uuid/uuid.h>
 #include <cstdint>
@@ -31,7 +30,7 @@
 #ifdef WIN32
 #include <Windows.h>
 #endif
-
+#include "utils/file/FileUtils.h"
 #ifndef S_ISDIR
 #define S_ISDIR(mode)  (((mode) & S_IFMT) == S_IFDIR)
 #endif
diff --git 
a/extensions/standard-processors/tests/integration/SecureSocketGetTCPTest.cpp 
b/extensions/standard-processors/tests/integration/SecureSocketGetTCPTest.cpp
index aefcf55..e3a0478 100644
--- 
a/extensions/standard-processors/tests/integration/SecureSocketGetTCPTest.cpp
+++ 
b/extensions/standard-processors/tests/integration/SecureSocketGetTCPTest.cpp
@@ -17,14 +17,14 @@
  */
 #include <signal.h>
 #include <sys/stat.h>
+#include <chrono>
+#include <thread>
 #undef NDEBUG
 #include <cassert>
 #include <utility>
-#include <chrono>
 #include <fstream>
 #include <memory>
 #include <string>
-#include <thread>
 #include <type_traits>
 #include <vector>
 #include <iostream>
diff --git 
a/extensions/standard-processors/tests/integration/TailFileCronTest.cpp 
b/extensions/standard-processors/tests/integration/TailFileCronTest.cpp
index 3432070..2b5ee77 100644
--- a/extensions/standard-processors/tests/integration/TailFileCronTest.cpp
+++ b/extensions/standard-processors/tests/integration/TailFileCronTest.cpp
@@ -17,14 +17,14 @@
  */
 
 #include <sys/stat.h>
+#include <chrono>
+#include <thread>
 #undef NDEBUG
 #include <cassert>
 #include <utility>
-#include <chrono>
 #include <fstream>
 #include <memory>
 #include <string>
-#include <thread>
 #include <type_traits>
 #include <vector>
 #include <iostream>
diff --git a/extensions/standard-processors/tests/integration/TailFileTest.cpp 
b/extensions/standard-processors/tests/integration/TailFileTest.cpp
index 3432070..2b5ee77 100644
--- a/extensions/standard-processors/tests/integration/TailFileTest.cpp
+++ b/extensions/standard-processors/tests/integration/TailFileTest.cpp
@@ -17,14 +17,14 @@
  */
 
 #include <sys/stat.h>
+#include <chrono>
+#include <thread>
 #undef NDEBUG
 #include <cassert>
 #include <utility>
-#include <chrono>
 #include <fstream>
 #include <memory>
 #include <string>
-#include <thread>
 #include <type_traits>
 #include <vector>
 #include <iostream>
diff --git 
a/extensions/standard-processors/tests/integration/TestExecuteProcess.cpp 
b/extensions/standard-processors/tests/integration/TestExecuteProcess.cpp
index 7c5e458..2c8cdf8 100644
--- a/extensions/standard-processors/tests/integration/TestExecuteProcess.cpp
+++ b/extensions/standard-processors/tests/integration/TestExecuteProcess.cpp
@@ -16,14 +16,15 @@
  * limitations under the License.
  */
 
+
+#include <type_traits> //NOLINT
+#include <sys/stat.h> //NOLINT
+#include <uuid/uuid.h> //NOLINT
+#include <chrono> //NOLINT
+#include <thread> //NOLINT
 #undef NDEBUG
 #include <cassert>
-#include <chrono>
 #include <string>
-#include <thread>
-#include <type_traits>
-#include <sys/stat.h>
-#include <uuid/uuid.h>
 #include <utility>
 #include <memory>
 #include <vector>
diff --git a/extensions/standard-processors/tests/unit/ManifestTests.cpp 
b/extensions/standard-processors/tests/unit/ManifestTests.cpp
index 962c869..d261e4d 100644
--- a/extensions/standard-processors/tests/unit/ManifestTests.cpp
+++ b/extensions/standard-processors/tests/unit/ManifestTests.cpp
@@ -22,7 +22,6 @@
 #include "core/state/nodes/AgentInformation.h"
 #include "TestBase.h"
 #include "io/ClientSocket.h"
-#include "core/Processor.h"
 #include "core/ClassLoader.h"
 
 TEST_CASE("Test Required", "[required]") {
diff --git a/extensions/standard-processors/tests/unit/ProcessorTests.cpp 
b/extensions/standard-processors/tests/unit/ProcessorTests.cpp
index 5d7edd6..afbc22f 100644
--- a/extensions/standard-processors/tests/unit/ProcessorTests.cpp
+++ b/extensions/standard-processors/tests/unit/ProcessorTests.cpp
@@ -266,80 +266,78 @@ TEST_CASE("LogAttributeTestInvalid", 
"[TestLogAttribute]") {
 
   plan->setProperty(getfile, 
org::apache::nifi::minifi::processors::GetFile::Directory.getName(), dir);
   plan->setProperty(getfile, 
org::apache::nifi::minifi::processors::GetFile::BatchSize.getName(), "1");
-  REQUIRE_THROWS_AS( plan->setProperty(loggattr, 
org::apache::nifi::minifi::processors::LogAttribute::FlowFilesToLog.getName(), 
"-1"),std::out_of_range);
+  REQUIRE_THROWS_AS(plan->setProperty(loggattr, 
org::apache::nifi::minifi::processors::LogAttribute::FlowFilesToLog.getName(), 
"-1"), std::out_of_range);
   LogTestController::getInstance().reset();
 }
 
-void testMultiplesLogAttribute(int fileCount, int flowsToLog, std::string 
verifyStringFlowsLogged = ""){
+void testMultiplesLogAttribute(int fileCount, int flowsToLog, std::string 
verifyStringFlowsLogged = "") {
   TestController testController;
-    
LogTestController::getInstance().setTrace<minifi::processors::LogAttribute>();
-    LogTestController::getInstance().setDebug<minifi::processors::GetFile>();
-
-    std::shared_ptr<TestPlan> plan = testController.createPlan();
-    std::shared_ptr<core::Processor> getfile = plan->addProcessor("GetFile", 
"getfileCreate2");
-
-    auto loggattr = plan->addProcessor("LogAttribute", "logattribute", 
core::Relationship("success", "description"), true);
-
-    char format[] = "/tmp/gt.XXXXXX";
-    char *dir = testController.createTempDirectory(format);
-
-    auto flowsToLogStr = std::to_string(flowsToLog);
-    if ( verifyStringFlowsLogged.empty() )
-      verifyStringFlowsLogged = std::to_string(flowsToLog);
-    plan->setProperty(getfile, 
org::apache::nifi::minifi::processors::GetFile::Directory.getName(), dir);
-    plan->setProperty(getfile, 
org::apache::nifi::minifi::processors::GetFile::BatchSize.getName(), 
std::to_string(fileCount));
-    plan->setProperty(loggattr, 
org::apache::nifi::minifi::processors::LogAttribute::FlowFilesToLog.getName(), 
flowsToLogStr);
-    testController.runSession(plan, false);
-    auto records = plan->getProvenanceRecords();
-    std::shared_ptr<core::FlowFile> record = plan->getCurrentFlowFile();
-    REQUIRE(record == nullptr);
-    REQUIRE(records.size() == 0);
+  
LogTestController::getInstance().setTrace<minifi::processors::LogAttribute>();
+  LogTestController::getInstance().setDebug<minifi::processors::GetFile>();
 
-    std::vector<std::string> files;
+  std::shared_ptr<TestPlan> plan = testController.createPlan();
+  std::shared_ptr<core::Processor> getfile = plan->addProcessor("GetFile", 
"getfileCreate2");
 
-    for (int i = 0; i < fileCount; i++) {
-      std::fstream file;
-      std::stringstream ss;
-      ss << dir << "/" << "tstFile" << i << ".ext";
-      file.open(ss.str(), std::ios::out);
-      file << "tempFile";
-      file.close();
+  auto loggattr = plan->addProcessor("LogAttribute", "logattribute", 
core::Relationship("success", "description"), true);
 
+  char format[] = "/tmp/gt.XXXXXX";
+  char *dir = testController.createTempDirectory(format);
 
-      files.push_back(ss.str());
-    }
+  auto flowsToLogStr = std::to_string(flowsToLog);
+  if (verifyStringFlowsLogged.empty())
+    verifyStringFlowsLogged = std::to_string(flowsToLog);
+  plan->setProperty(getfile, 
org::apache::nifi::minifi::processors::GetFile::Directory.getName(), dir);
+  plan->setProperty(getfile, 
org::apache::nifi::minifi::processors::GetFile::BatchSize.getName(), 
std::to_string(fileCount));
+  plan->setProperty(loggattr, 
org::apache::nifi::minifi::processors::LogAttribute::FlowFilesToLog.getName(), 
flowsToLogStr);
+  testController.runSession(plan, false);
+  auto records = plan->getProvenanceRecords();
+  std::shared_ptr<core::FlowFile> record = plan->getCurrentFlowFile();
+  REQUIRE(record == nullptr);
+  REQUIRE(records.size() == 0);
 
-    plan->reset();
-    testController.runSession(plan, false);
+  std::vector<std::string> files;
 
-    for (const auto &created_file : files) {
-      unlink(created_file.c_str());
-    }
+  for (int i = 0; i < fileCount; i++) {
+    std::fstream file;
+    std::stringstream ss;
+    ss << dir << "/" << "tstFile" << i << ".ext";
+    file.open(ss.str(), std::ios::out);
+    file << "tempFile";
+    file.close();
+
+    files.push_back(ss.str());
+  }
 
-    records = plan->getProvenanceRecords();
-    record = plan->getCurrentFlowFile();
-    testController.runSession(plan, false);
+  plan->reset();
+  testController.runSession(plan, false);
 
-    records = plan->getProvenanceRecords();
-    record = plan->getCurrentFlowFile();
+  for (const auto &created_file : files) {
+    unlink(created_file.c_str());
+  }
 
-    REQUIRE(true == LogTestController::getInstance().contains("Size:8 
Offset:0"));
-    REQUIRE(true == LogTestController::getInstance().contains("key:path 
value:" + std::string(dir)));
-    REQUIRE(true == LogTestController::getInstance().contains("Logged " +  
verifyStringFlowsLogged + " flow files"));
-    LogTestController::getInstance().reset();
+  records = plan->getProvenanceRecords();
+  record = plan->getCurrentFlowFile();
+  testController.runSession(plan, false);
+
+  records = plan->getProvenanceRecords();
+  record = plan->getCurrentFlowFile();
+
+  REQUIRE(true == LogTestController::getInstance().contains("Size:8 
Offset:0"));
+  REQUIRE(true == LogTestController::getInstance().contains("key:path value:" 
+ std::string(dir)));
+  REQUIRE(true == LogTestController::getInstance().contains("Logged " + 
verifyStringFlowsLogged + " flow files"));
+  LogTestController::getInstance().reset();
 }
 
 TEST_CASE("LogAttributeTestSingle", "[TestLogAttribute]") {
-  testMultiplesLogAttribute(1,3,"1");
+  testMultiplesLogAttribute(1, 3, "1");
 }
 
-
 TEST_CASE("LogAttributeTestMultiple", "[TestLogAttribute]") {
-  testMultiplesLogAttribute(5,3);
+  testMultiplesLogAttribute(5, 3);
 }
 
 TEST_CASE("LogAttributeTestAll", "[TestLogAttribute]") {
-  testMultiplesLogAttribute(5,0,"5");
+  testMultiplesLogAttribute(5, 0, "5");
 }
 
 TEST_CASE("Test Find file", "[getfileCreate3]") {
diff --git a/extensions/standard-processors/tests/unit/TailFileTests.cpp 
b/extensions/standard-processors/tests/unit/TailFileTests.cpp
index d23622f..c5cf392 100644
--- a/extensions/standard-processors/tests/unit/TailFileTests.cpp
+++ b/extensions/standard-processors/tests/unit/TailFileTests.cpp
@@ -22,6 +22,7 @@
 #include <memory>
 #include <utility>
 #include <string>
+#include <iostream>
 #include <set>
 #include "FlowController.h"
 #include "TestBase.h"
@@ -34,7 +35,7 @@
 #include "core/ProcessorNode.h"
 #include "TailFile.h"
 #include "LogAttribute.h"
-#include <iostream>
+
 
 static const char *NEWLINE_FILE = ""
     "one,two,three\n"
diff --git 
a/extensions/standard-processors/tests/unit/YamlConfigurationTests.cpp 
b/extensions/standard-processors/tests/unit/YamlConfigurationTests.cpp
index f358d7b..e0e6f67 100644
--- a/extensions/standard-processors/tests/unit/YamlConfigurationTests.cpp
+++ b/extensions/standard-processors/tests/unit/YamlConfigurationTests.cpp
@@ -19,7 +19,7 @@
 #include <map>
 #include <memory>
 #include "core/repository/VolatileContentRepository.h"
-#include <core/RepositoryFactory.h>
+#include "core/RepositoryFactory.h"
 #include "core/yaml/YamlConfiguration.h"
 #include "TestBase.h"
 
diff --git a/thirdparty/google-styleguide/run_linter.sh 
b/thirdparty/google-styleguide/run_linter.sh
index da5f503..a76ff61 100755
--- a/thirdparty/google-styleguide/run_linter.sh
+++ b/thirdparty/google-styleguide/run_linter.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 #
 # Licensed to the Apache Software Foundation (ASF) under one or more
 # contributor license agreements.  See the NOTICE file distributed with
@@ -14,12 +15,29 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-# ./run_linter <includedir> <srcdir>
-#!/bin/bash
-if [ "$(uname)" == "Darwin" ]; then
-SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+# ./run_linter <includedir1> <includedir2> ... <includedirN> -- <srcdir1> 
<srcdir2> ... <srcdirN>
+
+if [[ "$(uname)" == "Darwin" ]]; then
+    SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 else
-SCRIPT=$(readlink -f $0)
-SCRIPT_DIR=`dirname $SCRIPT`
+    SCRIPT=$(readlink -f $0)
+    SCRIPT_DIR=`dirname $SCRIPT`
 fi
-python ${SCRIPT_DIR}/cpplint.py --linelength=200 --extensions=cpp --recursive 
${1}/*
+
+while (( $# )) ; do
+    [ x"$1" == x"--" ] && break
+    INCLUDE_DIRS="$INCLUDE_DIRS $1"
+    shift
+done
+
+while (( $# )) ; do
+    SOURCE_DIRS="$SOURCE_DIRS $1"
+    shift
+done
+
+[ x"$INCLUDE_DIRS" == x"" ] && echo "WARNING: No include directories 
specified."
+[ x"$SOURCE_DIRS" == x"" ] && echo "ERROR: No source directories specified." 
&& exit 1
+
+HEADERS=`find $INCLUDE_DIRS -name '*.h' | sort | uniq | tr '\n' ','`
+SOURCES=`find $SOURCE_DIRS -name  '*.cpp' | sort | uniq | tr '\n' ' '`
+python2 ${SCRIPT_DIR}/cpplint.py --linelength=200 --headers=${HEADERS} 
${SOURCES}

Reply via email to