From b3bd94ab7037bad1dea71feca77903670aa22448 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Fri, 25 Apr 2008 16:48:31 +0000 Subject: [PATCH] Bug 228265 Removed dependencies to org.eclipse.cdt.launch from org.eclipse.dd.gdb.tests Also cleanup of launch of JUnit tests. --- .../META-INF/MANIFEST.MF | 1 - .../gdb/launching/TestLaunchDelegate.java | 164 ++---------------- 2 files changed, 10 insertions(+), 155 deletions(-) diff --git a/plugins/org.eclipse.dd.tests.gdb/META-INF/MANIFEST.MF b/plugins/org.eclipse.dd.tests.gdb/META-INF/MANIFEST.MF index ab27099db8c..a6bb4590501 100644 --- a/plugins/org.eclipse.dd.tests.gdb/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.dd.tests.gdb/META-INF/MANIFEST.MF @@ -9,7 +9,6 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.dd.dsf, org.eclipse.dd.dsf.debug, org.eclipse.cdt.core, - org.eclipse.cdt.launch, org.eclipse.cdt.debug.core, org.eclipse.dd.mi, org.junit4, diff --git a/plugins/org.eclipse.dd.tests.gdb/src/org/eclipse/dd/tests/gdb/launching/TestLaunchDelegate.java b/plugins/org.eclipse.dd.tests.gdb/src/org/eclipse/dd/tests/gdb/launching/TestLaunchDelegate.java index 89c266f6f17..f16ba60c8c4 100644 --- a/plugins/org.eclipse.dd.tests.gdb/src/org/eclipse/dd/tests/gdb/launching/TestLaunchDelegate.java +++ b/plugins/org.eclipse.dd.tests.gdb/src/org/eclipse/dd/tests/gdb/launching/TestLaunchDelegate.java @@ -10,20 +10,11 @@ *******************************************************************************/ package org.eclipse.dd.tests.gdb.launching; -import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; -import java.io.IOException; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; -import java.util.concurrent.RejectedExecutionException; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; -import org.eclipse.cdt.launch.AbstractCLaunchDelegate; -import org.eclipse.cdt.launch.internal.ui.LaunchMessages; -import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; -import org.eclipse.cdt.utils.pty.PTY; -import org.eclipse.cdt.utils.spawner.ProcessFactory; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -32,39 +23,26 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.dd.dsf.concurrent.ThreadSafe; -import org.eclipse.dd.dsf.debug.model.DsfMemoryBlockRetrieval; -import org.eclipse.dd.dsf.debug.service.IMemory.IMemoryDMContext; -import org.eclipse.dd.dsf.service.DsfServicesTracker; import org.eclipse.dd.gdb.internal.provisional.launching.FinalLaunchSequence; import org.eclipse.dd.gdb.internal.provisional.launching.GdbLaunch; import org.eclipse.dd.gdb.internal.provisional.launching.ServicesLaunchSequence; -import org.eclipse.dd.gdb.internal.provisional.service.command.GDBControl; import org.eclipse.dd.gdb.internal.provisional.service.command.GDBControl.SessionType; import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchManager; -import org.eclipse.debug.core.IStatusHandler; import org.eclipse.debug.core.model.ILaunchConfigurationDelegate2; -import org.eclipse.debug.core.model.IMemoryBlockRetrieval; -import org.eclipse.debug.core.model.IPersistableSourceLocator; -import org.eclipse.debug.core.model.ISourceLocator; -import org.eclipse.debug.core.sourcelookup.IPersistableSourceLocator2; +import org.eclipse.debug.core.model.LaunchConfigurationDelegate; /** - * The launch configuration delegate for the CDI debugger session types. + * The launch configuration delegate for the DSF GDB JUnit tests. */ @ThreadSafe -public class TestLaunchDelegate extends AbstractCLaunchDelegate +public class TestLaunchDelegate extends LaunchConfigurationDelegate implements ILaunchConfigurationDelegate2 { public final static String GDB_DEBUG_MODEL_ID = "org.eclipse.dd.tests.gdb"; //$NON-NLS-1$ - - /* (non-Javadoc) - * @see org.eclipse.cdt.launch.AbstractCLaunchDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor) - */ - @Override + public void launch( ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor ) throws CoreException { if ( monitor == null ) { monitor = new NullProgressMonitor(); @@ -96,16 +74,12 @@ public class TestLaunchDelegate extends AbstractCLaunchDelegate } final GdbLaunch launch = (GdbLaunch)l; - monitor.subTask("Debugging using GDB/MI reference for DSF"); //$NON-NLS-1$ + monitor.subTask("DSF GDB/MI reference JUnit tests"); //$NON-NLS-1$ IPath exePath = new Path(getProgramName(config)); verifyBinary(exePath); - setDefaultSourceLocator(launch, config); - monitor.worked( 1 ); - // Create and invoke the launch sequence to create the debug control and services - // Create and invoke the launch sequence to create the debug control and services final ServicesLaunchSequence servicesLaunchSequence = new ServicesLaunchSequence(launch.getSession(), launch, exePath); launch.getSession().getExecutor().execute(servicesLaunchSequence); @@ -134,29 +108,6 @@ public class TestLaunchDelegate extends AbstractCLaunchDelegate } catch (ExecutionException e1) { throw new DebugException(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Error in final launch sequence", e1.getCause())); //$NON-NLS-1$ } - // Create a memory retrieval and register it with session - try { - launch.getDsfExecutor().submit( new Callable() { - public Object call() throws CoreException { - DsfServicesTracker tracker = new DsfServicesTracker(TestsPlugin.getBundleContext(), launch.getSession().getId()); - GDBControl gdbControl = tracker.getService(GDBControl.class); - if (gdbControl != null) { - IMemoryBlockRetrieval memRetrieval = new DsfMemoryBlockRetrieval( - GDB_DEBUG_MODEL_ID, config, launch.getSession()); - launch.getSession().registerModelAdapter(IMemoryBlockRetrieval.class, memRetrieval); - ((DsfMemoryBlockRetrieval) memRetrieval).initialize((IMemoryDMContext)gdbControl.getControlDMContext()); - } - tracker.dispose(); - return null; - } - }).get(); - } catch (InterruptedException e) { - throw new CoreException(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID, 0, "Interrupted while waiting for get process callable.", e)); //$NON-NLS-1$ - } catch (ExecutionException e) { - throw (CoreException)e.getCause(); - } catch (RejectedExecutionException e) { - throw new CoreException(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID, 0, "Debugger shut down before launch was completed.", e)); //$NON-NLS-1$ - } } /* @@ -168,88 +119,16 @@ public class TestLaunchDelegate extends AbstractCLaunchDelegate } catch (Exception e) { Throwable exception = new FileNotFoundException(exePath.toOSString() + " does not exist"); //$NON-NLS-1$ int code = ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_BINARY; - throw new CoreException(new Status(IStatus.ERROR, getPluginID(), code, exception == null ? "" : exception.getLocalizedMessage(), //$NON-NLS-1$ + throw new CoreException(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID, code, exception == null ? "" : exception.getLocalizedMessage(), //$NON-NLS-1$ exception)); } } - - /* (non-Javadoc) - * @see org.eclipse.cdt.launch.AbstractCLaunchDelegate#getPluginID() - */ - @Override - protected String getPluginID() { - return LaunchUIPlugin.getUniqueIdentifier(); - } - - /** - * Performs a runtime exec on the given command line in the context of the - * specified working directory, and returns the resulting process. If the - * current runtime does not support the specification of a working - * directory, the status handler for error code - * ERR_WORKING_DIRECTORY_NOT_SUPPORTED is queried to see if - * the exec should be re-executed without specifying a working directory. - * - * @param cmdLine - * the command line - * @param workingDirectory - * the working directory, or null - * @return the resulting process or null if the exec is - * cancelled - * @see Runtime - */ - protected Process exec( String[] cmdLine, String[] environ, File workingDirectory, boolean usePty ) throws CoreException { - Process p = null; - try { - if ( workingDirectory == null ) { - p = ProcessFactory.getFactory().exec( cmdLine, environ ); - } - else { - if ( usePty && PTY.isSupported() ) { - p = ProcessFactory.getFactory().exec( cmdLine, environ, workingDirectory, new PTY() ); - } - else { - p = ProcessFactory.getFactory().exec( cmdLine, environ, workingDirectory ); - } - } - } - catch( IOException e ) { - if ( p != null ) { - p.destroy(); - } - abort( "Error starting process.", e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR ); //$NON-NLS-1$ - } - catch( NoSuchMethodError e ) { - // attempting launches on 1.2.* - no ability to set working - // directory - IStatus status = new Status( IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(), ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_NOT_SUPPORTED, LaunchMessages.getString( "LocalDsfLaunchDelegate.9" ), e ); //$NON-NLS-1$ - IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler( status ); - if ( handler != null ) { - Object result = handler.handleStatus( status, this ); - if ( result instanceof Boolean && ((Boolean)result).booleanValue() ) { - p = exec( cmdLine, environ, null, usePty ); - } - } - } - return p; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.launch.AbstractCLaunchDelegate#preLaunchCheck(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) - */ @Override public boolean preLaunchCheck( ILaunchConfiguration config, String mode, IProgressMonitor monitor ) throws CoreException { - // no pre launch check for core file - if ( mode.equals( ILaunchManager.DEBUG_MODE ) ) { - if ( ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE.equals( config.getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN ) ) ) - return true; - } return super.preLaunchCheck( config, mode, monitor ); -// return true; } - /////////////////////////////////////////////////////////////////////////// - // ILaunchConfigurationDelegate2 @Override public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { return false; @@ -262,33 +141,10 @@ public class TestLaunchDelegate extends AbstractCLaunchDelegate @Override public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws CoreException { - // Need to configure the source locator before creating the launch - // because once the launch is created and added to launch manager, - // the adapters will be created for the whole session, including - // the source lookup adapter. - ISourceLocator locator = getSourceLocator(configuration); - - return new GdbLaunch(configuration, mode, locator); + return new GdbLaunch(configuration, mode, null); } - - private ISourceLocator getSourceLocator(ILaunchConfiguration configuration) throws CoreException { - String type = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, (String)null); - if (type == null) { - type = configuration.getType().getSourceLocatorId(); - } - if (type != null) { - IPersistableSourceLocator locator = DebugPlugin.getDefault().getLaunchManager().newSourceLocator(type); - String memento = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String)null); - if (memento == null) { - locator.initializeDefaults(configuration); - } else { - if(locator instanceof IPersistableSourceLocator2) - ((IPersistableSourceLocator2)locator).initializeFromMemento(memento, configuration); - else - locator.initializeFromMemento(memento); - } - return locator; - } - return null; + + private static String getProgramName(ILaunchConfiguration configuration) throws CoreException { + return configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String)null); } }