diff --git a/build.gradle b/build.gradle index e2c1ff9f92a..948bbcd0803 100644 --- a/build.gradle +++ b/build.gradle @@ -77,7 +77,8 @@ for (String line : versionLines) { int major = Integer.parseInt(match.group(1)) int minor = Integer.parseInt(match.group(2)) int bugfix = Integer.parseInt(match.group(3)) - Version foundVersion = new Version(major, minor, bugfix, false) + boolean unreleased = match.group(4) != null + Version foundVersion = new Version(major, minor, bugfix, false, unreleased) if (currentVersion != foundVersion) { versions.add(foundVersion) } @@ -88,7 +89,7 @@ for (String line : versionLines) { } } if (versions.toSorted { it.id } != versions) { - println "Versions: ${versions}" + println "Versions: ${versions}" throw new GradleException("Versions.java contains out of order version constants") } if (currentVersion.bugfix == 0) { @@ -97,7 +98,8 @@ if (currentVersion.bugfix == 0) { // unreleased version of closest branch. So for those cases, the version includes -SNAPSHOT, // and the bwc-zip distribution will checkout and build that version. Version last = versions[-1] - versions[-1] = new Version(last.major, last.minor, last.bugfix, true) + versions[-1] = new Version(last.major, last.minor, last.bugfix, + true, last.unreleased) } // injecting groovy property variables into all projects diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/Version.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/Version.groovy index 44e488acd42..03fe4c34281 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/Version.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/Version.groovy @@ -29,13 +29,20 @@ public class Version { final int bugfix final int id final boolean snapshot + /** + * Is the vesion listed as {@code _UNRELEASED} in Version.java. + */ + final boolean unreleased - public Version(int major, int minor, int bugfix, boolean snapshot) { + public Version(int major, int minor, int bugfix, boolean snapshot, + boolean unreleased) { this.major = major this.minor = minor this.bugfix = bugfix this.snapshot = snapshot - this.id = major * 100000 + minor * 1000 + bugfix * 10 + (snapshot ? 1 : 0) + this.id = major * 100000 + minor * 1000 + bugfix * 10 + + (snapshot ? 1 : 0) + this.unreleased = unreleased } public static Version fromString(String s) { @@ -46,7 +53,8 @@ public class Version { snapshot = bugfix.endsWith('-SNAPSHOT') bugfix = bugfix.split('-')[0] } - return new Version(parts[0] as int, parts[1] as int, bugfix as int, snapshot) + return new Version(parts[0] as int, parts[1] as int, bugfix as int, + snapshot, false) } @Override diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantTestPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantTestPlugin.groovy index 9df6d36ef01..399b816280b 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantTestPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantTestPlugin.groovy @@ -82,29 +82,6 @@ class VagrantTestPlugin implements Plugin { } } - private static Set listVersions(Project project) { - Node xml - new URL('https://repo1.maven.org/maven2/org/elasticsearch/elasticsearch/maven-metadata.xml').openStream().withStream { s -> - xml = new XmlParser().parse(s) - } - Set versions = new TreeSet<>(xml.versioning.versions.version.collect { it.text() }.findAll { it ==~ /[5]\.\d\.\d/ }) - if (versions.isEmpty() == false) { - return versions; - } - - // If no version is found, we run the tests with the current version - return Collections.singleton(project.version); - } - - private static File getVersionsFile(Project project) { - File versions = new File(project.projectDir, 'versions'); - if (versions.exists() == false) { - // Use the elasticsearch's versions file from project :qa:vagrant - versions = project.project(":qa:vagrant").file('versions') - } - return versions - } - private static void configureBatsRepositories(Project project) { RepositoryHandler repos = project.repositories @@ -140,8 +117,7 @@ class VagrantTestPlugin implements Plugin { String upgradeFromVersion = System.getProperty("tests.packaging.upgradeVersion"); if (upgradeFromVersion == null) { - List availableVersions = getVersionsFile(project).readLines('UTF-8') - upgradeFromVersion = availableVersions[new Random(seed).nextInt(availableVersions.size())] + upgradeFromVersion = project.indexCompatVersions[new Random(seed).nextInt(project.indexCompatVersions.size())] } DISTRIBUTION_ARCHIVES.each { @@ -186,7 +162,6 @@ class VagrantTestPlugin implements Plugin { Task createBatsDirsTask = project.tasks.create('createBatsDirs') createBatsDirsTask.outputs.dir batsDir - createBatsDirsTask.dependsOn project.tasks.vagrantVerifyVersions createBatsDirsTask.doLast { batsDir.mkdirs() } @@ -252,32 +227,6 @@ class VagrantTestPlugin implements Plugin { vagrantSetUpTask.dependsOn copyBatsTests, copyBatsUtils, copyBatsArchives, createVersionFile, createUpgradeFromFile } - private static void createUpdateVersionsTask(Project project) { - project.tasks.create('vagrantUpdateVersions') { - description 'Update file containing options for the\n "starting" version in the "upgrade from" packaging tests.' - group 'Verification' - doLast { - File versions = getVersionsFile(project) - versions.setText(listVersions(project).join('\n') + '\n', 'UTF-8') - } - } - } - - private static void createVerifyVersionsTask(Project project) { - project.tasks.create('vagrantVerifyVersions') { - description 'Update file containing options for the\n "starting" version in the "upgrade from" packaging tests.' - group 'Verification' - doLast { - Set versions = listVersions(project) - Set actualVersions = new TreeSet<>(getVersionsFile(project).readLines('UTF-8')) - if (!versions.equals(actualVersions)) { - throw new GradleException("out-of-date versions " + actualVersions + - ", expected " + versions + "; run gradle vagrantUpdateVersions") - } - } - } - } - private static void createCheckVagrantVersionTask(Project project) { project.tasks.create('vagrantCheckVersion', Exec) { description 'Check the Vagrant version' @@ -342,8 +291,6 @@ class VagrantTestPlugin implements Plugin { createCleanTask(project) createStopTask(project) createSmokeTestTask(project) - createUpdateVersionsTask(project) - createVerifyVersionsTask(project) createCheckVagrantVersionTask(project) createCheckVirtualBoxVersionTask(project) createPrepareVagrantTestEnvTask(project) diff --git a/core/build.gradle b/core/build.gradle index 72aaca6da1c..516aeb1d0eb 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -124,8 +124,8 @@ forbiddenPatterns { task generateModulesList { List modules = project(':modules').subprojects.collect { it.name } File modulesFile = new File(buildDir, 'generated-resources/modules.txt') - processResources.from(modulesFile) - inputs.property('modules', modules) + processResources.from(modulesFile) + inputs.property('modules', modules) outputs.file(modulesFile) doLast { modulesFile.parentFile.mkdirs() @@ -138,8 +138,8 @@ task generatePluginsList { .findAll { it.name.contains('example') == false } .collect { it.name } File pluginsFile = new File(buildDir, 'generated-resources/plugins.txt') - processResources.from(pluginsFile) - inputs.property('plugins', plugins) + processResources.from(pluginsFile) + inputs.property('plugins', plugins) outputs.file(pluginsFile) doLast { pluginsFile.parentFile.mkdirs() @@ -256,7 +256,7 @@ thirdPartyAudit.excludes = [ 'org.zeromq.ZMQ', // from org.locationtech.spatial4j.io.GeoJSONReader (spatial4j) - 'org.noggit.JSONParser', + 'org.noggit.JSONParser', ] dependencyLicenses { @@ -277,3 +277,43 @@ if (isEclipse == false || project.path == ":core-tests") { check.dependsOn integTest integTest.mustRunAfter test } + +task('verifyVersions') { + description 'Verifies that all released versions that are indexed compatible are listed in Version.java.' + group 'Verification' + enabled = false == gradle.startParameter.isOffline() + doLast { + // Read the list from maven central + Node xml + new URL('https://repo1.maven.org/maven2/org/elasticsearch/elasticsearch/maven-metadata.xml').openStream().withStream { s -> + xml = new XmlParser().parse(s) + } + Set knownVersions = new TreeSet<>(xml.versioning.versions.version.collect { it.text() }.findAll { it ==~ /\d\.\d\.\d/ }) + + // Limit the known versions to those that should be wire compatible + String currentVersion = versions.elasticsearch.minus('-SNAPSHOT') + int prevMajor = Integer.parseInt(currentVersion.split('\\.')[0]) - 1 + if (prevMajor == 4) { + // 4 didn't exist, it was 2. + prevMajor = 2; + } + knownVersions = knownVersions.findAll { Integer.parseInt(it.split('\\.')[0]) >= prevMajor } + + /* Limit the listed versions to those that have been marked as released. + * Versions not marked as released don't get the same testing and we want + * to make sure that we flip all unreleased versions to released as soon + * as possible after release. */ + Set actualVersions = new TreeSet<>( + indexCompatVersions + .findAll { false == it.unreleased } + .collect { it.toString() }) + + // Finally, compare! + if (!knownVersions.equals(actualVersions)) { + throw new GradleException("out-of-date versions\nActual :" + + actualVersions + "\nExpected:" + knownVersions + + "; update Version.java") + } + } +} +check.dependsOn(verifyVersions) diff --git a/qa/vagrant/versions b/qa/vagrant/versions deleted file mode 100644 index e65c667a240..00000000000 --- a/qa/vagrant/versions +++ /dev/null @@ -1,12 +0,0 @@ -5.0.0 -5.0.1 -5.0.2 -5.1.1 -5.1.2 -5.2.0 -5.2.1 -5.2.2 -5.3.0 -5.3.1 -5.3.2 -5.4.0