source: launchers/macosx/build.sbt @ 21b3864

Last change on this file since 21b3864 was 21b3864, checked in by meeh <meeh@…>, 23 months ago

Moved some logic to C++, which will extract i2p if it's not already,
and then secondly fire up the router in a second java process when
extraction is completed. Gonna use "optional" type in C++ to make
global variables a bit less painful to use.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1import java.io.{File, FileNotFoundException, FileOutputStream}
2import java.util.zip._
3
4lazy val i2pVersion = "0.9.35"
5
6lazy val cleanAllTask = taskKey[Unit]("Clean up and remove the OSX bundle")
7lazy val buildAppBundleTask = taskKey[Unit](s"Build an Mac OS X bundle for I2P ${i2pVersion}.")
8lazy val buildDeployZipTask = taskKey[String](s"Build an zipfile with base directory for I2P ${i2pVersion}.")
9lazy val bundleBuildPath = new File("./output")
10
11
12lazy val resDir = new File("./../installer/resources")
13lazy val i2pBuildDir = new File("./../pkg-temp")
14lazy val warsForCopy = new File(i2pBuildDir, "webapps").list.filter { f => f.endsWith(".war") }
15lazy val jarsForCopy = new File(i2pBuildDir, "lib").list.filter { f => f.endsWith(".jar") }
16
17
18// Pointing the resources directory to the "installer" directory
19resourceDirectory in Compile := baseDirectory.value / ".." / ".." / "installer" / "resources"
20
21// Unmanaged base will be included in a fat jar
22unmanagedBase in Compile := baseDirectory.value / ".." / ".." / "pkg-temp" / "lib"
23
24// Unmanaged classpath will be available at compile time
25unmanagedClasspath in Compile ++= Seq(
26  baseDirectory.value / ".." / ".." / "pkg-temp" / "lib" / "*.jar"
27)
28
29assemblyOption in assembly := (assemblyOption in assembly).value.copy(includeScala = false, includeDependency = false)
30
31
32assemblyJarName in assembly := s"launcher.jar"
33
34assemblyExcludedJars in assembly := {
35  val cp = (fullClasspath in assembly).value
36  cp filter { c => jarsForCopy.toList.contains(c.data.getName) }
37}
38
39// TODO: MEEH: Add assemblyExcludedJars and load the router from own jar files, to handle upgrades better.
40// In fact, most likely the bundle never would need an update except for the router jars/wars.
41
42convertToICNSTask := {
43  println("TODO")
44}
45
46cleanAllTask := {
47  clean.value
48  IO.delete(bundleBuildPath)
49}
50
51buildDeployZipTask := {
52  println(s"Starting the zip file build process. This might take a while..")
53  if (!bundleBuildPath.exists()) bundleBuildPath.mkdir()
54  val sourceDir = i2pBuildDir
55  def recursiveListFiles(f: File): Array[File] = {
56    val these = f.listFiles
57    these ++ these.filter { f => f.isDirectory }.flatMap(recursiveListFiles).filter(!_.isDirectory)
58  }
59  def zip(out: String, files: Iterable[String]) = {
60    import java.io.{ BufferedInputStream, FileInputStream, FileOutputStream }
61    import java.util.zip.{ ZipEntry, ZipOutputStream }
62
63    val zip = new ZipOutputStream(new FileOutputStream(out))
64
65    files.foreach { name =>
66      val fname = sourceDir.toURI.relativize(new File(name).toURI).toString
67      //println(s"Zipping ${fname}")
68      if (!new File(name).isDirectory) {
69        zip.putNextEntry(new ZipEntry(fname))
70        val in = new BufferedInputStream(new FileInputStream(name))
71        var b = in.read()
72        while (b > -1) {
73          zip.write(b)
74          b = in.read()
75        }
76        in.close()
77        zip.closeEntry()
78      }
79    }
80    zip.close()
81  }
82  val fileList = recursiveListFiles(sourceDir.getCanonicalFile).toList
83  val zipFileName = new File(bundleBuildPath, "i2pbase.zip").getCanonicalPath
84  zip(zipFileName, fileList.map { f => f.toString }.toIterable)
85  zipFileName.toString
86}
87
88buildAppBundleTask := {
89  println(s"Building Mac OS X bundle for I2P version ${i2pVersion}.")
90  if (!bundleBuildPath.exists()) bundleBuildPath.mkdir()
91  val paths = Map[String,File](
92    "execBundlePath" -> new File(bundleBuildPath, "I2P.app/Contents/MacOS"),
93    "resBundlePath" -> new File(bundleBuildPath, "I2P.app/Contents/Resources")
94  )
95  paths.map { case (s,p) => p.mkdirs() }
96
97  val launcherBinary = Some(assembly.value)
98  launcherBinary.map { l => IO.copyFile( new File(l.toString), new File(paths.get("execBundlePath").get, "I2P") ) }
99
100  val zipFilePath = Some(buildDeployZipTask.value)
101
102  val zipFileOrigin = new File(zipFilePath.get)
103  IO.copyFile(zipFileOrigin, new File(paths.get("resBundlePath").get, "i2pbase.zip"))
104  println(s"Zip placed into bundle :)")
105
106}
Note: See TracBrowser for help on using the repository browser.