You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by am...@apache.org on 2021/08/12 19:48:14 UTC

[ignite-3] branch main updated: IGNITE-15025 Add Maven check scripts to VCS (#247)

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

amashenkov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new cd6d863  IGNITE-15025 Add Maven check scripts to VCS (#247)
cd6d863 is described below

commit cd6d86382352b7b9b77400065a837bf3dc953c9e
Author: Peter Ivanov <mr...@gmail.com>
AuthorDate: Thu Aug 12 22:48:04 2021 +0300

    IGNITE-15025 Add Maven check scripts to VCS (#247)
---
 DEVNOTES.md                                        | 12 ++++++
 .../CheckDependencyAndPluginVersionsNotInParent.sh | 30 ++++++++++++++
 .../CheckModulesInRootPomAreSorted.sh              | 25 ++++++++++++
 .../CheckPropertiesNotInParent.sh                  | 25 ++++++++++++
 .../CheckUnusedDependenciesAndPluginsInParent.sh   | 46 ++++++++++++++++++++++
 .../maven-check-scripts/CheckUnusedProperties.sh   | 34 ++++++++++++++++
 check-rules/maven-check-scripts/run.sh             | 42 ++++++++++++++++++++
 7 files changed, 214 insertions(+)

diff --git a/DEVNOTES.md b/DEVNOTES.md
index 4b56da4..cc02fd3 100644
--- a/DEVNOTES.md
+++ b/DEVNOTES.md
@@ -59,6 +59,18 @@ mvn clean compile pmd:check
 PMD check result (only if there are any violations) is generated at `target/pmd.xml`.
 ***
 
+### Maven
+Project is supplied with number of custom scripts for Maven sanity check.
+To run checks, execute:
+```
+bash check-rules/maven-check-scripts/run.sh
+```
+from root of the project.
+
+Linux, MacOS, WSL (Windows Subsystem on Linux) or alike environment is required.
+`xpath` should be present in PATH
+***
+
 
 ## Running tests
 Run unit tests only:
diff --git a/check-rules/maven-check-scripts/CheckDependencyAndPluginVersionsNotInParent.sh b/check-rules/maven-check-scripts/CheckDependencyAndPluginVersionsNotInParent.sh
new file mode 100644
index 0000000..bfd7b09
--- /dev/null
+++ b/check-rules/maven-check-scripts/CheckDependencyAndPluginVersionsNotInParent.sh
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+set -o nounset; set -o errexit; set -o pipefail; set -o errtrace; set -o functrace
+
+#  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.
+
+
+ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/../.."
+find ${ROOT} -name "pom.xml" |  \
+  grep -v parent | \
+  while read -r pom; do
+    for xpath in "project/dependencies/dependency/version" \
+                 "project/build/plugins/plugin/version" \
+                 "project/profiles/profile/build/plugins/plugin/version"; do
+		if xpath -e "${xpath}" ${pom} 2>&1 | \
+          grep -qE "^Found"; then
+            echo "[ERROR] Found version in non parent pom: ${pom}"
+		fi
+    done
+done
diff --git a/check-rules/maven-check-scripts/CheckModulesInRootPomAreSorted.sh b/check-rules/maven-check-scripts/CheckModulesInRootPomAreSorted.sh
new file mode 100644
index 0000000..611c3ac
--- /dev/null
+++ b/check-rules/maven-check-scripts/CheckModulesInRootPomAreSorted.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+set -o nounset; set -o errexit; set -o pipefail; set -o errtrace; set -o functrace
+
+#  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.
+
+
+ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/../.."
+xpath -e "project/modules/module/text()" ${ROOT}/pom.xml 2>/dev/null > current-list
+cat current-list | sort -h > sorted-list
+DIFF="$(diff current-list sorted-list || true)"
+if [ "${DIFF}" != "" ]; then
+	echo "[ERROR] Modules are in unsorted order:"
+    echo "${DIFF}"
+fi
diff --git a/check-rules/maven-check-scripts/CheckPropertiesNotInParent.sh b/check-rules/maven-check-scripts/CheckPropertiesNotInParent.sh
new file mode 100644
index 0000000..cacd370
--- /dev/null
+++ b/check-rules/maven-check-scripts/CheckPropertiesNotInParent.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+set -o nounset; set -o errexit; set -o pipefail; set -o errtrace; set -o functrace
+
+#  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.
+
+
+ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/../.."
+find ${ROOT} -name "pom.xml" | \
+  grep -v parent | \
+  while read -r pom; do
+      if grep '<properties>' "${pom}"; then
+          echo "[ERROR] Found <properties> section: ${pom}"
+      fi
+done
diff --git a/check-rules/maven-check-scripts/CheckUnusedDependenciesAndPluginsInParent.sh b/check-rules/maven-check-scripts/CheckUnusedDependenciesAndPluginsInParent.sh
new file mode 100644
index 0000000..f0a390f
--- /dev/null
+++ b/check-rules/maven-check-scripts/CheckUnusedDependenciesAndPluginsInParent.sh
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+set -o nounset; set -o errexit; set -o pipefail; set -o errtrace; set -o functrace
+
+#  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.
+
+
+ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/../.."
+POMS=$(find ${ROOT} -name pom.xml | grep -v parent)
+for xpath in "project/dependencyManagement/dependencies/dependency/artifactId/text()" \
+             "project/build/pluginManagement/plugins/plugin/artifactId/text()"; do
+	xpath -e "${xpath}" ${ROOT}/parent/pom.xml 2>&1 | \
+      grep -vE '(NODE|Found)' | \
+      while read -r declaration; do
+        FOUND=false
+        for pom in ${POMS}; do
+            if grep -E "<artifactId>${declaration}</artifactId>" "${pom}" 2>&1 1>/dev/null; then
+            	FOUND=true
+                continue 2
+            fi
+        done
+        for parent_xpath in "project/build/plugins" \
+                            "project/dependencies"; do
+            if xpath -e "${parent_xpath}" ${ROOT}/parent/pom.xml 2>&1 | \
+              grep -E "<" | \
+              grep -E "<artifactId>${declaration}</artifactId>" 2>&1 1>/dev/null; then
+              	FOUND=true
+                continue 2
+            fi
+        done
+        if [ "${FOUND}" == "false" ]; then
+            echo "${declaration}" >> unused-properties.txt
+            echo "[ERROR] Found unused declaration: ${declaration}"
+        fi
+    done
+done
diff --git a/check-rules/maven-check-scripts/CheckUnusedProperties.sh b/check-rules/maven-check-scripts/CheckUnusedProperties.sh
new file mode 100644
index 0000000..6ca2107
--- /dev/null
+++ b/check-rules/maven-check-scripts/CheckUnusedProperties.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+set -o nounset; set -o errexit; set -o pipefail; set -o errtrace; set -o functrace
+
+#  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.
+
+
+ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/../.."
+POMS=$(find ${ROOT} -name pom.xml)
+xpath -e "project/properties/*" ${ROOT}/parent/pom.xml 2>&1 | \
+  grep -E "^<.*\.version>" | \
+  sed -r 's|<(.*)>.*<\/.*>|\1|' | \
+  while read -r property; do
+    FOUND=false
+    for pom in ${POMS}; do
+        if grep -qE "\\$.*${property}" "${pom}"; then
+            FOUND=true
+        fi
+    done
+    if [ "${FOUND}" == "false" ]; then
+        echo "${property}" > unused-properties.txt
+        echo "[ERROR] Found unused property: ${property}"
+    fi
+done
diff --git a/check-rules/maven-check-scripts/run.sh b/check-rules/maven-check-scripts/run.sh
new file mode 100644
index 0000000..359b0ce
--- /dev/null
+++ b/check-rules/maven-check-scripts/run.sh
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+set -o nounset; set -o errexit; set -o pipefail; set -o errtrace; set -o functrace
+
+#  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.
+
+cleanup() {
+    rm -rf current-list \
+           sorted-list \
+           unused-properties.txt
+}
+trap cleanup EXIT SIGINT ERR
+
+command -v xpath > /dev/null || {
+    echo "xpath not found, exiting"
+}
+
+DIR__MAVEN_CHECK_SCRIPTS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
+for script in CheckDependencyAndPluginVersionsNotInParent.sh \
+              CheckModulesInRootPomAreSorted.sh \
+              CheckPropertiesNotInParent.sh \
+              CheckUnusedDependenciesAndPluginsInParent.sh \
+              CheckUnusedProperties.sh; do
+    echo -n " * Executing ${script}... "
+    bash ${DIR__MAVEN_CHECK_SCRIPTS}/${script} && \
+        echo "[OK]" || {
+            echo "[ERROR]"
+            exit 1
+        }
+done
+echo
+echo "All checks finished successfully"