This is an automated email from the ASF dual-hosted git repository.

dcapwell pushed a commit to branch cep-15-accord
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/cep-15-accord by this push:
     new 71f836b33e CEP-15: (C*) Add git submodule for Accord
71f836b33e is described below

commit 71f836b33eb90525f2b1e08fa26bcdb4f821b6ff
Author: David Capwell <[email protected]>
AuthorDate: Fri Feb 17 15:24:10 2023 -0800

    CEP-15: (C*) Add git submodule for Accord
    
    patch by David Capwell; reviewed by Caleb Rackliffe, Michael Semb Wever for 
CASSANDRA-18204
---
 .build/build-accord.xml                            |  37 +++++
 .build/build-resolver.xml                          |   4 +-
 .build/cassandra-build-deps-template.xml           |   4 +-
 .build/cassandra-deps-template.xml                 |   4 +-
 .../post-checkout/100-update-submodules.sh}        |  35 ++---
 .build/git/git-hooks/post-switch                   |   1 +
 .../pre-commit/100-verify-submodules-pushed.sh     |  98 +++++++++++++
 .../git-hooks/pre-push/100-push-submodules.sh}     |  45 +++---
 .build/git/install-git-defaults.sh                 | 117 ++++++++++++++++
 .build/parent-pom-template.xml                     |  12 +-
 .build/{include-accord.sh => sh/bump-accord.sh}    |  36 ++---
 .../change-submodule-accord.sh}                    |  29 +---
 .../{include-accord.sh => sh/change-submodule.sh}  |  43 +++---
 .build/sh/development-switch.sh                    | 153 +++++++++++++++++++++
 .gitignore                                         |   1 -
 .gitmodules                                        |   4 +
 CHANGES.txt                                        |   1 +
 CONTRIBUTING.md                                    |  33 +++++
 build.xml                                          |  42 ++++--
 ide/idea-iml-file.xml                              |  20 +++
 ide/idea/vcs.xml                                   |   3 +-
 modules/accord                                     |   1 +
 22 files changed, 576 insertions(+), 147 deletions(-)

diff --git a/.build/build-accord.xml b/.build/build-accord.xml
new file mode 100644
index 0000000000..eeadf4dd18
--- /dev/null
+++ b/.build/build-accord.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+  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.
+-->
+<project basedir=".." name="apache-cassandra-accord-build"
+         xmlns:if="ant:if">
+    <target name="_build-accord" depends="init">
+      <exec executable="${basedir}/${accord.dir}/gradlew" 
dir="${basedir}/${accord.dir}" logError="true" failonerror="true" 
failifexecutionfails="true">
+        <!-- Need to call clean as a version change with a jar that didn't 
have code changes will not produce a new jar with the new version... so need 
clean to make sure build is stable -->
+        <arg value="clean" />
+        <arg value="build" />
+        <arg value="copyDependencies" /> <!-- For IDE support -->
+        <arg value="publishToMavenLocal" />
+        <arg value="-x" />
+        <arg value="test" />
+        <arg value="-x" />
+        <arg value="rat" />
+        <arg value="-Paccord_group=org.apache.cassandra" />
+        <arg value="-Paccord_artifactId=cassandra-accord" />
+        <arg value="-Paccord_version=${version}" />
+      </exec>
+    </target>
+</project>
diff --git a/.build/build-resolver.xml b/.build/build-resolver.xml
index 60122b854f..7c47d0790a 100644
--- a/.build/build-resolver.xml
+++ b/.build/build-resolver.xml
@@ -165,7 +165,7 @@
         <property name="resolver-ant-tasks.initialized" value="true"/>
     </target>
 
-    <target name="resolver-retrieve-build" depends="resolver-init,write-poms">
+    <target name="resolver-retrieve-build" 
depends="resolver-init,write-poms,_build_subprojects">
         <resolvepom file="${build.dir}/${final.name}.pom" id="all-pom" />
         <resolvepom file="${build.dir}/tmp-${final.name}-deps.pom" 
id="pom-deps" />
 
@@ -189,7 +189,7 @@
         </unzip>
     </target>
 
-    <target name="resolver-dist-lib" depends="resolver-retrieve-build">
+    <target name="resolver-dist-lib" 
depends="resolver-retrieve-build,_build_subprojects">
         <resolvepom file="${build.dir}/${final.name}.pom" id="all-pom" />
 
         <resolve failOnMissingAttachments="true">
diff --git a/.build/cassandra-build-deps-template.xml 
b/.build/cassandra-build-deps-template.xml
index cfd2806fe7..704772a143 100644
--- a/.build/cassandra-build-deps-template.xml
+++ b/.build/cassandra-build-deps-template.xml
@@ -128,8 +128,8 @@
       <artifactId>jackson-dataformat-yaml</artifactId>
     </dependency>
     <dependency>
-      <groupId>accord</groupId>
-      <artifactId>accord</artifactId>
+      <groupId>org.apache.cassandra</groupId>
+      <artifactId>cassandra-accord</artifactId>
       <classifier>tests</classifier>
     </dependency>
   </dependencies>
diff --git a/.build/cassandra-deps-template.xml 
b/.build/cassandra-deps-template.xml
index 85940f5ae6..8f54619fbf 100644
--- a/.build/cassandra-deps-template.xml
+++ b/.build/cassandra-deps-template.xml
@@ -130,8 +130,8 @@
       <artifactId>jbcrypt</artifactId>
     </dependency>
     <dependency>
-      <groupId>accord</groupId>
-      <artifactId>accord</artifactId>
+      <groupId>org.apache.cassandra</groupId>
+      <artifactId>cassandra-accord</artifactId>
     </dependency>
     <dependency>
       <groupId>io.airlift</groupId>
