logic: removed license options from commandline API, accept EULA via commandline if necessary
This commit is contained in:
+35
-25
@@ -7,7 +7,6 @@
|
||||
#include "data/indexer/IndexerFactoryModuleJava.h"
|
||||
#include "data/indexer/IndexerFactoryModuleCxxCdb.h"
|
||||
#include "data/indexer/IndexerFactoryModuleCxxEmpty.h"
|
||||
#include "LicenseChecker.h"
|
||||
#include "project/SourceGroupFactory.h"
|
||||
#include "project/SourceGroupFactoryModuleCxx.h"
|
||||
#include "project/SourceGroupFactoryModuleJava.h"
|
||||
@@ -16,6 +15,7 @@
|
||||
#include "qt/QtCoreApplication.h"
|
||||
#include "qt/utility/utilityQt.h"
|
||||
#include "qt/view/QtViewFactory.h"
|
||||
#include "qt/window/QtEulaWindow.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "utility/commandline/CommandLineParser.h"
|
||||
#include "utility/logging/ConsoleLogger.h"
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "utility/messaging/type/MessageStatus.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
#include "utility/ScopedFunctor.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
#include "utility/UserPaths.h"
|
||||
#include "utility/utility.h"
|
||||
#include "utility/utilityApp.h"
|
||||
@@ -128,7 +129,8 @@ void prefillCxxHeaderPaths()
|
||||
std::vector<FilePath> paths = cxxHeaderDetector->getPaths();
|
||||
if (!paths.empty())
|
||||
{
|
||||
MessageStatus(L"Ran C/C++ header path detection, found " + std::to_wstring(paths.size()) + L" path" + (paths.size() == 1 ? L"" : L"s")).dispatch();
|
||||
MessageStatus(L"Ran C/C++ header path detection, found " + std::to_wstring(paths.size()) + L" path" +
|
||||
(paths.size() == 1 ? L"" : L"s")).dispatch();
|
||||
|
||||
settings->setHeaderSearchPaths(paths);
|
||||
settings->save();
|
||||
@@ -145,7 +147,8 @@ void prefillCxxFrameworkPaths()
|
||||
std::vector<FilePath> paths = cxxFrameworkDetector->getPaths();
|
||||
if (!paths.empty())
|
||||
{
|
||||
MessageStatus(L"Ran C/C++ framework path detection, found " + std::to_wstring(paths.size()) + L" path" + (paths.size() == 1 ? L"" : L"s")).dispatch();
|
||||
MessageStatus(L"Ran C/C++ framework path detection, found " + std::to_wstring(paths.size()) + L" path" +
|
||||
(paths.size() == 1 ? L"" : L"s")).dispatch();
|
||||
|
||||
settings->setFrameworkSearchPaths(paths);
|
||||
settings->save();
|
||||
@@ -235,42 +238,49 @@ int main(int argc, char *argv[])
|
||||
Application::destroyInstance();
|
||||
});
|
||||
|
||||
// check if already agreed to EULA
|
||||
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
|
||||
if (appSettings->getAcceptedEulaVersion() < QtEulaWindow::EULA_VERSION)
|
||||
{
|
||||
// to avoid interferring with other console output
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
||||
|
||||
std::shared_ptr<TextAccess> text =
|
||||
TextAccess::createFromFile(ResourcePaths::getGuiPath().concatenate(L"installer/EULA.txt"));
|
||||
|
||||
std::cout << std::endl << text->getText() << std::endl;
|
||||
std::cout << "Do you accept the Sourcetrail Software License Agreement? (y/n)" << std::endl;
|
||||
|
||||
char c = 'n';
|
||||
std::cin >> c;
|
||||
|
||||
if (c == 'Y' || c == 'y')
|
||||
{
|
||||
std::cout << "\nAgreement accepted.\n" << std::endl;
|
||||
appSettings->setAcceptedEulaVersion(QtEulaWindow::EULA_VERSION);
|
||||
appSettings->save();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "\nAgreement not accepted. quitting..." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
prefillPaths();
|
||||
addLanguageModules();
|
||||
|
||||
std::shared_ptr<LicenseChecker> checker = LicenseChecker::getInstance();
|
||||
|
||||
signal(SIGINT, signalHandler);
|
||||
signal(SIGTERM, signalHandler);
|
||||
signal(SIGABRT, signalHandler);
|
||||
|
||||
commandLineParser.parse();
|
||||
if (commandLineParser.startedWithLicense())
|
||||
{
|
||||
utility::saveLicense(commandLineParser.getLicensePtr());
|
||||
}
|
||||
|
||||
if (commandLineParser.exitApplication())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!checker->isCurrentLicenseValid() && !ApplicationSettings::getInstance()->getNonCommercialUse())
|
||||
{
|
||||
std::string appName = argc > 0 && std::string(argv[0]).size() ? argv[0] : "sourcetrail";
|
||||
|
||||
std::cout << "\nERROR: No valid license option selected.\n\n";
|
||||
std::cout << "For commercial use please run:\n\n";
|
||||
std::cout << "\t" << appName << " config --license-string <Commercial License or Test License string>\n";
|
||||
std::cout << "or\n";
|
||||
std::cout << "\t" << appName << " config --license-file <path/to/Commercial License or Test License file>\n\n\n";
|
||||
std::cout << "For non-commercial use please run:\n\n";
|
||||
std::cout << "\t" << appName << " config --non-commercial-use true\n" << std::endl;
|
||||
|
||||
LOG_WARNING("Your current Sourcetrail license seems to be invalid. Please update your license info.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (commandLineParser.hasError() )
|
||||
{
|
||||
std::wcout << commandLineParser.getError() << std::endl;
|
||||
|
||||
@@ -6,12 +6,9 @@
|
||||
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
namespace commandline {
|
||||
|
||||
void parseConfigFile(po::variables_map& vm,
|
||||
po::options_description& options)
|
||||
void parseConfigFile(po::variables_map& vm, po::options_description& options)
|
||||
{
|
||||
if (vm.count("config-file"))
|
||||
{
|
||||
@@ -20,9 +17,7 @@ void parseConfigFile(po::variables_map& vm,
|
||||
|
||||
if (!ifs)
|
||||
{
|
||||
std::cout << "Could not open config file( "
|
||||
<< configFile << ")"
|
||||
<< std::endl;
|
||||
std::cout << "Could not open config file( " << configFile << ")" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -31,18 +26,6 @@ void parseConfigFile(po::variables_map& vm,
|
||||
}
|
||||
}
|
||||
|
||||
void conflicting_options(const boost::program_options::variables_map& vm,
|
||||
const char* opt1, const char* opt2)
|
||||
{
|
||||
if (vm.count(opt1) && !vm[opt1].defaulted()
|
||||
&& vm.count(opt2) && !vm[opt2].defaulted())
|
||||
{
|
||||
std::cout << "Options " << opt1
|
||||
<< " and " << opt2
|
||||
<< " are conflicted." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<FilePath> extractPaths(const std::vector<std::string>& vector)
|
||||
{
|
||||
std::vector<FilePath> v;
|
||||
|
||||
@@ -14,6 +14,8 @@ namespace program_options {
|
||||
}
|
||||
}
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
namespace commandline
|
||||
{
|
||||
enum class ReturnStatus {
|
||||
@@ -22,14 +24,9 @@ namespace commandline
|
||||
CMD_FAILURE
|
||||
};
|
||||
|
||||
void parseConfigFile(boost::program_options::variables_map& vm,
|
||||
boost::program_options::options_description& options);
|
||||
|
||||
void conflicting_options(const boost::program_options::variables_map& vm,
|
||||
const char* opt1, const char* opt2);
|
||||
void parseConfigFile(po::variables_map& vm, po::options_description& options);
|
||||
|
||||
std::vector<FilePath> extractPaths(const std::vector<std::string>& vector);
|
||||
|
||||
}
|
||||
|
||||
#endif // COMMANDLINE_HELPER_H
|
||||
|
||||
@@ -3,28 +3,23 @@
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
#include "utility/UserPaths.h"
|
||||
#include "utility/commandline/CommandlineHelper.h"
|
||||
#include "utility/commandline/CommandLineParser.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "PublicKey.h"
|
||||
#include "utility/AppPath.h"
|
||||
|
||||
namespace po = boost::program_options;
|
||||
#include "settings/ApplicationSettings.h"
|
||||
|
||||
namespace commandline {
|
||||
|
||||
// helper functions
|
||||
typedef void(ApplicationSettings::*intFunc)(int);
|
||||
void parseAndSetValue(
|
||||
intFunc f,
|
||||
const char* opt,
|
||||
ApplicationSettings* settings,
|
||||
po::variables_map& vm)
|
||||
intFunc f,
|
||||
const char* opt,
|
||||
ApplicationSettings* settings,
|
||||
po::variables_map& vm)
|
||||
{
|
||||
if (vm.count(opt))
|
||||
{
|
||||
@@ -34,10 +29,10 @@ void parseAndSetValue(
|
||||
|
||||
typedef void(ApplicationSettings::*boolFunc)(bool);
|
||||
void parseAndSetValue(
|
||||
boolFunc f,
|
||||
const char* opt,
|
||||
ApplicationSettings* settings,
|
||||
po::variables_map& vm)
|
||||
boolFunc f,
|
||||
const char* opt,
|
||||
ApplicationSettings* settings,
|
||||
po::variables_map& vm)
|
||||
{
|
||||
if (vm.count(opt))
|
||||
{
|
||||
@@ -47,10 +42,10 @@ void parseAndSetValue(
|
||||
|
||||
typedef void(ApplicationSettings::*filePathFunc)(const FilePath&);
|
||||
void parseAndSetValue(
|
||||
filePathFunc f,
|
||||
const char* opt,
|
||||
ApplicationSettings* settings,
|
||||
po::variables_map& vm)
|
||||
filePathFunc f,
|
||||
const char* opt,
|
||||
ApplicationSettings* settings,
|
||||
po::variables_map& vm)
|
||||
{
|
||||
if (vm.count(opt))
|
||||
{
|
||||
@@ -66,10 +61,10 @@ void parseAndSetValue(
|
||||
|
||||
typedef bool(ApplicationSettings::*vectorFunc)(const std::vector<FilePath>&);
|
||||
void parseAndSetValue(
|
||||
vectorFunc f,
|
||||
const char* opt,
|
||||
ApplicationSettings* settings,
|
||||
po::variables_map& vm)
|
||||
vectorFunc f,
|
||||
const char* opt,
|
||||
ApplicationSettings* settings,
|
||||
po::variables_map& vm)
|
||||
{
|
||||
if (vm.count(opt))
|
||||
{
|
||||
@@ -96,22 +91,21 @@ void CommandConfig::setup()
|
||||
("use-processes,p", po::value<bool>(), "Enable C/C++ Indexer threads to run in different processes. <true/false>")
|
||||
("logging-enabled,l", po::value<bool>(), "Enable file/console logging <true/false>")
|
||||
("verbose-indexer-logging-enabled,L", po::value<bool>(),
|
||||
"Enable additional log of abstract syntax tree during the indexing. <true/false> WARNINIG Slows down indexing speed")
|
||||
"Enable additional log of abstract syntax tree during the indexing. <true/false> WARNINIG Slows down "
|
||||
"indexing speed")
|
||||
("jvm-path,j", po::value<std::string>(), "Path to the location of the jvm library")
|
||||
("jvm-max-memory,M", po::value<int>(),
|
||||
"Set the maximum amount of memory for the JVM indexer(-1 for using the JVM default settings)")
|
||||
"Set the maximum amount of memory for the JVM indexer(-1 for using the JVM default settings)")
|
||||
("maven-path,m", po::value<std::string>(), "Path to the maven binary")
|
||||
("jre-system-library-paths,J", po::value<std::vector<std::string>>(),
|
||||
"paths to the jars of the JRE system library. "
|
||||
"These jars can be found inside your JRE install directory (once per path or comma separated)")
|
||||
("license-file,z", po::value<std::string>(), "Enter license via Licensefile")
|
||||
("license-string,Z", po::value<std::string>(), "Enter licenes via commandline")
|
||||
"paths to the jars of the JRE system library. "
|
||||
"These jars can be found inside your JRE install directory (once per path or comma separated)")
|
||||
("global-header-search-paths,g", po::value<std::vector<std::string>>(),
|
||||
"Global include paths (once per path or comma separated)")
|
||||
"Global include paths (once per path or comma separated)")
|
||||
("global-framework-search-paths,F", po::value<std::vector<std::string>>(),
|
||||
"Global include paths (once per path or comma separated)")
|
||||
"Global include paths (once per path or comma separated)")
|
||||
("show,s", "displays all settings")
|
||||
("non-commercial-use", po::value<bool>(), "Enable non-commercial use. <true/false>");
|
||||
;
|
||||
|
||||
m_options.add(options);
|
||||
}
|
||||
@@ -202,51 +196,6 @@ ReturnStatus CommandConfig::parse(std::vector<std::string>& args)
|
||||
parseAndSetValue(&ApplicationSettings::setHeaderSearchPaths, "global-header-search-paths", settings, vm);
|
||||
parseAndSetValue(&ApplicationSettings::setFrameworkSearchPaths, "global-framework-search-paths", settings, vm);
|
||||
|
||||
parseAndSetValue(&ApplicationSettings::setNonCommercialUse, "non-commercial-use", settings, vm);
|
||||
|
||||
// license
|
||||
if (vm.count("license-string") || vm.count("license-file") )
|
||||
{
|
||||
bool licenseLoaded = false;
|
||||
if (vm.count("license-string"))
|
||||
{
|
||||
std::string licensetext = utility::replace(vm["license-string"].as<std::string>(), "\\n", "\n");
|
||||
licenseLoaded = m_parser->getLicensePtr()->loadFromString(licensetext);
|
||||
}
|
||||
|
||||
if (vm.count("license-file"))
|
||||
{
|
||||
const std::string licensefile = vm["license-file"].as<std::string>();
|
||||
if (FilePath(licensefile).exists())
|
||||
{
|
||||
std::cout << "Load license from file" << std::endl;
|
||||
licenseLoaded = m_parser->getLicensePtr()->loadFromFile(licensefile);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << licensefile << " not found" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (licenseLoaded)
|
||||
{
|
||||
if (!m_parser->getLicensePtr()->isValid())
|
||||
{
|
||||
std::cout << "License is not valid" << std::endl;
|
||||
return ReturnStatus::CMD_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "License is valid" << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Could not load License" << std::endl;
|
||||
return ReturnStatus::CMD_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
settings->save();
|
||||
|
||||
return ReturnStatus::CMD_QUIT;
|
||||
|
||||
Reference in New Issue
Block a user