Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

Commit e0960f8

Browse files
JeffsetSpace Team
authored andcommitted
[plugins] AMPER-5085 Add ${project.rootDir} API.
1 parent 867607d commit e0960f8

6 files changed

Lines changed: 31 additions & 13 deletions

File tree

docs/src/user-guide/plugins/topics/references.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,19 @@ tasks:
121121
myTask: {...}
122122
```
123123
124-
| Property path | Type | Description |
125-
|----------------------------|---------------------------------------------------------------|------------------------------------------------------------------------------------------------------------|
126-
| `pluginSettings` | the type specified in `pluginInfo.settingsClass` | The plugin’s settings object from the `plugins.<plugin-id>` block of the module the plugin is applied to. |
127-
| `module.name` | `string` | Module display name. |
128-
| `module.rootDir` | `path` | Absolute path to the module root (where `module.yaml` is). |
129-
| `module.runtimeClasspath` | `Classpath` | Resolved runtime classpath (JVM, main). |
130-
| `module.compileClasspath` | `Classpath` | Compile classpath plus the module’s compilation result. |
131-
| `module.kotlinJavaSources` | `ModuleSources` | Kotlin and Java sources (JVM, main). |
132-
| `module.resources` | `ModuleSources` | Resources (JVM, main). |
133-
| `module.jar` | `CompilationArtifact` | Compiled JAR (JVM, main). |
134-
| `module.self` | `Dependency.Local` | A dependency pointing to the module itself |
135-
| `module.settings.**` | depends on the actual setting type: `string`, `boolean`, etc. | The settings of the module where the plugin is applied. For example, `module.settings.publishing.version`. |
124+
| Property path | Type | Description |
125+
|----------------------------|---------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
126+
| `pluginSettings` | the type specified in `pluginInfo.settingsClass` | The plugin’s settings object from the `plugins.<plugin-id>` block of the module the plugin is applied to. |
127+
| `module.name` | `string` | Module display name. |
128+
| `module.rootDir` | `path` | Absolute path to the module root (where `module.yaml` is). |
129+
| `module.runtimeClasspath` | `Classpath` | Resolved runtime classpath (JVM, main). |
130+
| `module.compileClasspath` | `Classpath` | Compile classpath plus the module’s compilation result. |
131+
| `module.kotlinJavaSources` | `ModuleSources` | Kotlin and Java sources (JVM, main). |
132+
| `module.resources` | `ModuleSources` | Resources (JVM, main). |
133+
| `module.jar` | `CompilationArtifact` | Compiled JAR (JVM, main). |
134+
| `module.self` | `Dependency.Local` | A dependency pointing to the module itself |
135+
| `module.settings.**` | depends on the actual setting type: `string`, `boolean`, etc. | The settings of the module where the plugin is applied. For example, `module.settings.publishing.version`. |
136+
| `project.rootDir` | `path` | Absolute path to the project root where `project.yaml` (or `module.yaml`) is for multi- (or single-) module projects. |
136137

137138
!!! note
138139
* `pluginSettings` is defined only if a plugin has a [settings class](configuration.md#plugin-settings).

sources/frontend-api/src/org/jetbrains/amper/frontend/plugins/pluginYamlSchema.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class PluginYamlRoot : SchemaNode() {
3636
@SchemaDoc("Data from the module the plugin is applied to")
3737
val module by value<ModuleDataForPlugin>()
3838

39+
@ReadOnly
40+
@SchemaDoc("Data from the project within which the plugin is applied")
41+
val project by value<ProjectDataForPlugin>()
42+
3943
@ReadOnly
4044
@CanBeReferenced
4145
val pluginSettings: PluginSettingsPlaceholder by value()
@@ -85,6 +89,12 @@ class ModuleDataForPlugin : SchemaNode() {
8589
val settings by value<Settings>()
8690
}
8791

92+
class ProjectDataForPlugin : SchemaNode() {
93+
@CanBeReferenced
94+
@SchemaDoc("Project's root directory (where `project.yaml` resides if present)")
95+
val rootDir by value<Path>()
96+
}
97+
8898
@CustomSchemaDeclaration
8999
class TaskAction(
90100
// TODO: Remove @IgnoreForSchema here?

sources/frontend/schema/src/org/jetbrains/amper/frontend/aomBuilder/plugins/PluginTreeReader.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ internal class PluginTreeReader(
184184
settings(module.moduleCtxModule.settings.backingTree)
185185
// TODO: Maybe at include test-settings here also?
186186
}
187+
project {
188+
rootDir(projectContext.projectRootDir.toNioPath())
189+
}
187190
tasks {
188191
for ((taskName, taskBuildRoot) in taskDirs) {
189192
put[taskName] {

sources/test-integration/amper-cli-test/test/org/jetbrains/amper/cli/test/PluginsTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class PluginsTest : AmperCliTestBase() {
6969
taskName = taskName,
7070
output = """
7171
Hello from distribution
72+
local.properties: $projectDir/local.properties
7273
classpath base.dependencies = [{modulePath: $projectDir/app}]
7374
classpath base.dependencies[0] = {modulePath: $projectDir/app}
7475
classpath base.dependencies[0].modulePath = $projectDir/app

sources/test-integration/test-projects/extensibility/distribution/distribution-plugin/plugin.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ tasks:
66
settings: ${pluginSettings}
77
distributionDir: ${taskOutputDir}
88
baseJar:
9-
from: ${module.self}
9+
from: ${module.self}
10+
localProperties: ${project.rootDir}/local.properties

sources/test-integration/test-projects/extensibility/distribution/distribution-plugin/src/plugin.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ fun buildDistribution(
1818
@Input baseJar: CompilationArtifact,
1919
@Input baseClasspath: Classpath,
2020
@Input settings: DistributionSettings,
21+
@Input localProperties: Path,
2122
) {
2223
distributionDir.createDirectories()
2324
println("Hello from distribution")
25+
println("local.properties: ${localProperties}")
2426
printClasspathInfo("base", baseClasspath)
2527
settings.extraNamedClasspaths.forEach { (name, classpath) ->
2628
printClasspathInfo(name, classpath)

0 commit comments

Comments
 (0)