Skip to content

Commit 6c9ca44

Browse files
authored
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 0a31b67 commit 6c9ca44

File tree

7 files changed

+47
-10
lines changed

7 files changed

+47
-10
lines changed

buildSrc/build.gradle

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,17 @@ class VersionPropertiesLoader {
273273
}
274274
elasticsearch += "-" + qualifier
275275
}
276-
if ("true".equals(systemProperties.getProperty("build.snapshot", "true"))) {
277-
elasticsearch += "-SNAPSHOT"
276+
final String buildSnapshotSystemProperty = systemProperties.getProperty("build.snapshot", "true");
277+
switch (buildSnapshotSystemProperty) {
278+
case "true":
279+
elasticsearch += "-SNAPSHOT"
280+
break;
281+
case "false":
282+
// do nothing
283+
break;
284+
default:
285+
throw new IllegalArgumentException(
286+
"build.snapshot was set to [" + buildSnapshotSystemProperty + "] but can only be unset or [true|false]");
278287
}
279288
loadedProps.put("elasticsearch", elasticsearch)
280289
}

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

Lines changed: 15 additions & 0 deletions
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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.elasticsearch.gradle.info.BuildParams
2+
13
apply plugin: 'elasticsearch.testclusters'
24
apply plugin: 'elasticsearch.standalone-rest-test'
35
apply plugin: 'elasticsearch.rest-test'
@@ -65,8 +67,7 @@ integTest.runner {
6567

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

x-pack/plugin/core/build.gradle

Lines changed: 2 additions & 2 deletions
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
@@ -68,11 +69,10 @@ processResources {
6869
inputs.properties(expansions)
6970
MavenFilteringHack.filter(it, expansions)
7071
}
71-
boolean snapshot = "true".equals(System.getProperty("build.snapshot", "true"))
7272
String licenseKey = System.getProperty("license.key")
7373
if (licenseKey != null) {
7474
println "Using provided license key from ${licenseKey}"
75-
} else if (snapshot) {
75+
} else if (BuildParams.isSnapshotBuild()) {
7676
licenseKey = Paths.get(project.projectDir.path, 'snapshot.key')
7777
} else {
7878
throw new IllegalArgumentException('Property license.key must be set for release build')

0 commit comments

Comments
 (0)