Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Add deployment for plugin developers #103

Merged
merged 16 commits into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Various small fixes in deploy build code
  • Loading branch information
hlxid committed Jul 29, 2019
commit 055317921dd666b9371d4b78ba8055b8ee6f2b99
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ lazy val fetch = TaskKey[Unit]("fetch", "Searches for plugins in plugin director
lazy val copy = TaskKey[Unit]("copy", "Copies all packaged plugin jars to the target plugin folder.")
lazy val bs = TaskKey[Unit]("bs", "Updates the bootstrap project with current dependencies and chat overflow jars.")
lazy val deploy = TaskKey[Unit]("deploy", "Prepares the environment for deployment, fills deploy folder.")
lazy val deployDev = TaskKey[Unit]("deployDev", "Prepares the environment for deployment, fills deploy folder.")
lazy val deployDev = TaskKey[Unit]("deployDev", "Prepares the environment for plugin developers, fills deployDev folder.")
lazy val gui = TaskKey[Unit]("gui", "Installs GUI dependencies and builds it using npm.")

pluginBuildFileName := "plugins.sbt"
Expand Down Expand Up @@ -119,7 +119,7 @@ lazy val getDependencyList = Def.task[List[ModuleID]] {
m.name == s"chatoverflow_$scalaMajorVersion")
}
}
//lazy val x = ModuleID.apply()

// Clears the built GUI dirs on clean
cleanFiles += baseDirectory.value / guiProjectPath.value / "dist"
cleanFiles += baseDirectory.value / "src" / "main" / "resources" / "chatoverflow-gui"
10 changes: 5 additions & 5 deletions project/BootstrapUtility.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ object BootstrapUtility {

logger info "Started deployment process."

// First step: Create directories
createOrEmptyFolder("deployDev")
// First step: Create directory
createOrEmptyFolder("deploy/")

// Second step: Create bin directories and copy all binaries
val targetJarDirectories = List("bin", "deploy/bin")
Expand Down Expand Up @@ -146,16 +146,16 @@ object BootstrapUtility {

logger info "Started deployment process for plugin dev environment."

// First step: Create directories
createOrEmptyFolder("deployDev")
// First step: Create directory
createOrEmptyFolder("deployDev/")

// Second step: Copy all binaries
val targetJarDirectories = List("bin", "deployDev/bin")
prepareBinDirectories(logger, targetJarDirectories, scalaLibraryVersion, copyApi = false)

// Third step: Copy the api
sbt.IO.copyDirectory(new File(apiProjectPath), new File("deployDev/api/"))
sbt.IO.delete(new File("deployDev/api/target"))
sbt.IO.delete(new File("deployDev/api/target")) // otherwise compiled code would end up in the zip

// Fourth step: Copy required meta-build files
val requiredBuildFiles = Set("BuildUtility.scala", "build.properties", "Plugin.scala", "PluginCreateWizard.scala",
Expand Down
29 changes: 14 additions & 15 deletions project/BuildUtility.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import java.io.{File, IOException}
import java.nio.file.{Files, StandardCopyOption}

import BuildUtility._
import sbt.internal.util.ManagedLogger
import sbt.util.{FileFunction, FilesInfo}

Expand Down Expand Up @@ -236,6 +235,20 @@ class BuildUtility(logger: ManagedLogger) {
}
}

/**
* Creates a file listing with all files including files in any sub-dir.
*
* @param f the directory for which the file listing needs to be created.
* @return the file listing as a set of files.
*/
def recursiveFileListing(f: File): Set[File] = {
if (f.isDirectory) {
f.listFiles().flatMap(recursiveFileListing).toSet
} else {
Set(f)
}
}

private def withTaskInfo(taskName: String)(task: Unit): Unit = BuildUtility.withTaskInfo(taskName, logger)(task)
}

Expand All @@ -261,18 +274,4 @@ object BuildUtility {
// Info when task stopped (better log comprehension)
logger info s"Finished custom task: $taskName"
}

/**
* Creates a file listing with all files including files in any sub-dir.
*
* @param f the directory for which the file listing needs to be created.
* @return the file listing as a set of files.
*/
def recursiveFileListing(f: File): Set[File] = {
if (f.isDirectory) {
f.listFiles().flatMap(recursiveFileListing).toSet
} else {
Set(f)
}
}
}
40 changes: 20 additions & 20 deletions project/SbtFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SbtFile(val name: String, val version: String, val plugins: List[Plugin],
* @param name the name of a sbt project
* @param version the version of a sbt project
*/
def this(name: String, version: String) = this(name, version, List(), "", false, List())
def this(name: String, version: String) = this(name, version, List(), "", false, List())

/**
* Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files.
Expand Down Expand Up @@ -88,13 +88,8 @@ class SbtFile(val name: String, val version: String, val plugins: List[Plugin],
}

if (defineRoot) {
var aggregateElems = plugins.map(p => s"`${p.normalizedName}`")
if (apiProjectPath != "") {
aggregateElems = "apiProject" +: aggregateElems
}

var rootLine = "\n\nlazy val root = (project in file(\".\")).aggregate(%s)"
.format(aggregateElems.mkString(", "))
.format(("apiProject" +: plugins.map(p => s"`${p.normalizedName}`")).mkString(", "))

if (apiProjectPath != "") {
rootLine += ".dependsOn(apiProject)"
Expand All @@ -107,23 +102,28 @@ class SbtFile(val name: String, val version: String, val plugins: List[Plugin],
sbtContent append "\nresolvers += \"jcenter-bintray\" at \"http://jcenter.bintray.com\"\n"

// Note that the %% in the string are required to escape the string formatter and will turn into a single %
val depString = dependencies.map(m => {
var formatString = ""

if (m.crossVersion == CrossVersion.binary)
formatString += "\"%s\" %%%% \"%s\" %% \"%s\""
else
formatString += "\"%s\" %% \"%s\" %% \"%s\""

if (m.configurations.isDefined)
formatString += " %% \"%s\""

formatString.format(m.organization, m.name, m.revision, m.configurations.getOrElse(""))
}).mkString(" ", ",\n ", "")
val depString = dependencies.map(m => renderModuleID(m)).mkString(" ", ",\n ", "")

sbtContent append s"libraryDependencies ++= Seq(\n$depString\n)\n"
}

sbtContent.mkString
}

/**
* Converts a ModuleID instance to a string with the module in the syntax that is used in sbt files.
*/
private def renderModuleID(m: ModuleID): String = {
var formatString = ""

if (m.crossVersion == CrossVersion.binary)
formatString += "\"%s\" %%%% \"%s\" %% \"%s\""
else
formatString += "\"%s\" %% \"%s\" %% \"%s\""

if (m.configurations.isDefined)
formatString += " %% \"%s\""

formatString.format(m.organization, m.name, m.revision, m.configurations.getOrElse(""))
}
}