44 *******************************************************************************/
55package com .espressif .idf .ui .size ;
66
7+ import java .lang .module .ModuleDescriptor .Version ;
78import java .util .ArrayList ;
89import java .util .Collections ;
910import java .util .List ;
@@ -189,11 +190,12 @@ protected List<String> getCommandArgsArchives(String pythonExecutablenPath, IFil
189190
190191 private List <String > addJsonParseCommand ()
191192 {
192- List <String > arguments = new ArrayList <String >();
193+ List <String > arguments = new ArrayList <>();
193194 IEnvironmentVariable idfVersionEnv = new IDFEnvironmentVariables ()
194195 .getEnv (IDFEnvironmentVariables .ESP_IDF_VERSION );
195196 String idfVersion = idfVersionEnv != null ? idfVersionEnv .getValue () : null ;
196- if (idfVersion != null && Double .parseDouble (idfVersion ) >= 5.1 )
197+
198+ if (idfVersion != null && isVersionAtLeast (idfVersion , "5.1" )) //$NON-NLS-1$
197199 {
198200 arguments .add ("--format" ); //$NON-NLS-1$
199201 arguments .add ("json" ); //$NON-NLS-1$
@@ -205,6 +207,13 @@ private List<String> addJsonParseCommand()
205207 return arguments ;
206208 }
207209
210+ public boolean isVersionAtLeast (String currentIDFVersion , String minimumIDFVersion )
211+ {
212+ Version currentVersion = Version .parse (currentIDFVersion );
213+ Version minVersion = Version .parse (minimumIDFVersion );
214+ return currentVersion .compareTo (minVersion ) >= 0 ;
215+ }
216+
208217 protected List <String > getCommandArgsSymbolDetails (String pythonExecutablenPath , IFile file )
209218 {
210219 List <String > arguments = new ArrayList <String >();
@@ -231,6 +240,12 @@ protected List<String> getCommandArgs(String pythonExecutablenPath, IFile file,
231240 protected JSONObject getJSON (String jsonOutput )
232241 {
233242 JSONObject jsonObj = null ;
243+ if (jsonOutput .indexOf ("{" ) != 0 ) //$NON-NLS-1$
244+ {
245+ int begin = jsonOutput .indexOf ("{" ) - 1 ; //$NON-NLS-1$
246+ int end = jsonOutput .lastIndexOf ("}" ) + 1 ; //$NON-NLS-1$
247+ jsonOutput = jsonOutput .substring (begin , end );
248+ }
234249 try
235250 {
236251 jsonObj = (JSONObject ) new JSONParser ().parse (jsonOutput );
0 commit comments