Skip to content

Commit 92b611e

Browse files
committed
Formalize build snapshot (#51484)
Today we are repeatedly checking if the current build is a snapshot build or not by reading the system property build.snapshot. This commit formalizes this by adding a build parameter to indicate whether or not the current build is a snapshot build.
1 parent 65f49d0 commit 92b611e

File tree

7 files changed

+45
-10
lines changed

7 files changed

+45
-10
lines changed

buildSrc/build.gradle

+11-2
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,17 @@ class VersionPropertiesLoader {
276276
}
277277
elasticsearch += "-" + qualifier
278278
}
279-
if ("true".equals(systemProperties.getProperty("build.snapshot", "true"))) {
280-
elasticsearch += "-SNAPSHOT"
279+
final String buildSnapshotSystemProperty = systemProperties.getProperty("build.snapshot", "true");
280+
switch (buildSnapshotSystemProperty) {
281+
case "true":
282+
elasticsearch += "-SNAPSHOT"
283+
break;
284+
case "false":
285+
// do nothing
286+
break;
287+
default:
288+
throw new IllegalArgumentException(
289+
"build.snapshot was set to [" + buildSnapshotSystemProperty + "] but can only be unset or [true|false]");
281290
}
282291
loadedProps.put("elasticsearch", elasticsearch)
283292
}

buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java

+15
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ public void apply(Project project) {
5959
testSeed = testSeedProperty;
6060
}
6161

62+
final String buildSnapshotSystemProperty = System.getProperty("build.snapshot", "true");
63+
final boolean isSnapshotBuild;
64+
switch (buildSnapshotSystemProperty) {
65+
case "true":
66+
isSnapshotBuild = true;
67+
break;
68+
case "false":
69+
isSnapshotBuild = false;
70+
break;
71+
default:
72+
throw new IllegalArgumentException(
73+
"build.snapshot was set to [" + buildSnapshotSystemProperty + "] but can only be unset or [true|false]"
74+
);
75+
}
6276
final List<JavaHome> javaVersions = new ArrayList<>();
6377
for (int version = 8; version <= Integer.parseInt(minimumCompilerVersion.getMajorVersion()); version++) {
6478
if (System.getenv(getJavaHomeEnvVarName(Integer.toString(version))) != null) {
@@ -102,6 +116,7 @@ public void apply(Project project) {
102116
params.setIsInternal(GlobalBuildInfoPlugin.class.getResource("/buildSrc.marker") != null);
103117
params.setDefaultParallel(findDefaultParallel(project));
104118
params.setInFipsJvm(isInFipsJvm());
119+
params.setIsSnapshotBuild(isSnapshotBuild);
105120
});
106121

107122
project.allprojects(

buildSrc/src/minimumRuntime/java/org/elasticsearch/gradle/info/BuildParams.java

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class BuildParams {
3333
private static Boolean isCi;
3434
private static Boolean isInternal;
3535
private static Integer defaultParallel;
36+
private static Boolean isSnapshotBuild;
3637

3738
/**
3839
* Initialize global build parameters. This method accepts and a initialization function which in turn accepts a
@@ -112,6 +113,10 @@ public static Integer getDefaultParallel() {
112113
return value(defaultParallel);
113114
}
114115

116+
public static boolean isSnapshotBuild() {
117+
return value(BuildParams.isSnapshotBuild);
118+
}
119+
115120
private static <T> T value(T object) {
116121
if (object == null) {
117122
String callingMethod = Thread.currentThread().getStackTrace()[2].getMethodName();
@@ -225,6 +230,11 @@ public void setIsInternal(Boolean isInternal) {
225230
public void setDefaultParallel(int defaultParallel) {
226231
BuildParams.defaultParallel = defaultParallel;
227232
}
233+
234+
public void setIsSnapshotBuild(final boolean isSnapshotBuild) {
235+
BuildParams.isSnapshotBuild = isSnapshotBuild;
236+
}
237+
228238
}
229239

230240
/**

distribution/packages/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
* KIND, either express or implied. See the License for the
1616
*/
1717

18-
1918
import org.elasticsearch.gradle.LoggedExec
2019
import org.elasticsearch.gradle.MavenFilteringHack
21-
import org.redline_rpm.header.Flags
2220
import org.elasticsearch.gradle.OS
21+
import org.elasticsearch.gradle.info.BuildParams
22+
import org.redline_rpm.header.Flags
2323

2424
import java.nio.file.Files
2525
import java.nio.file.Path
@@ -281,7 +281,7 @@ ospackage {
281281
url 'https://www.elastic.co/'
282282

283283
// signing setup
284-
if (project.hasProperty('signing.password') && System.getProperty('build.snapshot', 'true') == 'false') {
284+
if (project.hasProperty('signing.password') && BuildParams.isSnapshotBuild() == false) {
285285
signingKeyId = project.hasProperty('signing.keyId') ? project.property('signing.keyId') : 'D88E42B4'
286286
signingKeyPassphrase = project.property('signing.password')
287287
signingKeyRingFile = project.hasProperty('signing.secretKeyRingFile') ?

docs/build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.elasticsearch.gradle.info.BuildParams
2+
13
import static org.elasticsearch.gradle.testclusters.TestDistribution.DEFAULT
24

35
/*
@@ -42,7 +44,7 @@ buildRestTests.expectedUnconvertedCandidates = [
4244
testClusters.integTest {
4345
if (singleNode().testDistribution == DEFAULT) {
4446
setting 'xpack.license.self_generated.type', 'trial'
45-
if ("false".equals(System.getProperty("build.snapshot")) == false) {
47+
if (BuildParams.isSnapshotBuild()) {
4648
setting 'xpack.autoscaling.enabled', 'true'
4749
}
4850
}

x-pack/plugin/build.gradle

+1-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ integTest.runner {
120120

121121
// TODO: fix this rest test to not depend on a hardcoded port!
122122
def blacklist = ['getting_started/10_monitor_cluster_health/*']
123-
boolean snapshot = Boolean.valueOf(System.getProperty("build.snapshot", "true"))
124-
if (!snapshot) {
123+
if (BuildParams.isSnapshotBuild() == false) {
125124
// these tests attempt to install basic/internal licenses signed against the dev/public.key
126125
// Since there is no infrastructure in place (anytime soon) to generate licenses using the production
127126
// private key, these tests are blacklisted in non-snapshot test runs

x-pack/plugin/core/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import org.elasticsearch.gradle.MavenFilteringHack
2+
import org.elasticsearch.gradle.info.BuildParams
23

34
import java.nio.file.Files
45
import java.nio.file.Paths
@@ -67,11 +68,10 @@ processResources {
6768
inputs.properties(expansions)
6869
MavenFilteringHack.filter(it, expansions)
6970
}
70-
boolean snapshot = "true".equals(System.getProperty("build.snapshot", "true"))
7171
String licenseKey = System.getProperty("license.key")
7272
if (licenseKey != null) {
7373
println "Using provided license key from ${licenseKey}"
74-
} else if (snapshot) {
74+
} else if (BuildParams.isSnapshotBuild()) {
7575
licenseKey = Paths.get(project.projectDir.path, 'snapshot.key')
7676
} else {
7777
throw new IllegalArgumentException('Property license.key must be set for release build')

0 commit comments

Comments
 (0)