2010-12-16 3 views
1

원격 서버를 모니터링하는 데몬 스크립트를 사용하고 있습니다. 원격 서버가 작동 중일 때 Netbeans가 자동으로 디버거를 원격 서버에 연결하기를 원합니다.Commandline의 Control Netbeans : 쉘 스크립트의 디버거를 연결하십시오.

이 동작을 명령 줄에서 제어 할 수 있습니까? 는 그렇게 터미널 내부

netbeans --attach-debugger 192.168.178.34:9009 

같은 뭔가를 입력하려면? 또는 Netbeans에 내부적으로 액세스해야하는 다른 방법은 무엇입니까? (지금까지는 Netbeans의 "사용자"였기 때문에 내부를 잘 모르고 액세스하는 방법을 잘 모릅니다.)

아니면 Netbeans 플러그인을 작성해야합니까? 그렇다면 그 기능을 추가 할 수있는 좋은 출발점을 제공해 줄 수 있습니까?

답변

3

명령 줄에서 디버거를 부착 할 수있는 옵션이 없으므로 NB 메일 링리스트의 this blog entrythis thread의 도움으로 Netbeans 플러그인을 작성했습니다. 이제 커맨드 라인에서 플러그인 액션을 호출 할 수있게되었습니다.

이렇게 두 가지 중요한 클래스가 포함 된 간단한 NetBeans 모듈을 빌드하십시오. 이 명령 줄 매개 변수를 가져 와서 내 작업에 전달하는 클래스입니다 :

import java.awt.event.ActionEvent; 
import java.util.Collections; 
import java.util.Map; 
import java.util.Set; 
import java.util.logging.Logger; 
import javax.swing.Action; 
import org.netbeans.api.sendopts.CommandException; 
import org.netbeans.spi.sendopts.Env; 
import org.netbeans.spi.sendopts.OptionProcessor; 
import org.netbeans.spi.sendopts.Option; 
import org.openide.ErrorManager; 
import org.openide.cookies.InstanceCookie; 
import org.openide.filesystems.FileObject; 
import org.openide.filesystems.FileUtil; 
import org.openide.loaders.DataObject; 
import org.openide.util.lookup.ServiceProvider; 
import org.openide.windows.WindowManager; 

@ServiceProvider(service = OptionProcessor.class) 
public class TriggerActionCommandLine extends OptionProcessor { 

    //Here we specify "runAction" as the new key in the command, 
    //but it could be any other string you like, of course: 
    private static Option action = Option.requiredArgument(Option.NO_SHORT_NAME, "debug"); 

    private static final Logger logger = Logger.getLogger(AttachDebugger.class.getName()); 

    @Override 
    public Set<org.netbeans.spi.sendopts.Option> getOptions() { 
     return Collections.singleton(action); 
    } 

    @Override 
    protected void process(Env env, Map<Option, String[]> values) throws CommandException { 
     final String[] args = (String[]) values.get(action); 
     if (args.length > 0) { 
      //Set the value to be the first argument from the command line, 
      //i.e., this is "GreetAction", for example: 
      final String ip = args[0]; 
      //Wait until the UI is constructed, 
      //otherwise you will fail to retrieve your action: 
      WindowManager.getDefault().invokeWhenUIReady(new Runnable() { 
       @Override 
       public void run() { 
        //Then find & perform the action: 
        Action a = findAction(AttachDebugger.ACTION_NAME); 
        // forward IP address to Action 
        ActionEvent e = new ActionEvent(this, 1, ip); 
        a.actionPerformed(e); 
       } 
      }); 
     } 
    } 

    public Action findAction(String actionName) { 
     FileObject myActionsFolder = FileUtil.getConfigFile("Actions/PSFActions"); 
     FileObject[] myActionsFolderKids = myActionsFolder.getChildren(); 
     for (FileObject fileObject : myActionsFolderKids) { 
      logger.info(fileObject.getName()); 
      //Probably want to make this more robust, 
      //but the point is that here we find a particular Action: 
      if (fileObject.getName().contains(actionName)) { 
       try { 
        DataObject dob = DataObject.find(fileObject); 
        InstanceCookie ic = dob.getLookup().lookup(InstanceCookie.class); 
        if (ic != null) { 
         Object instance = ic.instanceCreate(); 
         if (instance instanceof Action) { 
          Action a = (Action) instance; 
          return a; 
         } 
        } 
       } catch (Exception e) { 
        ErrorManager.getDefault().notify(ErrorManager.WARNING, e); 
        return null; 
       } 
      } 
     } 
     return null; 
    } 

} 

이 지정된 원격 주소에 디버거 부착 내 플러그인 작업입니다 :

import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
import org.netbeans.api.debugger.jpda.DebuggerStartException; 
import org.netbeans.api.debugger.jpda.JPDADebugger; 
import org.openide.DialogDisplayer; 
import org.openide.NotifyDescriptor; 
import org.openide.awt.ActionRegistration; 
import org.openide.awt.ActionReference; 
import org.openide.awt.ActionReferences; 
import org.openide.awt.ActionID; 
import org.python.util.PythonInterpreter; 

@ActionID(category = "PSFActions", id = "de.mackaz.AttachDebugger") 
@ActionRegistration(displayName = "#CTL_AttachDebuggerAction") 
@ActionReferences({ 
    @ActionReference(path = "Menu/Tools", position = 1800, separatorBefore = 1750, separatorAfter = 1850) 
}) 
public final class AttachDebugger implements ActionListener { 

    private static final Logger logger = Logger.getLogger(AttachDebugger.class.getName()); 

    public static final String ACTION_NAME="AttachDebugger"; 

    @Override 
    public void actionPerformed(ActionEvent e) { 
     String ip; 
     if (!e.getActionCommand().contains("Attach Debugger")) { 
      ip = e.getActionCommand(); 
     } else { 
      ip = lookupIP(); 
     } 
     try { 
      logger.log(Level.INFO, "Attaching Debugger to IP {0}", ip); 
      JPDADebugger.attach(
        ip, 
        9009, 
        new Object[]{null}); 
     } catch (DebuggerStartException ex) { 
      int msgType = NotifyDescriptor.ERROR_MESSAGE; 
      String msg = "Failed to connect debugger to remote IP " + ip; 
      NotifyDescriptor errorDescriptor = new NotifyDescriptor.Message(msg, msgType); 
      DialogDisplayer.getDefault().notify(errorDescriptor); 
     } 
    } 
} 

지금 내가 첨부 할 수 있습니다 특정 주소로 Netbeans 디버거를 호출하여 netbeans/bin/netbeans --debug 192.168.178.79

관련 문제