Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.
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
Next Next commit
Add a deployDev task that copies additional deployment files for plug…
…in devs
  • Loading branch information
hlxid committed Jul 27, 2019
commit 2d77b0fd4fb671ebd33b59e2a055de7b15b7ce60
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +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 gui = TaskKey[Unit]("gui", "Installs GUI dependencies and builds it using npm.")

pluginBuildFileName := "plugins.sbt"
Expand All @@ -96,7 +97,8 @@ fetch := BuildUtility(streams.value.log).fetchPluginsTask(pluginFolderNames.valu
pluginTargetFolderNames.value, apiProjectPath.value)
copy := BuildUtility(streams.value.log).copyPluginsTask(pluginFolderNames.value, pluginTargetFolderNames.value, scalaMajorVersion)
bs := BootstrapUtility.bootstrapGenTask(streams.value.log, s"$scalaMajorVersion$scalaMinorVersion", getDependencyList.value)
deploy := BootstrapUtility.prepareDeploymentTask(streams.value.log, scalaMajorVersion)
deploy := BootstrapUtility.prepareDeploymentTask(streams.value.log, scalaMajorVersion, dev = false)
deployDev := BootstrapUtility.prepareDeploymentTask(streams.value.log, scalaMajorVersion, dev = true)
gui := BuildUtility(streams.value.log).guiTask(guiProjectPath.value, streams.value.cacheDirectory / "gui")

// ---------------------------------------------------------------------------------------------------------------------
Expand Down
42 changes: 42 additions & 0 deletions deployment-files-dev/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// This is a stripped down version of the build.sbt found in the main framework.
// It just contains version numbers and all sbt tasks for plugin developers.

// ---------------------------------------------------------------------------------------------------------------------
// PROJECT INFORMATION
// ---------------------------------------------------------------------------------------------------------------------

name := "ChatOverflow"
version := "0.3"

// One version for all sub projects. Use "retrieveManaged := true" to download and show all library dependencies.
val scalaMajorVersion = "2.12"
val scalaMinorVersion = ".5"
inThisBuild(List(
scalaVersion := s"$scalaMajorVersion$scalaMinorVersion",
retrieveManaged := false)
)

// ---------------------------------------------------------------------------------------------------------------------
// PLUGIN FRAMEWORK DEFINITIONS
// ---------------------------------------------------------------------------------------------------------------------

// Plugin framework settings
lazy val pluginBuildFileName = settingKey[String]("The filename of the plugin build file. Remember to gitignore it!")
lazy val pluginFolderNames = settingKey[List[String]]("The folder names of all plugin source directories.")
lazy val pluginTargetFolderNames = settingKey[List[String]]("The folder names of compiled and packaged plugins. Remember to gitignore these!")
lazy val apiProjectPath = settingKey[String]("The path to the api sub project. Remember to gitignore it!")

// Plugin framework tasks
lazy val create = TaskKey[Unit]("create", "Creates a new plugin. Interactive command using the console.")
lazy val fetch = TaskKey[Unit]("fetch", "Searches for plugins in plugin directories, builds the plugin build file.")
lazy val copy = TaskKey[Unit]("copy", "Copies all packaged plugin jars to the target plugin folder.")

pluginBuildFileName := "plugins.sbt"
pluginFolderNames := List("plugins-public", "plugins-private")
pluginTargetFolderNames := List("plugins", s"target/scala-$scalaMajorVersion/plugins")
apiProjectPath := "api"

create := PluginCreateWizard(streams.value.log).createPluginTask(pluginFolderNames.value)
fetch := BuildUtility(streams.value.log).fetchPluginsTask(pluginFolderNames.value, pluginBuildFileName.value,
pluginTargetFolderNames.value, apiProjectPath.value)
copy := BuildUtility(streams.value.log).copyPluginsTask(pluginFolderNames.value, pluginTargetFolderNames.value, scalaMajorVersion)
57 changes: 35 additions & 22 deletions project/BootstrapUtility.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,17 @@ object BootstrapUtility {
}

