Changeset 70e994fc


Ignore:
Timestamp:
May 2, 2018 3:39:14 AM (3 years ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
1c677cd
Parents:
c326bb7
Message:

Some changes, after much testing I find it best to spawn an sub java
process for I2P rather than trying to load Router via reflection or
anything runtime fancy stuff. Shell script is implemented in SBT now,
and can now link to download JRE script and so on.

Location:
launchers
Files:
1 added
6 edited
1 moved

Legend:

Unmodified
Added
Removed
  • launchers/build.sbt

    rc326bb7 r70e994fc  
    4242    commonSettings,
    4343    name         := "MacI2PLauncher",
    44     assemblyJarName in assembly := s"${name.value}-${version.value}.jar",
    45     mainClass in assembly := Some("net.i2p.MacOSXRouterLauncherApp")
     44    mainClass in assembly := Some("net.i2p.launchers.osx.LauncherAppMain")
    4645  ).dependsOn(common)
    4746
  • launchers/common/build.sbt

    rc326bb7 r70e994fc  
     1libraryDependencies += "org.xeustechnologies" % "jcl-core" % "2.8"
  • launchers/common/src/main/scala/net/i2p/launchers/DeployProfile.scala

    rc326bb7 r70e994fc  
    11package net.i2p.launchers
    22
    3 import java.io.{File, InputStream}
     3import java.io.{File, IOException, InputStream}
     4import java.nio.file.FileAlreadyExistsException
    45
    56
     
    5960    * @return Unit
    6061    */
    61   def copyFileResToDisk(fStr: String) = Files.copy(
     62  def copyFileResToDisk(fStr: String) = try { Files.copy(
    6263    getClass.getResource("/".concat(fStr)).getContent.asInstanceOf[InputStream],
    6364    Paths.get(DeployProfile.pathJoin(confDir, fStr)).normalize()
    64   )
     65  )} catch {
     66    case _:FileAlreadyExistsException => {} // Ignored
     67    case ex:IOException => println(s"Error! Exception ${ex}")
     68  }
    6569
    6670
     
    7377    * @return Unit
    7478    */
    75   def copyBaseFileResToDisk(path: String, is: InputStream) = Files.copy(
     79  def copyBaseFileResToDisk(path: String, is: InputStream) = try { Files.copy(
    7680    is,
    7781    Paths.get(DeployProfile.pathJoin(baseDir, path)).normalize()
    78   )
     82  )} catch {
     83    case _:FileAlreadyExistsException => {} // Ignored
     84    case ex:IOException => println(s"Error! Exception ${ex}")
     85  }
    7986
    8087  /**
  • launchers/common/src/main/scala/net/i2p/launchers/OSXDeployment.scala

    rc326bb7 r70e994fc  
    138138      }
    139139    } catch {
     140      case _:FileAlreadyExistsException => {} // Ignored
    140141      case ex:IOException => println(s"Error! Exception ${ex}")
    141       case _:FileAlreadyExistsException => {} // Ignored
    142142    }
    143143  }
     
    167167        }
    168168      } catch {
     169        case _:FileAlreadyExistsException => {} // Ignored
    169170        case ex:IOException => println(s"Error! Exception ${ex}")
    170         case _:FileAlreadyExistsException => {} // Ignored
    171171      }
    172172    }
  • launchers/common/src/main/scala/net/i2p/launchers/RouterLauncher.scala

    rc326bb7 r70e994fc  
    11package net.i2p.launchers
    22
    3 import java.net.URL
     3import java.io.File
     4
    45
    56/**
     
    1011  */
    1112abstract class RouterLauncher {
    12 
    13   def getClassLoader: ClassLoader
    14 
    15   def addJarToClassPath(url: URL): Boolean
     13  def runRouter(basePath: File, args: Array[String]): Unit
    1614
    1715  def runRouter(args: Array[String]): Unit
  • launchers/macosx/build.sbt

    rc326bb7 r70e994fc  
    77lazy val i2pVersion = "0.9.34"
    88
     9lazy val cleanAllTask = taskKey[Unit]("Clean up and remove the OSX bundle")
    910lazy val buildAppBundleTask = taskKey[Unit](s"Build an Mac OS X bundle for I2P ${i2pVersion}.")
    1011lazy val bundleBuildPath = file("./output")
     
    2223
    2324lazy val resDir = new File("./../installer/resources")
    24 lazy val i2pBuildDir = new File("./../build")
    25 lazy val warsForCopy = i2pBuildDir.list.filter { f => f.endsWith(".war") }
    26 lazy val jarsForCopy = i2pBuildDir.list.filter { f => f.endsWith(".jar") }
     25lazy val i2pBuildDir = new File("./../pkg-temp")
     26lazy val warsForCopy = new File(i2pBuildDir, "webapps").list.filter { f => f.endsWith(".war") }
     27lazy val jarsForCopy = new File(i2pBuildDir, "lib").list.filter { f => f.endsWith(".jar") }
    2728
    2829
    29 
     30def defaultOSXLauncherShellScript(javaOpts: Seq[String] = Seq.empty): Seq[String] = {
     31  val javaOptsString = javaOpts.map(_ + " ").mkString
     32  Seq(
     33    "#!/usr/bin/env sh",
     34    s"""
     35       |echo "Yo"
     36       |export I2P=$$HOME/Library/I2P
     37       |for jar in `ls $${I2P}/lib/*.jar`; do
     38       |  if [ ! -z $$CP ]; then
     39       |      CP=$${CP}:$${jar};
     40       |  else
     41       |      CP=$${jar}
     42       |  fi
     43       |done
     44       |export CLASSPATH=$$CP
     45       |exec java -jar $javaOptsString$$JAVA_OPTS "$$0" "$$@"""".stripMargin,
     46    "")
     47}
    3048
    3149// Pointing the resources directory to the "installer" directory
     
    3351
    3452// Unmanaged base will be included in a fat jar
    35 unmanagedBase in Compile := baseDirectory.value / ".." / ".." / "build"
     53unmanagedBase in Compile := baseDirectory.value / ".." / ".." / "pkg-temp" / "lib"
    3654
    3755// Unmanaged classpath will be available at compile time
    3856unmanagedClasspath in Compile ++= Seq(
    39   baseDirectory.value / ".." / ".." / "build" / "*.jar"
     57  baseDirectory.value / ".." / ".." / "pkg-temp" / "lib" / "*.jar"
    4058)
    4159
    42 //assemblyOption in assembly := (assemblyOption in assembly).value.copy(prependShellScript = Some(defaultShellScript))
     60assemblyOption in assembly := (assemblyOption in assembly).value.copy(
     61  prependShellScript = Some(defaultOSXLauncherShellScript(
     62    Seq(
     63      "-Xmx512M",
     64      "-Xms128m",
     65      "-Dwrapper.logfile=/tmp/router.log",
     66      "-Dwrapper.logfile.loglevel=DEBUG",
     67      "-Dwrapper.java.pidfile=/tmp/routerjvm.pid",
     68      "-Dwrapper.console.loglevel=DEBUG",
     69      "-Djava.awt.headless=true",
     70      "-Di2p.dir.base=$I2P",
     71      "-Djava.library.path=$I2P"
     72    )))
     73)
     74
    4375
    4476assemblyJarName in assembly := s"OSXLauncher"
    4577
     78assemblyExcludedJars in assembly := {
     79  val cp = (fullClasspath in assembly).value
     80  cp filter { c => jarsForCopy.toList.contains(c.data.getName) }
     81}
    4682
    4783// TODO: MEEH: Add assemblyExcludedJars and load the router from own jar files, to handle upgrades better.
     
    5086convertToICNSTask := {
    5187  println("TODO")
     88}
     89
     90cleanAllTask := {
     91  clean.value
     92  IO.delete(bundleBuildPath)
    5293}
    5394
     
    81122    *
    82123    */
    83   dirsToCopy.map { d => IO.copyDirectory( new File(resDir, d), new File(paths.get("i2pbaseBunldePath").get, d) ) }
    84   warsForCopy.map { w => IO.copyFile( new File(i2pBuildDir, w), new File(paths.get("webappsBunldePath").get, w) ) }
    85   jarsForCopy.map { j => IO.copyFile( new File(i2pBuildDir, j), new File(paths.get("i2pJarsBunldePath").get, j) ) }
     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) ) }
    86127}
  • launchers/macosx/src/main/scala/net/i2p/launchers/osx/LauncherAppMain.scala

    rc326bb7 r70e994fc  
    1 package net.i2p
     1package net.i2p.launchers.osx
    22
    33import java.io.File
    44
    5 import collection.JavaConverters._
    6 import net.i2p.launchers.{OSXDefaults, OSXDeployment}
     5import net.i2p.launchers.{DeployProfile, OSXDefaults, OSXDeployment}
    76
    87/**
     
    3433  * @since 0.9.35
    3534  */
    36 object MacOSXRouterLauncherApp extends App {
     35object LauncherAppMain extends App {
    3736
    3837  val i2pBaseDir = OSXDefaults.getOSXBaseDirectory
    39 
    4038
    4139  new OSXDeployment()
     
    4442  System.setProperty("user.dir", i2pBaseDir.getAbsolutePath)
    4543
    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)
     44  try {
     45    MacOSXRouterLauncher.runRouter(i2pBaseDir, args)
     46  } finally {
     47    System.out.println("Exit.")
     48  }
    5549}
Note: See TracChangeset for help on using the changeset viewer.