@@ -12,9 +12,6 @@ import com.typesafe.sbt.packager.linux.LinuxPlugin.autoImport.{
1212 packageArchitecture
1313}
1414import scala .collection .JavaConversions ._
15- import org .vafer .jdeb .{DataProducer , DebMaker }
16- import org .vafer .jdeb .mapping ._
17- import org .vafer .jdeb .producers ._
1815import DebianPlugin .Names
1916import DebianPlugin .autoImport ._
2017
@@ -34,7 +31,7 @@ import DebianPlugin.autoImport._
3431 */
3532object JDebPackaging extends AutoPlugin with DebianPluginLike {
3633
37- override def requires = DebianPlugin
34+ override def requires : Plugins = DebianPlugin
3835
3936 override lazy val projectSettings : Seq [Setting [_]] = inConfig(Debian )(jdebSettings)
4037
@@ -79,23 +76,10 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike {
7976 }
8077
8178 log.info(" Building debian package with java based implementation 'jdeb'" )
82- val console = new JDebConsole (log)
8379 val archive = archiveFilename(normalizedName.value, version.value, packageArchitecture.value)
8480 val debianFile = targetDir.getParentFile / archive
85- val debMaker = new DebMaker (
86- console,
87- fileAndDirectoryProducers(mappings, targetDir) ++ linkProducers(symlinks),
88- conffileProducers(mappings, targetDir)
89- )
90- // set compression default to none - in line with native version / allows rsync to be effective
91- debMaker setCompression " none"
92- debMaker setDepends " "
93- debMaker setDeb debianFile
94- debMaker setControl (targetDir / Names .DebianMaintainerScripts )
95-
96- // TODO add signing with setKeyring, setKey, setPassphrase, setSignPackage, setSignMethod, setSignRole
97- debMaker validate ()
98- debMaker makeDeb ()
81+ val debMaker = new JDebPackagingTask ()
82+ debMaker.packageDebian(mappings, symlinks, debianFile, targetDir, log)
9983 debianFile
10084 },
10185 packageBin := (packageBin dependsOn debianControlFile).value,
@@ -108,7 +92,7 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike {
10892 * The same as [[DebianPluginLike.copyAndFixPerms ]] except chmod invocation (for windows compatibility).
10993 * Permissions will be handled by jDeb packager itself.
11094 */
111- private [ this ] def copyFiles (from : File , to : File , perms : LinuxFileMetaData , zipped : Boolean = false ): Unit =
95+ private def copyFiles (from : File , to : File , perms : LinuxFileMetaData , zipped : Boolean = false ): Unit =
11296 if (zipped) {
11397 IO .withTemporaryDirectory { dir =>
11498 val tmp = dir / from.getName
@@ -122,24 +106,71 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike {
122106 * The same as [[DebianPluginLike.filterAndFixPerms ]] except chmod invocation (for windows compatibility).
123107 * Permissions will be handled by jDeb packager itself.
124108 */
125- private [this ] final def filterFiles (script : File ,
126- replacements : Seq [(String , String )],
127- perms : LinuxFileMetaData ): File = {
109+ private final def filterFiles (script : File , replacements : Seq [(String , String )], perms : LinuxFileMetaData ): File = {
128110 val filtered =
129111 TemplateWriter .generateScript(script.toURI.toURL, replacements)
130112 IO .delete(script)
131113 IO .write(script, filtered)
132114 script
133115 }
134116
117+ }
118+
119+ /**
120+ * This provides the task for building a debian packaging with
121+ * the java-based implementation jdeb
122+ */
123+ class JDebConsole (log : Logger ) extends org.vafer.jdeb.Console {
124+
125+ def debug (message : String ): Unit = log debug message
126+
127+ def info (message : String ): Unit = log info message
128+
129+ def warn (message : String ): Unit = log warn message
130+ }
131+
132+ /**
133+ * == JDeb Packaging Task ==
134+ *
135+ * This private class contains all the jdeb-plugin specific implementations. It's only invoked when the jdeb plugin is
136+ * enabled and the `debian:packageBin` task is called. This means that all classes in `org.vafer.jdeb._` are only loaded
137+ * when required and allows us to put the dependency in the "provided" scope. The provided scope means that we have less
138+ * dependency issues in an sbt build.
139+ */
140+ private class JDebPackagingTask {
141+ import org .vafer .jdeb .{DataProducer , DebMaker }
142+ import org .vafer .jdeb .mapping ._
143+ import org .vafer .jdeb .producers ._
144+
145+ def packageDebian (mappings : Seq [LinuxPackageMapping ],
146+ symlinks : Seq [LinuxSymlink ],
147+ debianFile : File ,
148+ targetDir : File ,
149+ log : Logger ): Unit = {
150+ val debMaker = new DebMaker (
151+ new JDebConsole (log),
152+ fileAndDirectoryProducers(mappings, targetDir) ++ linkProducers(symlinks),
153+ conffileProducers(mappings, targetDir)
154+ )
155+ // set compression default to none - in line with native version / allows rsync to be effective
156+ debMaker setCompression " none"
157+ debMaker setDepends " "
158+ debMaker setDeb debianFile
159+ debMaker setControl (targetDir / Names .DebianMaintainerScripts )
160+
161+ // TODO add signing with setKeyring, setKey, setPassphrase, setSignPackage, setSignMethod, setSignRole
162+ debMaker validate ()
163+ debMaker makeDeb ()
164+ }
165+
135166 /**
136167 * Creating file and directory producers. These "produce" the
137168 * files for the debian packaging.
138169 *
139170 * May create duplicates together with the conffileProducers.
140171 * This will be an performance improvement (reducing IO)
141172 */
142- private [debian] def fileAndDirectoryProducers (mappings : Seq [LinuxPackageMapping ], target : File ): Seq [DataProducer ] =
173+ private def fileAndDirectoryProducers (mappings : Seq [LinuxPackageMapping ], target : File ): Seq [DataProducer ] =
143174 mappings.flatMap {
144175 case LinuxPackageMapping (paths, perms, zipped) =>
145176 paths.map {
@@ -168,7 +199,7 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike {
168199 */
169200 private [debian] def conffileProducers (linuxMappings : Seq [LinuxPackageMapping ], target : File ): Seq [DataProducer ] = {
170201
171- val producers = linuxMappings map {
202+ val producers = linuxMappings. map {
172203 case LinuxPackageMapping (concretMappings, perms, _) if perms.config == " true" =>
173204 concretMappings collect {
174205 case (path, name) if path.isFile =>
@@ -186,18 +217,4 @@ object JDebPackaging extends AutoPlugin with DebianPluginLike {
186217
187218 private [this ] def filePermissions (perms : LinuxFileMetaData ): PermMapper =
188219 new PermMapper (- 1 , - 1 , perms.user, perms.group, perms.permissions, null , - 1 , null )
189-
190- }
191-
192- /**
193- * This provides the task for building a debian packaging with
194- * the java-based implementation jdeb
195- */
196- class JDebConsole (log : Logger ) extends org.vafer.jdeb.Console {
197-
198- def debug (message : String ): Unit = log debug message
199-
200- def info (message : String ): Unit = log info message
201-
202- def warn (message : String ): Unit = log warn message
203220}
0 commit comments