Skip to content

Commit 9ac9f9a

Browse files
authored
Develop Version 0.0.1 (#1)
1 parent 65eae4a commit 9ac9f9a

File tree

18 files changed

+971
-2
lines changed

18 files changed

+971
-2
lines changed

.github/workflows/maven_ci_cd.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3+
4+
name: build
5+
6+
on:
7+
push:
8+
branches:
9+
- master
10+
pull_request:
11+
branches:
12+
- master
13+
14+
jobs:
15+
build_test_and_analyze:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
23+
24+
- name: Set up JDK 11
25+
uses: actions/setup-java@v3
26+
with:
27+
java-version: '11'
28+
distribution: 'temurin'
29+
cache: maven
30+
31+
- name: Build with Maven
32+
run: mvn -B package --file pom.xml -DskipTests
33+
34+
- name: Run Unit Test
35+
run: mvn test --file pom.xml
36+
37+
- name: Cache SonarCloud packages
38+
uses: actions/cache@v1
39+
with:
40+
path: ~/.sonar/cache
41+
key: ${{ runner.os }}-sonar
42+
restore-keys: ${{ runner.os }}-sonar
43+
44+
- name: Cache Maven packages
45+
uses: actions/cache@v1
46+
with:
47+
path: ~/.m2
48+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
49+
restore-keys: ${{ runner.os }}-m2
50+
51+
- name: Analyze SonarCloud
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
54+
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
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
2+
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
3+
4+
name: publish
5+
6+
on:
7+
release:
8+
types: [created]
9+
10+
jobs:
11+
publish:
12+
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Set up JDK 11
21+
uses: actions/setup-java@v3
22+
with:
23+
java-version: '11'
24+
distribution: 'temurin'
25+
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
26+
settings-path: ${{ github.workspace }} # location for the settings.xml file
27+
28+
- name: Build with Maven
29+
run: mvn -B package --file pom.xml -DskipTests
30+
31+
- name: Run Unit Test
32+
run: mvn test --file pom.xml
33+
34+
- name: Publish to GitHub Packages
35+
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
36+
env:
37+
GITHUB_TOKEN: ${{ github.token }}

.github/workflows/sonarcloud.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: SonarCloud
2+
on:
3+
push:
4+
branches:
5+
- '**' # matches every branch
6+
- '!master' # excludes master
7+
paths-ignore:
8+
- '**/README.md'
9+
# - '.github/workflows/**'
10+
11+
jobs:
12+
sonarcloud:
13+
name: SonarCloud
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
with:
18+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
19+
20+
- name: Set up JDK 11
21+
uses: actions/setup-java@v1
22+
with:
23+
java-version: 11
24+
25+
- name: Run Unit Test
26+
run: mvn test --file pom.xml
27+
28+
- name: Cache SonarCloud packages
29+
uses: actions/cache@v1
30+
with:
31+
path: ~/.sonar/cache
32+
key: ${{ runner.os }}-sonar
33+
restore-keys: ${{ runner.os }}-sonar
34+
35+
- name: Cache Maven packages
36+
uses: actions/cache@v1
37+
with:
38+
path: ~/.m2
39+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
40+
restore-keys: ${{ runner.os }}-m2
41+
42+
- name: Build and analyze
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
45+
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

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@
2121

2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
24+
25+
.classpath
26+
.factorypath
27+
.project
28+
.settings
29+
target/

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,32 @@
1-
# utils-annotations
2-
Project with utils annotations for Java
1+
# Java Util Validation Lib
2+
3+
### Quality Status
4+
[![build](https://github.com/bvilela/java-util-validation-lib/actions/workflows/maven_ci_cd.yml/badge.svg?branch=master)](https://github.com/bvilela/java-util-validation-lib/actions/workflows/maven_ci_cd.yml)
5+
[![publish](https://github.com/bvilela/java-util-validation-lib/actions/workflows/maven_ci_cd_publish.yml/badge.svg)](https://github.com/bvilela/java-util-validation-lib/actions/workflows/maven_ci_cd_publish.yml)
6+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=bvilela_java-util-validation-lib&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=bvilela_java-util-validation-lib)
7+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=bvilela_java-util-validation-lib&metric=coverage)](https://sonarcloud.io/summary/new_code?id=bvilela_java-util-validation-lib)
8+
9+
### Repository Statistics
10+
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=bvilela_java-util-validation-lib&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=bvilela_java-util-validation-lib)
11+
![GitHub repo size](https://img.shields.io/github/repo-size/bvilela/java-util-validation-lib)
12+
![GitHub language count](https://img.shields.io/github/languages/count/bvilela/java-util-validation-lib)
13+
![GitHub open issues](https://img.shields.io/github/issues-raw/bvilela/java-util-validation-lib)
14+
![GitHub open pull requests](https://img.shields.io/github/issues-pr/bvilela/java-util-validation-lib)
15+
<!--![GitHub forks](https://img.shields.io/github/forks/bvilela/java-util-validation-lib)-->
16+
17+
## Summary
18+
Project with validations utils for Java based in javax and Gson.
19+
20+
## Technologies
21+
* Maven
22+
* Java 8
23+
* [Lombok](https://projectlombok.org/)
24+
* Gson 2.9.0
25+
* Static Code Analysis: [SonarCloud](https://sonarcloud.io/)
26+
27+
## GitHub Action
28+
* Build and Test Java with Maven (branch master)
29+
* Analyze SonarCloud (branch master)
30+
* Publish on GitHub Packages (tag/release)
31+
32+
[⬆ Voltar ao topo](#java-util-validation-lib)<br>

pom.xml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>com.bvilela.lib</groupId>
9+
<artifactId>java-util-validation</artifactId>
10+
<version>0.0.1</version>
11+
<name>java-util-validation</name>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
16+
<maven.compiler.source>11</maven.compiler.source>
17+
<maven.compiler.target>11</maven.compiler.target>
18+
<sonar.organization>bvilela</sonar.organization>
19+
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
20+
</properties>
21+
22+
<dependencies>
23+
<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
24+
<dependency>
25+
<groupId>javax.validation</groupId>
26+
<artifactId>validation-api</artifactId>
27+
<version>2.0.1.Final</version>
28+
</dependency>
29+
<!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator -->
30+
<dependency>
31+
<groupId>org.hibernate.validator</groupId>
32+
<artifactId>hibernate-validator</artifactId>
33+
<version>6.2.3.Final</version>
34+
</dependency>
35+
<!-- API, java.xml.bind module -->
36+
<dependency>
37+
<groupId>jakarta.xml.bind</groupId>
38+
<artifactId>jakarta.xml.bind-api</artifactId>
39+
<version>2.3.2</version>
40+
</dependency>
41+
<!-- Runtime, com.sun.xml.bind module -->
42+
<dependency>
43+
<groupId>org.glassfish.jaxb</groupId>
44+
<artifactId>jaxb-runtime</artifactId>
45+
<version>2.3.2</version>
46+
</dependency>
47+
<!-- https://mvnrepository.com/artifact/javax.el/javax.el-api -->
48+
<dependency>
49+
<groupId>javax.el</groupId>
50+
<artifactId>javax.el-api</artifactId>
51+
<version>3.0.0</version>
52+
</dependency>
53+
<!-- https://mvnrepository.com/artifact/org.glassfish/javax.el -->
54+
<dependency>
55+
<groupId>org.glassfish</groupId>
56+
<artifactId>javax.el</artifactId>
57+
<version>3.0.0</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.projectlombok</groupId>
61+
<artifactId>lombok</artifactId>
62+
<version>1.18.24</version>
63+
<scope>provided</scope>
64+
</dependency>
65+
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
66+
<dependency>
67+
<groupId>org.junit.jupiter</groupId>
68+
<artifactId>junit-jupiter-engine</artifactId>
69+
<version>5.8.2</version>
70+
<scope>test</scope>
71+
</dependency>
72+
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
73+
<dependency>
74+
<groupId>com.google.code.gson</groupId>
75+
<artifactId>gson</artifactId>
76+
<version>2.9.0</version>
77+
</dependency>
78+
</dependencies>
79+
<build>
80+
<plugins>
81+
<plugin>
82+
<groupId>org.apache.maven.plugins</groupId>
83+
<artifactId>maven-surefire-plugin</artifactId>
84+
<version>2.19.1</version>
85+
<dependencies>
86+
<dependency>
87+
<groupId>org.junit.platform</groupId>
88+
<artifactId>junit-platform-surefire-provider</artifactId>
89+
<version>1.1.0</version>
90+
</dependency>
91+
<dependency>
92+
<groupId>org.junit.jupiter</groupId>
93+
<artifactId>junit-jupiter-engine</artifactId>
94+
<version>5.8.2</version>
95+
</dependency>
96+
</dependencies>
97+
</plugin>
98+
<plugin>
99+
<groupId>org.jacoco</groupId>
100+
<artifactId>jacoco-maven-plugin</artifactId>
101+
<version>0.8.8</version>
102+
<configuration>
103+
<output>file</output>
104+
<append>true</append>
105+
</configuration>
106+
<executions>
107+
<execution>
108+
<id>default-prepare-agent</id>
109+
<goals>
110+
<goal>prepare-agent</goal>
111+
</goals>
112+
</execution>
113+
<execution>
114+
<id>jacoco-report</id>
115+
<phase>test</phase>
116+
<goals>
117+
<goal>report</goal>
118+
</goals>
119+
</execution>
120+
</executions>
121+
</plugin>
122+
</plugins>
123+
</build>
124+
</project>

sonar-project.properties

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
sonar.organization=bvilela
2+
sonar.projectKey=java-utils-annotations
3+
sonar.projectName=Java Utils Annotations
4+
sonar.projectVersion=0.0.1
5+
6+
sonar.sourceEncoding=UTF-8
7+
sonar.language=java
8+
sonar.java.source=11
9+
10+
sonar.sources=src/main/java
11+
sonar.exclusions=target/**, **/domain/*
12+
sonar.tests=src/test
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.bvilela.utils;
2+
3+
import java.lang.reflect.Field;
4+
import java.lang.reflect.InvocationTargetException;
5+
import java.lang.reflect.Method;
6+
import java.time.LocalDate;
7+
import java.util.Locale;
8+
import java.util.Objects;
9+
10+
import com.bvilela.utils.annotation.javax.ValidParseDate;
11+
12+
public final class AnnotationUtils {
13+
14+
private AnnotationUtils() {
15+
}
16+
17+
public static <T> void parseDatesDto(T dto) throws NoSuchMethodException, SecurityException, IllegalAccessException,
18+
IllegalArgumentException, InvocationTargetException {
19+
String setMethodNameConverted = null;
20+
21+
for (Field field : dto.getClass().getDeclaredFields()) {
22+
ValidParseDate annotation = field.getDeclaredAnnotation(ValidParseDate.class);
23+
24+
if (Objects.nonNull(annotation) && annotation.parse()) {
25+
String fieldName = AppUtils.capitalize(field.getName());
26+
String getMethodName = "get".concat(fieldName);
27+
Method getMethod = dto.getClass().getMethod(getMethodName);
28+
29+
String value = (String) getMethod.invoke(dto);
30+
Locale locale = AppUtils.getLocale(annotation.locale());
31+
LocalDate valueConverted = AppUtils.parse(value, annotation.pattern(), locale);
32+
33+
setMethodNameConverted = "set".concat(fieldName).concat("Converted");
34+
Method setMethodConverted = dto.getClass().getMethod(setMethodNameConverted, LocalDate.class);
35+
setMethodConverted.invoke(dto, valueConverted);
36+
}
37+
}
38+
}
39+
40+
}

0 commit comments

Comments
 (0)