diff --git a/.editorconfig b/.editorconfig index f04c87852..779f99a12 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,6 +10,3 @@ insert_final_newline = true [*.md] trim_trailing_whitespace = false - -[*.properties] -insert_final_newline = false diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 67be8726d..f9cee6d08 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -11,5 +11,6 @@ labels: bug ## Useful information to include: - Minecraft version - - CC: Restitched version + - CC: Tweaked version + - Logs: These will be located in the `logs/` directory of your Minecraft instance. Please upload them as a gist or directly into this editor. - Detailed reproduction steps: sometimes I can spot a bug pretty easily, but often it's much more obscure. The more information I have to help reproduce it, the quicker it'll get fixed. diff --git a/.github/matchers/checkstyle.json b/.github/matchers/checkstyle.json new file mode 100644 index 000000000..ca6e30e63 --- /dev/null +++ b/.github/matchers/checkstyle.json @@ -0,0 +1,17 @@ +{ + "problemMatcher": [ + { + "owner": "checkstyle", + "pattern": [ + { + "regexp": "^([a-z]+) ([\\w./-]+):(\\d+):(\\d+): (.*)$", + "severity": 1, + "file": 2, + "line": 3, + "column": 4, + "message": 5 + } + ] + } + ] +} diff --git a/.github/matchers/illuaminate.json b/.github/matchers/illuaminate.json new file mode 100644 index 000000000..f59036028 --- /dev/null +++ b/.github/matchers/illuaminate.json @@ -0,0 +1,18 @@ +{ + "problemMatcher": [ + { + "owner": "illuaminate", + "severity": "warning", + "pattern": [ + { + "regexp": "^([\\w./-]+):\\[(\\d+):(\\d+)\\-(?:\\d+):(?:\\d+)\\]: (.*) \\[([a-z:-]+)\\]$", + "file": 1, + "line": 2, + "column": 3, + "message": 4, + "code": 5 + } + ] + } + ] +} diff --git a/.github/matchers/junit.json b/.github/matchers/junit.json new file mode 100644 index 000000000..1655a5f66 --- /dev/null +++ b/.github/matchers/junit.json @@ -0,0 +1,15 @@ +{ + "problemMatcher": [ + { + "owner": "junit", + "pattern": [ + { + "regexp": "^## ([\\w./-]+):(\\d+): (.*)$", + "file": 1, + "line": 2, + "message": 3 + } + ] + } + ] +} diff --git a/.github/workflows/main-ci.yml b/.github/workflows/main-ci.yml index 133c74a4c..a144e94db 100644 --- a/.github/workflows/main-ci.yml +++ b/.github/workflows/main-ci.yml @@ -3,33 +3,55 @@ name: Build on: [push, pull_request] jobs: - build: - name: Build - runs-on: ubuntu-latest + build: + name: Build + runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Checkout submodules - run: git submodule update --init --recursive + steps: + - uses: actions/checkout@v2 - - name: Set up Java 8 - uses: actions/setup-java@v1 - with: - java-version: 8 + - name: Set up Java 8 + uses: actions/setup-java@v1 + with: + java-version: 8 - - name: Cache gradle dependencies - uses: actions/cache@v2 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('gradle.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- + - name: Cache gradle dependencies + uses: actions/cache@v2 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('gradle.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- - - name: Build with Gradle - run: ./gradlew build --no-daemon || ./gradlew build --no-daemon + - name: Disable Gradle daemon + run: | + mkdir -p ~/.gradle + echo "org.gradle.daemon=false" >> ~/.gradle/gradle.properties - - name: Upload Jar - uses: actions/upload-artifact@v1 - with: - name: cc-restiched - path: build/libs + - name: Build with Gradle + run: | + ./gradlew assemble || ./gradlew assemble + ./gradlew build + + - name: Upload Jar + uses: actions/upload-artifact@v2 + with: + name: cc-restitched + path: build/libs + + - name: Parse test reports + run: ./tools/parse-reports.py + if: ${{ failure() }} + + - name: Cache pre-commit + uses: actions/cache@v2 + with: + path: ~/.cache/pre-commit + key: ${{ runner.os }}-pre-commit-${{ hashFiles('config/pre-commit/config.yml') }} + restore-keys: | + ${{ runner.os }}-pre-commit- + + - name: Run linters + run: | + pip install pre-commit + pre-commit run --config config/pre-commit/config.yml --show-diff-on-failure --all --color=always diff --git a/build.gradle b/build.gradle index 9d847ea70..686c19c8a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,8 @@ plugins { - id 'fabric-loom' version '0.6-SNAPSHOT' + id 'fabric-loom' version '0.7-SNAPSHOT' id 'maven-publish' + id "checkstyle" + id "com.github.hierynomus.license" version "0.15.0" } sourceCompatibility = JavaVersion.VERSION_1_8 @@ -22,10 +24,12 @@ repositories { } configurations { - compile.extendsFrom shade + implementation.extendsFrom shade } dependencies { + checkstyle "com.puppycrawl.tools:checkstyle:8.25" + minecraft "com.mojang:minecraft:${mc_version}" mappings "net.fabricmc:yarn:${mc_version}+build.${mappings_version}:v2" modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}" @@ -37,7 +41,7 @@ dependencies { modImplementation "io.github.prospector:modmenu:${modmenu_version}" modImplementation "me.shedaniel.cloth.api:cloth-utils-v1:${cloth_api_version}" - compile 'com.electronwill.night-config:toml:3.6.3' + implementation 'com.electronwill.night-config:toml:3.6.3' implementation 'com.google.code.findbugs:jsr305:3.0.2' shade 'org.squiddev:Cobalt:0.5.2-SNAPSHOT' @@ -85,6 +89,49 @@ jar { from configurations.shade.collect { it.isDirectory() ? it : zipTree(it) } } + +import com.hierynomus.gradle.license.tasks.LicenseCheck +import com.hierynomus.gradle.license.tasks.LicenseFormat + +license { + mapping("java", "SLASHSTAR_STYLE") + strictCheck true + + ext.year = Calendar.getInstance().get(Calendar.YEAR) +} + +[licenseMain, licenseFormatMain].forEach { + it.configure { + include("**/*.java") + exclude("dan200/computercraft/api/**") + header file('config/license/main.txt') + } +} + +[licenseTest, licenseFormatTest].forEach { + it.configure { + include("**/*.java") + header file('config/license/main.txt') + } +} + +gradle.projectsEvaluated { + tasks.withType(LicenseFormat) { + outputs.upToDateWhen { false } + } +} + + +task licenseAPI(type: LicenseCheck); +task licenseFormatAPI(type: LicenseFormat); +[licenseAPI, licenseFormatAPI].forEach { + it.configure { + source = sourceSets.main.java + include("dan200/computercraft/api/**") + header file('config/license/api.txt') + } +} + // configure the maven publication publishing { publications { diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 000000000..aaafdfd01 --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml new file mode 100644 index 000000000..647da4baa --- /dev/null +++ b/config/checkstyle/suppressions.xml @@ -0,0 +1,12 @@ + + + + + + + + + + diff --git a/config/idea/codeInspectionSettings.xml b/config/idea/codeInspectionSettings.xml new file mode 100644 index 000000000..57b8ed0d7 --- /dev/null +++ b/config/idea/codeInspectionSettings.xml @@ -0,0 +1,2491 @@ + + + + diff --git a/config/idea/codeStyleSettings.xml b/config/idea/codeStyleSettings.xml new file mode 100644 index 000000000..9a1e0f1d4 --- /dev/null +++ b/config/idea/codeStyleSettings.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + diff --git a/config/license/api.txt b/config/license/api.txt new file mode 100644 index 000000000..5c1d391fe --- /dev/null +++ b/config/license/api.txt @@ -0,0 +1,3 @@ +This file is part of the public ComputerCraft API - http://www.computercraft.info +Copyright Daniel Ratcliffe, 2011-${year}. This API may be redistributed unmodified and in full only. +For help using the API, and posting your mods, visit the forums at computercraft.info. diff --git a/config/license/main.txt b/config/license/main.txt new file mode 100644 index 000000000..bab494b2e --- /dev/null +++ b/config/license/main.txt @@ -0,0 +1,3 @@ +This file is part of ComputerCraft - http://www.computercraft.info +Copyright Daniel Ratcliffe, 2011-${year}. Do not distribute without permission. +Send enquiries to dratcliffe@gmail.com diff --git a/config/pre-commit/config.yml b/config/pre-commit/config.yml new file mode 100644 index 000000000..1f8ee9bcc --- /dev/null +++ b/config/pre-commit/config.yml @@ -0,0 +1,48 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-merge-conflict + + # Quick syntax checkers + - id: check-xml + - id: check-yaml + - id: check-toml + - id: check-json + exclude: "tsconfig\\.json$" + +- repo: https://github.com/editorconfig-checker/editorconfig-checker.python + rev: 2.3.5 + hooks: + - id: editorconfig-checker + args: ['-disable-indentation'] + exclude: "^(.*\\.(bat)|LICENSE)$" + +- repo: local + hooks: + - id: checkstyle + name: Check Java codestyle + files: ".*\\.java$" + language: system + entry: ./gradlew checkstyleMain checkstyleTest + pass_filenames: false + require_serial: true + - id: license + name: Check Java license headers + files: ".*\\.java$" + language: system + entry: ./gradlew licenseFormat + pass_filenames: false + require_serial: true + +exclude: | + (?x)^( + src/generated| + src/test/resources/test-rom/data/json-parsing/| + src/test/server-files/| + config/idea/ + ) diff --git a/config/pre-commit/illuaminate-lint.sh b/config/pre-commit/illuaminate-lint.sh new file mode 100755 index 000000000..ac7b762bf --- /dev/null +++ b/config/pre-commit/illuaminate-lint.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh +set -e + +test -d bin || mkdir bin +test -f bin/illuaminate || curl -s -obin/illuaminate https://squiddev.cc/illuaminate/linux-x86-64/illuaminate +chmod +x bin/illuaminate + +if [ -n ${GITHUB_ACTIONS+x} ]; then + # Register a problem matcher (see https://github.com/actions/toolkit/blob/master/docs/problem-matchers.md) + # for illuaminate. + echo "::add-matcher::.github/matchers/illuaminate.json" + trap 'echo "::remove-matcher owner=illuaminate::"' EXIT +fi + +./gradlew luaJavadoc +bin/illuaminate lint diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 5c2d1cf01..e708b1c02 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b343370e3..549d84424 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Tue Jul 07 13:15:43 EDT 2020 -distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index cccdd3d51..4f906e0c8 100755 --- a/gradlew +++ b/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -66,6 +82,7 @@ esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then @@ -109,10 +126,11 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath @@ -138,19 +156,19 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi @@ -159,14 +177,9 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=$(save "$@") +APP_ARGS=`save "$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index f9553162f..107acd32c 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -13,15 +29,18 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,28 +64,14 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell