1 11 package org.eclipse.pde.internal; 12 13 import org.eclipse.core.resources.*; 14 import org.eclipse.core.runtime.*; 15 17 public abstract class BaseProject extends PlatformObject implements IProjectNature { 18 private IProject project; 19 20 public BaseProject() { 21 super(); 22 } 23 24 protected void addToBuildSpec(String builderID) throws CoreException { 25 26 IProjectDescription description = getProject().getDescription(); 27 ICommand builderCommand = getBuilderCommand(description, builderID); 28 29 if (builderCommand == null) { 30 ICommand command = description.newCommand(); 32 command.setBuilderName(builderID); 33 setBuilderCommand(description, command); 34 } 35 } 36 37 private ICommand getBuilderCommand( 38 IProjectDescription description, 39 String builderId) 40 throws CoreException { 41 ICommand[] commands = description.getBuildSpec(); 42 for (int i = 0; i < commands.length; ++i) { 43 if (commands[i].getBuilderName().equals(builderId)) { 44 return commands[i]; 45 } 46 } 47 return null; 48 } 49 50 public IProject getProject() { 51 return project; 52 } 53 54 protected IWorkspace getWorkspace() { 55 return PDE.getWorkspace(); 56 } 57 58 protected void removeFromBuildSpec(String builderID) throws CoreException { 59 IProjectDescription description = getProject().getDescription(); 60 ICommand[] commands = description.getBuildSpec(); 61 for (int i = 0; i < commands.length; ++i) { 62 if (commands[i].getBuilderName().equals(builderID)) { 63 ICommand[] newCommands = new ICommand[commands.length - 1]; 64 System.arraycopy(commands, 0, newCommands, 0, i); 65 System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1); 66 description.setBuildSpec(newCommands); 67 return; 68 } 69 } 70 } 71 72 private void setBuilderCommand( 73 IProjectDescription description, 74 ICommand newCommand) 75 throws CoreException { 76 77 ICommand[] oldCommands = description.getBuildSpec(); 78 ICommand oldBuilderCommand = 79 getBuilderCommand(description, newCommand.getBuilderName()); 80 81 ICommand[] newCommands; 82 83 if (oldBuilderCommand == null) { 84 newCommands = new ICommand[oldCommands.length + 1]; 86 System.arraycopy(oldCommands, 0, newCommands, 0, oldCommands.length); 87 newCommands[oldCommands.length] = newCommand; 88 } else { 89 for (int i = 0, max = oldCommands.length; i < max; i++) { 90 if (oldCommands[i] == oldBuilderCommand) { 91 oldCommands[i] = newCommand; 92 break; 93 } 94 } 95 newCommands = oldCommands; 96 } 97 98 description.setBuildSpec(newCommands); 100 getProject().setDescription(description, null); 101 } 102 103 public void setProject(IProject project) { 104 this.project = project; 105 } 106 } 107 | Popular Tags |