Search in sources :

Example 1 with IVMConnector

use of org.eclipse.jdt.launching.IVMConnector in project sling by apache.

the class JVMDebuggerConnection method connectInDebugMode.

boolean connectInDebugMode(ILaunch launch, IServer iServer, IProgressMonitor monitor) throws CoreException {
    long start = System.currentTimeMillis();
    this.launch = launch;
    boolean success = false;
    IVMConnector connector = null;
    connector = JavaRuntime.getVMConnector(IJavaLaunchConfigurationConstants.ID_SOCKET_ATTACH_VM_CONNECTOR);
    if (connector == null) {
        connector = JavaRuntime.getDefaultVMConnector();
    }
    if (connector == null) {
        throw new CoreException(new Status(IStatus.ERROR, "org.apache.sling.ide.eclipse.wst", "Could not get jvm connctor"));
    }
    ISlingLaunchpadServer launchpadServer = (ISlingLaunchpadServer) iServer.loadAdapter(SlingLaunchpadServer.class, monitor);
    ISlingLaunchpadConfiguration configuration = launchpadServer.getConfiguration();
    int debugPort = configuration.getDebugPort();
    if (debugPort <= 0) {
        throw new CoreException(new Status(IStatus.ERROR, "org.apache.sling.ide.eclipse.wst", "debug port not configured"));
    }
    Map<String, String> connectMap = new HashMap<>();
    connectMap.put("hostname", iServer.getHost());
    connectMap.put("port", String.valueOf(debugPort));
    //			Map argMap = null;//configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CONNECT_MAP, (Map)null);
    int connectTimeout = JavaRuntime.getPreferences().getInt(JavaRuntime.PREF_CONNECT_TIMEOUT);
    //$NON-NLS-1$
    connectMap.put("timeout", Integer.toString(connectTimeout));
    // set the default source locator if required
    @SuppressWarnings("restriction") ISourceLookupDirector sourceLocator = new JavaSourceLookupDirector();
    sourceLocator.setSourcePathComputer(DebugPlugin.getDefault().getLaunchManager().getSourcePathComputer(//$NON-NLS-1$
    "org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer"));
    List<IRuntimeClasspathEntry> classpathEntries = new ArrayList<>();
    // 1. add java projects first
    for (IJavaProject javaProject : ProjectHelper.getAllJavaProjects()) {
        classpathEntries.add(JavaRuntime.newProjectRuntimeClasspathEntry(javaProject));
    }
    // 2. add the other modules deployed on server
    // 5/30
    ProgressUtils.advance(monitor, 5);
    // 30 - 5 - 1
    int workTicksForReferences = 24;
    SourceReferenceResolver resolver = Activator.getDefault().getSourceReferenceResolver();
    if (resolver != null && configuration.resolveSourcesInDebugMode()) {
        try {
            List<SourceReference> references = osgiClient.findSourceReferences();
            SubMonitor subMonitor = SubMonitor.convert(monitor, "Resolving source references", workTicksForReferences).setWorkRemaining(references.size());
            for (SourceReference reference : references) {
                try {
                    subMonitor.setTaskName("Resolving source reference: " + reference);
                    IRuntimeClasspathEntry classpathEntry = resolver.resolve(reference);
                    if (classpathEntry != null) {
                        classpathEntries.add(classpathEntry);
                    }
                    ProgressUtils.advance(subMonitor, 1);
                } catch (CoreException e) {
                    // don't fail the debug launch for artifact resolution errors
                    Activator.getDefault().getPluginLogger().warn("Failed resolving source reference", e);
                }
            }
            // 29/30
            subMonitor.done();
        } catch (OsgiClientException e1) {
            throw new CoreException(new Status(Status.ERROR, Activator.PLUGIN_ID, e1.getMessage(), e1));
        }
    } else {
        monitor.worked(workTicksForReferences);
    }
    // 3. add the JRE entry
    classpathEntries.add(JavaRuntime.computeJREEntry(launch.getLaunchConfiguration()));
    IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveSourceLookupPath(classpathEntries.toArray(new IRuntimeClasspathEntry[0]), launch.getLaunchConfiguration());
    sourceLocator.setSourceContainers(JavaRuntime.getSourceContainers(resolved));
    sourceLocator.initializeParticipants();
    launch.setSourceLocator(sourceLocator);
    // connect to remote VM
    try {
        // 30/30
        connector.connect(connectMap, monitor, launch);
        success = true;
        long elapsedMillis = System.currentTimeMillis() - start;
        Activator.getDefault().getPluginLogger().tracePerformance("Debug connection to {0}", elapsedMillis, iServer.getName());
    } catch (Exception e) {
        throw new CoreException(new Status(IStatus.ERROR, "org.apache.sling.ide.eclipse.wst", "could not establish debug connection to " + iServer.getHost() + " : " + debugPort, e));
    }
    return success;
}
Also used : HashMap(java.util.HashMap) JavaSourceLookupDirector(org.eclipse.jdt.internal.launching.JavaSourceLookupDirector) ISourceLookupDirector(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector) ArrayList(java.util.ArrayList) SourceReferenceResolver(org.apache.sling.ide.eclipse.core.launch.SourceReferenceResolver) IVMConnector(org.eclipse.jdt.launching.IVMConnector) SourceReference(org.apache.sling.ide.osgi.SourceReference) OsgiClientException(org.apache.sling.ide.osgi.OsgiClientException) ISlingLaunchpadServer(org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) SubMonitor(org.eclipse.core.runtime.SubMonitor) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) CoreException(org.eclipse.core.runtime.CoreException) DebugException(org.eclipse.debug.core.DebugException) OsgiClientException(org.apache.sling.ide.osgi.OsgiClientException) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) ISlingLaunchpadConfiguration(org.apache.sling.ide.eclipse.core.ISlingLaunchpadConfiguration) ISlingLaunchpadServer(org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer)

