Skip to content

Commit

Permalink
Use Gradle plugin to check code style
Browse files Browse the repository at this point in the history
  • Loading branch information
albertogoffi committed Jul 13, 2018
1 parent 4b4f87c commit 35da9e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 35 deletions.
37 changes: 7 additions & 30 deletions build.gradle
Expand Up @@ -18,6 +18,7 @@ plugins {
id 'de.undercouch.download' version '3.3.0' // For the download tasks
id 'eclipse' // Support for Eclipse projects
id 'idea' // Support for IntelliJ IDEA projects
id 'com.github.sherter.google-java-format' version '0.7.1'
}
apply plugin: 'kotlin'

Expand Down Expand Up @@ -233,7 +234,6 @@ tasks.withType(Test) {

/* Create Javadoc documentation as part of build task. */
build.dependsOn javadoc

javadoc {
options.encoding = 'UTF-8'
exclude 'org/toradocu/generator/**'
Expand Down Expand Up @@ -396,42 +396,19 @@ task installGitHook(type: Copy) {
}
build.dependsOn(installGitHook)

build.dependsOn verifyGoogleJavaFormat
googleJavaFormat {
exclude 'out'
exclude 'src/test/resources'
}

shadowJar {
// default: "${baseName}-${version}-${classifier}.${extension}",
// where ${baseName} is the name of the directory into which the toradocu
// repository is cloned.
archiveName = "toradocu-${version}-${classifier}.${extension}"
}

task getCodeFormatScripts(type: Exec) {
description "Obtain the run-google-java-format scripts"
commandLine "bash", "-c",
"[ -d .run-google-java-format ] " +
"&& (cd .run-google-java-format && git pull -q) " +
"|| git clone -q https://github.com/plume-lib/run-google-java-format.git .run-google-java-format"
}

task checkFormat(type: Exec) {
description "Check whether the source code is properly formatted"
commandLine "bash", "-c",
"find src -name \"*.java\" -type f " +
"-not -path \"src/test/resources/*\" " +
"| xargs ./.run-google-java-format/check-google-java-format.py " +
"|| (echo 'Try running: gradle reformat' && false)"
}
checkFormat.dependsOn getCodeFormatScripts
build.dependsOn checkFormat

/* Format the code according to the Google Java format code style */
task reformat(type: Exec) {
description "Format the Java source code"
commandLine "bash", "-c",
"find src -name \"*.java\" -type f " +
"-not -path \"src/test/resources/*\" " +
"| xargs ./.run-google-java-format/run-google-java-format.py"
}
reformat.dependsOn getCodeFormatScripts

/* Downloads dependencies needed for the tutorial. */
task tutorial(type: Download) {
src ([
Expand Down
6 changes: 1 addition & 5 deletions git-pre-commit-hook.sh
Expand Up @@ -3,11 +3,7 @@
# Fail if any command fails
set -e

CHANGED_JAVA_FILES=`git diff --staged --name-only --diff-filter=ACM | grep -v 'src/test/resources/aspects/*' | grep -v 'src/main/resources/AspectTemplate.java' | grep '\.java$'` || true
if [ ! -z "$CHANGED_JAVA_FILES" ]; then
(cd .run-google-java-format && git pull -q) || git clone -q https://github.com/plume-lib/run-google-java-format.git .run-google-java-format
./.run-google-java-format/check-google-java-format.py ${CHANGED_JAVA_FILES}
fi
./gradlew verGJF

# This is for non-.java files.
# May need to remove files that are allowed to have trailing whitespace.
Expand Down

0 comments on commit 35da9e1

Please sign in to comment.