Skip to content

Commit

Permalink
#990: Forward jar options without changing order
Browse files Browse the repository at this point in the history
  • Loading branch information
tomuben committed Oct 24, 2024
1 parent 23d5d1a commit 67d283e
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 35 deletions.
4 changes: 1 addition & 3 deletions exaudfclient/base/javacontainer/javacontainer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ void JavaVMImpl::parseScriptOptions(std::unique_ptr<JavaScriptOptions::Extractor

m_jvmOptions = std::move(extractor->moveJvmOptions());

for (const auto & jar : extractor->getJarPaths()) {
addJarToClasspath(jar);
}
extractor->iterateJarPaths([&](const std::string& s) { addJarToClasspath(s);});
}

void JavaVMImpl::shutdown() {
Expand Down
4 changes: 2 additions & 2 deletions exaudfclient/base/javacontainer/script_options/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <string>
#include <vector>
#include <set>
#include <functional>

namespace SWIGVMContainers {

Expand All @@ -24,7 +24,7 @@ class Converter {

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

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


private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@ void ConverterLegacy::convertExternalJar(const std::string& value) {
std::string jar;

while (std::getline(stream, jar, ':')) {
m_jarPaths.insert(jar);
if (m_jarPaths.find(jar) == m_jarPaths.end()) {
m_jarPaths.insert(jar);
}
}
}

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



} //namespace JavaScriptOptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ class ConverterLegacy : public Converter {

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

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

private:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ void ConverterV2::convertExternalJar(const std::string & value) {
std::string jar;

while (std::getline(stream, jar, ':')) {
m_jarPaths.insert(jar);
m_jarPaths.push_back(jar);
}
}

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


} //namespace JavaScriptOptions

} //namespace SWIGVMContainers
7 changes: 2 additions & 5 deletions exaudfclient/base/javacontainer/script_options/converter_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

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

#include "base/javacontainer/script_options/converter.h"
Expand All @@ -21,13 +20,11 @@ class ConverterV2 : public Converter {

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

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

private:

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

};

Expand Down
4 changes: 2 additions & 2 deletions exaudfclient/base/javacontainer/script_options/extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <string>
#include <vector>
#include <set>
#include <functional>


namespace SWIGVMContainers {
Expand All @@ -13,7 +13,7 @@ namespace JavaScriptOptions {
struct Extractor {
virtual ~Extractor() {}

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

virtual std::vector<std::string>&& moveJvmOptions() = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ ExtractorImpl<TParser, TConverter>::ExtractorImpl(std::unique_ptr<SwigFactory> s
, m_converter() {}

template<typename TParser, typename TConverter>
inline const std::set<std::string> & ExtractorImpl<TParser, TConverter>::getJarPaths() const {
return m_converter.getJarPaths();
void ExtractorImpl<TParser, TConverter>::iterateJarPaths(std::function<void(const std::string &option)> callback) const {
return m_converter.iterateJarPaths(callback);
}

template<typename TParser, typename TConverter>
inline std::vector<std::string>&& ExtractorImpl<TParser, TConverter>::moveJvmOptions() {
std::vector<std::string>&& ExtractorImpl<TParser, TConverter>::moveJvmOptions() {
return std::move(m_converter.moveJvmOptions());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ExtractorImpl : public Extractor {

ExtractorImpl(std::unique_ptr<SwigFactory> swigFactory);

const std::set<std::string> & getJarPaths() const override;
virtual void iterateJarPaths(std::function<void(const std::string &option)> callback) const override;
std::vector<std::string>&& moveJvmOptions() override;

void extract(std::string & scriptCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@
using namespace SWIGVMContainers::JavaScriptOptions;


class LegacyConverterJarTest : public ::testing::TestWithParam<std::pair<std::string, std::set<std::string>>> {};
class LegacyConverterJarTest : public ::testing::TestWithParam<std::pair<std::string, std::vector<std::string>>> {};

TEST_P(LegacyConverterJarTest, jar) {
const std::pair<std::string, std::set<std::string>> option_value = GetParam();
const std::pair<std::string, std::vector<std::string>> option_value = GetParam();
const std::string jar_option_value = option_value.first;

ConverterLegacy converter;
converter.convertExternalJar(option_value.first);
ASSERT_EQ(converter.getJarPaths(), option_value.second);
std::vector<std::string> result;
converter.iterateJarPaths([&](auto jar) {result.push_back(jar);});
ASSERT_EQ(result, option_value.second);
}

const std::vector<std::pair<std::string, std::set<std::string>>> jar_strings =
const std::vector<std::pair<std::string, std::vector<std::string>>> jar_strings =
{
std::make_pair("test.jar:test2.jar", std::set<std::string>({"test.jar", "test2.jar"})),
std::make_pair("\"test.jar:test2.jar\"", std::set<std::string>({"\"test.jar", "test2.jar\""})),
std::make_pair("t\\:est.jar:test2.jar", std::set<std::string>({"t\\", "est.jar", "test2.jar"})),
std::make_pair("test.jar:test2.jar", std::vector<std::string>({"test.jar", "test2.jar"})),
std::make_pair("test.jar:test.jar", std::vector<std::string>({"test.jar"})),
std::make_pair("testDEF.jar:testABC.jar", std::vector<std::string>({"testABC.jar", "testDEF.jar"})),
};

INSTANTIATE_TEST_SUITE_P(
Expand All @@ -33,23 +35,25 @@ INSTANTIATE_TEST_SUITE_P(



class ConverterV2JarTest : public ::testing::TestWithParam<std::pair<std::string, std::set<std::string>>> {};
class ConverterV2JarTest : public ::testing::TestWithParam<std::pair<std::string, std::vector<std::string>>> {};

TEST_P(ConverterV2JarTest, jar) {
const std::pair<std::string, std::set<std::string>> option_value = GetParam();
const std::pair<std::string, std::vector<std::string>> option_value = GetParam();
const std::string jar_option_value = option_value.first;
std::cerr << "DEBUG: " << jar_option_value << std::endl;

ConverterV2 converter;
converter.convertExternalJar(option_value.first);
ASSERT_EQ(converter.getJarPaths(), option_value.second);
std::vector<std::string> result;
converter.iterateJarPaths([&](auto jar) {result.push_back(jar);});
ASSERT_EQ(result, option_value.second);
}

const std::vector<std::pair<std::string, std::set<std::string>>> jar_escape_sequences =
const std::vector<std::pair<std::string, std::vector<std::string>>> jar_escape_sequences =
{
std::make_pair("test.jar:test2.jar", std::set<std::string>({"test.jar", "test2.jar"})),
std::make_pair("\"test.jar:test2.jar\"", std::set<std::string>({"\"test.jar", "test2.jar\""})),
std::make_pair("t\\:est.jar:test2.jar", std::set<std::string>({"t\\", "est.jar", "test2.jar"})),
std::make_pair("test.jar:test2.jar", std::vector<std::string>({"test.jar", "test2.jar"})),
std::make_pair("test.jar:test.jar", std::vector<std::string>({"test.jar", "test.jar"})),
std::make_pair("testDEF.jar:testABC.jar", std::vector<std::string>({"testDEF.jar", "testABC.jar"})),
};

INSTANTIATE_TEST_SUITE_P(
Expand Down

0 comments on commit 67d283e

Please sign in to comment.