Skip to content

Commit 5d5b96d

Browse files
committed
👷 Add Spotless Java linting to CI pipeline
Add automated Java code style checking using Spotless with: - Google Java Format (AOSP style) for Android-friendly formatting - New ci/java-lint/ Gradle project for linting - New 'spotless' job in GitHub Actions workflow - Excludes third-party code (org/kamranzafar/jtar/) Downstream CI jobs now depend on both flake8 and spotless checks.
1 parent 20aab57 commit 5d5b96d

File tree

4 files changed

+94
-5
lines changed

4 files changed

+94
-5
lines changed

.github/workflows/push.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,26 @@ jobs:
3030
pip install tox>=2.0
3131
tox -e pep8
3232
33+
spotless:
34+
name: Java Spotless check
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout python-for-android
38+
uses: actions/checkout@v5
39+
- name: Set up Java 17
40+
uses: actions/setup-java@v4
41+
with:
42+
distribution: 'temurin'
43+
java-version: '17'
44+
- name: Set up Gradle
45+
uses: gradle/actions/setup-gradle@v4
46+
- name: Run Spotless check
47+
working-directory: ci/java-lint
48+
run: gradle spotlessCheck
49+
3350
test:
3451
name: Pytest [Python ${{ matrix.python-version }} | ${{ matrix.os }}]
35-
needs: flake8
52+
needs: [flake8, spotless]
3653
runs-on: ${{ matrix.os }}
3754
strategy:
3855
fail-fast: false
@@ -61,7 +78,7 @@ jobs:
6178

6279
ubuntu_build:
6380
name: Build test APP [ ${{ matrix.runs_on }} | ${{ matrix.bootstrap.name }} ]
64-
needs: [flake8]
81+
needs: [flake8, spotless]
6582
runs-on: ${{ matrix.runs_on }}
6683
strategy:
6784
matrix:
@@ -119,7 +136,7 @@ jobs:
119136

120137
macos_build:
121138
name: Build test APP [ ${{ matrix.runs_on }} | ${{ matrix.bootstrap.name }} ]
122-
needs: [flake8]
139+
needs: [flake8, spotless]
123140
runs-on: ${{ matrix.runs_on }}
124141
strategy:
125142
matrix:
@@ -193,7 +210,7 @@ jobs:
193210

194211
ubuntu_rebuild_updated_recipes:
195212
name: Test updated recipes for arch ${{ matrix.android_arch }} [ ubuntu-latest ]
196-
needs: [flake8]
213+
needs: [flake8, spotless]
197214
runs-on: ubuntu-latest
198215
# continue on error to see failures across all architectures
199216
continue-on-error: true
@@ -225,7 +242,7 @@ jobs:
225242
226243
macos_rebuild_updated_recipes:
227244
name: Test updated recipes for arch ${{ matrix.android_arch }} [ ${{ matrix.runs_on }} ]
228-
needs: [flake8]
245+
needs: [flake8, spotless]
229246
runs-on: ${{ matrix.runs_on }}
230247
# continue on error to see failures across all architectures
231248
continue-on-error: true

ci/java-lint/build.gradle

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Java Lint Configuration for python-for-android
2+
// This file configures Spotless to lint Java source files across all bootstraps
3+
4+
plugins {
5+
id 'java'
6+
id 'com.diffplug.spotless' version '6.25.0'
7+
}
8+
9+
// Repositories for plugin dependencies (e.g., google-java-format)
10+
repositories {
11+
mavenCentral()
12+
}
13+
14+
// Define the root directory for bootstrap Java sources
15+
def bootstrapsDir = "${rootProject.projectDir}/../../pythonforandroid/bootstraps"
16+
17+
// Collect all Java source directories from all bootstraps
18+
def javaSourceDirs = []
19+
file(bootstrapsDir).eachDir { bootstrapDir ->
20+
def srcDir = new File(bootstrapDir, 'build/src/main/java')
21+
if (srcDir.exists()) {
22+
javaSourceDirs.add(srcDir.absolutePath)
23+
}
24+
}
25+
26+
sourceSets {
27+
main {
28+
java {
29+
srcDirs = javaSourceDirs
30+
}
31+
}
32+
}
33+
34+
spotless {
35+
java {
36+
// Target all Java files from the source directories
37+
target fileTree(bootstrapsDir) {
38+
include '**/build/src/main/java/**/*.java'
39+
// Exclude third-party vendored code
40+
exclude '**/org/kamranzafar/jtar/**'
41+
}
42+
43+
// Use Google Java Format with AOSP style (Android-friendly, slightly relaxed)
44+
googleJavaFormat('1.19.2').aosp()
45+
46+
// Remove unused imports
47+
removeUnusedImports()
48+
49+
// Trim trailing whitespace
50+
trimTrailingWhitespace()
51+
52+
// Ensure files end with a newline
53+
endWithNewline()
54+
}
55+
}
56+
57+
// Disable compilation - we only want to lint, not build
58+
tasks.withType(JavaCompile).configureEach {
59+
enabled = false
60+
}

ci/java-lint/gradle.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Gradle properties for Java lint project
2+
# Disable daemon for CI environments
3+
org.gradle.daemon=false
4+
5+
# Use parallel execution where possible
6+
org.gradle.parallel=true
7+
8+
# Configure JVM memory
9+
org.gradle.jvmargs=-Xmx512m

ci/java-lint/settings.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Java Lint Project Settings
2+
// This project is used for linting Java source files in CI
3+
rootProject.name = 'p4a-java-lint'

0 commit comments

Comments
 (0)