override suspend fun run()

in sources/amper-cli/src/org/jetbrains/amper/tasks/MetadataCompileTask.kt [75:137]


    override suspend fun run(dependenciesResult: List<TaskResult>, executionContext: TaskGraphExecutionContext): Result {
        logger.debug("compile metadata for '${module.userReadableName}' -- ${fragment.name}")

        val kotlinSettings = fragment.serializableKotlinSettings()

        val dependencyResolutionResults = dependenciesResult.filterIsInstance<ResolveExternalDependenciesTask.Result>()

        // TODO extract deps only for our fragment/platforms
        val mavenClasspath = dependencyResolutionResults.flatMap { it.compileClasspath }

        val localDependencies = dependenciesResult.filterIsInstance<Result>()

        // includes this module's fragment dependencies and other source fragment deps from other local modules
        val localClasspath = localDependencies.map { it.metadataOutputRoot }

        val classpath = localClasspath + mavenClasspath // TODO where to get transitive maven deps?
        val refinesPaths = fragment.refinedFragments.map { localDependencies.findMetadataResultForFragment(it).metadataOutputRoot }
        val friendPaths = fragment.friends.map { localDependencies.findMetadataResultForFragment(it).metadataOutputRoot }

        val jdk = jdkProvider.getJdkOrUserError(jdkSettings = fragment.settings.jvm.jdk)

        val inputValues = mapOf(
            "jdk.version" to jdk.version,
            "jdk.home" to jdk.homeDir.pathString,
            "user.settings" to Json.encodeToString(kotlinSettings),
            "task.output.root" to taskOutputRoot.path.pathString,
        )

        val sourceDirs = fragment.sourceRoots.map { it.toAbsolutePath() } + additionalKotlinJavaSourceDirs.map { it.path }
        val inputFiles = sourceDirs + classpath + refinesPaths + friendPaths

        incrementalCache.execute(taskName.name, inputValues, inputFiles) {
            cleanDirectory(taskOutputRoot.path)

            val existingSourceDirs = sourceDirs.filter { it.exists() }
            if (existingSourceDirs.isNotEmpty()) {
                existingSourceDirs.forEach {
                    if (!it.isDirectory()) {
                        userReadableError("Source directory '$it' exists, but it's not a directory, this is currently unsupported")
                    }
                }
                compileSources(
                    jdk = jdk,
                    kotlinUserSettings = kotlinSettings,
                    sourceDirectories = sourceDirs,
                    additionalSourceRoots = additionalKotlinJavaSourceDirs.map { SourceRoot(it.fragmentName, it.path) },
                    classpath = classpath,
                    friendPaths = friendPaths,
                    refinesPaths = refinesPaths,
                )
            } else {
                logger.debug("No sources were found for ${fragment.identificationPhrase()}, skipping compilation")
            }

            return@execute IncrementalCache.ExecutionResult(listOf(taskOutputRoot.path.toAbsolutePath()))
        }

        return Result(
            metadataOutputRoot = taskOutputRoot.path.toAbsolutePath(),
            module = module,
            fragment = fragment,
        )
    }