Skip to content

Commit

Permalink
Update to current code
Browse files Browse the repository at this point in the history
  • Loading branch information
Pikachu920 committed Sep 8, 2024
1 parent 9df635c commit 94fde53
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 109 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Just click on [![Use this template](https://img.shields.io/badge/-Use%20this%20t

Once created don't forget to update the:
- [gradle.properties](plugin-build/gradle.properties)
- 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).
- 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).

## Features 🎨

Expand Down
7 changes: 4 additions & 3 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
plugins {
java
id("com.ncorti.kotlin.gradle.template.plugin")
id("org.skriptlang.gradle.test.plugin")
}

templateExampleConfig {
message.set("Just trying this gradle plugin...")
tasks.skriptTest {
extraPluginsDirectory = File("build.gradle.kts")
testScriptDirectory = File("build.gradle.kts")
}
14 changes: 7 additions & 7 deletions plugin-build/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ID=com.ncorti.kotlin.gradle.template.plugin
ID=org.skriptlang.gradle.test.plugin
VERSION=1.0.0
GROUP=com.ncorti.kotlin.gradle.template
DISPLAY_NAME=An empty Gradle Plugin from a template
DESCRIPTION=An empty Gradle plugin created from a template
WEBSITE=https://github.com/cortinico/kotlin-gradle-plugin-template
VCS_URL=https://github.com/cortinico/kotlin-gradle-plugin-template
IMPLEMENTATION_CLASS=com.ncorti.kotlin.gradle.template.plugin.TemplatePlugin
GROUP=org.skriptlang.gradle.test
DISPLAY_NAME=A Gradle plugin to run Skript tests
DESCRIPTION=A Gradle plugin to run Skript tests
WEBSITE=https://github.com/SkriptLang/skript-test-gradle-plugin
VCS_URL=https://github.com/SkriptLang/skript-test-gradle-plugin
IMPLEMENTATION_CLASS=org.skriptlang.gradle.test.plugin.TemplatePlugin

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.skriptlang.gradle.test.plugin

import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.plugins.BasePlugin
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option
import java.nio.file.Files
import java.nio.file.Path

abstract class SkriptTestTask : DefaultTask() {
init {
description = "Run Skript tests"
group = BasePlugin.BUILD_GROUP
}

@get:InputFile
@get:Option(option = "testScriptDirectory", description = "The directory containing the test scripts to run")
abstract val testScriptDirectory: RegularFileProperty

@get:InputFile
@get:Option(option = "extraPluginsDirectory", description = "The directory of extra plugins to put on the test server")
abstract val extraPluginsDirectory: RegularFileProperty

@get:Input
@get:Option(option = "skriptRepoRef", description = "The Git ref to check out the Skript repo at")
@get:Optional
abstract val skriptRepoRef: Property<String>

@get:Input
@get:Option(option = "skriptRepo", description = "The Git URL to the Skript repo")
@get:Optional
abstract val skriptRepo: Property<String>

@get:Input
@get:Option(option = "runVanillaTests", description = "Controls whether the vanilla Skript tests are run")
@get:Optional
abstract val runVanillaTests: Property<Boolean>

fun runCommand(requiredExitValue: Int, workingDirectory: Path, vararg command: String) {
val processBuilder = ProcessBuilder(command.asList()).directory(workingDirectory.toFile())
val process = processBuilder.start()
process.waitFor()
if (process.exitValue() != requiredExitValue) {
throw IllegalStateException("${command.joinToString(" ")} returned exit code ${process.exitValue()}")
}
}

@TaskAction
fun runTests() {
val skriptRepoDir = Files.createTempDirectory("skript-test-skript-repo").toAbsolutePath()
runCommand(0, skriptRepoDir, "git", "init")
runCommand(0, skriptRepoDir, "git", "remote", "add", "origin", skriptRepo.getOrElse("https://github.com/SkriptLang/Skript.git"))
runCommand(0, skriptRepoDir, "git", "fetch", "--depth", "1", "origin", skriptRepoRef.getOrElse("master"))
runCommand(0, skriptRepoDir, "git", "checkout", "FETCH_HEAD")
runCommand(0, skriptRepoDir, "git", "submodule", "update", "--init", "--depth", "1")
try {
runCommand(0, skriptRepoDir, "./gradlew.bat", "quick")
} catch (exception: IllegalStateException) {
throw IllegalStateException("Tests failed")
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.skriptlang.gradle.test.plugin

import org.gradle.api.Plugin
import org.gradle.api.Project

const val EXTENSION_NAME = "templateExampleConfig"

abstract class TemplatePlugin : Plugin<Project> {
override fun apply(project: Project) {
project.tasks.register("skriptTest", SkriptTestTask::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
package com.ncorti.kotlin.gradle.template.plugin
package org.skriptlang.gradle.test.plugin.plugin

import org.gradle.testfixtures.ProjectBuilder
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Test
import org.skriptlang.gradle.test.plugin.SkriptTestTask
import org.skriptlang.gradle.test.plugin.TemplateExtension
import java.io.File

class TemplatePluginTest {
@Test
fun `plugin is applied correctly to the project`() {
val project = ProjectBuilder.builder().build()
project.pluginManager.apply("com.ncorti.kotlin.gradle.template.plugin")
project.pluginManager.apply("org.skriptlang.gradle.test.plugin.plugin")

assert(project.tasks.getByName("templateExample") is TemplateExampleTask)
assert(project.tasks.getByName("templateExample") is SkriptTestTask)
}

@Test
fun `extension templateExampleConfig is created correctly`() {
val project = ProjectBuilder.builder().build()
project.pluginManager.apply("com.ncorti.kotlin.gradle.template.plugin")
project.pluginManager.apply("org.skriptlang.gradle.test.plugin.plugin")

assertNotNull(project.extensions.getByName("templateExampleConfig"))
}

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

val task = project.tasks.getByName("templateExample") as TemplateExampleTask
val task = project.tasks.getByName("templateExample") as SkriptTestTask

assertEquals("a-sample-tag", task.tag.get())
assertEquals("just-a-message", task.message.get())
Expand Down
2 changes: 1 addition & 1 deletion plugin-build/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ develocity {
}
}

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

include(":plugin")

0 comments on commit 94fde53

Please sign in to comment.