From de3a0402681eaa85d56eac3f03986ddb352c210d Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Thu, 12 Jun 2025 16:57:11 -0400 Subject: [PATCH 01/48] integrated pmd into CI (#646) --- .github/workflows/pmd.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/pmd.yml diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml new file mode 100644 index 0000000000..961b25c6e0 --- /dev/null +++ b/.github/workflows/pmd.yml @@ -0,0 +1,21 @@ +name: PMD Analysis + +on: [push, pull_request, workflow_dispatch] + +jobs: + pmd: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '11' + - uses: pmd/pmd-github-action@v2 + id: pmd + with: + rulesets: 'ruleset.xml' + analyzeModifiedFilesOnly: true + createGitHubAnnotations: false + uploadSarifReport: true + From a1fe811848ceacf368455b012c13fa696260acde Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Thu, 12 Jun 2025 17:24:47 -0400 Subject: [PATCH 02/48] create rulset file --- .github/workflows/ruleset.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/ruleset.xml diff --git a/.github/workflows/ruleset.xml b/.github/workflows/ruleset.xml new file mode 100644 index 0000000000..7ab6044077 --- /dev/null +++ b/.github/workflows/ruleset.xml @@ -0,0 +1,15 @@ + + + + Ruleset to analyze only Fortran files within the src directory. + + + + src/.*\.(f|fpp|for|f90|f95|f03|f08)$ + toolchain/.*\.(py)$ + + \ No newline at end of file From 8defa9aaacf26040b9d0f770e8f156e1edf9684d Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Thu, 12 Jun 2025 17:27:51 -0400 Subject: [PATCH 03/48] corrected directory --- .github/workflows/pmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 961b25c6e0..9340ba4c85 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -14,7 +14,7 @@ jobs: - uses: pmd/pmd-github-action@v2 id: pmd with: - rulesets: 'ruleset.xml' + rulesets: '.github/workflows/ruleset.xml' analyzeModifiedFilesOnly: true createGitHubAnnotations: false uploadSarifReport: true From 1fde2bc26dd5a7050ddf9b4d82510afe588e836a Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Thu, 12 Jun 2025 17:31:37 -0400 Subject: [PATCH 04/48] changed ruleset pattern typo --- .github/workflows/ruleset.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ruleset.xml b/.github/workflows/ruleset.xml index 7ab6044077..46514c4406 100644 --- a/.github/workflows/ruleset.xml +++ b/.github/workflows/ruleset.xml @@ -9,7 +9,7 @@ - src/.*\.(f|fpp|for|f90|f95|f03|f08)$ - toolchain/.*\.(py)$ + .*/src/.*\.(f|fpp|for|f90|f95|f03|f08)$ + .*/toolchain/.*\.py$ \ No newline at end of file From 0332cf142b20e861902443faa30ddb4ea30bb3a0 Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Thu, 12 Jun 2025 17:35:59 -0400 Subject: [PATCH 05/48] added rules to python and fortran --- .github/workflows/ruleset.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ruleset.xml b/.github/workflows/ruleset.xml index 46514c4406..413db8992d 100644 --- a/.github/workflows/ruleset.xml +++ b/.github/workflows/ruleset.xml @@ -12,4 +12,13 @@ .*/src/.*\.(f|fpp|for|f90|f95|f03|f08)$ .*/toolchain/.*\.py$ + + + + + + + + + \ No newline at end of file From 9f46e719aa29643ad53d766e453f43e8ae809acd Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Thu, 12 Jun 2025 17:53:34 -0400 Subject: [PATCH 06/48] ruleset for py --- .github/workflows/ruleset.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ruleset.xml b/.github/workflows/ruleset.xml index 413db8992d..8bc7d4d305 100644 --- a/.github/workflows/ruleset.xml +++ b/.github/workflows/ruleset.xml @@ -18,7 +18,4 @@ - - - \ No newline at end of file From 8c3fb0863c5ea749506961485e8831bac3c4efaf Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Thu, 12 Jun 2025 17:55:42 -0400 Subject: [PATCH 07/48] individual rules --- .github/workflows/ruleset.xml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ruleset.xml b/.github/workflows/ruleset.xml index 8bc7d4d305..0c217b3437 100644 --- a/.github/workflows/ruleset.xml +++ b/.github/workflows/ruleset.xml @@ -12,10 +12,11 @@ .*/src/.*\.(f|fpp|for|f90|f95|f03|f08)$ .*/toolchain/.*\.py$ - - - - - + + + + + + \ No newline at end of file From cd8e2a5b280ea3dc66552b0b7506c6e28ec7c626 Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Thu, 12 Jun 2025 17:58:40 -0400 Subject: [PATCH 08/48] java rules - errorprone --- .github/workflows/ruleset.xml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/ruleset.xml b/.github/workflows/ruleset.xml index 0c217b3437..6c1e646324 100644 --- a/.github/workflows/ruleset.xml +++ b/.github/workflows/ruleset.xml @@ -13,10 +13,6 @@ .*/toolchain/.*\.py$ - - - - - + \ No newline at end of file From 4db4277a0fabc631c067c719de150369f009bbf0 Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Thu, 12 Jun 2025 18:00:51 -0400 Subject: [PATCH 09/48] java rules --- .github/workflows/ruleset.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ruleset.xml b/.github/workflows/ruleset.xml index 6c1e646324..66ca166ad6 100644 --- a/.github/workflows/ruleset.xml +++ b/.github/workflows/ruleset.xml @@ -13,6 +13,6 @@ .*/toolchain/.*\.py$ - + \ No newline at end of file From d6d3bc865c69e7e6eae32ff4b09265cb9a10d30f Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Thu, 12 Jun 2025 19:49:20 -0400 Subject: [PATCH 10/48] old school integration of PMD into workflow --- .github/workflows/pmd.yml | 63 +++++++++++++++++++++++++++-------- .github/workflows/ruleset.xml | 18 ---------- 2 files changed, 49 insertions(+), 32 deletions(-) delete mode 100644 .github/workflows/ruleset.xml diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 9340ba4c85..5b061705ad 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -3,19 +3,54 @@ name: PMD Analysis on: [push, pull_request, workflow_dispatch] jobs: - pmd: - runs-on: ubuntu-latest + file-changes: + name: Detect File Changes + runs-on: 'ubuntu-latest' + outputs: + checkall: ${{ steps.changes.outputs.checkall }} steps: - - uses: actions/checkout@v2 - - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '11' - - uses: pmd/pmd-github-action@v2 - id: pmd - with: - rulesets: '.github/workflows/ruleset.xml' - analyzeModifiedFilesOnly: true - createGitHubAnnotations: false - uploadSarifReport: true + - name: Clone + uses: actions/checkout@v4 + + - name: Detect Changes + uses: dorny/paths-filter@v3 + id: changes + with: + filters: ".github/file-filter.yml" + + pmd: + name: PMD Analysis + if: needs.file-changes.outputs.checkall == 'true' + needs: file-changes + runs-on: "ubuntu-latest" + env: + pr_everything: 0 + steps: + - name: Clone - PR + uses: actions/checkout@v4 + with: + path: pr + + - name: Clone PMD + run: | + sudo apt update -y + sudo apt install -y tar wget make cmake gcc g++ python3 python3-dev "openmpi-*" libopenmpi-dev + git clone https://github.com/pmd/pmd.git pmd + (cd pmd && git checkout pmd) + + - name: Build PMD + run: | + (cd pmd && ./mvnw clean install -DskipTests> ../pmd.txt) + + - name: Running PMD + run: | + (cd pmd && ./pmd cpd -l fortran pr/src/* > ../pmd-fort.txt) + (cd pmd && ./pmd cpd -l python pr/toolchain/* > ../pmd-py.txt) + - name: Display PMD Reports + uses: actions/upload-artifact@v2 + with: + name: pmd-reports + path: | + pmd-fort.txt + pmd-py.txt \ No newline at end of file diff --git a/.github/workflows/ruleset.xml b/.github/workflows/ruleset.xml deleted file mode 100644 index 66ca166ad6..0000000000 --- a/.github/workflows/ruleset.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - Ruleset to analyze only Fortran files within the src directory. - - - - .*/src/.*\.(f|fpp|for|f90|f95|f03|f08)$ - .*/toolchain/.*\.py$ - - - - - \ No newline at end of file From 54a6fc9c0eb2ddba82ebc654fe45a3d5c6d638a7 Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Thu, 12 Jun 2025 19:55:28 -0400 Subject: [PATCH 11/48] removed Detect File Changes --- .github/workflows/pmd.yml | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 5b061705ad..4d65511cd1 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -2,26 +2,9 @@ name: PMD Analysis on: [push, pull_request, workflow_dispatch] -jobs: - file-changes: - name: Detect File Changes - runs-on: 'ubuntu-latest' - outputs: - checkall: ${{ steps.changes.outputs.checkall }} - steps: - - name: Clone - uses: actions/checkout@v4 - - - name: Detect Changes - uses: dorny/paths-filter@v3 - id: changes - with: - filters: ".github/file-filter.yml" - +jobs: pmd: name: PMD Analysis - if: needs.file-changes.outputs.checkall == 'true' - needs: file-changes runs-on: "ubuntu-latest" env: pr_everything: 0 From 515c32a623c294ad8aedf52c857f61897132915c Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Thu, 12 Jun 2025 20:01:14 -0400 Subject: [PATCH 12/48] changed to cat to display reports --- .github/workflows/pmd.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 4d65511cd1..f293612b59 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -31,9 +31,8 @@ jobs: (cd pmd && ./pmd cpd -l python pr/toolchain/* > ../pmd-py.txt) - name: Display PMD Reports - uses: actions/upload-artifact@v2 - with: - name: pmd-reports - path: | - pmd-fort.txt - pmd-py.txt \ No newline at end of file + run: | + echo "PMD Fortran Report:" + cat /pmd/pmd-fort.txt + echo "PMD Python Report:" + cat /pmd/pmd-py.txt \ No newline at end of file From 4f4134ae11443db1ce959aab140386eea23d34ae Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Thu, 12 Jun 2025 20:36:01 -0400 Subject: [PATCH 13/48] added java compiler as dependency --- .github/workflows/pmd.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index f293612b59..96bdb52b27 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -1,4 +1,4 @@ -name: PMD Analysis +name: PMD on: [push, pull_request, workflow_dispatch] @@ -17,22 +17,23 @@ jobs: - name: Clone PMD run: | sudo apt update -y - sudo apt install -y tar wget make cmake gcc g++ python3 python3-dev "openmpi-*" libopenmpi-dev + sudo apt install -y tar wget make cmake gcc g++ python3 python3-dev maven + sudo apt install -y default-jdk git clone https://github.com/pmd/pmd.git pmd - (cd pmd && git checkout pmd) + (cd pmd && git checkout master) - name: Build PMD run: | - (cd pmd && ./mvnw clean install -DskipTests> ../pmd.txt) + (cd pmd && mvn clean install -DskipTests> ../pmd.txt) - name: Running PMD run: | - (cd pmd && ./pmd cpd -l fortran pr/src/* > ../pmd-fort.txt) - (cd pmd && ./pmd cpd -l python pr/toolchain/* > ../pmd-py.txt) + (cd pmd && pmd cpd -l fortran pr/src/* > ../pmd-fort.txt) + (cd pmd && pmd cpd -l python pr/toolchain/* > ../pmd-py.txt) - name: Display PMD Reports run: | echo "PMD Fortran Report:" - cat /pmd/pmd-fort.txt + cat pmd-fort.txt echo "PMD Python Report:" - cat /pmd/pmd-py.txt \ No newline at end of file + cat pmd-py.txt \ No newline at end of file From b3ae8fa604a5ecb58fa43a852f1e8f4673a1e53b Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Thu, 12 Jun 2025 20:39:19 -0400 Subject: [PATCH 14/48] removed something --- .github/workflows/pmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 96bdb52b27..27c6ee9311 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -20,7 +20,7 @@ jobs: sudo apt install -y tar wget make cmake gcc g++ python3 python3-dev maven sudo apt install -y default-jdk git clone https://github.com/pmd/pmd.git pmd - (cd pmd && git checkout master) + (cd pmd && git checkout) - name: Build PMD run: | From 085eaa5e81a38b9b7feed9e3b1043f3ec10c28c0 Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Thu, 12 Jun 2025 20:52:33 -0400 Subject: [PATCH 15/48] just checking syntax --- .github/workflows/pmd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 27c6ee9311..2f6f45ade6 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -28,8 +28,8 @@ jobs: - name: Running PMD run: | - (cd pmd && pmd cpd -l fortran pr/src/* > ../pmd-fort.txt) - (cd pmd && pmd cpd -l python pr/toolchain/* > ../pmd-py.txt) + (cd pmd && ./pmd cpd -l fortran pr/src/* > ../pmd-fort.txt) + (cd pmd && ./pmd cpd -l python pr/toolchain/* > ../pmd-py.txt) - name: Display PMD Reports run: | From e3626f6967922714fc3493d36c4efda676256d05 Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Fri, 13 Jun 2025 16:03:08 -0400 Subject: [PATCH 16/48] set env var pmd=/pmd/bin/pmd --- .github/workflows/pmd.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 2f6f45ade6..1bc59b4354 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -25,11 +25,12 @@ jobs: - name: Build PMD run: | (cd pmd && mvn clean install -DskipTests> ../pmd.txt) + alias pmd=/pmd/bin/pmd - name: Running PMD run: | - (cd pmd && ./pmd cpd -l fortran pr/src/* > ../pmd-fort.txt) - (cd pmd && ./pmd cpd -l python pr/toolchain/* > ../pmd-py.txt) + (cd pmd && $pmd cpd -l fortran pr/src/* > ../pmd-fort.txt) + (cd pmd && $pmd cpd -l python pr/toolchain/* > ../pmd-py.txt) - name: Display PMD Reports run: | From f022a85eb2110266f68d1b4c518c1369e2182dfe Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Fri, 13 Jun 2025 16:06:52 -0400 Subject: [PATCH 17/48] quick syntax correction --- .github/workflows/pmd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 1bc59b4354..2970a32a56 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -29,8 +29,8 @@ jobs: - name: Running PMD run: | - (cd pmd && $pmd cpd -l fortran pr/src/* > ../pmd-fort.txt) - (cd pmd && $pmd cpd -l python pr/toolchain/* > ../pmd-py.txt) + (cd pmd && pmd cpd -l fortran pr/src/* > ../pmd-fort.txt) + (cd pmd && pmd cpd -l python pr/toolchain/* > ../pmd-py.txt) - name: Display PMD Reports run: | From 4fdb0c33bda788751587df4bd227b0c166c4998a Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Fri, 13 Jun 2025 16:22:04 -0400 Subject: [PATCH 18/48] made PMD_COMMAND globally recognized --- .github/workflows/pmd.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 2970a32a56..99d24494fa 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -25,12 +25,12 @@ jobs: - name: Build PMD run: | (cd pmd && mvn clean install -DskipTests> ../pmd.txt) - alias pmd=/pmd/bin/pmd - + export PMD_COMMAND="$(pwd)/pmd/bin/pmd" + - name: Running PMD run: | - (cd pmd && pmd cpd -l fortran pr/src/* > ../pmd-fort.txt) - (cd pmd && pmd cpd -l python pr/toolchain/* > ../pmd-py.txt) + $PMD_COMMAND cpd -l fortran pr/src/* > ../pmd-fort.txt + $PMD_COMMAND cpd -l python pr/toolchain/* > ../pmd-py.txt - name: Display PMD Reports run: | From c7c1bdbfdb9b533d268fcafb20721782b72a89dc Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Fri, 13 Jun 2025 16:38:26 -0400 Subject: [PATCH 19/48] corrected package path --- .github/workflows/pmd.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 99d24494fa..3b3520c4a5 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -25,12 +25,12 @@ jobs: - name: Build PMD run: | (cd pmd && mvn clean install -DskipTests> ../pmd.txt) - export PMD_COMMAND="$(pwd)/pmd/bin/pmd" + export PATH=$PATH:$(pwd)/bin/pmd - name: Running PMD run: | - $PMD_COMMAND cpd -l fortran pr/src/* > ../pmd-fort.txt - $PMD_COMMAND cpd -l python pr/toolchain/* > ../pmd-py.txt + pmd cpd -l fortran pr/src/* > ../pmd-fort.txt + pmd cpd -l python pr/toolchain/* > ../pmd-py.txt - name: Display PMD Reports run: | From 393d69b41580bf8726042f45268105136da875e4 Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Fri, 13 Jun 2025 16:52:33 -0400 Subject: [PATCH 20/48] moved alias command under Running PMD --- .github/workflows/pmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 3b3520c4a5..386dabfbfc 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -25,10 +25,10 @@ jobs: - name: Build PMD run: | (cd pmd && mvn clean install -DskipTests> ../pmd.txt) - export PATH=$PATH:$(pwd)/bin/pmd - name: Running PMD run: | + alias pmd="$HOME/pmd/bin/pmd" pmd cpd -l fortran pr/src/* > ../pmd-fort.txt pmd cpd -l python pr/toolchain/* > ../pmd-py.txt From 74486098c780acebdfcb8472f75425ab453c7a2e Mon Sep 17 00:00:00 2001 From: mohdsaid497566 Date: Mon, 16 Jun 2025 16:44:07 -0400 Subject: [PATCH 21/48] comments removal --- .github/workflows/pmd.yml | 45 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 386dabfbfc..e7e971ad0f 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -29,7 +29,50 @@ jobs: - name: Running PMD run: | alias pmd="$HOME/pmd/bin/pmd" - pmd cpd -l fortran pr/src/* > ../pmd-fort.txt + + SOURCE_DIR="${1:-pr/src}" + total_files=$(find "$SOURCE_DIR" -type f \( -name "*.f" -o -name "*.f90" -o -name "*.for" -o -name "*.fpp" -o -name "*.F" -o -name "*.F90" \) | wc -l) + processed=0 + + find "$SOURCE_DIR" -type f \( -name "*.f" -o -name "*.f90" -o -name "*.for" -o -name "*.fpp" -o -name "*.F" -o -name "*.F90" \) -print0 | + while IFS= read -r -d $'\0' file; do + processed=$((processed + 1)) + echo -e "[$processed/$total_files] Processing ${file}..." + + # Create a temporary file with same permissions as original + TMP_FILE=$(mktemp) + if [ $? -ne 0 ]; then + echo -e "Failed to create temporary file for $file, skipping" + continue + fi + + # Copy permissions from original file + chmod --reference="$file" "$TMP_FILE" + + # More comprehensive sed command to handle different Fortran comment styles: + # 1. Replace lines that are entirely comments with an empty line: + # - Lines starting with '!' (free form comments) + # - Lines starting with 'c', 'C', '*', 'd', 'D' in column 1 (fixed form comments) + # 2. Remove end-of-line comments (anything after '!' that isn't in a string) + # 3. Preserve strings containing '!' characters + sed -E \ + -e '/^\s*!/s/.*//' \ + -e '/^[cC*dD]/s/.*//' \ + -e '/^[ \t]*[cC*dD]/s/.*//' \ + -e 's/([^"'\'']*("[^"]*"[^"'\'']*|'\''[^'\'']*'\''[^"'\'']*)*[^"'\'']*)[!].*$/\1/' \ + "$file" > "$TMP_FILE" + + # Check if file was actually modified before replacing + if cmp -s "$file" "$TMP_FILE"; then + echo -e "No changes needed for $file" + rm "$TMP_FILE" + else + # Overwrite the original file with the processed content + mv "$TMP_FILE" "$file" + echo -e "Successfully processed $file" + fi + done + pmd cpd -l fortran /* > ../pmd-fort.txt pmd cpd -l python pr/toolchain/* > ../pmd-py.txt - name: Display PMD Reports From 36fb29e32ad900c1b99162124049514775a76e84 Mon Sep 17 00:00:00 2001 From: mohdsaid497566 Date: Mon, 16 Jun 2025 16:50:07 -0400 Subject: [PATCH 22/48] comments removal 2 --- .github/workflows/pmd.yml | 48 ++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index e7e971ad0f..2f295d2914 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -1,36 +1,36 @@ -name: PMD +name: Source DRYness on: [push, pull_request, workflow_dispatch] jobs: pmd: - name: PMD Analysis + name: PMD runs-on: "ubuntu-latest" env: pr_everything: 0 steps: - name: Clone - PR uses: actions/checkout@v4 - with: - path: pr - - - name: Clone PMD - run: | - sudo apt update -y - sudo apt install -y tar wget make cmake gcc g++ python3 python3-dev maven - sudo apt install -y default-jdk - git clone https://github.com/pmd/pmd.git pmd - (cd pmd && git checkout) - - name: Build PMD - run: | - (cd pmd && mvn clean install -DskipTests> ../pmd.txt) + - name: Set up Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '17' - - name: Running PMD + - name: Run CPD for Fortran + continue-on-error: true run: | - alias pmd="$HOME/pmd/bin/pmd" + # Get latest PMD version from GitHub API + PMD_VERSION=$(curl -s https://api.github.com/repos/pmd/pmd/releases/latest | grep '"tag_name":' | cut -d'"' -f4 | sed 's/pmd_releases\///') + echo "Using PMD version: $PMD_VERSION" - SOURCE_DIR="${1:-pr/src}" + curl -sSL -o pmd.zip \ + "https://github.com/pmd/pmd/releases/download/pmd_releases/${PMD_VERSION}/pmd-dist-${PMD_VERSION}-bin.zip" + unzip -q pmd.zip + PMD_HOME="pmd-bin-${PMD_VERSION}" + + SOURCE_DIR="${1:-pr/src}" total_files=$(find "$SOURCE_DIR" -type f \( -name "*.f" -o -name "*.f90" -o -name "*.for" -o -name "*.fpp" -o -name "*.F" -o -name "*.F90" \) | wc -l) processed=0 @@ -72,12 +72,8 @@ jobs: echo -e "Successfully processed $file" fi done - pmd cpd -l fortran /* > ../pmd-fort.txt - pmd cpd -l python pr/toolchain/* > ../pmd-py.txt - - name: Display PMD Reports - run: | - echo "PMD Fortran Report:" - cat pmd-fort.txt - echo "PMD Python Report:" - cat pmd-py.txt \ No newline at end of file + "${PMD_HOME}/bin/pmd" cpd \ + --dir src \ + --language fortran \ + --minimum-tokens=40 \ No newline at end of file From 76352ddbebae3d53f58d7e14782e77f519b35ff9 Mon Sep 17 00:00:00 2001 From: mohdsaid497566 Date: Mon, 16 Jun 2025 16:52:50 -0400 Subject: [PATCH 23/48] comments removal 3 --- .github/workflows/pmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 2f295d2914..da7f9e452f 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -30,7 +30,7 @@ jobs: unzip -q pmd.zip PMD_HOME="pmd-bin-${PMD_VERSION}" - SOURCE_DIR="${1:-pr/src}" + SOURCE_DIR="${1:-src}" total_files=$(find "$SOURCE_DIR" -type f \( -name "*.f" -o -name "*.f90" -o -name "*.for" -o -name "*.fpp" -o -name "*.F" -o -name "*.F90" \) | wc -l) processed=0 From 0aa7abee6b5f85d7748ecddd03e35650058ca783 Mon Sep 17 00:00:00 2001 From: mohdsaid497566 Date: Mon, 16 Jun 2025 18:48:56 -0400 Subject: [PATCH 24/48] reduced number of tokens --- .github/workflows/pmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index da7f9e452f..fb35db7aa1 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -76,4 +76,4 @@ jobs: "${PMD_HOME}/bin/pmd" cpd \ --dir src \ --language fortran \ - --minimum-tokens=40 \ No newline at end of file + --minimum-tokens=10 From 52aeefce4186d844f0aa0227772da3575b51ac4f Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Mon, 16 Jun 2025 19:17:29 -0400 Subject: [PATCH 25/48] Update pmd.yml --- .github/workflows/pmd.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index ef209bc0d4..842ebb3475 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -76,4 +76,6 @@ jobs: "${PMD_HOME}/bin/pmd" cpd \ --dir src \ --language fortran \ - --minimum-tokens=10 \ No newline at end of file + --minimum-tokens=20 \ + --no-fail-on-violation \ + --no-fail-on-error From 037c2e6449be9f176dee1b3a26605cc3c594782a Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Mon, 16 Jun 2025 19:21:12 -0400 Subject: [PATCH 26/48] Update pmd.yml --- .github/workflows/pmd.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 842ebb3475..b3cc99f341 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -55,6 +55,8 @@ jobs: # - Lines starting with 'c', 'C', '*', 'd', 'D' in column 1 (fixed form comments) # 2. Remove end-of-line comments (anything after '!' that isn't in a string) # 3. Preserve strings containing '!' characters + sed -E ' :a /[[:space:]]*&[[:space:]]*$/ { N; s/[[:space:]]*&[[:space:]]*\n[[:space:]]*/ /; ba } s/^[[:space:]]*!\$acc[[:space:]]*/!$acc / :b s/[[:space:]]+!\$acc[[:space:]]*/ /g tb ' "$file" > "$file" + sed -E \ -e '/^\s*!/s/.*//' \ -e '/^[cC*dD]/s/.*//' \ From 26f3228b013135df33f5ccc90b24c4f2dab40cf0 Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Mon, 16 Jun 2025 19:24:37 -0400 Subject: [PATCH 27/48] Update pmd.yml --- .github/workflows/pmd.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index b3cc99f341..9994521d43 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -55,15 +55,15 @@ jobs: # - Lines starting with 'c', 'C', '*', 'd', 'D' in column 1 (fixed form comments) # 2. Remove end-of-line comments (anything after '!' that isn't in a string) # 3. Preserve strings containing '!' characters - sed -E ' :a /[[:space:]]*&[[:space:]]*$/ { N; s/[[:space:]]*&[[:space:]]*\n[[:space:]]*/ /; ba } s/^[[:space:]]*!\$acc[[:space:]]*/!$acc / :b s/[[:space:]]+!\$acc[[:space:]]*/ /g tb ' "$file" > "$file" + TMP_FILE=$(mktemp) + sed -E ' :a /[[:space:]]*&[[:space:]]*$/ { N; s/[[:space:]]*&[[:space:]]*\n[[:space:]]*/ /; ba } s/^[[:space:]]*!\$acc[[:space:]]*/!$acc / :b s/[[:space:]]+!\$acc[[:space:]]*/ /g tb ' "$file" > "$TMP_FILE" && mv "$TMP_FILE" "$file" sed -E \ -e '/^\s*!/s/.*//' \ -e '/^[cC*dD]/s/.*//' \ -e '/^[ \t]*[cC*dD]/s/.*//' \ -e 's/([^"'\'']*("[^"]*"[^"'\'']*|'\''[^'\'']*'\''[^"'\'']*)*[^"'\'']*)[!].*$/\1/' \ - "$file" > "$TMP_FILE" - + "$file" > "$TMP_FILE" && mv "$TMP_FILE" "$file" # Check if file was actually modified before replacing if cmp -s "$file" "$TMP_FILE"; then echo -e "No changes needed for $file" From 9605a29132d41486c4c91c4e2b0e13706b478756 Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Mon, 16 Jun 2025 19:25:53 -0400 Subject: [PATCH 28/48] Update pmd.yml --- .github/workflows/pmd.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 9994521d43..a8c5a1007b 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -56,8 +56,7 @@ jobs: # 2. Remove end-of-line comments (anything after '!' that isn't in a string) # 3. Preserve strings containing '!' characters TMP_FILE=$(mktemp) - sed -E ' :a /[[:space:]]*&[[:space:]]*$/ { N; s/[[:space:]]*&[[:space:]]*\n[[:space:]]*/ /; ba } s/^[[:space:]]*!\$acc[[:space:]]*/!$acc / :b s/[[:space:]]+!\$acc[[:space:]]*/ /g tb ' "$file" > "$TMP_FILE" && mv "$TMP_FILE" "$file" - + sed -E ' :a /[[:space:]]*&[[:space:]]*$/ { N; s/[[:space:]]*&[[:space:]]*\n[[:space:]]*/ /; ba } s/^[[:space:]]*!\$acc[[:space:]]*/!$acc / :b s/[[:space:]]+!\$acc[[:space:]]*/ /g tb ' "$file" > "$TMP_FILE" && mv "$TMP_FILE" "$file" sed -E \ -e '/^\s*!/s/.*//' \ -e '/^[cC*dD]/s/.*//' \ From 3c01cfa8db4ba8de21af00f5ca73097951e8401e Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Mon, 16 Jun 2025 19:30:02 -0400 Subject: [PATCH 29/48] Update pmd.yml --- .github/workflows/pmd.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index a8c5a1007b..057e8014fe 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -55,8 +55,20 @@ jobs: # - Lines starting with 'c', 'C', '*', 'd', 'D' in column 1 (fixed form comments) # 2. Remove end-of-line comments (anything after '!' that isn't in a string) # 3. Preserve strings containing '!' characters - TMP_FILE=$(mktemp) - sed -E ' :a /[[:space:]]*&[[:space:]]*$/ { N; s/[[:space:]]*&[[:space:]]*\n[[:space:]]*/ /; ba } s/^[[:space:]]*!\$acc[[:space:]]*/!$acc / :b s/[[:space:]]+!\$acc[[:space:]]*/ /g tb ' "$file" > "$TMP_FILE" && mv "$TMP_FILE" "$file" + sed -E ' + :a # ① label for looping + /&$/ { # ② if the *current* line ends with “&” + N # read the *next* line into the pattern space + s/&[[:space:]]*\n[[:space:]]*&/ / # ③ delete the trailing “&”, + # the following newline, the + # leading “&” on the next line, + # and join them with one space + ba # ④ repeat until the next line no longer starts + # with “&” (handles runs of many “&” lines) + } + s/&//g # ⑤ finally strip any stray “&” left in the file + ' "$file" > "$TMP_FILE" && mv "$TMP_FILE" "$file" + sed -E \ -e '/^\s*!/s/.*//' \ -e '/^[cC*dD]/s/.*//' \ From d2fff04672c09f129d276a4cf3047c730c4f6c20 Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Mon, 16 Jun 2025 19:32:24 -0400 Subject: [PATCH 30/48] Update pmd.yml --- .github/workflows/pmd.yml | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 057e8014fe..50f995e47a 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -56,25 +56,21 @@ jobs: # 2. Remove end-of-line comments (anything after '!' that isn't in a string) # 3. Preserve strings containing '!' characters sed -E ' - :a # ① label for looping - /&$/ { # ② if the *current* line ends with “&” - N # read the *next* line into the pattern space - s/&[[:space:]]*\n[[:space:]]*&/ / # ③ delete the trailing “&”, - # the following newline, the - # leading “&” on the next line, - # and join them with one space - ba # ④ repeat until the next line no longer starts - # with “&” (handles runs of many “&” lines) + :a + /&$/ { + N + s/&[[:space:]]*\n[[:space:]]*&/ / + ba } - s/&//g # ⑤ finally strip any stray “&” left in the file - ' "$file" > "$TMP_FILE" && mv "$TMP_FILE" "$file" - + s/&//g + ' "$file" | \ sed -E \ -e '/^\s*!/s/.*//' \ -e '/^[cC*dD]/s/.*//' \ -e '/^[ \t]*[cC*dD]/s/.*//' \ -e 's/([^"'\'']*("[^"]*"[^"'\'']*|'\''[^'\'']*'\''[^"'\'']*)*[^"'\'']*)[!].*$/\1/' \ - "$file" > "$TMP_FILE" && mv "$TMP_FILE" "$file" + > "$TMP_FILE" + # Check if file was actually modified before replacing if cmp -s "$file" "$TMP_FILE"; then echo -e "No changes needed for $file" From 3bd04f3e553e091b000c7ce586215db93b7f733d Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Tue, 17 Jun 2025 15:40:17 -0400 Subject: [PATCH 31/48] Update pmd.yml --- .github/workflows/pmd.yml | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 50f995e47a..2a160f7d76 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -55,21 +55,27 @@ jobs: # - Lines starting with 'c', 'C', '*', 'd', 'D' in column 1 (fixed form comments) # 2. Remove end-of-line comments (anything after '!' that isn't in a string) # 3. Preserve strings containing '!' characters - sed -E ' - :a - /&$/ { - N - s/&[[:space:]]*\n[[:space:]]*&/ / - ba - } - s/&//g - ' "$file" | \ - sed -E \ - -e '/^\s*!/s/.*//' \ - -e '/^[cC*dD]/s/.*//' \ - -e '/^[ \t]*[cC*dD]/s/.*//' \ - -e 's/([^"'\'']*("[^"]*"[^"'\'']*|'\''[^'\'']*'\''[^"'\'']*)*[^"'\'']*)[!].*$/\1/' \ - > "$TMP_FILE" +                  sed -E ' +                    # First pass: Remove comments +                    # Remove lines that are entirely comments +                    /^\s*!/s/.*// +                    /^[cC*dD]/s/.*// +                    /^[ \t]*[cC*dD]/s/.*// +                    # Remove end-of-line comments, preserving strings +                    s/([^"'\'']*("[^"]*"[^"'\'']*|'\''[^'\'']*'\''[^"'\'']*)*[^"'\'']*)[!].*$/\1/ + +                    # Second pass: Handle line continuations +                    :a +                    # If a line ends with '&' (possibly with trailing whitespace), read the next line +                    /&\s*$/ { +                          N +                          # Replace '&' at the end of the first line, newline, and potential leading '&' on the second line with a single space +                          s/&\s*\n\s*&/\ / +                          ba # Loop back to 'a' to handle multiple continuations +                    } +                    # If a line ends with '&' but is the last line or next line doesn't start with '&', remove the trailing '&' +                    s/&\s*$// +                  ' "$file" > "$TMP_FILE" # Check if file was actually modified before replacing if cmp -s "$file" "$TMP_FILE"; then From d4b77fb21a65ca2746204a68af0faa0bb7896cdf Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Tue, 17 Jun 2025 16:13:02 -0400 Subject: [PATCH 32/48] Update pmd.yml --- .github/workflows/pmd.yml | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 2a160f7d76..50f995e47a 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -55,27 +55,21 @@ jobs: # - Lines starting with 'c', 'C', '*', 'd', 'D' in column 1 (fixed form comments) # 2. Remove end-of-line comments (anything after '!' that isn't in a string) # 3. Preserve strings containing '!' characters -                  sed -E ' -                    # First pass: Remove comments -                    # Remove lines that are entirely comments -                    /^\s*!/s/.*// -                    /^[cC*dD]/s/.*// -                    /^[ \t]*[cC*dD]/s/.*// -                    # Remove end-of-line comments, preserving strings -                    s/([^"'\'']*("[^"]*"[^"'\'']*|'\''[^'\'']*'\''[^"'\'']*)*[^"'\'']*)[!].*$/\1/ - -                    # Second pass: Handle line continuations -                    :a -                    # If a line ends with '&' (possibly with trailing whitespace), read the next line -                    /&\s*$/ { -                          N -                          # Replace '&' at the end of the first line, newline, and potential leading '&' on the second line with a single space -                          s/&\s*\n\s*&/\ / -                          ba # Loop back to 'a' to handle multiple continuations -                    } -                    # If a line ends with '&' but is the last line or next line doesn't start with '&', remove the trailing '&' -                    s/&\s*$// -                  ' "$file" > "$TMP_FILE" + sed -E ' + :a + /&$/ { + N + s/&[[:space:]]*\n[[:space:]]*&/ / + ba + } + s/&//g + ' "$file" | \ + sed -E \ + -e '/^\s*!/s/.*//' \ + -e '/^[cC*dD]/s/.*//' \ + -e '/^[ \t]*[cC*dD]/s/.*//' \ + -e 's/([^"'\'']*("[^"]*"[^"'\'']*|'\''[^'\'']*'\''[^"'\'']*)*[^"'\'']*)[!].*$/\1/' \ + > "$TMP_FILE" # Check if file was actually modified before replacing if cmp -s "$file" "$TMP_FILE"; then From 502ab2cf52094c8871b3a183a4da61a9a87502d3 Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Tue, 17 Jun 2025 16:29:16 -0400 Subject: [PATCH 33/48] Update pmd.yml --- .github/workflows/pmd.yml | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 50f995e47a..a157e72344 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -55,22 +55,26 @@ jobs: # - Lines starting with 'c', 'C', '*', 'd', 'D' in column 1 (fixed form comments) # 2. Remove end-of-line comments (anything after '!' that isn't in a string) # 3. Preserve strings containing '!' characters - sed -E ' - :a - /&$/ { - N - s/&[[:space:]]*\n[[:space:]]*&/ / - ba - } - s/&//g - ' "$file" | \ sed -E \ -e '/^\s*!/s/.*//' \ -e '/^[cC*dD]/s/.*//' \ -e '/^[ \t]*[cC*dD]/s/.*//' \ -e 's/([^"'\'']*("[^"]*"[^"'\'']*|'\''[^'\'']*'\''[^"'\'']*)*[^"'\'']*)[!].*$/\1/' \ - > "$TMP_FILE" - + "$file" | \ + sed -E ' + :a + /\s*(\S+)\s*\n\s*([+*/=()-])/ { + N + s/([+*/=()-])\s*\n\s*([+*/=()-])/\1\2/ + s/\s*\n\s*/ / + ba + } + /\s*\n\s*\+/ { + N + s/\s*\n\s*\+/ +/ + ba + } + ' > "$TMP_FILE" # Check if file was actually modified before replacing if cmp -s "$file" "$TMP_FILE"; then echo -e "No changes needed for $file" From 31b873c8876d51bde82404afee2d6601ace340de Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Tue, 17 Jun 2025 16:45:30 -0400 Subject: [PATCH 34/48] Update pmd.yml --- .github/workflows/pmd.yml | 43 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index a157e72344..90f3503eba 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -55,26 +55,31 @@ jobs: # - Lines starting with 'c', 'C', '*', 'd', 'D' in column 1 (fixed form comments) # 2. Remove end-of-line comments (anything after '!' that isn't in a string) # 3. Preserve strings containing '!' characters - sed -E \ - -e '/^\s*!/s/.*//' \ - -e '/^[cC*dD]/s/.*//' \ - -e '/^[ \t]*[cC*dD]/s/.*//' \ - -e 's/([^"'\'']*("[^"]*"[^"'\'']*|'\''[^'\'']*'\''[^"'\'']*)*[^"'\'']*)[!].*$/\1/' \ - "$file" | \ sed -E ' - :a - /\s*(\S+)\s*\n\s*([+*/=()-])/ { - N - s/([+*/=()-])\s*\n\s*([+*/=()-])/\1\2/ - s/\s*\n\s*/ / - ba - } - /\s*\n\s*\+/ { - N - s/\s*\n\s*\+/ +/ - ba - } - ' > "$TMP_FILE" + # Label for loop to handle multi-line continuations + :a + # If line ends with '&' (continuation character), append next line + /&$/ { + N + # Replace '&' followed by newline, optional spaces, and another '&' with a single space + s/&[[:space:]]*\n[[:space:]]*&/ / + ba # Go back to label 'a' to process more continuations if present + } + # After handling all continuations, remove any remaining '&' characters + s/&//g + # Remove lines that are entirely comments: + # - Lines starting with '!' (free form) + /^\s*!/s/.*// + # - Lines starting with 'c', 'C', '*', 'd', 'D' (fixed form, column 1) + /^[cC*dD]/s/.*// + # - Lines starting with space/tab and then 'c', 'C', '*', 'd', 'D' (fixed form with leading space) + /^[ \t]*[cC*dD]/s/.*// + + # Remove end-of-line comments, preserving '!' inside strings. + # This pattern looks for '!' not preceded by an odd number of quotes. + # It captures everything before the '!' as group 1 and replaces the whole line with group 1. + s/([^"'\''\\]*("[^"]*")?('\''[^'\'']*'\''?)?[^"'\''\\]*)[!].*$/\1/ + ' "$file" > "$TMP_FILE" # Check if file was actually modified before replacing if cmp -s "$file" "$TMP_FILE"; then echo -e "No changes needed for $file" From 8cf02c0789b707effb09f935d39d2c0861903866 Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Tue, 17 Jun 2025 16:47:18 -0400 Subject: [PATCH 35/48] Update pmd.yml --- .github/workflows/pmd.yml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 90f3503eba..55b6a1b6fc 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -56,28 +56,16 @@ jobs: # 2. Remove end-of-line comments (anything after '!' that isn't in a string) # 3. Preserve strings containing '!' characters sed -E ' - # Label for loop to handle multi-line continuations :a - # If line ends with '&' (continuation character), append next line /&$/ { N - # Replace '&' followed by newline, optional spaces, and another '&' with a single space s/&[[:space:]]*\n[[:space:]]*&/ / - ba # Go back to label 'a' to process more continuations if present + ba } - # After handling all continuations, remove any remaining '&' characters s/&//g - # Remove lines that are entirely comments: - # - Lines starting with '!' (free form) /^\s*!/s/.*// - # - Lines starting with 'c', 'C', '*', 'd', 'D' (fixed form, column 1) /^[cC*dD]/s/.*// - # - Lines starting with space/tab and then 'c', 'C', '*', 'd', 'D' (fixed form with leading space) /^[ \t]*[cC*dD]/s/.*// - - # Remove end-of-line comments, preserving '!' inside strings. - # This pattern looks for '!' not preceded by an odd number of quotes. - # It captures everything before the '!' as group 1 and replaces the whole line with group 1. s/([^"'\''\\]*("[^"]*")?('\''[^'\'']*'\''?)?[^"'\''\\]*)[!].*$/\1/ ' "$file" > "$TMP_FILE" # Check if file was actually modified before replacing From 10082468cc5e27f0deab38e85fb5403e7764fd16 Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Tue, 17 Jun 2025 16:53:04 -0400 Subject: [PATCH 36/48] Update pmd.yml --- .github/workflows/pmd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 55b6a1b6fc..472a69754a 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -54,8 +54,8 @@ jobs: # - Lines starting with '!' (free form comments) # - Lines starting with 'c', 'C', '*', 'd', 'D' in column 1 (fixed form comments) # 2. Remove end-of-line comments (anything after '!' that isn't in a string) - # 3. Preserve strings containing '!' characters - sed -E ' + # 3. Preserve strings containing '!' characters + sed -E ' :a /&$/ { N From cd8f90823112211c403d62fabfe1d4baa1ef78ed Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Tue, 17 Jun 2025 16:56:52 -0400 Subject: [PATCH 37/48] Update pmd.yml --- .github/workflows/pmd.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 472a69754a..245c1ffb0a 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -55,20 +55,25 @@ jobs: # - Lines starting with 'c', 'C', '*', 'd', 'D' in column 1 (fixed form comments) # 2. Remove end-of-line comments (anything after '!' that isn't in a string) # 3. Preserve strings containing '!' characters - sed -E ' + sed -E ' :a /&$/ { N s/&[[:space:]]*\n[[:space:]]*&/ / ba } + /^[[:space:]]{5}[^[:space:]]/ { + N + s/\n([[:space:]]{5}[^[:space:]])/\1/ + ba + } s/&//g /^\s*!/s/.*// /^[cC*dD]/s/.*// /^[ \t]*[cC*dD]/s/.*// s/([^"'\''\\]*("[^"]*")?('\''[^'\'']*'\''?)?[^"'\''\\]*)[!].*$/\1/ ' "$file" > "$TMP_FILE" - # Check if file was actually modified before replacing + if cmp -s "$file" "$TMP_FILE"; then echo -e "No changes needed for $file" rm "$TMP_FILE" From ae4cbf5db1b2d27425d5e8d786f4516f98417e48 Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Tue, 17 Jun 2025 18:00:11 -0400 Subject: [PATCH 38/48] more cleanup --- .github/workflows/pmd.yml | 48 +++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 245c1ffb0a..cd23acf85c 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -56,24 +56,44 @@ jobs: # 2. Remove end-of-line comments (anything after '!' that isn't in a string) # 3. Preserve strings containing '!' characters sed -E ' - :a - /&$/ { - N - s/&[[:space:]]*\n[[:space:]]*&/ / - ba + # First handle & continuation style (modern Fortran) + :ampersand_loop + /&[[:space:]]*$/ { + N + s/&[[:space:]]*\n[[:space:]]*(&)?/ /g + tampersand_loop } - /^[[:space:]]{5}[^[:space:]]/ { - N - s/\n([[:space:]]{5}[^[:space:]])/\1/ - ba + + # Handle fixed-form continuation (column 6 indicator) + :fixed_form_loop + /^[[:space:]]{0,5}[^[:space:]!&]/ { + N + s/\n[[:space:]]{5}[^[:space:]]/ /g + tfixed_form_loop } + + # Remove any remaining continuation markers s/&//g - /^\s*!/s/.*// - /^[cC*dD]/s/.*// - /^[ \t]*[cC*dD]/s/.*// + + # Normalize spacing - replace multiple spaces with single space + s/[[:space:]]{2,}/ /g + + # Remove spaces around mathematical operators + s/[[:space:]]*\*[[:space:]]*/*/g + s/[[:space:]]*\+[[:space:]]*/+/g + s/[[:space:]]*-[[:space:]]*/-/g + s/[[:space:]]*\/[[:space:]]*/\//g + s/[[:space:]]*\*\*[[:space:]]*/\*\*/g + + # Remove full-line comments + /^\s*!/d + /^[cC*dD]/d + /^[ \t]*[cC*dD]/d + + # Remove end-of-line comments, preserving quoted strings s/([^"'\''\\]*("[^"]*")?('\''[^'\'']*'\''?)?[^"'\''\\]*)[!].*$/\1/ ' "$file" > "$TMP_FILE" - + if cmp -s "$file" "$TMP_FILE"; then echo -e "No changes needed for $file" rm "$TMP_FILE" @@ -87,6 +107,6 @@ jobs: "${PMD_HOME}/bin/pmd" cpd \ --dir src \ --language fortran \ - --minimum-tokens=20 \ + --minimum-tokens=50 \ --no-fail-on-violation \ --no-fail-on-error From 27c9932169dfb1bf5e8e00f21bf418a080b215e4 Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Tue, 17 Jun 2025 18:00:29 -0400 Subject: [PATCH 39/48] tokens=20 --- .github/workflows/pmd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index cd23acf85c..0b1650313a 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -107,6 +107,6 @@ jobs: "${PMD_HOME}/bin/pmd" cpd \ --dir src \ --language fortran \ - --minimum-tokens=50 \ + --minimum-tokens=20 \ --no-fail-on-violation \ --no-fail-on-error From 3c0682d91a17f79620b6d701f68e73b6f5cf39e6 Mon Sep 17 00:00:00 2001 From: malmahrouqi3 Date: Tue, 17 Jun 2025 18:41:42 -0400 Subject: [PATCH 40/48] strip out majority of spaces --- .github/workflows/pmd.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 0b1650313a..5ef99ad7d3 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -85,6 +85,27 @@ jobs: s/[[:space:]]*\/[[:space:]]*/\//g s/[[:space:]]*\*\*[[:space:]]*/\*\*/g + # Remove spaces in common Fortran constructs (array indexing, function calls) + s/\([[:space:]]*([^,)[:space:]]+)[[:space:]]*,/(\1,/g # First argument + s/,[[:space:]]*([^,)[:space:]]+)[[:space:]]*,/,\1,/g # Middle arguments + s/,[[:space:]]*([^,)[:space:]]+)[[:space:]]*\)/,\1)/g # Last argument + s/\([[:space:]]*([^,)[:space:]]+)[[:space:]]*\)/(\1)/g # Single argument + + # Remove spaces around brackets and parentheses + s/\[[[:space:]]*//g + s/\[[[:space:]]*/=[[:space:]]*/>/g + s/[[:space:]]*<[[:space:]]*/[[:space:]]*/>/g + s/[[:space:]]*==[[:space:]]*/==/g + # Remove full-line comments /^\s*!/d /^[cC*dD]/d From d5f882e6bfc3173c73b883bdf6f195e3ed681057 Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Wed, 18 Jun 2025 10:43:56 -0400 Subject: [PATCH 41/48] Update pmd.yml --- .github/workflows/pmd.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 5ef99ad7d3..28e9257de4 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -110,7 +110,9 @@ jobs: /^\s*!/d /^[cC*dD]/d /^[ \t]*[cC*dD]/d - + /^[Cc*]/d + /^[[:blank:]]*!/ + # Remove end-of-line comments, preserving quoted strings s/([^"'\''\\]*("[^"]*")?('\''[^'\'']*'\''?)?[^"'\''\\]*)[!].*$/\1/ ' "$file" > "$TMP_FILE" From 0806ba9f6afedd5830f065b0fdaeecd8bb8a9318 Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Wed, 18 Jun 2025 10:49:45 -0400 Subject: [PATCH 42/48] Update pmd.yml --- .github/workflows/pmd.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 28e9257de4..8129b8c0ea 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -107,12 +107,7 @@ jobs: s/[[:space:]]*==[[:space:]]*/==/g # Remove full-line comments - /^\s*!/d - /^[cC*dD]/d - /^[ \t]*[cC*dD]/d - /^[Cc*]/d - /^[[:blank:]]*!/ - + /^[[:space:]]*[!cC*dD]/d # Remove end-of-line comments, preserving quoted strings s/([^"'\''\\]*("[^"]*")?('\''[^'\'']*'\''?)?[^"'\''\\]*)[!].*$/\1/ ' "$file" > "$TMP_FILE" From 972ae380cc22d4eabf502d97dedb37df994c11fb Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Wed, 18 Jun 2025 10:59:18 -0400 Subject: [PATCH 43/48] Update pmd.yml --- .github/workflows/pmd.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 8129b8c0ea..a0ff441bbd 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -106,8 +106,12 @@ jobs: s/[[:space:]]*>[[:space:]]*/>/g s/[[:space:]]*==[[:space:]]*/==/g - # Remove full-line comments - /^[[:space:]]*[!cC*dD]/d + # Remove full-line comments + /^\s*!/d + /^[cC*dD]/d + /^[ \t]*[cC*dD]/d + /^[[:space:]]*$/d + # Remove end-of-line comments, preserving quoted strings s/([^"'\''\\]*("[^"]*")?('\''[^'\'']*'\''?)?[^"'\''\\]*)[!].*$/\1/ ' "$file" > "$TMP_FILE" From c20dacd1497a3501cc7a0b411075bb190cf837fa Mon Sep 17 00:00:00 2001 From: mohdsaid497566 Date: Thu, 19 Jun 2025 18:44:32 -0400 Subject: [PATCH 44/48] removed insignificant echo's --- .github/workflows/pmd.yml | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index a0ff441bbd..21fef0ba5f 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -106,24 +106,15 @@ jobs: s/[[:space:]]*>[[:space:]]*/>/g s/[[:space:]]*==[[:space:]]*/==/g - # Remove full-line comments - /^\s*!/d - /^[cC*dD]/d - /^[ \t]*[cC*dD]/d - /^[[:space:]]*$/d + # Remove full-line comments + /^\s*!/d + /^[cC*dD]/d + /^[ \t]*[cC*dD]/d + /^[[:space:]]*$/d # Remove end-of-line comments, preserving quoted strings s/([^"'\''\\]*("[^"]*")?('\''[^'\'']*'\''?)?[^"'\''\\]*)[!].*$/\1/ ' "$file" > "$TMP_FILE" - - if cmp -s "$file" "$TMP_FILE"; then - echo -e "No changes needed for $file" - rm "$TMP_FILE" - else - # Overwrite the original file with the processed content - mv "$TMP_FILE" "$file" - echo -e "Successfully processed $file" - fi done "${PMD_HOME}/bin/pmd" cpd \ From 48359893de29a9555b0709fac1f5b0e0381d08d9 Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Thu, 19 Jun 2025 18:52:11 -0400 Subject: [PATCH 45/48] Update pmd.yml From ce046e288ac6184506f6fbfe6440551190c6dab1 Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Thu, 19 Jun 2025 18:53:58 -0400 Subject: [PATCH 46/48] Update pmd.yml From dbd4489cc39a2099cbb4fd5d35188af54d70ac8a Mon Sep 17 00:00:00 2001 From: "Mohammed S. Al-Mahrouqi" <145478595+Malmahrouqi3@users.noreply.github.com> Date: Thu, 19 Jun 2025 18:56:44 -0400 Subject: [PATCH 47/48] Update pmd.yml --- .github/workflows/pmd.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 21fef0ba5f..59e7e8c304 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -115,6 +115,13 @@ jobs: # Remove end-of-line comments, preserving quoted strings s/([^"'\''\\]*("[^"]*")?('\''[^'\'']*'\''?)?[^"'\''\\]*)[!].*$/\1/ ' "$file" > "$TMP_FILE" + + if cmp -s "$file" "$TMP_FILE"; then + rm "$TMP_FILE" + else + # Overwrite the original file with the processed content + mv "$TMP_FILE" "$file" + fi done "${PMD_HOME}/bin/pmd" cpd \ From 9fc63716a17e083f2cc1a63e8e5fc728c24a28a5 Mon Sep 17 00:00:00 2001 From: Spencer Bryngelson Date: Thu, 19 Jun 2025 19:11:24 -0400 Subject: [PATCH 48/48] Update pmd.yml --- .github/workflows/pmd.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 59e7e8c304..24361e777c 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -37,7 +37,6 @@ jobs: find "$SOURCE_DIR" -type f \( -name "*.f" -o -name "*.f90" -o -name "*.for" -o -name "*.fpp" -o -name "*.F" -o -name "*.F90" \) -print0 | while IFS= read -r -d $'\0' file; do processed=$((processed + 1)) - echo -e "[$processed/$total_files] Processing ${file}..." # Create a temporary file with same permissions as original TMP_FILE=$(mktemp)