Skip to content

Commit

Permalink
Make bwcVersion a Version too
Browse files Browse the repository at this point in the history
  • Loading branch information
jasontedor committed Apr 13, 2018
1 parent edeef51 commit ee06d86
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 20 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import java.security.MessageDigest
// common maven publishing configuration
subprojects {
group = 'org.elasticsearch'
version = VersionProperties.elasticsearch
version = VersionProperties.elasticsearch.toString()
description = "Elasticsearch subproject ${project.path}"
}

Expand Down Expand Up @@ -80,7 +80,7 @@ configure(subprojects.findAll { it.projectDir.toPath().startsWith(rootPath) }) {
* 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.toString() != VersionProperties.elasticsearch) {
if (versions.currentVersion != VersionProperties.elasticsearch) {
throw new GradleException("The last version in Versions.java [${versions.currentVersion}] does not match " +
"VersionProperties.elasticsearch [${VersionProperties.elasticsearch}]")
}
Expand Down Expand Up @@ -245,7 +245,7 @@ subprojects {
// other packages (e.g org.elasticsearch.client) will point to server rather than
// their own artifacts.
if (project.plugins.hasPlugin(BuildPlugin)) {
String artifactsHost = VersionProperties.elasticsearch.endsWith("-SNAPSHOT") ? "https://snapshots.elastic.co" : "https://artifacts.elastic.co"
String artifactsHost = VersionProperties.elasticsearch.toString().endsWith("-SNAPSHOT") ? "https://snapshots.elastic.co" : "https://artifacts.elastic.co"
Closure sortClosure = { a, b -> b.group <=> a.group }
Closure depJavadocClosure = { dep ->
if (dep.group != null && dep.group.startsWith('org.elasticsearch')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,8 @@ class BuildPlugin implements Plugin<Project> {
jarTask.destinationDir = new File(project.buildDir, 'distributions')
// fixup the jar manifest
jarTask.doFirst {
boolean isSnapshot = VersionProperties.elasticsearch.endsWith("-SNAPSHOT");
String version = VersionProperties.elasticsearch;
final String version = VersionProperties.elasticsearch.toString()
boolean isSnapshot = version.endsWith("-SNAPSHOT");
if (isSnapshot) {
version = version.substring(0, version.length() - 9)
}
Expand Down
24 changes: 20 additions & 4 deletions buildSrc/src/main/groovy/org/elasticsearch/gradle/Version.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,36 @@ public class Version {
return "${major}.${minor}.${revision}${suffix}${snapshotStr}"
}

public boolean before(Version compareTo) {
return id < compareTo.id
}

public boolean before(String compareTo) {
return id < fromString(compareTo).id
return before(fromString(compareTo))
}

public boolean onOrBefore(Version compareTo) {
return id <= compareTo.id
}

public boolean onOrBefore(String compareTo) {
return id <= fromString(compareTo).id
return onOrBefore(fromString(compareTo))
}

public boolean onOrAfter(Version compareTo) {
return id >= compareTo.id
}

public boolean onOrAfter(String compareTo) {
return id >= fromString(compareTo).id
return onOrAfter(fromString(compareTo))
}

public boolean after(Version compareTo) {
return id > compareTo.id
}

public boolean after(String compareTo) {
return id > fromString(compareTo).id
return after(fromString(compareTo))
}

public boolean onOrBeforeIncludingSuffix(Version otherVersion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package org.elasticsearch.gradle
* Accessor for shared dependency versions used by elasticsearch, namely the elasticsearch and lucene versions.
*/
class VersionProperties {
static final String elasticsearch
static final Version elasticsearch
static final String lucene
static final Map<String, String> versions = new HashMap<>()
static {
Expand All @@ -32,7 +32,7 @@ class VersionProperties {
throw new RuntimeException('/version.properties resource missing')
}
props.load(propsStream)
elasticsearch = props.getProperty('elasticsearch')
elasticsearch = Version.fromString(props.getProperty('elasticsearch'))
lucene = props.getProperty('lucene')
for (String property : props.stringPropertyNames()) {
versions.put(property, props.getProperty(property))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class DocsTestPlugin extends RestTestPlugin {
* to the version being built for testing but needs to resolve to
* the last released version for docs. */
'\\{version\\}':
VersionProperties.elasticsearch.replace('-SNAPSHOT', ''),
VersionProperties.elasticsearch.toString().replace('-SNAPSHOT', ''),
'\\{lucene_version\\}' : VersionProperties.lucene.replaceAll('-snapshot-\\w+$', ''),
]
Task listSnippets = project.tasks.create('listSnippets', SnippetsTask)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class PluginPropertiesTask extends Copy {
'name': extension.name,
'description': extension.description,
'version': stringSnap(extension.version),
'elasticsearchVersion': stringSnap(VersionProperties.elasticsearch),
'elasticsearchVersion': stringSnap(VersionProperties.elasticsearch.toString()),
'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 @@ -18,6 +18,7 @@
*/
package org.elasticsearch.gradle.test

import org.elasticsearch.gradle.Version
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.tasks.Input
Expand All @@ -37,7 +38,7 @@ class ClusterConfiguration {
int numBwcNodes = 0

@Input
String bwcVersion = null
Version bwcVersion = null

@Input
int httpPort = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ClusterFormationTasks {

configureDistributionDependency(project, config.distribution, bwcDistro, config.bwcVersion)
for (Map.Entry<String, Project> entry : config.plugins.entrySet()) {
configureBwcPluginDependency("${prefix}_elasticsearchBwcPlugins", project, entry.getValue(), bwcPlugins, Version.fromString(config.bwcVersion))
configureBwcPluginDependency("${prefix}_elasticsearchBwcPlugins", project, entry.getValue(), bwcPlugins, config.bwcVersion)
}
bwcDistro.resolutionStrategy.cacheChangingModulesFor(0, TimeUnit.SECONDS)
bwcPlugins.resolutionStrategy.cacheChangingModulesFor(0, TimeUnit.SECONDS)
Expand All @@ -110,10 +110,10 @@ class ClusterFormationTasks {
final Configuration distro
final Version elasticsearchVersion
if (i < config.numBwcNodes) {
elasticsearchVersion = Version.fromString(config.bwcVersion)
elasticsearchVersion = config.bwcVersion
distro = bwcDistro
} else {
elasticsearchVersion = Version.fromString(VersionProperties.elasticsearch)
elasticsearchVersion = VersionProperties.elasticsearch
distro = currentDistro
}
NodeInfo node = new NodeInfo(config, i, project, prefix, elasticsearchVersion, sharedDir)
Expand All @@ -129,7 +129,7 @@ class ClusterFormationTasks {
}

/** Adds a dependency on the given distribution */
static void configureDistributionDependency(Project project, String distro, Configuration configuration, String elasticsearchVersion) {
static void configureDistributionDependency(Project project, String distro, Configuration configuration, Version elasticsearchVersion) {
String packaging = distro
if (distro == 'tar') {
packaging = 'tar.gz'
Expand Down Expand Up @@ -186,7 +186,7 @@ class ClusterFormationTasks {
setup = configureAddKeystoreFileTasks(prefix, project, setup, node)

if (node.config.plugins.isEmpty() == false) {
if (node.nodeVersion == Version.fromString(VersionProperties.elasticsearch)) {
if (node.nodeVersion == VersionProperties.elasticsearch) {
setup = configureCopyPluginsTask(taskName(prefix, node, 'copyPlugins'), project, setup, node, prefix)
} else {
setup = configureCopyBwcPluginsTask(taskName(prefix, node, 'copyBwcPlugins'), project, setup, node, prefix)
Expand Down Expand Up @@ -517,7 +517,7 @@ class ClusterFormationTasks {

static Task configureInstallPluginTask(String name, Project project, Task setup, NodeInfo node, Project plugin, String prefix) {
final FileCollection pluginZip;
if (node.nodeVersion != Version.fromString(VersionProperties.elasticsearch)) {
if (node.nodeVersion != VersionProperties.elasticsearch) {
pluginZip = project.configurations.getByName(pluginBwcConfigurationName(prefix, plugin))
} else {
pluginZip = project.configurations.getByName(pluginConfigurationName(prefix, plugin))
Expand Down

0 comments on commit ee06d86

Please sign in to comment.