diff --git a/.gitignore b/.gitignore index 5dd457cd..6da991be 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ project/plugins/project/ /bin/ /lib/ /deploy/ +/deployDev/ /wiki/ # Plugin Data 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/_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..92a77790 --- /dev/null +++ b/.idea/runConfigurations/_DeployDev__Generate_Bootstrap_Launcher_and_deploy_plugin_dev_environment.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/Makefile b/Makefile index 3bd9d1f5..4c1c39b4 100644 --- a/Makefile +++ b/Makefile @@ -15,12 +15,17 @@ simple_run: bootstrap_deploy: sbt clean - sbt compile sbt gui sbt package copy sbt bs "project bootstrapProject" assembly sbt deploy +bootstrap_deploy_dev: + sbt clean + sbt gui + sbt package copy + sbt deployDev + create: sbt create sbt fetch @@ -29,6 +34,9 @@ create: deploy: sbt deploy +deploy_dev: + sbt deployDev + fetch: sbt fetch diff --git a/build.sbt b/build.sbt index ee3c78f6..c2d0849d 100644 --- a/build.sbt +++ b/build.sbt @@ -65,7 +65,7 @@ libraryDependencies += "net.dv8tion" % "JDA" % "3.8.3_463" libraryDependencies += "com.fazecast" % "jSerialComm" % "[2.0.0,3.0.0)" // Socket.io -libraryDependencies += "io.socket" % "socket.io-client"% "1.0.0" +libraryDependencies += "io.socket" % "socket.io-client" % "1.0.0" // --------------------------------------------------------------------------------------------------------------------- // PLUGIN FRAMEWORK DEFINITIONS // --------------------------------------------------------------------------------------------------------------------- @@ -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 plugin developers, fills deployDev folder.") lazy val gui = TaskKey[Unit]("gui", "Installs GUI dependencies and builds it using npm.") pluginBuildFileName := "plugins.sbt" @@ -97,6 +98,7 @@ fetch := BuildUtility(streams.value.log).fetchPluginsTask(pluginFolderNames.valu 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) +deployDev := BootstrapUtility.prepareDevDeploymentTask(streams.value.log, scalaMajorVersion, apiProjectPath.value, libraryDependencies.value.toList) gui := BuildUtility(streams.value.log).guiTask(guiProjectPath.value, streams.value.cacheDirectory / "gui") Compile / packageBin := { @@ -111,6 +113,7 @@ Compile / unmanagedJars := (crossTarget.value ** "chatoverflow-gui*.jar").classp // --------------------------------------------------------------------------------------------------------------------- // Util task for bs, gets a dependency list kinda like "sbt dependencyList", but only includes deps required for runtime +// Filters out all chatoverflow modules, because those are not actual dependencies. lazy val getDependencyList = Def.task[List[ModuleID]] { // only get deps required for runtime and not for anything else like testing val updateReport = update.value.configuration(ConfigRef("runtime")) @@ -119,6 +122,8 @@ lazy val getDependencyList = Def.task[List[ModuleID]] { List() } else { updateReport.get.modules.map(m => m.module).toList + .filterNot(m => m.name == s"chatoverflow-api_$scalaMajorVersion" || + m.name == s"chatoverflow_$scalaMajorVersion") } } diff --git a/deployment-files/ChatOverflow.bat b/deployment-files/end-user/ChatOverflow.bat similarity index 100% rename from deployment-files/ChatOverflow.bat rename to deployment-files/end-user/ChatOverflow.bat diff --git a/deployment-files/ChatOverflow.command b/deployment-files/end-user/ChatOverflow.command similarity index 100% rename from deployment-files/ChatOverflow.command rename to deployment-files/end-user/ChatOverflow.command diff --git a/deployment-files/ChatOverflow.sh b/deployment-files/end-user/ChatOverflow.sh similarity index 100% rename from deployment-files/ChatOverflow.sh rename to deployment-files/end-user/ChatOverflow.sh diff --git a/deployment-files/LICENSE b/deployment-files/end-user/LICENSE similarity index 100% rename from deployment-files/LICENSE rename to deployment-files/end-user/LICENSE diff --git a/deployment-files/README.html b/deployment-files/end-user/README.html similarity index 100% rename from deployment-files/README.html rename to deployment-files/end-user/README.html diff --git a/deployment-files/plugin-dev/.idea/runConfigurations/Clean__sbt_clean_.xml b/deployment-files/plugin-dev/.idea/runConfigurations/Clean__sbt_clean_.xml new file mode 100644 index 00000000..50c2f725 --- /dev/null +++ b/deployment-files/plugin-dev/.idea/runConfigurations/Clean__sbt_clean_.xml @@ -0,0 +1,19 @@ + + + + + + + + + + \ No newline at end of file diff --git a/deployment-files/plugin-dev/.idea/runConfigurations/Create_Plugin__sbt_create_fetch_reload_.xml b/deployment-files/plugin-dev/.idea/runConfigurations/Create_Plugin__sbt_create_fetch_reload_.xml new file mode 100644 index 00000000..25b89651 --- /dev/null +++ b/deployment-files/plugin-dev/.idea/runConfigurations/Create_Plugin__sbt_create_fetch_reload_.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/deployment-files/plugin-dev/.idea/runConfigurations/Fetch_plugins__sbt_fetch_.xml b/deployment-files/plugin-dev/.idea/runConfigurations/Fetch_plugins__sbt_fetch_.xml new file mode 100644 index 00000000..12638c0d --- /dev/null +++ b/deployment-files/plugin-dev/.idea/runConfigurations/Fetch_plugins__sbt_fetch_.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/deployment-files/plugin-dev/.idea/runConfigurations/List_plugin_versions__sbt_version_.xml b/deployment-files/plugin-dev/.idea/runConfigurations/List_plugin_versions__sbt_version_.xml new file mode 100644 index 00000000..9fe721ce --- /dev/null +++ b/deployment-files/plugin-dev/.idea/runConfigurations/List_plugin_versions__sbt_version_.xml @@ -0,0 +1,19 @@ + + + + + + + + + + \ No newline at end of file diff --git a/deployment-files/plugin-dev/.idea/runConfigurations/Package_and_copy_plugins__sbt_package_copy_.xml b/deployment-files/plugin-dev/.idea/runConfigurations/Package_and_copy_plugins__sbt_package_copy_.xml new file mode 100644 index 00000000..77b18cc7 --- /dev/null +++ b/deployment-files/plugin-dev/.idea/runConfigurations/Package_and_copy_plugins__sbt_package_copy_.xml @@ -0,0 +1,19 @@ + + + + + + + + + + \ No newline at end of file diff --git a/deployment-files/plugin-dev/.idea/runConfigurations/Reload__sbt_reload_.xml b/deployment-files/plugin-dev/.idea/runConfigurations/Reload__sbt_reload_.xml new file mode 100644 index 00000000..e01a6513 --- /dev/null +++ b/deployment-files/plugin-dev/.idea/runConfigurations/Reload__sbt_reload_.xml @@ -0,0 +1,19 @@ + + + + + + + + + + \ No newline at end of file diff --git a/deployment-files/plugin-dev/.idea/runConfigurations/_Advanced__Full_Reload_and_Run_ChatOverflow.xml b/deployment-files/plugin-dev/.idea/runConfigurations/_Advanced__Full_Reload_and_Run_ChatOverflow.xml new file mode 100644 index 00000000..401c9115 --- /dev/null +++ b/deployment-files/plugin-dev/.idea/runConfigurations/_Advanced__Full_Reload_and_Run_ChatOverflow.xml @@ -0,0 +1,20 @@ + + + + \ No newline at end of file diff --git a/deployment-files/plugin-dev/.idea/runConfigurations/_Simple__Rebuild_plugins_and_Run_ChatOverflow.xml b/deployment-files/plugin-dev/.idea/runConfigurations/_Simple__Rebuild_plugins_and_Run_ChatOverflow.xml new file mode 100644 index 00000000..3b605953 --- /dev/null +++ b/deployment-files/plugin-dev/.idea/runConfigurations/_Simple__Rebuild_plugins_and_Run_ChatOverflow.xml @@ -0,0 +1,16 @@ + + + + diff --git a/deployment-files/plugin-dev/build.sbt b/deployment-files/plugin-dev/build.sbt new file mode 100644 index 00000000..17b6fc49 --- /dev/null +++ b/deployment-files/plugin-dev/build.sbt @@ -0,0 +1,45 @@ +// This is a stripped down version of the build.sbt found in the main framework. +// Its almost like the one from the framework but without some sbt tasks like 'deploy' that aren't needed for plugin developers +// and without dependencies, because those get their own generated file. + +// --------------------------------------------------------------------------------------------------------------------- +// 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) +) + +unmanagedBase := file("bin") + +// --------------------------------------------------------------------------------------------------------------------- +// 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 a162602c..f9dc2de1 100644 --- a/project/BootstrapUtility.scala +++ b/project/BootstrapUtility.scala @@ -70,12 +70,12 @@ object BootstrapUtility { logger info "Updating and modifying dependencies..." - // Modify dependencies: Remove ChatOverflow and opus-java, add scala library + // Modify dependencies: Remove opus-java, add scala library // opus-java is a virtual package which instructs sbt or any other build tool to get opus-java-api and opus-java-native. // Therefore it doesn't have a jar that needs to be downloaded and sbt includes the requested dependencies in the dependencyList. // So we can just ignore it as it can't be resolved and only need to include the requested deps in our xml. // Check https://github.com/discord-java/opus-java#opus-java-1 for more information on this. - val excludedDeps = List("chatoverflow", "chatoverflow-api", "opus-java") + val excludedDeps = List("opus-java") val filteredDeps = dependencyList.filter(d => !excludedDeps.contains(d.nameWithoutScalaVersion)) val modifiedDependencies = filteredDeps ++ @@ -92,59 +92,114 @@ 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 - */ + * Prepares the environment 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 + // Assuming, before this: clean, gui, bs, bootstrapProject/assembly, package // 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/end-user/" with all additional files (license, bat, etc.) withTaskInfo("PREPARE DEPLOYMENT", logger) { logger info "Started deployment process." - // First step: Preparing bin folder - logger info "Preparing 'bin/' folder." - createOrEmptyFolder("bin/") - - // Second step: Preparing deploy folder, copying bin folder, bootstrap launcher, etc. - logger info "Preparing 'deploy/' folder." + // First step: Create directory createOrEmptyFolder("deploy/") - createOrEmptyFolder("deploy/bin/") - - // Third step: Copying chat overflow files - logger info "Copying chat overflow files..." - - val sourceJarDirectories = List(s"target/scala-$scalaLibraryVersion/", - s"api/target/scala-$scalaLibraryVersion/") + // Second step: Create bin directories and copy all binaries val targetJarDirectories = List("bin", "deploy/bin") + prepareBinDirectories(logger, targetJarDirectories, scalaLibraryVersion, copyApi = true) - for (sourceDirectory <- sourceJarDirectories) { - copyJars(sourceDirectory, targetJarDirectories, logger) - } - - // Fourth step: Copy bootstrap launcher + // Third step: Copy bootstrap launcher copyJars(s"bootstrap/target/scala-$scalaLibraryVersion/", List("deploy/"), logger) // Last step: Copy additional files logger info "Copying additional deployment files..." - val deploymentFiles = new File("deployment-files/") + val deploymentFiles = new File("deployment-files/end-user/") 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." } } } + /** + * Prepares the environment for a deployment for plugin developers. + * Should be called after package and apiProject/packagedArtifacts task. + * + * @param logger the sbt logger + * @param scalaLibraryVersion the scala library major version + * @param apiProjectPath the path to the api project. Used to copy the api into the deployDev directory + * @param dependencies the dependencies of the framework. Used to create a sbt file with them. + */ + def prepareDevDeploymentTask(logger: ManagedLogger, scalaLibraryVersion: String, apiProjectPath: String, dependencies: List[ModuleID]): Unit = { + // Assuming, before this: clean, gui and package + // Assuming: Hardcoded "bin/" and "deployDev/" folders + // Assuming: A folder called "deployment-files/plugin-dev/" with more additional files for plugin developers + + withTaskInfo("PREPARE DEV DEPLOYMENT", logger) { + + logger info "Started deployment process for plugin dev environment." + + // 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")) // 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", + "PluginLanguage.scala", "PluginMetadata.scala", "SbtFile.scala", "APIUtility.scala", "RequirementsFile.scala", + "dependencies.sbt") + + for (filepath <- requiredBuildFiles) { + val origFile = new File(s"project/$filepath") + val deployFile = new File(s"deployDev/project/$filepath") + sbt.IO.copyFile(origFile, deployFile) + } + + // Fifth step: Create sbt files containing all dependencies + val depFile = new SbtFile(dependencies) + sbt.IO.write(new File("deployDev/dependencies.sbt"), depFile.toString) + + // Last step: Copy additional files + val devDeploymentFiles = new File("deployment-files/plugin-dev/") + if (!devDeploymentFiles.exists()) { + logger warn "Unable to find dev deployment files." + } else { + sbt.IO.copyDirectory(devDeploymentFiles, new File("deployDev/")) + logger info "Finished copying additional dev deployment files." + } + } + } + + private def prepareBinDirectories(logger: ManagedLogger, targetDirs: List[String], scalaLibraryVersion: String, copyApi: Boolean): Unit = { + // First prepare all bin folders + targetDirs.foreach(d => { + logger info s"Preparing '$d' folder." + createOrEmptyFolder(d) + }) + + // Then copy all binary files + logger info "Copying chat overflow files..." + val sourceJarDirectories = if (copyApi) + List(s"target/scala-$scalaLibraryVersion/", s"api/target/scala-$scalaLibraryVersion/") + else + List(s"target/scala-$scalaLibraryVersion/") + + sourceJarDirectories.foreach(d => copyJars(d, targetDirs, logger)) + } + /** * Creates a directory or empties it, by recursively deleting files and sub directories. */ @@ -155,18 +210,18 @@ object BootstrapUtility { if (file.isFile) { file.delete() } else { - createOrEmptyFolder(file.getAbsolutePath) - file.delete() + createOrEmptyFolder(file.getAbsolutePath) + file.delete() } } } else { - folder.mkdir() + folder.mkdirs() } } /** - * Copies all jar files from the source to all target directories. - */ + * 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")) diff --git a/project/BuildUtility.scala b/project/BuildUtility.scala index 774126f1..1894986d 100644 --- a/project/BuildUtility.scala +++ b/project/BuildUtility.scala @@ -31,11 +31,13 @@ import scala.io.Source class BuildUtility(logger: ManagedLogger) { /** - * Searches for plugins in plugin directories, builds the plugin build file. - * - * @param pluginSourceFolderNames All folder names, containing plugin source code. Defined in build.sbt. - * @param pluginBuildFileName The generated sbt build file, containing all sub project references. Defined in build.sbt. - */ + * Searches for plugins in plugin directories, builds the plugin build file. + * + * @param pluginSourceFolderNames All folder names, containing plugin source code. Defined in build.sbt. + * @param pluginBuildFileName The generated sbt build file, containing all sub project references. Defined in build.sbt. + * @param pluginTargetFolderNames The name of the directory, in which all plugins should be copied. + * @param apiProjectPath The path of the api project. Chosen over apiJarPath if possible. + */ def fetchPluginsTask(pluginSourceFolderNames: List[String], pluginBuildFileName: String, pluginTargetFolderNames: List[String], apiProjectPath: String): Unit = { withTaskInfo("FETCH PLUGINS") { @@ -49,7 +51,7 @@ class BuildUtility(logger: ManagedLogger) { val allPlugins = getAllPlugins(pluginSourceFolderNames) // Create a sbt file with all plugin dependencies (sub projects) - val sbtFile = new SbtFile("", "", allPlugins, apiProjectPath, defineRoot = true) + val sbtFile = new SbtFile("", "", allPlugins, apiProjectPath, defineRoot = true, List()) if (sbtFile.save(pluginBuildFileName)) { logger info s"Successfully updated plugin file at '$pluginBuildFileName'." @@ -249,12 +251,12 @@ 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] = { + * 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 { @@ -287,5 +289,4 @@ object BuildUtility { // Info when task stopped (better log comprehension) logger info s"Finished custom task: $taskName" } - } \ No newline at end of file diff --git a/project/SbtFile.scala b/project/SbtFile.scala index 6210bebb..1417dbd9 100644 --- a/project/SbtFile.scala +++ b/project/SbtFile.scala @@ -1,28 +1,39 @@ import java.io.{BufferedWriter, File, FileWriter, IOException} +import sbt.librarymanagement.{CrossVersion, ModuleID} + /** - * Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files. - * - * @param name the name of a sbt project - * @param version the version of a sbt project - * @param plugins list of paths of sub projects - * @param apiProjectPath the path of a base api project which every project depends on - * @param defineRoot true, if a root project (".") should be defined in the sbt file - */ -class SbtFile(var name: String, var version: String, var plugins: List[Plugin], var apiProjectPath: String, var defineRoot: Boolean) { + * Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files. + * + * @param name the name of a sbt project + * @param version the version of a sbt project + * @param plugins list of paths of sub projects + * @param apiProjectPath the path of a base api project which every project depends on + * @param defineRoot true, if a root project (".") should be defined in the sbt file + * @param dependencies library dependencies to add to the sbt file + */ +class SbtFile(val name: String, val version: String, val plugins: List[Plugin], val apiProjectPath: String, + val defineRoot: Boolean, dependencies: List[ModuleID]) { /** * Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files. * * @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) + 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. */ def this() = this("", "") + /** + * Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files. + * + * @param dependencies library dependencies to add to the sbt file + */ + def this(dependencies: List[ModuleID]) = this("", "", List(), "", false, dependencies) + /** * Tries to save the sbt files content into a defined directory. * @@ -62,16 +73,14 @@ class SbtFile(var name: String, var version: String, var plugins: List[Plugin], sbtContent append "\nversion := \"%s\"".format(version.replaceAll("\\\\", "")) } - if (plugins.nonEmpty) { - for (plugin <- plugins) { - var pluginLine = "\nlazy val `%s` = (project in file(\"%s\"))".format(plugin.normalizedName, plugin.pluginDirectoryPath) - - if (apiProjectPath != "") { - pluginLine += ".dependsOn(apiProject)" - } + for (plugin <- plugins) { + var pluginLine = "\nlazy val `%s` = (project in file(\"%s\"))".format(plugin.normalizedName, plugin.pluginDirectoryPath) - sbtContent append pluginLine + if (apiProjectPath != "") { + pluginLine += ".dependsOn(apiProject)" } + + sbtContent append pluginLine } if (apiProjectPath != "") { @@ -89,6 +98,32 @@ class SbtFile(var name: String, var version: String, var plugins: List[Plugin], sbtContent append rootLine } + if (dependencies.nonEmpty) { + 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 => 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("")) + } } diff --git a/project/assembly.sbt b/project/assembly.sbt deleted file mode 100644 index 813ce170..00000000 --- a/project/assembly.sbt +++ /dev/null @@ -1 +0,0 @@ -addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9") \ No newline at end of file diff --git a/project/dependencies.sbt b/project/dependencies.sbt new file mode 100644 index 00000000..b1d55893 --- /dev/null +++ b/project/dependencies.sbt @@ -0,0 +1,2 @@ +// JSON lib (Jackson) used for parsing the GUI version in the package.json file +libraryDependencies += "org.json4s" %% "json4s-jackson" % "3.5.2" \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index 9e16c189..e4bb4c08 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,2 @@ addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2") - -// JSON lib (Jackson) used for parsing the GUI version in the package.json file -libraryDependencies += "org.json4s" %% "json4s-jackson" % "3.5.2" \ No newline at end of file +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9") \ No newline at end of file