Skip to content

Commit

Permalink
Merge branch 'master' into refactor-geracao-dv-titulo
Browse files Browse the repository at this point in the history
  • Loading branch information
angeliski authored Feb 13, 2025
2 parents 3ecb770 + 81f41e2 commit c726bac
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 53 deletions.
102 changes: 66 additions & 36 deletions .github/workflows/sonatype-publish.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,77 @@
name: Maven Release

name: Maven Release

on:
workflow_dispatch:
inputs:
releaseVersion:
description: "Define the release version"
required: true
default: ""
developmentVersion:
description: "Define the snapshot version"
required: true
default: ""

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: 'Cache Maven packages'
uses: actions/cache@v4
with:
path: ~/.m2
key: 'cache'
restore-keys: 'cache'

- name: Setup Java JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 11

- name: 'Build with Maven'
run: mvn -B install --file pom.xml

- name: Release
uses: qcastel/github-actions-maven-release@master
env:
JAVA_HOME: /usr/lib/jvm/java-11-openjdk/
with:
git-release-bot-name: "angeliski"
git-release-bot-email: "[email protected]"
- uses: actions/checkout@v4
- name: Configure Git User
run: |
git config user.email "[email protected]"
git config user.name "GitHub Actions"
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Import SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
name: id_rsa
known_hosts: unnecessary_just_github

maven-args: "-DskipTests -PsonatypeDeploy"
maven-servers: ${{ secrets.MVN_REPO_SERVERS }}
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Import GPG Key
uses: crazy-max/[email protected]
with:
gpg_private_key: ${{ secrets.GPG_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
- name: 'Cache Maven packages'
uses: actions/cache@v4
with:
path: ~/.m2
key: 'cache'
restore-keys: 'cache'

gpg-enabled: true
gpg-key-id: ${{ secrets.GPG_KEY_ID }}
gpg-key: ${{ secrets.GPG_KEY }}
gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }}
- name: Setup Java JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 11

- name: 'Remove Snapshots Before Caching'
run: find ~/.m2 -name '*SNAPSHOT' | xargs rm -Rf
- name: 'Build with Maven'
run: mvn -B install --file pom.xml

- name: Verify Whether a Release is Ready
id: release
shell: bash
run: |
if [ "${{ github.event.inputs.releaseVersion }}" != "" ] && [ "${{ github.event.inputs.developmentVersion }}" != "" ]; then
echo "auto_release=true" >> $GITHUB_ENV
else
echo "auto_release=false" >> $GITHUB_ENV
fi
- name: Release With Maven
run: |
mvn -B -U \
-PsonatypeDeploy \
release:prepare \
release:perform \
javadoc:jar \
source:jar \
-s settings.xml \
-Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }} \
-DreleaseVersion=${{ github.event.inputs.releaseVersion }} \
-DdevelopmentVersion=${{ github.event.inputs.developmentVersion }}
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
2 changes: 1 addition & 1 deletion examples/faces-example-1x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>br.com.caelum.stella</groupId>
<artifactId>caelum-stella</artifactId>
<version>2.1.7-SNAPSHOT</version>
<version>2.1.8-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>faces-example-1x</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/faces-example-2x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>br.com.caelum.stella</groupId>
<artifactId>caelum-stella</artifactId>
<version>2.1.7-SNAPSHOT</version>
<version>2.1.8-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>faces-example-2x</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/hibernate-persistence-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>br.com.caelum.stella</groupId>
<artifactId>caelum-stella</artifactId>
<version>2.1.7-SNAPSHOT</version>
<version>2.1.8-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>hibernate-persistence-example</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/vraptor-validator-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>br.com.caelum.stella</groupId>
<artifactId>caelum-stella</artifactId>
<version>2.1.7-SNAPSHOT</version>
<version>2.1.8-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>vraptor-validator-example</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>br.com.caelum.stella</groupId>
<artifactId>caelum-stella</artifactId>
<packaging>pom</packaging>
<version>2.1.7-SNAPSHOT</version>
<version>2.1.8-SNAPSHOT</version>
<name>Caelum Stella</name>
<description>
Caelum Stella is a set of validators, formatters and converters
Expand Down Expand Up @@ -507,6 +507,7 @@
<connection>scm:git:git://github.com/caelum/caelum-stella</connection>
<developerConnection>scm:git:[email protected]:caelum/caelum-stella.git</developerConnection>
<url>https://github.com/caelum/caelum-stella</url>
<tag>HEAD</tag>
</scm>

