Skip to content

Commit

Permalink
Reformat code to match Kotlin official style
Browse files Browse the repository at this point in the history
  • Loading branch information
Virtlink committed May 27, 2024
1 parent 6660a2b commit eed8ae9
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 130 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plugins {
id("org.metaborg.gradle.config.root-project") version "0.4.8"
id("org.metaborg.gitonium") version "1.2.0"
id("org.metaborg.gradle.config.root-project") version "0.4.8"
id("org.metaborg.gitonium") version "1.2.0"
}
18 changes: 9 additions & 9 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
plugins {
id("org.metaborg.gradle.config.root-project") version "0.4.8"
id("org.metaborg.gitonium") version "1.2.0"
id("org.metaborg.gradle.config.root-project") version "0.4.8"
id("org.metaborg.gitonium") version "1.2.0"

// Set versions for plugins to use, only applying them in subprojects (apply false here).
id("org.metaborg.spoofax.gradle.langspec") apply false // No version: use the plugin from the included composite build
id("org.metaborg.spoofax.gradle.project") apply false
id("org.metaborg.spoofax.gradle.test") apply false
// Set versions for plugins to use, only applying them in subprojects (apply false here).
id("org.metaborg.spoofax.gradle.langspec") apply false // No version: use the plugin from the included composite build
id("org.metaborg.spoofax.gradle.project") apply false
id("org.metaborg.spoofax.gradle.test") apply false
}

subprojects {
metaborg {
configureSubProject()
}
metaborg {
configureSubProject()
}
}
4 changes: 2 additions & 2 deletions example/empty/empty.example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id("org.metaborg.spoofax.gradle.project")
id("org.metaborg.spoofax.gradle.project")
}

dependencies {
compileLanguage(project(":empty"))
compileLanguage(project(":empty"))
}
6 changes: 3 additions & 3 deletions example/empty/empty.test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugins {
id("org.metaborg.spoofax.gradle.test")
id("org.metaborg.spoofax.gradle.test")
}

spoofaxTest {
languageUnderTest.set(org.metaborg.core.language.LanguageIdentifier.parse("$group:empty:$version"))
languageUnderTest.set(org.metaborg.core.language.LanguageIdentifier.parse("$group:empty:$version"))
}

dependencies {
compileLanguage(project(":empty"))
compileLanguage(project(":empty"))
}
2 changes: 1 addition & 1 deletion example/empty/empty/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
plugins {
id("org.metaborg.spoofax.gradle.langspec")
id("org.metaborg.spoofax.gradle.langspec")
}
4 changes: 2 additions & 2 deletions example/language_contribution_addition/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import org.metaborg.core.language.*

plugins {
id("org.metaborg.spoofax.gradle.langspec")
id("org.metaborg.spoofax.gradle.langspec")
}

spoofaxLanguageSpecification {
languageContributions.add(LanguageContributionIdentifier(LanguageIdentifier(group.toString() + ".test", name + "_test", LanguageVersion.parse(version.toString() + "-test")), "lca"))
languageContributions.add(LanguageContributionIdentifier(LanguageIdentifier(group.toString() + ".test", name + "_test", LanguageVersion.parse(version.toString() + "-test")), "lca"))
}
6 changes: 3 additions & 3 deletions example/language_contribution_override/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import org.metaborg.core.language.*

plugins {
id("org.metaborg.spoofax.gradle.langspec")
id("org.metaborg.spoofax.gradle.langspec")
}

spoofaxLanguageSpecification {
addLanguageContributionsFromMetaborgYaml.set(false)
languageContributions.add(LanguageContributionIdentifier(LanguageIdentifier(group.toString(), name, LanguageVersion.parse(version.toString())), "lco"))
addLanguageContributionsFromMetaborgYaml.set(false)
languageContributions.add(LanguageContributionIdentifier(LanguageIdentifier(group.toString(), name, LanguageVersion.parse(version.toString())), "lco"))
}
20 changes: 10 additions & 10 deletions example/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
rootProject.name = "spoofax.gradle.example"

pluginManagement {
repositories {
maven("https://artifacts.metaborg.org/content/groups/public/")
}
repositories {
maven("https://artifacts.metaborg.org/content/groups/public/")
}
}

// Only include composite builds when this is the root project (it has no parent), for example when running Gradle tasks
// from the command-line. Otherwise, the parent project will include these composite builds.
if(gradle.parent == null) {
includeBuild("../plugin")
if (gradle.parent == null) {
includeBuild("../plugin")
}

fun String.includeProject(id: String, path: String = "$this/$id") {
include(id)
project(":$id").projectDir = file(path)
include(id)
project(":$id").projectDir = file(path)
}

"empty".run {
includeProject("empty")
includeProject("empty.example")
includeProject("empty.test")
includeProject("empty")
includeProject("empty.example")
includeProject("empty.test")
}

include("stratego_format_override")
Expand Down
4 changes: 2 additions & 2 deletions example/stratego_format_override/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id("org.metaborg.spoofax.gradle.langspec")
id("org.metaborg.spoofax.gradle.langspec")
}

