开发者

How to programmatically create Ant Builder in Eclipse?

开发者 https://www.devze.com 2023-03-25 12:14 出处:网络
I develop Eclipse plugin which should programmatic开发者_运维技巧ally create Ant Builder for specified project.

I develop Eclipse plugin which should programmatic开发者_运维技巧ally create Ant Builder for specified project.

The same way as using UI: Properties->Builders->New->Ant Builder.

I tried to find solution several weeks but without success. Could anybody help me?


Following might not be the cleanest way of doing what you are asking, but works. This adds a builder called "MyBuilderName" to the project's builders. You then need to create a file called "MyBuilderName.launch" under the folder .externalToolBuilders under the project folder.

Make an Ant builder and check the file in .externalToolBuilders folder to see what it should look like.

...
IProjectDescription desc = project.getDescription();
ICommand[] commands = desc.getBuildSpec();
ICommand[] newcommands = new ICommand[commands.length + 1];
System.arraycopy(commands, 0, newcommands, 1, commands.length);

ICommand command = desc.newCommand();
command.setBuilderName(
    "org.eclipse.ui.externaltools.ExternalToolBuilder");            
command.setArguments(
    Collections.singletonMap("LaunchConfigHandle", 
    "<project>/.externalToolBuilders/MyBuilderName"));
newcommands[0] = command;
desc.setBuildSpec(newcommands);
project.setDescription(desc, monitor);
...
0

精彩评论

暂无评论...
验证码 换一张
取 消