1 package $packageName$; 2 3 import org.eclipse.core.resources.ICommand; 4 import org.eclipse.core.resources.IProject; 5 import org.eclipse.core.resources.IProjectDescription; 6 import org.eclipse.core.resources.IProjectNature; 7 import org.eclipse.core.runtime.CoreException; 8 9 public class $natureClassName$ implements IProjectNature { 10 11 14 public static final String NATURE_ID = "$pluginId$.$natureId$"; 15 16 private IProject project; 17 18 23 public void configure() throws CoreException { 24 IProjectDescription desc = project.getDescription(); 25 ICommand[] commands = desc.getBuildSpec(); 26 27 for (int i = 0; i < commands.length; ++i) { 28 if (commands[i].getBuilderName().equals($builderClassName$.BUILDER_ID)) { 29 return; 30 } 31 } 32 33 ICommand[] newCommands = new ICommand[commands.length + 1]; 34 System.arraycopy(commands, 0, newCommands, 0, commands.length); 35 ICommand command = desc.newCommand(); 36 command.setBuilderName($builderClassName$.BUILDER_ID); 37 newCommands[newCommands.length - 1] = command; 38 desc.setBuildSpec(newCommands); 39 project.setDescription(desc, null); 40 } 41 42 47 public void deconfigure() throws CoreException { 48 IProjectDescription description = getProject().getDescription(); 49 ICommand[] commands = description.getBuildSpec(); 50 for (int i = 0; i < commands.length; ++i) { 51 if (commands[i].getBuilderName().equals($builderClassName$.BUILDER_ID)) { 52 ICommand[] newCommands = new ICommand[commands.length - 1]; 53 System.arraycopy(commands, 0, newCommands, 0, i); 54 System.arraycopy(commands, i + 1, newCommands, i, 55 commands.length - i - 1); 56 description.setBuildSpec(newCommands); 57 return; 58 } 59 } 60 } 61 62 67 public IProject getProject() { 68 return project; 69 } 70 71 76 public void setProject(IProject project) { 77 this.project = project; 78 } 79 80 } 81 | Popular Tags |