diff --git a/.github/workflows/build-prs.yml b/.github/workflows/build-prs.yml index 465d0c7..11e73a0 100644 --- a/.github/workflows/build-prs.yml +++ b/.github/workflows/build-prs.yml @@ -7,24 +7,14 @@ on: - opened - ready_for_review - reopened + push: + branches: + - 'feature/**' + workflow_dispatch: jobs: - jdk17: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 1000 - fetch-tags: true - - - name: Setup JDK 17 - uses: actions/setup-java@v2 - with: - java-version: '17' - distribution: 'temurin' - - - name: Build with Gradle - uses: gradle/gradle-build-action@v2 - with: - arguments: build \ No newline at end of file + build: + uses: neoforged/actions/.github/workflows/build-prs.yml@main + with: + java: 17 + gradle_tasks: test \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d75f12b..22452cc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,20 +9,18 @@ permissions: statuses: write jobs: - build: + release: uses: neoforged/actions/.github/workflows/gradle-publish.yml@main with: java: 17 - # pre_gradle_tasks: ':test' TODO - proper unit tests - gradle_tasks: ':publish closeAndReleaseSonatypeStagingRepository' + pre_gradle_tasks: test + gradle_tasks: publish closeAndReleaseSonatypeStagingRepository secrets: DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} - MAVEN_USER: ${{ secrets.MAVEN_USER }} MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} - + GPG_SUBKEY: ${{ secrets.GPG_SUBKEY }} + GPG_SUBKEY_ID: ${{ secrets.GPG_SUBKEY_ID }} + GPG_SUBKEY_PASSWORD: ${{ secrets.GPG_SUBKEY_PASSWORD }} SONATYPE_USER: ${{ secrets.SONATYPE_USER }} - SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} - - GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} - GPG_KEY_PASSWORD: ${{ secrets.GPG_KEY_PASSWORD }} \ No newline at end of file + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index e2828a1..76ffb79 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ build/ .settings/ bin/ *.launch +!src/test/resources diff --git a/build.gradle b/build.gradle index 91c4c6a..95c2af3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,23 @@ +import net.neoforged.gradleutils.PomUtilsExtension.License + plugins { id 'java-library' - id 'net.neoforged.gradleutils' + id 'net.neoforged.gradleutils' version '3.+' id 'maven-publish' - id 'signing' - id 'io.github.gradle-nexus.publish-plugin' version '1.3.0' } group = 'net.neoforged' -version = gradleutils.getTagOffsetVersion() +version = gradleutils.version repositories { mavenCentral() } +gradleutils { + setupSigning() + setupCentralPublishing() +} + java { toolchain { languageVersion = JavaLanguageVersion.of(17) @@ -22,9 +27,13 @@ java { } dependencies { - annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:0.4.2' - compileOnly 'com.github.bsideup.jabel:jabel-javac-plugin:0.4.2' + annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0' + annotationProcessor("net.java.dev.jna:jna-platform:5.13.0") + compileOnly 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0' compileOnly 'org.jetbrains:annotations:24.0.1' + + testImplementation(libs.junit.api) + testRuntimeOnly(libs.junit.engine) } // Uses https://github.com/bsideup/jabel to compile to Java 8 from Java 16 source. @@ -50,25 +59,11 @@ tasks.withType(Javadoc).configureEach { options.addStringOption('Xdoclint:all,-missing', '-public') } -tasks.register('hello') { - doLast { - println 'Hello from Gradle!' - if (project.hasProperty('helloReply')){ - println helloReply - } - // Test for --no-daemon launches to verify that the task was invoked. - new File(projectDir, "hello.txt").text = "Hello from Gradle inside a file!" - } -} - -nexusPublishing { - repositories { - sonatype { - username.set(System.getenv('SONATYPE_USER') ?: '') - password.set(System.getenv('SONATYPE_PASSWORD') ?: '') - nexusUrl.set(uri('https://s01.oss.sonatype.org/service/local/')) - } - } +test { + javaLauncher.set(javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(17) + }) + useJUnitPlatform() } publishing { @@ -79,52 +74,18 @@ publishing { pom { name = project.name description = 'A Java library for generating Eclipse Launch Configurations (.launch files).' - url = 'https://github.com/NeoForged/EclipseLaunchConfigs' - - scm { - url = 'https://github.com/NeoForged/EclipseLaunchConfigs' - connection = 'scm:git:git://github.com/NeoForged/EclipseLaunchConfigs.git' - developerConnection = 'scm:git:git@github.com:NeoForged/EclipseLaunchConfigs.git' - } - - issueManagement { - system = 'github' - url = 'https://github.com/NeoForged/EclipseLaunchConfigs/issues' - } - - licenses { - license { - name = 'LGPL 2.1' - url = 'https://github.com/NeoForged/EclipseLaunchConfigs/blob/main/LICENSE' - distribution = 'repo' - } - } - - developers { - developer { - id = 'neoforged' - name = 'NeoForged' - email = 'contact@neoforged.net' - url = 'https://github.com/NeoForged/' - } - } + + pomUtils.neoForgedDeveloper(it) + pomUtils.license(it, License.LGPL_v2) + pomUtils.githubRepo(it, 'EclipseLaunchConfigs') } } } repositories { - maven gradleutils.getPublishingForgeMaven() + maven gradleutils.publishingMaven } } changelog { - fromTag '0.1' -} - -if (System.getenv('GPG_PRIVATE_KEY')) { - signing { - final signingKey = System.getenv('GPG_PRIVATE_KEY') ?: '' - final signingPassword = System.getenv('GPG_KEY_PASSWORD') ?: '' - useInMemoryPgpKeys(signingKey, signingPassword) - sign publishing.publications.mavenJava - } + from '0.1' } \ No newline at end of file diff --git a/hello.txt b/hello.txt deleted file mode 100644 index fd7982f..0000000 --- a/hello.txt +++ /dev/null @@ -1 +0,0 @@ -Hello from Gradle inside a file! \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 451438b..b122589 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,11 +1,10 @@ -pluginManagement { - repositories { - gradlePluginPortal() - maven { url = 'https://maven.neoforged.net/' } - } - - plugins { - id 'net.neoforged.gradleutils' version '2.0.+' +dependencyResolutionManagement { + versionCatalogs { + libs { + final jupiter = version 'jupiter', '5.7.2' + library('junit-api', 'org.junit.jupiter', 'junit-jupiter-api').versionRef(jupiter) + library('junit-engine', 'org.junit.jupiter', 'junit-jupiter-engine').versionRef(jupiter) + } } } diff --git a/src/test/java/net/neoforged/elc/tests/GradleLaunchConfigTest.java b/src/test/java/net/neoforged/elc/tests/GradleLaunchConfigTest.java new file mode 100644 index 0000000..932fcce --- /dev/null +++ b/src/test/java/net/neoforged/elc/tests/GradleLaunchConfigTest.java @@ -0,0 +1,18 @@ +package net.neoforged.elc.tests; + +import net.neoforged.elc.configs.GradleLaunchConfig; +import org.junit.jupiter.api.Test; + +public class GradleLaunchConfigTest extends RunTest { + @Test + public void testGradleConfig() throws Exception { + assertExpectedConfig(GradleLaunchConfig.builder("EclipseLaunchConfigs") + .tasks(":hello") + .showConsole(false) + .offlineMode(true) + .args("--console=plain") + .property("helloReply", "Hello from Eclipse!") + .jvmArgs("-Xmx256M") + .build(), "runGradle.launch"); + } +} diff --git a/src/test/java/net/neoforged/elc/tests/JavaApplicationLaunchConfigTest.java b/src/test/java/net/neoforged/elc/tests/JavaApplicationLaunchConfigTest.java new file mode 100644 index 0000000..881cc59 --- /dev/null +++ b/src/test/java/net/neoforged/elc/tests/JavaApplicationLaunchConfigTest.java @@ -0,0 +1,17 @@ +package net.neoforged.elc.tests; + +import net.neoforged.elc.EclipseVariables; +import net.neoforged.elc.configs.JavaApplicationLaunchConfig; +import org.junit.jupiter.api.Test; + +public class JavaApplicationLaunchConfigTest extends RunTest { + @Test + public void testJavaConfig() throws Exception { + assertExpectedConfig(JavaApplicationLaunchConfig.builder("EclipseLaunchConfigs") + .envVar("PROMPT_VALUE", EclipseVariables.prompt("Enter Something", "Some")) + .envVar("CURRENT_DATE", EclipseVariables.currentDate("yyyy/MM/dd")) + .vmArgs("-Xmx256M") + .args("--doStuff=true") + .build("net.neoforged.elc.tests.Main"), "runJava.launch"); + } +} diff --git a/src/test/java/net/neoforged/elc/tests/LaunchGroupConfigTest.java b/src/test/java/net/neoforged/elc/tests/LaunchGroupConfigTest.java new file mode 100644 index 0000000..f0840a0 --- /dev/null +++ b/src/test/java/net/neoforged/elc/tests/LaunchGroupConfigTest.java @@ -0,0 +1,22 @@ +package net.neoforged.elc.tests; + +import net.neoforged.elc.configs.LaunchGroup; +import org.junit.jupiter.api.Test; + +public class LaunchGroupConfigTest extends RunTest { + @Test + public void testGroupConfig() throws Exception { + assertExpectedConfig(LaunchGroup.builder() + .entry(LaunchGroup.entry("EclipseLaunchConfigs - runGradle") + .enabled(true) + .adoptIfRunning(false) + .mode(LaunchGroup.Mode.RUN) + .action(LaunchGroup.Action.delay(2))) + .entry(LaunchGroup.entry("EclipseLaunchConfigs - runTest") + .enabled(true) + .adoptIfRunning(false) + .mode(LaunchGroup.Mode.DEBUG) + .action(LaunchGroup.Action.waitForTermination())) + .build(), "runGroup.launch"); + } +} diff --git a/src/test/java/net/neoforged/elc/tests/Main.java b/src/test/java/net/neoforged/elc/tests/Main.java deleted file mode 100644 index ad0c5b6..0000000 --- a/src/test/java/net/neoforged/elc/tests/Main.java +++ /dev/null @@ -1,69 +0,0 @@ -package net.neoforged.elc.tests; - -import java.io.FileWriter; -import java.io.IOException; -import java.nio.charset.StandardCharsets; - -import javax.xml.stream.XMLStreamException; - -import net.neoforged.elc.EclipseVariables; -import net.neoforged.elc.configs.GradleLaunchConfig; -import net.neoforged.elc.configs.JavaApplicationLaunchConfig; -import net.neoforged.elc.configs.LaunchConfig; -import net.neoforged.elc.configs.LaunchGroup; -import net.neoforged.elc.configs.LaunchGroup.Action; -import net.neoforged.elc.configs.LaunchGroup.Mode; - -public class Main { - - public static void main(String[] args) throws Exception { - - System.out.println("Prompt: " + System.getenv("PROMPT_VALUE")); - System.out.println("Date: " + System.getenv("CURRENT_DATE")); - - System.out.println("Args: "); - for (String s : args) System.out.println(s); - - writeLaunchToFile("EclipseLaunchConfigs - runTest", - JavaApplicationLaunchConfig.builder("EclipseLaunchConfigs") - .envVar("PROMPT_VALUE", EclipseVariables.prompt("Enter Something", "Some")) - .envVar("CURRENT_DATE", EclipseVariables.currentDate("yyyy/MM/dd")) - .vmArgs("-Xmx256M") - .args("--doStuff=true") - .build("net.neoforged.elc.tests.Main")); - - writeLaunchToFile("EclipseLaunchConfigs - runGradle", - GradleLaunchConfig.builder("EclipseLaunchConfigs") - .tasks(":hello") - .showConsole(false) - .offlineMode(true) - .args("--console=plain") - .property("helloReply", "Hello from Eclipse!") - .jvmArgs("-Xmx256M") - .build()); - - writeLaunchToFile("EclipseLaunchConfigs - runGroup", - LaunchGroup.builder() - .entry(LaunchGroup.entry("EclipseLaunchConfigs - runGradle") - .enabled(true) - .adoptIfRunning(false) - .mode(Mode.RUN) - .action(Action.delay(2))) - .entry(LaunchGroup.entry("EclipseLaunchConfigs - runTest") - .enabled(true) - .adoptIfRunning(false) - .mode(Mode.DEBUG) - .action(Action.waitForTermination())) - .build()); - - } - - public static void writeLaunchToFile(String fileName, LaunchConfig config) { - try (FileWriter writer = new FileWriter(fileName + ".launch", StandardCharsets.UTF_8, false)) { - config.write(writer); - } - catch (IOException | XMLStreamException e) { - e.printStackTrace(); - } - } -} diff --git a/src/test/java/net/neoforged/elc/tests/RunTest.java b/src/test/java/net/neoforged/elc/tests/RunTest.java new file mode 100644 index 0000000..9fb941d --- /dev/null +++ b/src/test/java/net/neoforged/elc/tests/RunTest.java @@ -0,0 +1,29 @@ +package net.neoforged.elc.tests; + +import net.neoforged.elc.configs.LaunchConfig; +import org.junit.jupiter.api.Assertions; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.stream.XMLStreamException; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; + +public abstract class RunTest { + protected final void assertExpectedConfig(LaunchConfig config, String name) throws XMLStreamException, ParserConfigurationException, IOException, SAXException { + final StringWriter writer = new StringWriter(); + config.write(writer); + final var factory = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + final var original = factory.parse(new ByteArrayInputStream(writer.toString().getBytes(StandardCharsets.UTF_8))); + final var in = RunTest.class.getResourceAsStream("/" + name); + final var fromFile = factory.parse(in); + in.close(); + + original.normalizeDocument(); + fromFile.normalizeDocument(); + Assertions.assertTrue(original.isEqualNode(fromFile), "Documents did not match!"); + } +}