Home > Back-end >  Get the Application Package name in template Wizard recipe class Intellij
Get the Application Package name in template Wizard recipe class Intellij

Time:10-27

Get the Application Package name in template recipe class

  • I am working on MVVM plugin template for android studio. I completed most of the work.

  • But now I only need to get the application package name.

  • Their is a method

    getPackageName(module: Module)

  • This method takes module as a input But I don't know how to pass the module as input.

  • My core requiremnet for this task is I want to create a directory in parent directory by stand in child directory.

For example:

I have four directories A, B, C, D.

A(parent) , B ( Child of A) , C (child of B) , D (Child of C).

let say I am standing in directory D and I want to create common directory (F) inside A along with B ( F sibling to B).

CodePudding user response:

You can get the parent directory form srcOut like

fun getApplicationPackageFile(srcOut: File, applicationPackage: String): File {
    var applicationPackageFile = srcOut.path.toString()
    var pk = applicationPackage.replace(".", "\\")

    val status: Boolean = applicationPackageFile.contains(pk)
    return if (status) {
        var file =
            applicationPackageFile.substring(0, applicationPackageFile.indexOf(pk))   pk   "\\"
        File(file)
    } else {
        srcOut
    }
}

And call it like

val pkFile = getApplicationPackageFile(srcOut, moduleData.projectTemplateData.applicationPackage)

So If you want to save some file to the core application package..

pkFile.resolve("AppViewModel.$ktOrJavaExt")

For Linux and Mac Change above line to

var pk = applicationPackage.replace(".", "/")
  • Related