Ignore:
Timestamp:
May 5, 2018 11:34:35 PM (3 years ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
0a1191a
Parents:
f6273a1
Message:

Mac OS X Launcher - reborn - ALPHA!

TLDR;
Howto? ant osxLauncher
Privacy Notes? If you don't got SBT, a bash script will trigger

download of SBT for you with task osxLauncher.

Results? open ./launchers/output
"Binary" App Bundle name: I2P.app
Runtime base directory? ~/Library/I2P
Runtime config directory? untouched.

After talk on IRC with zzz, I rewrote the logic since we could
start with a simple deploy, for a faster alpha version ready :)

SBT will build a zip file from the content of pkg-temp, which
CompleteDeployment?.scala will again unzip in runtime. Right now
it's quite basic, but the plan is to add version detection, so
it's capable of upgrading a already deployed I2P base directory.

OSXDeployment.scala is renamed to PartialDeployment?.scala for usage
in the browser bundle launcher, since it's going to be a subset of
the files found in pkg-temp.

A Info.plist is added to the launchers/macosx which is added to the
application bundle under building. Note that this differ from the one
in Start i2p router.app that's been here for years now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • launchers/macosx/build.sbt

    rf6273a1 r5f81a8de  
    1 import sbtassembly.AssemblyPlugin.defaultShellScript
    2 import sbt._
    3 import Keys._
    4 import sbt.io.IO
    5 import java.io.File
     1import java.io.{File, FileNotFoundException, FileOutputStream}
     2import java.util.zip._
    63
    74lazy val i2pVersion = "0.9.34"
     
    96lazy val cleanAllTask = taskKey[Unit]("Clean up and remove the OSX bundle")
    107lazy val buildAppBundleTask = taskKey[Unit](s"Build an Mac OS X bundle for I2P ${i2pVersion}.")
    11 lazy val bundleBuildPath = file("./output")
     8lazy val buildDeployZipTask = taskKey[String](s"Build an zipfile with base directory for I2P ${i2pVersion}.")
     9lazy val bundleBuildPath = new File("./output")
    1210
    1311lazy val staticFiles = List(
     
    3331    "#!/usr/bin/env sh",
    3432    s"""
    35        |echo "Yo"
     33       |echo "I2P - Mac OS X Launcher starting up"
    3634       |export I2P=$$HOME/Library/I2P
    3735       |for jar in `ls $${I2P}/lib/*.jar`; do
     
    6765      "-Dwrapper.java.pidfile=/tmp/routerjvm.pid",
    6866      "-Dwrapper.console.loglevel=DEBUG",
    69       "-Djava.awt.headless=true",
    7067      "-Di2p.dir.base=$I2P",
    7168      "-Djava.library.path=$I2P"
     
    9390}
    9491
     92buildDeployZipTask := {
     93  println(s"Starting the zip file build process. This might take a while..")
     94  if (!bundleBuildPath.exists()) bundleBuildPath.mkdir()
     95  val sourceDir = i2pBuildDir
     96  def recursiveListFiles(f: File): Array[File] = {
     97    val these = f.listFiles
     98    these ++ these.filter { f => f.isDirectory }.flatMap(recursiveListFiles).filter(!_.isDirectory)
     99  }
     100  def zip(out: String, files: Iterable[String]) = {
     101    import java.io.{ BufferedInputStream, FileInputStream, FileOutputStream }
     102    import java.util.zip.{ ZipEntry, ZipOutputStream }
     103
     104    val zip = new ZipOutputStream(new FileOutputStream(out))
     105
     106    files.foreach { name =>
     107      val fname = sourceDir.toURI.relativize(new File(name).toURI).toString
     108      //println(s"Zipping ${fname}")
     109      if (!new File(name).isDirectory) {
     110        zip.putNextEntry(new ZipEntry(fname))
     111        val in = new BufferedInputStream(new FileInputStream(name))
     112        var b = in.read()
     113        while (b > -1) {
     114          zip.write(b)
     115          b = in.read()
     116        }
     117        in.close()
     118        zip.closeEntry()
     119      }
     120    }
     121    zip.close()
     122  }
     123  val fileList = recursiveListFiles(sourceDir.getCanonicalFile).toList
     124  val zipFileName = new File(bundleBuildPath, "i2pbase.zip").getCanonicalPath
     125  zip(zipFileName, fileList.map { f => f.toString }.toIterable)
     126  zipFileName.toString
     127}
     128
    95129buildAppBundleTask := {
    96130  println(s"Building Mac OS X bundle for I2P version ${i2pVersion}.")
    97   bundleBuildPath.mkdir()
     131  if (!bundleBuildPath.exists()) bundleBuildPath.mkdir()
    98132  val paths = Map[String,File](
    99133    "execBundlePath" -> new File(bundleBuildPath, "I2P.app/Contents/MacOS"),
    100     "resBundlePath" -> new File(bundleBuildPath, "I2P.app/Contents/Resources"),
    101     "i2pbaseBunldePath" -> new File(bundleBuildPath, "I2P.app/Contents/Resources/i2pbase"),
    102     "i2pJarsBunldePath" -> new File(bundleBuildPath, "I2P.app/Contents/Resources/i2pbase/lib"),
    103     "webappsBunldePath" -> new File(bundleBuildPath, "I2P.app/Contents/Resources/i2pbase/webapps")
     134    "resBundlePath" -> new File(bundleBuildPath, "I2P.app/Contents/Resources")
    104135  )
    105136  paths.map { case (s,p) => p.mkdirs() }
    106   val dirsToCopy = List("certificates","locale","man")
    107137
    108138  val launcherBinary = Some(assembly.value)
     
    110140
    111141
    112   /**
    113     *
    114     * First of, if "map" is unknown for you - shame on you :p
    115     *
    116     * It's a loop basically where it loops through a list/array
    117     * with the current indexed item as subject.
    118     *
    119     * The code bellow takes the different lists and
    120     * copy all the directories or files from the i2p.i2p build dir,
    121     * and into the bundle so the launcher will know where to find i2p.
    122     *
    123     */
    124   dirsToCopy.map  { d => IO.copyDirectory( new File(resDir, d), new File(paths.get("i2pbaseBunldePath").get, d) ) }
    125   warsForCopy.map { w => IO.copyFile( new File(new File(i2pBuildDir, "webapps"), w), new File(paths.get("webappsBunldePath").get, w) ) }
    126   jarsForCopy.map { j => IO.copyFile( new File(new File(i2pBuildDir, "lib"), j), new File(paths.get("i2pJarsBunldePath").get, j) ) }
     142  val plistFile = new File("./macosx/Info.plist")
     143  if (plistFile.exists()) {
     144    println(s"Adding Info.plist...")
     145    IO.copyFile(plistFile, new File(bundleBuildPath, "I2P.app/Contents/Info.plist"))
     146  }
     147
     148  val zipFilePath = Some(buildDeployZipTask.value)
     149
     150  val zipFileOrigin = new File(zipFilePath.get)
     151  IO.copyFile(zipFileOrigin, new File(paths.get("resBundlePath").get, "i2pbase.zip"))
     152  println(s"Zip placed into bundle :)")
     153
    127154}
Note: See TracChangeset for help on using the changeset viewer.