Skip to content

Commit

Permalink
Fixes #18 and #19
Browse files Browse the repository at this point in the history
  • Loading branch information
ngbinh committed Dec 2, 2015
1 parent 24824e8 commit 83fc742
Show file tree
Hide file tree
Showing 23 changed files with 530 additions and 26 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
maven repo: http://jcenter.bintray.com/
groupId: org.github.ngbinh.scalastyle
artifactId: gradle-scalastyle-plugin_2.11
version: 0.8.1
version: 0.8.2
```

Use `artifactId: gradle-scalastyle-plugin_2.10` if you want to use with Scala `2.10`
Expand All @@ -20,7 +20,7 @@ Use `artifactId: gradle-scalastyle-plugin_2.10` if you want to use with Scala `
Add following dependencies to your buildScript

```groovy
classpath "org.github.ngbinh.scalastyle:gradle-scalastyle-plugin_2.11:0.8.1"
classpath "org.github.ngbinh.scalastyle:gradle-scalastyle-plugin_2.11:0.8.2"
```

Configure the plugin
Expand Down Expand Up @@ -60,7 +60,7 @@ Other optional properties are
}
dependencies {
classpath 'org.github.ngbinh.scalastyle:gradle-scalastyle-plugin_2.11:0.8.1'
classpath 'org.github.ngbinh.scalastyle:gradle-scalastyle-plugin_2.11:0.8.2'
}
}
Expand All @@ -71,4 +71,3 @@ Other optional properties are
testSource = "src/test/scala"
}
```

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ subprojects {
}

versions.scalaDist = scalaDist
versions.scalaStyle = "0.7.0"
versions.scalaStyle = "0.8.0"
versions.junit = "4.11"

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,17 @@ class ScalaStyleTask extends SourceTask {
def startMs = System.currentTimeMillis()
def configuration = ScalastyleConfiguration.readFromXml(configLocation)
def fileToProcess = scalaStyleUtils.getFilesToProcess(source.getFiles().toList(), testSourceDir.getFiles().toList(), inputEncoding, includeTestSourceDirectory)
def messages = new ScalastyleChecker().checkFiles(configuration, fileToProcess)

def testConfiguration = ScalastyleConfiguration.readFromXml(testConfigLocation)
if (testConfiguration != null) {
def testFilesToProcess = scalaStyleUtils.getFilesToProcess(source.getFiles().toList(), testSourceDir.getFiles().toList(), inputEncoding, includeTestSourceDirectory)
messages.addAll(new ScalastyleChecker().checkFiles(testConfiguration, testFilesToProcess))
def messages = scalaStyleUtils.checkFiles(configuration, fileToProcess)

if (testConfigLocation != null) {
def testConfiguration = ScalastyleConfiguration.readFromXml(testConfigLocation)
if (testConfiguration != null) {
def testFilesToProcess = scalaStyleUtils.getTestFilesToProcess(source.getFiles().toList(), testSourceDir.getFiles().toList(), inputEncoding, includeTestSourceDirectory)
messages.addAll(scalaStyleUtils.checkFiles(testConfiguration, testFilesToProcess))
}
}

def config = ConfigFactory.load()
def config = scalaStyleUtils.configFactory()

def outputResult = new TextOutput(config, verbose, quiet).output(messages)

Expand Down Expand Up @@ -160,4 +162,4 @@ class ScalaStyleTask extends SourceTask {
project.getLogger().info("inputEncoding: {}", inputEncoding)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

package org.github.ngbinh.scalastyle

import org.scalastyle.{Directory, FileSpec}
import org.scalastyle.{Directory, FileSpec, Message}
import org.scalastyle.ScalastyleChecker
import org.scalastyle.ScalastyleConfiguration
import com.typesafe.config.ConfigFactory
import com.typesafe.config.Config
import java.io.File
import java.util.{List => jList}
import scala.collection.JavaConverters._
Expand All @@ -30,8 +34,6 @@ import scala.collection.JavaConverters._
* @since 5/11/13
*/
class ScalaStyleUtils {


def getFilesToProcess(sourceFiles: jList[File], testFiles: jList[File], inputEncoding: String, includeTestSourceDirectory: Boolean): List[FileSpec] = {
val sd = getFiles("sourceDirectory", asScalaBufferConverter(sourceFiles).asScala.toList, inputEncoding)
val tsd = if (includeTestSourceDirectory) getFiles("testFiles", asScalaBufferConverter(testFiles).asScala.toList, inputEncoding) else Nil
Expand All @@ -48,4 +50,12 @@ class ScalaStyleUtils {
}

def isDirectory(file: File) = file != null && file.exists() && file.isDirectory

def checkFiles(configuration: ScalastyleConfiguration, files: List[FileSpec]): List[Message[FileSpec]] = {
new ScalastyleChecker(Some(this.getClass().getClassLoader())).checkFiles(configuration, files)
}

def configFactory(): Config = {
ConfigFactory.load(this.getClass().getClassLoader())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ class ScalaStyleTask extends SourceTask {
def startMs = System.currentTimeMillis()
def configuration = ScalastyleConfiguration.readFromXml(configLocation)
def fileToProcess = scalaStyleUtils.getFilesToProcess(source.getFiles().toList(), testSourceDir.getFiles().toList(), inputEncoding, includeTestSourceDirectory)
def messages = new ScalastyleChecker().checkFiles(configuration, fileToProcess)
def messages = scalaStyleUtils.checkFiles(configuration, fileToProcess)

if (testConfigLocation != null) {
def testConfiguration = ScalastyleConfiguration.readFromXml(testConfigLocation)
if (testConfiguration != null) {
def testFilesToProcess = scalaStyleUtils.getFilesToProcess(source.getFiles().toList(), testSourceDir.getFiles().toList(), inputEncoding, includeTestSourceDirectory)
messages.addAll(new ScalastyleChecker().checkFiles(testConfiguration, testFilesToProcess))
def testFilesToProcess = scalaStyleUtils.getTestFilesToProcess(source.getFiles().toList(), testSourceDir.getFiles().toList(), inputEncoding, includeTestSourceDirectory)
messages.addAll(scalaStyleUtils.checkFiles(testConfiguration, testFilesToProcess))
}
}

def config = ConfigFactory.load()
def config = scalaStyleUtils.configFactory()

def outputResult = new TextOutput(config, verbose, quiet).output(messages)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

package org.github.ngbinh.scalastyle

import org.scalastyle.{Directory, FileSpec}
import org.scalastyle.{Directory, FileSpec, Message}
import org.scalastyle.ScalastyleChecker
import org.scalastyle.ScalastyleConfiguration
import com.typesafe.config.ConfigFactory
import com.typesafe.config.Config
import java.io.File
import java.util.{List => jList}
import scala.collection.JavaConverters._
Expand Down Expand Up @@ -46,4 +50,12 @@ class ScalaStyleUtils {
}

def isDirectory(file: File) = file != null && file.exists() && file.isDirectory

def checkFiles(configuration: ScalastyleConfiguration, files: List[FileSpec]): List[Message[FileSpec]] = {
new ScalastyleChecker(Some(this.getClass().getClassLoader())).checkFiles(configuration, files)
}

def configFactory(): Config = {
ConfigFactory.load(this.getClass().getClassLoader())
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ projectRepo = 'https://github.com/ngbinh/gradle-scalastyle-plugin'
projectGroup = org.github.ngbinh.scalastyle

# Change every releases
projectVersion = 0.8.1
projectVersion = 0.8.2

# switch off build daemon
org.gradle.daemon=false
49 changes: 49 additions & 0 deletions samples/zinc-2_10/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apply plugin: 'scala'
apply plugin: 'scalaStyle'

buildscript {
repositories {
jcenter() // only work after gradle 1.7
mavenLocal()
}

dependencies {
classpath 'org.github.ngbinh.scalastyle:gradle-scalastyle-plugin_2.10:0.8.3'
}
}

scalaStyle {
configLocation = "scalastyle_config.xml"
// includeTestSourceDirectory = true
source = "src/main/scala"
// testSource = "src/test/scala"
verbose = false
}

repositories {
mavenCentral()
}

dependencies {
compile 'org.scala-lang:scala-library:2.10.1'
}

dependencies {
compile 'commons-collections:commons-collections:3.2'
testCompile 'junit:junit:4.12'
}

// START SNIPPET use-zinc
tasks.withType(ScalaCompile) {
scalaCompileOptions.useAnt = false
}
// END SNIPPET use-zinc

// START SNIPPET adjust-memory
tasks.withType(ScalaCompile) {
configure(scalaCompileOptions.forkOptions) {
memoryMaximumSize = '1g'
jvmArgs = ['-XX:MaxPermSize=512m']
}
}
// END SNIPPET adjust-memory
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip
File renamed without changes.
File renamed without changes.
File renamed without changes.
142 changes: 142 additions & 0 deletions samples/zinc-2_10/scalastyle_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<scalastyle commentFilter="enabled">
<name>Scalastyle standard configuration</name>
<check level="warning" class="org.scalastyle.file.FileTabChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.FileLengthChecker" enabled="true">
<parameters>
<parameter name="maxFileLength"><![CDATA[800]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.file.HeaderMatchesChecker" enabled="true">
<parameters>
<parameter name="header"><![CDATA[// Copyright (C) 2011-2012 the original author or authors.
// See the LICENCE.txt file distributed with this work for additional
// information regarding copyright ownership.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.SpacesAfterPlusChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.WhitespaceEndOfLineChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.SpacesBeforePlusChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.FileLineLengthChecker" enabled="true">
<parameters>
<parameter name="maxLineLength"><![CDATA[160]]></parameter>
<parameter name="tabSize"><![CDATA[4]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.ClassNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></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>
<check level="warning" class="org.scalastyle.scalariform.PackageObjectNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[^[a-z][A-Za-z]*$]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.EqualsHashCodeChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.IllegalImportsChecker" enabled="true">
<parameters>
<parameter name="illegalImports"><![CDATA[sun._,java.awt._]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.ParameterNumberChecker" enabled="true">
<parameters>
<parameter name="maxParameters"><![CDATA[8]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.MagicNumberChecker" enabled="true">
<parameters>
<parameter name="ignore"><![CDATA[-1,0,1,2,3]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.NoWhitespaceBeforeLeftBracketChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NoWhitespaceAfterLeftBracketChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.ReturnChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NullChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NoCloneChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.NoFinalizeChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.CovariantEqualsChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.StructuralTypeChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.file.RegexChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[println]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.NumberOfTypesChecker" enabled="true">
<parameters>
<parameter name="maxTypes"><![CDATA[30]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.CyclomaticComplexityChecker" enabled="true">
<parameters>
<parameter name="maximum"><![CDATA[10]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.UppercaseLChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.SimplifyBooleanExpressionChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.IfBraceChecker" enabled="true">
<parameters>
<parameter name="singleLineAllowed"><![CDATA[true]]></parameter>
<parameter name="doubleLineAllowed"><![CDATA[false]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.MethodLengthChecker" enabled="true">
<parameters>
<parameter name="maxLength"><![CDATA[50]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.MethodNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[^[a-z][A-Za-z0-9]*$]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.NumberOfMethodsInTypeChecker" enabled="true">
<parameters>
<parameter name="maxMethods"><![CDATA[30]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.PublicMethodsHaveTypeChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.NewLineAtEofChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.file.NoNewLineAtEofChecker" enabled="false"></check>
<check level="warning" class="org.scalastyle.scalariform.WhileChecker" enabled="false"></check>
<check level="warning" class="org.scalastyle.scalariform.VarFieldChecker" enabled="false"></check>
<check level="warning" class="org.scalastyle.scalariform.VarLocalChecker" enabled="false"></check>
<check level="warning" class="org.scalastyle.scalariform.RedundantIfChecker" enabled="false"></check>
<check level="warning" class="org.scalastyle.scalariform.TokenChecker" enabled="false">
<parameters>
<parameter name="regex"><![CDATA[println]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.DeprecatedJavaChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.EmptyClassChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.ClassTypeParameterChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[^[A-Z_]$]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.UnderscoreImportChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.LowercasePatternMatchChecker" enabled="true"></check>
<check level="warning" class="org.scalastyle.scalariform.MultipleStringLiteralsChecker" enabled="true">
<parameters>
<parameter name="allowed"><![CDATA[2]]></parameter>
<parameter name="ignoreRegex"><![CDATA[^""$]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.ImportGroupingChecker" enabled="true"></check>
</scalastyle>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.gradle.sample.impl

import org.gradle.sample.api.Person
import org.apache.commons.collections.list.GrowthList;

/**
* Immutable implementation of {@link Person}.
*/
class PersonImpl(val names: List[String]) extends Person
{
private val importedList = new GrowthList()

private def times100(x: Int) = {
val k = x * 100
println(s"k = $k")
}
}
3 changes: 2 additions & 1 deletion samples/zinc/build.gradle → samples/zinc-2_11/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'org.github.ngbinh.scalastyle:gradle-scalastyle-plugin_2.11:0.8.1-SNAPSHOT'
classpath 'org.github.ngbinh.scalastyle:gradle-scalastyle-plugin_2.11:0.8.3'
}
}

Expand All @@ -17,6 +17,7 @@ scalaStyle {
// includeTestSourceDirectory = true
source = "src/main/scala"
// testSource = "src/test/scala"
verbose = false
}

repositories {
Expand Down
Loading

0 comments on commit 83fc742

Please sign in to comment.