如何在 IntelliJ 插件中“注册”新的模块类型?

2023-12-20

我是 IntelliJ 插件开发的初学者,但我希望我的插件在“新项目”/“新模块”窗口中注册新的模块类型。

我已经搜索了插件开发人员的文档,但找不到任何有用的东西。我还查看了 Kotlin 和 Scala 等现有插件,它们也添加了新的模块类型,但我不知道如何让完成的 ModuleType 显示在上述对话框中。

我必须在plugin.xml 文件中更改什么?我已经添加了扩展并为 ModuleType、ModuleBuilder 和 ModuleConfigurationExtensionProvider 创建了 java 类,但这并没有改变任何内容。

我希望你能帮助我并提前致谢。


这可以通过 IntelliJ IDEA 的“新建项目向导”功能来实现,通过提供 ModuleBuilder 的模块/项目类型实现类,即通过扩展 IntelliJ IDEA 提供的相同扩展点 (com.intellij)。

您需要在您的plugin.xml 中进行以下更改,以便在“新建项目向导”项目/模块类型列表中显示您的新模块/项目类型。

<extensions defaultExtensionNs="com.intellij">
    <moduleBuilder builderClass="com.yourcompany.wizards.YourModuleBuilder"/>
</extensions>

为您的 ModuleBuilder 类提供包建造者类属性,够了。

以下是 ModuleBuilder 实现示例:

public class AsposeJavaModuleBuilder extends ModuleBuilder implements SourcePathsBuilder {

private Project myProject;
ResourceBundle bundle = ResourceBundle.getBundle("Bundle");

@Override
public String getBuilderId() {
    return getClass().getName();
}

@Override
public String getPresentableName() {
    return "Aspose Application";
}

@Override
public String getDescription() {
    return bundle.getString("AsposeWizardPanel.myMainPanel.description");


}

@Override
public Icon getBigIcon() {
    return AsposeIcons.AsposeMedium;
}

@Override
public Icon getNodeIcon() {
    return AsposeIcons.AsposeLogo;
}


@Override
public ModuleWizardStep[] createWizardSteps(@NotNull WizardContext wizardContext, @NotNull ModulesProvider modulesProvider) {
    return new ModuleWizardStep[]{
            new AsposeAPIsWizardStep(this, wizardContext),
    };
}


@Override
public void setupRootModel(ModifiableRootModel rootModel) throws com.intellij.openapi.options.ConfigurationException {



    setMyProject(rootModel.getProject());
    final CompilerModuleExtension compilerModuleExtension = rootModel.getModuleExtension(CompilerModuleExtension.class);
    compilerModuleExtension.setExcludeOutput(true);

    if (myJdk != null) {
        rootModel.setSdk(myJdk);
    } else {
        rootModel.inheritSdk();
    }

    ContentEntry contentEntry = doAddContentEntry(rootModel);
    if (contentEntry != null) {
        final List<Pair<String, String>> sourcePaths = getSourcePaths();

        if (sourcePaths != null) {
            for (final Pair<String, String> sourcePath : sourcePaths) {
                String first = sourcePath.first;
                new File(first).mkdirs();
                final VirtualFile sourceRoot = LocalFileSystem.getInstance()
                        .refreshAndFindFileByPath(FileUtil.toSystemIndependentName(first));
                if (sourceRoot != null) {
                    contentEntry.addSourceFolder(sourceRoot, false, sourcePath.second);
                }
            }
        }
    }

    if (myCompilerOutputPath != null) {
        // should set only absolute paths
        String canonicalPath;
        try {
            canonicalPath = FileUtil.resolveShortWindowsName(myCompilerOutputPath);
        } catch (IOException e) {
            canonicalPath = myCompilerOutputPath;
        }
        compilerModuleExtension
                .setCompilerOutputPath(VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(canonicalPath)));
    } else {
        compilerModuleExtension.inheritCompilerOutputPath(true);
    }

