Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore non-standard repositories #225

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.goyeau.mill.scalafix

import com.goyeau.mill.scalafix.ScalafixModule.{filesToFix, fixAction}
import coursier.Repository
import mill.{Agg, T}
import mill.{Agg, T, Task}
import mill.api.{Logger, PathRef, Result}
import mill.scalalib.{Dep, ScalaModule}
import mill.define.Command
Expand All @@ -15,6 +15,24 @@ import scala.jdk.CollectionConverters.*
trait ScalafixModule extends ScalaModule {
def scalafixConfig: T[Option[os.Path]] = T(None)
def scalafixIvyDeps: T[Agg[Dep]] = Agg.empty[Dep]

/** Override this to filter out repositories that don't need to be passed to scalafix
*
* Repositories passed to scalafix need to be converted to the coursier-interface API (coursierapi.*). This can be an
* issue for non-Maven or Ivy repositories. Overriding this task and filtering those repositories out allows to work
* around that.
*/
def scalafixRepositories: Task[Seq[Repository]] = Task.Anon {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between Task.Anon and Task?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The former doesn't serialize and cache its result, while the latter does. CoursierModule#repositoriesTask relies on that for example, as all coursier.Repository instances cannot all be serialized to JSON (coursier.Repository is an "open" abstract class, we don't know all its implementations beforehand). We need to do the same here, as coursier.Repository is involved.

repositoriesTask().filter {
case repo if repo.getClass.getName == "mill.scalalib.JavaModule$InternalRepo" =>
// Change to this when bumping to Mill 0.13.x:
// case _: mill.scalalib.JavaModule.InternalRepo =>
// no need to pass Mill's internal repository to scalafix
false
case _ => true
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Do you mind adding a space after this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure


@deprecated("Scalafix now follows scalaVersion", since = "0.4.2")
def scalafixScalaBinaryVersion: T[String] = "2.12"

Expand All @@ -24,7 +42,7 @@ trait ScalafixModule extends ScalaModule {
T.command {
fixAction(
T.ctx().log,
repositoriesTask(),
scalafixRepositories(),
filesToFix(sources()).map(_.path),
classpath = (compileClasspath() ++ localClasspath() ++ Seq(semanticDbData())).iterator.toSeq.map(_.path),
scalaVersion(),
Expand Down
Loading