diff --git a/bundles/com.espressif.idf.core/META-INF/MANIFEST.MF b/bundles/com.espressif.idf.core/META-INF/MANIFEST.MF index 7cceb1532..b350d035c 100644 --- a/bundles/com.espressif.idf.core/META-INF/MANIFEST.MF +++ b/bundles/com.espressif.idf.core/META-INF/MANIFEST.MF @@ -63,6 +63,7 @@ Bundle-ClassPath: ., lib/commons-compress-1.21.jar, lib/xz-1.9.jar Import-Package: org.apache.commons.logging, + org.eclipse.cdt.debug.core, org.eclipse.cdt.debug.core.launch, org.eclipse.embedcdt.core, org.eclipse.ui.console diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/ActiveLaunchConfigurationProvider.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/ActiveLaunchConfigurationProvider.java deleted file mode 100644 index f91afa00d..000000000 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/ActiveLaunchConfigurationProvider.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright 2023 Espressif Systems (Shanghai) PTE LTD. All rights reserved. - * Use is subject to license terms. - *******************************************************************************/ -package com.espressif.idf.core.build; - -import java.util.Optional; -import java.util.stream.Stream; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.launchbar.core.ILaunchBarManager; - -import com.espressif.idf.core.IDFCorePlugin; -import com.espressif.idf.core.logging.Logger; - -/** - * This provider allows you getting the active launch configuration from the ILaunchBarManager, even if it is not yet - * initialized. In this case, we look for the initialization Job and join it. - * - * @author Denys Almazov - * - */ -public class ActiveLaunchConfigurationProvider -{ - private ILaunchBarManager launchBarManager; - - public ActiveLaunchConfigurationProvider(ILaunchBarManager launchBarManager) - { - this.launchBarManager = launchBarManager; - } - - public ActiveLaunchConfigurationProvider() - { - this(IDFCorePlugin.getService(ILaunchBarManager.class)); - } - - public ILaunchConfiguration getActiveLaunchConfiguration() throws CoreException - { - ILaunchConfiguration configuration = launchBarManager.getActiveLaunchConfiguration(); - - if (configuration == null) - { - Job[] jobs = Job.getJobManager().find(null); - @SuppressWarnings("restriction") - Optional launchBarInitJob = Stream.of(jobs) - .filter(job -> job.getName() - .equals(org.eclipse.launchbar.core.internal.Messages.LaunchBarManager_0)) - .findAny(); - launchBarInitJob.ifPresent(job -> { - try - { - job.join(); - } - catch (InterruptedException e) - { - Logger.log(e); - Thread.currentThread().interrupt(); - } - }); - configuration = launchBarManager.getActiveLaunchConfiguration(); - } - return configuration; - } -} 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 a37843fc6..1ca246b07 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 @@ -93,7 +93,6 @@ public class IDFBuildConfiguration extends CBuildConfiguration { - private static final ActiveLaunchConfigurationProvider LAUNCH_CONFIG_PROVIDER = new ActiveLaunchConfigurationProvider(); private static final String NINJA = "Ninja"; //$NON-NLS-1$ protected static final String COMPILE_COMMANDS_JSON = "compile_commands.json"; //$NON-NLS-1$ protected static final String COMPONENTS = "components"; //$NON-NLS-1$ @@ -190,16 +189,29 @@ public String getProperty(String name) { try { - ILaunchConfiguration configuration = LAUNCH_CONFIG_PROVIDER.getActiveLaunchConfiguration(); - if (configuration != null - && configuration.getType().getIdentifier().equals(IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE)) + ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class); + ILaunchConfiguration configuration = null; + + if (launchBarManager != null) + { + configuration = launchBarManager.getActiveLaunchConfiguration(); + } + + if (configuration == null) + { + Logger.log("Warning: Launch Bar not ready. Falling back to default properties for " + name); //$NON-NLS-1$ + return super.getProperty(name); + } + + if (configuration.getType().getIdentifier().equals(IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE)) { configuration = new LaunchUtil(DebugPlugin.getDefault().getLaunchManager()) .getBoundConfiguration(configuration); } - String property = configuration == null ? StringUtil.EMPTY - : configuration.getAttribute(name, StringUtil.EMPTY); + + String property = configuration.getAttribute(name, StringUtil.EMPTY); property = property.isBlank() ? getSettings().get(name, StringUtil.EMPTY) : property; + return property; } catch (CoreException e) diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java index 23a2d12ca..2dd8ccb9d 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java @@ -21,13 +21,13 @@ import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.launchbar.core.ILaunchBarManager; import org.eclipse.ui.console.MessageConsole; import org.eclipse.ui.console.MessageConsoleStream; import com.espressif.idf.core.IDFCorePlugin; import com.espressif.idf.core.IDFEnvironmentVariables; import com.espressif.idf.core.ProcessBuilderFactory; -import com.espressif.idf.core.build.ActiveLaunchConfigurationProvider; import com.espressif.idf.core.build.IDFLaunchConstants; import com.espressif.idf.core.logging.Logger; @@ -36,8 +36,7 @@ public class IdfCommandExecutor private final String target; private final MessageConsole console; - private static final String CMAKE_ARGUMENTS = "cmake.arguments"; //$NON-NLS-1$ - private static final ActiveLaunchConfigurationProvider LAUNCH_CONFIG_PROVIDER = new ActiveLaunchConfigurationProvider(); + public IdfCommandExecutor(String target, MessageConsole console) { @@ -100,7 +99,14 @@ public String getProperty(String name) { try { - ILaunchConfiguration configuration = LAUNCH_CONFIG_PROVIDER.getActiveLaunchConfiguration(); + ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class); + ILaunchConfiguration configuration = null; + + if (launchBarManager != null) + { + configuration = launchBarManager.getActiveLaunchConfiguration(); + } + if (configuration != null && configuration.getType().getIdentifier().equals(IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE)) { diff --git a/tests/com.espressif.idf.core.test/src/com/espressif/idf/core/test/ActiveLaunchConfigurationTest.java b/tests/com.espressif.idf.core.test/src/com/espressif/idf/core/test/ActiveLaunchConfigurationTest.java deleted file mode 100644 index 529debca8..000000000 --- a/tests/com.espressif.idf.core.test/src/com/espressif/idf/core/test/ActiveLaunchConfigurationTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright 2023 Espressif Systems (Shanghai) PTE LTD. All rights reserved. - * Use is subject to license terms. - *******************************************************************************/ -package com.espressif.idf.core.test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import org.eclipse.core.runtime.CoreException; -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.debug.core.ILaunchConfiguration; -import org.eclipse.launchbar.core.ILaunchBarManager; -import org.junit.jupiter.api.DisplayNameGeneration; -import org.junit.jupiter.api.DisplayNameGenerator; -import org.junit.jupiter.api.Test; - -import com.espressif.idf.core.build.ActiveLaunchConfigurationProvider; -import com.espressif.idf.core.logging.Logger; - -@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -class ActiveLaunchConfigurationTest -{ - - private static final String EXPECTED_LAUNCH_CONFIG_NAME = "expected_launch_config_name"; - - @Test - void get_active_launch_configuration_returns_expected_config_when_init_launchbar_job_is_active() - throws CoreException - { - ILaunchBarManager launchBarManager = mock(ILaunchBarManager.class); - ILaunchConfiguration launchConfiguration = mock(ILaunchConfiguration.class); - - when(launchConfiguration.getName()).thenReturn(EXPECTED_LAUNCH_CONFIG_NAME); - when(launchBarManager.getActiveLaunchConfiguration()).thenReturn(null); - ActiveLaunchConfigurationProvider provider = new ActiveLaunchConfigurationProvider(launchBarManager); - runInitLaunchBarJob(launchBarManager, launchConfiguration); - ILaunchConfiguration configuration = provider.getActiveLaunchConfiguration(); - - assertEquals(EXPECTED_LAUNCH_CONFIG_NAME, configuration.getName()); - } - - @Test - void get_active_launch_configuration_returns_expected_config_when_init_launchbar_job_is_not_active() - throws CoreException - { - ILaunchBarManager launchBarManager = mock(ILaunchBarManager.class); - ILaunchConfiguration launchConfiguration = mock(ILaunchConfiguration.class); - - when(launchConfiguration.getName()).thenReturn(EXPECTED_LAUNCH_CONFIG_NAME); - when(launchBarManager.getActiveLaunchConfiguration()).thenReturn(launchConfiguration); - ActiveLaunchConfigurationProvider provider = new ActiveLaunchConfigurationProvider(launchBarManager); - ILaunchConfiguration configuration = provider.getActiveLaunchConfiguration(); - - assertEquals(EXPECTED_LAUNCH_CONFIG_NAME, configuration.getName()); - } - - private void runInitLaunchBarJob(ILaunchBarManager launchBarManager, ILaunchConfiguration launchConfiguration) - { - @SuppressWarnings("restriction") - Job job = new Job(org.eclipse.launchbar.core.internal.Messages.LaunchBarManager_0) - { - - protected IStatus run(IProgressMonitor monitor) - { - try - { - when(launchBarManager.getActiveLaunchConfiguration()).thenReturn(launchConfiguration); - } - catch (CoreException e) - { - Logger.log(e); - } - return Status.OK_STATUS; - } - }; - job.schedule(); - } - -}