Example 2 with IVMConnector

use of org.eclipse.jdt.launching.IVMConnector in project liferay-ide by liferay.

the class RemoteLaunchConfigDelegate method debugLaunch.

@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
protected void debugLaunch(IServer server, ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    // setup the run launch so we get console monitor
    runLaunch(server, configuration, launch, monitor);
    String connectorId = getVMConnectorId(configuration);
    IVMConnector connector = null;
    if (connectorId == null) {
        connector = JavaRuntime.getDefaultVMConnector();
    } else {
        connector = JavaRuntime.getVMConnector(connectorId);
    }
    if (connector == null) {
        abort(// $NON-NLS-1$
        "Debugging connector not specified.", // $NON-NLS-1$
        null, IJavaLaunchConfigurationConstants.ERR_CONNECTOR_NOT_AVAILABLE);
    }
    Map connectMap = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CONNECT_MAP, (Map) null);
    int connectTimeout = JavaRuntime.getPreferences().getInt(JavaRuntime.PREF_CONNECT_TIMEOUT);
    // $NON-NLS-1$
    connectMap.put("timeout", StringPool.EMPTY + connectTimeout);
    // check for cancellation
    if (monitor.isCanceled()) {
        return;
    }
    if (!launch.isTerminated()) {
        // connect to remote VM
        connector.connect(connectMap, monitor, launch);
    }
    // check for cancellation
    if (monitor.isCanceled() || launch.isTerminated()) {
        IDebugTarget[] debugTargets = launch.getDebugTargets();
        for (int i = 0; i < debugTargets.length; i++) {
            IDebugTarget target = debugTargets[i];
            if (target.canDisconnect()) {
                target.disconnect();
            }
        }
        return;
    }
    monitor.done();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IVMConnector(org.eclipse.jdt.launching.IVMConnector) IDebugTarget(org.eclipse.debug.core.model.IDebugTarget) Map(java.util.Map)

Example 3 with IVMConnector

use of org.eclipse.jdt.launching.IVMConnector in project bndtools by bndtools.

the class LaunchThread method doDebug.

