Skip to content

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- committed Nov 8, 2024
1 parent cade715 commit fb67987
Showing 1 changed file with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.roots.CompilerModuleExtension
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.vfs.VirtualFile
import io.netty.handler.codec.http.HttpResponseStatus
import org.jetbrains.jps.model.java.JavaResourceRootType
import org.jetbrains.jps.model.java.JavaSourceRootType

class GetModulePathsHandler(project: Project) : AbstractHandler(project) {

@JvmRecord
data class ProjectInfo(
val basePath: String?,
val modules: List<ModuleInfo>
)
@JvmRecord data class ProjectInfo(val basePath: String?, val modules: List<ModuleInfo>)

@JvmRecord
data class ModuleInfo(
val name: String,
Expand All @@ -25,7 +24,7 @@ class GetModulePathsHandler(project: Project) : AbstractHandler(project) {
val javaTestSourcePaths: Array<String>,
val resourcePaths: Array<String>,
val testResourcePaths: Array<String>,
val outputPath:String?
val outputPath: String?
)

override fun run(): HandlerResponse {
Expand All @@ -35,15 +34,27 @@ class GetModulePathsHandler(project: Project) : AbstractHandler(project) {
val contentRoots = moduleRootManager.contentRoots.map { it.path }

val compilerModuleExtension = CompilerModuleExtension.getInstance(module)
val outputPath = compilerModuleExtension?.compilerOutputPath

// Note that the JavaSourceRootType.SOURCE also includes Kotlin source folders
val javaSourcePaths = moduleRootManager.getSourceRoots(JavaSourceRootType.SOURCE).map { it.path }
val javaTestSourcePaths = moduleRootManager.getSourceRoots(JavaSourceRootType.TEST_SOURCE).map { it.path }
// Only include folder if is is not in the output path
val javaSourcePaths =
moduleRootManager.getSourceRoots(JavaSourceRootType.SOURCE).filter(exclude(outputPath)).map({ it.path })
val javaTestSourcePaths =
moduleRootManager.getSourceRoots(JavaSourceRootType.TEST_SOURCE).filter(exclude(outputPath)) map
{
it.path
}

val resourcePaths = moduleRootManager.getSourceRoots(JavaResourceRootType.RESOURCE).map { it.path }
val testResourcePaths = moduleRootManager.getSourceRoots(JavaResourceRootType.TEST_RESOURCE).map { it.path }
val resourcePaths =
moduleRootManager.getSourceRoots(JavaResourceRootType.RESOURCE).filter(exclude(outputPath)).map {
it.path
}
val testResourcePaths =
moduleRootManager.getSourceRoots(JavaResourceRootType.TEST_RESOURCE).filter(exclude(outputPath)).map {
it.path
}

val outputPath = compilerModuleExtension?.compilerOutputPath?.path;
modules.add(
ModuleInfo(
module.name,
Expand All @@ -52,10 +63,14 @@ class GetModulePathsHandler(project: Project) : AbstractHandler(project) {
javaTestSourcePaths.toTypedArray(),
resourcePaths.toTypedArray(),
testResourcePaths.toTypedArray(),
outputPath ))
outputPath?.path))
}
val projectInfo = ProjectInfo(project.guessProjectDir()?.path, modules)
val data = mapOf("project" to projectInfo)
return HandlerResponse(HttpResponseStatus.OK, data)
}

private fun exclude(outputPath: VirtualFile?) = { sourceRoot: VirtualFile ->
outputPath == null || !VfsUtil.isAncestor(outputPath, sourceRoot, false)
}
}

0 comments on commit fb67987

Please sign in to comment.