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

Commit 0c9c7bf

Browse files
committed
Replace illegal identifiers in generated getting started source files
1 parent e719b3f commit 0c9c7bf

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

project/Plugin.scala

+16-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import scala.xml.PrettyPrinter
1212
* @param name the name of the plugin
1313
*/
1414
class Plugin(val pluginSourceDirectoryName: String, val name: String) {
15-
val normalizedName: String = Plugin.toPluginPathName(name)
16-
val pluginDirectoryPath: String = s"$pluginSourceDirectoryName/$normalizedName"
15+
val normalizedName: String = Plugin.toNormalizedName(name)
16+
val pluginDirectoryPath: String = s"$pluginSourceDirectoryName/${normalizedName.toLowerCase}"
1717

1818
/**
1919
* Creates the plugin folder inside of a plugin source directory
@@ -147,7 +147,20 @@ object Plugin {
147147
pluginSourceFolder.exists() && pluginSourceFolder.isDirectory
148148
}
149149

150-
private def toPluginPathName(name: String) = name.replaceAll("[ -]", "").toLowerCase
150+
private def toNormalizedName(name: String): String = {
151+
if (name.isEmpty) {
152+
return ""
153+
}
154+
155+
val firstChar = name(0)
156+
157+
if (!Character.isJavaIdentifierStart(firstChar)) {
158+
toNormalizedName(name.substring(1))
159+
} else {
160+
val rest = name.substring(1)
161+
firstChar + rest.filter(Character.isJavaIdentifierPart)
162+
}
163+
}
151164

152165
private def containsPluginXMLFile(directory: File): Boolean = {
153166
new File(s"$directory/src/main/resources/plugin.xml").exists()

project/SbtFile.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ class SbtFile(var name: String, var version: String, var plugins: List[Plugin],
5555
val sbtContent = new StringBuilder("// GENERATED FILE USING THE CHAT OVERFLOW PLUGIN FRAMEWORK\n")
5656

5757
if (name != "") {
58-
sbtContent append "\nname := \"%s\"".format(name)
58+
sbtContent append "\nname := \"%s\"".format(name.replaceAll("\\", ""))
5959
}
6060

6161
if (version != "") {
62-
sbtContent append "\nversion := \"%s\"".format(version)
62+
sbtContent append "\nversion := \"%s\"".format(version.replaceAll("\\", ""))
6363
}
6464

6565
if (plugins.nonEmpty) {

0 commit comments

Comments
 (0)