diff --git a/Tools/AddLicense/AddLicense.sh b/Tools/AddLicense/AddLicense.sh new file mode 100644 index 000000000..a5b080513 --- /dev/null +++ b/Tools/AddLicense/AddLicense.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. + +function addLicense() { + local MPL=( + 'This Source Code Form is subject to the terms of the Mozilla Public' + 'License, v. 2.0. If a copy of the MPL was not distributed with this' + 'file, You can obtain one at https://mozilla.org/MPL/2.0/.' + ) + local comment='' + local fileType=${1##*.} + local lineNumber=1 + + # 各種ファイルに適したコメントを生成する + if [ "$fileType" == 'axml' ]; then + comment='\\n'$(printf '\\n' "${MPL[@]}") + lineNumber=2 # XML 宣言の後に挿入する + + elif [ "$fileType" == 'bat' ]; then + comment=$(printf '@REM %s\\n' "${MPL[@]}") + + elif [ "$fileType" == 'cs' ]; then + comment=$(printf '/* %s\\n * %s\\n * %s */\\n' "${MPL[@]}") + + elif [ "$fileType" == 'feature' ]; then + comment=$(printf '# %s\\n' "${MPL[@]}") + + elif [ "$fileType" == 'resx' ]; then + comment='\\n'$(printf '\\n' "${MPL[@]}") + lineNumber=2 # XML 宣言の後に挿入する + + elif [ "$fileType" == 'sh' ]; then + comment='\\n'$(printf '# %s\\n' "${MPL[@]}") + lineNumber=2 # Shebang の後に挿入する + + elif [ "$fileType" == 'storyboard' ]; then + comment='\\n'$(printf '\\n' "${MPL[@]}") + lineNumber=2 # XML 宣言の後に挿入する + + elif [ "$fileType" == 'strings' ]; then + comment=$(printf '/* %s\\n * %s\\n * %s */\\n' "${MPL[@]}") + + elif [ "$fileType" == 'tf' ]; then + comment=$(printf '# %s\\n' "${MPL[@]}") + + elif [ "$fileType" == 'xaml' ]; then + comment='\\n'$(printf '\\n' "${MPL[@]}") + lineNumber=2 # XML 宣言の後に挿入する + + elif [ "$fileType" == 'xml' ]; then + comment='\\n'$(printf '\\n' "${MPL[@]}") + lineNumber=2 # XML 宣言の後に挿入する + + elif [ "$fileType" == 'yml' ]; then + comment=$(printf '# %s\\n' "${MPL[@]}") + fi + + # MPL の適用対象であるかを確認する。その中でライセンスの文言がないものに限り,生成したコメントを挿入する + if [ "$comment" != '' ] && [ "$(grep -c "$1" Tools/AddLicense/Exclusions.txt)" -eq 0 ]; then + git grep -z -I -L "${MPL[0]}" -- "$1" | xargs -0 -r sed -i -e "${lineNumber}i$comment" + else + echo "Excluded: $1" + fi +} diff --git a/Tools/AddLicense/CheckAllFiles.sh b/Tools/AddLicense/CheckAllFiles.sh new file mode 100644 index 000000000..123051c4b --- /dev/null +++ b/Tools/AddLicense/CheckAllFiles.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. + +# リポジトリ内のファイルについて MPL の記載漏れをチェックします。 +# 詳しい処理につきましては Tools/AddLicense/AddLicense.sh をご参照ください。 + +# リポジトリのルートへ移動 +cd "$(git rev-parse --show-toplevel)" || exit 1 + +# `addLicense` の読み込み +source Tools/AddLicense/AddLicense.sh && export -f addLicense + +# 対象ファイル(リポジトリのルートを基準とした相対パスで記述) +FILES=( + '*.axml' + '*.bat' + '*.cs' + '*.feature' + '*.resx' + '*.sh' + '*.storyboard' + '*.strings' + '*.tf' + '*.xaml' + '*.xml' + '*.yml' +) + +# 対象ファイルの内,MPL が抜けているもの対して文言を挿入する +for file in "${FILES[@]}"; do + git ls-files -- "$file" | xargs -r -P 4 -I '%' bash -c 'addLicense %' +done diff --git a/Tools/AddLicense/Exclusions.txt b/Tools/AddLicense/Exclusions.txt new file mode 100644 index 000000000..5db70a4b3 --- /dev/null +++ b/Tools/AddLicense/Exclusions.txt @@ -0,0 +1,102 @@ +.editorconfig +.gitattributes +.github/ISSUE_TEMPLATE/bug_report.md +.github/ISSUE_TEMPLATE/config.yml +.github/ISSUE_TEMPLATE/feature_request.md +.github/PULL_REQUEST_TEMPLATE.md +.github/workflows/CI.yml +.gitignore +CONTRIBUTING.md +CONTRIBUTORS.md +Covid19Radar.Functions.runsettings +Covid19Radar.Functions.sln +Covid19Radar.sln +Covid19Radar/Covid19Radar.Android/Assets/AboutAssets.txt +Covid19Radar/Covid19Radar.Android/Covid19Radar.Android.csproj +Covid19Radar/Covid19Radar.Android/Resources/AboutResources.txt +Covid19Radar/Covid19Radar.iOS/Assets.xcassets/AppIcons.appiconset/Contents.json +Covid19Radar/Covid19Radar.iOS/Assets.xcassets/Contents.json +Covid19Radar/Covid19Radar.iOS/Covid19Radar.iOS.csproj +Covid19Radar/Covid19Radar.iOS/Entitlements.plist +Covid19Radar/Covid19Radar.iOS/Info.plist +Covid19Radar/Covid19Radar/Covid19Radar.csproj +Covid19Radar/Covid19Radar/Memo.md +Covid19Radar/Covid19Radar/Resources/AppResources.Designer.cs +Covid19Radar/Covid19Radar/Resources/html/en/chatbot2.html +Covid19Radar/Covid19Radar/Resources/html/en/chatbot3.html +Covid19Radar/Covid19Radar/Resources/html/en/chatbot4.html +Covid19Radar/Covid19Radar/Resources/html/en/chatbot5.html +Covid19Radar/Covid19Radar/Resources/html/en/css/style.css +Covid19Radar/Covid19Radar/Resources/html/en/index.html +Covid19Radar/Covid19Radar/Resources/html/en/privacypolicy.html +Covid19Radar/Covid19Radar/Resources/html/en/privacypolicy.md +Covid19Radar/Covid19Radar/Resources/html/en/termofuse.html +Covid19Radar/Covid19Radar/Resources/html/en/termofuse.md +Covid19Radar/Covid19Radar/Resources/html/index.html +Covid19Radar/Covid19Radar/Resources/html/ja/chatbot2.html +Covid19Radar/Covid19Radar/Resources/html/ja/chatbot3.html +Covid19Radar/Covid19Radar/Resources/html/ja/chatbot4.html +Covid19Radar/Covid19Radar/Resources/html/ja/chatbot5.html +Covid19Radar/Covid19Radar/Resources/html/ja/css/style.css +Covid19Radar/Covid19Radar/Resources/html/ja/index.html +Covid19Radar/Covid19Radar/Resources/html/ja/privacypolicy.html +Covid19Radar/Covid19Radar/Resources/html/ja/privacypolicy.md +Covid19Radar/Covid19Radar/Resources/html/ja/termofuse.html +Covid19Radar/Covid19Radar/Resources/html/ja/termofuse.md +Covid19Radar/Covid19Radar/Resources/html/zh-hans/chatbot2.html +Covid19Radar/Covid19Radar/Resources/html/zh-hans/chatbot3.html +Covid19Radar/Covid19Radar/Resources/html/zh-hans/chatbot4.html +Covid19Radar/Covid19Radar/Resources/html/zh-hans/chatbot5.html +Covid19Radar/Covid19Radar/Resources/html/zh-hans/css/style.css +Covid19Radar/Covid19Radar/Resources/html/zh-hans/index.html +Covid19Radar/Covid19Radar/Resources/html/zh-hans/privacypolicy.html +Covid19Radar/Covid19Radar/Resources/html/zh-hans/privacypolicy.md +Covid19Radar/Covid19Radar/Resources/html/zh-hans/termofuse.html +Covid19Radar/Covid19Radar/Resources/html/zh-hans/termofuse.md +Covid19Radar/Covid19Radar/settings.json +Covid19Radar/Tests/Covid19Radar.UITest/App.config +Covid19Radar/Tests/Covid19Radar.UITest/Covid19Radar.UITest.csproj +Covid19Radar/Tests/Covid19Radar.UITest/Features/HomePage/ContributorsList.feature.cs +Covid19Radar/Tests/Covid19Radar.UITest/Features/HomePage/Home.feature.cs +Covid19Radar/Tests/Covid19Radar.UITest/Features/HomePage/LicenseAgreement.feature.cs +Covid19Radar/Tests/Covid19Radar.UITest/Features/HomePage/UpdateInformation.feature.cs +Covid19Radar/Tests/Covid19Radar.UITest/Features/Tutorial/Tutorial.feature.cs +Covid19Radar/Tests/Covid19Radar.UITest/ReadMe.txt +Covid19Radar/Tests/Covid19Radar.UITest/TestConfig.json +Covid19Radar/Tests/Covid19Radar.UnitTests/Covid19Radar.UnitTests.csproj +Covid19Radar/Xamarin.ExposureNotification/CallbackService.android.cs +Covid19Radar/Xamarin.ExposureNotification/ExposureInfo.shared.cs +Covid19Radar/Xamarin.ExposureNotification/ExposureNotification.android.cs +Covid19Radar/Xamarin.ExposureNotification/ExposureNotification.customize.android.cs +Covid19Radar/Xamarin.ExposureNotification/ExposureNotification.ios.cs +Covid19Radar/Xamarin.ExposureNotification/ExposureNotification.netstandard.cs +Covid19Radar/Xamarin.ExposureNotification/ExposureNotification.shared.cs +Covid19Radar/Xamarin.ExposureNotification/IExposureNotificationHandler.shared.cs +Covid19Radar/Xamarin.ExposureNotification/TemporaryExposureKey.shared.cs +Covid19Radar/Xamarin.ExposureNotification/Xamarin.ExposureNotification.csproj +OPERATION_POLICY.md +README.ja.md +README.md +Tools/ConvertBase64/ConvertBase64.sln +Tools/ConvertBase64/ConvertBase64/ConvertBase64.csproj +Tools/GenerateKeys/GenerateKeys.sln +Tools/GenerateKeys/GenerateKeys/GenerateKeys.csproj +Tools/UpdateUserStatusTool/UpdateUserStatusTool.sln +Tools/UpdateUserStatusTool/UpdateUserStatusTool/App.config.example +Tools/UpdateUserStatusTool/UpdateUserStatusTool/Properties/launchSettings.json +Tools/UpdateUserStatusTool/UpdateUserStatusTool/UpdateUserStatusTool.csproj +infrastructure/01_init/Readme.md +infrastructure/02_runtime/Readme.md +infrastructure/Readme.md +src/Covid19Radar.Api.Common/Covid19Radar.Api.Common.csproj +src/Covid19Radar.Api.External/Covid19Radar.Api.External.csproj +src/Covid19Radar.Api.External/host.json +src/Covid19Radar.Api.External/local.settings.json.example +src/Covid19Radar.Api.Tests/Covid19Radar.Api.Tests.csproj +src/Covid19Radar.Api/Covid19Radar.Api.csproj +src/Covid19Radar.Api/host.json +src/Covid19Radar.Api/local.settings.json.example +src/Covid19Radar.Background/Covid19Radar.Background.csproj +src/Covid19Radar.Background/Protobuf/TemporaryExposureKeyExportFileFormat.proto +src/Covid19Radar.Background/host.json +src/Covid19Radar.Background/local.settings.json.example diff --git a/Tools/GitHooks/PreCommit.sh b/Tools/GitHooks/PreCommit.sh new file mode 100644 index 000000000..9b2611da5 --- /dev/null +++ b/Tools/GitHooks/PreCommit.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. + +# Commit 時に MPL の記載漏れをチェックします。 +# あらかじめ Tools/GitHooks/PrepareHooks.sh を実行する必要があります。 +# 詳しい処理につきましては Tools/AddLicense/AddLicense.sh をご参照ください。 + +# リポジトリのルートへ移動 +cd "$(git rev-parse --show-toplevel)" || exit 1 + +# `addLicense` の読み込み +source Tools/AddLicense/AddLicense.sh + +# ステージングエリアのファイル一覧を取得(削除を除く) +stagedFiles=$(git diff --name-only --cached --diff-filter=d) + +# 対象ファイルの内,MPL が抜けているもの対して文言を挿入する +for file in $stagedFiles; do + addLicense "$file" && git add "$file" +done diff --git a/Tools/GitHooks/PrepareHooks.sh b/Tools/GitHooks/PrepareHooks.sh new file mode 100644 index 000000000..7f4c7a24c --- /dev/null +++ b/Tools/GitHooks/PrepareHooks.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. + +# リポジトリのルートへ移動 +cd "$(git rev-parse --show-toplevel)" || exit 1 + +# pre-commit 用のスクリプトを追加 +install -m 755 -D Tools/GitHooks/PreCommit.sh .git/hooks/pre-commit + +# 追加した Git Hooks を有効にする +git init