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/examples/faces-example-1x/pom.xml b/examples/faces-example-1x/pom.xml
index 9ed14b26..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-SNAPSHOT
+ 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 826864d5..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-SNAPSHOT
+ 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 f8a407e2..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-SNAPSHOT
+ 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 952848bf..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-SNAPSHOT
+ 2.1.8-SNAPSHOT
../../pom.xml
vraptor-validator-example
diff --git a/pom.xml b/pom.xml
index 96d0f0f2..e3ee138a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
br.com.caelum.stella
caelum-stella
pom
- 2.1.7-SNAPSHOT
+ 2.1.8-SNAPSHOT
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
+ HEAD
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
diff --git a/stella-bean-validation/pom.xml b/stella-bean-validation/pom.xml
index 6ba899ee..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-SNAPSHOT
+ 2.1.8-SNAPSHOT
caelum-stella-bean-validation
jar
diff --git a/stella-boleto/pom.xml b/stella-boleto/pom.xml
index af45daa0..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-SNAPSHOT
+ 2.1.8-SNAPSHOT
caelum-stella-boleto
@@ -16,7 +16,7 @@
br.com.caelum.stella
caelum-stella-core
- 2.1.7-SNAPSHOT
+ 2.1.8-SNAPSHOT
diff --git a/stella-core/pom.xml b/stella-core/pom.xml
index f9c3d3e8..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-SNAPSHOT
+ 2.1.8-SNAPSHOT
caelum-stella-core
jar
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
diff --git a/stella-faces/pom.xml b/stella-faces/pom.xml
index d274ba30..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-SNAPSHOT
+ 2.1.8-SNAPSHOT
caelum-stella-faces
diff --git a/stella-frete/pom.xml b/stella-frete/pom.xml
index 9ddae80e..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-SNAPSHOT
+ 2.1.8-SNAPSHOT
caelum-stella-frete
diff --git a/stella-hibernate-user-types/pom.xml b/stella-hibernate-user-types/pom.xml
index 5d048470..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-SNAPSHOT
+ 2.1.8-SNAPSHOT
caelum-stella-hibernate-user-types
jar