Skip to content

Commit fed4332

Browse files
committed
SQ workflow
1 parent 581c9ca commit fed4332

File tree

2 files changed

+107
-28
lines changed

2 files changed

+107
-28
lines changed

.github/workflows/sonarqube.yml

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,44 +56,72 @@ jobs:
5656
# Create the target directory
5757
mkdir -p build/intermediates/runtime_library_classes_dir/debug
5858
59-
# Find all directories containing class files
60-
CLASS_DIRS=$(find build -name "*.class" -type f -exec dirname {} \; | sort -u)
59+
# Find all directories containing class files with better patterns
60+
CLASS_DIRS=$(find build -name "*.class" -type f -exec dirname {} \; | sort -u | grep -E "(javac|kotlin-classes|runtime_library)" | head -10)
6161
6262
if [ -z "$CLASS_DIRS" ]; then
6363
echo "WARNING: No class files found in the build directory!"
64+
echo "Searching in all build subdirectories..."
65+
find build -name "*.class" -type f | head -20
6466
else
6567
echo "Found class files in the following directories:"
6668
echo "$CLASS_DIRS"
6769
68-
# Copy classes from the first directory with classes
69-
FIRST_CLASS_DIR=$(echo "$CLASS_DIRS" | head -1)
70-
echo "Copying classes from $FIRST_CLASS_DIR to build/intermediates/runtime_library_classes_dir/debug"
71-
cp -r $FIRST_CLASS_DIR/* build/intermediates/runtime_library_classes_dir/debug/ || echo "Failed to copy from $FIRST_CLASS_DIR"
70+
# Copy classes from all relevant directories, not just the first one
71+
for CLASS_DIR in $CLASS_DIRS; do
72+
if [ -d "$CLASS_DIR" ] && [ "$(find "$CLASS_DIR" -name "*.class" | wc -l)" -gt 0 ]; then
73+
echo "Copying classes from $CLASS_DIR"
74+
cp -r "$CLASS_DIR"/* build/intermediates/runtime_library_classes_dir/debug/ 2>/dev/null || echo "Failed to copy from $CLASS_DIR"
75+
fi
76+
done
7277
7378
# Verify the target directory now has class files
7479
CLASS_COUNT=$(find build/intermediates/runtime_library_classes_dir/debug -name "*.class" | wc -l)
7580
echo "Target directory now contains $CLASS_COUNT class files"
7681
fi
7782
78-
# Update sonar-project.properties with all found class directories as a fallback
79-
echo "\n# Additional binary paths found during build" >> sonar-project.properties
80-
echo "sonar.java.binaries=build/intermediates/runtime_library_classes_dir/debug,$CLASS_DIRS" >> sonar-project.properties
83+
# Update sonar-project.properties with all found class directories
84+
echo "" >> sonar-project.properties
85+
echo "# Additional binary paths found during build" >> sonar-project.properties
86+
if [ -n "$CLASS_DIRS" ]; then
87+
# Convert newlines to commas for sonar.java.binaries
88+
BINARY_PATHS=$(echo "$CLASS_DIRS" | tr '\n' ',' | sed 's/,$//')
89+
echo "sonar.java.binaries=build/intermediates/runtime_library_classes_dir/debug,$BINARY_PATHS" >> sonar-project.properties
90+
else
91+
echo "sonar.java.binaries=build/intermediates/runtime_library_classes_dir/debug" >> sonar-project.properties
92+
fi
8193
8294
echo "Checking for JaCoCo report files..."
83-
find build -name "*.xml" | grep jacoco || echo "No XML files found"
84-
find build -name "*.exec" | grep jacoco || echo "No exec files found"
95+
find build -name "*.xml" | grep jacoco || echo "No JaCoCo XML files found"
96+
find build -name "*.exec" | grep jacoco || echo "No JaCoCo exec files found"
97+
8598
echo "Contents of JaCoCo report directory:"
8699
ls -la build/reports/jacoco/jacocoTestReport/ || echo "Directory not found"
87100
88-
echo "\nChecking test execution results:"
89-
find build -name "TEST-*.xml" | xargs cat | grep -E 'tests|failures|errors|skipped' || echo "No test result files found"
101+
echo ""
102+
echo "Checking test execution results:"
103+
TEST_RESULT_FILES=$(find build -name "TEST-*.xml" 2>/dev/null)
104+
if [ -n "$TEST_RESULT_FILES" ]; then
105+
echo "Found test result files:"
106+
echo "$TEST_RESULT_FILES"
107+
# Count total tests, failures, errors
108+
TOTAL_TESTS=$(cat $TEST_RESULT_FILES | grep -o 'tests="[0-9]*"' | cut -d'"' -f2 | awk '{sum+=$1} END {print sum}')
109+
TOTAL_FAILURES=$(cat $TEST_RESULT_FILES | grep -o 'failures="[0-9]*"' | cut -d'"' -f2 | awk '{sum+=$1} END {print sum}')
110+
TOTAL_ERRORS=$(cat $TEST_RESULT_FILES | grep -o 'errors="[0-9]*"' | cut -d'"' -f2 | awk '{sum+=$1} END {print sum}')
111+
echo "Test summary: $TOTAL_TESTS tests, $TOTAL_FAILURES failures, $TOTAL_ERRORS errors"
112+
else
113+
echo "No test result files found"
114+
fi
90115
91-
echo "\nChecking JaCoCo report content:"
116+
echo ""
117+
echo "Checking JaCoCo report content:"
92118
if [ -f build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml ]; then
93119
echo "Report file size: $(wc -c < build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml) bytes"
94120
echo "First 500 chars of report:"
95121
head -c 500 build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml
96-
echo "\n\nCounting coverage elements:"
122+
echo ""
123+
echo ""
124+
echo "Counting coverage elements:"
97125
grep -c "<package" build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml || echo "No packages found"
98126
grep -c "<class" build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml || echo "No classes found"
99127
grep -c "<method" build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml || echo "No methods found"
@@ -103,12 +131,18 @@ jobs:
103131
echo "JaCoCo report file not found"
104132
fi
105133
106-
echo "\nChecking binary directories specified in sonar-project.properties:"
134+
echo ""
135+
echo "Checking binary directories specified in sonar-project.properties:"
107136
echo "build/intermediates/runtime_library_classes_dir/debug:"
108137
ls -la build/intermediates/runtime_library_classes_dir/debug || echo "Directory not found"
109138
110-
echo "\nChecking all available class directories:"
111-
find build -path "*/build/*" -name "*.class" | head -n 5 || echo "No class files found"
139+
echo ""
140+
echo "Checking all available class directories:"
141+
find build -path "*/build/*" -name "*.class" | head -n 10 || echo "No class files found"
142+
143+
echo ""
144+
echo "Final sonar-project.properties content:"
145+
cat sonar-project.properties
112146
113147
- name: SonarCloud Scan
114148
uses: SonarSource/sonarqube-scan-action@v5

jacoco.gradle

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,79 @@ tasks.register('jacocoTestReport', JacocoReport) {
2828
}
2929

3030
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
31-
def debugTree = fileTree(dir: "${buildDir}/intermediates/javac/debug/classes", excludes: fileFilter)
3231

33-
// Make sure to include all source directories
34-
sourceDirectories.from = files(['src/main/java'])
32+
// Updated to handle multiple possible class directory locations
33+
def classDirectoriesFiles = []
3534

36-
// Include all class files except excluded ones
37-
classDirectories.from = files([debugTree])
35+
// Try multiple possible class directory locations for different AGP versions
36+
def possibleClassDirs = [
37+
"${buildDir}/intermediates/javac/debug/classes",
38+
"${buildDir}/intermediates/javac/debug/compileDebugJavaWithJavac/classes",
39+
"${buildDir}/intermediates/runtime_library_classes_dir/debug",
40+
"${buildDir}/tmp/kotlin-classes/debug"
41+
]
3842

39-
// Include execution data files
43+
possibleClassDirs.each { dirPath ->
44+
def classDir = fileTree(dir: dirPath, excludes: fileFilter)
45+
if (classDir.files.size() > 0) {
46+
classDirectoriesFiles.add(classDir)
47+
}
48+
}
49+
50+
// Include all source directories (Java and Kotlin)
51+
sourceDirectories.from = files([
52+
'src/main/java',
53+
'src/main/kotlin'
54+
])
55+
56+
// Include all found class files
57+
classDirectories.from = files(classDirectoriesFiles)
58+
59+
// Include execution data files from multiple possible locations
4060
executionData.from(fileTree(dir: "$buildDir", includes: [
4161
'jacoco/testDebugUnitTest.exec',
42-
'outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec'
62+
'outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec',
63+
'jacoco/*.exec',
64+
'outputs/**/**.exec'
4365
]))
4466

