Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bundles/com.espressif.idf.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ Export-Package: com.espressif.idf.core,
com.espressif.idf.core.resources,
com.espressif.idf.core.toolchain,
com.espressif.idf.core.tools,
com.espressif.idf.core.tools.eimjson,
com.espressif.idf.core.tools.eimjson.model,
com.espressif.idf.core.tools.eimjson.presentation,
com.espressif.idf.core.tools.exceptions,
com.espressif.idf.core.tools.launch,
com.espressif.idf.core.tools.util,
com.espressif.idf.core.tools.vo,
com.espressif.idf.core.tools.watcher,
com.espressif.idf.core.util,
com.espressif.idf.core.variable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ public interface EimConstants

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

String EIM_JSON_VALID_VERSION = "2.0"; //$NON-NLS-1$
}
Original file line number Diff line number Diff line change
@@ -1,56 +1,39 @@
/*******************************************************************************
* Copyright 2026 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
* Use is subject to license terms.
*******************************************************************************/
package com.espressif.idf.core.tools;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Path;

import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.tools.eimjson.EimIdfJsonLoader;
import com.espressif.idf.core.tools.eimjson.model.EimConfigModel;
import com.espressif.idf.core.tools.exceptions.EimVersionMismatchException;
import com.espressif.idf.core.tools.vo.EimJson;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
* Loads {@code eim_idf.json}. Delegates version detection and parsing to
* {@link EimIdfJsonLoader}.
*/
public class EimIdfConfiguratinParser
{
private EimJson eimJson;
private Gson gson;
private final EimIdfJsonLoader loader = new EimIdfJsonLoader();
private EimConfigModel configModel;

public EimIdfConfiguratinParser()
{
gson = new GsonBuilder().setPrettyPrinting().enableComplexMapKeySerialization()
.excludeFieldsWithoutExposeAnnotation().create();
}

private void load() throws IOException, EimVersionMismatchException
{
Path jsonPath = new EimIdfJsonPathResolver().resolveEimIdfJsonFile();
String path = jsonPath.toString();
File file = new File(path);
if (!file.exists())
{
Logger.log("EIM config file not found: " + path); //$NON-NLS-1$
return;
}

try (FileReader fileReader = new FileReader(file))
{
eimJson = gson.fromJson(fileReader, EimJson.class);
}

if (Double.parseDouble(eimJson.getVersion()) > Double.parseDouble(EimConstants.EIM_JSON_VALID_VERSION))
{
throw new EimVersionMismatchException(EimConstants.EIM_JSON_VALID_VERSION, eimJson.getVersion());
}
configModel = loader.loadDefault();
}

public EimJson getEimJson(boolean reload) throws IOException, EimVersionMismatchException
public EimConfigModel getConfigModel(boolean reload) throws IOException, EimVersionMismatchException
{
if (reload || eimJson == null)
if (reload || configModel == null)
{
load();
}

return eimJson;
return configModel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ public class Messages extends NLS

public static String EimVersionMismatchExceptionMessage;
public static String EimVersionMismatchExceptionMessageTitle;

public static String EimInstallationStatusActive;
public static String EimInstallationStatusSettingUp;
public static String EimInstallationStatusInProgress;
public static String EimInstallationStatusFailed;
public static String EimInstallationStatusBeingRepaired;
public static String EimInstallationStatusBroken;

static
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import com.espressif.idf.core.ProcessBuilderFactory;
import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.toolchain.ESPToolChainManager;
import com.espressif.idf.core.tools.eimjson.model.EimConfigModel;
import com.espressif.idf.core.tools.eimjson.model.EimInstallationModel;
import com.espressif.idf.core.tools.util.ToolsUtility;
import com.espressif.idf.core.tools.vo.EimJson;
import com.espressif.idf.core.tools.vo.IdfInstalled;
import com.espressif.idf.core.util.IDFUtil;
import com.espressif.idf.core.util.LspService;
import com.espressif.idf.core.util.StringUtil;
Expand All @@ -46,18 +46,19 @@
*/
public class SetupToolsInIde extends Job
{
private EimJson eimJson;
private IdfInstalled idfInstalled;
private EimConfigModel config;
private EimInstallationModel installation;
private MessageConsoleStream errorConsoleStream;
private MessageConsoleStream standardConsoleStream;
private Map<String, String> envVarsFromActivationScriptMap;
private Map<String, String> existingEnvVarsInIdeForRollback;

public SetupToolsInIde(IdfInstalled idfInstalled, EimJson eimJson, MessageConsoleStream errorConsoleStream, MessageConsoleStream standardConsoleStream)
public SetupToolsInIde(EimInstallationModel installation, EimConfigModel config,
MessageConsoleStream errorConsoleStream, MessageConsoleStream standardConsoleStream)
{
super("Tools Setup"); //$NON-NLS-1$
this.idfInstalled = idfInstalled;
this.eimJson = eimJson;
this.installation = installation;
this.config = config;
this.errorConsoleStream = errorConsoleStream;
this.standardConsoleStream = standardConsoleStream;
}
Expand All @@ -83,7 +84,7 @@ public void rollback()
IDFUtil.updateEspressifPrefPageOpenocdPath();
try
{
setUpToolChainsAndTargets(true);
setUpToolChainsAndTargets(true, null);
}
catch (Exception e)
{
Expand All @@ -96,13 +97,27 @@ private IStatus setupTools(IProgressMonitor monitor)
monitor.beginTask("Setting up tools in IDE", 7); //$NON-NLS-1$
monitor.worked(1);
Map<String, String> env = new HashMap<>(System.getenv());
addGitToEnvironment(env, eimJson.getGitPath());
List<String> arguemnts = ToolsUtility.getExportScriptCommand(idfInstalled.getActivationScript());
addGitToEnvironment(env, config.getGitPath());
var activationScriptOpt = installation.getActivationScript();
if (activationScriptOpt.isEmpty())
{
log("Activation script path is missing", IStatus.ERROR); //$NON-NLS-1$
return IDFCorePlugin.errorStatus("Activation script path is missing", null); //$NON-NLS-1$
}
var pythonOpt = installation.getPython();
if (pythonOpt.isEmpty())
{
log("Python path is missing for installation", IStatus.ERROR); //$NON-NLS-1$
return IDFCorePlugin.errorStatus("Python path is missing for installation", null); //$NON-NLS-1$
}
String activationScript = activationScriptOpt.get();
String pythonPath = pythonOpt.get();
List<String> arguemnts = ToolsUtility.getExportScriptCommand(activationScript);
Comment thread
d-almazov marked this conversation as resolved.
final ProcessBuilderFactory processBuilderFactory = new ProcessBuilderFactory();
try
{
monitor.setTaskName("Running Activation Script"); //$NON-NLS-1$
IStatus status = processBuilderFactory.runInBackground(arguemnts, Path.ROOT, System.getenv());
IStatus status = processBuilderFactory.runInBackground(arguemnts, Path.ROOT, env);
if (status == null)
{
Logger.log(IDFCorePlugin.getPlugin(), IDFCorePlugin.errorStatus("Status returned null from activation script process", null)); //$NON-NLS-1$
Expand Down Expand Up @@ -134,12 +149,12 @@ private IStatus setupTools(IProgressMonitor monitor)

monitor.setTaskName("Setting up IDE environment"); //$NON-NLS-1$
log("Setting up IDE environment variables", IStatus.INFO); //$NON-NLS-1$
setupEnvVarsInEclipse();
setupEnvVarsInEclipse(pythonPath);
monitor.worked(1);

monitor.setTaskName("Setting up toolchains"); //$NON-NLS-1$
log("Setting up toolchains", IStatus.INFO); //$NON-NLS-1$
setUpToolChainsAndTargets(false);
setUpToolChainsAndTargets(false, pythonPath);
monitor.worked(1);

monitor.setTaskName("Applying Clangd Preferences"); //$NON-NLS-1$
Expand Down Expand Up @@ -172,12 +187,12 @@ private String getUpdatedPathWithSystemPath()
return path;
}

private IStatus loadTargetsAvailableFromIdfInCurrentToolSet(boolean rollback)
private IStatus loadTargetsAvailableFromIdfInCurrentToolSet(boolean rollback, String pythonPath)
{
List<String> arguments = new ArrayList<String>();
arguments.add(rollback
? existingEnvVarsInIdeForRollback.get(IDFEnvironmentVariables.PYTHON_EXE_PATH)
: idfInstalled.getPython());
: pythonPath);
arguments
.add(IDFUtil
.getIDFPythonScriptFile(
Expand Down Expand Up @@ -243,7 +258,7 @@ private void prepEnvMap(Map<String, String> env)
{
env.put("PYTHONUNBUFFERED", "1"); //$NON-NLS-1$ //$NON-NLS-2$
loadIdfPathWithSystemPath(env);
addGitToEnvironment(env, eimJson.getGitPath());
addGitToEnvironment(env, config.getGitPath());
}

private void loadIdfPathWithSystemPath(Map<String, String> systemEnv)
Expand Down Expand Up @@ -276,9 +291,9 @@ private void loadIdfPathWithSystemPath(Map<String, String> systemEnv)
}
}

private void setUpToolChainsAndTargets(boolean rollback)
private void setUpToolChainsAndTargets(boolean rollback, String pythonPath)
{
IStatus status = loadTargetsAvailableFromIdfInCurrentToolSet(rollback);
IStatus status = loadTargetsAvailableFromIdfInCurrentToolSet(rollback, pythonPath);
if (status.getSeverity() == IStatus.ERROR)
{
Logger.log("Unable to get IDF targets from current toolset"); //$NON-NLS-1$
Expand All @@ -305,27 +320,25 @@ private List<String> extractTargets(String input)
return targets;
}

private void setupEnvVarsInEclipse()
private void setupEnvVarsInEclipse(String pythonPath)
{
createExistingBackup();
IDFEnvironmentVariables idfEnvironmentVariables = new IDFEnvironmentVariables();
for (Entry<String, String> entry : envVarsFromActivationScriptMap.entrySet())
{
idfEnvironmentVariables.addEnvVariable(entry.getKey(), entry.getValue());
}

String path = getUpdatedPathWithSystemPath();
idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.PATH, path);

idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.IDF_COMPONENT_MANAGER, "1"); //$NON-NLS-1$
// IDF_MAINTAINER=1 to be able to build with the clang toolchain
idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.IDF_MAINTAINER, "1"); //$NON-NLS-1$
idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.ESP_IDF_EIM_ID, idfInstalled.getId());

idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.PYTHON_EXE_PATH, idfInstalled.getPython());



idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.ESP_IDF_EIM_ID, installation.getId());

idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.PYTHON_EXE_PATH, pythonPath);

