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
Prev Previous commit
Next Next commit
Update fetch task to support plugin developer environment
  • Loading branch information
hlxid committed Jul 27, 2019
commit e249ff90d951e5aa134608d1160547a0faf9d530

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ guiProjectPath := "gui"

create := PluginCreateWizard(streams.value.log).createPluginTask(pluginFolderNames.value)
fetch := BuildUtility(streams.value.log).fetchPluginsTask(pluginFolderNames.value, pluginBuildFileName.value,
pluginTargetFolderNames.value, apiProjectPath.value)
pluginTargetFolderNames.value, apiProjectPath.value, apiJarPath = "")
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, dev = false)
Expand Down
4 changes: 1 addition & 3 deletions deployment-files-dev/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ inThisBuild(List(
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.")
Expand All @@ -34,9 +33,8 @@ lazy val copy = TaskKey[Unit]("copy", "Copies all packaged plugin jars to the ta
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)
pluginTargetFolderNames.value, "", "bin/")
copy := BuildUtility(streams.value.log).copyPluginsTask(pluginFolderNames.value, pluginTargetFolderNames.value, scalaMajorVersion)
17 changes: 10 additions & 7 deletions project/BuildUtility.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ import sbt.util.{FileFunction, FilesInfo}
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.
* @param apiJarPath The path of a directory which is containing all api jars. Chosen if apiProjectPath is empty.
*/
def fetchPluginsTask(pluginSourceFolderNames: List[String], pluginBuildFileName: String,
pluginTargetFolderNames: List[String], apiProjectPath: String): Unit = {
pluginTargetFolderNames: List[String], apiProjectPath: String, apiJarPath: String): Unit = {
withTaskInfo("FETCH PLUGINS") {

// Check validity of plugin source folders
Expand All @@ -46,7 +49,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, apiJarPath, defineRoot = true)

if (sbtFile.save(pluginBuildFileName)) {
logger info s"Successfully updated plugin file at '$pluginBuildFileName'."
Expand Down
47 changes: 28 additions & 19 deletions project/SbtFile.scala
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import java.io.{BufferedWriter, File, FileWriter, IOException}

/**
* 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 apiJarDirPath the path of a directory containing jar files over the api. Designed to be a fallback to apiProjectPath
* @param defineRoot true, if a root project (".") should be defined in the sbt file
*/
class SbtFile(val name: String, val version: String, val plugins: List[Plugin], val apiProjectPath: String,
val apiJarDirPath: String, val 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
*/
def this(name: String, version: String) = this(name, version, List(), "", false)
def this(name: String, version: String) = this(name, version, List(), "", "", false)

/**
* 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 @@ -62,25 +64,32 @@ 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)
for (plugin <- plugins) {
var pluginLine = "\nlazy val `%s` = (project in file(\"%s\"))".format(plugin.normalizedName, plugin.pluginDirectoryPath)

if (apiProjectPath != "") {
pluginLine += ".dependsOn(apiProject)"
}

sbtContent append pluginLine
if (apiProjectPath != "") {
pluginLine += ".dependsOn(apiProject)"
} else if (apiJarDirPath != "") {
pluginLine += ".settings(Compile / unmanagedJars := jars)"
}

sbtContent append pluginLine
}

if (apiProjectPath != "") {
sbtContent append "\n\nlazy val apiProject = project in file(\"%s\")".format(apiProjectPath)
} else if (apiJarDirPath != "") {
sbtContent append "\nlazy val jars: Classpath = (file(\"%s\") ** \"chatoverflow-api*.jar\").classpath\n".format(apiJarDirPath)
}

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(("apiProject" +: plugins.map(p => s"`${p.normalizedName}`")).mkString(", "))
.format(aggregateElems.mkString(", "))

if (apiProjectPath != "") {
rootLine += ".dependsOn(apiProject)"
Expand Down