diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml new file mode 100644 index 000000000..f2d5ac510 --- /dev/null +++ b/.github/workflows/checkstyle.yml @@ -0,0 +1,36 @@ +name: Checkstyle + +on: + pull_request: + branches: [ main ] + +permissions: + contents: read + +jobs: + pr_build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ ubuntu-latest ] + java-distribution: [ temurin ] + java-version: [ 25 ] + fail-fast: false + + steps: + - name: "Check out MM Data" + uses: actions/checkout@v6 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v5 + + - name: Checkstyle + run: ./gradlew checkstyleMain + + - name: Upload Test Logs on Failure + uses: actions/upload-artifact@v6 + if: failure() + with: + name: cd-failure-logs + path: ./megamek/megamek/build/reports/ diff --git a/build.gradle.kts b/build.gradle.kts index 67e85d9cd..13e3b1134 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,8 +5,47 @@ * Learn more about Gradle by exploring our Samples at https://docs.gradle.org/9.0.0/samples */ +plugins { + checkstyle + java +} + +sourceSets { + main { + java { + setSrcDirs(listOf("data")) + } + resources { + setSrcDirs(listOf("data")) + } + } +} + +tasks.withType(Checkstyle::class.java).configureEach { + minHeapSize = "200m" + maxHeapSize = "4g" + maxWarnings = 0 // Fail on any warning + maxErrors = 0 // Fail on any error + source(project.sourceSets.main.get().allSource) + configFile = file("${rootDir}/config/checkstyle/checkstyle.xml") +} + var stagingFolder = File(project.layout.buildDirectory.get().toString(), "staging") +dependencies { + implementation("com.puppycrawl.tools:checkstyle:13.0.0") +} + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(25) + } +} + +repositories { + mavenCentral() +} + tasks.register("unitFilesZip") { description = "Creates zip archives of all the unit file folders (excluding loose .txt and .xml files)." group = "build" @@ -160,7 +199,3 @@ tasks.register("stageFiles") { into("${stagingFolder}/all") } - -tasks.register("clean") { - delete(stagingFolder) -} diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 000000000..a2393980f --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/xsl/.gitkeep b/config/xsl/.gitkeep new file mode 100644 index 000000000..e69de29bb