diff --git a/mill-universal-packager/src/io/github/hoangmaihuy/mill/packager/archetypes/JavaAppPackagingModule.scala b/mill-universal-packager/src/io/github/hoangmaihuy/mill/packager/archetypes/JavaAppPackagingModule.scala index cb2dbc5..9049a7e 100644 --- a/mill-universal-packager/src/io/github/hoangmaihuy/mill/packager/archetypes/JavaAppPackagingModule.scala +++ b/mill-universal-packager/src/io/github/hoangmaihuy/mill/packager/archetypes/JavaAppPackagingModule.scala @@ -10,20 +10,20 @@ trait JavaAppPackagingModule extends UniversalPackagerModule with BashStartScrip def bundledJvmLocation: T[Option[String]] = T { Option.empty[String] } - private def moduleDepMappings: T[Seq[(os.Path, os.SubPath)]] = T.traverse(transitiveModuleDeps.distinct) { module => + private def moduleDepMappings: T[Seq[(PathRef, os.SubPath)]] = T.traverse(transitiveModuleDeps.distinct) { module => T.task { - module.jar().path -> os.sub / "lib" / (module.artifactName() + ".jar") + module.jar() -> os.sub / "lib" / (module.artifactName() + ".jar") } } - private def ivyDepMappings: T[Seq[(os.Path, os.SubPath)]] = T { + private def ivyDepMappings: T[Seq[(PathRef, os.SubPath)]] = T { resolvedRunIvyDeps().toSeq.map { ivyDep => - ivyDep.path -> (os.sub / "lib" / ivyDep.path.last) + ivyDep -> (os.sub / "lib" / ivyDep.path.last) } } /** The order of the classpath used at runtime for the bat/bash scripts. */ - def classpathMappings: T[Seq[(os.Path, os.SubPath)]] = T { + def classpathMappings: T[Seq[(PathRef, os.SubPath)]] = T { ivyDepMappings() ++ moduleDepMappings() } diff --git a/mill-universal-packager/src/io/github/hoangmaihuy/mill/packager/archetypes/scripts/BashStartScriptModule.scala b/mill-universal-packager/src/io/github/hoangmaihuy/mill/packager/archetypes/scripts/BashStartScriptModule.scala index b980fc8..3bcfcab 100644 --- a/mill-universal-packager/src/io/github/hoangmaihuy/mill/packager/archetypes/scripts/BashStartScriptModule.scala +++ b/mill-universal-packager/src/io/github/hoangmaihuy/mill/packager/archetypes/scripts/BashStartScriptModule.scala @@ -59,7 +59,7 @@ trait BashStartScriptModule extends Module with CommonStartScriptGenerator { sel def bashScriptEnvConfigLocation: T[Option[String]] = T { Option.empty[String] } - def bashScriptMappings: T[Seq[(os.Path, os.SubPath)]] = T { + def bashScriptMappings: T[Seq[(PathRef, os.SubPath)]] = T { val discoveredMainClasses = zincWorker().worker().discoverMainClasses(compile()) generateStartScripts( BashScriptConfig( diff --git a/mill-universal-packager/src/io/github/hoangmaihuy/mill/packager/archetypes/scripts/CommonStartScriptGenerator.scala b/mill-universal-packager/src/io/github/hoangmaihuy/mill/packager/archetypes/scripts/CommonStartScriptGenerator.scala index 5539367..26a8e9a 100644 --- a/mill-universal-packager/src/io/github/hoangmaihuy/mill/packager/archetypes/scripts/CommonStartScriptGenerator.scala +++ b/mill-universal-packager/src/io/github/hoangmaihuy/mill/packager/archetypes/scripts/CommonStartScriptGenerator.scala @@ -3,8 +3,7 @@ package io.github.hoangmaihuy.mill.packager.archetypes.scripts import java.io.File import java.net.URL -import mill.api.Logger - +import mill.api._ import io.github.hoangmaihuy.mill.packager.archetypes.TemplateWriter trait CommonStartScriptGenerator { @@ -61,7 +60,7 @@ trait CommonStartScriptGenerator { discoveredMainClasses: Seq[String], targetDir: os.Path, log: Logger - ): Seq[(os.Path, os.SubPath)] = + ): Seq[(PathRef, os.SubPath)] = StartScriptMainClassConfig.from(mainClass, discoveredMainClasses) match { case NoMain => log.error("You have no main class in your project. No start script will be generated.") @@ -103,7 +102,7 @@ trait CommonStartScriptGenerator { config: SpecializedScriptConfig, targetDir: os.Path, log: Logger - ): Seq[(os.Path, os.SubPath)] = { + ): Seq[(PathRef, os.SubPath)] = { val classAndScriptNames = ScriptUtils.createScriptNames(discoveredMainClasses) ScriptUtils.warnOnScriptNameCollision(classAndScriptNames, log) @@ -143,7 +142,7 @@ trait CommonStartScriptGenerator { config: SpecializedScriptConfig, targetDir: os.Path, mainClasses: Seq[String] - ): (os.Path, os.SubPath) = { + ): (PathRef, os.SubPath) = { val template = resolveTemplate(config.templateLocation) val replacements = createReplacementsForMainScript( mainClass, @@ -162,7 +161,7 @@ trait CommonStartScriptGenerator { os.write.over(script, scriptContent, createFolders = true) // TODO - Better control over this! script.toIO.setExecutable(executableBitValue) - script -> os.sub / scriptTargetFolder / scriptNameWithSuffix + PathRef(script) -> os.sub / scriptTargetFolder / scriptNameWithSuffix } private[this] def resolveTemplate(defaultTemplateLocation: File): URL = { @@ -175,7 +174,7 @@ trait CommonStartScriptGenerator { targetDir: os.Path, config: ScriptConfig, log: Logger - ): Seq[(os.Path, os.SubPath)] = { + ): Seq[(PathRef, os.SubPath)] = { val tmp = targetDir / scriptTargetFolder val forwarderTemplate = getClass.getResource(s"/packager/scripts/$forwarderTemplateName") val classAndScriptNames = ScriptUtils.createScriptNames(discoveredMainClasses) @@ -194,7 +193,7 @@ trait CommonStartScriptGenerator { os.write.over(file, scriptContent, createFolders = true) file.toIO.setExecutable(executableBitValue) - file -> os.sub / scriptTargetFolder / scriptName + PathRef(file) -> os.sub / scriptTargetFolder / scriptName } } diff --git a/mill-universal-packager/src/io/github/hoangmaihuy/mill/packager/universal/UniversalPackagerModule.scala b/mill-universal-packager/src/io/github/hoangmaihuy/mill/packager/universal/UniversalPackagerModule.scala index 24c23fe..524002f 100644 --- a/mill-universal-packager/src/io/github/hoangmaihuy/mill/packager/universal/UniversalPackagerModule.scala +++ b/mill-universal-packager/src/io/github/hoangmaihuy/mill/packager/universal/UniversalPackagerModule.scala @@ -29,26 +29,21 @@ trait UniversalPackagerModule extends PackagerModule { def universalSources: T[PathRef] = T.source(millSourcePath / "universal") - def universalMappings: T[Seq[(os.Path, os.SubPath)]] = T { + def universalMappings: T[Seq[(PathRef, os.SubPath)]] = T { val sourceDirectory = universalSources().path if (os.exists(sourceDirectory)) { os .walk(sourceDirectory) .map { source => - source -> source.subRelativeTo(sourceDirectory) + PathRef(source) -> source.subRelativeTo(sourceDirectory) } } else { Seq.empty } } - private def universalMappingSources = T.sources( - universalMappings().map(mapping => PathRef(mapping._1)) - ) - // mappings with or without the configured topLevelDirectory - private def universalPackageMappings: T[Seq[(os.Path, os.SubPath)]] = T { - universalMappingSources() + private def universalPackageMappings: T[Seq[(PathRef, os.SubPath)]] = T { val mappings = universalMappings() topLevelDirectory().map { dir => mappings.map { case (f, p) => f -> (os.sub / dir / p) } @@ -84,7 +79,7 @@ trait UniversalPackagerModule extends PackagerModule { os.remove.all(T.dest) universalMappings().foreach { case (f, p) => os.copy( - from = f, + from = f.path, to = Path(p, T.dest), createFolders = true, followLinks = true, @@ -164,7 +159,7 @@ trait UniversalPackagerModule extends PackagerModule { */ def universalPackageZip: T[PathRef] = T { val zip = T.dest / (packageName() + ".zip") - ZipHelper.zip(universalPackageMappings(), zip) + ZipHelper.zip(universalPackageMappings().map(m => m._1.path -> m._2), zip) T.log.info(s"Generated package: $zip") PathRef(zip) } @@ -173,7 +168,7 @@ trait UniversalPackagerModule extends PackagerModule { */ def universalPackageTarZstd: T[PathRef] = T { val out: Path = T.dest / (packageName() + universalTarZstdExt()) - Archiver().mkTarball(universalMappings(), out, universalTopLevelPath())( + Archiver().mkTarball(universalPackageMappings().map(m => m._1.path -> m._2), out, universalTopLevelPath())( new ZstdCompressorOutputStream(_, universalZstdCompressLevel()) ) T.log.info(s"Generated package: $out") @@ -186,7 +181,7 @@ trait UniversalPackagerModule extends PackagerModule { val out: Path = T.dest / (packageName() + universalTarGZExt()) val parameter = new GzipParameters() parameter.setCompressionLevel(universalGzipCompressLevel()) - Archiver().mkTarball(universalMappings(), out, universalTopLevelPath())(new GzipCompressorOutputStream(_, parameter)) + Archiver().mkTarball(universalPackageMappings().map(m => m._1.path -> m._2), out, universalTopLevelPath())(new GzipCompressorOutputStream(_, parameter)) T.log.info(s"Generated package: $out") PathRef(out) } @@ -195,7 +190,7 @@ trait UniversalPackagerModule extends PackagerModule { */ def universalPackageTarBzip2: T[PathRef] = T { val out: Path = T.dest / (packageName() + universalTarBzip2Ext()) - Archiver().mkTarball(universalMappings(), out, universalTopLevelPath())(new BZip2CompressorOutputStream(_)) + Archiver().mkTarball(universalPackageMappings().map(m => m._1.path -> m._2), out, universalTopLevelPath())(new BZip2CompressorOutputStream(_)) PathRef(out) } @@ -203,7 +198,7 @@ trait UniversalPackagerModule extends PackagerModule { */ def universalPackageTarXz: T[PathRef] = T { val out: Path = T.dest / (packageName() + universalTarXZExt()) - Archiver().mkTarball(universalMappings(), out, universalTopLevelPath())(new XZCompressorOutputStream(_)) + Archiver().mkTarball(universalPackageMappings().map(m => m._1.path -> m._2), out, universalTopLevelPath())(new XZCompressorOutputStream(_)) T.log.info(s"Generated package: $out") PathRef(out) }