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

Commit 6e1e69a

Browse files
committed
Also split and clean sbt files in plugin dev environment
#124 93ddc3f has done this for the main repo
1 parent 93ddc3f commit 6e1e69a

File tree

3 files changed

+6
-45
lines changed

3 files changed

+6
-45
lines changed

build/src/main/scala/org/codeoverflow/chatoverflow/build/SbtFile.scala

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package org.codeoverflow.chatoverflow.build
33
import java.io.{BufferedWriter, File, FileWriter, IOException}
44

55
import org.codeoverflow.chatoverflow.build.plugins.Plugin
6-
import sbt.librarymanagement.{CrossVersion, ModuleID}
76

87
/**
98
* Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files.
@@ -13,30 +12,22 @@ import sbt.librarymanagement.{CrossVersion, ModuleID}
1312
* @param plugins list of paths of sub projects
1413
* @param apiProjectPath the path of a base api project which every project depends on
1514
* @param defineRoot true, if a root project (".") should be defined in the sbt file
16-
* @param dependencies library dependencies to add to the sbt file
1715
*/
1816
class SbtFile(val name: String, val version: String, val plugins: List[Plugin], val apiProjectPath: String,
19-
val defineRoot: Boolean, dependencies: List[ModuleID]) {
17+
val defineRoot: Boolean) {
2018
/**
2119
* Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files.
2220
*
2321
* @param name the name of a sbt project
2422
* @param version the version of a sbt project
2523
*/
26-
def this(name: String, version: String) = this(name, version, List(), "", false, List())
24+
def this(name: String, version: String) = this(name, version, List(), "", false)
2725

2826
/**
2927
* Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files.
3028
*/
3129
def this() = this("", "")
3230

33-
/**
34-
* Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files.
35-
*
36-
* @param dependencies library dependencies to add to the sbt file
37-
*/
38-
def this(dependencies: List[ModuleID]) = this("", "", List(), "", false, dependencies)
39-
4031
/**
4132
* Tries to save the sbt files content into a defined directory.
4233
*
@@ -101,32 +92,6 @@ class SbtFile(val name: String, val version: String, val plugins: List[Plugin],
10192
sbtContent append rootLine
10293
}
10394

104-
if (dependencies.nonEmpty) {
105-
sbtContent append "\nresolvers += \"jcenter-bintray\" at \"https://jcenter.bintray.com\"\n"
106-
107-
val depString = dependencies.map(m => renderModuleID(m)).mkString(" ", ",\n ", "")
108-
109-
sbtContent append s"libraryDependencies ++= Seq(\n$depString\n)\n"
110-
}
111-
11295
sbtContent.mkString
11396
}
114-
115-
/**
116-
* Converts a ModuleID instance to a string with the module in the syntax that is used in sbt files.
117-
*/
118-
private def renderModuleID(m: ModuleID): String = {
119-
var formatString = ""
120-
121-
// Note that the %% in the string are required to escape the string formatter and will turn into a single %
122-
if (m.crossVersion == CrossVersion.binary)
123-
formatString += "\"%s\" %%%% \"%s\" %% \"%s\""
124-
else
125-
formatString += "\"%s\" %% \"%s\" %% \"%s\""
126-
127-
if (m.configurations.isDefined)
128-
formatString += " %% \"%s\""
129-
130-
formatString.format(m.organization, m.name, m.revision, m.configurations.getOrElse(""))
131-
}
13297
}

build/src/main/scala/org/codeoverflow/chatoverflow/build/deployment/DeploymentUtility.scala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import java.io.File
44
import java.nio.file.{Files, Paths}
55

66
import org.codeoverflow.chatoverflow.build.BuildUtils.withTaskInfo
7-
import org.codeoverflow.chatoverflow.build.SbtFile
87
import sbt.internal.util.ManagedLogger
9-
import sbt.librarymanagement.ModuleID
108

119
/**
1210
* Holds the functionality to create end-user and plugin dev deployments.
@@ -59,9 +57,8 @@ object DeploymentUtility {
5957
* @param logger the sbt logger
6058
* @param scalaLibraryVersion the scala library major version
6159
* @param apiProjectPath the path to the api project. Used to copy the api into the deployDev directory
62-
* @param dependencies the dependencies of the framework. Used to create a sbt file with them.
6360
*/
64-
def prepareDevDeploymentTask(logger: ManagedLogger, scalaLibraryVersion: String, apiProjectPath: String, dependencies: List[ModuleID]): Unit = {
61+
def prepareDevDeploymentTask(logger: ManagedLogger, scalaLibraryVersion: String, apiProjectPath: String): Unit = {
6562
// Assuming, before this: clean, gui, package and buildProject/package
6663
// Assuming: Hardcoded "bin/", "deployDev/", "launcher/" and "build/" folders
6764
// Assuming: A folder called "launcher/deployment-files/plugin-dev/" with more additional files for plugin developers
@@ -85,9 +82,8 @@ object DeploymentUtility {
8582
sbt.IO.copyDirectory(new File(apiProjectPath), new File("deployDev/api/"))
8683
sbt.IO.delete(new File("deployDev/api/target")) // otherwise compiled code would end up in the zip
8784

88-
// Fourth step: Create sbt files containing all dependencies
89-
val depFile = new SbtFile(dependencies)
90-
sbt.IO.write(new File("deployDev/dependencies.sbt"), depFile.toString)
85+
// Fourth step: Copy sbt file containing dependencies
86+
sbt.IO.copyFile(new File("dependencies.sbt"), new File("deployDev/dependencies.sbt"))
9187

9288
// Last step: Copy additional files
9389
val devDeploymentFiles = new File("launcher/deployment-files/plugin-dev/")

keys.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ copy := new PluginUtility(streams.value.log).copyPluginsTask(pluginFolderNames.v
3838
deploy := DeploymentUtility.prepareDeploymentTask(streams.value.log,
3939
scalaVersion.value.split('.').dropRight(1).mkString("."))
4040
deployDev := DeploymentUtility.prepareDevDeploymentTask(streams.value.log,
41-
scalaVersion.value.split('.').dropRight(1).mkString("."), apiProjectPath.value, libraryDependencies.value.toList)
41+
scalaVersion.value.split('.').dropRight(1).mkString("."), apiProjectPath.value)
4242
gui := new GUIUtility(streams.value.log).guiTask(guiProjectPath.value, streams.value.cacheDirectory / "gui")
4343

4444

0 commit comments

Comments
 (0)