Changeset f6c8e44 for launchers


Ignore:
Timestamp:
May 1, 2018 11:15:11 AM (3 years ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
c326bb7
Parents:
345e741
Message:

Jar deployment, SBT hacking, and more related to launcher code.
Some refactoring, bugfixing, and self awareness of launcher jar.

Location:
launchers
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • launchers/browserbundle/build.sbt

    r345e741 rf6c8e44  
    11
    22
    3 libraryDependencies ++= Seq(
    4   "org.json4s" %% "json4s-native" % "3.5.3"
    5 )
    63
    74assemblyExcludedJars in assembly := {
  • launchers/browserbundle/src/main/scala/net/i2p/RouterLauncherApp.scala

    r345e741 rf6c8e44  
    33import java.io.{File, InputStream}
    44
     5//import net.i2p.Router
    56import net.i2p.launchers.DeployProfile
    6 import net.i2p.router.Router
    7 import org.json4s._
    8 import org.json4s.native.JsonMethods._
    97
    108/**
     
    105103  //ErrorUtils.printError(s"Starting up with arguments ${(args mkString ", ")}",":)")
    106104
    107   Router.main(args)
     105  //Router.main(args)
    108106}
    109107
  • launchers/build.sbt

    r345e741 rf6c8e44  
    3232    name         := "RouterLaunchApp",
    3333    assemblyJarName in assembly := s"${name.value}-${version.value}.jar",
    34     mainClass in assembly := Some("net.i2p.RouterLauncherApp")
     34    mainClass in assembly := Some("net.i2p.RouterLauncherApp"),
     35    libraryDependencies ++= Seq(
     36      "org.json4s" %% "json4s-native" % "3.5.3"
     37    )
    3538  ).dependsOn(common)
    3639
     
    5356run / javaOptions += "-Xmx512M"
    5457run / connectInput := true
     58
  • launchers/common/src/main/scala/net/i2p/launchers/OSXDeployment.scala

    r345e741 rf6c8e44  
    22
    33import java.io.{File, IOException}
     4import java.nio.file.FileAlreadyExistsException
    45import java.util.zip.ZipFile
     6
     7import java.nio.file.StandardCopyOption.REPLACE_EXISTING
     8import java.nio.file.Files.copy
     9import java.nio.file.Paths.get
     10
    511import collection.JavaConverters._
    612
     
    121127  def copyDirFromRes(dir: File): Unit = {
    122128    // A small hack
    123     val zipFile = new ZipFile(DeployProfile.executingJarFile.getFile)
    124     zipFile.entries().asScala.toList.filter(_.toString.startsWith(dir.getPath)).filter(!_.isDirectory).map { entry =>
    125       new File(DeployProfile.pathJoin(baseDir,entry.getName)).getParentFile.mkdirs()
    126       if (entry.isDirectory) {
    127         createFileOrDirectory(new File(DeployProfile.pathJoin(baseDir,entry.getName)), true)
    128       } else {
    129         copyBaseFileResToDisk(entry.getName, getClass.getResourceAsStream("/".concat(entry.getName)))
    130       }
     129    try {
     130      val zipFile = new ZipFile(DeployProfile.executingJarFile.getFile)
     131      zipFile.entries().asScala.toList.filter(_.toString.startsWith(dir.getPath)).filter(!_.isDirectory).map { entry =>
     132        new File(DeployProfile.pathJoin(baseDir,entry.getName)).getParentFile.mkdirs()
     133        if (entry.isDirectory) {
     134          createFileOrDirectory(new File(DeployProfile.pathJoin(baseDir,entry.getName)), true)
     135        } else {
     136          copyBaseFileResToDisk(entry.getName, getClass.getResourceAsStream("/".concat(entry.getName)))
     137        }
     138      }
     139    } catch {
     140      case ex:IOException => println(s"Error! Exception ${ex}")
     141      case _:FileAlreadyExistsException => {} // Ignored
    131142    }
    132143  }
     
    157168      } catch {
    158169        case ex:IOException => println(s"Error! Exception ${ex}")
     170        case _:FileAlreadyExistsException => {} // Ignored
    159171      }
    160172    }
     
    163175  if (!new File(baseDir).exists()) {
    164176    new File(baseDir).mkdirs()
     177  }
     178
     179  implicit def toPath (filename: String) = get(filename)
     180
     181  val selfFile = new File(DeployProfile.executingJarFile.getFile)
     182  val selfDir = selfFile.getParentFile
     183  val resDir = new File(selfDir.getParent, "Resources")
     184  val i2pBaseBundleDir = new File(resDir, "i2pbase")
     185  val i2pBundleJarDir = new File(i2pBaseBundleDir, "lib")
     186
     187  val i2pBaseDir = OSXDefaults.getOSXBaseDirectory
     188  val i2pDeployJarDir = new File(i2pBaseDir, "lib")
     189  if (!i2pDeployJarDir.exists()) {
     190    i2pDeployJarDir.mkdirs()
     191    i2pBundleJarDir.list().toList.map {
     192      jar => {
     193        copy (
     194          DeployProfile.pathJoin(i2pBundleJarDir.getAbsolutePath, jar),
     195          DeployProfile.pathJoin(i2pDeployJarDir.getAbsolutePath, jar),
     196          REPLACE_EXISTING)
     197        println(s"Copied ${jar} to right place")
     198      }
     199    }
    165200  }
    166201
     
    185220      case Left(is) => {
    186221        // Write file
    187         if (!new File(DeployProfile.pathJoin(baseDir, fd.getPath)).exists()) {
     222        val f = DeployProfile.pathJoin(baseDir, fd.getPath)
     223        println(s"f: ${f.toString}")
     224        if (!new File(f).exists()) {
    188225          //println(s"copyBaseFileResToDisk(${fd.getPath})")
    189226          try {
     
    191228          } catch {
    192229            case ex:IOException => println(s"Error! Exception ${ex}")
     230            case _:FileAlreadyExistsException => {} // Ignored
    193231          }
    194232        }
  • launchers/macosx/build.sbt

    r345e741 rf6c8e44  
    3232resourceDirectory in Compile := baseDirectory.value / ".." / ".." / "installer" / "resources"
    3333
     34// Unmanaged base will be included in a fat jar
     35unmanagedBase in Compile := baseDirectory.value / ".." / ".." / "build"
     36
    3437// Unmanaged classpath will be available at compile time
    3538unmanagedClasspath in Compile ++= Seq(
    36   baseDirectory.value / ".." / ".." / "build" / "*.jar",
    37   baseDirectory.value / ".." / ".." / "router" / "java" / "src"
     39  baseDirectory.value / ".." / ".." / "build" / "*.jar"
    3840)
    39 
    40 // Please note the difference between browserbundle, this has
    41 // the "in Compile" which limit it's scope to that.
    42 //unmanagedBase in Compile := baseDirectory.value / ".." / ".." / "build"
    43 
    44 libraryDependencies ++= Seq(
    45   "net.i2p" % "router" % i2pVersion % Compile
    46 )
    47 
    4841
    4942//assemblyOption in assembly := (assemblyOption in assembly).value.copy(prependShellScript = Some(defaultShellScript))
    5043
    51 assemblyJarName in assembly := s"${name.value}-${version.value}"
     44assemblyJarName in assembly := s"OSXLauncher"
    5245
    5346
     
    7265  val dirsToCopy = List("certificates","locale","man")
    7366
     67  val launcherBinary = Some(assembly.value)
     68  launcherBinary.map { l => IO.copyFile( new File(l.toString), new File(paths.get("execBundlePath").get, "I2P") ) }
     69
     70
    7471  /**
    7572    *
     
    8683  dirsToCopy.map { d => IO.copyDirectory( new File(resDir, d), new File(paths.get("i2pbaseBunldePath").get, d) ) }
    8784  warsForCopy.map { w => IO.copyFile( new File(i2pBuildDir, w), new File(paths.get("webappsBunldePath").get, w) ) }
    88   warsForCopy.map { j => IO.copyFile( new File(i2pBuildDir, j), new File(paths.get("i2pJarsBunldePath").get, j) ) }
     85  jarsForCopy.map { j => IO.copyFile( new File(i2pBuildDir, j), new File(paths.get("i2pJarsBunldePath").get, j) ) }
    8986}
  • launchers/macosx/src/main/scala/net/i2p/MacOSXRouterLauncherApp.scala

    r345e741 rf6c8e44  
    11package net.i2p
    22
    3 import net.i2p.router.Router
     3import java.io.File
     4
     5import collection.JavaConverters._
    46import net.i2p.launchers.{OSXDefaults, OSXDeployment}
    5 import java.io.File
    67
    78/**
     
    3536object MacOSXRouterLauncherApp extends App {
    3637
    37   val i2pBaseDir = new File(OSXDefaults.getOSXBaseDirectory)
     38  val i2pBaseDir = OSXDefaults.getOSXBaseDirectory
     39
    3840
    3941  new OSXDeployment()
     
    4244  System.setProperty("user.dir", i2pBaseDir.getAbsolutePath)
    4345
    44   Router.main(args)
     46  val i2pJarDir = new File(i2pBaseDir.getAbsolutePath, "lib")
     47  i2pJarDir.list().toList.map { jar => {
     48    val jarFile = new File(i2pJarDir, jar)
     49    println(s"Loading jar: ${jarFile.toURI.toURL} => ${MacOSXRouterLauncher.addJarToClassPath(jarFile.toURI.toURL)}")
     50
     51  } }
     52
     53  MacOSXRouterLauncher.runRouter(args)
     54  //net.i2p.Router.main(args)
    4555}
Note: See TracChangeset for help on using the changeset viewer.