ArKanjo 0.2
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
tool_method.cpp
Go to the documentation of this file.
5
6#include <iostream>
7
8using fm = FormatterManager;
9
10ToolMethod::ToolMethod(const fs::path& base_path_, double similarity_) {
11 base_path = base_path_;
12 similarity = similarity_;
13}
14
15void ToolMethod::execute_by_feature(const fs::path& folder_path, const std::string feature_name) {
16 fs::path output_parsed = base_path / "output_parsed.txt";
17 if (!feature_name.empty())
18 fs::path output_parsed = base_path / ("output_parsed" + feature_name + ".txt");
19
20 fs::path cwd = fs::current_path();
21 fs::current_path(folder_path);
22
23 std::string command_tool = "python3 -W ignore ";
24 command_tool += Config::config().third_party_dir;
25 command_tool += "/duplicate-code-detection-tool/duplicate_code_detection.py";
26 command_tool += " --project-root-dir ";
27 command_tool += folder_path;
28 command_tool += " -d ";
29 command_tool += folder_path;
30
31 fm::write(SAVING_MESSAGE);
32
33 FILE* pipe = popen(command_tool.c_str(), "r");
34 if (!pipe) {
35 std::cerr << "Error executing the tool.\n";
36 return;
37 }
38
39 Parser parser(output_parsed, similarity);
40 parser.exec_from_stream(pipe);
41
42 fs::current_path(cwd);
43 pclose(pipe);
44}
45
47 fs::path base = base_path / source_feature_path;
48
49 auto source = fd.get_feature<SourceFeature>();
50 if (!source)
51 return;
52
53 fs::path relative(fd.path);
54 std::string filename = fd.function_name + relative.extension().string();
55 fs::path path = base / relative / filename;
56 Utils::write_file(path, source->code + "\n");
57}
58
60 fs::path base = base_path / source_feature_path;
61
63}
static Config & config()
Gets the singleton configuration instance.
Definition config.cpp:36
fs::path third_party_dir
Directory containing third-party dependencies.
Definition config.hpp:43
static void write(const std::string &template_str, const std::vector< T > &data, enum Format effective=Format::AUTO, RowColorFn color_fn=nullptr, std::ostream &out=std::cout)
std::string function_name
Name of the function.
std::string path
std::shared_ptr< T > get_feature() const
Parses and transforms duplication detection tool output.
Definition parser.hpp:68
void exec_from_stream(FILE *pipe)
Main parsing execution method using stream.
Definition parser.cpp:88
ToolMethod(const fs::path &base_path_, double similarity_)
Constructs the duplication finder tool.
void execute_by_feature(const fs::path &path, const std::string feature_name="")
Executes the full duplication analysis pipeline.
void on_function(const FunctionData &fd) override
void execute() override
Configuration management interface.
void write_file(const fs::path &path, const std::string &content)
Writes content to a file at specified path.
Definition utils.cpp:19
fs::path source_feature_path
Main duplication detection tool interface.