diff --git a/.githooks/applypatch-msg b/.githooks/applypatch-msg new file mode 100755 index 000000000..9238151fc --- /dev/null +++ b/.githooks/applypatch-msg @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if applypatch-msg is defined, skip if not +has_hook_script applypatch-msg || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" applypatch-msg || { + echo + echo "applypatch-msg hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/commit-msg b/.githooks/commit-msg new file mode 100755 index 000000000..bcf5ca4c3 --- /dev/null +++ b/.githooks/commit-msg @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if commit-msg is defined, skip if not +has_hook_script commit-msg || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" commit-msg || { + echo + echo "commit-msg hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/post-applypatch b/.githooks/post-applypatch new file mode 100755 index 000000000..9ccf912ec --- /dev/null +++ b/.githooks/post-applypatch @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if post-applypatch is defined, skip if not +has_hook_script post-applypatch || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" post-applypatch || { + echo + echo "post-applypatch hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/post-checkout b/.githooks/post-checkout new file mode 100755 index 000000000..99afe2778 --- /dev/null +++ b/.githooks/post-checkout @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if post-checkout is defined, skip if not +has_hook_script post-checkout || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" post-checkout || { + echo + echo "post-checkout hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/post-commit b/.githooks/post-commit new file mode 100755 index 000000000..6328db64d --- /dev/null +++ b/.githooks/post-commit @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if post-commit is defined, skip if not +has_hook_script post-commit || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" post-commit || { + echo + echo "post-commit hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/post-merge b/.githooks/post-merge new file mode 100755 index 000000000..df67e6cee --- /dev/null +++ b/.githooks/post-merge @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if post-merge is defined, skip if not +has_hook_script post-merge || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" post-merge || { + echo + echo "post-merge hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/post-receive b/.githooks/post-receive new file mode 100755 index 000000000..3d602239c --- /dev/null +++ b/.githooks/post-receive @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if post-receive is defined, skip if not +has_hook_script post-receive || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" post-receive || { + echo + echo "post-receive hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/post-rewrite b/.githooks/post-rewrite new file mode 100755 index 000000000..b8b44e6a2 --- /dev/null +++ b/.githooks/post-rewrite @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if post-rewrite is defined, skip if not +has_hook_script post-rewrite || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" post-rewrite || { + echo + echo "post-rewrite hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/post-update b/.githooks/post-update new file mode 100755 index 000000000..2952ab26d --- /dev/null +++ b/.githooks/post-update @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if post-update is defined, skip if not +has_hook_script post-update || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" post-update || { + echo + echo "post-update hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/pre-applypatch b/.githooks/pre-applypatch new file mode 100755 index 000000000..36444ec1c --- /dev/null +++ b/.githooks/pre-applypatch @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if pre-applypatch is defined, skip if not +has_hook_script pre-applypatch || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" pre-applypatch || { + echo + echo "pre-applypatch hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/pre-auto-gc b/.githooks/pre-auto-gc new file mode 100755 index 000000000..744b350a2 --- /dev/null +++ b/.githooks/pre-auto-gc @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if pre-auto-gc is defined, skip if not +has_hook_script pre-auto-gc || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" pre-auto-gc || { + echo + echo "pre-auto-gc hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 000000000..13052d1c2 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,154 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (C) 2015-2017 Carlos Jenkins +# +# Licensed 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. + +""" +Small delegating Python script to allow multiple hooks in a git repository. + +Usage: + +Make your building system to create a symbolic link in the git hooks directory +to this script with the name of the hook you want to attend. For example, +``pre-commit``. + +This hook will then execute, in alphabetic order, all executables files +(subhooks) found under a folder named after the hook type you're attending +suffixed with ``.d``. For example, ``pre-commit.d``. + +For example: + +``` +.git/hooks/ +|_ pre-commit +|_ pre-commit.d/ + |_ 01-cpp_coding_standard + |_ 02-python_coding_standard + |_ 03-something_else +``` + +Additionally, colored logging is supported if the package colorlog is +installed. +""" + +from sys import argv +from logging import getLogger +from subprocess import Popen, PIPE +from os import access, listdir, X_OK +from os.path import isfile, isdir, abspath, normpath, dirname, join, basename + + +GIT_HOOKS = [ + 'applypatch-msg', + 'commit-msg', + 'fsmonitor-watchman', + 'post-checkout', + 'post-commit', + 'post-merge', + 'post-update', + 'pre-applypatch', + 'pre-commit', + 'pre-push', + 'pre-rebase', + 'pre-receive', + 'prepare-commit-msg', + 'update', +] + + +def setup_logging(): + """ + Setup logging with support for colored output if available. + """ + + from logging import basicConfig, DEBUG + + FORMAT = ( + ' %(log_color)s%(levelname)-8s%(reset)s | ' + '%(log_color)s%(message)s%(reset)s' + ) + + logging_kwargs = { + 'level': DEBUG, + } + + try: + from logging import StreamHandler + from colorlog import ColoredFormatter + + stream = StreamHandler() + stream.setFormatter(ColoredFormatter(FORMAT)) + + logging_kwargs['handlers'] = [stream] + + except ImportError: + pass + + basicConfig(**logging_kwargs) + + +def main(): + """ + Execute subhooks for the assigned hook type. + """ + setup_logging() + log = getLogger(basename(__file__)) + + # Check multihooks facing what hook type + hook_type = basename(__file__) + if hook_type not in GIT_HOOKS: + log.fatal('Unknown hook type: {}'.format(hook_type)) + exit(1) + + # Lookup for sub-hooks directory + root = normpath(abspath(dirname(__file__))) + hooks_dir = join(root, '{}.d'.format(hook_type)) + if not isdir(hooks_dir): + log.warning('No such directory: {}'.format(hooks_dir)) + exit(0) + + # Gather scripts to call + files = [join(hooks_dir, f) for f in listdir(hooks_dir)] + hooks = sorted( + [h for h in files if isfile(h) and access(h, X_OK)] + ) + if not hooks: + log.warning('No sub-hooks found for {}.'.format(hook_type)) + exit(0) + + # Execute hooks + for h in hooks: + hook_id = '{}.d/{}'.format(hook_type, basename(h)) + log.info('Running hook {}...'.format(hook_id)) + + proc = Popen([h] + argv[1:], stdout=PIPE, stderr=PIPE) + stdout_raw, stderr_raw = proc.communicate() + + stdout = stdout_raw.decode('utf-8').strip() + stderr = stderr_raw.decode('utf-8').strip() + + if stdout: + log.info(stdout) + if stderr: + log.error(stderr) + + # Log errors if a hook failed + if proc.returncode != 0: + log.error('Hook {} failed. Aborting...'.format(hook_id)) + exit(proc.returncode) + + +if __name__ == '__main__': + main() diff --git a/.githooks/pre-commit.d/check_signature b/.githooks/pre-commit.d/check_signature new file mode 100755 index 000000000..d9832f062 --- /dev/null +++ b/.githooks/pre-commit.d/check_signature @@ -0,0 +1,23 @@ +#!/bin/bash + +PWD=`pwd` +globalEmail=`git config --global --get user.email` +signingKey=$( git config --global --get user.signingkey ) +workEmail="julien.gribonvald@recia.fr" + +echo "Using signing key "$signingKey"" + +if [[ $PWD != "*demo*" && $globalEmail != $workEmail ]]; +then + echo "Commit email and global git config email differ" + echo "Global commit email: "$globalEmail"" + echo "Committing email expected: $workEmail" + exit 1 +elif [[ -z $signingKey ]]; +then + echo "No signing key found. Check global gitconfig that provided "$signingKey"" + exit 1 +else + echo "" + exit 0 +fi diff --git a/.githooks/pre-commit.d/load-nvm b/.githooks/pre-commit.d/load-nvm new file mode 100755 index 000000000..39faff404 --- /dev/null +++ b/.githooks/pre-commit.d/load-nvm @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if pre-commit is defined, skip if not +has_hook_script pre-commit || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" pre-commit || { + echo + echo "pre-commit hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/pre-commit.d/mvn_chek_on_pre-commit b/.githooks/pre-commit.d/mvn_chek_on_pre-commit new file mode 100755 index 000000000..3e0c64b45 --- /dev/null +++ b/.githooks/pre-commit.d/mvn_chek_on_pre-commit @@ -0,0 +1,29 @@ +#!/bin/bash + +# save the file as /.git/hooks/pre-commit.d/mvn_test and chmod +x + +echo "Running mvn checks before commit" + +# test Java version +java -version 2>&1 | grep -q -e "OpenJDK .*Temurin-11" && echo "Your java version is an OpenJDK Temurin version 11." || (echo "Your java version is not and OpenJDK Temuring version 11." && exit 1) + +# retrieving current working directory +CWD=`pwd` +MAIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# go to main project dir +cd $MAIN_DIR/../../ +# running maven conform test +#MVN_RESULT=$(JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/ ./mvnw notice:check sortpom:verify 2>&1) +MVN_RESULT=$(./mvnw notice:check sortpom:verify 2>&1) +if [ $? -ne 0 ]; then + echo + echo "${MVN_RESULT}" + #echo "${MVN_RESULT}" | ((tee /dev/fd/5 | grep -A 10 -B 2 "Reactor Summary:" >/dev/fd/4) 5>&1 | sed -n -e '/^Failed tests:/,/Tests run:.*$/ p' ) 4>&1 + echo + echo "Error while testing the code" + # go back to current working dir + cd $CWD + exit 1 +fi +# go back to current working dir +cd $CWD diff --git a/.githooks/pre-push b/.githooks/pre-push new file mode 100755 index 000000000..f398fe3e8 --- /dev/null +++ b/.githooks/pre-push @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if pre-push is defined, skip if not +has_hook_script pre-push || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" pre-push || { + echo + echo "pre-push hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/pre-rebase b/.githooks/pre-rebase new file mode 100755 index 000000000..1d9c914e5 --- /dev/null +++ b/.githooks/pre-rebase @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if pre-rebase is defined, skip if not +has_hook_script pre-rebase || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" pre-rebase || { + echo + echo "pre-rebase hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/pre-receive b/.githooks/pre-receive new file mode 100755 index 000000000..776b48bd8 --- /dev/null +++ b/.githooks/pre-receive @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if pre-receive is defined, skip if not +has_hook_script pre-receive || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" pre-receive || { + echo + echo "pre-receive hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/prepare-commit-msg b/.githooks/prepare-commit-msg new file mode 100755 index 000000000..8903b80fb --- /dev/null +++ b/.githooks/prepare-commit-msg @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if prepare-commit-msg is defined, skip if not +has_hook_script prepare-commit-msg || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" prepare-commit-msg || { + echo + echo "prepare-commit-msg hook failed (cannot be bypassed with --no-verify due to Git specs)" + exit 1 +} diff --git a/.githooks/push-to-checkout b/.githooks/push-to-checkout new file mode 100755 index 000000000..e874ad2a0 --- /dev/null +++ b/.githooks/push-to-checkout @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if push-to-checkout is defined, skip if not +has_hook_script push-to-checkout || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" push-to-checkout || { + echo + echo "push-to-checkout hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/sendemail-validate b/.githooks/sendemail-validate new file mode 100755 index 000000000..04e51c916 --- /dev/null +++ b/.githooks/sendemail-validate @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if sendemail-validate is defined, skip if not +has_hook_script sendemail-validate || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" sendemail-validate || { + echo + echo "sendemail-validate hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/.githooks/update b/.githooks/update new file mode 100755 index 000000000..476271442 --- /dev/null +++ b/.githooks/update @@ -0,0 +1,49 @@ +#!/bin/sh +#yorkie 2.0.0 + +command_exists () { + command -v "$1" >/dev/null 2>&1 +} + +has_hook_script () { + [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:" +} + +# OS X and Linux only +load_nvm () { + # If nvm is not loaded, load it + command_exists nvm || { + export NVM_DIR="$1" + [ -s "$1/nvm.sh" ] && . "$1/nvm.sh" + } +} + +# OS X and Linux only +run_nvm () { + # If nvm has been loaded correctly, use project .nvmrc + command_exists nvm && [ -f .nvmrc ] && nvm use +} + +cd "." + +# Check if update is defined, skip if not +has_hook_script update || exit 0 + +# Add common path where Node can be found +# Brew standard installation path /usr/local/bin +# Node standard installation path /usr/local +export PATH="$PATH:/usr/local/bin:/usr/local" + +# Try to load nvm using path of standard installation +load_nvm /home/${USER}/.nvm +run_nvm + +# Export Git hook params +export GIT_PARAMS="$*" + +# Run hook +node "./node_modules/yorkie/src/runner.js" update || { + echo + echo "update hook failed (add --no-verify to bypass)" + exit 1 +} diff --git a/doc/dev.md b/doc/dev.md index e2fb13709..f5565a412 100644 --- a/doc/dev.md +++ b/doc/dev.md @@ -1,107 +1,132 @@ -# migration help +## migration help ## migrating from utf8 to utf8mb4 -- old liquibase migration files where removed and a new init schema was generated -- to migrate : -__Don't forget to make a dump of your datas before such operation__ -1. dump datas with -```sql - mysqldump -h hostname -u user -p --no-create-info --complete-insert --extended-insert --ignore-table="publisher.databasechangeloglock" --ignore-table="publisher.databasechangelog" --ignore-table="publisher.t_persistent_audit_event" --ignore-table="publisher.t_persistent_audit_event_data" "publisher" > "publisher.sql" -``` -2. drop and recreate database -```sql - drop database publisher; - create database publisher DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci; -``` -3. run the publisher app or run -```mvn -./mvnw compile liquibase:update -``` -4. import dumped datas -```sql - delete from publisher.t_user; - \. publisher.sql -``` -# mvn commands +* old liquibase migration files where removed and a new init schema was generated +* to migrate : + **Don't forget to make a dump of your datas before such operation** + +1. dump datas with +2. drop and recreate database +3. run the publisher app or run +4. import dumped datas + +## developpers requirements + +1. This project have some dev requirements, like using nvm as a file .nvmrc is provided for all developpers use the same node version. The nvmrc file should follow the last quilified node version and according to CI test +2. Also this project embed some git hooks, so please configure hooks path for this project with this command `git config core.hooksPath .githooks` +3. As node version giit hooks check the java version, so please update the `.githooks/pre-commit.d/mvn_chek_on_pre-commit` file to follow versions + +## mvn commands ## to add NOTICE -`./mvnw notice:check` Checks that a NOTICE file exists and that its content match what would be generated. -`./mvnw notice:generate` Generates a new NOTICE file, replacing any existing NOTICE file. +`./mvnw notice:check` Checks that a NOTICE file exists and that its content match what would be generated. +`./mvnw notice:generate` Generates a new NOTICE file, replacing any existing NOTICE file. ## to add licence headers -`./mvnw license:check` verify if some files miss license header -`./mvnw license:format` add the license header when missing. If a header is existing, it is updated to the new one. + +`./mvnw license:check` verify if some files miss license header +`./mvnw license:format` add the license header when missing. If a header is existing, it is updated to the new one. `./mvnw license:remove` remove existing license header ## to sort dependencies in pom -`./mvnw sortpom:sort` will sort all in pom + +`./mvnw sortpom:sort` will sort all in pom `./mvnw sortpom:verify` will check the order in the pom and provide a bak file to compare. ## In dev process when changing the entities -`./mvnw clean generate-sources` will generates new or modified Q__ classes or to update evaluator's entites when updating evaluator lib + +`./mvnw clean generate-sources` will generates new or modified Q\_\_ classes or to update evaluator's entites when updating evaluator lib ## To see deprecated code and warnings - `./mvnw compile -Dmaven.compiler.showWarnings=true -Dmaven.compiler.showDeprecation=true` +`./mvnw compile -Dmaven.compiler.showWarnings=true -Dmaven.compiler.showDeprecation=true` ## Liquibase memento : -[WARN]JAVA 8 use: Don't forget to add `-Djadira.usertype.useJdbc42Apis=false` jvm arg to the command line -- see in liquibase.properties.generation to set database name and defaultSchemaName (important for mysql, schemaName must be equals to database name) -- on non local database you can have X11 error if your are running the script from a server, see in liquibase.properties.generation property promptOnNonLocalDatabase to set to false -- `./mvnw compile liquibase:update` will apply changelog not loaded (from liquibase files) to the database -- `./mvnw compile liquibase:generateChangeLog` will generate the creation of database changelog file -- `./mvnw compile liquibase:diff` to generate each diff -- IMPORTANT : check for mysql that table names are in lower case in changelog files, do sames things for all table links... +\[WARN\]JAVA 8 use: Don't forget to add `-Djadira.usertype.useJdbc42Apis=false` jvm arg to the command line + +* see in liquibase.properties.generation to set database name and defaultSchemaName (important for mysql, schemaName must be equals to database name) +* on non local database you can have X11 error if your are running the script from a server, see in liquibase.properties.generation property promptOnNonLocalDatabase to set to false +* `./mvnw compile liquibase:update` will apply changelog not loaded (from liquibase files) to the database +* `./mvnw compile liquibase:generateChangeLog` will generate the creation of database changelog file +* `./mvnw compile liquibase:diff` to generate each diff +* IMPORTANT : check for mysql that table names are in lower case in changelog files, do sames things for all table links... ## to run tests : + ### Init steps : -- running local docker `docker run -it -p 3306:3306/tcp --health-cmd="mysqladmin -uroot -proot ping" --health-interval=10s --health-timeout=10s --health-retries=10 -e "TZ=Europe/Paris" -e "MYSQL_USER=root" -e "MYSQL_ROOT_PASSWORD=root" -e "MYSQL_DATABASE=publisher_test" -e "MYSQL_DEFAULT_STORAGE_ENGINE=InnoDB" -e "MYSQL_CHARACTER_SET_SERVER=utf8mb4" -e "MYSQL_COLLATION_SERVER=utf8mb4_unicode_520_ci" -e "MYSQL_INNODB_BUFFER_POOL_SIZE=2G" -e "MYSQL_INNODB_DEFAULT_ROW_FORMAT=dynamic" -e "MYSQL_INNODB_DATA_FILE_PATH=ibdata1:100M:autoextend:max:10G" -e "MYSQL_INNODB_FLUSH_LOG_AT_TRX_COMMIT=1" -e "MYSQL_INNODB_LOG_BUFFER_SIZE=64M" -e "MYSQL_INNODB_LOG_FILE_SIZE=256M" -e "MYSQL_INNODB_STRICT_MODE=ON" -e "MYSQL_LOWER_CASE_TABLE_NAMES=1" -e "MYSQL_MAX_CONNECT_ERRORS=100" -e "MYSQL_MAX_CONNECTIONS=1000" -e "MYSQL_QUERY_CACHE_LIMIT=10M" -e "MYSQL_QUERY_CACHE_SIZE=0" -e "MYSQL_QUERY_CACHE_TYPE=OFF" wodby/mariadb:latest` -- `./mvnw clean generate-sources compile liquibase:update` -- `mysql -h127.0.0.1 -u root -proot -e "ALTER TABLE publisher_test.t_permission CHANGE perm perm VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NULL;"` -- run the openldap-unittest docker like on github-action description +* running local docker `docker run -it -p 3306:3306/tcp --health-cmd="mysqladmin -uroot -proot ping" --health-interval=10s --health-timeout=10s --health-retries=10 -e "TZ=Europe/Paris" -e "MYSQL_USER=root" -e "MYSQL_ROOT_PASSWORD=root" -e "MYSQL_DATABASE=publisher_test" -e "MYSQL_DEFAULT_STORAGE_ENGINE=InnoDB" -e "MYSQL_CHARACTER_SET_SERVER=utf8mb4" -e "MYSQL_COLLATION_SERVER=utf8mb4_unicode_520_ci" -e "MYSQL_INNODB_BUFFER_POOL_SIZE=2G" -e "MYSQL_INNODB_DEFAULT_ROW_FORMAT=dynamic" -e "MYSQL_INNODB_DATA_FILE_PATH=ibdata1:100M:autoextend:max:10G" -e "MYSQL_INNODB_FLUSH_LOG_AT_TRX_COMMIT=1" -e "MYSQL_INNODB_LOG_BUFFER_SIZE=64M" -e "MYSQL_INNODB_LOG_FILE_SIZE=256M" -e "MYSQL_INNODB_STRICT_MODE=ON" -e "MYSQL_LOWER_CASE_TABLE_NAMES=1" -e "MYSQL_MAX_CONNECT_ERRORS=100" -e "MYSQL_MAX_CONNECTIONS=1000" -e "MYSQL_QUERY_CACHE_LIMIT=10M" -e "MYSQL_QUERY_CACHE_SIZE=0" -e "MYSQL_QUERY_CACHE_TYPE=OFF" wodby/mariadb:latest` +* `./mvnw clean generate-sources compile liquibase:update` +* `mysql -h127.0.0.1 -u root -proot -e "ALTER TABLE publisher_test.t_permission CHANGE perm perm VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NULL;"` +* run the openldap-unittest docker like on github-action description ### And running test: -- `./mvnw test -Ptest -Dspring.profiles.active=test` don't forget to change databasename between prod, adding argument `-Dspring.profiles.active=test,fast,ldapgrp` will permit to override the default conf -- `./mvnw test -Dtest=org.esupportail.publisher.repository.PermissionOnContextRepositoryTest#testInsert -Ptest -Dspring.profiles.active=test` don't forget to change databasename between prod for a specific class +* `./mvnw test -Ptest -Dspring.profiles.active=test` don't forget to change databasename between prod, adding argument `-Dspring.profiles.active=test,fast,ldapgrp` will permit to override the default conf +* `./mvnw test -Dtest=org.esupportail.publisher.repository.PermissionOnContextRepositoryTest#testInsert -Ptest -Dspring.profiles.active=test` don't forget to change databasename between prod for a specific class ## to run in dev : -- `./mvnw clean spring-boot:run -Dmaven.test.skip=true -Pdev` (+ `npm run serve` pour firefox) + +* `./mvnw clean spring-boot:run -Dmaven.test.skip=true -Pdev` (+ `npm run serve` pour firefox) ## to run with additional configuration overriding -- `./mvnw spring-boot:run -Pprod -e -Dspring-boot.run.arguments="--spring.profiles.active=prod --spring.config.additional-location=${project.home}/esup-publisher/config"` to provide custom properties, like overriding config + +* `./mvnw spring-boot:run -Pprod -e -Dspring-boot.run.arguments="--spring.profiles.active=prod --spring.config.additional-location=${project.home}/esup-publisher/config"` to provide custom properties, like overriding config ## Release process : -- put away local change `git stash` -- `./mvnw clean generate-sources release:prepare release:perform deploy -P prod -Dmaven.test.skip=true -Darguments="-DskipTests -Dmaven.deploy.skip=true"` -- `git push origin master` -- `git stash apply` + +* put away local change `git stash` +* `./mvnw clean generate-sources release:prepare release:perform deploy -P prod -Dmaven.test.skip=true -Darguments="-DskipTests -Dmaven.deploy.skip=true"` +* `git push origin master` +* `git stash apply` ## ./mvnw remember : -- `./mvnw release:perform -Dmaven.test.skip=true -Darguments="-DskipTests -Dmaven.deploy.skip=true"` to avoid to deploy a release + +* `./mvnw release:perform -Dmaven.test.skip=true -Darguments="-DskipTests -Dmaven.deploy.skip=true"` to avoid to deploy a release ## to deploy : -- before you should build the war package : `./mvnw clean package -P prod -Dmaven.test.skip=true -Darguments="-DskipTests -Dmaven.deploy.skip=true"` -- and deploy the war into your webapps directory `unzip esup-publisher-ui-x.y.z.war -d publisher` -- into a local nexus `./mvnw deploy:deploy-file -Durl=https://nexus.recia.fr/repository/public/ -DrepositoryId=local-nexus-snapshot -Dfile=target/esup-publisher-ui-2.0.0-SNAPSHOT.war -DpomFile=pom.xml` + +* before you should build the war package : `./mvnw clean package -P prod -Dmaven.test.skip=true -Darguments="-DskipTests -Dmaven.deploy.skip=true"` +* and deploy the war into your webapps directory `unzip esup-publisher-ui-x.y.z.war -d publisher` +* into a local nexus `./mvnw deploy:deploy-file -Durl=https://nexus.recia.fr/repository/public/ -DrepositoryId=local-nexus-snapshot -Dfile=target/esup-publisher-ui-2.0.0-SNAPSHOT.war -DpomFile=pom.xml` ## mvn param to debug xml binding : --Djaxb.debug=true + +\-Djaxb.debug=true this permit to view : javax.xml.bind - Trying to locate org/esupportail/publisher/web/rest/vo/jaxb.properties and other params -# TODO +## TODO ## TODO dependencies update + //@JsonFormat(shape = JsonFormat.Shape.STRING) should works with jackson 2.5, until use @JsonSerialize with custom serializer ## TODO with cache -error appear : -[WARN] net.sf.ehcache.pool.sizeof.ObjectGraphWalker - The configured limit of 1 000 object references was reached while attempting to calculate the size of the object graph. -Severe performance degradation could occur if the sizing operation continues. This can be avoided by setting the CacheManger or Cache elements maxDepthExceededBehavior -to "abort" or adding stop points with @IgnoreSizeOf annotations. If performance degradation is NOT an issue at the configured limit, raise the limit value using the CacheManager or -Cache elements maxDepth attribute. For more information, see the Ehcache configuration documentation. -=> read http://www.ehcache.org/documentation/2.8/configuration/cache-size.html#built-in-sizing-computation-and-enforcement \ No newline at end of file + +error appear : +\[WARN\] net.sf.ehcache.pool.sizeof.ObjectGraphWalker - The configured limit of 1 000 object references was reached while attempting to calculate the size of the object graph. +Severe performance degradation could occur if the sizing operation continues. This can be avoided by setting the CacheManger or Cache elements maxDepthExceededBehavior +to "abort" or adding stop points with @IgnoreSizeOf annotations. If performance degradation is NOT an issue at the configured limit, raise the limit value using the CacheManager or +Cache elements maxDepth attribute. For more information, see the Ehcache configuration documentation. +\=> read http://www.ehcache.org/documentation/2.8/configuration/cache-size.html#built-in-sizing-computation-and-enforcement + +```plaintext +delete from publisher.t_user; +\. publisher.sql +``` + +```plaintext +./mvnw compile liquibase:update +``` + +```plaintext +drop database publisher; +create database publisher DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci; +``` + +```plaintext +mysqldump -h hostname -u user -p --no-create-info --complete-insert --extended-insert --ignore-table="publisher.databasechangeloglock" --ignore-table="publisher.databasechangelog" --ignore-table="publisher.t_persistent_audit_event" --ignore-table="publisher.t_persistent_audit_event_data" "publisher" > "publisher.sql" +``` \ No newline at end of file