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

Commit d0c3dce

Browse files
committed
Generate dependencies for plugin environment automatically
1 parent d0bf391 commit d0c3dce

File tree

5 files changed

+36
-58
lines changed

5 files changed

+36
-58
lines changed

build.sbt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,15 @@ fetch := BuildUtility(streams.value.log).fetchPluginsTask(pluginFolderNames.valu
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)
101-
deployDev := BootstrapUtility.prepareDevDeploymentTask(streams.value.log, scalaMajorVersion)
101+
deployDev := BootstrapUtility.prepareDevDeploymentTask(streams.value.log, scalaMajorVersion, getDependencyList.value)
102102
gui := BuildUtility(streams.value.log).guiTask(guiProjectPath.value, streams.value.cacheDirectory / "gui")
103103

104104
// ---------------------------------------------------------------------------------------------------------------------
105105
// UTIL
106106
// ---------------------------------------------------------------------------------------------------------------------
107107

108108
// Util task for bs, gets a dependency list kinda like "sbt dependencyList", but only includes deps required for runtime
109+
// Filters out all chatoverflow modules, because those are not actual dependencies.
109110
lazy val getDependencyList = Def.task[List[ModuleID]] {
110111
// only get deps required for runtime and not for anything else like testing
111112
val updateReport = update.value.configuration(ConfigRef("runtime"))
@@ -114,6 +115,8 @@ lazy val getDependencyList = Def.task[List[ModuleID]] {
114115
List()
115116
} else {
116117
updateReport.get.modules.map(m => m.module).toList
118+
.filterNot(m => m.name == s"chatoverflow-api_$scalaMajorVersion" ||
119+
m.name == s"chatoverflow_$scalaMajorVersion")
117120
}
118121
}
119122

deployment-files-dev/build.sbt

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This is a stripped down version of the build.sbt found in the main framework.
2-
// Its almost like the one from the framework but without some sbt tasks like 'deploy' that aren't needed for plugin developers.
2+
// Its almost like the one from the framework but without some sbt tasks like 'deploy' that aren't needed for plugin developers
3+
// and without dependencies, because those get their own generated file.
34

45
// ---------------------------------------------------------------------------------------------------------------------
56
// PROJECT INFORMATION
@@ -16,56 +17,6 @@ inThisBuild(List(
1617
retrieveManaged := false)
1718
)
1819

19-
// ---------------------------------------------------------------------------------------------------------------------
20-
// LIBRARY DEPENDENCIES
21-
// ---------------------------------------------------------------------------------------------------------------------
22-
23-
// Command Line Parsing
24-
libraryDependencies += "com.github.scopt" %% "scopt" % "3.5.0"
25-
26-
// log4j Logger
27-
libraryDependencies += "org.slf4j" % "slf4j-log4j12" % "1.7.22"
28-
29-
// Scalatra (REST, ...)
30-
libraryDependencies ++= Seq(
31-
"org.scalatra" %% "scalatra" % "2.6.+",
32-
"org.scalatra" %% "scalatra-scalate" % "2.6.+",
33-
"org.scalatra" %% "scalatra-specs2" % "2.6.+",
34-
"ch.qos.logback" % "logback-classic" % "1.2.3" % "provided",
35-
"org.eclipse.jetty" % "jetty-webapp" % "9.4.7.v20170914" % "provided",
36-
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
37-
"org.scalatra" %% "scalatra-json" % "2.6.3",
38-
"org.scalatra" %% "scalatra-swagger" % "2.6.5",
39-
)
40-
41-
// JSON Lib (Jackson)
42-
libraryDependencies += "org.json4s" %% "json4s-jackson" % "3.5.2"
43-
44-
// PIRCBotX
45-
libraryDependencies += "org.pircbotx" % "pircbotx" % "2.1"
46-
47-
// Reflections API for annotation indexing
48-
libraryDependencies += "org.reflections" % "reflections" % "0.9.11"
49-
50-
// Akka Actors
51-
libraryDependencies ++= Seq(
52-
"com.typesafe.akka" %% "akka-actor" % "2.5.18",
53-
//"com.typesafe.akka" %% "akka-testkit" % "2.5.18" % Test
54-
)
55-
56-
// Google GSON
57-
libraryDependencies += "com.google.code.gson" % "gson" % "2.8.5"
58-
59-
// JDA
60-
resolvers += "jcenter-bintray" at "http://jcenter.bintray.com"
61-
libraryDependencies += "net.dv8tion" % "JDA" % "3.8.3_463"
62-
63-
//Serial Communication
64-
libraryDependencies += "com.fazecast" % "jSerialComm" % "[2.0.0,3.0.0)"
65-
66-
// Socket.io
67-
libraryDependencies += "io.socket" % "socket.io-client"% "1.0.0"
68-
6920
unmanagedBase := file("bin")
7021

7122
// ---------------------------------------------------------------------------------------------------------------------

