logic: commandline indexing and configuration

This commit is contained in:
Andreas Stallinger
2017-08-09 12:33:43 +02:00
parent 2399e733b4
commit 802153883e
53 changed files with 1384 additions and 298 deletions
+12 -8
View File
@@ -6,6 +6,7 @@
#include "utility/messaging/filter_types/MessageFilterFocusInOut.h"
#include "utility/messaging/filter_types/MessageFilterSearchAutocomplete.h"
#include "utility/messaging/MessageQueue.h"
#include "utility/messaging/type/MessageQuitApplication.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/scheduling/TaskScheduler.h"
#include "utility/tracing.h"
@@ -230,6 +231,10 @@ void Application::refreshProject(bool force)
m_componentManager->refreshViews();
}
}
else if (!m_hasGUI)
{
MessageQuitApplication().dispatch();
}
}
}
@@ -270,18 +275,17 @@ void Application::handleMessage(MessageLoadProject* message)
return;
}
if (m_project && projectSettingsFilePath == m_project->getProjectSettingsFilePath())
if (!m_project || projectSettingsFilePath != m_project->getProjectSettingsFilePath())
{
if (message->forceRefresh)
{
m_project->setStateSettingsUpdated();
refreshProject(false);
}
createAndLoadProject(projectSettingsFilePath);
}
return;
if (message->forceRefresh)
{
m_project->setStateSettingsUpdated();
refreshProject(false);
}
createAndLoadProject(projectSettingsFilePath);
}
void Application::handleMessage(MessageRefresh* message)
+17 -2
View File
@@ -21,8 +21,9 @@ add_files(
component/controller/BookmarkController.h
component/controller/CodeController.cpp
component/controller/CodeController.h
component/controller/Controller.cpp
component/controller/Controller.h
#component/controller/Controller.cpp
component/controller/Controller
#component/controller/Controller.h
component/controller/ErrorController.cpp
component/controller/ErrorController.h
component/controller/GraphController.cpp
@@ -299,10 +300,23 @@ add_files(
settings/SourceGroupSettingsJava.cpp
settings/SourceGroupSettingsJava.h
settings/SourceGroupType.cpp
settings/SourceGroupType.h
utility/commandline/CommandlineHelper.cpp
utility/commandline/CommandlineHelper.h
utility/commandline/CommandLineParser.cpp
utility/commandline/CommandLineParser.h
utility/commandline/commands/CommandlineCommand
utility/commandline/commands/CommandlineCommandConfig
utility/commandline/commands/CommandlineCommandIndex
# utility/commandline/commands/CommandlineSourceGroupOptions.h
# utility/commandline/commands/CommandlineSourceGroupOptionsC.cpp
# utility/commandline/commands/CommandlineSourceGroupOptionsC.h
# utility/commandline/commands/CommandlineSourceGroupOptionsCxx.cpp
# utility/commandline/commands/CommandlineSourceGroupOptionsCxx.h
# utility/commandline/commands/CommandlineSourceGroupOptionsJava.cpp
# utility/commandline/commands/CommandlineSourceGroupOptionsJava.h
utility/file/FileInfo.cpp
utility/file/FileInfo.h
@@ -399,6 +413,7 @@ add_files(
utility/messaging/type/MessagePluginPortChange.h
utility/messaging/type/MessageProjectEdit.h
utility/messaging/type/MessageProjectNew.h
utility/messaging/type/MessageQuitApplication.h
utility/messaging/type/MessageRedo.h
utility/messaging/type/MessageRefresh.h
utility/messaging/type/MessageResetZoom.h
+4 -14
View File
@@ -2,6 +2,7 @@
#include "utility/AppPath.h"
#include "utility/logging/logging.h"
#include "utility/utilityApp.h"
#include "utility/messaging/type/MessageForceEnterLicense.h"
#include "License.h"
@@ -44,25 +45,14 @@ std::string LicenseChecker::getCurrentLicenseString() const
void LicenseChecker::saveCurrentLicenseString(const std::string& licenseString) const
{
License license;
// license.loadPublicKeyFromString(PUBLIC_KEY);
bool isLoaded = license.loadFromString(licenseString);
if (!isLoaded)
{
return;
}
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
if (appSettings == NULL)
{
LOG_ERROR_STREAM(<< "Unable to retrieve app settings");
return;
}
std::string appPath(AppPath::getAppPath());
appSettings->setLicenseString(license.getLicenseEncodedString(appPath));
appSettings->setLicenseCheck(license.hashLocation(FilePath(appPath).absolute().str()));
appSettings->save();
utility::saveLicense(&license);
}
bool LicenseChecker::isCurrentLicenseValid()
@@ -194,7 +184,7 @@ void LicenseChecker::handleMessage(MessageEnteredLicense* message)
LicenseChecker::LicenseState LicenseChecker::checkLicense(License& license) const
{
license.loadPublicKeyFromString(PUBLIC_KEY);
// license.loadPublicKeyFromString(PUBLIC_KEY);
if (license.isExpired())
{
+11
View File
@@ -3,6 +3,7 @@
#include "component/view/DialogView.h"
#include "data/storage/PersistentStorage.h"
#include "utility/messaging/type/MessageFinishedParsing.h"
#include "utility/messaging/type/MessageQuitApplication.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/scheduling/Blackboard.h"
#include "utility/utility.h"
@@ -41,6 +42,11 @@ Task::TaskState TaskFinishParsing::doUpdate(std::shared_ptr<Blackboard> blackboa
dialogView->hideUnknownProgressDialog();
MessageFinishedParsing().dispatch();
if (!Application::getInstance()->hasGUI())
{
MessageQuitApplication().dispatch();
}
float time = utility::duration(start);
if (blackboard->exists("clear_time"))
@@ -98,4 +104,9 @@ void TaskFinishParsing::terminate()
MessageStatus("An unknown exception was thrown during indexing.", true, false).dispatch();
MessageFinishedParsing().dispatch();
if (!Application::getInstance()->hasGUI())
{
MessageQuitApplication().dispatch();
}
}
+1 -1
View File
@@ -50,7 +50,7 @@ private:
template <typename ComponentType>
ComponentType* Token::getComponent() const
{
for (std::shared_ptr<TokenComponent> component: m_components)
for (const std::shared_ptr<TokenComponent>& component: m_components)
{
TokenComponent* componentPtr = component.get();
if (typeid(ComponentType) == typeid(*componentPtr))
+11
View File
@@ -11,6 +11,7 @@
#include "data/indexer/IndexerCommandList.h"
#include "data/indexer/interprocess/InterprocessIndexer.h"
#include "data/storage/StorageProvider.h"
#include "utility/messaging/type/MessageStatus.h"
#if _WIN32
const std::string TaskBuildIndex::s_processName("sourcetrail_indexer.exe");
@@ -267,6 +268,16 @@ void TaskBuildIndex::updateIndexingDialog(
blackboard->get("indexed_source_file_count", indexedSourceFileCount);
}
if (!sourcePath.empty())
{
std::stringstream ss;
ss << "[" << m_indexingFileCount
<< "/" << sourceFileCount
<< "] Indexing file: ";
ss << sourcePath.str();
MessageStatus(ss.str(), false, true).dispatch();
}
if (std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView())
{
dialogView->updateIndexingDialog(
+1 -1
View File
@@ -22,7 +22,7 @@ void TaskParseWrapper::doEnter(std::shared_ptr<Blackboard> blackboard)
if (std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView())
{
dialogView->updateIndexingDialog(0, 0, sourceFileCount, "");
}
}
m_start = utility::durationStart();
+7 -11
View File
@@ -108,9 +108,7 @@ bool Project::refresh(bool forceRefresh)
Application::getInstance()->hasGUI()
)
{
std::vector<std::string> options;
options.push_back("Yes");
options.push_back("No");
std::vector<std::string> options = { "Yes", "No" };
int result = dialogView->confirm(
"Warning: You are about to index your project with the \"verbose indexer logging\" setting "
"enabled. This will cause a significant slowdown in indexing performance. Do you want to proceed?",
@@ -123,12 +121,9 @@ bool Project::refresh(bool forceRefresh)
}
}
if (!forceRefresh && needsFullRefresh && question.size() && Application::getInstance()->hasGUI())
{
std::vector<std::string> options;
options.push_back("Yes");
options.push_back("No");
std::vector<std::string> options = { "Yes", "No"};
int result = dialogView->confirm(question, options);
if (result == 1)
@@ -139,8 +134,7 @@ bool Project::refresh(bool forceRefresh)
if (Application::getInstance()->isInTrial())
{
std::vector<std::string> options;
options.push_back("Ok");
std::vector<std::string> options = { "Ok" };
dialogView->confirm("You can't refresh the project in trial mode, please unlock with a license key.", options);
MessageDispatchWhenLicenseValid(std::make_shared<MessageRefresh>()).dispatch();
@@ -148,7 +142,6 @@ bool Project::refresh(bool forceRefresh)
return false;
}
dialogView->showUnknownProgressDialog("Preparing Project", "Processing Files");
ScopedFunctor dialogHider([&dialogView](){
@@ -275,7 +268,9 @@ void Project::load()
MessageStatus("Project not loaded", false, false).dispatch();
}
if (m_state != PROJECT_STATE_LOADED)
// refresh always on headless
// since just opening a project in headless does not make sense
if (m_state != PROJECT_STATE_LOADED || !Application::getInstance()->hasGUI())
{
MessageRefresh().dispatch();
}
@@ -355,6 +350,7 @@ bool Project::requestIndex(bool forceRefresh, bool needsFullRefresh)
filesToAdd = staticSourceFiles;
}
std::set<FilePath> staticSourceFilePaths;
for (const FilePath& path: allSourceFilePaths)
{
+2 -2
View File
@@ -262,9 +262,9 @@ std::string ApplicationSettings::getJavaPath() const
return getValue<std::string>("indexing/java/java_path", "");
}
void ApplicationSettings::setJavaPath(const std::string path)
void ApplicationSettings::setJavaPath(const FilePath& path)
{
setValue<std::string>("indexing/java/java_path", path);
setValue<std::string>("indexing/java/java_path", path.str());
}
int ApplicationSettings::getJavaMaximumMemory() const
+1 -1
View File
@@ -79,7 +79,7 @@ public:
void setMultiProcessIndexingEnabled(bool enabled);
std::string getJavaPath() const;
void setJavaPath(const std::string path);
void setJavaPath(const FilePath& path);
int getJavaMaximumMemory() const;
void setJavaMaximumMemory(int size);
+178 -101
View File
@@ -1,9 +1,14 @@
#include "utility/commandline/CommandLineParser.h"
#include <iostream>
#include <fstream>
#include <utility>
#include "boost/program_options.hpp"
#include "utility/commandline/CommandlineHelper.h"
#include "utility/commandline/commands/CommandlineCommandConfig.h"
#include "utility/commandline/commands/CommandlineCommandIndex.h"
#include "utility/ConfigManager.h"
#include "utility/text/TextAccess.h"
#include "utility/utilityString.h"
@@ -12,112 +17,172 @@
namespace po = boost::program_options;
CommandLineParser::CommandLineParser(int argc, char** argv, const std::string& version)
: m_force(false)
, m_quit(false)
, m_withLicense(false)
, m_withoutGUI(false)
namespace commandline
{
std::string projectfile;
std::string projectfile_db;
std::string licensefile;
std::string licensetext;
po::options_description desc("Sourcetrail");
desc.add_options()
CommandLineParser::CommandLineParser(const std::string& version)
: m_version(version)
{
setup();
}
void CommandLineParser::setup()
{
po::options_description options("Sourcetrail Options");
options.add_options()
("help,h", "Print this help message")
("version,v", "Version of Sourcetrail")
("project,p", "Load Sourcetrail with a Sourcetrailprojectfile")
("project-file", po::value<std::string>(), "Open Sourcetrail with this project")
;
po::positional_options_description positionalOption;
positionalOption.add("project-file", 1);
po::options_description hidden_desc("hidden commandlineflags");
hidden_desc.add_options()
("force,f", "Force sourcetrail to parse if database exists")
("licenseFile,z", po::value<std::string>(&licensefile), "Enter license via Licensefile")
("license,l", po::value<std::string>(&licensetext), "Enter licenes via commandline")
("hidden", "Print this help message with hidden arguments")
("database,d", "Start sourcetrail to parse a Sourcetrail projectfile to get a sourcetraildatabase")
("project-file", po::value<std::string>(&projectfile), "Sourcetrail project file");
;
po::options_description all("Allowed options");
all.add(desc).add(hidden_desc);
m_options.add(options);
m_positional.add("project-file", 1);
addCommand(std::make_unique<commandline::CommandConfig>(this));
addCommand(std::make_unique<commandline::CommandIndex>(this));
po::variables_map vm;
po::store(po::command_line_parser(argc,argv).options(all).positional(positionalOption).allow_unregistered().run(), vm);
po::notify(vm);
if (vm.count("help"))
for ( auto& command : m_commands)
{
std::cout << desc << std::endl;
m_quit = true;
command->setup();
}
if (vm.count("hidden"))
{
std::cout << all << std::endl;
m_quit = true;
}
if (vm.count("force"))
{
m_force = true;
}
if (vm.count("license"))
{
licensetext = utility::replace(licensetext, "\\n", "\n");
processLicense(m_license.loadFromString(licensetext));
}
if (vm.count("licenseFile"))
{
std::cout << "licensefile flag" << std::endl;
if (FilePath(licensefile).exists())
{
std::cout << "licensefile exists" << std::endl;
processLicense(m_license.loadFromFile(licensefile));
}
else
{
std::cout << licensefile << " not found" << std::endl;
}
}
if (vm.count("version"))
{
std::cout << "Sourcetrail Version " << version << std::endl;
m_quit = true;
}
if (vm.count("project-file"))
{
processProjectfile(projectfile);
if (vm.count("database"))
{
m_withoutGUI = true;
}
}
else if (vm.count("database") || vm.count("project") ) {
std::cout << "A project file is needed for this option" << std::endl;
}
}
void CommandLineParser::processLicense(const bool isLoaded)
void CommandLineParser::setProjectFile(const FilePath &filepath)
{
if (!isLoaded)
{
std::cout << "Could not load License" << std::endl;
}
m_license.loadPublicKeyFromString(PUBLIC_KEY);
if (!m_license.isValid())
{
std::cout << "License is not valid" << std::endl;
}
m_withLicense = true;
m_withoutGUI = true;
m_projectFile = filepath;
processProjectfile();
}
void CommandLineParser::addCommand(std::unique_ptr<Command> command)
{
m_commands.push_back(std::move(command));
}
void CommandLineParser::preparse(int argc, char** argv)
{
// put argv into a string vector
std::vector<std::string> args;
for(int i = 1; i < argc; i++)
{
args.push_back(std::string(argv[i]));
}
preparse(args);
}
void CommandLineParser::preparse(std::vector<std::string>& args)
{
if (args.size() < 1)
{
return;
}
m_args = std::move(args);
try
{
// parsing for all commands
for ( auto& command : m_commands)
{
if ( m_args[0] == command->name())
{
m_withoutGUI = true;
return;
}
}
po::variables_map vm;
po::positional_options_description positional;
positional.add("project-file",1);
po::store(po::command_line_parser(m_args).options(m_options).positional(positional).allow_unregistered().run(), vm);
po::notify(vm);
if (vm.count("version"))
{
std::cout << "Sourcetrail Version " << m_version << std::endl;
m_quit = true;
return;
}
if (vm.count("help"))
{
printHelp();
m_quit = true;
}
if (vm.count("project-file"))
{
m_projectFile = FilePath(vm["project-file"].as<std::string>());
processProjectfile();
}
}
catch(boost::program_options::error& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
std::cerr << m_options << std::endl;
}
}
void CommandLineParser::parse()
{
if (m_args.size() < 1)
{
return;
}
try
{
// parsing for all commands
for ( auto& command : m_commands)
{
if ( m_args[0] == command->name())
{
m_args.erase(m_args.begin());
ReturnStatus status = command->parse(m_args);
if (status == ReturnStatus::CMD_QUIT
|| status == ReturnStatus::CMD_FAILURE)
{
m_quit = true;
}
}
}
}
catch(boost::program_options::error& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
std::cerr << m_options << std::endl;
}
}
License* CommandLineParser::getLicensePtr()
{
return &m_license;
}
void CommandLineParser::printHelp() const
{
std::cout << "Usage:\n sourcetrail [command] [option...] [positional arguments]\n\n";
// Commands
std::cout << "Commands:\n";
for (auto& Command : m_commands)
{
std::cout << " " << Command->name() << "\n";
}
std::cout << "\n * Each Commands has his own --help\n";
std::cout << m_options << std::endl;
if (m_positional.max_total_count() > 0)
{
std::cout << "Positional Arguments: ";
for (unsigned int i = 0; i < m_positional.max_total_count(); i++)
{
std::cout << "\n " << i+1 << ": " << m_positional.name_for_position(i);
}
std::cout << std::endl;
}
}
bool CommandLineParser::hasError()
{
return !m_errorString.empty();
@@ -144,34 +209,39 @@ bool CommandLineParser::exitApplication()
bool CommandLineParser::startedWithLicense()
{
return m_withLicense;
if (m_license.getUser().empty())
{
return false;
}
return m_license.isValid();
}
void CommandLineParser::processProjectfile(const std::string& file)
void CommandLineParser::processProjectfile()
{
FilePath projectfile = FilePath(file).absolute();
m_projectFile = m_projectFile.absolute();
const std::string errorstring =
"Provided Projectfile is not valid:\n* Provided Projectfile('" + projectfile.fileName() + "') ";
if (!projectfile.exists())
"Provided Projectfile is not valid:\n* Provided Projectfile('" + m_projectFile.fileName() + "') ";
if (!m_projectFile.exists())
{
m_errorString = errorstring + " does not exist";
m_projectFile = FilePath();
return;
}
if (projectfile.extension() != ".srctrlprj" && projectfile.extension() != ".coatiproject")
if (m_projectFile.extension() != ".srctrlprj" && m_projectFile.extension() != ".coatiproject")
{
m_errorString = errorstring + " has a wrong fileending";
m_projectFile = FilePath();
return;
}
std::shared_ptr<ConfigManager> configManager = ConfigManager::createEmpty();
if (!configManager->load(TextAccess::createFromFile(projectfile)))
if (!configManager->load(TextAccess::createFromFile(m_projectFile)))
{
m_errorString = errorstring + " could not be loaded(invalid)";
m_projectFile = FilePath();
return;
}
m_projectFile = projectfile;
}
License CommandLineParser::getLicense()
@@ -179,6 +249,11 @@ License CommandLineParser::getLicense()
return m_license;
}
void CommandLineParser::force()
{
m_force = true;
}
const FilePath& CommandLineParser::getProjectFilePath() const
{
return m_projectFile;
@@ -188,3 +263,5 @@ bool CommandLineParser::getFullProjectRefresh() const
{
return m_force;
}
} // namespace cmd
@@ -1,39 +1,75 @@
#ifndef COMMANDLINEPARSER_H
#define COMMANDLINEPARSER_H
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include "boost/program_options.hpp"
#include "License.h"
#include "utility/file/FilePath.h"
namespace po = boost::program_options;
namespace commandline {
class Command;
class CommandLineParser
{
public:
CommandLineParser(int argc, char** argv, const std::string& version);
CommandLineParser(const std::string& version);
~CommandLineParser();
void setup();
void preparse(int argc, char** argv);
/// args will be moved so dont use them after calling this function
void preparse(std::vector<std::string>& args);
void parse();
bool runWithoutGUI();
bool exitApplication();
bool startedWithLicense();
bool hasError();
void force();
std::string getError();
License getLicense();
License* getLicensePtr();
const FilePath& getProjectFilePath() const;
void setProjectFile(const FilePath& filepath);
bool getFullProjectRefresh() const;
private:
void processProjectfile(const std::string& file);
void addCommand(std::unique_ptr<Command> command);
void processProjectfile();
void processLicense(const bool isLoaded);
void printHelp() const;
FilePath m_projectFile;
bool m_force;
bool m_quit;
bool m_withLicense;
bool m_withoutGUI;
std::vector<std::shared_ptr<Command>> m_commands;
const std::string m_version;
bool m_force{false};
bool m_quit{false};
bool m_withoutGUI{false};
boost::program_options::options_description m_options;
boost::program_options::positional_options_description m_positional;
std::string m_errorString;
License m_license;
std::vector<std::string> m_args;
};
} // namespace cmd
#endif //COMMANDLINEPARSER_H
@@ -0,0 +1,60 @@
#include "utility/commandline/CommandlineHelper.h"
#include <fstream>
#include <iostream>
#include <string>
#include "boost/program_options.hpp"
namespace po = boost::program_options;
namespace commandline {
void parseConfigFile(po::variables_map& vm,
po::options_description& options)
{
if (vm.count("config-file"))
{
const std::string configFile = vm["config-file"].as<std::string>();
std::ifstream ifs(configFile.c_str());
if (!ifs)
{
std::cout << "Could not open config file( "
<< configFile << ")"
<< std::endl;
}
else
{
po::store(po::parse_config_file(ifs, options), 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;
for (std::string s : vector)
{
std::vector<std::string> temp= utility::splitToVector(s, ',');
for (std::string path : temp)
{
v.push_back(FilePath(path));
}
}
return std::move(v);
}
} // namespace cmd
@@ -0,0 +1,35 @@
#ifndef COMMANDLINE_HELPER_H
#define COMMANDLINE_HELPER_H
#include <string>
#include <vector>
#include "utility/utilityString.h"
#include "utility/utility.h"
namespace boost {
namespace program_options {
class variables_map;
class options_description;
}
}
namespace commandline
{
enum class ReturnStatus {
CMD_OK,
CMD_QUIT,
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);
std::vector<FilePath> extractPaths(const std::vector<std::string>& vector);
}
#endif // COMMANDLINE_HELPER_H
@@ -0,0 +1,36 @@
#include "utility/commandline/commands/CommandlineCommand.h"
#include <iostream>
namespace commandline
{
Command::Command(const std::string name, CommandLineParser* parser)
: m_name(name)
, m_parser(parser)
{
}
const std::string Command::name()
{
return m_name;
}
void Command::printHelp()
{
std::cout << "Usage:\n sourcetrail "
<< m_name << " [option...]\n\n";
std::cout << m_options << std::endl;
if (m_positional.max_total_count() > 0)
{
std::cout << "Positional Arguments: ";
for (unsigned int i = 0; i < m_positional.max_total_count(); i++)
{
std::cout << "\n " << i+1 << ": " << m_positional.name_for_position(i);
}
std::cout << std::endl;
}
}
} // namespace cmd
@@ -0,0 +1,72 @@
#ifndef COMMANDLINE_Command_H
#define COMMANDLINE_Command_H
#include <memory>
#include <iostream>
#include "boost/program_options.hpp"
//#include "utility/commandline/commands/CommandlineSourceGroupOptionsC.h"
//#include "utility/commandline/commands/CommandlineSourceGroupOptionsCxx.h"
//#include "utility/commandline/commands/CommandlineSourceGroupOptionsJava.h"
namespace po = boost::program_options;
namespace commandline {
enum class ReturnStatus;
class CommandLineParser;
class Command {
public:
Command(const std::string name, CommandLineParser* parser = nullptr);
const std::string name();
virtual void setup() = 0;
virtual ReturnStatus parse(std::vector<std::string>& args) = 0;
virtual void printHelp();
protected:
const std::string m_name;
po::options_description m_options;
po::positional_options_description m_positional;
CommandLineParser* m_parser;
};
}
//class CommandlineCommandAdd : public CommandlineCommand
//{
// std::vector<std::shared_ptr<CommandlineSourceGroupOptions>> m_sourceGroupTypes;
// CommandlineSourceGroupOptionsJava javaSourceGroup;
// virtual void setup()
// {
// // ADD different sourcegroups here
// m_sourceGroupTypes.push_back(std::make_shared<CommandlineSourceGroupOptionsJava>());
// for (std::shared_ptr<CommandlineSourceGroupOptions> group : m_sourceGroupTypes)
// {
// group->setup();
// }
// }
// virtual void parse(int argc, char** argv)
// {
// for (std::shared_ptr<CommandlineSourceGroupOptions> group : m_sourceGroupTypes)
// {
// // 0 .. sourcetrail
// // 1 .. add
// // 2 .. sourcegrouptype
// if (argv[2] == group->name())
// {
// group->parse(argc, argv);
// }
// }
// }
//};
#endif // !COMMANDLINE_COMMAND_H
@@ -0,0 +1,257 @@
#include "utility/commandline/commands/CommandlineCommandConfig.h"
#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;
namespace commandline {
// helper functions
typedef void(ApplicationSettings::*intFunc)(int);
void parseAndSetValue(
intFunc f,
const char* opt,
ApplicationSettings* settings,
po::variables_map& vm)
{
if (vm.count(opt))
{
(settings->*f)(vm[opt].as<int>());
}
}
typedef void(ApplicationSettings::*boolFunc)(bool);
void parseAndSetValue(
boolFunc f,
const char* opt,
ApplicationSettings* settings,
po::variables_map& vm)
{
if (vm.count(opt))
{
(settings->*f)(vm[opt].as<bool>());
}
}
typedef void(ApplicationSettings::*filePathFunc)(const FilePath&);
void parseAndSetValue(
filePathFunc f,
const char* opt,
ApplicationSettings* settings,
po::variables_map& vm)
{
if (vm.count(opt))
{
FilePath path(vm[opt].as<std::string>());
if (!path.exists())
{
std::cout << "\nWARNING: " << path.str()
<< " does not exist." << std::endl;
}
(settings->*f)(path);
}
}
typedef bool(ApplicationSettings::*vectorFunc)(const std::vector<FilePath>&);
void parseAndSetValue(
vectorFunc f,
const char* opt,
ApplicationSettings* settings,
po::variables_map& vm)
{
if (vm.count(opt))
{
std::vector<FilePath> v = extractPaths(vm[opt].as<std::vector<std::string>>());
(settings->*f)(v);
}
}
CommandConfig::CommandConfig(CommandLineParser* parser)
: Command("config", parser)
{
}
void CommandConfig::setup()
{
po::options_description options("Config Options");
options.add_options()
("help,h", "Print this help message")
("indexerthreads,t", po::value<int>(), "Set the number of threads used for indexing")
("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 the indexing process")
("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)")
("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")
("global-header-search-paths,g", po::value<std::vector<std::string>>(),
"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)")
("show,s", "displays all settings")
;
m_options.add(options);
}
void printVector(std::string title, std::vector<FilePath> vec)
{
std::cout << "\n " << title << ":";
if (vec.empty())
{
std::cout << "\n -\n";
}
for (const FilePath& item : vec)
{
std::cout << "\n " << item.str();
}
}
void CommandConfig::printSettings()
{
ApplicationSettings* settings = ApplicationSettings::getInstance().get();
settings->load(UserPaths::getAppSettingsPath());
if (settings == nullptr)
{
LOG_ERROR("Could not load application settings");
return;
}
std::cout << "Sourcetrail Settings:\n"
<< "\n indexerthread count: " << settings->getIndexerThreadCount()
<< "\n use-processes: " << settings->getMultiProcessIndexingEnabled()
<< "\n logging-enabled: " << settings->getLoggingEnabled()
<< "\n verbose-indexer-logging-enabled: " << settings->getVerboseIndexerLoggingEnabled()
<< "\n jvm-path: " << settings->getJavaPath()
<< "\n jvm-max-memory: " << settings->getJavaMaximumMemory()
<< "\n maven-path: " << settings->getMavenPath().str();
printVector("global-header-search-paths", std::move(settings->getHeaderSearchPaths()));
printVector("global-framework-search-paths", std::move(settings->getFrameworkSearchPaths()));
printVector("jre-system-library-paths", std::move(settings->getJreSystemLibraryPaths()));
License license;
license.loadFromEncodedString(settings->getLicenseString(), AppPath::getAppPath());
std::cout << "\nValid license: " << license.isValid() << std::endl;
}
ReturnStatus CommandConfig::parse(std::vector<std::string>& args)
{
po::variables_map vm;
try
{
po::store(po::command_line_parser(args).options(m_options).run(), vm);
po::notify(vm);
parseConfigFile(vm, m_options);
}
catch(po::error& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
std::cerr << m_options << std::endl;
return ReturnStatus::CMD_FAILURE;
}
// when "sourcetrail config" without any options is started,
// show help since configure nothing wont help
if (vm.count("help") || args.size() == 0 || args[0] == "help")
{
printHelp();
return ReturnStatus::CMD_QUIT;
}
if (args[0] == "show" || vm.count("show"))
{
printSettings();
return ReturnStatus::CMD_QUIT;
}
ApplicationSettings* settings = ApplicationSettings::getInstance().get();
settings->load(UserPaths::getAppSettingsPath());
parseAndSetValue(&ApplicationSettings::setMultiProcessIndexingEnabled, "use-processes", settings, vm);
parseAndSetValue(&ApplicationSettings::setLoggingEnabled, "logging-enabled", settings, vm);
parseAndSetValue(
&ApplicationSettings::setVerboseIndexerLoggingEnabled,
"verbose-indexer-logging-enabled",
settings,
vm
);
parseAndSetValue(&ApplicationSettings::setIndexerThreadCount, "indexerthreads", settings, vm);
parseAndSetValue(&ApplicationSettings::setJavaMaximumMemory, "jvm-max-memory", settings, vm);
parseAndSetValue(&ApplicationSettings::setMavenPath, "maven-path", settings, vm);
parseAndSetValue(&ApplicationSettings::setJavaPath, "jvm-path", settings, vm);
parseAndSetValue(&ApplicationSettings::setJreSystemLibraryPaths, "jre-system-library-paths", settings, vm);
parseAndSetValue(&ApplicationSettings::setHeaderSearchPaths, "global-header-search-paths", settings, vm);
parseAndSetValue(&ApplicationSettings::setFrameworkSearchPaths, "global-framework-search-paths", 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(UserPaths::getAppSettingsPath());
return ReturnStatus::CMD_QUIT;
}
} // namespace cmd
@@ -0,0 +1,31 @@
#ifndef COMMANDLINE_COMMAND_CONFIG_H
#define COMMANDLINE_COMMAND_CONFIG_H
#include <memory>
#include <iostream>
#include "utility/commandline/commands/CommandlineCommand.h"
//#include "utility/commandline/commands/CommandlineSourceGroupOptionsC.h"
//#include "utility/commandline/commands/CommandlineSourceGroupOptionsCxx.h"
//#include "utility/commandline/commands/CommandlineSourceGroupOptionsJava.h"
class CommandLineParser;
namespace commandline
{
enum class ReturnStatus;
class CommandConfig : public Command {
public:
CommandConfig(CommandLineParser* parser);
virtual void setup();
virtual ReturnStatus parse(std::vector<std::string>& args);
private:
void printSettings();
};
} // namespace cmd
#endif // !COMMANDLINE_COMMAND_H
@@ -0,0 +1,63 @@
#include "utility/commandline/commands/CommandlineCommandIndex.h"
#include "utility/commandline/CommandlineHelper.h"
#include "utility/commandline/CommandLineParser.h"
namespace commandline
{
CommandIndex::CommandIndex(CommandLineParser* parser)
: Command("index", parser)
{
}
void CommandIndex::setup()
{
po::options_description options("Config Options");
options.add_options()
("help,h", "Print this help message")
("full", "Paths for Sourcefiles")
("project-file", po::value<std::string>(), "Project file to index")
;
m_options.add(options);
m_positional.add("project-file", 1);
}
ReturnStatus CommandIndex::parse(std::vector<std::string>& args)
{
po::variables_map vm;
try
{
po::store(po::command_line_parser(args).options(m_options).positional(m_positional).run(), vm);
po::notify(vm);
parseConfigFile(vm, m_options);
}
catch(po::error& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
std::cerr << m_options << std::endl;
return ReturnStatus::CMD_FAILURE;
}
if (vm.count("help") || args.size() == 0 || args[0] == "help")
{
printHelp();
return ReturnStatus::CMD_QUIT;
}
if (vm.count("full"))
{
m_parser->force();
}
if (vm.count("project-file"))
{
m_parser->setProjectFile(FilePath(vm["project-file"].as<std::string>()));
}
return ReturnStatus::CMD_OK;
}
}
@@ -0,0 +1,28 @@
#ifndef COMMANDLINE_COMMAND_INDEX_H
#define COMMANDLINE_COMMAND_INDEX_H
#include <memory>
#include "boost/program_options.hpp"
#include "utility/commandline/commands/CommandlineCommand.h"
//#include "utility/commandline/commands/CommandlineSourceGroupOptionsC.h"
//#include "utility/commandline/commands/CommandlineSourceGroupOptionsCxx.h"
//#include "utility/commandline/commands/CommandlineSourceGroupOptionsJava.h"
namespace po = boost::program_options;
namespace commandline {
enum class ReturnStatus;
class CommandIndex : public Command {
public:
CommandIndex(CommandLineParser* parser);
virtual void setup();
virtual ReturnStatus parse(std::vector<std::string>& args);
};
} // namespace cmd
#endif // !COMMANDLINE_COMMAND_H
@@ -0,0 +1,6 @@
#include "commandlineSourceGroupOptions.h"
CommandlineSourceGroupOptions::CommandlineSourceGroupOptions()
{
}
@@ -0,0 +1,19 @@
#ifndef COMMANDLINE_SOURCEGROUP_OPTIONS_H
#define COMMANDLINE_SOURCEGROUP_OPTIONS_H
#include <string>
#include "boost/program_options.hpp"
class CommandlineSourceGroupOptions
{
public:
virtual const std::string name() const = 0;
virtual void setup() = 0;
virtual void parse(int argc, char** argv) = 0;
protected:
boost::program_options::options_description m_options;
};
#endif // COMMANDLINE_SOURCEGROUP_OPTIONS_H
@@ -0,0 +1,6 @@
#include "CommandlineSourceGroupOptionsC.h"
CommandlineSourceGroupOptionsC::CommandlineSourceGroupOptionsC()
{
}
@@ -0,0 +1,12 @@
#ifndef COMMANDLINE_SOURCEGROUP_OPTIONS_C_H
#define COMMANDLINE_SOURCEGROUP_OPTIONS_C_H
#include "utility/commandline/modes/CommandlineSourceGroupOptions.h"
class CommandlineSourceGroupOptionsC : public CommandlineSourceGroupOptions
{
public:
CommandlineSourceGroupOptionsC();
};
#endif // COMMANDLINE_SOURCEGROUP_OPTIONS_C_H
@@ -0,0 +1,6 @@
#include "CommandlineSourceGroupOptionsCxx.h"
CommandlineSourceGroupOptionsCxx::CommandlineSourceGroupOptionsCxx()
{
}
@@ -0,0 +1,12 @@
#ifndef COMMANDLINE_SOURCEGROUP_OPTIONS_CXX_H
#define COMMANDLINE_SOURCEGROUP_OPTIONS_CXX_H
#include "utility/commandline/modes/CommandlineSourceGroupOptions.h"
class CommandlineSourceGroupOptionsCxx : public CommandlineSourceGroupOptions
{
public:
CommandlineSourceGroupOptionsCxx();
};
#endif // COMMANDLINE_SOURCEGROUP_OPTIONS_CXX_H
@@ -0,0 +1,42 @@
#include "CommandlineSourceGroupOptionsJava.h"
#include <iostream>
namespace po = boost::program_options;
const std::string CommandlineSourceGroupOptionsJava::name() const
{
return "java";
}
void CommandlineSourceGroupOptionsJava::setup()
{
m_options.add_options()
("help,h", "Print this help message")
("mavenpath,m", po::value<std::string>(), "path to the maven executable")
("jvmpath,j", po::value<std::string>(), "path the jvm root")
("excludePaths,e", po::value<std::vector<std::string>>(), "files or directories that will be excludes indexing")
("source-extensions", po::value<std::string>(), "extension of Sourcefiles")
("java-standard", po::value<int>(), "Java Standard")
("classpath", po::value<std::vector<std::string>>(), "Java Class Paths")
;
}
void CommandlineSourceGroupOptionsJava::parse(int argc, char** argv)
{
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(m_options).run(), vm);
po::notify(vm);
if (vm.count("help"))
{
std::cout << m_options << std::endl;
}
if (vm.count("config-file"))
{
}
}
@@ -0,0 +1,17 @@
#ifndef COMMANDLINE_SOURCEGROUP_OPTIONS_JAVA_H
#define COMMANDLINE_SOURCEGROUP_OPTIONS_JAVA_H
#include "utility/commandline/modes/CommandlineSourceGroupOptions.h"
class CommandlineSourceGroupOptionsJava : public CommandlineSourceGroupOptions
{
virtual const std::string name() const;
virtual void setup() override;
virtual void parse(int argc, char** argv) override;
private:
};
#endif // COMMANDLINE_SOURCEGROUP_OPTIONS_JAVA_H