Skip to content

Commit

Permalink
Extract VersionNumber to standalone artifact (#1039)
Browse files Browse the repository at this point in the history
<!--
  ⬆ Put your description above this! ⬆

  Please be descriptive and detailed.
  
Please read our [Contributing
Guidelines](https://github.com/tinyspeck/foundry/blob/main/.github/CONTRIBUTING.md)
and [Code of Conduct](https://slackhq.github.io/code-of-conduct).

Don't worry about deleting this, it's not visible in the PR!
-->
  • Loading branch information
ZacSweers authored Oct 16, 2024
1 parent a58de5d commit 621df83
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Changelog
- project-local `gradle.properties`
- root-project `local.properties`
- root-project/global `gradle.properties`
- **New**: Extract `version-number` artifact. This contains a Kotlin, non-deprecated `VersionNumber` API. This is useful given that Gradle's is both deprecated and not available in standard JVM projects.
- Remove defunct `foundry.git.hooksPath` and `foundry.git.ignoreRevsFile` properties.

0.20.2
Expand Down
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ dependencies {
dokka(projects.tools.foundryCommon)
dokka(projects.tools.skippy)
dokka(projects.tools.tracing)
dokka(projects.tools.versionNumber)
dokka(projects.platforms.gradle.betterGradleProperties)
dokka(projects.platforms.gradle.foundryGradlePlugin)
dokka(projects.platforms.gradle.agpHandlers.agpHandlerApi)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ plugins {

dependencies {
lintChecks(libs.gradleLints)
implementation(libs.guava)
implementation(projects.tools.versionNumber)

compileOnly(gradleApi())
compileOnly(libs.agp)
Expand Down
1 change: 1 addition & 0 deletions platforms/gradle/foundry-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ dependencies {
// Better I/O
api(libs.okio)
api(projects.platforms.gradle.agpHandlers.agpHandlerApi)
api(projects.tools.versionNumber)

implementation(platform(libs.coroutines.bom))
implementation(libs.commonsText) { because("For access to its StringEscapeUtils") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import com.osacky.doctor.DoctorExtension
import com.squareup.moshi.adapter
import foundry.cli.AppleSiliconCompat
import foundry.gradle.agp.VersionNumber
import foundry.common.versioning.VersionNumber
import foundry.gradle.avoidance.ComputeAffectedProjectsTask
import foundry.gradle.avoidance.GenerateAndroidTestProjectPathsTask
import foundry.gradle.avoidance.GenerateDependencyGraphTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package foundry.gradle.tasks

import foundry.gradle.agp.VersionNumber
import foundry.common.versioning.VersionNumber
import java.io.IOException
import javax.inject.Inject
import okhttp3.OkHttpClient
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ include(
":tools:foundry-common",
":tools:skippy",
":tools:tracing",
":tools:version-number",
)

// https://docs.gradle.org/5.6/userguide/groovy_plugin.html#sec:groovy_compilation_avoidance
Expand Down
33 changes: 33 additions & 0 deletions tools/version-number/api/version-number.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public final class foundry/common/versioning/VersionNumber : java/lang/Comparable {
public static final field Companion Lfoundry/common/versioning/VersionNumber$Companion;
public fun <init> (IIIILjava/lang/String;)V
public synthetic fun <init> (IIIILjava/lang/String;Lfoundry/common/versioning/VersionNumber$AbstractScheme;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (IIILjava/lang/String;)V
public fun compareTo (Lfoundry/common/versioning/VersionNumber;)I
public synthetic fun compareTo (Ljava/lang/Object;)I
public fun equals (Ljava/lang/Object;)Z
public final fun getBaseVersion ()Lfoundry/common/versioning/VersionNumber;
public final fun getMajor ()I
public final fun getMicro ()I
public final fun getMinor ()I
public final fun getPatch ()I
public final fun getQualifier ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class foundry/common/versioning/VersionNumber$Companion {
public final fun getUNKNOWN ()Lfoundry/common/versioning/VersionNumber;
public final fun parse (Ljava/lang/String;)Lfoundry/common/versioning/VersionNumber;
public final fun scheme ()Lfoundry/common/versioning/VersionNumber$Scheme;
public final fun version (I)Lfoundry/common/versioning/VersionNumber;
public final fun version (II)Lfoundry/common/versioning/VersionNumber;
public static synthetic fun version$default (Lfoundry/common/versioning/VersionNumber$Companion;IIILjava/lang/Object;)Lfoundry/common/versioning/VersionNumber;
public final fun withPatchNumber ()Lfoundry/common/versioning/VersionNumber$Scheme;
}

public abstract interface class foundry/common/versioning/VersionNumber$Scheme {
public abstract fun format (Lfoundry/common/versioning/VersionNumber;)Ljava/lang/String;
public abstract fun parse (Ljava/lang/String;)Lfoundry/common/versioning/VersionNumber;
}

22 changes: 22 additions & 0 deletions tools/version-number/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2024 Slack Technologies, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.mavenPublish)
alias(libs.plugins.lint)
}

dependencies { implementation(libs.guava) }
3 changes: 3 additions & 0 deletions tools/version-number/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=version-number
POM_NAME=VersionNumber
POM_DESCRIPTION=VersionNumber
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package foundry.gradle.agp
package foundry.common.versioning

import com.google.common.collect.Ordering
import java.util.Locale
Expand Down Expand Up @@ -101,7 +101,7 @@ private constructor(

private abstract class AbstractScheme protected constructor(val depth: Int) : Scheme {
override fun parse(value: String?): VersionNumber {
if (value == null || value.isEmpty()) {
if (value.isNullOrEmpty()) {
return UNKNOWN
}
val scanner = Scanner(value)
Expand Down

0 comments on commit 621df83

Please sign in to comment.