diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000000..274d11b5d75 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,33 @@ +root = true +charset = "utf-8" + +[*.java] +indent_style = "space" +indent_size = 4 +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = 140 # Google Style Guide +curly_bracket_next_line = false +spaces_around_operators = true +spaces_around_brackets = "both" +indent_brace_style = "K&R" +wildcard_import_limit = 10 +continuation_indent_size = 4 # Google Style Guid + +[*.xml] +indent_style = "space" +indent_size = 4 +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true + +[*.blk] +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true + +[*.mtf] +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66b8bcc464d..23197d6408f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,7 +39,7 @@ jobs: - name: Build with Gradle working-directory: megamek - run: ./gradlew build --stacktrace --scan + run: ./gradlew build -x checkstyleMain -x checkstyleTest --stacktrace --scan - name: Upload Test Logs on Failure uses: actions/upload-artifact@v4 @@ -55,12 +55,6 @@ jobs: fail_ci_if_error: false verbose: true - # - name: Upload Zip Artifacts - # uses: actions/upload-artifact@v4 - # with: - # name: mm-release-zip-${{ matrix.java-distribution }}-jdk${{ matrix.java-version }} - # path: ./megamek/megamek/build/distributions/*.zip - - name: Upload TarGZ Release uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/java-doc.yml b/.github/workflows/java-doc.yml new file mode 100644 index 00000000000..932370f3714 --- /dev/null +++ b/.github/workflows/java-doc.yml @@ -0,0 +1,38 @@ +name: JavaDoc Generation + +on: + pull_request: + branches: [master] + +env: + GRADLE_OPTS: "-Dscan.link.VCS=${{ github.event.pull_request.html_url }}" + +jobs: + javadoc: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest] + java-distribution: [temurin] + java-version: [17] + fail-fast: false + + steps: + - name: "Check out MegaMek" + uses: actions/checkout@v4 + with: + path: megamek + + - name: Set up ${{ matrix.java-distribution }} JDK ${{ matrix.java-version }} + uses: actions/setup-java@v4 + with: + distribution: ${{ matrix.java-distribution }} + java-version: ${{ matrix.java-version }} + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: Build with Gradle + working-directory: megamek + run: ./gradlew javadoc diff --git a/README.md b/README.md deleted file mode 120000 index c3f3aab38f7..00000000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -megamek/docs/1-Readme/readme.txt \ No newline at end of file diff --git a/gradle/gradle-daemon-jvm.properties b/gradle/gradle-daemon-jvm.properties new file mode 100644 index 00000000000..858feb7e383 --- /dev/null +++ b/gradle/gradle-daemon-jvm.properties @@ -0,0 +1,2 @@ +#This file is generated by updateDaemonJvm +toolchainVersion=17 diff --git a/megamek/HACKING b/megamek/HACKING deleted file mode 100644 index 0f2433d21f3..00000000000 --- a/megamek/HACKING +++ /dev/null @@ -1,68 +0,0 @@ -ATTENTION TO FREE/LIBRE/OPEN SOURCE SOFTWARE HACKERS - -This project started on a Windows system and as such, it has a few quirks that -you may find disconcerting. The first is a complete lack of a Makefile; the -primary means of building this project is Apache Ant. Also, there is an EXE -(which calls a BAT file) to run the game on a Windows system; the corresponding -shell script is called "startup.sh"). The release file is a ZIP file, and it -does not place everything into a directory with a version number; many files -are deposited directly into the directory that you unzip into. As is typical -in a Windows-centric Java app, all third party libraries (i.e. JAR files) are -supplied by the project itself. Finally, MegaMek is very particular about the -contents of the directory in which it runs; the startup.sh script attempt to -solve this problem, but let me know if it doesn't work in your setup. - -Someday, I intend to address every single issue listed above. For now, -however, please accept the limitations and move on. - -MegaMek can be run on any Java v1.5 runtime, but we've gotten some -problem reports from specific OS/JVM combinations. - -While there is no Makefile, it's very easy to build MegaMek with Jikes. My -computer is running Debian Sarge with GCC installed. Therefore, I can build -MegaMek with the following command; please modify the command to meet your -environment (email me if you have any problems). - -jikes-gij -q -d classes -classpath classes -extdirs lib -sourcepath src `find src -name '*.java'` - -Once MegaMek is built, I can run it with GIJ with the following command. - -gij --classpath lib/Ostermiller.jar:lib/PngEncoder.jar:lib/TabPanel.jar:lib/TinyXML.jar:lib/collections.jar:l10n:classes megamek.MegaMek -log | tee MegaMek.log - -I can run it under Kaffe with a similar command. - -kaffe -classpath lib/Ostermiller.jar:lib/PngEncoder.jar:lib/TabPanel.jar:lib/TinyXML.jar:lib/collections.jar:l10n:classes megamek.MegaMek -log | tee MegaMek.log - -The following runtime flags are available: - -testdice : Test the random number generator used by MegaMek, and exit. - -dedicated [gamefile.sav] : Run MegaMek as a headless server; if the - optional SAV file is supplied, that saved game will be loaded. - -log [filename] : If no filename is given, run MegaMek without a log - file. If a file is named, write the log to that file. If this - flag is omitted, output is automatically sent to MegaMek.log. - -testxml filename : Parse the named XML file, display its contents, and - then exit. - -gui swing : Start the swing GUI - -eqdb filename : creates a list of all valid Equipment names for MTF - files and saves it to the specified file - -validate unitname : tests if the specified unit is a valid design - E.g. to test the Stalker STK-4N, use -validate "Stalker STK-4N" - -TODO list: - * The Splash Screen that is displayed first when MegaMek starts contains an - image. This image should always be shown, but it flickers in and out - of view under certain FLOSS Java runtimes. - * The Splash Screen has a column of buttons to the right of the image. Under - certain FLOSS runtimes, this column has a strange width, and it has a - stranger resize behavior. - * The Map Editor (launched from the button with the same name) has a strange - layout in the runtimes that have trouble laying out the Splash Screen. - * The Map Editor has image display problems in the runtimes that have problems - showing the image on the Splash Screen. - * The default random number generator that MegaMek uses is an instance of the - java.security.SecureRandom class. Under certain runtimes, this RNG is - very poorly implemented, as evidenced by the "-testdice" flag. - -James Damour -suvarov454@users.sourceforge.net -last updated 2008-01-25 diff --git a/megamek/docs/1-Readme/readme.txt b/megamek/README.md similarity index 100% rename from megamek/docs/1-Readme/readme.txt rename to megamek/README.md diff --git a/megamek/build.gradle b/megamek/build.gradle index 176ff1b9ada..6d94571c683 100644 --- a/megamek/build.gradle +++ b/megamek/build.gradle @@ -2,11 +2,14 @@ import java.time.LocalDateTime plugins { id 'application' + id 'checkstyle' + id 'com.palantir.git-version' version '3.1.0' id 'edu.sc.seis.launch4j' version '3.0.6' + id "io.sentry.jvm.gradle" version '4.11.0' id 'jacoco' id 'java' - id "io.sentry.jvm.gradle" version '4.11.0' - id 'com.palantir.git-version' version '3.1.0' + id 'org.ec4j.editorconfig' version '0.1.0' + } java { @@ -82,6 +85,12 @@ ext { atlasedImages = "${fileStagingDir}/atlasedImages.txt" } +checkstyle { + toolVersion '10.18.1' + configFile file("config/checkstyle/checkstyle.xml") + ignoreFailures false +} + run { jvmArgs = mmJvmOptions } @@ -389,3 +398,12 @@ task unitFileMigrationTool(type: JavaExec, dependsOn: jar) { classpath = sourceSets.main.runtimeClasspath mainClass = 'megamek.utilities.UnitFileMigrationTool' } + +tasks.withType(Checkstyle) { + minHeapSize = "200m" + maxHeapSize = "1g" + reports { + xml.required = false + html.required = true + } +} diff --git a/megamek/config/checkstyle/checkstyle.xml b/megamek/config/checkstyle/checkstyle.xml new file mode 100644 index 00000000000..3ed9c8d6b7c --- /dev/null +++ b/megamek/config/checkstyle/checkstyle.xml @@ -0,0 +1,427 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/megamek/config/checkstyle/suppressions.xml b/megamek/config/checkstyle/suppressions.xml new file mode 100644 index 00000000000..e69de29bb2d