Skip to content

Commit

Permalink
[hibernate#1956] Handling of version for release processing
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole authored and DavideD committed Sep 16, 2024
1 parent 9614bb3 commit 4bd2790
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 137 deletions.
137 changes: 8 additions & 129 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import java.util.regex.Pattern

plugins {
id "local.versions"

id 'java-library'
id 'maven-publish'
id 'com.diffplug.spotless' version '6.25.0'
id 'org.asciidoctor.jvm.convert' version '4.0.2' apply false
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
}

group = "org.hibernate.reactive"
// leverage the ProjectVersion which comes from the `local.versions` plugin
version = project.projectVersion.fullName

ext {
if ( !project.hasProperty( 'sonatypeOssrhUser' ) ) {
sonatypeOssrhUser = null
Expand All @@ -17,57 +21,12 @@ ext {
}
}

ext {
projectGroup = 'org.hibernate.reactive'
projectVersionFile = file( "${rootProject.projectDir}/gradle/version.properties" )
projectVersion = Version.parseProjectVersion( readVersionFromProperties( projectVersionFile ) )

if ( project.hasProperty('releaseVersion') ) {
releaseVersion = Version.parseReleaseVersion( project.releaseVersion )
}
if ( project.hasProperty('developmentVersion') ) {
developmentVersion = Version.parseDevelopmentVersion( project.developmentVersion )
}
}

// nexusPublishing uses group and version
// as defaults
group = projectGroup
version = projectVersion

// Versions which need to be aligned across modules; this also
// allows overriding the build using a parameter, which can be
// useful to monitor compatibility for upcoming versions on CI:
//
// ./gradlew clean build -PhibernateOrmVersion=5.6.15-SNAPSHOT
ext {
if ( !project.hasProperty('hibernateOrmVersion') ) {
hibernateOrmVersion = '6.6.0.Final'
}
if ( !project.hasProperty( 'hibernateOrmGradlePluginVersion' ) ) {
// Same as ORM as default
hibernateOrmGradlePluginVersion = project.hibernateOrmVersion
}
// For ORM, we need a parsed version (to get the family, ...)

// For ORM, we need a parsed version (to get the family for the documentation during release).
// We use intervals to build with the latest ORM snapshot and this will fail version check.
// Because we don't need to publish or release anything we can disable the check in this case.
// Example:
// ./gradlew build -PhibernateOrmVersion='[5.4,5.5)' -PskipOrmVersionParsing
if ( project.hasProperty( 'skipOrmVersionParsing' ) ) {
// Default to true if the property is null
skipOrmVersionParsing = project.skipOrmVersionParsing ?: true
}
else {
skipOrmVersionParsing = false
}

if ( !Boolean.valueOf( project.skipOrmVersionParsing ) ) {
logger.lifecycle "Parsing ORM version"
hibernateOrmVersion = Version.parseProjectVersion( project.hibernateOrmVersion )
}

// Mainly, to allow CI to test the latest versions of Vert.X
// Example:
// ./gradlew build -PvertxSqlClientVersion=4.0.0-SNAPSHOT
Expand All @@ -77,10 +36,7 @@ ext {

testcontainersVersion = '1.19.8'

logger.lifecycle "Hibernate ORM Version: " + project.hibernateOrmVersion
logger.lifecycle "Hibernate ORM Gradle plugin Version: " + project.hibernateOrmGradlePluginVersion
logger.lifecycle "Vert.x SQL Client Version: " + project.vertxSqlClientVersion
logger.lifecycle "Hibernate Reactive: " + project.version
}

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

// FIXME: Also setting the group and version here otherwise not all tasks will find them
group = projectGroup
version = projectVersion
group = rootProject.group
version = rootProject.version

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

private static String readVersionFromProperties(File file) {
if ( !file.exists() ) {
throw new FileNotFoundException( "Version file $file.canonicalPath does not exists" )
}
Properties versionProperties = new Properties()
file.withInputStream {
stream -> versionProperties.load( stream )
}
return versionProperties.projectVersion
}

class Version {

private static final Pattern RELEASE_VERSION_PATTERN = ~/^(\d+)\.(\d+)\.(\d+)\.((?:Alpha\d+|Beta\d+|CR\d+)|Final)$/

private static final Pattern DEVELOPMENT_VERSION_PATTERN = ~/^(\d+)\.(\d+)\.(\d+)-SNAPSHOT$/

static Version parseReleaseVersion(String versionString) {
def matcher = (versionString =~ RELEASE_VERSION_PATTERN)
if ( !matcher.matches() ) {
throw new IllegalArgumentException(
"Invalid version number: '$versionString'." +
" Release version numbers must match /$RELEASE_VERSION_PATTERN/."
)
}
return new Version( matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(4), false )
}

static Version parseDevelopmentVersion(String versionString) {
def matcher = (versionString =~ DEVELOPMENT_VERSION_PATTERN)
if ( !matcher.matches() ) {
throw new IllegalArgumentException(
"Invalid version number: '$versionString'." +
" Development version numbers must match /$DEVELOPMENT_VERSION_PATTERN/."
)
}

return new Version( matcher.group(1), matcher.group(2), matcher.group(3), null, true )
}

static Version parseProjectVersion(String versionString) {
if ( (versionString =~ RELEASE_VERSION_PATTERN).matches() ) {
return parseReleaseVersion( versionString )
}
if ( (versionString =~ DEVELOPMENT_VERSION_PATTERN).matches() ) {
return parseDevelopmentVersion( versionString )
}
throw new IllegalArgumentException(
"Invalid version number: '$versionString'." +
" Project version numbers must match either /$RELEASE_VERSION_PATTERN/ or /$DEVELOPMENT_VERSION_PATTERN/."
)
}

final String major
final String minor
final String micro
final String qualifier
final boolean snapshot

Version(String major, String minor, String micro, String qualifier, boolean snapshot) {
this.major = major
this.minor = minor
this.micro = micro
this.qualifier = qualifier
this.snapshot = snapshot
}

@Override
String toString() {
[major, minor, micro, qualifier].findAll({ it != null }).join('.') + (snapshot ? '-SNAPSHOT' : '')
}

String getFamily() {
"$major.$minor"
}
}
10 changes: 4 additions & 6 deletions documentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import org.asciidoctor.gradle.jvm.AsciidoctorTask

import java.time.Year

apply plugin: 'org.asciidoctor.jvm.convert'
plugins {
id "org.asciidoctor.jvm.convert"
}

ext {
projectsToSkipWhenAggregatingJavadocs = [
Expand Down Expand Up @@ -119,13 +121,11 @@ def renderReferenceDocumentationTask = tasks.register( 'renderReferenceDocumenta
outputDir = project.layout.buildDirectory.dir( "asciidoc/reference/html_single" ).get().asFile
options logDocuments: true

logger.lifecycle "---- Rendering docs with version $project.version"

attributes icons: 'font',
'source-highlighter': 'rouge',
experimental: true,
linkcss: true,
majorMinorVersion: project.version.family,
majorMinorVersion: project.projectVersion.family,
fullVersion: project.version.toString(),
docinfo: 'private'
}
Expand All @@ -138,8 +138,6 @@ def assembleDocumentationTask = tasks.register( 'assembleDocumentation' ) {
dependsOn aggregateJavadocsTask, renderReferenceDocumentationTask
group 'Documentation'
description 'Grouping task for performing all documentation building tasks'

logger.lifecycle "Documentation groupId: '" + project.group + "', version: '" + project.version + "'"
}

assemble.dependsOn assembleDocumentationTask
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ org.gradle.java.installations.auto-download=false
# Enable the maven local repository (for local development when needed) when present (value ignored)
#enableMavenLocalRepo = true

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

# Override default Hibernate ORM Gradle plugin version
# Using the stable version because I don't know how to configure the build to download the snapshot version from
Expand Down
30 changes: 30 additions & 0 deletions local-build-plugins/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
plugins {
id "java-gradle-plugin"
}

repositories {
mavenCentral()
}

group = 'org.hibernate.reactive.build'
version = '1.0.0-SNAPSHOT'


dependencies {
implementation gradleApi()
}

java {
sourceCompatibility = 11
targetCompatibility = 11
}


gradlePlugin {
plugins {
projectEnv {
id = 'local.versions'
implementationClass = 'org.hibernate.reactive.env.VersionsPlugin'
}
}
}
1 change: 1 addition & 0 deletions local-build-plugins/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'local-build-plugins'
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.hibernate.reactive.env;

/**
* @author Steve Ebersole
*/
public class ProjectVersion {
final String major;
final String minor;
final boolean snapshot;

private final String family;
private final String fullName;

ProjectVersion(String fullName) {
this.fullName = fullName;

try {
final String[] hibernateVersionComponents = fullName.split( "\\." );
major = hibernateVersionComponents[0];
minor = hibernateVersionComponents[1];
}
catch (Exception e) {
throw new IllegalArgumentException( "Invalid version number: " + fullName + "." );
}

family = major + "." + minor;
snapshot = fullName.endsWith( "-SNAPSHOT" );
}

public String getMajor() {
return major;
}

public String getMinor() {
return minor;
}

public String getFullName() {
return fullName;
}

public String getFamily() {
return family;
}

public boolean isSnapshot() {
return snapshot;
}

@Override
public String toString() {
return fullName;
}
}
Loading

0 comments on commit 4bd2790

Please sign in to comment.