From de665ab4989bceb4ff323ebc0851ef781a0ef5de Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Thu, 20 May 2021 23:47:48 +0100 Subject: [PATCH] Add SignedProjectTest #404 --- .../test/integration/SignedProjectTest.groovy | 96 +++++++++++++++++++ .../loom/test/util/ProjectTestTrait.groovy | 2 +- .../resources/projects/signed/build.gradle | 57 +++++++++++ .../java/net/fabricmc/example/ExampleLib.java | 13 +++ .../signed/main/resources/fabric.mod.json | 4 + .../resources/projects/signed/settings.gradle | 2 + 6 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 src/test/groovy/net/fabricmc/loom/test/integration/SignedProjectTest.groovy create mode 100644 src/test/resources/projects/signed/build.gradle create mode 100644 src/test/resources/projects/signed/main/java/net/fabricmc/example/ExampleLib.java create mode 100644 src/test/resources/projects/signed/main/resources/fabric.mod.json create mode 100644 src/test/resources/projects/signed/settings.gradle diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/SignedProjectTest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/SignedProjectTest.groovy new file mode 100644 index 0000000..3570b22 --- /dev/null +++ b/src/test/groovy/net/fabricmc/loom/test/integration/SignedProjectTest.groovy @@ -0,0 +1,96 @@ +/* + * This file is part of fabric-loom, licensed under the MIT License (MIT). + * + * Copyright (c) 2016, 2017, 2018 FabricMC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package net.fabricmc.loom.test.integration + +import net.fabricmc.loom.test.util.ArchiveAssertionsTrait + +import net.fabricmc.loom.test.util.MockMavenServerTrait +import spock.lang.Specification +import spock.lang.Stepwise +import spock.lang.Unroll +import spock.util.environment.RestoreSystemProperties + +import static java.lang.System.setProperty +import static org.gradle.testkit.runner.TaskOutcome.SUCCESS + +/** + * This tests publishing signed artifacts to a maven server + */ +@Stepwise +class SignedProjectTest extends Specification implements MockMavenServerTrait, ArchiveAssertionsTrait { + @Unroll + @RestoreSystemProperties + def "sign and publish lib #gradle"() { + given: + setProperty('loom.test.secretKey', PRIVATE_KEY) + when: + def result = create("publish", gradle) + then: + result.task(":publish").outcome == SUCCESS + where: + gradle | _ + DEFAULT_GRADLE | _ + PRE_RELEASE_GRADLE | _ + } + + @Override + String name() { + "signed" + } + + static final String PRIVATE_KEY = """ +-----BEGIN PGP PRIVATE KEY BLOCK----- + +lQPGBGCm5LMBCADUeHXbe4TmP3qELtz6he7CLaVMFXqL/fU+M7GIrj0qtLU6pJ9v +KSbF3tQATKlU91zkQCIPg41VBlqkx85bOm0u7Nvv4JhWMqE+ZsNoNVXS2xQEyEIW +rX9Cd0/YibU2FpWOlo1l/UZPPD/lYUrkZEhgoKHMHP3SYb5Ohgpy4klTeQdXTRMF +q0IeyFynw3eqrdWmktOEApd7qeu/Hs1NEnZssSZQdAYB4R+tL/ePgIYXsViWvqbT +XDYfmd+AiRnACGtrt5P8tSmKhLPzth36cvqLXI+hSBGHu0PRfvQnfjn3CWq8AaIj +dLsmRYw8NedYZ5DgY3NIRMBkG561Uc1Kj5c7ABEBAAH+BwMCfh5aZV7x7zP/HCCP +WwbuNO9fLKss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RAr799Fr58zf9YGBcH5 +7F3TQpzK2zd6iktFy9cjIu04pYtvdrEP+29hLmy1ibUBI3yx8HH1BxHm8Eu2ZTAn +b5EYkmF73CecdtSu3yL0tmk/4GLO6t2r/SN7imFnq9xKyTqJmtftQngBhgoA6KPk +4ZEkOA1MbVpaSjGy5H1U/XusH1UDA3SZWlOwrY3xO8TfycsR9BijtCqxTnuwNXzT +wWoDPJEzJM/KCs0aXRbwwWALcxqk6sevLwx4D4/k3xxEB8cf5cBJC8bJjnBz5FSi +WBVyzTF8wLkcSacL93kE6swpP+iNkIwkO4eoyTA2RmTJUcz/M0zWS7NEM8S0 +=xl+8 +-----END PGP PRIVATE KEY BLOCK-----""" +} \ No newline at end of file diff --git a/src/test/groovy/net/fabricmc/loom/test/util/ProjectTestTrait.groovy b/src/test/groovy/net/fabricmc/loom/test/util/ProjectTestTrait.groovy index 56ed8c9..fdb70c9 100644 --- a/src/test/groovy/net/fabricmc/loom/test/util/ProjectTestTrait.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/util/ProjectTestTrait.groovy @@ -29,7 +29,7 @@ import org.gradle.testkit.runner.GradleRunner trait ProjectTestTrait { final static String DEFAULT_GRADLE = "7.0.1" - final static String PRE_RELEASE_GRADLE = "7.1-20210511220046+0000" + final static String PRE_RELEASE_GRADLE = "7.1-20210520220048+0000" static File gradleHome = File.createTempDir() File testProjectDir = File.createTempDir() diff --git a/src/test/resources/projects/signed/build.gradle b/src/test/resources/projects/signed/build.gradle new file mode 100644 index 0000000..5da4823 --- /dev/null +++ b/src/test/resources/projects/signed/build.gradle @@ -0,0 +1,57 @@ +plugins { + id 'fabric-loom' + id 'maven-publish' + id 'signing' +} + +archivesBaseName = "fabric-example-lib" +version = "1.0.0" +group = "com.example" + +dependencies { + minecraft "com.mojang:minecraft:1.16.5" + mappings "net.fabricmc:yarn:1.16.5+build.5:v2" + modImplementation "net.fabricmc:fabric-loader:0.11.2" +} + +processResources { + inputs.property "version", project.version + + filesMatching("fabric.mod.json") { + expand "version": project.version + } +} + +java { + withSourcesJar() +} + +publishing { + publications { + mavenJava(MavenPublication) { + artifact(remapJar) { + builtBy remapJar + } + artifact(remapJar) { + builtBy remapJar + classifier "classifier" + } + artifact(sourcesJar) { + builtBy remapSourcesJar + } + } + } + + repositories { + maven { + url "http://localhost:${System.getProperty("loom.test.mavenPort")}/" + allowInsecureProtocol = true + } + } +} + +signing { + def privateKey = System.getProperty("loom.test.secretKey") ?: "no key!" + useInMemoryPgpKeys(privateKey, 'password') + sign publishing.publications.mavenJava +} diff --git a/src/test/resources/projects/signed/main/java/net/fabricmc/example/ExampleLib.java b/src/test/resources/projects/signed/main/java/net/fabricmc/example/ExampleLib.java new file mode 100644 index 0000000..e6ec1e6 --- /dev/null +++ b/src/test/resources/projects/signed/main/java/net/fabricmc/example/ExampleLib.java @@ -0,0 +1,13 @@ +package net.fabricmc.example; + +import net.fabricmc.api.ModInitializer; + +public class ExampleLib implements ModInitializer { + @Override + public void onInitialize() { + } + + public static void hello() { + System.out.println("Hello Fabric world!"); + } +} diff --git a/src/test/resources/projects/signed/main/resources/fabric.mod.json b/src/test/resources/projects/signed/main/resources/fabric.mod.json new file mode 100644 index 0000000..f527100 --- /dev/null +++ b/src/test/resources/projects/signed/main/resources/fabric.mod.json @@ -0,0 +1,4 @@ +{ + "schemaVersion": 1, + "id": "modid" +} diff --git a/src/test/resources/projects/signed/settings.gradle b/src/test/resources/projects/signed/settings.gradle new file mode 100644 index 0000000..fc4c0f7 --- /dev/null +++ b/src/test/resources/projects/signed/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = "fabric-example-lib" +