Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/ajsquared/scalastyle-sbt-pl…
Browse files Browse the repository at this point in the history
…ugin into ajsquared-master

Conflicts:
	src/main/scala/org/scalastyle/sbt/Plugin.scala
  • Loading branch information
matthewfarwell committed Oct 15, 2015
2 parents 0a48863 + 0172d15 commit 6f374df
Show file tree
Hide file tree
Showing 23 changed files with 198 additions and 7 deletions.
31 changes: 25 additions & 6 deletions src/main/scala/org/scalastyle/sbt/Plugin.scala
Expand Up @@ -110,7 +110,7 @@ object ScalastylePlugin extends Plugin {
scalastyleFailOnError := true,
(scalastyleFailOnError in Test) := (scalastyleFailOnError in scalastyle).value,
scalastyleSources := Seq((scalaSource in Compile).value),
(scalastyleSources in Test) := Seq((scalaSource in Test).value)
(scalastyleSources in Test) := (scalastyleSources in scalastyle).value
) ++
Project.inConfig(Compile)(rawScalastyleSettings()) ++
Project.inConfig(Test)(rawScalastyleSettings())
Expand All @@ -120,8 +120,13 @@ object Tasks {
def doScalastyle(args: Seq[String], config: File, configUrl: Option[URL], failOnError: Boolean, scalastyleSources: Seq[File], scalastyleTarget: File,
streams: TaskStreams[ScopedKey[_]], refreshHours: Integer, target: File, urlCacheFile: String): Unit = {
val logger = streams.log
val quietArg = "q"
val warnErrorArg = "w"
val supportedArgs = Set(quietArg, warnErrorArg)

val quiet = args.exists(_ == "q")
val quiet = args.contains(quietArg)
val warnError = args.contains(warnErrorArg)
println("config=" + config)

def onHasErrors(message: String): Unit = {
if (failOnError) {
Expand Down Expand Up @@ -155,15 +160,29 @@ object Tasks {
f
}

def isInProject(sources: Seq[File])(f: File) = {
val validFile = f.exists() && sources.find(s => f.getAbsolutePath.startsWith(s.getAbsolutePath)).isDefined
if (!validFile) logger.warn(s"File $f does not exist in project")
validFile
}

def doScalastyleWithConfig(config: File): Unit = {
val messageConfig = ConfigFactory.load(new ScalastyleChecker().getClass().getClassLoader())
//streams.log.error("messageConfig=" + messageConfig.root().render())
System.out.println("args=" + args)
System.out.println("scalastyleSources=" + scalastyleSources)

val filesToProcess: Seq[File] = args.filterNot(supportedArgs.contains).map(file).filter(isInProject(scalastyleSources)) match {
case Nil => scalastyleSources
case files => files
}

val messages = runScalastyle(config, scalastyleSources)
println("filesToProcess=" + filesToProcess)
println("config=" + config)
val messages = runScalastyle(config, filesToProcess)

saveToXml(messageConfig, messages, scalastyleTarget.absolutePath)

val warnError = args.exists(_ == "w")
val result = printResults(messageConfig, logger, messages, quiet = quiet, warnError = warnError)
if (!quiet) {
logger.success("created output: %s".format(target))
Expand All @@ -188,9 +207,9 @@ object Tasks {
getFileFromJar(getClass.getResource("/scalastyle-config.xml"), config.absolutePath, streams.log)
}

private[this] def runScalastyle(config: File, scalastyleSources: Seq[File]) = {
private[this] def runScalastyle(config: File, filesToProcess: Seq[File]) = {
val configuration = ScalastyleConfiguration.readFromXml(config.absolutePath)
new ScalastyleChecker().checkFiles(configuration, Directory.getFiles(None, scalastyleSources.toList))
new ScalastyleChecker().checkFiles(configuration, Directory.getFiles(None, filesToProcess))
}

private[this] def printResults(config: Config, logger: Logger, messages: List[Message[FileSpec]], quiet: Boolean = false, warnError: Boolean = false): OutputResult = {
Expand Down
16 changes: 16 additions & 0 deletions src/sbt-test/specific-files/directories/build.sbt
@@ -0,0 +1,16 @@
version := "0.1"

scalaVersion := "2.10.0"

val containsMessage = taskKey[Boolean]("contains message")

containsMessage := {
val search = "File length exceeds"
val filename = "target/scalastyle-result.xml"
val lines = sbt.IO.readLines(file(filename))
val contains = lines.find(s => s.contains(search)).isDefined
if (contains) {
sys.error("Found " + search + " in " + filename)
}
contains
}
@@ -0,0 +1 @@
sbt.version=0.13.0
9 changes: 9 additions & 0 deletions src/sbt-test/specific-files/directories/project/plugins.sbt
@@ -0,0 +1,9 @@
resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"

{
val pluginVersion = System.getProperty("plugin.version")
if(pluginVersion == null)
throw new RuntimeException("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
else addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % pluginVersion)
}
13 changes: 13 additions & 0 deletions src/sbt-test/specific-files/directories/scalastyle-config.xml
@@ -0,0 +1,13 @@
<scalastyle>
<name>Scalastyle standard configuration</name>
<check level="warning" class="org.scalastyle.file.FileLengthChecker" enabled="true">
<parameters>
<parameter name="maxFileLength"><![CDATA[5]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.ObjectNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter>
</parameters>
</check>
</scalastyle>
@@ -0,0 +1,5 @@
class Example {
def hello(): Unit = {
println("hello")
}
}
@@ -0,0 +1,9 @@

object Main extends App {
println("hello")
}

object foo {
println("hello")
}

4 changes: 4 additions & 0 deletions src/sbt-test/specific-files/directories/test
@@ -0,0 +1,4 @@
# scalastyle on specific files
> clean
> scalastyle src/main/scala/package1
> containsMessage
16 changes: 16 additions & 0 deletions src/sbt-test/specific-files/files/build.sbt
@@ -0,0 +1,16 @@
version := "0.1"

scalaVersion := "2.10.0"

val containsMessage = taskKey[Boolean]("contains message")

containsMessage := {
val search = "File length exceeds"
val filename = "target/scalastyle-result.xml"
val lines = sbt.IO.readLines(file(filename))
val contains = lines.find(s => s.contains(search)).isDefined
if (contains) {
sys.error("Found " + search + " in " + filename)
}
contains
}
1 change: 1 addition & 0 deletions src/sbt-test/specific-files/files/project/build.properties
@@ -0,0 +1 @@
sbt.version=0.13.0
9 changes: 9 additions & 0 deletions src/sbt-test/specific-files/files/project/plugins.sbt
@@ -0,0 +1,9 @@
resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"

{
val pluginVersion = System.getProperty("plugin.version")
if(pluginVersion == null)
throw new RuntimeException("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
else addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % pluginVersion)
}
13 changes: 13 additions & 0 deletions src/sbt-test/specific-files/files/scalastyle-config.xml
@@ -0,0 +1,13 @@
<scalastyle>
<name>Scalastyle standard configuration</name>
<check level="warning" class="org.scalastyle.file.FileLengthChecker" enabled="true">
<parameters>
<parameter name="maxFileLength"><![CDATA[5]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.ObjectNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter>
</parameters>
</check>
</scalastyle>
@@ -0,0 +1,5 @@
class Example {
def hello(): Unit = {
println("hello")
}
}
9 changes: 9 additions & 0 deletions src/sbt-test/specific-files/files/src/main/scala/hello.scala
@@ -0,0 +1,9 @@

object Main extends App {
println("hello")
}

object foo {
println("hello")
}

4 changes: 4 additions & 0 deletions src/sbt-test/specific-files/files/test
@@ -0,0 +1,4 @@
# scalastyle on specific files
> clean
> scalastyle src/main/scala/Example.scala
> containsMessage
16 changes: 16 additions & 0 deletions src/sbt-test/specific-files/nonexistent-file/build.sbt
@@ -0,0 +1,16 @@
version := "0.1"

scalaVersion := "2.10.0"

val containsMessage = taskKey[Boolean]("contains message")

containsMessage := {
val search = "File length exceeds"
val filename = "target/scalastyle-result.xml"
val lines = sbt.IO.readLines(file(filename))
val contains = lines.find(s => s.contains(search)).isDefined
if (!contains) {
sys.error("Could not find " + search + " in " + filename)
}
contains
}
@@ -0,0 +1 @@
sbt.version=0.13.0
@@ -0,0 +1,9 @@
resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"

{
val pluginVersion = System.getProperty("plugin.version")
if(pluginVersion == null)
throw new RuntimeException("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
else addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % pluginVersion)
}
13 changes: 13 additions & 0 deletions src/sbt-test/specific-files/nonexistent-file/scalastyle-config.xml
@@ -0,0 +1,13 @@
<scalastyle>
<name>Scalastyle standard configuration</name>
<check level="warning" class="org.scalastyle.file.FileLengthChecker" enabled="true">
<parameters>
<parameter name="maxFileLength"><![CDATA[5]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.ObjectNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter>
</parameters>
</check>
</scalastyle>
@@ -0,0 +1,5 @@
class Example {
def hello(): Unit = {
println("hello")
}
}
@@ -0,0 +1,9 @@

object Main extends App {
println("hello")
}

object foo {
println("hello")
}

5 changes: 5 additions & 0 deletions src/sbt-test/specific-files/nonexistent-file/test
@@ -0,0 +1,5 @@
# scalastyle on specific files
> clean
# simulated typo
> scalastyle src/main/scala/Eaxmple.scala
> containsMessage
2 changes: 1 addition & 1 deletion src/sbt-test/test-config/scalastyle-config/build.sbt
@@ -1,4 +1,4 @@
(scalastyleConfig in Test) := file("alternative-config.xml")
(scalastyleConfig in Test) := file("gggalternative-config.xml")

version := "0.1"

Expand Down

0 comments on commit 6f374df

Please sign in to comment.