-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from stephennancekivell/fix-idea-parsing-match-…
…error fix idea plugin parsing match error
- Loading branch information
Showing
4 changed files
with
69 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.jmotor.sbt.util | ||
|
||
import sbt.ModuleID | ||
|
||
object PluginParser { | ||
private[this] val addSbtPluginRegex = """addSbtPlugin\("([\w\.-]+)" *%{1,2} *"([\w\.-]+)"\ *% *"([\w\.-]+)"\)""".r | ||
|
||
def parseline(lines: Seq[String]): Seq[ModuleID] = { | ||
lines.map(_.trim).filter { line ⇒ | ||
line.nonEmpty && line.startsWith("addSbtPlugin") | ||
}.flatMap { | ||
case addSbtPluginRegex(org, n, v) ⇒ Some(ModuleID(org, n, v)) | ||
case _ ⇒ None | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.jmotor.sbt.util | ||
|
||
import org.scalatest.{ FunSpec, Matchers } | ||
import sbt.ModuleID | ||
|
||
class PluginParserSpec extends FunSpec with Matchers { | ||
|
||
describe("PluginParser") { | ||
it("reads normal plugin") { | ||
val lines = | ||
""" | ||
|addSbtPlugin("org.jmotor.sbt" % "sbt-dependency-updates" % "1.1.0") | ||
""".stripMargin.split("\n") | ||
val found = PluginParser.parseline(lines).toList | ||
found shouldBe Seq(ModuleID("org.jmotor.sbt", "sbt-dependency-updates", "1.1.0")) | ||
} | ||
|
||
it("reads a few plugins with mixed content") { | ||
val lines = | ||
""" | ||
| // comments | ||
| | ||
|addSbtPlugin("org.jmotor.sbt" % "sbt-dependency-updates" % "1.1.0") | ||
| | ||
| addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") | ||
| | ||
""".stripMargin.split("\n") | ||
|
||
val found = PluginParser.parseline(lines).toList | ||
found shouldBe Seq( | ||
ModuleID("org.jmotor.sbt", "sbt-dependency-updates", "1.1.0"), | ||
ModuleID("org.scalastyle", "scalastyle-sbt-plugin", "1.0.0")) | ||
} | ||
|
||
it("doesnt crash on the intellij plugin") { | ||
val lines = | ||
""" | ||
|// Generated by IntelliJ-IDEA Scala plugin. | ||
|// Add settings when starting sbt from IDEA. | ||
|// Manual changes to this file will be lost. | ||
|if (java.lang.System.getProperty("idea.runid", "false") == "2017.2") scala.collection.Seq( | ||
|addSbtPlugin("org.jetbrains" % "sbt-structure-extractor" % "2017.2"), | ||
|addSbtPlugin("org.jetbrains" % "sbt-idea-shell" % "2017.2") | ||
|) else scala.collection.Seq.empty% | ||
""".stripMargin.split("\n") | ||
|
||
PluginParser.parseline(lines) shouldBe Seq(ModuleID("org.jetbrains", "sbt-idea-shell", "2017.2")) | ||
} | ||
} | ||
} |