diff --git a/exaudfclient/BUILD b/exaudfclient/BUILD index 656ed774..1c609375 100644 --- a/exaudfclient/BUILD +++ b/exaudfclient/BUILD @@ -78,7 +78,7 @@ cc_binary( srcs = ["exaudfclient.cc", "//base:load_dynamic"], linkopts = ["-ldl"], # needed for dynamicly loading libexaudflib_complete.so into another linker namespace deps = ["//base/exaudflib:header", "//base/utils:utils"]+VM_ENABLED_DEPS+VM_PYTHON3_DEPS+ - ["//base/exaudflib:exaudflib-deps", "//base/swig_factory:swig_factory"], + ["//base/exaudflib:exaudflib-deps"], defines = VM_ENABLED_DEFINES, data = ["//base:libexaudflib_complete.so"] ) @@ -101,7 +101,7 @@ cc_binary( srcs = ["exaudfclient.cc", "//base:load_dynamic"], linkopts = ["-ldl"], # needed for dynamicly loading libexaudflib_complete.so into another linker namespace deps = ["//base/exaudflib:header", "//base/utils:utils"]+VM_ENABLED_DEPS+VM_PYTHON3_DEPS+ - ["//base/exaudflib:exaudflib-deps", "//base/swig_factory:swig_factory"] + + ["//base/exaudflib:exaudflib-deps"] + [ "@zmq//:zmq", "@protobuf//:protobuf"], defines = VM_ENABLED_DEFINES, data = ["//base:libexaudflib_complete.so"], diff --git a/exaudfclient/base/javacontainer/BUILD b/exaudfclient/base/javacontainer/BUILD index 5c837f1d..d63bbf5b 100644 --- a/exaudfclient/base/javacontainer/BUILD +++ b/exaudfclient/base/javacontainer/BUILD @@ -111,7 +111,7 @@ cc_library( hdrs = [":filter_swig_code_exascript_java_h", "exascript_java_jni_decl.h"], deps = ["@java//:java", ":exascript_java", "//base/exaudflib:header", "//base/utils:utils","//base/javacontainer/script_options:java_script_option_lines", - "//base/swig_factory:swig_factory_if"], + "//base/swig_factory:swig_factory"], # copts= ["-O0","-fno-lto"], alwayslink=True, ) diff --git a/exaudfclient/base/javacontainer/javacontainer.cc b/exaudfclient/base/javacontainer/javacontainer.cc index aa655b6a..f8de356c 100644 --- a/exaudfclient/base/javacontainer/javacontainer.cc +++ b/exaudfclient/base/javacontainer/javacontainer.cc @@ -5,10 +5,9 @@ using namespace SWIGVMContainers; using namespace std; -JavaVMach::JavaVMach(bool checkOnly, SwigFactory& swigFactory, - std::unique_ptr scriptOptionsParser) { +JavaVMach::JavaVMach(bool checkOnly, std::unique_ptr scriptOptionsParser) { try { - m_impl = new JavaVMImpl(checkOnly, false, swigFactory, std::move(scriptOptionsParser)); + m_impl = new JavaVMImpl(checkOnly, false, std::move(scriptOptionsParser)); } catch (std::exception& err) { lock_guard lock(exception_msg_mtx); exception_msg = "F-UDF-CL-SL-JAVA-1000: "+std::string(err.what()); diff --git a/exaudfclient/base/javacontainer/javacontainer.h b/exaudfclient/base/javacontainer/javacontainer.h index a03aa268..c8c1b91f 100644 --- a/exaudfclient/base/javacontainer/javacontainer.h +++ b/exaudfclient/base/javacontainer/javacontainer.h @@ -11,7 +11,6 @@ namespace SWIGVMContainers { class JavaVMImpl; -class SwigFactory; namespace JavaScriptOptions { @@ -24,7 +23,7 @@ class JavaVMach: public SWIGVM { /* * scriptOptionsParser: JavaVMach takes ownership of ScriptOptionsParser pointer. */ - JavaVMach(bool checkOnly, SwigFactory& swigFactory, std::unique_ptr scriptOptionsParser); + JavaVMach(bool checkOnly, std::unique_ptr scriptOptionsParser); virtual ~JavaVMach() {} virtual void shutdown(); virtual bool run(); diff --git a/exaudfclient/base/javacontainer/javacontainer_builder.cc b/exaudfclient/base/javacontainer/javacontainer_builder.cc index 6b10fedf..c1535e57 100644 --- a/exaudfclient/base/javacontainer/javacontainer_builder.cc +++ b/exaudfclient/base/javacontainer/javacontainer_builder.cc @@ -2,26 +2,26 @@ #include "base/javacontainer/script_options/parser_ctpg.h" #include "base/javacontainer/script_options/parser_legacy.h" #include "base/javacontainer/javacontainer.h" +#include "base/swig_factory/swig_factory_impl.h" #ifdef ENABLE_JAVA_VM namespace SWIGVMContainers { -JavaContainerBuilder::JavaContainerBuilder(SwigFactory& swigFactory) -: m_parser() -, m_swigFactory(swigFactory) {} +JavaContainerBuilder::JavaContainerBuilder() +: m_parser() {} JavaContainerBuilder& JavaContainerBuilder::useCtpgParser(const bool useCtpgParser) { - m_parser = std::make_unique(); + m_parser = std::make_unique(std::make_unique()); return *this; } JavaVMach* JavaContainerBuilder::build() { if (m_parser) { - return new JavaVMach(false, m_swigFactory, std::move(m_parser)); + return new JavaVMach(false, std::move(m_parser)); } else { - m_parser = std::make_unique(); - return new JavaVMach(false, m_swigFactory, std::move(m_parser)); + m_parser = std::make_unique(std::make_unique()); + return new JavaVMach(false, std::move(m_parser)); } } diff --git a/exaudfclient/base/javacontainer/javacontainer_builder.h b/exaudfclient/base/javacontainer/javacontainer_builder.h index 614ce283..e258abd6 100644 --- a/exaudfclient/base/javacontainer/javacontainer_builder.h +++ b/exaudfclient/base/javacontainer/javacontainer_builder.h @@ -8,7 +8,6 @@ namespace SWIGVMContainers { class JavaVMach; -struct SwigFactory; namespace JavaScriptOptions { @@ -18,7 +17,7 @@ struct ScriptOptionsParser; class JavaContainerBuilder { public: - JavaContainerBuilder(SwigFactory& swigFactory); + JavaContainerBuilder(); JavaContainerBuilder& useCtpgParser(const bool value); @@ -26,8 +25,6 @@ class JavaContainerBuilder { private: std::unique_ptr m_parser; - SwigFactory& m_swigFactory; - }; } //namespace SWIGVMContainers diff --git a/exaudfclient/base/javacontainer/javacontainer_impl.cc b/exaudfclient/base/javacontainer/javacontainer_impl.cc index 2fac4e34..8a9cb2a0 100644 --- a/exaudfclient/base/javacontainer/javacontainer_impl.cc +++ b/exaudfclient/base/javacontainer/javacontainer_impl.cc @@ -12,16 +12,14 @@ #include "base/javacontainer/javacontainer.h" #include "base/javacontainer/javacontainer_impl.h" #include "base/javacontainer/script_options/extractor.h" -#include "base/javacontainer/script_options/parser_legacy.h" -#include "base/javacontainer/script_options/parser_ctpg.h" -#include "base/swig_factory/swig_factory.h" +#include "base/javacontainer/script_options/parser.h" using namespace SWIGVMContainers; using namespace std; -JavaVMImpl::JavaVMImpl(bool checkOnly, bool noJNI, SwigFactory& swigFactory, - std::unique_ptr scriptOptionsParser) +JavaVMImpl::JavaVMImpl(bool checkOnly, bool noJNI, + std::unique_ptr scriptOptionsParser) : m_checkOnly(checkOnly) , m_exaJavaPath("") , m_localClasspath("/tmp") // **IMPORTANT**: /tmp needs to be in the classpath, otherwise ExaCompiler crashe with com.exasol.ExaCompilationException: /DATE_STRING.java:3: error: error while writing DATE_STRING: could not create parent directories @@ -30,14 +28,12 @@ JavaVMImpl::JavaVMImpl(bool checkOnly, bool noJNI, SwigFactory& swigFactory, , m_jvm(NULL) , m_env(NULL) , m_needsCompilation(true) -, m_swigFactory(swigFactory) { stringstream ss; m_exaJavaPath = "/exaudf/base/javacontainer"; // TODO hardcoded path - JavaScriptOptions::ScriptOptionLinesParserCTPG parser; - parseScriptOptions(std::move(scriptOptionsParser), swigFactory); + parseScriptOptions(std::move(scriptOptionsParser)); m_needsCompilation = checkNeedsCompilation(); if (m_needsCompilation) { @@ -54,9 +50,8 @@ JavaVMImpl::JavaVMImpl(bool checkOnly, bool noJNI, SwigFactory& swigFactory, } } -void JavaVMImpl::parseScriptOptions(std::unique_ptr scriptOptionsParser, - SwigFactory& swigFactory) { - JavaScriptOptions::Extractor extractor(*scriptOptionsParser, swigFactory); +void JavaVMImpl::parseScriptOptions(std::unique_ptr scriptOptionsParser) { + JavaScriptOptions::Extractor extractor(*scriptOptionsParser); DBG_FUNC_CALL(cerr,extractor.extract(m_scriptCode)); diff --git a/exaudfclient/base/javacontainer/javacontainer_impl.h b/exaudfclient/base/javacontainer/javacontainer_impl.h index b0ad812a..973b7ede 100644 --- a/exaudfclient/base/javacontainer/javacontainer_impl.h +++ b/exaudfclient/base/javacontainer/javacontainer_impl.h @@ -23,10 +23,10 @@ class JavaVMImpl { public: friend class ::JavaVMTest; /* - * scriptOptionsParser: JavaVMach takes ownership of ScriptOptionsParser pointer. + * scriptOptionsParser: JavaVMImpl takes ownership of ScriptOptionsParser pointer. */ - JavaVMImpl(bool checkOnly, bool noJNI, SwigFactory& swigFactory, - std::unique_ptr scriptOptionsParser); + JavaVMImpl(bool checkOnly, bool noJNI, + std::unique_ptr scriptOptionsParser); ~JavaVMImpl() {} void shutdown(); bool run(); @@ -46,8 +46,7 @@ class JavaVMImpl { void throwException(const std::string& ex); void setJvmOptions(); void addJarToClasspath(const std::string& path); - void parseScriptOptions(std::unique_ptr scriptOptionsParser, - SwigFactory& swigFactory); + void parseScriptOptions(std::unique_ptr scriptOptionsParser); bool m_checkOnly; std::string m_exaJavaPath; std::string m_localClasspath; @@ -59,7 +58,6 @@ class JavaVMImpl { JavaVM *m_jvm; JNIEnv *m_env; bool m_needsCompilation; - SwigFactory& m_swigFactory; }; } //namespace SWIGVMContainers diff --git a/exaudfclient/base/javacontainer/script_options/extractor.cc b/exaudfclient/base/javacontainer/script_options/extractor.cc index bc7934e4..9a75c1c1 100644 --- a/exaudfclient/base/javacontainer/script_options/extractor.cc +++ b/exaudfclient/base/javacontainer/script_options/extractor.cc @@ -10,17 +10,15 @@ namespace SWIGVMContainers { namespace JavaScriptOptions { -Extractor::Extractor(ScriptOptionsParser & parser, - SwigFactory& swigFactory) -: m_parser(parser) -, m_swigFactory(swigFactory) {} +Extractor::Extractor(ScriptOptionsParser & parser) +: m_parser(parser) {} void Extractor::extract(std::string & scriptCode) { m_parser.prepareScriptCode(scriptCode); EXTR_DBG_FUNC_CALL(m_parser.parseForScriptClass( [&](const std::string& value){ EXTR_DBG_FUNC_CALL(m_converter.convertScriptClassName(value)); // To be called before scripts are imported. Otherwise, the script classname from an imported script could be used })); - EXTR_DBG_FUNC_CALL(m_parser.extractImportScripts(m_swigFactory)); + EXTR_DBG_FUNC_CALL(m_parser.extractImportScripts()); EXTR_DBG_FUNC_CALL(m_parser.parseForJvmOptions( [&](const std::string& value){ EXTR_DBG_FUNC_CALL(m_converter.convertJvmOption(value)); })); diff --git a/exaudfclient/base/javacontainer/script_options/extractor.h b/exaudfclient/base/javacontainer/script_options/extractor.h index d69ae354..03ce623b 100644 --- a/exaudfclient/base/javacontainer/script_options/extractor.h +++ b/exaudfclient/base/javacontainer/script_options/extractor.h @@ -10,8 +10,6 @@ namespace SWIGVMContainers { -struct SwigFactory; - namespace JavaScriptOptions { class ScriptOptionsParser; @@ -19,8 +17,7 @@ class ScriptOptionsParser; class Extractor { public: - Extractor(ScriptOptionsParser & parser, - SwigFactory& swigFactory); + Extractor(ScriptOptionsParser & parser); const std::set & getJarPaths() const { return m_converter.getJarPaths(); @@ -36,8 +33,6 @@ class Extractor { Converter m_converter; ScriptOptionsParser & m_parser; - - SwigFactory& m_swigFactory; }; diff --git a/exaudfclient/base/javacontainer/script_options/parser.h b/exaudfclient/base/javacontainer/script_options/parser.h index e82eac05..abb497fc 100644 --- a/exaudfclient/base/javacontainer/script_options/parser.h +++ b/exaudfclient/base/javacontainer/script_options/parser.h @@ -8,8 +8,6 @@ namespace SWIGVMContainers { -struct SwigFactory; - namespace JavaScriptOptions { struct ScriptOptionsParser { @@ -43,7 +41,7 @@ struct ScriptOptionsParser { Searches for the "%import" options and embeds the respective imported script code at the same location as the option in the script code. */ - virtual void extractImportScripts(SwigFactory & swigFactory) = 0; + virtual void extractImportScripts() = 0; /* Returns the (eventually modified) script code. diff --git a/exaudfclient/base/javacontainer/script_options/parser_ctpg.cc b/exaudfclient/base/javacontainer/script_options/parser_ctpg.cc index a545d43c..3f576242 100644 --- a/exaudfclient/base/javacontainer/script_options/parser_ctpg.cc +++ b/exaudfclient/base/javacontainer/script_options/parser_ctpg.cc @@ -2,6 +2,7 @@ #include "base/javacontainer/script_options/parser_ctpg_script_importer.h" #include "base/utils/exceptions.h" #include "base/script_options_parser/exception.h" +#include "base/swig_factory/swig_factory.h" #include @@ -11,10 +12,11 @@ namespace SWIGVMContainers { namespace JavaScriptOptions { -ScriptOptionLinesParserCTPG::ScriptOptionLinesParserCTPG() +ScriptOptionLinesParserCTPG::ScriptOptionLinesParserCTPG(std::unique_ptr swigFactory) : m_scriptCode() , m_keywords(false) -, m_needParsing(true) {} +, m_needParsing(true) +, m_swigFactory(std::move(swigFactory)) {} void ScriptOptionLinesParserCTPG::prepareScriptCode(const std::string & scriptCode) { m_scriptCode = scriptCode; @@ -44,7 +46,7 @@ void ScriptOptionLinesParserCTPG::parseForExternalJars(std::function namespace SWIGVMContainers { +struct SwigFactory; + namespace JavaScriptOptions { class ScriptOptionLinesParserCTPG : public ScriptOptionsParser { public: - ScriptOptionLinesParserCTPG(); + ScriptOptionLinesParserCTPG(std::unique_ptr swigFactory); virtual ~ScriptOptionLinesParserCTPG() {}; @@ -25,7 +27,7 @@ class ScriptOptionLinesParserCTPG : public ScriptOptionsParser { void parseForExternalJars(std::function callback) override; - void extractImportScripts(SwigFactory & swigFactory) override; + void extractImportScripts() override; std::string && getScriptCode() override; @@ -42,6 +44,7 @@ class ScriptOptionLinesParserCTPG : public ScriptOptionsParser { Keywords m_keywords; ExecutionGraph::OptionsLineParser::CTPG::options_map_t m_foundOptions; bool m_needParsing; + std::unique_ptr m_swigFactory; }; } //namespace JavaScriptOptions diff --git a/exaudfclient/base/javacontainer/script_options/parser_legacy.cc b/exaudfclient/base/javacontainer/script_options/parser_legacy.cc index d46b355d..4a07ead4 100644 --- a/exaudfclient/base/javacontainer/script_options/parser_legacy.cc +++ b/exaudfclient/base/javacontainer/script_options/parser_legacy.cc @@ -13,17 +13,18 @@ namespace SWIGVMContainers { namespace JavaScriptOptions { -ScriptOptionLinesParserLegacy::ScriptOptionLinesParserLegacy() +ScriptOptionLinesParserLegacy::ScriptOptionLinesParserLegacy(std::unique_ptr swigFactory) : m_whitespace(" \t\f\v") , m_lineend(";") , m_scriptCode() -, m_keywords(true) {} +, m_keywords(true) +, m_swigFactory(std::move(swigFactory)) {} void ScriptOptionLinesParserLegacy::prepareScriptCode(const std::string & scriptCode) { m_scriptCode = scriptCode; } -void ScriptOptionLinesParserLegacy::extractImportScripts(SwigFactory & swigFactory) { +void ScriptOptionLinesParserLegacy::extractImportScripts() { std::unique_ptr metaData; // Attention: We must hash the parent script before modifying it (adding the // package definition). Otherwise we don't recognize if the script imports its self @@ -111,7 +112,7 @@ void ScriptOptionLinesParserLegacy::extractImportScripts(SwigFactory & swigFacto } if (!newScript.empty()) { if (!metaData) { - metaData.reset(swigFactory.makeSwigMetadata()); + metaData.reset(m_swigFactory->makeSwigMetadata()); if (!metaData) throw std::runtime_error("F-UDF-CL-SL-JAVA-1615: Failure while importing scripts"); } diff --git a/exaudfclient/base/javacontainer/script_options/parser_legacy.h b/exaudfclient/base/javacontainer/script_options/parser_legacy.h index 93d4c134..447ca394 100644 --- a/exaudfclient/base/javacontainer/script_options/parser_legacy.h +++ b/exaudfclient/base/javacontainer/script_options/parser_legacy.h @@ -5,15 +5,18 @@ #include "base/javacontainer/script_options/parser.h" #include "base/javacontainer/script_options/keywords.h" +#include namespace SWIGVMContainers { +struct SwigFactory; + namespace JavaScriptOptions { class ScriptOptionLinesParserLegacy : public ScriptOptionsParser { public: - ScriptOptionLinesParserLegacy(); + ScriptOptionLinesParserLegacy(std::unique_ptr swigFactory); virtual ~ScriptOptionLinesParserLegacy() {}; @@ -25,7 +28,7 @@ class ScriptOptionLinesParserLegacy : public ScriptOptionsParser { void parseForExternalJars(std::function callback) override; - void extractImportScripts(SwigFactory & swigFactory) override; + void extractImportScripts() override; std::string && getScriptCode() override; @@ -40,6 +43,7 @@ class ScriptOptionLinesParserLegacy : public ScriptOptionsParser { const std::string m_lineend; std::string m_scriptCode; Keywords m_keywords; + std::unique_ptr m_swigFactory; }; } //namespace JavaScriptOptions diff --git a/exaudfclient/base/javacontainer/script_options/test/ctpg_script_importer_test.cc b/exaudfclient/base/javacontainer/script_options/test/ctpg_script_importer_test.cc index 7df4ff78..eb34a961 100644 --- a/exaudfclient/base/javacontainer/script_options/test/ctpg_script_importer_test.cc +++ b/exaudfclient/base/javacontainer/script_options/test/ctpg_script_importer_test.cc @@ -39,18 +39,19 @@ TEST(ScriptImporterTest, max_recursion_depth) { */ size_t currentIdx = 0; - SwigFactoryTestImpl swigFactoryTest([&](const char* scriptKey) { + std::unique_ptr swigFactory = + std::make_unique([&](const char* scriptKey) { checkIndex(currentIdx, scriptKey); return buildNewScriptCode(++currentIdx); }); - ScriptOptionLinesParserCTPG parser; + ScriptOptionLinesParserCTPG parser(std::move(swigFactory)); const std::string code = buildNewScriptCode(currentIdx); parser.prepareScriptCode(code); EXPECT_THROW({ try { - parser.extractImportScripts(swigFactoryTest); + parser.extractImportScripts(); } catch( const std::runtime_error& e ) { diff --git a/exaudfclient/base/javacontainer/test/cpp/javacontainer_ctpg_test.cc b/exaudfclient/base/javacontainer/test/cpp/javacontainer_ctpg_test.cc index a3db7c2d..e66168e5 100644 --- a/exaudfclient/base/javacontainer/test/cpp/javacontainer_ctpg_test.cc +++ b/exaudfclient/base/javacontainer/test/cpp/javacontainer_ctpg_test.cc @@ -4,6 +4,7 @@ #include "base/javacontainer/test/cpp/javavm_test.h" #include "base/javacontainer/test/cpp/swig_factory_test.h" #include +#include class JavaContainerEscapeSequenceTest : public ::testing::TestWithParam> {}; @@ -72,7 +73,7 @@ TEST(JavaContainer, import_script_with_escaped_options) { " ctx.emit(\"Success!\");\n" " }\n" "}\n"; - SwigFactoryTestImpl swigFactory; + std::unique_ptr swigFactory = std::make_unique(); const std::string other_script_code = "%jvmoption -Dsomeotheroption=\"DE\\nF\";\n\n" @@ -81,8 +82,8 @@ TEST(JavaContainer, import_script_with_escaped_options) { "static void doSomething() {\n\n" " }\n" "}\n"; - swigFactory.addModule("other_script", other_script_code); - JavaVMTest vm(script_code, swigFactory); + swigFactory->addModule("other_script", other_script_code); + JavaVMTest vm(script_code, std::move(swigFactory)); EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJavaPath, "/exaudf/base/javacontainer"); EXPECT_EQ(vm.getJavaVMInternalStatus().m_localClasspath, "/tmp"); const std::string expected_script_code = diff --git a/exaudfclient/base/javacontainer/test/cpp/javacontainer_test.cc b/exaudfclient/base/javacontainer/test/cpp/javacontainer_test.cc index 4b98c4f5..0c754206 100644 --- a/exaudfclient/base/javacontainer/test/cpp/javacontainer_test.cc +++ b/exaudfclient/base/javacontainer/test/cpp/javacontainer_test.cc @@ -5,6 +5,7 @@ #include "base/javacontainer/test/cpp/swig_factory_test.h" #include + TEST(JavaContainer, basic_jar) { const std::string script_code = "%scriptclass com.exasol.udf_profiling.UdfProfiler;\n" "%jar base/javacontainer/test/test.jar;"; @@ -123,15 +124,15 @@ TEST(JavaContainer, simple_import_script) { " ctx.emit(\"Success!\");\n" " }\n" "}\n"; - SwigFactoryTestImpl swigFactory; + auto swigFactory = std::make_unique(); const std::string other_script_code = "class OtherClass {\n" "static void doSomething() {\n\n" " }\n" "}\n"; - swigFactory.addModule("other_script", other_script_code); - JavaVMTest vm(script_code, swigFactory); + swigFactory->addModule("other_script", other_script_code); + JavaVMTest vm(script_code, std::move(swigFactory)); EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJavaPath, "/exaudf/base/javacontainer"); EXPECT_EQ(vm.getJavaVMInternalStatus().m_localClasspath, "/tmp"); const std::string expected_script_code = @@ -164,7 +165,7 @@ TEST(JavaContainer, import_script_with_recursion) { " ctx.emit(\"Success!\");\n" " }\n" "}\n"; - SwigFactoryTestImpl swigFactory; + auto swigFactory = std::make_unique(); const std::string other_script_code = "%import other_script;\n\n" @@ -172,8 +173,8 @@ TEST(JavaContainer, import_script_with_recursion) { "static void doSomething() {\n\n" " }\n" "}\n"; - swigFactory.addModule("other_script", other_script_code); - JavaVMTest vm(script_code, swigFactory); + swigFactory->addModule("other_script", other_script_code); + JavaVMTest vm(script_code, std::move(swigFactory)); EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJavaPath, "/exaudf/base/javacontainer"); EXPECT_EQ(vm.getJavaVMInternalStatus().m_localClasspath, "/tmp"); const std::string expected_script_code = @@ -205,7 +206,7 @@ TEST(JavaContainer, import_script_with_jvmoption) { " ctx.emit(\"Success!\");\n" " }\n" "}\n"; - SwigFactoryTestImpl swigFactory; + auto swigFactory = std::make_unique(); const std::string other_script_code = "%jvmoption -Dhttp.agent=\"ABC\";\n\n" @@ -213,8 +214,8 @@ TEST(JavaContainer, import_script_with_jvmoption) { "static void doSomething() {\n\n" " }\n" "}\n"; - swigFactory.addModule("other_script", other_script_code); - JavaVMTest vm(script_code, swigFactory); + swigFactory->addModule("other_script", other_script_code); + JavaVMTest vm(script_code, std::move(swigFactory)); EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJavaPath, "/exaudf/base/javacontainer"); EXPECT_EQ(vm.getJavaVMInternalStatus().m_localClasspath, "/tmp"); const std::string expected_script_code = @@ -247,7 +248,7 @@ TEST(JavaContainer, multiple_import_scripts) { " ctx.emit(\"Success!\");\n" " }\n" "}\n"; - SwigFactoryTestImpl swigFactory; + auto swigFactory = std::make_unique(); const std::string other_scipt_code_A = "%import other_script_B;\n\n" @@ -266,10 +267,10 @@ TEST(JavaContainer, multiple_import_scripts) { "static void doSomething() {\n\n" " }\n" "}\n"; - swigFactory.addModule("other_script_A", other_scipt_code_A); - swigFactory.addModule("other_script_B", other_scipt_code_B); - swigFactory.addModule("other_script_C", other_scipt_code_C); - JavaVMTest vm(script_code, swigFactory); + swigFactory->addModule("other_script_A", other_scipt_code_A); + swigFactory->addModule("other_script_B", other_scipt_code_B); + swigFactory->addModule("other_script_C", other_scipt_code_C); + JavaVMTest vm(script_code, std::move(swigFactory)); EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJavaPath, "/exaudf/base/javacontainer"); EXPECT_EQ(vm.getJavaVMInternalStatus().m_localClasspath, "/tmp"); const std::string expected_script_code = @@ -312,7 +313,7 @@ TEST(JavaContainer, import_script_with_mixed_options) { " ctx.emit(\"Success!\");\n" " }\n" "}\n"; - SwigFactoryTestImpl swigFactory; + auto swigFactory = std::make_unique(); const std::string other_script_code = "%jvmoption -Dsomeotheroption=\"DEF\";\n\n" @@ -321,8 +322,8 @@ TEST(JavaContainer, import_script_with_mixed_options) { "static void doSomething() {\n\n" " }\n" "}\n"; - swigFactory.addModule("other_script", other_script_code); - JavaVMTest vm(script_code, swigFactory); + swigFactory->addModule("other_script", other_script_code); + JavaVMTest vm(script_code, std::move(swigFactory)); EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJavaPath, "/exaudf/base/javacontainer"); EXPECT_EQ(vm.getJavaVMInternalStatus().m_localClasspath, "/tmp"); const std::string expected_script_code = @@ -355,7 +356,7 @@ TEST(JavaContainer, import_script_script_class_option_ignored) { " ctx.emit(\"Success!\");\n" " }\n" "}\n"; - SwigFactoryTestImpl swigFactory; + auto swigFactory = std::make_unique(); const std::string other_script_code = "%scriptclass com.exasol.udf_profiling.UdfProfiler;\n" @@ -363,8 +364,8 @@ TEST(JavaContainer, import_script_script_class_option_ignored) { "static void doSomething() {\n\n" " }\n" "}\n"; - swigFactory.addModule("other_script", other_script_code); - JavaVMTest vm(script_code, swigFactory); + swigFactory->addModule("other_script", other_script_code); + JavaVMTest vm(script_code, std::move(swigFactory)); EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJavaPath, "/exaudf/base/javacontainer"); EXPECT_EQ(vm.getJavaVMInternalStatus().m_localClasspath, "/tmp"); const std::string expected_script_code = @@ -401,7 +402,7 @@ TEST(JavaContainer, import_scripts_deep_recursion) { " ctx.emit(\"Success!\");\n" " }\n" "}\n"; - SwigFactoryTestImpl swigFactory; + auto swigFactory = std::make_unique(); const std::string other_scipt_code_A = "%import other_script_B;\n\n" @@ -427,11 +428,11 @@ TEST(JavaContainer, import_scripts_deep_recursion) { "static void doSomething() {\n\n" " }\n" "}\n"; - swigFactory.addModule("other_script_A", other_scipt_code_A); - swigFactory.addModule("other_script_B", other_scipt_code_B); - swigFactory.addModule("other_script_C", other_scipt_code_C); - swigFactory.addModule("other_script_D", other_scipt_code_D); - JavaVMTest vm(script_code, swigFactory); + swigFactory->addModule("other_script_A", other_scipt_code_A); + swigFactory->addModule("other_script_B", other_scipt_code_B); + swigFactory->addModule("other_script_C", other_scipt_code_C); + swigFactory->addModule("other_script_D", other_scipt_code_D); + JavaVMTest vm(script_code, std::move(swigFactory)); EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJavaPath, "/exaudf/base/javacontainer"); EXPECT_EQ(vm.getJavaVMInternalStatus().m_localClasspath, "/tmp"); const std::string expected_script_code = diff --git a/exaudfclient/base/javacontainer/test/cpp/javavm_test.cc b/exaudfclient/base/javacontainer/test/cpp/javavm_test.cc index 6ec41888..6a26dc35 100644 --- a/exaudfclient/base/javacontainer/test/cpp/javavm_test.cc +++ b/exaudfclient/base/javacontainer/test/cpp/javavm_test.cc @@ -5,31 +5,29 @@ #include "base/javacontainer/script_options/parser_legacy.h" #include - -SwigFactoryTestImpl & defaultSwigFactory() { - static SwigFactoryTestImpl swigFactory; - return swigFactory; +std::unique_ptr makeDefaultSwigFactory() { + return std::make_unique(); } JavaVMTest::JavaVMTest(std::string scriptCode) : javaVMInternalStatus() { - run(scriptCode, defaultSwigFactory()); + run(scriptCode, std::move(makeDefaultSwigFactory())); } -JavaVMTest::JavaVMTest(std::string scriptCode, SwigFactoryTestImpl & swigFactory) : javaVMInternalStatus() { - run(scriptCode, swigFactory); +JavaVMTest::JavaVMTest(std::string scriptCode, std::unique_ptr swigFactory) : javaVMInternalStatus() { + run(scriptCode, std::move(swigFactory)); } -void JavaVMTest::run(std::string scriptCode, SwigFactoryTestImpl & swigFactory) { +void JavaVMTest::run(std::string scriptCode, std::unique_ptr swigFactory) { char* script_code = ::strdup(scriptCode.c_str()); SWIGVMContainers::SWIGVM_params->script_code = script_code; #ifndef USE_CTPG_PARSER std::unique_ptr parser = - std::make_unique(); + std::make_unique(std::move(swigFactory)); #else std::unique_ptr parser = - std::make_unique(); + std::make_unique(std::move(swigFactory)); #endif - SWIGVMContainers::JavaVMImpl javaVMImpl(false, true, swigFactory, std::move(parser)); + SWIGVMContainers::JavaVMImpl javaVMImpl(false, true, std::move(parser)); javaVMInternalStatus.m_exaJavaPath = javaVMImpl.m_exaJavaPath; javaVMInternalStatus.m_localClasspath = javaVMImpl.m_localClasspath; javaVMInternalStatus.m_scriptCode = javaVMImpl.m_scriptCode; diff --git a/exaudfclient/base/javacontainer/test/cpp/javavm_test.h b/exaudfclient/base/javacontainer/test/cpp/javavm_test.h index d4e31844..a0e8e0b5 100644 --- a/exaudfclient/base/javacontainer/test/cpp/javavm_test.h +++ b/exaudfclient/base/javacontainer/test/cpp/javavm_test.h @@ -4,6 +4,7 @@ #include #include #include +#include struct JavaVMInternalStatus { std::string m_exaJavaPath; @@ -21,12 +22,12 @@ class JavaVMTest { public: JavaVMTest(std::string scriptCode); - JavaVMTest(std::string scriptCode, SwigFactoryTestImpl & swigFactory); + JavaVMTest(std::string scriptCode, std::unique_ptr swigFactory); const JavaVMInternalStatus& getJavaVMInternalStatus() {return javaVMInternalStatus;} private: - void run(std::string scriptCode, SwigFactoryTestImpl & swigFactory); + void run(std::string scriptCode, std::unique_ptr swigFactory); private: JavaVMInternalStatus javaVMInternalStatus; };