diff --git a/bundles/com.espressif.idf.swt.custom/.gitignore b/bundles/com.espressif.idf.swt.custom/.gitignore new file mode 100644 index 000000000..ae3c17260 --- /dev/null +++ b/bundles/com.espressif.idf.swt.custom/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/IDFDownloadPage.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/IDFDownloadPage.java index a6bf8b5f4..085580162 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/IDFDownloadPage.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/IDFDownloadPage.java @@ -8,15 +8,19 @@ import java.net.MalformedURLException; import java.net.URL; import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; 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.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; @@ -29,7 +33,6 @@ import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.DirectoryDialog; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; @@ -38,9 +41,13 @@ import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; +import com.espressif.idf.core.IDFConstants; +import com.espressif.idf.core.IDFCorePlugin; import com.espressif.idf.core.IDFVersion; import com.espressif.idf.core.IDFVersionsReader; +import com.espressif.idf.core.ProcessBuilderFactory; import com.espressif.idf.core.SystemExecutableFinder; +import com.espressif.idf.core.logging.Logger; import com.espressif.idf.core.util.IDFUtil; import com.espressif.idf.core.util.StringUtil; import com.espressif.idf.ui.UIPlugin; @@ -105,6 +112,14 @@ public void createControl(Composite parent) GridData gridData = new GridData(SWT.NONE, SWT.NONE, false, false, 2, 1); gridData.widthHint = 250; versionCombo.setLayoutData(gridData); + versionCombo.addSelectionListener(new SelectionAdapter() + { + @Override + public void widgetSelected(SelectionEvent e) + { + validate(); + } + }); versionsMap = new IDFVersionsReader().getVersionsMap(); Set keySet = versionsMap.keySet(); @@ -388,18 +403,30 @@ private void validate() setPageComplete(false); return; } - if (idfPath.contains(" ")) //$NON-NLS-1$ + + String version = getIdfVersionUsingGit(idfPath); + + if (idfPath.contains(" ") && !StringUtil.isEmpty(version)) //$NON-NLS-1$ { - setErrorMessage(Messages.IDFDownloadPage_IDFBuildNotSupported); - setPageComplete(false); - showMessage(); - return; + boolean validVersion = isVersionGreaterOrEqual(version, "5.0.0"); //$NON-NLS-1$ + if (!validVersion) + { + setErrorMessage(Messages.IDFDownloadPage_VersionSpaceError); + setPageComplete(false); + return; + } + if (getErrorMessage() == null || getErrorMessage().equals(Messages.IDFDownloadPage_VersionSpaceError)) + { + setErrorMessage(null); + setPageComplete(true); + } } - String idfPyPath = idfPath + File.separator + "tools" + File.separator + "idf.py"; //$NON-NLS-1$ //$NON-NLS-2$ - if (!new File (idfPyPath).exists()) + String idfPyPath = idfPath + File.separator + IDFConstants.TOOLS_FOLDER + File.separator + IDFConstants.IDF_PYTHON_SCRIPT; + String idfToolsPyPth = idfPath + File.separator + IDFConstants.TOOLS_FOLDER + File.separator + IDFConstants.IDF_TOOLS_SCRIPT; + if (!new File (idfPyPath).exists() || !new File (idfToolsPyPth).exists()) { - setErrorMessage(MessageFormat.format(Messages.IDFDownloadPage_CantfindIDFpy, idfPath)); + setErrorMessage(MessageFormat.format(Messages.IDFDownloadPage_CantfindProperEspIDFDirectory, idfPath)); setPageComplete(false); return; } @@ -437,7 +464,7 @@ private void validate() if (!supportSpaces && directoryTxt.getText().contains(" ")) //$NON-NLS-1$ { - setErrorMessage(Messages.IDFDownloadPage_IDFBuildNotSupported); + setErrorMessage(Messages.IDFDownloadPage_VersionSpaceError); setPageComplete(false); return; } @@ -455,6 +482,96 @@ private void validate() } } + private String getIdfVersionUsingGit(String idfPath) + { + if (!validateGitAndPython()) + return StringUtil.EMPTY; + + List commands = new ArrayList(); + commands.add(gitExecutablePath); + commands.add("describe"); //$NON-NLS-1$ + + ProcessBuilderFactory processRunner = new ProcessBuilderFactory(); + try + { + Logger.log("Executing commads: " + commands.toString()); + Map environment = new HashMap<>(System.getenv()); + IStatus status = processRunner.runInBackground(commands, Path.fromOSString(idfPath), environment); + if (status == null) + { + Logger.log(IDFCorePlugin.getPlugin(), + IDFCorePlugin.errorStatus("Unable to get the process status.", null)); //$NON-NLS-1$ + return StringUtil.EMPTY; + } + String cmdOutput = status.getMessage(); + String version = StringUtil.EMPTY; + String patternString = "\\d+\\.\\d+\\.\\d+"; //$NON-NLS-1$ + Pattern pattern = Pattern.compile(patternString); + Matcher matcher = pattern.matcher(cmdOutput); + if (matcher.find()) + { + version = matcher.group(0); + } + + if(StringUtil.isEmpty(version)) + { + return StringUtil.EMPTY; + } + + return version; + } + catch (Exception e) + { + Logger.log(e); + } + + return StringUtil.EMPTY; + } + + private boolean isVersionGreaterOrEqual(String version, String minVersion) + { + // Define the regex pattern to match version numbers + String pattern = "\\d+\\.\\d+\\.\\d+"; //$NON-NLS-1$ + Pattern r = Pattern.compile(pattern); + + // Now create matcher object. + Matcher m = r.matcher(version); + Matcher mMin = r.matcher(minVersion); + + if (m.find() && mMin.find()) + { + String[] currentVersionParts = m.group(0).split("\\."); //$NON-NLS-1$ + String[] minVersionParts = mMin.group(0).split("\\."); //$NON-NLS-1$ + + int currentMajor = Integer.parseInt(currentVersionParts[0]); + int currentMinor = Integer.parseInt(currentVersionParts[1]); + int currentPatch = Integer.parseInt(currentVersionParts[2]); + + int minMajor = Integer.parseInt(minVersionParts[0]); + int minMinor = Integer.parseInt(minVersionParts[1]); + int minPatch = Integer.parseInt(minVersionParts[2]); + + if (currentMajor > minMajor) + { + return true; + } + else if (currentMajor == minMajor) + { + if (currentMinor > minMinor) + { + return true; + } + else if (currentMinor == minMinor) + { + return currentPatch >= minPatch; + } + } + } + + return false; + } + + protected IDFVersion Version() { String versionTxt = versionCombo.getText(); @@ -476,24 +593,6 @@ public boolean isConfigureExistingEnabled() { return fileSystemBtn.getSelection(); } - - private void showMessage() - { - Display.getDefault().asyncExec(new Runnable() - { - - @Override - public void run() { - boolean allowToCreateProjectWithSpaces = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.IDFDownloadWizard_AllowSpacesTitle, - Messages.IDFDownloadWizard_AllowSpacesMsg); - - if (allowToCreateProjectWithSpaces) { - setErrorMessage(null); - setPageComplete(true); - } - } - }); - } public String getPythonExePath() { diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/Messages.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/Messages.java index a07a585b4..cc53e5c79 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/Messages.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/Messages.java @@ -9,7 +9,7 @@ public class Messages extends NLS public static String IDFDownloadPage_0; public static String IDFDownloadPage_BrowseBtn; public static String IDFDownloadPage_BrowseBtnTxt; - public static String IDFDownloadPage_CantfindIDFpy; + public static String IDFDownloadPage_CantfindProperEspIDFDirectory; public static String IDFDownloadPage_CantFindRequirementsFile; public static String IDFDownloadPage_ChooseAnExistingIDF; public static String IDFDownloadPage_ChooseDirIDF; @@ -22,6 +22,7 @@ public class Messages extends NLS public static String IDFDownloadPage_DirectoryDialogMsg; public static String IDFDownloadPage_DirectoryDialogText; public static String IDFDownloadPage_DirectoryDialogTxt; + public static String IDFDownloadPage_VersionSpaceError; public static String IDFDownloadPage_DownloadIDF; public static String IDFDownloadPage_IDFBuildNotSupported; public static String IDFDownloadPage_Note; diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/messages.properties b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/messages.properties index 5e07c8f83..071dc26af 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/messages.properties +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/messages.properties @@ -2,7 +2,7 @@ GitRepositoryBuilder_gitClone=git clone result: %s IDFDownloadPage_0=icons/espressif_logo.png IDFDownloadPage_BrowseBtn=Browse... IDFDownloadPage_BrowseBtnTxt=Browse... -IDFDownloadPage_CantfindIDFpy=Can not find idf.py in {0} tools +IDFDownloadPage_CantfindProperEspIDFDirectory=Can not find idf python scripts in {0} tools. Make sure to select valid ESP-IDF directory. IDFDownloadPage_ChooseAnExistingIDF=Use an existing ESP-IDF directory from file system IDFDownloadPage_ChooseDirIDF=Choose existing ESP-IDF directory: IDFDownloadPage_ChooseIDFDir=Choose a directory to download ESP-IDF to: @@ -10,6 +10,7 @@ IDFDownloadPage_ChooseIDFVersion=Please choose ESP-IDF version to download: IDFDownloadPage_ClickFinishToDownload=Click on `Finish` to download IDFDownloadPage_ClickOnFinish=Click on `Finish` to configure IDF_PATH with IDFDownloadPage_DirDoesnotExist=Directory doesn''t exist: +IDFDownloadPage_VersionSpaceError=ESP-IDF build system support spaces in paths after v5.0. Please choose a different directory. IDFDownloadPage_DirectoryDialogMessage=Choose Directory to download ESP-IDF IDFDownloadPage_DirectoryDialogMsg=Select ESP-IDF Directory: IDFDownloadPage_DirectoryDialogText=Choose Directory diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsJob.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsJob.java index 98c285809..e47e0cffa 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsJob.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsJob.java @@ -107,31 +107,24 @@ protected void processExportCmdOutput(final String exportCmdOp) } - idfToolSet.getEnvVars().put(IDFEnvironmentVariables.IDF_COMPONENT_MANAGER, "1"); + idfToolSet.getEnvVars().put(IDFEnvironmentVariables.IDF_COMPONENT_MANAGER, "1"); //$NON-NLS-1$ // IDF_MAINTAINER=1 to be able to build with the clang toolchain - idfToolSet.getEnvVars().put(IDFEnvironmentVariables.IDF_MAINTAINER, "1"); + idfToolSet.getEnvVars().put(IDFEnvironmentVariables.IDF_MAINTAINER, "1"); //$NON-NLS-1$ if (!StringUtil.isEmpty(idfPath)) { idfToolSet.getEnvVars().put(IDFEnvironmentVariables.IDF_PATH, idfPath); idfToolSet.setIdfLocation(idfPath); } - if (StringUtil.isEmpty(idfToolSet.getEnvVars().get(IDFEnvironmentVariables.ESP_IDF_VERSION))) + IStatus status = getIdfVersionFromIdfPy(); + String cmdOutput = status.getMessage(); + Pattern pattern = Pattern.compile("v(\\d+\\.\\d+\\.\\d+)"); //$NON-NLS-1$ + Matcher matcher = pattern.matcher(cmdOutput.toLowerCase()); + if (matcher.find()) { - IStatus status = getIdfVersionFromIdfPy(); - String cmdOutput = status.getMessage(); - Pattern pattern = Pattern.compile("v(\\d+\\.\\d+\\.\\d+)"); - Matcher matcher = pattern.matcher(cmdOutput.toLowerCase()); - if (matcher.find()) - { - idfToolSet.setIdfVersion(matcher.group(1)); - } - idfToolSet.getEnvVars().put(IDFEnvironmentVariables.ESP_IDF_VERSION, idfToolSet.getIdfVersion()); - } - else - { - idfToolSet.setIdfVersion(idfToolSet.getEnvVars().get(IDFEnvironmentVariables.ESP_IDF_VERSION)); + idfToolSet.setIdfVersion(matcher.group(1)); } + idfToolSet.getEnvVars().put(IDFEnvironmentVariables.ESP_IDF_VERSION, idfToolSet.getIdfVersion()); } diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/manager/pages/ESPIDFMainTablePage.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/manager/pages/ESPIDFMainTablePage.java index 76bc486ac..0bfa5b5f0 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/manager/pages/ESPIDFMainTablePage.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/manager/pages/ESPIDFMainTablePage.java @@ -36,7 +36,6 @@ 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.LaunchBarListener; import com.espressif.idf.ui.UIPlugin; import com.espressif.idf.ui.install.IDFNewToolsWizard; import com.espressif.idf.ui.tools.Messages;