    LibraryTable libraryTable = rootModel.getModuleLibraryTable();
    for (Pair<String, String> libInfo : myModuleLibraries) {
        final String moduleLibraryPath = libInfo.first;
        final String sourceLibraryPath = libInfo.second;
        Library library = libraryTable.createLibrary();
        Library.ModifiableModel modifiableModel = library.getModifiableModel();
        modifiableModel.addRoot(getUrlByPath(moduleLibraryPath), OrderRootType.CLASSES);
        if (sourceLibraryPath != null) {
            modifiableModel.addRoot(getUrlByPath(sourceLibraryPath), OrderRootType.SOURCES);
        }
        modifiableModel.commit();
    }
    RunnableHelper.runWhenInitialized(getMyProject(), new Runnable() {
        public void run() {
            System.out.println("Hello I came here");
            final LibraryTablesRegistrar libTablesRegistrar = LibraryTablesRegistrar.getInstance();

            final LibraryTable libraryTable = libTablesRegistrar.getLibraryTable(getMyProject());

            final LibraryTable.ModifiableModel libTableModel = libraryTable.getModifiableModel();


            Library library = libTableModel.createLibrary(AsposeConstants.LIBRARY_NAME);
            libTableModel.commit();

            @NonNls final String path = getContentEntryPath() + File.separator + AsposeConstants.LIB_FOLDER;
            new File(path).mkdirs();


            for (AsposeJavaAPI api : AsposeProject.getApiList().values()) {
                System.out.println("Hello I came here2");
                if (api.is_selected()) {
                    try {
                        System.out.println("Hello I came here3");
                        AsposeAPIsManager.copyDirectory(AsposeAPIsManager.getLibaryDownloadPath() + api.get_name().toLowerCase(), path + File.separator + api.get_name());
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                    String[] children = new File(path + File.separator + api.get_name().toLowerCase() + File.separator).list();
                    for (String _child : children) {
                        String jarPath = "jar://" + path + File.separator + api.get_name() + File.separator + _child + "!/";

                        Library.ModifiableModel model = library.getModifiableModel();

                        model.addRoot(jarPath, OrderRootType.CLASSES);

                        model.commit();

                    }
                }
            }


            Collection<Module> modules = ModuleUtil.getModulesOfType(getMyProject(), StdModuleTypes.JAVA);
            Iterator itr = modules.iterator();
            Module module = null;
            while (itr.hasNext()) {
                module = (Module) itr.next();
                break;
            }
            final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);

            final ModifiableRootModel moduleRootModel = moduleRootManager.getModifiableModel();

            final Library lib = libraryTable.getLibraryByName(AsposeConstants.LIBRARY_NAME);

            if (moduleRootModel.findLibraryOrderEntry(lib) == null) {

                moduleRootModel.addLibraryEntry(lib);

            }
            moduleRootModel.commit();


        }
    });
}

@Override
public String getGroupName() {
    return JavaModuleType.JAVA_GROUP;
}

public Project getMyProject() {
    return myProject;
}

public void setMyProject(Project myProject) {
    this.myProject = myProject;
}

@Nullable
public ModuleWizardStep getCustomOptionsStep(WizardContext context, Disposable parentDisposable) {
    AsposeIntroWizardStep step = new AsposeIntroWizardStep();
    Disposer.register(parentDisposable, step);
    return step;
}


private String myCompilerOutputPath;
// Pair<Source Path, Package Prefix>
private List<Pair<String, String>> mySourcePaths;
// Pair<Library path, Source path>
private final List<Pair<String, String>> myModuleLibraries = new ArrayList<Pair<String, String>>();

public final void setCompilerOutputPath(String compilerOutputPath) {
    myCompilerOutputPath = acceptParameter(compilerOutputPath);
}

