-
Notifications
You must be signed in to change notification settings - Fork 134
GH #798: At execution Espressif-IDE getting 'Cannot invoke "org.eclipse.debug.core.ILaunchConfiguration.getType()" because "configuration" is null' #804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /******************************************************************************* | ||
| * 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; | ||
|
|
||
| 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<Job> launchBarInitJob = Stream.of(jobs) | ||
| .filter(job -> job.getName() | ||
| .equals(org.eclipse.launchbar.core.internal.Messages.LaunchBarManager_0)) | ||
| .findAny(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can avoid referencing internal classes and messages if possible. In this case if we can copy the message and compare it directly
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @kolipakakondal, thanks for your feedback. In this case, we rely on this message because it's the name of the Job, so if this message is changed on the eclipse side, this code just won't work and we won't know about it |
||
| launchBarInitJob.ifPresent(job -> { | ||
| try | ||
| { | ||
| job.join(); | ||
| } | ||
| catch (InterruptedException e) | ||
| { | ||
| Logger.log(e); | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| }); | ||
| configuration = launchBarManager.getActiveLaunchConfiguration(); | ||
| } | ||
| return configuration; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /******************************************************************************* | ||
| * 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.Assert.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(); | ||
| } | ||
|
|
||
| } |
Uh oh!
There was an error while loading. Please reload this page.