MINIFICPP-1261 - Mark ScopeGuard class deprecated

MINIFICPP-1261 - Replace internal usages of ScopeGuard with gsl::finally

Signed-off-by: Arpad Boda <aboda@apache.org>

This closes #849
diff --git a/extensions/librdkafka/PublishKafka.cpp b/extensions/librdkafka/PublishKafka.cpp
index ae8f339..a6a3182 100644
--- a/extensions/librdkafka/PublishKafka.cpp
+++ b/extensions/librdkafka/PublishKafka.cpp
@@ -29,7 +29,6 @@
 
 #include "utils/TimeUtil.h"
 #include "utils/StringUtils.h"
-#include "utils/ScopeGuard.h"
 #include "utils/GeneralUtils.h"
 #include "core/ProcessContext.h"
 #include "core/ProcessSession.h"
diff --git a/extensions/opc/src/opc.cpp b/extensions/opc/src/opc.cpp
index 2baa8aa..8f8d136 100644
--- a/extensions/opc/src/opc.cpp
+++ b/extensions/opc/src/opc.cpp
@@ -19,11 +19,12 @@
 #include "opc.h"
 
 //MiNiFi includes
-#include "utils/ScopeGuard.h"
 #include "utils/StringUtils.h"
 #include "logging/Logger.h"
 #include "Exception.h"
 
+#include "utils/gsl.h"
+
 //Standard includes
 #include <stdlib.h>
 #include <iostream>
@@ -302,7 +303,7 @@
 
   UA_BrowseResponse bResp = UA_Client_Service_browse(client_, bReq);
 
