54 IProjectDescription description = project.getDescription(); |
54 IProjectDescription description = project.getDescription(); |
55 |
55 |
56 // create array for the new natures |
56 // create array for the new natures |
57 String[] newNatures = new String[natures.length + 2]; |
57 String[] newNatures = new String[natures.length + 2]; |
58 |
58 |
59 |
59 // if QT nature found we must adjust pre- and post natures to |
60 //if QT nature found we must adjust pre- and post natures to correct place |
60 // correct place |
61 if( description.hasNature(com.trolltech.qtcppproject.QtNature.QT_NATURE_ID) ) { |
61 if (description |
62 |
62 .hasNature(com.trolltech.qtcppproject.QtNature.QT_NATURE_ID)) { |
63 //find QT nature location |
63 |
|
64 // find QT nature location |
64 int qtNatureIndex = 0; |
65 int qtNatureIndex = 0; |
65 for( int i=0; i<natures.length; i++ ) { |
66 for (int i = 0; i < natures.length; i++) { |
66 if( natures[i].equals(com.trolltech.qtcppproject.QtNature.QT_NATURE_ID ) ) { |
67 if (natures[i] |
|
68 .equals(com.trolltech.qtcppproject.QtNature.QT_NATURE_ID)) { |
67 qtNatureIndex = i; |
69 qtNatureIndex = i; |
68 break; |
70 break; |
69 } |
71 } |
70 } |
72 } |
71 |
73 |
72 //QT nature id found and it is first nature=> now start to copy existing id and add AT id |
74 // QT nature id found and it is first nature=> now start to copy |
73 if( qtNatureIndex == 0 ) { |
75 // existing id and add AT id |
74 //add natures |
76 if (qtNatureIndex == 0) { |
|
77 // add natures |
75 newNatures[0] = natures[0]; |
78 newNatures[0] = natures[0]; |
76 newNatures[1] = PreNature.NATURE_ID; |
79 newNatures[1] = PreNature.NATURE_ID; |
77 |
80 |
78 //copy rest of the existing natures |
81 // copy rest of the existing natures |
79 System.arraycopy(natures, 1, newNatures, 2, natures.length-1); |
82 System.arraycopy(natures, 1, newNatures, 2, |
|
83 natures.length - 1); |
80 |
84 |
81 // add post-builder nature |
85 // add post-builder nature |
82 newNatures[natures.length + 1] = PostNature.NATURE_ID; |
86 newNatures[natures.length + 1] = PostNature.NATURE_ID; |
83 } |
87 } |
84 //QT nature id found but there are some other natures |
88 // QT nature id found but there are some other natures |
85 //before QT nature |
89 // before QT nature |
86 else { |
90 else { |
87 //copy existing natures |
91 // copy existing natures |
88 System.arraycopy(natures, 0, newNatures, 0, qtNatureIndex+1); |
92 System.arraycopy(natures, 0, newNatures, 0, |
89 newNatures[qtNatureIndex+1] = PreNature.NATURE_ID; |
93 qtNatureIndex + 1); |
90 |
94 newNatures[qtNatureIndex + 1] = PreNature.NATURE_ID; |
91 //copy rest of the existing natures |
95 |
92 System.arraycopy(natures, qtNatureIndex+1, newNatures, qtNatureIndex+2, natures.length-qtNatureIndex); |
96 // copy rest of the existing natures |
|
97 System.arraycopy(natures, qtNatureIndex + 1, newNatures, |
|
98 qtNatureIndex + 2, natures.length - qtNatureIndex); |
93 |
99 |
94 // add post-builder nature |
100 // add post-builder nature |
95 newNatures[natures.length + 1] = PostNature.NATURE_ID; |
101 newNatures[natures.length + 1] = PostNature.NATURE_ID; |
96 } |
102 } |
97 } |
103 } |
98 //no QT nature found just add pre nature first and post nature last |
104 // no QT nature found just add pre nature first and post nature last |
99 else { |
105 else { |
100 |
106 |
101 // set pre-builder nature |
107 // set pre-builder nature |
102 newNatures[0] = PreNature.NATURE_ID; |
108 newNatures[0] = PreNature.NATURE_ID; |
103 |
109 |
139 boolean foundPreNature = description |
143 boolean foundPreNature = description |
140 .hasNature(PreNature.NATURE_ID); |
144 .hasNature(PreNature.NATURE_ID); |
141 boolean foundPostNature = description |
145 boolean foundPostNature = description |
142 .hasNature(PostNature.NATURE_ID); |
146 .hasNature(PostNature.NATURE_ID); |
143 |
147 |
144 //either pre- or post builder nature found => remove it |
148 // either pre- or post builder nature found => remove it |
145 if (foundPreNature || foundPostNature) { |
149 if (foundPreNature || foundPostNature) { |
146 removeNature(project, 1); |
150 removeNature(project, 1); |
147 } |
151 } |
148 |
152 } |
149 } |
153 } catch (CoreException ce) { |
150 } catch (CoreException ce) { |
154 ce.printStackTrace(); |
151 ce.printStackTrace(); |
155 } |
152 } |
|
153 |
|
154 } |
156 } |
155 |
157 |
156 /** |
158 /** |
157 * Add AnalyzeTool custom builder nature to project builder natures. |
159 * Add AnalyzeTool custom builder nature to project builder natures. |
158 * |
160 * |
159 * @param project |
161 * @param project |
160 * Project reference |
162 * Project reference |
161 * @return True if natures are added otherwise False |
163 * @return True if natures are added otherwise False |
162 */ |
164 */ |
163 public final boolean enableNatures(final IProject project) { |
165 public final boolean enableNatures(final IProject project) { |
164 try { |
166 try { |
165 // check is nature enable |
167 // check is nature enable |
166 if( isNatureEnabled(project)) { |
168 if (isNatureEnabled(project)) { |
167 return true; |
169 return true; |
168 } |
170 } |
169 // get project description |
171 // get project description |
170 IProjectDescription description = project.getDescription(); |
172 IProjectDescription description = project.getDescription(); |
171 |
173 |
172 // find natures |
174 // find natures |
173 boolean foundPreNature = description |
175 boolean foundPreNature = description.hasNature(PreNature.NATURE_ID); |
174 .hasNature(PreNature.NATURE_ID); |
|
175 boolean foundPostNature = description |
176 boolean foundPostNature = description |
176 .hasNature(PostNature.NATURE_ID); |
177 .hasNature(PostNature.NATURE_ID); |
177 |
178 |
178 // only one analyzetool nature found => remove it |
179 // only one analyzetool nature found => remove it |
179 if (foundPostNature || foundPreNature) { |
180 if (foundPostNature || foundPreNature) { |