diff --git a/.idea/misc.xml b/.idea/misc.xml index a092c32..e43bc12 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -2,6 +2,10 @@ + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml index 55adcb9..354189b 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,6 @@ - diff --git a/lib/bld/bld-wrapper.jar b/lib/bld/bld-wrapper.jar index 28a07b5..623720b 100644 Binary files a/lib/bld/bld-wrapper.jar and b/lib/bld/bld-wrapper.jar differ diff --git a/src/bld/java/net/thauvin/erik/httpstatus/HttpStatusBuild.java b/src/bld/java/net/thauvin/erik/httpstatus/HttpStatusBuild.java index a14d668..70be27f 100644 --- a/src/bld/java/net/thauvin/erik/httpstatus/HttpStatusBuild.java +++ b/src/bld/java/net/thauvin/erik/httpstatus/HttpStatusBuild.java @@ -34,18 +34,14 @@ package net.thauvin.erik.httpstatus; import rife.bld.BuildCommand; import rife.bld.Project; -import rife.bld.dependencies.Dependency; import rife.bld.extension.JacocoReportOperation; import rife.bld.extension.PmdOperation; -import rife.bld.publish.PublishDeveloper; -import rife.bld.publish.PublishInfo; -import rife.bld.publish.PublishLicense; -import rife.bld.publish.PublishScm; +import rife.bld.operations.JUnitOperation; +import rife.bld.publish.*; +import rife.tools.FileUtils; import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.StandardCopyOption; import java.util.List; import static rife.bld.dependencies.Repository.*; @@ -75,8 +71,8 @@ public class HttpStatusBuild extends Project { .include(dependency("jakarta.el", "jakarta.el-api", version(5, 0, 1))); scope(test) .include(dependency("org.assertj", "assertj-joda-time", version(2, 2, 0))) - .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 9, 3))) - .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 9, 3))); + .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 0))) + .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 0))); javadocOperation().javadocOptions() .docTitle(description + ' ' + version.toString()) @@ -93,6 +89,7 @@ public class HttpStatusBuild extends Project { .groupId(pkg) .artifactId(name.toLowerCase()) .name(name) + .version(version) .description(description) .url(url) .developer(new PublishDeveloper().id("ethauvin").name("Erik C. Thauvin").email("erik@thauvin.net") @@ -110,16 +107,7 @@ public class HttpStatusBuild extends Project { new HttpStatusBuild().start(args); } - @Override - public void publish() throws Exception { - super.publish(); - var pomPath = Path.of(MAVEN_LOCAL.getArtifactLocation(new Dependency(pkg, name.toLowerCase(), version)), - version.toString(), - name.toLowerCase() + '-' + version + ".pom"); - Files.copy(pomPath, Path.of(workDirectory.getAbsolutePath(), "pom.xml"), StandardCopyOption.REPLACE_EXISTING); - } - - @BuildCommand(summary = "Generates Jacoco Reports") + @BuildCommand(summary = "Generates JaCoCo Reports") public void jacoco() throws IOException { new JacocoReportOperation() .fromProject(this) @@ -134,4 +122,11 @@ public class HttpStatusBuild extends Project { .ruleSets("config/pmd.xml") .execute(); } + + @Override + public void publish() throws Exception { + super.publish(); + var xml = new PomBuilder().info(publishOperation().info()).dependencies(dependencies).build(); + FileUtils.writeString(xml, Path.of(workDirectory.getPath(), "pom.xml").toFile()); + } } \ No newline at end of file diff --git a/src/main/java/net/thauvin/erik/httpstatus/taglibs/CauseTag.java b/src/main/java/net/thauvin/erik/httpstatus/taglibs/CauseTag.java index 54b01a7..ba6db9b 100644 --- a/src/main/java/net/thauvin/erik/httpstatus/taglibs/CauseTag.java +++ b/src/main/java/net/thauvin/erik/httpstatus/taglibs/CauseTag.java @@ -52,15 +52,24 @@ public class CauseTag extends XmlSupport { @Override public void doTag() throws IOException { final PageContext pageContext = (PageContext) getJspContext(); - @SuppressWarnings("PMD.CloseResource") final JspWriter out = pageContext.getOut(); + final JspWriter out = pageContext.getOut(); final Throwable cause = pageContext.getErrorData().getThrowable().getCause(); - String message = defaultValue; - if (cause != null && cause.getLocalizedMessage() != null) { - message = cause.getLocalizedMessage(); - } + Utils.outWrite(out, getCause(cause), defaultValue, escapeXml); + } - Utils.outWrite(out, message, defaultValue, escapeXml); + /** + * Returns the cause's localized message or default value. + * + * @param cause The cause. + * @return The cause or {@code null}. + */ + public String getCause(Throwable cause) { + if (cause != null && cause.getLocalizedMessage() != null) { + return cause.getLocalizedMessage(); + } else { + return null; + } } } \ No newline at end of file diff --git a/src/main/java/net/thauvin/erik/httpstatus/taglibs/CodeTag.java b/src/main/java/net/thauvin/erik/httpstatus/taglibs/CodeTag.java index 763157a..7eba9d1 100644 --- a/src/main/java/net/thauvin/erik/httpstatus/taglibs/CodeTag.java +++ b/src/main/java/net/thauvin/erik/httpstatus/taglibs/CodeTag.java @@ -52,7 +52,7 @@ public class CodeTag extends SimpleTagSupport { @Override public void doTag() throws IOException { final PageContext pageContext = (PageContext) getJspContext(); - @SuppressWarnings("PMD.CloseResource") final JspWriter out = pageContext.getOut(); + final JspWriter out = pageContext.getOut(); out.write(String.valueOf(pageContext.getErrorData().getStatusCode())); } diff --git a/src/main/java/net/thauvin/erik/httpstatus/taglibs/MessageTag.java b/src/main/java/net/thauvin/erik/httpstatus/taglibs/MessageTag.java index 7a72750..61738ea 100644 --- a/src/main/java/net/thauvin/erik/httpstatus/taglibs/MessageTag.java +++ b/src/main/java/net/thauvin/erik/httpstatus/taglibs/MessageTag.java @@ -52,7 +52,7 @@ public class MessageTag extends XmlSupport { @Override public void doTag() throws IOException { final PageContext pageContext = (PageContext) getJspContext(); - @SuppressWarnings("PMD.CloseResource") final JspWriter out = pageContext.getOut(); + final JspWriter out = pageContext.getOut(); final String message = (String) pageContext.getRequest().getAttribute( jakarta.servlet.RequestDispatcher.ERROR_MESSAGE); diff --git a/src/main/java/net/thauvin/erik/httpstatus/taglibs/ReasonTag.java b/src/main/java/net/thauvin/erik/httpstatus/taglibs/ReasonTag.java index dccf365..4de7537 100644 --- a/src/main/java/net/thauvin/erik/httpstatus/taglibs/ReasonTag.java +++ b/src/main/java/net/thauvin/erik/httpstatus/taglibs/ReasonTag.java @@ -56,7 +56,7 @@ public class ReasonTag extends XmlSupport { @Override public void doTag() { final PageContext pageContext = (PageContext) getJspContext(); - @SuppressWarnings("PMD.CloseResource") final JspWriter out = pageContext.getOut(); + final JspWriter out = pageContext.getOut(); try { if (statusCode > -1) { @@ -75,7 +75,6 @@ public class ReasonTag extends XmlSupport { * * @param statusCode The status code. */ - @SuppressWarnings("unused") public void setCode(final int statusCode) { this.statusCode = statusCode; } diff --git a/src/main/java/net/thauvin/erik/httpstatus/taglibs/XmlSupport.java b/src/main/java/net/thauvin/erik/httpstatus/taglibs/XmlSupport.java index 31b9abb..c405ae4 100644 --- a/src/main/java/net/thauvin/erik/httpstatus/taglibs/XmlSupport.java +++ b/src/main/java/net/thauvin/erik/httpstatus/taglibs/XmlSupport.java @@ -57,7 +57,6 @@ public abstract class XmlSupport extends SimpleTagSupport { * * @param defaultValue The default value. */ - @SuppressWarnings("unused") public void setDefault(final String defaultValue) { this.defaultValue = defaultValue; } @@ -67,7 +66,6 @@ public abstract class XmlSupport extends SimpleTagSupport { * * @param escapeXml true or false */ - @SuppressWarnings("unused") public void setEscapeXml(final boolean escapeXml) { this.escapeXml = escapeXml; } diff --git a/src/test/java/net/thauvin/erik/httpstatus/CauseTagTest.java b/src/test/java/net/thauvin/erik/httpstatus/CauseTagTest.java new file mode 100644 index 0000000..757ba15 --- /dev/null +++ b/src/test/java/net/thauvin/erik/httpstatus/CauseTagTest.java @@ -0,0 +1,57 @@ +/* + * CauseTagTest.java + * + * Copyright 2023 sErik C. Thauvin (erik@thauvin.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of this project nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.thauvin.erik.httpstatus; + +import net.thauvin.erik.httpstatus.taglibs.CauseTag; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Implements the CauseTagTest class. + * + * @author Erik C. Thauvin + * @since 1.0 + */ +class CauseTagTest { + @Test + void causeTest() { + var message = "This is the cause"; + var tag = new CauseTag(); + + assertThat(tag.getCause(new Exception(message))).as("has cause").isEqualTo(message); + assertThat(tag.getCause(new Exception())).as("no cause").isNull(); + assertThat(tag.getCause(null)).as("null").isNull(); + assertThat(tag.getCause(new Exception(""))).as("empty").isEmpty(); + } +}
true
false