项目的Nature&Builder

SpringProjectNature

org.springframework.ide.eclipse.core.internal.project.SpringProjectNatureconfigure()中添加org.springframework.ide.eclipse.core.springbuilder,在deconfigure()中删除springbuilder

 

 添加Nature

/** * Adds given nature as first nature to specified project. */ public static void addProjectNature(IProject project, String nature, IProgressMonitor monitor) throws CoreException { if (project != null && nature != null) { if (!project.hasNature(nature)) { IProjectDescription desc = project.getDescription(); String[] oldNatures = desc.getNatureIds(); String[] newNatures = new String[oldNatures.length + 1]; newNatures[0] = nature; if (oldNatures.length > 0) { System.arraycopy(oldNatures, 0, newNatures, 1, oldNatures.length); } desc.setNatureIds(newNatures); project.setDescription(desc, monitor); } } }
 

 

 删除Nature

 

/** * Removes given nature from specified project. */ public static void removeProjectNature(IProject project, String nature, IProgressMonitor monitor) throws CoreException { if (project != null && nature != null) { if (project.exists() && project.hasNature(nature)) { // first remove all problem markers (including the // inherited ones) from Spring beans project if (nature.equals(SpringCore.NATURE_ID)) { project.deleteMarkers(SpringCore.MARKER_ID, true, IResource.DEPTH_INFINITE); } // now remove project nature IProjectDescription desc = project.getDescription(); String[] oldNatures = desc.getNatureIds(); String[] newNatures = new String[oldNatures.length - 1]; int newIndex = oldNatures.length - 2; for (int i = oldNatures.length - 1; i >= 0; i--) { if (!oldNatures[i].equals(nature)) { newNatures[newIndex--] = oldNatures[i]; } } desc.setNatureIds(newNatures); project.setDescription(desc, monitor); } } }
 

 

添加Builder

 

/** * Adds given builder to specified project. */ public static void addProjectBuilder(IProject project, String builderID, IProgressMonitor monitor) throws CoreException { IProjectDescription desc = project.getDescription(); ICommand oldBuilderCommand = getProjectBuilderCommand(desc, builderID); if (oldBuilderCommand == null) { // Add a new build spec ICommand command = desc.newCommand(); command.setBuilderName(builderID); // Commit the spec change into the project addProjectBuilderCommand(desc, command); project.setDescription(desc, monitor); } } 
 

删除Builder

/** * Removes given builder from specified project. */ public static void removeProjectBuilder(IProject project, String builderID, IProgressMonitor monitor) throws CoreException { if (project != null && builderID != null) { IProjectDescription desc = project.getDescription(); ICommand[] commands = desc.getBuildSpec(); for (int i = commands.length - 1; i >= 0; i--) { if (commands[i].getBuilderName().equals(builderID)) { ICommand[] newCommands = new ICommand[commands.length - 1]; System.arraycopy(commands, 0, newCommands, 0, i); System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1); // Commit the spec change into the project desc.setBuildSpec(newCommands); project.setDescription(desc, monitor); break; } } } }
 

 添加BuilderCommand

/** * Adds (or updates) a builder in given project description. */ public static void addProjectBuilderCommand(IProjectDescription description, ICommand command) throws CoreException { ICommand[] oldCommands = description.getBuildSpec(); ICommand oldBuilderCommand = getProjectBuilderCommand(description, command.getBuilderName()); ICommand[] newCommands; if (oldBuilderCommand == null) { // Add given builder to the end of the builder list newCommands = new ICommand[oldCommands.length + 1]; System.arraycopy(oldCommands, 0, newCommands, 0, oldCommands.length); newCommands[oldCommands.length] = command; } else { // Replace old builder with given new one for (int i = 0, max = oldCommands.length; i < max; i++) { if (oldCommands[i] == oldBuilderCommand) { oldCommands[i] = command; break; } } newCommands = oldCommands; } description.setBuildSpec(newCommands); }
 

删除BuilderCommand

/** * Returns specified builder from given project description. */ public static ICommand getProjectBuilderCommand(IProjectDescription description, String builderID) throws CoreException { ICommand[] commands = description.getBuildSpec(); for (int i = commands.length - 1; i >= 0; i--) { if (commands[i].getBuilderName().equals(builderID)) { return commands[i]; } } return null; }
 

 

 

 

 

 

 

 

 

StProjectNature

/** * 配置项目的性质,主要目的是为项目添加构建器 */ public void configure() throws CoreException { IProjectDescription desc = project.getDescription(); ICommand builderCommand = getBuilderCommand(desc, SoTowerProjectPlugin.BUILDER_ID); if (builderCommand == null) { ICommand command = desc.newCommand(); command.setBuilderName(StProjectPlugin.BUILDER_ID); setBuilderCommand(desc, command); project.setDescription(desc, new NullProgressMonitor()); } } /** * 向项目添加构建器 * * @param description 项目描述 * @param command 与构建器对应的构建命令 * @throws CoreException */ private void setBuilderCommand(IProjectDescription description, ICommand command) throws CoreException { ICommand[] oldCommands = description.getBuildSpec(); ICommand[] newCommands = new ICommand[oldCommands.length + 1]; System.arraycopy(oldCommands, 0, newCommands, 0, oldCommands.length); newCommands[oldCommands.length] = command; description.setBuildSpec(newCommands); } /** * 获得项目的某个特定构建器 * * @param description 项目描述 * @param builderID 构建器ID * @return * @throws CoreException */ private ICommand getBuilderCommand(IProjectDescription description, String builderID) throws CoreException { for (ICommand command : description.getBuildSpec()) { if (command.getBuilderName().equals(builderID)) { return command; } } return null; } /** * 把性质从项目中移除 */ public void deconfigure() throws CoreException {}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值