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

Commit e249ff9

Browse files
committed
Update fetch task to support plugin developer environment
1 parent d404708 commit e249ff9

File tree

5 files changed

+41
-31
lines changed

5 files changed

+41
-31
lines changed

.idea/runConfigurations/_DeployDev__Generate_Bootstrap_Launcher_and_deploy_plugin_dev_environment.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ guiProjectPath := "gui"
9494

9595
create := PluginCreateWizard(streams.value.log).createPluginTask(pluginFolderNames.value)
9696
fetch := BuildUtility(streams.value.log).fetchPluginsTask(pluginFolderNames.value, pluginBuildFileName.value,
97-
pluginTargetFolderNames.value, apiProjectPath.value)
97+
pluginTargetFolderNames.value, apiProjectPath.value, apiJarPath = "")
9898
copy := BuildUtility(streams.value.log).copyPluginsTask(pluginFolderNames.value, pluginTargetFolderNames.value, scalaMajorVersion)
9999
bs := BootstrapUtility.bootstrapGenTask(streams.value.log, s"$scalaMajorVersion$scalaMinorVersion", getDependencyList.value)
100100
deploy := BootstrapUtility.prepareDeploymentTask(streams.value.log, scalaMajorVersion, dev = false)

deployment-files-dev/build.sbt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ inThisBuild(List(
2424
lazy val pluginBuildFileName = settingKey[String]("The filename of the plugin build file. Remember to gitignore it!")
2525
lazy val pluginFolderNames = settingKey[List[String]]("The folder names of all plugin source directories.")
2626
lazy val pluginTargetFolderNames = settingKey[List[String]]("The folder names of compiled and packaged plugins. Remember to gitignore these!")
27-
lazy val apiProjectPath = settingKey[String]("The path to the api sub project. Remember to gitignore it!")
2827

2928
// Plugin framework tasks
3029
lazy val create = TaskKey[Unit]("create", "Creates a new plugin. Interactive command using the console.")
@@ -34,9 +33,8 @@ lazy val copy = TaskKey[Unit]("copy", "Copies all packaged plugin jars to the ta
3433
pluginBuildFileName := "plugins.sbt"
3534
pluginFolderNames := List("plugins-public", "plugins-private")
3635
pluginTargetFolderNames := List("plugins", s"target/scala-$scalaMajorVersion/plugins")
37-
apiProjectPath := "api"
3836

3937
create := PluginCreateWizard(streams.value.log).createPluginTask(pluginFolderNames.value)
4038
fetch := BuildUtility(streams.value.log).fetchPluginsTask(pluginFolderNames.value, pluginBuildFileName.value,
41-
pluginTargetFolderNames.value, apiProjectPath.value)
39+
pluginTargetFolderNames.value, "", "bin/")
4240
copy := BuildUtility(streams.value.log).copyPluginsTask(pluginFolderNames.value, pluginTargetFolderNames.value, scalaMajorVersion)

project/BuildUtility.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ import sbt.util.{FileFunction, FilesInfo}
2828
class BuildUtility(logger: ManagedLogger) {
2929

3030
/**
31-
* Searches for plugins in plugin directories, builds the plugin build file.
32-
*
33-
* @param pluginSourceFolderNames All folder names, containing plugin source code. Defined in build.sbt.
34-
* @param pluginBuildFileName The generated sbt build file, containing all sub project references. Defined in build.sbt.
35-
*/
31+
* Searches for plugins in plugin directories, builds the plugin build file.
32+
*
33+
* @param pluginSourceFolderNames All folder names, containing plugin source code. Defined in build.sbt.
34+
* @param pluginBuildFileName The generated sbt build file, containing all sub project references. Defined in build.sbt.
35+
* @param pluginTargetFolderNames The name of the directory, in which all plugins should be copied.
36+
* @param apiProjectPath The path of the api project. Chosen over apiJarPath if possible.
37+
* @param apiJarPath The path of a directory which is containing all api jars. Chosen if apiProjectPath is empty.
38+
*/
3639
def fetchPluginsTask(pluginSourceFolderNames: List[String], pluginBuildFileName: String,
37-
pluginTargetFolderNames: List[String], apiProjectPath: String): Unit = {
40+
pluginTargetFolderNames: List[String], apiProjectPath: String, apiJarPath: String): Unit = {
3841
withTaskInfo("FETCH PLUGINS") {
3942

4043
// Check validity of plugin source folders
@@ -46,7 +49,7 @@ class BuildUtility(logger: ManagedLogger) {
4649
val allPlugins = getAllPlugins(pluginSourceFolderNames)
4750

4851
// Create a sbt file with all plugin dependencies (sub projects)
49-
val sbtFile = new SbtFile("", "", allPlugins, apiProjectPath, defineRoot = true)
52+
val sbtFile = new SbtFile("", "", allPlugins, apiProjectPath, apiJarPath, defineRoot = true)
5053

5154
if (sbtFile.save(pluginBuildFileName)) {
5255
logger info s"Successfully updated plugin file at '$pluginBuildFileName'."

project/SbtFile.scala

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import java.io.{BufferedWriter, File, FileWriter, IOException}
22

33
/**
4-
* Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files.
5-
*
6-
* @param name the name of a sbt project
7-
* @param version the version of a sbt project
8-
* @param plugins list of paths of sub projects
9-
* @param apiProjectPath the path of a base api project which every project depends on
10-
* @param defineRoot true, if a root project (".") should be defined in the sbt file
11-
*/
12-
class SbtFile(var name: String, var version: String, var plugins: List[Plugin], var apiProjectPath: String, var defineRoot: Boolean) {
4+
* Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files.
5+
*
6+
* @param name the name of a sbt project
7+
* @param version the version of a sbt project
8+
* @param plugins list of paths of sub projects
9+
* @param apiProjectPath the path of a base api project which every project depends on
10+
* @param apiJarDirPath the path of a directory containing jar files over the api. Designed to be a fallback to apiProjectPath
11+
* @param defineRoot true, if a root project (".") should be defined in the sbt file
12+
*/
13+
class SbtFile(val name: String, val version: String, val plugins: List[Plugin], val apiProjectPath: String,
14+
val apiJarDirPath: String, val defineRoot: Boolean) {
1315
/**
1416
* Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files.
1517
*
1618
* @param name the name of a sbt project
1719
* @param version the version of a sbt project
1820
*/
19-
def this(name: String, version: String) = this(name, version, List(), "", false)
21+
def this(name: String, version: String) = this(name, version, List(), "", "", false)
2022

2123
/**
2224
* Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files.
@@ -62,25 +64,32 @@ class SbtFile(var name: String, var version: String, var plugins: List[Plugin],
6264
sbtContent append "\nversion := \"%s\"".format(version.replaceAll("\\", ""))
6365
}
6466

65-
if (plugins.nonEmpty) {
66-
for (plugin <- plugins) {
67-
var pluginLine = "\nlazy val `%s` = (project in file(\"%s\"))".format(plugin.normalizedName, plugin.pluginDirectoryPath)
67+
for (plugin <- plugins) {
68+
var pluginLine = "\nlazy val `%s` = (project in file(\"%s\"))".format(plugin.normalizedName, plugin.pluginDirectoryPath)
6869

69-
if (apiProjectPath != "") {
70-
pluginLine += ".dependsOn(apiProject)"
71-
}
72-
73-
sbtContent append pluginLine
70+
if (apiProjectPath != "") {
71+
pluginLine += ".dependsOn(apiProject)"
72+
} else if (apiJarDirPath != "") {
73+
pluginLine += ".settings(Compile / unmanagedJars := jars)"
7474
}
75+
76+
sbtContent append pluginLine
7577
}
7678

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

8185
if (defineRoot) {
86+
var aggregateElems = plugins.map(p => s"`${p.normalizedName}`")
87+
if (apiProjectPath != "") {
88+
aggregateElems = "apiProject" +: aggregateElems
89+
}
90+
8291
var rootLine = "\n\nlazy val root = (project in file(\".\")).aggregate(%s)"
83-
.format(("apiProject" +: plugins.map(p => s"`${p.normalizedName}`")).mkString(", "))
92+
.format(aggregateElems.mkString(", "))
8493

8594
if (apiProjectPath != "") {
8695
rootLine += ".dependsOn(apiProject)"

0 commit comments

Comments
 (0)