14
14
*******************************************************************************/
15
15
package io .sloeber .autoBuild .integration ;
16
16
17
-
18
17
import static io .sloeber .autoBuild .helpers .api .AutoBuildConstants .*;
19
18
import java .io .File ;
20
19
import java .io .IOException ;
@@ -43,8 +42,6 @@ public class AutoBuildConfigurationDescriptionProvider extends CConfigurationDat
43
42
private static final String AUTO_BUILD_PROJECT_FILE = ".autoBuildProject" ; //$NON-NLS-1$
44
43
private static final String AUTO_BUILD_TEAM_FILE = "autoBuildProject.cfg" ; //$NON-NLS-1$
45
44
46
-
47
-
48
45
// public class KeyValuePairs{
49
46
// private String myLinePrefix;
50
47
// private String myLineEnd;
@@ -115,8 +112,6 @@ public class AutoBuildConfigurationDescriptionProvider extends CConfigurationDat
115
112
//
116
113
// }
117
114
118
-
119
-
120
115
public AutoBuildConfigurationDescriptionProvider () {
121
116
}
122
117
@@ -128,65 +123,59 @@ public CConfigurationData applyConfiguration(ICConfigurationDescription cfgDescr
128
123
ICProjectDescription projDesc = cfgDescription .getProjectDescription ();
129
124
IProject iProject = projDesc .getProject ();
130
125
131
-
132
-
133
- KeyValueTree keyValuePairs =KeyValueTree .createRoot ();
134
- //Map<ICConfigurationDescription,KeyValuePairs> keyValues=new TreeMap<>();
126
+ // Get the tree value pairs
127
+ KeyValueTree keyValuePairs = KeyValueTree .createRoot ();
135
128
for (ICConfigurationDescription curConfDesc : projDesc .getConfigurations ()) {
136
129
AutoBuildConfigurationDescription autoBuildConfigBase = (AutoBuildConfigurationDescription ) curConfDesc
137
130
.getConfigurationData ();
138
131
139
- KeyValueTree cfgkeyValuePairs = keyValuePairs .addChild (curConfDesc .getName ());
132
+ KeyValueTree cfgkeyValuePairs = keyValuePairs .addChild (curConfDesc .getName ());
140
133
141
134
autoBuildConfigBase .serialize (cfgkeyValuePairs );
142
- // configText.append(keyValuePairs.getBuffer());
143
- // if (autoBuildConfigBase.isTeamShared()) {
144
- // teamText.append(keyValuePairs.getBuffer(excludedKeys));
145
- // }
146
135
}
147
136
148
- //StringBuffer
149
-
150
- File projectFile = getStorageFile (iProject ).getLocation ().toFile ();
151
- IFile teamFile = getTeamFile (iProject ); // TODO add config saving
137
+ // Save the autobuild project file and the team file (if needed)
152
138
try {
139
+ File projectFile = getStorageFile (iProject ).getLocation ().toFile ();
140
+ IFile teamFile = getTeamFile (iProject );
141
+
142
+ // save the project file if needed
153
143
boolean needsWriting = true ;
154
- String configText = keyValuePairs .dump ();
144
+ String configText = keyValuePairs .dump ();
155
145
if (projectFile .exists ()) {
156
146
String curConfigsText = FileUtils .readFileToString (projectFile , AUTOBUILD_CONFIG_FILE_CHARSET );
157
147
needsWriting = !curConfigsText .equals (configText );
158
148
}
159
149
if (needsWriting ) {
160
150
FileUtils .write (projectFile , configText , Charset .defaultCharset ());
161
151
}
152
+
153
+ // Remove the keys that the user does not want in the team file
162
154
for (ICConfigurationDescription curConfDesc : projDesc .getConfigurations ()) {
163
155
AutoBuildConfigurationDescription autoBuildConfigBase = (AutoBuildConfigurationDescription ) curConfDesc
164
156
.getConfigurationData ();
165
157
166
- if (!autoBuildConfigBase .isTeamShared ()) {
167
- keyValuePairs .removeChild (curConfDesc .getName ());
168
- }
169
- else {
170
- Set <String > excludedKeys =autoBuildConfigBase .getTeamExclusionKeys ();
171
- for (String curKey :excludedKeys ) {
172
- keyValuePairs .removeKey (curKey );
173
- }
158
+ Set <String > excludedKeys = autoBuildConfigBase .getTeamExclusionKeys ();
159
+ for (String curKey : excludedKeys ) {
160
+ keyValuePairs .removeKey (curKey );
174
161
}
175
162
}
163
+
164
+ // save the team file if needed
176
165
needsWriting = true ;
177
- String teamText = keyValuePairs .dump ();
178
- if (teamText .length ()< 2 ) {
179
- teamFile .delete (true ,monitor );
180
- needsWriting = false ;
166
+ String teamText = keyValuePairs .dump ();
167
+ if (teamText .length () < 2 ) {
168
+ teamFile .delete (true , monitor );
169
+ needsWriting = false ;
181
170
}
182
- File teamFile2 = teamFile .getLocation ().toFile ();
171
+ File teamFile2 = teamFile .getLocation ().toFile ();
183
172
if (teamFile .exists ()) {
184
173
String curTeamText = FileUtils .readFileToString (teamFile2 , Charset .defaultCharset ());
185
174
needsWriting = !curTeamText .equals (teamText .toString ());
186
175
187
176
}
188
177
if (needsWriting ) {
189
- FileUtils .write (teamFile2 , teamText , Charset .defaultCharset ());
178
+ FileUtils .write (teamFile2 , teamText , Charset .defaultCharset ());
190
179
}
191
180
} catch (IOException e ) {
192
181
e .printStackTrace ();
@@ -214,12 +203,13 @@ public CConfigurationData loadConfiguration(ICConfigurationDescription cfgDescri
214
203
IFile teamFile = getTeamFile (iProject );
215
204
try {
216
205
if (projectFile .exists ()) {
217
- KeyValueTree keyValues =KeyValueTree .createRoot ();
206
+ KeyValueTree keyValues = KeyValueTree .createRoot ();
218
207
keyValues .mergeFile (projectFile );
219
208
if (teamFile .exists ()) {
220
209
keyValues .mergeFile (teamFile .getLocation ().toFile ());
221
210
}
222
- return new AutoBuildConfigurationDescription (cfgDescription , keyValues .getChild ( cfgDescription .getName ()));
211
+ return new AutoBuildConfigurationDescription (cfgDescription ,
212
+ keyValues .getChild (cfgDescription .getName ()));
223
213
}
224
214
// This Should not happen
225
215
throw new CoreException (null );
@@ -265,12 +255,11 @@ public void dataCached(ICConfigurationDescription cfgDescription, CConfiguration
265
255
return ;
266
256
}
267
257
268
-
269
258
public static IFile getStorageFile (IProject iProject ) {
270
259
return iProject .getFile (AUTO_BUILD_PROJECT_FILE );
271
260
}
272
261
273
- public static IFile getTeamFile (IProject iProject ) {
262
+ public static IFile getTeamFile (IProject iProject ) {
274
263
return iProject .getFile (AUTO_BUILD_TEAM_FILE );
275
264
}
276
265
}
0 commit comments