entlicher commented on a change in pull request #2978: URL: https://github.com/apache/netbeans/pull/2978#discussion_r641966735
########## File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/attach/AttachConfigurations.java ########## @@ -0,0 +1,216 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.java.lsp.server.debugging.attach; + +import com.sun.jdi.Bootstrap; +import com.sun.jdi.VirtualMachineManager; +import com.sun.jdi.connect.AttachingConnector; +import com.sun.jdi.connect.Connector; +import com.sun.tools.attach.AttachNotSupportedException; +import com.sun.tools.attach.VirtualMachine; +import com.sun.tools.attach.VirtualMachineDescriptor; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; + +import org.eclipse.lsp4j.MessageParams; +import org.eclipse.lsp4j.MessageType; + +import org.netbeans.modules.java.lsp.server.protocol.DebugConnector; +import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient; +import org.netbeans.modules.java.lsp.server.protocol.QuickPickItem; +import org.netbeans.modules.java.lsp.server.protocol.ShowQuickPickParams; +import org.openide.util.RequestProcessor; + +/** + * Debugger attach configurations provider. + * + * @author Martin Entlicher + */ +public final class AttachConfigurations { + + static final String NAME_ATTACH_PROCESS = "Attach to Process"; // NOI18N + static final String NAME_ATTACH_SOCKET = "Attach to Port"; // NOI18N + static final String NAME_ATTACH_SHMEM = "Attach to Shared Memory"; // NOI18N + static final String NAME_ATTACH_BY = "Attach by "; // NOI18N + + static final String CONNECTOR_PROCESS = "com.sun.jdi.ProcessAttach"; // NOI18N + static final String CONNECTOR_SOCKET = "com.sun.jdi.SocketAttach"; // NOI18N + static final String CONNECTOR_SHMEM = "com.sun.jdi.SharedMemoryAttach"; // NOI18N + + static final String PROCESS_ARG_PID = "processId"; // NOI18N + static final String SOCKET_ARG_HOST = "hostName"; // NOI18N + static final String SOCKET_ARG_PORT = "port"; // NOI18N + static final String SHMEM_ARG_NAME = "sharedMemoryName"; // NOI18N + + private static final RequestProcessor RP = new RequestProcessor(AttachConfigurations.class); + + private AttachConfigurations() {} + + public static CompletableFuture<Object> findConnectors() { + return CompletableFuture.supplyAsync(() -> { + return listAttachingConnectors(); + }, RP); + } + + private static List<DebugConnector> listAttachingConnectors() { + VirtualMachineManager vmm = Bootstrap.virtualMachineManager (); + List<AttachingConnector> attachingConnectors = vmm.attachingConnectors(); + List<DebugConnector> connectors = new ArrayList<>(5); + String type = "java8+"; // NOI18N + for (AttachingConnector ac : attachingConnectors) { + String connectorName = ac.name(); + Map<String, Connector.Argument> defaultArguments = ac.defaultArguments(); + DebugConnector connector; + switch (connectorName) { + case CONNECTOR_PROCESS: + connector = new DebugConnector(NAME_ATTACH_PROCESS, type, + Collections.singletonList(PROCESS_ARG_PID), + Collections.singletonList("${command:java.attachDebugger.pickProcess}")); // NOI18N Review comment: Good point, thanks. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
