From 2d77b0fd4fb671ebd33b59e2a055de7b15b7ce60 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 27 Jul 2019 11:04:32 +0200 Subject: [PATCH 01/14] Add a deployDev task that copies additional deployment files for plugin devs --- build.sbt | 4 ++- deployment-files-dev/build.sbt | 42 +++++++++++++++++++++++++ project/BootstrapUtility.scala | 57 +++++++++++++++++++++------------- project/BuildUtility.scala | 28 ++++++++--------- 4 files changed, 94 insertions(+), 37 deletions(-) create mode 100644 deployment-files-dev/build.sbt diff --git a/build.sbt b/build.sbt index b10c28c8..992334cf 100644 --- a/build.sbt +++ b/build.sbt @@ -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" @@ -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") // --------------------------------------------------------------------------------------------------------------------- diff --git a/deployment-files-dev/build.sbt b/deployment-files-dev/build.sbt new file mode 100644 index 00000000..8b30026b --- /dev/null +++ b/deployment-files-dev/build.sbt @@ -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) diff --git a/project/BootstrapUtility.scala b/project/BootstrapUtility.scala index d7ebfee8..8a981d26 100644 --- a/project/BootstrapUtility.scala +++ b/project/BootstrapUtility.scala @@ -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) { @@ -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) } } } @@ -155,8 +172,8 @@ object BootstrapUtility { if (file.isFile) { file.delete() } else { - createOrEmptyFolder(file.getAbsolutePath) - file.delete() + createOrEmptyFolder(file.getAbsolutePath) + file.delete() } } } else { @@ -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'." } } } \ No newline at end of file diff --git a/project/BuildUtility.scala b/project/BuildUtility.scala index dc408456..1700364e 100644 --- a/project/BuildUtility.scala +++ b/project/BuildUtility.scala @@ -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} @@ -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) } @@ -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) + } + } } \ No newline at end of file From b22455d9ab244c110d4eda30671a126766fa3034 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 27 Jul 2019 12:13:39 +0200 Subject: [PATCH 02/14] Add run configuration and make target for deployDev --- .../Deploy_dev__sbt_deployDev_.xml | 20 +++++++++++++++++++ ...ll_API_package__sbt_packagedArtifacts_.xml | 20 +++++++++++++++++++ ...cher_and_deploy_plugin_dev_environment.xml | 15 ++++++++++++++ Makefile | 12 +++++++++++ 4 files changed, 67 insertions(+) create mode 100644 .idea/runConfigurations/Deploy_dev__sbt_deployDev_.xml create mode 100644 .idea/runConfigurations/Full_API_package__sbt_packagedArtifacts_.xml create mode 100644 .idea/runConfigurations/_DeployDev__Generate_Bootstrap_Launcher_and_deploy_plugin_dev_environment.xml diff --git a/.idea/runConfigurations/Deploy_dev__sbt_deployDev_.xml b/.idea/runConfigurations/Deploy_dev__sbt_deployDev_.xml new file mode 100644 index 00000000..236f0b0f --- /dev/null +++ b/.idea/runConfigurations/Deploy_dev__sbt_deployDev_.xml @@ -0,0 +1,20 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Full_API_package__sbt_packagedArtifacts_.xml b/.idea/runConfigurations/Full_API_package__sbt_packagedArtifacts_.xml new file mode 100644 index 00000000..da90d3f3 --- /dev/null +++ b/.idea/runConfigurations/Full_API_package__sbt_packagedArtifacts_.xml @@ -0,0 +1,20 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/_DeployDev__Generate_Bootstrap_Launcher_and_deploy_plugin_dev_environment.xml b/.idea/runConfigurations/_DeployDev__Generate_Bootstrap_Launcher_and_deploy_plugin_dev_environment.xml new file mode 100644 index 00000000..6b04f0c8 --- /dev/null +++ b/.idea/runConfigurations/_DeployDev__Generate_Bootstrap_Launcher_and_deploy_plugin_dev_environment.xml @@ -0,0 +1,15 @@ + + + + \ No newline at end of file diff --git a/Makefile b/Makefile index 3bd9d1f5..9a066642 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,15 @@ bootstrap_deploy: sbt bs "project bootstrapProject" assembly sbt deploy +bootstrap_deploy_dev: + sbt clean + sbt compile + sbt gui + sbt package copy + sbt apiProject/packagedArtifacts + sbt bs "project bootstrapProject" assembly + sbt deployDev + create: sbt create sbt fetch @@ -29,6 +38,9 @@ create: deploy: sbt deploy +deploy_dev: + sbt deployDev + fetch: sbt fetch From e249ff90d951e5aa134608d1160547a0faf9d530 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 27 Jul 2019 19:34:28 +0200 Subject: [PATCH 03/14] Update fetch task to support plugin developer environment --- ...cher_and_deploy_plugin_dev_environment.xml | 2 +- build.sbt | 2 +- deployment-files-dev/build.sbt | 4 +- project/BuildUtility.scala | 17 ++++--- project/SbtFile.scala | 47 +++++++++++-------- 5 files changed, 41 insertions(+), 31 deletions(-) diff --git a/.idea/runConfigurations/_DeployDev__Generate_Bootstrap_Launcher_and_deploy_plugin_dev_environment.xml b/.idea/runConfigurations/_DeployDev__Generate_Bootstrap_Launcher_and_deploy_plugin_dev_environment.xml index 6b04f0c8..4d99a24c 100644 --- a/.idea/runConfigurations/_DeployDev__Generate_Bootstrap_Launcher_and_deploy_plugin_dev_environment.xml +++ b/.idea/runConfigurations/_DeployDev__Generate_Bootstrap_Launcher_and_deploy_plugin_dev_environment.xml @@ -9,7 +9,7 @@