diff --git a/.build/include-accord.sh 
b/.build/git/git-hooks/post-checkout/100-update-submodules.sh
similarity index 55%
copy from .build/include-accord.sh
copy to .build/git/git-hooks/post-checkout/100-update-submodules.sh
index 34ee959221..b495ed0860 100755
--- a/.build/include-accord.sh
+++ b/.build/git/git-hooks/post-checkout/100-update-submodules.sh
@@ -1,5 +1,4 @@
 #!/usr/bin/env bash
-#
 # 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
@@ -15,7 +14,9 @@
 # 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.
-#
+
+# Redirect output to stderr.
+exec 1>&2
 
 #set -o xtrace
 set -o errexit
@@ -24,29 +25,17 @@ set -o nounset
 
 bin="$(cd "$(dirname "$0")" > /dev/null; pwd)"
 
-accord_repo='https://github.com/apache/cassandra-accord.git'
-accord_sha='da77b744e4fdb5f39656e4269f4f1806e485c9c0'
-accord_src="$bin/cassandra-accord"
-
 _main() {
-  # have we already cloned?
-  if [[ ! -e "$accord_src" ]] || [[ $(cat "$accord_src/.REPO" || true) != 
"$accord_repo" ]]; then
-    rm -rf "$accord_src" || true
-    git clone "$accord_repo" "$accord_src"
-    echo "$accord_repo" > "$accord_src/.REPO"
-  fi
-  cd "$accord_src"
-  # switch to target SHA
-  git fetch origin # check for changes
-  local current_sha
-  current_sha="$(git rev-parse HEAD)"
-  if [[ "$current_sha" != "$accord_sha" ]]; then
-    git checkout "$accord_sha"
-  fi
-  if [[ "$accord_sha" != $(cat .SHA || true) ]]; then
-    ./gradlew clean install -x test -x rat
-    git rev-parse HEAD > .SHA
+  # In case the usage happens at a different layer, make sure to cd to the 
toplevel
+  local root_dir
+  root_dir="$(git rev-parse --show-toplevel)"
+  cd "$root_dir"
+
+  if [[ ! -e .gitmodules ]]; then
+    # nothing to see here, look away!
+    return 0
   fi
+  git submodule update --init --recursive
 }
 
 _main "$@"
diff --git a/.build/git/git-hooks/post-switch b/.build/git/git-hooks/post-switch
new file mode 120000
index 0000000000..5513d1deed
--- /dev/null
+++ b/.build/git/git-hooks/post-switch
@@ -0,0 +1 @@
+post-checkout
\ No newline at end of file
diff --git a/.build/git/git-hooks/pre-commit/100-verify-submodules-pushed.sh 
b/.build/git/git-hooks/pre-commit/100-verify-submodules-pushed.sh
new file mode 100755
index 0000000000..c54099ac0f
--- /dev/null
+++ b/.build/git/git-hooks/pre-commit/100-verify-submodules-pushed.sh
@@ -0,0 +1,98 @@
+#!/usr/bin/env bash
+# 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.
+
+##
+## When working with submodules the top level project (Apache Cassandra) needs 
to commit all submodule
+## changes so the top level knows what SHA to use.  When working in a 
development environment it is
+## common that multiple commits will exist in both projects, if the submodule 
has its history
+## rewritten, then historic top level commits are no longer valid unless the 
SHAs are pushed to a
+## remote repo; this is what the script attempts to do, make sure all SHAs 
added to the
+## Apache Cassandra are backed up to a remote repo to make the Cassandra SHA 
buildable.
+##
+
+# Redirect output to stderr.
+exec 1>&2
+
+
+#set -o xtrace
+set -o errexit
+set -o pipefail
+set -o nounset
+
+bin="$(cd "$(dirname "$0")" > /dev/null; pwd)"
+
+_log() {
+  echo -e "[pre-commit]\t$*"
+}
+
+error() {
+  _log "$@" 1>&2
+  exit 1
+}
+
+# Status Table
+# A         Added
+# C         Copied
+# D         Deleted
+# M         Modified
+# R         Renamed
+# T         Type Changed (i.e. regular file, symlink, submodule, …<200b>)
+# U         Unmerged
+# X         Unknown
+# B         Broken
+_main() {
+  # In case the usage happens at a different layer, make sure to cd to the 
toplevel
+  local root_dir
+  root_dir="$(git rev-parse --show-toplevel)"
+  cd "$root_dir"
+
+  [[ ! -e .gitmodules ]] && return 0
+  local enabled=$(git config --bool 
cassandra.pre-commit.verify-submodules.enabled || echo true)
+  [ "$enabled" == "false" ] && return 0
+  local submodules=( $(git config --file .gitmodules --get-regexp path | awk 
'{ print $2 }') )
+
+  local is_submodule=false
+  local git_sub_dir
+  local git_sha
+  while read status file; do
+    is_submodule=false
+    for to_check in "${submodules[*]}"; do
+      if [[ "$to_check" == "$file" ]]; then
+        is_submodule=true
+        break
+      fi
+    done
+    if $is_submodule; then
+      local enabled=$(git config --bool 
cassandra.pre-commit.verify-submodule-${file}.enabled || echo true)
+      [ "$enabled" == "false" ] && continue
+      _log "Submodule detected: ${file} with status ${status}; attempting a 
push"
+      _log "\tTo disable pushes, run"
+      _log "\t\tgit config --local 
cassandra.pre-commit.verify-submodules.enabled false"
+      _log "\tOr"
+      _log "\t\tgit config --local 
cassandra.pre-commit.verify-submodule-${file}.enabled false"
+      set -x
+      git_sub_dir="${file}/.git"
+      branch="$(git config -f .gitmodules "submodule.${file}.branch")"
+      [[ -z "${branch:-}" ]] && error "Submodule ${file} does not define a 
branch"
+      git_sha="$(git --git-dir "${git_sub_dir}" rev-parse HEAD)"
+      git --git-dir "${git_sub_dir}" fetch origin
+      git --git-dir "${git_sub_dir}" branch "origin/${branch}" --contains 
"${git_sha}" || error "Git commit ${git_sha} not found in $(git remote get-url 
origin) on branch ${branch}"
+    fi
+  done < <(git diff --cached --name-status)
+}
+
+_main "$@"
diff --git a/.build/include-accord.sh 
b/.build/git/git-hooks/pre-push/100-push-submodules.sh
similarity index 55%
copy from .build/include-accord.sh
copy to .build/git/git-hooks/pre-push/100-push-submodules.sh
index 34ee959221..c3daa95597 100755
--- a/.build/include-accord.sh
+++ b/.build/git/git-hooks/pre-push/100-push-submodules.sh
@@ -1,5 +1,4 @@
 #!/usr/bin/env bash