void doDebug(IProgressMonitor monitor) throws InterruptedException {
    monitor.setTaskName("Connecting debugger " + session.getName() + " to " + session.getHost() + ":" + session.getJdb());
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("hostname", session.getHost());
    parameters.put("port", session.getJdb() + "");
    parameters.put("timeout", session.getTimeout() + "");
    IVMConnector connector = JavaRuntime.getDefaultVMConnector();
    while (!monitor.isCanceled()) {
        try {
            connector.connect(parameters, monitor, launch);
            break;
        } catch (Exception e) {
            Thread.sleep(500);
        }
    }
}
Also used : IVMConnector(org.eclipse.jdt.launching.IVMConnector) HashMap(java.util.HashMap) DebugException(org.eclipse.debug.core.DebugException)

Example 4 with IVMConnector

use of org.eclipse.jdt.launching.IVMConnector in project webtools.servertools by eclipse.

the class ExternalDebugLaunchConfigurationDelegate method launch.

/* (non-Javadoc)
     * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
     */
@SuppressWarnings({ "unchecked", "null" })
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    monitor.beginTask(NLS.bind(GenericServerCoreMessages.attachingToExternalGenericServer, new String[] { configuration.getName() }), 3);
    // check for cancellation
    if (monitor.isCanceled()) {
        return;
    }
    monitor.subTask(GenericServerCoreMessages.verifyingExternalServerDebuggingLaunchAttributes);
    String connectorId = getVMConnectorId(configuration);
    IVMConnector connector = null;
    if (connectorId == null) {
        connector = JavaRuntime.getDefaultVMConnector();
    } else {
        connector = JavaRuntime.getVMConnector(connectorId);
    }
    if (connector == null) {
        abort(GenericServerCoreMessages.externalServerDebugConnectorNotSpecified, null, IJavaLaunchConfigurationConstants.ERR_CONNECTOR_NOT_AVAILABLE);
    }
    Map argMap = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CONNECT_MAP, (Map) null);
    int connectTimeout = JavaRuntime.getPreferences().getInt(JavaRuntime.PREF_CONNECT_TIMEOUT);
    // $NON-NLS-1$//$NON-NLS-2$
    argMap.put("timeout", "" + connectTimeout);
    // check for cancellation
    if (monitor.isCanceled()) {
        return;
    }
    monitor.worked(1);
    monitor.subTask(GenericServerCoreMessages.creatingExternalServerDebuggingSourceLocator);
    // set the default source locator if required
    setDefaultSourceLocator(launch, configuration);
    monitor.worked(1);
    // connect to remote VM
    connector.connect(argMap, monitor, launch);
    // check for cancellation
    if (monitor.isCanceled()) {
        IDebugTarget[] debugTargets = launch.getDebugTargets();
        for (int i = 0; i < debugTargets.length; i++) {
            IDebugTarget target = debugTargets[i];
            if (target.canDisconnect()) {
                target.disconnect();
            }
        }
        return;
    }
    monitor.done();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IVMConnector(org.eclipse.jdt.launching.IVMConnector) IDebugTarget(org.eclipse.debug.core.model.IDebugTarget) Map(java.util.Map)

Aggregations

IVMConnector (org.eclipse.jdt.launching.IVMConnector)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 DebugException (org.eclipse.debug.core.DebugException)2 IDebugTarget (org.eclipse.debug.core.model.IDebugTarget)2 ArrayList (java.util.ArrayList)1 ISlingLaunchpadConfiguration (org.apache.sling.ide.eclipse.core.ISlingLaunchpadConfiguration)1 ISlingLaunchpadServer (org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer)1 SourceReferenceResolver (org.apache.sling.ide.eclipse.core.launch.SourceReferenceResolver)1 OsgiClientException (org.apache.sling.ide.osgi.OsgiClientException)1 SourceReference (org.apache.sling.ide.osgi.SourceReference)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 ISourceLookupDirector (org.eclipse.debug.core.sourcelookup.ISourceLookupDirector)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 JavaSourceLookupDirector (org.eclipse.jdt.internal.launching.JavaSourceLookupDirector)1 IRuntimeClasspathEntry (org.eclipse.jdt.launching.IRuntimeClasspathEntry)1