-  utils::ScopeGuard guard([&bResp]() {
+  const auto guard = gsl::finally([&bResp]() {
     UA_BrowseResponse_deleteMembers(&bResp);
   });
 
@@ -363,7 +364,7 @@
 
   UA_TranslateBrowsePathsToNodeIdsResponse response = UA_Client_Service_translateBrowsePathsToNodeIds(client_, request);
 
-  utils::ScopeGuard guard([&browsePath]() {
+  const auto guard = gsl::finally([&browsePath]() {
     UA_BrowsePath_deleteMembers(&browsePath);
   });
 
diff --git a/extensions/openwsman/processors/SourceInitiatedSubscriptionListener.cpp b/extensions/openwsman/processors/SourceInitiatedSubscriptionListener.cpp
index d285b95..367e374 100644
--- a/extensions/openwsman/processors/SourceInitiatedSubscriptionListener.cpp
+++ b/extensions/openwsman/processors/SourceInitiatedSubscriptionListener.cpp
@@ -51,9 +51,10 @@
 #include "io/StreamFactory.h"
 #include "ResourceClaim.h"
 #include "utils/StringUtils.h"
-#include "utils/ScopeGuard.h"
 #include "utils/file/FileUtils.h"
 
+#include "utils/gsl.h"
+
 #define XML_NS_CUSTOM_SUBSCRIPTION "http://schemas.microsoft.com/wbem/wsman/1/subscription"
 #define XML_NS_CUSTOM_AUTHENTICATION "http://schemas.microsoft.com/wbem/wsman/1/authentication"
 #define XML_NS_CUSTOM_POLICY "http://schemas.xmlsoap.org/ws/2002/12/policy"
@@ -391,7 +392,7 @@
 }
 
 bool SourceInitiatedSubscriptionListener::Handler::handleSubscriptionManager(struct mg_connection* conn, const std::string& endpoint, WsXmlDocH request) {
-  utils::ScopeGuard request_guard([&]() {
+  const auto request_guard = gsl::finally([&]() {
       ws_xml_destroy_doc(request);
   });
 
@@ -406,7 +407,7 @@
 
   // Create reponse envelope from request
   WsXmlDocH response = wsman_create_response_envelope(request, nullptr);
-  utils::ScopeGuard response_guard([&]() {
+  const auto response_guard = gsl::finally([&]() {
     ws_xml_destroy_doc(response);
   });
 
@@ -653,7 +654,7 @@
 }
 
 bool SourceInitiatedSubscriptionListener::Handler::handleSubscriptions(struct mg_connection* conn, const std::string& endpoint, WsXmlDocH request) {
-  utils::ScopeGuard guard([&]() {
+  const auto guard = gsl::finally([&]() {
       ws_xml_destroy_doc(request);
   });
   auto action = getSoapAction(request);
diff --git a/extensions/rocksdb-repos/FlowFileRepository.cpp b/extensions/rocksdb-repos/FlowFileRepository.cpp
index 5184c7c..d04671c 100644
--- a/extensions/rocksdb-repos/FlowFileRepository.cpp
+++ b/extensions/rocksdb-repos/FlowFileRepository.cpp
@@ -17,7 +17,6 @@
  */
 #include "FlowFileRecord.h"
 #include "FlowFileRepository.h"
-#include "utils/ScopeGuard.h"
 
 #include "rocksdb/options.h"
 #include "rocksdb/write_batch.h"
diff --git a/extensions/sftp/client/SFTPClient.cpp b/extensions/sftp/client/SFTPClient.cpp
index 8f66ccc..ba982a4 100644
--- a/extensions/sftp/client/SFTPClient.cpp
+++ b/extensions/sftp/client/SFTPClient.cpp
@@ -24,8 +24,8 @@
 #include <sstream>
 #include <iomanip>
 #include "utils/StringUtils.h"
-#include "utils/ScopeGuard.h"
-#include "utils/StringUtils.h"
+
+#include "utils/gsl.h"
 
 namespace org {
 namespace apache {
@@ -506,7 +506,7 @@
     }
     return false;
   }
-  utils::ScopeGuard guard([&file_handle]() {
+  const auto guard = gsl::finally([&file_handle]() {
     libssh2_sftp_close(file_handle);
   });
 
@@ -563,7 +563,7 @@
       logger_->log_error("Failed to open remote file \"%s\" due to an underlying SSH error: %s", path.c_str(), err_msg);
     }
   }
-  utils::ScopeGuard guard([this, &file_handle, &path]() {
+  const auto guard = gsl::finally ([this, &file_handle, &path]() {
     logger_->log_trace("Closing remote file \"%s\"", path.c_str());
     libssh2_sftp_close(file_handle);
   });
@@ -706,7 +706,7 @@
     logger_->log_error("Failed to open remote directory \"%s\", error: %s", path.c_str(), sftp_strerror(last_error_));
     return false;
   }
-  utils::ScopeGuard guard([&dir_handle]() {
+  const auto guard = gsl::finally([&dir_handle]() {
     libssh2_sftp_close(dir_handle);
   });
 
diff --git a/extensions/sftp/processors/ListSFTP.cpp b/extensions/sftp/processors/ListSFTP.cpp
index 3b30611..ad0d187 100644
--- a/extensions/sftp/processors/ListSFTP.cpp
+++ b/extensions/sftp/processors/ListSFTP.cpp
@@ -37,7 +37,6 @@
 #include "utils/TimeUtil.h"
 #include "utils/StringUtils.h"
 #include "utils/RegexUtils.h"
-#include "utils/ScopeGuard.h"
 #include "utils/file/FileUtils.h"
 #include "core/FlowFile.h"
 #include "core/logging/Logger.h"
diff --git a/extensions/sftp/processors/PutSFTP.cpp b/extensions/sftp/processors/PutSFTP.cpp
index 79c2758..8bb1bc6 100644
--- a/extensions/sftp/processors/PutSFTP.cpp
+++ b/extensions/sftp/processors/PutSFTP.cpp
@@ -41,7 +41,6 @@
 #include "io/StreamFactory.h"
 #include "ResourceClaim.h"
 #include "utils/StringUtils.h"
-#include "utils/ScopeGuard.h"
 #include "utils/file/FileUtils.h"
 
 namespace org {
diff --git a/extensions/sftp/processors/SFTPProcessorBase.cpp b/extensions/sftp/processors/SFTPProcessorBase.cpp
index 4cbc5ac..296c9d8 100644
--- a/extensions/sftp/processors/SFTPProcessorBase.cpp
+++ b/extensions/sftp/processors/SFTPProcessorBase.cpp
@@ -41,7 +41,6 @@
 #include "io/StreamFactory.h"
 #include "ResourceClaim.h"
 #include "utils/StringUtils.h"
-#include "utils/ScopeGuard.h"
 
 namespace org {
 namespace apache {
diff --git a/extensions/standard-processors/tests/unit/HashContentTest.cpp b/extensions/standard-processors/tests/unit/HashContentTest.cpp
index fe4e775..c699455 100644
--- a/extensions/standard-processors/tests/unit/HashContentTest.cpp
+++ b/extensions/standard-processors/tests/unit/HashContentTest.cpp
@@ -34,7 +34,6 @@
 #include "core/ProcessContext.h"
 #include "core/ProcessSession.h"
 #include "core/ProcessorNode.h"
-#include "utils/ScopeGuard.h"
 
 #include "GetFile.h"
 #include "HashContent.h"
diff --git a/extensions/windows-event-log/Bookmark.cpp b/extensions/windows-event-log/Bookmark.cpp
index eccb22d..05445ec 100644
--- a/extensions/windows-event-log/Bookmark.cpp
+++ b/extensions/windows-event-log/Bookmark.cpp
@@ -22,7 +22,6 @@
 
 #include "wel/UnicodeConversion.h"
 #include "utils/file/FileUtils.h"
-#include "utils/ScopeGuard.h"
 
 namespace org {
 namespace apache {
diff --git a/extensions/windows-event-log/CollectorInitiatedSubscription.cpp b/extensions/windows-event-log/CollectorInitiatedSubscription.cpp
index 7c68f38..bbf3870 100644
--- a/extensions/windows-event-log/CollectorInitiatedSubscription.cpp
+++ b/extensions/windows-event-log/CollectorInitiatedSubscription.cpp
@@ -33,7 +33,8 @@
 #include "io/DataStream.h"
 #include "core/ProcessContext.h"
 #include "core/ProcessSession.h"
-#include "utils/ScopeGuard.h"
+
+#include "utils/gsl.h"
 
 #pragma comment(lib, "wevtapi.lib")
 #pragma comment(lib, "Wecapi.lib")
@@ -244,7 +245,7 @@
     LOG_SUBSCRIPTION_WINDOWS_ERROR("EcOpenSubscription");
     return false;
   }
-  const utils::ScopeGuard guard_hSubscription([hSubscription]() { EcClose(hSubscription); });
+  const auto guard_hSubscription = gsl::finally([hSubscription]() { EcClose(hSubscription); });
 
   PEC_VARIANT vProperty = NULL;
   std::vector<BYTE> buffer;
@@ -264,7 +265,7 @@
   }
 
   const EC_OBJECT_ARRAY_PROPERTY_HANDLE hArray = vProperty->PropertyHandleVal;
-  const utils::ScopeGuard guard_hArray([hArray]() { EcClose(hArray); });
+  const auto guard_hArray = gsl::finally([hArray]() { EcClose(hArray); });
 
   // Get the EventSources array size (number of elements).
   DWORD dwEventSourceCount{};
@@ -459,7 +460,7 @@
     LOG_SUBSCRIPTION_WINDOWS_ERROR("EcOpenSubscription");
     return false;
   }
-  const utils::ScopeGuard guard_hSubscription([hSubscription]() { EcClose(hSubscription); });
+  const auto guard_hSubscription = gsl::finally([hSubscription]() { EcClose(hSubscription); });
 
   struct SubscriptionProperty
   {
@@ -529,7 +530,7 @@
   }
 
   const EC_OBJECT_ARRAY_PROPERTY_HANDLE hArray = vProperty->PropertyHandleVal;
-  const utils::ScopeGuard guard_hArray([hArray]() { EcClose(hArray); });
+  const auto guard_hArray = gsl::finally([hArray]() { EcClose(hArray); });
 
   DWORD dwEventSourceCount{};
   if (!EcGetObjectArraySize(hArray, &dwEventSourceCount)) {
diff --git a/extensions/windows-event-log/ConsumeWindowsEventLog.cpp b/extensions/windows-event-log/ConsumeWindowsEventLog.cpp
index 74a3dc4..103a7b9 100644
--- a/extensions/windows-event-log/ConsumeWindowsEventLog.cpp
+++ b/extensions/windows-event-log/ConsumeWindowsEventLog.cpp
@@ -35,12 +35,13 @@
 #include "wel/XMLString.h"
 #include "wel/UnicodeConversion.h"
 
-#include "utils/ScopeGuard.h"
 #include "io/DataStream.h"
 #include "core/ProcessContext.h"
 #include "core/ProcessSession.h"
 #include "Bookmark.h"
 
+#include "utils/gsl.h"
+
 #pragma comment(lib, "wevtapi.lib")
 #pragma comment(lib, "ole32.lib")
 
@@ -340,7 +341,7 @@
 
   size_t eventCount = 0;
   const TimeDiff timeDiff;
-  utils::ScopeGuard timeGuard([&]() {
+  const auto timeGuard = gsl::finally([&]() {
     logger_->log_debug("processed %zu Events in %"  PRId64 " ms", eventCount, timeDiff());
   });
 
@@ -353,7 +354,7 @@
     context->yield();
     return;
   }
-  const utils::ScopeGuard guard_hEventResults([hEventResults]() { EvtClose(hEventResults); });
+  const auto guard_hEventResults = gsl::finally([hEventResults]() { EvtClose(hEventResults); });
 
   logger_->log_trace("Retrieved results in Channel: %ls with Query: %ls", wstrChannel_.c_str(), wstrQuery_.c_str());
 
@@ -385,7 +386,7 @@
       }
       break;
     }
-    const utils::ScopeGuard guard_hEvent([hEvent]() { EvtClose(hEvent); });
+    const auto guard_hEvent = gsl::finally([hEvent]() { EvtClose(hEvent); });
     logger_->log_trace("Succesfully get the next hEvent, performing event rendering");
     EventRender eventRender;
     std::wstring newBookmarkXml;
diff --git a/extensions/windows-event-log/wel/WindowsEventLog.cpp b/extensions/windows-event-log/wel/WindowsEventLog.cpp
index c16b8ed..31c1fef 100644
--- a/extensions/windows-event-log/wel/WindowsEventLog.cpp
+++ b/extensions/windows-event-log/wel/WindowsEventLog.cpp
@@ -19,9 +19,10 @@
 #include "WindowsEventLog.h"
 #include "UnicodeConversion.h"
 #include "utils/Deleters.h"
-#include "utils/ScopeGuard.h"
 #include <algorithm>
 
+#include "utils/gsl.h"
+
 namespace org {
 namespace apache {
 namespace nifi {
@@ -39,7 +40,7 @@
   if (context == NULL) {
     return;
   }
-  utils::ScopeGuard contextGuard([&context](){
+  const auto contextGuard = gsl::finally([&context](){
     EvtClose(context);
   });
   if (!EvtRender(context, event_ptr_, EvtRenderEventValues, dwBufferSize, nullptr, &dwBufferUsed, &dwPropertyCount))
diff --git a/libminifi/include/utils/ScopeGuard.h b/libminifi/include/utils/ScopeGuard.h
index 01fa314..a208adf 100644
--- a/libminifi/include/utils/ScopeGuard.h
+++ b/libminifi/include/utils/ScopeGuard.h
@@ -23,7 +23,7 @@
 #include <utility>
 #include <functional>
 
-#include "gsl.h"
+#include "utils/gsl.h"
 #include "core/Deprecated.h"
 
 namespace org {
@@ -32,10 +32,10 @@
 namespace minifi {
 namespace utils {
 
-struct ScopeGuard : ::gsl::final_action<std::function<void()>> {
+struct DEPRECATED(/*deprecated in*/ 0.8.0, /*will remove in */ 1.0) ScopeGuard : ::gsl::final_action<std::function<void()>> {
   using ::gsl::final_action<std::function<void()>>::final_action;
 
-  DEPRECATED(/*deprecated in*/ 0.8.0, /*will remove in */ 1.0) void disable() noexcept {
+  void disable() noexcept {
     dismiss();
   }
 };
diff --git a/libminifi/src/io/tls/TLSSocket.cpp b/libminifi/src/io/tls/TLSSocket.cpp
index ce4796f..eb85185 100644
--- a/libminifi/src/io/tls/TLSSocket.cpp
+++ b/libminifi/src/io/tls/TLSSocket.cpp
@@ -30,7 +30,6 @@
 #include "io/tls/TLSSocket.h"
 #include "io/tls/TLSUtils.h"
 #include "properties/Configure.h"
-#include "utils/ScopeGuard.h"
 #include "utils/StringUtils.h"
 #include "core/Property.h"
 #include "core/logging/LoggerConfiguration.h"
diff --git a/libminifi/src/utils/OsUtils.cpp b/libminifi/src/utils/OsUtils.cpp
index 9ac74c0..cdbf897 100644
--- a/libminifi/src/utils/OsUtils.cpp
+++ b/libminifi/src/utils/OsUtils.cpp
@@ -21,7 +21,7 @@
 #include <iostream>
 #include <map>
 
-#include "utils/ScopeGuard.h"
+#include "utils/gsl.h"
 
 #ifdef __linux__
 #include <sstream>
@@ -90,7 +90,7 @@
     }
     // First call to LookupAccountSid to get the buffer sizes.
     PSID pSidOwner = NULL;
-    const utils::ScopeGuard guard_pSidOwner([&pSidOwner]() { if (pSidOwner != NULL) { LocalFree(pSidOwner); } });
+    const auto guard_pSidOwner = gsl::finally([&pSidOwner]() { if (pSidOwner != NULL) { LocalFree(pSidOwner); } });
     if (ConvertStringSidToSidA(name.c_str(), &pSidOwner)) {
       SID_NAME_USE sidType = SidTypeUnknown;
       DWORD windowsAccountNameSize = 0, dwwindowsDomainSize = 0;