Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#990: Forward jar options without changing order #467

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions exaudfclient/base/javacontainer/javacontainer.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "base/javacontainer/javacontainer.h"
#include "base/javacontainer/javacontainer_impl.h"
#include "base/javacontainer/script_options/parser.h"
#include "base/javacontainer/script_options/extractor.h"

using namespace SWIGVMContainers;
using namespace std;

JavaVMach::JavaVMach(bool checkOnly, std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser) {
JavaVMach::JavaVMach(bool checkOnly,std::unique_ptr<JavaScriptOptions::Extractor> extractor) {
try {
m_impl = new JavaVMImpl(checkOnly, false, std::move(scriptOptionsParser));
m_impl = new JavaVMImpl(checkOnly, false, std::move(extractor));
} catch (std::exception& err) {
lock_guard<mutex> lock(exception_msg_mtx);
exception_msg = "F-UDF-CL-SL-JAVA-1000: "+std::string(err.what());
Expand Down
4 changes: 2 additions & 2 deletions exaudfclient/base/javacontainer/javacontainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class JavaVMImpl;

namespace JavaScriptOptions {

struct ScriptOptionsParser;
struct Extractor;

}

Expand All @@ -23,7 +23,7 @@ class JavaVMach: public SWIGVM {
/*
* scriptOptionsParser: JavaVMach takes ownership of ScriptOptionsParser pointer.
*/
JavaVMach(bool checkOnly, std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser);
JavaVMach(bool checkOnly, std::unique_ptr<JavaScriptOptions::Extractor> extractor);
virtual ~JavaVMach() {}
virtual void shutdown();
virtual bool run();
Expand Down
11 changes: 5 additions & 6 deletions exaudfclient/base/javacontainer/javacontainer_builder.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "base/javacontainer/javacontainer_builder.h"
#include "base/javacontainer/script_options/parser_ctpg.h"
#include "base/javacontainer/script_options/parser_legacy.h"
#include "base/javacontainer/script_options/extractor_impl.h"
#include "base/swig_factory/swig_factory_impl.h"

#ifdef ENABLE_JAVA_VM
Expand All @@ -16,13 +15,13 @@ JavaContainerBuilder& JavaContainerBuilder::useCtpgParser() {
}

JavaVMach* JavaContainerBuilder::build() {
std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> parser;
std::unique_ptr<JavaScriptOptions::Extractor> extractor;
if (m_useCtpgParser) {
parser = std::make_unique<JavaScriptOptions::ScriptOptionLinesParserCTPG>(std::make_unique<SwigFactoryImpl>());
extractor = std::make_unique<JavaScriptOptions::tExtractorV2>(std::make_unique<SwigFactoryImpl>());
} else {
parser = std::make_unique<JavaScriptOptions::ScriptOptionLinesParserLegacy>(std::make_unique<SwigFactoryImpl>());
extractor = std::make_unique<JavaScriptOptions::tExtractorLegacy>(std::make_unique<SwigFactoryImpl>());
}
return new JavaVMach(false, std::move(parser));
return new JavaVMach(false, std::move(extractor));
}


Expand Down
18 changes: 6 additions & 12 deletions exaudfclient/base/javacontainer/javacontainer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
#include "base/javacontainer/javacontainer.h"
#include "base/javacontainer/javacontainer_impl.h"
#include "base/javacontainer/script_options/extractor.h"
#include "base/javacontainer/script_options/parser.h"


using namespace SWIGVMContainers;
using namespace std;

JavaVMImpl::JavaVMImpl(bool checkOnly, bool noJNI,
std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser)
std::unique_ptr<JavaScriptOptions::Extractor> extractor)
: 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
Expand All @@ -32,7 +31,7 @@ JavaVMImpl::JavaVMImpl(bool checkOnly, bool noJNI,
stringstream ss;
m_exaJavaPath = "/exaudf/base/javacontainer"; // TODO hardcoded path

parseScriptOptions(std::move(scriptOptionsParser));
parseScriptOptions(std::move(extractor));

m_needsCompilation = checkNeedsCompilation();
if (m_needsCompilation) {
Expand All @@ -49,19 +48,14 @@ JavaVMImpl::JavaVMImpl(bool checkOnly, bool noJNI,
}
}

void JavaVMImpl::parseScriptOptions(std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser) {
JavaScriptOptions::Extractor extractor(*scriptOptionsParser);
void JavaVMImpl::parseScriptOptions(std::unique_ptr<JavaScriptOptions::Extractor> extractor) {

DBG_FUNC_CALL(cerr,extractor.extract(m_scriptCode));
DBG_FUNC_CALL(cerr,extractor->extract(m_scriptCode));

DBG_FUNC_CALL(cerr,setClasspath());

m_jvmOptions = std::move(extractor.moveJvmOptions());

for (set<string>::iterator it = extractor.getJarPaths().begin(); it != extractor.getJarPaths().end();
++it) {
addJarToClasspath(*it);
}
m_jvmOptions = std::move(extractor->moveJvmOptions());
extractor->iterateJarPaths([&](const std::string& s) { addJarToClasspath(s);});
}

void JavaVMImpl::shutdown() {
Expand Down
7 changes: 3 additions & 4 deletions exaudfclient/base/javacontainer/javacontainer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class JavaVMTest;
namespace SWIGVMContainers {

namespace JavaScriptOptions {
struct ScriptOptionsParser;
struct Extractor;
}

class JavaVMImpl {
Expand All @@ -25,8 +25,7 @@ class JavaVMImpl {
/*
* scriptOptionsParser: JavaVMImpl takes ownership of ScriptOptionsParser pointer.
*/
JavaVMImpl(bool checkOnly, bool noJNI,
std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser);
JavaVMImpl(bool checkOnly, bool noJNI, std::unique_ptr<JavaScriptOptions::Extractor> extractor);
~JavaVMImpl() {}
void shutdown();
bool run();
Expand All @@ -43,7 +42,7 @@ class JavaVMImpl {
void setClasspath();
void setJvmOptions();
void addJarToClasspath(const std::string& path);
void parseScriptOptions(std::unique_ptr<JavaScriptOptions::ScriptOptionsParser> scriptOptionsParser);
void parseScriptOptions(std::unique_ptr<JavaScriptOptions::Extractor> extractor);
bool m_checkOnly;
std::string m_exaJavaPath;
std::string m_localClasspath;
Expand Down
7 changes: 5 additions & 2 deletions exaudfclient/base/javacontainer/script_options/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package(default_visibility = ["//visibility:public"])

cc_library(
name = "java_script_option_lines",
hdrs = [":extractor.h", ":parser_legacy.h", ":parser_ctpg.h"],
srcs = [":parser.h", ":converter.h", ":converter.cc", ":parser_legacy.cc", ":extractor.cc",
hdrs = [":extractor.h", ":extractor_impl.h", ":parser_legacy.h", ":parser_ctpg.h",
":converter_v2.h", ":converter_legacy.h"],
srcs = [":parser.h", ":converter.h", ":converter.cc", ":parser_legacy.cc", ":extractor_impl.h",
":extractor_impl.cc", ":converter_legacy.cc", ":converter_legacy.h",
":converter_v2.cc", ":converter_v2.h",
":keywords.h", ":keywords.cc", ":checksum.h", ":checksum.cc", ":parser_ctpg.cc",
":parser_ctpg_script_importer.cc", ":parser_ctpg_script_importer.h", ":string_ops.h", ":string_ops.cc"],
deps = ["@ssl//:ssl", "//base/script_options_parser/legacy:script_option_lines_parser_legacy",
Expand Down
22 changes: 2 additions & 20 deletions exaudfclient/base/javacontainer/script_options/converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,8 @@ namespace SWIGVMContainers {
namespace JavaScriptOptions {

Converter::Converter()
: m_jvmOptions()
, m_jarPaths()
, m_whitespace(" \t\f\v") {}

void Converter::convertExternalJar(const std::string & value) {
for (size_t start = 0, delim = 0; ; start = delim + 1) {
delim = value.find(":", start);
if (delim != std::string::npos) {
std::string jar = value.substr(start, delim - start);
if (m_jarPaths.find(jar) == m_jarPaths.end())
m_jarPaths.insert(jar);
}
else {
std::string jar = value.substr(start);
if (m_jarPaths.find(jar) == m_jarPaths.end())
m_jarPaths.insert(jar);
break;
}
}
}
: m_whitespace(" \t\f\v")
, m_jvmOptions() {}

void Converter::convertScriptClassName(const std::string & value) {
std::string trimmedValue(value);
Expand Down
22 changes: 7 additions & 15 deletions exaudfclient/base/javacontainer/script_options/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@

#include <string>
#include <vector>
#include <set>
#include <memory>

#include "base/javacontainer/script_options/parser.h"


#include <functional>
#include <iterator>

namespace SWIGVMContainers {

Expand All @@ -19,32 +15,28 @@ class Converter {
public:
Converter();

void convertExternalJar(const std::string & value);
virtual void convertExternalJar(const std::string & value) = 0;

void convertScriptClassName(const std::string & value);

void convertJvmOption(const std::string & value);

const std::set<std::string> & getJarPaths() const {
return m_jarPaths;
}
virtual void iterateJarPaths(std::function<void(const std::string &option)> callback) const = 0;

std::vector<std::string>&& moveJvmOptions() {
return std::move(m_jvmOptions);
}

private:
protected:
const std::string m_whitespace;

private:
std::vector<std::string> m_jvmOptions;

std::set<std::string> m_jarPaths;

const std::string m_whitespace;
};




} //namespace JavaScriptOptions

} //namespace SWIGVMContainers
Expand Down
33 changes: 33 additions & 0 deletions exaudfclient/base/javacontainer/script_options/converter_legacy.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "base/javacontainer/script_options/converter_legacy.h"
#include "base/javacontainer/script_options/string_ops.h"
#include <iostream>

namespace SWIGVMContainers {

namespace JavaScriptOptions {

ConverterLegacy::ConverterLegacy()
: Converter()
, m_jarPaths() {}

void ConverterLegacy::convertExternalJar(const std::string & value) {
for (size_t start = 0, delim = 0; ; start = delim + 1) {
delim = value.find(":", start);
if (delim != std::string::npos) {
std::string jar = value.substr(start, delim - start);
if (m_jarPaths.find(jar) == m_jarPaths.end())
m_jarPaths.insert(jar);
}
else {
std::string jar = value.substr(start);
if (m_jarPaths.find(jar) == m_jarPaths.end())
m_jarPaths.insert(jar);
break;
}
}
}


} //namespace JavaScriptOptions

} //namespace SWIGVMContainers
43 changes: 43 additions & 0 deletions exaudfclient/base/javacontainer/script_options/converter_legacy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef SCRIPTOPTIONLINEPARSERCONVERTERLEGACY_H
#define SCRIPTOPTIONLINEPARSERCONVERTERLEGACY_H 1

#include <string>
#include <vector>
#include <set>
#include <memory>

#include "base/javacontainer/script_options/converter.h"



namespace SWIGVMContainers {

namespace JavaScriptOptions {

class ConverterLegacy : public Converter {

public:
ConverterLegacy();

void convertExternalJar(const std::string & value);

void iterateJarPaths(std::function<void(const std::string &option)> callback) const override {
for (const auto & jar: m_jarPaths) {
callback(jar);
}
}

private:

std::set<std::string> m_jarPaths;

};




} //namespace JavaScriptOptions

} //namespace SWIGVMContainers

#endif //SCRIPTOPTIONLINEPARSERCONVERTER_H
35 changes: 35 additions & 0 deletions exaudfclient/base/javacontainer/script_options/converter_v2.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "base/javacontainer/script_options/converter_v2.h"
#include "base/javacontainer/script_options/string_ops.h"
#include <iostream>

namespace SWIGVMContainers {

namespace JavaScriptOptions {

ConverterV2::ConverterV2()
: Converter()
, m_jarPaths() {}

void ConverterV2::convertExternalJar(const std::string & value) {
std::string unquotedValue(value);
StringOps::removeQuotesSafely(unquotedValue, m_whitespace);
for (size_t start = 0, delim = 0; ; start = delim + 1) {
delim = unquotedValue.find(":", start);
if (delim != std::string::npos) {
std::string jar = unquotedValue.substr(start, delim - start);
StringOps::removeQuotesSafely(jar, m_whitespace);
m_jarPaths.push_back(jar);
}
else {
std::string jar = unquotedValue.substr(start);
StringOps::removeQuotesSafely(jar, m_whitespace);
m_jarPaths.push_back(jar);
break;
}
}
}


} //namespace JavaScriptOptions

} //namespace SWIGVMContainers
43 changes: 43 additions & 0 deletions exaudfclient/base/javacontainer/script_options/converter_v2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef SCRIPTOPTIONLINEPARSERCONVERTERV2_H
#define SCRIPTOPTIONLINEPARSERCONVERTERV2_H 1

#include <string>
#include <vector>
#include <set>
#include <memory>

#include "base/javacontainer/script_options/converter.h"



namespace SWIGVMContainers {

namespace JavaScriptOptions {

class ConverterV2 : public Converter {

public:
ConverterV2();

void convertExternalJar(const std::string & value);

void iterateJarPaths(std::function<void(const std::string &option)> callback) const override {
for (const auto & jar : m_jarPaths) {
callback(jar);
}
}

private:

std::vector<std::string> m_jarPaths;

};




} //namespace JavaScriptOptions

} //namespace SWIGVMContainers

#endif //SCRIPTOPTIONLINEPARSERCONVERTER_H
Loading
Loading