关于eclipse的问题扩展了工具构建器编程

时间:2010-11-26 04:34:13

标签: java eclipse-plugin

我想实现一个eclipse插件,将shell脚本作为外部工具生成器添加到项目中。按下插件菜单后,eclipse配置文件.project将添加如下。将生成另一个配置文件.externalToolBuilders / lstest [Builder] .launch。

<buildCommand>
        <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
        <triggers>full,incremental,</triggers>
        <arguments>
            <dictionary>
                <key>LaunchConfigHandle</key>
                <value>&lt;project&gt;/.externalToolBuilders/lstest [Builder].launch</value>
            </dictionary>
        </arguments>
    </buildCommand>

目前,我可以使用以下代码添加到.project。但是我怎么能生成.externalToolBuilders / lstest [Builder] .launch?非常感谢你。

org.eclipse.core.resources.ICommand command = pDesc.newCommand();
     command.setBuilderName("org.eclipse.ui.externaltools.ExternalToolBuilder");
Map args = command.getArguments();
args.put("LaunchConfigHandle", "<project>;/.externalToolBuilders/lstest [Builder].launch");
args = conf.getAttributes();
command.setArguments(args);
org.eclipse.core.resources.ICommand command = BuilderUtils.commandFromLaunchConfig(projects[i],conf);
org.eclipse.core.resources.ICommand[] commands = pDesc.getBuildSpec();
 org.eclipse.core.resources.ICommand[] nc = new ICommand[commands.length + 1];
System.arraycopy(commands, 0, nc, 1, commands.length);
nc[0] = command;
pDesc.setBuildSpec(nc);
projects[i].setDescription(pDesc, null);

2 个答案:

答案 0 :(得分:0)

从菜单中按“运行/外部工具/外部工具配置...”,您可以在其中定义蚂蚁跑步者,程序跑步者。另一方面,我不确定你是否可以直接附加shell脚本,而是从ant调用它。

答案 1 :(得分:0)

在.externalToolBuilders文件夹中生成lstest.launch。在代码

之前添加以下行
    ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType antType =
launchManager.getLaunchConfigurationType(IExternalToolConstants.ID_PROGRAM_BUILDER_LAUNCH_CONFIGURATION_TYPE);

ILaunchConfigurationWorkingCopy workingCopy = antType.newInstance(BuilderUtils.getBuilderFolder(project, true), "lstest" ); 
workingCopy.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, false);
workingCopy.setAttribute(IExternalToolConstants.ATTR_LOCATION, "${project_loc}\\YOUR_SHELL_SCRIPT");
workingCopy.setAttribute(....);


ILaunchConfiguration ilc = workingCopy.doSave();

create ANT builder programmatically