project/BootstrapUtility.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ object BootstrapUtility {
7070

7171
logger info "Updating and modifying dependencies..."
7272

73-
// Modify dependencies: Remove ChatOverflow and opus-java, add scala library
73+
// Modify dependencies: Remove opus-java, add scala library
7474
// opus-java is a virtual package which instructs sbt or any other build tool to get opus-java-api and opus-java-native.
7575
// Therefore it doesn't have a jar that needs to be downloaded and sbt includes the requested dependencies in the dependencyList.
7676
// So we can just ignore it as it can't be resolved and only need to include the requested deps in our xml.
7777
// Check https://github.com/discord-java/opus-java#opus-java-1 for more information on this.
78-
val excludedDeps = List("chatoverflow", "chatoverflow-api", "opus-java")
78+
val excludedDeps = List("opus-java")
7979
val filteredDeps = dependencyList.filter(d => !excludedDeps.contains(d.nameWithoutScalaVersion))
8080

8181
val modifiedDependencies = filteredDeps ++
@@ -135,7 +135,7 @@ object BootstrapUtility {
135135
* @param logger the sbt logger
136136
* @param scalaLibraryVersion the scala library major version
137137
*/
138-
def prepareDevDeploymentTask(logger: ManagedLogger, scalaLibraryVersion: String): Unit = {
138+
def prepareDevDeploymentTask(logger: ManagedLogger, scalaLibraryVersion: String, dependencies: List[ModuleID]): Unit = {
139139
// Assuming, before this: clean, package and apiProject/packagedArtifacts
140140
// Assuming: Hardcoded "bin/" and "deployDev/" folders
141141
// Assuming: A folder called "deployment-files-dev" with more additional files for plugin developers
@@ -161,6 +161,10 @@ object BootstrapUtility {
161161
sbt.IO.copyFile(origFile, deployFile)
162162
}
163163

164+
// Fourth step: Create sbt files containing all dependencies
165+
val depFile = new SbtFile(dependencies)
166+
sbt.IO.write(new File("deployDev/dependencies.sbt"), depFile.toString)
167+
164168
// Last step: Copy additional files
165169
val devDeploymentFiles = new File("deployment-files-dev/")
166170
if (!devDeploymentFiles.exists()) {

project/BuildUtility.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class BuildUtility(logger: ManagedLogger) {
4949
val allPlugins = getAllPlugins(pluginSourceFolderNames)
5050

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

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

project/SbtFile.scala

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

3+
import sbt.librarymanagement.ModuleID
4+
35
/**
46
* Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files.
57
*
@@ -9,22 +11,30 @@ import java.io.{BufferedWriter, File, FileWriter, IOException}
911
* @param apiProjectPath the path of a base api project which every project depends on
1012
* @param apiJarDirPath the path of a directory containing jar files over the api. Designed to be a fallback to apiProjectPath
1113
* @param defineRoot true, if a root project (".") should be defined in the sbt file
14+
* @param dependencies library dependencies to add to the sbt file
1215
*/
1316
class SbtFile(val name: String, val version: String, val plugins: List[Plugin], val apiProjectPath: String,
14-
val apiJarDirPath: String, val defineRoot: Boolean) {
17+
val apiJarDirPath: String, val defineRoot: Boolean, dependencies: List[ModuleID]) {
1518
/**
1619
* Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files.
1720
*
1821
* @param name the name of a sbt project
1922
* @param version the version of a sbt project
2023
*/
21-
def this(name: String, version: String) = this(name, version, List(), "", "", false)
24+
def this(name: String, version: String) = this(name, version, List(), "", "", false, List())
2225

2326
/**
2427
* Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files.
2528
*/
2629
def this() = this("", "")
2730

31+
/**
32+
* Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files.
33+
*
34+
* @param dependencies library dependencies to add to the sbt file
35+
*/
36+
def this(dependencies: List[ModuleID]) = this("", "", List(), "", "", false, dependencies)
37+
2838
/**
2939
* Tries to save the sbt files content into a defined directory.
3040
*
@@ -98,6 +108,16 @@ class SbtFile(val name: String, val version: String, val plugins: List[Plugin],
98108
sbtContent append rootLine
99109
}
100110

111+
if (dependencies.nonEmpty) {
112+
sbtContent append "\nresolvers += \"jcenter-bintray\" at \"http://jcenter.bintray.com\"\n"
113+
114+
// Note that the %% in the string are required to escape the string formatter and will turn into a single %
115+
val depString = dependencies.map(m => "\"%s\" %% \"%s\" %% \"%s\"".format(m.organization, m.name, m.revision))
116+
.mkString(" ", ",\n ", "")
117+
118+
sbtContent append s"libraryDependencies ++= Seq(\n$depString\n)\n"
119+
}
120+
101121
sbtContent.mkString
102122
}
103123
}

0 commit comments

Comments
 (0)