Skip to content

Commit 36da418

Browse files
alirana01Shen7436
authored andcommitted
IEP-1603: version handling for json file from eim (#1276)
* IEP-1603: version handling for json file from eim
1 parent 351b0a9 commit 36da418

File tree

13 files changed

+134
-15
lines changed

13 files changed

+134
-15
lines changed

bundles/com.espressif.idf.core/META-INF/MANIFEST.MF

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Export-Package: com.espressif.idf.core,
4646
com.espressif.idf.core.resources,
4747
com.espressif.idf.core.toolchain,
4848
com.espressif.idf.core.tools,
49+
com.espressif.idf.core.tools.exceptions,
4950
com.espressif.idf.core.tools.util,
5051
com.espressif.idf.core.tools.vo,
5152
com.espressif.idf.core.tools.watcher,

bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/EimConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ public interface EimConstants
2727

2828
String USER_EIM_DIR = Paths.get(System.getProperty("user.home"), ".espressif", "eim_gui").toString(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
2929

30+
String EIM_JSON_VALID_VERSION = "1.0"; //$NON-NLS-1$
3031
}

bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/EimIdfConfiguratinParser.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.eclipse.core.runtime.Platform;
88

99
import com.espressif.idf.core.logging.Logger;
10+
import com.espressif.idf.core.tools.exceptions.EimVersionMismatchException;
1011
import com.espressif.idf.core.tools.vo.EimJson;
1112
import com.google.gson.Gson;
1213
import com.google.gson.GsonBuilder;
@@ -22,7 +23,7 @@ public EimIdfConfiguratinParser()
2223
.excludeFieldsWithoutExposeAnnotation().create();
2324
}
2425

25-
private void load() throws IOException
26+
private void load() throws IOException, EimVersionMismatchException
2627
{
2728
String path = Platform.getOS().equals(Platform.OS_WIN32) ? EimConstants.EIM_WIN_PATH
2829
: EimConstants.EIM_POSIX_PATH;
@@ -38,9 +39,14 @@ private void load() throws IOException
3839
{
3940
eimJson = gson.fromJson(fileReader, EimJson.class);
4041
}
42+
43+
if (!eimJson.getVersion().equals(EimConstants.EIM_JSON_VALID_VERSION))
44+
{
45+
throw new EimVersionMismatchException(EimConstants.EIM_JSON_VALID_VERSION,eimJson.getVersion());
46+
}
4147
}
4248