IDFUtil.updateEspressifPrefPageOpenocdPath();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand All @@ -26,8 +27,8 @@
import com.espressif.idf.core.ProcessBuilderFactory;
import com.espressif.idf.core.SystemExecutableFinder;
import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.tools.eimjson.model.EimConfigModel;
import com.espressif.idf.core.tools.exceptions.EimVersionMismatchException;
import com.espressif.idf.core.tools.vo.EimJson;
import com.espressif.idf.core.util.StringUtil;

/**
Expand Down Expand Up @@ -150,10 +151,10 @@ else if (isWindows)
* <li>Default CLI install location (existence-checked)</li>
* </ol>
*
* @param eimJson parsed JSON or {@code null}
* @param config parsed JSON model or {@code null}
* @return resolved absolute path string, or empty if nothing could be resolved
*/
public String resolveEimExecutablePath(EimJson eimJson)
public String resolveEimExecutablePath(EimConfigModel config)
{
String fromPath = findEimOnSystemPath();
if (!StringUtil.isEmpty(fromPath))
Expand All @@ -167,12 +168,23 @@ public String resolveEimExecutablePath(EimJson eimJson)
return fromPkgMgr;
}

if (eimJson != null && !StringUtil.isEmpty(eimJson.getEimPath()))
if (config != null)
{
String jsonPath = eimJson.getEimPath();
if (Files.exists(Paths.get(jsonPath)))
var eimPath = config.getEimPath();
if (eimPath.isPresent())
{
return jsonPath;
try
{
if (Files.exists(Paths.get(eimPath.get())))
{
return eimPath.get();
}
Logger.log("eimPath from eim_idf.json does not exist: " + eimPath.get()); //$NON-NLS-1$
}
catch (InvalidPathException e)
{
Logger.log("Ignoring invalid eimPath from eim_idf.json: " + eimPath.get()); //$NON-NLS-1$
}
}
}

Expand Down Expand Up @@ -203,11 +215,11 @@ public boolean isEimIdfJsonPresent()
return Files.isRegularFile(path) && Files.isReadable(path);
}

public EimJson loadEimJson() throws EimVersionMismatchException
public EimConfigModel loadEimConfig() throws EimVersionMismatchException
{
try
{
return parser.getEimJson(true);
return parser.getConfigModel(true);
}
catch (IOException e)
{
Expand Down
Loading
Loading