diff --git a/.gitignore b/.gitignore index 4fca8ee..f1b884a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build *.iws -target \ No newline at end of file +target +.savant/cache diff --git a/build.savant b/build.savant index b351ffb..1b4565f 100644 --- a/build.savant +++ b/build.savant @@ -1,15 +1,19 @@ /* - * Copyright (c) 2015-2019, Inversoft Inc., All Rights Reserved + * Copyright (c) 2015-2025, Inversoft Inc., All Rights Reserved */ -savantVersion = "1.0.0" - -project(group: "com.inversoft", name: "java-error", version: "2.2.2", licenses: ["ApacheV2_0"]) { +project(group: "com.inversoft", name: "java-error", version: "2.2.3", licenses: ["ApacheV2_0"]) { workflow { - standard() + fetch { + cache() + url(url: "https://repository.savantbuild.org") + } + publish { + cache() + } } publishWorkflow { - subversion(repository: "http://svn.inversoft.org/savant") + subversion(repository: "https://svn.savantbuild.org") } dependencies { @@ -26,11 +30,12 @@ project(group: "com.inversoft", name: "java-error", version: "2.2.2", licenses: } // Plugins -dependency = loadPlugin(id: "org.savantbuild.plugin:dependency:1.0.2") -file = loadPlugin(id: "org.savantbuild.plugin:file:1.0.2") -java = loadPlugin(id: "org.savantbuild.plugin:java:1.0.2") -idea = loadPlugin(id: "org.savantbuild.plugin:idea:1.0.1") -release = loadPlugin(id: "org.savantbuild.plugin:release-git:${savantVersion}") +dependency = loadPlugin(id: "org.savantbuild.plugin:dependency:2.0.0") +file = loadPlugin(id: "org.savantbuild.plugin:file:2.0.0") +java = loadPlugin(id: "org.savantbuild.plugin:java:2.0.0") +idea = loadPlugin(id: "org.savantbuild.plugin:idea:2.0.0") +release = loadPlugin(id: "org.savantbuild.plugin:release-git:2.0.0") +pom = loadPlugin(id: "org.savantbuild.plugin:pom:2.0.0") java.settings.javaVersion = "1.8" @@ -55,7 +60,7 @@ target(name: "doc", description: "Generate the project's JavaDoc", dependsOn: [" java.document() } -target(name: "int", description: "Releases a local integration build of the project", dependsOn: ["test"]) { +target(name: "int", description: "Releases a local integration build of the project", dependsOn: ["test", "pom"]) { dependency.integrate() } @@ -71,6 +76,10 @@ target(name: "idea", description: "Updates the IntelliJ IDEA module file") { idea.iml() } +target(name: "pom", description: "Updates the pom.xml file") { + pom.update() +} + target(name: "publish", description: "Publish to MVN repo", dependsOn: ["clean", "test"]) { if (new ProcessBuilder('mvn', 'deploy', '-Prelease').inheritIO().start().waitFor() != 0) { fail("deploy failed") diff --git a/java-error.iml b/java-error.iml index 60696f9..303cb27 100644 --- a/java-error.iml +++ b/java-error.iml @@ -13,128 +13,128 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -143,22 +143,22 @@ - + - + - + - + diff --git a/pom.xml b/pom.xml index 4da19d9..001a12d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,12 +1,11 @@ - - + 4.0.0 com.inversoft java-error - 2.2.2 + 2.2.3 jar Inversoft Java Error @@ -15,13 +14,16 @@ - ossrh - https://oss.sonatype.org/content/repositories/snapshots + Central Portal Snapshots + central-portal-snapshots + https://central.sonatype.com/repository/maven-snapshots/ + + true + + + false + - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - @@ -41,8 +43,9 @@ - The Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt + Apache-2.0 + https://www.apache.org/licenses/LICENSE-2.0 + repo @@ -61,11 +64,17 @@ com.fasterxml.jackson.core jackson-annotations 2.10.1 + jar + compile + false com.inversoft jackson5 2.4.4 + jar + compile + false @@ -83,7 +92,7 @@ sign - Inversoft + ${gpg.keyname} @@ -91,7 +100,7 @@ org.apache.maven.plugins maven-source-plugin - 2.2.1 + 3.2.1 attach-sources @@ -104,7 +113,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.9.1 + 3.4.1 attach-javadocs @@ -117,6 +126,42 @@ - - + + + release + + + + org.sonatype.central + central-publishing-maven-plugin + 0.8.0 + true + + central + true + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + ${gpg.keyname} + false + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/inversoft/error/Error.java b/src/main/java/com/inversoft/error/Error.java index 1a2c9c2..63ffe09 100644 --- a/src/main/java/com/inversoft/error/Error.java +++ b/src/main/java/com/inversoft/error/Error.java @@ -16,6 +16,8 @@ package com.inversoft.error; import java.util.Arrays; +import java.util.Map; +import java.util.Objects; import com.fasterxml.jackson.annotation.JsonIgnore; import com.inversoft.json.JacksonConstructor; @@ -29,6 +31,8 @@ public class Error { public String code; + public Map data; + public String message; @JsonIgnore @@ -41,6 +45,13 @@ public class Error { public Error() { } + public Error(String code, String message, Map data, Object... values) { + this.code = code; + this.data = data; + this.message = message; + this.values = values; + } + public Error(String code, String message, Object... values) { this.code = code; this.message = message; @@ -51,18 +62,13 @@ public Error(String code, String message, Object... values) { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - Error error = (Error) o; - - return code.equals(error.code) && - (message != null ? message.equals(error.message) : error.message == null) && - Arrays.equals(values, error.values); + return Objects.equals(code, error.code) && Objects.equals(data, error.data) && Objects.equals(message, error.message) && Arrays.equals(values, error.values); } @Override public int hashCode() { - int result = code.hashCode(); - result = 31 * result + (message != null ? message.hashCode() : 0); + int result = Objects.hash(code, data, message); result = 31 * result + Arrays.hashCode(values); return result; } diff --git a/src/main/java/com/inversoft/error/Errors.java b/src/main/java/com/inversoft/error/Errors.java index 97bffb4..c7b04ca 100644 --- a/src/main/java/com/inversoft/error/Errors.java +++ b/src/main/java/com/inversoft/error/Errors.java @@ -46,18 +46,16 @@ public Errors add(Errors otherErrors) { return this; } - public Errors addFieldError(String field, String code, String message, Object... values) { - List errors = fieldErrors.get(field); - if (errors == null) { - errors = new LinkedList<>(); - fieldErrors.put(field, errors); - } - - errors.add(new Error(code, message, values)); - + public Errors addFieldError(String field, String code, String message, Map data, Object... values) { + List errors = fieldErrors.computeIfAbsent(field, k -> new LinkedList<>()); + errors.add(new Error(code, message, data, values)); return this; } + public Errors addFieldError(String field, String code, String message, Object... values) { + return addFieldError(field, code, message, null, values); + } + public Errors addGeneralError(String code, String message, Object... values) { generalErrors.add(new Error(code, message, values)); return this; @@ -69,6 +67,9 @@ public Errors addGeneralError(String code, String message, Object... values) { *

* This is a little loose, making the caller know which code prefixes the Validator is using, an enum or something * might work nicely... for now keeping this. + * + * @param codePrefix the code prefix. + * @return true if an error code with this prefix exists in general or field errors. */ public boolean containsError(String codePrefix) { for (Error error : generalErrors) { @@ -105,6 +106,21 @@ public boolean equals(Object o) { return fieldErrors.equals(errors.fieldErrors) && generalErrors.equals(errors.generalErrors); } + public Error getFieldError(String field, String code) { + List errors = fieldErrors.get(field); + if (errors == null) { + return null; + } + + for (Error fieldError : errors) { + if (fieldError.code.equals(code)) { + return fieldError; + } + } + + return null; + } + @Override public int hashCode() { int result = generalErrors.hashCode();