summaryrefslogtreecommitdiff
path: root/scalalib/src/mill/scalalib/dependency/DependencyUpdatesImpl.scala
blob: 3bb94202f7d0dc113a4835bff8c1c8fc7264d113 (plain) (blame)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package mill.scalalib.dependency

import mill.define._
import mill.scalalib.dependency.updates.{
  DependencyUpdates,
  ModuleDependenciesUpdates,
  UpdatesFinder
}
import mill.scalalib.dependency.versions.VersionsFinder
import mill.api.Ctx.{Home, Log}

object DependencyUpdatesImpl {

  def apply(ctx: Log with Home,
            rootModule: BaseModule,
            discover: Discover[_],
            allowPreRelease: Boolean): Unit = {

    // 1. Find all available versions for each dependency
    val allDependencyVersions = VersionsFinder.findVersions(ctx, rootModule)

    // 2. Extract updated versions from all available versions
    val allUpdates = allDependencyVersions.map { dependencyVersions =>
      UpdatesFinder.findUpdates(dependencyVersions, allowPreRelease)
    }

    // 3. Print the results
    showAllUpdates(allUpdates)
  }

  private def showAllUpdates(updates: Seq[ModuleDependenciesUpdates]): Unit =
    updates.foreach { dependencyUpdates =>
      val module = dependencyUpdates.module.toString
      val actualUpdates =
        dependencyUpdates.dependencies.filter(_.updates.nonEmpty)
      if (actualUpdates.isEmpty) {
        println(s"No dependency updates found for $module")
      } else {
        println(s"Found ${actualUpdates.length} dependency update for $module")
        showUpdates(actualUpdates)
      }
    }

  private def showUpdates(updates: Seq[DependencyUpdates]): Unit =
    updates.foreach { dependencyUpdate =>
      val module = s"${dependencyUpdate.dependency.module}"
      val allVersions =
        (dependencyUpdate.currentVersion +: dependencyUpdate.updates.toList)
          .mkString(" -> ")
      println(s"  $module : $allVersions")
    }
}