4567
outputs.upToDateWhen { false }
4668

4769
doFirst {
48-
// Log a warning if no execution data files exist
70+
// Enhanced logging for debugging
71+
logger.lifecycle("=== JaCoCo Report Generation ===")
72+
73+
// Log source directories
74+
logger.lifecycle("Source directories:")
75+
sourceDirectories.files.each { dir ->
76+
if (dir.exists()) {
77+
logger.lifecycle(" - Found: $dir")
78+
} else {
79+
logger.lifecycle(" - Missing: $dir")
80+
}
81+
}
82+
83+
// Log class directories
84+
logger.lifecycle("Class directories:")
85+
classDirectories.files.each { dir ->
86+
logger.lifecycle(" - $dir (${dir.exists() ? 'exists' : 'missing'})")
87+
}
88+
89+
// Log execution data files
4990
def execFiles = executionData.files
91+
logger.lifecycle("Execution data files:")
5092
if (execFiles.isEmpty() || !execFiles.any { it.exists() }) {
51-
logger.warn("JaCoCo will not generate coverage report because no execution data files were found")
93+
logger.warn(" - No execution data files found - coverage report will be empty")
5294
} else {
5395
execFiles.each { file ->
5496
if (file.exists()) {
55-
logger.lifecycle("Found JaCoCo execution data file: $file")
97+
logger.lifecycle(" - Found: $file (${file.length()} bytes)")
98+
} else {
99+
logger.lifecycle(" - Missing: $file")
56100
}
57101
}
58102
}
103+
logger.lifecycle("================================")
59104
}
60105
}
61106

0 commit comments

Comments
 (0)