aboutsummaryrefslogtreecommitdiffstats
path: root/build-logic/src/main/kotlin/app/passwordstore/gradle/DependencyUpdatesPlugin.kt
blob: e35a184385688cb60b1f0141be30fb58479d788e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
 * Copyright © 2014-2024 The Android Password Store Authors. All Rights Reserved.
 * SPDX-License-Identifier: GPL-3.0-only
 */
package app.passwordstore.gradle

import com.github.zafarkhaja.semver.Version
import kotlin.jvm.optionals.getOrNull
import nl.littlerobots.vcu.plugin.VersionCatalogUpdateExtension
import nl.littlerobots.vcu.plugin.VersionCatalogUpdatePlugin
import nl.littlerobots.vcu.plugin.versionSelector
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure

@Suppress("Unused")
class DependencyUpdatesPlugin : Plugin<Project> {
  override fun apply(project: Project) {
    project.pluginManager.apply(VersionCatalogUpdatePlugin::class)
    project.extensions.configure<VersionCatalogUpdateExtension> {
      versionSelector {
        val currentVersion = Version.tryParse(it.currentVersion).getOrNull()
        val newVersion = Version.tryParse(it.candidate.version).getOrNull()
        if (currentVersion == null || newVersion == null) {
          false
        } else {
          newVersion.isHigherThan(currentVersion)
        }
      }
    }
  }
}