Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the build version qualifier aware #32128

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2bb8616
Switch build to dynamically configured qualifiers
alpar-t Jul 17, 2018
9dd442c
Remove alpha1 from version qualifier
alpar-t Jul 17, 2018
9380817
Merge remote-tracking branch 'origin/master' into version-qualifier-a…
alpar-t Jul 17, 2018
08096d2
PR changes, version ID
alpar-t Jul 18, 2018
018fafa
Merge remote-tracking branch 'origin/master' into version-qualifier-a…
alpar-t Jul 18, 2018
76b67b3
Correct references to 7.0.0-alpha1
alpar-t Jul 23, 2018
ee2359f
Don't pass qualifier to plugin metadata
alpar-t Jul 23, 2018
54176b6
Rename from suffix to qualifier for consistency
alpar-t Jul 23, 2018
67c06f3
Temp: hard code information about released major
alpar-t Jul 23, 2018
cbaa33a
Add comment, reproduction info
alpar-t Aug 6, 2018
6071cfd
Merge remote-tracking branch 'origin/master' into version-qualifier-a…
alpar-t Aug 6, 2018
218bbf4
fix references to 7.0.0 alpha1
alpar-t Aug 6, 2018
d5ceca9
fix merge errort
alpar-t Aug 6, 2018
6507480
fix doc tests
alpar-t Aug 7, 2018
73d7496
drop snapshot and qualifier from version passed to packaging tests
alpar-t Aug 7, 2018
4c68d70
Fix tests failing to match versions
alpar-t Aug 8, 2018
ad58c10
fix packaging tests
alpar-t Aug 8, 2018
63910ab
Merge remote-tracking branch 'origin/master' into version-qualifier-a…
alpar-t Aug 8, 2018
de4b304
Merge branch 'master' into version-qualifier-aware
alpar-t Aug 10, 2018
13d92a5
Don't rely on version conventions for wildfly test
alpar-t Aug 10, 2018
75489c7
Merge remote-tracking branch 'origin/master' into version-qualifier-a…
alpar-t Aug 14, 2018
64a833d
Remove qualifier from version in manifest
alpar-t Aug 14, 2018
e10f818
update version IDs
alpar-t Aug 14, 2018
1fe9ac4
PR review
alpar-t Aug 15, 2018
051539d
PR review: change method names
alpar-t Aug 21, 2018
c9be34e
Merge remote-tracking branch 'origin/master' into version-qualifier-a…
alpar-t Aug 22, 2018
4195a55
replace reference to alpha1 version
alpar-t Aug 22, 2018
377b632
Merge remote-tracking branch 'origin/master' into version-qualifier-a…
alpar-t Aug 29, 2018
dd5122e
Don't allow for dash in qualifier
alpar-t Aug 29, 2018
d5a3f2e
remove qualifeir from version enums as part of merge
alpar-t Aug 29, 2018
6a47804
Merge remote-tracking branch 'origin/master' into version-qualifier-a…
alpar-t Aug 29, 2018
53b1fce
Merge remote-tracking branch 'origin/master' into version-qualifier-a…
alpar-t Aug 29, 2018
85d010e
Correct test failure
alpar-t Aug 30, 2018
6f53bd3
Merge remote-tracking branch 'origin/master' into version-qualifier-a…
alpar-t Aug 30, 2018
4074bc3
Merge remote-tracking branch 'origin/master' into version-qualifier-a…
alpar-t Aug 30, 2018
e76a255
Merge remote-tracking branch 'origin/master' into version-qualifier-a…
alpar-t Sep 6, 2018
2e7b567
PR review: remove snapshot and qualifier from version
alpar-t Sep 6, 2018
dcf67a9
Make clusterformation deal with snapshot and qualifier not in build
alpar-t Sep 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ if (properties.get("org.elasticsearch.acceptScanTOS", "false") == "true") {
}
}

boolean isSnapshot = Boolean.parseBoolean(System.getProperty("build.snapshot", "true"))

// common maven publishing configuration
subprojects {
group = 'org.elasticsearch'
version = VersionProperties.elasticsearch.toString()
version = VersionProperties.elasticsearch
description = "Elasticsearch subproject ${project.path}"
}

