-
Notifications
You must be signed in to change notification settings - Fork 133
fix: fixing duplicates configs when creating new project #918
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ea6270e
fix: fixing duplicates configs when creating new project
sigmaaa 3a9a293
fix: refactoring code and adding unit tests
sigmaaa 27eea8c
fix: fixed typo and redundant call
sigmaaa 0735672
fix: changed class name removed const
sigmaaa a9fc856
Merge branch 'master' into IEP-1187
kolipakakondal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/LaunchConfigFinder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /******************************************************************************* | ||
| * Copyright 2024-2025 Espressif Systems (Shanghai) PTE LTD. All rights reserved. | ||
| * Use is subject to license terms. | ||
| *******************************************************************************/ | ||
| package com.espressif.idf.core.util; | ||
|
|
||
| import org.eclipse.core.resources.IProject; | ||
| import org.eclipse.core.resources.IResource; | ||
| import org.eclipse.core.runtime.CoreException; | ||
| import org.eclipse.debug.core.DebugPlugin; | ||
| import org.eclipse.debug.core.ILaunchConfiguration; | ||
| import org.eclipse.debug.core.ILaunchManager; | ||
| import org.eclipse.launchbar.core.ILaunchDescriptor; | ||
|
|
||
| public class LaunchConfigFinder | ||
| { | ||
| private final ILaunchManager launchManager; | ||
|
|
||
| public LaunchConfigFinder() | ||
| { | ||
| launchManager = DebugPlugin.getDefault().getLaunchManager(); | ||
| } | ||
|
|
||
| public LaunchConfigFinder(ILaunchManager launchManager) | ||
| { | ||
| this.launchManager = launchManager; | ||
| } | ||
|
|
||
| public ILaunchConfiguration findAppropriateLaunchConfig(ILaunchDescriptor descriptor, String configIndentifier) | ||
| throws CoreException | ||
| { | ||
| IProject project = descriptor.getAdapter(IProject.class); | ||
| for (ILaunchConfiguration config : launchManager.getLaunchConfigurations()) | ||
| { | ||
| IResource[] mappedResource = config.getMappedResources(); | ||
| if (mappedResource != null && mappedResource.length > 0 && mappedResource[0].getProject().equals(project) | ||
| && config.getType().getIdentifier().contentEquals(configIndentifier)) | ||
| { | ||
| return config; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| } | ||
|
kolipakakondal marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
....espressif.idf.core.test/src/com/espressif/idf/core/util/test/LaunchConfigFinderTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| /******************************************************************************* | ||
| * Copyright 2024-2025 Espressif Systems (Shanghai) PTE LTD. All rights reserved. | ||
| * Use is subject to license terms. | ||
| *******************************************************************************/ | ||
| package com.espressif.idf.core.util.test; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import org.eclipse.core.resources.IProject; | ||
| import org.eclipse.core.runtime.CoreException; | ||
| import org.eclipse.debug.core.ILaunchConfiguration; | ||
| import org.eclipse.debug.core.ILaunchConfigurationType; | ||
| import org.eclipse.debug.core.ILaunchManager; | ||
| import org.eclipse.launchbar.core.ILaunchDescriptor; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.mockito.Mock; | ||
| import org.mockito.Mockito; | ||
|
|
||
| import com.espressif.idf.core.build.IDFLaunchConstants; | ||
| import com.espressif.idf.core.util.LaunchConfigFinder; | ||
|
|
||
| public class LaunchConfigFinderTest | ||
| { | ||
| @Mock | ||
| private ILaunchManager launchManager; | ||
| @Mock | ||
| private ILaunchConfiguration launchConfiguration; | ||
| @Mock | ||
| private IProject project; | ||
| @Mock | ||
| private ILaunchDescriptor launchDescriptor; | ||
|
|
||
| @Mock | ||
| private ILaunchConfigurationType launchConfigType; | ||
|
|
||
| private LaunchConfigFinder launchConfigFinder; | ||
|
|
||
| @Before | ||
| public void setUp() | ||
| { | ||
| this.launchManager = Mockito.mock(ILaunchManager.class); | ||
| this.launchConfiguration = Mockito.mock(ILaunchConfiguration.class); | ||
| this.launchConfigType = Mockito.mock(ILaunchConfigurationType.class); | ||
| this.launchDescriptor = Mockito.mock(ILaunchDescriptor.class); | ||
| this.project = Mockito.mock(IProject.class); | ||
| launchConfigFinder = new LaunchConfigFinder(launchManager); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFindAppropriateDebugConfig() throws CoreException | ||
| { | ||
| when(project.getProject()).thenReturn(project); | ||
| when(launchManager.getLaunchConfigurations()).thenReturn(new ILaunchConfiguration[] { launchConfiguration }); | ||
| when(launchConfiguration.getMappedResources()).thenReturn(new IProject[] { project }); | ||
| when(launchConfiguration.getType()).thenReturn(launchConfigType); | ||
| when(launchConfiguration.getType().getIdentifier()).thenReturn(IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE); | ||
| when(launchDescriptor.getAdapter(IProject.class)).thenReturn(project); | ||
|
|
||
| ILaunchConfiguration result = launchConfigFinder.findAppropriateLaunchConfig(launchDescriptor, | ||
| IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE); | ||
|
|
||
| assertEquals(launchConfiguration, result); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFindExistingLaunchConfiguration() throws CoreException | ||
| { | ||
| when(project.getProject()).thenReturn(project); | ||
| when(launchManager.getLaunchConfigurations()).thenReturn(new ILaunchConfiguration[] { launchConfiguration }); | ||
| when(launchConfiguration.getMappedResources()).thenReturn(new IProject[] { project }); | ||
| when(launchConfiguration.getType()).thenReturn(launchConfigType); | ||
| when(launchConfiguration.getType().getIdentifier()).thenReturn(IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE); | ||
| when(launchDescriptor.getAdapter(IProject.class)).thenReturn(project); | ||
| when(launchConfiguration.getName()).thenReturn("name"); | ||
| when(launchDescriptor.getName()).thenReturn("name"); | ||
|
|
||
| ILaunchConfiguration result = launchConfigFinder.findAppropriateLaunchConfig(launchDescriptor, | ||
| IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE); | ||
|
|
||
| assertEquals(launchConfiguration, result); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFindAppropriateDebugConfig_NoMappedResources() throws CoreException | ||
| { | ||
| when(project.getProject()).thenReturn(project); | ||
| when(launchManager.getLaunchConfigurations()).thenReturn(new ILaunchConfiguration[] { launchConfiguration }); | ||
| when(launchConfiguration.getMappedResources()).thenReturn(null); | ||
| when(launchDescriptor.getAdapter(IProject.class)).thenReturn(project); | ||
|
|
||
| ILaunchConfiguration result = launchConfigFinder.findAppropriateLaunchConfig(launchDescriptor, | ||
| IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE); | ||
|
|
||
| assertEquals(null, result); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFindAppropriateDebugConfig_MappedResourcesAreEmpty() throws CoreException | ||
| { | ||
| when(project.getProject()).thenReturn(project); | ||
| when(launchManager.getLaunchConfigurations()).thenReturn(new ILaunchConfiguration[] { launchConfiguration }); | ||
| when(launchConfiguration.getMappedResources()).thenReturn(new IProject[] {}); | ||
| when(launchDescriptor.getAdapter(IProject.class)).thenReturn(project); | ||
|
|
||
| ILaunchConfiguration result = launchConfigFinder.findAppropriateLaunchConfig(launchDescriptor, | ||
| IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE); | ||
|
|
||
| assertEquals(null, result); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFindAppropriateDebugConfig_NoMatchingType() throws CoreException | ||
| { | ||
| when(project.getProject()).thenReturn(project); | ||
| when(launchManager.getLaunchConfigurations()).thenReturn(new ILaunchConfiguration[] { launchConfiguration }); | ||
| when(launchConfiguration.getMappedResources()).thenReturn(new IProject[] { project }); | ||
| when(launchConfiguration.getType()).thenReturn(launchConfigType); | ||
| when(launchConfigType.getIdentifier()).thenReturn("notDebugType"); | ||
| when(launchDescriptor.getAdapter(IProject.class)).thenReturn(project); | ||
|
|
||
| ILaunchConfiguration result = launchConfigFinder.findAppropriateLaunchConfig(launchDescriptor, | ||
| IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE); | ||
|
|
||
| assertEquals(null, result); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFindExistingLaunchConfiguration_NoMatchingName() throws CoreException | ||
| { | ||
| when(project.getProject()).thenReturn(project); | ||
| when(launchManager.getLaunchConfigurations()).thenReturn(new ILaunchConfiguration[] { launchConfiguration }); | ||
| when(launchConfiguration.getMappedResources()).thenReturn(new IProject[] { project }); | ||
| when(launchConfiguration.getName()).thenReturn("anotherName"); | ||
| when(launchDescriptor.getName()).thenReturn("name"); | ||
| when(launchConfiguration.getType()).thenReturn(launchConfigType); | ||
| when(launchConfiguration.getType().getIdentifier()).thenReturn(IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE); | ||
|
|
||
| ILaunchConfiguration result = launchConfigFinder.findAppropriateLaunchConfig(launchDescriptor, | ||
| IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE); | ||
|
|
||
| assertEquals(null, result); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.