|
| 1 | +/* |
| 2 | + * Copyright 2019 Vladimir Sitnikov <[email protected]> |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + */ |
| 17 | +package release |
| 18 | + |
| 19 | +import com.github.vlsi.gradle.BaseGradleTest |
| 20 | +import org.eclipse.jgit.api.Git |
| 21 | +import org.gradle.testkit.runner.TaskOutcome |
| 22 | +import org.junit.jupiter.api.Assertions.assertEquals |
| 23 | +import org.junit.jupiter.api.Assertions.assertFalse |
| 24 | +import org.junit.jupiter.api.Assertions.assertTrue |
| 25 | +import org.junit.jupiter.api.fail |
| 26 | +import org.junit.jupiter.params.ParameterizedTest |
| 27 | +import org.junit.jupiter.params.provider.Arguments |
| 28 | +import org.junit.jupiter.params.provider.MethodSource |
| 29 | + |
| 30 | +class ChecksumFileTest : BaseGradleTest() { |
| 31 | + companion object { |
| 32 | + val isCI = System.getenv().containsKey("CI") || System.getProperties().containsKey("CI") |
| 33 | + |
| 34 | + @JvmStatic |
| 35 | + private fun gradleVersionAndSettings(): Iterable<Arguments> { |
| 36 | + if (!isCI) { |
| 37 | + // Use only the minimum supported Gradle version to make the test faster |
| 38 | + return listOf(Arguments.arguments("8.1.1", ConfigurationCache.OFF)) |
| 39 | + } |
| 40 | + return mutableListOf<Arguments>().apply { |
| 41 | + add(Arguments.arguments("6.0", ConfigurationCache.OFF)) |
| 42 | + add(Arguments.arguments("6.5", ConfigurationCache.OFF)) |
| 43 | + add(Arguments.arguments("7.0", ConfigurationCache.OFF)) |
| 44 | + add(Arguments.arguments("7.4.2", ConfigurationCache.OFF)) |
| 45 | + add(Arguments.arguments("8.1.1", ConfigurationCache.OFF)) |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + @ParameterizedTest |
| 51 | + @MethodSource("gradleVersionAndSettings") |
| 52 | + fun previewSvnDist(gradleVersion: String, configurationCache: ConfigurationCache) { |
| 53 | + enableConfigurationCache(gradleVersion, configurationCache) |
| 54 | + projectDir.resolve("src/main/java/acme").toFile().mkdirs() |
| 55 | + projectDir.resolve("src/main/java/acme/Main.java").write( |
| 56 | + /* language=Java */ |
| 57 | + """ |
| 58 | + public class Main { |
| 59 | + public int sum(int a, int b) { |
| 60 | + return a + b; |
| 61 | + } |
| 62 | + } |
| 63 | + """.trimIndent() |
| 64 | + ) |
| 65 | + Git.init().apply { |
| 66 | + setGitDir(projectDir.toFile()) |
| 67 | + call() |
| 68 | + } |
| 69 | + projectDir.resolve("settings.gradle").write( |
| 70 | + /* language=gradle */ |
| 71 | + """ |
| 72 | + rootProject.name = 'checksums' |
| 73 | + """.trimIndent() |
| 74 | + ) |
| 75 | + projectDir.resolve("build.gradle").write( |
| 76 | + /* language=gradle */ |
| 77 | + """ |
| 78 | + plugins { |
| 79 | + id 'java-library' |
| 80 | + id 'maven-publish' |
| 81 | + id 'com.github.vlsi.stage-vote-release' |
| 82 | + } |
| 83 | +
|
| 84 | + releaseParams { |
| 85 | + tlp = "tulip" |
| 86 | + } |
| 87 | +
|
| 88 | + releaseArtifacts { |
| 89 | + // Release artifacts from the root project |
| 90 | + fromProject(":") |
| 91 | +
|
| 92 | + // Add jar as a release artifact, so create checksum for it, and so on |
| 93 | + releaseArtifacts { |
| 94 | + artifact(tasks.named('jar')) |
| 95 | + } |
| 96 | + } |
| 97 | +
|
| 98 | + tasks.withType(Sign).configureEach { |
| 99 | + enabled = false |
| 100 | + } |
| 101 | + """.trimIndent() |
| 102 | + ) |
| 103 | + prepare(gradleVersion, "previewSvnDist", "-i", "-Prc=1").build().let { result -> |
| 104 | + if (isCI) { |
| 105 | + println(result.output) |
| 106 | + } |
| 107 | + |
| 108 | + assertChecksumFilePresent("First execution") |
| 109 | + } |
| 110 | + |
| 111 | + prepare(gradleVersion, "previewSvnDist", "-i", "-Prc=1").build().let { result -> |
| 112 | + if (isCI) { |
| 113 | + println(result.output) |
| 114 | + } |
| 115 | + assertEquals(TaskOutcome.UP_TO_DATE, result.task(":jarSha512")?.outcome) { |
| 116 | + "jar is UP-TO-DATE, so jarSha512 should be UP-TO-DATE as well" |
| 117 | + } |
| 118 | + |
| 119 | + assertChecksumFilePresent("Checksum file should be present in up-to-date execution") |
| 120 | + } |
| 121 | + |
| 122 | + prepare( |
| 123 | + gradleVersion, |
| 124 | + "cleanJarSha512", |
| 125 | + "previewSvnDist", |
| 126 | + "-x", |
| 127 | + "jar", |
| 128 | + "-i", |
| 129 | + "-Prc=1" |
| 130 | + ).build().let { result -> |
| 131 | + if (isCI) { |
| 132 | + println(result.output) |
| 133 | + } |
| 134 | + assertEquals(TaskOutcome.SKIPPED, result.task(":jarSha512")?.outcome) { |
| 135 | + "jar is SKIPPED, so jarSha512 should be SKIPPED as well" |
| 136 | + } |
| 137 | + |
| 138 | + assertChecksumFileAbsent("jar task is skipped, so checksum file should not be generated") |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + private fun assertChecksumFilePresent(message: String) { |
| 143 | + val sha512File = projectDir.resolve("build/previewSvnDist/checksums.jar.sha512").toFile() |
| 144 | + assertTrue(sha512File.isFile) { "$message: file $sha512File should exist" } |
| 145 | + if (sha512File.length() < 140) { |
| 146 | + fail("$message: file $sha512File should have length 140 or more, got ${sha512File.length()}") |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + private fun assertChecksumFileAbsent(message: String) { |
| 151 | + val sha512File = projectDir.resolve("build/previewSvnDist/checksums.jar.sha512").toFile() |
| 152 | + assertFalse(sha512File.isFile) { "$message: file $sha512File should not exist" } |
| 153 | + } |
| 154 | +} |
0 commit comments