From 7497567e19361cc6188ea7b10842dce492c00f6c Mon Sep 17 00:00:00 2001 From: Binh Nguyen Date: Wed, 28 Oct 2015 21:46:23 +0700 Subject: [PATCH 1/3] Add a test project --- samples/zinc/build.gradle | 29 ++++ .../gradle/wrapper/gradle-wrapper.properties | 6 + samples/zinc/gradlew | 164 ++++++++++++++++++ samples/zinc/gradlew.bat | 90 ++++++++++ samples/zinc/readme.xml | 3 + .../scala/org/gradle/sample/api/Person.scala | 9 + .../org/gradle/sample/impl/PersonImpl.scala | 12 ++ 7 files changed, 313 insertions(+) create mode 100755 samples/zinc/build.gradle create mode 100644 samples/zinc/gradle/wrapper/gradle-wrapper.properties create mode 100755 samples/zinc/gradlew create mode 100644 samples/zinc/gradlew.bat create mode 100755 samples/zinc/readme.xml create mode 100755 samples/zinc/src/main/scala/org/gradle/sample/api/Person.scala create mode 100755 samples/zinc/src/main/scala/org/gradle/sample/impl/PersonImpl.scala diff --git a/samples/zinc/build.gradle b/samples/zinc/build.gradle new file mode 100755 index 0000000..e09ae7b --- /dev/null +++ b/samples/zinc/build.gradle @@ -0,0 +1,29 @@ +apply plugin: 'scala' + +repositories { + mavenCentral() +} + +dependencies { + compile 'org.scala-lang:scala-library:2.11.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 diff --git a/samples/zinc/gradle/wrapper/gradle-wrapper.properties b/samples/zinc/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..f56f036 --- /dev/null +++ b/samples/zinc/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Dec 18 12:09:49 ICT 2014 +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 diff --git a/samples/zinc/gradlew b/samples/zinc/gradlew new file mode 100755 index 0000000..91a7e26 --- /dev/null +++ b/samples/zinc/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/samples/zinc/gradlew.bat b/samples/zinc/gradlew.bat new file mode 100644 index 0000000..aec9973 --- /dev/null +++ b/samples/zinc/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/samples/zinc/readme.xml b/samples/zinc/readme.xml new file mode 100755 index 0000000..f39990f --- /dev/null +++ b/samples/zinc/readme.xml @@ -0,0 +1,3 @@ + + Scala project using the Zinc based Scala compiler. + \ No newline at end of file diff --git a/samples/zinc/src/main/scala/org/gradle/sample/api/Person.scala b/samples/zinc/src/main/scala/org/gradle/sample/api/Person.scala new file mode 100755 index 0000000..5effb67 --- /dev/null +++ b/samples/zinc/src/main/scala/org/gradle/sample/api/Person.scala @@ -0,0 +1,9 @@ +package org.gradle.sample.api + +/** + * Defines the interface for a person. + */ +abstract trait Person +{ + def names: List[String] +} diff --git a/samples/zinc/src/main/scala/org/gradle/sample/impl/PersonImpl.scala b/samples/zinc/src/main/scala/org/gradle/sample/impl/PersonImpl.scala new file mode 100755 index 0000000..c6743e9 --- /dev/null +++ b/samples/zinc/src/main/scala/org/gradle/sample/impl/PersonImpl.scala @@ -0,0 +1,12 @@ +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(); +} From edafbdcf967b5312bf9609f846755e297260012d Mon Sep 17 00:00:00 2001 From: Binh Nguyen Date: Wed, 28 Oct 2015 22:36:02 +0700 Subject: [PATCH 2/3] Fix NPE when test sources are missing --- .../ngbinh/scalastyle/ScalaStyleTask.groovy | 10 +- gradle.properties | 2 +- samples/zinc/build.gradle | 19 +++ samples/zinc/scalastyle_config.xml | 142 ++++++++++++++++++ 4 files changed, 168 insertions(+), 5 deletions(-) create mode 100644 samples/zinc/scalastyle_config.xml diff --git a/gradle-scalastyle-plugin_2.11/src/main/groovy/org/github/ngbinh/scalastyle/ScalaStyleTask.groovy b/gradle-scalastyle-plugin_2.11/src/main/groovy/org/github/ngbinh/scalastyle/ScalaStyleTask.groovy index 262ef7a..1f1f702 100644 --- a/gradle-scalastyle-plugin_2.11/src/main/groovy/org/github/ngbinh/scalastyle/ScalaStyleTask.groovy +++ b/gradle-scalastyle-plugin_2.11/src/main/groovy/org/github/ngbinh/scalastyle/ScalaStyleTask.groovy @@ -65,10 +65,12 @@ class ScalaStyleTask extends SourceTask { 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)) + 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 config = ConfigFactory.load() diff --git a/gradle.properties b/gradle.properties index 020b607..3a718be 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ projectRepo = 'https://github.com/ngbinh/gradle-scalastyle-plugin' projectGroup = org.github.ngbinh.scalastyle # Change every releases -projectVersion = 0.8.0 +projectVersion = 0.8.1-SNAPSHOT # switch off build daemon org.gradle.daemon=false diff --git a/samples/zinc/build.gradle b/samples/zinc/build.gradle index e09ae7b..5185c4d 100755 --- a/samples/zinc/build.gradle +++ b/samples/zinc/build.gradle @@ -1,4 +1,23 @@ 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.11:0.8.1-SNAPSHOT' + } +} + +scalaStyle { + configLocation = "scalastyle_config.xml" + // includeTestSourceDirectory = true + source = "src/main/scala" + // testSource = "src/test/scala" +} repositories { mavenCentral() diff --git a/samples/zinc/scalastyle_config.xml b/samples/zinc/scalastyle_config.xml new file mode 100644 index 0000000..eb3c2a7 --- /dev/null +++ b/samples/zinc/scalastyle_config.xml @@ -0,0 +1,142 @@ + + Scalastyle standard configuration + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 9182c0d40d097f34e5880b9bc46d89e3a44acdde Mon Sep 17 00:00:00 2001 From: Binh Nguyen Date: Wed, 28 Oct 2015 22:37:46 +0700 Subject: [PATCH 3/3] 0.8.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 3a718be..fc5f4b4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ projectRepo = 'https://github.com/ngbinh/gradle-scalastyle-plugin' projectGroup = org.github.ngbinh.scalastyle # Change every releases -projectVersion = 0.8.1-SNAPSHOT +projectVersion = 0.8.1 # switch off build daemon org.gradle.daemon=false