2010-11-26 65 views
1

我想實現一個eclipse插件來將shell腳本作爲外部工具生成器添加到項目中。按下插件菜單後,eclipse配置文件.project會添加如下。並且會生成另一個配置文件.externalToolBuilders/lstest [Builder] .launch。關於eclipse擴展工具生成器編程的問題

<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); 

回答

0

從菜單上按「運行/外部工具/外部工具配置...」那裏你可以定義螞蟻跑步,跑步者的程序。另一方面,我不確定你可以直接附加一個shell腳本,但是可以從ant中調用它。

+0

感謝您的反饋之前,添加以下行! – user2510797 2010-11-30 23:10:30

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