From a216a6623a9296518cdc85462c427690fc0b46d7 Mon Sep 17 00:00:00 2001
From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com>
Date: Wed, 5 Aug 2020 13:35:14 -0500
Subject: [PATCH] adding some good code
---
.automation/test/java/README.md | 19 +++
.automation/test/java/java_bad_1.java | 11 ++
.automation/test/java/java_good_1.java | 11 ++
.github/linters/sun_checks.xml | 198 +++++++++++++++++++++++++
TEMPLATES/sun_checks.xml | 198 +++++++++++++++++++++++++
docs/disabling-linters.md | 22 +++
lib/buildFileList.sh | 12 ++
lib/linter.sh | 27 ++--
lib/worker.sh | 1 +
9 files changed, 488 insertions(+), 11 deletions(-)
create mode 100644 .automation/test/java/README.md
create mode 100644 .automation/test/java/java_bad_1.java
create mode 100644 .automation/test/java/java_good_1.java
create mode 100644 .github/linters/sun_checks.xml
create mode 100644 TEMPLATES/sun_checks.xml
diff --git a/.automation/test/java/README.md b/.automation/test/java/README.md
new file mode 100644
index 00000000..c51155cc
--- /dev/null
+++ b/.automation/test/java/README.md
@@ -0,0 +1,19 @@
+# Java Test Cases
+
+This folder holds the test cases for **Java**.
+
+## Additional Docs
+
+No Additional information is needed for this test case.
+
+## Good Test Cases
+
+The test cases denoted: `LANGUAGE_good_FILE.EXTENSION` are all valid, and should pass successfully when linted.
+
+- **Note:** They are linted utilizing the default linter rules.
+
+## Bad Test Cases
+
+The test cases denoted: `LANGUAGE_bad_FILE.EXTENSION` are **NOT** valid, and should trigger errors when linted.
+
+- **Note:** They are linted utilizing the default linter rules.
diff --git a/.automation/test/java/java_bad_1.java b/.automation/test/java/java_bad_1.java
new file mode 100644
index 00000000..6d3c5be1
--- /dev/null
+++ b/.automation/test/java/java_bad_1.java
@@ -0,0 +1,11 @@
+/* This is a simple Java program.
+ FileName : "HelloWorld.java". */
+class HelloWorld
+{
+ // Your program begins with a call to main().
+ // Prints "Hello, World" to the terminal window.
+ public static void main(String args[])
+ {
+ System.out.println("Hello, World)
+ }
+}
diff --git a/.automation/test/java/java_good_1.java b/.automation/test/java/java_good_1.java
new file mode 100644
index 00000000..2d789a3e
--- /dev/null
+++ b/.automation/test/java/java_good_1.java
@@ -0,0 +1,11 @@
+/* This is a simple Java program.
+ FileName : "HelloWorld.java". */
+class java_good
+{
+ // Your program begins with a call to main().
+ // Prints "Hello, World" to the terminal window.
+ public static void main(String args[])
+ {
+ System.out.println("Hello, World");
+ }
+}
diff --git a/.github/linters/sun_checks.xml b/.github/linters/sun_checks.xml
new file mode 100644
index 00000000..adfd1b1c
--- /dev/null
+++ b/.github/linters/sun_checks.xml
@@ -0,0 +1,198 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/TEMPLATES/sun_checks.xml b/TEMPLATES/sun_checks.xml
new file mode 100644
index 00000000..adfd1b1c
--- /dev/null
+++ b/TEMPLATES/sun_checks.xml
@@ -0,0 +1,198 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md
index 00b246a2..455f37f2 100644
--- a/docs/disabling-linters.md
+++ b/docs/disabling-linters.md
@@ -29,6 +29,7 @@ For some linters it is also possible to override rules on a case by case level w
- [Golang](#golang)
- [Groovy](#groovy)
- [HTML](#html)
+ - [Java](#java)
- [Javascript eslint](#javascript-eslint)
- [Javascript standard](#javascript-standard)
- [JSON](#json)
@@ -461,6 +462,27 @@ def variable = 1;
---
+## Java
+
+- [checkstyle](https://github.com/checkstyle/checkstyle)
+
+### Java Config file
+
+- `.github/linters/sun_checks.xml`
+- You can pass multiple rules and overwrite default rules
+- File should be located at: `.github/linters/sun_checks.xml`
+
+### Java disable single line
+- There is currently **No** way to disable rules inline of the file(s)
+
+### Java disable code block
+- There is currently **No** way to disable rules inline of the file(s)
+
+### Java disable entire file
+- There is currently **No** way to disable rules inline of the file(s)
+
+---
+
## Javascript eslint
- [eslint](https://eslint.org/)
diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh
index d98e7e6f..c878a3be 100755
--- a/lib/buildFileList.sh
+++ b/lib/buildFileList.sh
@@ -275,6 +275,18 @@ function BuildFileList() {
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
##########################################################
READ_ONLY_CHANGE_FLAG=1
+ ######################
+ # Get the Java files #
+ ######################
+ elif [ "${FILE_TYPE}" == "java" ]; then
+ ################################
+ # Append the file to the array #
+ ################################
+ FILE_ARRAY_JAVA+=("${FILE}")
+ ##########################################################
+ # Set the READ_ONLY_CHANGE_FLAG since this could be exec #
+ ##########################################################
+ READ_ONLY_CHANGE_FLAG=1
############################
# Get the JavaScript files #
############################
diff --git a/lib/linter.sh b/lib/linter.sh
index 137ab107..7671b0fd 100755
--- a/lib/linter.sh
+++ b/lib/linter.sh
@@ -60,6 +60,9 @@ GROOVY_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${GROOVY_FILE_NAME}" # Path to th
# HTML Vars
HTML_FILE_NAME='.htmlhintrc' # Name of the file
HTML_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${HTML_FILE_NAME}" # Path to the CSS lint rules
+# Java Vars
+JAVA_FILE_NAME="sun_checks.xml" # Name of the Java config file
+JAVA_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${JAVA_FILE_NAME}" # Path to the Java lint rules
# Javascript Vars
JAVASCRIPT_FILE_NAME="${JAVASCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}" # Name of the file
JAVASCRIPT_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${JAVASCRIPT_FILE_NAME}" # Path to the Javascript lint rules
@@ -1132,6 +1135,8 @@ GetLinterRules "GO"
GetLinterRules "GROOVY"
# Get HTML rules
GetLinterRules "HTML"
+# get Java rules
+etLinterRules "JAVA"
# Get JavaScript rules
GetLinterRules "JAVASCRIPT"
# Get LUA rules
@@ -1402,6 +1407,17 @@ if [ "${VALIDATE_HTML}" == "true" ]; then
LintCodebase "HTML" "htmlhint" "htmlhint --config ${HTML_LINTER_RULES}" ".*\.\(html\)\$" "${FILE_ARRAY_HTML[@]}"
fi
+################
+# JAVA LINTING #
+################
+if [ "$VALIDATE_JAVA" == "true" ]; then
+ #######################
+ # Lint the JAVA files #
+ #######################
+ # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
+ LintCodebase "JAVA" "checkstyle" "java -jar /usr/bin/checksytle.jar -c ${JAVA_LINTER_RULES}" ".*\.\(java\)\$" "${FILE_ARRAY_JAVA[@]}"
+fi
+
######################
# JAVASCRIPT LINTING #
######################
@@ -1450,17 +1466,6 @@ if [ "${VALIDATE_JSX}" == "true" ]; then
LintCodebase "JSX" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(jsx\)\$" "${FILE_ARRAY_JSX[@]}"
fi
-################
-# JAVA LINTING #
-################
-if [ "$VALIDATE_JAVA" == "true" ]; then
- #######################
- # Lint the JAVA files #
- #######################
- # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
- LintCodebase "JAVA" "checkstyle" "java -jar /usr/bin/checksytle.jar -c sun_checks.xml" ".*\.\(java\)\$" "${FILE_ARRAY_JAVA[@]}"
-fi
-
##################
# KOTLIN LINTING #
##################
diff --git a/lib/worker.sh b/lib/worker.sh
index 8caefd05..ba7d9f15 100755
--- a/lib/worker.sh
+++ b/lib/worker.sh
@@ -583,6 +583,7 @@ function RunTestCases() {
TestCodebase "GO" "golangci-lint" "golangci-lint run -c ${GO_LINTER_RULES}" ".*\.\(go\)\$" "golang"
TestCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES --failon error" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "groovy"
TestCodebase "HTML" "htmlhint" "htmlhint --config ${HTML_LINTER_RULES}" ".*\.\(html\)\$" "html"
+ TestCodebase "JAVA" "checkstyle" "java -jar /usr/bin/checksytle.jar -c ${JAVA_LINTER_RULES}" ".*\.\(java\)\$" "java"
TestCodebase "JAVASCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(js\)\$" "javascript"
TestCodebase "JAVASCRIPT_STANDARD" "standard" "standard ${JAVASCRIPT_STANDARD_LINTER_RULES}" ".*\.\(js\)\$" "javascript"
TestCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "json"