Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions subprojects/mps-gradle-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

### Added

- Ant tasks of build scripts receive an `artifacts.X` property for each top-level directory `X` of the extracted
external MPS libraries, so MPS build scripts find libraries packaged by this plugin without additional path variables.
- `RunAnt.propertyFiles`: property files passed to Ant with `-propertyfile`.

### Changed

- **Breaking:** MPS libraries produced by other projects of the build (project dependencies and included builds) are no
Expand Down
10 changes: 10 additions & 0 deletions subprojects/mps-gradle-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ dependency of each library it consumes.

External libraries are extracted into `mpsDefaults.mpsLibrariesDirectory` (`build/dependencies` by default).

For each top-level directory `X` of the extracted libraries, the MPS build scripts receive an Ant property `artifacts.X`
pointing at that directory. MPS-generated build scripts read the location of the artifacts of a dependency build project
named `X` from `artifacts.X`, so build scripts find libraries packaged by this plugin without additional path variables:
their zips contain the artifacts directory of each published build as a top-level directory, and its name usually
matches the name of the build project. Path variables set in `mpsDefaults.pathVariables` take precedence over these
properties.

### Dependencies on other projects

A dependency can also point at another project of the same Gradle build (`api(project(":other"))`) or at an included
Expand Down Expand Up @@ -238,6 +245,8 @@ Based on the above configuration, the plugin creates the following tasks:
bundled dependencies, and `setup` of other projects this project depends on (see
[Dependencies on other projects](#dependencies-on-other-projects)).
- `resolveMpsLibraries` – downloads external MPS libraries and extracts them into `mpsDefaults.mpsLibrariesDirectory`.
Also writes `build/mps-libraries-artifacts.properties` with an `artifacts.<name>` property for each top-level
directory of the extracted libraries. The Ant tasks of all build scripts load this file.
- `zip` – packages all artifacts of published main builds into a zip file.
- `test` – runs tests in all test build scripts. `test` is a lifecycle task that does nothing on its own but depends on
`check<Name>` tasks of all test build scripts.
Expand Down Expand Up @@ -305,6 +314,7 @@ val myTask by tasks.registering(RunAnt::class) {

pathProperties.put("mps_home", file("/my/mps/home"))
valueProperties.put("version", provider { project.version.toString() })
propertyFiles.from(file("my.properties")) // passed with -propertyfile, -D properties take precedence

targets.set(listOf("myTarget")) // no default
}
Expand Down
1 change: 1 addition & 0 deletions subprojects/mps-gradle-plugin/api/mps-gradle-plugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public abstract class com/specificlanguages/mps/RunAnt : org/gradle/api/DefaultT
public abstract fun getOptions ()Lorg/gradle/api/provider/ListProperty;
public abstract fun getPathProperties ()Lorg/gradle/api/provider/MapProperty;
public abstract fun getPreserveWorkingDirectory ()Lorg/gradle/api/provider/Property;
public abstract fun getPropertyFiles ()Lorg/gradle/api/file/ConfigurableFileCollection;
public abstract fun getTargets ()Lorg/gradle/api/provider/ListProperty;
protected abstract fun getToolchains ()Lorg/gradle/jvm/toolchain/JavaToolchainService;
public abstract fun getValueProperties ()Lorg/gradle/api/provider/MapProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import com.specificlanguages.jbrtoolchain.JbrToolchainExtension
import com.specificlanguages.jbrtoolchain.JbrToolchainPlugin
import com.specificlanguages.mps.internal.ConfigurationNames
import com.specificlanguages.mps.internal.configureMbeddrIntegration
import com.specificlanguages.mps.internal.configureLibrariesArtifactsProperties
import com.specificlanguages.mps.internal.configureProjectDependencies
import com.specificlanguages.mps.internal.writeArtifactsProperties
import com.specificlanguages.mps.internal.createBundledDependenciesContainer
import com.specificlanguages.mps.internal.createMpsBuildsContainer
import com.specificlanguages.mps.internal.registerArtifactDirectoriesVariant
Expand Down Expand Up @@ -98,6 +100,8 @@ open class MpsPlugin @Inject constructor(
extendsFrom(apiConfiguration.get(), testImplementationConfiguration.get())
}

val mpsLibrariesArtifactsProperties = layout.buildDirectory.file("mps-libraries-artifacts.properties")

val resolveMpsLibraries by tasks.registering(Sync::class) {
// Libraries of other projects (in this build or in included builds) are not extracted. To open the
// project in MPS, their sources are expected to be added to the MPS project as project libraries. The
Expand All @@ -111,6 +115,12 @@ open class MpsPlugin @Inject constructor(
into(mpsDefaults.mpsLibrariesDirectory)
group = "build setup"
description = "Downloads and extracts all external MPS libraries."

val librariesDirectory = mpsDefaults.mpsLibrariesDirectory
outputs.file(mpsLibrariesArtifactsProperties)
doLast {
writeArtifactsProperties(librariesDirectory.get().asFile, mpsLibrariesArtifactsProperties.get().asFile)
}
}

val setupTask = tasks.register("setup") {
Expand Down Expand Up @@ -142,6 +152,10 @@ open class MpsPlugin @Inject constructor(
val mpsBuilds = createMpsBuildsContainer(objects, tasks, generateBuildScriptsTask)
extensions.add(typeOf<PolymorphicDomainObjectContainer<MpsBuild>>(), "mpsBuilds", mpsBuilds)
configureProjectDependencies(mpsBuilds, mpsLibraries, providers)
configureLibrariesArtifactsProperties(
mpsBuilds,
files(mpsLibrariesArtifactsProperties).builtBy(resolveMpsLibraries)
)

configureMbeddrIntegration(project, mpsDefaults)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.gradle.api.provider.Property
import org.gradle.api.tasks.Classpath
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.PathSensitive
Expand Down Expand Up @@ -62,6 +63,14 @@ abstract class RunAnt : DefaultTask() {
@get:Internal("not considered inputs")
abstract val pathProperties: MapProperty<String, File>

/**
* Property files to load properties from, passed to Ant with `-propertyfile`. Properties given in
* [pathProperties] and [valueProperties] take precedence over properties loaded from these files.
*/
@get:InputFiles
@get:PathSensitive(PathSensitivity.NONE)
abstract val propertyFiles: ConfigurableFileCollection

/**
* Value properties (e.g. build numbers, version numbers, etc.). Considered task inputs.
*/
Expand Down Expand Up @@ -145,6 +154,10 @@ abstract class RunAnt : DefaultTask() {
private fun buildAntArguments(): List<String?> = buildList {
addAll(pathProperties.get().map { "-D${it.key}=${it.value}" })
addAll(valueProperties.get().map { "-D${it.key}=${it.value}" })
propertyFiles.forEach {
add("-propertyfile")
add(it.path)
}

addAll(options.get())

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.specificlanguages.mps.internal

import com.specificlanguages.mps.MpsBuild
import org.gradle.api.DomainObjectCollection
import org.gradle.api.file.FileCollection
import java.io.File
import java.util.Properties

/**
* Writes an `artifacts.<name>` property for each top-level directory `<name>` of the extracted MPS libraries in
* [librariesDirectory].
*
* Zips produced by this plugin contain the artifacts directory of each published main build as a top-level directory.
* Its name usually matches the name of the MPS build project, and MPS-generated Ant scripts read the location of the
* artifacts of a dependency build project named `X` from the `artifacts.X` property.
*/
internal fun writeArtifactsProperties(librariesDirectory: File, propertiesFile: File) {
val properties = Properties()
librariesDirectory.listFiles()
?.filter { it.isDirectory }
?.forEach { properties["artifacts.${it.name}"] = it.absolutePath }

propertiesFile.parentFile.mkdirs()
propertiesFile.outputStream().use { properties.store(it, null) }
}

/**
* Passes [propertiesFile] (written by [writeArtifactsProperties]) to the Ant tasks of all [mpsBuilds].
*/
internal fun configureLibrariesArtifactsProperties(
mpsBuilds: DomainObjectCollection<MpsBuild>,
propertiesFile: FileCollection
) {
mpsBuilds.configureEach {
antTasks(this).forEach { task ->
task.configure { propertyFiles.from(propertiesFile) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ internal fun configureProjectDependencies(
}
}

private fun antTasks(build: MpsBuild): List<TaskProvider<out RunAnt>> = when (build) {
internal fun antTasks(build: MpsBuild): List<TaskProvider<out RunAnt>> = when (build) {
is MainBuild -> listOf(build.generateTask, build.assembleTask)
is TestBuild -> listOf(build.generateTask, build.assembleAndCheckTask)
else -> listOf(build.generateTask)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package com.specificlanguages.mps
import org.gradle.testkit.runner.GradleRunner
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.*
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import java.io.File
import java.util.Properties
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream

Expand Down Expand Up @@ -100,6 +102,13 @@ class ProjectDependenciesTest {
.forEach { (key, value) -> println("${'$'}key=${'$'}{value.canonicalPath}") }
}
}

val generateMainPropertyFiles = tasks.named<RunAnt>("generateMain").map { it.propertyFiles.files }
tasks.register("printPropertyFiles") {
doLast {
generateMainPropertyFiles.get().forEach { println("propertyFile=${'$'}{it.canonicalPath}") }
}
}
""".trimIndent()
)
}
Expand Down Expand Up @@ -136,6 +145,30 @@ class ProjectDependenciesTest {
))
}

@Test
fun `setup writes artifacts properties for top-level directories of external libraries`() {
runner(":a:setup").build()

val properties = Properties()
projectDir.resolve("a/build/mps-libraries-artifacts.properties").inputStream().use { properties.load(it) }

assertThat(properties.keys, contains("artifacts.ext"))
assertEquals(
projectDir.resolve("a/build/dependencies/ext").canonicalPath,
File(properties.getProperty("artifacts.ext")).canonicalPath
)
}

@Test
fun `Ant tasks load artifacts properties of external libraries`() {
val dryRunLines = runner(":a:generateMain", "--dry-run").build().output.lines()
assertThat(dryRunLines, containsInRelativeOrder(":a:resolveMpsLibraries SKIPPED", ":a:generateMain SKIPPED"))

val lines = runner(":a:printPropertyFiles").build().output.lines()
val expected = projectDir.canonicalFile.resolve("a/build/mps-libraries-artifacts.properties").path
assertThat(lines, hasItem("propertyFile=$expected"))
}

private fun runner(vararg arguments: String): GradleRunner = GradleRunner.create()
.withProjectDir(projectDir)
.withPluginClasspath()
Expand Down