Skip to content
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

WIP: IEP-957 EBV_Workshop: Filter configurations based on the config type- run or debug #806

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.launchbar.core.ILaunchBarListener;
import org.eclipse.launchbar.core.ILaunchBarManager;

Expand All @@ -28,6 +29,7 @@ public ResourceChangeListener(ILaunchBarListener launchBarListener)
{
this.launchBarListener = launchBarListener;
}

@Override
public void resourceChanged(IResourceChangeEvent event)
{
Expand Down Expand Up @@ -69,7 +71,6 @@ public boolean visit(final IResourceDelta delta) throws CoreException
}
return true;
}

});

}
Expand All @@ -84,11 +85,10 @@ private void updateLaunchBar(IResource resource, int kind, int flags) throws Cor
{
if (resource instanceof IProject)
{
ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class);
IProject project = (IProject) resource;

if ((kind & IResourceDelta.CHANGED) != 0)
if ((flags & IResourceDelta.OPEN) != 0)
{
ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class);
IProject project = (IProject) resource;
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfiguration[] configs = launchManager.getLaunchConfigurations();
// remove launch bar listener before updating launch bar
Expand All @@ -98,7 +98,10 @@ private void updateLaunchBar(IResource resource, int kind, int flags) throws Cor
IResource[] mappedResource = config.getMappedResources();
if (mappedResource != null && mappedResource[0].getProject() == project)
{
if (project.isOpen())
ILaunchMode activeMode = launchBarManager.getActiveLaunchMode();
String activeIdentifier = activeMode == null ? ILaunchManager.RUN_MODE
: activeMode.getIdentifier();
if (project.isOpen() && config.getType().getIdentifier().equals(activeIdentifier))
{
launchBarManager.launchConfigurationAdded(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

import java.io.File;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.core.resources.IProject;
Expand All @@ -16,7 +20,10 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.launchbar.core.ILaunchBarListener;
import org.eclipse.launchbar.core.ILaunchBarManager;
Expand All @@ -36,11 +43,32 @@
public class LaunchBarListener implements ILaunchBarListener
{
private static boolean jtagIgnored = false;
private static ILaunchMode mode;

public static void setIgnoreJtagTargetChange(boolean status)
{
jtagIgnored = status;
}

@Override
public void activeLaunchModeChanged(ILaunchMode mode)
{
try
{
if (LaunchBarListener.mode != null && !LaunchBarListener.mode.equals(mode))
{
filterConfigurationsBySelectedMode(mode);
}
LaunchBarListener.mode = mode;
ILaunchBarListener.super.activeLaunchModeChanged(mode);

}
catch (CoreException e)
{
Logger.log(e);
}
}

@Override
public void activeLaunchTargetChanged(ILaunchTarget target)
{
Expand All @@ -52,7 +80,8 @@ public void run()
{
if (target != null)
{
String targetName = target.getAttribute("com.espressif.idf.launch.serial.core.idfTarget", ""); //$NON-NLS-1$
String targetName = target.getAttribute("com.espressif.idf.launch.serial.core.idfTarget", //$NON-NLS-1$
StringUtil.EMPTY);
if (!StringUtil.isEmpty(targetName))
{
update(targetName);
Expand All @@ -63,17 +92,86 @@ public void run()

}

private void filterConfigurationsBySelectedMode(ILaunchMode mode) throws CoreException
{
ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class);
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfiguration[] configs = launchManager.getLaunchConfigurations();
launchBarManager.removeListener(this);
List<ILaunchConfiguration> debugConfigs = new ArrayList<>();
List<ILaunchConfiguration> launchConfigs = new ArrayList<>();
Set<IProject> projectsToRemove = new HashSet<>();
Set<IProject> projectsToAdd = new HashSet<>();
for (ILaunchConfiguration config : configs)
{
IResource[] mappedResource = config.getMappedResources();
if (mappedResource == null)
continue;

IProject project = mappedResource[0].getProject();
if (project.isOpen())
{
(config.getType().getIdentifier().contentEquals(IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE)
? debugConfigs
: launchConfigs).add(config);
if (launchBarManager.getActiveLaunchMode().getIdentifier().equals(ILaunchManager.DEBUG_MODE))
{
projectsToRemove.add(project);
}
else
{
projectsToAdd.add(project);
}
}
else
{
projectsToRemove.add(project);
}

}
ILaunchMode activeMode = launchBarManager.getActiveLaunchMode();
String activeIdentifier = activeMode == null ? ILaunchManager.RUN_MODE : activeMode.getIdentifier();
if (activeIdentifier.equals(ILaunchManager.RUN_MODE))
updateConfigurationList(launchConfigs, debugConfigs, launchBarManager);
else
updateConfigurationList(debugConfigs, launchConfigs, launchBarManager);

for (IProject project : projectsToAdd)
{
launchBarManager.launchObjectAdded(project);
}
for (IProject project : projectsToRemove)
{
launchBarManager.launchObjectRemoved(project);
}
launchBarManager.addListener(this);
}

private void updateConfigurationList(List<ILaunchConfiguration> configurationsToAdd,
List<ILaunchConfiguration> configurationsToRemove, ILaunchBarManager launchBarManager) throws CoreException
{
for (ILaunchConfiguration config : configurationsToRemove)
{
launchBarManager.launchObjectRemoved(config);
}
for (ILaunchConfiguration config : configurationsToAdd)
{
launchBarManager.launchObjectAdded(config);
}
}

private void update(String newTarget)
{
// Get old IDF target for the project
try
{
ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class);
ILaunchConfiguration activeConfig = launchBarManager.getActiveLaunchConfiguration();
if (activeConfig == null) {
if (activeConfig == null)
{
return;
}

String projectName = activeConfig.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
if (projectName.isEmpty())
{
Expand All @@ -98,25 +196,28 @@ private void update(String newTarget)
{
// get current target
String currentTarget = new SDKConfigJsonReader((IProject) project).getValue("IDF_TARGET"); //$NON-NLS-1$
final String jtag_device_id = activeConfig.getAttribute("org.eclipse.cdt.debug.gdbjtag.core.jtagDeviceId", ""); //$NON-NLS-1$ //$NON-NLS-2$
final String jtag_device_id = activeConfig
.getAttribute("org.eclipse.cdt.debug.gdbjtag.core.jtagDeviceId", ""); //$NON-NLS-1$ //$NON-NLS-2$
if ((activeConfig.getAttribute(IDFLaunchConstants.FLASH_OVER_JTAG, false) && !jtagIgnored)
|| jtag_device_id.contentEquals("ESP-IDF GDB OpenOCD")) //$NON-NLS-1$
{
String targetForJtagFlash = activeConfig.getWorkingCopy().getAttribute(IDFLaunchConstants.TARGET_FOR_JTAG, ""); //$NON-NLS-1$
if (!newTarget.equals(targetForJtagFlash))
String targetForJtagFlash = activeConfig.getWorkingCopy()
.getAttribute(IDFLaunchConstants.TARGET_FOR_JTAG, ""); //$NON-NLS-1$
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) {
if (isYes)
{
ILaunchBarUIManager uiManager = UIPlugin.getService(ILaunchBarUIManager.class);
uiManager.openConfigurationEditor(launchBarManager.getActiveLaunchDescriptor());
return;
}
}
}

// If both are not same
if (currentTarget != null && !newTarget.equals(currentTarget))
{
Expand Down
Loading