Skip to content

Commit

Permalink
updated code to avoid installing tools if the offline installer is used
Browse files Browse the repository at this point in the history
  • Loading branch information
alirana01 committed Aug 19, 2024
1 parent 8784a80 commit 8508a11
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import org.eclipse.cdt.cmake.core.internal.Activator;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.launchbar.core.ILaunchBarManager;
import org.eclipse.osgi.service.datalocation.Location;
Expand All @@ -35,21 +33,20 @@
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;

import com.espressif.idf.core.IDFCorePlugin;
import com.espressif.idf.core.IDFCorePreferenceConstants;
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.tools.ToolSetConfigurationManager;
import com.espressif.idf.core.tools.vo.IDFToolSet;
import com.espressif.idf.core.util.IDFUtil;
import com.espressif.idf.ui.dialogs.BuildView;
import com.espressif.idf.ui.dialogs.MessageLinkDialog;
import com.espressif.idf.ui.tools.ToolsActivationJob;
import com.espressif.idf.ui.tools.ToolsActivationJobListener;
import com.espressif.idf.ui.tools.ToolsInstallationJob;

@SuppressWarnings("restriction")
public class InitializeToolsStartup implements IStartup
Expand All @@ -64,6 +61,7 @@ public class InitializeToolsStartup implements IStartup

