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

Support to convert cross-versioned ModuleID to ModuleCoordinate #500

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

cryeo
Copy link

@cryeo cryeo commented Jul 10, 2023

Resolve #403

Support to convert cross-versioned ModuleID to ModuleCoordinate.

Background

  • ShadePattern.inLibrary extension method provides an easy way to add sbt-librarymanagement's ModuleID as jarjar-abrams's ModuleCoordinate to ShadeRule.
  • However, current conversion from ModuleID to ModuleCoordinate does not support for cross-versioned ModuleID.

Consideration

  • Should be completed on sbt-assembly plugin layer.
    • This support should essentially be provided in sbt-assembly plugin, so it is not good to modify jarjar-abrams.
  • Should not break current syntax.
    • Introduce wrapper class AssemblyShadeRule for ShadeRule without modifying jarjar-abrams.
    • Provide implicit conversion for compatibility.

@MasseGuillaume
Copy link
Member

alternatively if you don't wan't for this PR to get published:

import com.eed3si9n.jarjarabrams
import sbt.librarymanagement.{CrossVersion, ScalaModuleInfo}

implicit class RichShadePattern(pattern: jarjarabrams.ShadePattern) {
    def inLibraryWithScalaModuleInfo(scalaModuleInfo: Option[ScalaModuleInfo])(moduleIds: ModuleID*): jarjarabrams.ShadeRule = {
      val moduleIdsWithCrossVersion = 
        moduleIds.map(module =>
          (for {
            sm <- scalaModuleInfo
            f <- CrossVersion(module, scalaModuleInfo)
          } yield module.withName(f(module.name))).getOrElse(module)
        )

      inLibraryBase(moduleIdsWithCrossVersion: _*)
    }

    private def inLibraryBase(moduleId: ModuleID*): jarjarabrams.ShadeRule =
      pattern.inModuleCoordinates(
        moduleId.toVector
          .map(m => jarjarabrams.ModuleCoordinate(m.organization, m.name, m.revision)): _*
      )
  }

usage:

ShadeRule.rename("cats.kernel.**" -> s"new_cats.kernel.@1").inLibraryWithScalaModuleInfo(scalaModuleInfo.value)(
    "org.typelevel" %% "spire"  % "0.17.0"
)

@eed3si9n
Copy link
Member

Sorry about the delayed response. Given that I control Jar Jar Abrams as well, I feel like a better solution would be to capture whatever information we need to about ModuleID at Jar Jar Abrams level, if current ModuleCoordinate is insufficient. % vs %% for instance is expressed by crossVersion here - https://github.com/sbt/librarymanagement/blob/54011d5e74335bab229bc3f6532b6a1ca6d0d5cd/core/src/main/contraband-scala/sbt/librarymanagement/ModuleID.scala

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ShadeRule's libraries coordinates do not support cross version
3 participants