fun asAppliedTo()

in sources/frontend/schema/src/org/jetbrains/amper/frontend/aomBuilder/plugins/PluginTreeReader.kt [92:157]


    fun asAppliedTo(
        module: ModuleBuildCtx,
    ): PluginYamlRoot? = context(problemReporter, pluginTypes) {
        val moduleRootDir = module.module.source.moduleDir
        val pluginConfiguration = module.pluginsTree[pluginData.id.value] as? RefinedMappingNode
            ?: return@context null

        val enabled = (pluginConfiguration["enabled"] as? BooleanNode)?.value
        if (enabled != true) {
            reportExplicitValuesWhenDisabled(pluginConfiguration)
            return null
        }

        val taskDirs = (pluginTree[PluginYamlRoot::tasks] as? RefinedMappingNode)
            ?.refinedChildren
            ?.filterValues { it.value !is ErrorNode }
            ?.mapValues { (name, _) ->
                projectContext.getTaskOutputRoot(taskNameFor(module.module, name))
            }.orEmpty()

        // Build a tree with computed "reference-only" values.
        val referenceValuesTree = syntheticBuilder(DefaultTrace) {
            `object`<PluginYamlRoot> {
                if (pluginData.pluginSettingsSchemaName != null) {
                    PluginYamlRoot.PLUGIN_SETTINGS setTo pluginConfiguration
                }
                PluginYamlRoot::module setTo `object`<ModuleDataForPlugin> {
                    ModuleDataForPlugin::name setTo scalar(module.module.userReadableName)
                    ModuleDataForPlugin::rootDir setTo scalar(moduleRootDir)
                    val selfDependency = `object`<ShadowDependencyLocal> {
                        ShadowDependencyLocal::modulePath setTo scalar(moduleRootDir)
                    }
                    ModuleDataForPlugin::self setTo selfDependency
                    ModuleDataForPlugin::runtimeClasspath setTo `object`<ShadowClasspath> {
                        ShadowClasspath::dependencies setToList { add(selfDependency) }
                    }
                    ModuleDataForPlugin::compileClasspath setTo `object`<ShadowClasspath> {
                        ShadowClasspath::dependencies setToList { add(selfDependency) }
                        ShadowClasspath::scope setTo scalar(ShadowResolutionScope.Compile)
                    }
                    ModuleDataForPlugin::kotlinJavaSources setTo `object`<ShadowModuleSources> {
                        ShadowModuleSources::from setTo selfDependency
                    }
                    ModuleDataForPlugin::resources setTo `object`<ShadowModuleSources> {
                        ShadowModuleSources::from setTo selfDependency
                        ShadowModuleSources::kind setTo scalar(ShadowSourcesKind.Resources)
                    }
                    ModuleDataForPlugin::jar setTo `object`<ShadowCompilationArtifact> {
                        ShadowCompilationArtifact::from setTo selfDependency
                    }
                }
                PluginYamlRoot::tasks setToMap {
                    for ((taskName, taskBuildRoot) in taskDirs) {
                        taskName setTo `object`<Task> {
                            Task::taskOutputDir setTo scalar(taskBuildRoot)
                        }
                    }
                }
            }
        }

        val mergedTree = mergeTrees(pluginTree, referenceValuesTree)
            .substituteCatalogDependencies(pluginModule.usedCatalog)
        val refinedTree = treeRefiner.refineTree(mergedTree, EmptyContexts)
        createSchemaNode<PluginYamlRoot>(refinedTree)
    }