Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/checkstyle.yml
Original file line number Diff line number Diff line change
@@ -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/
43 changes: 39 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Zip>("unitFilesZip") {
description = "Creates zip archives of all the unit file folders (excluding loose .txt and .xml files)."
group = "build"
Expand Down Expand Up @@ -160,7 +199,3 @@ tasks.register<Copy>("stageFiles") {

into("${stagingFolder}/all")
}

tasks.register<Delete>("clean") {
delete(stagingFolder)
}
39 changes: 39 additions & 0 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">

<module name="Checker">
<module name="SuppressionSingleFilter">
<property name="checks" value=".*" />
<property name="files" value=".gif$|.png$|.ttf$|.jpg$|.svg$|.bmp$|.JPG$" />
</module>

<module name="RegexpSingleline">
<property name="format" value="^(?!.*(bg\.battletech|MechWarrior Copyright|MechWarrior, BattleMech, `Mech and AeroTech are registered trademarks|BattleMech Manual)).*\b(?i)(mech|mechwarrior|battlemech|aerotech|protomech|'mech|`Mech|TripodMech|BipedMech|QuadMech|LandAirMech|OmniMech|'Mechs)\b.*$" />
<property name="ignoreCase" value="true" />
<property name="message" value="Forbidden word found" />
<property name="severity" value="error" />
</module>

<!-- Check that "license" appears at least once in the file -->
<module name="RegexpSingleline">
<property name="format" value="(?i)\b(The MegaMek Team is licensed under)\b" />
<property name="minimum" value="1" />
<property name="maximum" value="9999" />
<property name="ignoreCase" value="true" />
<property name="message" value="File must contain a license header" />
<property name="severity" value="error" />
</module>

<module name="TreeWalker">
<module name="RegexpSinglelineJava">
<property name="id" value="ForbiddenWords" />
<property name="format" value="^(?!.*(bg\.battletech|MechWarrior Copyright|MechWarrior, BattleMech, `Mech and AeroTech are registered trademarks)).*\b(?i)(mech|mechwarrior|battlemech|aerotech|protomech|'mech|`Mech|TripodMech|BipedMech|QuadMech|LandAirMech|OmniMech|’Mechs)\b.*$" />
<property name="ignoreCase" value="true" />
<property name="ignoreComments" value="false" />
<property name="message" value="Forbidden word found" />
<property name="severity" value="error" />
</module>
</module>
</module>
Empty file added config/xsl/.gitkeep
Empty file.
Loading