debug插件

官网:https://plugins.jetbrains.com/docs/intellij/welcome.html

1、创建插件项目

在这里插入图片描述

配置文件说明

plugin.xml

<idea-plugin>
    
  <!-- 插件唯一id,不能和其他插件项目重复,所以推荐使用com.xxx.xxx的格式
       插件不同版本之间不能更改,若没有指定,则与插件名称相同 -->
  <id>com.your.company.unique.plugin.id</id>
   
  <!-- 插件名称,别人在官方插件库搜索你的插件时使用的名称 -->
  <name>Plugin display name here</name>
  
  <!-- 插件版本号 -->
  <version>1.0</version>
    
  <!-- 供应商主页和email(不能使用默认值,必须修改成自己的)-->
  <vendor email="support@yourcompany.com" url="http://www.yourcompany.com">YourCompany</vendor>
  <!-- 插件的描述 (不能使用默认值,必须修改成自己的。并且需要大于40个字符)-->
  <description><![CDATA[
      Enter short description for your plugin here.<br>
      <em>most HTML tags may be used</em>
    ]]></description>
  <!-- 插件版本变更信息,支持HTML标签;
       将展示在 settings | Plugins 对话框和插件仓库的Web页面 -->
  <change-notes><![CDATA[
      Add change notes here.<br>
      <em>most HTML tags may be used</em>
    ]]>
  </change-notes>

 <!-- 插件兼容IDEAbuild 号-->
  <idea-version since-build="173.0"/>

  <!-- 插件所依赖的其他插件的id -->
  <depends>com.intellij.modules.platform</depends>

  <extensions defaultExtensionNs="com.intellij">
  <!-- 声明该插件对IDEA core或其他插件的扩展 -->
  </extensions>

  <!-- 编写插件动作 -->
  <actions>
  </actions>

</idea-plugin>

2、创建action

新建Plugin DevKit > Action

在这里插入图片描述
生成的对应代码:

  <actions>
    <!-- Add your actions here -->
    <!-- IronMan为将来菜单中的名字 -->
    <action id="DebugMine" class="com.DebugParse" text="IronMan" description="自动获取配置填充debug">
      <!-- group-id 将菜单挂在ToolsMenu菜单下,位置为first -->
      <add-to-group group-id="ToolsMenu" anchor="first"/>
    </action>
  </actions>
public class DebugParse extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {

        String env = Messages.showInputDialog("请输入环境", "环境", null);
        if (env == null || "".equals(env.trim())) {
            Messages.showMessageDialog("请输入环境信息", "Info", null);
            return;
        }

        Project project = e.getProject();
        String name = project.getName();

        String cmd = getCmdReturn(name, env);
        if (cmd == null) {//查到多个,用项目名全名再查一次
            @SystemIndependent String basePath = project.getBasePath();
            String name2 = Arrays.asList(basePath.split("/")).stream().filter(x -> x.contains(name)).collect(Collectors.toList()).get(0);
            cmd = getCmdReturn(name2, env);
            if (cmd == null) {
                Messages.showMessageDialog("当前项目未查询到debug端口", "Warn", null);
                return;
            }
        }


        List<String> collect = Arrays.asList(cmd.split(" ")).stream()
                .filter(x -> x != null && !"".equals(x.trim()))
                .collect(Collectors.toList());

        String pName = collect.get(0);
        String ip = collect.get(2);

        Messages.showInfoMessage(pName + " " + ip, "Info");

        setRemoteConfig(project, env, ip);
    }

    private String getCmdReturn(String name, String env){
        List<String> keys = Arrays.asList(name.split("-"));

        Shell shell = new Shell("xx_ip", "xx_userName", "xx_pwd");
		
		//拼接命令
        String cmd = "kubectl get service -n " + env + " | ";

        List<String> collect = keys.stream().map(x -> String.format(" grep '%s'", x)).collect(Collectors.toList());

        for (int i = collect.size(); i > 0; i--) {
            String newCmd = cmd + String.join("|", collect.subList(0, i));
            String execute = cmdExe(shell, newCmd);
            System.out.println("cmd:" + cmd + "\n" + "return:" + execute);
            if (execute != null) {
                return execute;
            }
        }

        return null;
    }


    private String cmdExe(Shell shell, String cmd){
        List<String> execute = shell.execute(cmd);
        if (execute != null) {
            return execute.get(0);
        }
        return null;
    }


    private void setRemoteConfig(Project project, String env, String host){
        RunConfiguration setting = new RemoteConfigurationType()
                .createTemplateConfiguration(Objects.requireNonNull(project));

        //这里可以根据自己需要配置配置源
        RemoteConfiguration remote = (RemoteConfiguration) setting;
        remote.setName(env + "_remote");
        remote.HOST = host;
        remote.PORT = "8000";

        RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project);
        RunnerAndConfigurationSettingsImpl configurationSettings = new RunnerAndConfigurationSettingsImpl(runManager,
                setting, false, RunConfigurationLevel.WORKSPACE);
        SingleConfigurationConfigurable singleConfigurationConfigurable = SingleConfigurationConfigurable
                .editSettings(configurationSettings, null);
        RunnerAndConfigurationSettings settings =
                (RunnerAndConfigurationSettings) singleConfigurationConfigurable.getSettings();
        runManager.addConfiguration(settings);

        //选中
        runManager.setSelectedConfiguration(settings);
    }

}

异常

在这里插入图片描述
版本问题导致的异常
在plugin.xml中添加相关依赖
com.intellij.java

3、打包

在这里插入图片描述

4、导入

setting --> plugins --> installed --> install plugin from disk --> 选中 --> apply

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
vscode debug插件是一款用于在Visual Studio Code编辑器中进行代码调试的插件。你可以使用该插件来设置断点、观察变量、单步执行代码、查看调用栈等操作,以帮助你更方便地进行程序调试。根据你提供的引用信息,我找到了两个相关的链接,分别是【01】和【02】。你可以参考这些链接中的文档来了解更多关于vscode debug插件的详细信息和使用方法。另外,如果你在配置调试插件时遇到问题,我也可以提供一些常见的解决方法,以帮助你解决断点灰色、无法调试的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [如何用VsCode进行Debug](https://blog.csdn.net/weixin_42962086/article/details/123274273)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [VSCode配置 Debugger for Chrome插件(终于搞定了..)](https://blog.csdn.net/weixin_45295262/article/details/110299445)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值