1
1
package org .elasticsearch .gradle .info ;
2
2
3
+ import org .apache .commons .io .IOUtils ;
4
+ import org .elasticsearch .gradle .BwcVersions ;
3
5
import org .elasticsearch .gradle .OS ;
4
6
import org .elasticsearch .gradle .util .Util ;
5
7
import org .gradle .api .GradleException ;
20
22
import java .io .BufferedReader ;
21
23
import java .io .ByteArrayOutputStream ;
22
24
import java .io .File ;
25
+ import java .io .FileInputStream ;
23
26
import java .io .FileReader ;
24
27
import java .io .IOException ;
25
28
import java .io .UncheckedIOException ;
44
47
45
48
public class GlobalBuildInfoPlugin implements Plugin <Project > {
46
49
private static final Logger LOGGER = Logging .getLogger (GlobalBuildInfoPlugin .class );
50
+ private static final String DEFAULT_VERSION_JAVA_FILE_PATH = "server/src/main/java/org/elasticsearch/Version.java" ;
47
51
private static Integer _defaultParallel = null ;
48
52
49
53
private final JavaInstallationRegistry javaInstallationRegistry ;
@@ -69,10 +73,13 @@ public void apply(Project project) {
69
73
File compilerJavaHome = findCompilerJavaHome ();
70
74
File runtimeJavaHome = findRuntimeJavaHome (compilerJavaHome );
71
75
72
- GitInfo gitInfo = gitInfo (project .getRootProject ().getRootDir ());
76
+ File rootDir = project .getRootDir ();
77
+ GitInfo gitInfo = gitInfo (rootDir );
73
78
74
- // Initialize global build parameters
75
79
BuildParams .init (params -> {
80
+ // Initialize global build parameters
81
+ boolean isInternal = GlobalBuildInfoPlugin .class .getResource ("/buildSrc.marker" ) != null ;
82
+
76
83
params .reset ();
77
84
params .setCompilerJavaHome (compilerJavaHome );
78
85
params .setRuntimeJavaHome (runtimeJavaHome );
@@ -88,16 +95,32 @@ public void apply(Project project) {
88
95
params .setBuildDate (ZonedDateTime .now (ZoneOffset .UTC ));
89
96
params .setTestSeed (getTestSeed ());
90
97
params .setIsCi (System .getenv ("JENKINS_URL" ) != null );
91
- params .setIsInternal (GlobalBuildInfoPlugin . class . getResource ( "/buildSrc.marker" ) != null );
98
+ params .setIsInternal (isInternal );
92
99
params .setDefaultParallel (findDefaultParallel (project ));
93
100
params .setInFipsJvm (Util .getBooleanProperty ("tests.fips.enabled" , false ));
94
101
params .setIsSnapshotBuild (Util .getBooleanProperty ("build.snapshot" , true ));
102
+ if (isInternal ) {
103
+ params .setBwcVersions (resolveBwcVersions (rootDir ));
104
+ }
95
105
});
96
106
97
107
// Print global build info header just before task execution
98
108
project .getGradle ().getTaskGraph ().whenReady (graph -> logGlobalBuildInfo ());
99
109
}
100
110
111
+ /* Introspect all versions of ES that may be tested against for backwards
112
+ * compatibility. It is *super* important that this logic is the same as the
113
+ * logic in VersionUtils.java. */
114
+ private static BwcVersions resolveBwcVersions (File root ) {
115
+ File versionsFile = new File (root , DEFAULT_VERSION_JAVA_FILE_PATH );
116
+ try {
117
+ List <String > versionLines = IOUtils .readLines (new FileInputStream (versionsFile ), "UTF-8" );
118
+ return new BwcVersions (versionLines );
119
+ } catch (IOException e ) {
120
+ throw new IllegalStateException ("Unable to resolve to resolve bwc versions from versionsFile." , e );
121
+ }
122
+ }
123
+
101
124
private void logGlobalBuildInfo () {
102
125
final String osName = System .getProperty ("os.name" );
103
126
final String osVersion = System .getProperty ("os.version" );
0 commit comments