Skip to content

Commit

Permalink
Cross build to sbt 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Nov 10, 2024
1 parent 23515b3 commit 280d305
Show file tree
Hide file tree
Showing 62 changed files with 735 additions and 697 deletions.
10 changes: 7 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ organization := "com.github.sbt"
homepage := Some(url("https://github.com/sbt/sbt-native-packager"))

Global / onChangedBuildSource := ReloadOnSourceChanges
Global / scalaVersion := "2.12.20"

// crossBuildingSettings
lazy val scala212 = "2.12.20"
lazy val scala3 = "3.3.4"
Global / scalaVersion := scala3
crossScalaVersions := Seq(scala3, scala212)
(pluginCrossBuild / sbtVersion) := {
scalaBinaryVersion.value match {
case "2.12" => "1.1.6"
Expand Down Expand Up @@ -48,8 +51,7 @@ libraryDependencies ++= {
// scala version depended libraries
libraryDependencies ++= {
scalaBinaryVersion.value match {
case "2.10" => Nil
case _ =>
case "2.12" =>
Seq(
// Do NOT upgrade these dependencies to 2.x or newer! sbt-native-packager is a sbt-plugin
// and gets published with Scala 2.12, therefore we need to stay at the same major version
Expand All @@ -58,6 +60,8 @@ libraryDependencies ++= {
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2", // Do not upgrade beyond 1.x
"org.scala-lang.modules" %% "scala-xml" % "2.2.0"
)
case _ =>
Nil
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/main/scala-2.12/com/typesafe/sbt/packager/PluginCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.typesafe.sbt.packager

import java.nio.file.{Path => NioPath}
import java.util.jar.Attributes
import sbt.*
import xsbti.{FileConverter, HashedVirtualFileRef, VirtualFile}

private[packager] object PluginCompat {
type FileRef = java.io.File
type ArtifactPath = java.io.File
type Out = java.io.File

def toNioPath(a: Attributed[File])(implicit conv: FileConverter): NioPath =
a.data.toPath()
def toFile(a: Attributed[File])(implicit conv: FileConverter): File =
a.data
def artifactPathToFile(ref: File)(implicit conv: FileConverter): File =
ref
def toNioPaths(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[NioPath] =
cp.map(_.data.toPath()).toVector
def toFiles(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[File] =
cp.map(_.data).toVector

def classpathAttr = Attributes.Name.CLASS_PATH
def mainclassAttr = Attributes.Name.MAIN_CLASS
}
3 changes: 3 additions & 0 deletions src/main/scala-3/com/typesafe/sbt/packager/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.typesafe.sbt.packager

object Compat {}
56 changes: 56 additions & 0 deletions src/main/scala-3/com/typesafe/sbt/packager/PluginCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.typesafe.sbt.packager

import java.io.File
import java.nio.file.{ Path => NioPath }
import java.util.jar.Attributes
import sbt.*
import xsbti.{ FileConverter, HashedVirtualFileRef, VirtualFile, VirtualFileRef }
import sbt.internal.RemoteCache

private[packager] object PluginCompat:
type FileRef = HashedVirtualFileRef
type ArtifactPath = VirtualFileRef
type Out = VirtualFile
type IncludeArtifact = Any => Boolean

val artifactStr = Keys.artifactStr
val moduleIDStr = Keys.moduleIDStr
def parseModuleIDStrAttribute(str: String): ModuleID =
Classpaths.moduleIdJsonKeyFormat.read(str)
def moduleIDToStr(m: ModuleID): String =
Classpaths.moduleIdJsonKeyFormat.write(m)

def parseArtifactStrAttribute(str: String): Artifact =
import sbt.librarymanagement.LibraryManagementCodec.ArtifactFormat
import sjsonnew.support.scalajson.unsafe.*
Converter.fromJsonUnsafe[Artifact](Parser.parseUnsafe(str))
def artifactToStr(art: Artifact): String =
import sbt.librarymanagement.LibraryManagementCodec.ArtifactFormat
import sjsonnew.support.scalajson.unsafe.*
CompactPrinter(Converter.toJsonUnsafe(art))

def toNioPath(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): NioPath =
conv.toPath(a.data)
def toNioPath(ref: HashedVirtualFileRef)(using conv: FileConverter): NioPath =
conv.toPath(ref)
inline def toFile(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): File =
toNioPath(a).toFile()
inline def toFile(ref: HashedVirtualFileRef)(using conv: FileConverter): File =
toNioPath(ref).toFile()
def artifactPathToFile(ref: VirtualFileRef)(using conv: FileConverter): File =
conv.toPath(ref).toFile()
def toArtifactPath(f: File)(using conv: FileConverter): ArtifactPath =
conv.toVirtualFile(f.toPath())
def toNioPaths(cp: Seq[Attributed[HashedVirtualFileRef]])(using conv: FileConverter): Vector[NioPath] =
cp.map(toNioPath).toVector
inline def toFiles(cp: Seq[Attributed[HashedVirtualFileRef]])(using conv: FileConverter): Vector[File] =
toNioPaths(cp).map(_.toFile())
def toFileRef(x: File)(using conv: FileConverter): FileRef =
conv.toVirtualFile(x.toPath())
def getName(ref: FileRef): String =
ref.name()
def getArtifactPathName(ref: ArtifactPath): String =
ref.name()
def classpathAttr: String = Attributes.Name.CLASS_PATH.toString()
def mainclassAttr: String = Attributes.Name.MAIN_CLASS.toString()
end PluginCompat
50 changes: 0 additions & 50 deletions src/main/scala-sbt-0.13/com/typesafe/sbt/packager/Compat.scala

This file was deleted.

130 changes: 0 additions & 130 deletions src/main/scala-sbt-0.13/com/typesafe/sbt/packager/MappingsHelper.scala

This file was deleted.

This file was deleted.

Loading

0 comments on commit 280d305

Please sign in to comment.