forked from etsy/sbt-checkstyle-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes etsy#16: Make sbt-checkstyle-plugin an AutoPlugin
- Loading branch information
Showing
13 changed files
with
53 additions
and
64 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 |
---|---|---|
|
@@ -2,53 +2,22 @@ package com.etsy.sbt.checkstyle | |
|
||
import javax.xml.transform.stream.StreamSource | ||
|
||
import com.etsy.sbt.checkstyle.CheckstyleSeverityLevel.CheckstyleSeverityLevel | ||
import com.puppycrawl.tools.checkstyle.Main.{main => CheckstyleMain} | ||
import net.sf.saxon.s9api.Processor | ||
import sbt.Def.Initialize | ||
import sbt.Keys._ | ||
import sbt._ | ||
|
||
import scala.io.Source | ||
|
||
/** | ||
* An SBT plugin to run checkstyle over Java code | ||
* | ||
* @author Andrew Johnson <[email protected]> | ||
* @author Alejandro Rivera <[email protected]> | ||
* @author Joseph Earl <[email protected]> | ||
*/ | ||
object Checkstyle extends Plugin { | ||
sealed abstract class CheckstyleConfig(val location: String) { | ||
def read(resources: Seq[File]): String | ||
} | ||
|
||
object CheckstyleConfig { | ||
case class URL(url: String) extends CheckstyleConfig(url) { | ||
override def read(resources: Seq[sbt.File]): String = Source.fromURL(url).mkString | ||
} | ||
|
||
case class File(path: String) extends CheckstyleConfig(path) { | ||
override def read(resources: Seq[sbt.File]): String = Source.fromFile(path).mkString | ||
} | ||
|
||
case class Classpath(name: String) extends CheckstyleConfig(name) { | ||
override def read(resources: Seq[sbt.File]): String = { | ||
val classpath = resources.map((f) => f.toURI.toURL) | ||
val loader = new java.net.URLClassLoader(classpath.toArray, getClass.getClassLoader) | ||
Source.fromInputStream(loader.getResourceAsStream(name)).mkString | ||
} | ||
} | ||
} | ||
|
||
object CheckstyleSeverityLevel extends Enumeration { | ||
type CheckstyleSeverityLevel = Value | ||
val Ignore = Value("ignore") | ||
val Info = Value("info") | ||
val Warning = Value("warning") | ||
val Error = Value("error") | ||
} | ||
|
||
import Checkstyle.CheckstyleSeverityLevel._ | ||
object Checkstyle extends AutoPlugin { | ||
override def trigger: PluginTrigger = allRequirements | ||
|
||
val checkstyle = TaskKey[Unit]("checkstyle", "Runs checkstyle") | ||
val outputFile = SettingKey[File]("checkstyle-target", "The location of the generated checkstyle report") | ||
|
@@ -166,7 +135,7 @@ object Checkstyle extends Plugin { | |
} | ||
} | ||
|
||
val checkstyleSettings: Seq[Def.Setting[_]] = Seq( | ||
override def projectSettings: Seq[Def.Setting[_]] = Seq( | ||
outputFile <<= target(_ / "checkstyle-report.xml"), | ||
outputFile in Test <<= target(_ / "checkstyle-test-report.xml"), | ||
configLocation := CheckstyleConfig.File("checkstyle-config.xml"), | ||
|
27 changes: 27 additions & 0 deletions
27
src/main/scala/com/etsy/sbt/checkstyle/CheckstyleConfig.scala
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,27 @@ | ||
package com.etsy.sbt.checkstyle | ||
|
||
import sbt.File | ||
|
||
import scala.io.Source | ||
|
||
sealed abstract class CheckstyleConfig(val location: String) { | ||
def read(resources: Seq[File]): String | ||
} | ||
|
||
object CheckstyleConfig { | ||
case class URL(url: String) extends CheckstyleConfig(url) { | ||
override def read(resources: Seq[sbt.File]): String = Source.fromURL(url).mkString | ||
} | ||
|
||
case class File(path: String) extends CheckstyleConfig(path) { | ||
override def read(resources: Seq[sbt.File]): String = Source.fromFile(path).mkString | ||
} | ||
|
||
case class Classpath(name: String) extends CheckstyleConfig(name) { | ||
override def read(resources: Seq[sbt.File]): String = { | ||
val classpath = resources.map((f) => f.toURI.toURL) | ||
val loader = new java.net.URLClassLoader(classpath.toArray, getClass.getClassLoader) | ||
Source.fromInputStream(loader.getResourceAsStream(name)).mkString | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/scala/com/etsy/sbt/checkstyle/CheckstyleSeverityLevel.scala
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,9 @@ | ||
package com.etsy.sbt.checkstyle | ||
|
||
object CheckstyleSeverityLevel extends Enumeration { | ||
type CheckstyleSeverityLevel = Value | ||
val Ignore = Value("ignore") | ||
val Info = Value("info") | ||
val Warning = Value("warning") | ||
val Error = Value("error") | ||
} |
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
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
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
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
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