From 2e0709f05b820ac339b8034f4dacbc56a4ece36c Mon Sep 17 00:00:00 2001 From: Austin Shalit Date: Wed, 16 May 2018 22:47:35 -0400 Subject: [PATCH] Add spotless to check line endings (#1055) --- build.gradle | 17 ++- styleguide/pmd-ruleset.xml | 8 +- test-scripts/deploy-and-run-test-on-robot.sh | 54 ++++----- test-scripts/jenkins-run-tests-get-results.sh | 18 +-- test-scripts/run-tests-on-robot.sh | 112 +++++++++--------- 5 files changed, 110 insertions(+), 99 deletions(-) diff --git a/build.gradle b/build.gradle index 6679374b62..c5f613c50f 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ plugins { id 'edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin' version '2.0' id 'edu.wpi.first.NativeUtils' version '1.6.2' id "edu.wpi.first.GradleJni" version "0.1.0" apply false + id "com.diffplug.gradle.spotless" version "3.10.0" id 'idea' id 'com.gradle.build-scan' version '1.13.1' } @@ -11,6 +12,17 @@ repositories { mavenCentral() } +spotless { + format 'misc', { + target '**/*.gradle', '**/*.md', '**/.gitignore', '**/*.yml', '**/*.sh', 'styleguide/*.xml' + lineEndings 'UNIX' + + trimTrailingWhitespace() + indentWithSpaces() + endWithNewline() + } +} + buildScan { termsOfServiceUrl = 'https://gradle.com/terms-of-service' termsOfServiceAgree = 'yes' @@ -54,15 +66,14 @@ task outputVersions() { } } -task build() {} - task libraryBuild() {} build.dependsOn outputVersions -task clean(type: Delete) { +task cleanBuildDir(type: Delete) { delete buildDir } +clean.dependsOn cleanBuildDir task copyAllOutputs(type: Copy) { destinationDir outputsFolder diff --git a/styleguide/pmd-ruleset.xml b/styleguide/pmd-ruleset.xml index 1b50aa778d..e4ee34d5ef 100644 --- a/styleguide/pmd-ruleset.xml +++ b/styleguide/pmd-ruleset.xml @@ -48,11 +48,11 @@ diff --git a/test-scripts/deploy-and-run-test-on-robot.sh b/test-scripts/deploy-and-run-test-on-robot.sh index c2d896e93c..f023a18e0e 100755 --- a/test-scripts/deploy-and-run-test-on-robot.sh +++ b/test-scripts/deploy-and-run-test-on-robot.sh @@ -37,28 +37,28 @@ TEST_RUN_ARGS="" PARAM_ARGS=${@:2} if [[ "$1" = java ]]; then - LANGUAGE=$1 - LOCAL_TEST_FILE=$DEFAULT_LOCAL_JAVA_TEST_FILE - DESTINATION_TEST_FILE=$DEFAULT_DESTINATION_JAVA_TEST_FILE + LANGUAGE=$1 + LOCAL_TEST_FILE=$DEFAULT_LOCAL_JAVA_TEST_FILE + DESTINATION_TEST_FILE=$DEFAULT_DESTINATION_JAVA_TEST_FILE elif [[ "$1" = cpp ]]; then - LANGUAGE=$1 - LOCAL_TEST_FILE=$DEFAULT_LOCAL_CPP_TEST_FILE - DESTINATION_TEST_FILE=$DEFAULT_DESTINATION_CPP_TEST_FILE + LANGUAGE=$1 + LOCAL_TEST_FILE=$DEFAULT_LOCAL_CPP_TEST_FILE + DESTINATION_TEST_FILE=$DEFAULT_DESTINATION_CPP_TEST_FILE elif [[ "$1" = "-h" ]]; then - printf "Usage:\n" - echo "$usage" - exit + printf "Usage:\n" + echo "$usage" + exit else - printf "Invalid language selection: %s\n\n" "$1" >&2 - echo "$usage" >&2 - exit 1 + printf "Invalid language selection: %s\n\n" "$1" >&2 + echo "$usage" >&2 + exit 1 fi # Check if the test file to upload exists if [[ ! -e ${LOCAL_TEST_FILE} ]]; then - printf "The test file does not exist: %s\nAre you sure that you compiled the tests??\n\n" "${LOCAL_TEST_FILE}" >&2 - echo "$usage" >&2 - exit 1 + printf "The test file does not exist: %s\nAre you sure that you compiled the tests??\n\n" "${LOCAL_TEST_FILE}" >&2 + echo "$usage" >&2 + exit 1 fi TEST_RUN_ARGS="${@:2}" @@ -73,17 +73,17 @@ SCP_NATIVE_LIBRARIES="scp ${DEFAULT_LIBRARY_NATIVE_FILES}/* ${ROBOT_ADDRESS}:${D CONFIG_NATIVE_LIBRARIES="ssh -t ${ADMIN_ROBOT_ADDRESS} ldconfig" if [ $(which sshpass) ]; then - sshpass -p "" ${SCP_NATIVE_LIBRARIES} - sshpass -p "" ${CONFIG_NATIVE_LIBRARIES} - sshpass -p "" ${SCP_TEST_SCRIPT} - sshpass -p "" ${SSH_CHMOD_AND_MAKE_TEMP_TEST_DIR} - sshpass -p "" ${SCP_TEST_PROGRAM} - sshpass -p "" ${SSH_RUN_TESTS} + sshpass -p "" ${SCP_NATIVE_LIBRARIES} + sshpass -p "" ${CONFIG_NATIVE_LIBRARIES} + sshpass -p "" ${SCP_TEST_SCRIPT} + sshpass -p "" ${SSH_CHMOD_AND_MAKE_TEMP_TEST_DIR} + sshpass -p "" ${SCP_TEST_PROGRAM} + sshpass -p "" ${SSH_RUN_TESTS} else - eval ${SCP_NATIVE_LIBRARIES} - eval ${CONFIG_NATIVE_LIBRARIES} - eval ${SCP_TEST_SCRIPT} - eval ${SSH_CHMOD_AND_MAKE_TEMP_TEST_DIR} - eval ${SCP_TEST_PROGRAM} - eval ${SSH_RUN_TESTS} + eval ${SCP_NATIVE_LIBRARIES} + eval ${CONFIG_NATIVE_LIBRARIES} + eval ${SCP_TEST_SCRIPT} + eval ${SSH_CHMOD_AND_MAKE_TEMP_TEST_DIR} + eval ${SCP_TEST_PROGRAM} + eval ${SSH_RUN_TESTS} fi diff --git a/test-scripts/jenkins-run-tests-get-results.sh b/test-scripts/jenkins-run-tests-get-results.sh index d1975f4d97..8981b4d78c 100755 --- a/test-scripts/jenkins-run-tests-get-results.sh +++ b/test-scripts/jenkins-run-tests-get-results.sh @@ -17,14 +17,14 @@ flock -x 200 || exit 1 # Ensure the teststand is dead SSH_STOP_TESTSTAND="ssh -t ${ROBOT_ADDRESS} sh -c '/etc/init.d/teststand stop; sleep 1'" if [ $(which sshpass) ]; then - sshpass -p "" ${SSH_STOP_TESTSTAND} + sshpass -p "" ${SSH_STOP_TESTSTAND} else - eval ${SSH_STOP_TESTSTAND} + eval ${SSH_STOP_TESTSTAND} fi # If there are already test results in the repository then remove them if [[ -e ${DEFAULT_LOCAL_TEST_RESULTS_DIR} ]]; then - rm -R ${DEFAULT_LOCAL_TEST_RESULTS_DIR} + rm -R ${DEFAULT_LOCAL_TEST_RESULTS_DIR} fi # Make the directory where the tests should live @@ -33,9 +33,9 @@ mkdir ${DEFAULT_LOCAL_TEST_RESULTS_DIR} 2>/dev/null # Remove the preivous test results from the the robot SSH_REMOVE_OLD_TEST_RESULTS="ssh -t ${ROBOT_ADDRESS} rm -R ${DEFAULT_DESTINATION_TEST_RESULTS_DIR}; mkdir ${DEFAULT_DESTINATION_TEST_RESULTS_DIR}" if [ $(which sshpass) ]; then - sshpass -p "" ${SSH_REMOVE_OLD_TEST_RESULTS} + sshpass -p "" ${SSH_REMOVE_OLD_TEST_RESULTS} else - eval ${SSH_REMOVE_OLD_TEST_RESULTS} + eval ${SSH_REMOVE_OLD_TEST_RESULTS} fi printf "Running cpp test\n" @@ -46,9 +46,9 @@ printf "Running cpp test\n" # Retrive the C++ Test Results SCP_GET_CPP_TEST_RESULT="scp ${ROBOT_ADDRESS}:${DEFAULT_DESTINATION_CPP_TEST_RESULTS} ${DEFAULT_LOCAL_CPP_TEST_RESULT}" if [ $(which sshpass) ]; then - sshpass -p "" ${SCP_GET_CPP_TEST_RESULT} + sshpass -p "" ${SCP_GET_CPP_TEST_RESULT} else - eval ${SCP_GET_CPP_TEST_RESULT} + eval ${SCP_GET_CPP_TEST_RESULT} fi sleep 10 @@ -59,9 +59,9 @@ sleep 10 # Retrive the Java Test Results SCP_GET_JAVA_TEST_RESULT="scp ${ROBOT_ADDRESS}:${DEFAULT_DESTINATION_JAVA_TEST_RESULTS} ${DEFAULT_LOCAL_JAVA_TEST_RESULT}" if [ $(which sshpass) ]; then - sshpass -p "" ${SCP_GET_JAVA_TEST_RESULT} + sshpass -p "" ${SCP_GET_JAVA_TEST_RESULT} else - eval ${SCP_GET_JAVA_TEST_RESULT} + eval ${SCP_GET_JAVA_TEST_RESULT} fi # Make sure that we got test results back. diff --git a/test-scripts/run-tests-on-robot.sh b/test-scripts/run-tests-on-robot.sh index e0785ad9e4..baa4da277f 100755 --- a/test-scripts/run-tests-on-robot.sh +++ b/test-scripts/run-tests-on-robot.sh @@ -34,10 +34,10 @@ Where: # Are you trying to run this program on a platform other than the roboRIO? if [[ ! -e "${DEFAULT_TEST_DIR}" ]]; then - printf "Failed to find %s\nAre you trying to run this file on your local computer?\n" "${DEFAULT_TEST_DIR}" - printf "This script should only be run on the roboRIO.\n\n" - echo "$usage" - exit 1 + printf "Failed to find %s\nAre you trying to run this file on your local computer?\n" "${DEFAULT_TEST_DIR}" + printf "This script should only be run on the roboRIO.\n\n" + echo "$usage" + exit 1 fi LANGUAGE=none @@ -53,21 +53,21 @@ DEFAULT_ARGS="" # Determine the language that we are attempting to run if [[ "$1" = java ]]; then - LANGUAGE=$1 - TEST_FILE=$DEFAULT_JAVA_TEST_NAME - DEFAULT_ARGS=$DEFAULT_JAVA_TEST_ARGS + LANGUAGE=$1 + TEST_FILE=$DEFAULT_JAVA_TEST_NAME + DEFAULT_ARGS=$DEFAULT_JAVA_TEST_ARGS elif [[ "$1" = cpp ]]; then - LANGUAGE=$1 - TEST_FILE=$DEFAULT_CPP_TEST_NAME - DEFAULT_ARGS=$DEFAULT_CPP_TEST_ARGS + LANGUAGE=$1 + TEST_FILE=$DEFAULT_CPP_TEST_NAME + DEFAULT_ARGS=$DEFAULT_CPP_TEST_ARGS elif [[ "$1" = "-h" ]]; then - #If the first argument is the help option - #Allow it to be searhced for in getopts - PARAM_ARGS=${@} + #If the first argument is the help option + #Allow it to be searhced for in getopts + PARAM_ARGS=${@} else - printf "Invalid language selection: %s\n\n" "$1" >&2 - echo "$usage" >&2 - exit 1 + printf "Invalid language selection: %s\n\n" "$1" >&2 + echo "$usage" >&2 + exit 1 fi PARAM_COUNTER=2 @@ -75,41 +75,41 @@ printf "Param Args ${PARAM_ARGS}\n" # Check for optional paramaters while getopts ':hmd:A' option $PARAM_ARGS ; do - case "$option" in - h) - # Print the help message - printf "Usage:\n" - echo "$usage" - exit - ;; - A) - # Remove the default arguments - RUN_WITH_DEFAULT_ARGS=false - PARAM_COUNTER=$[$PARAM_COUNTER +1] - ;; - d) - TEST_DIR=$OPTARG - # Since we are selecting the directory the run args start from the 5th argument - PARAM_COUNTER=$[$PARAM_COUNTER +2] - ;; - ?) - # When an unknown param is found then we are done so break - break - ;; - esac + case "$option" in + h) + # Print the help message + printf "Usage:\n" + echo "$usage" + exit + ;; + A) + # Remove the default arguments + RUN_WITH_DEFAULT_ARGS=false + PARAM_COUNTER=$[$PARAM_COUNTER +1] + ;; + d) + TEST_DIR=$OPTARG + # Since we are selecting the directory the run args start from the 5th argument + PARAM_COUNTER=$[$PARAM_COUNTER +2] + ;; + ?) + # When an unknown param is found then we are done so break + break + ;; + esac done TEST_RUN_ARGS=${@:$[$PARAM_COUNTER +1]} if [[ "$RUN_WITH_DEFAULT_ARGS" == true ]]; then - TEST_RUN_ARGS="${DEFAULT_ARGS} ${TEST_RUN_ARGS}" + TEST_RUN_ARGS="${DEFAULT_ARGS} ${TEST_RUN_ARGS}" fi # Make sure at least two paramaters are passed or four if running with -d option if [[ $# -lt $PARAM_COUNTER ]]; then - printf "Invalid arg count. Should be %s, was %s.\n" "${PARAM_COUNTER}" "$#" - echo "$usage" - exit 1 + printf "Invalid arg count. Should be %s, was %s.\n" "${PARAM_COUNTER}" "$#" + echo "$usage" + exit 1 fi # Kill all running robot programs @@ -117,11 +117,11 @@ killall java FRCUserProgram # If we are running with the -d argument move the test to the DEFAULT_TEST_DIR if [[ ! -e "${TEST_DIR}/${TEST_FILE}" ]]; then - printf "Failed to find %s.\nDid you copy the test file correctly?\n" "${TEST_DIR}/${TEST_FILE}" - echo "$usage" - exit 1 + printf "Failed to find %s.\nDid you copy the test file correctly?\n" "${TEST_DIR}/${TEST_FILE}" + echo "$usage" + exit 1 elif [[ $TEST_DIR != "$DEFAULT_TEST_DIR" ]]; then - mv "${TEST_DIR}/${TEST_FILE}" "${DEFAULT_TEST_DIR}" + mv "${TEST_DIR}/${TEST_FILE}" "${DEFAULT_TEST_DIR}" fi # Make sure the excecutable file has permission to run @@ -133,11 +133,11 @@ export eval `/sbin/fw_printenv DeviceCode FPGADeviceCode DeviceDesc TargetClass` # Store the run command for the language RUN_COMMAND=none if [[ ${LANGUAGE} = java ]]; then - chmod a+x ${DEFAULT_JAVA_TEST_NAME} - RUN_COMMAND="env LD_LIBRARY_PATH=/opt/GenICam_v3_0_NI/bin/Linux32_ARM/:/usr/local/frc/lib ${DEFAULT_PATH_TO_JRE} -ea -jar ${DEFAULT_JAVA_TEST_NAME} ${TEST_RUN_ARGS}" + chmod a+x ${DEFAULT_JAVA_TEST_NAME} + RUN_COMMAND="env LD_LIBRARY_PATH=/opt/GenICam_v3_0_NI/bin/Linux32_ARM/:/usr/local/frc/lib ${DEFAULT_PATH_TO_JRE} -ea -jar ${DEFAULT_JAVA_TEST_NAME} ${TEST_RUN_ARGS}" elif [[ ${LANGUAGE} = cpp ]]; then - chmod a+x ${DEFAULT_CPP_TEST_NAME} - RUN_COMMAND="./${DEFAULT_CPP_TEST_NAME} ${TEST_RUN_ARGS}" + chmod a+x ${DEFAULT_CPP_TEST_NAME} + RUN_COMMAND="./${DEFAULT_CPP_TEST_NAME} ${TEST_RUN_ARGS}" fi printf "Running: %s\n\n" "${RUN_COMMAND}" @@ -148,10 +148,10 @@ echo ${CORE_LOCATION} > /proc/sys/kernel/core_pattern ulimit -c unlimited eval ${RUN_COMMAND} if [[ $? -gt 127 && -e ${CORE_LOCATION} ]]; then - mv ${CORE_LOCATION} ${COREDUMP_DIR}/core.${LANGUAGE} - if [[ ${LANGUAGE} = java ]]; then - cp -p ${DEFAULT_JAVA_TEST_NAME} ${COREDUMP_DIR}/ - elif [[ ${LANGUAGE} = cpp ]]; then - cp -p ${DEFAULT_CPP_TEST_NAME} ${COREDUMP_DIR}/ - fi + mv ${CORE_LOCATION} ${COREDUMP_DIR}/core.${LANGUAGE} + if [[ ${LANGUAGE} = java ]]; then + cp -p ${DEFAULT_JAVA_TEST_NAME} ${COREDUMP_DIR}/ + elif [[ ${LANGUAGE} = cpp ]]; then + cp -p ${DEFAULT_CPP_TEST_NAME} ${COREDUMP_DIR}/ + fi fi