diff --git a/bundles/.settings/org.eclipse.m2e.core.prefs b/bundles/.settings/org.eclipse.m2e.core.prefs deleted file mode 100644 index f897a7f1c..000000000 --- a/bundles/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 diff --git a/bundles/com.espressif.idf.core/OSGI-INF/l10n/bundle.properties b/bundles/com.espressif.idf.core/OSGI-INF/l10n/bundle.properties index 990c9491c..892587cea 100644 --- a/bundles/com.espressif.idf.core/OSGI-INF/l10n/bundle.properties +++ b/bundles/com.espressif.idf.core/OSGI-INF/l10n/bundle.properties @@ -3,4 +3,7 @@ Bundle-Vendor = ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD Bundle-Name = ESP-IDF Core openocd_bin_path = path to openocd bin folder specified in Espressif -> Global OpenOCD path openocd_exe = openocd executable file -openocd_scripts = OPENOCD_SCRIPTS represents the value specified in environment variables \ No newline at end of file +openocd_scripts = OPENOCD_SCRIPTS represents the value specified in environment variables +jtag_flash_args = JTAG_FLASH_ARGS dynamically converts ${JTAG_FLASH_ARGS} into a command line with -c and -f options. These options are generated based on the current launch target, configuring settings like flash voltage and specifying configuration files for the JTAG interface and target device. +gdb_client_executable = GDB_CLIENT_EXECUTABLE is a dynamic variable that is replaced during the debug session with the appropriate toolchain path automatically based on the selected target. +serial_port = serial_port is a dynamic variable that is replaced by the serial port specified in the launch target diff --git a/bundles/com.espressif.idf.core/plugin.xml b/bundles/com.espressif.idf.core/plugin.xml index e72984e9c..015375aec 100644 --- a/bundles/com.espressif.idf.core/plugin.xml +++ b/bundles/com.espressif.idf.core/plugin.xml @@ -318,7 +318,7 @@ config-only component and an interface library is created instead." + + + + + + diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/DefaultBoardProvider.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/DefaultBoardProvider.java index dde824b5f..407bde16c 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/DefaultBoardProvider.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/DefaultBoardProvider.java @@ -8,6 +8,7 @@ import java.util.stream.IntStream; import java.util.stream.Stream; +import com.espressif.idf.core.util.EspConfigParser; import com.espressif.idf.core.util.StringUtil; public class DefaultBoardProvider @@ -15,6 +16,7 @@ public class DefaultBoardProvider private static final int DEFAULT_BOARD_EMPTY_INDEX = 0; private static final String ESP32C3_DEFAULT_BOARD = "ESP32-C3 chip (via builtin USB-JTAG)"; //$NON-NLS-1$ private static final String ESP32S3_DEFAULT_BOARD = "ESP32-S3 chip (via builtin USB-JTAG)"; //$NON-NLS-1$ + private EspConfigParser espConfigParser; private enum EspTarget { @@ -34,7 +36,12 @@ public static EspTarget enumOf(String value) } } - + + public DefaultBoardProvider() + { + this.espConfigParser = new EspConfigParser(); + } + public int getIndexOfDefaultBoard(String targetName, String[] boardsForTarget) { String defaultBoard = EspTarget.enumOf(targetName).board; @@ -45,4 +52,11 @@ public int getIndexOfDefaultBoard(String targetName, String[] boardsForTarget) return index.orElse(DEFAULT_BOARD_EMPTY_INDEX); } + public String getDefaultBoard(String targetName) + { + var boardConfigMap = this.espConfigParser.getBoardsConfigs(targetName); + var boards = boardConfigMap.keySet().toArray(new String[0]); + return boards[getIndexOfDefaultBoard(targetName, boards)]; + } + } diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/LaunchBarTargetConstants.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/LaunchBarTargetConstants.java new file mode 100644 index 000000000..b5743ce0f --- /dev/null +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/LaunchBarTargetConstants.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved. + * Use is subject to license terms. + *******************************************************************************/ +package com.espressif.idf.core; + +/** + * This class defines constants used to access attributes in the launch bar target. These constants are used to uniquely + * identify settings such as the board, flash voltage, serial port, and target within the launch configuration. + */ +public final class LaunchBarTargetConstants +{ + public static final String PREFIX = "com.espressif.idf.launch.serial.core"; //$NON-NLS-1$ + public static final String BOARD = PREFIX + ".board"; //$NON-NLS-1$ + public static final String FLASH_VOLTAGE = PREFIX + ".flash_voltage"; //$NON-NLS-1$ + public static final String SERIAL_PORT = PREFIX + ".serialPort"; //$NON-NLS-1$ + public static final String TARGET = PREFIX + ".idfTarget"; //$NON-NLS-1$ + + private LaunchBarTargetConstants() + { + } +} diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java index c3bc2b7d0..2bb4fad5d 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java @@ -81,6 +81,7 @@ import com.espressif.idf.core.IDFCorePlugin; import com.espressif.idf.core.IDFCorePreferenceConstants; import com.espressif.idf.core.IDFEnvironmentVariables; +import com.espressif.idf.core.LaunchBarTargetConstants; import com.espressif.idf.core.internal.CMakeConsoleWrapper; import com.espressif.idf.core.internal.CMakeErrorParser; import com.espressif.idf.core.logging.Logger; @@ -515,7 +516,7 @@ private void runCmakeCommand(IConsole console, IProgressMonitor monitor, IProjec if (launchtarget != null) { - String idfTargetName = launchtarget.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY); + String idfTargetName = launchtarget.getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY); if (!idfTargetName.isEmpty()) { command.add("-DIDF_TARGET=" + idfTargetName); //$NON-NLS-1$ @@ -651,7 +652,7 @@ public IToolChain getToolChain() throws CoreException ILaunchBarManager launchBarManager = CCorePlugin.getService(ILaunchBarManager.class); Collection matchedToolChains = toolChainManager .getToolChainsMatching(Map.of(IToolChain.ATTR_OS, launchBarManager.getActiveLaunchTarget() - .getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY), TOOLCHAIN_TYPE, typeId)); + .getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY), TOOLCHAIN_TYPE, typeId)); return matchedToolChains.stream().findAny().orElse(toolChainManager.getToolChain(typeId, id)); } diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFLaunchConstants.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFLaunchConstants.java index b4567f210..fc6d15961 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFLaunchConstants.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFLaunchConstants.java @@ -3,7 +3,6 @@ public final class IDFLaunchConstants { public static final String ESP_LAUNCH_TARGET_TYPE = "com.espressif.idf.launch.serial.core.serialFlashTarget"; //$NON-NLS-1$ - public static final String ATTR_IDF_TARGET = "com.espressif.idf.launch.serial.core.idfTarget"; //$NON-NLS-1$ public static final String DEBUG_LAUNCH_CONFIG_TYPE = "com.espressif.idf.debug.gdbjtag.openocd.launchConfigurationType"; //$NON-NLS-1$ public static final String RUN_LAUNCH_CONFIG_TYPE = "com.espressif.idf.launch.serial.launchConfigurationType"; //$NON-NLS-1$ public static final String FLASH_OVER_JTAG = "FLASH_OVER_JTAG"; //$NON-NLS-1$ @@ -15,7 +14,6 @@ public final class IDFLaunchConstants public static final String ATTR_DFU_FLASH_ARGUMENTS = "com.espressif.idf.launch.serial.core.dfuFlashArguments"; //$NON-NLS-1$ public static final String ATTR_JTAG_FLASH_ARGUMENTS = "com.espressif.idf.debug.gdbjtag.openocd.jtagFlashArguments"; //$NON-NLS-1$ public static final String ATTR_LAUNCH_CONFIGURATION_NAME = "com.espressif.idf.debug.gdbjtag.openocd.launchConfigurationName"; //$NON-NLS-1$ - public static final String ATTR_SERIAL_PORT = "com.espressif.idf.launch.serial.core.serialPort"; //$NON-NLS-1$ public static final String IDF_TARGET_TYPE = "com.espressif.idf.launch.serial.core.serialFlashTarget"; //$NON-NLS-1$ public static final String OPEN_SERIAL_MONITOR = "OPEN_SERIAL_MONITOR"; //$NON-NLS-1$ public static final String SERIAL_MONITOR_ENCODING = "SERIAL_MONITOR_ENCODING"; //$NON-NLS-1$ diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/toolchain/ESPToolChainManager.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/toolchain/ESPToolChainManager.java index 4e6668a06..f0717c527 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/toolchain/ESPToolChainManager.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/toolchain/ESPToolChainManager.java @@ -25,7 +25,6 @@ import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; import org.eclipse.cdt.cmake.core.ICMakeToolChainFile; import org.eclipse.cdt.cmake.core.ICMakeToolChainManager; @@ -43,9 +42,11 @@ import org.eclipse.launchbar.core.target.ILaunchTargetManager; import org.eclipse.launchbar.core.target.ILaunchTargetWorkingCopy; +import com.espressif.idf.core.DefaultBoardProvider; import com.espressif.idf.core.IDFConstants; import com.espressif.idf.core.IDFCorePlugin; import com.espressif.idf.core.IDFEnvironmentVariables; +import com.espressif.idf.core.LaunchBarTargetConstants; import com.espressif.idf.core.ProcessBuilderFactory; import com.espressif.idf.core.build.IDFLaunchConstants; import com.espressif.idf.core.build.Messages; @@ -109,7 +110,7 @@ public void initToolChain(IToolChainManager manager, String toolchainId) Logger.log(e); } } - + /** * @param manager * @param toolchainProvider @@ -244,7 +245,7 @@ private void removeMatchedToolChain(IToolChainManager manager, ESPToolChainEleme props.put(TOOLCHAIN_ATTR_ID, toolChainElement.fileName); try { - manager.getToolChainsMatching(props).forEach(toolchain -> manager.removeToolChain(toolchain)); + manager.getToolChainsMatching(props).forEach(manager::removeToolChain); } catch (CoreException e) { @@ -414,7 +415,7 @@ public List getAvailableEspTargetList() { targetSet.add(toolchain.getProperty(IToolChain.ATTR_OS)); } - return targetSet.stream().collect(Collectors.toList()); + return targetSet.stream().toList(); } public Collection getAllEspToolchains() @@ -430,14 +431,14 @@ public Collection getAllEspToolchains() Logger.log(e); } return toolchains.stream().filter(tc -> tc.getProperty(IToolChain.ATTR_OS).contains("esp")) //$NON-NLS-1$ - .collect(Collectors.toList()); + .toList(); } public void addToolchainBasedTargets(ILaunchTargetManager targetManager) { Collection toolchainsWithoutDuplicateTargets = getAllEspToolchains().stream() - .filter(distinctByOs(tc -> tc.getProperty(IToolChain.ATTR_OS))).collect(Collectors.toList()); + .filter(distinctByOs(tc -> tc.getProperty(IToolChain.ATTR_OS))).toList(); try { @@ -448,11 +449,11 @@ public void addToolchainBasedTargets(ILaunchTargetManager targetManager) Logger.log(e); } } - + public void addToolchainBasedTargets(ILaunchTargetManager targetManager, List targets) { Collection toolchainsWithoutDuplicateTargets = getAllEspToolchains().stream() - .filter(distinctByOs(tc -> tc.getProperty(IToolChain.ATTR_OS))).collect(Collectors.toList()); + .filter(distinctByOs(tc -> tc.getProperty(IToolChain.ATTR_OS))).toList(); try { @@ -485,26 +486,29 @@ private void addLaunchTargets(ILaunchTargetManager targetManager, ILaunchTargetWorkingCopy wc = target.getWorkingCopy(); wc.setAttribute(ILaunchTarget.ATTR_OS, os); wc.setAttribute(ILaunchTarget.ATTR_ARCH, arch); - wc.setAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, os); + wc.setAttribute(LaunchBarTargetConstants.TARGET, os); + wc.setAttribute(LaunchBarTargetConstants.FLASH_VOLTAGE, "default"); //$NON-NLS-1$ + wc.setAttribute(LaunchBarTargetConstants.BOARD, new DefaultBoardProvider().getDefaultBoard(os)); wc.save(); } } - + addLaunchTargets(targetManager, toolchainsWithoutDuplicateTargets, null); } - + private void addLaunchTargets(ILaunchTargetManager targetManager, - Collection toolchainsWithoutDuplicateTargets, List targets) throws SecurityException, IllegalArgumentException + Collection toolchainsWithoutDuplicateTargets, List targets) + throws SecurityException, IllegalArgumentException { List toolChainsToRemove = null; List toolChainsToUse = null; if (targets != null) { toolChainsToRemove = toolchainsWithoutDuplicateTargets.stream() - .filter(tc -> !targets.contains(tc.getProperty(IToolChain.ATTR_OS))).collect(Collectors.toList()); + .filter(tc -> !targets.contains(tc.getProperty(IToolChain.ATTR_OS))).toList(); toolChainsToUse = toolchainsWithoutDuplicateTargets.stream() - .filter(tc -> targets.contains(tc.getProperty(IToolChain.ATTR_OS))).collect(Collectors.toList()); - for(IToolChain toolChain : toolChainsToRemove) + .filter(tc -> targets.contains(tc.getProperty(IToolChain.ATTR_OS))).toList(); + for (IToolChain toolChain : toolChainsToRemove) { String os = toolChain.getProperty(IToolChain.ATTR_OS); ILaunchTarget target = targetManager.getLaunchTarget(IDFLaunchConstants.ESP_LAUNCH_TARGET_TYPE, os); @@ -514,11 +518,10 @@ private void addLaunchTargets(ILaunchTargetManager targetManager, } } } - else + else { - toolChainsToUse = toolchainsWithoutDuplicateTargets.stream().collect(Collectors.toList()); + toolChainsToUse = toolchainsWithoutDuplicateTargets.stream().toList(); } - for (IToolChain toolchain : toolChainsToUse) { @@ -530,7 +533,9 @@ private void addLaunchTargets(ILaunchTargetManager targetManager, ILaunchTargetWorkingCopy wc = target.getWorkingCopy(); wc.setAttribute(ILaunchTarget.ATTR_OS, os); wc.setAttribute(ILaunchTarget.ATTR_ARCH, arch); - wc.setAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, os); + wc.setAttribute(LaunchBarTargetConstants.TARGET, os); + wc.setAttribute(LaunchBarTargetConstants.FLASH_VOLTAGE, "default"); //$NON-NLS-1$ + wc.setAttribute(LaunchBarTargetConstants.BOARD, new DefaultBoardProvider().getDefaultBoard(os)); wc.save(); } } @@ -553,9 +558,10 @@ public void configureToolChain() initCMakeToolChain(cmakeTcManager); addToolchainBasedTargets(IDFCorePlugin.getService(ILaunchTargetManager.class)); } - + /** * Configure the file in the preferences and initialize the launch bar with available targets + * * @param targets The targets to filter from the given idf version */ public void configureToolChain(List targets) @@ -567,15 +573,14 @@ public void configureToolChain(List targets) initCMakeToolChain(cmakeTcManager); addToolchainBasedTargets(IDFCorePlugin.getService(ILaunchTargetManager.class), targets); } - - + /** * Removes all the launch targets */ public void removeLaunchTargetsNotPresent(List targetsToKeep) { ILaunchTargetManager targetManager = IDFCorePlugin.getService(ILaunchTargetManager.class); - ILaunchTarget [] launchTargets = targetManager.getLaunchTargets(); + ILaunchTarget[] launchTargets = targetManager.getLaunchTargets(); for (ILaunchTarget launchTarget : launchTargets) { if (!targetsToKeep.contains(launchTarget.getId())) @@ -584,30 +589,30 @@ public void removeLaunchTargetsNotPresent(List targetsToKeep) } } } - + /** * Removes all the cmake toolchains in the current environment */ public void removeCmakeToolChains() { ICMakeToolChainManager cmakeTcManager = CCorePlugin.getService(ICMakeToolChainManager.class); - - List cIcMakeToolChainFiles = new ArrayList(cmakeTcManager.getToolChainFiles()); + + List cIcMakeToolChainFiles = new ArrayList<>(cmakeTcManager.getToolChainFiles()); for (ICMakeToolChainFile cmakeToolchain : cIcMakeToolChainFiles) { cmakeTcManager.removeToolChainFile(cmakeToolchain); } } - + /** - * Removes all the gcc/std toolchains for ESP in current environment + * Removes all the gcc/std toolchains for ESP in current environment */ public void removeStdToolChains() { IToolChainManager tcManager = CCorePlugin.getService(IToolChainManager.class); try { - List espToolchains = new ArrayList(tcManager.getAllToolChains()); + List espToolchains = new ArrayList<>(tcManager.getAllToolChains()); for (IToolChain espToolChain : espToolchains) { if (!StringUtil.isEmpty(espToolChain.getTypeId())) @@ -621,37 +626,39 @@ public void removeStdToolChains() Logger.log(e); } } - + /** * Gets all the standard toolchains in the given path + * * @param path Path to look into for toolchains * @return - * @throws CoreException + * @throws CoreException */ public List getStdToolChains(List paths, String idfPath) throws CoreException { - List espToolchains = new ArrayList(); - + List espToolchains = new ArrayList<>(); + IToolChainManager manager = CCorePlugin.getService(IToolChainManager.class); IToolChainProvider toolchainProvider = manager.getProvider(ESPToolChainProvider.ID); - + for (ESPToolChainElement toolChainElement : toolchainElements.values()) { File toolchainCompilerFile = findToolChain(paths, toolChainElement.compilerPattern); Path toolChainCmakeFile = Paths.get(getIdfCMakePath(idfPath)).resolve(toolChainElement.fileName); if (toolchainCompilerFile != null && Files.exists(toolChainCmakeFile)) { - espToolchains.add(new ESPToolchain(toolchainProvider, toolchainCompilerFile.toPath(), toolChainElement)); + espToolchains + .add(new ESPToolchain(toolchainProvider, toolchainCompilerFile.toPath(), toolChainElement)); } } - + return espToolchains; } - - public List getCmakeToolChains(String idfPath) throws CoreException + + public List getCmakeToolChains(String idfPath) { - List espToolchains = new ArrayList(); + List espToolchains = new ArrayList<>(); ICMakeToolChainManager manager = CCorePlugin.getService(ICMakeToolChainManager.class); toolchainElements.values().stream().forEach(value -> { @@ -667,35 +674,8 @@ public List getCmakeToolChains(String idfPath) throws CoreE espToolchains.add(toolchainFile); } }); - - return espToolchains; - } - - public List getToolChainTargets(List espToolchains) - { - List launchTargets = new ArrayList(); - ILaunchTargetManager targetManager = IDFCorePlugin.getService(ILaunchTargetManager.class); - Collection toolchainsWithoutDuplicateTargets = espToolchains.stream() - .filter(distinctByOs(tc -> tc.getProperty(IToolChain.ATTR_OS))).collect(Collectors.toList()); - - for (IToolChain toolchain : toolchainsWithoutDuplicateTargets) - { - String os = toolchain.getProperty(IToolChain.ATTR_OS); - String arch = toolchain.getProperty(IToolChain.ATTR_ARCH); - if (targetManager.getLaunchTarget(IDFLaunchConstants.ESP_LAUNCH_TARGET_TYPE, os) == null) - { - ILaunchTarget target = targetManager.addLaunchTarget(IDFLaunchConstants.ESP_LAUNCH_TARGET_TYPE, os); - ILaunchTargetWorkingCopy wc = target.getWorkingCopy(); - wc.setAttribute(ILaunchTarget.ATTR_OS, os); - wc.setAttribute(ILaunchTarget.ATTR_ARCH, arch); - wc.setAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, os); - wc.save(); - launchTargets.add(target); - } - } - - return launchTargets; + return espToolchains; } } diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/DfuCommandsUtil.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/DfuCommandsUtil.java index 8520abcca..42ddc6ae8 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/DfuCommandsUtil.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/DfuCommandsUtil.java @@ -28,6 +28,7 @@ import com.espressif.idf.core.IDFCorePlugin; import com.espressif.idf.core.IDFDynamicVariables; import com.espressif.idf.core.IDFEnvironmentVariables; +import com.espressif.idf.core.LaunchBarTargetConstants; import com.espressif.idf.core.build.IDFLaunchConstants; import com.espressif.idf.core.logging.Logger; @@ -38,6 +39,10 @@ public class DfuCommandsUtil private static final String[] SUPPORTED_TARGETS = { "esp32s2", "esp32s3" }; //$NON-NLS-1$ //$NON-NLS-2$ private static final String DFU_FLASH_COMMAND = "dfu-flash"; //$NON-NLS-1$ + private DfuCommandsUtil() + { + } + public static String[] getSupportedTargets() { return SUPPORTED_TARGETS; @@ -61,16 +66,11 @@ public static boolean isDfu() public static boolean isDfuSupported(ILaunchTarget launchTarget) { boolean isDfuSupported = isTargetSupportDfu(launchTarget); - Display.getDefault().asyncExec(new Runnable() - { - @Override - public void run() + Display.getDefault().asyncExec(() -> { + if (!isDfuSupported) { - if (!isDfuSupported) - { - MessageDialog.openWarning(getShell(), Messages.DfuWarningDialog_Title, - Messages.DfuWarningDialog_WrongTargterMsg); - } + MessageDialog.openWarning(getShell(), Messages.DfuWarningDialog_Title, + Messages.DfuWarningDialog_WrongTargterMsg); } }); return isDfuSupported; @@ -78,8 +78,7 @@ public void run() public static boolean isTargetSupportDfu(ILaunchTarget launchTarget) { - String targetName = launchTarget.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, - StringUtil.EMPTY); + String targetName = launchTarget.getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY); return Arrays.stream(SUPPORTED_TARGETS).anyMatch(target -> target.contentEquals(targetName)); } diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java index 8f43e142a..b1f26e3a7 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java @@ -43,9 +43,9 @@ import com.espressif.idf.core.IDFCorePlugin; import com.espressif.idf.core.IDFCorePreferenceConstants; import com.espressif.idf.core.IDFEnvironmentVariables; +import com.espressif.idf.core.LaunchBarTargetConstants; import com.espressif.idf.core.ProcessBuilderFactory; import com.espressif.idf.core.SystemExecutableFinder; -import com.espressif.idf.core.build.IDFLaunchConstants; import com.espressif.idf.core.logging.Logger; import com.espressif.idf.core.toolchain.ESPToolChainManager; @@ -375,7 +375,7 @@ public static String getToolchainExePathForActiveTarget() if (launchTarget != null) { File file = new ESPToolChainManager() - .findCompiler(launchTarget.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY)); + .findCompiler(launchTarget.getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY)); if (file != null) { return file.getAbsolutePath(); diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/LaunchTargetHelper.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/LaunchTargetHelper.java index 37d28e831..baea4f32c 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/LaunchTargetHelper.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/LaunchTargetHelper.java @@ -12,6 +12,7 @@ import org.eclipse.launchbar.core.target.ILaunchTarget; import org.eclipse.launchbar.core.target.ILaunchTargetManager; +import com.espressif.idf.core.LaunchBarTargetConstants; import com.espressif.idf.core.build.IDFLaunchConstants; import com.espressif.idf.core.logging.Logger; @@ -19,6 +20,10 @@ public class LaunchTargetHelper { private static String lastSavedTargetName; + private LaunchTargetHelper() + { + } + public static void saveTargetName(String targetName) { lastSavedTargetName = targetName; @@ -46,14 +51,14 @@ public static Optional findSuitableTargetForSelectedItem(ILaunchT Stream launchTargetStream = streamTargetsByName(selectedItem, targets); return launchTargetStream .filter(target -> suitableSerialPort - .equals(target.getAttribute(IDFLaunchConstants.ATTR_SERIAL_PORT, StringUtil.EMPTY))) + .equals(target.getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY))) .findFirst().or(() -> streamTargetsByName(selectedItem, targets).findFirst()); } private static Stream streamTargetsByName(String selectedItem, ILaunchTarget[] targets) { - return Stream.of(targets).filter(target -> selectedItem - .equals(target.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY))); + return Stream.of(targets).filter( + target -> selectedItem.equals(target.getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY))); } private static String getSerialPort(ILaunchBarManager launchBarManager) @@ -62,7 +67,7 @@ private static String getSerialPort(ILaunchBarManager launchBarManager) String serialPort = StringUtil.EMPTY; try { - serialPort = launchBarManager.getActiveLaunchTarget().getAttribute(IDFLaunchConstants.ATTR_SERIAL_PORT, + serialPort = launchBarManager.getActiveLaunchTarget().getAttribute(LaunchBarTargetConstants.SERIAL_PORT, StringUtil.EMPTY); } diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/GdbClientDynamicVariable.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/GdbClientDynamicVariable.java new file mode 100644 index 000000000..eece70588 --- /dev/null +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/GdbClientDynamicVariable.java @@ -0,0 +1,10 @@ +/******************************************************************************* + * Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved. + * Use is subject to license terms. + *******************************************************************************/ +package com.espressif.idf.core.variable; + +public enum GdbClientDynamicVariable +{ + GDB_CLIENT_EXECUTABLE +} diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/GdbClientVariableResolver.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/GdbClientVariableResolver.java new file mode 100644 index 000000000..2032967b7 --- /dev/null +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/GdbClientVariableResolver.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved. + * Use is subject to license terms. + *******************************************************************************/ +package com.espressif.idf.core.variable; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.variables.IDynamicVariable; +import org.eclipse.core.variables.IDynamicVariableResolver; +import org.eclipse.launchbar.core.ILaunchBarManager; + +import com.espressif.idf.core.IDFCorePlugin; +import com.espressif.idf.core.LaunchBarTargetConstants; +import com.espressif.idf.core.util.IDFUtil; +import com.espressif.idf.core.util.StringUtil; + +public class GdbClientVariableResolver implements IDynamicVariableResolver +{ + + public String resolveValue(IDynamicVariable variable, String argument) throws CoreException + { + ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class); + var targetName = launchBarManager.getActiveLaunchTarget().getAttribute(LaunchBarTargetConstants.TARGET, + StringUtil.EMPTY); + return IDFUtil.getXtensaToolchainExecutablePathByTarget(targetName); + } + +} diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/JtagDynamicVariable.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/JtagDynamicVariable.java new file mode 100644 index 000000000..aefaae4c6 --- /dev/null +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/JtagDynamicVariable.java @@ -0,0 +1,10 @@ +/******************************************************************************* + * Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved. + * Use is subject to license terms. + *******************************************************************************/ +package com.espressif.idf.core.variable; + +public enum JtagDynamicVariable +{ + JTAG_FLASH_ARGS +} diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/JtagVariableResolver.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/JtagVariableResolver.java new file mode 100644 index 000000000..e6fd907ce --- /dev/null +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/JtagVariableResolver.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved. + * Use is subject to license terms. + *******************************************************************************/ +package com.espressif.idf.core.variable; + +import java.util.Arrays; +import java.util.Optional; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.variables.IDynamicVariable; +import org.eclipse.core.variables.IDynamicVariableResolver; +import org.eclipse.launchbar.core.ILaunchBarManager; +import org.eclipse.launchbar.core.target.ILaunchTarget; + +import com.espressif.idf.core.DefaultBoardProvider; +import com.espressif.idf.core.IDFCorePlugin; +import com.espressif.idf.core.LaunchBarTargetConstants; +import com.espressif.idf.core.logging.Logger; +import com.espressif.idf.core.util.EspConfigParser; +import com.espressif.idf.core.util.StringUtil; + +public class JtagVariableResolver implements IDynamicVariableResolver +{ + + public String resolveValue(IDynamicVariable variable, String argument) + { + return getAppropriateEnumVariable(variable).map(this::resolveForDynamicEnum).orElse(variable.getName()); + } + + private Optional getAppropriateEnumVariable(IDynamicVariable variable) + { + return Arrays.stream(JtagDynamicVariable.values()).filter(v -> v.name().equals(variable.getName())).findFirst(); + } + + private String resolveForDynamicEnum(JtagDynamicVariable enumVariable) + { + + return switch (enumVariable) + { + case JTAG_FLASH_ARGS -> generatePartOfConfigOptionsForVoltage() + generatePartOfConfigOptionsForBoard(); // $NON-NLS-1$ + }; + } + + private Optional getActiveLaunchTarget() + { + try + { + return Optional.of(IDFCorePlugin.getService(ILaunchBarManager.class).getActiveLaunchTarget()); + } + catch (CoreException e) + { + Logger.log(e); + } + return Optional.empty(); + } + + private String generatePartOfConfigOptionsForVoltage() + { + ILaunchTarget activeILaunchTarget = getActiveLaunchTarget().orElseGet(() -> ILaunchTarget.NULL_TARGET); + var selectedVoltage = activeILaunchTarget.getAttribute(LaunchBarTargetConstants.FLASH_VOLTAGE, "default"); //$NON-NLS-1$ + return selectedVoltage.equals("default") ? StringUtil.EMPTY //$NON-NLS-1$ + : String.format("-c 'set ESP32_FLASH_VOLTAGE' %s' ", selectedVoltage); //$NON-NLS-1$ + + } + + private String generatePartOfConfigOptionsForBoard() + { + var parser = new EspConfigParser(); + ILaunchTarget activeILaunchTarget = getActiveLaunchTarget().orElseGet(() -> ILaunchTarget.NULL_TARGET); + var targetName = activeILaunchTarget.getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY); + var boardConfigMap = parser.getBoardsConfigs(targetName); + var board = activeILaunchTarget.getAttribute(LaunchBarTargetConstants.BOARD, + new DefaultBoardProvider().getDefaultBoard(targetName)); + var boardConfigs = boardConfigMap.get(board); + var result = new StringBuilder(); + for (Object config : boardConfigs) + { + result.append(String.format("-f %s ", config)); //$NON-NLS-1$ + } + return result.toString(); + } + +} diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/OpenocdDynamicVariable.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/OpenocdDynamicVariable.java index bb223376e..b713ad25c 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/OpenocdDynamicVariable.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/OpenocdDynamicVariable.java @@ -6,7 +6,7 @@ public enum OpenocdDynamicVariable { - OPENOCD_PATH("openocd_path"), OPENOCD_EXE("openocd_exe"), OPENOCD_SCRIPTS; //$NON-NLS-1$ //$NON-NLS-2$ + OPENOCD_PATH("openocd_path"), OPENOCD_EXE("openocd_executable"), OPENOCD_SCRIPTS; //$NON-NLS-1$ //$NON-NLS-2$ private String value; diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/OpenocdVariableResolver.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/OpenocdVariableResolver.java index e0e38f8fc..4dcc45445 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/OpenocdVariableResolver.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/OpenocdVariableResolver.java @@ -4,7 +4,6 @@ *******************************************************************************/ package com.espressif.idf.core.variable; -import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; @@ -31,6 +30,7 @@ public class OpenocdVariableResolver implements IDynamicVariableResolver { private static final String OPENOCD_PREFIX = "com.espressif.idf.debug.gdbjtag.openocd"; //$NON-NLS-1$ private static final String INSTALL_FOLDER = "install.folder"; //$NON-NLS-1$ + private static final String EXECUTABLE_NAME = "executable.name"; //$NON-NLS-1$ public String resolveValue(IDynamicVariable variable, String argument) { @@ -45,15 +45,16 @@ private Optional getAppropriateEnumVariable(IDynamicVari private String resolveForOpenocdDynamicEnum(OpenocdDynamicVariable enumVariable) { + ILaunchConfiguration configuration = getActiveLaunchConfiguration(); switch (enumVariable) { case OPENOCD_PATH: - ILaunchConfiguration configuration = getActiveLaunchConfiguration(); Path openocdBinPath = getOpenocdBinPath(configuration); - return openocdBinPath.getParent().toString(); + return openocdBinPath.toString(); case OPENOCD_EXE: - return File.separator + "bin" + File.separator + "openocd"; //$NON-NLS-1$ //$NON-NLS-2$ + Path openocdExe = getOpenocdExecutable(configuration); + return openocdExe.toString(); case OPENOCD_SCRIPTS: return new IDFEnvironmentVariables().getEnvValue(IDFEnvironmentVariables.OPENOCD_SCRIPTS); @@ -85,4 +86,11 @@ protected Path getOpenocdBinPath(ILaunchConfiguration configuration) EclipseUtils.getProjectByLaunchConfiguration(configuration)); return Paths.get(installFolder); } + + protected Path getOpenocdExecutable(ILaunchConfiguration configuration) + { + String executableName = EclipseUtils.getPreferenceValueForId(OPENOCD_PREFIX, EXECUTABLE_NAME, "", //$NON-NLS-1$ + EclipseUtils.getProjectByLaunchConfiguration(configuration)); + return Paths.get(executableName); + } } diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/UartDynamicVariable.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/UartDynamicVariable.java new file mode 100644 index 000000000..9b8d56ff9 --- /dev/null +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/UartDynamicVariable.java @@ -0,0 +1,18 @@ +package com.espressif.idf.core.variable; + +public enum UartDynamicVariable +{ + SERIAL_PORT("serial_port"); //$NON-NLS-1$ + + private String value; + + UartDynamicVariable(String value) + { + this.value = value; + } + + public String getValue() + { + return value; + } +} diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/UartVariableResolver.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/UartVariableResolver.java new file mode 100644 index 000000000..ea8371aba --- /dev/null +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/UartVariableResolver.java @@ -0,0 +1,60 @@ +package com.espressif.idf.core.variable; + +import java.util.Arrays; +import java.util.Optional; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.variables.IDynamicVariable; +import org.eclipse.core.variables.IDynamicVariableResolver; +import org.eclipse.launchbar.core.ILaunchBarManager; +import org.eclipse.launchbar.core.target.ILaunchTarget; + +import com.espressif.idf.core.IDFCorePlugin; +import com.espressif.idf.core.LaunchBarTargetConstants; +import com.espressif.idf.core.logging.Logger; +import com.espressif.idf.core.util.StringUtil; + +public class UartVariableResolver implements IDynamicVariableResolver +{ + + public String resolveValue(IDynamicVariable variable, String argument) + { + return getAppropriateEnumVariable(variable).map(this::resolveForDynamicEnum).orElse(variable.getName()); + } + + private Optional getAppropriateEnumVariable(IDynamicVariable variable) + { + return Arrays.stream(UartDynamicVariable.values()).filter(v -> v.getValue().equals(variable.getName())) + .findFirst(); + } + + private String resolveForDynamicEnum(UartDynamicVariable enumVariable) + { + + return switch (enumVariable) + { + case SERIAL_PORT -> getSerialPort(); // $NON-NLS-1$ + }; + } + + private String getSerialPort() + { + return getActiveLaunchTarget().orElseGet(() -> ILaunchTarget.NULL_TARGET) + .getAttribute(LaunchBarTargetConstants.SERIAL_PORT, StringUtil.EMPTY); + } + + private Optional getActiveLaunchTarget() + { + + try + { + return Optional.of(IDFCorePlugin.getService(ILaunchBarManager.class).getActiveLaunchTarget()); + } + catch (CoreException e) + { + Logger.log(e); + } + return Optional.empty(); + } + +} diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/META-INF/MANIFEST.MF b/bundles/com.espressif.idf.debug.gdbjtag.openocd/META-INF/MANIFEST.MF index c1e8c3e7d..d335aa727 100644 --- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/META-INF/MANIFEST.MF +++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/META-INF/MANIFEST.MF @@ -42,4 +42,5 @@ Export-Package: com.espressif.idf.debug.gdbjtag.openocd, com.espressif.idf.debug.gdbjtag.openocd.dsf, com.espressif.idf.debug.gdbjtag.openocd.preferences, com.espressif.idf.debug.gdbjtag.openocd.ui -Import-Package: org.eclipse.embedcdt.debug.gdbjtag.ui +Import-Package: com.espressif.idf.swt.custom, + org.eclipse.embedcdt.debug.gdbjtag.ui diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/SvdPathResolver.java b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/SvdPathResolver.java index 6e21faa92..bec415a02 100644 --- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/SvdPathResolver.java +++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/SvdPathResolver.java @@ -23,7 +23,7 @@ import org.eclipse.launchbar.core.ILaunchBarManager; import com.espressif.idf.core.IDFConstants; -import com.espressif.idf.core.build.IDFLaunchConstants; +import com.espressif.idf.core.LaunchBarTargetConstants; import com.espressif.idf.core.logging.Logger; import com.espressif.idf.core.util.StringUtil; import com.espressif.idf.debug.gdbjtag.openocd.ui.TabSvdTarget; @@ -45,7 +45,7 @@ public String resolveValue(IDynamicVariable variable, String argument) throws Co String selectedTargetPath = StringUtil.EMPTY; try { - selectedTarget = LAUNCH_BAR_MANAGER.getActiveLaunchTarget().getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, + selectedTarget = LAUNCH_BAR_MANAGER.getActiveLaunchTarget().getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY); if (StringUtil.isEmpty(selectedTarget)) return StringUtil.EMPTY; @@ -98,5 +98,4 @@ private String resolveSvdPathFromJar(URL svdUrl, String jarPath) throws Exceptio return svdFile.getRawLocation().toOSString(); } - } diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/preferences/DefaultPreferences.java b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/preferences/DefaultPreferences.java index 30b2f227a..19371a6ec 100644 --- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/preferences/DefaultPreferences.java +++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/preferences/DefaultPreferences.java @@ -19,9 +19,13 @@ import com.espressif.idf.core.util.IDFUtil; import com.espressif.idf.core.util.StringUtil; +import com.espressif.idf.core.variable.GdbClientDynamicVariable; +import com.espressif.idf.core.variable.JtagDynamicVariable; +import com.espressif.idf.core.variable.OpenocdDynamicVariable; import com.espressif.idf.debug.gdbjtag.openocd.Activator; -public class DefaultPreferences extends org.eclipse.embedcdt.debug.gdbjtag.core.preferences.DefaultPreferences { +public class DefaultPreferences extends org.eclipse.embedcdt.debug.gdbjtag.core.preferences.DefaultPreferences +{ // ------------------------------------------------------------------------ @@ -33,26 +37,29 @@ public class DefaultPreferences extends org.eclipse.embedcdt.debug.gdbjtag.core. // Preferences protected static final boolean TAB_MAIN_CHECK_PROGRAM_DEFAULT = false; - public static final String GDB_SERVER_EXECUTABLE_DEFAULT = "${openocd_path}/bin/${openocd_executable}"; + public static final String GDB_SERVER_EXECUTABLE_DEFAULT = "${openocd_path}/bin/${openocd_executable}"; //$NON-NLS-1$ + + public static final String GDB_SERVER_EXECUTABLE_DEFAULT_NAME = "openocd"; //$NON-NLS-1$ + protected static final String GDB_CLIENT_EXECUTABLE_DEFAULT = "${cross_prefix}gdb${cross_suffix}"; //$NON-NLS-1$ - public static final String GDB_SERVER_EXECUTABLE_DEFAULT_NAME = "openocd"; - protected static final String GDB_CLIENT_EXECUTABLE_DEFAULT = "${cross_prefix}gdb${cross_suffix}"; - // ------------------------------------------------------------------------ // Not yet preferences public static final boolean DO_START_GDB_SERVER_DEFAULT = true; - public static final String GDB_SERVER_CONNECTION_ADDRESS_DEFAULT = ""; + public static final String GDB_SERVER_CONNECTION_ADDRESS_DEFAULT = ""; //$NON-NLS-1$ public static final int GDB_SERVER_GDB_PORT_NUMBER_DEFAULT = 3333; public static final int GDB_SERVER_TELNET_PORT_NUMBER_DEFAULT = 4444; - public static final String GDB_SERVER_TCL_PORT_NUMBER_DEFAULT = "6666"; + public static final String GDB_SERVER_TCL_PORT_NUMBER_DEFAULT = "6666"; //$NON-NLS-1$ public static final String GDB_SERVER_LOG_DEFAULT = ""; //$NON-NLS-1$ - public static final String GDB_SERVER_OTHER_DEFAULT = ""; //$NON-NLS-1$ + public static final String GDB_SERVER_OTHER_DEFAULT = String.format("-s ${%s} ${%s}", //$NON-NLS-1$ + OpenocdDynamicVariable.OPENOCD_SCRIPTS, JtagDynamicVariable.JTAG_FLASH_ARGS); public static final boolean DO_GDB_SERVER_ALLOCATE_CONSOLE_DEFAULT = true; public static final boolean DO_GDB_SERVER_ALLOCATE_TELNET_CONSOLE_DEFAULT = false; public static final boolean DO_START_GDB_CLIENT_DEFAULT = true; - public static final String GDB_CLIENT_OTHER_OPTIONS_DEFAULT = ""; + public static final String GDB_CLIENT_EXECUTABLE_DYNAMIC_DEFAULT = String.format("${%s}", //$NON-NLS-1$ + GdbClientDynamicVariable.GDB_CLIENT_EXECUTABLE); + public static final String GDB_CLIENT_OTHER_OPTIONS_DEFAULT = ""; //$NON-NLS-1$ public static final boolean USE_REMOTE_TARGET_DEFAULT = true; public static final String REMOTE_IP_ADDRESS_DEFAULT = REMOTE_IP_ADDRESS_LOCALHOST; // $NON-NLS-1$ @@ -61,7 +68,7 @@ public class DefaultPreferences extends org.eclipse.embedcdt.debug.gdbjtag.core. public static final boolean UPDATE_THREAD_LIST_DEFAULT = false; public static final boolean DO_FIRST_RESET_DEFAULT = true; - public static final String FIRST_RESET_TYPE_DEFAULT = "init"; + public static final String FIRST_RESET_TYPE_DEFAULT = "init"; //$NON-NLS-1$ public static final boolean ENABLE_SEMIHOSTING_DEFAULT = true; @@ -69,27 +76,26 @@ public class DefaultPreferences extends org.eclipse.embedcdt.debug.gdbjtag.core. public static final boolean DO_SECOND_RESET_DEFAULT = true; - public static final String SECOND_RESET_TYPE_DEFAULT = "halt"; + public static final String SECOND_RESET_TYPE_DEFAULT = "halt"; //$NON-NLS-1$ public static final boolean DO_STOP_AT_DEFAULT = true; - public static final String STOP_AT_NAME_DEFAULT = "app_main"; + public static final String STOP_AT_NAME_DEFAULT = "app_main"; //$NON-NLS-1$ public static final boolean DO_CONTINUE_DEFAULT = true; // ------------------------------------------------------------------------ // Debugger commands - public static final String GDB_CLIENT_OTHER_COMMANDS_DEFAULT = "set mem inaccessible-by-default off\nset remotetimeout 20"; - public static final String DO_FIRST_RESET_COMMAND = "monitor reset "; - public static final String HALT_COMMAND = "monitor halt"; - public static final String ENABLE_SEMIHOSTING_COMMAND = "monitor arm semihosting enable"; - public static final String DO_SECOND_RESET_COMMAND = "monitor reset "; - public static final String DO_CONTINUE_COMMAND = "continue"; - public static final String IDF_TARGET_CPU_WATCHPOINT_NUM = "{IDF_TARGET_CPU_WATCHPOINT_NUM}"; - public static final String OTHER_INIT_COMMANDS_DEFAULT = "mon reset halt\n" + - "flushregs\n" + - "set remote hardware-watchpoint-limit " + IDF_TARGET_CPU_WATCHPOINT_NUM; - public static final String OTHER_RUN_COMMANDS_DEFAULT = ""; + public static final String GDB_CLIENT_OTHER_COMMANDS_DEFAULT = "set mem inaccessible-by-default off\nset remotetimeout 20"; //$NON-NLS-1$ + public static final String DO_FIRST_RESET_COMMAND = "monitor reset "; //$NON-NLS-1$ + public static final String HALT_COMMAND = "monitor halt"; //$NON-NLS-1$ + public static final String ENABLE_SEMIHOSTING_COMMAND = "monitor arm semihosting enable"; //$NON-NLS-1$ + public static final String DO_SECOND_RESET_COMMAND = "monitor reset "; //$NON-NLS-1$ + public static final String DO_CONTINUE_COMMAND = "continue"; //$NON-NLS-1$ + public static final String IDF_TARGET_CPU_WATCHPOINT_NUM = "{IDF_TARGET_CPU_WATCHPOINT_NUM}"; //$NON-NLS-1$ + public static final String OTHER_INIT_COMMANDS_DEFAULT = "mon reset halt\n" + "flushregs\n" //$NON-NLS-1$ //$NON-NLS-2$ + + "set remote hardware-watchpoint-limit " + IDF_TARGET_CPU_WATCHPOINT_NUM; //$NON-NLS-1$ + public static final String OTHER_RUN_COMMANDS_DEFAULT = ""; //$NON-NLS-1$ // ------------------------------------------------------------------------ @@ -100,101 +106,114 @@ public class DefaultPreferences extends org.eclipse.embedcdt.debug.gdbjtag.core. // ------------------------------------------------------------------------ // HKCU & HKLM LOCAL_MACHINE - private static final String REG_SUBKEY = "\\GNU ARM Eclipse\\OpenOCD"; + private static final String REG_SUBKEY = "\\GNU ARM Eclipse\\OpenOCD"; //$NON-NLS-1$ // Standard Microsoft recommendation. - private static final String REG_NAME = "InstallLocation"; + private static final String REG_NAME = "InstallLocation"; //$NON-NLS-1$ // ------------------------------------------------------------------------ - public DefaultPreferences(String pluginId) { + public DefaultPreferences(String pluginId) + { super(pluginId); } // ------------------------------------------------------------------------ - public String getGdbServerExecutable() { + public String getGdbServerExecutable() + { String value = getString(PersistentPreferences.GDB_SERVER_EXECUTABLE, GDB_SERVER_EXECUTABLE_DEFAULT); return value; } - public String getGdbClientExecutable() { + public String getGdbClientExecutable() + { String value = getString(PersistentPreferences.GDB_CLIENT_EXECUTABLE, GDB_CLIENT_EXECUTABLE_DEFAULT); return value; } // ------------------------------------------------------------------------ - public String getOpenocdConfig() { - String value = getString(PersistentPreferences.GDB_SERVER_OTHER_OPTIONS, - DefaultPreferences.GDB_SERVER_OTHER_DEFAULT); - return value; + public String getOpenocdConfig() + { + return getString(PersistentPreferences.GDB_SERVER_OTHER_OPTIONS, DefaultPreferences.GDB_SERVER_OTHER_DEFAULT); } // ------------------------------------------------------------------------ - public boolean getTabMainCheckProgram() { + public boolean getTabMainCheckProgram() + { return getBoolean(PersistentPreferences.TAB_MAIN_CHECK_PROGRAM, PersistentPreferences.TAB_MAIN_CHECK_PROGRAM_DEFAULT); } // ------------------------------------------------------------------------ - public String getExecutableName() { + public String getExecutableName() + { String key = PersistentPreferences.EXECUTABLE_NAME; - String value = getString(key, ""); + String value = getString(key, ""); //$NON-NLS-1$ - if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.DefaultPreferences.getExecutableName() = \"" + value + "\""); + if (Activator.getInstance().isDebugging()) + { + System.out.println("openocd.DefaultPreferences.getExecutableName() = \"" + value + "\""); //$NON-NLS-1$ //$NON-NLS-2$ } return value; } - public String getExecutableNameOs() { + public String getExecutableNameOs() + { String key = EclipseUtils.getKeyOs(PersistentPreferences.EXECUTABLE_NAME_OS); - String value = getString(key, ""); + String value = getString(key, ""); //$NON-NLS-1$ - if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.DefaultPreferences.getExecutableNameOs() = \"" + value + "\" (" + key + ")"); + if (Activator.getInstance().isDebugging()) + { + System.out.println("openocd.DefaultPreferences.getExecutableNameOs() = \"" + value + "\" (" + key + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } return value; } - public void putExecutableName(String value) { + public void putExecutableName(String value) + { String key = PersistentPreferences.EXECUTABLE_NAME; - if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.DefaultPreferences.putExecutableName(\"" + value + "\")"); + if (Activator.getInstance().isDebugging()) + { + System.out.println("openocd.DefaultPreferences.putExecutableName(\"" + value + "\")"); //$NON-NLS-1$ //$NON-NLS-2$ } putString(key, value); } // ------------------------------------------------------------------------ - public String getInstallFolder() { + public String getInstallFolder() + { String key = PersistentPreferences.INSTALL_FOLDER; - String value = getString(key, ""); - + String value = getString(key, ""); //$NON-NLS-1$ + if (StringUtil.isEmpty(value)) { value = IDFUtil.getOpenOCDLocation(); } - if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.DefaultPreferences.getInstallFolder() = \"" + value + "\""); + if (Activator.getInstance().isDebugging()) + { + System.out.println("openocd.DefaultPreferences.getInstallFolder() = \"" + value + "\""); //$NON-NLS-1$ //$NON-NLS-2$ } return value; } - public void putInstallFolder(String value) { + public void putInstallFolder(String value) + { String key = PersistentPreferences.INSTALL_FOLDER; - if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.DefaultPreferences.putInstallFolder(\"" + value + "\")"); + if (Activator.getInstance().isDebugging()) + { + System.out.println("openocd.DefaultPreferences.putInstallFolder(\"" + value + "\")"); //$NON-NLS-1$ //$NON-NLS-2$ } putString(key, value); } @@ -202,36 +221,42 @@ public void putInstallFolder(String value) { // ------------------------------------------------------------------------ @Override - public String getSearchPath() { + public String getSearchPath() + { String key = PersistentPreferences.SEARCH_PATH; - String value = getString(key, ""); + String value = getString(key, ""); //$NON-NLS-1$ - if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.DefaultPreferences.getSearchPath() = \"" + value + "\""); + if (Activator.getInstance().isDebugging()) + { + System.out.println("openocd.DefaultPreferences.getSearchPath() = \"" + value + "\""); //$NON-NLS-1$ //$NON-NLS-2$ } return value; } @Override - public String getSearchPathOs() { + public String getSearchPathOs() + { String key = EclipseUtils.getKeyOs(PersistentPreferences.SEARCH_PATH_OS); - String value = getString(key, ""); + String value = getString(key, ""); //$NON-NLS-1$ - if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.DefaultPreferences.getSearchPathOs() = \"" + value + "\""); + if (Activator.getInstance().isDebugging()) + { + System.out.println("openocd.DefaultPreferences.getSearchPathOs() = \"" + value + "\""); //$NON-NLS-1$ //$NON-NLS-2$ } return value; } @Override - public void putSearchPath(String value) { + public void putSearchPath(String value) + { String key = PersistentPreferences.SEARCH_PATH; - if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.DefaultPreferences.putSearchPath(\"" + value + "\")"); + if (Activator.getInstance().isDebugging()) + { + System.out.println("openocd.DefaultPreferences.putSearchPath(\"" + value + "\")"); //$NON-NLS-1$ //$NON-NLS-2$ } putString(key, value); } @@ -239,7 +264,8 @@ public void putSearchPath(String value) { // ------------------------------------------------------------------------ @Override - protected String getRegistryInstallFolder(String subFolder, String executableName) { + protected String getRegistryInstallFolder(String subFolder, String executableName) + { String path = Discoverer.getRegistryInstallFolder(executableName, subFolder, REG_SUBKEY, REG_NAME); return path; diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabDebugger.java b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabDebugger.java index abe59b370..97fafb379 100644 --- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabDebugger.java +++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabDebugger.java @@ -25,26 +25,25 @@ package com.espressif.idf.debug.gdbjtag.openocd.ui; import java.io.File; -import java.util.Map; import org.eclipse.cdt.debug.gdbjtag.core.IGDBJtagConstants; import org.eclipse.cdt.debug.gdbjtag.ui.GDBJtagImages; import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.variables.VariablesPlugin; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; import org.eclipse.debug.ui.StringVariableSelectionDialog; import org.eclipse.embedcdt.core.EclipseUtils; import org.eclipse.jface.window.Window; -import org.eclipse.launchbar.core.ILaunchBarManager; -import org.eclipse.launchbar.core.target.ILaunchTargetManager; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseTrackAdapter; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.VerifyEvent; @@ -53,7 +52,6 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.FileDialog; @@ -62,16 +60,8 @@ import org.eclipse.swt.widgets.Link; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.dialogs.PreferencesUtil; -import org.json.simple.JSONArray; -import com.espressif.idf.core.DefaultBoardProvider; -import com.espressif.idf.core.IDFEnvironmentVariables; -import com.espressif.idf.core.actions.ApplyTargetJob; -import com.espressif.idf.core.build.IDFLaunchConstants; import com.espressif.idf.core.logging.Logger; -import com.espressif.idf.core.util.EspConfigParser; -import com.espressif.idf.core.util.IDFUtil; -import com.espressif.idf.core.util.StringUtil; import com.espressif.idf.debug.gdbjtag.openocd.Activator; import com.espressif.idf.debug.gdbjtag.openocd.Configuration; import com.espressif.idf.debug.gdbjtag.openocd.ConfigurationAttributes; @@ -80,7 +70,8 @@ import com.espressif.idf.debug.gdbjtag.openocd.ui.preferences.GlobalMcuPage; import com.espressif.idf.debug.gdbjtag.openocd.ui.preferences.WorkspaceMcuPage; import com.espressif.idf.debug.gdbjtag.openocd.ui.properties.ProjectMcuPage; -import com.espressif.idf.launch.serial.ui.internal.NewSerialFlashTargetWizard; +import com.espressif.idf.swt.custom.StyledInfoText; +import com.espressif.idf.swt.custom.TextWithButton; /** * @since 7.0 @@ -88,13 +79,8 @@ public class TabDebugger extends AbstractLaunchConfigurationTab { - // ------------------------------------------------------------------------ - private static final int JOB_DELAY_MS = 100; private static final String TAB_NAME = "Debugger"; //$NON-NLS-1$ private static final String TAB_ID = Activator.PLUGIN_ID + ".ui.debuggertab"; //$NON-NLS-1$ - private static final String EMPTY_CONFIG_OPTIONS = "-s ${openocd_path}/share/openocd/scripts"; //$NON-NLS-1$ - // ------------------------------------------------------------------------ - private ILaunchConfiguration fConfiguration; private Button fDoStartGdbServer; @@ -102,23 +88,18 @@ public class TabDebugger extends AbstractLaunchConfigurationTab private Text fGdbServerTelnetPort; private Text fGdbServerTclPort; - private Text fGdbServerExecutable; + private TextWithButton fGdbServerExecutable; private Button fGdbServerBrowseButton; private Button fGdbServerVariablesButton; private Text fGdbServerPathLabel; - private Text fGdbServerOtherOptions; + private TextWithButton fGdbServerOtherOptions; private Button fDoGdbServerAllocateConsole; private Button fDoGdbServerAllocateTelnetConsole; - private Combo fFlashVoltage; - private Combo fTarget; - private Combo fTargetName; - private Map boardConfigsMap; - private Button fDoStartGdbClient; - private Text fGdbClientExecutable; + private TextWithButton fGdbClientExecutable; private Button fGdbClientBrowseButton; private Button fGdbClientVariablesButton; private Text fGdbClientOtherOptions; @@ -134,22 +115,16 @@ public class TabDebugger extends AbstractLaunchConfigurationTab private DefaultPreferences fDefaultPreferences; private PersistentPreferences fPersistentPreferences; - private ILaunchBarManager launchBarManager; - private final ILaunchTargetManager targetManager = Activator.getService(ILaunchTargetManager.class); - // ------------------------------------------------------------------------ protected TabDebugger(TabStartup tabStartup) { super(); - fDefaultPreferences = Activator.getInstance().getDefaultPreferences(); fPersistentPreferences = Activator.getInstance().getPersistentPreferences(); - launchBarManager = Activator.getService(ILaunchBarManager.class); } // ------------------------------------------------------------------------ - @Override public String getName() { @@ -170,10 +145,6 @@ public void createControl(Composite parent) System.out.println("openocd.TabDebugger.createControl() "); //$NON-NLS-1$ } - parent.addDisposeListener(event -> { - scheduleApplyTargetJob(); - }); - if (!(parent instanceof ScrolledComposite)) { ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL); @@ -196,7 +167,11 @@ public void createControl(Composite parent) setControl(comp); GridLayout layout = new GridLayout(); comp.setLayout(layout); - + StyledInfoText styledInfoText = new StyledInfoText(comp); + styledInfoText.setMouseListenerAction(() -> { + initializeFromDefaults(); + scheduleUpdateJob(); + }); createGdbServerGroup(comp); createGdbClientControls(comp); @@ -242,33 +217,25 @@ public void widgetSelected(final SelectionEvent event) }); } - private void scheduleApplyTargetJob() - { - Job applyTargetJob = new ApplyTargetJob(launchBarManager, targetManager, IDFLaunchConstants.TARGET_FOR_JTAG, - new NewSerialFlashTargetWizard()); - - applyTargetJob.schedule(JOB_DELAY_MS); - } - - private void browseButtonSelected(String title, Text text) + private void browseButtonSelected(String title, TextWithButton fGdbServerExecutable2) { FileDialog dialog = new FileDialog(getShell(), SWT.NONE); dialog.setText(title); - String str = text.getText().trim(); + String str = fGdbServerExecutable2.getText().trim(); int lastSeparatorIndex = str.lastIndexOf(File.separator); if (lastSeparatorIndex != -1) dialog.setFilterPath(str.substring(0, lastSeparatorIndex)); str = dialog.open(); if (str != null) - text.setText(str); + fGdbServerExecutable2.setText(str); } - private void variablesButtonSelected(Text text) + private void variablesButtonSelected(TextWithButton fGdbServerOtherOptions2) { StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell()); if (dialog.open() == StringVariableSelectionDialog.OK) { - text.insert(dialog.getVariableExpression()); + fGdbServerOtherOptions2.insert(dialog.getVariableExpression()); } } @@ -327,7 +294,7 @@ private void createGdbServerGroup(Composite parent) gd.horizontalSpan = ((GridLayout) comp.getLayout()).numColumns - 1; local.setLayoutData(gd); { - fGdbServerExecutable = new Text(local, SWT.SINGLE | SWT.BORDER); + fGdbServerExecutable = new TextWithButton(local, SWT.SINGLE | SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); fGdbServerExecutable.setLayoutData(gd); @@ -399,115 +366,34 @@ private void createGdbServerGroup(Composite parent) fGdbServerTclPort.setLayoutData(gd); } - String selectedTarget = getLaunchTarget(); - EspConfigParser parser = new EspConfigParser(); - String openOCDPath = new IDFEnvironmentVariables().getEnvValue(IDFEnvironmentVariables.OPENOCD_SCRIPTS); - if (!openOCDPath.isEmpty() && parser.hasBoardConfigJson()) // $NON-NLS-1$ - { - { - Label label = new Label(comp, SWT.NONE); - label.setText(Messages.getString("DebuggerTab.flashVoltageLabel")); //$NON-NLS-1$ - label.setToolTipText(Messages.getString("DebuggerTab.flashVoltageToolTip")); //$NON-NLS-1$ - GridData gd = new GridData(); - gd.widthHint = 80; - gd.horizontalSpan = ((GridLayout) comp.getLayout()).numColumns - 1; - fFlashVoltage = new Combo(comp, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); - fFlashVoltage.setItems(parser.getEspFlashVoltages().toArray(new String[0])); - fFlashVoltage.setText("default"); //$NON-NLS-1$ - - fFlashVoltage.addSelectionListener(new SelectionAdapter() - { - @Override - public void widgetSelected(SelectionEvent e) - { - fTargetName.notifyListeners(SWT.Selection, null); - } - }); - fFlashVoltage.setLayoutData(gd); - } - { - Label label = new Label(comp, SWT.NONE); - label.setText(Messages.getString("DebuggerTab.configTargetLabel")); //$NON-NLS-1$ - label.setToolTipText(Messages.getString("DebuggerTab.configTargetToolTip")); //$NON-NLS-1$ - GridData gd = new GridData(); - gd.widthHint = 80; - gd.horizontalSpan = ((GridLayout) comp.getLayout()).numColumns - 1; - fTarget = new Combo(comp, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); - fTarget.setItems(parser.getTargets().toArray(new String[0])); - fTarget.setText(selectedTarget); - fTarget.addSelectionListener(new SelectionAdapter() - { - @Override - public void widgetSelected(SelectionEvent e) - { - String selectedItem = fTarget.getText(); - fGdbClientExecutable.setText(IDFUtil.getXtensaToolchainExecutablePathByTarget(selectedItem)); - boardConfigsMap = parser.getBoardsConfigs(selectedItem); - fTargetName.setItems(parser.getBoardsConfigs(selectedItem).keySet().toArray(new String[0])); - fTargetName.select(new DefaultBoardProvider().getIndexOfDefaultBoard(selectedItem, - fTargetName.getItems())); - fTargetName.notifyListeners(SWT.Selection, null); - } - }); - fTarget.setLayoutData(gd); - } - { - Label label = new Label(comp, SWT.NONE); - label.setText(Messages.getString("DebuggerTab.configBoardLabel")); //$NON-NLS-1$ - label.setToolTipText(Messages.getString("DebuggerTab.configBoardTooTip")); //$NON-NLS-1$ - - GridData gd = new GridData(); - gd.widthHint = 250; - gd.horizontalSpan = ((GridLayout) comp.getLayout()).numColumns - 1; - fTargetName = new Combo(comp, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); - fTargetName.setItems(parser.getBoardsConfigs(selectedTarget).keySet().toArray(new String[0])); - boardConfigsMap = parser.getBoardsConfigs(selectedTarget); - - fTargetName.select( - new DefaultBoardProvider().getIndexOfDefaultBoard(selectedTarget, fTargetName.getItems())); - fTargetName.addSelectionListener(new SelectionAdapter() - { - @SuppressWarnings("unchecked") - @Override - public void widgetSelected(SelectionEvent e) - { - String selectedVoltage = fFlashVoltage.getText(); - String selectedItem = fTargetName.getText(); - String configOptionString = EMPTY_CONFIG_OPTIONS; - if (!selectedVoltage.equals("default")) //$NON-NLS-1$ - { - configOptionString = configOptionString + " -c 'set ESP32_FLASH_VOLTAGE " + selectedVoltage //$NON-NLS-1$ - + "'"; //$NON-NLS-1$ - } - if (!selectedItem.isEmpty()) - { - for (String config : (String[]) boardConfigsMap.get(selectedItem).toArray(new String[0])) - { - configOptionString = configOptionString + " -f " + config; //$NON-NLS-1$ - } - fGdbServerOtherOptions.setText(configOptionString); - } - - } - - }); - fTargetName.setLayoutData(gd); - } - } - { Label label = new Label(comp, SWT.NONE); label.setText(Messages.getString("DebuggerTab.gdbServerOther_Label")); //$NON-NLS-1$ label.setToolTipText(Messages.getString("DebuggerTab.gdbServerOther_ToolTipText")); //$NON-NLS-1$ - GridData gd = new GridData(); - gd.verticalAlignment = SWT.TOP; - label.setLayoutData(gd); - fGdbServerOtherOptions = new Text(comp, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); - gd = new GridData(SWT.FILL, SWT.FILL, true, true); - gd.heightHint = 60; + Composite local = new Composite(comp, SWT.NONE); + GridLayout layout = new GridLayout(3, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + local.setLayout(layout); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = ((GridLayout) comp.getLayout()).numColumns - 1; - fGdbServerOtherOptions.setLayoutData(gd); + local.setLayoutData(gd); + { + fGdbServerOtherOptions = new TextWithButton(local, SWT.SINGLE | SWT.BORDER); + fGdbServerOtherOptions.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Button browseVariablesButton = new Button(local, SWT.NONE); + browseVariablesButton.setText(Messages.getString("DebuggerTab.gdbOtherOptionsBrowse")); //$NON-NLS-1$ + browseVariablesButton.addListener(SWT.Selection, + e -> browseButtonSelected(Messages.getString("DebuggerTab.gdbOtherOptionsBrowse_Title"), //$NON-NLS-1$ + fGdbServerOtherOptions)); + + Button otherOptionsVariablesButton = new Button(local, SWT.NONE); + otherOptionsVariablesButton.setText(Messages.getString("DebuggerTab.gdbOtherOptionsVariable")); //$NON-NLS-1$ + otherOptionsVariablesButton.addListener(SWT.Selection, + e -> variablesButtonSelected(fGdbServerOtherOptions)); + } } { @@ -516,7 +402,7 @@ public void widgetSelected(SelectionEvent e) layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; - layout.makeColumnsEqualWidth = true; + layout.makeColumnsEqualWidth = false; local.setLayout(layout); GridData gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = ((GridLayout) comp.getLayout()).numColumns; @@ -539,12 +425,29 @@ public void widgetSelected(SelectionEvent e) // update doStartGdbServerChanged() too fDoGdbServerAllocateTelnetConsole.setEnabled(false); + fGdbServerOtherOptions.addMouseTrackListener(new MouseTrackAdapter() + { + @Override + public void mouseExit(MouseEvent e) + { + try + { + fGdbServerOtherOptions.setToolTipText(VariablesPlugin.getDefault().getStringVariableManager() + .performStringSubstitution(fGdbServerOtherOptions.getText(), false).trim()); + } + catch (CoreException exc) + { + Logger.log(exc); + } + } + }); } // ----- Actions ------------------------------------------------------ ModifyListener scheduleUpdateJobModifyListener = new ModifyListener() { + @Override public void modifyText(ModifyEvent e) { @@ -666,26 +569,6 @@ public void modifyText(ModifyEvent e) fDoGdbServerAllocateTelnetConsole.addSelectionListener(scheduleUpdateJobSelectionAdapter); } - private String getLaunchTarget() - { - launchBarManager = Activator.getService(ILaunchBarManager.class); - String selectedTarget = StringUtil.EMPTY; - try - { - if (launchBarManager.getActiveLaunchConfiguration() != null) - { - selectedTarget = launchBarManager.getActiveLaunchTarget() - .getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY); - } - - } - catch (CoreException e) - { - Logger.log(e); - } - return selectedTarget; - } - private void createGdbClientControls(Composite parent) { @@ -732,7 +615,7 @@ private void createGdbClientControls(Composite parent) gd.horizontalSpan = ((GridLayout) comp.getLayout()).numColumns - 1; local.setLayoutData(gd); { - fGdbClientExecutable = new Text(local, SWT.SINGLE | SWT.BORDER); + fGdbClientExecutable = new TextWithButton(local, SWT.SINGLE | SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); fGdbClientExecutable.setLayoutData(gd); @@ -989,17 +872,6 @@ public void initializeFrom(ILaunchConfiguration configuration) Boolean booleanDefault; String stringDefault; - // JTAG options - if (fFlashVoltage != null && fTarget != null && fTargetName != null) - { - fFlashVoltage.setText( - configuration.getAttribute(IDFLaunchConstants.JTAG_FLASH_VOLTAGE, fFlashVoltage.getText())); - fTarget.setText(configuration.getAttribute(IDFLaunchConstants.TARGET_FOR_JTAG, fTarget.getText())); - fTarget.notifyListeners(SWT.Selection, null); - fTargetName.setText(configuration.getAttribute(IDFLaunchConstants.JTAG_BOARD, fTargetName.getText())); - - } - // OpenOCD GDB server { @@ -1132,8 +1004,7 @@ public void initializeFromDefaults() fGdbServerTclPort.setText(DefaultPreferences.GDB_SERVER_TCL_PORT_NUMBER_DEFAULT); // Other options - stringDefault = fDefaultPreferences.getOpenocdConfig(); - fGdbServerOtherOptions.setText(stringDefault); + fGdbServerOtherOptions.setText(DefaultPreferences.GDB_SERVER_OTHER_DEFAULT); // Allocate server console if (EclipseUtils.isWindows()) @@ -1148,16 +1019,13 @@ public void initializeFromDefaults() // Allocate telnet console fDoGdbServerAllocateTelnetConsole .setSelection(DefaultPreferences.DO_GDB_SERVER_ALLOCATE_TELNET_CONSOLE_DEFAULT); - - fFlashVoltage.select(0); - fTarget.select(0); - fTarget.notifyListeners(SWT.Selection, null); } // GDB Client Setup { fDoStartGdbClient.setSelection(DefaultPreferences.DO_START_GDB_CLIENT_DEFAULT); + fGdbClientExecutable.setText(DefaultPreferences.GDB_CLIENT_EXECUTABLE_DYNAMIC_DEFAULT); // Other options fGdbClientOtherOptions.setText(DefaultPreferences.GDB_CLIENT_OTHER_OPTIONS_DEFAULT); @@ -1442,14 +1310,6 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) } } - // JTAG options - if (fFlashVoltage != null && fTarget != null && fTargetName != null) - { - configuration.setAttribute(IDFLaunchConstants.JTAG_FLASH_VOLTAGE, fFlashVoltage.getText()); - configuration.setAttribute(IDFLaunchConstants.TARGET_FOR_JTAG, fTarget.getText()); - configuration.setAttribute(IDFLaunchConstants.JTAG_BOARD, fTargetName.getText()); - } - // Force thread update configuration.setAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_UPDATE_THREADLIST_ON_SUSPEND, fUpdateThreadlistOnSuspend.getSelection()); @@ -1511,6 +1371,10 @@ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) configuration.setAttribute(ConfigurationAttributes.DO_GDB_SERVER_ALLOCATE_TELNET_CONSOLE, DefaultPreferences.DO_GDB_SERVER_ALLOCATE_TELNET_CONSOLE_DEFAULT); + configuration.setAttribute(ConfigurationAttributes.GDB_SERVER_OTHER, + DefaultPreferences.GDB_SERVER_OTHER_DEFAULT); + configuration.setAttribute(defaultString, defaultBoolean); + } // GDB client setup @@ -1518,6 +1382,9 @@ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) configuration.setAttribute(IGDBJtagConstants.ATTR_USE_REMOTE_TARGET, DefaultPreferences.USE_REMOTE_TARGET_DEFAULT); + configuration.setAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUG_NAME, + DefaultPreferences.GDB_CLIENT_EXECUTABLE_DYNAMIC_DEFAULT); + defaultString = fPersistentPreferences.getGdbClientOtherOptions(); configuration.setAttribute(ConfigurationAttributes.GDB_CLIENT_OTHER_OPTIONS, defaultString); diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/messages.properties b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/messages.properties index 5ea3e07c1..ffeeceab4 100644 --- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/messages.properties +++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/messages.properties @@ -124,6 +124,9 @@ DebuggerTab.gdbOtherOptions_ToolTipText=\ Additional command line options to be passed\n\ to the GDB client. They are added to the\n\ mandatory '--interpreter=mi2 --nx' passed first. +DebuggerTab.gdbOtherOptionsBrowse=Browse... +DebuggerTab.gdbOtherOptionsBrowse_Title=Select Openocd Scripts Folder +DebuggerTab.gdbOtherOptionsVariable=Variables... DebuggerTab.gdbOtherCommands_Label=Commands: DebuggerTab.gdbOtherCommands_ToolTipText=\ diff --git a/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/SerialFlashLaunchTargetProvider.java b/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/SerialFlashLaunchTargetProvider.java index e5f6f46c0..9b56fcc65 100644 --- a/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/SerialFlashLaunchTargetProvider.java +++ b/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/SerialFlashLaunchTargetProvider.java @@ -27,11 +27,6 @@ */ public class SerialFlashLaunchTargetProvider implements ILaunchTargetProvider { - - public static final String ATTR_SERIAL_PORT = "com.espressif.idf.launch.serial.core.serialPort"; //$NON-NLS-1$ - - public static final String ATTR_IDF_TARGET = "com.espressif.idf.launch.serial.core.idfTarget"; //$NON-NLS-1$ - @Override public void init(ILaunchTargetManager targetManager) { diff --git a/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/internal/SerialFlashLaunch.java b/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/internal/SerialFlashLaunch.java index 7ec699719..7dd14ca3d 100644 --- a/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/internal/SerialFlashLaunch.java +++ b/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/internal/SerialFlashLaunch.java @@ -26,7 +26,7 @@ import org.eclipse.launchbar.core.target.ILaunchTarget; import org.eclipse.launchbar.core.target.launch.TargetedLaunch; -import com.espressif.idf.launch.serial.SerialFlashLaunchTargetProvider; +import com.espressif.idf.core.LaunchBarTargetConstants; import com.espressif.idf.terminal.connector.serial.connector.SerialPortHandler; public class SerialFlashLaunch extends TargetedLaunch @@ -41,7 +41,7 @@ public SerialFlashLaunch(ILaunchConfiguration launchConfiguration, String mode, super(launchConfiguration, mode, target, locator); if (target != null) { - String serialPortName = target.getAttribute(SerialFlashLaunchTargetProvider.ATTR_SERIAL_PORT, ""); //$NON-NLS-1$ + String serialPortName = target.getAttribute(LaunchBarTargetConstants.SERIAL_PORT, ""); //$NON-NLS-1$ serialPort = !serialPortName.isEmpty() ? SerialPortHandler.get(serialPortName) : null; } DebugPlugin.getDefault().addDebugEventListener(this); diff --git a/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/internal/SerialFlashLaunchConfigDelegate.java b/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/internal/SerialFlashLaunchConfigDelegate.java index 448f6c3c2..f9d909195 100644 --- a/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/internal/SerialFlashLaunchConfigDelegate.java +++ b/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/internal/SerialFlashLaunchConfigDelegate.java @@ -53,13 +53,13 @@ import com.espressif.idf.core.IDFCorePlugin; import com.espressif.idf.core.IDFEnvironmentVariables; +import com.espressif.idf.core.LaunchBarTargetConstants; import com.espressif.idf.core.build.IDFLaunchConstants; import com.espressif.idf.core.logging.Logger; import com.espressif.idf.core.util.DfuCommandsUtil; import com.espressif.idf.core.util.IDFUtil; import com.espressif.idf.core.util.RecheckConfigsHelper; import com.espressif.idf.core.util.StringUtil; -import com.espressif.idf.launch.serial.SerialFlashLaunchTargetProvider; import com.espressif.idf.launch.serial.util.ESPFlashUtil; import com.espressif.idf.terminal.connector.serial.connector.SerialSettings; import com.espressif.idf.terminal.connector.serial.launcher.SerialLauncherDelegate; @@ -92,11 +92,12 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun // Start the launch (pause the serial port) ((SerialFlashLaunch) launch).start(); - serialPort = ((SerialFlashLaunch) launch).getLaunchTarget() - .getAttribute(SerialFlashLaunchTargetProvider.ATTR_SERIAL_PORT, ""); //$NON-NLS-1$ + serialPort = ((ITargetedLaunch) launch).getLaunchTarget().getAttribute(LaunchBarTargetConstants.SERIAL_PORT, + StringUtil.EMPTY); if (DfuCommandsUtil.isDfu()) { - DfuCommandsUtil.flashDfuBins(configuration, getProject(configuration), launch); + if (DfuCommandsUtil.isTargetSupportDfu(((ITargetedLaunch) launch).getLaunchTarget())) + DfuCommandsUtil.flashDfuBins(configuration, getProject(configuration), launch); return; } if (ESPFlashUtil.isJtag()) @@ -148,7 +149,6 @@ protected void launchInternal(ILaunchConfiguration configuration, String mode, I return; } String arguments = configuration.getAttribute(IDFLaunchConstants.ATTR_SERIAL_FLASH_ARGUMENTS, espFlashCommand); - arguments = arguments.replace(ESPFlashUtil.SERIAL_PORT, serialPort); arguments = varManager.performStringSubstitution(arguments); if (!arguments.isEmpty()) { diff --git a/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/util/ESPFlashUtil.java b/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/util/ESPFlashUtil.java index 2867d9198..108fce44f 100644 --- a/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/util/ESPFlashUtil.java +++ b/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/util/ESPFlashUtil.java @@ -38,7 +38,7 @@ public class ESPFlashUtil public static final String VERSION_PATTERN = "(v.\\S+)"; //$NON-NLS-1$ public static final String SERIAL_PORT = "${serial_port}"; //$NON-NLS-1$ // prefix for backward compatibility with 2.9.1 where this prefix was not added in the argument in the UI - private static final String DEFAULT_ARGUMENT_PREFIX = "${openocd_path}/${openocd_exe} "; //$NON-NLS-1$ + private static final String DEFAULT_ARGUMENT_PREFIX = "${openocd_path}/${openocd_executable} "; //$NON-NLS-1$ private ESPFlashUtil() { diff --git a/bundles/com.espressif.idf.launch.serial.ui/META-INF/MANIFEST.MF b/bundles/com.espressif.idf.launch.serial.ui/META-INF/MANIFEST.MF index bb915ec76..25d8f883f 100644 --- a/bundles/com.espressif.idf.launch.serial.ui/META-INF/MANIFEST.MF +++ b/bundles/com.espressif.idf.launch.serial.ui/META-INF/MANIFEST.MF @@ -22,7 +22,8 @@ Bundle-Activator: com.espressif.idf.launch.serial.ui.internal.Activator Bundle-ActivationPolicy: lazy Automatic-Module-Name: org.eclipse.cdt.launch.serial.ui Bundle-Vendor: %Bundle-Vendor -Import-Package: com.espressif.idf.ui, +Import-Package: com.espressif.idf.swt.custom, + com.espressif.idf.ui, com.espressif.idf.ui.dialogs, org.eclipse.cdt.dsf.gdb, org.eclipse.cdt.ui diff --git a/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/CMakeMainTab2.java b/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/CMakeMainTab2.java index 7b745ca04..7e6e6c658 100644 --- a/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/CMakeMainTab2.java +++ b/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/CMakeMainTab2.java @@ -18,13 +18,10 @@ import java.net.URI; import java.nio.charset.Charset; import java.nio.charset.IllegalCharsetNameException; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.EnumMap; import java.util.List; -import java.util.Map; -import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -41,7 +38,6 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.variables.VariablesPlugin; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; @@ -51,8 +47,6 @@ import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.window.Window; -import org.eclipse.launchbar.core.ILaunchBarManager; -import org.eclipse.launchbar.core.target.ILaunchTargetManager; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.SelectionAdapter; @@ -68,32 +62,25 @@ import org.eclipse.swt.widgets.Text; import org.eclipse.ui.dialogs.ElementListSelectionDialog; import org.eclipse.ui.ide.IDEEncoding; -import org.json.simple.JSONArray; -import com.espressif.idf.core.DefaultBoardProvider; import com.espressif.idf.core.IDFDynamicVariables; -import com.espressif.idf.core.actions.ApplyTargetJob; import com.espressif.idf.core.build.IDFLaunchConstants; import com.espressif.idf.core.logging.Logger; import com.espressif.idf.core.util.DfuCommandsUtil; -import com.espressif.idf.core.util.EspConfigParser; -import com.espressif.idf.core.util.LaunchTargetHelper; import com.espressif.idf.core.util.StringUtil; +import com.espressif.idf.core.variable.JtagDynamicVariable; import com.espressif.idf.core.variable.OpenocdDynamicVariable; import com.espressif.idf.launch.serial.util.ESPFlashUtil; +import com.espressif.idf.swt.custom.StyledInfoText; +import com.espressif.idf.swt.custom.TextWithButton; import com.espressif.idf.ui.EclipseUtil; @SuppressWarnings("restriction") public class CMakeMainTab2 extends GenericMainTab { - private static final String LAUNCH_TARGET_ATTR = "LAUNCH_TARGET"; //$NON-NLS-1$ - private static final int JOB_DELAY_MS = 100; - private static final String EMPTY_CONFIG_OPTIONS = "%s" + File.separator + "%s -s %s"; //$NON-NLS-1$ //$NON-NLS-2$ + private static final String DEFAULT_JTAG_CONFIG_OPTIONS = String.format("-s ${%s} ${%s}", //$NON-NLS-1$ + OpenocdDynamicVariable.OPENOCD_SCRIPTS, JtagDynamicVariable.JTAG_FLASH_ARGS); private Combo flashOverComboButton; - private Combo fFlashVoltage; - private Combo fTarget; - private Map boardConfigsMap; - private Combo fTargetName; private boolean isFlashOverJtag; private boolean isJtagFlashAvailable; private Text fProjText; @@ -101,13 +88,9 @@ public class CMakeMainTab2 extends GenericMainTab private Composite mainComposite; private EnumMap> switchComposites = new EnumMap<>(FlashInterface.class); private EnumMap> switchGridDatas = new EnumMap<>(FlashInterface.class); - private Text uartAgrumentsField; - private Text jtagArgumentsField; - private Text dfuArgumentsField; - private Label dfuErrorLbl; - private Combo comboTargets; - private ILaunchBarManager launchBarManager = Activator.getService(ILaunchBarManager.class); - private ILaunchTargetManager targetManager = Activator.getService(ILaunchTargetManager.class); + private TextWithButton uartAgrumentsField; + private TextWithButton jtagArgumentsField; + private TextWithButton dfuArgumentsField; private Button checkOpenSerialMonitorButton; private Combo fEncodingCombo; @@ -125,8 +108,6 @@ public static String[] getNames() @Override public void createControl(Composite parent) { - parent.addDisposeListener(event -> scheduleApplyTargetJob()); - mainComposite = new Composite(parent, SWT.NONE); mainComposite.setFont(parent.getFont()); GridLayout layout = new GridLayout(); @@ -134,13 +115,17 @@ public void createControl(Composite parent) GridData gridData = new GridData(GridData.FILL_HORIZONTAL); mainComposite.setLayout(layout); mainComposite.setLayoutData(gridData); + StyledInfoText styledInfoText = new StyledInfoText(mainComposite); + styledInfoText.setMouseListenerAction(() -> { + initializeFromDefaults(); + scheduleUpdateJob(); + }); isJtagFlashAvailable = ESPFlashUtil.checkIfJtagIsAvailable(); setControl(mainComposite); createJtagFlashButton(mainComposite); createOpenSerialMonitorGroup(mainComposite); createProjectGroup(mainComposite, 0); - createDfuTargetComposite(mainComposite); createUartComposite(mainComposite); createJtagflashComposite(mainComposite); createDfuArgumentField(mainComposite); @@ -160,7 +145,7 @@ protected void updateArgument(ILaunchConfiguration configuration) * * @param parent the composite to create the controls in */ - protected void createArgumentComponent(Composite parent, Text argumentField) + protected void createArgumentComponent(Composite parent, TextWithButton argumentField) { Group group = new Group(parent, SWT.NONE); String groupName = Messages.CMakeMainTab2_Arguments; @@ -182,10 +167,9 @@ protected void createArgumentComponent(Composite parent, Text argumentField) gridData = new GridData(GridData.FILL_BOTH); gridData.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; - gridData.heightHint = 100; argumentField.setLayoutData(gridData); argumentField.addModifyListener(fListener); - addControlAccessibleListener(argumentField, group.getText()); + addControlAccessibleListener(argumentField.getControl(), group.getText()); Composite composite = new Composite(group, SWT.NONE); layout = new GridLayout(); @@ -205,7 +189,7 @@ protected void createArgumentComponent(Composite parent, Text argumentField) instruction.setLayoutData(gridData); } - private void handleVariablesButtonSelected(Text textField) + private void handleVariablesButtonSelected(TextWithButton textField) { String variable = getVariable(); if (variable != null) @@ -242,7 +226,7 @@ protected void createUartComposite(Composite parent) locationField.getParent().setLayoutData(locationAndWorkDirGroupData); workDirectoryField.getParent().setLayoutData(locationAndWorkDirGroupData); - uartAgrumentsField = new Text(parent, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); + uartAgrumentsField = new TextWithButton(parent, SWT.WRAP | SWT.BORDER); createArgumentComponent(defaultComposite, uartAgrumentsField); createVerticalSpacer(defaultComposite, 1); @@ -264,73 +248,11 @@ protected void createJtagflashComposite(Composite parent) jtagComposite.setLayout(layout); jtagComposite.setLayoutData(jtagCompositeGridData); - String selectedTarget = getLaunchTarget(); - EspConfigParser parser = new EspConfigParser(); - createOpenOcdSetupComponent(jtagComposite, selectedTarget, parser); - - jtagArgumentsField = new Text(parent, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); + jtagArgumentsField = new TextWithButton(parent, SWT.WRAP | SWT.BORDER); createArgumentComponent(jtagComposite, jtagArgumentsField); createVerticalSpacer(jtagComposite, 1); } - protected void createDfuTargetComposite(Composite parent) - { - Composite dfuComposite = createDfuComposite(parent); - - Composite targetComposite = new Composite(dfuComposite, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 3; - GridData targetGridData = new GridData(GridData.FILL_HORIZONTAL); - targetComposite.setLayout(layout); - targetComposite.setData(targetGridData); - - Label comboTargetLbl = new Label(targetComposite, SWT.NONE); - comboTargetLbl.setText(Messages.CMakeMainTab2_TargetsComboLbl); - comboTargets = new Combo(targetComposite, SWT.DROP_DOWN | SWT.READ_ONLY); - comboTargets.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); - - String[] targetsWithDfuSupport = DfuCommandsUtil.getSupportedTargets(); - comboTargets.setItems(targetsWithDfuSupport); - comboTargets.addSelectionListener(new SelectionAdapter() - { - - @Override - public void widgetSelected(SelectionEvent evt) - { - if (!((Combo) evt.widget).getText().isEmpty() && dfuErrorLbl != null) - { - dfuErrorLbl.setText(StringUtil.EMPTY); - } - updateLaunchConfigurationDialog(); - } - }); - - Optional suitableTarget = Stream.of(targetsWithDfuSupport).filter(t -> { - try - { - if (launchBarManager.getActiveLaunchConfiguration() != null) - { - return t.contentEquals(launchBarManager.getActiveLaunchTarget() - .getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY)); - } - } - catch (CoreException e) - { - Logger.log(e); - } - return false; - }).findFirst(); - - suitableTarget.ifPresentOrElse(t -> comboTargets.select(Arrays.asList(comboTargets.getItems()).indexOf(t)), - () -> { - dfuErrorLbl = new Label(targetComposite, SWT.NONE); - dfuErrorLbl.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_DARK_YELLOW)); - dfuErrorLbl.setText(Messages.CMakeMainTab2_WarningDfuMsg); - }); - - comboTargets.notifyListeners(SWT.Selection, null); - } - private Composite createDfuComposite(Composite parent) { Composite dfuComposite = new Composite(parent, SWT.NONE); @@ -352,7 +274,7 @@ private void createDfuArgumentField(Composite parent) { Composite dfuComposite = createDfuComposite(parent); - dfuArgumentsField = new Text(parent, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); + dfuArgumentsField = new TextWithButton(parent, SWT.WRAP | SWT.BORDER); createArgumentComponent(dfuComposite, dfuArgumentsField); createVerticalSpacer(dfuComposite, 1); } @@ -448,11 +370,9 @@ public void widgetSelected(SelectionEvent e) break; case JTAG: isFlashOverJtag = true; - fTarget.notifyListeners(SWT.Selection, null); break; case DFU: isFlashOverJtag = false; - comboTargets.notifyListeners(SWT.Selection, null); break; default: break; @@ -585,20 +505,7 @@ public boolean isValid(ILaunchConfiguration launchConfig) setErrorMessage(LaunchMessages.CMainTab_Project_must_be_opened); return false; } - if (flashOverComboButton.getText().contentEquals(FlashInterface.DFU.name()) - && comboTargets.getSelectionIndex() == -1) - { - try - { - setErrorMessage(MessageFormat.format(Messages.CMakeMainTab2_NoDfuTargetSelectedError, - launchBarManager.getActiveLaunchTarget().getId())); - } - catch (CoreException e) - { - Logger.log(e); - } - return false; - } + return isConfigValid && hasProject && validateEncoding(); } @@ -615,23 +522,8 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) { initializeCProject(selectedProject, wc); } - if (!isFlashOverJtag && comboTargets.getSelectionIndex() != -1) - { - saveLaunchTargetName(wc, comboTargets.getItem(comboTargets.getSelectionIndex())); - } - else if (isFlashOverJtag) - { - saveLaunchTargetName(wc, fTarget.getText()); - } - else - { - saveLaunchTargetName(wc, getLaunchTarget()); - } wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, fProjText.getText()); - wc.setAttribute(IDFLaunchConstants.JTAG_FLASH_VOLTAGE, fFlashVoltage.getText()); - wc.setAttribute(IDFLaunchConstants.TARGET_FOR_JTAG, fTarget.getText()); - wc.setAttribute(IDFLaunchConstants.JTAG_BOARD, fTargetName.getText()); wc.setAttribute(IDFLaunchConstants.FLASH_OVER_JTAG, isFlashOverJtag); // For the case, when user wants to edit arguments line somehow and save changes @@ -649,12 +541,6 @@ else if (isFlashOverJtag) } } - private void saveLaunchTargetName(ILaunchConfigurationWorkingCopy wc, String targetName) - { - wc.setAttribute(LAUNCH_TARGET_ATTR, targetName); - LaunchTargetHelper.saveTargetName(targetName); - } - @Override public void initializeFrom(ILaunchConfiguration configuration) { @@ -717,15 +603,6 @@ private void updateFlashOverStatus(ILaunchConfiguration configuration) } if (isFlashOverJtag && !isDfu) { - try - { - initializeJtagComboFields(configuration); - } - catch (CoreException e) - { - Logger.log(e); - } - flashOverComboButton .select(Arrays.asList(flashOverComboButton.getItems()).indexOf(FlashInterface.JTAG.name())); } @@ -742,8 +619,8 @@ private void updateArgumentsWithDefaultFlashCommand(ILaunchConfiguration configu uartFlashCommand.isBlank() ? ESPFlashUtil.getParseableEspFlashCommand(ESPFlashUtil.SERIAL_PORT) : uartFlashCommand); - jtagArgumentsField.setText( - configuration.getAttribute(IDFLaunchConstants.ATTR_JTAG_FLASH_ARGUMENTS, StringUtil.EMPTY)); + jtagArgumentsField.setText(configuration.getAttribute(IDFLaunchConstants.ATTR_JTAG_FLASH_ARGUMENTS, + DEFAULT_JTAG_CONFIG_OPTIONS)); dfuArgumentsField.setText(configuration.getAttribute(IDFLaunchConstants.ATTR_DFU_FLASH_ARGUMENTS, DfuCommandsUtil.getDfuFlashCommand())); @@ -756,135 +633,6 @@ private void updateArgumentsWithDefaultFlashCommand(ILaunchConfiguration configu } - private void initializeJtagComboFields(ILaunchConfiguration configuration) throws CoreException - { - fFlashVoltage - .setText(configuration.getAttribute(IDFLaunchConstants.JTAG_FLASH_VOLTAGE, fFlashVoltage.getText())); - fTarget.setText(configuration.getAttribute(IDFLaunchConstants.TARGET_FOR_JTAG, fTarget.getText())); - fTarget.notifyListeners(SWT.Selection, null); - fTargetName.setText(configuration.getAttribute(IDFLaunchConstants.JTAG_BOARD, fTargetName.getText())); - fTargetName.notifyListeners(SWT.Selection, null); - } - - private void createOpenOcdSetupComponent(Composite parent, String selectedTarget, EspConfigParser parser) - { - Group group = new Group(parent, SWT.NONE); - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 6; - group.setText(Messages.CMakeMainTab2_OpeonOcdSetupGroupTitle); - group.setLayout(gridLayout); - { - Label label = new Label(group, SWT.NONE); - label.setText(Messages.flashVoltageLabel); - label.setToolTipText(Messages.flashVoltageToolTip); - fFlashVoltage = new Combo(group, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); - fFlashVoltage.setItems(parser.getEspFlashVoltages().toArray(new String[0])); - fFlashVoltage.setText("default"); //$NON-NLS-1$ - fFlashVoltage.addSelectionListener(new SelectionAdapter() - { - @Override - public void widgetSelected(SelectionEvent e) - { - fTargetName.notifyListeners(SWT.Selection, null); - } - }); - } - { - Label label = new Label(group, SWT.NONE); - label.setText(Messages.configTargetLabel); - label.setToolTipText(Messages.configTargetToolTip); - fTarget = new Combo(group, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); - fTarget.setItems(parser.getTargets().toArray(new String[0])); - fTarget.setText(selectedTarget); - fTarget.addSelectionListener(new SelectionAdapter() - { - - @Override - public void widgetSelected(SelectionEvent e) - { - int selectedIndex = fTarget.getSelectionIndex(); - String selectedItem = StringUtil.EMPTY; - if (selectedIndex != -1) - { - selectedItem = fTarget.getItem(fTarget.getSelectionIndex()); - } - - boardConfigsMap = parser.getBoardsConfigs(selectedItem); - fTargetName.setItems(parser.getBoardsConfigs(selectedItem).keySet().toArray(new String[0])); - fTargetName.select( - new DefaultBoardProvider().getIndexOfDefaultBoard(selectedItem, fTargetName.getItems())); - updateArgumentsField(); - } - }); - } - { - Label label = new Label(group, SWT.NONE); - label.setText(Messages.configBoardLabel); - label.setToolTipText(Messages.configBoardTooTip); - fTargetName = new Combo(group, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); - fTargetName.setItems(parser.getBoardsConfigs(selectedTarget).keySet().toArray(new String[0])); - boardConfigsMap = parser.getBoardsConfigs(selectedTarget); - fTargetName - .select(new DefaultBoardProvider().getIndexOfDefaultBoard(selectedTarget, fTargetName.getItems())); - fTargetName.addSelectionListener(new SelectionAdapter() - { - @Override - public void widgetSelected(SelectionEvent e) - { - updateArgumentsField(); - } - }); - } - GridData openOcdGroupData = new GridData(SWT.FILL, SWT.NONE, true, true); - group.setLayoutData(openOcdGroupData); - } - - @SuppressWarnings("unchecked") - private void updateArgumentsField() - { - String selectedVoltage = fFlashVoltage.getText(); - String selectedItem = fTargetName.getText(); - String configOptiopns = String.format(EMPTY_CONFIG_OPTIONS, - newVariableExpression(OpenocdDynamicVariable.OPENOCD_PATH), - newVariableExpression(OpenocdDynamicVariable.OPENOCD_EXE), - newVariableExpression(OpenocdDynamicVariable.OPENOCD_SCRIPTS)); - if (!selectedVoltage.equals("default"))//$NON-NLS-1$ - { - configOptiopns = configOptiopns + " -c 'set ESP32_FLASH_VOLTAGE " + selectedVoltage + "'"; //$NON-NLS-1$//$NON-NLS-2$ - } - if (!selectedItem.isEmpty()) - { - for (String config : (String[]) boardConfigsMap.get(selectedItem).toArray(new String[0])) - { - configOptiopns = configOptiopns + " -f " + config; //$NON-NLS-1$ - } - } - jtagArgumentsField.setText(configOptiopns); - } - - private String newVariableExpression(OpenocdDynamicVariable dynamicVariable) - { - return newVariableExpression(dynamicVariable.getValue(), null); - } - - private String getLaunchTarget() - { - String selectedTarget = StringUtil.EMPTY; - try - { - if (launchBarManager.getActiveLaunchConfiguration() != null) - { - selectedTarget = launchBarManager.getActiveLaunchTarget() - .getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY); - } - } - catch (CoreException e) - { - Logger.log(e); - } - return selectedTarget; - } - @Override protected void updateLocation(ILaunchConfiguration configuration) { @@ -933,13 +681,6 @@ protected void updateWorkingDirectory(ILaunchConfiguration configuration) } } - private void scheduleApplyTargetJob() - { - Job applyTargetJob = new ApplyTargetJob(launchBarManager, targetManager, LAUNCH_TARGET_ATTR, - new NewSerialFlashTargetWizard()); - applyTargetJob.schedule(JOB_DELAY_MS); - } - private void createOpenSerialMonitorGroup(Composite mainComposite) { Group group = SWTFactory.createGroup(mainComposite, Messages.CMakeMainTab2_SerialMonitorGroup, 2, 1, @@ -1020,4 +761,10 @@ private boolean isValidEncoding(String enc) } } + private void initializeFromDefaults() + { + uartAgrumentsField.setText(ESPFlashUtil.getParseableEspFlashCommand(ESPFlashUtil.SERIAL_PORT)); + jtagArgumentsField.setText(DEFAULT_JTAG_CONFIG_OPTIONS); + dfuArgumentsField.setText(DfuCommandsUtil.getDfuFlashCommand()); + } } diff --git a/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/Messages.java b/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/Messages.java index bf9b12248..48264b908 100644 --- a/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/Messages.java +++ b/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/Messages.java @@ -51,12 +51,15 @@ public class Messages extends NLS public static String CMakeMainTab2_SerialMonitorBtn; public static String CMakeMainTab2_SerialMonitorGroup; public static String CMakeMainTab2_SerialMonitorEncodingLbl; + public static String jtagGroupLbl; public static String TargetPortUpdatingMessage; public static String TargetPortInformationMessage; public static String TargetPortFoundMessage; public static String TargetPortNotFoundMessage; + public static String AddingTargetJobName; + static { // initialize resource bundle diff --git a/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/NewSerialFlashTargetWizard.java b/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/NewSerialFlashTargetWizard.java index 62ea707cc..46a6fdd0b 100644 --- a/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/NewSerialFlashTargetWizard.java +++ b/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/NewSerialFlashTargetWizard.java @@ -15,72 +15,103 @@ *******************************************************************************/ package com.espressif.idf.launch.serial.ui.internal; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.launchbar.core.target.ILaunchTarget; import org.eclipse.launchbar.core.target.ILaunchTargetManager; +import org.eclipse.launchbar.core.target.ILaunchTargetManager2; import org.eclipse.launchbar.core.target.ILaunchTargetWorkingCopy; import org.eclipse.launchbar.ui.target.LaunchTargetWizard; import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.Preferences; +import com.espressif.idf.core.LaunchBarTargetConstants; import com.espressif.idf.core.build.IDFLaunchConstants; -import com.espressif.idf.launch.serial.SerialFlashLaunchTargetProvider; -public class NewSerialFlashTargetWizard extends LaunchTargetWizard { +public class NewSerialFlashTargetWizard extends LaunchTargetWizard +{ private NewSerialFlashTargetWizardPage page; - public NewSerialFlashTargetWizard() { + public NewSerialFlashTargetWizard() + { setWindowTitle(Messages.NewSerialFlashTargetWizard_Title); } @Override - public void addPages() { + public void addPages() + { super.addPages(); page = new NewSerialFlashTargetWizardPage(getLaunchTarget()); addPage(page); } @Override - public boolean performFinish() { - ILaunchTargetManager manager = Activator.getService(ILaunchTargetManager.class); + public boolean performFinish() + { + ILaunchTargetManager targetManager = Activator.getService(ILaunchTargetManager.class); String typeId = IDFLaunchConstants.ESP_LAUNCH_TARGET_TYPE; String id = page.getTargetName(); - ILaunchTarget target = manager.addLaunchTarget(typeId, id); + ILaunchTarget target = ((ILaunchTargetManager2) targetManager).addLaunchTargetNoNotify(typeId, id); ILaunchTargetWorkingCopy wc = target.getWorkingCopy(); wc.setId(id); wc.setAttribute(ILaunchTarget.ATTR_OS, page.getOS()); wc.setAttribute(ILaunchTarget.ATTR_ARCH, page.getArch()); - wc.setAttribute(SerialFlashLaunchTargetProvider.ATTR_SERIAL_PORT, page.getSerialPortName()); - wc.setAttribute(SerialFlashLaunchTargetProvider.ATTR_IDF_TARGET, page.getIDFTarget()); + wc.setAttribute(LaunchBarTargetConstants.SERIAL_PORT, page.getSerialPortName()); + wc.setAttribute(LaunchBarTargetConstants.TARGET, page.getIDFTarget()); + wc.setAttribute(LaunchBarTargetConstants.BOARD, page.getBoard()); + wc.setAttribute(LaunchBarTargetConstants.FLASH_VOLTAGE, page.getVoltage()); wc.save(); storeLastUsedSerialPort(); + + // adding the target later to trigger LaunchBarListener with proper wc attributes + Job job = new Job(Messages.AddingTargetJobName) + { + + @Override + protected IStatus run(IProgressMonitor monitor) + { + targetManager.addLaunchTarget(typeId, id); + return Status.OK_STATUS; + } + }; + job.schedule(); return true; } - private void storeLastUsedSerialPort() { + private void storeLastUsedSerialPort() + { Preferences preferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); - preferences.put(SerialFlashLaunchTargetProvider.ATTR_SERIAL_PORT, page.getSerialPortName()); + preferences.put(LaunchBarTargetConstants.SERIAL_PORT, page.getSerialPortName()); - try { + try + { // forces the application to save the preferences preferences.flush(); - } catch (BackingStoreException e) { + } + catch (BackingStoreException e) + { e.printStackTrace(); } } @Override - public boolean canDelete() { + public boolean canDelete() + { return true; } @Override - public void performDelete() { + public void performDelete() + { ILaunchTargetManager targetMgr = Activator.getService(ILaunchTargetManager.class); ILaunchTarget target = getLaunchTarget(); - if (target != null) { + if (target != null) + { targetMgr.removeLaunchTarget(target); } } diff --git a/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/NewSerialFlashTargetWizardPage.java b/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/NewSerialFlashTargetWizardPage.java index fc7340d0a..54b9002f6 100644 --- a/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/NewSerialFlashTargetWizardPage.java +++ b/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/NewSerialFlashTargetWizardPage.java @@ -41,16 +41,21 @@ import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; +import org.json.simple.JSONArray; +import com.espressif.idf.core.DefaultBoardProvider; +import com.espressif.idf.core.LaunchBarTargetConstants; import com.espressif.idf.core.logging.Logger; import com.espressif.idf.core.toolchain.ESPToolChainManager; +import com.espressif.idf.core.util.EspConfigParser; import com.espressif.idf.core.util.EspToolCommands; import com.espressif.idf.core.util.StringUtil; -import com.espressif.idf.launch.serial.SerialFlashLaunchTargetProvider; -public class NewSerialFlashTargetWizardPage extends WizardPage { +public class NewSerialFlashTargetWizardPage extends WizardPage +{ private static final String PORT_NAME_DESCRIPTOR_SPLITOR = " "; //$NON-NLS-1$ private static final String OS = "esp32"; //$NON-NLS-1$ @@ -65,9 +70,12 @@ public class NewSerialFlashTargetWizardPage extends WizardPage { private Map> targetPortMap; private TargetPortInfo targetPortInfo; private Display display; - private String port; + private String serialPort; + private Combo fBoardCombo; + private Combo fFlashVoltage; - public NewSerialFlashTargetWizardPage(ILaunchTarget launchTarget) { + public NewSerialFlashTargetWizardPage(ILaunchTarget launchTarget) + { super(NewSerialFlashTargetWizardPage.class.getName()); this.launchTarget = launchTarget; targetPortMap = new HashMap<>(); @@ -77,7 +85,8 @@ public NewSerialFlashTargetWizardPage(ILaunchTarget launchTarget) { } @Override - public void createControl(Composite parent) { + public void createControl(Composite parent) + { Composite comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); setControl(comp); @@ -88,7 +97,8 @@ public void createControl(Composite parent) { nameText = new Text(comp, SWT.BORDER); nameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - if (launchTarget != null) { + if (launchTarget != null) + { nameText.setText(launchTarget.getId()); } @@ -102,157 +112,255 @@ public void createControl(Composite parent) { idfTargetCombo.setItems(idfTargetList.toArray(new String[idfTargetList.size()])); idfTargetCombo.setToolTipText(Messages.NewSerialFlashTargetWizardPage_IDFTargetToolTipMsg); idfTargetCombo.addSelectionListener(new TargetComboSelectionAdapter()); + idfTargetCombo.addSelectionListener(new SelectionAdapter() + { + @Override + public void widgetSelected(SelectionEvent e) + { + EspConfigParser parser = new EspConfigParser(); + String selectedTargetString = idfTargetCombo.getText(); + fBoardCombo.setItems(parser.getBoardsConfigs(selectedTargetString).keySet().toArray(new String[0])); + fBoardCombo.select(new DefaultBoardProvider().getIndexOfDefaultBoard(selectedTargetString, + fBoardCombo.getItems())); + super.widgetSelected(e); + } + }); - if (idfTargetCombo.getItemCount() > 0 && idfTargetCombo.getSelectionIndex() < 0) { + if (idfTargetCombo.getItemCount() > 0 && idfTargetCombo.getSelectionIndex() < 0) + { idfTargetCombo.select(0); } - if (launchTarget != null) { - String idfTarget = launchTarget.getAttribute(SerialFlashLaunchTargetProvider.ATTR_IDF_TARGET, null); - if (idfTarget != null) { - int index = idfTargetList.indexOf(idfTarget); - if (index != -1) { - idfTargetCombo.select(index); - } else { - idfTargetCombo.setText(idfTarget); - } - } - } + createJtagGroup(comp); label = new Label(comp, SWT.NONE); label.setText(Messages.NewSerialFlashTargetWizardPage_SerialPort); serialPortCombo = new Combo(comp, SWT.READ_ONLY); - serialPortCombo.addSelectionListener(new SelectionAdapter() { + serialPortCombo.addSelectionListener(new SelectionAdapter() + { @Override - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(SelectionEvent e) + { display.asyncExec(() -> { - if (targetPortInfo.getState() == Job.RUNNING) { + if (targetPortInfo.getState() == Job.RUNNING) + { targetPortInfo.cancel(); } - port = serialPortCombo.getText().split(PORT_NAME_DESCRIPTOR_SPLITOR)[0]; + serialPort = serialPortCombo.getText().split(PORT_NAME_DESCRIPTOR_SPLITOR)[0]; targetPortInfo.schedule(); }); } }); - try { + try + { String[] ports = SerialPort.list(); - for (String port : ports) { + for (String port : ports) + { StringBuilder comboString = new StringBuilder(); comboString.append(port); - com.fazecast.jSerialComm.SerialPort serialPort = com.fazecast.jSerialComm.SerialPort.getCommPort(port); - if (serialPort != null) { + com.fazecast.jSerialComm.SerialPort serialComPort = com.fazecast.jSerialComm.SerialPort + .getCommPort(port); + if (serialComPort != null) + { comboString.append(PORT_NAME_DESCRIPTOR_SPLITOR); - comboString.append(serialPort.getDescriptivePortName()); + comboString.append(serialComPort.getDescriptivePortName()); } serialPortCombo.add(comboString.toString()); } - if (serialPortCombo.getItemCount() > 0) { - if (launchTarget != null) { - String targetPort = launchTarget.getAttribute(SerialFlashLaunchTargetProvider.ATTR_SERIAL_PORT, - null); - if (targetPort != null) { - com.fazecast.jSerialComm.SerialPort serialPort = com.fazecast.jSerialComm.SerialPort - .getCommPort(targetPort); - targetPort = targetPort + PORT_NAME_DESCRIPTOR_SPLITOR + serialPort.getDescriptivePortName(); - int i = 0; - for (String port : serialPortCombo.getItems()) { - if (port.equals(targetPort)) { - serialPortCombo.select(i); - break; - } - i++; - } - } - } - } - } catch (Exception e) { + } + catch (Exception e) + { Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NewSerialFlashTargetWizardPage_Fetching, e)); } infoArea = new Text(comp, SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI); infoArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); + setDefaults(); + } + + private void setDefaults() + { + if (launchTarget == null) + { + return; + } + setDefaultTargetAndBoard(); + setDefaultVoltage(); + setDefaultSerialPort(); + } + + private void setDefaultVoltage() + { + String flashVoltage = launchTarget.getAttribute(LaunchBarTargetConstants.FLASH_VOLTAGE, null); + if (flashVoltage != null) + { + fFlashVoltage.setText(flashVoltage); + } + } + + private void setDefaultTargetAndBoard() + { + String idfTarget = launchTarget.getAttribute(LaunchBarTargetConstants.TARGET, null); + if (idfTarget != null) + { + int index = getIDFTargetList().indexOf(idfTarget); + if (index != -1) + { + idfTargetCombo.select(index); + } + else + { + idfTargetCombo.setText(idfTarget); + } + idfTargetCombo.notifyListeners(SWT.Selection, null); + } + String board = launchTarget.getAttribute(LaunchBarTargetConstants.BOARD, null); + if (board != null) + { + fBoardCombo.setText(board); + } + + } + + private void setDefaultSerialPort() + { + if (serialPortCombo.getItemCount() < 0 || launchTarget == null) + { + return; + } + String targetPort = launchTarget.getAttribute(LaunchBarTargetConstants.SERIAL_PORT, null); + if (targetPort != null && !targetPort.isEmpty()) + { + int i = 0; + for (String port : serialPortCombo.getItems()) + { + if (port.contains(targetPort)) + { + serialPortCombo.select(i); + break; + } + i++; + } + } + } + + private void createJtagGroup(Composite comp) + { + EspConfigParser parser = new EspConfigParser(); + Group jtaGroup = new Group(comp, SWT.NONE); + jtaGroup.setLayout(new GridLayout(2, false)); + jtaGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1)); + jtaGroup.setText(Messages.jtagGroupLbl); + Label fVoltageLbl = new Label(jtaGroup, SWT.NONE); + fVoltageLbl.setText(Messages.flashVoltageLabel); + fFlashVoltage = new Combo(jtaGroup, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); + fFlashVoltage.setItems(parser.getEspFlashVoltages().toArray(new String[0])); + fFlashVoltage.setText("default"); //$NON-NLS-1$ + Label fTargetLbl = new Label(jtaGroup, SWT.NONE); + fTargetLbl.setText(Messages.configBoardLabel); + fBoardCombo = new Combo(jtaGroup, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); + String selectedTargetString = getIDFTarget(); + Map boardConfigsMap = parser.getBoardsConfigs(selectedTargetString); + fBoardCombo.setItems(boardConfigsMap.keySet().toArray(new String[0])); + fBoardCombo.select( + new DefaultBoardProvider().getIndexOfDefaultBoard(selectedTargetString, fBoardCombo.getItems())); } @Override - public void dispose() { - if (targetPortInfo.getState() == Job.RUNNING) { + public void dispose() + { + if (targetPortInfo.getState() == Job.RUNNING) + { targetPortInfo.cancel(); } super.dispose(); } - public String getTargetName() { + public String getTargetName() + { return nameText.getText(); } - public String getOS() { + public String getOS() + { return getModel(); } - private String getModel() { + public String getVoltage() + { + return fFlashVoltage.getText(); + } + + public String getBoard() + { + return fBoardCombo.getText(); + } + + private String getModel() + { String idfTarget = getIDFTarget(); List idfTargetList = getIDFTargetList(); int index = idfTargetList.indexOf(idfTarget); - if (index != -1) { + if (index != -1) + { return idfTarget; } return OS; } - public String getArch() { - for (IToolChain map : getToolchains()) { - if (map.getProperty(IToolChain.ATTR_OS).equals(getIDFTarget())) { + public String getArch() + { + for (IToolChain map : getToolchains()) + { + if (map.getProperty(IToolChain.ATTR_OS).equals(getIDFTarget())) + { return map.getProperty(IToolChain.ATTR_ARCH); } } return ARCH; } - public String getIDFTarget() { + public String getIDFTarget() + { return idfTargetCombo.getText(); } - public String getSerialPortName() { + public String getSerialPortName() + { return serialPortCombo.getText().split(PORT_NAME_DESCRIPTOR_SPLITOR)[0]; } - private List getIDFTargetList() { + private List getIDFTargetList() + { return new ESPToolChainManager().getAvailableEspTargetList(); } - private Collection getToolchains() { + private Collection getToolchains() + { return new ESPToolChainManager().getAllEspToolchains(); } - private String extractChipFromChipInfoOutput(String chipInfoOutput) { - Pattern pattern = Pattern.compile("Chip is (ESP32[^\\s]*)"); //$NON-NLS-1$ - Matcher matcher = pattern.matcher(chipInfoOutput); - if (matcher.find()) { - String chipType = matcher.group(1); - chipType = chipType.replace(PORT_NAME_DESCRIPTOR_SPLITOR, StringUtil.EMPTY).toLowerCase(); - return chipType; - } - - return StringUtil.EMPTY; - } - - private class TargetComboSelectionAdapter extends SelectionAdapter { + private class TargetComboSelectionAdapter extends SelectionAdapter + { @Override - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(SelectionEvent e) + { String selectedTarget = idfTargetCombo.getText(); List comPortList = targetPortMap.get(selectedTarget); - if (comPortList != null && comPortList.size() > 0) { + if (comPortList != null && !comPortList.isEmpty()) + { serialPortCombo.select(serialPortCombo.indexOf(comPortList.get(0))); infoArea.setText( String.format(Messages.TargetPortInformationMessage, selectedTarget, comPortList.toString())); com.fazecast.jSerialComm.SerialPort serialPort = com.fazecast.jSerialComm.SerialPort .getCommPort(comPortList.get(0)); - if (serialPort != null) { + if (serialPort != null) + { infoArea.setText(serialPort.getDescriptivePortName() + System.lineSeparator() + infoArea.getText()); } } @@ -260,55 +368,75 @@ public void widgetSelected(SelectionEvent e) { } } - private class TargetPortInfo extends Job { - public TargetPortInfo(String name) { + private class TargetPortInfo extends Job + { + public TargetPortInfo(String name) + { super(name); } @Override - protected IStatus run(IProgressMonitor monitor) { + protected IStatus run(IProgressMonitor monitor) + { EspToolCommands espToolCommands = new EspToolCommands(); - String message = String.format(Messages.TargetPortUpdatingMessage, port); + String message = String.format(Messages.TargetPortUpdatingMessage, serialPort); display.asyncExec(() -> { if (infoArea != null && !infoArea.isDisposed()) infoArea.append(System.lineSeparator() + message); }); - try { - Process chipInfoProcess = espToolCommands.chipInformation(port); + try + { + Process chipInfoProcess = espToolCommands.chipInformation(serialPort); InputStream targetIn = chipInfoProcess.getInputStream(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(targetIn)); StringBuilder chipInfo = new StringBuilder(); String readLine; - while ((readLine = bufferedReader.readLine()) != null) { - display.asyncExec(() -> { - infoArea.append("."); //$NON-NLS-1$ - }); + while ((readLine = bufferedReader.readLine()) != null) + { + display.asyncExec(() -> infoArea.append(".")); //$NON-NLS-1$ chipInfo.append(readLine); chipInfo.append(System.lineSeparator()); } String chipType = extractChipFromChipInfoOutput(chipInfo.toString()); display.asyncExec(() -> { - if (StringUtil.isEmpty(chipType)) { + if (StringUtil.isEmpty(chipType)) + { if (infoArea != null && !infoArea.isDisposed()) infoArea.setText(infoArea.getText() + System.lineSeparator() - + String.format(Messages.TargetPortNotFoundMessage, port)); - } else { + + String.format(Messages.TargetPortNotFoundMessage, serialPort)); + } + else + { infoArea.append(System.lineSeparator()); - infoArea.append(String.format(Messages.TargetPortFoundMessage, port, chipType)); + infoArea.append(String.format(Messages.TargetPortFoundMessage, serialPort, chipType)); } }); - } catch (Exception e) { + } + catch (Exception e) + { Logger.log(e); } - display.asyncExec(() -> { - infoArea.append(System.lineSeparator()); - }); + display.asyncExec(() -> infoArea.append(System.lineSeparator())); return Status.OK_STATUS; } + private String extractChipFromChipInfoOutput(String chipInfoOutput) + { + Pattern pattern = Pattern.compile("Chip is (ESP32[^\\s]*)"); //$NON-NLS-1$ + Matcher matcher = pattern.matcher(chipInfoOutput); + if (matcher.find()) + { + String chipType = matcher.group(1); + chipType = chipType.replace(PORT_NAME_DESCRIPTOR_SPLITOR, StringUtil.EMPTY).toLowerCase(); + return chipType; + } + + return StringUtil.EMPTY; + } + } } diff --git a/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/messages.properties b/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/messages.properties index 85ec9250d..8a620938f 100644 --- a/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/messages.properties +++ b/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/messages.properties @@ -41,8 +41,11 @@ IDFLaunchTargetNotFoundMsg2=\ is not found. IDFLaunchTargetNotFoundIDFLaunchTargetNotFoundTitle=IDF Launch Target not found IDFLaunchTargetNotFoundMsg3=Do you want to create a new IDF launch target? +jtagGroupLbl=Settings required for JTAG flash/debug TargetPortUpdatingMessage=Finding Targets for %s port via esptool.py TargetPortInformationMessage=Target: %s\nAvailable Ports: %s TargetPortFoundMessage=Port: %s is Linked to Target: %s TargetPortNotFoundMessage=No suitable target found for Port: %s + +AddingTargetJobName=Adding target... diff --git a/bundles/com.espressif.idf.swt.custom/.classpath b/bundles/com.espressif.idf.swt.custom/.classpath new file mode 100644 index 000000000..5050774b8 --- /dev/null +++ b/bundles/com.espressif.idf.swt.custom/.classpath @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/com.espressif.idf.swt.custom/.gitignore b/bundles/com.espressif.idf.swt.custom/.gitignore index ae3c17260..09e3bc9b2 100644 --- a/bundles/com.espressif.idf.swt.custom/.gitignore +++ b/bundles/com.espressif.idf.swt.custom/.gitignore @@ -1 +1,2 @@ /bin/ +/target/ diff --git a/bundles/com.espressif.idf.swt.custom/.project b/bundles/com.espressif.idf.swt.custom/.project new file mode 100644 index 000000000..0abcc1704 --- /dev/null +++ b/bundles/com.espressif.idf.swt.custom/.project @@ -0,0 +1,34 @@ + + + com.espressif.idf.swt.custom + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/bundles/.settings/org.eclipse.core.resources.prefs b/bundles/com.espressif.idf.swt.custom/.settings/org.eclipse.core.resources.prefs similarity index 100% rename from bundles/.settings/org.eclipse.core.resources.prefs rename to bundles/com.espressif.idf.swt.custom/.settings/org.eclipse.core.resources.prefs diff --git a/bundles/com.espressif.idf.swt.custom/.settings/org.eclipse.jdt.core.prefs b/bundles/com.espressif.idf.swt.custom/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..62ef3488c --- /dev/null +++ b/bundles/com.espressif.idf.swt.custom/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/bundles/com.espressif.idf.swt.custom/.settings/org.eclipse.pde.core.prefs b/bundles/com.espressif.idf.swt.custom/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 000000000..f29e940a0 --- /dev/null +++ b/bundles/com.espressif.idf.swt.custom/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +pluginProject.extensions=false +resolve.requirebundle=false diff --git a/bundles/com.espressif.idf.swt.custom/META-INF/MANIFEST.MF b/bundles/com.espressif.idf.swt.custom/META-INF/MANIFEST.MF new file mode 100644 index 000000000..0e6c30225 --- /dev/null +++ b/bundles/com.espressif.idf.swt.custom/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: com.espressif.idf.swt.custom;singleton:=true +Bundle-Version: 1.0.1.qualifier +Export-Package: com.espressif.idf.swt.custom +Bundle-Activator: com.espressif.idf.swt.custom.Activator +Bundle-Vendor: %Bundle-Vendor +Bundle-RequiredExecutionEnvironment: JavaSE-17 +Automatic-Module-Name: com.espressif.idf.swt.custom +Import-Package: org.osgi.framework;version="1.3.0" +Require-Bundle: org.eclipse.swt, + org.eclipse.jface, + org.eclipse.core.variables, + org.eclipse.equinox.registry, + com.espressif.idf.core, + org.eclipse.core.runtime, + org.eclipse.ui +Bundle-ActivationPolicy: lazy diff --git a/bundles/com.espressif.idf.swt.custom/OSGI-INF/l10n/bundle.properties b/bundles/com.espressif.idf.swt.custom/OSGI-INF/l10n/bundle.properties new file mode 100644 index 000000000..bc425d78b --- /dev/null +++ b/bundles/com.espressif.idf.swt.custom/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,3 @@ +#Properties file for com.espressif.idf.serial.monitor +Bundle-Vendor = ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD +Bundle-Name = ESP-IDF CUSTOM SWT WIDGETS diff --git a/bundles/com.espressif.idf.swt.custom/build.properties b/bundles/com.espressif.idf.swt.custom/build.properties new file mode 100644 index 000000000..c6baffa00 --- /dev/null +++ b/bundles/com.espressif.idf.swt.custom/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + icons/ diff --git a/bundles/com.espressif.idf.swt.custom/icons/hide.png b/bundles/com.espressif.idf.swt.custom/icons/hide.png new file mode 100644 index 000000000..61a0b1c49 Binary files /dev/null and b/bundles/com.espressif.idf.swt.custom/icons/hide.png differ diff --git a/bundles/com.espressif.idf.swt.custom/icons/show.png b/bundles/com.espressif.idf.swt.custom/icons/show.png new file mode 100644 index 000000000..2abe8a2cf Binary files /dev/null and b/bundles/com.espressif.idf.swt.custom/icons/show.png differ diff --git a/bundles/com.espressif.idf.swt.custom/plugin.xml b/bundles/com.espressif.idf.swt.custom/plugin.xml new file mode 100644 index 000000000..36aa2a8e4 --- /dev/null +++ b/bundles/com.espressif.idf.swt.custom/plugin.xml @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/bundles/com.espressif.idf.swt.custom/pom.xml b/bundles/com.espressif.idf.swt.custom/pom.xml new file mode 100644 index 000000000..f8b18eaac --- /dev/null +++ b/bundles/com.espressif.idf.swt.custom/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + com.espressif.idf.swt.custom + 1.0.1-SNAPSHOT + eclipse-plugin + + + com.espressif.idf + com.espressif.idf.bundles + 1.0.0-SNAPSHOT + + diff --git a/bundles/com.espressif.idf.swt.custom/src/com/espressif/idf/swt/custom/Activator.java b/bundles/com.espressif.idf.swt.custom/src/com/espressif/idf/swt/custom/Activator.java new file mode 100644 index 000000000..1a36b92af --- /dev/null +++ b/bundles/com.espressif.idf.swt.custom/src/com/espressif/idf/swt/custom/Activator.java @@ -0,0 +1,26 @@ +package com.espressif.idf.swt.custom; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator +{ + + private static BundleContext context; + + static BundleContext getContext() + { + return context; + } + + public void start(BundleContext bundleContext) throws Exception + { + Activator.context = bundleContext; + } + + public void stop(BundleContext bundleContext) throws Exception + { + Activator.context = null; + } + +} diff --git a/bundles/com.espressif.idf.swt.custom/src/com/espressif/idf/swt/custom/StyledInfoText.java b/bundles/com.espressif.idf.swt.custom/src/com/espressif/idf/swt/custom/StyledInfoText.java new file mode 100644 index 000000000..66d2ffc0d --- /dev/null +++ b/bundles/com.espressif.idf.swt.custom/src/com/espressif/idf/swt/custom/StyledInfoText.java @@ -0,0 +1,156 @@ +package com.espressif.idf.swt.custom; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.GlyphMetrics; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; + +import com.espressif.idf.swt.messages.Messages; + +public class StyledInfoText +{ + private static final String IMAGE_CODE = "\uFFFC"; //$NON-NLS-1$ + private StyledText styledText; + private String text; + private StyleRange linkStyleRange; + + public StyledInfoText(Composite parent) + { + text = String.format(Messages.styledTextInfoDefaultMsg, IMAGE_CODE, Messages.styledTextRestoreDefaultsLinkMsg); + + styledText = new StyledText(parent, SWT.WRAP | SWT.MULTI | SWT.READ_ONLY); + var gd = new GridData(GridData.FILL_HORIZONTAL); + gd.widthHint = 100; + styledText.setLayoutData(gd); + Color grayColor = parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND); + styledText.setBackground(grayColor); + styledText.setText(text); + + linkStyleRange = new StyleRange(text.indexOf(Messages.styledTextRestoreDefaultsLinkMsg), + Messages.styledTextRestoreDefaultsLinkMsg.length(), null, null); + linkStyleRange.underline = true; + linkStyleRange.underlineStyle = SWT.UNDERLINE_LINK; + styledText.setStyleRange(linkStyleRange); + + addAllListeners(); + } + + public void setMouseListenerAction(Runnable action) + { + styledText.addMouseListener(new MouseAdapter() + { + @Override + public void mouseUp(MouseEvent e) + { + int offset = styledText.getOffsetAtPoint(new Point(e.x, e.y)); + if (offset >= linkStyleRange.start && offset < linkStyleRange.start + linkStyleRange.length) + { + action.run(); + } + } + }); + + } + + public int getOffsetAtPoint(Point point) + { + return styledText.getOffsetAtPoint(point); + } + + private void addAllListeners() + { + Image buttonShowImage = ImageDescriptor.createFromURL(getClass().getResource("/icons/show.png")) //$NON-NLS-1$ + .createImage(); + Image infoButtonImage = ImageDescriptor.createFromImage(JFaceResources.getImage("dialog_messasge_info_image")) //$NON-NLS-1$ + .createImage(); + Image[] images = new Image[] { infoButtonImage, buttonShowImage, buttonShowImage }; + int[] offsets = new int[images.length]; + int lastOffset = 0; + for (int i = 0; i < images.length; i++) + { + int offset = text.indexOf(IMAGE_CODE, lastOffset); + offsets[i] = offset; + addImage(images[i], offset, styledText); + lastOffset = offset + 1; + } + addVerifyListener(images, offsets); + addPaintObjectListener(images, offsets); + addDisposeListener(images); + } + + private void addDisposeListener(Image[] images) + { + styledText.addDisposeListener(e -> { + for (Image image : images) + { + image.dispose(); + } + }); + } + + private void addVerifyListener(Image[] images, int[] offsets) + { + styledText.addVerifyListener(e -> { + int start = e.start; + int replaceCharCount = e.end - e.start; + int newCharCount = e.text.length(); + for (int i = 0; i < offsets.length; i++) + { + int offset = offsets[i]; + if (start <= offset && offset < start + replaceCharCount) + { + if (images[i] != null && !images[i].isDisposed()) + { + images[i].dispose(); + images[i] = null; + } + offset = -1; + } + if (offset != -1 && offset >= start) + offset += newCharCount - replaceCharCount; + offsets[i] = offset; + } + }); + } + + private void addPaintObjectListener(Image[] images, int[] offsets) + { + styledText.addPaintObjectListener(event -> { + GC gc = event.gc; + StyleRange style = event.style; + int start = style.start; + for (int i = 0; i < offsets.length; i++) + { + int offset = offsets[i]; + if (start == offset) + { + Image image = images[i]; + int x = event.x; + int y = event.y + event.ascent - style.metrics.ascent + 3; + gc.drawImage(image, x, y); + } + } + }); + } + + private void addImage(Image image, int offset, StyledText styledText) + { + StyleRange style = new StyleRange(); + style.start = offset; + style.length = 1; + Rectangle rect = image.getBounds(); + style.metrics = new GlyphMetrics(rect.height, 0, rect.width); + styledText.setStyleRange(style); + } +} diff --git a/bundles/com.espressif.idf.swt.custom/src/com/espressif/idf/swt/custom/TextWithButton.java b/bundles/com.espressif.idf.swt.custom/src/com/espressif/idf/swt/custom/TextWithButton.java new file mode 100644 index 000000000..464a34b67 --- /dev/null +++ b/bundles/com.espressif.idf.swt.custom/src/com/espressif/idf/swt/custom/TextWithButton.java @@ -0,0 +1,150 @@ +package com.espressif.idf.swt.custom; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.variables.VariablesPlugin; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseTrackAdapter; +import org.eclipse.swt.events.TraverseListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +import com.espressif.idf.core.logging.Logger; + +public class TextWithButton +{ + + private Text text; + private Label button; + private Composite baseComposite; + + public TextWithButton(final Composite parent, int style) + { + baseComposite = new Composite(parent, style); + baseComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + final GridLayout baseCompositeGridLayout = new GridLayout(2, false); + baseCompositeGridLayout.marginHeight = 0; + baseCompositeGridLayout.marginWidth = 0; + baseComposite.setLayout(baseCompositeGridLayout); + + baseComposite.setBackground(new Color(parent.getDisplay(), new RGB(255, 255, 255))); + baseComposite.setBackgroundMode(SWT.INHERIT_FORCE); + + text = new Text(baseComposite, SWT.SINGLE); + text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + Image buttonShowImage = ImageDescriptor.createFromURL(getClass().getResource("/icons/show.png")) //$NON-NLS-1$ + .createImage(); + Image buttonHideImage = ImageDescriptor.createFromURL(getClass().getResource("/icons/hide.png")) //$NON-NLS-1$ + .createImage(); + + button = new Label(baseComposite, SWT.NONE); + button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true)); + button.setImage(buttonShowImage); + button.addMouseListener(new MouseAdapter() + { + String textWhenButtonIsPressed; + + @Override + public void mouseUp(final MouseEvent e) + { + button.setImage(buttonShowImage); + text.setText(textWhenButtonIsPressed); + } + + @Override + public void mouseDown(final MouseEvent e) + { + button.setImage(buttonHideImage); + textWhenButtonIsPressed = text.getText(); + + try + { + text.setText(VariablesPlugin.getDefault().getStringVariableManager() + .performStringSubstitution((textWhenButtonIsPressed), false)); + } + catch (CoreException e1) + { + Logger.log(e1); + } + } + + }); + button.addDisposeListener(e -> { + buttonHideImage.dispose(); + buttonShowImage.dispose(); + }); + } + + public void insert(String variableExpression) + { + text.insert(variableExpression); + } + + public void addMouseTrackListener(MouseTrackAdapter mouseTrackAdapter) + { + text.addMouseTrackListener(mouseTrackAdapter); + } + + public String getText() + { + return text.getText(); + } + + public Control getControl() + { + return text; + } + + public void setToolTipText(String trim) + { + text.setToolTipText(trim); + + } + + public void addModifyListener(ModifyListener modifyListener) + { + text.addModifyListener(modifyListener); + + } + + public void setLayoutData(GridData gd) + { + baseComposite.setLayoutData(gd); + } + + public void setText(String str) + { + text.setText(str); + + } + + public void setEnabled(boolean enabled) + { + text.setEnabled(enabled); + button.setEnabled(enabled); + } + + public void setParent(Group group) + { + baseComposite.setParent(group); + + } + + public void addTraverseListener(TraverseListener traverseListener) + { + baseComposite.addTraverseListener(traverseListener); + + } +} diff --git a/bundles/com.espressif.idf.swt.custom/src/com/espressif/idf/swt/messages/Messages.java b/bundles/com.espressif.idf.swt.custom/src/com/espressif/idf/swt/messages/Messages.java new file mode 100644 index 000000000..972b5d6d0 --- /dev/null +++ b/bundles/com.espressif.idf.swt.custom/src/com/espressif/idf/swt/messages/Messages.java @@ -0,0 +1,20 @@ +package com.espressif.idf.swt.messages; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS +{ + private static final String BUNDLE_NAME = Messages.class.getPackageName() + ".messages"; //$NON-NLS-1$ + public static String styledTextInfoDefaultMsg; + public static String styledTextRestoreDefaultsLinkMsg; + + static + { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() + { + } +} diff --git a/bundles/com.espressif.idf.swt.custom/src/com/espressif/idf/swt/messages/messages.properties b/bundles/com.espressif.idf.swt.custom/src/com/espressif/idf/swt/messages/messages.properties new file mode 100644 index 000000000..54780c3e6 --- /dev/null +++ b/bundles/com.espressif.idf.swt.custom/src/com/espressif/idf/swt/messages/messages.properties @@ -0,0 +1,2 @@ +styledTextInfoDefaultMsg=%1$s Text fields with an icon %1$s use dynamic variables. Click %1$s to see actual values. If the configuration is from an older version, click %2$s to populate fields with dynamic variables. +styledTextRestoreDefaultsLinkMsg=Restore defaults diff --git a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/controls/SerialSettingsPage.java b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/controls/SerialSettingsPage.java index 10b8b677b..78628829b 100644 --- a/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/controls/SerialSettingsPage.java +++ b/bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/controls/SerialSettingsPage.java @@ -38,6 +38,7 @@ import org.osgi.service.prefs.Preferences; import com.espressif.idf.core.IDFProjectNature; +import com.espressif.idf.core.LaunchBarTargetConstants; import com.espressif.idf.core.logging.Logger; import com.espressif.idf.core.util.StringUtil; import com.espressif.idf.terminal.connector.serial.activator.Activator; @@ -56,7 +57,6 @@ public class SerialSettingsPage extends AbstractSettingsPage private Combo portCombo; private Combo projectCombo; - private String portName; private String lastUsedSerialPort; private Text filterText; private String filterConfig; @@ -69,7 +69,7 @@ public SerialSettingsPage(SerialSettings settings, IConfigurationPanel panel) dialogSettings = DialogSettings.getOrCreateSection(Activator.getDefault().getDialogSettings(), this.getClass().getSimpleName()); - portName = dialogSettings.get(SerialSettings.PORT_NAME_ATTR); + dialogSettings.get(SerialSettings.PORT_NAME_ATTR); filterConfig = dialogSettings.get(SerialSettings.MONITOR_FILTER); lastUsedSerialPort = getLastUsedSerialPort(); @@ -79,7 +79,7 @@ public SerialSettingsPage(SerialSettings settings, IConfigurationPanel panel) protected String getLastUsedSerialPort() { Preferences preferences = InstanceScope.INSTANCE.getNode("com.espressif.idf.launch.serial.ui"); //$NON-NLS-1$ - return preferences.get("com.espressif.idf.launch.serial.core.serialPort", ""); //$NON-NLS-1$ //$NON-NLS-2$ + return preferences.get(LaunchBarTargetConstants.SERIAL_PORT, ""); //$NON-NLS-1$ } @Override diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java index 32fca72f5..5bc6d0c52 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java @@ -26,11 +26,11 @@ import org.eclipse.launchbar.core.ILaunchBarManager; import org.eclipse.launchbar.core.ILaunchDescriptor; import org.eclipse.launchbar.core.target.ILaunchTarget; -import org.eclipse.launchbar.ui.ILaunchBarUIManager; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Display; import com.espressif.idf.core.IDFCorePlugin; +import com.espressif.idf.core.LaunchBarTargetConstants; import com.espressif.idf.core.build.IDFLaunchConstants; import com.espressif.idf.core.logging.Logger; import com.espressif.idf.core.util.IDFUtil; @@ -40,14 +40,8 @@ public class LaunchBarListener implements ILaunchBarListener { - private static boolean jtagIgnored = false; private static boolean targetChangeIgnored = false; - public static void setIgnoreJtagTargetChange(boolean status) - { - jtagIgnored = status; - } - public static void setIgnoreTargetChange(boolean status) { targetChangeIgnored = status; @@ -93,8 +87,7 @@ public void activeLaunchTargetChanged(ILaunchTarget target) Display.getDefault().syncExec(() -> { if (target != null) { - String targetName = target.getAttribute("com.espressif.idf.launch.serial.core.idfTarget", //$NON-NLS-1$ - StringUtil.EMPTY); + String targetName = target.getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY); if (!StringUtil.isEmpty(targetName) && (!targetChangeIgnored)) { update(targetName); @@ -145,28 +138,6 @@ private void update(String newTarget) // get current target String currentTarget = new SDKConfigJsonReader((IProject) project).getValue("IDF_TARGET"); //$NON-NLS-1$ - if ((activeConfig.getAttribute(IDFLaunchConstants.FLASH_OVER_JTAG, false) || activeConfig - .getType().getIdentifier().contentEquals(IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE)) - && !jtagIgnored) - { - String targetForJtagFlash = activeConfig.getWorkingCopy() - .getAttribute(IDFLaunchConstants.TARGET_FOR_JTAG, StringUtil.EMPTY); - if (!newTarget.equals(targetForJtagFlash)) - { - boolean isYes = MessageDialog.openQuestion(EclipseUtil.getShell(), - Messages.LaunchBarListener_TargetChanged_Title, - MessageFormat.format(Messages.LaunchBarListener_TargetDontMatch_Msg, newTarget, - targetForJtagFlash, activeConfig.getName())); - if (isYes) - { - ILaunchBarUIManager uiManager = UIPlugin.getService(ILaunchBarUIManager.class); - uiManager.openConfigurationEditor(launchBarManager.getActiveLaunchDescriptor()); - deleteBuildFolder(project, buildLocation); - return; - } - } - } - // If both are not same if (currentTarget != null && !newTarget.equals(currentTarget)) { diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/WriteFlashDialog.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/WriteFlashDialog.java index 6317da3d7..e916686d0 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/WriteFlashDialog.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/WriteFlashDialog.java @@ -35,6 +35,7 @@ import org.eclipse.ui.PlatformUI; import com.espressif.idf.core.IDFCorePlugin; +import com.espressif.idf.core.LaunchBarTargetConstants; import com.espressif.idf.core.logging.Logger; import com.espressif.idf.core.util.BigIntDecoder; import com.espressif.idf.core.util.EspToolCommands; @@ -42,7 +43,6 @@ public class WriteFlashDialog extends TitleAreaDialog { - private static final String ATTR_SERIAL_PORT = "com.espressif.idf.launch.serial.core.serialPort"; //$NON-NLS-1$ private static final String DEFAULT_BIN_NAME = "nvs.bin"; //$NON-NLS-1$ private static final String DEFAULT_OFFSET = "0x8000"; //$NON-NLS-1$ private static final String[] EXTENSIONS = new String[] { "*.bin" }; //$NON-NLS-1$ @@ -150,13 +150,13 @@ private void setDefaults() offsetText.setText(DEFAULT_OFFSET); ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService() .getSelection(); - if (selection instanceof IStructuredSelection) + if (selection instanceof IStructuredSelection sel) { - Object element = ((IStructuredSelection) selection).getFirstElement(); + Object element = sel.getFirstElement(); - if (element instanceof IResource) + if (element instanceof IResource elem) { - project = ((IResource) element).getProject(); + project = elem.getProject(); } } String defaultPathToBin = project.getFile(DEFAULT_BIN_NAME).getLocation().toOSString(); @@ -173,8 +173,8 @@ private void setDefaults() ILaunchBarManager barManager = IDFCorePlugin.getService(ILaunchBarManager.class); try { - String serialPortFromTarget = barManager.getActiveLaunchTarget().getAttribute(ATTR_SERIAL_PORT, - StringUtil.EMPTY); + String serialPortFromTarget = barManager.getActiveLaunchTarget() + .getAttribute(LaunchBarTargetConstants.SERIAL_PORT, StringUtil.EMPTY); comPortsCombo.setText(serialPortFromTarget); if (!serialPortFromTarget.isEmpty()) { diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java index b8e091719..d43476490 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java @@ -37,6 +37,7 @@ import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; import com.espressif.idf.core.IDFConstants; +import com.espressif.idf.core.LaunchBarTargetConstants; import com.espressif.idf.core.build.IDFLaunchConstants; import com.espressif.idf.core.logging.Logger; import com.espressif.idf.core.util.ClangFormatFileHandler; @@ -274,7 +275,7 @@ private ILaunchTarget findSuitableTargetForSelectedTargetString() for (ILaunchTarget iLaunchTarget : targets) { - String idfTarget = iLaunchTarget.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, null); + String idfTarget = iLaunchTarget.getAttribute(LaunchBarTargetConstants.TARGET, null); if (idfTarget.contentEquals(target)) { return iLaunchTarget; diff --git a/bundles/pom.xml b/bundles/pom.xml index 747c9ec8e..9560c1730 100644 --- a/bundles/pom.xml +++ b/bundles/pom.xml @@ -30,6 +30,7 @@ com.espressif.idf.serial.monitor com.espressif.idf.wokwi com.espressif.idf.lsp + com.espressif.idf.swt.custom diff --git a/features/com.espressif.idf.feature/feature.xml b/features/com.espressif.idf.feature/feature.xml index e3de941f5..38718d735 100644 --- a/features/com.espressif.idf.feature/feature.xml +++ b/features/com.espressif.idf.feature/feature.xml @@ -161,4 +161,8 @@ You may add additional accurate notices of copyright ownership. id="com.espressif.idf.lsp" version="0.0.0"/> + + diff --git a/tests/com.espressif.idf.core.test/src/com/espressif/idf/core/actions/test/ApplyTargetJobTest.java b/tests/com.espressif.idf.core.test/src/com/espressif/idf/core/actions/test/ApplyTargetJobTest.java index 61be8e701..fba79a5e0 100644 --- a/tests/com.espressif.idf.core.test/src/com/espressif/idf/core/actions/test/ApplyTargetJobTest.java +++ b/tests/com.espressif.idf.core.test/src/com/espressif/idf/core/actions/test/ApplyTargetJobTest.java @@ -31,8 +31,8 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import com.espressif.idf.core.LaunchBarTargetConstants; import com.espressif.idf.core.actions.test.TestableApplyTargetJob.TestableApplyTargetJobException; -import com.espressif.idf.core.build.IDFLaunchConstants; import com.espressif.idf.core.util.StringUtil; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @@ -91,9 +91,8 @@ void run_whenSuitableTargetFound_shouldSetActiveLaunchTarget() throws CoreExcept { // Available ILaunchTargets in provided by mocked target manager ILaunchTarget target = Mockito.mock(ILaunchTarget.class); - when(target.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY)) - .thenReturn(EXPECTED_TARGET_NAME); - when(target.getAttribute(IDFLaunchConstants.ATTR_SERIAL_PORT, StringUtil.EMPTY)).thenReturn(SERIAL_PORT); + when(target.getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY)).thenReturn(EXPECTED_TARGET_NAME); + when(target.getAttribute(LaunchBarTargetConstants.SERIAL_PORT, StringUtil.EMPTY)).thenReturn(SERIAL_PORT); when(targetManager.getLaunchTargetsOfType(Mockito.anyString())).thenReturn(new ILaunchTarget[] { target }); // Mocked LaunchBarManager has the active launch target with expected target name @@ -114,9 +113,8 @@ void run_whenNoSuitableTargetFound_shouldShowNoTargetMessage() throws CoreExcept ILaunchTarget target = mock(ILaunchTarget.class); ILaunchConfiguration launchConfiguration = mock(ILaunchConfiguration.class); - when(target.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY)) - .thenReturn(EXPECTED_TARGET_NAME); - when(target.getAttribute(IDFLaunchConstants.ATTR_SERIAL_PORT, StringUtil.EMPTY)).thenReturn(SERIAL_PORT); + when(target.getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY)).thenReturn(EXPECTED_TARGET_NAME); + when(target.getAttribute(LaunchBarTargetConstants.SERIAL_PORT, StringUtil.EMPTY)).thenReturn(SERIAL_PORT); when(launchConfiguration.getAttribute(eq(TARGET_NAME_ATTR), anyString())).thenReturn(NOT_EXISTING_TARGET_NAME); when(launchBarManager.getActiveLaunchConfiguration()).thenReturn(launchConfiguration); when(launchBarManager.getActiveLaunchTarget()).thenReturn(target); diff --git a/tests/com.espressif.idf.core.test/src/com/espressif/idf/core/test/OpenocdVariableResolverTest.java b/tests/com.espressif.idf.core.test/src/com/espressif/idf/core/test/OpenocdVariableResolverTest.java index f370fd9cb..5e8407668 100644 --- a/tests/com.espressif.idf.core.test/src/com/espressif/idf/core/test/OpenocdVariableResolverTest.java +++ b/tests/com.espressif.idf.core.test/src/com/espressif/idf/core/test/OpenocdVariableResolverTest.java @@ -29,7 +29,7 @@ class OpenocdVariableResolverTest { private static final String NON_EXISTING_VALUE = "nonExistingValue"; private static final String OPENOCD_SCRIPTS_EXPECTED = "OPENOCD_SCRIPTS"; - private static final String OPENOCD_EXE_EXPECTED = File.separator + "bin" + File.separator + "openocd"; + private static final String OPENOCD_EXE_EXPECTED = "openocd"; private static final String OPENOCD_BIN_PATH_EXPECTED = "openocd" + File.separator + "bin"; private OpenocdVariableResolver variableResolver; @@ -57,7 +57,7 @@ void resolveValue_on_openocd_scripts_dynamic_variable_returns_openocd_scripts() void resolveValue_on_openocd_path_dynamic_variable_returns_openocd_path() { IDynamicVariable dynamicVariable = mock(IDynamicVariable.class); - String expectedResult = Paths.get(OPENOCD_BIN_PATH_EXPECTED).getParent().toString(); + String expectedResult = Paths.get(OPENOCD_BIN_PATH_EXPECTED).toString(); when(dynamicVariable.getName()).thenReturn(OpenocdDynamicVariable.OPENOCD_PATH.getValue()); String actualResult = variableResolver.resolveValue(dynamicVariable, null); @@ -103,5 +103,10 @@ protected Path getOpenocdBinPath(ILaunchConfiguration configuration) return Paths.get(OPENOCD_BIN_PATH_EXPECTED); } + @Override + protected Path getOpenocdExecutable(ILaunchConfiguration configuration) + { + return Paths.get(OPENOCD_EXE_EXPECTED); + } } } diff --git a/tests/com.espressif.idf.core.test/src/com/espressif/idf/core/util/test/LaunchBarNameUtilTest.java b/tests/com.espressif.idf.core.test/src/com/espressif/idf/core/util/test/LaunchBarNameUtilTest.java index 9563c7e7a..98253387a 100644 --- a/tests/com.espressif.idf.core.test/src/com/espressif/idf/core/util/test/LaunchBarNameUtilTest.java +++ b/tests/com.espressif.idf.core.test/src/com/espressif/idf/core/util/test/LaunchBarNameUtilTest.java @@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import com.espressif.idf.core.build.IDFLaunchConstants; +import com.espressif.idf.core.LaunchBarTargetConstants; import com.espressif.idf.core.util.LaunchTargetHelper; import com.espressif.idf.core.util.StringUtil; @@ -74,10 +74,10 @@ void findSuitableTargetForSelectedItem_should_return_correct_launch_target() thr ILaunchTarget target = Mockito.mock(ILaunchTarget.class); Mockito.when(launchTargetManager.getLaunchTargetsOfType(Mockito.anyString())) .thenReturn(new ILaunchTarget[] { target }); - Mockito.when(target.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY)) + Mockito.when(target.getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY)) .thenReturn(EXPECTED_TARGET_NAME); Mockito.when(launchBarManager.getActiveLaunchTarget()).thenReturn(target); - Mockito.when(target.getAttribute(IDFLaunchConstants.ATTR_SERIAL_PORT, StringUtil.EMPTY)) + Mockito.when(target.getAttribute(LaunchBarTargetConstants.SERIAL_PORT, StringUtil.EMPTY)) .thenReturn(SERIAL_PORT); Optional result = LaunchTargetHelper.findSuitableTargetForSelectedItem(launchTargetManager, @@ -85,8 +85,8 @@ void findSuitableTargetForSelectedItem_should_return_correct_launch_target() thr assertTrue(result.isPresent()); assertEquals(EXPECTED_TARGET_NAME, - result.get().getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY)); - assertEquals(SERIAL_PORT, result.get().getAttribute(IDFLaunchConstants.ATTR_SERIAL_PORT, StringUtil.EMPTY)); + result.get().getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY)); + assertEquals(SERIAL_PORT, result.get().getAttribute(LaunchBarTargetConstants.SERIAL_PORT, StringUtil.EMPTY)); } @Test @@ -97,14 +97,14 @@ void findSuitableTargetForSelectedItem_should_return_launch_target_with_correct_ ILaunchTarget target2 = Mockito.mock(ILaunchTarget.class); Mockito.when(launchTargetManager.getLaunchTargetsOfType(Mockito.anyString())) .thenReturn(new ILaunchTarget[] { target, target2 }); - Mockito.when(target.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY)) + Mockito.when(target.getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY)) .thenReturn(EXPECTED_TARGET_NAME); - Mockito.when(target2.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY)) + Mockito.when(target2.getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY)) .thenReturn(EXPECTED_TARGET_NAME); Mockito.when(launchBarManager.getActiveLaunchTarget()).thenReturn(target); - Mockito.when(target.getAttribute(IDFLaunchConstants.ATTR_SERIAL_PORT, StringUtil.EMPTY)) + Mockito.when(target.getAttribute(LaunchBarTargetConstants.SERIAL_PORT, StringUtil.EMPTY)) .thenReturn(SERIAL_PORT); - Mockito.when(target2.getAttribute(IDFLaunchConstants.ATTR_SERIAL_PORT, StringUtil.EMPTY)) + Mockito.when(target2.getAttribute(LaunchBarTargetConstants.SERIAL_PORT, StringUtil.EMPTY)) .thenReturn(FAKE_SERIAL_PORT); Optional result = LaunchTargetHelper.findSuitableTargetForSelectedItem(launchTargetManager, @@ -112,8 +112,8 @@ void findSuitableTargetForSelectedItem_should_return_launch_target_with_correct_ assertTrue(result.isPresent()); assertEquals(EXPECTED_TARGET_NAME, - result.get().getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY)); - assertEquals(SERIAL_PORT, result.get().getAttribute(IDFLaunchConstants.ATTR_SERIAL_PORT, StringUtil.EMPTY)); + result.get().getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY)); + assertEquals(SERIAL_PORT, result.get().getAttribute(LaunchBarTargetConstants.SERIAL_PORT, StringUtil.EMPTY)); } @Test @@ -125,14 +125,14 @@ void findSuitableTargetForSelectedItem_should_return_launch_target_even_if_targe Mockito.when(launchTargetManager.getLaunchTargetsOfType(Mockito.anyString())) .thenReturn(new ILaunchTarget[] { target }); - Mockito.when(target.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY)) + Mockito.when(target.getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY)) .thenReturn(EXPECTED_TARGET_NAME); - Mockito.when(activeTarget.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY)) + Mockito.when(activeTarget.getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY)) .thenReturn(ACTIVE_LAUNCH_TARGET); Mockito.when(launchBarManager.getActiveLaunchTarget()).thenReturn(activeTarget); - Mockito.when(target.getAttribute(IDFLaunchConstants.ATTR_SERIAL_PORT, StringUtil.EMPTY)) + Mockito.when(target.getAttribute(LaunchBarTargetConstants.SERIAL_PORT, StringUtil.EMPTY)) .thenReturn(FAKE_SERIAL_PORT); - Mockito.when(activeTarget.getAttribute(IDFLaunchConstants.ATTR_SERIAL_PORT, StringUtil.EMPTY)) + Mockito.when(activeTarget.getAttribute(LaunchBarTargetConstants.SERIAL_PORT, StringUtil.EMPTY)) .thenReturn(SERIAL_PORT); Optional result = LaunchTargetHelper.findSuitableTargetForSelectedItem(launchTargetManager, @@ -140,7 +140,7 @@ void findSuitableTargetForSelectedItem_should_return_launch_target_even_if_targe assertTrue(result.isPresent()); assertEquals(EXPECTED_TARGET_NAME, - result.get().getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY)); + result.get().getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY)); } @Test @@ -149,7 +149,7 @@ void findSuitableTargetForSelectedItem_should_return_empty_optional() throws Cor ILaunchTarget target = Mockito.mock(ILaunchTarget.class); Mockito.when(launchTargetManager.getLaunchTargetsOfType(Mockito.anyString())) .thenReturn(new ILaunchTarget[] { target }); - Mockito.when(target.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY)) + Mockito.when(target.getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY)) .thenReturn(EXPECTED_TARGET_NAME); Mockito.when(launchBarManager.getActiveLaunchTarget()).thenReturn(target);