Skip to content

Commit 00c5856

Browse files
sebersoleDavideD
authored andcommitted
[#1956] Handling of version for release processing
1 parent c929e2e commit 00c5856

File tree

8 files changed

+250
-137
lines changed

8 files changed

+250
-137
lines changed

build.gradle

+8-129
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import java.util.regex.Pattern
2-
31
plugins {
2+
id "local.versions"
3+
44
id 'java-library'
55
id 'maven-publish'
66
id 'com.diffplug.spotless' version '6.25.0'
77
id 'org.asciidoctor.jvm.convert' version '4.0.2' apply false
88
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
99
}
1010

11+
group = "org.hibernate.reactive"
12+
// leverage the ProjectVersion which comes from the `local.versions` plugin
13+
version = project.projectVersion.fullName
14+
1115
ext {
1216
if ( !project.hasProperty( 'sonatypeOssrhUser' ) ) {
1317
sonatypeOssrhUser = null
@@ -17,57 +21,12 @@ ext {
1721
}
1822
}
1923

20-
ext {
21-
projectGroup = 'org.hibernate.reactive'
22-
projectVersionFile = file( "${rootProject.projectDir}/gradle/version.properties" )
23-
projectVersion = Version.parseProjectVersion( readVersionFromProperties( projectVersionFile ) )
24-
25-
if ( project.hasProperty('releaseVersion') ) {
26-
releaseVersion = Version.parseReleaseVersion( project.releaseVersion )
27-
}
28-
if ( project.hasProperty('developmentVersion') ) {
29-
developmentVersion = Version.parseDevelopmentVersion( project.developmentVersion )
30-
}
31-
}
32-
33-
// nexusPublishing uses group and version
34-
// as defaults
35-
group = projectGroup
36-
version = projectVersion
37-
3824
// Versions which need to be aligned across modules; this also
3925
// allows overriding the build using a parameter, which can be
4026
// useful to monitor compatibility for upcoming versions on CI:
4127
//
4228
// ./gradlew clean build -PhibernateOrmVersion=5.6.15-SNAPSHOT
4329
ext {
44-
if ( !project.hasProperty('hibernateOrmVersion') ) {
45-
hibernateOrmVersion = '6.6.0.Final'
46-
}
47-
if ( !project.hasProperty( 'hibernateOrmGradlePluginVersion' ) ) {
48-
// Same as ORM as default
49-
hibernateOrmGradlePluginVersion = project.hibernateOrmVersion
50-
}
51-
// For ORM, we need a parsed version (to get the family, ...)
52-
53-
// For ORM, we need a parsed version (to get the family for the documentation during release).
54-
// We use intervals to build with the latest ORM snapshot and this will fail version check.
55-
// Because we don't need to publish or release anything we can disable the check in this case.
56-
// Example:
57-
// ./gradlew build -PhibernateOrmVersion='[5.4,5.5)' -PskipOrmVersionParsing
58-
if ( project.hasProperty( 'skipOrmVersionParsing' ) ) {
59-
// Default to true if the property is null
60-
skipOrmVersionParsing = project.skipOrmVersionParsing ?: true
61-
}
62-
else {
63-
skipOrmVersionParsing = false
64-
}
65-
66-
if ( !Boolean.valueOf( project.skipOrmVersionParsing ) ) {
67-
logger.lifecycle "Parsing ORM version"
68-
hibernateOrmVersion = Version.parseProjectVersion( project.hibernateOrmVersion )
69-
}
70-
7130
// Mainly, to allow CI to test the latest versions of Vert.X
7231
// Example:
7332
// ./gradlew build -PvertxSqlClientVersion=4.0.0-SNAPSHOT
@@ -77,10 +36,7 @@ ext {
7736

7837
testcontainersVersion = '1.19.8'
7938

80-
logger.lifecycle "Hibernate ORM Version: " + project.hibernateOrmVersion
81-
logger.lifecycle "Hibernate ORM Gradle plugin Version: " + project.hibernateOrmGradlePluginVersion
8239
logger.lifecycle "Vert.x SQL Client Version: " + project.vertxSqlClientVersion
83-
logger.lifecycle "Hibernate Reactive: " + project.version
8440
}
8541

8642
// To release, see task ciRelease in release/build.gradle
@@ -99,9 +55,8 @@ subprojects {
9955
apply plugin: 'java-library'
10056
apply plugin: 'com.diffplug.spotless'
10157

102-
// FIXME: Also setting the group and version here otherwise not all tasks will find them
103-
group = projectGroup
104-
version = projectVersion
58+
group = rootProject.group
59+
version = rootProject.version
10560

10661
spotless {
10762
//Don't fail during the check: rather than enforcing guidelines, we use this plugin to fix mistakes automatically.
@@ -201,79 +156,3 @@ subprojects {
201156
}
202157
}
203158

204-
private static String readVersionFromProperties(File file) {
205-
if ( !file.exists() ) {
206-
throw new FileNotFoundException( "Version file $file.canonicalPath does not exists" )
207-
}
208-
Properties versionProperties = new Properties()
209-
file.withInputStream {
210-
stream -> versionProperties.load( stream )
211-
}
212-
return versionProperties.projectVersion
213-
}
214-
215-
class Version {
216-
217-
private static final Pattern RELEASE_VERSION_PATTERN = ~/^(\d+)\.(\d+)\.(\d+)\.((?:Alpha\d+|Beta\d+|CR\d+)|Final)$/
218-
219-
private static final Pattern DEVELOPMENT_VERSION_PATTERN = ~/^(\d+)\.(\d+)\.(\d+)-SNAPSHOT$/
220-
221-
static Version parseReleaseVersion(String versionString) {
222-
def matcher = (versionString =~ RELEASE_VERSION_PATTERN)
223-
if ( !matcher.matches() ) {
224-
throw new IllegalArgumentException(
225-
"Invalid version number: '$versionString'." +
226-
" Release version numbers must match /$RELEASE_VERSION_PATTERN/."
227-
)
228-
}
229-
return new Version( matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(4), false )
230-
}
231-
232-
static Version parseDevelopmentVersion(String versionString) {
233-
def matcher = (versionString =~ DEVELOPMENT_VERSION_PATTERN)
234-
if ( !matcher.matches() ) {
235-
throw new IllegalArgumentException(
236-
"Invalid version number: '$versionString'." +
237-
" Development version numbers must match /$DEVELOPMENT_VERSION_PATTERN/."
238-
)
239-
}
240-
241-
return new Version( matcher.group(1), matcher.group(2), matcher.group(3), null, true )
242-
}
243-
244-
static Version parseProjectVersion(String versionString) {
245-
if ( (versionString =~ RELEASE_VERSION_PATTERN).matches() ) {
246-
return parseReleaseVersion( versionString )
247-
}
248-
if ( (versionString =~ DEVELOPMENT_VERSION_PATTERN).matches() ) {
249-
return parseDevelopmentVersion( versionString )
250-
}
251-
throw new IllegalArgumentException(
252-
"Invalid version number: '$versionString'." +
253-
" Project version numbers must match either /$RELEASE_VERSION_PATTERN/ or /$DEVELOPMENT_VERSION_PATTERN/."
254-
)
255-
}
256-
257-
final String major
258-
final String minor
259-
final String micro
260-
final String qualifier
261-
final boolean snapshot
262-
263-
Version(String major, String minor, String micro, String qualifier, boolean snapshot) {
264-
this.major = major
265-
this.minor = minor
266-
this.micro = micro
267-
this.qualifier = qualifier
268-
this.snapshot = snapshot
269-
}
270-
271-
@Override
272-
String toString() {
273-
[major, minor, micro, qualifier].findAll({ it != null }).join('.') + (snapshot ? '-SNAPSHOT' : '')
274-
}
275-
276-
String getFamily() {
277-
"$major.$minor"
278-
}
279-
}

documentation/build.gradle

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import org.asciidoctor.gradle.jvm.AsciidoctorTask
22

33
import java.time.Year
44

5-
apply plugin: 'org.asciidoctor.jvm.convert'
5+
plugins {
6+
id "org.asciidoctor.jvm.convert"
7+
}
68

79
ext {
810
projectsToSkipWhenAggregatingJavadocs = [
@@ -115,13 +117,11 @@ def renderReferenceDocumentationTask = tasks.register( 'renderReferenceDocumenta
115117
outputDir = project.layout.buildDirectory.dir( "asciidoc/reference/html_single" ).get().asFile
116118
options logDocuments: true
117119

118-
logger.lifecycle "---- Rendering docs with version $project.version"
119-
120120
attributes icons: 'font',
121121
'source-highlighter': 'rouge',
122122
experimental: true,
123123
linkcss: true,
124-
majorMinorVersion: project.version.family,
124+
majorMinorVersion: project.projectVersion.family,
125125
fullVersion: project.version.toString(),
126126
docinfo: 'private'
127127
}
@@ -134,8 +134,6 @@ def assembleDocumentationTask = tasks.register( 'assembleDocumentation' ) {
134134
dependsOn aggregateJavadocsTask, renderReferenceDocumentationTask
135135
group 'Documentation'
136136
description 'Grouping task for performing all documentation building tasks'
137-
138-
logger.lifecycle "Documentation groupId: '" + project.group + "', version: '" + project.version + "'"
139137
}
140138

141139
assemble.dependsOn assembleDocumentationTask

gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ org.gradle.java.installations.auto-download=false
3434
# Enable the maven local repository (for local development when needed) when present (value ignored)
3535
#enableMavenLocalRepo = true
3636

37-
# Override default Hibernate ORM version
38-
#hibernateOrmVersion = 6.6.0.Final
37+
# The default Hibernate ORM version (override using `-PhibernateOrmVersion=the.version.you.want`)
38+
hibernateOrmVersion = 6.6.0.Final
3939

4040
# Override default Hibernate ORM Gradle plugin version
4141
# Using the stable version because I don't know how to configure the build to download the snapshot version from

local-build-plugins/build.gradle

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
plugins {
2+
id "java-gradle-plugin"
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
group = 'org.hibernate.reactive.build'
10+
version = '1.0.0-SNAPSHOT'
11+
12+
13+
dependencies {
14+
implementation gradleApi()
15+
}
16+
17+
java {
18+
sourceCompatibility = 11
19+
targetCompatibility = 11
20+
}
21+
22+
23+
gradlePlugin {
24+
plugins {
25+
projectEnv {
26+
id = 'local.versions'
27+
implementationClass = 'org.hibernate.reactive.env.VersionsPlugin'
28+
}
29+
}
30+
}

local-build-plugins/settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'local-build-plugins'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.hibernate.reactive.env;
2+
3+
/**
4+
* @author Steve Ebersole
5+
*/
6+
public class ProjectVersion {
7+
final String major;
8+
final String minor;
9+
final boolean snapshot;
10+
11+
private final String family;
12+
private final String fullName;
13+
14+
ProjectVersion(String fullName) {
15+
this.fullName = fullName;
16+
17+
try {
18+
final String[] hibernateVersionComponents = fullName.split( "\\." );
19+
major = hibernateVersionComponents[0];
20+
minor = hibernateVersionComponents[1];
21+
}
22+
catch (Exception e) {
23+
throw new IllegalArgumentException( "Invalid version number: " + fullName + "." );
24+
}
25+
26+
family = major + "." + minor;
27+
snapshot = fullName.endsWith( "-SNAPSHOT" );
28+
}
29+
30+
public String getMajor() {
31+
return major;
32+
}
33+
34+
public String getMinor() {
35+
return minor;
36+
}
37+
38+
public String getFullName() {
39+
return fullName;
40+
}
41+
42+
public String getFamily() {
43+
return family;
44+
}
45+
46+
public boolean isSnapshot() {
47+
return snapshot;
48+
}
49+
50+
@Override
51+
public String toString() {
52+
return fullName;
53+
}
54+
}

0 commit comments

Comments
 (0)