使用IntelliJ插件SDK添加自定义新模块模板(Android Studio)
当AndroidStudio停止支持项目模板文件时,他们切换到插件架构。我是IntelliJ插件的新手,希望重新创建丢失的模板 我正在尝试使用插件创建一个“新模块”模板。基本上,这个想法是用户将右键点击一个应用程序项目,并选择“新建通用模块”,一个新模块将与我的所有自定义gradle文件一起出现在项目中 我甚至在创建模块的时候都遇到了麻烦。下面是插件的“配方”使用IntelliJ插件SDK添加自定义新模块模板(Android Studio),android,intellij-idea,Android,Intellij Idea,当AndroidStudio停止支持项目模板文件时,他们切换到插件架构。我是IntelliJ插件的新手,希望重新创建丢失的模板 我正在尝试使用插件创建一个“新模块”模板。基本上,这个想法是用户将右键点击一个应用程序项目,并选择“新建通用模块”,一个新模块将与我的所有自定义gradle文件一起出现在项目中 我甚至在创建模块的时候都遇到了麻烦。下面是插件的“配方” fun RecipeExecutor.MyModuleSetup( moduleData: ModuleTemplate
fun RecipeExecutor.MyModuleSetup(
moduleData: ModuleTemplateData,
packageName: String,
entityName: String,
moduleName: String,
) {
val (projectData) = moduleData
val project = projectInstance ?: return
addAllKotlinDependencies(moduleData)
try {
WriteCommandAction.writeCommandAction(project).compute(ThrowableComputable<Module, RuntimeException> {
val f: VirtualFile = createProjectSubFile(ModuleManager.getInstance(project).modules[0]).contentRoots[0].path, "$moduleName/$moduleName.iml")
val module = ModuleManager.getInstance(project).newModule(f.path, ModuleTypeId.JAVA_MODULE)
PsiTestUtil.addContentRoot(module, f.parent)
module
})
} catch (e: IOException) {
throw RuntimeException(e)
}
}
@Throws(IOException::class)
fun createProjectSubFile(projectPath: String?, relativePath: String?): VirtualFile {
val f = File(projectPath, relativePath)
FileUtil.ensureExists(f.getParentFile())
FileUtil.ensureCanCreateFile(f)
val created: Boolean = f.createNewFile()
if (!created && !f.exists()) {
throw AssertionError("Unable to create the project sub file: " + f.getAbsolutePath())
}
return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f)!!
}
fun RecipeExecutor.MyModuleSetup(
moduleData:ModuleTemplateData,
packageName:String,
entityName:String,
moduleName:字符串,
) {
val(项目数据)=模块数据
val project=projectInstance?:返回
AddAllKotlIndependence(模块数据)
试一试{
WriteCommandAction.WriteCommandAction(项目).compute(ThrowableComputable{
val f:VirtualFile=createProjectSubFile(ModuleManager.getInstance(project).modules[0]).contentRoots[0]。路径“$moduleName/$moduleName.iml”)
val module=ModuleManager.getInstance(project).newModule(f.path,ModuleTypeId.JAVA_module)
PsiTestUtil.addContentRoot(模块,f.parent)
模块
})
}捕获(e:IOException){
抛出运行时异常(e)
}
}
@抛出(IOException::类)
fun createProjectSubFile(项目路径:String?,相对路径:String?):虚拟文件{
val f=文件(项目路径,相对路径)
FileUtil.ensureExists(f.getParentFile())
FileUtil.ensureConcreateFile(f)
创建的val:Boolean=f.createNewFile()
如果(!created&&!f.exists()){
抛出断言错误(“无法创建项目子文件:+f.getAbsolutePath())
}
返回LocalFileSystem.getInstance().RefreshAndFindFileByofile(f)!!
}
如果我在一个名为“app1”的项目中使用该插件创建一个名为“mod1”的新模块,我希望有一个这样的新导演:
/用户/xxxxxx/Documents/tests/app1/mod1
相反,什么也没发生!我应该在它出现之前写些什么吗
这是在使用插件的项目中创建新模块的正确方法吗
谢谢大家