-#
 # 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
@@ -15,7 +14,9 @@
 # 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.
-#
+
+# Redirect output to stderr.
+exec 1>&2
 
 #set -o xtrace
 set -o errexit
@@ -24,29 +25,27 @@ set -o nounset
 
 bin="$(cd "$(dirname "$0")" > /dev/null; pwd)"
 
-accord_repo='https://github.com/apache/cassandra-accord.git'
-accord_sha='da77b744e4fdb5f39656e4269f4f1806e485c9c0'
-accord_src="$bin/cassandra-accord"
-
 _main() {
-  # have we already cloned?
-  if [[ ! -e "$accord_src" ]] || [[ $(cat "$accord_src/.REPO" || true) != 
"$accord_repo" ]]; then
-    rm -rf "$accord_src" || true
-    git clone "$accord_repo" "$accord_src"
-    echo "$accord_repo" > "$accord_src/.REPO"
-  fi
-  cd "$accord_src"
-  # switch to target SHA
-  git fetch origin # check for changes
-  local current_sha
-  current_sha="$(git rev-parse HEAD)"
-  if [[ "$current_sha" != "$accord_sha" ]]; then
-    git checkout "$accord_sha"
-  fi
-  if [[ "$accord_sha" != $(cat .SHA || true) ]]; then
-    ./gradlew clean install -x test -x rat
-    git rev-parse HEAD > .SHA
+  # In case the usage happens at a different layer, make sure to cd to the 
toplevel
+  local root_dir
+  root_dir="$(git rev-parse --show-toplevel)"
+  cd "$root_dir"
+
+  if [[ ! -e .gitmodules ]]; then
+    # nothing to see here, look away!
+    return 0
   fi
+
+  local -r cmd='
+branch="$(git rev-parse --abbrev-ref HEAD)"
+[[ "$branch" == "HEAD" ]] && exit 0
+
+default_remote="$(git config --local --get branch."${branch}".remote || true)"
+remote="${default_remote:-origin}"
+
+git push --atomic "$remote" "$branch"
+'
+  git submodule foreach --recursive "$cmd"
 }
 
 _main "$@"
