Skip to content

Commit a702877

Browse files
authored
General refactory + PMD + Code Format + PR Template (#6)
* move src to inside app folder; Add PMD plugin * code format plugin * update PMD Rules e ajuste codigo * refactory unit tests * update workflows * refactory UnitTest * add PR template * Update maven_ci_cd.yml
1 parent ec917c0 commit a702877

File tree

26 files changed

+968
-759
lines changed

26 files changed

+968
-759
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Descrever mudanças realizadas e/ou bugs corrigidos :)

.github/workflows/maven_ci_cd.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ jobs:
2929
cache: maven
3030

3131
- name: Build with Maven
32-
run: mvn -B package --file pom.xml -DskipTests
32+
run: mvn -B package --file app/pom.xml -DskipTests
3333

3434
- name: Run Unit Test
35-
run: mvn test --file pom.xml
35+
run: mvn test --file app/pom.xml
3636

3737
- name: Cache SonarCloud packages
3838
uses: actions/cache@v1
@@ -52,4 +52,7 @@ jobs:
5252
env:
5353
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
5454
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
55-
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=bvilela_java-util-validation-lib
55+
run: |
56+
echo "Change directory..."
57+
cd app
58+
mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=bvilela_java-util-validation-lib

.github/workflows/maven_ci_cd_publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ jobs:
2626
settings-path: ${{ github.workspace }} # location for the settings.xml file
2727

2828
- name: Build with Maven
29-
run: mvn -B package --file pom.xml -DskipTests
29+
run: mvn -B package --file app/pom.xml -DskipTests
3030

3131
- name: Run Unit Test
32-
run: mvn test --file pom.xml
32+
run: mvn test --file app/pom.xml
3333

3434
- name: Publish to GitHub Packages
35-
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
35+
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml --file app/pom.xml
3636
env:
3737
GITHUB_TOKEN: ${{ github.token }}

.github/workflows/sonarcloud.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
java-version: 11
2424

2525
- name: Run Unit Test
26-
run: mvn test --file pom.xml
26+
run: mvn test --file app/pom.xml
2727

2828
- name: Cache SonarCloud packages
2929
uses: actions/cache@v1
@@ -43,4 +43,7 @@ jobs:
4343
env:
4444
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
4545
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
46-
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=bvilela_java-util-validation-lib
46+
run: |
47+
echo "Change directory..."
48+
cd app
49+
mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=bvilela_java-util-validation-lib

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ hs_err_pid*
2626
.factorypath
2727
.project
2828
.settings
29-
target/
29+
target/
30+
31+
.idea

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ Project with validations utils for Java based in javax and Gson.
4949

5050
> The annotated element will **not be serialized** to gson.toJson(dto).
5151
>
52-
> :exclamation: You need to get the Gson() by the `com.bvilela.utils.GsonUtils.getGson()`.
52+
> :exclamation: You need to get the Gson() by the `br.com.bvilela.lib.utils.GsonUtils.getGson()`.
53+
54+
55+
## :heavy_check_mark: Check PMD rules locally
56+
To check PMD rules in your machine, run follow command in `app` dir:
57+
```
58+
mvn pmd:check
59+
```
5360

5461

5562
## :gear: Add dependency in your project
@@ -111,7 +118,7 @@ Validate if a variable of type `String` is a **Valid date**.
111118
For this, use the **`@ValidParseDate`** annotation, with the `parse` parameter as `false` or **omit** this param (default is `false`).
112119

113120
```java
114-
import com.bvilela.utils.annotation.javax.ValidParseDate;
121+
import javax.annotation.br.com.bvilela.lib.utils.ValidParseDate;
115122

116123
public class MyExampleDTO {
117124
@ValidParseDate(message = "DateInit is a invalid date!", pattern = "dd-MM-yyyy")
@@ -120,7 +127,7 @@ public class MyExampleDTO {
120127
```
121128

122129
```java
123-
import com.bvilela.utils.annotation.javax.ValidParseDate;
130+
import javax.annotation.br.com.bvilela.lib.utils.ValidParseDate;
124131

125132
public class MyExampleDTO {
126133
@ValidParseDate(parse = false, pattern = "dd MMMM yyyy", locale = "en")
@@ -129,7 +136,7 @@ public class MyExampleDTO {
129136
```
130137

131138
```java
132-
import com.bvilela.utils.annotation.javax.ValidParseDate;
139+
import javax.annotation.br.com.bvilela.lib.utils.ValidParseDate;
133140

134141
public class MyExampleDTO {
135142
@ValidParseDate(pattern = "yyyy dd MMMM", locale = "de_DE")
@@ -138,7 +145,7 @@ public class MyExampleDTO {
138145
```
139146

