Skip to content

Commit 94fde53

Browse files
committed
Update to current code
1 parent 9df635c commit 94fde53

File tree

10 files changed

+101
-109
lines changed

10 files changed

+101
-109
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Just click on [![Use this template](https://img.shields.io/badge/-Use%20this%20t
1212

1313
Once created don't forget to update the:
1414
- [gradle.properties](plugin-build/gradle.properties)
15-
- Plugin Usages (search for [com.ncorti.kotlin.gradle.template](https://github.com/cortinico/kotlin-gradle-plugin-template/search?q=com.ncorti.kotlin.gradle.template&unscoped_q=com.ncorti.kotlin.gradle.template) in the repo and replace it with your ID).
15+
- Plugin Usages (search for [org.skriptlang.gradle.test.plugin](https://github.com/cortinico/kotlin-gradle-plugin-template/search?q=org.skriptlang.gradle.test.plugin&unscoped_q=org.skriptlang.gradle.test.plugin) in the repo and replace it with your ID).
1616

1717
## Features 🎨
1818

example/build.gradle.kts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
plugins {
22
java
3-
id("com.ncorti.kotlin.gradle.template.plugin")
3+
id("org.skriptlang.gradle.test.plugin")
44
}
55

6-
templateExampleConfig {
7-
message.set("Just trying this gradle plugin...")
6+
tasks.skriptTest {
7+
extraPluginsDirectory = File("build.gradle.kts")
8+
testScriptDirectory = File("build.gradle.kts")
89
}

plugin-build/gradle.properties

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
ID=com.ncorti.kotlin.gradle.template.plugin
1+
ID=org.skriptlang.gradle.test.plugin
22
VERSION=1.0.0
3-
GROUP=com.ncorti.kotlin.gradle.template
4-
DISPLAY_NAME=An empty Gradle Plugin from a template
5-
DESCRIPTION=An empty Gradle plugin created from a template
6-
WEBSITE=https://github.com/cortinico/kotlin-gradle-plugin-template
7-
VCS_URL=https://github.com/cortinico/kotlin-gradle-plugin-template
8-
IMPLEMENTATION_CLASS=com.ncorti.kotlin.gradle.template.plugin.TemplatePlugin
3+
GROUP=org.skriptlang.gradle.test
4+
DISPLAY_NAME=A Gradle plugin to run Skript tests
5+
DESCRIPTION=A Gradle plugin to run Skript tests
6+
WEBSITE=https://github.com/SkriptLang/skript-test-gradle-plugin
7+
VCS_URL=https://github.com/SkriptLang/skript-test-gradle-plugin
8+
IMPLEMENTATION_CLASS=org.skriptlang.gradle.test.plugin.TemplatePlugin

plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExampleTask.kt

Lines changed: 0 additions & 42 deletions
This file was deleted.

plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplateExtension.kt

Lines changed: 0 additions & 28 deletions
This file was deleted.

plugin-build/plugin/src/main/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePlugin.kt

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package org.skriptlang.gradle.test.plugin
2+
3+
import org.gradle.api.DefaultTask
4+
import org.gradle.api.file.RegularFileProperty
5+
import org.gradle.api.plugins.BasePlugin
6+
import org.gradle.api.provider.Property
7+
import org.gradle.api.tasks.Input
8+
import org.gradle.api.tasks.InputFile
9+
import org.gradle.api.tasks.Optional
10+
import org.gradle.api.tasks.TaskAction
11+
import org.gradle.api.tasks.options.Option
12+
import java.nio.file.Files
13+
import java.nio.file.Path
14+
15+
abstract class SkriptTestTask : DefaultTask() {
16+
init {
17+
description = "Run Skript tests"
18+
group = BasePlugin.BUILD_GROUP
19+
}
20+
21+
@get:InputFile
22+
@get:Option(option = "testScriptDirectory", description = "The directory containing the test scripts to run")
23+
abstract val testScriptDirectory: RegularFileProperty
24+
25+
@get:InputFile
26+
@get:Option(option = "extraPluginsDirectory", description = "The directory of extra plugins to put on the test server")
27+
abstract val extraPluginsDirectory: RegularFileProperty
28+
29+
@get:Input
30+
@get:Option(option = "skriptRepoRef", description = "The Git ref to check out the Skript repo at")
31+
@get:Optional
32+
abstract val skriptRepoRef: Property<String>
33+
34+
@get:Input
35+
@get:Option(option = "skriptRepo", description = "The Git URL to the Skript repo")
36+
@get:Optional
37+
abstract val skriptRepo: Property<String>
38+
39+
@get:Input
40+
@get:Option(option = "runVanillaTests", description = "Controls whether the vanilla Skript tests are run")
41+
@get:Optional
42+
abstract val runVanillaTests: Property<Boolean>
43+
44+
fun runCommand(requiredExitValue: Int, workingDirectory: Path, vararg command: String) {
45+
val processBuilder = ProcessBuilder(command.asList()).directory(workingDirectory.toFile())
46+
val process = processBuilder.start()
47+
process.waitFor()
48+
if (process.exitValue() != requiredExitValue) {
49+
throw IllegalStateException("${command.joinToString(" ")} returned exit code ${process.exitValue()}")
50+
}
51+
}
52+
53+
@TaskAction
54+
fun runTests() {
55+
val skriptRepoDir = Files.createTempDirectory("skript-test-skript-repo").toAbsolutePath()
56+
runCommand(0, skriptRepoDir, "git", "init")
57+
runCommand(0, skriptRepoDir, "git", "remote", "add", "origin", skriptRepo.getOrElse("https://github.com/SkriptLang/Skript.git"))
58+
runCommand(0, skriptRepoDir, "git", "fetch", "--depth", "1", "origin", skriptRepoRef.getOrElse("master"))
59+
runCommand(0, skriptRepoDir, "git", "checkout", "FETCH_HEAD")
60+
runCommand(0, skriptRepoDir, "git", "submodule", "update", "--init", "--depth", "1")
61+
try {
62+
runCommand(0, skriptRepoDir, "./gradlew.bat", "quick")
63+
} catch (exception: IllegalStateException) {
64+
throw IllegalStateException("Tests failed")
65+
}
66+
}
67+
68+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.skriptlang.gradle.test.plugin
2+
3+
import org.gradle.api.Plugin
4+
import org.gradle.api.Project
5+
6+
const val EXTENSION_NAME = "templateExampleConfig"
7+
8+
abstract class TemplatePlugin : Plugin<Project> {
9+
override fun apply(project: Project) {
10+
project.tasks.register("skriptTest", SkriptTestTask::class.java)
11+
}
12+
}

plugin-build/plugin/src/test/java/com/ncorti/kotlin/gradle/template/plugin/TemplatePluginTest.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
1-
package com.ncorti.kotlin.gradle.template.plugin
1+
package org.skriptlang.gradle.test.plugin.plugin
22

33
import org.gradle.testfixtures.ProjectBuilder
44
import org.junit.Assert.assertEquals
55
import org.junit.Assert.assertNotNull
66
import org.junit.Test
7+
import org.skriptlang.gradle.test.plugin.SkriptTestTask
8+
import org.skriptlang.gradle.test.plugin.TemplateExtension
79
import java.io.File
810

911
class TemplatePluginTest {
1012
@Test
1113
fun `plugin is applied correctly to the project`() {
1214
val project = ProjectBuilder.builder().build()
13-
project.pluginManager.apply("com.ncorti.kotlin.gradle.template.plugin")
15+
project.pluginManager.apply("org.skriptlang.gradle.test.plugin.plugin")
1416

15-
assert(project.tasks.getByName("templateExample") is TemplateExampleTask)
17+
assert(project.tasks.getByName("templateExample") is SkriptTestTask)
1618
}
1719

1820
@Test
1921
fun `extension templateExampleConfig is created correctly`() {
2022
val project = ProjectBuilder.builder().build()
21-
project.pluginManager.apply("com.ncorti.kotlin.gradle.template.plugin")
23+
project.pluginManager.apply("org.skriptlang.gradle.test.plugin.plugin")
2224

2325
assertNotNull(project.extensions.getByName("templateExampleConfig"))
2426
}
2527

2628
@Test
2729
fun `parameters are passed correctly from extension to task`() {
2830
val project = ProjectBuilder.builder().build()
29-
project.pluginManager.apply("com.ncorti.kotlin.gradle.template.plugin")
31+
project.pluginManager.apply("org.skriptlang.gradle.test.plugin.plugin")
3032
val aFile = File(project.projectDir, ".tmp")
3133
(project.extensions.getByName("templateExampleConfig") as TemplateExtension).apply {
3234
tag.set("a-sample-tag")
3335
message.set("just-a-message")
3436
outputFile.set(aFile)
3537
}
3638

37-
val task = project.tasks.getByName("templateExample") as TemplateExampleTask
39+
val task = project.tasks.getByName("templateExample") as SkriptTestTask
3840

3941
assertEquals("a-sample-tag", task.tag.get())
4042
assertEquals("just-a-message", task.message.get())

plugin-build/settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ develocity {
3131
}
3232
}
3333

34-
rootProject.name = ("com.ncorti.kotlin.gradle.template")
34+
rootProject.name = ("org.skriptlang.gradle.test.plugin")
3535

3636
include(":plugin")

0 commit comments

Comments
 (0)