Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IEP-974: Adding the IDE env versions to the esp_idf.json #781

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

alirana01
Copy link
Collaborator

@alirana01 alirana01 commented Jun 7, 2023

Description

Previously only the path was changed in the file and now the esp_idf.json file is modified keeping the formatting proper and also adding the object for a different version.

Also improved the message to user

Fixes # (IEP-974)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How has this been tested?

Use the testing from IEP-952 (PR)
Additionally verify that the updated version in the IDE is also added to the esp_idf.json file and is the activated one

Test Configuration:

  • ESP-IDF Version: Any
  • OS (Windows,Linux and macOS): Windows only

Checklist

  • PR Self Reviewed
  • Applied Code formatting
  • Added Documentation
  • Verified on all platforms - Windows,Linux and macOS

Previously only the path was changed in the file and now the esp_idf.json file is modified keeping the formatting proper and also adding the object for a different version
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see if this is fine here or we can somehow add it to main README.MD

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestions needed on how we can improve this message

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to use gson from google's api to make the file output pretty.

@alirana01 alirana01 self-assigned this Jun 7, 2023
@alirana01 alirana01 changed the title [WIP] IEP-974: Adding the IDE env versions to the esp_idf.json IEP-974: Adding the IDE env versions to the esp_idf.json Jun 7, 2023
Copy link
Collaborator

@sigmaaa sigmaaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @alirana01. Added suggestions to improve the message. Code LGTM, I couldn't find visually any bugs, however, I'm finding methods in this class are a little bit complex, and maybe we want to refactor them in the future.
My ideas on what we can add in the future:

  1. We could move all json related operations to separate classes and cover them with unit tests.
  2. I'm finding earlyStartup() method has at least two reasons to change (violation SRP), so mb we want to create another class that implements IStartup.

Let me know what you think about it. Do you have any other ideas on how to make it more maintainable and robust?

Comment on lines +126 to +127
java.util.regex.Pattern p = java.util.regex.Pattern.compile("([0-9][.][0-9])"); //$NON-NLS-1$
java.util.regex.Matcher m = p.matcher(version);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use Pattern and Matcher and import java.util.regex.Matcher; import java.util.regex.Pattern; here?

ToolsInitializationDifferentPathMessageBoxTitle=Different IDF path found in the config file
ToolsInitializationDifferentPathMessageBoxMessage=A different IDF path was found in the startup configuration file do you want to install the tools in this path or keep the older path\nNew Path: {0}\nOld Path: {1}
ToolsInitializationDifferentPathMessageBoxTitle=Different IDF path found in IDE Environment
ToolsInitializationDifferentPathMessageBoxMessage=Different IDF tools are installed in the IDE Environment: {0} than the one selected in startup config file for IDE (esp_idf.json).\nIf you want to keep the IDF tools in the IDE Environment select Yes(This will also add the tools to esp_idf.json).\nIf you want to revert to the last used tools in esp_idf.json press No.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about rephrasing it like this:

  • 1 version:
    The IDE Environment has different IDF tools installed compared to the ones selected in the startup-config file for the IDE (esp_idf.json).
    To keep the IDF tools {0} in the IDE Environment and update the tools in esp_idf.json, select "Yes."
    To revert to the last used tools in esp_idf.json, press "No."

However, I found version 1 too verbose

  • 2 version:
    The IDF tools installed in the IDE Environment are different from the ones selected in the startup-config file (esp_idf.json) for the IDE. Do you want to keep the IDF tools {0} in the IDE Environment and update the tools in esp_idf.json?

what do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second version is misleading to my understanding as I think it can confuse the user like they can press No thinking that the tools wont be added to json file but instead we are trying to revert the tools back to the original installation. This would be okay if we didnt have the usecase where the tools are updated via the IDE offline installer.

Copy link
Collaborator

@kolipakakondal kolipakakondal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, we can also update message box with more clear and concise message

JSONObject selectedIDFInfo = (JSONObject) list.get(idfVersionId);
String idfPath = (String) selectedIDFInfo.get(IDF_PATH);
IDFEnvironmentVariables idfEnvMgr = new IDFEnvironmentVariables();
return !idfEnvMgr.getEnvValue(IDFEnvironmentVariables.IDF_PATH).equals(idfPath);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idfEnvMgr.getEnvValue(IDFEnvironmentVariables.IDF_PATH) will return null when IDE is not configured with the IDF_PATH(IDE is not launched and configured not even once). That leads to NPE

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of multiple back slashes in the path, this might fail.
IDE would have configured IDF_PATH to C:\esp\esp-idf-5.0 and windows installer would have set to C:\\esp\\esp-idf-5.0 as per equals() both will be different

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. Probably we could use Paths.get().normalize() here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. Probably we could use Paths.get().normalize() here

I dont think using normalize is a good idea simply comparison like using Paths.get(path).toAbsolutePath().compareTo(pathToCompare) == 0
should be enough for us considering that we null check first.

Comment on lines +125 to +134
String version = IDFUtil.getEspIdfVersion();
java.util.regex.Pattern p = java.util.regex.Pattern.compile("([0-9][.][0-9])"); //$NON-NLS-1$
java.util.regex.Matcher m = p.matcher(version);
if (m.find())
{
version = m.group(0);
}
updateEspIdfJsonFile(idf_json_file, idfEnvMgr.getEnvValue(IDFEnvironmentVariables.IDF_PATH),
IDFUtil.getIDFPythonEnvPath(),
version);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the user updated esp-idf(let's say 5.0 to 5.1) through windows installer, in this case isVersionDifferentInFile is true considering we compare esp-idf path from IDE and esp-idf.json

Don't we export the paths in this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants