目前我正在研究Eclipse CDT的插件。
我想要实现的目标:
在命令行之前添加一个工具(我们称之为cov)。
gcc -omain.o main.c
应该成为 cov gcc -omain.o main.c
我尝试编写一个自定义的BuildRunner,它扩展了ExternalBuildrunner,在调用外部运行程序之前修改了这些工具。我是通过编辑COmmandLinePattern
来做到这一点的到目前为止,如果我不恢复旧的CommandLinePattern,它仍然有用。
是否有办法更新配置以使用修改后的工具,稍后在调用后再写回旧配置。
在修改之前,我备份了工具命令行模式,这样就不会出现问题了。我猜错了这里的更新步骤。
public class CovBuildRunner extends ExternalBuildRunner {
private final Set<String> VALUES;
public CovBuildRunner() {
VALUES = new HashSet<String>();
VALUES.add("gcc");
VALUES.add("g++");
}
@Override
public boolean invokeBuild(int kind, IProject project,
IConfiguration configuration, IBuilder builder, IConsole console,
IMarkerGenerator markerGenerator,
IncrementalProjectBuilder projectBuilder, IProgressMonitor monitor)
throws CoreException {
Map<ITool, String> cmdPatternBackup = new HashMap<>();
for (ITool tool : configuration.getTools()) {
if (cmdPatternBackup.containsKey(tool)) {
System.out.println("ERROR! TOOL ALREADY MODIFIED!");
} else if (this.supports(tool)) {
cmdPatternBackup.put(tool, tool.getCommandLinePattern());
tool.setCommandLinePattern("cov " + tool.getCommandLinePattern());
System.out.println(
configuration.getToolCommand(tool));
}
}
configuration.getToolChain().set;
boolean success = invokeExternalBuild(kind, project, configuration, builder, console, markerGenerator, projectBuilder, monitor);
for (ITool tool : cmdPatternBackup.keySet()) {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Setting back " + tool.getName() + "\n" + tool.getCommandLinePattern());
tool.setCommandLinePattern(cmdPatternBackup.get(tool));
}
return success;
}
private boolean supports(ITool tool) {
String command = tool.getToolCommand();
return VALUES.contains(command);
}
}