From 18da853a3beca8710a1ea6e37d644d647caf972b Mon Sep 17 00:00:00 2001 From: Rogerio Angeliski Date: Fri, 8 Nov 2024 19:24:41 -0300 Subject: [PATCH 1/4] change release mode (#304) --- .github/workflows/sonatype-publish.yml | 102 ++++++++++++++++--------- settings.xml | 12 +++ 2 files changed, 78 insertions(+), 36 deletions(-) create mode 100644 settings.xml diff --git a/.github/workflows/sonatype-publish.yml b/.github/workflows/sonatype-publish.yml index 1b8397fb..0b3c25a3 100644 --- a/.github/workflows/sonatype-publish.yml +++ b/.github/workflows/sonatype-publish.yml @@ -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: "angeliski@hotmail.com" + - uses: actions/checkout@v4 + - name: Configure Git User + run: | + git config user.email "actions@github.com" + 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/ghaction-import-gpg@v5.0.0 + 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 \ No newline at end of file + - 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 }} diff --git a/settings.xml b/settings.xml new file mode 100644 index 00000000..0a08dd1e --- /dev/null +++ b/settings.xml @@ -0,0 +1,12 @@ + + + + + ossrh + ${env.MAVEN_USERNAME} + ${env.MAVEN_PASSWORD} + + + \ No newline at end of file From e825abd682422c6006a0573e50e5fdd9b1a94d05 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 8 Nov 2024 22:27:50 +0000 Subject: [PATCH 2/4] [ci skip] prepare release 2.1.7 --- examples/faces-example-1x/pom.xml | 2 +- examples/faces-example-2x/pom.xml | 2 +- examples/hibernate-persistence-example/pom.xml | 2 +- examples/vraptor-validator-example/pom.xml | 2 +- pom.xml | 3 ++- stella-bean-validation/pom.xml | 2 +- stella-boleto/pom.xml | 4 ++-- stella-core/pom.xml | 2 +- stella-faces/pom.xml | 2 +- stella-frete/pom.xml | 2 +- stella-hibernate-user-types/pom.xml | 2 +- 11 files changed, 13 insertions(+), 12 deletions(-) diff --git a/examples/faces-example-1x/pom.xml b/examples/faces-example-1x/pom.xml index 9ed14b26..01bcbb11 100644 --- a/examples/faces-example-1x/pom.xml +++ b/examples/faces-example-1x/pom.xml @@ -4,7 +4,7 @@ br.com.caelum.stella caelum-stella - 2.1.7-SNAPSHOT + 2.1.7 ../../pom.xml faces-example-1x diff --git a/examples/faces-example-2x/pom.xml b/examples/faces-example-2x/pom.xml index 826864d5..f2d4b446 100644 --- a/examples/faces-example-2x/pom.xml +++ b/examples/faces-example-2x/pom.xml @@ -4,7 +4,7 @@ br.com.caelum.stella caelum-stella - 2.1.7-SNAPSHOT + 2.1.7 ../../pom.xml faces-example-2x diff --git a/examples/hibernate-persistence-example/pom.xml b/examples/hibernate-persistence-example/pom.xml index f8a407e2..54f51074 100644 --- a/examples/hibernate-persistence-example/pom.xml +++ b/examples/hibernate-persistence-example/pom.xml @@ -4,7 +4,7 @@ br.com.caelum.stella caelum-stella - 2.1.7-SNAPSHOT + 2.1.7 ../../pom.xml hibernate-persistence-example diff --git a/examples/vraptor-validator-example/pom.xml b/examples/vraptor-validator-example/pom.xml index 952848bf..cc39df26 100644 --- a/examples/vraptor-validator-example/pom.xml +++ b/examples/vraptor-validator-example/pom.xml @@ -3,7 +3,7 @@ br.com.caelum.stella caelum-stella - 2.1.7-SNAPSHOT + 2.1.7 ../../pom.xml vraptor-validator-example diff --git a/pom.xml b/pom.xml index 96d0f0f2..2a4c3a87 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ br.com.caelum.stella caelum-stella pom - 2.1.7-SNAPSHOT + 2.1.7 Caelum Stella Caelum Stella is a set of validators, formatters and converters @@ -507,6 +507,7 @@ scm:git:git://github.com/caelum/caelum-stella scm:git:git@github.com:caelum/caelum-stella.git https://github.com/caelum/caelum-stella + 2.1.7 diff --git a/stella-bean-validation/pom.xml b/stella-bean-validation/pom.xml index 6ba899ee..ba805221 100644 --- a/stella-bean-validation/pom.xml +++ b/stella-bean-validation/pom.xml @@ -3,7 +3,7 @@ br.com.caelum.stella caelum-stella - 2.1.7-SNAPSHOT + 2.1.7 caelum-stella-bean-validation jar diff --git a/stella-boleto/pom.xml b/stella-boleto/pom.xml index af45daa0..2e476d10 100644 --- a/stella-boleto/pom.xml +++ b/stella-boleto/pom.xml @@ -4,7 +4,7 @@ br.com.caelum.stella caelum-stella - 2.1.7-SNAPSHOT + 2.1.7 caelum-stella-boleto @@ -16,7 +16,7 @@ br.com.caelum.stella caelum-stella-core - 2.1.7-SNAPSHOT + 2.1.7 diff --git a/stella-core/pom.xml b/stella-core/pom.xml index f9c3d3e8..ffe7d622 100644 --- a/stella-core/pom.xml +++ b/stella-core/pom.xml @@ -3,7 +3,7 @@ br.com.caelum.stella caelum-stella - 2.1.7-SNAPSHOT + 2.1.7 caelum-stella-core jar diff --git a/stella-faces/pom.xml b/stella-faces/pom.xml index d274ba30..a4b3e29e 100644 --- a/stella-faces/pom.xml +++ b/stella-faces/pom.xml @@ -4,7 +4,7 @@ br.com.caelum.stella caelum-stella - 2.1.7-SNAPSHOT + 2.1.7 caelum-stella-faces diff --git a/stella-frete/pom.xml b/stella-frete/pom.xml index 9ddae80e..b7c8df7e 100644 --- a/stella-frete/pom.xml +++ b/stella-frete/pom.xml @@ -3,7 +3,7 @@ br.com.caelum.stella caelum-stella - 2.1.7-SNAPSHOT + 2.1.7 caelum-stella-frete diff --git a/stella-hibernate-user-types/pom.xml b/stella-hibernate-user-types/pom.xml index 5d048470..432dc562 100644 --- a/stella-hibernate-user-types/pom.xml +++ b/stella-hibernate-user-types/pom.xml @@ -3,7 +3,7 @@ br.com.caelum.stella caelum-stella - 2.1.7-SNAPSHOT + 2.1.7 caelum-stella-hibernate-user-types jar From 89f561daee2bd5730f9a6bbb94d438b68c39fd79 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 8 Nov 2024 22:27:51 +0000 Subject: [PATCH 3/4] [ci skip] prepare for next development iteration --- examples/faces-example-1x/pom.xml | 2 +- examples/faces-example-2x/pom.xml | 2 +- examples/hibernate-persistence-example/pom.xml | 2 +- examples/vraptor-validator-example/pom.xml | 2 +- pom.xml | 4 ++-- stella-bean-validation/pom.xml | 2 +- stella-boleto/pom.xml | 4 ++-- stella-core/pom.xml | 2 +- stella-faces/pom.xml | 2 +- stella-frete/pom.xml | 2 +- stella-hibernate-user-types/pom.xml | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/faces-example-1x/pom.xml b/examples/faces-example-1x/pom.xml index 01bcbb11..2f871c07 100644 --- a/examples/faces-example-1x/pom.xml +++ b/examples/faces-example-1x/pom.xml @@ -4,7 +4,7 @@ br.com.caelum.stella caelum-stella - 2.1.7 + 2.1.8-SNAPSHOT ../../pom.xml faces-example-1x diff --git a/examples/faces-example-2x/pom.xml b/examples/faces-example-2x/pom.xml index f2d4b446..cb0439e4 100644 --- a/examples/faces-example-2x/pom.xml +++ b/examples/faces-example-2x/pom.xml @@ -4,7 +4,7 @@ br.com.caelum.stella caelum-stella - 2.1.7 + 2.1.8-SNAPSHOT ../../pom.xml faces-example-2x diff --git a/examples/hibernate-persistence-example/pom.xml b/examples/hibernate-persistence-example/pom.xml index 54f51074..6dc0497b 100644 --- a/examples/hibernate-persistence-example/pom.xml +++ b/examples/hibernate-persistence-example/pom.xml @@ -4,7 +4,7 @@ br.com.caelum.stella caelum-stella - 2.1.7 + 2.1.8-SNAPSHOT ../../pom.xml hibernate-persistence-example diff --git a/examples/vraptor-validator-example/pom.xml b/examples/vraptor-validator-example/pom.xml index cc39df26..8a2ba3fa 100644 --- a/examples/vraptor-validator-example/pom.xml +++ b/examples/vraptor-validator-example/pom.xml @@ -3,7 +3,7 @@ br.com.caelum.stella caelum-stella - 2.1.7 + 2.1.8-SNAPSHOT ../../pom.xml vraptor-validator-example diff --git a/pom.xml b/pom.xml index 2a4c3a87..e3ee138a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ br.com.caelum.stella caelum-stella pom - 2.1.7 + 2.1.8-SNAPSHOT Caelum Stella Caelum Stella is a set of validators, formatters and converters @@ -507,7 +507,7 @@ scm:git:git://github.com/caelum/caelum-stella scm:git:git@github.com:caelum/caelum-stella.git https://github.com/caelum/caelum-stella - 2.1.7 + HEAD diff --git a/stella-bean-validation/pom.xml b/stella-bean-validation/pom.xml index ba805221..4082bd5e 100644 --- a/stella-bean-validation/pom.xml +++ b/stella-bean-validation/pom.xml @@ -3,7 +3,7 @@ br.com.caelum.stella caelum-stella - 2.1.7 + 2.1.8-SNAPSHOT caelum-stella-bean-validation jar diff --git a/stella-boleto/pom.xml b/stella-boleto/pom.xml index 2e476d10..a7cc5a46 100644 --- a/stella-boleto/pom.xml +++ b/stella-boleto/pom.xml @@ -4,7 +4,7 @@ br.com.caelum.stella caelum-stella - 2.1.7 + 2.1.8-SNAPSHOT caelum-stella-boleto @@ -16,7 +16,7 @@ br.com.caelum.stella caelum-stella-core - 2.1.7 + 2.1.8-SNAPSHOT diff --git a/stella-core/pom.xml b/stella-core/pom.xml index ffe7d622..8fd28476 100644 --- a/stella-core/pom.xml +++ b/stella-core/pom.xml @@ -3,7 +3,7 @@ br.com.caelum.stella caelum-stella - 2.1.7 + 2.1.8-SNAPSHOT caelum-stella-core jar diff --git a/stella-faces/pom.xml b/stella-faces/pom.xml index a4b3e29e..0713b703 100644 --- a/stella-faces/pom.xml +++ b/stella-faces/pom.xml @@ -4,7 +4,7 @@ br.com.caelum.stella caelum-stella - 2.1.7 + 2.1.8-SNAPSHOT caelum-stella-faces diff --git a/stella-frete/pom.xml b/stella-frete/pom.xml index b7c8df7e..988285a0 100644 --- a/stella-frete/pom.xml +++ b/stella-frete/pom.xml @@ -3,7 +3,7 @@ br.com.caelum.stella caelum-stella - 2.1.7 + 2.1.8-SNAPSHOT caelum-stella-frete diff --git a/stella-hibernate-user-types/pom.xml b/stella-hibernate-user-types/pom.xml index 432dc562..89d320d0 100644 --- a/stella-hibernate-user-types/pom.xml +++ b/stella-hibernate-user-types/pom.xml @@ -3,7 +3,7 @@ br.com.caelum.stella caelum-stella - 2.1.7 + 2.1.8-SNAPSHOT caelum-stella-hibernate-user-types jar From 81f41e2eb7940500633ddb0c703e75a81daddbf5 Mon Sep 17 00:00:00 2001 From: Danilo dos Santos Andrade Date: Wed, 12 Feb 2025 22:34:41 -0300 Subject: [PATCH 4/4] =?UTF-8?q?Adicionar=20suporte=20a=20CNPJ=20Alpha=20nu?= =?UTF-8?q?m=C3=A9ricos=20(#305)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Adicionado suporte para CNPJ alpha numérico * test: complementado tests com CNPJ Alpha numérico --- .../java/br/com/caelum/stella/DigitoPara.java | 3 ++- .../stella/validation/CNPJValidator.java | 10 +++++---- .../stella/validation/CNPJValidatorTest.java | 22 +++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/stella-core/src/main/java/br/com/caelum/stella/DigitoPara.java b/stella-core/src/main/java/br/com/caelum/stella/DigitoPara.java index e66914c6..9f3c8314 100644 --- a/stella-core/src/main/java/br/com/caelum/stella/DigitoPara.java +++ b/stella-core/src/main/java/br/com/caelum/stella/DigitoPara.java @@ -35,6 +35,7 @@ */ public class DigitoPara { + private static final int ZERO_ASCII = 48; private LinkedList numero; private List multiplicadores = new ArrayList(); private boolean complementar; @@ -56,7 +57,7 @@ public DigitoPara(String trecho) { this.numero = new LinkedList(); char[] digitos = trecho.toCharArray(); for (char digito : digitos) { - this.numero.add(Character.getNumericValue(digito)); + this.numero.add(((int) digito) - ZERO_ASCII); } Collections.reverse(numero); } diff --git a/stella-core/src/main/java/br/com/caelum/stella/validation/CNPJValidator.java b/stella-core/src/main/java/br/com/caelum/stella/validation/CNPJValidator.java index fc6429b3..0fa3728b 100644 --- a/stella-core/src/main/java/br/com/caelum/stella/validation/CNPJValidator.java +++ b/stella-core/src/main/java/br/com/caelum/stella/validation/CNPJValidator.java @@ -19,8 +19,10 @@ */ public class CNPJValidator implements Validator { - 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; @@ -97,8 +99,8 @@ private List 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)); } diff --git a/stella-core/src/test/java/br/com/caelum/stella/validation/CNPJValidatorTest.java b/stella-core/src/test/java/br/com/caelum/stella/validation/CNPJValidatorTest.java index c2b28dd6..7070b0d2 100644 --- a/stella-core/src/test/java/br/com/caelum/stella/validation/CNPJValidatorTest.java +++ b/stella-core/src/test/java/br/com/caelum/stella/validation/CNPJValidatorTest.java @@ -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() { @@ -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) { @@ -87,6 +99,7 @@ public void shouldValidateValidCNPJ() { validator.assertValid("63025530002409"); validator.assertValid("61519128000150"); validator.assertValid("68745386000102"); + validator.assertValid("12ABC34501DE35"); } @Test @@ -186,6 +199,9 @@ 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 @@ -193,6 +209,9 @@ 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 @@ -200,6 +219,9 @@ 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