public List<Pair<String, String>> getSourcePaths() {
    if (mySourcePaths == null) {
        final List<Pair<String, String>> paths = new ArrayList<Pair<String, String>>();
        @NonNls final String path = getContentEntryPath() + File.separator + "src";
        new File(path).mkdirs();
        paths.add(Pair.create(path, ""));
        return paths;
    }
    return mySourcePaths;
}

public void setSourcePaths(List<Pair<String, String>> sourcePaths) {
    mySourcePaths = sourcePaths != null ? new ArrayList<Pair<String, String>>(sourcePaths) : null;
}

public void addSourcePath(Pair<String, String> sourcePathInfo) {
    if (mySourcePaths == null) {
        mySourcePaths = new ArrayList<Pair<String, String>>();
    }
    mySourcePaths.add(sourcePathInfo);
}

public ModuleType getModuleType() {
    return StdModuleTypes.JAVA;
}

@Override
public boolean isSuitableSdkType(SdkTypeId sdkType) {
    return sdkType instanceof JavaSdkType;
}

@Nullable
@Override
public ModuleWizardStep modifySettingsStep(@NotNull SettingsStep settingsStep) {
    return StdModuleTypes.JAVA.modifySettingsStep(settingsStep, this);
}

private static String getUrlByPath(final String path) {
    return VfsUtil.getUrlForLibraryRoot(new File(path));
}

public void addModuleLibrary(String moduleLibraryPath, String sourcePath) {
    myModuleLibraries.add(Pair.create(moduleLibraryPath, sourcePath));
}

@Nullable
protected static String getPathForOutputPathStep() {
    return null;
}
}

