-
Notifications
You must be signed in to change notification settings - Fork 121
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-1018 Automation of hints viewer #809
Changes from 13 commits
6cbcf05
61e5861
b2be1bf
2457fbe
c3731fe
2f52ad6
5fb5362
0c003c3
4c3a13a
8d77bf1
1f3ef2d
f294aa7
e252066
c96ba4b
4394945
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/******************************************************************************* | ||
* Copyright 2022-2023 Espressif Systems (Shanghai) PTE LTD. All rights reserved. | ||
* Use is subject to license terms. | ||
*******************************************************************************/ | ||
package com.espressif.idf.core.build; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
import java.util.regex.PatternSyntaxException; | ||
|
||
import org.eclipse.cdt.core.IConsoleParser; | ||
|
||
import com.espressif.idf.core.logging.Logger; | ||
import com.espressif.idf.core.resources.OpenDialogListenerSupport; | ||
import com.espressif.idf.core.resources.PopupDialog; | ||
import com.espressif.idf.core.util.StringUtil; | ||
|
||
/** | ||
* The EspIdfErrorParser class implements the IConsoleParser interface to parse console output for ESP-IDF errors and | ||
* extract relevant hints. It processes each line of the console output and checks against a list of regular expression | ||
* patterns to identify errors and their corresponding hints. | ||
* | ||
* This class maintains a list of regular expression hint pairs (ReHintPair) that are used to match and identify errors, | ||
* and associate them with appropriate hints. It accumulates matched pairs in the 'allMatchesList' for further | ||
* processing. | ||
* | ||
* The processLine method is responsible for processing each input line by iterating through the list of regular | ||
* expression hint pairs. It uses regular expressions to determine if the line matches any error pattern. If a match is | ||
* found, the corresponding hint is associated with the error message and added to the 'allMatchesList'. | ||
* | ||
* The shutdown method is used to trigger the completion of parsing. It notifies listeners registred in the UI plugin | ||
* that the list of available hints has changed and providing the accumulated error hint pairs. The 'allMatchesList' is | ||
* then cleared to prepare for the next parsing session. | ||
* | ||
* | ||
* @author Denys Almazov ([email protected]) | ||
* | ||
*/ | ||
public class EspIdfErrorParser implements IConsoleParser | ||
{ | ||
|
||
private List<ReHintPair> reHintsList; | ||
private List<ReHintPair> allMatchesList; | ||
|
||
public EspIdfErrorParser(List<ReHintPair> reHintPairs) | ||
{ | ||
this.reHintsList = reHintPairs; | ||
Check warning on line 48 in bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/EspIdfErrorParser.java GitHub Actions / spotbugsEI_EXPOSE_REP2
Raw output
|
||
this.allMatchesList = new ArrayList<>(); | ||
} | ||
Comment on lines
+44
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The constructor + if (reHintPairs == null) {
+ throw new IllegalArgumentException("reHintPairs cannot be null");
+ } |
||
public boolean processLine(String paramString) | ||
{ | ||
for (ReHintPair reHintEntry : reHintsList) | ||
{ | ||
boolean isRegexMatchesWithProcessedString = false; | ||
try | ||
{ | ||
isRegexMatchesWithProcessedString = Pattern.compile(reHintEntry.getRe()).matcher(paramString).find(); | ||
} | ||
catch (PatternSyntaxException e) | ||
{ | ||
// catching incompatible Python regex | ||
Logger.log(e); | ||
continue; | ||
} | ||
|
||
if (isRegexMatchesWithProcessedString) | ||
{ | ||
allMatchesList.add(new ReHintPair(paramString, reHintEntry.getHint())); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public void shutdown() | ||
{ | ||
OpenDialogListenerSupport.getSupport().firePropertyChange(PopupDialog.AVAILABLE_HINTS.name(), | ||
StringUtil.EMPTY, new ArrayList<>(allMatchesList)); | ||
allMatchesList.clear(); | ||
} | ||
sigmaaa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
sigmaaa marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,7 @@ | |
import com.espressif.idf.core.internal.CMakeErrorParser; | ||
import com.espressif.idf.core.logging.Logger; | ||
import com.espressif.idf.core.util.DfuCommandsUtil; | ||
import com.espressif.idf.core.util.HintsUtil; | ||
import com.espressif.idf.core.util.IDFUtil; | ||
import com.espressif.idf.core.util.ParitionSizeHandler; | ||
import com.espressif.idf.core.util.StringUtil; | ||
|
@@ -156,7 +157,7 @@ | |
ICMakeToolChainFile toolChainFile, String launchMode) | ||
{ | ||
super(config, name, toolChain, launchMode); | ||
this.toolChainFile = toolChainFile; | ||
Check warning on line 160 in bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java GitHub Actions / spotbugsEI_EXPOSE_REP2
Raw output
|
||
} | ||
|
||
@Override | ||
|
@@ -189,7 +190,7 @@ | |
org.eclipse.core.runtime.Path path = new org.eclipse.core.runtime.Path(customBuildDir); | ||
if (!path.toFile().exists()) | ||
{ | ||
path.toFile().mkdirs(); | ||
Check warning on line 193 in bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java GitHub Actions / spotbugsRV_RETURN_VALUE_IGNORED_BAD_PRACTICE
Raw output
|
||
} | ||
return path; | ||
} | ||
|
@@ -293,7 +294,7 @@ | |
public ICMakeToolChainFile getToolChainFile() throws CoreException | ||
{ | ||
ICMakeToolChainManager manager = IDFCorePlugin.getService(ICMakeToolChainManager.class); | ||
this.toolChainFile = manager.getToolChainFileFor(getToolChain()); | ||
Check warning on line 297 in bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java GitHub Actions / spotbugsEI_EXPOSE_REP
Raw output
|
||
return toolChainFile; | ||
} | ||
|
||
|
@@ -308,7 +309,7 @@ | |
@Override | ||
public IProject[] build(int kind, Map<String, String> args, IConsole console, IProgressMonitor monitor) | ||
throws CoreException | ||
{ | ||
Check warning on line 312 in bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java GitHub Actions / spotbugsEI_EXPOSE_REP2
Raw output
|
||
this.monitor = monitor; | ||
isProgressSet = false; | ||
|
||
|
@@ -329,7 +330,7 @@ | |
// create build directory | ||
Path buildDir = getBuildDirectory(); | ||
if (!buildDir.toFile().exists()) | ||
{ | ||
Check warning on line 333 in bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java GitHub Actions / spotbugsRV_RETURN_VALUE_IGNORED_BAD_PRACTICE
Raw output
|
||
buildDir.toFile().mkdir(); | ||
} | ||
|
||
|
@@ -419,8 +420,14 @@ | |
console.getErrorStream().write(String.format(Messages.CMakeBuildConfiguration_Failure, "")); //$NON-NLS-1$ | ||
throw new CmakeBuildException(); | ||
} | ||
|
||
watchProcess(p, new IConsoleParser[] { epm, new StatusParser() }); | ||
boolean buildHintsStatus = Platform.getPreferencesService().getBoolean(IDFCorePlugin.PLUGIN_ID, | ||
IDFCorePreferenceConstants.AUTOMATE_BUILD_HINTS_STATUS, | ||
IDFCorePreferenceConstants.AUTOMATE_BUILD_HINTS_DEFAULT_STATUS, null); | ||
IConsoleParser[] consoleParsers = buildHintsStatus | ||
? new IConsoleParser[] { epm, new StatusParser(), | ||
new EspIdfErrorParser(HintsUtil.getReHintsList(new File(HintsUtil.getHintsYmlPath()))) } | ||
: new IConsoleParser[] { epm, new StatusParser() }; | ||
sigmaaa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
watchProcess(p, consoleParsers); | ||
|
||
final String isSkip = System.getProperty("skip.idf.components"); //$NON-NLS-1$ | ||
if (!Boolean.parseBoolean(isSkip)) | ||
Comment on lines
420
to
433
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code now checks for a preference setting to decide whether to use the - new EspIdfErrorParser(HintsUtil.getReHintsList(new File(HintsUtil.getHintsYmlPath())))
+ List<Hint> hints = Collections.emptyList();
+ try {
+ hints = HintsUtil.getReHintsList(new File(HintsUtil.getHintsYmlPath()));
+ } catch (Exception e) {
+ Logger.log(e);
+ }
+ new EspIdfErrorParser(hints) |
||
|
@@ -502,6 +509,7 @@ | |
{ | ||
Thread.sleep(100); | ||
} | ||
Stream.of(consoleParsers).forEach(IConsoleParser::shutdown); | ||
return rc; | ||
} | ||
catch (InterruptedException e) | ||
|
@@ -520,15 +528,15 @@ | |
|
||
public ReaderThread(CBuildConfiguration config, InputStream in, IConsoleParser[] consoleParsers) | ||
{ | ||
this.config = config; | ||
Check warning on line 531 in bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java GitHub Actions / spotbugsDM_DEFAULT_ENCODING
Raw output
|
||
this.in = new BufferedReader(new InputStreamReader(in)); | ||
this.out = null; | ||
this.consoleParsers = consoleParsers; | ||
} | ||
|
||
public ReaderThread(InputStream in, OutputStream out) | ||
{ | ||
Check warning on line 538 in bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java GitHub Actions / spotbugsDM_DEFAULT_ENCODING
Raw output
|
||
this.in = new BufferedReader(new InputStreamReader(in)); | ||
Check warning on line 539 in bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java GitHub Actions / spotbugsDM_DEFAULT_ENCODING
Raw output
|
||
this.out = new PrintStream(out); | ||
this.consoleParsers = null; | ||
this.config = null; | ||
|
@@ -778,7 +786,7 @@ | |
File jsonDiskFile = jsonIPath.toFile(); | ||
|
||
IFolder folder = getIDFComponentsFolder(); | ||
CommandEntry[] sourceFileInfos = null; | ||
Check warning on line 789 in bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java GitHub Actions / spotbugsDM_DEFAULT_ENCODING
Raw output
|
||
try (Reader in = new FileReader(jsonDiskFile)) | ||
{ | ||
Gson gson = new Gson(); | ||
|
@@ -816,7 +824,7 @@ | |
IFolder folder = project.getFolder(getComponentsPath()); | ||
File file = folder.getLocation().toFile(); | ||
if (!file.exists()) | ||
{ | ||
Check warning on line 827 in bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java GitHub Actions / spotbugsRV_RETURN_VALUE_IGNORED_BAD_PRACTICE
Raw output
|
||
folder.getLocation().toFile().mkdirs(); | ||
IProgressMonitor monitor = new NullProgressMonitor(); | ||
folder.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.espressif.idf.core.resources; | ||
|
||
public enum PopupDialog | ||
{ | ||
LOW_PARTITION_SIZE, AVAILABLE_HINTS | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,13 @@ | |
package com.espressif.idf.ui; | ||
|
||
import java.beans.PropertyChangeEvent; | ||
import java.beans.PropertyChangeListener; | ||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.text.MessageFormat; | ||
import java.util.List; | ||
|
||
import org.eclipse.cdt.cmake.core.internal.Activator; | ||
import org.eclipse.core.resources.ResourcesPlugin; | ||
|
@@ -25,6 +25,8 @@ | |
import org.eclipse.swt.widgets.MessageBox; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.eclipse.ui.IStartup; | ||
import org.eclipse.ui.PartInitException; | ||
import org.eclipse.ui.PlatformUI; | ||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
import org.json.simple.parser.ParseException; | ||
|
@@ -33,11 +35,14 @@ | |
|
||
import com.espressif.idf.core.IDFEnvironmentVariables; | ||
import com.espressif.idf.core.build.Messages; | ||
import com.espressif.idf.core.build.ReHintPair; | ||
import com.espressif.idf.core.logging.Logger; | ||
import com.espressif.idf.core.resources.OpenDialogListenerSupport; | ||
import com.espressif.idf.core.resources.PopupDialog; | ||
import com.espressif.idf.core.resources.ResourceChangeListener; | ||
import com.espressif.idf.core.toolchain.ESPToolChainManager; | ||
import com.espressif.idf.core.util.StringUtil; | ||
import com.espressif.idf.ui.dialogs.BuildView; | ||
import com.espressif.idf.ui.dialogs.MessageLinkDialog; | ||
import com.espressif.idf.ui.update.ExportIDFTools; | ||
import com.espressif.idf.ui.update.InstallToolsHandler; | ||
|
@@ -46,6 +51,8 @@ | |
public class InitializeToolsStartup implements IStartup | ||
{ | ||
|
||
private static final String BUILDHINTS_ID = "com.espressif.idf.ui.views.buildhints"; //$NON-NLS-1$ | ||
|
||
Comment on lines
+54
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The constant |
||
/** | ||
* esp-idf.json is file created by the installer | ||
*/ | ||
|
@@ -65,24 +72,18 @@ | |
@Override | ||
public void earlyStartup() | ||
{ | ||
OpenDialogListenerSupport.getSupport().addPropertyChangeListener(new PropertyChangeListener() | ||
{ | ||
|
||
@Override | ||
public void propertyChange(PropertyChangeEvent evt) | ||
OpenDialogListenerSupport.getSupport().addPropertyChangeListener(evt -> { | ||
PopupDialog popupDialog = PopupDialog.valueOf(evt.getPropertyName()); | ||
switch (popupDialog) | ||
{ | ||
Display.getDefault().asyncExec(new Runnable() | ||
{ | ||
@Override | ||
public void run() | ||
{ | ||
MessageLinkDialog.openWarning(Display.getDefault().getActiveShell(), | ||
Messages.IncreasePartitionSizeTitle, | ||
MessageFormat.format(Messages.IncreasePartitionSizeMessage, evt.getNewValue(), | ||
evt.getOldValue(), DOC_URL)); | ||
} | ||
}); | ||
|
||
case LOW_PARTITION_SIZE: | ||
openLowPartitionSizeDialog(evt); | ||
break; | ||
case AVAILABLE_HINTS: | ||
openAvailableHintsDialog(evt); | ||
break; | ||
default: | ||
break; | ||
} | ||
}); | ||
ILaunchBarListener launchBarListener = new LaunchBarListener(); | ||
|
@@ -141,7 +142,7 @@ | |
JSONParser parser = new JSONParser(); | ||
try | ||
{ | ||
JSONObject jsonObj = (JSONObject) parser.parse(new FileReader(idf_json_file)); | ||
Check warning on line 145 in bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/InitializeToolsStartup.java GitHub Actions / spotbugsDM_DEFAULT_ENCODING
Raw output
Check warning on line 145 in bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/InitializeToolsStartup.java GitHub Actions / spotbugsOBL_UNSATISFIED_OBLIGATION
Raw output
|
||
String gitExecutablePath = (String) jsonObj.get(GIT_PATH); | ||
String idfVersionId = (String) jsonObj.get(IDF_VERSIONS_ID); | ||
JSONObject list = (JSONObject) jsonObj.get(IDF_INSTALLED_LIST_KEY); | ||
|
@@ -197,13 +198,59 @@ | |
Logger.log(e); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private void openAvailableHintsDialog(PropertyChangeEvent evt) | ||
{ | ||
Display.getDefault().asyncExec(() -> | ||
{ | ||
List<ReHintPair> erroHintPairs = (List<ReHintPair>) evt.getNewValue(); | ||
// if list is empty we don't want to change focus from the console output | ||
if (erroHintPairs.isEmpty()) | ||
{ | ||
updateValuesInBuildView(erroHintPairs); | ||
return; | ||
} | ||
try | ||
{ | ||
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() | ||
.showView(BUILDHINTS_ID); | ||
} | ||
catch (PartInitException e) | ||
{ | ||
Comment on lines
+219
to
+220
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exception logging is good, but it might be more helpful to provide some context or additional information about what operation was being attempted when the exception occurred. This can make debugging easier if an error occurs. |
||
Logger.log(e); | ||
} | ||
updateValuesInBuildView(erroHintPairs); | ||
} | ||
); | ||
|
||
} | ||
Comment on lines
+202
to
+227
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method opens a dialog with available hints. However, it seems like it's doing more than just opening a dialog. It's also updating the values in the BuildView. Consider renaming this method to better reflect its functionality or splitting it into two methods: one for opening the dialog and another for updating the BuildView. |
||
|
||
private void updateValuesInBuildView(List<ReHintPair> erroHintPairs) | ||
{ | ||
BuildView view = ((BuildView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() | ||
.findView(BUILDHINTS_ID)); | ||
if (view != null) | ||
{ | ||
view.updateReHintsPairs(erroHintPairs); | ||
} | ||
} | ||
Comment on lines
+229
to
+237
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method updates the values in the BuildView. However, it doesn't check whether the + if (erroHintPairs == null) {
+ throw new IllegalArgumentException("erroHintPairs cannot be null");
+ } |
||
|
||
private void openLowPartitionSizeDialog(PropertyChangeEvent evt) | ||
{ | ||
Display.getDefault().asyncExec(() -> | ||
MessageLinkDialog.openWarning(Display.getDefault().getActiveShell(), | ||
Messages.IncreasePartitionSizeTitle, MessageFormat.format(Messages.IncreasePartitionSizeMessage, | ||
evt.getNewValue(), evt.getOldValue(), DOC_URL)) | ||
); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private void updateEspIdfJsonFile(File idf_json_file, String newIdfPathToUpdate) | ||
{ | ||
JSONParser parser = new JSONParser(); | ||
JSONObject jsonObj = null; | ||
try (FileReader reader = new FileReader(idf_json_file)) | ||
Check warning on line 253 in bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/InitializeToolsStartup.java GitHub Actions / spotbugsDM_DEFAULT_ENCODING
Raw output
|
||
{ | ||
jsonObj = (JSONObject) parser.parse(reader); | ||
String idfVersionId = (String) jsonObj.get(IDF_VERSIONS_ID); | ||
|
@@ -227,7 +274,7 @@ | |
|
||
if (jsonObj != null) | ||
{ | ||
try (FileWriter fileWriter = new FileWriter(idf_json_file)) | ||
Check warning on line 277 in bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/InitializeToolsStartup.java GitHub Actions / spotbugsDM_DEFAULT_ENCODING
Raw output
|
||
{ | ||
fileWriter.write(jsonObj.toJSONString()); | ||
fileWriter.flush(); | ||
|
@@ -245,7 +292,7 @@ | |
{ | ||
// read esp-idf.json file | ||
JSONParser parser = new JSONParser(); | ||
try (FileReader reader = new FileReader(idf_json_file)) | ||
Check warning on line 295 in bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/InitializeToolsStartup.java GitHub Actions / spotbugsDM_DEFAULT_ENCODING
Raw output
|
||
{ | ||
JSONObject jsonObj = (JSONObject) parser.parse(reader); | ||
String idfVersionId = (String) jsonObj.get(IDF_VERSIONS_ID); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor
EspIdfErrorParser(List<ReHintPair> reHintPairs)
does not check if the passed listreHintPairs
is null. This can lead to a NullPointerException in theprocessLine
method when it tries to iterate overreHintsList
. It's a good practice to validate constructor parameters to avoid potential runtime exceptions.