Skip to content

Commit 30b766a

Browse files
authored
IEP-1585: Fixed eim old config import handling (#1263)
* IEP-1585: Fixed eim old config import handling
1 parent 5b1961b commit 30b766a

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,26 @@ public boolean isOldEspIdfConfigPresent()
8484
return getOldConfigFile().exists();
8585
}
8686

87-
public IStatus exportOldConfig(String eimPath) throws IOException
87+
public IStatus exportOldConfig(Path eimPath) throws IOException
8888
{
8989
File oldConfig = getOldConfigFile();
9090
if (oldConfig.exists())
9191
{
9292
// eim import pathToOldConfigJson
9393
List<String> commands = new ArrayList<>();
94-
commands.add(StringUtil.isEmpty(eimPath) ?
95-
idfEnvironmentVariables.getEnvValue(IDFEnvironmentVariables.EIM_PATH) : eimPath);
94+
String eimPathStr = StringUtil.EMPTY;
95+
96+
if (eimPath != null && Files.exists(eimPath))
97+
{
98+
eimPathStr = eimPath.toString();
99+
}
100+
else
101+
{
102+
return new Status(IStatus.ERROR, IDFCorePlugin.getId(), -1, "Cannot Convert EIM is not installed", null); //$NON-NLS-1$
103+
}
104+
105+
106+
commands.add(eimPathStr);
96107
commands.add("import"); //$NON-NLS-1$
97108
commands.add(oldConfig.getAbsolutePath());
98109
Logger.log("Running: " + commands.toString()); //$NON-NLS-1$
@@ -123,7 +134,7 @@ public boolean isEspIdfSet()
123134
return preferences.getBoolean(EimConstants.INSTALL_TOOLS_FLAG, false);
124135
}
125136

126-
private Path getDefaultEimPath()
137+
public Path getDefaultEimPath()
127138
{
128139
String userHome = System.getProperty("user.home"); //$NON-NLS-1$
129140
Path defaultEimPath;

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.io.IOException;
88
import java.nio.file.Files;
9+
import java.nio.file.Path;
910
import java.nio.file.Paths;
1011

1112
import org.eclipse.core.runtime.IProgressMonitor;
@@ -161,7 +162,23 @@ private void handleOldConfigExport()
161162
{
162163
try
163164
{
164-
IStatus status = toolInitializer.exportOldConfig(eimJson != null ? eimJson.getEimPath() : StringUtil.EMPTY);
165+
// if eim json is present it means that it contains the updated path and we use that else we fallback to finding eim in default paths
166+
Path eimPath;
167+
String eimPathEnvVar = idfEnvironmentVariables.getEnvValue(IDFEnvironmentVariables.EIM_PATH);
168+
if (eimJson != null)
169+
{
170+
eimPath = Paths.get(eimJson.getEimPath());
171+
}
172+
else if (!StringUtil.isEmpty(eimPathEnvVar))
173+
{
174+
eimPath = Paths.get(eimPathEnvVar);
175+
}
176+
else
177+
{
178+
eimPath = toolInitializer.getDefaultEimPath();
179+
}
180+
181+
IStatus status = toolInitializer.exportOldConfig(eimPath);
165182
Logger.log("Tools Conversion Process Message: ");
166183
Logger.log(status.getMessage());
167184
if (status.getSeverity() != IStatus.ERROR)

0 commit comments

Comments
 (0)