From 8adf55a5683c89f831b4aed7c74870a213edccd1 Mon Sep 17 00:00:00 2001 From: meeh Date: Tue, 24 Apr 2018 04:18:21 +0000 Subject: [PATCH] Still WIP, but I've added a new sbt plugin named sbt-native-packager for future rpm/deb/windows and maybe even OSX packages. Also, the macosx sbt project now has a task named buildAppBundleTask and which will produce an I2P.app and copy over needed directories/jars/wars which later needs to be extracted to an writeable area which would be i2p base directory in runtime. The MacOSXRouterLauncherApp contains more information about how the executable in the OS X bundle will locate our R/O i2pbase so it can copy it to a writable area. The R/O is also to ensure valid signature on the bundle. At last, this approach is done casue letting an Mach-O binary load libjvm.dylib was proved unstable, so MacOSXRouterLauncherApp will rather use an JNI module to load the needed glue with the Mac OS X system. --- launchers/build.sbt | 13 +++++--- launchers/macosx/build.sbt | 32 +++++++++++++++++++ .../net/i2p/MacOSXRouterLauncherApp.scala | 11 +++++++ launchers/project/build.properties | 2 +- launchers/project/plugins.sbt | 2 +- 5 files changed, 53 insertions(+), 7 deletions(-) diff --git a/launchers/build.sbt b/launchers/build.sbt index c696c5680..ee01191c2 100644 --- a/launchers/build.sbt +++ b/launchers/build.sbt @@ -1,4 +1,6 @@ -import sbt.Keys._ +import sbt._ +import Keys._ + resolvers ++= Seq( DefaultMavenRepository, @@ -11,7 +13,10 @@ resolvers ++= Seq( lazy val commonSettings = Seq( organization := "net.i2p", scalaVersion := "2.11.11", // We have to use Scala 11 as long as we're going to support JRE 1.7 - version := "0.1.0-SNAPSHOT" + version := "0.1.0-SNAPSHOT", + maintainer := "Meeh ", + packageSummary := "The Invisible Internet Project", + packageDescription := "Blabla" ) @@ -26,7 +31,7 @@ lazy val browserbundle = (project in file("browserbundle")) lazy val macosx = (project in file("macosx")) .settings( commonSettings, - name := "RouterLaunchApp", + name := "MacI2PLauncher", assemblyJarName in assembly := s"${name.value}-${version.value}.jar", mainClass in assembly := Some("net.i2p.MacOSXRouterLauncherApp") ) @@ -36,8 +41,6 @@ lazy val root = (project in file(".")) .aggregate(browserbundle, macosx) - - fork := true run / javaOptions += "-Xmx512M" diff --git a/launchers/macosx/build.sbt b/launchers/macosx/build.sbt index 3311b34aa..d7ddb7ff8 100644 --- a/launchers/macosx/build.sbt +++ b/launchers/macosx/build.sbt @@ -1,7 +1,39 @@ import sbtassembly.AssemblyPlugin.defaultShellScript +import sbt._ +import Keys._ +import sbt.io.IO +import java.io.File lazy val i2pVersion = "0.9.34" +lazy val buildAppBundleTask = taskKey[Unit](s"Build an Mac OS X bundle for I2P ${i2pVersion}.") +lazy val bundleBuildPath = file("./output") + + +// Pointing the resources directory to the "installer" directory +resourceDirectory in Compile := baseDirectory.value / ".." / ".." / "installer" / "resources" +lazy val resDir = new File("./../installer/resources") +lazy val i2pBuildDir = new File("./../build") +lazy val warsForCopy = i2pBuildDir.list.filter { f => f.endsWith(".war") } +lazy val jarsForCopy = i2pBuildDir.list.filter { f => f.endsWith(".jar") } + +buildAppBundleTask := { + println(s"Building Mac OS X bundle for I2P version ${i2pVersion}.") + bundleBuildPath.mkdir() + val paths = Map[String,File]( + "execBundlePath" -> new File(bundleBuildPath, "I2P.app/Contents/MacOS"), + "resBundlePath" -> new File(bundleBuildPath, "I2P.app/Contents/Resources"), + "i2pbaseBunldePath" -> new File(bundleBuildPath, "I2P.app/Contents/Resources/i2pbase"), + "i2pJarsBunldePath" -> new File(bundleBuildPath, "I2P.app/Contents/Resources/i2pbase/lib"), + "webappsBunldePath" -> new File(bundleBuildPath, "I2P.app/Contents/Resources/i2pbase/webapps") + ) + paths.map { case (s,p) => p.mkdirs() } + val dirsToCopy = List("certificates","locale","man") + dirsToCopy.map { d => IO.copyDirectory( new File(resDir, d), new File(paths.get("i2pbaseBunldePath").get, d) ) } + warsForCopy.map { w => IO.copyFile( new File(i2pBuildDir, w), new File(paths.get("webappsBunldePath").get, w) ) } + warsForCopy.map { j => IO.copyFile( new File(i2pBuildDir, j), new File(paths.get("i2pJarsBunldePath").get, j) ) } +} + // Unmanaged classpath will be available at compile time unmanagedClasspath in Compile ++= Seq( baseDirectory.value / ".." / ".." / "build" / "*.jar", diff --git a/launchers/macosx/src/main/scala/net/i2p/MacOSXRouterLauncherApp.scala b/launchers/macosx/src/main/scala/net/i2p/MacOSXRouterLauncherApp.scala index c363786dd..a454b0d0a 100644 --- a/launchers/macosx/src/main/scala/net/i2p/MacOSXRouterLauncherApp.scala +++ b/launchers/macosx/src/main/scala/net/i2p/MacOSXRouterLauncherApp.scala @@ -1,6 +1,7 @@ package net.i2p import net.i2p.router.Router +import java.io.File /** * @@ -17,12 +18,22 @@ import net.i2p.router.Router * var is mutable * * + * The i2p base directory in the build should be in a relative path from + * the launcher, which would be ../Resources/i2pbase - this directory would + * need to be copied out to a "writable" area, since we're in a signed "immutable" + * bundle. First this launcher will check if i2pbase is already deployed to a + * writable area, if it's not, it deploys, if the i2pbase directory has an older + * version than the one in the bundle, it upgrades. It does nothing if versions + * matches. + * + * * @author Meeh * @version 0.0.1 * @since 0.9.35 */ object MacOSXRouterLauncherApp extends App { + val i2pBaseBundleDir = new File(new File("."), "../Resources/i2pbase") Router.main(args) } diff --git a/launchers/project/build.properties b/launchers/project/build.properties index 31334bbd3..05313438a 100644 --- a/launchers/project/build.properties +++ b/launchers/project/build.properties @@ -1 +1 @@ -sbt.version=1.1.1 +sbt.version=1.1.2 diff --git a/launchers/project/plugins.sbt b/launchers/project/plugins.sbt index 3f27344fa..42c612c7a 100644 --- a/launchers/project/plugins.sbt +++ b/launchers/project/plugins.sbt @@ -1,4 +1,4 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1") addSbtPlugin("com.oradian.sbt" % "sbt-sh" % "0.3.0") addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6") - +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.4")