43-
public EimJson getEimJson(boolean reload) throws IOException
49+
public EimJson getEimJson(boolean reload) throws IOException, EimVersionMismatchException
4450
{
4551
if (reload || eimJson == null)
4652
{

bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/Messages.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public class Messages extends NLS
1515
public static String InstallToolsHandler_OpenOCDRulesCopyError;
1616
public static String InstallToolsHandler_OpenOCDRulesCopied;
1717

18+
public static String EimVersionMismatchExceptionMessage;
19+
public static String EimVersionMismatchExceptionMessageTitle;
20+
1821
static
1922
{
2023
// initialize resource bundle

bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/ToolInitializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.espressif.idf.core.IDFEnvironmentVariables;
2424
import com.espressif.idf.core.ProcessBuilderFactory;
2525
import com.espressif.idf.core.logging.Logger;
26+
import com.espressif.idf.core.tools.exceptions.EimVersionMismatchException;
2627
import com.espressif.idf.core.tools.vo.EimJson;
2728
import com.espressif.idf.core.util.StringUtil;
2829

@@ -66,7 +67,7 @@ public boolean isEimIdfJsonPresent()
6667
return new File(path).exists();
6768
}
6869

69-
public EimJson loadEimJson()
70+
public EimJson loadEimJson() throws EimVersionMismatchException
7071
{
7172
try
7273
{
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*******************************************************************************
2+
* Copyright 2025 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
3+
* Use is subject to license terms.
4+
*******************************************************************************/
5+
package com.espressif.idf.core.tools.exceptions;
6+
7+
import com.espressif.idf.core.logging.Logger;
8+
import com.espressif.idf.core.tools.Messages;
9+
10+
/**
11+
* Exception to be thrown when the EIM version found
12+
* does not match the expected version
13+
* @author Ali Azam Rana
14+
* */
15+
public class EimVersionMismatchException extends Exception
16+
{
17+
private static final long serialVersionUID = 4471390598613711666L;
18+
private final String expectedVersion;
19+
private final String foundVersion;
20+
21+
public EimVersionMismatchException(String expectedVersion, String foundVersion)
22+
{
23+
super(String.format(Messages.EimVersionMismatchExceptionMessage, expectedVersion, foundVersion));
24+
Logger.log(String.format("Invalid eim_idf.json version. Expected: %s, but found: %s.", expectedVersion, foundVersion)); //$NON-NLS-1$
25+
this.expectedVersion = expectedVersion;
26+
this.foundVersion = foundVersion;
27+
}
28+
29+
public String getExpectedVersion()
30+
{
31+
return expectedVersion;
32+
}
33+
34+
public String getFoundVersion()
35+
{
36+
return foundVersion;
37+
}
38+
39+
public String msgTitle()
40+
{
41+
return Messages.EimVersionMismatchExceptionMessageTitle;
42+
}
43+
}

bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/messages.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ InstallToolsHandler_OpenOCDRulesCopyWarningMessage=The rules file is already pre
55
InstallToolsHandler_OpenOCDRulesNotCopied=Rules Not Copied to system
66
InstallToolsHandler_OpenOCDRulesCopyError=Unable to copy rules for OpenOCD to system directory, try running the eclipse with sudo command
77
InstallToolsHandler_OpenOCDRulesCopied=Rules Copied to system
8+
9+
EimVersionMismatchExceptionMessage=Invalid eim_idf.json version. Expected: %s, but found: %s.\nThe IDE may not function correctly.
10+
EimVersionMismatchExceptionMessageTitle=EIM Version Mismatch

bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/vo/EimJson.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
public class EimJson
99
{
10+
@Expose
11+
private String version;
1012
@Expose
1113
private String eimPath;
1214
@Expose
@@ -56,4 +58,14 @@ public void setEimPath(String eimPath)
5658
this.eimPath = eimPath;
5759
}
5860

61+
public String getVersion()
62+
{
63+
return version;
64+
}
65+
66+
public void setVersion(String version)
67+
{
68+
this.version = version;
69+
}
70+
5971
}

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/EimButtonLaunchListener.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.eclipse.core.runtime.IStatus;
1212
import org.eclipse.core.runtime.Status;
1313
import org.eclipse.core.runtime.jobs.Job;
14+
import org.eclipse.jface.dialogs.MessageDialog;
1415
import org.eclipse.swt.events.SelectionAdapter;
1516
import org.eclipse.swt.events.SelectionEvent;
1617
import org.eclipse.swt.widgets.Display;
@@ -26,6 +27,7 @@
2627
import com.espressif.idf.core.tools.EimIdfConfiguratinParser;
2728
import com.espressif.idf.core.tools.EimLoader;
2829
import com.espressif.idf.core.tools.ToolInitializer;
30+
import com.espressif.idf.core.tools.exceptions.EimVersionMismatchException;
2931
import com.espressif.idf.core.tools.vo.EimJson;
3032
import com.espressif.idf.ui.UIPlugin;
3133
import com.espressif.idf.ui.handlers.EclipseHandler;
@@ -129,10 +131,15 @@ private void launchEspIdfManager() throws PartInitException
129131
IDE.openEditor(activeww.getActivePage(), new EimEditorInput(eimJson), ESPIDFManagerEditor.EDITOR_ID,
130132
true);
131133
}
132-
catch (PartInitException | IOException e)
134+
catch (PartInitException| EimVersionMismatchException | IOException e)
133135
{
134136
Logger.log("Failed to open ESP-IDF Manager Editor.");
135137
Logger.log(e);
138+
if (e instanceof EimVersionMismatchException)
139+
{
140+
EimVersionMismatchException eimEx = (EimVersionMismatchException) e;
141+
MessageDialog.openError(Display.getDefault().getActiveShell(), eimEx.msgTitle(), eimEx.getMessage());
142+
}
136143
}
137144
});
138145

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/EspressifToolStartup.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@
2222
import org.eclipse.ui.IEditorPart;
2323
import org.eclipse.ui.IEditorReference;
2424
import org.eclipse.ui.IStartup;
25-
import org.eclipse.ui.IWorkbench;
2625
import org.eclipse.ui.IWorkbenchPage;
2726
import org.eclipse.ui.IWorkbenchWindow;
2827
import org.eclipse.ui.PartInitException;
29-
import org.eclipse.ui.PlatformUI;
3028
import org.eclipse.ui.console.MessageConsoleStream;
3129
import org.eclipse.ui.ide.IDE;
32-
import org.eclipse.ui.intro.IIntroManager;
3330
import org.osgi.service.prefs.Preferences;
3431

3532
import com.espressif.idf.core.IDFEnvironmentVariables;
@@ -39,6 +36,7 @@
3936
import com.espressif.idf.core.tools.EimConstants;
4037
import com.espressif.idf.core.tools.EimLoader;
4138
import com.espressif.idf.core.tools.ToolInitializer;
39+
import com.espressif.idf.core.tools.exceptions.EimVersionMismatchException;
4240
import com.espressif.idf.core.tools.vo.EimJson;
4341
import com.espressif.idf.core.tools.watcher.EimJsonWatchService;
4442
import com.espressif.idf.core.util.IDFUtil;
@@ -88,7 +86,15 @@ public void earlyStartup()
8886
return;
8987
}
9088

91-
eimJson = toolInitializer.loadEimJson();
89+
try
90+
{
91+
eimJson = toolInitializer.loadEimJson();
92+
}
93+
catch (EimVersionMismatchException e)
94+
{
95+
Logger.log(e);
96+
return;
97+
}
9298

9399
if (toolInitializer.isOldEspIdfConfigPresent() && !toolInitializer.isOldConfigExported())
94100
{
@@ -395,7 +401,16 @@ public void onCompleted(String filePath)
395401
Logger.log("Old configuration found and not converted");
396402
handleOldConfigExport();
397403
}
398-
eimJson = toolInitializer.loadEimJson();
404+
try
405+
{
406+
eimJson = toolInitializer.loadEimJson();
407+
}
408+
catch (EimVersionMismatchException e)
409+
{
410+
Logger.log(e);
411+
MessageDialog.openError(Display.getDefault().getActiveShell(), e.msgTitle(), e.getMessage());
412+
return;
413+
}
399414
openEspIdfManager(eimJson);
400415
});
401416
}

0 commit comments

Comments
 (0)