source: launchers/browserbundle/src/main/scala/net/i2p/DeployProfile.scala @ 8c10ec9

Last change on this file since 8c10ec9 was 8c10ec9, checked in by meeh <meeh@…>, 2 years ago

Realised a better way to handle the build process of both the
Browser Bundle i2p launcher, as well as the upcoming Mac OS X
i2p launcher. They share some few properties and how code has
to be managed for both system's update managers and so on.
More details will be documentated in README.md files as well as
in those commit messages I now write :)

  • Property mode set to 100644
File size: 2.5 KB
Line 
1package net.i2p
2
3import java.io.{File, InputStream}
4/**
5  *
6  * The purpose of this class is to copy files from the i2p "default config" directory
7  * and to a "current config" directory relative to the browser bundle.
8  *
9  * @author Meeh
10  * @version 0.0.1
11  * @since 0.9.35
12  */
13class DeployProfile(confDir: String, baseDir: String) {
14  import java.nio.file.{Paths, Files}
15  import java.nio.charset.StandardCharsets
16
17
18  /**
19    * This joins two paths in a cross platform way. Meaning it takes care of either we use
20    * \\ or / as directory separator. It returns the resulting path in a string.
21    *
22    * @since 0.9.35
23    * @param parent The parent path
24    * @param child The child path to append
25    * @return String
26    */
27  def pathJoin(parent:String,child:String): String = new File(new File(parent), child).getPath
28
29  /**
30    * This function copies resources from the fatjar to the config directory of i2p.
31    *
32    * @since 0.9.35
33    * @param fStr
34    * @return Unit
35    */
36  def copyFileResToDisk(fStr: String) = Files.copy(
37    getClass.getResource("/".concat(fStr)).getContent.asInstanceOf[InputStream],
38    Paths.get(pathJoin(confDir, fStr)).normalize()
39  )
40
41  /**
42    * Filter function for finding missing required files.
43    *
44    * @since 0.9.35
45    * @param l1
46    * @param l2
47    * @return
48    */
49  def missingFiles(l1: List[String], l2: List[String]) = l1.filter { x => !l2.contains(x) }
50
51
52  val warFiles = List("routerconsole.war")
53
54  val staticFiles = List(
55    "blocklist.txt",
56    "clients.config",
57    "continents.txt",
58    "countries.txt",
59    "hosts.txt",
60    "geoip.txt",
61    "i2ptunnel.config",
62    "logger.config",
63    "router.config",
64    "webapps.config"
65  )
66
67  /**
68    *
69    * This function will check the existence of static files,
70    * and if any of them are lacking, it will be copied from the
71    * fat jar's resources.
72    *
73    * @since 0.9.35
74    * @return Unit (Null)
75    */
76  def verifyExistenceOfConfig() = {
77    val fDir = new File(confDir)
78    if (fDir.exists()) {
79      // We still check if files are in place
80      val currentDirContentList = fDir.list.toList
81      val missing = missingFiles(staticFiles, currentDirContentList)
82      if (!missing.isEmpty) {
83        missing.map(copyFileResToDisk)
84      }
85    } else {
86      // New deployment!
87      deployDefaultConfig()
88    }
89  }
90
91  /**
92    *
93    * This function does the default deployment of files,
94    * map is the same as a loop. we're looping over the file list.
95    *
96    * @since 0.9.35
97    * @return Unit
98    */
99  def deployDefaultConfig(): Unit = staticFiles.map(copyFileResToDisk)
100
101}
Note: See TracBrowser for help on using the repository browser.