diff --git a/.build/git/install-git-defaults.sh 
b/.build/git/install-git-defaults.sh
new file mode 100755
index 0000000000..00f1dc435d
--- /dev/null
+++ b/.build/git/install-git-defaults.sh
@@ -0,0 +1,117 @@
+#!/usr/bin/env bash
+# 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.
+
+#set -o xtrace
+set -o errexit
+set -o pipefail
+set -o nounset
+
+bin="$(cd "$(dirname "$0")" > /dev/null; pwd)"
+
+install_template_script() {
+  local -r name="$1"
+  local -r d_dir="$2"
+
+  cat <<EOF > "$name"
+#!/usr/bin/env bash
+
+# This script is autogenerated by the Apache Cassandra build; DO NOT CHANGE!
+# When this script is not found it will be installed automatically by the build
+# If an existing script is found, that script will be reloated under ${d_dir} 
as 000-original.sh
+
+# Redirect output to stderr.
+exec 1>&2
+
+# Find all scripts to run
+for path in \$(find "$d_dir" -name '*.sh' | perl -e "print sort{(split '/', 
\\\$a)[-1] <=> (split '/', \\\$b)[-1]}<>"); do
+  "\$path" "\$@"
+done
+EOF
+  chmod a+x "$name"
+}
+
+install_hook() {
+  local -r git_dir="$1"
+  local -r hooks_dir="${git_dir}/hooks"
+  local -r name="$2"
+  local -r d_dir="${hooks_dir}/${name}.d"
+  local -r trigger_on_install=$3
+
+  mkdir "${d_dir}" &> /dev/null || true
+  local -r script_name="${hooks_dir}/${name}"
+  local installed=true
+  if [[ -e "$script_name" ]]; then
+    # was the script already installed?
+    if ! grep "This script is autogenerated by the Apache Cassandra build" 
"$script_name" &> /dev/null ; then
+      echo "$script_name found, but was not generated by the Apache Cassandra 
build; please remove or move to ${d_dir}/000-original.sh; creating and moving 
to ${d_dir} will cause it to run as expected, but won't conflict with hooks 
this build adds" 1>&2
+      exit 1
+    else
+      installed=false
+    fi
+  fi
+  # install all hooks
+  cp "$bin"/git-hooks/"${name}"/* "$d_dir"/
+
+  # install coordinator hook
+  install_template_script "$script_name" "$d_dir"
+  if $installed && $trigger_on_install ; then
+    echo "Running script $script_name"
+    "$script_name"
+  fi
+}
+
+_install_hooks() {
+  local git_dir
+  # make sure to use --git-common-dir and not --git-dir to support worktrees
+  git_dir="$(git rev-parse --git-common-dir 2> /dev/null || true)"
+  if [[ -z "${git_dir:-}" ]]; then
+    # not in a git repo, noop
+    return 0
+  fi
+
+  # make sure hooks directory exists; does not exist by default for worktrees
+  mkdir -p "${git_dir}/hooks" &> /dev/null || true
+
+  install_hook "$git_dir" "post-checkout" true
+  install_hook "$git_dir" "post-switch"   false
+  install_hook "$git_dir" "pre-commit"    false
+  install_hook "$git_dir" "pre-push"      false
+}
+
+_git_config_set() {
+  local -r name="$1"
+  # only care about rc
+  git config --local --get "$name" &> /dev/null
+}
+
+_install_configs() {
+  # when doing pull, this makes sure submodules are updated
+  _git_config_set submodule.recurse || git config --local submodule.recurse 
true
+}
+
+_main() {
+  local git_dir
+  # make sure to use --git-common-dir and not --git-dir to support worktrees
+  git_dir="$(git rev-parse --git-common-dir 2> /dev/null || true)"
+  # not in a git repo, noop
+  [[ -z "${git_dir:-}" ]] && return 0
+
+  _install_configs
+  _install_hooks
+}
+
+_main "$@"
diff --git a/.build/parent-pom-template.xml b/.build/parent-pom-template.xml
index 218065968d..29423d771f 100644
--- a/.build/parent-pom-template.xml
+++ b/.build/parent-pom-template.xml
@@ -675,14 +675,14 @@
         <version>0.4</version>
       </dependency>
       <dependency>
-        <groupId>accord</groupId>
-        <artifactId>accord</artifactId>
-        <version>1.0-SNAPSHOT</version>
+        <groupId>org.apache.cassandra</groupId>
+        <artifactId>cassandra-accord</artifactId>
+        <version>@version@</version>
       </dependency>
       <dependency>
-        <groupId>accord</groupId>
-        <artifactId>accord</artifactId>
-        <version>1.0-SNAPSHOT</version>
+        <groupId>org.apache.cassandra</groupId>
+        <artifactId>cassandra-accord</artifactId>
+        <version>@version@</version>
         <classifier>tests</classifier>
         <scope>test</scope>
         <exclusions>
diff --git a/.build/include-accord.sh b/.build/sh/bump-accord.sh
similarity index 52%
copy from .build/include-accord.sh
copy to .build/sh/bump-accord.sh
index 34ee959221..43a476f3ed 100755
--- a/.build/include-accord.sh
+++ b/.build/sh/bump-accord.sh
@@ -1,5 +1,4 @@
 #!/usr/bin/env bash
-#
 # 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
@@ -15,38 +14,25 @@
 # 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.
-#
 
 #set -o xtrace
 set -o errexit
 set -o pipefail
 set -o nounset
 
-bin="$(cd "$(dirname "$0")" > /dev/null; pwd)"
-
-accord_repo='https://github.com/apache/cassandra-accord.git'
-accord_sha='da77b744e4fdb5f39656e4269f4f1806e485c9c0'
-accord_src="$bin/cassandra-accord"
-
 _main() {
-  # have we already cloned?
-  if [[ ! -e "$accord_src" ]] || [[ $(cat "$accord_src/.REPO" || true) != 
"$accord_repo" ]]; then
-    rm -rf "$accord_src" || true
-    git clone "$accord_repo" "$accord_src"
-    echo "$accord_repo" > "$accord_src/.REPO"
-  fi
-  cd "$accord_src"
-  # switch to target SHA
-  git fetch origin # check for changes
-  local current_sha
-  current_sha="$(git rev-parse HEAD)"
-  if [[ "$current_sha" != "$accord_sha" ]]; then
-    git checkout "$accord_sha"
-  fi
-  if [[ "$accord_sha" != $(cat .SHA || true) ]]; then
-    ./gradlew clean install -x test -x rat
-    git rev-parse HEAD > .SHA
+  local home
+  home="$(git rev-parse --show-toplevel)"
+  cd "$home"
+
+  git submodule status modules/accord
+  echo "Is this the correct SHA? [y/n; default=y]"
+  read correct
+  if [[ "${correct:-y}" != "y" ]]; then
+    echo "Please update Accord's SHA and try again"
+    exit 1
   fi
+  git commit -m "Change Accord to $(cd modules/accord; git log -1  
--format='%h: %B')" modules/accord
 }
 
 _main "$@"
diff --git a/.build/include-accord.sh b/.build/sh/change-submodule-accord.sh
similarity index 53%
copy from .build/include-accord.sh
copy to .build/sh/change-submodule-accord.sh
index 34ee959221..997db3dc2c 100755
--- a/.build/include-accord.sh
+++ b/.build/sh/change-submodule-accord.sh
@@ -1,5 +1,4 @@
 #!/usr/bin/env bash
-#
 # 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
@@ -15,7 +14,6 @@
 # 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.
-#
 
 #set -o xtrace
 set -o errexit
@@ -24,29 +22,4 @@ set -o nounset
 
 bin="$(cd "$(dirname "$0")" > /dev/null; pwd)"
 
-accord_repo='https://github.com/apache/cassandra-accord.git'
-accord_sha='da77b744e4fdb5f39656e4269f4f1806e485c9c0'
-accord_src="$bin/cassandra-accord"
-
-_main() {
-  # have we already cloned?
-  if [[ ! -e "$accord_src" ]] || [[ $(cat "$accord_src/.REPO" || true) != 
"$accord_repo" ]]; then
-    rm -rf "$accord_src" || true
-    git clone "$accord_repo" "$accord_src"
-    echo "$accord_repo" > "$accord_src/.REPO"
-  fi
-  cd "$accord_src"
-  # switch to target SHA
-  git fetch origin # check for changes
-  local current_sha
-  current_sha="$(git rev-parse HEAD)"
-  if [[ "$current_sha" != "$accord_sha" ]]; then
-    git checkout "$accord_sha"
-  fi
-  if [[ "$accord_sha" != $(cat .SHA || true) ]]; then
-    ./gradlew clean install -x test -x rat
-    git rev-parse HEAD > .SHA
-  fi
-}
-
-_main "$@"
+"$bin"/change-submodule.sh modules/accord 
'https://github.com/apache/cassandra-accord.git' trunk
diff --git a/.build/include-accord.sh b/.build/sh/change-submodule.sh
similarity index 52%
rename from .build/include-accord.sh
rename to .build/sh/change-submodule.sh
index 34ee959221..d8b1d8d5d9 100755
--- a/.build/include-accord.sh
+++ b/.build/sh/change-submodule.sh
@@ -1,5 +1,4 @@
 #!/usr/bin/env bash
-#
 # 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
@@ -15,38 +14,34 @@
 # 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.
-#
 
 #set -o xtrace
 set -o errexit
 set -o pipefail
 set -o nounset
 
-bin="$(cd "$(dirname "$0")" > /dev/null; pwd)"
-
-accord_repo='https://github.com/apache/cassandra-accord.git'
-accord_sha='da77b744e4fdb5f39656e4269f4f1806e485c9c0'
-accord_src="$bin/cassandra-accord"
+_usage() {
+  cat <<EOF
+Usage: $(basename $0) [submodule path] [git repo URL] [git branch]
+EOF
+ exit 1
+}
 
 _main() {
-  # have we already cloned?
-  if [[ ! -e "$accord_src" ]] || [[ $(cat "$accord_src/.REPO" || true) != 
"$accord_repo" ]]; then
-    rm -rf "$accord_src" || true
-    git clone "$accord_repo" "$accord_src"
-    echo "$accord_repo" > "$accord_src/.REPO"
-  fi
-  cd "$accord_src"
-  # switch to target SHA
-  git fetch origin # check for changes
-  local current_sha
-  current_sha="$(git rev-parse HEAD)"
-  if [[ "$current_sha" != "$accord_sha" ]]; then
-    git checkout "$accord_sha"
-  fi
-  if [[ "$accord_sha" != $(cat .SHA || true) ]]; then
-    ./gradlew clean install -x test -x rat
-    git rev-parse HEAD > .SHA
+  if [[ $# -ne 3 ]]; then
+    _usage
   fi
+  local -r path="$1"
+  local -r url="$2"
+  local -r branch="$3"
+
+  local home
+  home="$(git rev-parse --show-toplevel)"
+  cd "$home"
+
+  git submodule set-url "${path}" "${url}"
+  git submodule set-branch --branch "${branch}" "${path}"
+  git submodule update --remote
 }
 
 _main "$@"
diff --git a/.build/sh/development-switch.sh b/.build/sh/development-switch.sh
new file mode 100755
index 0000000000..9e66a95cd4
--- /dev/null
+++ b/.build/sh/development-switch.sh
@@ -0,0 +1,153 @@
+#!/usr/bin/env bash
+# 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.
+
+#set -o xtrace
+set -o errexit
+set -o pipefail
+set -o nounset
+
+error() {
+  echo -e "$*" 1>&2
+  exit 1
+}
+
+_usage() {
+  cat <<EOF
+Usage: $(basename $0) (options)* (submodule)*
+
+Options:
+  --github-user Github user/org where the fork exists; defaults to $USER
+  --jira        JIRA used for development, will checkout if not done yet
+  -h|--help     This help page
+EOF
+  exit 1
+}
+
+_is_main_branch() {
+  local -r name="$1"
+  [[ "$name" == cassandra-* ]] && return 0
+  [[ "$name" == "trunk" ]] && return 0
+  return 1
+}
+
+_get_gh_user() {
+  # was the GitHub user set?
+  local gh_user
+  gh_user="$(git config --get 'cassandra.github.user' || true)"
+  if [[ ! -z "${gh_user:-}" ]]; then
+    echo "${gh_user}"
+    return 0
+  fi
+
+  # can it be inferred from remote?
+  local current_branch
+  current_branch="$(git rev-parse --abbrev-ref HEAD)"
+  local url
+  url="$(git config --local --get branch."${current_branch}".url || true)"
+  local inferred_name="$USER"
+  if [[ ! -z "${url:-}" ]]; then
+    inferred_name="$(echo "$url" | awk -F/ '{print $(NF-1)}' | awk -F: '{print 
$NF}')"
+  fi
+  echo "What is the github user/org used?  Inferred ${inferred_name}, enter 
new name or empty to accept:" 1>&2
+  read user_input
+  if [[ ! -z "${user_input:-}" ]]; then
+    gh_user="${user_input}"
+  else
+    gh_user="${inferred_name}"
+  fi
+  git config --local 'cassandra.github.user' "$gh_user"
+  echo "${gh_user}"
+}
+
+_main() {
+  local home
+  home="$(git rev-parse --show-toplevel)"
+  cd "$home"
+
+  local gh_user
+  gh_user="$(_get_gh_user)"
+  local branch
+  branch="$(git rev-parse --abbrev-ref HEAD)"
+  # loop over args, executing as in order of execution
+  while [ $# -gt 0 ]; do
+    case "$1" in
+      -h|--help)
+        _usage
+        ;;
+      --github-user)
+        gh_user="$2"
+        shift 2
+        ;;
+      --jira)
+        if [[ "$2" != "$branch" ]]; then
+          git checkout -b "$2"
+          branch="$2"
+        fi
+        shift 2
+        ;;
+      *)
+        break
+        ;;
+    esac
+  done
+  while _is_main_branch "$branch" ; do
+    echo "Currently on $branch, which does not look like a development 
brarnch; what JIRA are you working on? "
+    read jira
+    if [[ ! -z "${jira:-}" ]]; then
+      git checkout -b "$jira"
+      branch="$jira"
+      break
+    fi
+  done
+  local submodules
+  submodules=( $(git config --file "$home"/.gitmodules --get-regexp path | awk 
'{ print $2 }') )
+  local to_change=()
+  if [[ $# -gt 0 ]]; then
+    local exists
+    for a in "$@"; do
+      exists=false
+      for sub in "${submodules[@]}"; do
+        if [[ "$sub" == "$a" ]]; then
+          exists=true
+          break
+        fi
+      done
+      [ "$exists" == false ] && error "git submodule $a does not exist"
+      to_change+=( "$a" )
+    done
+  else
+    for sub in "${submodules[@]}"; do
+      to_change+=( "$sub" )
+    done
+  fi
+  local submodule_branch
+  local name
+  for path in "${to_change[@]}"; do
+    name="$(basename "$path")"
+    # why use https rather than git@?  This is to make sure CI works, as CI 
will fail to clone with git@
+    git submodule set-url "${path}" 
"https://github.com/${gh_user}/cassandra-${name}.git";
+    git submodule set-branch --branch "${branch}" "${path}"
+    cd "$path"
+      submodule_branch="$(git rev-parse --abbrev-ref HEAD)"
+      if [[ "${submodule_branch}" != "${branch}" ]]; then
+        git checkout -b "$branch"
+      fi
+    cd -
+  done
+}
+
+_main "$@"
diff --git a/.gitignore b/.gitignore
index 2cb754cab6..a7abbccd68 100644
--- a/.gitignore
+++ b/.gitignore
@@ -84,4 +84,3 @@ venv/
 # build-scripts will put cassandra-builds into the directory
 cassandra-builds/
 cassandra-dtest/
-.build/cassandra-accord/
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000000..616dacf610
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,4 @@
+[submodule "modules/accord"]
+       path = modules/accord
+       url = https://github.com/apache/cassandra-accord.git
+       branch = trunk
diff --git a/CHANGES.txt b/CHANGES.txt
index a7199d0f7e..8058edab9f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -5,6 +5,7 @@ accord
  * CEP-15 (C*): Messaging and storage engine integration (CASSANDRA-17103)
 
 4.2
+ * CEP-15: (C*) Add git submodule for Accord (CASSANDRA-18204)
  * Print friendly error when nodetool attempts to connect to uninitialized 
server (CASSANDRA-11537)
  * Use G1GC by default, and update default G1GC settings (CASSANDRA-18027)
  * SimpleSeedProvider can resolve multiple IP addresses per DNS record 
(CASSANDRA-14361)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 9b33116d16..8021b4eda0 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -27,6 +27,39 @@ In fact, this repository is a GitHub mirror of [the official 
repo](https://gitbo
 
 Use [Cassandra JIRA](https://issues.apache.org/jira/browse/CASSANDRA/) to 
create an issue, then either attach a patch or post a link to a GitHub branch 
with your changes.
 
+# Working with submodules
+
+Apache Cassandra uses git submodules for a set of dependencies, this is to 
make cross cutting changes easier for developers.  When working on such 
changes, there are a set of scripts to help with the process.
+
+## Local Development
+
+When starting a development branch, the following will change all submodules 
to a new branch based off the JIRA
+
+```
+$ .build/sh/development-switch.sh --jira CASSANDRA-<number>
+```
+
+When changes are made to a submodule (such as to accord), you need to commit 
and update the reference in Apache Cassandra
+
+```
+$ (cd modules/accord ; git commit -am 'Saving progress')
+$ .build/sh/bump-accord.sh
+```
+
+During this step you may be asked for github credentials, github removed 
password auth for `https` endpoints in 2021 so you will need to generate a auth 
token to support pushing, this can be done by going to 
https://github.com/settings/tokens/new and creating a token with the "repo" 
scope.
+
+## Commit and Merge Process
+
+Due to the nature of submodules, the changes to the submodules must be 
committed and pushed before the changes to Apache Cassandra; these are 
different repositories so git's `--atomic` does not prevent conflicts from 
concurrent merges; the basic process is as follows:
+
+* Follow the normal merge process for the submodule
+* Update Apache Cassandra's submodule entry to point to the newly committed 
change; follow the Accord example below for an example
+
+```
+$ .build/sh/change-submodule-accord.sh
+$ .build/sh/bump-accord.sh
+```
+
 # Useful Links
 
 - How you can contribute to Apache Cassandra 
[presentation](http://www.slideshare.net/yukim/cassandrasummit2013) by Yuki 
Morishita
diff --git a/build.xml b/build.xml
index 0563f04263..6e7f64af58 100644
--- a/build.xml
+++ b/build.xml
@@ -80,6 +80,7 @@
     <property name="test.jvm.args" value="" />
     <property name="dist.dir" value="${build.dir}/dist"/>
     <property name="tmp.dir" value="${java.io.tmpdir}"/>
+    <property name="ant.build.src" value="${basedir}/.build" />
 
     <property name="doc.dir" value="${basedir}/doc"/>
 
@@ -90,8 +91,12 @@
     <property name="version.properties.dir"
               value="${build.src.resources}/org/apache/cassandra/config/" />
     <property name="final.name" value="${ant.project.name}-${version}"/>
+    <property name="accord.dir" value="modules/accord" />
+    <!-- The reason not to use ant.project.name is we publish as 
"cassandra-accord" so the file names won't be named apache-cassandra-accord -->
+    <property name="accord.final.name" value="cassandra-accord-${version}"/>
 
     <property name="local.repository" value="${user.home}/.m2/repository" />
+    <property name="accord.local.repository" 
value="${local.repository}/org/apache/cassandra/cassandra-accord/${version}" />
 
     <!-- details of how and which Maven repository we publish to -->
     <property name="maven.version" value="3.0.3" />
@@ -283,11 +288,6 @@
         </fileset>
     </path>
 
-    <target name="_build-accord">
-      <echo unless:set="env.ACCORD_LOCAL_DEV">building Accord, set 
ACCORD_LOCAL_DEV environment variable to skip</echo>
-      <exec unless:set="env.ACCORD_LOCAL_DEV" 
executable=".build/include-accord.sh" dir="${basedir}" logError="true" 
failonerror="true" failifexecutionfails="true" />
-      <echo if:set="env.ACCORD_LOCAL_DEV">ACCORD_LOCAL_DEV environment 
variable is set, skipping pull/install</echo>
-    </target>
   <macrodef name="create-javadoc">
     <attribute name="destdir"/>
     <element name="filesets"/>
@@ -359,7 +359,7 @@
     <!--
         Setup the output directories.
     -->
-    <target name="init" depends="validate-build-conf,_build-accord">
+    <target name="init" depends="validate-build-conf">
         <fail unless="is.source.artifact"
             message="Not a source artifact, stopping here." />
         <mkdir dir="${build.classes.main}"/>
@@ -371,6 +371,7 @@
         <mkdir dir="${build.dir.lib}"/>
         <mkdir dir="${jacoco.export.dir}"/>
         <mkdir dir="${jacoco.partials.dir}"/>
+        <exec executable="${ant.build.src}/git/install-git-defaults.sh" 
osfamily="unix" dir="${basedir}" logError="true" failonerror="true" 
failifexecutionfails="true" />
     </target>
 
     <target name="clean" description="Remove all locally created artifacts">
@@ -481,8 +482,9 @@
     <!--
         The build target builds all the .class files
     -->
-    <target name="build" 
depends="resolver-retrieve-build,build-project,checkstyle" description="Compile 
Cassandra classes"/>
-    <target name="_build_unsafe" 
depends="resolver-retrieve-build,build-project" description="Compile Cassandra 
classes without checks"/>
+    <target name="_build_subprojects" depends="_build-accord" 
description="Builds all subprojects needed for the build" />
+    <target name="build" 
depends="resolver-retrieve-build,_build_subprojects,build-project,checkstyle" 
description="Compile Cassandra classes"/>
+    <target name="_build_unsafe" 
depends="resolver-retrieve-build,_build_subprojects,build-project" 
description="Compile Cassandra classes without checks"/>
     <target name="codecoverage" depends="jacoco-run,jacoco-report" 
description="Create code coverage report"/>
 
     <target name="_build_java">
@@ -920,6 +922,9 @@
           <exclude name=".externalToolBuilders/**" />
           <!-- exclude NetBeans files -->
           <exclude name="ide/nbproject/private/**" />
+          <!-- Accord build -->
+          <exclude name="${accord.dir}/*/build/**" />
+          <exclude name="${accord.dir}/**/.gradle/**" />
         </tarfileset>
 
         <!-- python driver -->
@@ -938,6 +943,9 @@
           <exclude name="bin/*.in.sh" />
           <include name="tools/bin/*"/>
           <exclude name="tools/bin/*.in.sh" />
+          <include name=".build/git/*" />
+          <include name=".build/sh/*" />
+          <include name="${accord.dir}/gradlew" />
         </tarfileset>
       </tar>
 
@@ -1916,7 +1924,7 @@
         </java>
   </target>
 
-  <target name="init-checkstyle" 
depends="resolver-retrieve-build,build-project" unless="no-checkstyle">
+  <target name="init-checkstyle" 
depends="resolver-retrieve-build,_build_subprojects,build-project" 
unless="no-checkstyle">
       <path id="checkstyle.lib.path">
           <fileset dir="${test.lib}/jars" includes="*.jar"/>
       </path>
@@ -1942,7 +1950,7 @@
       </checkstyle>
   </target>
 
-  <target name="checkstyle-test" 
depends="init-checkstyle,resolver-retrieve-build,build-project" 
description="Run custom checkstyle code analysis on tests" if="java.version.8" 
unless="no-checkstyle">
+  <target name="checkstyle-test" 
depends="init-checkstyle,resolver-retrieve-build,_build_subprojects,build-project"
 description="Run custom checkstyle code analysis on tests" if="java.version.8" 
unless="no-checkstyle">
       <property name="checkstyle.log.dir" value="${build.dir}/checkstyle" />
       <property name="checkstyle_test.report.file" 
value="${checkstyle.log.dir}/checkstyle_report_test.xml"/>
       <mkdir  dir="${checkstyle.log.dir}" />
@@ -1962,6 +1970,7 @@
   <target name="mvn-install"
           depends="jar,sources-jar,javadoc-jar"
           description="Installs the artifacts in the Maven Local Repository">
+    <!-- This logic does not install cassandra-accord as the accord submodule 
already did so -->
 
     <!-- the parent -->
     <install pomFile="${build.dir}/${final.name}-parent.pom"
@@ -1983,6 +1992,18 @@
   <target name="publish"
           depends="mvn-install,artifacts"
           description="Publishes the artifacts to the Maven repository">
+    <!-- Accord -->
+    <deploy pomFile="${accord.local.repository}/${accord.final.name}.pom"
+            file="${accord.local.repository}/${accord.final.name}.pom"
+            packaging="pom"/>
+    <deploy pomFile="${accord.local.repository}/${accord.final.name}.pom"
+            file="${accord.local.repository}/${accord.final.name}.jar" />
+    <deploy pomFile="${accord.local.repository}/${accord.final.name}.pom"
+            file="${accord.local.repository}/${accord.final.name}-sources.jar"
+            classifier="sources"/>
+    <deploy pomFile="${accord.local.repository}/${accord.final.name}.pom"
+            file="${accord.local.repository}/${accord.final.name}-javadoc.jar"
+            classifier="javadoc"/>
 
     <!-- the parent -->
     <deploy pomFile="${build.dir}/${final.name}-parent.pom"
@@ -2009,4 +2030,5 @@
   <import file="${basedir}/.build/build-rat.xml"/>
   <import file="${basedir}/.build/build-owasp.xml"/>
   <import file="${basedir}/.build/build-git.xml"/>
+  <import file="${basedir}/.build/build-accord.xml" />
 </project>
diff --git a/ide/idea-iml-file.xml b/ide/idea-iml-file.xml
index 4c529892a4..a1c37caed4 100644
--- a/ide/idea-iml-file.xml
+++ b/ide/idea-iml-file.xml
@@ -47,6 +47,16 @@
             <excludeFolder url="file://$MODULE_DIR$/build" />
             <excludeFolder url="file://$MODULE_DIR$/data"/>
             <excludeFolder url="file://$MODULE_DIR$/logs"/>
+
+            <sourceFolder 
url="file://$MODULE_DIR$/modules/accord/accord-core/src/main/java" 
isTestSource="false"/>
+            <sourceFolder 
url="file://$MODULE_DIR$/modules/accord/accord-core/src/main/resources" 
ype="java-resource"/>
+            <sourceFolder 
url="file://$MODULE_DIR$/modules/accord/accord-core/src/test/java" 
isTestSource="true"/>
+            <sourceFolder 
url="file://$MODULE_DIR$/modules/accord/accord-core/src/test/resources" 
ype="java-test-resource"/>
+
+            <sourceFolder 
url="file://$MODULE_DIR$/modules/accord/accord-maelstrom/src/main/java" 
isTestSource="false"/>
+            <sourceFolder 
url="file://$MODULE_DIR$/modules/accord/accord-maelstrom/src/main/resources" 
ype="java-resource"/>
+            <sourceFolder 
url="file://$MODULE_DIR$/modules/accord/accord-maelstrom/src/test/java" 
isTestSource="true"/>
+            <sourceFolder 
url="file://$MODULE_DIR$/modules/accord/accord-maelstrom/src/test/resources" 
ype="java-test-resource"/>
         </content>
         <orderEntry type="inheritedJdk" />
         <orderEntry type="sourceFolder" forTests="false" />
@@ -54,6 +64,8 @@
             <library>
                 <CLASSES>
                     <root url="file://$MODULE_DIR$/build/lib/jars" />
+                    <root 
url="file://$MODULE_DIR$/modules/accord/accord-core/build/dependencies/main/libs"
 />
+                    <root 
url="file://$MODULE_DIR$/modules/accord/accord-maelstrom/build/dependencies/main/libs"
 />
                 </CLASSES>
                 <JAVADOC />
                 <SOURCES>
@@ -61,12 +73,17 @@
                 </SOURCES>
                 <jarDirectory url="file://$MODULE_DIR$/build/lib/jars" 
recursive="false" />
                 <jarDirectory url="file://$MODULE_DIR$/build/lib/sources" 
recursive="false" type="SOURCES" />
+
+                <jarDirectory 
url="file://$MODULE_DIR$/modules/accord/accord-core/build/dependencies/main/libs"
 recursive="false" />
+                <jarDirectory 
url="file://$MODULE_DIR$/modules/accord/accord-maelstrom/build/dependencies/main/libs"
 recursive="false" />
             </library>
         </orderEntry>
         <orderEntry type="module-library" scope="TEST">
             <library>
                 <CLASSES>
                     <root url="file://$MODULE_DIR$/build/test/lib/jars" />
+                    <root 
url="file://$MODULE_DIR$/modules/accord/accord-core/build/dependencies/test/libs"
 />
+                    <root 
url="file://$MODULE_DIR$/modules/accord/accord-maelstrom/build/dependencies/test/libs"
 />
                 </CLASSES>
                 <JAVADOC />
                 <SOURCES>
@@ -74,6 +91,9 @@
                 </SOURCES>
                 <jarDirectory url="file://$MODULE_DIR$/build/test/lib/jars" 
recursive="false" />
                 <jarDirectory url="file://$MODULE_DIR$/build/test/lib/sources" 
recursive="false" type="SOURCES" />
+
+                <jarDirectory 
url="file://$MODULE_DIR$/modules/accord/accord-core/build/dependencies/test/libs"
 recursive="false" />
+                <jarDirectory 
url="file://$MODULE_DIR$/modules/accord/accord-maelstrom/build/dependencies/test/libs"
 recursive="false" />
             </library>
         </orderEntry>
     </component>
diff --git a/ide/idea/vcs.xml b/ide/idea/vcs.xml
index 81872fd3f1..a5367a526e 100644
--- a/ide/idea/vcs.xml
+++ b/ide/idea/vcs.xml
@@ -2,6 +2,7 @@
 <project version="4">
   <component name="VcsDirectoryMappings">
     <mapping directory="$PROJECT_DIR$" vcs="Git" />
+    <mapping directory="$PROJECT_DIR$/modules/accord" vcs="Git" />
   </component>
   <component name="IssueNavigationConfiguration">
     <option name="links">
@@ -13,4 +14,4 @@
       </list>
     </option>
   </component>
-</project>
\ No newline at end of file
+</project>
diff --git a/modules/accord b/modules/accord
new file mode 160000
index 0000000000..b9025e5939
--- /dev/null
+++ b/modules/accord
@@ -0,0 +1 @@
+Subproject commit b9025e59395f47535e4ed1fec20b1186cdb07db8


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


Reply via email to