-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_metadata_plugin.sh
executable file
·94 lines (78 loc) · 2.5 KB
/
test_metadata_plugin.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
set -e
# If this script is planned to run on minimal or server-focused Linux distributions,
# we may need to install the `tree` package manually using the system's package manager,
# e.g., `sudo apt install tree` on Ubuntu.
errors=()
# Helper function to check metadata file format
check_metadata_file_format() {
metadata_file="$1"
separator="$2"
package_line="package=.*"
file_line="fileName=.*"
loc_line="linesOfCode=.*"
if [ "${separator}" != "\n" ]; then
package_line="${package_line}${separator}"
file_line="${file_line}${separator}"
fi
if ! grep -q "${package_line}" "${metadata_file}"; then
errors+=("${metadata_file} does not contain correct package information")
fi
if ! grep -q "${file_line}" "${metadata_file}"; then
errors+=("${metadata_file} does not contain correct file information")
fi
if ! grep -q "${loc_line}" "${metadata_file}"; then
errors+=("${metadata_file} does not contain correct linesOfCode information")
fi
}
# Cleanup function
cleanup() {
echo "Cleaning up..."
./gradlew clean
}
# Check for JAVA_HOME
if [ -z "$JAVA_HOME" ]; then
echo "JAVA_HOME is not set. Please set the JAVA_HOME env var and try again."
exit 1
fi
# Initial cleanup
cleanup
# Run the tasks and validate metadata
for separator in "\n" ";" ","
do
echo "Running extractJavaMetadata with separator=${separator} ..."
./gradlew extractJavaMetadata -Pseparator="${separator}"
echo "Checking metadata format..."
for project_dir in $(find . -maxdepth 1 -type d -name 'project*' | grep -v "project10")
do
for metadata_file in $(find "${project_dir}/build/metadata" -name "*.metadata")
do
check_metadata_file_format "${metadata_file}" "${separator}"
done
done
# Cleanup after checking metadata
cleanup
done
# Build the projects and check JAR files
echo "Building projects..."
./gradlew build
echo "Checking JAR files..."
for project_dir in $(find . -maxdepth 1 -type d -name 'project*' | grep -v "project10")
do
jar_file="${project_dir}/build/libs/$(basename ${project_dir})-1.0.jar"
if unzip -l "${jar_file}" | grep -q ".metadata"; then
echo "${jar_file} contains it's metadata"
else
errors+=("Metadata not found in ${jar_file}")
fi
done
# Check if errors array is not empty
if [ ${#errors[@]} -ne 0 ]; then
echo "Errors found during testing:"
for error in "${errors[@]}"
do
echo " - ${error}"
done
exit 1
fi
echo "Hurray! All tests passed!"