Skip to content

Commit

Permalink
Merge branch 'backport-4135' into release-1.7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Coduz committed Nov 19, 2024
2 parents 8989164 + e42d601 commit 21b67d2
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build-tools/src/main/resources/checkstyle/kapua.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@

<module name="RegexpHeader">
<property name="header"
value="^/\*{79}$\n^ \* Copyright \(c\) (|\d{4}, )2022 (.*) and others\.?$\n^ \*$\n^ \* This program and the accompanying materials are made$\n^ \* available under the terms of the Eclipse Public License 2.0$\n^ \* which is available at https://www.eclipse.org/legal/epl-2.0/$\n^ \*$\n^ \* SPDX-License-Identifier: EPL-2.0$\n^ \*$\n^ \* Contributors:$\n^ \* (.*)(| - .*)$\n^ \*{79}/\n^package" />
value="^/\*{79}$\n^ \* Copyright \(c\) (|\d{4}, )\d{4} (.*) and others\.?$\n^ \*$\n^ \* This program and the accompanying materials are made$\n^ \* available under the terms of the Eclipse Public License 2.0$\n^ \* which is available at https://www.eclipse.org/legal/epl-2.0/$\n^ \*$\n^ \* SPDX-License-Identifier: EPL-2.0$\n^ \*$\n^ \* Contributors:$\n^ \* (.*)(| - .*)$\n^ \*{79}/\n^package" />
<property name="charset" value="UTF-8" />
<property name="multiLines" value="11" />
<property name="fileExtensions" value="java" />
</module>

<module name="RegexpHeader">
<property name="header"
value="^&lt;\?xml.*&gt;$\n^&lt;!--$\n^ Copyright \(c\) (|\d{4}, )2022 (.*) and others\.?$\n^$\n^ This program and the accompanying materials are made$\n^ available under the terms of the Eclipse Public License 2\.0$\n^ which is available at https\:\/\/www.eclipse.org/legal/epl-2.0/$\n^$\n^ SPDX-License-Identifier: EPL-2.0$\n^$\n^ Contributors\:$\n^ (.*)(| - .*)$\n^ ?--&gt;$" />
value="^&lt;\?xml.*&gt;$\n^&lt;!--$\n^ Copyright \(c\) (|\d{4}, )\d{4} (.*) and others\.?$\n^$\n^ This program and the accompanying materials are made$\n^ available under the terms of the Eclipse Public License 2\.0$\n^ which is available at https\:\/\/www.eclipse.org/legal/epl-2.0/$\n^$\n^ SPDX-License-Identifier: EPL-2.0$\n^$\n^ Contributors\:$\n^ (.*)(| - .*)$\n^ ?--&gt;$" />
<property name="charset" value="UTF-8" />
<property name="multiLines" value="12" />
<property name="fileExtensions" value="xml" />
Expand Down
60 changes: 60 additions & 0 deletions dev-tools/header/update_year_header.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

# Check for the correct number of arguments
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <path_to_directory>"
exit 1
fi

# Set variables from arguments
root="$1"
currentYear=$(date +%Y)

# Initialize a counter for changed files
changedFiles=0

# Loop through all .java files in the specified directory recursively
for file in $(find "$root" -type f -name "*.java"); do
fileChanged=false

# Create a temporary file for modified content
tempFile="${file}.tmp"

# Capture the first line and the second line
line1=$(head -n 1 "$file") # First line
line2=$(head -2 "$file" | tail -n 1) # Second line

{
# Check for the second header pattern with two years (e.g., "2016, 2022")
if [[ "$line2" =~ Copyright\ \(c\)\ ([0-9]{4}),\ ([0-9]{4})\ .+\ and\ others ]]; then
# Replace the last year with the current year
line2=$(echo "$line2" | sed -E 's/([0-9]{4}), ([0-9]{4})/\1, '"$currentYear"'/')
fileChanged=true
# Check for the first header pattern with a single year (e.g., "2016")
elif [[ "$line2" =~ Copyright\ \(c\)\ ([0-9]{4})\ .+\ and\ others ]]; then
# Append the current year to the existing year
line2=$(echo "$line2" | sed -E "s/([0-9]{4})/\1, $currentYear/")
fileChanged=true
fi

# Write the first line (unchanged) to the temporary file
echo "$line1" > "$tempFile"
# Write the modified second line
echo "$line2" >> "$tempFile"

# Write the rest of the file unchanged, starting from the third line
tail -n +3 "$file" >> "$tempFile"
}

# If the file was changed, replace the original file
if [ "$fileChanged" = true ]; then
mv "$tempFile" "$file"
echo "File changed: $file"
((changedFiles++))
else
rm "$tempFile"
fi
done

# Print the total number of changed files
echo "Total files changed: $changedFiles"

0 comments on commit 21b67d2

Please sign in to comment.