apply plugin: 'nebula.info-scm'
String licenseCommit
if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) {
if (isSnapshot) {
licenseCommit = scminfo.change ?: "master" // leniency for non git builds
} else {
licenseCommit = "v${version}"
Expand Down Expand Up @@ -103,7 +105,7 @@ subprojects {
* in a branch if there are only betas and rcs in the branch so we have
* *something* to test against. */
VersionCollection versions = new VersionCollection(file('server/src/main/java/org/elasticsearch/Version.java').readLines('UTF-8'))
if (versions.currentVersion != VersionProperties.elasticsearch) {
if (versions.currentVersion.isSameVersionNumber(VersionProperties.elasticsearchVersion) == false) {
throw new GradleException("The last version in Versions.java [${versions.currentVersion}] does not match " +
"VersionProperties.elasticsearch [${VersionProperties.elasticsearch}]")
}
Expand Down Expand Up @@ -299,7 +301,7 @@ subprojects {
// other packages (e.g org.elasticsearch.client) will point to server rather than
// their own artifacts.
if (project.plugins.hasPlugin(BuildPlugin) || project.plugins.hasPlugin(PluginBuildPlugin)) {
String artifactsHost = VersionProperties.elasticsearch.isSnapshot() ? "https://snapshots.elastic.co" : "https://artifacts.elastic.co"
String artifactsHost = isSnapshot ? "https://snapshots.elastic.co" : "https://artifacts.elastic.co"
Closure sortClosure = { a, b -> b.group <=> a.group }
Closure depJavadocClosure = { shadowed, dep ->
if (dep.group == null || false == dep.group.startsWith('org.elasticsearch')) {
Expand Down
42 changes: 16 additions & 26 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
import java.nio.file.Files
import org.gradle.util.GradleVersion

plugins {
Expand Down Expand Up @@ -53,35 +52,26 @@ sourceCompatibility = minimumRuntimeVersion

Properties props = new Properties()
props.load(project.file('version.properties').newDataInputStream())
version = props.getProperty('elasticsearch')
boolean snapshot = "true".equals(System.getProperty("build.snapshot", "true"));
if (snapshot) {
// we update the version property to reflect if we are building a snapshot or a release build
// we write this back out below to load it in the Build.java which will be shown in rest main action
// to indicate this being a snapshot build or a release build.
version += "-SNAPSHOT"
props.put("elasticsearch", version);
}

File tempPropertiesFile = new File(project.buildDir, "version.properties")
task writeVersionProperties {
inputs.properties(props)
outputs.file(tempPropertiesFile)
processResources {
doLast {
OutputStream stream = Files.newOutputStream(tempPropertiesFile.toPath());
try {
props.store(stream, "UTF-8");
} finally {
stream.close();
}
// TODO change default to "" once we have a non qualified ML snapshot
String qualifier = System.getProperty("build.version_qualifier", "alpha1");
boolean isSnapshot = Boolean.parseBoolean(System.getProperty("build.snapshot", "true"));
props.put(
"elasticsearchBuild",
props.get("elasticsearch") +
(qualifier.isEmpty() ? "" : "-") + qualifier +
(isSnapshot ? "-SNAPSHOT" : "")
)
Writer versionFileWriter = file("$destinationDir/version.properties").newWriter()
try {
props.store(versionFileWriter, "Generated version properties")
} finally {
versionFileWriter.close()
}
}
}

processResources {
dependsOn writeVersionProperties
from tempPropertiesFile
}

/*****************************************************************************
* Dependencies used by the entire build *
*****************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,18 +694,15 @@ class BuildPlugin implements Plugin<Project> {
jarTask.destinationDir = new File(project.buildDir, 'distributions')
// fixup the jar manifest
jarTask.doFirst {
final Version versionWithoutSnapshot = new Version(
VersionProperties.elasticsearch.major,
VersionProperties.elasticsearch.minor,
VersionProperties.elasticsearch.revision,
VersionProperties.elasticsearch.suffix,
false)
// this doFirst is added before the info plugin, therefore it will run
// after the doFirst added by the info plugin, and we can override attributes
jarTask.manifest.attributes(
'X-Compile-Elasticsearch-Version': versionWithoutSnapshot,
'X-Compile-Elasticsearch-Version': VersionProperties.elasticsearchVersion,
'X-Compile-Elasticsearch-Qualifier': System.getProperty("build.version_qualifier", ""),
'X-Compile-Elasticsearch-Snapshot': Boolean.parseBoolean(
System.getProperty("build.snapshot", "true")
),
'X-Compile-Lucene-Version': VersionProperties.lucene,
'X-Compile-Elasticsearch-Snapshot': VersionProperties.elasticsearch.isSnapshot(),
'Build-Date': ZonedDateTime.now(ZoneOffset.UTC),
'Build-Java-Version': project.compilerJavaVersion)
if (jarTask.manifest.attributes.containsKey('Change') == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ import java.util.regex.Matcher
* Notes on terminology:
* - The case for major+1 being released is accomplished through the isReleasableBranch value. If this is false, then the branch is no longer
* releasable, meaning not to test against any snapshots.
* - Released is defined as having > 1 suffix-free version in a major.minor series. For instance, only 6.2.0 means unreleased, but a
* 6.2.0 and 6.2.1 mean that 6.2.0 was released already.
*/
class VersionCollection {

Expand All @@ -73,48 +71,27 @@ class VersionCollection {
* @param versionLines The lines of the Version.java file.
*/
VersionCollection(List<String> versionLines) {
final boolean buildSnapshot = System.getProperty("build.snapshot", "true") == "true"

List<Version> versions = []
// This class should be converted wholesale to use the treeset

for (final String line : versionLines) {
final Matcher match = line =~ /\W+public static final Version V_(\d+)_(\d+)_(\d+)(_alpha\d+|_beta\d+|_rc\d+)? .*/
if (match.matches()) {
final Version foundVersion = new Version(
Integer.parseInt(match.group(1)), Integer.parseInt(match.group(2)),
Integer.parseInt(match.group(3)), (match.group(4) ?: '').replace('_', '-'), false)
safeAddToSet(foundVersion)
Integer.parseInt(match.group(1)),
Integer.parseInt(match.group(2)),
Integer.parseInt(match.group(3))
)
versionSet.add(foundVersion)
}
}

if (versionSet.empty) {
throw new GradleException("Unexpectedly found no version constants in Versions.java")
}

// If the major version has been released, then remove all of the alpha/beta/rc versions that exist in the set
versionSet.removeAll { it.suffix.isEmpty() == false && isMajorReleased(it, versionSet) }

// set currentVersion
Version lastVersion = versionSet.last()
currentVersion = new Version(lastVersion.major, lastVersion.minor, lastVersion.revision, lastVersion.suffix, buildSnapshot)

// remove all of the potential alpha/beta/rc from the currentVersion
versionSet.removeAll {
it.suffix.isEmpty() == false &&
it.major == currentVersion.major &&
it.minor == currentVersion.minor &&
it.revision == currentVersion.revision }

// re-add the currentVersion to the set
versionSet.add(currentVersion)
currentVersion = versionSet.last()

if (isReleasableBranch) {
if (isReleased(currentVersion)) {
// caveat 0 - if the minor has been released then it only has a maintenance version
// go back 1 version to get the last supported snapshot version of the line, which is a maint bugfix
Version highestMinor = getHighestPreviousMinor(currentVersion.major)
maintenanceBugfixSnapshot = replaceAsSnapshot(highestMinor)
maintenanceBugfixSnapshot = getHighestPreviousMinor(currentVersion.major)
} else {
// caveat 3 - if our currentVersion is a X.0.0, we need to check X-1 minors to see if they are released
if (currentVersion.minor == 0) {
Expand All @@ -125,15 +102,15 @@ class VersionCollection {
// it will bail. The order is that the minor snapshot is fufilled first, and then the staged minor snapshot
if (nextMinorSnapshot == null) {
// it has not been set yet
nextMinorSnapshot = replaceAsSnapshot(version)
nextMinorSnapshot = version
} else if (stagedMinorSnapshot == null) {
stagedMinorSnapshot = replaceAsSnapshot(version)
stagedMinorSnapshot = version
} else {
throw new GradleException("More than 2 snapshot version existed for the next minor and staged (frozen) minors.")
}
} else {
// caveat 2 - this is the last minor snap for this major, so replace the highest (last) one of these and break
nextBugfixSnapshot = replaceAsSnapshot(version)
nextBugfixSnapshot = version
// we only care about the largest minor here, so in the case of 6.1 and 6.0, it will only get 6.1
break
}
Expand All @@ -148,24 +125,23 @@ class VersionCollection {
// caveat 1 - This should only ever contain 0 or 1 branch in flight. An example is 6.x is frozen, and 6.2 is cut
// but not yet released there is some simple logic to make sure that in the case of more than 1, it will bail
if (stagedMinorSnapshot == null) {
stagedMinorSnapshot = replaceAsSnapshot(version)
stagedMinorSnapshot = version
} else {
throw new GradleException("More than 1 snapshot version existed for the staged (frozen) minors.")
}
} else {
// caveat 2 - this is the last minor snap for this major, so replace the highest (last) one of these and break
nextBugfixSnapshot = replaceAsSnapshot(version)
nextBugfixSnapshot = version
// we only care about the largest minor here, so in the case of 6.1 and 6.0, it will only get 6.1
break
}
}
// caveat 0 - now dip back 1 version to get the last supported snapshot version of the line
Version highestMinor = getHighestPreviousMinor(currentVersion.major)
maintenanceBugfixSnapshot = replaceAsSnapshot(highestMinor)
maintenanceBugfixSnapshot = highestMinor
}
}
}

this.versions = Collections.unmodifiableList(versionSet.toList())
}

Expand Down Expand Up @@ -275,18 +251,6 @@ class VersionCollection {
return version.revision > 0
}

/**
* Validates that the count of non suffixed (alpha/beta/rc) versions in a given major to major+1 is greater than 1.
* This means that there is more than just a major.0.0 or major.0.0-alpha in a branch to signify it has been prevously released.
*/
private boolean isMajorReleased(Version version, TreeSet<Version> items) {
return items
.tailSet(Version.fromString("${version.major}.0.0"))
.headSet(Version.fromString("${version.major + 1}.0.0"))
.count { it.suffix.isEmpty() } // count only non suffix'd versions as actual versions that may be released
.intValue() > 1
}

/**
* Gets the largest version previous major version based on the nextMajorVersion passed in.
* If you have a list [5.0.2, 5.1.2, 6.0.1, 6.1.1] and pass in 6 for the nextMajorVersion, it will return you 5.1.2
Expand All @@ -299,22 +263,11 @@ class VersionCollection {
/**
* Helper function for turning a version into a snapshot version, removing and readding it to the tree
*/
private Version replaceAsSnapshot(Version version) {
versionSet.remove(version)
Version snapshotVersion = new Version(version.major, version.minor, version.revision, version.suffix, true)
safeAddToSet(snapshotVersion)
return snapshotVersion
}

/**
* Safely adds a value to the treeset, or bails if the value already exists.
* @param version
*/
private void safeAddToSet(Version version) {
if (versionSet.add(version) == false) {
throw new GradleException("Versions.java contains duplicate entries for ${version}")
}
}

/**
* Gets the entire set of major.minor.* given those parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public class DocsTestPlugin extends RestTestPlugin {
// Docs are published separately so no need to assemble
project.tasks.assemble.enabled = false
Map<String, String> defaultSubstitutions = [
/* These match up with the asciidoc syntax for substitutions but
* the values may differ. In particular {version} needs to resolve
* to the version being built for testing but needs to resolve to
* the last released version for docs. */
'\\{version\\}':
VersionProperties.elasticsearch.toString().replace('-SNAPSHOT', ''),
/* These match up with the asciidoc syntax for substitutions but
* the values may differ. In particular {version} needs to resolve
* to the version being built for testing but needs to resolve to
* the last released version for docs. */
'\\{version\\}': VersionProperties.elasticsearchVersion.toString(),
'\\{plugin_version\\}': VersionProperties.elasticsearchVersion.toString(),
'\\{lucene_version\\}' : VersionProperties.lucene.replaceAll('-snapshot-\\w+$', ''),
'\\{build_flavor\\}' :
project.integTestCluster.distribution.startsWith('oss-') ? 'oss' : 'default',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import nebula.plugin.publishing.maven.MavenScmPlugin
import org.elasticsearch.gradle.BuildPlugin
import org.elasticsearch.gradle.NoticeTask
import org.elasticsearch.gradle.VersionProperties
import org.elasticsearch.gradle.test.RestIntegTestTask
import org.elasticsearch.gradle.test.RunTask
import org.gradle.api.Project
Expand Down Expand Up @@ -112,8 +113,8 @@ public class PluginBuildPlugin extends BuildPlugin {

private static void configureDependencies(Project project) {
project.dependencies {
compileOnly "org.elasticsearch:elasticsearch:${project.versions.elasticsearch}"
testCompile "org.elasticsearch.test:framework:${project.versions.elasticsearch}"
compileOnly "org.elasticsearch:elasticsearch:${VersionProperties.elasticsearch}"
testCompile "org.elasticsearch.test:framework:${VersionProperties.elasticsearch}"
// we "upgrade" these optional deps to provided for plugins, since they will run
// with a full elasticsearch server that includes optional deps
compileOnly "org.locationtech.spatial4j:spatial4j:${project.versions.spatial4j}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,11 @@ class PluginPropertiesTask extends Copy {
}

Map<String, String> generateSubstitutions() {
def stringSnap = { version ->
if (version.endsWith("-SNAPSHOT")) {
return version.substring(0, version.length() - 9)
}
return version
}
return [
'name': extension.name,
'description': extension.description,
'version': stringSnap(extension.version),
'elasticsearchVersion': stringSnap(VersionProperties.elasticsearch.toString()),
'version': extension.version as String,
'elasticsearchVersion': VersionProperties.elasticsearchVersion as String,
'javaVersion': project.targetCompatibility as String,
'classname': extension.classname,
'extendedPlugins': extension.extendedPlugins.join(','),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package org.elasticsearch.gradle.precommit
import org.elasticsearch.gradle.ExportElasticsearchBuildResourcesTask
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.quality.Checkstyle
/**
Expand Down
Loading