The final restructured version for automatic build using maven tycho
[Mograsim.git] / plugins / net.mograsim.plugin.core / src / net / mograsim / plugin / nature / MograsimNature.java
1 package net.mograsim.plugin.nature;
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 MograsimNature implements IProjectNature
10 {
11
12         /**
13          * ID of this project nature
14          */
15         public static final String NATURE_ID = "net.mograsim";
16
17         private IProject project;
18
19         @Override
20         public void configure() throws CoreException
21         {
22                 IProjectDescription desc = project.getDescription();
23                 ICommand[] commands = desc.getBuildSpec();
24
25                 for (int i = 0; i < commands.length; ++i)
26                 {
27                         if (commands[i].getBuilderName().equals(MograsimBuilder.BUILDER_ID))
28                         {
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(MograsimBuilder.BUILDER_ID);
37                 newCommands[newCommands.length - 1] = command;
38                 desc.setBuildSpec(newCommands);
39                 project.setDescription(desc, null);
40         }
41
42         @Override
43         public void deconfigure() throws CoreException
44         {
45                 IProjectDescription description = getProject().getDescription();
46                 ICommand[] commands = description.getBuildSpec();
47                 for (int i = 0; i < commands.length; ++i)
48                 {
49                         if (commands[i].getBuilderName().equals(MograsimBuilder.BUILDER_ID))
50                         {
51                                 ICommand[] newCommands = new ICommand[commands.length - 1];
52                                 System.arraycopy(commands, 0, newCommands, 0, i);
53                                 System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
54                                 description.setBuildSpec(newCommands);
55                                 project.setDescription(description, null);
56                                 return;
57                         }
58                 }
59         }
60
61         @Override
62         public IProject getProject()
63         {
64                 return project;
65         }
66
67         @Override
68         public void setProject(IProject project)
69         {
70                 this.project = project;
71         }
72
73 }