|
1 | 1 | import java.io.{BufferedWriter, File, FileWriter, IOException} |
2 | 2 |
|
3 | 3 | /** |
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) { |
13 | 15 | /** |
14 | 16 | * Represents a simple sbt files content and methods to create a new sbt file. Not intended to open/read sbt files. |
15 | 17 | * |
16 | 18 | * @param name the name of a sbt project |
17 | 19 | * @param version the version of a sbt project |
18 | 20 | */ |
19 | | - def this(name: String, version: String) = this(name, version, List(), "", false) |
| 21 | + def this(name: String, version: String) = this(name, version, List(), "", "", false) |
20 | 22 |
|
21 | 23 | /** |
22 | 24 | * 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], |
62 | 64 | sbtContent append "\nversion := \"%s\"".format(version.replaceAll("\\", "")) |
63 | 65 | } |
64 | 66 |
|
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) |
68 | 69 |
|
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)" |
74 | 74 | } |
| 75 | + |
| 76 | + sbtContent append pluginLine |
75 | 77 | } |
76 | 78 |
|
77 | 79 | if (apiProjectPath != "") { |
78 | 80 | 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) |
79 | 83 | } |
80 | 84 |
|
81 | 85 | if (defineRoot) { |
| 86 | + var aggregateElems = plugins.map(p => s"`${p.normalizedName}`") |
| 87 | + if (apiProjectPath != "") { |
| 88 | + aggregateElems = "apiProject" +: aggregateElems |
| 89 | + } |
| 90 | + |
82 | 91 | 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(", ")) |
84 | 93 |
|
85 | 94 | if (apiProjectPath != "") { |
86 | 95 | rootLine += ".dependsOn(apiProject)" |
|
0 commit comments