<mailingLists>
Expand Down
12 changes: 12 additions & 0 deletions settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<server>
<id>ossrh</id>
<username>${env.MAVEN_USERNAME}</username>
<password>${env.MAVEN_PASSWORD}</password>
</server>
</servers>
</settings>
2 changes: 1 addition & 1 deletion stella-bean-validation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>br.com.caelum.stella</groupId>
<artifactId>caelum-stella</artifactId>
<version>2.1.7-SNAPSHOT</version>
<version>2.1.8-SNAPSHOT</version>
</parent>
<artifactId>caelum-stella-bean-validation</artifactId>
<packaging>jar</packaging>
Expand Down
4 changes: 2 additions & 2 deletions stella-boleto/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>br.com.caelum.stella</groupId>
<artifactId>caelum-stella</artifactId>
<version>2.1.7-SNAPSHOT</version>
<version>2.1.8-SNAPSHOT</version>
</parent>

<artifactId>caelum-stella-boleto</artifactId>
Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>br.com.caelum.stella</groupId>
<artifactId>caelum-stella-core</artifactId>
<version>2.1.7-SNAPSHOT</version>
<version>2.1.8-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion stella-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>br.com.caelum.stella</groupId>
<artifactId>caelum-stella</artifactId>
<version>2.1.7-SNAPSHOT</version>
<version>2.1.8-SNAPSHOT</version>
</parent>
<artifactId>caelum-stella-core</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*/
public class DigitoPara {

private static final int ZERO_ASCII = 48;
private LinkedList<Integer> numero;
private List<Integer> multiplicadores = new ArrayList<Integer>();
private boolean complementar;
Expand All @@ -56,7 +57,7 @@ public DigitoPara(String trecho) {
this.numero = new LinkedList<Integer>();
char[] digitos = trecho.toCharArray();
for (char digito : digitos) {
this.numero.add(Character.getNumericValue(digito));
this.numero.add(((int) digito) - ZERO_ASCII);
}
Collections.reverse(numero);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
*/
public class CNPJValidator implements Validator<String> {

public static final Pattern FORMATED = Pattern.compile("(\\d{2})[.](\\d{3})[.](\\d{3})/(\\d{4})-(\\d{2})");
public static final Pattern UNFORMATED = Pattern.compile("(\\d{2})(\\d{3})(\\d{3})(\\d{4})(\\d{2})");
public static final Pattern FORMATED = Pattern.compile(
"([0-9A-Z]{2})[.]([0-9A-Z]{3})[.]([0-9A-Z]{3})/([0-9A-Z]{4})-([0-9A-Z]{2})");
public static final Pattern UNFORMATED = Pattern.compile(
"([0-9A-Z]{2})([0-9A-Z]{3})([0-9A-Z]{3})([0-9A-Z]{4})([0-9A-Z]{2})");

private boolean isFormatted = false;
private boolean isIgnoringRepeatedDigits;
Expand Down Expand Up @@ -97,8 +99,8 @@ private List<ValidationMessage> getInvalidValues(String cnpj) {
errors.add(messageProducer.getMessage(CNPJError.INVALID_DIGITS));
return errors;
}
if(unformatedCNPJ.length() != 14 || !unformatedCNPJ.matches("[0-9]*")){

if (unformatedCNPJ.length() != 14 || !unformatedCNPJ.matches("[0-9A-Z]*")) {
errors.add(messageProducer.getMessage(CNPJError.INVALID_DIGITS));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public class CNPJValidatorTest {
private final String validString = "26.637.142/0001-58";
private final String validStringNotFormatted = "26637142000158";

private final String validStringAlpha = "12.ABC.345/01DE-35";
private final String validStringAlphaNotFormatted = "12ABC34501DE35";

private final String firstCheckDigitWrongNotFormatted = "26637142000168";
private final String alphaFirstCheckDigitWrongNotFormatted = "12ABC34501DE45";

@Test
public void shouldHaveDefaultConstructorThatUsesSimpleMessageProducerAndAssumesThatStringIsNotFormatted() {
Expand All @@ -34,6 +38,14 @@ public void shouldHaveDefaultConstructorThatUsesSimpleMessageProducerAndAssumesT
InvalidStateException invalidStateException = (InvalidStateException) e;
assertMessage(invalidStateException, INVALID_CHECK_DIGITS);
}

try {
new CNPJValidator().assertValid(alphaFirstCheckDigitWrongNotFormatted);
fail("Test expected to throw exception");
} catch (InvalidStateException e) {
InvalidStateException invalidStateException = (InvalidStateException) e;
assertMessage(invalidStateException, INVALID_CHECK_DIGITS);
}
}

private void assertMessage(InvalidStateException invalidStateException, String expected) {
Expand Down Expand Up @@ -87,6 +99,7 @@ public void shouldValidateValidCNPJ() {
validator.assertValid("63025530002409");
validator.assertValid("61519128000150");
validator.assertValid("68745386000102");
validator.assertValid("12ABC34501DE35");
}

@Test
Expand Down Expand Up @@ -186,20 +199,29 @@ public void shouldBeEligibleDefaultConstructor() {
final CNPJValidator cnpjValidator = new CNPJValidator();
assertTrue(cnpjValidator.isEligible(validStringNotFormatted));
assertFalse(cnpjValidator.isEligible(validString));

assertTrue(cnpjValidator.isEligible(validStringAlphaNotFormatted));
assertFalse(cnpjValidator.isEligible(validStringAlpha));
}

@Test
public void shouldBeEligibleConstructorNotFormatted() {
final CNPJValidator cnpjValidator = new CNPJValidator(false);
assertTrue(cnpjValidator.isEligible(validStringNotFormatted));
assertFalse(cnpjValidator.isEligible(validString));

assertTrue(cnpjValidator.isEligible(validStringAlphaNotFormatted));
assertFalse(cnpjValidator.isEligible(validStringAlpha));
}

@Test
public void shouldBeEligibleConstructorFormatted() {
final CNPJValidator cnpjValidator = new CNPJValidator(true);
assertFalse(cnpjValidator.isEligible(validStringNotFormatted));
assertTrue(cnpjValidator.isEligible(validString));

assertFalse(cnpjValidator.isEligible(validStringAlphaNotFormatted));
assertTrue(cnpjValidator.isEligible(validStringAlpha));
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion stella-faces/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>br.com.caelum.stella</groupId>
<artifactId>caelum-stella</artifactId>
<version>2.1.7-SNAPSHOT</version>
<version>2.1.8-SNAPSHOT</version>
</parent>

<artifactId>caelum-stella-faces</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion stella-frete/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>br.com.caelum.stella</groupId>
<artifactId>caelum-stella</artifactId>
<version>2.1.7-SNAPSHOT</version>
<version>2.1.8-SNAPSHOT</version>
</parent>

<artifactId>caelum-stella-frete</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion stella-hibernate-user-types/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>br.com.caelum.stella</groupId>
<artifactId>caelum-stella</artifactId>
<version>2.1.7-SNAPSHOT</version>
<version>2.1.8-SNAPSHOT</version>
</parent>
<artifactId>caelum-stella-hibernate-user-types</artifactId>
<packaging>jar</packaging>
Expand Down

0 comments on commit c726bac

Please sign in to comment.