|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the "Elastic License |
| 4 | + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side |
| 5 | + * Public License v 1"; you may not use this file except in compliance with, at |
| 6 | + * your election, the "Elastic License 2.0", the "GNU Affero General Public |
| 7 | + * License v3.0 only", or the "Server Side Public License, v 1". |
| 8 | + */ |
| 9 | + |
| 10 | +package org.elasticsearch.gradle.internal.info |
| 11 | + |
| 12 | +import groovy.json.JsonOutput |
| 13 | +import spock.lang.Specification |
| 14 | +import spock.lang.TempDir |
| 15 | + |
| 16 | +import org.elasticsearch.gradle.Version |
| 17 | +import org.elasticsearch.gradle.internal.BwcVersions |
| 18 | +import org.gradle.api.Project |
| 19 | +import org.gradle.api.provider.Provider |
| 20 | +import org.gradle.api.provider.ProviderFactory |
| 21 | +import org.gradle.testfixtures.ProjectBuilder |
| 22 | + |
| 23 | +import java.nio.file.Path |
| 24 | + |
| 25 | +class GlobalBuildInfoPluginSpec extends Specification { |
| 26 | + |
| 27 | + @TempDir |
| 28 | + File projectRoot |
| 29 | + |
| 30 | + Project project |
| 31 | + |
| 32 | + def setup() { |
| 33 | + project = ProjectBuilder.builder() |
| 34 | + .withProjectDir(projectRoot) |
| 35 | + .withName("bwcTestProject") |
| 36 | + .build() |
| 37 | + project = Spy(project) |
| 38 | + project.getRootProject() >> project |
| 39 | + |
| 40 | + File versionFileDir = new File(projectRoot, "server/src/main/java/org/elasticsearch") |
| 41 | + versionFileDir.mkdirs() |
| 42 | + new File(versionFileDir, "Version.java").text = """ |
| 43 | + package org.elasticsearch; |
| 44 | + public class Version { |
| 45 | + public static final Version V_8_17_8 = new Version(8_17_08_99); |
| 46 | + public static final Version V_8_18_0 = new Version(8_18_00_99); |
| 47 | + public static final Version V_8_18_1 = new Version(8_18_01_99); |
| 48 | + public static final Version V_8_18_2 = new Version(8_18_02_99); |
| 49 | + public static final Version V_8_18_3 = new Version(8_18_03_99); |
| 50 | + public static final Version V_8_19_0 = new Version(8_19_00_99); |
| 51 | + public static final Version V_9_0_0 = new Version(9_00_00_99); |
| 52 | + public static final Version V_9_0_1 = new Version(9_00_01_99); |
| 53 | + public static final Version V_9_0_2 = new Version(9_00_02_99); |
| 54 | + public static final Version V_9_0_3 = new Version(9_00_03_99); |
| 55 | + public static final Version V_9_1_0 = new Version(9_01_00_99); |
| 56 | + public static final Version CURRENT = V_9_1_0; |
| 57 | +
|
| 58 | + } |
| 59 | + """ |
| 60 | + } |
| 61 | + |
| 62 | + def "resolve unreleased versions from branches file set by Gradle property"() { |
| 63 | + given: |
| 64 | + ProviderFactory providerFactorySpy = Spy(project.getProviders()) |
| 65 | + Path branchesJsonPath = projectRoot.toPath().resolve("myBranches.json") |
| 66 | + Provider<String> gradleBranchesLocationProvider = project.providers.provider { return branchesJsonPath.toString() } |
| 67 | + providerFactorySpy.gradleProperty("org.elasticsearch.build.branches-file-location") >> gradleBranchesLocationProvider |
| 68 | + project.getProviders() >> providerFactorySpy |
| 69 | + branchesJsonPath.text = branchesJson( |
| 70 | + [ |
| 71 | + new DevelopmentBranch("main", Version.fromString("9.1.0")), |
| 72 | + new DevelopmentBranch("9.0", Version.fromString("9.0.3")), |
| 73 | + new DevelopmentBranch("8.19", Version.fromString("8.19.1")), |
| 74 | + new DevelopmentBranch("8.18", Version.fromString("8.18.2")), |
| 75 | + ] |
| 76 | + ) |
| 77 | + |
| 78 | + when: |
| 79 | + project.objects.newInstance(GlobalBuildInfoPlugin).apply(project) |
| 80 | + BuildParameterExtension ext = project.extensions.getByType(BuildParameterExtension) |
| 81 | + BwcVersions bwcVersions = ext.bwcVersions |
| 82 | + |
| 83 | + then: |
| 84 | + bwcVersions != null |
| 85 | + bwcVersions.unreleased.toSet() == ["9.1.0", "9.0.3", "8.19.1", "8.18.2"].collect { Version.fromString(it) }.toSet() |
| 86 | + } |
| 87 | + |
| 88 | + String branchesJson(List<DevelopmentBranch> branches) { |
| 89 | + Map<String, Object> branchesFileContent = [ |
| 90 | + branches: branches.collect { branch -> |
| 91 | + [ |
| 92 | + branch: branch.name(), |
| 93 | + version: branch.version().toString(), |
| 94 | + ] |
| 95 | + } |
| 96 | + ] |
| 97 | + return JsonOutput.prettyPrint(JsonOutput.toJson(branchesFileContent)) |
| 98 | + } |
| 99 | +} |
0 commit comments