spoofaxLanguageSpecification {
strategoFormat.set(org.metaborg.spoofax.meta.core.config.StrategoFormat.jar)
strategoFormat.set(org.metaborg.spoofax.meta.core.config.StrategoFormat.jar)
}
192 changes: 96 additions & 96 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,140 +8,140 @@
*/

buildscript {
if(gradle.parent?.rootProject?.name == "spoofax.gradle.root") { // If standalone build, put additional plugins on the classpath.
repositories {
maven("https://artifacts.metaborg.org/content/groups/public/")
if (gradle.parent?.rootProject?.name == "spoofax.gradle.root") { // If standalone build, put additional plugins on the classpath.
repositories {
maven("https://artifacts.metaborg.org/content/groups/public/")
}
dependencies {
classpath("org.metaborg:gradle.config:0.4.8")
classpath("org.metaborg:gitonium:1.1.0")
}
}
dependencies {
classpath("org.metaborg:gradle.config:0.4.8")
classpath("org.metaborg:gitonium:1.1.0")
}
}
}

plugins {
`java-gradle-plugin`
`kotlin-dsl`
`maven-publish`
`java-gradle-plugin`
`kotlin-dsl`
`maven-publish`
}

var spoofax2Version: String
var spoofax2CoreDependency: String
val standaloneBuild = gradle.parent?.rootProject?.name == "spoofax.gradle.root"
if(standaloneBuild) { // If standalone build, apply additional plugins and set different dependencies.
apply(plugin = "org.metaborg.gradle.config.root-project")
apply(plugin = "org.metaborg.gitonium")
spoofax2Version = System.getProperty("spoofax2Version")
spoofax2CoreDependency = "org.metaborg:org.metaborg.spoofax.core:$spoofax2Version"
// Embed Spoofax Core dependencies into the plugin so that users do not receive the transitive dependency tree.
val embedded: Configuration = configurations.create("embedded")
configurations.getByName(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME).extendsFrom(embedded)
dependencies {
embedded("org.metaborg:org.metaborg.spoofax.meta.core:$spoofax2Version")
embedded("org.metaborg:org.metaborg.spt.core:$spoofax2Version")
}
tasks {
jar {
// Closure inside from to defer evaluation of configuration until task execution time.
from({ embedded.filter { it.exists() }.map { if(it.isDirectory) it else zipTree(it) } }) {
// Exclude signature files from dependencies, otherwise the JVM will refuse to load the created JAR file.
exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA")
}
// Enable zip64 to support ZIP files with more than 2^16 entries, which we need.
isZip64 = true
// Allow duplicates, as Spoofax 2 has several duplicate things on the classpath.
duplicatesStrategy = DuplicatesStrategy.INCLUDE
if (standaloneBuild) { // If standalone build, apply additional plugins and set different dependencies.
apply(plugin = "org.metaborg.gradle.config.root-project")
apply(plugin = "org.metaborg.gitonium")
spoofax2Version = System.getProperty("spoofax2Version")
spoofax2CoreDependency = "org.metaborg:org.metaborg.spoofax.core:$spoofax2Version"
// Embed Spoofax Core dependencies into the plugin so that users do not receive the transitive dependency tree.
val embedded: Configuration = configurations.create("embedded")
configurations.getByName(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME).extendsFrom(embedded)
dependencies {
embedded("org.metaborg:org.metaborg.spoofax.meta.core:$spoofax2Version")
embedded("org.metaborg:org.metaborg.spt.core:$spoofax2Version")
}
tasks {
jar {
// Closure inside from to defer evaluation of configuration until task execution time.
from({ embedded.filter { it.exists() }.map { if (it.isDirectory) it else zipTree(it) } }) {
// Exclude signature files from dependencies, otherwise the JVM will refuse to load the created JAR file.
exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA")
}
// Enable zip64 to support ZIP files with more than 2^16 entries, which we need.
isZip64 = true
// Allow duplicates, as Spoofax 2 has several duplicate things on the classpath.
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
}
}
} else {
spoofax2Version = ext["spoofax2Version"]!!.toString()
spoofax2CoreDependency = "$group:org.metaborg.spoofax.core:$version"
dependencies {
api("$group:org.metaborg.spoofax.meta.core:$version")
api("$group:org.metaborg.spt.core:$version")
}
spoofax2Version = ext["spoofax2Version"]!!.toString()
spoofax2CoreDependency = "$group:org.metaborg.spoofax.core:$version"
dependencies {
api("$group:org.metaborg.spoofax.meta.core:$version")
api("$group:org.metaborg.spt.core:$version")
}
}

configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
configure<mb.gradle.config.MetaborgExtension> {
kotlinApiVersion = "1.2"
kotlinLanguageVersion = "1.2"
kotlinApiVersion = "1.2"
kotlinLanguageVersion = "1.2"
}

dependencies {
/*
org.metaborg.spoofax.meta.core depends on older version of several artifacts. Due to an issue in Gradle, the first
version of those artifacts that are loaded will be used by code in plugins that react to certain Gradle events, such
as Project#afterEvaluate. Since the old versions do not have certain APIs, this will fail. Therefore, we force the
versions to the latest ones.
*/
api("org.metaborg:resource:0.14.1")
api("org.metaborg:common:0.11.0")
api("org.metaborg:pie.runtime:0.21.0")
/*
org.metaborg.spoofax.meta.core depends on older version of several artifacts. Due to an issue in Gradle, the first
version of those artifacts that are loaded will be used by code in plugins that react to certain Gradle events, such
as Project#afterEvaluate. Since the old versions do not have certain APIs, this will fail. Therefore, we force the
versions to the latest ones.
*/
api("org.metaborg:resource:0.14.1")
api("org.metaborg:common:0.11.0")
api("org.metaborg:pie.runtime:0.21.0")
}

gradlePlugin {
plugins {
val pluginIdAffix = if(!standaloneBuild) ".devenv" else ""
create("spoofax-base") {
id = "org.metaborg$pluginIdAffix.spoofax.gradle.base"
implementationClass = "mb.spoofax.gradle.plugin.SpoofaxBasePlugin"
}
create("spoofax-language-specification") {
id = "org.metaborg$pluginIdAffix.spoofax.gradle.langspec"
implementationClass = "mb.spoofax.gradle.plugin.SpoofaxLanguageSpecificationPlugin"
}
create("spoofax-project") {
id = "org.metaborg$pluginIdAffix.spoofax.gradle.project"
implementationClass = "mb.spoofax.gradle.plugin.SpoofaxProjectPlugin"
}
create("spoofax-test") {
id = "org.metaborg$pluginIdAffix.spoofax.gradle.test"
implementationClass = "mb.spoofax.gradle.plugin.SpoofaxTestPlugin"
plugins {
val pluginIdAffix = if (!standaloneBuild) ".devenv" else ""
create("spoofax-base") {
id = "org.metaborg$pluginIdAffix.spoofax.gradle.base"
implementationClass = "mb.spoofax.gradle.plugin.SpoofaxBasePlugin"
}
create("spoofax-language-specification") {
id = "org.metaborg$pluginIdAffix.spoofax.gradle.langspec"
implementationClass = "mb.spoofax.gradle.plugin.SpoofaxLanguageSpecificationPlugin"
}
create("spoofax-project") {
id = "org.metaborg$pluginIdAffix.spoofax.gradle.project"
implementationClass = "mb.spoofax.gradle.plugin.SpoofaxProjectPlugin"
}
create("spoofax-test") {
id = "org.metaborg$pluginIdAffix.spoofax.gradle.test"
implementationClass = "mb.spoofax.gradle.plugin.SpoofaxTestPlugin"
}
}
}
}

// Add generated resources directory as a resource source directory.
val generatedResourcesDir = project.buildDir.resolve("generated/resources")
sourceSets {
main {
resources {
srcDir(generatedResourcesDir)
main {
resources {
srcDir(generatedResourcesDir)
}
}
}
}
// Task that writes properties to a config.properties file, which is used in the plugin.
val propertiesFile = generatedResourcesDir.resolve("config.properties")
val generatePropertiesTask = tasks.register("generateConfigProperties") {
inputs.property("spoofax2Version", spoofax2Version)
inputs.property("spoofax2CoreDependency", spoofax2CoreDependency)
outputs.file(propertiesFile)
doLast {
val properties = NonShittyProperties()
properties.setProperty("spoofax2Version", spoofax2Version)
properties.setProperty("spoofax2CoreDependency", spoofax2CoreDependency)
propertiesFile.parentFile.run { if(!exists()) mkdirs() }
propertiesFile.bufferedWriter().use {
properties.storeWithoutDate(it)
inputs.property("spoofax2Version", spoofax2Version)
inputs.property("spoofax2CoreDependency", spoofax2CoreDependency)
outputs.file(propertiesFile)
doLast {
val properties = NonShittyProperties()
properties.setProperty("spoofax2Version", spoofax2Version)
properties.setProperty("spoofax2CoreDependency", spoofax2CoreDependency)
propertiesFile.parentFile.run { if (!exists()) mkdirs() }
propertiesFile.bufferedWriter().use {
properties.storeWithoutDate(it)
}
}
}
}
tasks.compileJava.configure { dependsOn(generatePropertiesTask) }
tasks.processResources.configure { dependsOn(generatePropertiesTask) }
// Custom properties class that does not write the current date, fixing incrementality.
class NonShittyProperties : java.util.Properties() {
fun storeWithoutDate(writer: java.io.BufferedWriter) {
val e: java.util.Enumeration<*> = keys()
while(e.hasMoreElements()) {
val key = e.nextElement()
val value = get(key)
writer.write("$key=$value")
writer.newLine()
fun storeWithoutDate(writer: java.io.BufferedWriter) {
val e: java.util.Enumeration<*> = keys()
while (e.hasMoreElements()) {
val key = e.nextElement()
val value = get(key)
writer.write("$key=$value")
writer.newLine()
}
writer.flush()
}
writer.flush()
}
}

0 comments on commit eed8ae9

Please sign in to comment.