1616import org .eclipse .cdt .core .settings .model .ICProjectDescription ;
1717import org .eclipse .cdt .core .settings .model .ICSettingEntry ;
1818import org .eclipse .cdt .core .settings .model .ICSourceEntry ;
19- import org .eclipse .cdt .core .settings .model .util .CDataUtil ;
2019import org .eclipse .core .resources .IFile ;
2120import org .eclipse .core .resources .IFolder ;
2221import org .eclipse .core .resources .IProject ;
4342import io .sloeber .autoBuild .helpers .api .KeyValueTree ;
4443import io .sloeber .autoBuild .integration .AutoBuildConfigurationDescription ;
4544import io .sloeber .autoBuild .integration .AutoBuildManager ;
45+ import io .sloeber .autoBuild .schema .api .IConfiguration ;
4646import io .sloeber .autoBuild .schema .api .IProjectType ;
4747import io .sloeber .core .Activator ;
4848import io .sloeber .core .internal .SloeberConfiguration ;
49+ import io .sloeber .core .listeners .IndexerController ;
4950import io .sloeber .core .natures .SloeberNature ;
5051import io .sloeber .core .txt .TxtFile ;
5152
@@ -84,10 +85,6 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
8485 OldCoreFolder .delete (true , monitor );
8586 }
8687
87- // IFile CdtDotFile = project.getFile(".cproject"); //$NON-NLS-1$
88- // if(CdtDotFile.exists()) {
89- // CdtDotFile.delete(true, monitor);
90- // }
9188
9289 File sloeberDotFile = project .getFile (".sproject" ).getLocation ().toFile (); //$NON-NLS-1$
9390 File sloeberCfgFile = project .getFile (SLOEBER_CFG ).getLocation ().toFile ();
@@ -104,6 +101,22 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
104101 }
105102 }
106103
104+ CCorePlugin cCorePlugin = CCorePlugin .getDefault ();
105+ ICProjectDescription oldPrjCDesc = cCorePlugin .getProjectDescription (project , false );
106+ Set <String >cfgNames =new HashSet <>();
107+ for (ICConfigurationDescription curConfig : oldPrjCDesc .getConfigurations ()) {
108+ cfgNames .add ( curConfig .getName ());
109+ }
110+
111+
112+ KeyValueTree oldConfigs =null ;
113+ if (oldSloeberInfo != null ) {
114+ oldConfigs = oldSloeberInfo .getData ().getChild ("Config" ); //$NON-NLS-1$
115+ for (String curTree : oldConfigs .getChildren ().keySet ()) {
116+ cfgNames .add (curTree );
117+ }
118+ }
119+
107120 String builderName = AutoBuildProject .INTERNAL_BUILDER_ID ;
108121 IBuildTools buildTools = IBuildToolsManager .getDefault ().getBuildTools (SLOEBER_BUILD_TOOL_PROVIDER_ID ,
109122 null );
@@ -114,46 +127,33 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
114127 CCProjectNature .CC_NATURE_ID , codeProvider , buildTools , true , internalMonitor );
115128
116129 SloeberNature .addNature (project , internalMonitor );
117-
118- CCorePlugin cCorePlugin = CCorePlugin .getDefault ();
119130 ICProjectDescription prjCDesc = cCorePlugin .getProjectDescription (project , true );
120131
121- Set <String >cfgNames =new HashSet <>();
122- for (ICConfigurationDescription curConfig : prjCDesc .getConfigurations ()) {
123- cfgNames .add ( curConfig .getName ());
124- }
125- KeyValueTree oldConfigs =null ;
126- if (oldSloeberInfo != null ) {
127- oldConfigs = oldSloeberInfo .getData ().getChild ("Config" ); //$NON-NLS-1$
128- for (String curTree : oldConfigs .getChildren ().keySet ()) {
129- cfgNames .add (curTree );
130- }
131- }
132+
133+ IConfiguration defaultConfig = projectType .getConfigurations ()[0 ];
132134 for (String cfgName :cfgNames ) {
133135 KeyValueTree oldConfig =null ;
134136 if (oldConfigs != null ) {
135137 oldConfig = oldConfigs .getChild (cfgName );
136138 }
137- //get the CDT config and AutoBuildConfigurationDescription (if it does not exist create it)
138- ICConfigurationDescription curConfig = prjCDesc .getConfigurationByName (cfgName );
139- if (curConfig ==null ) {
140- //config does not exists so create it
141- String id = CDataUtil .genId (Activator .getId ());
142- curConfig = prjCDesc .createConfiguration (id ,cfgName ,prjCDesc .getActiveConfiguration ());
139+
140+ IConfiguration config = projectType .getConfiguration (cfgName );
141+ if (config == null ) {
142+ config = defaultConfig ;
143143 }
144- IAutoBuildConfigurationDescription autoConf = IAutoBuildConfigurationDescription
145- .getConfig (curConfig );
146- if (!(autoConf instanceof AutoBuildConfigurationDescription )) {
147- // this should not happen as we just created a autoBuild project
148- Activator .log (new Status (SLOEBER_STATUS_DEBUG , Activator .getId (),
149- "\" Auto build created a project that does not seem to be a autobuild project :-s : " //$NON-NLS-1$
150- + project .getName ()));
151- continue ;
144+ ICConfigurationDescription curConfig = prjCDesc .getConfigurationByName (cfgName );
145+ AutoBuildConfigurationDescription autoConf =null ;
146+ if (curConfig == null ) {
147+ // config does not exists so create it
148+ autoConf = new AutoBuildConfigurationDescription (config ,
149+ project , buildTools , null );
150+ autoConf .setName (cfgName );
151+ curConfig = prjCDesc .createConfiguration (AutoBuildProject .INTERNAL_BUILDER_ID , autoConf );
152+ autoConf .setCdtConfigurationDescription (curConfig );
153+ }else {
154+ autoConf = (AutoBuildConfigurationDescription ) IAutoBuildConfigurationDescription .getConfig (curConfig );
152155 }
153156
154-
155-
156-
157157 ICSourceEntry newSourceEntries [] = new ICSourceEntry [2 ];
158158 // old Sloeber project so the code is in the root of the project for sure
159159 // as we are at the root
@@ -201,24 +201,27 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
201201 SubMonitor refreshMonitor = SubMonitor .convert (internalMonitor , 3 );
202202 project .open (refreshMonitor );
203203 project .refreshLocal (IResource .DEPTH_INFINITE , refreshMonitor );
204+ prjCDesc .setActiveConfiguration (prjCDesc .getConfigurations ()[0 ]);
204205 prjCDesc .setCdtProjectCreated ();
206+
205207 cCorePlugin .setProjectDescription (project , prjCDesc , true , SubMonitor .convert (internalMonitor , 1 ));
206- project .close (monitor );
207- project .open (monitor );
208+ // project.close(monitor);
209+ // project.open(monitor);
208210
209211 Activator .log (new Status (SLOEBER_STATUS_DEBUG , Activator .getId (),
210212 "internal creation of project is done: " + project .getName ())); //$NON-NLS-1$
211- // IndexerController.index(newProjectHandle);
212213 }
213214 };
214215 try
215216
216217 {
218+ IndexerController .doNotIndex (project );
217219 workspace .run (runnable , root , IWorkspace .AVOID_UPDATE , monitor );
218220 } catch (Exception e ) {
219- Activator .log (new Status (IStatus .INFO , io .sloeber .core .Activator .getId (),
221+ Activator .log (new Status (IStatus .ERROR , io .sloeber .core .Activator .getId (),
220222 "Project creation failed: " + project .getName (), e )); //$NON-NLS-1$
221223 }
224+ IndexerController .index (project );
222225 monitor .done ();
223226 }
224227
@@ -233,10 +236,14 @@ private static OtherDescription getOtherDescription(KeyValueTree config) {
233236
234237 private static CompileDescription getCompileDescription (KeyValueTree oldConfig ) {
235238 CompileDescription ret = new CompileDescription ();
239+ if (oldConfig == null ) {
240+ return ret ;
241+ }
236242 KeyValueTree compileConfig =oldConfig .getChild ("compile" ).getChild ("sloeber" ); //$NON-NLS-1$ //$NON-NLS-2$
237243 if (compileConfig == null ) {
238244 return ret ;
239245 }
246+
240247 KeyValueTree extraConfig =compileConfig .getChild ("extra" ); //$NON-NLS-1$
241248 ret .set_All_CompileOptions (extraConfig .getValue ("all" )); //$NON-NLS-1$
242249 ret .set_Archive_CompileOptions (extraConfig .getValue ("archive" )); //$NON-NLS-1$
@@ -281,10 +288,11 @@ private static BoardDescription getBoardDescription(KeyValueTree oldConfig) {
281288 }
282289 }
283290 }
284- if (foundBoardsFilePath == null ) {
291+ if (foundBoardsFilePath == null || (! foundBoardsFilePath . toFile (). exists ()) ) {
285292 return new BoardDescription ();
286293 }
287294
295+
288296 KeyValueTree optionsHolder =oldConfig .getChild ("board.BOARD.MENU" ); //$NON-NLS-1$
289297
290298 Map <String , String > options =new HashMap <>();
0 commit comments