Skip to content

Dynamic Retrieval of Source Directory Names #170

@xterao

Description

@xterao

Currently, the source and resource directory names are hardcoded as /src/main and /resources. Because some projects may use different directory structures, use ModuleRootManager to dynamically obtain the correct directory names based on the project’s configuration.

ex)

val module = sqlFile.module
val moduleName = module?.name?.substringAfter(project.name.plus("."))?.split(".")?.first() ?: ""
val modulemanager = module?.let {  ModuleRootManager.getInstance(module)}
val subStringPath = module?.name?.plus(project.basePath?:"") ?:""

modulemanager?.contentEntries?.firstOrNull()?.let { entry ->
    entry.sourceFolders.map { folder ->
        val file = folder.file
        val pathName = file?.path?.substringAfter(subStringPath) ?: ""
        val sourceFileName = pathName.substringAfter("${project.basePath ?: ""}/")
.substringBefore("/${file?.name ?: ""}")            
}
    entry.file?.path?.substringAfter(moduleName)
}

This code snippet extracts the /src/main segment that sits between the module name and each source-directory path. Inside the map { } block, the variable file represents each individual source directory.

entry.file?.path?.substringAfter(moduleName)

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions