diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2015dde9..a470d938 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,18 +12,26 @@ jobs: fail-fast: false matrix: include: + - os: ubuntu-latest + java: 8 + distribution: zulu + jobtype: 1 - os: ubuntu-latest java: 8 distribution: temurin + jobtype: 2 - os: ubuntu-latest java: 21 distribution: temurin + jobtype: 1 - os: ubuntu-latest java: 24-ea distribution: temurin + jobtype: 1 - os: windows-latest java: 11 distribution: temurin + jobtype: 1 env: # define Java options for both official sbt and sbt-extras JAVA_OPTS: -Xms2048M -Xmx2048M -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8 @@ -36,7 +44,13 @@ jobs: distribution: "${{ matrix.distribution }}" java-version: "${{ matrix.java }}" cache: sbt - - name: Build and test + - name: Build and test (sbt 1.x) + if: ${{ matrix.jobtype == 1 }} + shell: bash + run: | + sbt -v ++2.12.x scripted + - name: Build and test (sbt 2.x) + if: ${{ matrix.jobtype == 2 }} shell: bash run: | - sbt -v clean scripted + sbt -v ++3.x scripted diff --git a/.gitignore b/.gitignore index a436503d..d101d4bf 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ project/plugins/lib_managed project/plugins/src_managed project/plugins/target project/plugins/project/build.properties -.idea \ No newline at end of file +.idea +metals.sbt diff --git a/build.sbt b/build.sbt index 913bb64b..f743d118 100644 --- a/build.sbt +++ b/build.sbt @@ -6,22 +6,35 @@ ThisBuild / version := { ThisBuild / organization := "com.eed3si9n" -def scala212 = "2.12.18" -ThisBuild / crossScalaVersions := Seq(scala212) -ThisBuild / scalaVersion := scala212 +def scala212 = "2.12.20" +def scala3 = "3.3.4" +ThisBuild / crossScalaVersions := Seq(scala212, scala3) +ThisBuild / scalaVersion := scala3 lazy val jarjar = "com.eed3si9n.jarjarabrams" %% "jarjar-abrams-core" % "1.14.0" lazy val root = (project in file(".")) - .enablePlugins(SbtPlugin, ContrabandPlugin, SbtPlugin) - .settings(pomConsistency2021DraftSettings) + .enablePlugins(SbtPlugin, ContrabandPlugin) .settings(nocomma { name := "sbt-assembly" - scalacOptions := Seq("-deprecation", "-unchecked", "-Dscalac.patmat.analysisBudget=1024", "-Xfuture") - libraryDependencies += jarjar + scalacOptions := Seq( + "-Xsource:3", + "-deprecation", + "-unchecked", + "-Dscalac.patmat.analysisBudget=1024", + "-Xfuture", + ) + libraryDependencies += jarjar.cross(CrossVersion.for3Use2_13) (pluginCrossBuild / sbtVersion) := { scalaBinaryVersion.value match { - case "2.12" => "1.2.8" + case "2.12" => "1.5.8" + case _ => "2.0.0-M2" + } + } + scriptedSbt := { + scalaBinaryVersion.value match { + case "2.12" => "1.10.2" + case _ => "2.0.0-M2" } } Compile / generateContrabands / sourceManaged := baseDirectory.value / "src" / "main" / "scala" @@ -29,7 +42,6 @@ lazy val root = (project in file(".")) Seq("-Xmx1024M", "-Dplugin.version=" + version.value) } scriptedBufferLog := false - scriptedSbt := "1.9.7" }) ThisBuild / scmInfo := Some( @@ -56,30 +68,3 @@ ThisBuild / publishTo := { else Some("releases" at nexus + "service/local/staging/deploy/maven2") } ThisBuild / publishMavenStyle := true - -// See https://eed3si9n.com/pom-consistency-for-sbt-plugins -lazy val pomConsistency2021Draft = settingKey[Boolean]("experimental") - -/** - * this is an unofficial experiment to re-publish plugins with better Maven compatibility - */ -def pomConsistency2021DraftSettings: Seq[Setting[_]] = Seq( - pomConsistency2021Draft := Set("true", "1")(sys.env.get("POM_CONSISTENCY").getOrElse("false")), - moduleName := { - if (pomConsistency2021Draft.value) - sbtPluginModuleName2021Draft(moduleName.value, - (pluginCrossBuild / sbtBinaryVersion).value) - else moduleName.value - }, - projectID := { - if (pomConsistency2021Draft.value) sbtPluginExtra2021Draft(projectID.value) - else projectID.value - }, -) - -def sbtPluginModuleName2021Draft(n: String, sbtV: String): String = - s"""${n}_sbt${if (sbtV == "1.0") "1" else if (sbtV == "2.0") "2" else sbtV}""" - -def sbtPluginExtra2021Draft(m: ModuleID): ModuleID = - m.withExtraAttributes(Map.empty) - .withCrossVersion(CrossVersion.binary) diff --git a/project/build.properties b/project/build.properties index 04267b14..0b699c30 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.9 +sbt.version=1.10.2 diff --git a/src/main/scala-2.12/PluginCompat.scala b/src/main/scala-2.12/PluginCompat.scala new file mode 100644 index 00000000..d4476cce --- /dev/null +++ b/src/main/scala-2.12/PluginCompat.scala @@ -0,0 +1,87 @@ +package sbtassembly + +import java.nio.file.{ Path => NioPath } +import java.util.jar.{ Manifest => JManifest } +import sbt.* +import sbt.internal.util.HNil +import sbt.internal.util.Types.:+: +import sbt.util.FileInfo.lastModified +import sbt.util.Tracked.{ inputChanged, lastOutput } +import xsbti.FileConverter + +private[sbtassembly] object PluginCompat { + type Out = java.io.File + type MainClass = sbt.Package.MainClass + + object CollectionConverters + + val moduleIDStr = Keys.moduleID.key + def parseModuleIDStrAttribute(m: ModuleID): ModuleID = m + + def toNioPath(a: Attributed[File])(implicit conv: FileConverter): NioPath = + a.data.toPath() + def toFile(a: Attributed[File])(implicit conv: FileConverter): File = + a.data + def toOutput(x: File)(implicit conv: FileConverter): File = + x + 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 + + type CacheKey = FilesInfo[ModifiedFileInfo] :+: + Map[String, (Boolean, String)] :+: // map of target paths that matched a merge strategy + JManifest :+: + // Assembly options... + Boolean :+: + Option[Seq[String]] :+: + Option[Int] :+: + Boolean :+: + HNil + + val HListFormats = sbt.internal.util.HListFormats + val Streamable = scala.tools.nsc.io.Streamable + + private[sbtassembly] def makeCacheKey( + classes: Vector[NioPath], + filteredJars: Vector[Attributed[File]], + mergeStrategiesByPathList: Map[String, (Boolean, String)], + jarManifest: JManifest, + ao: AssemblyOption, + ): CacheKey = + lastModified(classes.map(_.toFile()).toSet ++ filteredJars.map(_.data).toSet) :+: + mergeStrategiesByPathList :+: + jarManifest :+: + ao.repeatableBuild :+: + ao.prependShellScript :+: + ao.maxHashLength :+: + ao.appendContentHash :+: + HNil + + // sbt 1.x style disk cache + private[sbtassembly] def cachedAssembly(inputs: CacheKey, cacheDir: File, scalaVersion: String, log: Logger)( + buildAssembly: () => File + ): File = { + import CacheImplicits._ + import sbt.internal.util.HListFormats._ + import sbt.Package.manifestFormat + val cacheBlock = inputChanged(cacheDir / s"assembly-cacheKey-$scalaVersion") { (inputChanged, _: CacheKey) => + lastOutput(cacheDir / s"assembly-outputs-$scalaVersion") { (_: Unit, previousOutput: Option[File]) => + val outputExists = previousOutput.exists(_.exists()) + (inputChanged, outputExists) match { + case (false, true) => + log.info("Assembly jar up to date: " + previousOutput.get.toPath) + previousOutput.get + case (true, true) => + log.debug("Building assembly jar due to changed inputs...") + IO.delete(previousOutput.get) + buildAssembly() + case (_, _) => + log.debug("Building assembly jar due to missing output...") + buildAssembly() + } + } + } + cacheBlock(inputs)(Unit) + } +} diff --git a/src/main/scala-3/PluginCompat.scala b/src/main/scala-3/PluginCompat.scala new file mode 100644 index 00000000..8027bc65 --- /dev/null +++ b/src/main/scala-3/PluginCompat.scala @@ -0,0 +1,65 @@ +package sbtassembly + +import java.io.File +import java.nio.file.{ Path => NioPath } +import java.util.jar.{ Manifest => JManifest } +import sbt.* +import sbt.librarymanagement.ModuleID +import xsbti.{ FileConverter, HashedVirtualFileRef } + +object PluginCompat: + type Out = HashedVirtualFileRef + type JarManifest = PackageOption.JarManifest + type MainClass = PackageOption.MainClass + type ManifestAttributes = PackageOption.ManifestAttributes + type FixedTimestamp = PackageOption.FixedTimestamp + + val CollectionConverters = scala.collection.parallel.CollectionConverters + + val moduleIDStr = Keys.moduleIDStr + def parseModuleIDStrAttribute(str: String): ModuleID = + Classpaths.moduleIdJsonKeyFormat.read(str) + + def toNioPath(a: Attributed[HashedVirtualFileRef])(implicit conv: FileConverter): NioPath = + conv.toPath(a.data) + inline def toFile(a: Attributed[HashedVirtualFileRef])(implicit conv: FileConverter): File = + toNioPath(a).toFile() + def toOutput(x: File)(implicit conv: FileConverter): HashedVirtualFileRef = + conv.toVirtualFile(x.toPath()) + def toNioPaths(cp: Seq[Attributed[HashedVirtualFileRef]])(implicit conv: FileConverter): Vector[NioPath] = + cp.map(toNioPath).toVector + inline def toFiles(cp: Seq[Attributed[HashedVirtualFileRef]])(implicit conv: FileConverter): Vector[File] = + toNioPaths(cp).map(_.toFile()) + + object HListFormats + val Streamable = scala.reflect.io.Streamable + + extension [A1](init: Def.Initialize[Task[A1]]) + def ? : Def.Initialize[Task[Option[A1]]] = Def.optional(init) { + case None => sbt.std.TaskExtra.task { None } + case Some(t) => t.map(Some.apply) + } + + def or[A2 >: A1](i: Def.Initialize[Task[A2]]): Def.Initialize[Task[A2]] = + init.?.zipWith(i) { (toa1: Task[Option[A1]], ta2: Task[A2]) => + (toa1, ta2).mapN { + case (oa1: Option[A1], a2: A2) => oa1.getOrElse(a2) + } + } + + val inTask = Project.inTask + + type CacheKey = Int + private[sbtassembly] def makeCacheKey( + classes: Vector[NioPath], + filteredJars: Vector[Attributed[HashedVirtualFileRef]], + mergeStrategiesByPathList: Map[String, (Boolean, String)], + jarManifest: JManifest, + ao: AssemblyOption, + ): CacheKey = 0 + + private[sbtassembly] def cachedAssembly(inputs: CacheKey, cacheDir: File, scalaVersion: String, log: Logger)( + buildAssembly: () => PluginCompat.Out + ): PluginCompat.Out = + buildAssembly() +end PluginCompat diff --git a/src/main/scala-sbt-1.0/PluginCompat.scala b/src/main/scala-sbt-1.0/PluginCompat.scala deleted file mode 100644 index 964c7d7d..00000000 --- a/src/main/scala-sbt-1.0/PluginCompat.scala +++ /dev/null @@ -1,9 +0,0 @@ -package sbtassembly - -import sbt._ -import Keys._ - -object PluginCompat { - val ClasspathUtilities = sbt.internal.inc.classpath.ClasspathUtilities - val Using = sbt.io.Using -} diff --git a/src/main/scala/sbtassembly/Assembly.scala b/src/main/scala/sbtassembly/Assembly.scala index 3fff00d8..a92820f9 100644 --- a/src/main/scala/sbtassembly/Assembly.scala +++ b/src/main/scala/sbtassembly/Assembly.scala @@ -3,24 +3,19 @@ package sbtassembly import com.eed3si9n.jarjarabrams._ import sbt.Def.Initialize import sbt.Keys._ -import sbt.Package.{ manifestFormat, JarManifest, MainClass, ManifestAttributes } -import sbt.internal.util.HListFormats._ -import sbt.internal.util.HNil -import sbt.internal.util.Types.:+: +import sbt.Package.{ manifestFormat, JarManifest, MainClass, ManifestAttributes, FixedTimestamp } +import sbt.internal.inc.classpath.ClasspathUtil import sbt.io.{ DirectoryFilter => _, IO => _, Path => _, Using } -import sbt.util.FileInfo.lastModified -import sbt.util.Tracked.{ inputChanged, lastOutput } import sbt.util.{ FilesInfo, Level, ModifiedFileInfo } import sbt.{ File, Logger, _ } import sbt.Tags.Tag import CacheImplicits._ import sbtassembly.AssemblyPlugin.autoImport.{ Assembly => _, _ } -import sbtassembly.PluginCompat.ClasspathUtilities import java.io.{ BufferedInputStream, ByteArrayInputStream, FileInputStream, InputStream } import java.net.URI import java.nio.file.attribute.{ BasicFileAttributeView, FileTime, PosixFilePermission } -import java.nio.file.{ Path, _ } +import java.nio.file.{ Path => NioPath, _ } import java.security.MessageDigest import java.time.Instant import java.util.jar.{ Attributes => JAttributes, JarFile, Manifest => JManifest } @@ -28,7 +23,9 @@ import scala.annotation.tailrec import scala.collection.GenSeq import scala.collection.JavaConverters._ import scala.language.postfixOps -import scala.tools.nsc.io.Streamable +import xsbti.FileConverter +import PluginCompat.* +import CollectionConverters.{ given, * } object Assembly { // used for contraband @@ -43,15 +40,6 @@ object Assembly { val assemblyTag = Tag("assembly") - private[sbtassembly] type CacheKey = FilesInfo[ModifiedFileInfo] :+: - Map[String, (Boolean, String)] :+: // map of target paths that matched a merge strategy - JManifest :+: - // Assembly options... - Boolean :+: - Option[Seq[String]] :+: - Option[Int] :+: - Boolean :+: - HNil private[sbtassembly] val scalaPre213Libraries = Vector( "scala-actors", "scala-compiler", @@ -69,7 +57,7 @@ object Assembly { private[sbtassembly] val jarFileSystemResource = Using.resource((uri: URI) => FileSystems.newFileSystem(uri, Map("create" -> "true").asJava)) private[sbtassembly] val jarEntryInputStreamResource = Using.resource((entry: JarEntry) => entry.stream()) - private[sbtassembly] val jarEntryOutputStreamResource = Using.resource((path: Path) => + private[sbtassembly] val jarEntryOutputStreamResource = Using.resource((path: NioPath) => Files.newOutputStream(path, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE) ) private[sbtassembly] val byteArrayInputStreamResource = @@ -182,9 +170,10 @@ object Assembly { val jarName: String = s"$name${if (version.nonEmpty) "-" else ""}$version.jar" } - def assemblyTask(key: TaskKey[File]): Initialize[Task[File]] = Def.task { + def assemblyTask(key: TaskKey[PluginCompat.Out]): Initialize[Task[PluginCompat.Out]] = Def.task { val t = (key / test).value val s = (key / streams).value + val conv = fileConverter.value assemble( (key / assemblyJarName).value.replaceAll(".jar", ""), (key / assemblyOutputPath).value, @@ -192,6 +181,7 @@ object Assembly { (assembly / externalDependencyClasspath).value, (key / assemblyOption).value, (key / packageOptions).value, + conv, s.cacheDirectory, s.log ) @@ -219,9 +209,10 @@ object Assembly { externalDepClasspath: Classpath, ao: AssemblyOption, po: Seq[PackageOption], + conv: FileConverter, cacheDir: File, log: Logger - ): File = { + ): PluginCompat.Out = { def timed[A](level: Level.Value, desc: String)(f: => A): A = { log.log(level, desc + " start:") val start = Instant.now().toEpochMilli @@ -230,16 +221,18 @@ object Assembly { log.log(level, s"$desc end. Took ${end - start} ms") res } + implicit val ev: FileConverter = conv // used by PluginCompat val (jars, dirs) = timed(Level.Debug, "Separate classpath projects and all dependencies") { - classpath.toVector.sortBy(_.data.getCanonicalPath).partition(c => ClasspathUtilities.isArchive(c.data)) + classpath.toVector + .sortBy(x => toNioPath(x).toAbsolutePath().toString()) + .partition(x => ClasspathUtil.isArchive(toNioPath(x))) } val externalDeps = timed(Level.Debug, "Collect only external dependencies") { - externalDepClasspath.map(_.data).toSet.filter(ClasspathUtilities.isArchive) + externalDepClasspath.toSet + .filter(x => ClasspathUtil.isArchive(toNioPath(x))) } - val excludedJars = timed(Level.Debug, "Collect excluded jar names") { - ao.excludedJars map { - _.data - } + val excludedJars: Vector[NioPath] = timed(Level.Debug, "Collect excluded jar names") { + toNioPaths(ao.excludedJars) } val scalaLibraries = { val scalaVersionParts = VersionNumber(ao.scalaVersion) @@ -250,10 +243,10 @@ object Assembly { val filteredJars = timed(Level.Debug, "Filter jars") { jars.flatMap { - case jar if excludedJars contains jar.data.asFile => None - case jar if isScalaLibraryFile(scalaLibraries, jar.data.asFile) => + case jar if excludedJars.contains(jar) => None + case jar if isScalaLibraryFile(scalaLibraries, toNioPath(jar)) => if (ao.includeScala) Some(jar) else None - case jar if externalDeps contains jar.data.asFile => + case jar if externalDeps.contains(jar) => if (ao.includeDependency) Some(jar) else None case jar => if (ao.includeBin) Some(jar) else None @@ -261,15 +254,18 @@ object Assembly { } val classShader = shader(ao.shadeRules.filter(_.isApplicableToCompiling), log) - val classByParentDir = - if (!ao.includeBin) Vector.empty[(File, File)] - else dirs.flatMap(dir => (dir.data ** (-DirectoryFilter)).get.map(dir.data -> _)) + val classByParentDir: Vector[(NioPath, NioPath)] = + if (!ao.includeBin) Vector.empty + else dirs.flatMap { dir0 => + val dir = toNioPath(dir0) + (dir.toFile ** (-DirectoryFilter)).get().map(dir -> _.toPath()) + } val classMappings = timed(Level.Debug, "Collect and shade project classes") { classByParentDir .flatMap { case (parentDir, file) => - val originalTarget = file.relativeTo(parentDir).get.toPath.toString - classShader(originalTarget, () => new BufferedInputStream(new FileInputStream(file))) + val originalTarget = parentDir.relativize(file).toString + classShader(originalTarget, () => new BufferedInputStream(new FileInputStream(file.toFile()))) .map { case (shadedName, stream) => Project(targetJarName, originalTarget, shadedName, stream) } @@ -290,10 +286,11 @@ object Assembly { val (jarFiles, jarFileEntries) = timed(Level.Debug, "Collect and shade dependency entries") { filteredJars.par.map { jar => val module = jar.metadata - .get(moduleID.key) + .get(PluginCompat.moduleIDStr) + .map(PluginCompat.parseModuleIDStrAttribute) .map(m => ModuleCoordinate(m.organization, m.name, m.revision)) .getOrElse(ModuleCoordinate("", jar.data.name.replaceAll(".jar", ""), "")) - val jarFile = new JarFile(jar.data) + val jarFile = new JarFile(toFile(jar)) jarFile -> jarFile .entries() .asScala @@ -325,7 +322,7 @@ object Assembly { if (mergeStrategy.name == MergeStrategy.rename.name) Option.empty else Option(mergeStrategy) } - val buildAssembly = () => { + val buildAssembly: () => PluginCompat.Out = () => { val mergedEntries = timed(Level.Debug, "Merge all conflicting jar entries (including those renamed)") { merge(renamedDependencies ++ others, secondPassMergeStrategy, log) } @@ -338,9 +335,11 @@ object Assembly { } val jarEntriesToWrite = timed(Level.Debug, "Sort/Parallelize merged entries") { if (ao.repeatableBuild) // we need the jars in a specific order to have a consistent hash - mergedEntries.flatMap(_.entries).seq.sortBy(_.target) + mergedEntries.flatMap(_.entries) + .seq.sortBy(_.target) else // we actually gain performance when creating the jar in parallel, but we won't have a consistent hash - mergedEntries.flatMap(_.entries).par + mergedEntries.flatMap(_.entries) + .par.toVector } val localTime = timestamp .map(t => t - java.util.TimeZone.getDefault.getOffset(t)) @@ -392,7 +391,7 @@ object Assembly { } log.info("Built: " + builtAssemblyJar.toPath) log.info("Jar hash: " + fullSha1) - builtAssemblyJar + toOutput(builtAssemblyJar) } val mergeStrategiesByPathList = timed(Level.Debug, "Collect all merge strategies for cache check") { // collect all @@ -413,14 +412,13 @@ object Assembly { } ) { val (_, classes) = classByParentDir.unzip - val cacheKey = lastModified(classes.toSet ++ filteredJars.map(_.data).toSet) :+: - mergeStrategiesByPathList :+: - jarManifest :+: - ao.repeatableBuild :+: - ao.prependShellScript :+: - ao.maxHashLength :+: - ao.appendContentHash :+: - HNil + val cacheKey = makeCacheKey( + classes, + filteredJars, + mergeStrategiesByPathList, + jarManifest, + ao, + ) cachedAssembly(cacheKey, cacheDir, ao.scalaVersion, log)(buildAssembly) } else buildAssembly() } finally @@ -448,7 +446,7 @@ object Assembly { * @return flag representing if the file is a license file */ def isLicenseFile(fileName: String): Boolean = { - val LicenseFile = """(license|licence|notice|copying)([.]\w+)?$""".r + val LicenseFile = """(\._license|license|licence|notice|copying)([.]\w+)?$""".r fileName.toLowerCase match { case LicenseFile(_, ext) if ext != ".class" => true // DISLIKE case _ => false @@ -488,8 +486,8 @@ object Assembly { * @param file the given file to check * @return flag representing if the file is a Scala library */ - def isScalaLibraryFile(scalaLibraries: Vector[String], file: File): Boolean = - scalaLibraries exists { x => file.getName startsWith x } + def isScalaLibraryFile(scalaLibraries: Vector[String], file: NioPath): Boolean = + scalaLibraries exists { x => file.getFileName.toString.startsWith(x) } private[sbtassembly] def shader( shadeRules: SeqShadeRules, @@ -518,29 +516,6 @@ object Assembly { } } - private[sbtassembly] def cachedAssembly(inputs: CacheKey, cacheDir: File, scalaVersion: String, log: Logger)( - buildAssembly: () => File - ): File = { - val cacheBlock = inputChanged(cacheDir / s"assembly-cacheKey-$scalaVersion") { (inputChanged, _: CacheKey) => - lastOutput(cacheDir / s"assembly-outputs-$scalaVersion") { (_: Unit, previousOutput: Option[File]) => - val outputExists = previousOutput.exists(_.exists()) - (inputChanged, outputExists) match { - case (false, true) => - log.info("Assembly jar up to date: " + previousOutput.get.toPath) - previousOutput.get - case (true, true) => - log.debug("Building assembly jar due to changed inputs...") - IO.delete(previousOutput.get) - buildAssembly() - case (_, _) => - log.debug("Building assembly jar due to missing output...") - buildAssembly() - } - } - } - cacheBlock(inputs)(Unit) - } - private[sbtassembly] def createJar( output: File, entries: GenSeq[JarEntry], @@ -589,19 +564,9 @@ object Assembly { case JarManifest(mergeManifest) => Package.mergeManifests(manifest, mergeManifest) case MainClass(mainClassName) => main.put(JAttributes.Name.MAIN_CLASS, mainClassName) case ManifestAttributes(attrs @ _*) => main ++= attrs + case FixedTimestamp(value) => time = value case _ => - // use reflection for compatibility - if (option.getClass.getName == "sbt.Package$FixedTimestamp") { - try - // https://github.com/sbt/sbt/blob/59130d4703e9238e/main-actions/src/main/scala/sbt/Package.scala#L50 - time = option.asInstanceOf[{ def value: Option[Long] }].value - catch { - case e: Throwable => - log.debug(e.toString) - } - } else { - log.warn("Ignored unknown package option " + option) - } + log.warn("Ignored unknown package option " + option) } if (!main.contains(JAttributes.Name.MANIFEST_VERSION)) main.put(JAttributes.Name.MANIFEST_VERSION, "1.0") manifest -> time diff --git a/src/main/scala/sbtassembly/AssemblyKeys.scala b/src/main/scala/sbtassembly/AssemblyKeys.scala index ca8f49d3..33969153 100644 --- a/src/main/scala/sbtassembly/AssemblyKeys.scala +++ b/src/main/scala/sbtassembly/AssemblyKeys.scala @@ -1,15 +1,15 @@ package sbtassembly import com.eed3si9n.jarjarabrams -import sbt.Keys._ -import sbt._ +import sbt.Keys.* +import sbt.* trait AssemblyKeys { - lazy val assembly = taskKey[File]("Builds a deployable über JAR") + lazy val assembly = taskKey[PluginCompat.Out]("Builds a deployable über JAR") lazy val assembleArtifact = settingKey[Boolean]("Enables (true) or disables (false) assembling an artifact") lazy val assemblyOption = taskKey[AssemblyOption]("Configuration for making a deployable über JAR") - lazy val assemblyPackageScala = taskKey[File]("Produces the Scala artifact") - lazy val assemblyPackageDependency = taskKey[File]("Produces the dependency artifact") + lazy val assemblyPackageScala = taskKey[PluginCompat.Out]("Produces the Scala artifact") + lazy val assemblyPackageDependency = taskKey[PluginCompat.Out]("Produces the dependency artifact") lazy val assemblyJarName = taskKey[String]("name of the über jar") lazy val assemblyDefaultJarName = taskKey[String]("default name of the über jar") lazy val assemblyOutputPath = taskKey[File]("output path of the über jar") diff --git a/src/main/scala/sbtassembly/AssemblyPlugin.scala b/src/main/scala/sbtassembly/AssemblyPlugin.scala index c893c647..7abacc5d 100644 --- a/src/main/scala/sbtassembly/AssemblyPlugin.scala +++ b/src/main/scala/sbtassembly/AssemblyPlugin.scala @@ -2,7 +2,8 @@ package sbtassembly import com.eed3si9n.jarjarabrams import sbt.Keys._ -import sbt._ +import sbt.{ given, * } +import PluginCompat.* object AssemblyPlugin extends sbt.AutoPlugin { override def requires = plugins.JvmPlugin @@ -43,18 +44,18 @@ object AssemblyPlugin extends sbt.AutoPlugin { override lazy val projectSettings: Seq[Def.Setting[_]] = assemblySettings // Compile-specific defaults - lazy val assemblySettings: Seq[sbt.Def.Setting[_]] = baseAssemblySettings ++ Seq( + def assemblySettings: Seq[sbt.Def.Setting[_]] = baseAssemblySettings ++ Seq( assembly / packageOptions := { - val os = (packageOptions in (Compile, packageBin)).value + val os = (Compile / packageBin / packageOptions).value (assembly / mainClass).value map { s => - Package.MainClass(s) +: (os filterNot { _.isInstanceOf[Package.MainClass] }) + Package.MainClass(s) +: (os filterNot { _.isInstanceOf[MainClass] }) } getOrElse os }, - assemblyPackageScala / packageOptions := (packageOptions in (Compile, packageBin)).value, - assemblyPackageDependency / packageOptions := (packageOptions in (Compile, packageBin)).value + assemblyPackageScala / packageOptions := (Compile / packageBin / packageOptions).value, + assemblyPackageDependency / packageOptions := (Compile / packageBin / packageOptions).value ) - lazy val baseAssemblySettings: Seq[sbt.Def.Setting[_]] = (Seq( + def baseAssemblySettings: Seq[sbt.Def.Setting[_]] = (Seq( assembly := Assembly.assemblyTask(assembly).value, assemblyPackageScala := Assembly.assemblyTask(assemblyPackageScala).value, assemblyPackageDependency := Assembly.assemblyTask(assemblyPackageDependency).value, @@ -68,7 +69,7 @@ object AssemblyPlugin extends sbt.AutoPlugin { assembly / packageOptions := { val os = (packageBin / packageOptions).value (assembly / mainClass).value map { s => - Package.MainClass(s) +: (os filterNot { _.isInstanceOf[Package.MainClass] }) + Package.MainClass(s) +: (os filterNot { _.isInstanceOf[MainClass] }) } getOrElse os }, assemblyPackageScala / packageOptions := (packageBin / packageOptions).value, @@ -107,6 +108,10 @@ object AssemblyPlugin extends sbt.AutoPlugin { def assemblyOptionSettings: Seq[Setting[_]] = Seq( assemblyOption := { val s = streams.value + val sr = assemblyShadeRules.value + if (sr.nonEmpty && exportJars.value) { + sys.error("exportJars must be set to false for the shading to work") + } AssemblyOption() .withIncludeBin((packageBin / assembleArtifact).value) .withIncludeScala((assemblyPackageScala / assembleArtifact).value) @@ -117,7 +122,7 @@ object AssemblyPlugin extends sbt.AutoPlugin { .withAppendContentHash(assemblyAppendContentHash.value) .withPrependShellScript(assemblyPrependShellScript.value) .withMaxHashLength(assemblyMaxHashLength.?.value) - .withShadeRules(assemblyShadeRules.value) + .withShadeRules(sr) .withScalaVersion(scalaVersion.value) .withLevel(logLevel.?.value.getOrElse(Level.Info)) .withRepeatableBuild(assemblyRepeatableBuild.value) diff --git a/src/sbt-test/caching/caching/build.sbt b/src/sbt-test/caching/caching/build.sbt index 96754cba..d3b9c2c1 100644 --- a/src/sbt-test/caching/caching/build.sbt +++ b/src/sbt-test/caching/caching/build.sbt @@ -19,13 +19,13 @@ lazy val root = (project in file(".")). }, TaskKey[Unit]("check") := { val process = sys.process.Process("java", Seq("-jar", (crossTarget.value / "foo.jar").toString)) - val out = (process!!) + val out = process.!! if (out.trim != "hello") sys.error("unexpected output: " + out) () }, TaskKey[Unit]("checkfoo") := { val process = sys.process.Process("java", Seq("-jar", (crossTarget.value / "foo.jar").toString)) - val out = (process!!) + val out = process.!! if (out.trim != "foo.txt") sys.error("unexpected output: " + out) () }, @@ -44,3 +44,11 @@ lazy val root = (project in file(".")). () } ) + +TaskKey[Unit]("fileCheck1") := { + assert((crossTarget.value / "foo.jar").exists()) +} + +TaskKey[Unit]("fileCheck2") := { + assert((crossTarget.value / "jarHash.txt").exists()) +} diff --git a/src/sbt-test/caching/caching/test b/src/sbt-test/caching/caching/test index f84fe08e..e355e273 100644 --- a/src/sbt-test/caching/caching/test +++ b/src/sbt-test/caching/caching/test @@ -1,12 +1,12 @@ # check if the file gets created > clean > assembly -$ exists target/scala-2.12/foo.jar +> fileCheck1 # run to cache the hash, then check it's consistent > check > checkhash -$ exists target/scala-2.12/jarHash.txt +> fileCheck2 > checkhash > assembly @@ -16,7 +16,7 @@ $ exists target/scala-2.12/jarHash.txt # when the unzipped jars are read from cache # on disk > checkhash -$ newer target/scala-2.12/jarHash.txt target/scala-2.12/foo.jar +# $ newer target/scala-2.12/jarHash.txt target/scala-2.12/foo.jar # generate file > genresource diff --git a/src/sbt-test/caching/custommergestrat/build.sbt b/src/sbt-test/caching/custommergestrat/build.sbt index 97acd286..7fcec623 100644 --- a/src/sbt-test/caching/custommergestrat/build.sbt +++ b/src/sbt-test/caching/custommergestrat/build.sbt @@ -23,7 +23,7 @@ lazy val testmerge = (project in file(".")). version := "0.1", assembly / assemblyJarName := "foo.jar", TaskKey[Unit]("check") := { - IO.withTemporaryDirectory { dir ⇒ + IO.withTemporaryDirectory { dir => IO.unzip(crossTarget.value / "foo.jar", dir) mustContain(dir / "sbtassembly", Seq("reversed")) } @@ -40,3 +40,7 @@ def mustContain(f: File, l: Seq[String]): Unit = { TaskKey[Unit]("copy-preserve-last-modified") := { IO.copy(Seq((crossTarget.value / "foo.jar") -> (crossTarget.value / "foo-1.jar")), true, true, true) } + +TaskKey[Unit]("fileCheck1") := { + assert((crossTarget.value / "foo.jar").exists()) +} diff --git a/src/sbt-test/caching/custommergestrat/test b/src/sbt-test/caching/custommergestrat/test index 8d18b295..a18a86b8 100644 --- a/src/sbt-test/caching/custommergestrat/test +++ b/src/sbt-test/caching/custommergestrat/test @@ -1,13 +1,13 @@ > assembly -$ exists target/scala-2.12/foo.jar +> fileCheck1 > check > copyPreserveLastModified # should fail, they should have the same timestamp --$ newer target/scala-2.12/foo-1.jar target/scala-2.12/foo.jar +# -$ newer target/scala-2.12/foo-1.jar target/scala-2.12/foo.jar # assembly should run again, invalidating the cache because of the custom merge strategy > assembly -$ exists target/scala-2.12/foo.jar +> fileCheck1 > check -$ newer target/scala-2.12/foo.jar target/scala-2.12/foo-1.jar +# $ newer target/scala-2.12/foo.jar target/scala-2.12/foo-1.jar diff --git a/src/sbt-test/merging/custommergestrat/build.sbt b/src/sbt-test/merging/custommergestrat/build.sbt index 64fef1ca..8298ff27 100644 --- a/src/sbt-test/merging/custommergestrat/build.sbt +++ b/src/sbt-test/merging/custommergestrat/build.sbt @@ -10,7 +10,7 @@ lazy val testmerge = (project in file(".")). version := "0.1", assembly / assemblyJarName := "foo.jar", TaskKey[Unit]("check") := { - IO.withTemporaryDirectory { dir ⇒ + IO.withTemporaryDirectory { dir => IO.unzip(crossTarget.value / "foo.jar", dir) mustContain(dir / "some-other-target", Seq("I should exist")) mustContain(dir / "sbtassembly" / "file.txt", Seq("test file")) diff --git a/src/sbt-test/merging/merging/build.sbt b/src/sbt-test/merging/merging/build.sbt index 84f3709c..157e9423 100644 --- a/src/sbt-test/merging/merging/build.sbt +++ b/src/sbt-test/merging/merging/build.sbt @@ -1,6 +1,6 @@ -ThisBuild / version := "0.1" -ThisBuild / scalaVersion := "2.12.18" -ThisBuild / assemblyMergeStrategy := { +version := "0.1" +scalaVersion := "2.12.18" +assemblyMergeStrategy := { case "a" => MergeStrategy.concat case "b" => MergeStrategy.first case "c" => MergeStrategy.last @@ -9,15 +9,17 @@ ThisBuild / assemblyMergeStrategy := { case "f" => MergeStrategy.discard case PathList("x", "y") => MergeStrategy.discard case x => - val oldStrategy = (ThisBuild / assemblyMergeStrategy).value + val oldStrategy = assemblyMergeStrategy.value oldStrategy(x) } +name := "foo" +exportJars := true lazy val testmerge = (project in file(".")) .settings( assembly / assemblyJarName := "foo.jar", TaskKey[Unit]("check") := { - IO.withTemporaryDirectory { dir ⇒ + IO.withTemporaryDirectory { dir => IO.unzip(crossTarget.value / "foo.jar", dir) mustContain(dir / "a", Seq("1", "2", "1", "3")) mustContain(dir / "b", Seq("1")) @@ -25,9 +27,9 @@ lazy val testmerge = (project in file(".")) mustContain(dir / "d", Seq("1", "2", "3")) mustContain(dir / "e", Seq("1")) mustNotExist(dir / "f") - mustContain(dir / "README_foo", Seq("resources")) + mustContain(dir / "README_foo-0.1", Seq("resources")) mustContain(dir / "README_1", Seq("1")) - mustContain(dir / "LICENSE_foo", Seq("resources")) + mustContain(dir / "LICENSE_foo-0.1", Seq("resources")) mustContain(dir / "LICENSE" / "a", Seq("1")) // 80f5a06 -- don't rename License.class mustExist(dir / "com" / "example" / "License.class") diff --git a/src/sbt-test/merging/merging/test b/src/sbt-test/merging/merging/test index a74309b0..b7a2eeb6 100644 --- a/src/sbt-test/merging/merging/test +++ b/src/sbt-test/merging/merging/test @@ -1,6 +1,6 @@ # check if the file gets created +> debug > assembly -$ exists target/scala-2.12/foo.jar # check if it says hello > check diff --git a/src/sbt-test/merging/rename/build.sbt b/src/sbt-test/merging/rename/build.sbt index 3b59f33d..99b62b70 100644 --- a/src/sbt-test/merging/rename/build.sbt +++ b/src/sbt-test/merging/rename/build.sbt @@ -14,7 +14,7 @@ lazy val testmerge = (project in file(".")).settings( version := "0.1", assembly / assemblyJarName := "foo.jar", TaskKey[Unit]("check") := { - IO.withTemporaryDirectory { dir ⇒ + IO.withTemporaryDirectory { dir => IO.unzip(crossTarget.value / "foo.jar", dir) mustContain(dir / "b", Seq("a", "b", "c", "d")) mustContain(dir / "a", Seq("e")) diff --git a/src/sbt-test/sbt-assembly/appendhash/build.sbt b/src/sbt-test/sbt-assembly/appendhash/build.sbt index 0ed6605b..290e0aec 100644 --- a/src/sbt-test/sbt-assembly/appendhash/build.sbt +++ b/src/sbt-test/sbt-assembly/appendhash/build.sbt @@ -1,6 +1,6 @@ -ThisBuild / version := "0.1" -ThisBuild / scalaVersion := "2.12.18" -ThisBuild / assemblyAppendContentHash := true +version := "0.1" + scalaVersion := "2.12.18" +assemblyAppendContentHash := true lazy val root = (project in file(".")) .settings( @@ -17,14 +17,13 @@ lazy val root = (project in file(".")) InputKey[Unit]("checkFile") := { val args = sbt.complete.Parsers.spaceDelimited("").parsed val expectFileNameRegex = args.head.r - assert((crossTarget.value ** "*.jar").get.exists{ jar => + assert((crossTarget.value ** "*.jar").get().exists{ jar => expectFileNameRegex.findFirstIn(jar.getName).isDefined }) }, TaskKey[Unit]("checkPrevious") := { import sbinary.DefaultProtocol._ - import sbtassembly.PluginCompat._ import CacheImplicits._ assert(Some(assembly.value) == assembly.previous) } diff --git a/src/sbt-test/sbt-assembly/config/build.sbt b/src/sbt-test/sbt-assembly/config/build.sbt index 856e4b3b..b7e0f090 100644 --- a/src/sbt-test/sbt-assembly/config/build.sbt +++ b/src/sbt-test/sbt-assembly/config/build.sbt @@ -1,5 +1,5 @@ -ThisBuild / version := "0.1" -ThisBuild / scalaVersion := "2.12.18" +version := "0.1" +scalaVersion := "2.12.18" lazy val root = (project in file(".")) .settings(inConfig(Test)(baseAssemblySettings)) @@ -7,8 +7,12 @@ lazy val root = (project in file(".")) Test / assembly / assemblyJarName := "foo.jar", TaskKey[Unit]("check") := { val process = sys.process.Process("java", Seq("-jar", (crossTarget.value / "foo.jar").toString)) - val out = (process!!) + val out = process.!! if (out.trim != "hellospec") sys.error("unexpected output: " + out) () } ) + +TaskKey[Unit]("fileCheck") := { + assert((crossTarget.value / "foo.jar").exists()) +} diff --git a/src/sbt-test/sbt-assembly/config/test b/src/sbt-test/sbt-assembly/config/test index f80f9a3d..4aaab032 100644 --- a/src/sbt-test/sbt-assembly/config/test +++ b/src/sbt-test/sbt-assembly/config/test @@ -1,6 +1,6 @@ # check if the file gets created -> test:assembly -$ exists target/scala-2.12/foo.jar +> Test/assembly +> fileCheck # check if it says hello > check diff --git a/src/sbt-test/sbt-assembly/deps/build.sbt b/src/sbt-test/sbt-assembly/deps/build.sbt index 4ace32ce..bbecb1bb 100644 --- a/src/sbt-test/sbt-assembly/deps/build.sbt +++ b/src/sbt-test/sbt-assembly/deps/build.sbt @@ -1,27 +1,37 @@ -ThisBuild / version := "0.1" -ThisBuild / scalaVersion := "2.12.18" +version := "0.1" +scalaVersion := "2.12.18" lazy val root = (project in file(".")) .settings( libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test", libraryDependencies += "ch.qos.logback" % "logback-classic" % "0.9.29" % "runtime", Compile / unmanagedJars ++= { - (baseDirectory.value / "lib" / "compile" ** "*.jar").classpath + val conv = fileConverter.value + implicit val c: xsbti.FileConverter = conv + (baseDirectory.value / "lib" / "compile" ** "*.jar").classpath }, Runtime / unmanagedJars ++= { - (baseDirectory.value / "lib" / "runtime" ** "*.jar").classpath + val conv = fileConverter.value + implicit val c: xsbti.FileConverter = conv + (baseDirectory.value / "lib" / "runtime" ** "*.jar").classpath }, Test / unmanagedJars ++= { - (baseDirectory.value / "lib" / "test" ** "*.jar").classpath + val conv = fileConverter.value + implicit val c: xsbti.FileConverter = conv + (baseDirectory.value / "lib" / "test" ** "*.jar").classpath }, assemblyExcludedJars := { - (assembly / fullClasspath).value filter {_.data.getName == "compile-0.1.0.jar"} + (assembly / fullClasspath).value.filter { _.data.toString().endsWith("compile-0.1.0.jar") } }, assembly / assemblyJarName := "foo.jar", TaskKey[Unit]("check") := { val process = sys.process.Process("java", Seq("-jar", (crossTarget.value / "foo.jar").toString)) - val out = (process!!) + val out = process.!! if (out.trim != "hello") sys.error("unexpected output: " + out) () } ) + +TaskKey[Unit]("fileCheck") := { + assert((crossTarget.value / "foo.jar").exists()) +} diff --git a/src/sbt-test/sbt-assembly/deps/test b/src/sbt-test/sbt-assembly/deps/test index a74309b0..9f48c65c 100644 --- a/src/sbt-test/sbt-assembly/deps/test +++ b/src/sbt-test/sbt-assembly/deps/test @@ -1,6 +1,6 @@ # check if the file gets created > assembly -$ exists target/scala-2.12/foo.jar +> fileCheck # check if it says hello > check diff --git a/src/sbt-test/sbt-assembly/empty/build.sbt b/src/sbt-test/sbt-assembly/empty/build.sbt index 6dab2e0f..b4733665 100644 --- a/src/sbt-test/sbt-assembly/empty/build.sbt +++ b/src/sbt-test/sbt-assembly/empty/build.sbt @@ -1,2 +1,3 @@ -ThisBuild / version := "0.1" -ThisBuild / scalaVersion := "2.12.18" +version := "0.1" +scalaVersion := "2.12.18" +name := "foo" diff --git a/src/sbt-test/sbt-assembly/main-class/build.sbt b/src/sbt-test/sbt-assembly/main-class/build.sbt index 9e4899e2..cd9a2ad8 100644 --- a/src/sbt-test/sbt-assembly/main-class/build.sbt +++ b/src/sbt-test/sbt-assembly/main-class/build.sbt @@ -7,7 +7,7 @@ lazy val root = (project in file(".")). assembly / assemblyJarName := "foo.jar", TaskKey[Unit]("check") := { val process = sys.process.Process("java", Seq("-jar", (crossTarget.value / "foo.jar").toString)) - val out = (process!!) + val out = process.!! if (out.trim != "hello") sys.error("unexpected output: " + out) () } diff --git a/src/sbt-test/sbt-assembly/piecemeal/build.sbt b/src/sbt-test/sbt-assembly/piecemeal/build.sbt index 2bbdebec..7f0b9b22 100644 --- a/src/sbt-test/sbt-assembly/piecemeal/build.sbt +++ b/src/sbt-test/sbt-assembly/piecemeal/build.sbt @@ -1,8 +1,7 @@ -ThisBuild / version := "0.1" -ThisBuild / scalaVersion := "2.12.18" - -ThisBuild / assemblyPackageScala / assembleArtifact := false -ThisBuild / assemblyPackageDependency / assembleArtifact := false +version := "0.1" +scalaVersion := "2.12.18" +assemblyPackageScala / assembleArtifact := false +assemblyPackageDependency / assembleArtifact := false lazy val root = (project in file(".")) .settings( @@ -18,7 +17,7 @@ lazy val root = (project in file(".")) val process = sys.process.Process("java", Seq("-cp", (crossTarget.value / "foo-assembly-0.1.jar").toString, "Main")) - val out = (process!!) + val out = process.!! if (out.trim != "hello") sys.error("unexpected output: " + out) () }, @@ -28,8 +27,20 @@ lazy val root = (project in file(".")) (if (scala.util.Properties.isWin) ";" else ":") + (crossTarget.value / "foo-assembly-0.1.jar").toString, "Main")) - val out = (process!!) + val out = process.!! if (out.trim != "hello") sys.error("unexpected output: " + out) () } ) + +TaskKey[Unit]("fileCheck1") := { + assert((crossTarget.value / "foo-assembly-0.1.jar").exists()) +} + +TaskKey[Unit]("fileCheck2") := { + assert((crossTarget.value / "foo-assembly-0.1-deps.jar").exists()) +} + +TaskKey[Unit]("fileCheck3") := { + assert((crossTarget.value / "scala-library-2.12.18-assembly.jar").exists()) +} diff --git a/src/sbt-test/sbt-assembly/piecemeal/test b/src/sbt-test/sbt-assembly/piecemeal/test index b40af72a..03501bfa 100644 --- a/src/sbt-test/sbt-assembly/piecemeal/test +++ b/src/sbt-test/sbt-assembly/piecemeal/test @@ -1,17 +1,17 @@ # check if the file gets created > assembly -$ exists target/scala-2.12/foo-assembly-0.1.jar +> fileCheck1 # try running this JAR. this should fail -> check1 # check if the file gets created > assemblyPackageDependency -$ exists target/scala-2.12/foo-assembly-0.1-deps.jar +> fileCheck2 # check if the file gets created > assemblyPackageScala -$ exists target/scala-2.12/scala-library-2.12.18-assembly.jar +> fileCheck3 # check if it says hello > check2 diff --git a/src/sbt-test/sbt-assembly/simple/build.sbt b/src/sbt-test/sbt-assembly/simple/build.sbt index 2b3656d4..96a6e50b 100644 --- a/src/sbt-test/sbt-assembly/simple/build.sbt +++ b/src/sbt-test/sbt-assembly/simple/build.sbt @@ -1,13 +1,14 @@ -ThisBuild / version := "0.1" -ThisBuild / scalaVersion := "2.12.18" +name := "foo" +version := "0.1" +scalaVersion := "2.12.18" +assemblyJarName := "foo.jar" +TaskKey[Unit]("check") := { + val process = sys.process.Process("java", Seq("-jar", (crossTarget.value / "foo.jar").toString)) + val out = process.!! + if (out.trim != "hello") sys.error("unexpected output: " + out) + () +} -lazy val root = (project in file(".")) - .settings( - assemblyJarName := "foo.jar", - TaskKey[Unit]("check") := { - val process = sys.process.Process("java", Seq("-jar", (crossTarget.value / "foo.jar").toString)) - val out = (process!!) - if (out.trim != "hello") sys.error("unexpected output: " + out) - () - } - ) +TaskKey[Unit]("fileCheck") := { + assert((crossTarget.value / "foo.jar").exists()) +} diff --git a/src/sbt-test/sbt-assembly/simple/test b/src/sbt-test/sbt-assembly/simple/test index a74309b0..9f48c65c 100644 --- a/src/sbt-test/sbt-assembly/simple/test +++ b/src/sbt-test/sbt-assembly/simple/test @@ -1,6 +1,6 @@ # check if the file gets created > assembly -$ exists target/scala-2.12/foo.jar +> fileCheck # check if it says hello > check diff --git a/src/sbt-test/shading/directories/build.sbt b/src/sbt-test/shading/directories/build.sbt index 59ba2cde..8857406b 100644 --- a/src/sbt-test/shading/directories/build.sbt +++ b/src/sbt-test/shading/directories/build.sbt @@ -1,22 +1,22 @@ -ThisBuild / scalaVersion := "2.12.18" - -ThisBuild / assemblyShadeRules := Seq( +scalaVersion := "2.12.18" +assemblyShadeRules := Seq( ShadeRule.rename("somepackage.**" -> "shaded.@1").inAll ) +exportJars := false lazy val root = (project in file(".")) .settings( - crossPaths := false, - assembly / assemblyJarName := "assembly.jar", - - TaskKey[Unit]("check") := { - val expected = "Hello shaded.SomeClass" - val output = sys.process.Process("java", Seq("-jar", assembly.value.absString)).!!.trim - if (output != expected) sys.error("Unexpected output: " + output) - }, - TaskKey[Unit]("unzip") := { IO.unzip((assembly / assemblyOutputPath).value, crossTarget.value / "unzipped") } ) + +TaskKey[Unit]("check") := { + val expected = "Hello shaded.SomeClass" + val output = sys.process.Process( + "java", + Seq("-jar", (crossTarget.value / "assembly.jar").toString) + ).!!.trim + if (output != expected) sys.error("Unexpected output: " + output) +} diff --git a/src/sbt-test/shading/directories/test b/src/sbt-test/shading/directories/test index 29413a52..0ada7216 100644 --- a/src/sbt-test/shading/directories/test +++ b/src/sbt-test/shading/directories/test @@ -1,12 +1,7 @@ # Test that assembly contains shaded classes # but the original classes are left untouched. +> assembly > check -$ exists target/classes/somepackage/SomeClass.class -$ absent target/classes/shaded/SomeClass.class - > unzip - -$ exists target/unzipped/shaded/SomeClass.class -$ absent target/unzipped/somepackage/SomeClass.class diff --git a/src/sbt-test/shading/jdk11/build.sbt b/src/sbt-test/shading/jdk11/build.sbt index 8ceeb03c..8734d587 100644 --- a/src/sbt-test/shading/jdk11/build.sbt +++ b/src/sbt-test/shading/jdk11/build.sbt @@ -1,3 +1,4 @@ +exportJars := false scalaVersion := scala212 lazy val scala212 = "2.12.18" diff --git a/src/sbt-test/shading/jdk17/build.sbt b/src/sbt-test/shading/jdk17/build.sbt index c9d696c4..118f0a5c 100644 --- a/src/sbt-test/shading/jdk17/build.sbt +++ b/src/sbt-test/shading/jdk17/build.sbt @@ -1,3 +1,4 @@ +exportJars := false scalaVersion := "2.13.12" assembly / assemblyShadeRules := Seq( diff --git a/src/sbt-test/shading/keeponly/build.sbt b/src/sbt-test/shading/keeponly/build.sbt index 0c92edb1..a64b7143 100644 --- a/src/sbt-test/shading/keeponly/build.sbt +++ b/src/sbt-test/shading/keeponly/build.sbt @@ -1,3 +1,4 @@ +exportJars := false lazy val scala212 = "2.12.18" lazy val scala213 = "2.13.11" @@ -12,11 +13,11 @@ lazy val testkeep = (project in file(".")). ShadeRule.keep("keep.**").inProject ), TaskKey[Unit]("check") := { - IO.withTemporaryDirectory { dir ⇒ + IO.withTemporaryDirectory { dir => IO.unzip(crossTarget.value / "foo.jar", dir) mustNotExist(dir / "removed" / "ShadeClass.class") mustNotExist(dir / "removed" / "ShadePackage.class") - mustExist(dir / "keep" / "Keeped.class") + mustExist(dir / "keep" / "Kept.class") } }) diff --git a/src/sbt-test/shading/keeponly/src/main/scala/keep/Keeped.scala b/src/sbt-test/shading/keeponly/src/main/scala/keep/Kept.scala similarity index 53% rename from src/sbt-test/shading/keeponly/src/main/scala/keep/Keeped.scala rename to src/sbt-test/shading/keeponly/src/main/scala/keep/Kept.scala index 789b5f46..ee7c53ea 100644 --- a/src/sbt-test/shading/keeponly/src/main/scala/keep/Keeped.scala +++ b/src/sbt-test/shading/keeponly/src/main/scala/keep/Kept.scala @@ -1,3 +1,3 @@ package keep -class Keeped \ No newline at end of file +class Kept \ No newline at end of file diff --git a/src/sbt-test/shading/keeponly/test b/src/sbt-test/shading/keeponly/test index 29d5e420..0ecd72a4 100644 --- a/src/sbt-test/shading/keeponly/test +++ b/src/sbt-test/shading/keeponly/test @@ -1,7 +1,5 @@ # check if the file gets created > +assembly -$ exists target/scala-2.12/foo.jar -$ exists target/scala-2.13/foo.jar # check if it says hello > +check diff --git a/src/sbt-test/shading/scalasigannot/build.sbt b/src/sbt-test/shading/scalasigannot/build.sbt index ddb335a7..a6444ba6 100644 --- a/src/sbt-test/shading/scalasigannot/build.sbt +++ b/src/sbt-test/shading/scalasigannot/build.sbt @@ -9,6 +9,7 @@ ThisBuild / crossScalaVersions := List(scala212, scala213) val shadingSettings: Seq[Def.Setting[_]] = Seq( + exportJars := false, assembly / assemblyShadeRules := Seq( ShadeRule.rename( "to.be.shaded.**" -> "shade.@1" @@ -18,7 +19,7 @@ val shadingSettings: Seq[Def.Setting[_]] = Seq( assembly / assemblyExcludedJars := { val cp = (assembly / fullClasspath).value cp.filterNot {p => - p.data.getName.startsWith("tobeshaded") + p.data.toString.contains("tobeshaded") } }, @@ -39,10 +40,10 @@ lazy val fatLib = project.in(file("fatlib")) Seq( name := "fatlib", (Compile / unmanagedJars) := { - val tbs: File = (toBeShaded / Compile / packageBin).value + val tbs = (toBeShaded / Compile / packageBin).value //Seq(sbt.internal.util.Attributed.blank[java.io.File](tbs)) - Seq(Attributed.blank[java.io.File](tbs)) + Seq(Attributed.blank(tbs)) } ) ) @@ -62,8 +63,9 @@ lazy val root = project.in(file(".")) //Seq(sbt.internal.util.Attributed.blank[java.io.File](tbs)) val x = (fatLib / Compile / assembly).value - Seq(Attributed.blank[java.io.File](x)) - } + Seq(Attributed.blank(x)) + }, + fgRun / aggregate := false, ) ) .aggregate(fatLib, toBeShaded) \ No newline at end of file diff --git a/src/sbt-test/shading/scalasigannot/project/plugins.sbt b/src/sbt-test/shading/scalasigannot/project/plugins.sbt index 25c3fb81..b7bb6c0d 100644 --- a/src/sbt-test/shading/scalasigannot/project/plugins.sbt +++ b/src/sbt-test/shading/scalasigannot/project/plugins.sbt @@ -3,5 +3,5 @@ if(pluginVersion == null) throw new RuntimeException("""|The system property 'plugin.version' is not defined. |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) - else addSbtPlugin("com.eed3si9n" % "sbt-assembly" % pluginVersion changing()) + else addSbtPlugin("com.eed3si9n" % "sbt-assembly" % pluginVersion) } diff --git a/src/sbt-test/shading/scalasigannot/test b/src/sbt-test/shading/scalasigannot/test index 06b8f1c0..7999a1f1 100644 --- a/src/sbt-test/shading/scalasigannot/test +++ b/src/sbt-test/shading/scalasigannot/test @@ -1,3 +1,3 @@ # Run the main project -> +root/run +> +root/fgRun diff --git a/src/sbt-test/shading/shading/build.sbt b/src/sbt-test/shading/shading/build.sbt index 141efc97..e9a54fb3 100644 --- a/src/sbt-test/shading/shading/build.sbt +++ b/src/sbt-test/shading/shading/build.sbt @@ -1,3 +1,5 @@ +exportJars := false + lazy val testshade = (project in file(".")). settings( version := "0.1", @@ -12,7 +14,7 @@ lazy val testshade = (project in file(".")). ), // logLevel in assembly := Level.Debug, TaskKey[Unit]("check") := { - IO.withTemporaryDirectory { dir ⇒ + IO.withTemporaryDirectory { dir => IO.unzip(crossTarget.value / "foo.jar", dir) mustNotExist(dir / "remove" / "Removed.class") mustNotExist(dir / "org" / "apache" / "commons" / "io" / "ByteOrderMark.class") @@ -21,7 +23,7 @@ lazy val testshade = (project in file(".")). mustExist(dir / "shadeio" / "ByteOrderMark.class") } val process = sys.process.Process("java", Seq("-jar", (crossTarget.value / "foo.jar").toString)) - val out = (process!!) + val out = process.!! if (out.trim != "hello shadeio.filefilter.AgeFileFilter") sys.error("unexpected output: " + out) () }) diff --git a/src/sbt-test/shading/shading/test b/src/sbt-test/shading/shading/test index a74309b0..8f0400c8 100644 --- a/src/sbt-test/shading/shading/test +++ b/src/sbt-test/shading/shading/test @@ -1,6 +1,5 @@ # check if the file gets created > assembly -$ exists target/scala-2.12/foo.jar # check if it says hello > check diff --git a/src/sbt-test/shading/unmanagedjars/build.sbt b/src/sbt-test/shading/unmanagedjars/build.sbt index 58039de0..5b5f237a 100644 --- a/src/sbt-test/shading/unmanagedjars/build.sbt +++ b/src/sbt-test/shading/unmanagedjars/build.sbt @@ -1,3 +1,5 @@ +exportJars := false + lazy val testshade = (project in file(".")). settings( version := "0.1", @@ -13,7 +15,7 @@ lazy val testshade = (project in file(".")). ), // logLevel in assembly := Level.Debug, TaskKey[Unit]("check") := { - IO.withTemporaryDirectory { dir ⇒ + IO.withTemporaryDirectory { dir => IO.unzip(crossTarget.value / "foo.jar", dir) mustNotExist(dir / "remove" / "Removed.class") mustNotExist(dir / "org" / "apache" / "commons" / "io" / "ByteOrderMark.class") @@ -24,7 +26,7 @@ lazy val testshade = (project in file(".")). mustExist(dir / "shadeio" / "ByteOrderMark.class") } val process = sys.process.Process("java", Seq("-jar", (crossTarget.value / "foo.jar").toString)) - val out = (process!!) + val out = process.!! if (out.trim != "hello shadeio.filefilter.AgeFileFilter") sys.error("unexpected output: " + out) () }) diff --git a/src/sbt-test/shading/unmanagedjars/test b/src/sbt-test/shading/unmanagedjars/test index a74309b0..8f0400c8 100644 --- a/src/sbt-test/shading/unmanagedjars/test +++ b/src/sbt-test/shading/unmanagedjars/test @@ -1,6 +1,5 @@ # check if the file gets created > assembly -$ exists target/scala-2.12/foo.jar # check if it says hello > check