/**
* Prepares the environemnt for deployment. Should be called after package and assembly task.
*
* @param logger the sbt logger
* @param scalaLibraryVersion the scala library major version
*/
def prepareDeploymentTask(logger: ManagedLogger, scalaLibraryVersion: String): Unit = {
// Assuming, before this: clean, bs, assembly bootstrapProject, package
* Prepares the environemnt for deployment. Should be called after package and assembly task.
*
* @param logger the sbt logger
* @param scalaLibraryVersion the scala library major version
* @param dev whether sbt scripts and stuff for plugin developers should be included
*/
def prepareDeploymentTask(logger: ManagedLogger, scalaLibraryVersion: String, dev: Boolean): Unit = {
// Assuming, before this: clean, bs, assembly bootstrapProject, package and if dev apiProject/packagedArtifacts
// Assuming: Hardcoded "bin/" and "deploy/" folders
// Assuming: A folder called "deployment-files" with all additional files (license, bat, etc.)
// Assuming: A folder called "deployment-files-dev" with more additional files for plugin developers (only included if dev == true)

withTaskInfo("PREPARE DEPLOYMENT", logger) {

Expand Down Expand Up @@ -136,10 +138,25 @@ object BootstrapUtility {
if (!deploymentFiles.exists()) {
logger warn "Unable to find deployment files."
} else {
for (deploymentFile <- deploymentFiles.listFiles()) {
Files.copy(Paths.get(deploymentFile.getAbsolutePath),
Paths.get(s"deploy/${deploymentFile.getName}"))
logger info s"Finished copying additional deployment file '${deploymentFile.getName}'."
sbt.IO.copyDirectory(deploymentFiles, new File("deploy/"))
logger info s"Finished copying additional deployment files."
}

if (dev) {
val devDeploymentFiles = new File("deployment-files-dev/")
if (!devDeploymentFiles.exists()) {
logger warn "Unable to find dev deployment files."
} else {
sbt.IO.copyDirectory(devDeploymentFiles, new File("deploy/"))
logger info "Finished copying additional dev deployment files."
}

val requiredBuildFiles = Set("BuildUtility.scala", "build.properties", "Plugin.scala", "PluginCreateWizard.scala",
"PluginLanguage.scala", "PluginMetadata.scala", "SbtFile.scala")
for (filepath <- requiredBuildFiles) {
val origFile = new File(s"project/$filepath")
val deployFile = new File(s"deploy/project/$filepath")
sbt.IO.copyFile(origFile, deployFile)
}
}
}
Expand All @@ -155,8 +172,8 @@ object BootstrapUtility {
if (file.isFile) {
file.delete()
} else {
createOrEmptyFolder(file.getAbsolutePath)
file.delete()
createOrEmptyFolder(file.getAbsolutePath)
file.delete()
}
}
} else {
Expand All @@ -165,19 +182,15 @@ object BootstrapUtility {
}

/**
* Copies ONE jar file from the source to all target directories. Useful for single packaged jar files.
* Copies all jar files from the source to all target directories.
*/
private def copyJars(sourceDirectory: String, targetDirectories: List[String], logger: ManagedLogger): Unit = {
val candidates = new File(sourceDirectory)
.listFiles().filter(f => f.isFile && f.getName.toLowerCase.endsWith(".jar"))
if (candidates.length != 1) {
logger warn s"Unable to identify jar file in $sourceDirectory"
} else {
for (targetDirectory <- targetDirectories) {
Files.copy(Paths.get(candidates.head.getAbsolutePath),
Paths.get(s"$targetDirectory/${candidates.head.getName}"))
logger info s"Finished copying file '${candidates.head.getAbsolutePath}' to '$targetDirectory'."
}
for (targetDirectory <- targetDirectories; file <- candidates) {
Files.copy(Paths.get(file.getAbsolutePath),
Paths.get(s"$targetDirectory/${file.getName}"))
logger info s"Finished copying file '${file.getAbsolutePath}' to '$targetDirectory'."
}
}
}
28 changes: 14 additions & 14 deletions project/BuildUtility.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 @@ -233,20 +234,6 @@ 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.
*/
private 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 @@ -273,4 +260,17 @@ object BuildUtility {
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)
}
}
}