diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..1b04cdad3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +[*.sh] +indent_style = space +indent_size = 2 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 63b7ab9f9..64f9e1cda 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,6 @@ repos: - id: check-added-large-files - id: file-contents-sorter files: .gitignore - - repo: local hooks: - id: rat @@ -39,3 +38,15 @@ repos: dev/release/run_rat.sh apache-arrow-go.tar.gz" always_run: true pass_filenames: false + - repo: https://github.com/koalaman/shellcheck-precommit + rev: v0.10.0 + hooks: + - id: shellcheck + - repo: https://github.com/scop/pre-commit-shfmt + rev: v3.9.0-1 + hooks: + - id: shfmt + args: + # The default args is "--write --simplify" but we don't use + # "--simplify". Because it's conflicted will ShellCheck. + - "--write" diff --git a/ci/scripts/java_build.sh b/ci/scripts/java_build.sh index b5a12d917..f3f202375 100755 --- a/ci/scripts/java_build.sh +++ b/ci/scripts/java_build.sh @@ -22,16 +22,15 @@ if [[ "${ARROW_JAVA_BUILD:-ON}" != "ON" ]]; then exit fi -arrow_dir=${1} source_dir=${1} build_dir=${2} java_jni_dist_dir=${3} -: ${BUILD_DOCS_JAVA:=OFF} +: "${BUILD_DOCS_JAVA:=OFF}" mvn="mvn -B -DskipTests -Drat.skip=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn" -if [ $ARROW_JAVA_SKIP_GIT_PLUGIN ]; then +if [ "$ARROW_JAVA_SKIP_GIT_PLUGIN" ]; then mvn="${mvn} -Dmaven.gitcommitid.skip=true" fi @@ -50,13 +49,13 @@ cp -r "${source_dir}/dev" "${build_dir}" poms=$(find "${source_dir}" -not \( -path "${source_dir}"/build -prune \) -type f -name pom.xml) if [[ "$OSTYPE" == "darwin"* ]]; then - poms=$(echo "$poms" | xargs -n1 python -c "import sys; import os.path; print(os.path.relpath(sys.argv[1], '${source_dir}'))") + poms=$(echo "$poms" | xargs -n1 python -c "import sys; import os.path; print(os.path.relpath(sys.argv[1], '${source_dir}'))") else - poms=$(echo "$poms" | xargs -n1 realpath -s --relative-to="${source_dir}") + poms=$(echo "$poms" | xargs -n1 realpath -s --relative-to="${source_dir}") fi for source_root in $(echo "${poms}" | awk -F/ '{print $1}' | sort -u); do - cp -r "${source_dir}/${source_root}" "${build_dir}" + cp -r "${source_dir}/${source_root}" "${build_dir}" done pushd "${build_dir}" @@ -79,9 +78,9 @@ ${mvn} -T 2C clean install if [ "${BUILD_DOCS_JAVA}" == "ON" ]; then # HTTP pooling is turned of to avoid download issues https://issues.apache.org/jira/browse/ARROW-11633 # GH-43378: Maven site plugins not compatible with multithreading - mkdir -p ${build_dir}/docs/java/reference + mkdir -p "${build_dir}"/docs/java/reference ${mvn} -Dcheckstyle.skip=true -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false clean install site - rsync -a target/site/apidocs/ ${build_dir}/docs/java/reference + rsync -a target/site/apidocs/ "${build_dir}"/docs/java/reference fi popd diff --git a/ci/scripts/java_jni_build.sh b/ci/scripts/java_jni_build.sh index 7b63dbeea..44388e33f 100755 --- a/ci/scripts/java_jni_build.sh +++ b/ci/scripts/java_jni_build.sh @@ -27,54 +27,54 @@ prefix_dir="${build_dir}/java-jni" echo "=== Clear output directories and leftovers ===" # Clear output directories and leftovers -rm -rf ${build_dir} +rm -rf "${build_dir}" echo "=== Building Arrow Java C Data Interface native library ===" mkdir -p "${build_dir}" pushd "${build_dir}" case "$(uname)" in - Linux) - n_jobs=$(nproc) - ;; - Darwin) - n_jobs=$(sysctl -n hw.logicalcpu) - ;; - *) - n_jobs=${NPROC:-1} - ;; +Linux) + n_jobs=$(nproc) + ;; +Darwin) + n_jobs=$(sysctl -n hw.logicalcpu) + ;; +*) + n_jobs=${NPROC:-1} + ;; esac -: ${ARROW_JAVA_BUILD_TESTS:=${ARROW_BUILD_TESTS:-OFF}} -: ${CMAKE_BUILD_TYPE:=release} +: "${ARROW_JAVA_BUILD_TESTS:=${ARROW_BUILD_TESTS:-OFF}}" +: "${CMAKE_BUILD_TYPE:=release}" cmake \ - -DARROW_JAVA_JNI_ENABLE_DATASET=${ARROW_DATASET:-OFF} \ - -DARROW_JAVA_JNI_ENABLE_GANDIVA=${ARROW_GANDIVA:-OFF} \ - -DARROW_JAVA_JNI_ENABLE_ORC=${ARROW_ORC:-OFF} \ - -DBUILD_TESTING=${ARROW_JAVA_BUILD_TESTS} \ - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \ - -DCMAKE_PREFIX_PATH=${arrow_install_dir} \ - -DCMAKE_INSTALL_PREFIX=${prefix_dir} \ - -DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD:-OFF} \ + -DARROW_JAVA_JNI_ENABLE_DATASET="${ARROW_DATASET:-OFF}" \ + -DARROW_JAVA_JNI_ENABLE_GANDIVA="${ARROW_GANDIVA:-OFF}" \ + -DARROW_JAVA_JNI_ENABLE_ORC="${ARROW_ORC:-OFF}" \ + -DBUILD_TESTING="${ARROW_JAVA_BUILD_TESTS}" \ + -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \ + -DCMAKE_PREFIX_PATH="${arrow_install_dir}" \ + -DCMAKE_INSTALL_PREFIX="${prefix_dir}" \ + -DCMAKE_UNITY_BUILD="${CMAKE_UNITY_BUILD:-OFF}" \ -DProtobuf_USE_STATIC_LIBS=ON \ -GNinja \ - ${JAVA_JNI_CMAKE_ARGS:-} \ - ${arrow_dir} + "${JAVA_JNI_CMAKE_ARGS:-}" \ + "${arrow_dir}" export CMAKE_BUILD_PARALLEL_LEVEL=${n_jobs} -cmake --build . --config ${CMAKE_BUILD_TYPE} +cmake --build . --config "${CMAKE_BUILD_TYPE}" if [ "${ARROW_JAVA_BUILD_TESTS}" = "ON" ]; then ctest \ --output-on-failure \ - --parallel ${n_jobs} \ + --parallel "${n_jobs}" \ --timeout 300 fi -cmake --build . --config ${CMAKE_BUILD_TYPE} --target install +cmake --build . --config "${CMAKE_BUILD_TYPE}" --target install popd -mkdir -p ${dist_dir} +mkdir -p "${dist_dir}" # For Windows. *.dll are installed into bin/ on Windows. if [ -d "${prefix_dir}/bin" ]; then - mv ${prefix_dir}/bin/* ${dist_dir}/ + mv "${prefix_dir}"/bin/* "${dist_dir}"/ else - mv ${prefix_dir}/lib/* ${dist_dir}/ + mv "${prefix_dir}"/lib/* "${dist_dir}"/ fi diff --git a/ci/scripts/java_test.sh b/ci/scripts/java_test.sh index 9d4bc018b..6449bbc2c 100755 --- a/ci/scripts/java_test.sh +++ b/ci/scripts/java_test.sh @@ -22,7 +22,6 @@ if [[ "${ARROW_JAVA_TEST:-ON}" != "ON" ]]; then exit fi -arrow_dir=${1} source_dir=${1} build_dir=${2} java_jni_dist_dir=${3} @@ -31,7 +30,7 @@ mvn="mvn -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMave # Use `2 * ncores` threads mvn="${mvn} -T 2C" -pushd ${build_dir} +pushd "${build_dir}" ${mvn} -Darrow.test.dataRoot="${source_dir}/testing/data" clean test @@ -43,13 +42,16 @@ if [ "${ARROW_JAVA_JNI}" = "ON" ]; then fi if [ "${#projects[@]}" -gt 0 ]; then ${mvn} clean test \ - -Parrow-jni \ - -pl $(IFS=,; echo "${projects[*]}") \ - -Darrow.cpp.build.dir=${java_jni_dist_dir} + -Parrow-jni \ + -pl "$( + IFS=, + echo \""${projects[*]}"\" + )" \ + -Darrow.cpp.build.dir="${java_jni_dist_dir}" fi if [ "${ARROW_JAVA_CDATA}" = "ON" ]; then - ${mvn} clean test -Parrow-c-data -pl c -Darrow.c.jni.dist.dir=${java_jni_dist_dir} + ${mvn} clean test -Parrow-c-data -pl c -Darrow.c.jni.dist.dir="${java_jni_dist_dir}" fi popd