Skip to content

Commit

Permalink
style: fix all QA execptions
Browse files Browse the repository at this point in the history
  • Loading branch information
manticore-projects committed Dec 28, 2023
1 parent 4e90365 commit 750a5ed
Show file tree
Hide file tree
Showing 19 changed files with 1,308 additions and 728 deletions.
89 changes: 44 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,53 @@ Java SQL Formatter, Beautifier and Pretty Printer. Please visit our [Website](ht
* Export to Java String, StringBuilder or MessageFormat, while handling parameters
* Command Line Option (CLI) and SQL Inline Options

```shell
java -jar JSQLFormatter.jar [-i <arg>] [-o <arg>] [-f <arg> |
--ansi | --html] [-t <arg> | -2 | -8] [--keywordSpelling <arg>]
[--functionSpelling <arg>] [--objectSpelling <arg>] [--separation
<arg>] [--squareBracketQuotation <arg>]

-i,--inputFile <arg> The input SQL file or folder.
-o,--outputFile <arg> The out SQL file for the formatted
statements.
-f,--outputFormat <arg> The output-format.
[PLAIN* ANSI HTML RTF]
--ansi Output ANSI annotated text.
--html Output HTML annotated text.
-t,--indent <arg> The indent width.
[2 4* 8]
-2 Indent with 2 characters.
-8 Indent with 8 characters.
--keywordSpelling <arg> Keyword spelling.
[UPPER*, LOWER, CAMEL, KEEP]
--functionSpelling <arg> Function name spelling.
[UPPER, LOWER, CAMEL*, KEEP]
--objectSpelling <arg> Object name spelling.
[UPPER, LOWER*, CAMEL, KEEP]
--separation <arg> Position of the field separator.
[BEFORE*, AFTER]
--squareBracketQuotation <arg> Position of the field separator.
[AUTO*, YES, NO]
```
```shell
java -jar JSQLFormatter.jar [-i <arg>] [-o <arg>] [-f <arg> |
--ansi | --html] [-t <arg> | -2 | -8] [--keywordSpelling <arg>]
[--functionSpelling <arg>] [--objectSpelling <arg>] [--separation
<arg>] [--squareBracketQuotation <arg>]

-i,--inputFile <arg> The input SQL file or folder.
-o,--outputFile <arg> The out SQL file for the formatted
statements.
-f,--outputFormat <arg> The output-format.
[PLAIN* ANSI HTML RTF]
--ansi Output ANSI annotated text.
--html Output HTML annotated text.
-t,--indent <arg> The indent width.
[2 4* 8]
-2 Indent with 2 characters.
-8 Indent with 8 characters.
--keywordSpelling <arg> Keyword spelling.
[UPPER*, LOWER, CAMEL, KEEP]
--functionSpelling <arg> Function name spelling.
[UPPER, LOWER, CAMEL*, KEEP]
--objectSpelling <arg> Object name spelling.
[UPPER, LOWER*, CAMEL, KEEP]
--separation <arg> Position of the field separator.
[BEFORE*, AFTER]
--squareBracketQuotation <arg> Position of the field separator.
[AUTO*, YES, NO]
```


* simple usage of the Java library

```java
import com.manticore.jsqlformatter.JSqlFormatter;
...
String formattedSql = JSqlFormatter.format("SELECT * FROM table1")
```
```java
import com.manticore.jsqlformatter.JSqlFormatter;
...
String formattedSql = JSqlFormatter.format("SELECT * FROM table1")
```

with Maven Artifact:
with Maven Artifact:

```xml
<dependency>
<groupId>com.manticore-projects.jsqlformatter</groupId>
<artifactId>jsqlformatter</artifactId>
<version>1.0.0</version>
</dependency>
```
```xml
<dependency>
<groupId>com.manticore-projects.jsqlformatter</groupId>
<artifactId>jsqlformatter</artifactId>
<version>1.0.0</version>
</dependency>
```


## Samples
Expand Down Expand Up @@ -104,19 +104,18 @@ WHERE id_calendar = ?
MERGE /*+ PARALLEL */ INTO test1 /*the target table*/ a
USING all_objects /*the source table*/
ON ( /*joins in()!*/ a.object_id = b.object_id )
-- INSERT CLAUSE
-- INSERT CLAUSE
WHEN /*comments between keywords!*/ NOT MATCHED THEN
INSERT ( object_id /*ID Column*/
, status /*Status Column*/ )
VALUES ( b.object_id
, b.status )
/* UPDATE CLAUSE
WITH A WHERE CONDITION */
WITH A WHERE CONDITION */
WHEN MATCHED THEN /* Lets rock */
UPDATE SET a.status = '/*this is no comment!*/ and -- this ain''t either'
WHERE b."--status" != 'VALID'
;
```
[More Samples](http://manticore-projects.com/JSQLFormatter/samples.html)

[More Samples](http://manticore-projects.com/JSQLFormatter/samples.html)
148 changes: 144 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ plugins {
id 'maven-publish'
id 'signing'

id "com.github.spotbugs" version "latest.release"
id "com.diffplug.spotless" version "latest.release"
id 'pmd'
id 'checkstyle'
id 'jacoco'
id 'com.github.kt3k.coveralls' version "latest.release"
id "com.github.spotbugs" version "latest.release"
id "com.diffplug.spotless" version "latest.release"

// download the RR tools which have no Maven Repository
id "de.undercouch.download" version "latest.release"
Expand Down Expand Up @@ -42,7 +44,7 @@ configurations {
}

dependencies {
implementation 'com.github.jsqlparser:jsqlparser:4.8-SNAPSHOT'
implementation('com.github.jsqlparser:jsqlparser:+'){ changing = true }
// Java Doc in XML Format
xmlDoclet 'com.manticore-projects.tools:xml-doclet:+'

Expand Down Expand Up @@ -182,20 +184,158 @@ license {
ignoreFailures = true
}

coveralls {
jacocoReportPath 'build/reports/jacoco/test/jacocoTestReport.xml'
}

jacocoTestReport {
dependsOn test // tests are required to run before generating the report
reports {
xml.required = false
csv.required = false
html.outputLocation = layout.buildDirectory.dir('reports/jacoco')
}
}
jacocoTestCoverageVerification {
violationRules {
rule {
//element = 'CLASS'
limit {
//@todo: temporarily reduced it 80%, we need to bring that back to 84% accepting the Keywords PR
minimum = 0.80
}
excludes = [
'net.sf.jsqlparser.util.validation.*',
'net.sf.jsqlparser.**.*Adapter',
'net.sf.jsqlparser.parser.JJTCCJSqlParserState',
'net.sf.jsqlparser.parser.TokenMgrError',
'net.sf.jsqlparser.parser.StreamProvider',
'net.sf.jsqlparser.parser.CCJSqlParserTokenManager',
'net.sf.jsqlparser.parser.ParseException',
'net.sf.jsqlparser.parser.SimpleNode',
'net.sf.jsqlparser.parser.SimpleCharStream',
'net.sf.jsqlparser.parser.StringProvider',
]
}
rule {
//element = 'CLASS'
limit {
counter = 'LINE'
value = 'MISSEDCOUNT'

//@todo: temporarily increased to 7000, we need to bring that down to 5500 after accepting the Keywords PR
maximum = 7000
}
excludes = [
'net.sf.jsqlparser.util.validation.*',
'net.sf.jsqlparser.**.*Adapter',
'net.sf.jsqlparser.parser.JJTCCJSqlParserState',
'net.sf.jsqlparser.parser.TokenMgrError',
'net.sf.jsqlparser.parser.StreamProvider',
'net.sf.jsqlparser.parser.CCJSqlParserTokenManager',
'net.sf.jsqlparser.parser.ParseException',
'net.sf.jsqlparser.parser.SimpleNode',
'net.sf.jsqlparser.parser.SimpleCharStream',
'net.sf.jsqlparser.parser.StringProvider',
]
}
// rule {
// element = 'CLASS'
// limit {
// counter = 'LINE'
// value = 'MISSEDRATIO'
// maximum = 0.3
// }
// excludes = [
// 'net.sf.jsqlparser.util.validation.*',
// 'net.sf.jsqlparser.**.*Adapter',
// 'net.sf.jsqlparser.parser.JJTCCJSqlParserState',
// 'net.sf.jsqlparser.parser.TokenMgrError',
// 'net.sf.jsqlparser.parser.StreamProvider',
// 'net.sf.jsqlparser.parser.CCJSqlParserTokenManager',
// 'net.sf.jsqlparser.parser.ParseException',
// 'net.sf.jsqlparser.parser.SimpleNode',
// 'net.sf.jsqlparser.parser.SimpleCharStream',
// 'net.sf.jsqlparser.parser.StringProvider',
// ]
// }
}
}

spotbugsMain {
reports {
html {
enabled = true
destination = file("build/reports/spotbugs/main/spotbugs.html")
stylesheet = 'fancy-hist.xsl'
}
}
}

spotbugs {
// fail only on P1 and without the net.sf.jsqlparser.parser.*
excludeFilter = file("config/spotbugs/spotBugsExcludeFilter.xml")

// do not run over the test, although we should do that eventually
spotbugsTest.enabled = false
}

pmd {
consoleOutput = true
sourceSets = [sourceSets.main]

// clear the ruleset in order to use configured rules only
ruleSets = []

//rulesMinimumPriority = 1
ruleSetFiles = files("config/pmd/ruleset.xml")

pmdMain {
excludes = [
"build/generated/*"
]
}
}

checkstyle {
sourceSets = [sourceSets.main, sourceSets.test]
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
}

spotless {
// optional: limit format enforcement to just the files changed by this feature branch
ratchetFrom 'origin/master'

format 'misc', {
// define the files to apply `misc` to
target '*.rst', '*.md', '.gitignore'

// define the steps to apply to those files
trimTrailingWhitespace()
indentWithSpaces(4) // or spaces. Takes an integer argument if you don't like 4
endWithNewline()
}
java {
indentWithSpaces(4)
eclipse().configFile('config/formatter/eclipse-java-google-style.xml')
}
}

tasks.withType(Checkstyle).configureEach {
reports {
xml.required = false
html.required = true
}
}

publishing {
publications {
mavenJava(MavenPublication) {
artifactId 'jsqlformatter'
from(components.java)
versionMapping {
usage('java-api') {
fromResolutionOf('testFixturesRuntimeClasspath')
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
Expand Down
2 changes: 1 addition & 1 deletion config/pmd/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ under the License.
<!-- for Codazy -->
<rule ref="category/java/design.xml/CyclomaticComplexity" />
<rule ref="category/java/design.xml/ExcessiveMethodLength" />
<rule ref="category/java/bestpractices.xml/SwitchStmtsShouldHaveDefault" />
<!-- <rule ref="category/java/bestpractices.xml/SwitchStmtsShouldHaveDefault" /> -->

<rule ref="category/java/errorprone.xml/AvoidBranchingStatementAsLastInLoop" />
<rule ref="category/java/errorprone.xml/AvoidDecimalLiteralsInBigDecimalConstructor" />
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/manticore/jsqlformatter/Comment.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Manticore Projects JSQLFormatter is a SQL Beautifying and Formatting Software.
* Copyright (C) 2022 Andreas Reichel <andreas@manticore-projects.com>
* Copyright (C) 2023 Andreas Reichel <andreas@manticore-projects.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
Expand Down
Loading

0 comments on commit 750a5ed

Please sign in to comment.