// Variables defined in the esp-idf.json file
private static final String GIT_PATH = "gitPath"; //$NON-NLS-1$
private static final String IDF_TOOLS_PATH_KEY = "idfToolsPath"; //$NON-NLS-1$
private static final String IDF_VERSIONS_ID = "idfSelectedId"; //$NON-NLS-1$
private static final String IDF_INSTALLED_LIST_KEY = "idfInstalled"; //$NON-NLS-1$
private static final String PYTHON_PATH = "python"; //$NON-NLS-1$
Expand Down Expand Up @@ -157,6 +155,7 @@ else if (isInstallerConfigSet())
{
JSONObject jsonObj = (JSONObject) parser.parse(new FileReader(idf_json_file));

Check warning on line 156 in bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/InitializeToolsStartup.java

View workflow job for this annotation

GitHub Actions / spotbugs

DM_DEFAULT_ENCODING

Found reliance on default encoding in com.espressif.idf.ui.InitializeToolsStartup.earlyStartup(): new java.io.FileReader(File)
Raw output
Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable. This will cause the application behavior to vary between platforms. Use an alternative API and specify a charset name or Charset object explicitly.

Check warning on line 156 in bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/InitializeToolsStartup.java

View workflow job for this annotation

GitHub Actions / spotbugs

OBL_UNSATISFIED_OBLIGATION

com.espressif.idf.ui.InitializeToolsStartup.earlyStartup() may fail to clean up java.io.Reader
Raw output
This method may fail to clean up (close, dispose of) a stream, database object, or other resource requiring an explicit cleanup operation.

In general, if a method opens a stream or other resource, the method should use a try/finally block to ensure that the stream or resource is cleaned up before the method returns.

This bug pattern is essentially the same as the OS_OPEN_STREAM and ODR_OPEN_DATABASE_RESOURCE bug patterns, but is based on a different (and hopefully better) static analysis technique. We are interested is getting feedback about the usefulness of this bug pattern. For sending feedback, check:

 * contributing guideline [https://github.com/spotbugs/spotbugs/blob/master/.github/CONTRIBUTING.md]
 * mailinglist [https://github.com/spotbugs/discuss/issues?q=]

In particular, the false-positive suppression heuristics for this bug pattern have not been extensively tuned, so reports about false positives are helpful to us.

See Weimer and Necula, Finding and Preventing Run-Time Error Handling Mistakes (PDF [https://people.eecs.berkeley.edu/~necula/Papers/rte_oopsla04.pdf]), for a description of the analysis technique.
String gitExecutablePath = (String) jsonObj.get(GIT_PATH);
String idfToolsPath = (String) jsonObj.get(IDF_TOOLS_PATH_KEY);
String idfVersionId = (String) jsonObj.get(IDF_VERSIONS_ID);
JSONObject list = (JSONObject) jsonObj.get(IDF_INSTALLED_LIST_KEY);
if (list != null)
Expand All @@ -165,12 +164,24 @@ else if (isInstallerConfigSet())
JSONObject selectedIDFInfo = (JSONObject) list.get(idfVersionId);
String idfPath = (String) selectedIDFInfo.get(IDF_PATH);
String pythonExecutablePath = (String) selectedIDFInfo.get(PYTHON_PATH);
ToolsInstallationJob toolsInstallationJob = new ToolsInstallationJob(pythonExecutablePath,
gitExecutablePath, idfPath);
ToolsInstallationJobChangeListener toolsInstallationJobChangeListener = new ToolsInstallationJobChangeListener(
gitExecutablePath, pythonExecutablePath, idfPath);
toolsInstallationJob.addJobChangeListener(toolsInstallationJobChangeListener);
toolsInstallationJob.schedule();
IDFToolSet newToolSet = new IDFToolSet();
newToolSet.setIdfLocation(idfPath);
newToolSet.setSystemGitExecutablePath(gitExecutablePath);
newToolSet.setSystemPythonExecutablePath(pythonExecutablePath);
newToolSet.setActive(true);
Preferences prefs = InstanceScope.INSTANCE.getNode(IDFCorePlugin.PLUGIN_ID);
prefs.put(IDFCorePreferenceConstants.IDF_TOOLS_PATH, idfToolsPath);
try
{
prefs.flush();
}
catch (BackingStoreException e)
{
Logger.log(e);
}
ToolsActivationJob toolsActivationJob = new ToolsActivationJob(newToolSet, pythonExecutablePath, gitExecutablePath);
toolsActivationJob.schedule();

}

// save state
Expand Down Expand Up @@ -341,38 +352,4 @@ private boolean isInstallerConfigSet()
{
return getPreferences().getBoolean(IS_INSTALLER_CONFIG_SET, false);
}

private class ToolsInstallationJobChangeListener extends JobChangeAdapter
{
private String gitExecutablePath;
private String pythonExecutablePath;
private String idfPath;
private ToolsInstallationJobChangeListener(String gitExecutablePath, String pythonExecutablePath, String idfPath)
{
this.gitExecutablePath = gitExecutablePath;
this.pythonExecutablePath = pythonExecutablePath;
this.idfPath = idfPath;
}

@Override
public void done(IJobChangeEvent event)
{
ToolSetConfigurationManager toolSetConfigurationManager = new ToolSetConfigurationManager();
List<IDFToolSet> idfToolSets = toolSetConfigurationManager.getIdfToolSets(false);
IDFToolSet idfToolSetToUse = null;
for (IDFToolSet idfToolSet : idfToolSets)
{
if (idfToolSet.getIdfLocation().equals(idfPath))
{
idfToolSetToUse = idfToolSet;
break;
}
}

ToolsActivationJob toolsActivationJob = new ToolsActivationJob(idfToolSetToUse, pythonExecutablePath, gitExecutablePath);
ToolsActivationJobListener toolsActivationJobListener = new ToolsActivationJobListener();
toolsActivationJob.addJobChangeListener(toolsActivationJobListener);
toolsActivationJob.schedule();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.console.MessageConsoleStream;

import com.espressif.idf.core.IDFConstants;
import com.espressif.idf.core.IDFCorePlugin;
import com.espressif.idf.core.IDFCorePreferenceConstants;
import com.espressif.idf.core.IDFEnvironmentVariables;
import com.espressif.idf.core.ProcessBuilderFactory;
import com.espressif.idf.core.logging.Logger;
Expand Down

0 comments on commit 8508a11

Please sign in to comment.