2018-05-05 23:34:35 +00:00
|
|
|
import java.io.{File, FileNotFoundException, FileOutputStream}
|
|
|
|
import java.util.zip._
|
2018-04-22 23:13:32 +00:00
|
|
|
|
2018-06-30 13:11:17 +00:00
|
|
|
lazy val i2pVersion = "0.9.35"
|
2018-04-22 23:13:32 +00:00
|
|
|
|
2018-05-02 03:39:14 +00:00
|
|
|
lazy val cleanAllTask = taskKey[Unit]("Clean up and remove the OSX bundle")
|
2018-04-24 04:18:21 +00:00
|
|
|
lazy val buildAppBundleTask = taskKey[Unit](s"Build an Mac OS X bundle for I2P ${i2pVersion}.")
|
2018-05-05 23:34:35 +00:00
|
|
|
lazy val buildDeployZipTask = taskKey[String](s"Build an zipfile with base directory for I2P ${i2pVersion}.")
|
|
|
|
lazy val bundleBuildPath = new File("./output")
|
2018-04-24 04:18:21 +00:00
|
|
|
|
2018-05-01 02:54:36 +00:00
|
|
|
lazy val staticFiles = List(
|
|
|
|
"blocklist.txt",
|
|
|
|
"clients.config",
|
|
|
|
"continents.txt",
|
|
|
|
"countries.txt",
|
|
|
|
"hosts.txt",
|
|
|
|
"geoip.txt",
|
|
|
|
"router.config",
|
|
|
|
"webapps.config"
|
|
|
|
)
|
2018-04-24 04:18:21 +00:00
|
|
|
|
|
|
|
lazy val resDir = new File("./../installer/resources")
|
2018-05-02 03:39:14 +00:00
|
|
|
lazy val i2pBuildDir = new File("./../pkg-temp")
|
|
|
|
lazy val warsForCopy = new File(i2pBuildDir, "webapps").list.filter { f => f.endsWith(".war") }
|
|
|
|
lazy val jarsForCopy = new File(i2pBuildDir, "lib").list.filter { f => f.endsWith(".jar") }
|
|
|
|
|
2018-06-30 13:11:17 +00:00
|
|
|
// TODO: Meeh: To be removed - logic is moved to obj-cpp
|
2018-05-02 03:39:14 +00:00
|
|
|
def defaultOSXLauncherShellScript(javaOpts: Seq[String] = Seq.empty): Seq[String] = {
|
|
|
|
val javaOptsString = javaOpts.map(_ + " ").mkString
|
|
|
|
Seq(
|
|
|
|
"#!/usr/bin/env sh",
|
|
|
|
s"""
|
2018-05-05 23:34:35 +00:00
|
|
|
|echo "I2P - Mac OS X Launcher starting up"
|
2018-05-02 03:39:14 +00:00
|
|
|
|export I2P=$$HOME/Library/I2P
|
|
|
|
|for jar in `ls $${I2P}/lib/*.jar`; do
|
|
|
|
| if [ ! -z $$CP ]; then
|
|
|
|
| CP=$${CP}:$${jar};
|
|
|
|
| else
|
|
|
|
| CP=$${jar}
|
|
|
|
| fi
|
|
|
|
|done
|
|
|
|
|export CLASSPATH=$$CP
|
|
|
|
|exec java -jar $javaOptsString$$JAVA_OPTS "$$0" "$$@"""".stripMargin,
|
|
|
|
"")
|
|
|
|
}
|
2018-05-01 03:21:04 +00:00
|
|
|
|
|
|
|
// Pointing the resources directory to the "installer" directory
|
|
|
|
resourceDirectory in Compile := baseDirectory.value / ".." / ".." / "installer" / "resources"
|
|
|
|
|
2018-05-01 11:15:11 +00:00
|
|
|
// Unmanaged base will be included in a fat jar
|
2018-05-02 03:39:14 +00:00
|
|
|
unmanagedBase in Compile := baseDirectory.value / ".." / ".." / "pkg-temp" / "lib"
|
2018-05-01 11:15:11 +00:00
|
|
|
|
2018-05-01 03:21:04 +00:00
|
|
|
// Unmanaged classpath will be available at compile time
|
|
|
|
unmanagedClasspath in Compile ++= Seq(
|
2018-05-02 03:39:14 +00:00
|
|
|
baseDirectory.value / ".." / ".." / "pkg-temp" / "lib" / "*.jar"
|
|
|
|
)
|
|
|
|
|
|
|
|
assemblyOption in assembly := (assemblyOption in assembly).value.copy(
|
|
|
|
prependShellScript = Some(defaultOSXLauncherShellScript(
|
|
|
|
Seq(
|
|
|
|
"-Xmx512M",
|
|
|
|
"-Xms128m",
|
|
|
|
"-Dwrapper.logfile=/tmp/router.log",
|
|
|
|
"-Dwrapper.logfile.loglevel=DEBUG",
|
|
|
|
"-Dwrapper.java.pidfile=/tmp/routerjvm.pid",
|
|
|
|
"-Dwrapper.console.loglevel=DEBUG",
|
|
|
|
"-Di2p.dir.base=$I2P",
|
|
|
|
"-Djava.library.path=$I2P"
|
|
|
|
)))
|
2018-05-01 03:21:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-05-01 11:15:11 +00:00
|
|
|
assemblyJarName in assembly := s"OSXLauncher"
|
2018-05-01 03:21:04 +00:00
|
|
|
|
2018-05-02 03:39:14 +00:00
|
|
|
assemblyExcludedJars in assembly := {
|
|
|
|
val cp = (fullClasspath in assembly).value
|
|
|
|
cp filter { c => jarsForCopy.toList.contains(c.data.getName) }
|
|
|
|
}
|
2018-05-01 03:21:04 +00:00
|
|
|
|
|
|
|
// TODO: MEEH: Add assemblyExcludedJars and load the router from own jar files, to handle upgrades better.
|
|
|
|
// In fact, most likely the bundle never would need an update except for the router jars/wars.
|
|
|
|
|
2018-04-24 05:01:25 +00:00
|
|
|
convertToICNSTask := {
|
|
|
|
println("TODO")
|
|
|
|
}
|
|
|
|
|
2018-05-02 03:39:14 +00:00
|
|
|
cleanAllTask := {
|
|
|
|
clean.value
|
|
|
|
IO.delete(bundleBuildPath)
|
|
|
|
}
|
|
|
|
|
2018-05-05 23:34:35 +00:00
|
|
|
buildDeployZipTask := {
|
|
|
|
println(s"Starting the zip file build process. This might take a while..")
|
|
|
|
if (!bundleBuildPath.exists()) bundleBuildPath.mkdir()
|
|
|
|
val sourceDir = i2pBuildDir
|
|
|
|
def recursiveListFiles(f: File): Array[File] = {
|
|
|
|
val these = f.listFiles
|
|
|
|
these ++ these.filter { f => f.isDirectory }.flatMap(recursiveListFiles).filter(!_.isDirectory)
|
|
|
|
}
|
|
|
|
def zip(out: String, files: Iterable[String]) = {
|
|
|
|
import java.io.{ BufferedInputStream, FileInputStream, FileOutputStream }
|
|
|
|
import java.util.zip.{ ZipEntry, ZipOutputStream }
|
|
|
|
|
|
|
|
val zip = new ZipOutputStream(new FileOutputStream(out))
|
|
|
|
|
|
|
|
files.foreach { name =>
|
|
|
|
val fname = sourceDir.toURI.relativize(new File(name).toURI).toString
|
|
|
|
//println(s"Zipping ${fname}")
|
|
|
|
if (!new File(name).isDirectory) {
|
|
|
|
zip.putNextEntry(new ZipEntry(fname))
|
|
|
|
val in = new BufferedInputStream(new FileInputStream(name))
|
|
|
|
var b = in.read()
|
|
|
|
while (b > -1) {
|
|
|
|
zip.write(b)
|
|
|
|
b = in.read()
|
|
|
|
}
|
|
|
|
in.close()
|
|
|
|
zip.closeEntry()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zip.close()
|
|
|
|
}
|
|
|
|
val fileList = recursiveListFiles(sourceDir.getCanonicalFile).toList
|
|
|
|
val zipFileName = new File(bundleBuildPath, "i2pbase.zip").getCanonicalPath
|
|
|
|
zip(zipFileName, fileList.map { f => f.toString }.toIterable)
|
|
|
|
zipFileName.toString
|
|
|
|
}
|
|
|
|
|
2018-04-24 04:18:21 +00:00
|
|
|
buildAppBundleTask := {
|
|
|
|
println(s"Building Mac OS X bundle for I2P version ${i2pVersion}.")
|
2018-05-05 23:34:35 +00:00
|
|
|
if (!bundleBuildPath.exists()) bundleBuildPath.mkdir()
|
2018-04-24 04:18:21 +00:00
|
|
|
val paths = Map[String,File](
|
|
|
|
"execBundlePath" -> new File(bundleBuildPath, "I2P.app/Contents/MacOS"),
|
2018-05-05 23:34:35 +00:00
|
|
|
"resBundlePath" -> new File(bundleBuildPath, "I2P.app/Contents/Resources")
|
2018-04-24 04:18:21 +00:00
|
|
|
)
|
|
|
|
paths.map { case (s,p) => p.mkdirs() }
|
2018-05-01 02:54:36 +00:00
|
|
|
|
2018-05-01 11:15:11 +00:00
|
|
|
val launcherBinary = Some(assembly.value)
|
|
|
|
launcherBinary.map { l => IO.copyFile( new File(l.toString), new File(paths.get("execBundlePath").get, "I2P") ) }
|
|
|
|
|
2018-05-05 23:34:35 +00:00
|
|
|
val zipFilePath = Some(buildDeployZipTask.value)
|
|
|
|
|
|
|
|
val zipFileOrigin = new File(zipFilePath.get)
|
|
|
|
IO.copyFile(zipFileOrigin, new File(paths.get("resBundlePath").get, "i2pbase.zip"))
|
|
|
|
println(s"Zip placed into bundle :)")
|
|
|
|
|
2018-04-24 04:18:21 +00:00
|
|
|
}
|