diff --git a/dev/intellij-setup.md b/dev/intellij-setup.md index 74b09a0739f..a3d9816ef40 100644 --- a/dev/intellij-setup.md +++ b/dev/intellij-setup.md @@ -47,7 +47,7 @@ will generate a report to show the current code coverage on the code (not just y ## Git Checkstyle Verification Hook (Optional) Git Checkstyle pre-commit hook can be installed to automatically run checkstyle verification before committing, saving cycle from avoiding the checkstyle failing later in Travis/CI environment. -The hook can be setup easily by running the /setup-hooks.sh script. +The hook can be setup easily by running the /hooks/install-hooks.sh script. ## Metadata The installation of a MySQL metadata store is outside the scope of this document, but instructions on setting up MySQL can be found at [docs/development/extensions-core/mysql.md](/docs/development/extensions-core/mysql.md). This assumes you followed the example there and have a database named `druid` with proper permissions for a user named `druid` and a password of `diurd`. diff --git a/hooks/install-hooks.sh b/hooks/install-hooks.sh new file mode 100755 index 00000000000..506816b4764 --- /dev/null +++ b/hooks/install-hooks.sh @@ -0,0 +1,40 @@ +#!/bin/bash -eu + +# 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. + +function cp_if_not_exist(){ + if [ -e "$2" ] + then + echo "$2 already exists!" + exit 1 + else + cp -r "$1" "$2" + fi +} + +if [ $# != 1 ] + then + echo 'usage: program {$DRUID_ROOT}' + exit 1 +fi + +DRUID_ROOT=$1 + +cp_if_not_exist ${DRUID_ROOT}/hooks/run-all-in-dir.py ${DRUID_ROOT}/.git/hooks/run-all-in-dir.py +cp_if_not_exist ${DRUID_ROOT}/hooks/pre-commit ${DRUID_ROOT}/.git/hooks/pre-commit +cp_if_not_exist ${DRUID_ROOT}/hooks/pre-push ${DRUID_ROOT}/.git/hooks/pre-push +cp_if_not_exist ${DRUID_ROOT}/hooks/pre-commits ${DRUID_ROOT}/.git/hooks/pre-commits +cp_if_not_exist ${DRUID_ROOT}/hooks/pre-pushes ${DRUID_ROOT}/.git/hooks/pre-pushes diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100755 index 00000000000..6cfd4b962e5 --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,18 @@ +#!/bin/bash -eu + +# 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. + +.git/hooks/run-all-in-dir.py .git/hooks/pre-commits \ No newline at end of file diff --git a/setup-hooks.sh b/hooks/pre-commits/_pre-commit.sample similarity index 94% rename from setup-hooks.sh rename to hooks/pre-commits/_pre-commit.sample index 85c60d1a725..b6db0410fba 100755 --- a/setup-hooks.sh +++ b/hooks/pre-commits/_pre-commit.sample @@ -1,4 +1,5 @@ #!/bin/bash -eu + # 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. @@ -14,4 +15,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -ln -s ../../hooks/pre-push.sh .git/hooks/pre-push +echo 'pre-commit sample' \ No newline at end of file diff --git a/hooks/pre-push b/hooks/pre-push new file mode 100755 index 00000000000..40c40db1209 --- /dev/null +++ b/hooks/pre-push @@ -0,0 +1,22 @@ +#!/bin/bash -eu + +# +# 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. +# + +.git/hooks/run-all-in-dir.py .git/hooks/pre-pushes $1 $2 \ No newline at end of file diff --git a/hooks/pre-pushes/_pre-push.sample b/hooks/pre-pushes/_pre-push.sample new file mode 100755 index 00000000000..a4ca214d844 --- /dev/null +++ b/hooks/pre-pushes/_pre-push.sample @@ -0,0 +1,18 @@ +#!/bin/bash -eu + +# 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. + +echo 'pre-push sample' \ No newline at end of file diff --git a/hooks/pre-push.sh b/hooks/pre-pushes/checkstyle-check similarity index 99% rename from hooks/pre-push.sh rename to hooks/pre-pushes/checkstyle-check index c1b51402872..fdfdd09eab2 100755 --- a/hooks/pre-push.sh +++ b/hooks/pre-pushes/checkstyle-check @@ -1,4 +1,5 @@ #!/bin/bash -eu + # 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. diff --git a/hooks/run-all-in-dir.py b/hooks/run-all-in-dir.py new file mode 100755 index 00000000000..6922e044f0e --- /dev/null +++ b/hooks/run-all-in-dir.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +# 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. + +import os +import sys +import subprocess + + +if len(sys.argv) < 2: + sys.stderr.write('usage: program \n') + sys.exit(1) + +hooks_dir = sys.argv[1] +args = sys.argv[2:] + +for hook in os.listdir(hooks_dir): + if not hook.startswith("_"): + command = [os.path.join(hooks_dir, hook)] + args + print("Running {}".format(command)) + subprocess.run(command, shell=True) diff --git a/hooks/uninstall-hooks.sh b/hooks/uninstall-hooks.sh new file mode 100755 index 00000000000..e118eb05d90 --- /dev/null +++ b/hooks/uninstall-hooks.sh @@ -0,0 +1,37 @@ +#!/bin/bash -eu + +# +# 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. +# + +if [ $# != 1 ] + then + echo 'usage: program {$DRUID_ROOT}' + exit 1 +fi + +DRUID_ROOT=$1 + +# This script does not remove .git/hooks/pre-commit, .git/hooks/pre-push, or any other git hook scripts +# because those files may have user-custom hooks. +# Instead, we remove only the files and directories that we are sure it is safe to remove. +rm -f ${DRUID_ROOT}/.git/hooks/run-all-in-dir.py +rm -rf ${DRUID_ROOT}/.git/hooks/pre-commits +rm -rf ${DRUID_ROOT}/.git/hooks/pre-pushes + +echo "This script does not remove or modify the git hook script files in .git/hooks, such as 'pre-commit' or 'pre-push'. Those scripts should be removed or modified manually."