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

Commit 2d77b0f

Browse files
committed
Add a deployDev task that copies additional deployment files for plugin devs
1 parent f3ee424 commit 2d77b0f

File tree

4 files changed

+94
-37
lines changed

4 files changed

+94
-37
lines changed

build.sbt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ lazy val fetch = TaskKey[Unit]("fetch", "Searches for plugins in plugin director
8383
lazy val copy = TaskKey[Unit]("copy", "Copies all packaged plugin jars to the target plugin folder.")
8484
lazy val bs = TaskKey[Unit]("bs", "Updates the bootstrap project with current dependencies and chat overflow jars.")
8585
lazy val deploy = TaskKey[Unit]("deploy", "Prepares the environment for deployment, fills deploy folder.")
86+
lazy val deployDev = TaskKey[Unit]("deployDev", "Prepares the environment for deployment, fills deploy folder.")
8687
lazy val gui = TaskKey[Unit]("gui", "Installs GUI dependencies and builds it using npm.")
8788

8889
pluginBuildFileName := "plugins.sbt"
@@ -96,7 +97,8 @@ fetch := BuildUtility(streams.value.log).fetchPluginsTask(pluginFolderNames.valu
9697
pluginTargetFolderNames.value, apiProjectPath.value)
9798
copy := BuildUtility(streams.value.log).copyPluginsTask(pluginFolderNames.value, pluginTargetFolderNames.value, scalaMajorVersion)
9899
bs := BootstrapUtility.bootstrapGenTask(streams.value.log, s"$scalaMajorVersion$scalaMinorVersion", getDependencyList.value)
99-
deploy := BootstrapUtility.prepareDeploymentTask(streams.value.log, scalaMajorVersion)
100+
deploy := BootstrapUtility.prepareDeploymentTask(streams.value.log, scalaMajorVersion, dev = false)
101+
deployDev := BootstrapUtility.prepareDeploymentTask(streams.value.log, scalaMajorVersion, dev = true)
100102
gui := BuildUtility(streams.value.log).guiTask(guiProjectPath.value, streams.value.cacheDirectory / "gui")
101103

102104
// ---------------------------------------------------------------------------------------------------------------------

deployment-files-dev/build.sbt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// This is a stripped down version of the build.sbt found in the main framework.
2+
// It just contains version numbers and all sbt tasks for plugin developers.
3+
4+
// ---------------------------------------------------------------------------------------------------------------------
5+
// PROJECT INFORMATION
6+
// ---------------------------------------------------------------------------------------------------------------------
7+
8+
name := "ChatOverflow"
9+
version := "0.3"
10+
11+
// One version for all sub projects. Use "retrieveManaged := true" to download and show all library dependencies.
12+
val scalaMajorVersion = "2.12"
13+
val scalaMinorVersion = ".5"
14+
inThisBuild(List(
15+
scalaVersion := s"$scalaMajorVersion$scalaMinorVersion",
16+
retrieveManaged := false)
17+
)
18+
19+
// ---------------------------------------------------------------------------------------------------------------------
20+
// PLUGIN FRAMEWORK DEFINITIONS
21+
// ---------------------------------------------------------------------------------------------------------------------
22+
23+
// Plugin framework settings
24+
lazy val pluginBuildFileName = settingKey[String]("The filename of the plugin build file. Remember to gitignore it!")
25+
lazy val pluginFolderNames = settingKey[List[String]]("The folder names of all plugin source directories.")
26+
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!")
28+
29+
// Plugin framework tasks
30+
lazy val create = TaskKey[Unit]("create", "Creates a new plugin. Interactive command using the console.")
31+
lazy val fetch = TaskKey[Unit]("fetch", "Searches for plugins in plugin directories, builds the plugin build file.")
32+
lazy val copy = TaskKey[Unit]("copy", "Copies all packaged plugin jars to the target plugin folder.")
33+
34+
pluginBuildFileName := "plugins.sbt"
35+
pluginFolderNames := List("plugins-public", "plugins-private")
36+
pluginTargetFolderNames := List("plugins", s"target/scala-$scalaMajorVersion/plugins")
37+
apiProjectPath := "api"
38+
39+
create := PluginCreateWizard(streams.value.log).createPluginTask(pluginFolderNames.value)
40+
fetch := BuildUtility(streams.value.log).fetchPluginsTask(pluginFolderNames.value, pluginBuildFileName.value,
41+
pluginTargetFolderNames.value, apiProjectPath.value)
42+
copy := BuildUtility(streams.value.log).copyPluginsTask(pluginFolderNames.value, pluginTargetFolderNames.value, scalaMajorVersion)

project/BootstrapUtility.scala

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,17 @@ object BootstrapUtility {
9292
}
9393

9494
/**
95-
* Prepares the environemnt for deployment. Should be called after package and assembly task.
96-
*
97-
* @param logger the sbt logger
98-
* @param scalaLibraryVersion the scala library major version
99-
*/
100-
def prepareDeploymentTask(logger: ManagedLogger, scalaLibraryVersion: String): Unit = {
101-
// Assuming, before this: clean, bs, assembly bootstrapProject, package
95+
* Prepares the environemnt for deployment. Should be called after package and assembly task.
96+
*
97+
* @param logger the sbt logger
98+
* @param scalaLibraryVersion the scala library major version
99+
* @param dev whether sbt scripts and stuff for plugin developers should be included
100+
*/
101+
def prepareDeploymentTask(logger: ManagedLogger, scalaLibraryVersion: String, dev: Boolean): Unit = {
102+
// Assuming, before this: clean, bs, assembly bootstrapProject, package and if dev apiProject/packagedArtifacts
102103
// Assuming: Hardcoded "bin/" and "deploy/" folders
103104
// Assuming: A folder called "deployment-files" with all additional files (license, bat, etc.)
105+
// Assuming: A folder called "deployment-files-dev" with more additional files for plugin developers (only included if dev == true)
104106

105107
withTaskInfo("PREPARE DEPLOYMENT", logger) {
106108

@@ -136,10 +138,25 @@ object BootstrapUtility {
136138
if (!deploymentFiles.exists()) {
137139
logger warn "Unable to find deployment files."
138140
} else {
139-
for (deploymentFile <- deploymentFiles.listFiles()) {
140-
Files.copy(Paths.get(deploymentFile.getAbsolutePath),
141-
Paths.get(s"deploy/${deploymentFile.getName}"))
142-
logger info s"Finished copying additional deployment file '${deploymentFile.getName}'."
141+
sbt.IO.copyDirectory(deploymentFiles, new File("deploy/"))
142+
logger info s"Finished copying additional deployment files."
143+
}
144+
145+
if (dev) {
146+
val devDeploymentFiles = new File("deployment-files-dev/")
147+
if (!devDeploymentFiles.exists()) {
148+
logger warn "Unable to find dev deployment files."
149+
} else {
150+
sbt.IO.copyDirectory(devDeploymentFiles, new File("deploy/"))
151+
logger info "Finished copying additional dev deployment files."
152+
}
153+
154+
val requiredBuildFiles = Set("BuildUtility.scala", "build.properties", "Plugin.scala", "PluginCreateWizard.scala",
155+
"PluginLanguage.scala", "PluginMetadata.scala", "SbtFile.scala")
156+
for (filepath <- requiredBuildFiles) {
157+
val origFile = new File(s"project/$filepath")
158+
val deployFile = new File(s"deploy/project/$filepath")
159+
sbt.IO.copyFile(origFile, deployFile)
143160
}
144161
}
145162
}
@@ -155,8 +172,8 @@ object BootstrapUtility {
155172
if (file.isFile) {
156173
file.delete()
157174
} else {
158-
createOrEmptyFolder(file.getAbsolutePath)
159-
file.delete()
175+
createOrEmptyFolder(file.getAbsolutePath)
176+
file.delete()
160177
}
161178
}
162179
} else {
@@ -165,19 +182,15 @@ object BootstrapUtility {
165182
}
166183

167184
/**
168-
* Copies ONE jar file from the source to all target directories. Useful for single packaged jar files.
185+
* Copies all jar files from the source to all target directories.
169186
*/
170187
private def copyJars(sourceDirectory: String, targetDirectories: List[String], logger: ManagedLogger): Unit = {
171188
val candidates = new File(sourceDirectory)
172189
.listFiles().filter(f => f.isFile && f.getName.toLowerCase.endsWith(".jar"))
173-
if (candidates.length != 1) {
174-
logger warn s"Unable to identify jar file in $sourceDirectory"
175-
} else {
176-
for (targetDirectory <- targetDirectories) {
177-
Files.copy(Paths.get(candidates.head.getAbsolutePath),
178-
Paths.get(s"$targetDirectory/${candidates.head.getName}"))
179-
logger info s"Finished copying file '${candidates.head.getAbsolutePath}' to '$targetDirectory'."
180-
}
190+
for (targetDirectory <- targetDirectories; file <- candidates) {
191+
Files.copy(Paths.get(file.getAbsolutePath),
192+
Paths.get(s"$targetDirectory/${file.getName}"))
193+
logger info s"Finished copying file '${file.getAbsolutePath}' to '$targetDirectory'."
181194
}
182195
}
183196
}

project/BuildUtility.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import java.io.{File, IOException}
22
import java.nio.file.{Files, StandardCopyOption}
33

4+
import BuildUtility._
45
import sbt.internal.util.ManagedLogger
56
import sbt.util.{FileFunction, FilesInfo}
67

@@ -233,20 +234,6 @@ class BuildUtility(logger: ManagedLogger) {
233234
}
234235
}
235236

236-
/**
237-
* Creates a file listing with all files including files in any sub-dir.
238-
*
239-
* @param f the directory for which the file listing needs to be created.
240-
* @return the file listing as a set of files.
241-
*/
242-
private def recursiveFileListing(f: File): Set[File] = {
243-
if (f.isDirectory) {
244-
f.listFiles().flatMap(recursiveFileListing).toSet
245-
} else {
246-
Set(f)
247-
}
248-
}
249-
250237
private def withTaskInfo(taskName: String)(task: Unit): Unit = BuildUtility.withTaskInfo(taskName, logger)(task)
251238
}
252239

@@ -273,4 +260,17 @@ object BuildUtility {
273260
logger info s"Finished custom task: $taskName"
274261
}
275262

263+
/**
264+
* Creates a file listing with all files including files in any sub-dir.
265+
*
266+
* @param f the directory for which the file listing needs to be created.
267+
* @return the file listing as a set of files.
268+
*/
269+
def recursiveFileListing(f: File): Set[File] = {
270+
if (f.isDirectory) {
271+
f.listFiles().flatMap(recursiveFileListing).toSet
272+
} else {
273+
Set(f)
274+
}
275+
}
276276
}

0 commit comments

Comments
 (0)