@@ -2,53 +2,22 @@ package com.etsy.sbt.checkstyle
2
2
3
3
import javax .xml .transform .stream .StreamSource
4
4
5
+ import com .etsy .sbt .checkstyle .CheckstyleSeverityLevel .CheckstyleSeverityLevel
5
6
import com .puppycrawl .tools .checkstyle .Main .{main => CheckstyleMain }
6
7
import net .sf .saxon .s9api .Processor
7
8
import sbt .Def .Initialize
8
9
import sbt .Keys ._
9
10
import sbt ._
10
11
11
- import scala .io .Source
12
-
13
12
/**
14
13
* An SBT plugin to run checkstyle over Java code
15
14
*
16
15
* @author Andrew Johnson <ajohnson@etsy.com>
17
16
* @author Alejandro Rivera <alejandro.rivera.lopez@gmail.com>
18
17
* @author Joseph Earl <joe@josephearl.co.uk>
19
18
*/
20
- object Checkstyle extends Plugin {
21
- sealed abstract class CheckstyleConfig (val location : String ) {
22
- def read (resources : Seq [File ]): String
23
- }
24
-
25
- object CheckstyleConfig {
26
- case class URL (url : String ) extends CheckstyleConfig (url) {
27
- override def read (resources : Seq [sbt.File ]): String = Source .fromURL(url).mkString
28
- }
29
-
30
- case class File (path : String ) extends CheckstyleConfig (path) {
31
- override def read (resources : Seq [sbt.File ]): String = Source .fromFile(path).mkString
32
- }
33
-
34
- case class Classpath (name : String ) extends CheckstyleConfig (name) {
35
- override def read (resources : Seq [sbt.File ]): String = {
36
- val classpath = resources.map((f) => f.toURI.toURL)
37
- val loader = new java.net.URLClassLoader (classpath.toArray, getClass.getClassLoader)
38
- Source .fromInputStream(loader.getResourceAsStream(name)).mkString
39
- }
40
- }
41
- }
42
-
43
- object CheckstyleSeverityLevel extends Enumeration {
44
- type CheckstyleSeverityLevel = Value
45
- val Ignore = Value (" ignore" )
46
- val Info = Value (" info" )
47
- val Warning = Value (" warning" )
48
- val Error = Value (" error" )
49
- }
50
-
51
- import Checkstyle .CheckstyleSeverityLevel ._
19
+ object Checkstyle extends AutoPlugin {
20
+ override def trigger : PluginTrigger = allRequirements
52
21
53
22
val checkstyle = TaskKey [Unit ](" checkstyle" , " Runs checkstyle" )
54
23
val outputFile = SettingKey [File ](" checkstyle-target" , " The location of the generated checkstyle report" )
@@ -166,7 +135,7 @@ object Checkstyle extends Plugin {
166
135
}
167
136
}
168
137
169
- val checkstyleSettings : Seq [Def .Setting [_]] = Seq (
138
+ override def projectSettings : Seq [Def .Setting [_]] = Seq (
170
139
outputFile <<= target(_ / " checkstyle-report.xml" ),
171
140
outputFile in Test <<= target(_ / " checkstyle-test-report.xml" ),
172
141
configLocation := CheckstyleConfig .File (" checkstyle-config.xml" ),
0 commit comments