140147
```java
141-
import com.bvilela.utils.annotation.javax.ValidParseDate;
148+
import javax.annotation.br.com.bvilela.lib.utils.ValidParseDate;
142149

143150
public class MyExampleDTO {
144151
@ValidParseDate(pattern = "dd MMMM yyyy")
@@ -155,7 +162,7 @@ For this, use the **`@ValidParseDate`** annotation, with the `parse` parameter a
155162
In this case, you need to create a `LocalDate` variable with the same name of String variable, concatenating `Converted` in name.
156163

157164
```java
158-
import com.bvilela.utils.annotation.javax.ValidParseDate;
165+
import javax.annotation.br.com.bvilela.lib.utils.ValidParseDate;
159166

160167
public class MyExampleDTO {
161168
@ValidParseDate(message = "DateInit is a invalid date!", pattern = "dd-MM-yyyy", parse = true)
@@ -169,7 +176,7 @@ public class MyExampleDTO {
169176
Use @NotSerialized annotation.
170177

171178
```java
172-
import com.bvilela.utils.annotation.gson.NotSerialized;
179+
import gson.annotation.br.com.bvilela.lib.utils.NotSerialized;
173180

174181
public class MyExampleDTO {
175182
private String name;
@@ -183,7 +190,7 @@ public class MyExampleDTO {
183190
```
184191

185192
```java
186-
import com.bvilela.utils.GsonUtils;
193+
import br.com.bvilela.lib.utils.GsonUtils;
187194

188195
var json = GsonUtils.getGson().toJson(dto);
189196
// json = {"name":"nameValue"}

app/pmd-ruleset.xml

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
<?xml version="1.0"?>
2+
3+
<ruleset name="Custom Rules"
4+
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
7+
8+
<description>
9+
My custom PMD Rules
10+
</description>
11+
12+
<!-- BEST PRACTICES -->
13+
<rule ref="category/java/bestpractices.xml/AbstractClassWithoutAbstractMethod" />
14+
<rule ref="category/java/bestpractices.xml/AvoidPrintStackTrace" />
15+
<rule ref="category/java/bestpractices.xml/AvoidStringBufferField"/>
16+
<rule ref="category/java/bestpractices.xml/AvoidUsingHardCodedIP"/>
17+
<rule ref="category/java/bestpractices.xml/CheckResultSet"/>
18+
<rule ref="category/java/bestpractices.xml/ConstantsInInterface"/>
19+
<rule ref="category/java/bestpractices.xml/DefaultLabelNotLastInSwitchStmt"/>
20+
<rule ref="category/java/bestpractices.xml/ForLoopCanBeForeach"/>
21+
<!-- <rule ref="category/java/bestpractices.xml/GuardLogStatement"/> -->
22+
<!-- <rule ref="category/java/bestpractices.xml/JUnit4SuitesShouldUseSuiteAnnotation" /> -->
23+
<!-- <rule ref="category/java/bestpractices.xml/JUnit4TestShouldUseAfterAnnotation" /> -->
24+
<!-- <rule ref="category/java/bestpractices.xml/JUnit4TestShouldUseBeforeAnnotation" /> -->
25+
<!-- <rule ref="category/java/bestpractices.xml/JUnit4TestShouldUseTestAnnotation" /> -->
26+
<!-- <rule ref="category/java/bestpractices.xml/JUnitAssertionsShouldIncludeMessage" /> -->
27+
<!-- <rule ref="category/java/bestpractices.xml/JUnitTestContainsTooManyAsserts" /> -->
28+
<!-- <rule ref="category/java/bestpractices.xml/JUnitTestsShouldIncludeAssert" /> -->
29+
<rule ref="category/java/bestpractices.xml/JUnitUseExpected" />
30+
<rule ref="category/java/bestpractices.xml/LooseCoupling"/>
31+
<rule ref="category/java/bestpractices.xml/MissingOverride"/>
32+
33+
<rule ref="category/java/bestpractices.xml/OneDeclarationPerLine"/>
34+
<rule ref="category/java/bestpractices.xml/PositionLiteralsFirstInCaseInsensitiveComparisons"/>
35+
<rule ref="category/java/bestpractices.xml/PositionLiteralsFirstInComparisons"/>
36+
<rule ref="category/java/bestpractices.xml/PreserveStackTrace"/>
37+
<rule ref="category/java/bestpractices.xml/SwitchStmtsShouldHaveDefault"/>
38+
<rule ref="category/java/bestpractices.xml/SystemPrintln" />
39+
<rule ref="category/java/bestpractices.xml/UnusedFormalParameter"/>
40+
<rule ref="category/java/bestpractices.xml/UnusedImports"/>
41+
<rule ref="category/java/errorprone.xml/ImportFromSamePackage"/>
42+
<rule ref="category/java/bestpractices.xml/UnusedLocalVariable"/>
43+
<rule ref="category/java/bestpractices.xml/UnusedPrivateField"/>
44+
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod"/>
45+
<rule ref="category/java/bestpractices.xml/UseAssertEqualsInsteadOfAssertTrue"/>
46+
<rule ref="category/java/bestpractices.xml/UseAssertNullInsteadOfAssertTrue"/>
47+
<rule ref="category/java/bestpractices.xml/UseAssertSameInsteadOfAssertTrue"/>
48+
<rule ref="category/java/bestpractices.xml/UseAssertTrueInsteadOfAssertEquals"/>
49+
<rule ref="category/java/bestpractices.xml/UseCollectionIsEmpty"/>
50+
51+
<rule ref="category/java/codestyle.xml/AvoidDollarSigns"/>
52+
<rule ref="category/java/codestyle.xml/AvoidProtectedFieldInFinalClass"/>
53+
<rule ref="category/java/codestyle.xml/AvoidProtectedMethodInFinalClassNotExtending"/>
54+
55+
<!-- NAMING CONVENTIONS -->
56+
<rule ref="category/java/codestyle.xml/FormalParameterNamingConventions"/>
57+
<rule ref="category/java/codestyle.xml/ClassNamingConventions"/>
58+
<rule ref="category/java/codestyle.xml/LocalVariableNamingConventions"/>
59+
<rule ref="category/java/codestyle.xml/MethodNamingConventions"/>
60+
<rule ref="category/java/codestyle.xml/PackageCase"/>
61+
62+
<!-- UNIMPLEMENTED -->
63+
<rule ref="category/java/codestyle.xml/FieldNamingConventions" />
64+
<rule ref="category/java/codestyle.xml/GenericsNaming"/>
65+
66+
<rule ref="category/java/codestyle.xml/LongVariable">
67+
<properties>
68+
<property name="minimum" value="25" />
69+
</properties>
70+
</rule>
71+
<rule ref="category/java/codestyle.xml/ShortClassName"/>
72+
<rule ref="category/java/codestyle.xml/ShortMethodName"/>
73+
<rule ref="category/java/codestyle.xml/ShortVariable"/>
74+
75+
<!-- OTHER -->
76+
<rule ref="category/java/codestyle.xml/AvoidUsingNativeCode" />
77+
<rule ref="category/java/codestyle.xml/BooleanGetMethodName" />
78+
<rule ref="category/java/codestyle.xml/ConfusingTernary" />
79+
<rule ref="category/java/codestyle.xml/ControlStatementBraces"/>
80+
<rule ref="category/java/codestyle.xml/DontImportJavaLang"/>
81+
<rule ref="category/java/codestyle.xml/DuplicateImports"/>
82+
<rule ref="category/java/codestyle.xml/EmptyMethodInAbstractClassShouldBeAbstract" />
83+
<rule ref="category/java/codestyle.xml/ExtendsObject"/>
84+
<rule ref="category/java/codestyle.xml/ForLoopShouldBeWhileLoop"/>
85+
<rule ref="category/java/codestyle.xml/IdenticalCatchBranches"/>
86+
<!-- <rule ref="category/java/codestyle.xml/LocalVariableCouldBeFinal" /> -->
87+
<!-- <rule ref="category/java/codestyle.xml/MethodArgumentCouldBeFinal" /> -->
88+
<rule ref="category/java/codestyle.xml/NoPackage"/>
89+
<rule ref="category/java/codestyle.xml/TooManyStaticImports">
90+
<properties>
91+
<property name="maximumStaticImports" value="5"/>
92+
</properties>
93+
</rule>
94+
<rule ref="category/java/codestyle.xml/UnnecessaryAnnotationValueElement"/>
95+
<rule ref="category/java/codestyle.xml/UnnecessaryConstructor"/>
96+
<rule ref="category/java/codestyle.xml/UnnecessaryFullyQualifiedName"/>
97+
<rule ref="category/java/codestyle.xml/UnnecessaryLocalBeforeReturn"/>
98+
<rule ref="category/java/codestyle.xml/UnnecessaryModifier"/>
99+
<rule ref="category/java/codestyle.xml/UnnecessaryReturn"/>
100+
<rule ref="category/java/codestyle.xml/UselessParentheses"/>
101+
<rule ref="category/java/codestyle.xml/UselessQualifiedThis"/>
102+
103+
<rule ref="category/java/design.xml/AbstractClassWithoutAnyMethod"/>
104+
<rule ref="category/java/design.xml/AvoidDeeplyNestedIfStmts" />
105+
<rule ref="category/java/design.xml/ClassWithOnlyPrivateConstructorsShouldBeFinal"/>
106+
<rule ref="category/java/design.xml/CouplingBetweenObjects"/>
107+
<rule ref="category/java/design.xml/ExcessiveMethodLength"/>
108+
<rule ref="category/java/design.xml/ExcessiveParameterList"/>
109+
<rule ref="category/java/design.xml/ExcessivePublicCount"/>
110+
<rule ref="category/java/design.xml/FinalFieldCouldBeStatic"/>
111+
<rule ref="category/java/design.xml/LogicInversion"/>
112+
113+
<rule ref="category/java/design.xml/CyclomaticComplexity"/>
114+
<rule ref="category/java/design.xml/NPathComplexity"/>
115+
<rule ref="category/java/design.xml/SimplifiedTernary"/>
116+
<rule ref="category/java/design.xml/SimplifyBooleanReturns"/>
117+
<rule ref="category/java/design.xml/SimplifyConditional"/>
118+
<rule ref="category/java/design.xml/SingularField"/>
119+
<rule ref="category/java/design.xml/SwitchDensity" />
120+
<rule ref="category/java/design.xml/TooManyFields"/>
121+
<rule ref="category/java/design.xml/TooManyMethods">
122+
<properties>
123+
<property name="maxmethods" value="20"/>
124+
</properties>
125+
</rule>
126+
<rule ref="category/java/design.xml/UselessOverridingMethod"/>
127+
<rule ref="category/java/design.xml/UseUtilityClass"/>
128+
129+
<rule ref="category/java/documentation.xml/UncommentedEmptyConstructor"/>
130+
<rule ref="category/java/documentation.xml/UncommentedEmptyMethodBody"/>
131+
132+
<rule ref="category/java/errorprone.xml/AssignmentInOperand">
133+
<properties>
134+
<property name="allowWhile" value="true"/>
135+
</properties>
136+
</rule>
137+
<rule ref="category/java/errorprone.xml/AssignmentToNonFinalStatic"/>
138+
<rule ref="category/java/errorprone.xml/AvoidAccessibilityAlteration"/>
139+
<rule ref="category/java/errorprone.xml/AvoidBranchingStatementAsLastInLoop"/>
140+
<rule ref="category/java/errorprone.xml/AvoidCatchingThrowable"/>
141+
<rule ref="category/java/errorprone.xml/AvoidDecimalLiteralsInBigDecimalConstructor"/>
142+
<rule ref="category/java/errorprone.xml/AvoidInstanceofChecksInCatchClause"/>
143+
<rule ref="category/java/errorprone.xml/AvoidMultipleUnaryOperators"/>
144+
<rule ref="category/java/errorprone.xml/AvoidUsingOctalValues"/>
145+
<rule ref="category/java/errorprone.xml/BadComparison"/>
146+
<rule ref="category/java/errorprone.xml/BrokenNullCheck"/>
147+
<rule ref="category/java/errorprone.xml/CheckSkipResult"/>
148+
<rule ref="category/java/errorprone.xml/ClassCastExceptionWithToArray"/>
149+
<rule ref="category/java/errorprone.xml/CloneMethodMustBePublic"/>
150+
<rule ref="category/java/errorprone.xml/CloneMethodMustImplementCloneable"/>
151+
<rule ref="category/java/errorprone.xml/CloneMethodReturnTypeMustMatchClassName"/>
152+
<rule ref="category/java/errorprone.xml/CloneThrowsCloneNotSupportedException"/>
153+
<rule ref="category/java/errorprone.xml/CloseResource"/>
154+
<rule ref="category/java/errorprone.xml/CompareObjectsWithEquals"/>
155+
<rule ref="category/java/errorprone.xml/DoNotCallGarbageCollectionExplicitly"/>
156+
157+
<rule ref="category/java/errorprone.xml/DoNotExtendJavaLangThrowable"/>
158+
<rule ref="category/java/design.xml/DoNotExtendJavaLangError"/>
159+
160+
<rule ref="category/java/errorprone.xml/DontUseFloatTypeForLoopIndices"/>
161+
<rule ref="category/java/errorprone.xml/EmptyCatchBlock"/>
162+
163+
<!-- EMPTY RULES -->
164+
<rule ref="category/java/errorprone.xml/EmptyFinalizer"/>
165+
<rule ref="category/java/errorprone.xml/EmptyFinallyBlock"/>
166+
<rule ref="category/java/errorprone.xml/EmptyIfStmt"/>
167+
<rule ref="category/java/errorprone.xml/EmptyInitializer"/>
168+
<rule ref="category/java/errorprone.xml/EmptyStatementBlock"/>
169+
<rule ref="category/java/errorprone.xml/EmptyStatementNotInLoop"/>
170+
<rule ref="category/java/errorprone.xml/EmptySwitchStatements"/>
171+
<rule ref="category/java/errorprone.xml/EmptySynchronizedBlock"/>
172+
<rule ref="category/java/errorprone.xml/EmptyTryBlock"/>
173+
<rule ref="category/java/errorprone.xml/EmptyWhileStmt"/>
174+
175+
<rule ref="category/java/errorprone.xml/EqualsNull"/>
176+
177+
<rule ref="category/java/errorprone.xml/IdempotentOperations"/>
178+
<rule ref="category/java/errorprone.xml/InstantiationToGetClass"/>
179+
<rule ref="category/java/errorprone.xml/JumbledIncrementer"/>
180+
<rule ref="category/java/errorprone.xml/MisplacedNullCheck"/>
181+
<rule ref="category/java/errorprone.xml/MissingBreakInSwitch"/>
182+
<rule ref="category/java/errorprone.xml/MissingStaticMethodInNonInstantiatableClass"/>
183+
<rule ref="category/java/errorprone.xml/MoreThanOneLogger" />
184+
<rule ref="category/java/errorprone.xml/NonCaseLabelInSwitchStatement"/>
185+
<rule ref="category/java/errorprone.xml/NonStaticInitializer"/>
186+
<rule ref="category/java/errorprone.xml/OverrideBothEqualsAndHashcode"/>
187+
<rule ref="category/java/errorprone.xml/ProperCloneImplementation"/>
188+
<rule ref="category/java/errorprone.xml/ProperLogger"/>
189+
<rule ref="category/java/errorprone.xml/ReturnEmptyArrayRatherThanNull"/>
190+
<rule ref="category/java/errorprone.xml/ReturnFromFinallyBlock"/>
191+
<rule ref="category/java/errorprone.xml/SingleMethodSingleton"/>
192+
<rule ref="category/java/errorprone.xml/SingletonClassReturningNewInstance"/>
193+
<rule ref="category/java/errorprone.xml/SuspiciousEqualsMethodName"/>
194+
<rule ref="category/java/errorprone.xml/SuspiciousHashcodeMethodName"/>
195+
<rule ref="category/java/errorprone.xml/SuspiciousOctalEscape"/>
196+
<rule ref="category/java/errorprone.xml/UnconditionalIfStatement"/>
197+
<rule ref="category/java/errorprone.xml/UnnecessaryConversionTemporary"/>
198+
<rule ref="category/java/errorprone.xml/UnusedNullCheckInEquals"/>
199+
<rule ref="category/java/errorprone.xml/UseEqualsToCompareStrings"/>
200+
<rule ref="category/java/errorprone.xml/UselessOperationOnImmutable"/>
201+
202+
<rule ref="category/java/multithreading.xml/AvoidThreadGroup"/>
203+
<rule ref="category/java/multithreading.xml/AvoidUsingVolatile"/>
204+
<rule ref="category/java/multithreading.xml/DontCallThreadRun"/>
205+
<rule ref="category/java/multithreading.xml/DoubleCheckedLocking"/>
206+
<rule ref="category/java/multithreading.xml/NonThreadSafeSingleton"/>
207+
<rule ref="category/java/multithreading.xml/UseNotifyAllInsteadOfNotify"/>
208+
209+
<rule ref="category/java/performance.xml/BigIntegerInstantiation"/>
210+
<rule ref="category/java/performance.xml/BooleanInstantiation"/>
211+
<rule ref="category/java/performance.xml/OptimizableToArrayCall"/>
212+
<rule ref="category/java/performance.xml/TooFewBranchesForASwitchStatement"/>
213+
</ruleset>

0 commit comments

Comments
 (0)