有关在 IntelliJ IDEA 中创建新模块/项目类型的完整源代码参考,请参阅以下源代码Aspose 项目向导(一个 IntelliJ IDEA 插件Aspose有限公司 http://www.aspose.com/)

源代码可以从以下网址下载:

https://asposejetbrains.codeplex.com/ https://asposejetbrains.codeplex.com/

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 IntelliJ 插件中“注册”新的模块类型? 的相关文章

随机推荐

  • android 动画后按钮不起作用

    我在 android 中创建了一个视图 我需要从下到上对其进行动画处理 反之亦然 我已经使用 TranslateAnimation 成功地做到了这一点 但问题是我的视图上有几个按钮 当动画出现时 触摸点保留在原始位置并且不会移动到新位置 因
  • List 是指针吗?

    我注意到的行为List
  • 始终位于顶部窗口

    我正在寻找一种解决方案 以便使 JFrame 始终处于顶部 并且 始终 我真正的意思是 始终 setAlwaysOnTop true 当我以全屏模式启动游戏时 这将不起作用 我知道您通常不希望窗口保持在顶部 但在这种情况下这是必需的 这是不
  • cdk虚拟滚动问题

    有没有人遇到过 Angular 7 cdk 虚拟滚动在 mat tab 组中工作异常的问题 https github com angular material2 issues 13981 https github com angular m
  • jQuery 分页插件

    希望这是很容易解决的问题 我在理解上遇到了一些问题jQuery 分页 http plugins jquery com project pagination plugin 本质上 我想做的就是加载 PHP 文件 然后对结果进行分页 我试图摆脱
  • 基本类型的 C++ 类包装器

    我见过 使用的许多库都有 typedef 来提供可移植的 固定大小的变量 例如 int8 uint8 int16 uint16 等 无论平台如何 它们都是正确的大小 并且 c 11 本身使用头文件 stdint txt 来实现 H 最近在我
  • 如何在 C++ 中使用小数(浮点)?

    根据IEEE 754 2008 http en wikipedia org wiki IEEE 754 2008有 存在三种二进制浮点基本格式 可以使用 32 64 或 128 位进行编码 和两种十进制浮点基本格式 可以使用 64 或 12
  • 如何通过货币名称获取货币符号?

    我想要获得货币符号 例如 or 按货币名称 例如USD or EUR 对于英语 美国 我可以获得符号 如果英语 美国 设置为设备上的语言 Currency currency Currency getInstance Locale getDe
  • Firebase 在 iOS 上使用 Swift 多次调用“Observe”

    当我开始observer在 Firebase 数据库节点上 我注意到 Firebase 继续调用该方法observer即使没有数据变化 这是我的设置 FIRDatabase database reference withPath test
  • 如何正确配置嵌入式 OpenEJB 容器进行测试?

    这是我的 SLSB Stateless public class MyService PersistenceContext unitName abc EntityManager em public boolean exists int id
  • Intellij IDEA 未从 Groovy 项目中的 @Grab 导入依赖项

    我正在处理一个 groovy 脚本 它使用 Grab 注释导入依赖项 该脚本将在 IDEA 中从命令行运行 但是 在 IDE 中 导入显示为红色 不可解析 并且不会对导入的类提供自动完成功能 我正在通过代理访问企业存储库 该代理已在 IDE
  • 为 C++ 应用程序提供 HTTP Web 服务器功能

    我有一个 C 应用程序 正在寻找一个库 使其成为能够提供静态文件以及执行非常简单的任务的 HTTP 服务器 唯一的限制是它必须是跨平台的 我有什么选择 澄清 我的应用程序需要一个 Web 界面 该应用程序是执行其他任务的后台程序 我想提供一
  • 使用 HTML5 验证多个电子邮件地址

    我正在尝试构建一个电子邮件表单 该表单将多个逗号分隔的电子邮件作为输入并使用 HTML5 验证它们 我想使用以下正则表达式来检查输入的完整性 b A Za z0 9 A Za z0 9 A Za z 2 4 b 这是我尝试过的 这似乎不适用
  • 如何在 CakePHP 中定义模型的“全局”查找条件?

    是否可以定义在使用特定模型的所有控制器和功能中始终有效的查找条件 例如 如果我只想退回有库存的产品 无论如何 也许在模型中的某个地方 conditions gt array inStock gt gt 0 我认为您可以尝试在模型上执行一个函
  • 如何使用puppet为不同用户设置自定义bash环境?

    我刚刚开始使用 puppet 和 vagrant 为我们的团队设置开发环境 该团队由 8 名以上的开发人员组成 每个人都有其特定的 bash 配置等 我已经将所有软件安装在系统来快速部署新的开发虚拟机 但我不确定以自动化的方式为每个特定用户
  • Gradle 错误:字符串索引超出范围:0

    尝试使用 Gradle 编译 Android 项目并收到奇怪的错误 当我跑步时 gradlew tasks stacktrace 尝试过干净的重建 新的仓库克隆 不同的分支 同事能够构建 aok 寻找要检查 尝试解决此问题的想法 更新 恢复
  • Selenium 和 Geckodriver 在 Python 中创建 Webdriver 时出现问题

    我在 python 爬虫中有一段代码曾经可以工作 我将其安装在新系统上 现在正在尝试获取正确的依赖项 使用geckodriver 0 13 0并执行以下代码时 def login self print self colors OKBLUE
  • “你好世界”从何而来?

    hello world 通常是任何编程语言的第一个示例 我一直想知道这句话是从哪里来的 又是在哪里第一次使用的 我曾经被告知这是有史以来在计算机屏幕上显示的第一句话 但我找不到任何对此的参考 所以我的问题是 练习在哪里使用 hello wo
  • 有没有办法为 Kotlin 顶级函数引用 Java 类?

    我想使用以下方式在顶级函数中加载资源Class getResourceAsStream 有什么方法可以获取顶级函数将被编译到的类的引用 以便我可以编写 例如 val myThing readFromStream MYCLASS getRes
  • 如何在 IntelliJ 插件中“注册”新的模块类型?

    我是 IntelliJ 插件开发的初学者 但我希望我的插件在 新项目 新模块 窗口中注册新的模块类型 我已经搜索了插件开发人员的文档 但找不到任何有用的东西 我还查看了 Kotlin 和 Scala 等现有插件 它们也添加了新的模块类型 但