Skip to content

Commit 81bb9bb

Browse files
committed
IEP 1517: Handling case for conversion of existing json file to eim_idf.json (#1218)
* eim auto import for old config added
1 parent 0f5621f commit 81bb9bb

5 files changed

Lines changed: 107 additions & 14 deletions

File tree

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ ToolsInitializationDifferentPathMessageBoxTitle=Different IDF path found in the
2222
ToolsInitializationEimMissingMsgBoxTitle=ESP-IDF Not Found
2323
ToolsInitializationEimMissingMsgBoxMessage=ESP-IDF is not found on your system. To use the IDE, install ESP-IDF using <a href="{0}">EIM - GUI Installer</a>. \n\nOnce installed, the IDE will automatically detect ESP-IDF. You can verify and activate it from the ESP-IDF Manager, accessible via the menu: Espressif > ESP-IDF Manager.\n\n
2424
ToolsInitializationDifferentPathMessageBoxMessage=A different ESP-IDF path was found in the esp_idf.json.json configuration file. Do you want to install the tools in the new path or the old path? Please click on the appropriate button.\nNew Path: {0}\nOld Path: {1}
25-
ToolsInitializationDifferentPathMessageBoxOptionYes=Use New Path
26-
ToolsInitializationDifferentPathMessageBoxOptionNo=Use Old Path
25+
ToolsInitializationDifferentPathMessageBoxOptionYes=Yes
26+
ToolsInitializationDifferentPathMessageBoxOptionNo=No
2727
RefreshingProjects_JobName=Refreshing Projects...
2828
IDFBuildConfiguration_PreCheck_DifferentIdfPath=The project was built using the ESP-IDF located at the {0} path.\nThe currently active ESP-IDF path in the IDE is {1}.\nPlease clean the project using "ESP-IDF:Project Full Clean" menu option to use the active ESP-IDF configuration.
2929
IDFToolChainsMissingErrorMsg=Toolchains are missing. Please use ESP-IDF Manager for configuring
3030

3131
NoActiveEspIdfInWorkspaceMsgTitle=ESP-IDF Setup
3232
NoActiveEspIdfInWorkspaceMsg=ESP-IDF is required to use Espressif IDE. Would you like to configure it now?
3333

34-
OldConfigFoundMsgBoxTitle=Old Configuration Found
35-
OldConfigFoundMsgBoxMsg=An old ESP-IDF configuration has been detected.\nIf you want to use these you need to export these configuration and pass them on to EIM for updated configurations.\nWould you like to export these settings?\n\nPress 'Yes' to choose a location to save.
34+
OldConfigFoundMsgBoxTitle=Old Configuration Detected
35+
OldConfigFoundMsgBoxMsg=Espressif IDE now uses the EIM system to manage ESP-IDF installations. A legacy configuration was found in your current workspace. Converting it to the EIM format will allow proper environment setup and ensure the IDE works seamlessly with your existing projects. Would you like to convert the configuration now?
3636
OldConfigExportDirectorSelectionDialogTitle=Select Destination
3737
OldConfigExportDirectorSelectionDialogInfo=Choose a directory to save the exported settings.
38-
OldConfigExportCompleteSuccessMsgTitle=Export Successful
39-
OldConfigExportCompleteSuccessMsg=The configuration has been successfully copied to:\n{0}
40-
OldConfigExportCompleteFailMsgTitle=Export Failed
41-
OldConfigExportCompleteFailMsg=An error occurred while copying the configuration.\n{0}
38+
OldConfigExportCompleteSuccessMsgTitle=Import Successful
39+
OldConfigExportCompleteSuccessMsg=The configuration has been successfully Imported
40+
OldConfigExportCompleteFailMsgTitle=Conversion Failed
41+
OldConfigExportCompleteFailMsg=An error occurred while converting old configuration.

bundles/com.espressif.idf.core/src/com/espressif/idf/core/logging/Logger.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
*/
2121
public class Logger
2222
{
23+
public static void log(String message, Exception e)
24+
{
25+
log(IDFCorePlugin.getPlugin(), message, e);
26+
}
2327

2428
public static void log(String message)
2529
{

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66

77
import java.io.File;
88
import java.io.IOException;
9-
import java.nio.file.Files;
10-
import java.nio.file.StandardCopyOption;
9+
import java.util.ArrayList;
10+
import java.util.List;
1111

1212
import org.eclipse.core.resources.ResourcesPlugin;
1313
import org.eclipse.core.runtime.IPath;
14+
import org.eclipse.core.runtime.IStatus;
1415
import org.eclipse.core.runtime.Platform;
16+
import org.eclipse.core.runtime.Status;
1517
import org.osgi.service.prefs.Preferences;
1618

19+
import com.espressif.idf.core.IDFCorePlugin;
20+
import com.espressif.idf.core.ProcessBuilderFactory;
1721
import com.espressif.idf.core.logging.Logger;
1822
import com.espressif.idf.core.tools.vo.EimJson;
1923

@@ -57,15 +61,25 @@ public boolean isOldEspIdfConfigPresent()
5761
return getOldConfigFile().exists();
5862
}
5963

60-
public void exportOldConfigIfNeeded(String exportPath) throws IOException
64+
public IStatus exportOldConfig() throws IOException
6165
{
6266
File oldConfig = getOldConfigFile();
6367
if (oldConfig.exists())
6468
{
65-
File destinationFile = new File(exportPath, oldConfig.getName());
66-
Files.copy(oldConfig.toPath(), destinationFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
67-
preferences.putBoolean(EimConstants.OLD_CONFIG_EXPORTED_FLAG, true);
69+
// eim import pathToOldConfigJson
70+
List<String> commands = new ArrayList<>();
71+
commands.add(loadEimJson().getEimPath());
72+
commands.add("import"); //$NON-NLS-1$
73+
commands.add(oldConfig.getAbsolutePath());
74+
ProcessBuilderFactory processBuilderFactory = new ProcessBuilderFactory();
75+
IStatus status = processBuilderFactory.runInBackground(commands, org.eclipse.core.runtime.Path.ROOT,
76+
System.getenv());
77+
78+
Logger.log(status.getMessage());
79+
return status;
6880
}
81+
82+
return new Status(IStatus.ERROR, IDFCorePlugin.getId(), -1, "Error in conversion", null); //$NON-NLS-1$
6983
}
7084

7185
public boolean isOldConfigExported()

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 eimPath;
1012
@Expose
1113
private String gitPath;
1214
@Expose
@@ -44,4 +46,14 @@ public void setIdfInstalled(List<IdfInstalled> idfInstalled)
4446
this.idfInstalled = idfInstalled;
4547
}
4648

49+
public String getEimPath()
50+
{
51+
return eimPath;
52+
}
53+
54+
public void setEimPath(String eimPath)
55+
{
56+
this.eimPath = eimPath;
57+
}
58+
4759
}

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
*******************************************************************************/
55
package com.espressif.idf.ui.tools;
66

7+
import java.io.IOException;
78
import java.text.MessageFormat;
89

10+
import org.eclipse.core.runtime.IStatus;
11+
import org.eclipse.jface.dialogs.MessageDialog;
912
import org.eclipse.swt.SWT;
1013
import org.eclipse.swt.widgets.Display;
1114
import org.eclipse.swt.widgets.MessageBox;
@@ -41,6 +44,9 @@
4144
public class EspressifToolStartup implements IStartup
4245
{
4346
private EimJsonUiChangeHandler eimJsonUiChangeHandler;
47+
private ToolInitializer toolInitializer;
48+
private Preferences preferences;
49+
4450
@Override
4551
public void earlyStartup()
4652
{
@@ -51,11 +57,20 @@ public void earlyStartup()
5157
eimJsonUiChangeHandler = new EimJsonUiChangeHandler(preferences);
5258
stateChecker.updateLastSeenTimestamp();
5359
EimJsonWatchService.getInstance().addEimJsonChangeListener(eimJsonUiChangeHandler);
60+
5461
if (!toolInitializer.isEimInstalled())
5562
{
63+
Logger.log("EIM not installed");
5664
notifyMissingTools();
5765
return;
5866
}
67+
68+
if (toolInitializer.isOldEspIdfConfigPresent()
69+
&& !toolInitializer.isOldConfigExported())
70+
{
71+
Logger.log("Old configuration found and not converted");
72+
handleOldConfigExport();
73+
}
5974

6075
EimJson eimJson = toolInitializer.loadEimJson();
6176
if (eimJson == null)
@@ -74,6 +89,54 @@ public void earlyStartup()
7489
}
7590
}
7691

92+
private void handleOldConfigExport()
93+
{
94+
final int[] response = new int[] { -1 };
95+
Display display = Display.getDefault();
96+
display.syncExec(() -> {
97+
MessageDialog messageDialog = new MessageDialog(display.getActiveShell(),
98+
Messages.OldConfigFoundMsgBoxTitle, null, Messages.OldConfigFoundMsgBoxMsg, 0, 0,
99+
new String[] { Messages.ToolsInitializationDifferentPathMessageBoxOptionYes,
100+
Messages.ToolsInitializationDifferentPathMessageBoxOptionNo });
101+
response[0] = messageDialog.open();
102+
});
103+
104+
if (response[0] == 0)
105+
{
106+
try
107+
{
108+
IStatus status = toolInitializer.exportOldConfig();
109+
Logger.log("Tools Conversion Process Message: ");
110+
Logger.log(status.getMessage());
111+
if (status.getSeverity() != IStatus.ERROR)
112+
{
113+
preferences.putBoolean(EimConstants.OLD_CONFIG_EXPORTED_FLAG, true);
114+
displayInformationMessageBox(Messages.OldConfigExportCompleteSuccessMsgTitle,
115+
Messages.OldConfigExportCompleteSuccessMsg);
116+
}
117+
else
118+
{
119+
displayInformationMessageBox(Messages.OldConfigExportCompleteFailMsgTitle,
120+
Messages.OldConfigExportCompleteFailMsg);
121+
}
122+
}
123+
catch (IOException e)
124+
{
125+
Logger.log("Error exporting old configuration", e);
126+
displayInformationMessageBox(Messages.OldConfigExportCompleteFailMsgTitle,
127+
Messages.OldConfigExportCompleteFailMsg);
128+
}
129+
}
130+
}
131+
132+
private void displayInformationMessageBox(String messageTitle, String message)
133+
{
134+
Display display = Display.getDefault();
135+
display.syncExec(() -> {
136+
MessageDialog.openInformation(display.getActiveShell(), messageTitle, message);
137+
});
138+
}
139+
77140
private void showEimJsonStateChangeNotification()
78141
{
79142
int response = eimJsonUiChangeHandler.displayMessageToUser();

0 commit comments

Comments
 (0)