From 7f8cee8298aae15d7528b1f41bc0615c93a9b60c Mon Sep 17 00:00:00 2001 From: Richard J Hancock Date: Wed, 18 Sep 2024 15:06:33 -0500 Subject: [PATCH 1/8] Added JavaDoc building in Actions. Added CheckStyle and configured for Google Format Guide Added .editorconfig and set defaults based upon Style Guide and Google Style Guide --- .editorconfig | 16 + .github/workflows/ci.yml | 6 - .github/workflows/java-doc.yml | 38 ++ megamek/build.gradle | 18 + megamek/config/checkstyle/checkstyle.xml | 427 +++++++++++++++++++++ megamek/config/checkstyle/suppressions.xml | 0 6 files changed, 499 insertions(+), 6 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/workflows/java-doc.yml create mode 100644 megamek/config/checkstyle/checkstyle.xml create mode 100644 megamek/config/checkstyle/suppressions.xml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000000..60d4a95d05c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +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 = 100 # 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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66b8bcc464d..aeda53f415c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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..9fca8dfb312 --- /dev/null +++ b/.github/workflows/java-doc.yml @@ -0,0 +1,38 @@ +name: MegaMek CI with Gradle + +on: + pull_request: + branches: [master] + +env: + GRADLE_OPTS: "-Dscan.link.VCS=${{ github.event.pull_request.html_url }}" + +jobs: + ci_cd: + 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/megamek/build.gradle b/megamek/build.gradle index 176ff1b9ada..47755c0cb2e 100644 --- a/megamek/build.gradle +++ b/megamek/build.gradle @@ -2,11 +2,14 @@ import java.time.LocalDateTime plugins { id 'application' + id 'checkstyle' id 'edu.sc.seis.launch4j' version '3.0.6' id 'jacoco' id 'java' + id 'org.ec4j.editorconfig' version '0.1.0' id "io.sentry.jvm.gradle" version '4.11.0' id 'com.palantir.git-version' version '3.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..36a790e38d5 --- /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 From 6c40579473b003e5114bff7559e1fa415e16ef42 Mon Sep 17 00:00:00 2001 From: Richard J Hancock Date: Wed, 18 Sep 2024 15:07:31 -0500 Subject: [PATCH 2/8] Corrected Name of Action --- .github/workflows/java-doc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/java-doc.yml b/.github/workflows/java-doc.yml index 9fca8dfb312..4724dcfd47b 100644 --- a/.github/workflows/java-doc.yml +++ b/.github/workflows/java-doc.yml @@ -1,4 +1,4 @@ -name: MegaMek CI with Gradle +name: JavaDoc Generation on: pull_request: From 36b60e1a384652c77b898a966acaddae0f5ce9ee Mon Sep 17 00:00:00 2001 From: Richard J Hancock Date: Wed, 18 Sep 2024 15:17:49 -0500 Subject: [PATCH 3/8] Reordered Plugins --- megamek/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/megamek/build.gradle b/megamek/build.gradle index 47755c0cb2e..6d94571c683 100644 --- a/megamek/build.gradle +++ b/megamek/build.gradle @@ -3,12 +3,12 @@ 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 'org.ec4j.editorconfig' version '0.1.0' - id "io.sentry.jvm.gradle" version '4.11.0' - id 'com.palantir.git-version' version '3.1.0' } From 48c750c60d1120b99b5cb4f8db566db261694222 Mon Sep 17 00:00:00 2001 From: Richard J Hancock Date: Wed, 18 Sep 2024 15:36:19 -0500 Subject: [PATCH 4/8] Removed link to ReadMe. Removed 'hacking' as no longer relevant --- README.md | 1 - megamek/HACKING | 68 ------------------- .../{docs/1-Readme/readme.txt => README.md} | 0 3 files changed, 69 deletions(-) delete mode 120000 README.md delete mode 100644 megamek/HACKING rename megamek/{docs/1-Readme/readme.txt => README.md} (100%) 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/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 From 2997419f07973cf73f8af998a80e4c26205a591c Mon Sep 17 00:00:00 2001 From: Richard J Hancock Date: Wed, 18 Sep 2024 15:43:27 -0500 Subject: [PATCH 5/8] Adjusted to 4 spaces --- megamek/config/checkstyle/checkstyle.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/megamek/config/checkstyle/checkstyle.xml b/megamek/config/checkstyle/checkstyle.xml index 36a790e38d5..72a7eeb7379 100644 --- a/megamek/config/checkstyle/checkstyle.xml +++ b/megamek/config/checkstyle/checkstyle.xml @@ -277,7 +277,7 @@ https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resource value="GenericWhitespace ''{0}'' is not preceded with whitespace." /> - + From 06cd4c0fca16d3d6a7f029a03f9c3fb7376fb47d Mon Sep 17 00:00:00 2001 From: Richard J Hancock Date: Wed, 18 Sep 2024 15:54:48 -0500 Subject: [PATCH 6/8] Adjusted CI to NOT run checkstyle tests --- .github/workflows/ci.yml | 2 +- .github/workflows/java-doc.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aeda53f415c..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 diff --git a/.github/workflows/java-doc.yml b/.github/workflows/java-doc.yml index 4724dcfd47b..932370f3714 100644 --- a/.github/workflows/java-doc.yml +++ b/.github/workflows/java-doc.yml @@ -8,7 +8,7 @@ env: GRADLE_OPTS: "-Dscan.link.VCS=${{ github.event.pull_request.html_url }}" jobs: - ci_cd: + javadoc: runs-on: ${{ matrix.os }} strategy: From 736c9638529ae9c0a7371b38e75d1dd5b157b73f Mon Sep 17 00:00:00 2001 From: Richard J Hancock Date: Wed, 18 Sep 2024 16:05:32 -0500 Subject: [PATCH 7/8] Gradle Daemon JVM Update --- gradle/gradle-daemon-jvm.properties | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 gradle/gradle-daemon-jvm.properties 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 From 036eda5cac32a0cf2cd44ddadb2cab127a775f4d Mon Sep 17 00:00:00 2001 From: Richard J Hancock Date: Fri, 20 Sep 2024 16:44:15 -0500 Subject: [PATCH 8/8] Adjusted to 140 width. Added config for XML, MTF, and BLK as a precaution --- .editorconfig | 19 +- megamek/config/checkstyle/checkstyle.xml | 702 +++++++++++------------ 2 files changed, 369 insertions(+), 352 deletions(-) diff --git a/.editorconfig b/.editorconfig index 60d4a95d05c..274d11b5d75 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,10 +7,27 @@ indent_size = 4 end_of_line = lf trim_trailing_whitespace = true insert_final_newline = true -max_line_length = 100 # Google Style Guide +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/megamek/config/checkstyle/checkstyle.xml b/megamek/config/checkstyle/checkstyle.xml index 72a7eeb7379..3ed9c8d6b7c 100644 --- a/megamek/config/checkstyle/checkstyle.xml +++ b/megamek/config/checkstyle/checkstyle.xml @@ -19,116 +19,114 @@ https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resource --> + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - - + - - - - - - + + + + - - - - + + + + + + - - - - + + + + + - - + + + + + - - + + + + + + + + + + + + + + + + + + + + + - - - - + + - - - - - + + + - - - - - - - - + + + + + + - - - - - - - - - + + + + + + + - - - - - - + + + + - - - - + + - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + - - - + - - - - + + + - - - - + + - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + - - - - + + - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + -