From 68c0b7d2923149b1c1ea68ff09a3c35bc5668517 Mon Sep 17 00:00:00 2001 From: Edgar Espina Date: Sat, 25 Sep 2021 13:37:49 -0300 Subject: [PATCH 001/157] Build: add github actions --- .github/workflows/build-matrix.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/build-matrix.yml diff --git a/.github/workflows/build-matrix.yml b/.github/workflows/build-matrix.yml new file mode 100644 index 000000000..6147ec33c --- /dev/null +++ b/.github/workflows/build-matrix.yml @@ -0,0 +1,30 @@ +name: Build Matrix + +on: [push] + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + java_version: [1.8, 11, 13, 15, 17] + os: [ubuntu-latest, windows-latest, macOS-latest] + + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Set up JDK ${{ matrix.java_version }} + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java_version }} + - name: Install + run: mvn clean install -DskipTests + env: + BUILD_PORT: 0 + BUILD_SECURE_PORT: 0 + - name: Build + run: mvn clean package + env: + BUILD_PORT: 0 + BUILD_SECURE_PORT: 0 From 8f36cae1dde6d77a8d65cfc05ce63594769f1c77 Mon Sep 17 00:00:00 2001 From: Logan Rosen Date: Mon, 14 Jun 2021 19:53:58 -0400 Subject: [PATCH 002/157] Upgrade to latest handlebars.js (4.7.7) Fixes #848. --- .../handlebars/maven/PrecompilePlugin.java | 2 +- .../jknack/handlebars/maven/Issue234.java | 2 +- .../maven/PrecompilePluginTest.java | 22 +++++++++---------- .../springmvc/HandlebarsViewResolver.java | 4 ++-- .../github/jknack/handlebars/Handlebars.java | 2 +- ...dlebars-v4.7.6.js => handlebars-v4.7.7.js} | 8 +++---- .../jknack/handlebars/i417/Issue417.java | 2 +- 7 files changed, 21 insertions(+), 21 deletions(-) rename handlebars/src/main/resources/{handlebars-v4.7.6.js => handlebars-v4.7.7.js} (99%) diff --git a/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/PrecompilePlugin.java b/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/PrecompilePlugin.java index c80e260bf..9f6b80a0b 100644 --- a/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/PrecompilePlugin.java +++ b/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/PrecompilePlugin.java @@ -113,7 +113,7 @@ public class PrecompilePlugin extends HandlebarsPlugin { /** * The handlebars js file. */ - @Parameter(defaultValue = "/handlebars-v4.7.6.js") + @Parameter(defaultValue = "/handlebars-v4.7.7.js") private String handlebarsJsFile; /** diff --git a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java index 72cb5438a..986023614 100644 --- a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java +++ b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java @@ -24,7 +24,7 @@ public void withAmdOutput() throws Exception { plugin.addTemplate("c"); plugin.setAmd(true); plugin.setProject(newProject()); - plugin.setHandlebarsJsFile("/handlebars-v4.7.6.js"); + plugin.setHandlebarsJsFile("/handlebars-v4.7.7.js"); plugin.execute(); diff --git a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java index 58ad68661..31bbcbf8a 100644 --- a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java +++ b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java @@ -27,7 +27,7 @@ public void i18nJs() throws Exception { plugin.setSuffix(".html"); plugin.setOutput("target/helpers-i18njs.js"); plugin.setProject(newProject()); - plugin.setHandlebarsJsFile("/handlebars-v4.7.6.js"); + plugin.setHandlebarsJsFile("/handlebars-v4.7.7.js"); plugin.execute(); @@ -45,7 +45,7 @@ public void chooseSpecificFiles() throws Exception { plugin.addTemplate("a"); plugin.addTemplate("c"); plugin.setProject(newProject()); - plugin.setHandlebarsJsFile("/handlebars-v4.7.6.js"); + plugin.setHandlebarsJsFile("/handlebars-v4.7.7.js"); plugin.execute(); @@ -61,7 +61,7 @@ public void outputDirMustBeCreated() throws Exception { plugin.setSuffix(".html"); plugin.setOutput("target/newdir/helpers.js"); plugin.setProject(newProject()); - plugin.setHandlebarsJsFile("/handlebars-v4.7.6.js"); + plugin.setHandlebarsJsFile("/handlebars-v4.7.7.js"); plugin.execute(); } @@ -73,7 +73,7 @@ public void missingHelperMustBeSilent() throws Exception { plugin.setSuffix(".html"); plugin.setOutput("target/missing-helpers.js"); plugin.setProject(newProject()); - plugin.setHandlebarsJsFile("/handlebars-v4.7.6.js"); + plugin.setHandlebarsJsFile("/handlebars-v4.7.7.js"); plugin.execute(); } @@ -85,7 +85,7 @@ public void noFileMustBeCreatedIfNoTemplatesWereFound() throws Exception { plugin.setSuffix(".html"); plugin.setOutput("target/no-helpers.js"); plugin.setProject(newProject()); - plugin.setHandlebarsJsFile("/handlebars-v4.7.6.js"); + plugin.setHandlebarsJsFile("/handlebars-v4.7.7.js"); plugin.execute(); @@ -127,7 +127,7 @@ public void mustFailOnUnExpectedException() throws Exception { plugin.setSuffix(".html"); plugin.setOutput("target/no-helpers.js"); plugin.setProject(project); - plugin.setHandlebarsJsFile("/handlebars-v4.7.6.js"); + plugin.setHandlebarsJsFile("/handlebars-v4.7.7.js"); plugin.execute(); } @@ -139,7 +139,7 @@ public void fileWithRuntimeMustBeLargerThanNormalFiles() throws Exception { withoutRT.setSuffix(".html"); withoutRT.setOutput("target/without-rt-helpers.js"); withoutRT.setProject(newProject()); - withoutRT.setHandlebarsJsFile("/handlebars-v4.7.6.js"); + withoutRT.setHandlebarsJsFile("/handlebars-v4.7.7.js"); withoutRT.execute(); @@ -149,7 +149,7 @@ public void fileWithRuntimeMustBeLargerThanNormalFiles() throws Exception { withRT.setOutput("target/with-rt-helpers.js"); withRT.setRuntime("src/test/resources/handlebars.runtime.js"); withRT.setProject(newProject()); - withRT.setHandlebarsJsFile("/handlebars-v4.7.6.js"); + withRT.setHandlebarsJsFile("/handlebars-v4.7.7.js"); withRT.execute(); @@ -165,7 +165,7 @@ public void normalFileShouleBeLargerThanMinimizedFiles() throws Exception { withoutRT.setSuffix(".html"); withoutRT.setOutput("target/helpers-normal.js"); withoutRT.setProject(newProject()); - withoutRT.setHandlebarsJsFile("/handlebars-v4.7.6.js"); + withoutRT.setHandlebarsJsFile("/handlebars-v4.7.7.js"); withoutRT.execute(); @@ -175,7 +175,7 @@ public void normalFileShouleBeLargerThanMinimizedFiles() throws Exception { withRT.setOutput("target/helpers.min.js"); withRT.setMinimize(true); withRT.setProject(newProject()); - withRT.setHandlebarsJsFile("/handlebars-v4.7.6.js"); + withRT.setHandlebarsJsFile("/handlebars-v4.7.7.js"); withRT.execute(); assertTrue("Normal file must be larger than minimized", @@ -190,7 +190,7 @@ public void partials() throws Exception { plugin.setSuffix(".html"); plugin.setOutput("target/helpers.js"); plugin.setProject(newProject()); - plugin.setHandlebarsJsFile("/handlebars-v4.7.6.js"); + plugin.setHandlebarsJsFile("/handlebars-v4.7.7.js"); plugin.execute(); diff --git a/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolver.java b/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolver.java index 7b5bcb058..83357869e 100644 --- a/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolver.java +++ b/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolver.java @@ -371,10 +371,10 @@ public void setFormatters(final Formatter... formatters) { * *
    *   Handlebars handlebars = new Handlebars()
-   *      .handlebarsJsFile("handlebars-v4.7.6.js");
+   *      .handlebarsJsFile("handlebars-v4.7.7.js");
    * 
* - * Default handlebars.js is handlebars-v4.7.6.js. + * Default handlebars.js is handlebars-v4.7.7.js. * * @param location A classpath location of the handlebar.js file. */ diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java b/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java index 89820a119..aea841d99 100644 --- a/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java +++ b/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java @@ -313,7 +313,7 @@ public static CharSequence escapeExpression(final CharSequence input) { private String endDelimiter = DELIM_END; /** Location of the handlebars.js file. */ - private String handlebarsJsFile = "/handlebars-v4.7.6.js"; + private String handlebarsJsFile = "/handlebars-v4.7.7.js"; /** List of formatters. */ private List formatters = new ArrayList<>(); diff --git a/handlebars/src/main/resources/handlebars-v4.7.6.js b/handlebars/src/main/resources/handlebars-v4.7.7.js similarity index 99% rename from handlebars/src/main/resources/handlebars-v4.7.6.js rename to handlebars/src/main/resources/handlebars-v4.7.7.js index 05d9f6141..baad5d3d9 100644 --- a/handlebars/src/main/resources/handlebars-v4.7.6.js +++ b/handlebars/src/main/resources/handlebars-v4.7.7.js @@ -1,7 +1,7 @@ /**! @license - handlebars v4.7.6 + handlebars v4.7.7 Copyright (C) 2011-2019 by Yehuda Katz @@ -278,7 +278,7 @@ return /******/ (function(modules) { // webpackBootstrap var _internalProtoAccess = __webpack_require__(33); - var VERSION = '4.7.6'; + var VERSION = '4.7.7'; exports.VERSION = VERSION; var COMPILER_REVISION = 8; exports.COMPILER_REVISION = COMPILER_REVISION; @@ -1525,7 +1525,7 @@ return /******/ (function(modules) { // webpackBootstrap loc: loc }); } - return obj[name]; + return container.lookupProperty(obj, name); }, lookupProperty: function lookupProperty(parent, propertyName) { var result = parent[propertyName]; @@ -3903,7 +3903,7 @@ return /******/ (function(modules) { // webpackBootstrap return this.internalNameLookup(parent, name); }, depthedLookup: function depthedLookup(name) { - return [this.aliasable('container.lookup'), '(depths, "', name, '")']; + return [this.aliasable('container.lookup'), '(depths, ', JSON.stringify(name), ')']; }, compilerInfo: function compilerInfo() { diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/i417/Issue417.java b/handlebars/src/test/java/com/github/jknack/handlebars/i417/Issue417.java index 51c96833f..b78f91adb 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/i417/Issue417.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/i417/Issue417.java @@ -25,7 +25,7 @@ public void v4_0_0() throws IOException { + " return \"Hi \"\n" + " + container.escapeExpression(((helper = (helper = lookupProperty(helpers,\"var\") || (depth0 != null ? lookupProperty(depth0,\"var\") : depth0)) != null ? helper : container.hooks.helperMissing),(typeof helper === \"function\" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{\"name\":\"var\",\"hash\":{},\"data\":data,\"loc\":{\"start\":{\"line\":1,\"column\":3},\"end\":{\"line\":1,\"column\":10}}}) : helper)))\n" + " + \"!\";\n" - + "},\"useData\":true}", new Handlebars().handlebarsJsFile("/handlebars-v4.7.6.js") + + "},\"useData\":true}", new Handlebars().handlebarsJsFile("/handlebars-v4.7.7.js") .compileInline("Hi {{var}}!").toJavaScript()); } From a79d870610fc2b79a0e2c8f5f8a82d5a3257618d Mon Sep 17 00:00:00 2001 From: Edgar Espina Date: Sat, 25 Sep 2021 13:53:49 -0300 Subject: [PATCH 003/157] build: add sub-modules --- .github/workflows/build-matrix.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build-matrix.yml b/.github/workflows/build-matrix.yml index 6147ec33c..482dc4f42 100644 --- a/.github/workflows/build-matrix.yml +++ b/.github/workflows/build-matrix.yml @@ -14,6 +14,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v1 + - name: Mustache Specs + run: | + git submodule update --init --recursive - name: Set up JDK ${{ matrix.java_version }} uses: actions/setup-java@v1 with: From 942e34db42774c122d8f4be794a303894be56bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E5=9D=A4?= Date: Mon, 26 Apr 2021 08:57:07 +0800 Subject: [PATCH 004/157] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 089207a23..c72106e7b 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Handlebars.java is a Java port of [handlebars](http://handlebarsjs.com/). Handlebars provides the power necessary to let you build semantic templates effectively with no frustration. -[Mustache](http://mustache.github.com/mustache.5.html) templates are compatible with Handlebars, so you can take a [Mustache](http://mustache.github.com) template, import it into Handlebars, and start taking advantage of the extra Handlebars features. +[Mustache](http://mustache.github.io/mustache.5.html) templates are compatible with Handlebars, so you can take a [Mustache](http://mustache.github.com) template, import it into Handlebars, and start taking advantage of the extra Handlebars features. # Getting Started In general, the syntax of **Handlebars** templates is a superset of [Mustache](http://mustache.github.com) templates. For basic syntax, check out the [Mustache manpage](http://mustache.github.com). From 40ca09ab5145f735f0c1ada77e68af3159826655 Mon Sep 17 00:00:00 2001 From: Yannick Dylla Date: Tue, 17 Aug 2021 12:06:51 +0200 Subject: [PATCH 005/157] feat(StringHelpers): add Instant support for dateFormat * add support for more date types like Instant, OffsetDateTime, LocalDateTime, ... --- .../handlebars/helper/StringHelpers.java | 108 +++++++++++++----- .../jknack/handlebars/DateFormatTest.java | 67 ++++++++++- 2 files changed, 145 insertions(+), 30 deletions(-) diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java index 47d8c9e38..3d178653b 100644 --- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java +++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java @@ -26,11 +26,13 @@ import java.io.IOException; import java.math.RoundingMode; -import java.text.DateFormat; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; -import java.text.SimpleDateFormat; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; +import java.time.temporal.TemporalAccessor; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -501,7 +503,7 @@ protected CharSequence safeApply(final Object context, final Options options) { *

* *
-   *    {{dateFormat date ["format"] [format="format"][tz=timeZone|timeZoneId]}}
+   *    {{dateFormat date ["format"] [format="format"][locale="locale"][tz=timeZone|timeZoneId][time="format"]}}
    * 
* * Format parameters is one of: @@ -510,48 +512,102 @@ protected CharSequence safeApply(final Object context, final Options options) { *
  • "long": long date format. For example: June 19, 2012
  • *
  • "medium": medium date format. For example: Jun 19, 2012
  • *
  • "short": short date format. For example: 6/19/12
  • - *
  • "pattern": a date pattern.
  • + *
  • "pattern": a {@link java.time.format.DateTimeFormatter} pattern.
  • * * Otherwise, the default formatter will be used. * The format option can be specified as a parameter or hash (a.k.a named parameter). + * + *
      + *
    • + * The "locale" parameter can be use to select a locale, e.g. "de" or "en_GB". + * It defaults to the system locale. + *
    • + *
    • + * The "tz" parameter is the time zone to use, e.g. "Europe/Berlin" or "GMT-8:00". + * It defaults to the system time zone. + *
    • + *
    • + * The "time" parameter specifies the format of the time part, it can be "full", "long", "medium" or "short". + * If you do not specify it only the date part will appear in the output string. + *
    • + *
    */ dateFormat { /** - * The default date styles. + * The default format styles. */ - @SuppressWarnings("serial") - private Map styles = new HashMap() { + private final Map formatStyles = new HashMap(4) { { - put("full", DateFormat.FULL); - put("long", DateFormat.LONG); - put("medium", DateFormat.MEDIUM); - put("short", DateFormat.SHORT); + put("full", FormatStyle.FULL); + put("long", FormatStyle.LONG); + put("medium", FormatStyle.MEDIUM); + put("short", FormatStyle.SHORT); } }; + private TemporalAccessor toTemporalAccessor(final Object value) { + if (value instanceof TemporalAccessor) { + return (TemporalAccessor) value; + } else if (value instanceof Date) { + return ((Date) value).toInstant(); + } else { + String className = null; + if (value != null) { + className = value.getClass().getSimpleName(); + } + throw new IllegalArgumentException(String.format( + "found instance of %s with value '%s', but expected instance of TemporalAccessor", + className, value)); + } + } + @Override protected CharSequence safeApply(final Object value, final Options options) { - isTrue(value instanceof Date, "found '%s', expected 'date'", value); - Date date = (Date) value; - final DateFormat dateFormat; - Object pattern = options.param(0, options.hash("format", "medium")); - String localeStr = options.param(1, options.hash("locale", Locale.getDefault().toString())); - Locale locale = LocaleUtils.toLocale(localeStr); - Integer style = styles.get(pattern); - if (style == null) { - dateFormat = new SimpleDateFormat(pattern.toString(), locale); + TemporalAccessor date = toTemporalAccessor(value); + + String pattern = options.param(0, options.hash("format", "medium")); + FormatStyle dateStyle = formatStyles.get(pattern); + FormatStyle timeStyle = formatStyles.get(options.hash("time")); + + DateTimeFormatter formatter; + if (dateStyle == null) { + formatter = DateTimeFormatter.ofPattern(pattern); + } else { + if (timeStyle != null) { + formatter = DateTimeFormatter.ofLocalizedDateTime(dateStyle, timeStyle); + } else { + formatter = DateTimeFormatter.ofLocalizedDate(dateStyle); + } + } + + // configure locale + String localeStr = options.param(1, options.hash("locale")); + Locale locale; + if (localeStr != null && localeStr.length() > 0) { + locale = LocaleUtils.toLocale(localeStr); } else { - dateFormat = DateFormat.getDateInstance(style, locale); + locale = Locale.getDefault(); } + formatter = formatter.withLocale(locale); + + // configure timezone Object tz = options.hash("tz"); if (tz != null) { - final TimeZone timeZone = tz instanceof TimeZone ? (TimeZone) tz : TimeZone.getTimeZone(tz - .toString()); - dateFormat.setTimeZone(timeZone); + ZoneId zoneId; + if (tz instanceof ZoneId) { + zoneId = (ZoneId) tz; + } else if (tz instanceof TimeZone) { + zoneId = ((TimeZone) tz).toZoneId(); + } else { + zoneId = TimeZone.getTimeZone(tz.toString()).toZoneId(); + } + formatter = formatter.withZone(zoneId); + } else { + formatter = formatter.withZone(ZoneId.systemDefault()); } - return dateFormat.format(date); - } + return formatter.format(date); + } }, /** diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/DateFormatTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/DateFormatTest.java index 126240751..d24d6b7ea 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/DateFormatTest.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/DateFormatTest.java @@ -17,17 +17,24 @@ */ package com.github.jknack.handlebars; +import com.github.jknack.handlebars.helper.StringHelpers; +import org.junit.Test; + import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; +import java.time.temporal.TemporalAccessor; import java.util.Calendar; import java.util.Date; import java.util.Locale; -import org.junit.Test; - -import com.github.jknack.handlebars.helper.StringHelpers; - public class DateFormatTest extends AbstractTest { @Override @@ -106,4 +113,56 @@ public static Date date(final int day, final int month, final int year) { calendar.set(Calendar.YEAR, year); return calendar.getTime(); } + + public void verifyDateTimeFormats(Object date) throws IOException { + shouldCompileTo("{{dateFormat this \"medium\" locale=\"de\"}}", date, "12.08.2021"); + shouldCompileTo("{{dateFormat this \"medium\" \"en_EN\"}}", date, "Aug 12, 2021"); + shouldCompileTo("{{dateFormat this \"dd\"}}", date, "12"); + shouldCompileTo("{{dateFormat this \"'week' w '@' mm:ss\" \"de_DE\"}}", date, "week 32 @ 38:55"); + + TemporalAccessor temporalAccessor; + if (date instanceof Date) { + temporalAccessor = ((Date) date).toInstant(); + } else { + temporalAccessor = (TemporalAccessor) date; + } + + // "12.08.2021 16:38:55" with jdk 8, but "12.08.2021, 16:38:55" with jdk 11 + String expected1 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.MEDIUM) + .withLocale(Locale.GERMAN).withZone(ZoneId.of("Europe/Berlin")).format(temporalAccessor); + shouldCompileTo("{{dateFormat this time=\"medium\" locale=\"de\" tz=\"Europe/Berlin\"}}", date, expected1); + + // "12. August 2021 06:38" with jdk 8, but "12. August 2021, 06:38" with jdk 11 + String expected2 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT) + .withLocale(Locale.GERMAN).withZone(ZoneId.of("GMT-8")).format(temporalAccessor); + shouldCompileTo("{{dateFormat this \"long\" locale=\"de\" time=\"short\" tz=\"GMT-8:00\"}}", date, expected2); + + String expected3 = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM) + .withLocale(Locale.getDefault()).withZone(ZoneId.systemDefault()).format(temporalAccessor); + shouldCompileTo("{{dateFormat this}}", date, expected3); + + String expected4 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.MEDIUM) + .withLocale(Locale.getDefault()).withZone(ZoneId.systemDefault()).format(temporalAccessor); + shouldCompileTo("{{dateFormat this time=\"medium\"}}", date, expected4); + } + + @Test + public void formatDate() throws IOException { + verifyDateTimeFormats(new Date(1628779135*1000L)); + } + + @Test + public void formatInstant() throws IOException { + verifyDateTimeFormats(Instant.ofEpochSecond(1628779135)); + } + + @Test + public void formatOffsetDateTime() throws IOException { + verifyDateTimeFormats(OffsetDateTime.ofInstant(Instant.ofEpochSecond(1628779135), ZoneOffset.UTC)); + } + + @Test + public void formatLocalDateTime() throws IOException { + verifyDateTimeFormats(LocalDateTime.ofInstant(Instant.ofEpochSecond(1628779135), ZoneOffset.UTC)); + } } From ab5c6e40844c962568b127b2c7152029919982d0 Mon Sep 17 00:00:00 2001 From: Liam Williams Date: Thu, 13 May 2021 12:56:36 +0100 Subject: [PATCH 006/157] Added support for newlines in string literals --- .../jknack/handlebars/internal/HbsLexer.g4 | 4 +-- .../spec/StringLiteralParametersTest.java | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/handlebars/src/main/antlr4/com/github/jknack/handlebars/internal/HbsLexer.g4 b/handlebars/src/main/antlr4/com/github/jknack/handlebars/internal/HbsLexer.g4 index 69047bf1c..7f9438387 100644 --- a/handlebars/src/main/antlr4/com/github/jknack/handlebars/internal/HbsLexer.g4 +++ b/handlebars/src/main/antlr4/com/github/jknack/handlebars/internal/HbsLexer.g4 @@ -271,12 +271,12 @@ PIPE DOUBLE_STRING : - '"' ( '\\"' | ~[\n] )*? '"' + '"' ( '\\"' | . )*? '"' ; SINGLE_STRING : - '\'' ( '\\\'' | ~[\n] )*? '\'' + '\'' ( '\\\'' | . )*? '\'' ; EQ diff --git a/handlebars/src/test/java/handlebarsjs/spec/StringLiteralParametersTest.java b/handlebars/src/test/java/handlebarsjs/spec/StringLiteralParametersTest.java index da8982d28..26dfd9abc 100644 --- a/handlebars/src/test/java/handlebarsjs/spec/StringLiteralParametersTest.java +++ b/handlebars/src/test/java/handlebarsjs/spec/StringLiteralParametersTest.java @@ -84,4 +84,29 @@ public Object apply(final String cruel, final Options options) throws IOExceptio "block helpers with multiple params"); } + @Test + public void usingNewlinesInDoubleStringIsAllowed() throws IOException { + String string = "Message: {{{hello \"before\" \"multi\nline\" \"after\"}}}"; + Hash helpers = $("hello", new Helper() { + @Override + public Object apply(final String param, final Options options) throws IOException { + return "Hello " + param + " " + options.param(0) + " " + options.param(1); + } + }); + shouldCompileTo(string, $, helpers, "Message: Hello before multi\nline after", + "template with an escaped String literal"); + } + + @Test + public void usingNewlinesInSingleStringIsAllowed() throws IOException { + String string = "Message: {{{hello 'before' 'multi\nline' 'after' }}}"; + Hash helpers = $("hello", new Helper() { + @Override + public Object apply(final String param, final Options options) throws IOException { + return "Hello " + param + " " + options.param(0) + " " + options.param(1); + } + }); + shouldCompileTo(string, $, helpers, "Message: Hello before multi\nline after", + "template with an escaped String literal"); + } } From 1fffd956fc937879b7993c90b6eb208811f239fd Mon Sep 17 00:00:00 2001 From: Edgar Espina Date: Sat, 25 Sep 2021 14:19:04 -0300 Subject: [PATCH 007/157] upgrade jetty to latest 9.x --- handlebars-proto/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml index 644046f4a..313401de8 100644 --- a/handlebars-proto/pom.xml +++ b/handlebars-proto/pom.xml @@ -14,7 +14,7 @@ A standalone Handlebars Server - 9.4.28.v20200408 + 9.4.43.v20210629 From 54f72d7698ab9f372af2555e1aef2db39503e2bd Mon Sep 17 00:00:00 2001 From: Harris Date: Fri, 8 Jan 2021 14:50:37 +0530 Subject: [PATCH 008/157] fix token position when text block has new line char --- .../jknack/handlebars/internal/HbsLexer.g4 | 4 +- .../jknack/handlebars/internal/Issue823.java | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 handlebars/src/test/java/com/github/jknack/handlebars/internal/Issue823.java diff --git a/handlebars/src/main/antlr4/com/github/jknack/handlebars/internal/HbsLexer.g4 b/handlebars/src/main/antlr4/com/github/jknack/handlebars/internal/HbsLexer.g4 index 7f9438387..bc6727a7b 100644 --- a/handlebars/src/main/antlr4/com/github/jknack/handlebars/internal/HbsLexer.g4 +++ b/handlebars/src/main/antlr4/com/github/jknack/handlebars/internal/HbsLexer.g4 @@ -21,8 +21,10 @@ lexer grammar HbsLexer; int lineOffset = 0; boolean inNewline = false; boolean resetLine = false; + boolean hasNewLine = false; while(!isEOF(tokenOffset) && !(ahead("\\" + token, tokenOffset) || ahead(token, tokenOffset))) { if (resetLine) { + hasNewLine = true; colOffset = 0; lineOffset+=1; resetLine = false; @@ -44,7 +46,7 @@ lexer grammar HbsLexer; } // Since we found the text, increase the CharStream's index. _input.seek(_input.index() + tokenOffset - 1); - getInterpreter().setCharPositionInLine(_tokenStartCharPositionInLine + colOffset - 1); + getInterpreter().setCharPositionInLine(hasNewLine ? (colOffset - 1) : (_tokenStartCharPositionInLine + colOffset - 1)); getInterpreter().setLine(_tokenStartLine + lineOffset); return true; } diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/internal/Issue823.java b/handlebars/src/test/java/com/github/jknack/handlebars/internal/Issue823.java new file mode 100644 index 000000000..dec1adae0 --- /dev/null +++ b/handlebars/src/test/java/com/github/jknack/handlebars/internal/Issue823.java @@ -0,0 +1,39 @@ +package com.github.jknack.handlebars.internal; + +import com.github.jknack.handlebars.AbstractTest; +import org.antlr.v4.runtime.ANTLRInputStream; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.tree.ParseTree; +import org.junit.Test; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class Issue823 extends AbstractTest { + // correct token position is captured when text block has new line + @Test + public void correctTokenPositionForTextBlockWithNewline() throws IOException { + final HbsLexer lexer = new HbsLexer(new ANTLRInputStream("Hi {{x.y.z.a}}a\n a phrase{{x.y.z}}"), "{{", "}}"); + lexer.removeErrorListeners(); + CommonTokenStream tokens = new CommonTokenStream(lexer); + HbsParser parser = new HbsParser(tokens) { + @Override + void setStart(final String start) { + lexer.start = "{{"; + } + + @Override + void setEnd(final String end) { + lexer.end = "}}"; + } + }; + parser.removeErrorListeners(); + parser.template(); + List tList = tokens.getTokens(); + assertEquals(tList.get(5).getCharPositionInLine(),9); + assertEquals(tList.get(5).getLine(),2); + } +} From 4cebfe635aefad6df70b10f89f79dfe42df9a227 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 4 Jun 2021 09:21:12 +0000 Subject: [PATCH 009/157] Bump closure-compiler from v20200426 to v20210601 Bumps closure-compiler from v20200426 to v20210601. Signed-off-by: dependabot-preview[bot] --- handlebars-maven-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml index 3bb517407..a38c7603b 100644 --- a/handlebars-maven-plugin/pom.xml +++ b/handlebars-maven-plugin/pom.xml @@ -69,7 +69,7 @@ com.google.javascript closure-compiler - v20200426 + v20210601 From 2108dd4afd8e08aca4db3e4bdb0b151741cc95fd Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 22 Apr 2021 09:44:23 +0000 Subject: [PATCH 010/157] [Security] Bump jackson-databind from 2.9.10.4 to 2.9.10.7 Bumps [jackson-databind](https://github.com/FasterXML/jackson) from 2.9.10.4 to 2.9.10.7. **This update includes a security fix.** - [Release notes](https://github.com/FasterXML/jackson/releases) - [Commits](https://github.com/FasterXML/jackson/commits) Signed-off-by: dependabot-preview[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index dff13c2d7..68e75a886 100644 --- a/pom.xml +++ b/pom.xml @@ -421,7 +421,7 @@ UTF-8 - 2.9.10.4 + 2.9.10.7 1.2.2 0.8.5 yyyy-MM-dd HH:mm:ssa From 51219aeae0dc2d9affb1884b332864b45b81b726 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 29 Mar 2021 11:07:38 +0000 Subject: [PATCH 011/157] Bump maven-bundle-plugin from 4.2.1 to 5.1.2 Bumps maven-bundle-plugin from 4.2.1 to 5.1.2. Signed-off-by: dependabot-preview[bot] --- handlebars/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlebars/pom.xml b/handlebars/pom.xml index b8fd62086..5c8c253a0 100644 --- a/handlebars/pom.xml +++ b/handlebars/pom.xml @@ -131,7 +131,7 @@ org.apache.felix maven-bundle-plugin - 4.2.1 + 5.1.2 bundle-manifest From e0496da19c3fb76df49240e8653423dc7d468f16 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 2 Mar 2021 09:14:59 +0000 Subject: [PATCH 012/157] Bump commons-lang3 from 3.8.1 to 3.12.0 Bumps commons-lang3 from 3.8.1 to 3.12.0. Signed-off-by: dependabot-preview[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 68e75a886..cde2aba5d 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ org.apache.commons commons-lang3 - 3.8.1 + 3.12.0 From cf485e14c73760aa7a0664c697066df1dd9d841a Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 3 Jun 2020 09:19:48 +0000 Subject: [PATCH 013/157] Bump exec-maven-plugin from 1.6.0 to 3.0.0 Bumps [exec-maven-plugin](https://github.com/mojohaus/exec-maven-plugin) from 1.6.0 to 3.0.0. - [Release notes](https://github.com/mojohaus/exec-maven-plugin/releases) - [Commits](https://github.com/mojohaus/exec-maven-plugin/compare/exec-maven-plugin-1.6.0...exec-maven-plugin-3.0.0) Signed-off-by: dependabot-preview[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cde2aba5d..9a6cf2364 100644 --- a/pom.xml +++ b/pom.xml @@ -338,7 +338,7 @@ org.codehaus.mojo exec-maven-plugin - 1.6.0 + 3.0.0 initialize From a98054a6dfd4d8df30f8f683b0a62fc937bdeb03 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 3 Jun 2020 09:20:11 +0000 Subject: [PATCH 014/157] Bump maven-shade-plugin from 3.2.3 to 3.2.4 Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.3 to 3.2.4. - [Release notes](https://github.com/apache/maven-shade-plugin/releases) - [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.2.3...maven-shade-plugin-3.2.4) Signed-off-by: dependabot-preview[bot] --- handlebars-proto/pom.xml | 2 +- handlebars/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml index 313401de8..bb5a29398 100644 --- a/handlebars-proto/pom.xml +++ b/handlebars-proto/pom.xml @@ -28,7 +28,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.3 + 3.2.4 package diff --git a/handlebars/pom.xml b/handlebars/pom.xml index 5c8c253a0..1fd07d52b 100644 --- a/handlebars/pom.xml +++ b/handlebars/pom.xml @@ -21,7 +21,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.3 + 3.2.4 standalone From 021987ca4f26a57715a732e54ffd267915f3e166 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 23 Jun 2020 09:47:46 +0000 Subject: [PATCH 015/157] Bump build-helper-maven-plugin from 3.1.0 to 3.2.0 Bumps [build-helper-maven-plugin](https://github.com/mojohaus/build-helper-maven-plugin) from 3.1.0 to 3.2.0. - [Release notes](https://github.com/mojohaus/build-helper-maven-plugin/releases) - [Commits](https://github.com/mojohaus/build-helper-maven-plugin/compare/build-helper-maven-plugin-3.1.0...build-helper-maven-plugin-3.2.0) Signed-off-by: dependabot-preview[bot] --- handlebars/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlebars/pom.xml b/handlebars/pom.xml index 1fd07d52b..b26dafe21 100644 --- a/handlebars/pom.xml +++ b/handlebars/pom.xml @@ -78,7 +78,7 @@ org.codehaus.mojo build-helper-maven-plugin - 3.1.0 + 3.2.0 add-antlr-source From f779d32123243ce6196aafcecc94e300d1eb2d44 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 10 Sep 2020 09:15:16 +0000 Subject: [PATCH 016/157] Bump commons-io from 2.6 to 2.8.0 Bumps commons-io from 2.6 to 2.8.0. Signed-off-by: dependabot-preview[bot] --- handlebars-proto/pom.xml | 2 +- handlebars/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml index bb5a29398..3d5746cb1 100644 --- a/handlebars-proto/pom.xml +++ b/handlebars-proto/pom.xml @@ -139,7 +139,7 @@ commons-io commons-io - 2.4 + 2.8.0 diff --git a/handlebars/pom.xml b/handlebars/pom.xml index b26dafe21..0f647daa1 100644 --- a/handlebars/pom.xml +++ b/handlebars/pom.xml @@ -222,7 +222,7 @@ commons-io commons-io - 2.6 + 2.8.0 test From badd79956fadfa70e6473835f05a1b2a388e52b7 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 17:57:47 +0000 Subject: [PATCH 017/157] [Security] Bump junit from 4.13 to 4.13.1 Bumps [junit](https://github.com/junit-team/junit4) from 4.13 to 4.13.1. **This update includes a security fix.** - [Release notes](https://github.com/junit-team/junit4/releases) - [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.13.1.md) - [Commits](https://github.com/junit-team/junit4/compare/r4.13...r4.13.1) Signed-off-by: dependabot-preview[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9a6cf2364..62387f8f2 100644 --- a/pom.xml +++ b/pom.xml @@ -148,7 +148,7 @@ junit junit test - 4.13 + 4.13.1 From 32760601757d899cde919a63a8e2fddd8d00c6f2 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 22 Feb 2021 09:23:48 +0000 Subject: [PATCH 018/157] Bump snakeyaml from 1.10 to 1.28 Bumps [snakeyaml](https://bitbucket.org/asomov/snakeyaml) from 1.10 to 1.28. - [Commits](https://bitbucket.org/asomov/snakeyaml/branches/compare/snakeyaml-1.28..v1.10) Signed-off-by: dependabot-preview[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 62387f8f2..05af34d88 100644 --- a/pom.xml +++ b/pom.xml @@ -154,7 +154,7 @@ org.yaml snakeyaml - 1.10 + 1.28 test From 4007ad8941ed6d1c578a1cf169aa987d0c972304 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 29 Apr 2021 21:28:12 +0000 Subject: [PATCH 019/157] Upgrade to GitHub-native Dependabot --- .github/dependabot.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..3bb582caa --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,38 @@ +version: 2 +updates: +- package-ecosystem: maven + directory: "/" + schedule: + interval: daily + time: "09:00" + open-pull-requests-limit: 10 + ignore: + - dependency-name: org.springframework:spring-test + versions: + - ">= 5.a, < 6" + - dependency-name: com.google.javascript:closure-compiler + versions: + - v20210106 + - v20210202 + - v20210302 + - dependency-name: org.eclipse.jetty:jetty-servlet + versions: + - 11.0.0 + - 11.0.1 + - dependency-name: org.eclipse.jetty:jetty-webapp + versions: + - 11.0.0 + - 11.0.1 + - dependency-name: org.eclipse.jetty:jetty-server + versions: + - 11.0.0 + - 11.0.1 + - dependency-name: org.yaml:snakeyaml + versions: + - "1.27" + - dependency-name: org.apache.commons:commons-lang3 + versions: + - "3.11" + - dependency-name: org.apache.felix:maven-bundle-plugin + versions: + - 5.1.1 From 7cc3360866f3a24b0547ff4091b6cfa887dd7875 Mon Sep 17 00:00:00 2001 From: Edgar Espina Date: Sat, 25 Sep 2021 15:31:34 -0300 Subject: [PATCH 020/157] build: fix yaml upgrade --- .../github/jknack/handlebars/helper/StringHelpers.java | 6 ++++-- .../com/github/jknack/handlebars/AbstractTest.java | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java index 3d178653b..798247222 100644 --- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java +++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java @@ -503,7 +503,8 @@ protected CharSequence safeApply(final Object context, final Options options) { *

    * *
    -   *    {{dateFormat date ["format"] [format="format"][locale="locale"][tz=timeZone|timeZoneId][time="format"]}}
    +   *    {{dateFormat date ["format"] [format="format"][locale="locale"][tz=timeZone|timeZoneId]
    +   *        [time="format"]}}
        * 
    * * Format parameters is one of: @@ -527,7 +528,8 @@ protected CharSequence safeApply(final Object context, final Options options) { * It defaults to the system time zone. * *
  • - * The "time" parameter specifies the format of the time part, it can be "full", "long", "medium" or "short". + * The "time" parameter specifies the format of the time part, it can be "full", "long", + * "medium" or "short". * If you do not specify it only the date part will appear in the output string. *
  • * diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/AbstractTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/AbstractTest.java index 0bfb9fcd1..4cc8180e8 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/AbstractTest.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/AbstractTest.java @@ -33,7 +33,7 @@ public void shouldCompileTo(final String template, final String context, final String expected, final String message) throws IOException { Object deserializedContext = context; if (deserializedContext != null) { - deserializedContext = new Yaml().load(context); + deserializedContext = parseYaml(context); } shouldCompileTo(template, deserializedContext, expected, message); } @@ -50,12 +50,16 @@ public void shouldCompileTo(final String template, final Object context, public void shouldCompileTo(final String template, final String context, final Hash helpers, final String expected) throws IOException { - shouldCompileTo(template, new Yaml().load(context), helpers, expected, ""); + shouldCompileTo(template, parseYaml(context), helpers, expected, ""); + } + + private Object parseYaml(String context) { + return new Yaml().load(context); } public void shouldCompileTo(final String template, final String context, final Hash helpers, final String expected, final String message) throws IOException { - shouldCompileTo(template, new Yaml().load(context), helpers, expected, message); + shouldCompileTo(template, parseYaml(context), helpers, expected, message); } public void shouldCompileTo(final String template, final Object context, From 5eeab12c18270abcbc6f1e113f2e028b67f6e917 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Sep 2021 17:34:47 +0000 Subject: [PATCH 021/157] Bump easymock from 4.2 to 4.3 Bumps [easymock](https://github.com/easymock/easymock) from 4.2 to 4.3. - [Release notes](https://github.com/easymock/easymock/releases) - [Changelog](https://github.com/easymock/easymock/blob/master/ReleaseNotes.md) - [Commits](https://github.com/easymock/easymock/compare/easymock-4.2...easymock-4.3) --- updated-dependencies: - dependency-name: org.easymock:easymock dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 05af34d88..d740fbb2e 100644 --- a/pom.xml +++ b/pom.xml @@ -161,7 +161,7 @@ org.easymock easymock - 4.2 + 4.3 From 519de4ad64cbd2c969b8bec2448e298efa25338b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Sep 2021 17:34:50 +0000 Subject: [PATCH 022/157] Bump snakeyaml from 1.28 to 1.29 Bumps [snakeyaml](https://bitbucket.org/asomov/snakeyaml) from 1.28 to 1.29. - [Commits](https://bitbucket.org/asomov/snakeyaml/branches/compare/snakeyaml-1.29..snakeyaml-1.28) --- updated-dependencies: - dependency-name: org.yaml:snakeyaml dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d740fbb2e..04717da79 100644 --- a/pom.xml +++ b/pom.xml @@ -154,7 +154,7 @@ org.yaml snakeyaml - 1.28 + 1.29 test From a5ca54ca5ba20648e91a0a0859ab8ec21dd3c700 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Sep 2021 17:34:54 +0000 Subject: [PATCH 023/157] Bump antlr-version from 4.8-1 to 4.9.2 Bumps `antlr-version` from 4.8-1 to 4.9.2. Updates `antlr4-runtime` from 4.8-1 to 4.9.2 - [Release notes](https://github.com/antlr/antlr4/releases) - [Changelog](https://github.com/antlr/antlr4/blob/master/CHANGES.txt) - [Commits](https://github.com/antlr/antlr4/commits/4.9.2) Updates `antlr4-maven-plugin` from 4.8-1 to 4.9.2 - [Release notes](https://github.com/antlr/antlr4/releases) - [Changelog](https://github.com/antlr/antlr4/blob/master/CHANGES.txt) - [Commits](https://github.com/antlr/antlr4/commits/4.9.2) --- updated-dependencies: - dependency-name: org.antlr:antlr4-runtime dependency-type: direct:production - dependency-name: org.antlr:antlr4-maven-plugin dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- handlebars/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlebars/pom.xml b/handlebars/pom.xml index 0f647daa1..2ee9ade4f 100644 --- a/handlebars/pom.xml +++ b/handlebars/pom.xml @@ -241,7 +241,7 @@ - 4.8-1 + 4.9.2 From 0670733be501ee9a0793c6d510131ee81b538bc2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Sep 2021 17:34:55 +0000 Subject: [PATCH 024/157] Bump jackson-databind from 2.9.10.7 to 2.12.5 Bumps [jackson-databind](https://github.com/FasterXML/jackson) from 2.9.10.7 to 2.12.5. - [Release notes](https://github.com/FasterXML/jackson/releases) - [Commits](https://github.com/FasterXML/jackson/commits) --- updated-dependencies: - dependency-name: com.fasterxml.jackson.core:jackson-databind dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 04717da79..6f08fcc12 100644 --- a/pom.xml +++ b/pom.xml @@ -421,7 +421,7 @@ UTF-8 - 2.9.10.7 + 2.12.5 1.2.2 0.8.5 yyyy-MM-dd HH:mm:ssa From d82499e4cb2b90536bd79a2745af0c2d41304d60 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Sep 2021 17:34:59 +0000 Subject: [PATCH 025/157] Bump joda-time from 2.10.6 to 2.10.11 Bumps [joda-time](https://github.com/JodaOrg/joda-time) from 2.10.6 to 2.10.11. - [Release notes](https://github.com/JodaOrg/joda-time/releases) - [Changelog](https://github.com/JodaOrg/joda-time/blob/master/RELEASE-NOTES.txt) - [Commits](https://github.com/JodaOrg/joda-time/compare/v2.10.6...v2.10.11) --- updated-dependencies: - dependency-name: joda-time:joda-time dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- handlebars-helpers/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlebars-helpers/pom.xml b/handlebars-helpers/pom.xml index f70fde687..a92c465de 100644 --- a/handlebars-helpers/pom.xml +++ b/handlebars-helpers/pom.xml @@ -30,7 +30,7 @@ joda-time joda-time - 2.10.6 + 2.10.11 true From 8bd8febca4bb9fbeab9d3fd5d4b730088263cfd3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Sep 2021 17:35:13 +0000 Subject: [PATCH 026/157] Bump powermock-api-easymock from 2.0.7 to 2.0.9 Bumps [powermock-api-easymock](https://github.com/powermock/powermock) from 2.0.7 to 2.0.9. - [Release notes](https://github.com/powermock/powermock/releases) - [Changelog](https://github.com/powermock/powermock/blob/release/2.x/docs/changelog.txt) - [Commits](https://github.com/powermock/powermock/compare/powermock-2.0.7...powermock-2.0.9) --- updated-dependencies: - dependency-name: org.powermock:powermock-api-easymock dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6f08fcc12..5d312d6d3 100644 --- a/pom.xml +++ b/pom.xml @@ -167,7 +167,7 @@ org.powermock powermock-api-easymock - 2.0.7 + 2.0.9 test From d81be3e10dbb6e7549dd34d7488012f33c4214e9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Sep 2021 17:35:17 +0000 Subject: [PATCH 027/157] Bump junit from 4.13.1 to 4.13.2 Bumps [junit](https://github.com/junit-team/junit4) from 4.13.1 to 4.13.2. - [Release notes](https://github.com/junit-team/junit4/releases) - [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.13.1.md) - [Commits](https://github.com/junit-team/junit4/compare/r4.13.1...r4.13.2) --- updated-dependencies: - dependency-name: junit:junit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5d312d6d3..b51664893 100644 --- a/pom.xml +++ b/pom.xml @@ -148,7 +148,7 @@ junit junit test - 4.13.1 + 4.13.2 From fade13e2f6298fde2c5f0d83b6c1243a1e47b7fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Sep 2021 17:35:21 +0000 Subject: [PATCH 028/157] Bump maven-plugin-annotations from 3.6.0 to 3.6.1 Bumps [maven-plugin-annotations](https://github.com/apache/maven-plugin-tools) from 3.6.0 to 3.6.1. - [Release notes](https://github.com/apache/maven-plugin-tools/releases) - [Commits](https://github.com/apache/maven-plugin-tools/compare/maven-plugin-tools-3.6.0...maven-plugin-tools-3.6.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugin-tools:maven-plugin-annotations dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- handlebars-maven-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml index a38c7603b..5c8bf4714 100644 --- a/handlebars-maven-plugin/pom.xml +++ b/handlebars-maven-plugin/pom.xml @@ -56,7 +56,7 @@ org.apache.maven.plugin-tools maven-plugin-annotations - 3.6.0 + 3.6.1 provided From 490f9399b7879d4839fd2193569bb1ae77e4aab9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Sep 2021 17:35:24 +0000 Subject: [PATCH 029/157] Bump maven-core from 3.6.3 to 3.8.2 Bumps [maven-core](https://github.com/apache/maven) from 3.6.3 to 3.8.2. - [Release notes](https://github.com/apache/maven/releases) - [Commits](https://github.com/apache/maven/compare/maven-3.6.3...maven-3.8.2) --- updated-dependencies: - dependency-name: org.apache.maven:maven-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- handlebars-maven-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml index 5c8bf4714..b2feb5b2e 100644 --- a/handlebars-maven-plugin/pom.xml +++ b/handlebars-maven-plugin/pom.xml @@ -50,7 +50,7 @@ org.apache.maven maven-core - 3.6.3 + 3.8.2 From dfc2b900c0ff685d439af508cd147c1cbd8ff1c4 Mon Sep 17 00:00:00 2001 From: Edgar Espina Date: Sat, 25 Sep 2021 15:49:29 -0300 Subject: [PATCH 030/157] helpers: remove warn while overriding a helper --- .../github/jknack/handlebars/helper/DefaultHelperRegistry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java index ee7db2d27..e921b4a86 100644 --- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java +++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java @@ -112,7 +112,7 @@ public HelperRegistry registerHelper(final String name, final Helper help Helper oldHelper = helpers.put(name, helper); if (oldHelper != null) { - logger.warn("Helper '{}' has been replaced by '{}'", name, helper); + logger.debug("Helper '{}' has been replaced by '{}'", name, helper); } return this; } From 1cf383b855611c18b3f31e55bdba394aa71c1bce Mon Sep 17 00:00:00 2001 From: Brian Caruso Date: Tue, 2 Feb 2021 21:56:44 -0800 Subject: [PATCH 031/157] Add @HelperFunction annotation for overriding method names from Helper Sources (#829) --- .../helper/DefaultHelperRegistry.java | 3 ++- .../handlebars/helper/HelperFunction.java | 18 ++++++++++++++++++ .../handlebars/ReflectiveHelperTest.java | 11 +++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java index e921b4a86..3cdd33fd7 100644 --- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java +++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java @@ -234,10 +234,11 @@ private void registerDynamicHelper(final Object source, final Class clazz) { Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { boolean isPublic = Modifier.isPublic(method.getModifiers()); - String helperName = method.getName(); if (isPublic) { boolean isStatic = Modifier.isStatic(method.getModifiers()); if (source != null || isStatic) { + HelperFunction annotation = method.getAnnotation(HelperFunction.class); + String helperName = annotation != null ? annotation.value() : method.getName(); isTrue(overloaded.add(helperName), "name conflict found: " + helperName); registerHelper(helperName, new MethodHelper(method, source)); } diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java new file mode 100644 index 000000000..2dbc56e11 --- /dev/null +++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java @@ -0,0 +1,18 @@ +package com.github.jknack.handlebars.helper; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Decorates a method that represents a helper function extracted via a "helper source" + * with metadata that cannot be inferred from its signature, such as a custom helper name. + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface HelperFunction { + + /** + * The name used to invoke the decorated helper function in a handlebars template. + */ + String value(); + +} diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/ReflectiveHelperTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/ReflectiveHelperTest.java index 192968320..fa4644390 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/ReflectiveHelperTest.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/ReflectiveHelperTest.java @@ -8,6 +8,7 @@ import java.io.IOException; +import com.github.jknack.handlebars.helper.HelperFunction; import org.junit.Test; import com.github.jknack.handlebars.Handlebars.SafeString; @@ -53,6 +54,11 @@ public void testHelperWithParamsAndOptions() throws IOException { "helperWithParamsAndOptions:string:true:4"); } + @Test + public void testAnnotatedHelper() throws IOException { + shouldCompileTo("{{this-is-annotated}}", null, "i am an annotated helper function"); + } + @Test public void testBlog() throws IOException { shouldCompileTo("{{blog this}}", new Blog("title", "body"), @@ -155,6 +161,11 @@ public SafeString helperWithParamsAndOptions(final String context, final boolean return new SafeString(String.format("helperWithParamsAndOptions:%s:%s:%s", context, p0, p1)); } + @HelperFunction("this-is-annotated") + public CharSequence annotatedHelper() { + return "i am an annotated helper function"; + } + public CharSequence blog(final Blog blog, final Options options) { assertNotNull(options); return "blog:" + blog.toString(); From 2a4b461db20b1564c5d3ffe3e85b57baebddb2cc Mon Sep 17 00:00:00 2001 From: Edgar Espina Date: Sat, 25 Sep 2021 15:52:46 -0300 Subject: [PATCH 032/157] build: keep jdk 1.8 on github actions. Will add more jdk progressively --- .github/workflows/build-matrix.yml | 2 +- .../handlebars/helper/HelperFunction.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-matrix.yml b/.github/workflows/build-matrix.yml index 482dc4f42..1f61ab8fc 100644 --- a/.github/workflows/build-matrix.yml +++ b/.github/workflows/build-matrix.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: false matrix: - java_version: [1.8, 11, 13, 15, 17] + java_version: [1.8] os: [ubuntu-latest, windows-latest, macOS-latest] steps: diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java index 2dbc56e11..3252b8ec4 100644 --- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java +++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java @@ -1,3 +1,20 @@ +/** + * Copyright (c) 2012-2015 Edgar Espina + * + * This file is part of Handlebars.java. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.github.jknack.handlebars.helper; import java.lang.annotation.Retention; @@ -12,6 +29,7 @@ /** * The name used to invoke the decorated helper function in a handlebars template. + * @return Name or null/empty to use default method name. */ String value(); From 76b66abe07a9314f9e6f41f12f08b4305d0f443f Mon Sep 17 00:00:00 2001 From: Edgar Espina Date: Sat, 25 Sep 2021 21:12:34 -0300 Subject: [PATCH 033/157] upgrade: guava for cache but not when using humanize - next release going to remove humanize from project (it is not active anymore) --- handlebars-humanize/pom.xml | 6 ++++++ pom.xml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/handlebars-humanize/pom.xml b/handlebars-humanize/pom.xml index b6c407226..61d6cc454 100644 --- a/handlebars-humanize/pom.xml +++ b/handlebars-humanize/pom.xml @@ -14,6 +14,12 @@ Humanize helpers + + com.google.guava + guava + 23.0 + + com.github.jknack handlebars diff --git a/pom.xml b/pom.xml index b51664893..3ea17b3ef 100644 --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,7 @@ com.google.guava guava - 23.0 + 30.0-jre From 2afc50fd5dcd32af28f8305b59689b3fec4a3b07 Mon Sep 17 00:00:00 2001 From: Edgar Espina Date: Sun, 26 Sep 2021 13:01:42 -0300 Subject: [PATCH 034/157] v4.2.1 --- handlebars-guava-cache/pom.xml | 2 +- handlebars-helpers/pom.xml | 2 +- handlebars-humanize/pom.xml | 2 +- handlebars-jackson2/pom.xml | 2 +- handlebars-markdown/pom.xml | 2 +- handlebars-maven-plugin-tests/pom.xml | 2 +- handlebars-maven-plugin/pom.xml | 2 +- handlebars-proto/pom.xml | 2 +- handlebars-springmvc/pom.xml | 2 +- handlebars/pom.xml | 2 +- pom.xml | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/handlebars-guava-cache/pom.xml b/handlebars-guava-cache/pom.xml index 87cf48f05..9b6ac5eb2 100644 --- a/handlebars-guava-cache/pom.xml +++ b/handlebars-guava-cache/pom.xml @@ -5,7 +5,7 @@ com.github.jknack handlebars.java - 4.2.1-SNAPSHOT + 4.2.1 4.0.0 diff --git a/handlebars-helpers/pom.xml b/handlebars-helpers/pom.xml index a92c465de..e127bd774 100644 --- a/handlebars-helpers/pom.xml +++ b/handlebars-helpers/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.2.1-SNAPSHOT + 4.2.1 4.0.0 diff --git a/handlebars-humanize/pom.xml b/handlebars-humanize/pom.xml index 61d6cc454..248739a53 100644 --- a/handlebars-humanize/pom.xml +++ b/handlebars-humanize/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.2.1-SNAPSHOT + 4.2.1 4.0.0 diff --git a/handlebars-jackson2/pom.xml b/handlebars-jackson2/pom.xml index 111bb8ad8..2f99ce448 100644 --- a/handlebars-jackson2/pom.xml +++ b/handlebars-jackson2/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.2.1-SNAPSHOT + 4.2.1 4.0.0 diff --git a/handlebars-markdown/pom.xml b/handlebars-markdown/pom.xml index 90b308917..8112e6758 100644 --- a/handlebars-markdown/pom.xml +++ b/handlebars-markdown/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.2.1-SNAPSHOT + 4.2.1 4.0.0 diff --git a/handlebars-maven-plugin-tests/pom.xml b/handlebars-maven-plugin-tests/pom.xml index 439b34f48..1b2865b20 100644 --- a/handlebars-maven-plugin-tests/pom.xml +++ b/handlebars-maven-plugin-tests/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.2.1-SNAPSHOT + 4.2.1 4.0.0 diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml index b2feb5b2e..d51482c77 100644 --- a/handlebars-maven-plugin/pom.xml +++ b/handlebars-maven-plugin/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.2.1-SNAPSHOT + 4.2.1 4.0.0 diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml index 3d5746cb1..3afe2ea2a 100644 --- a/handlebars-proto/pom.xml +++ b/handlebars-proto/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.2.1-SNAPSHOT + 4.2.1 4.0.0 diff --git a/handlebars-springmvc/pom.xml b/handlebars-springmvc/pom.xml index b9d8fca99..3b62f712d 100644 --- a/handlebars-springmvc/pom.xml +++ b/handlebars-springmvc/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.2.1-SNAPSHOT + 4.2.1 4.0.0 diff --git a/handlebars/pom.xml b/handlebars/pom.xml index 2ee9ade4f..1859aaca9 100644 --- a/handlebars/pom.xml +++ b/handlebars/pom.xml @@ -6,7 +6,7 @@ com.github.jknack handlebars.java - 4.2.1-SNAPSHOT + 4.2.1 4.0.0 diff --git a/pom.xml b/pom.xml index 3ea17b3ef..79bc75411 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.github.jknack handlebars.java - 4.2.1-SNAPSHOT + 4.2.1 pom Handlebars.java From 6a4ab57f4ddfb1be05f799a3aa53530c857a8870 Mon Sep 17 00:00:00 2001 From: Edgar Espina Date: Sun, 26 Sep 2021 13:02:19 -0300 Subject: [PATCH 035/157] prepare for next development cycle --- handlebars-guava-cache/pom.xml | 2 +- handlebars-helpers/pom.xml | 2 +- handlebars-humanize/pom.xml | 2 +- handlebars-jackson2/pom.xml | 2 +- handlebars-markdown/pom.xml | 2 +- handlebars-maven-plugin-tests/pom.xml | 2 +- handlebars-maven-plugin/pom.xml | 2 +- handlebars-proto/pom.xml | 2 +- handlebars-springmvc/pom.xml | 2 +- handlebars/pom.xml | 2 +- pom.xml | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/handlebars-guava-cache/pom.xml b/handlebars-guava-cache/pom.xml index 9b6ac5eb2..bc81524da 100644 --- a/handlebars-guava-cache/pom.xml +++ b/handlebars-guava-cache/pom.xml @@ -5,7 +5,7 @@ com.github.jknack handlebars.java - 4.2.1 + 4.3.0-SNAPSHOT 4.0.0 diff --git a/handlebars-helpers/pom.xml b/handlebars-helpers/pom.xml index e127bd774..2aa26507b 100644 --- a/handlebars-helpers/pom.xml +++ b/handlebars-helpers/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.2.1 + 4.3.0-SNAPSHOT 4.0.0 diff --git a/handlebars-humanize/pom.xml b/handlebars-humanize/pom.xml index 248739a53..bf1159e2c 100644 --- a/handlebars-humanize/pom.xml +++ b/handlebars-humanize/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.2.1 + 4.3.0-SNAPSHOT 4.0.0 diff --git a/handlebars-jackson2/pom.xml b/handlebars-jackson2/pom.xml index 2f99ce448..603d816c6 100644 --- a/handlebars-jackson2/pom.xml +++ b/handlebars-jackson2/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.2.1 + 4.3.0-SNAPSHOT 4.0.0 diff --git a/handlebars-markdown/pom.xml b/handlebars-markdown/pom.xml index 8112e6758..0f098df2d 100644 --- a/handlebars-markdown/pom.xml +++ b/handlebars-markdown/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.2.1 + 4.3.0-SNAPSHOT 4.0.0 diff --git a/handlebars-maven-plugin-tests/pom.xml b/handlebars-maven-plugin-tests/pom.xml index 1b2865b20..3cab1f89c 100644 --- a/handlebars-maven-plugin-tests/pom.xml +++ b/handlebars-maven-plugin-tests/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.2.1 + 4.3.0-SNAPSHOT 4.0.0 diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml index d51482c77..efb37c691 100644 --- a/handlebars-maven-plugin/pom.xml +++ b/handlebars-maven-plugin/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.2.1 + 4.3.0-SNAPSHOT 4.0.0 diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml index 3afe2ea2a..6fc692d54 100644 --- a/handlebars-proto/pom.xml +++ b/handlebars-proto/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.2.1 + 4.3.0-SNAPSHOT 4.0.0 diff --git a/handlebars-springmvc/pom.xml b/handlebars-springmvc/pom.xml index 3b62f712d..c1b9894dd 100644 --- a/handlebars-springmvc/pom.xml +++ b/handlebars-springmvc/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.2.1 + 4.3.0-SNAPSHOT 4.0.0 diff --git a/handlebars/pom.xml b/handlebars/pom.xml index 1859aaca9..b3e29a49d 100644 --- a/handlebars/pom.xml +++ b/handlebars/pom.xml @@ -6,7 +6,7 @@ com.github.jknack handlebars.java - 4.2.1 + 4.3.0-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index 79bc75411..fbd91fea3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.github.jknack handlebars.java - 4.2.1 + 4.3.0-SNAPSHOT pom Handlebars.java From 96e61bd4b1659d3d45bdb396dffd2f1a56a75f6d Mon Sep 17 00:00:00 2001 From: Edgar Espina Date: Mon, 27 Sep 2021 09:47:24 -0300 Subject: [PATCH 036/157] build: attempt to fix windows build --- .../jknack/handlebars/Jackson2HelperTest.java | 62 +++++++++---------- handlebars-maven-plugin/a.txt | 54 ++++++++++++++++ handlebars-maven-plugin/b.txt | 54 ++++++++++++++++ handlebars-maven-plugin/pom.xml | 8 +++ .../handlebars/maven/PrecompilePlugin.java | 1 - .../handlebars/maven/I18nJsPluginTest.java | 19 +++++- .../jknack/handlebars/maven/Issue230.java | 13 +++- .../jknack/handlebars/maven/Issue234.java | 17 ++++- .../maven/PrecompilePluginTest.java | 30 +++++---- .../test/resources/helpers-i18njs.expected | 1 - .../src/test/resources/helpers.expected | 4 -- .../src/test/resources/i230.properties | 2 +- .../src/test/resources/issue234.expected | 2 - .../test/resources/specific-files.expected | 2 - .../handlebars/IgnoreWindowsLineMatcher.java | 28 +++++++++ .../handlebars/TemporalPartialTest.java | 41 ++++++------ .../jknack/handlebars/i275/Issue275.java | 29 +++++---- .../jknack/handlebars/issues/Hbs507.java | 33 +++++----- 18 files changed, 291 insertions(+), 109 deletions(-) create mode 100644 handlebars-maven-plugin/a.txt create mode 100644 handlebars-maven-plugin/b.txt create mode 100644 handlebars/src/test/java/com/github/jknack/handlebars/IgnoreWindowsLineMatcher.java diff --git a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Jackson2HelperTest.java b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Jackson2HelperTest.java index 37c6eecba..f6cbf5568 100644 --- a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Jackson2HelperTest.java +++ b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Jackson2HelperTest.java @@ -13,7 +13,8 @@ */ package com.github.jknack.handlebars; -import static org.junit.Assert.assertEquals; +import static com.github.jknack.handlebars.IgnoreWindowsLineMatcher.equalsToStringIgnoringWindowsNewLine; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.util.HashMap; @@ -40,10 +41,8 @@ public void toJSON() throws IOException { Template template = handlebars.compileInline("{{@json this}}"); - CharSequence result = template.apply(new Blog("First Post", "...")); - - assertEquals("{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}", - result); + assertThat(template.apply(new Blog("First Post", "...")), equalsToStringIgnoringWindowsNewLine( + "{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}")); } @Test @@ -53,14 +52,12 @@ public void toPrettyJSON() throws IOException { Template template = handlebars.compileInline("{{@json this pretty=true}}"); - CharSequence result = template.apply(new Blog("First Post", "...")); - - assertEquals("{\n" + - " \"title\" : \"First Post\",\n" + - " \"body\" : \"...\",\n" + - " \"comments\" : [ ]\n" + - "}", - result); + assertThat(template.apply(new Blog("First Post", "...")), + equalsToStringIgnoringWindowsNewLine("{\n" + + " \"title\" : \"First Post\",\n" + + " \"body\" : \"...\",\n" + + " \"comments\" : [ ]\n" + + "}")); } @Test @@ -71,12 +68,12 @@ public void toJSONViewInclusive() throws IOException { Template template = handlebars - .compileInline("{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}"); - - CharSequence result = template.apply(new Blog("First Post", "...")); + .compileInline( + "{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}"); - assertEquals("{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}", - result); + assertThat(template.apply(new Blog("First Post", "...")), + equalsToStringIgnoringWindowsNewLine( + "{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}")); } @Test @@ -90,11 +87,11 @@ public void toJSONViewExclusive() throws IOException { Template template = handlebars - .compileInline("{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}"); + .compileInline( + "{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}"); - CharSequence result = template.apply(new Blog("First Post", "...")); - - assertEquals("{\"title\":\"First Post\"}", result); + assertThat(template.apply(new Blog("First Post", "...")), + equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}")); } @Test @@ -111,9 +108,8 @@ public void toJSONAliasViewExclusive() throws IOException { handlebars .compileInline("{{@json this view=\"myView\"}}"); - CharSequence result = template.apply(new Blog("First Post", "...")); - - assertEquals("{\"title\":\"First Post\"}", result); + assertThat(template.apply(new Blog("First Post", "...")), + equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}")); } @Test(expected = HandlebarsException.class) @@ -129,9 +125,8 @@ public void jsonViewNotFound() throws IOException { handlebars .compileInline("{{@json this view=\"missing.ViewClass\"}}"); - CharSequence result = template.apply(new Blog("First Post", "...")); - - assertEquals("{\"title\":\"First Post\"}", result); + assertThat(template.apply(new Blog("First Post", "...")), + equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}")); } @Test @@ -142,11 +137,12 @@ public void escapeHtml() throws IOException { Map model = new HashMap(); model.put("script", ""); - assertEquals("{\"script\":\"\"}", handlebars - .compileInline("{{@json this}}").apply(model)); + assertThat(handlebars + .compileInline("{{@json this}}").apply(model), equalsToStringIgnoringWindowsNewLine( + "{\"script\":\"\"}")); - assertEquals( - "{\"script\":\"\\u003Cscript text=\\\"text/javascript\\\"\\u003E\\u003C/script\\u003E\"}", - handlebars.compileInline("{{@json this escapeHTML=true}}").apply(model)); + assertThat(handlebars.compileInline("{{@json this escapeHTML=true}}").apply(model), + equalsToStringIgnoringWindowsNewLine( + "{\"script\":\"\\u003Cscript text=\\\"text/javascript\\\"\\u003E\\u003C/script\\u003E\"}")); } } diff --git a/handlebars-maven-plugin/a.txt b/handlebars-maven-plugin/a.txt new file mode 100644 index 000000000..58bb9ad25 --- /dev/null +++ b/handlebars-maven-plugin/a.txt @@ -0,0 +1,54 @@ +... () { +// Source: src[/test/resources/partials/level1/level1.html + + var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + var helper, lookupProperty = container.lookupProperty || function(parent, propertyName) { + if (Object.prototype.hasOwnProperty.call(parent, propertyName)) { + return parent[propertyName]; + } + return undefined + }; + + return "

    I'm " + + container.escapeExpression(((helper = (helper = lookupProperty(helpers,"level1") || (depth0 != null ? lookupProperty(depth0,"level1") : depth0)) != null ? helper : container.hooks.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"level1","hash":{},"data":data,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":18}}}) : helper))) + + "

    "; +},"useData":true}); + var templates = Handlebars.templates = Handlebars.templates || {}; + templates['level1/level1'] = template; + var partials = Handlebars.partials = Handlebars.partials || {}; + partials['level1/level1'] = template; + + +// Source: src/test/resources/partials/partial/base.html + + var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) { + if (Object.prototype.hasOwnProperty.call(parent, propertyName)) { + return parent[propertyName]; + } + return undefined + }; + + return "I'm the base partial\n" + + ((stack1 = container.invokePartial(lookupProperty(partials,"partial/partial"),depth0,{"name":"partial/partial","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); +},"usePartial":true,"useData":true}); + var templates = Handlebars.templates = Handlebars.templates || {}; + templates['partial/base'] = template; + var partials = Handlebars.partials = Handlebars.partials || {}; + partials['partial/base'] = template; + + +// Source: src/test/resources/partials/partial/partial.html + + var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + return "I'm the child partial"; +},"useData":true}); + var templates = Handlebars.templates = Handlebars.templates || {}; + templates['partial/partial'] = template; + var partials = Handlebars.partials = Handlebars.partials || {}; + partials['partial/partial'] = template; + + +// Source: src/test/resources/partials/r]oot.html + + var temp... diff --git a/handlebars-maven-plugin/b.txt b/handlebars-maven-plugin/b.txt new file mode 100644 index 000000000..e11eae7c4 --- /dev/null +++ b/handlebars-maven-plugin/b.txt @@ -0,0 +1,54 @@ +... () { +// Source: src[\testesources\partials\level1\level1.html + + var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + var helper, lookupProperty = container.lookupProperty || function(parent, propertyName) { + if (Object.prototype.hasOwnProperty.call(parent, propertyName)) { + return parent[propertyName]; + } + return undefined + }; + + return "

    I'm " + + container.escapeExpression(((helper = (helper = lookupProperty(helpers,"level1") || (depth0 != null ? lookupProperty(depth0,"level1") : depth0)) != null ? helper : container.hooks.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"level1","hash":{},"data":data,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":18}}}) : helper))) + + "

    "; +},"useData":true}); + var templates = Handlebars.templates = Handlebars.templates || {}; + templates['level1/level1'] = template; + var partials = Handlebars.partials = Handlebars.partials || {}; + partials['level1/level1'] = template; + + +// Source: src\testesources\partials\partial\base.html + + var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) { + if (Object.prototype.hasOwnProperty.call(parent, propertyName)) { + return parent[propertyName]; + } + return undefined + }; + + return "I'm the base partial\n" + + ((stack1 = container.invokePartial(lookupProperty(partials,"partial/partial"),depth0,{"name":"partial/partial","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); +},"usePartial":true,"useData":true}); + var templates = Handlebars.templates = Handlebars.templates || {}; + templates['partial/base'] = template; + var partials = Handlebars.partials = Handlebars.partials || {}; + partials['partial/base'] = template; + + +// Source: src\testesources\partials\partial\partial.html + + var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { + return "I'm the child partial"; +},"useData":true}); + var templates = Handlebars.templates = Handlebars.templates || {}; + templates['partial/partial'] = template; + var partials = Handlebars.partials = Handlebars.partials || {}; + partials['partial/partial'] = template; + + +// Source: src\testesources\partials]oot.html + + var temp... diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml index efb37c691..836ce2f2b 100644 --- a/handlebars-maven-plugin/pom.xml +++ b/handlebars-maven-plugin/pom.xml @@ -90,6 +90,14 @@ easymock test
    + + + com.github.jknack + handlebars + ${project.version} + test + tests +
    diff --git a/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/PrecompilePlugin.java b/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/PrecompilePlugin.java index 9f6b80a0b..42eac9287 100644 --- a/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/PrecompilePlugin.java +++ b/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/PrecompilePlugin.java @@ -230,7 +230,6 @@ protected void doExecute() throws Exception { .setHash(hash) .build(); - writer.append("// Source: ").append(file.getPath()).append("\n"); writer.append(PrecompileHelper.INSTANCE.apply(templateName, opts).toString()) .append("\n\n"); } diff --git a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/I18nJsPluginTest.java b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/I18nJsPluginTest.java index 1ebdddfef..31338c8a4 100644 --- a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/I18nJsPluginTest.java +++ b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/I18nJsPluginTest.java @@ -47,8 +47,7 @@ public void i18nJsNoMergeDeepPath() throws Exception { plugin.execute(); - assertEquals(FileUtils.fileRead("src/test/resources/deep.expected.js"), - FileUtils.fileRead("target/deep.js")); + equalsToIgnoreBlanks("src/test/resources/deep.expected.js", "target/deep.js"); } @Test @@ -106,7 +105,21 @@ private MavenProject newProject(final String... classpath) * Matches on tokens and avoid errors between Java 6.x and Java 7.x. */ private Set tokens(final String filename) throws IOException { - String content = FileUtils.fileRead(filename); + String content = FileUtils.fileRead(filename) + .replace("\r", "") + .replace("\t", " "); return Sets.newLinkedHashSet(Splitter.on(Pattern.compile("\\s|,")).split(content)); } + + private void equalsToIgnoreBlanks(String expected, String found) throws IOException { + assertEquals(replaceWhiteCharsWithSpace(FileUtils.fileRead(expected)), + replaceWhiteCharsWithSpace(FileUtils.fileRead(found))); + } + + private String replaceWhiteCharsWithSpace(String content) { + return content + .replace("\r", "") + .replace("\t", " ") + .trim(); + } } diff --git a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue230.java b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue230.java index bac5a4fc1..fbf8d4221 100644 --- a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue230.java +++ b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue230.java @@ -5,6 +5,8 @@ import static org.easymock.EasyMock.replay; import static org.junit.Assert.assertEquals; +import java.io.IOException; + import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.FileUtils; @@ -27,9 +29,9 @@ public void issue230() throws Exception { " /* English (United States) */\n" + " I18n.translations = I18n.translations || {};\n" + " I18n.translations['en_US'] = {\n" + - " \"pagination_top_of_page\": \"Inicio de la página\"\n" + + " \"pagination_top_of_page\": \"Inicio de la pagina\"\n" + " };\n" + - "})();\n", FileUtils.fileRead("target/i230.js")); + "})();", replaceWhiteCharsWithSpace(FileUtils.fileRead("target/i230.js"))); } private MavenProject newProject(final String... classpath) @@ -39,4 +41,11 @@ private MavenProject newProject(final String... classpath) replay(project); return project; } + + private String replaceWhiteCharsWithSpace(String content) { + return content + .replace("\r", "") + .replace("\t", " ") + .trim(); + } } diff --git a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java index 986023614..fa54cb404 100644 --- a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java +++ b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java @@ -5,6 +5,8 @@ import static org.easymock.EasyMock.replay; import static org.junit.Assert.assertEquals; +import java.io.IOException; + import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.FileUtils; @@ -28,8 +30,19 @@ public void withAmdOutput() throws Exception { plugin.execute(); - assertEquals(FileUtils.fileRead("target/issue234.js"), FileUtils.fileRead("src/test/resources/issue234.expected").trim(), - FileUtils.fileRead("target/issue234.js").trim()); + equalsToIgnoreBlanks("src/test/resources/issue234.expected", "target/issue234.js"); + } + + private void equalsToIgnoreBlanks(String expected, String found) throws IOException { + assertEquals(replaceWhiteCharsWithSpace(FileUtils.fileRead(expected)), + replaceWhiteCharsWithSpace(FileUtils.fileRead(found))); + } + + private String replaceWhiteCharsWithSpace(String content) { + return content.trim() + .replace("\\r\\n", "\\n") + .replace("\r", "") + .replace("\t", " "); } private MavenProject newProject(final String... classpath) diff --git a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java index 31bbcbf8a..88d819c6d 100644 --- a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java +++ b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java @@ -7,6 +7,7 @@ import static org.junit.Assert.assertTrue; import java.io.File; +import java.io.IOException; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DependencyResolutionRequiredException; @@ -31,9 +32,20 @@ public void i18nJs() throws Exception { plugin.execute(); - assertEquals(FileUtils.fileRead("target/helpers-i18njs.js"), - FileUtils.fileRead("src/test/resources/helpers-i18njs.expected").trim(), - FileUtils.fileRead("target/helpers-i18njs.js").trim()); + equalsToIgnoreBlanks("src/test/resources/helpers-i18njs.expected", "target/helpers-i18njs.js"); + } + + private void equalsToIgnoreBlanks(String expected, String found) throws IOException { + assertEquals(replaceWhiteCharsWithSpace(FileUtils.fileRead(expected)), + replaceWhiteCharsWithSpace(FileUtils.fileRead(found))); + } + + private String replaceWhiteCharsWithSpace(String content) { + return content + .replace("\\r\\n", "\\n") + .replace("\r", "") + .replace("\t", " ") + .trim(); } @Test @@ -49,9 +61,7 @@ public void chooseSpecificFiles() throws Exception { plugin.execute(); - assertEquals(FileUtils.fileRead("target/specific-files.js"), - FileUtils.fileRead("src/test/resources/specific-files.expected").trim(), - FileUtils.fileRead("target/specific-files.js").trim()); + equalsToIgnoreBlanks("src/test/resources/specific-files.expected", "target/specific-files.js"); } @Test @@ -155,7 +165,7 @@ public void fileWithRuntimeMustBeLargerThanNormalFiles() throws Exception { assertTrue("File with runtime must be larger", FileUtils.fileRead("target/without-rt-helpers.js").length() < - FileUtils.fileRead("target/with-rt-helpers.js").length()); + FileUtils.fileRead("target/with-rt-helpers.js").length()); } @Test @@ -180,7 +190,7 @@ public void normalFileShouleBeLargerThanMinimizedFiles() throws Exception { assertTrue("Normal file must be larger than minimized", FileUtils.fileRead("target/helpers-normal.js").length() > - FileUtils.fileRead("target/helpers.min.js").length()); + FileUtils.fileRead("target/helpers.min.js").length()); } @Test @@ -194,9 +204,7 @@ public void partials() throws Exception { plugin.execute(); - assertEquals(FileUtils.fileRead("target/helpers.js"), - FileUtils.fileRead("src/test/resources/helpers.expected").trim(), - FileUtils.fileRead("target/helpers.js").trim()); + equalsToIgnoreBlanks("src/test/resources/helpers.expected", "target/helpers.js"); } private MavenProject newProject(final String... classpath) diff --git a/handlebars-maven-plugin/src/test/resources/helpers-i18njs.expected b/handlebars-maven-plugin/src/test/resources/helpers-i18njs.expected index fac1b66d3..21a1cd43e 100644 --- a/handlebars-maven-plugin/src/test/resources/helpers-i18njs.expected +++ b/handlebars-maven-plugin/src/test/resources/helpers-i18njs.expected @@ -1,5 +1,4 @@ (function () { -// Source: src/test/resources/i18nJs/i18njs.html var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { var helper, lookupProperty = container.lookupProperty || function(parent, propertyName) { diff --git a/handlebars-maven-plugin/src/test/resources/helpers.expected b/handlebars-maven-plugin/src/test/resources/helpers.expected index c8a1cf1cf..3d789496a 100644 --- a/handlebars-maven-plugin/src/test/resources/helpers.expected +++ b/handlebars-maven-plugin/src/test/resources/helpers.expected @@ -1,5 +1,4 @@ (function () { -// Source: src/test/resources/partials/level1/level1.html var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { var helper, lookupProperty = container.lookupProperty || function(parent, propertyName) { @@ -19,7 +18,6 @@ partials['level1/level1'] = template; -// Source: src/test/resources/partials/partial/base.html var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) { @@ -38,7 +36,6 @@ partials['partial/base'] = template; -// Source: src/test/resources/partials/partial/partial.html var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { return "I'm the child partial"; @@ -49,7 +46,6 @@ partials['partial/partial'] = template; -// Source: src/test/resources/partials/root.html var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { return "Hello " diff --git a/handlebars-maven-plugin/src/test/resources/i230.properties b/handlebars-maven-plugin/src/test/resources/i230.properties index d5338b368..874b46d37 100644 --- a/handlebars-maven-plugin/src/test/resources/i230.properties +++ b/handlebars-maven-plugin/src/test/resources/i230.properties @@ -1 +1 @@ -pagination_top_of_page = Inicio de la página \ No newline at end of file +pagination_top_of_page = Inicio de la pagina diff --git a/handlebars-maven-plugin/src/test/resources/issue234.expected b/handlebars-maven-plugin/src/test/resources/issue234.expected index 04830afc1..af0b68f29 100644 --- a/handlebars-maven-plugin/src/test/resources/issue234.expected +++ b/handlebars-maven-plugin/src/test/resources/issue234.expected @@ -1,4 +1,3 @@ -// Source: src/test/resources/templates/a.hbs define('a.hbs', ['handlebars'], function(Handlebars) { var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { return "I'm template a.\nHello " @@ -12,7 +11,6 @@ define('a.hbs', ['handlebars'], function(Handlebars) { return template; }); -// Source: src/test/resources/templates/c.hbs define('c.hbs', ['handlebars'], function(Handlebars) { var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { return "I'm template c.\nHello " diff --git a/handlebars-maven-plugin/src/test/resources/specific-files.expected b/handlebars-maven-plugin/src/test/resources/specific-files.expected index 57b69b72c..0dac70f4e 100644 --- a/handlebars-maven-plugin/src/test/resources/specific-files.expected +++ b/handlebars-maven-plugin/src/test/resources/specific-files.expected @@ -1,5 +1,4 @@ (function () { -// Source: src/test/resources/templates/a.hbs var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { return "I'm template a.\nHello " @@ -12,7 +11,6 @@ partials['a'] = template; -// Source: src/test/resources/templates/c.hbs var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { return "I'm template c.\nHello " diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/IgnoreWindowsLineMatcher.java b/handlebars/src/test/java/com/github/jknack/handlebars/IgnoreWindowsLineMatcher.java new file mode 100644 index 000000000..b325987a2 --- /dev/null +++ b/handlebars/src/test/java/com/github/jknack/handlebars/IgnoreWindowsLineMatcher.java @@ -0,0 +1,28 @@ +package com.github.jknack.handlebars; + +import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; + +public class IgnoreWindowsLineMatcher extends TypeSafeMatcher { + + private String value; + + private IgnoreWindowsLineMatcher(String value) { + this.value = value; + } + + public static IgnoreWindowsLineMatcher equalsToStringIgnoringWindowsNewLine(String value) { + return new IgnoreWindowsLineMatcher(value); + } + + @Override protected boolean matchesSafely(String item) { + return item.replace("\r\n", "\n").equals(value); + } + + @Override public void describeTo(Description description) { + description.appendText("a string ") + .appendText("ignoring \\r") + .appendText(" ") + .appendValue(value); + } +} diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/TemporalPartialTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/TemporalPartialTest.java index dd7a1ac39..7954fc7d2 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/TemporalPartialTest.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/TemporalPartialTest.java @@ -1,6 +1,7 @@ package com.github.jknack.handlebars; -import static org.junit.Assert.assertEquals; +import static com.github.jknack.handlebars.IgnoreWindowsLineMatcher.equalsToStringIgnoringWindowsNewLine; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.util.Arrays; @@ -34,12 +35,13 @@ public CharSequence apply(final Item item, final Options options) throws IOExcep } }); Template template = handlebars.compile("temporal-partials"); - assertEquals("Items:\n" + - "\n" + - "Item: Custom\n" + - "...\n" + - "Item: 2\n" + - "...\n", template.apply(Arrays.asList(new Item("1"), new Item("2")))); + assertThat(template.apply(Arrays.asList(new Item("1"), new Item("2"))), + equalsToStringIgnoringWindowsNewLine("Items:\n" + + "\n" + + "Item: Custom\n" + + "...\n" + + "Item: 2\n" + + "...\n")); } @Test @@ -47,17 +49,18 @@ public void defaultPartials() throws IOException { Handlebars handlebars = new Handlebars(); handlebars.setPrettyPrint(true); Template template = handlebars.compile("derived"); - assertEquals("\n" + - "\n" + - "\n" + - " \n" + - " Home \n" + - " \n" + - "\n" + - "\n" + - "

    Home

    \n" + - " HOME\n" + - "\n" + - "", template.apply(null)); + assertThat(template.apply(null), + equalsToStringIgnoringWindowsNewLine("\n" + + "\n" + + "\n" + + " \n" + + " Home \n" + + " \n" + + "\n" + + "\n" + + "

    Home

    \n" + + " HOME\n" + + "\n" + + "")); } } diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/i275/Issue275.java b/handlebars/src/test/java/com/github/jknack/handlebars/i275/Issue275.java index 5c2ab1524..075eb7c81 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/i275/Issue275.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/i275/Issue275.java @@ -1,6 +1,7 @@ package com.github.jknack.handlebars.i275; -import static org.junit.Assert.assertEquals; +import static com.github.jknack.handlebars.IgnoreWindowsLineMatcher.equalsToStringIgnoringWindowsNewLine; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.util.Arrays; @@ -41,12 +42,13 @@ public CharSequence apply(final Item item, final Options options) throws IOExcep } }); Template template = handlebars.compile("temporal-partials"); - assertEquals("Items:\n" + - "\n" + - "Item: Custom\n" + - "...\n" + - "Item: 2\n" + - "...\n", template.apply(Arrays.asList(new Item("1"), new Item("2")))); + assertThat(template.apply(Arrays.asList(new Item("1"), new Item("2"))), + equalsToStringIgnoringWindowsNewLine("Items:\n" + + "\n" + + "Item: Custom\n" + + "...\n" + + "Item: 2\n" + + "...\n")); } @Test @@ -63,11 +65,12 @@ public CharSequence apply(final Item item, final Options options) throws IOExcep } }); Template template = handlebars.compile("temporal-partials"); - assertEquals("Items:\n" + - "\n" + - "Item: Custom\n" + - "...\n" + - "Item: Custom\n" + - "...\n", template.apply(Arrays.asList(new Item("1"), new Item("2")))); + assertThat(template.apply(Arrays.asList(new Item("1"), new Item("2"))), + equalsToStringIgnoringWindowsNewLine("Items:\n" + + "\n" + + "Item: Custom\n" + + "...\n" + + "Item: Custom\n" + + "...\n")); } } diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/issues/Hbs507.java b/handlebars/src/test/java/com/github/jknack/handlebars/issues/Hbs507.java index 96efb7f23..5cab35564 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/issues/Hbs507.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/issues/Hbs507.java @@ -1,6 +1,7 @@ package com.github.jknack.handlebars.issues; -import static org.junit.Assert.assertEquals; +import static com.github.jknack.handlebars.IgnoreWindowsLineMatcher.equalsToStringIgnoringWindowsNewLine; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.util.Map; @@ -12,11 +13,11 @@ import com.github.jknack.handlebars.Helper; import com.github.jknack.handlebars.Options; import com.github.jknack.handlebars.Template; -import com.github.jknack.handlebars.v4Test; import com.github.jknack.handlebars.cache.HighConcurrencyTemplateCache; import com.github.jknack.handlebars.cache.NullTemplateCache; import com.github.jknack.handlebars.cache.TemplateCache; import com.github.jknack.handlebars.io.ClassPathTemplateLoader; +import com.github.jknack.handlebars.v4Test; public class Hbs507 extends v4Test { @@ -61,19 +62,21 @@ public CharSequence apply(final Object partial, final Options options) $("aggregateId", "ID:y0", "aggregateType", "brett", "businessKey", "favre")); Template template = handlebars.compile("a"); - assertEquals("This is a test for: \"ID:x0\"\n" + - "\n" + - "\"metadata.aggregateId\" : \"ID:x0\" \n" + - "\"metadata.businessKey\" : \"favre\"\n" + - "\n" + - "End test", template.apply(h1)); - - assertEquals("This is a test for: \"ID:y0\"\n" + - "\n" + - "\"metadata.aggregateId\" : \"ID:y0\" \n" + - "\"metadata.businessKey\" : \"favre\"\n" + - "\n" + - "End test", template.apply(h2)); + assertThat(template.apply(h1), + equalsToStringIgnoringWindowsNewLine("This is a test for: \"ID:x0\"\n" + + "\n" + + "\"metadata.aggregateId\" : \"ID:x0\" \n" + + "\"metadata.businessKey\" : \"favre\"\n" + + "\n" + + "End test")); + + assertThat(template.apply(h2), + equalsToStringIgnoringWindowsNewLine("This is a test for: \"ID:y0\"\n" + + "\n" + + "\"metadata.aggregateId\" : \"ID:y0\" \n" + + "\"metadata.businessKey\" : \"favre\"\n" + + "\n" + + "End test")); } } From e0952192c3ae38053a532ecba0621740eb9de926 Mon Sep 17 00:00:00 2001 From: Edgar Espina Date: Sun, 3 Oct 2021 20:21:47 -0300 Subject: [PATCH 037/157] Remove Guava from maven build - Fixes #881 - Guava cache module is still available - Add notes about very old humanize library --- handlebars-guava-cache/pom.xml | 1 + .../handlebars/cache/GuavaTemplateCache.java | 2 +- handlebars-humanize/README.md | 8 + handlebars-humanize/pom.xml | 6 - handlebars-maven-plugin/a.txt | 54 --- handlebars-maven-plugin/b.txt | 54 --- handlebars-maven-plugin/pom.xml | 6 - out | 334 ++++++++++++++++++ pom.xml | 7 - 9 files changed, 344 insertions(+), 128 deletions(-) create mode 100644 handlebars-humanize/README.md delete mode 100644 handlebars-maven-plugin/a.txt delete mode 100644 handlebars-maven-plugin/b.txt create mode 100644 out diff --git a/handlebars-guava-cache/pom.xml b/handlebars-guava-cache/pom.xml index bc81524da..aa3c4d42b 100644 --- a/handlebars-guava-cache/pom.xml +++ b/handlebars-guava-cache/pom.xml @@ -25,6 +25,7 @@ com.google.guava guava + 30.0-jre diff --git a/handlebars-guava-cache/src/main/java/com/github/jknack/handlebars/cache/GuavaTemplateCache.java b/handlebars-guava-cache/src/main/java/com/github/jknack/handlebars/cache/GuavaTemplateCache.java index 9b746052a..d2292f55c 100644 --- a/handlebars-guava-cache/src/main/java/com/github/jknack/handlebars/cache/GuavaTemplateCache.java +++ b/handlebars-guava-cache/src/main/java/com/github/jknack/handlebars/cache/GuavaTemplateCache.java @@ -30,7 +30,7 @@ /** * An implementation of {@link TemplateCache} built on top of Guava. If {@link #setReload(boolean)} - * is on we recommended to use one of the available auto-eviction policy of Guava, it + * is on we recommended one of the available auto-eviction policy of Guava, it * helps to reduce leaks when auto-reload is on. * * @author edgar.espina diff --git a/handlebars-humanize/README.md b/handlebars-humanize/README.md new file mode 100644 index 000000000..5050186b8 --- /dev/null +++ b/handlebars-humanize/README.md @@ -0,0 +1,8 @@ +handlebars-humanize +====== + +A collection of helpers for https://github.com/mfornos/humanize + +The https://github.com/mfornos/humanize library depends on very old version of Guava. + +We are going to remove humanize from handlebars.java in near future. diff --git a/handlebars-humanize/pom.xml b/handlebars-humanize/pom.xml index bf1159e2c..e1f14a035 100644 --- a/handlebars-humanize/pom.xml +++ b/handlebars-humanize/pom.xml @@ -14,12 +14,6 @@ Humanize helpers - - com.google.guava - guava - 23.0 - - com.github.jknack handlebars diff --git a/handlebars-maven-plugin/a.txt b/handlebars-maven-plugin/a.txt deleted file mode 100644 index 58bb9ad25..000000000 --- a/handlebars-maven-plugin/a.txt +++ /dev/null @@ -1,54 +0,0 @@ -... () { -// Source: src[/test/resources/partials/level1/level1.html - - var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { - var helper, lookupProperty = container.lookupProperty || function(parent, propertyName) { - if (Object.prototype.hasOwnProperty.call(parent, propertyName)) { - return parent[propertyName]; - } - return undefined - }; - - return "

    I'm " - + container.escapeExpression(((helper = (helper = lookupProperty(helpers,"level1") || (depth0 != null ? lookupProperty(depth0,"level1") : depth0)) != null ? helper : container.hooks.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"level1","hash":{},"data":data,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":18}}}) : helper))) - + "

    "; -},"useData":true}); - var templates = Handlebars.templates = Handlebars.templates || {}; - templates['level1/level1'] = template; - var partials = Handlebars.partials = Handlebars.partials || {}; - partials['level1/level1'] = template; - - -// Source: src/test/resources/partials/partial/base.html - - var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { - var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) { - if (Object.prototype.hasOwnProperty.call(parent, propertyName)) { - return parent[propertyName]; - } - return undefined - }; - - return "I'm the base partial\n" - + ((stack1 = container.invokePartial(lookupProperty(partials,"partial/partial"),depth0,{"name":"partial/partial","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"usePartial":true,"useData":true}); - var templates = Handlebars.templates = Handlebars.templates || {}; - templates['partial/base'] = template; - var partials = Handlebars.partials = Handlebars.partials || {}; - partials['partial/base'] = template; - - -// Source: src/test/resources/partials/partial/partial.html - - var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { - return "I'm the child partial"; -},"useData":true}); - var templates = Handlebars.templates = Handlebars.templates || {}; - templates['partial/partial'] = template; - var partials = Handlebars.partials = Handlebars.partials || {}; - partials['partial/partial'] = template; - - -// Source: src/test/resources/partials/r]oot.html - - var temp... diff --git a/handlebars-maven-plugin/b.txt b/handlebars-maven-plugin/b.txt deleted file mode 100644 index e11eae7c4..000000000 --- a/handlebars-maven-plugin/b.txt +++ /dev/null @@ -1,54 +0,0 @@ -... () { -// Source: src[\testesources\partials\level1\level1.html - - var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { - var helper, lookupProperty = container.lookupProperty || function(parent, propertyName) { - if (Object.prototype.hasOwnProperty.call(parent, propertyName)) { - return parent[propertyName]; - } - return undefined - }; - - return "

    I'm " - + container.escapeExpression(((helper = (helper = lookupProperty(helpers,"level1") || (depth0 != null ? lookupProperty(depth0,"level1") : depth0)) != null ? helper : container.hooks.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"level1","hash":{},"data":data,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":18}}}) : helper))) - + "

    "; -},"useData":true}); - var templates = Handlebars.templates = Handlebars.templates || {}; - templates['level1/level1'] = template; - var partials = Handlebars.partials = Handlebars.partials || {}; - partials['level1/level1'] = template; - - -// Source: src\testesources\partials\partial\base.html - - var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { - var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) { - if (Object.prototype.hasOwnProperty.call(parent, propertyName)) { - return parent[propertyName]; - } - return undefined - }; - - return "I'm the base partial\n" - + ((stack1 = container.invokePartial(lookupProperty(partials,"partial/partial"),depth0,{"name":"partial/partial","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"usePartial":true,"useData":true}); - var templates = Handlebars.templates = Handlebars.templates || {}; - templates['partial/base'] = template; - var partials = Handlebars.partials = Handlebars.partials || {}; - partials['partial/base'] = template; - - -// Source: src\testesources\partials\partial\partial.html - - var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) { - return "I'm the child partial"; -},"useData":true}); - var templates = Handlebars.templates = Handlebars.templates || {}; - templates['partial/partial'] = template; - var partials = Handlebars.partials = Handlebars.partials || {}; - partials['partial/partial'] = template; - - -// Source: src\testesources\partials]oot.html - - var temp... diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml index 836ce2f2b..5c0b28c44 100644 --- a/handlebars-maven-plugin/pom.xml +++ b/handlebars-maven-plugin/pom.xml @@ -72,12 +72,6 @@ v20210601
    - - com.google.guava - guava - 23.0 - - junit diff --git a/out b/out new file mode 100644 index 000000000..2b99d9476 --- /dev/null +++ b/out @@ -0,0 +1,334 @@ +[INFO] Scanning for projects... +[INFO] Inspecting build with total of 11 modules... +[INFO] Installing Nexus Staging features: +[INFO] ... total of 11 executions of maven-deploy-plugin replaced with nexus-staging-maven-plugin +[WARNING] The project com.github.jknack:handlebars.java:pom:4.3.0-SNAPSHOT uses prerequisites which is only intended for maven-plugin projects but not for non maven-plugin projects. For such purposes you should use the maven-enforcer-plugin. See https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html +[INFO] ------------------------------------------------------------------------ +[INFO] Reactor Build Order: +[INFO] +[INFO] Handlebars.java [pom] +[INFO] Handlebars [jar] +[INFO] Handlebars Helpers [jar] +[INFO] Handlebars Spring MVC [jar] +[INFO] A Jackson 2.x helper [jar] +[INFO] A Markdown Helper [jar] +[INFO] Humanize helpers [jar] +[INFO] A standalone Handlebars Server [jar] +[INFO] Handlebars Guava Cache [jar] +[INFO] Handlebars.js maven plugin [maven-plugin] +[INFO] Handlebars.js maven plugin tests [war] +[INFO] +[INFO] -----------------< com.github.jknack:handlebars.java >------------------ +[INFO] Building Handlebars.java 4.3.0-SNAPSHOT [1/11] +[INFO] --------------------------------[ pom ]--------------------------------- +[INFO] +[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ handlebars.java --- +[INFO] com.github.jknack:handlebars.java:pom:4.3.0-SNAPSHOT +[INFO] +[INFO] --------------------< com.github.jknack:handlebars >-------------------- +[INFO] Building Handlebars 4.3.0-SNAPSHOT [2/11] +[INFO] --------------------------------[ jar ]--------------------------------- +[INFO] +[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ handlebars --- +[INFO] com.github.jknack:handlebars:jar:4.3.0-SNAPSHOT +[INFO] +- org.apache.commons:commons-lang3:jar:3.12.0:compile +[INFO] +- org.apache.commons:commons-text:jar:1.8:compile +[INFO] +- org.antlr:antlr4-runtime:jar:4.9.2:compile +[INFO] +- org.slf4j:slf4j-api:jar:1.7.30:compile +[INFO] +- javax.servlet:servlet-api:jar:2.5:provided +[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:test +[INFO] | \- ch.qos.logback:logback-core:jar:1.2.3:test +[INFO] +- org.jacoco:org.jacoco.agent:jar:runtime:0.8.5:test +[INFO] +- junit:junit:jar:4.13.2:test +[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test +[INFO] +- org.yaml:snakeyaml:jar:1.29:test +[INFO] +- org.easymock:easymock:jar:4.3:test +[INFO] | \- org.objenesis:objenesis:jar:3.2:test +[INFO] +- commons-io:commons-io:jar:2.8.0:test +[INFO] +- org.powermock:powermock-api-easymock:jar:2.0.9:test +[INFO] | +- org.powermock:powermock-api-support:jar:2.0.9:test +[INFO] | | +- org.powermock:powermock-reflect:jar:2.0.9:test +[INFO] | | | +- net.bytebuddy:byte-buddy:jar:1.10.14:test +[INFO] | | | \- net.bytebuddy:byte-buddy-agent:jar:1.10.14:test +[INFO] | | \- org.powermock:powermock-core:jar:2.0.9:test +[INFO] | | \- org.javassist:javassist:jar:3.27.0-GA:test +[INFO] | \- cglib:cglib-nodep:jar:3.2.9:test +[INFO] \- org.powermock:powermock-module-junit4:jar:2.0.7:test +[INFO] \- org.powermock:powermock-module-junit4-common:jar:2.0.7:test +[INFO] +[INFO] ----------------< com.github.jknack:handlebars-helpers >---------------- +[INFO] Building Handlebars Helpers 4.3.0-SNAPSHOT [3/11] +[INFO] --------------------------------[ jar ]--------------------------------- +[INFO] +[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ handlebars-helpers --- +[INFO] com.github.jknack:handlebars-helpers:jar:4.3.0-SNAPSHOT +[INFO] +- com.github.jknack:handlebars:jar:4.3.0-SNAPSHOT:compile +[INFO] | \- org.slf4j:slf4j-api:jar:1.7.30:compile +[INFO] +- org.apache.commons:commons-lang3:jar:3.12.0:compile +[INFO] +- joda-time:joda-time:jar:2.10.11:compile +[INFO] +- javax.servlet:servlet-api:jar:2.5:provided +[INFO] +- com.github.jknack:handlebars:jar:tests:4.3.0-SNAPSHOT:test +[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:test +[INFO] | \- ch.qos.logback:logback-core:jar:1.2.3:test +[INFO] +- junit:junit:jar:4.13.2:test +[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test +[INFO] +- org.easymock:easymock:jar:4.3:test +[INFO] | \- org.objenesis:objenesis:jar:3.2:test +[INFO] \- org.yaml:snakeyaml:jar:1.29:test +[INFO] +[INFO] ---------------< com.github.jknack:handlebars-springmvc >--------------- +[INFO] Building Handlebars Spring MVC 4.3.0-SNAPSHOT [4/11] +[INFO] --------------------------------[ jar ]--------------------------------- +[INFO] +[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ handlebars-springmvc --- +[INFO] com.github.jknack:handlebars-springmvc:jar:4.3.0-SNAPSHOT +[INFO] +- com.github.jknack:handlebars:jar:4.3.0-SNAPSHOT:compile +[INFO] | \- org.slf4j:slf4j-api:jar:1.7.30:compile +[INFO] +- org.springframework:spring-webmvc:jar:3.1.1.RELEASE:compile +[INFO] | +- org.springframework:spring-asm:jar:3.1.1.RELEASE:compile +[INFO] | +- org.springframework:spring-beans:jar:3.1.1.RELEASE:compile +[INFO] | +- org.springframework:spring-context:jar:3.1.1.RELEASE:compile +[INFO] | | \- org.springframework:spring-aop:jar:3.1.1.RELEASE:compile +[INFO] | +- org.springframework:spring-context-support:jar:3.1.1.RELEASE:compile +[INFO] | +- org.springframework:spring-core:jar:3.1.1.RELEASE:compile +[INFO] | | \- commons-logging:commons-logging:jar:1.1.1:compile +[INFO] | +- org.springframework:spring-expression:jar:3.1.1.RELEASE:compile +[INFO] | \- org.springframework:spring-web:jar:3.1.1.RELEASE:compile +[INFO] | \- aopalliance:aopalliance:jar:1.0:compile +[INFO] +- javax.servlet:servlet-api:jar:2.5:provided +[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:test +[INFO] | \- ch.qos.logback:logback-core:jar:1.2.3:test +[INFO] +- org.springframework:spring-test:jar:3.1.1.RELEASE:test +[INFO] +- junit:junit:jar:4.13.2:test +[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test +[INFO] +- org.easymock:easymock:jar:4.3:test +[INFO] | \- org.objenesis:objenesis:jar:3.2:test +[INFO] +- org.powermock:powermock-api-easymock:jar:2.0.9:test +[INFO] | +- org.powermock:powermock-api-support:jar:2.0.9:test +[INFO] | | +- org.powermock:powermock-reflect:jar:2.0.9:test +[INFO] | | | +- net.bytebuddy:byte-buddy:jar:1.10.14:test +[INFO] | | | \- net.bytebuddy:byte-buddy-agent:jar:1.10.14:test +[INFO] | | \- org.powermock:powermock-core:jar:2.0.9:test +[INFO] | | \- org.javassist:javassist:jar:3.27.0-GA:test +[INFO] | \- cglib:cglib-nodep:jar:3.2.9:test +[INFO] \- org.powermock:powermock-module-junit4:jar:2.0.7:test +[INFO] \- org.powermock:powermock-module-junit4-common:jar:2.0.7:test +[INFO] +[INFO] ---------------< com.github.jknack:handlebars-jackson2 >---------------- +[INFO] Building A Jackson 2.x helper 4.3.0-SNAPSHOT [5/11] +[INFO] --------------------------------[ jar ]--------------------------------- +[INFO] +[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ handlebars-jackson2 --- +[INFO] com.github.jknack:handlebars-jackson2:jar:4.3.0-SNAPSHOT +[INFO] +- com.github.jknack:handlebars:jar:4.3.0-SNAPSHOT:compile +[INFO] | \- org.slf4j:slf4j-api:jar:1.7.30:compile +[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.12.5:compile +[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.12.5:compile +[INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.12.5:compile +[INFO] +- javax.servlet:servlet-api:jar:2.5:provided +[INFO] +- com.github.jknack:handlebars:jar:tests:4.3.0-SNAPSHOT:test +[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:test +[INFO] | \- ch.qos.logback:logback-core:jar:1.2.3:test +[INFO] +- junit:junit:jar:4.13.2:test +[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test +[INFO] \- org.easymock:easymock:jar:4.3:test +[INFO] \- org.objenesis:objenesis:jar:3.2:test +[INFO] +[INFO] ---------------< com.github.jknack:handlebars-markdown >---------------- +[INFO] Building A Markdown Helper 4.3.0-SNAPSHOT [6/11] +[INFO] --------------------------------[ jar ]--------------------------------- +[INFO] +[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ handlebars-markdown --- +[INFO] com.github.jknack:handlebars-markdown:jar:4.3.0-SNAPSHOT +[INFO] +- com.github.jknack:handlebars:jar:4.3.0-SNAPSHOT:compile +[INFO] | \- org.slf4j:slf4j-api:jar:1.7.30:compile +[INFO] +- org.pegdown:pegdown:jar:1.6.0:compile +[INFO] | \- org.parboiled:parboiled-java:jar:1.1.7:compile +[INFO] | +- org.parboiled:parboiled-core:jar:1.1.7:compile +[INFO] | +- org.ow2.asm:asm:jar:5.0.3:compile +[INFO] | +- org.ow2.asm:asm-tree:jar:5.0.3:compile +[INFO] | +- org.ow2.asm:asm-analysis:jar:5.0.3:compile +[INFO] | \- org.ow2.asm:asm-util:jar:5.0.3:compile +[INFO] +- javax.servlet:servlet-api:jar:2.5:provided +[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:test +[INFO] | \- ch.qos.logback:logback-core:jar:1.2.3:test +[INFO] \- junit:junit:jar:4.13.2:test +[INFO] \- org.hamcrest:hamcrest-core:jar:1.3:test +[INFO] +[INFO] ---------------< com.github.jknack:handlebars-humanize >---------------- +[INFO] Building Humanize helpers 4.3.0-SNAPSHOT [7/11] +[INFO] --------------------------------[ jar ]--------------------------------- +[INFO] +[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ handlebars-humanize --- +[INFO] com.github.jknack:handlebars-humanize:jar:4.3.0-SNAPSHOT +[INFO] +- com.github.jknack:handlebars:jar:4.3.0-SNAPSHOT:compile +[INFO] | \- org.slf4j:slf4j-api:jar:1.7.30:compile +[INFO] +- com.github.mfornos:humanize-slim:jar:1.2.2:compile +[INFO] | +- com.google.guava:guava:jar:18.0:compile +[INFO] | +- org.ocpsoft.prettytime:prettytime:jar:3.2.5.Final:compile +[INFO] | +- me.xuender:unidecode:jar:0.0.7:compile +[INFO] | \- com.google.code.findbugs:jsr305:jar:1.3.9:compile +[INFO] +- javax.servlet:servlet-api:jar:2.5:provided +[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:test +[INFO] | \- ch.qos.logback:logback-core:jar:1.2.3:test +[INFO] \- junit:junit:jar:4.13.2:test +[INFO] \- org.hamcrest:hamcrest-core:jar:1.3:test +[INFO] +[INFO] -----------------< com.github.jknack:handlebars-proto >----------------- +[INFO] Building A standalone Handlebars Server 4.3.0-SNAPSHOT [8/11] +[INFO] --------------------------------[ jar ]--------------------------------- +[INFO] +[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ handlebars-proto --- +[INFO] com.github.jknack:handlebars-proto:jar:4.3.0-SNAPSHOT +[INFO] +- org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016:compile +[INFO] +- com.github.jknack:handlebars:jar:4.3.0-SNAPSHOT:compile +[INFO] | \- org.slf4j:slf4j-api:jar:1.7.30:compile +[INFO] +- com.github.jknack:handlebars-jackson2:jar:4.3.0-SNAPSHOT:compile +[INFO] +- com.github.jknack:handlebars-markdown:jar:4.3.0-SNAPSHOT:compile +[INFO] | \- org.pegdown:pegdown:jar:1.6.0:compile +[INFO] | \- org.parboiled:parboiled-java:jar:1.1.7:compile +[INFO] | +- org.parboiled:parboiled-core:jar:1.1.7:compile +[INFO] | +- org.ow2.asm:asm:jar:5.0.3:compile +[INFO] | +- org.ow2.asm:asm-tree:jar:5.0.3:compile +[INFO] | +- org.ow2.asm:asm-analysis:jar:5.0.3:compile +[INFO] | \- org.ow2.asm:asm-util:jar:5.0.3:compile +[INFO] +- com.github.jknack:handlebars-humanize:jar:4.3.0-SNAPSHOT:compile +[INFO] | \- com.github.mfornos:humanize-slim:jar:1.2.2:compile +[INFO] | +- com.google.guava:guava:jar:18.0:compile +[INFO] | +- org.ocpsoft.prettytime:prettytime:jar:3.2.5.Final:compile +[INFO] | +- me.xuender:unidecode:jar:0.0.7:compile +[INFO] | \- com.google.code.findbugs:jsr305:jar:1.3.9:compile +[INFO] +- commons-io:commons-io:jar:2.8.0:compile +[INFO] +- org.apache.commons:commons-lang3:jar:3.12.0:compile +[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.12.5:compile +[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.12.5:compile +[INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.12.5:compile +[INFO] +- org.yaml:snakeyaml:jar:1.29:compile +[INFO] +- org.eclipse.jetty:jetty-server:jar:9.4.43.v20210629:compile +[INFO] | +- javax.servlet:javax.servlet-api:jar:3.1.0:compile +[INFO] | +- org.eclipse.jetty:jetty-http:jar:9.4.43.v20210629:compile +[INFO] | | \- org.eclipse.jetty:jetty-util:jar:9.4.43.v20210629:compile +[INFO] | \- org.eclipse.jetty:jetty-io:jar:9.4.43.v20210629:compile +[INFO] +- org.eclipse.jetty:jetty-webapp:jar:9.4.43.v20210629:compile +[INFO] | \- org.eclipse.jetty:jetty-xml:jar:9.4.43.v20210629:compile +[INFO] +- org.eclipse.jetty:jetty-servlet:jar:9.4.43.v20210629:compile +[INFO] | +- org.eclipse.jetty:jetty-security:jar:9.4.43.v20210629:compile +[INFO] | \- org.eclipse.jetty:jetty-util-ajax:jar:9.4.43.v20210629:compile +[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:compile +[INFO] | \- ch.qos.logback:logback-core:jar:1.2.3:compile +[INFO] +- args4j:args4j:jar:2.33:compile +[INFO] \- junit:junit:jar:4.13.2:test +[INFO] \- org.hamcrest:hamcrest-core:jar:1.3:test +[INFO] +[INFO] --------------< com.github.jknack:handlebars-guava-cache >-------------- +[INFO] Building Handlebars Guava Cache 4.3.0-SNAPSHOT [9/11] +[INFO] --------------------------------[ jar ]--------------------------------- +[INFO] +[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ handlebars-guava-cache --- +[INFO] com.github.jknack:handlebars-guava-cache:jar:4.3.0-SNAPSHOT +[INFO] +- com.github.jknack:handlebars:jar:4.3.0-SNAPSHOT:compile +[INFO] | \- org.slf4j:slf4j-api:jar:1.7.30:compile +[INFO] +- com.google.guava:guava:jar:30.0-jre:compile +[INFO] | +- com.google.guava:failureaccess:jar:1.0.1:compile +[INFO] | +- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile +[INFO] | +- com.google.code.findbugs:jsr305:jar:3.0.2:compile +[INFO] | +- org.checkerframework:checker-qual:jar:3.5.0:compile +[INFO] | +- com.google.errorprone:error_prone_annotations:jar:2.3.4:compile +[INFO] | \- com.google.j2objc:j2objc-annotations:jar:1.3:compile +[INFO] +- javax.servlet:servlet-api:jar:2.5:provided +[INFO] +- com.github.jknack:handlebars:jar:tests:4.3.0-SNAPSHOT:test +[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:test +[INFO] | \- ch.qos.logback:logback-core:jar:1.2.3:test +[INFO] +- junit:junit:jar:4.13.2:test +[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test +[INFO] \- org.easymock:easymock:jar:4.3:test +[INFO] \- org.objenesis:objenesis:jar:3.2:test +[INFO] +[INFO] -------------< com.github.jknack:handlebars-maven-plugin >-------------- +[INFO] Building Handlebars.js maven plugin 4.3.0-SNAPSHOT [10/11] +[INFO] ----------------------------[ maven-plugin ]---------------------------- +[INFO] +[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ handlebars-maven-plugin --- +[INFO] com.github.jknack:handlebars-maven-plugin:maven-plugin:4.3.0-SNAPSHOT +[INFO] +- com.github.jknack:handlebars:jar:4.3.0-SNAPSHOT:compile +[INFO] | \- org.slf4j:slf4j-api:jar:1.7.30:compile +[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:compile +[INFO] | \- ch.qos.logback:logback-core:jar:1.2.3:compile +[INFO] +- javax.servlet:servlet-api:jar:2.5:provided +[INFO] +- org.apache.maven:maven-plugin-api:jar:3.6.3:compile +[INFO] | +- org.apache.maven:maven-model:jar:3.6.3:compile +[INFO] | +- org.apache.maven:maven-artifact:jar:3.6.3:compile +[INFO] | +- org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.3.4:compile +[INFO] | | \- javax.enterprise:cdi-api:jar:1.0:compile +[INFO] | | \- javax.annotation:jsr250-api:jar:1.0:compile +[INFO] | \- org.codehaus.plexus:plexus-classworlds:jar:2.6.0:compile +[INFO] +- org.apache.maven:maven-project:jar:2.2.1:compile +[INFO] | +- org.apache.maven:maven-settings:jar:2.2.1:compile +[INFO] | +- org.apache.maven:maven-profile:jar:2.2.1:compile +[INFO] | +- org.apache.maven:maven-artifact-manager:jar:2.2.1:compile +[INFO] | | +- org.apache.maven.wagon:wagon-provider-api:jar:1.0-beta-6:compile +[INFO] | | \- backport-util-concurrent:backport-util-concurrent:jar:3.1:compile +[INFO] | +- org.apache.maven:maven-plugin-registry:jar:2.2.1:compile +[INFO] | +- org.codehaus.plexus:plexus-interpolation:jar:1.11:compile +[INFO] | \- org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile +[INFO] | \- classworlds:classworlds:jar:1.1-alpha-2:compile +[INFO] +- org.apache.maven:maven-core:jar:3.8.2:compile +[INFO] | +- org.apache.maven:maven-settings-builder:jar:3.8.2:compile +[INFO] | | \- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.4:compile +[INFO] | +- org.apache.maven:maven-builder-support:jar:3.8.2:compile +[INFO] | +- org.apache.maven:maven-repository-metadata:jar:3.8.2:compile +[INFO] | +- org.apache.maven:maven-model-builder:jar:3.8.2:compile +[INFO] | +- org.apache.maven:maven-resolver-provider:jar:3.8.2:compile +[INFO] | +- org.apache.maven.resolver:maven-resolver-impl:jar:1.6.3:compile +[INFO] | +- org.apache.maven.resolver:maven-resolver-api:jar:1.6.3:compile +[INFO] | +- org.apache.maven.resolver:maven-resolver-spi:jar:1.6.3:compile +[INFO] | +- org.apache.maven.resolver:maven-resolver-util:jar:1.6.3:compile +[INFO] | +- org.apache.maven.shared:maven-shared-utils:jar:3.3.4:compile +[INFO] | | \- commons-io:commons-io:jar:2.6:compile +[INFO] | +- org.eclipse.sisu:org.eclipse.sisu.inject:jar:0.3.4:compile +[INFO] | +- com.google.inject:guice:jar:no_aop:4.2.2:compile +[INFO] | | +- aopalliance:aopalliance:jar:1.0:compile +[INFO] | | \- com.google.guava:guava:jar:25.1-android:compile +[INFO] | | +- com.google.code.findbugs:jsr305:jar:3.0.2:compile +[INFO] | | +- org.checkerframework:checker-compat-qual:jar:2.0.0:compile +[INFO] | | +- com.google.errorprone:error_prone_annotations:jar:2.1.3:compile +[INFO] | | +- com.google.j2objc:j2objc-annotations:jar:1.1:compile +[INFO] | | \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.14:compile +[INFO] | +- javax.inject:javax.inject:jar:1:compile +[INFO] | +- org.codehaus.plexus:plexus-component-annotations:jar:2.1.0:compile +[INFO] | \- org.apache.commons:commons-lang3:jar:3.12.0:compile +[INFO] +- org.apache.maven.plugin-tools:maven-plugin-annotations:jar:3.6.1:provided +[INFO] +- org.codehaus.plexus:plexus-utils:jar:3.3.0:compile +[INFO] +- com.google.javascript:closure-compiler:jar:v20210601:compile +[INFO] +- junit:junit:jar:4.13.2:test +[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test +[INFO] +- org.easymock:easymock:jar:4.3:test +[INFO] | \- org.objenesis:objenesis:jar:3.2:test +[INFO] \- com.github.jknack:handlebars:jar:tests:4.3.0-SNAPSHOT:test +[INFO] +[INFO] ----------< com.github.jknack:handlebars-maven-plugin-tests >----------- +[INFO] Building Handlebars.js maven plugin tests 4.3.0-SNAPSHOT [11/11] +[INFO] --------------------------------[ war ]--------------------------------- +[INFO] +[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ handlebars-maven-plugin-tests --- +[INFO] com.github.jknack:handlebars-maven-plugin-tests:war:4.3.0-SNAPSHOT +[INFO] ------------------------------------------------------------------------ +[INFO] Reactor Summary for Handlebars.java 4.3.0-SNAPSHOT: +[INFO] +[INFO] Handlebars.java .................................... SUCCESS [ 0.516 s] +[INFO] Handlebars ......................................... SUCCESS [ 0.119 s] +[INFO] Handlebars Helpers ................................. SUCCESS [ 0.027 s] +[INFO] Handlebars Spring MVC .............................. SUCCESS [ 0.042 s] +[INFO] A Jackson 2.x helper ............................... SUCCESS [ 0.024 s] +[INFO] A Markdown Helper .................................. SUCCESS [ 0.023 s] +[INFO] Humanize helpers ................................... SUCCESS [ 0.023 s] +[INFO] A standalone Handlebars Server ..................... SUCCESS [ 0.075 s] +[INFO] Handlebars Guava Cache ............................. SUCCESS [ 0.023 s] +[INFO] Handlebars.js maven plugin ......................... SUCCESS [ 0.136 s] +[INFO] Handlebars.js maven plugin tests ................... SUCCESS [ 0.009 s] +[INFO] ------------------------------------------------------------------------ +[INFO] BUILD SUCCESS +[INFO] ------------------------------------------------------------------------ +[INFO] Total time: 1.706 s +[INFO] Finished at: 2021-10-03T20:16:33-03:00 +[INFO] ------------------------------------------------------------------------ diff --git a/pom.xml b/pom.xml index fbd91fea3..75f5bc055 100644 --- a/pom.xml +++ b/pom.xml @@ -74,13 +74,6 @@ 1.8 - - - com.google.guava - guava - 30.0-jre - - org.springframework spring-webmvc From a7adb1030d9dadc653f4ae89c13a28e62f8237b8 Mon Sep 17 00:00:00 2001 From: Adam Gent Date: Mon, 27 Sep 2021 12:19:43 -0400 Subject: [PATCH 038/157] Fix for #667 Illegal Access for JDK 9 or greater --- .github/workflows/build-matrix.yml | 4 +- .../context/MemberValueResolver.java | 27 ++++++++- .../SetAccessibleValueResolverTest.java | 58 +++++++++++++++++++ 3 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 handlebars/src/test/java/com/github/jknack/handlebars/context/SetAccessibleValueResolverTest.java diff --git a/.github/workflows/build-matrix.yml b/.github/workflows/build-matrix.yml index 1f61ab8fc..6fbe383c1 100644 --- a/.github/workflows/build-matrix.yml +++ b/.github/workflows/build-matrix.yml @@ -22,12 +22,12 @@ jobs: with: java-version: ${{ matrix.java_version }} - name: Install - run: mvn clean install -DskipTests + run: mvn clean install -DskipTests --batch-mode --no-transfer-progress env: BUILD_PORT: 0 BUILD_SECURE_PORT: 0 - name: Build - run: mvn clean package + run: mvn clean package --batch-mode --no-transfer-progress env: BUILD_PORT: 0 BUILD_SECURE_PORT: 0 diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/context/MemberValueResolver.java b/handlebars/src/main/java/com/github/jknack/handlebars/context/MemberValueResolver.java index 3278a691d..1ec5c2dd0 100644 --- a/handlebars/src/main/java/com/github/jknack/handlebars/context/MemberValueResolver.java +++ b/handlebars/src/main/java/com/github/jknack/handlebars/context/MemberValueResolver.java @@ -78,7 +78,7 @@ private Map cache(final Class clazz) { Set members = members(clazz); for (M m : members) { // Mark as accessible. - if (m instanceof AccessibleObject) { + if (isUseSetAccessible(m) && m instanceof AccessibleObject) { ((AccessibleObject) m).setAccessible(true); } mcache.put(memberName(m), m); @@ -88,6 +88,31 @@ private Map cache(final Class clazz) { return mcache; } + /** + * Determines whether or not to call + * {@link AccessibleObject#setAccessible(boolean)} on members before they are + * cached. + * + * Calling setAccessible on JDK 9 or later on private or protected declaring + * classes in modules will result in errors so the default implementation checks + * to see if the declared class cannonical name starts with "java." or "sun." to + * prevent most of these errors. + * + * Modular applications should create their own resolvers and override this + * method to prevent encapsulation violation errors. + * + * @param member Not null. + * @return true will cause setAccessible(true) to be called. + */ + protected boolean isUseSetAccessible(final M member) { + Class dc = member.getDeclaringClass(); + String dn = dc == null ? null : dc.getCanonicalName(); + if (dn != null && (dn.startsWith("java.") || dn.startsWith("sun."))) { + return false; + } + return true; + } + /** * Invoke the member in the given context. * diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/context/SetAccessibleValueResolverTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/context/SetAccessibleValueResolverTest.java new file mode 100644 index 000000000..37f0c636f --- /dev/null +++ b/handlebars/src/test/java/com/github/jknack/handlebars/context/SetAccessibleValueResolverTest.java @@ -0,0 +1,58 @@ +package com.github.jknack.handlebars.context; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; + +import java.lang.reflect.Method; +import java.util.Collections; + +import org.junit.Test; + +public class SetAccessibleValueResolverTest { + + /* + * The following tests require JDK 9 or greater. + * To keep the tests from failing we use junit assume. + */ + + @Test + public void testSetAccessibleOnJDK9OrGreater() throws Exception { + assumeTrue(getJavaVersion() >= 9); + MethodValueResolver mv = new MethodValueResolver() { + + @Override + protected boolean isUseSetAccessible(Method m) { + return true; + } + }; + try { + mv.resolve(Collections.emptyMap(), "doesNotMatter"); + fail("Expect InaccessibleObjectException"); + } catch (/* InaccessibleObjectException */ Exception e) { + } + + mv = new MethodValueResolver(); + mv.resolve(Collections.emptyMap(), "doesNotMatter"); + Object result = mv.resolve(Collections.emptyMap(), "isEmpty"); + assertEquals(Boolean.TRUE, result); + } + + static int getJavaVersion() { + String version = System.getProperty("java.version"); + if (version.startsWith("1.")) { + version = version.substring(2, 3); + } else { + int dot = version.indexOf("."); + if (dot != -1) { + version = version.substring(0, dot); + } + } + try { + return Integer.parseInt(version); + } catch (NumberFormatException e) { + return 8; + } + } + +} From 0b6015a3f580747ad29b4e671a1a5a58530a883a Mon Sep 17 00:00:00 2001 From: Edgar Espina Date: Sun, 3 Oct 2021 20:31:19 -0300 Subject: [PATCH 039/157] README.md: Fix some links --- README.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c72106e7b..6bfae7180 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,4 @@ [![Become a Patreon](https://img.shields.io/badge/patreon-donate-orange.svg)](https://patreon.com/edgarespina) -[![Build Status](https://travis-ci.org/jknack/handlebars.java.svg?branch=master)](https://travis-ci.org/jknack/handlebars.java) -[![coveralls.io](https://img.shields.io/coveralls/jknack/handlebars.java.svg)](https://coveralls.io/r/jknack/handlebars.java?branch=master) -[![codecov](https://codecov.io/gh/jknack/handlebars.java/branch/master/graph/badge.svg)](https://codecov.io/gh/jknack/handlebars.java) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.jknack/handlebars/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.jknack/handlebars) [![javadoc](https://javadoc.io/badge/com.github.jknack/handlebars.svg)](https://javadoc.io/doc/com.github.jknack/handlebars) @@ -22,16 +19,16 @@ Output: Hello Handlebars.java! ``` -Handlebars.java is a Java port of [handlebars](http://handlebarsjs.com/). +Handlebars.java is a Java port of [handlebars](https://handlebarsjs.com/). Handlebars provides the power necessary to let you build semantic templates effectively with no frustration. -[Mustache](http://mustache.github.io/mustache.5.html) templates are compatible with Handlebars, so you can take a [Mustache](http://mustache.github.com) template, import it into Handlebars, and start taking advantage of the extra Handlebars features. +[Mustache](https://mustache.github.io/mustache.5.html) templates are compatible with Handlebars, so you can take a [Mustache](https://mustache.github.io) template, import it into Handlebars, and start taking advantage of the extra Handlebars features. # Getting Started - In general, the syntax of **Handlebars** templates is a superset of [Mustache](http://mustache.github.com) templates. For basic syntax, check out the [Mustache manpage](http://mustache.github.com). + In general, the syntax of **Handlebars** templates is a superset of [Mustache](https://mustache.github.io) templates. For basic syntax, check out the [Mustache manpage](https://mustache.github.io). - The [Handlebars.java blog](http://jknack.github.io/handlebars.java) is a good place for getting started too. Javadoc is available at [javadoc.io](https://javadoc.io/doc/com.github.jknack/handlebars). + The [Handlebars.java blog](https://jknack.github.io/handlebars.java) is a good place for getting started too. Javadoc is available at [javadoc.io](https://javadoc.io/doc/com.github.jknack/handlebars). ## Maven #### Stable version: [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.jknack/handlebars/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.jknack/handlebars) From d83e0bc51f0cfd004073dcbc2782b2428fb0c475 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 3 Oct 2021 23:23:58 +0000 Subject: [PATCH 040/157] Bump maven-plugin-api from 3.6.3 to 3.8.3 Bumps [maven-plugin-api](https://github.com/apache/maven) from 3.6.3 to 3.8.3. - [Release notes](https://github.com/apache/maven/releases) - [Commits](https://github.com/apache/maven/compare/maven-3.6.3...maven-3.8.3) --- updated-dependencies: - dependency-name: org.apache.maven:maven-plugin-api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- handlebars-maven-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml index 5c0b28c44..3405848c4 100644 --- a/handlebars-maven-plugin/pom.xml +++ b/handlebars-maven-plugin/pom.xml @@ -38,7 +38,7 @@ org.apache.maven maven-plugin-api - 3.6.3 + 3.8.3 From 22c028d73fa81bb8f632ea62d075a69328d9f4e6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Sep 2021 09:32:22 +0000 Subject: [PATCH 041/157] Bump logback-classic from 1.2.3 to 1.2.6 Bumps logback-classic from 1.2.3 to 1.2.6. --- updated-dependencies: - dependency-name: ch.qos.logback:logback-classic dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 75f5bc055..40494f4f4 100644 --- a/pom.xml +++ b/pom.xml @@ -133,7 +133,7 @@ ch.qos.logback logback-classic - 1.2.3 + 1.2.6 test From 7861a390550bdfac9d1bdebe46005cb7f4f8b994 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Sep 2021 09:32:21 +0000 Subject: [PATCH 042/157] Bump plexus-utils from 3.3.0 to 3.4.1 Bumps [plexus-utils](https://github.com/codehaus-plexus/plexus-utils) from 3.3.0 to 3.4.1. - [Release notes](https://github.com/codehaus-plexus/plexus-utils/releases) - [Commits](https://github.com/codehaus-plexus/plexus-utils/compare/plexus-utils-3.3.0...plexus-utils-3.4.1) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-utils dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- handlebars-maven-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml index 3405848c4..c99c22c16 100644 --- a/handlebars-maven-plugin/pom.xml +++ b/handlebars-maven-plugin/pom.xml @@ -63,7 +63,7 @@ org.codehaus.plexus plexus-utils - 3.3.0 + 3.4.1 From 865f2d7f3c91a76a41cf855e7fac1e8a112c3056 Mon Sep 17 00:00:00 2001 From: bithazard Date: Sun, 22 Aug 2021 16:53:48 +0200 Subject: [PATCH 043/157] Added dependency for the Nashorn JS engine which was removed in Java 15 --- handlebars/pom.xml | 7 +++++++ .../main/java/com/github/jknack/handlebars/Handlebars.java | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/handlebars/pom.xml b/handlebars/pom.xml index b3e29a49d..45f963c73 100644 --- a/handlebars/pom.xml +++ b/handlebars/pom.xml @@ -173,6 +173,13 @@ true + + + org.openjdk.nashorn + nashorn-core + 15.3 + + org.slf4j diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java b/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java index aea841d99..222875017 100644 --- a/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java +++ b/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java @@ -1474,7 +1474,7 @@ private ScriptEngine engine() { synchronized (this) { if (this.engine == null) { - this.engine = new ScriptEngineManager(null).getEngineByName("nashorn"); + this.engine = new ScriptEngineManager().getEngineByName("nashorn"); Throwing.run(() -> engine.eval(Files.read(this.handlebarsJsFile, charset))); } From 0021d5f60556d6833f9dda8d58aa6a08422fe08d Mon Sep 17 00:00:00 2001 From: bithazard Date: Sun, 22 Aug 2021 17:00:01 +0200 Subject: [PATCH 044/157] Java 11 upgrade: Merge MemberValueResolver --- .../handlebars/internal/BaseTemplate.java | 22 ++-- .../handlebars/CollectionsLengthTest.java | 2 +- .../TypeSafeTemplateDefaultMethodTest.java | 2 +- .../test/java/mustache/specs/SpecRunner.java | 116 ++---------------- 4 files changed, 21 insertions(+), 121 deletions(-) diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/internal/BaseTemplate.java b/handlebars/src/main/java/com/github/jknack/handlebars/internal/BaseTemplate.java index 0a57af768..aa97f6837 100644 --- a/handlebars/src/main/java/com/github/jknack/handlebars/internal/BaseTemplate.java +++ b/handlebars/src/main/java/com/github/jknack/handlebars/internal/BaseTemplate.java @@ -25,7 +25,7 @@ import java.io.IOException; import java.io.Writer; import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; +import java.lang.invoke.MethodType; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -263,19 +263,13 @@ private boolean isDefault(final Method method) { } private Object invokeDefaultMethod(final Method method, final Class lookupClass, - final Object proxy, final Object... args) - throws Throwable { - // Jumping through these hoops is needed because calling unreflectSpecial requires that - // the lookup instance have private access to the special caller. None of the static - // factory methods for Lookup will give us an instance with the access modes we need, - // so we work around it by calling the private constructor via reflection. - Constructor constructor = MethodHandles.Lookup.class - .getDeclaredConstructor(Class.class, int.class); - constructor.setAccessible(true); - return constructor.newInstance(lookupClass, -1 /* trusted */) - .unreflectSpecial(method, lookupClass) - .bindTo(proxy) - .invokeWithArguments(args); + final Object proxy, final Object... args) throws Throwable { + MethodType methodType = MethodType.methodType(method.getReturnType(), + method.getParameterTypes()); + return MethodHandles.lookup() + .findSpecial(lookupClass, method.getName(), methodType, lookupClass) + .bindTo(proxy) + .invokeWithArguments(args); } @Override diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/CollectionsLengthTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/CollectionsLengthTest.java index d4b4b1659..f700390f1 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/CollectionsLengthTest.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/CollectionsLengthTest.java @@ -8,7 +8,7 @@ public class CollectionsLengthTest extends AbstractTest { - static class SizeAndLength { + public static class SizeAndLength { int size; int length; diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/TypeSafeTemplateDefaultMethodTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/TypeSafeTemplateDefaultMethodTest.java index 3c86fc001..7b9e3145e 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/TypeSafeTemplateDefaultMethodTest.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/TypeSafeTemplateDefaultMethodTest.java @@ -19,7 +19,7 @@ public String getName() { } } - interface UserTemplate extends TypeSafeTemplate { + public interface UserTemplate extends TypeSafeTemplate { default String renderUpperCase(User user) throws IOException { return apply(user).toUpperCase(); } diff --git a/handlebars/src/test/java/mustache/specs/SpecRunner.java b/handlebars/src/test/java/mustache/specs/SpecRunner.java index 208d6100e..ccfa0b6e9 100644 --- a/handlebars/src/test/java/mustache/specs/SpecRunner.java +++ b/handlebars/src/test/java/mustache/specs/SpecRunner.java @@ -17,18 +17,17 @@ */ package mustache.specs; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.junit.runner.Description; import org.junit.runners.Parameterized; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.TestClass; public class SpecRunner extends Parameterized { - private List labels; - private Description labelledDescription; public SpecRunner(final Class cl) throws Throwable { @@ -37,120 +36,28 @@ public SpecRunner(final Class cl) throws Throwable { generateLabelledDescription(); } - private void initialiseLabels() throws Exception { - Collection parameterArrays = getParameterArrays(); + private void initialiseLabels() throws Throwable { + Collection parameterArrays = getParameterArrays4_4(); labels = new ArrayList(); for (Object[] parameterArray : parameterArrays) { Spec spec = (Spec) parameterArray[0]; labels.add(spec.name()); } - - } - - private Collection getParameterArrays() throws Exception { - Method testClassMethod = getDeclaredMethod(this.getClass(), - "getTestClass"); - Class returnType = testClassMethod.getReturnType(); - if (returnType == Class.class) { - return getParameterArrays4_3(); - } else { - return getParameterArrays4_4(); - } - } - - private Collection getParameterArrays4_3() throws Exception { - Object[][] methodCalls = new Object[][] {new Object[] {"getTestClass" } }; - Class cl = invokeMethodChain(this, methodCalls); - Method[] methods = cl.getMethods(); - - Method parametersMethod = null; - for (Method method : methods) { - boolean providesParameters = method - .isAnnotationPresent(Parameters.class); - if (!providesParameters) { - continue; - } - - if (parametersMethod != null) { - throw new Exception( - "Only one method should be annotated with @Labels"); - } - - parametersMethod = method; - } - - if (parametersMethod == null) { - throw new Exception("No @Parameters method found"); - } - - @SuppressWarnings("unchecked") - Collection parameterArrays = - (Collection) parametersMethod - .invoke(null); - return parameterArrays; - - } - - private Collection getParameterArrays4_4() throws Exception { - Object[][] methodCalls = new Object[][] { - new Object[] {"getTestClass" }, - new Object[] {"getAnnotatedMethods", Class.class, - Parameters.class }, - new Object[] {"get", int.class, 0 }, - // use array type for varargs (equivalent (almost)) - new Object[] {"invokeExplosively", Object.class, null, - Object[].class, new Object[] {} } }; - Collection parameterArrays = invokeMethodChain(this, - methodCalls); - return parameterArrays; } @SuppressWarnings("unchecked") - private T invokeMethodChain(Object object, final Object[][] methodCalls) - throws Exception { - for (Object[] methodCall : methodCalls) { - String methodName = (String) methodCall[0]; - int parameterCount = (methodCall.length - 1) / 2; - Class[] classes = new Class[parameterCount]; - Object[] arguments = new Object[parameterCount]; - for (int i = 1; i < methodCall.length; i += 2) { - Class cl = (Class) methodCall[i]; - Object argument = methodCall[i + 1]; - int index = (i - 1) / 2; // messy! - classes[index] = cl; - arguments[index] = argument; - } - Method method = getDeclaredMethod(object.getClass(), methodName, - classes); - method.setAccessible(true); - object = method.invoke(object, arguments); - } - return (T) object; - } - - // iterates through super-classes until found. Throws NoSuchMethodException - // if not - private Method getDeclaredMethod(Class cl, final String methodName, - final Class... parameterTypes) throws NoSuchMethodException { - do { - try { - Method method = cl - .getDeclaredMethod(methodName, parameterTypes); - return method; - } catch (NoSuchMethodException e) { - // do nothing - just fall through to the below - } - cl = cl.getSuperclass(); - } while (cl != null); - throw new NoSuchMethodException("Method " + methodName - + "() not found in hierarchy"); + private Collection getParameterArrays4_4() throws Throwable { + TestClass testClass = this.getTestClass(); + List annotatedMethods = testClass.getAnnotatedMethods(Parameters.class); + FrameworkMethod frameworkMethod = annotatedMethods.get(0); + return (Collection)frameworkMethod.invokeExplosively(testClass); } private void generateLabelledDescription() throws Exception { Description originalDescription = super.getDescription(); labelledDescription = Description .createSuiteDescription(originalDescription.getDisplayName()); - ArrayList childDescriptions = originalDescription + List childDescriptions = originalDescription .getChildren(); int childCount = childDescriptions.size(); if (childCount != labels.size()) { @@ -163,7 +70,7 @@ private void generateLabelledDescription() throws Exception { String label = labels.get(i); Description newDescription = Description .createSuiteDescription(label); - ArrayList grandChildren = childDescription + List grandChildren = childDescription .getChildren(); for (Description grandChild : grandChildren) { newDescription.addChild(grandChild); @@ -176,5 +83,4 @@ private void generateLabelledDescription() throws Exception { public Description getDescription() { return labelledDescription; } - } From 73e9f117adaf21c262c934a47cfcd3bece8915ed Mon Sep 17 00:00:00 2001 From: bithazard Date: Sun, 22 Aug 2021 17:12:41 +0200 Subject: [PATCH 045/157] WIP: upgrade Java 11 or higher - Fix some locale specific issues on modern JVM - Add nashorn dependency - Replaced the mocking frameworks (easymock/powermock) with mockito which seems to have no problems with the Java 9 module system --- .github/workflows/build-matrix.yml | 4 +- .gitignore | 4 +- handlebars-guava-cache/pom.xml | 5 +- .../cache/GuavaTemplateCacheTest.java | 87 ++--- handlebars-helpers/pom.xml | 8 +- .../handlebars/helper/JodaHelperTest.java | 11 +- handlebars-humanize/pom.xml | 33 ++ .../jknack/handlebars/HumanizeHelperTest.java | 25 +- handlebars-jackson2/pom.xml | 4 +- .../handlebars/JsonNodeValueResolverTest.java | 67 ++-- handlebars-maven-plugin/pom.xml | 4 +- .../handlebars/maven/I18nJsPluginTest.java | 10 +- .../jknack/handlebars/maven/Issue230.java | 10 +- .../jknack/handlebars/maven/Issue234.java | 10 +- .../maven/PrecompilePluginTest.java | 18 +- handlebars-springmvc/pom.xml | 17 +- .../springmvc/HandlebarsViewTest.java | 36 +- .../springmvc/MessageSourceHelperTest.java | 83 ++--- handlebars/pom.xml | 17 +- .../jknack/handlebars/AbstractTest.java | 28 ++ .../github/jknack/handlebars/EachKeyTest.java | 5 +- .../handlebars/HandlebarsExceptionTest.java | 6 +- .../github/jknack/handlebars/Issue266.java | 28 +- .../cache/ConcurrentMapTemplateCacheTest.java | 49 ++- .../HighConcurrencyTemplateCacheTest.java | 246 ++++++------- .../cache/NullTemplateCacheTest.java | 25 +- .../SetAccessibleValueResolverTest.java | 3 +- .../handlebars/helper/StringHelpersTest.java | 312 ++++++++-------- .../io/ForwardingTemplateSourceTest.java | 31 +- .../io/ServletContextTemplateLoaderTest.java | 75 ++-- .../handlebars/io/URLTemplateSourceTest.java | 75 ++-- out | 334 ------------------ pom.xml | 28 +- 33 files changed, 601 insertions(+), 1097 deletions(-) delete mode 100644 out diff --git a/.github/workflows/build-matrix.yml b/.github/workflows/build-matrix.yml index 6fbe383c1..13e709886 100644 --- a/.github/workflows/build-matrix.yml +++ b/.github/workflows/build-matrix.yml @@ -1,4 +1,4 @@ -name: Build Matrix +name: Build on: [push] @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: false matrix: - java_version: [1.8] + java_version: [1.8, 11] os: [ubuntu-latest, windows-latest, macOS-latest] steps: diff --git a/.gitignore b/.gitignore index b82627118..2970e1308 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,6 @@ dependency-reduced-pom.xml *.versionsBackup pom.xml.versionsBackup -jacoco.exec \ No newline at end of file +jacoco.exec + +out diff --git a/handlebars-guava-cache/pom.xml b/handlebars-guava-cache/pom.xml index aa3c4d42b..688271702 100644 --- a/handlebars-guava-cache/pom.xml +++ b/handlebars-guava-cache/pom.xml @@ -57,11 +57,10 @@ - org.easymock - easymock + org.mockito + mockito-core test -
    diff --git a/handlebars-guava-cache/src/test/java/com/github/jknack/handlebars/cache/GuavaTemplateCacheTest.java b/handlebars-guava-cache/src/test/java/com/github/jknack/handlebars/cache/GuavaTemplateCacheTest.java index 2181421eb..fb2c2bfc7 100644 --- a/handlebars-guava-cache/src/test/java/com/github/jknack/handlebars/cache/GuavaTemplateCacheTest.java +++ b/handlebars-guava-cache/src/test/java/com/github/jknack/handlebars/cache/GuavaTemplateCacheTest.java @@ -1,12 +1,12 @@ package com.github.jknack.handlebars.cache; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.isA; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.io.IOException; import java.util.concurrent.Callable; @@ -33,12 +33,10 @@ public void get() throws IOException { TemplateSource source = new URLTemplateSource("/template.hbs", getClass().getResource( "/template.hbs")); - Template template = createMock(Template.class); + Template template = mock(Template.class); - Parser parser = createMock(Parser.class); - expect(parser.parse(source)).andReturn(template); - - replay(parser, template); + Parser parser = mock(Parser.class); + when(parser.parse(source)).thenReturn(template); // 1st call, parse must be call it assertEquals(template, new GuavaTemplateCache(cache).get(source, parser)); @@ -46,7 +44,7 @@ public void get() throws IOException { // 2nd call, should return from cache assertEquals(template, new GuavaTemplateCache(cache).get(source, parser)); - verify(parser, template); + verify(parser).parse(source); } @Test @@ -56,12 +54,12 @@ public void getAndReload() throws IOException, InterruptedException { TemplateSource source = source("/template.hbs"); - Template template = createMock(Template.class); + Template template = mock(Template.class); - Template reloadTemplate = createMock(Template.class); + Template reloadTemplate = mock(Template.class); - Parser parser = createMock(Parser.class); - expect(parser.parse(source)).andReturn(template); + Parser parser = mock(Parser.class); + when(parser.parse(same(source))).thenReturn(template); TemplateSource reloadSource = new ForwardingTemplateSource(source) { @Override @@ -69,9 +67,7 @@ public long lastModified() { return System.currentTimeMillis() * 7; } }; - expect(parser.parse(reloadSource)).andReturn(reloadTemplate); - - replay(parser, template, reloadTemplate); + when(parser.parse(same(reloadSource))).thenReturn(reloadTemplate); // 1st call, parse must be call it assertEquals(template, new GuavaTemplateCache(cache).setReload(true).get(source, parser)); @@ -83,89 +79,76 @@ public long lastModified() { assertEquals(reloadTemplate, new GuavaTemplateCache(cache).setReload(true).get(reloadSource, parser)); - verify(parser, template, reloadTemplate); + verify(parser).parse(same(source)); + verify(parser).parse(same(reloadSource)); } @Test public void evict() throws IOException { - TemplateSource source = createMock(TemplateSource.class); + TemplateSource source = mock(TemplateSource.class); @SuppressWarnings("unchecked") - Cache cache = createMock(Cache.class); + Cache cache = mock(Cache.class); cache.invalidate(source); - replay(cache, source); - new GuavaTemplateCache(cache).evict(source); - - verify(cache, source); } @Test public void clear() throws IOException { @SuppressWarnings("unchecked") - Cache cache = createMock(Cache.class); + Cache cache = mock(Cache.class); cache.invalidateAll(); - replay(cache); - new GuavaTemplateCache(cache).clear(); - - verify(cache); } @SuppressWarnings("unchecked") @Test(expected = IllegalStateException.class) public void executionExceptionWithRuntimeException() throws IOException, ExecutionException { - TemplateSource source = createMock(TemplateSource.class); + TemplateSource source = mock(TemplateSource.class); - Parser parser = createMock(Parser.class); + Parser parser = mock(Parser.class); - Cache cache = createMock(Cache.class); - expect(cache.get(eq(source), isA(Callable.class))).andThrow( + Cache cache = mock(Cache.class); + when(cache.get(eq(source), any(Callable.class))).thenThrow( new ExecutionException(new IllegalStateException())); - replay(cache, source, parser); - new GuavaTemplateCache(cache).get(source, parser); - verify(cache, source, parser); + verify(cache).get(eq(source), any(Callable.class)); } @SuppressWarnings("unchecked") @Test(expected = Error.class) public void executionExceptionWithError() throws IOException, ExecutionException { - TemplateSource source = createMock(TemplateSource.class); + TemplateSource source = mock(TemplateSource.class); - Parser parser = createMock(Parser.class); + Parser parser = mock(Parser.class); - Cache cache = createMock(Cache.class); - expect(cache.get(eq(source), isA(Callable.class))).andThrow( + Cache cache = mock(Cache.class); + when(cache.get(eq(source), any(Callable.class))).thenThrow( new ExecutionException(new Error())); - replay(cache, source, parser); - new GuavaTemplateCache(cache).get(source, parser); - verify(cache, source, parser); + verify(cache).get(eq(source), any(Callable.class)); } @SuppressWarnings("unchecked") @Test(expected = HandlebarsException.class) public void executionExceptionWithCheckedException() throws IOException, ExecutionException { - TemplateSource source = createMock(TemplateSource.class); + TemplateSource source = mock(TemplateSource.class); - Parser parser = createMock(Parser.class); + Parser parser = mock(Parser.class); - Cache cache = createMock(Cache.class); - expect(cache.get(eq(source), isA(Callable.class))).andThrow( + Cache cache = mock(Cache.class); + when(cache.get(eq(source), any(Callable.class))).thenThrow( new ExecutionException(new IOException())); - replay(cache, source, parser); - new GuavaTemplateCache(cache).get(source, parser); - verify(cache, source, parser); + verify(cache).get(eq(source), any(Callable.class)); } private TemplateSource source(final String filename) throws IOException { diff --git a/handlebars-helpers/pom.xml b/handlebars-helpers/pom.xml index 2aa26507b..8e5a80ee6 100644 --- a/handlebars-helpers/pom.xml +++ b/handlebars-helpers/pom.xml @@ -26,7 +26,7 @@ org.apache.commons commons-lang3
    - + joda-time joda-time @@ -62,12 +62,6 @@ test - - org.easymock - easymock - test - - org.yaml snakeyaml diff --git a/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/JodaHelperTest.java b/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/JodaHelperTest.java index 12393bcc6..73fcfbb54 100644 --- a/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/JodaHelperTest.java +++ b/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/JodaHelperTest.java @@ -48,7 +48,8 @@ protected Handlebars newHandlebars() { @Test public void testPattern() throws IOException { DateTime dateTime = new DateTime().withDate(1995, 7, 4).withTime(14, 32, 12, 0); - shouldCompileTo("{{jodaPatternHelper this \"y-MMM-d H:m:s\"}}", dateTime, "1995-Jul-4 14:32:12"); + shouldCompileTo("{{jodaPatternHelper this \"y-MMM-d H:m:s\"}}", dateTime, + "1995-Jul-4 14:32:12"); } @Test @@ -66,7 +67,10 @@ public void testBadPattern() throws IOException { @Test public void testStyle() throws IOException { DateTime dateTime = new DateTime().withDate(1995, 7, 4).withTime(14, 32, 12, 0); - shouldCompileTo("{{jodaStyleHelper this \"SS\"}}", dateTime, "7/4/95 2:32 PM"); + withJava(version -> version <= 8, + () -> shouldCompileTo("{{jodaStyleHelper this \"SS\"}}", dateTime, "7/4/95 2:32 PM")); + withJava(version -> version >= 9, + () -> shouldCompileTo("{{jodaStyleHelper this \"SS\"}}", dateTime, "7/4/95, 2:32 PM")); } @Test @@ -82,7 +86,8 @@ public void testBadStyle() throws IOException { @Test public void testISO() throws IOException { - DateTime dateTime = new DateTime().withDate(1995, 7, 4).withTime(14, 32, 12, 0).withZoneRetainFields(DateTimeZone.UTC); + DateTime dateTime = new DateTime().withDate(1995, 7, 4).withTime(14, 32, 12, 0) + .withZoneRetainFields(DateTimeZone.UTC); shouldCompileTo("{{jodaISOHelper this}}", dateTime, "1995-07-04T14:32:12Z"); } } diff --git a/handlebars-humanize/pom.xml b/handlebars-humanize/pom.xml index e1f14a035..2c67802ff 100644 --- a/handlebars-humanize/pom.xml +++ b/handlebars-humanize/pom.xml @@ -45,6 +45,39 @@ test + + org.apache.commons + commons-lang3 + test + + + + org.antlr + antlr4-runtime + 4.9.2 + + + org.abego.treelayout + org.abego.treelayout.core + + + test + + + + org.apache.commons + commons-text + test + + + + com.github.jknack + handlebars + ${project.version} + test + tests + + diff --git a/handlebars-humanize/src/test/java/com/github/jknack/handlebars/HumanizeHelperTest.java b/handlebars-humanize/src/test/java/com/github/jknack/handlebars/HumanizeHelperTest.java index 06b44a5b7..351d4a410 100644 --- a/handlebars-humanize/src/test/java/com/github/jknack/handlebars/HumanizeHelperTest.java +++ b/handlebars-humanize/src/test/java/com/github/jknack/handlebars/HumanizeHelperTest.java @@ -8,7 +8,7 @@ import org.junit.Test; -public class HumanizeHelperTest { +public class HumanizeHelperTest extends AbstractTest { private static final Handlebars handlebars = new Handlebars(); static { @@ -59,17 +59,28 @@ public void decamelize() throws IOException { */ @Test public void formatCurrency_es_AR() throws IOException { - assertEquals("$34", + withJava(v -> v <= 8, () -> assertEquals("$34", handlebars.compileInline("{{formatCurrency this locale=\"es_AR\"}}") - .apply(34)); + .apply(34))); + withJava(v -> v >= 9, () -> assertEquals("$\u00A034", + handlebars.compileInline("{{formatCurrency this locale=\"es_AR\"}}") + .apply(34))); - assertEquals("$1.000", + withJava(v -> v == 8, () -> assertEquals("$1.000", handlebars.compileInline("{{formatCurrency this locale=\"es_AR\"}}") - .apply(1000)); + .apply(1000))); - assertEquals("$12,50", + withJava(v -> v >= 9, () -> assertEquals("$\u00A01.000", handlebars.compileInline("{{formatCurrency this locale=\"es_AR\"}}") - .apply(12.5)); + .apply(1000))); + + withJava(v -> v == 8, () -> assertEquals("$12,50", + handlebars.compileInline("{{formatCurrency this locale=\"es_AR\"}}") + .apply(12.5))); + + withJava(v -> v >= 9, () -> assertEquals("$\u00A012,50", + handlebars.compileInline("{{formatCurrency this locale=\"es_AR\"}}") + .apply(12.5))); } /** diff --git a/handlebars-jackson2/pom.xml b/handlebars-jackson2/pom.xml index 603d816c6..4d3e7d93b 100644 --- a/handlebars-jackson2/pom.xml +++ b/handlebars-jackson2/pom.xml @@ -55,8 +55,8 @@
    - org.easymock - easymock + org.mockito + mockito-core test diff --git a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/JsonNodeValueResolverTest.java b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/JsonNodeValueResolverTest.java index da27637e9..f7f561ff9 100644 --- a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/JsonNodeValueResolverTest.java +++ b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/JsonNodeValueResolverTest.java @@ -1,11 +1,10 @@ package com.github.jknack.handlebars; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.io.IOException; import java.math.BigDecimal; @@ -57,17 +56,13 @@ public void resolveBinaryNode() { String name = "binary"; byte[] result = new byte[]{1 }; - JsonNode node = createMock(JsonNode.class); + JsonNode node = mock(JsonNode.class); BinaryNode value = BinaryNode.valueOf(result); - expect(node.get(name)).andReturn(value); - - Object[] mocks = {node }; - - replay(mocks); + when(node.get(name)).thenReturn(value); assertEquals(result, JsonNodeValueResolver.INSTANCE.resolve(node, name)); - verify(mocks); + verify(node).get(name); } @Test @@ -75,17 +70,13 @@ public void resolveNullNode() { String name = "null"; Object result = ValueResolver.UNRESOLVED; - JsonNode node = createMock(JsonNode.class); + JsonNode node = mock(JsonNode.class); NullNode value = NullNode.instance; - expect(node.get(name)).andReturn(value); - - Object[] mocks = {node }; - - replay(mocks); + when(node.get(name)).thenReturn(value); assertEquals(result, JsonNodeValueResolver.INSTANCE.resolve(node, name)); - verify(mocks); + verify(node).get(name); } @Test @@ -93,17 +84,13 @@ public void resolveBigIntegerNode() { String name = "bigInt"; BigInteger result = BigInteger.ONE; - JsonNode node = createMock(JsonNode.class); + JsonNode node = mock(JsonNode.class); JsonNode value = BigIntegerNode.valueOf(result); - expect(node.get(name)).andReturn(value); - - Object[] mocks = {node }; - - replay(mocks); + when(node.get(name)).thenReturn(value); assertEquals(result, JsonNodeValueResolver.INSTANCE.resolve(node, name)); - verify(mocks); + verify(node).get(name); } @Test @@ -111,17 +98,13 @@ public void resolveDecimalNode() { String name = "decimal"; BigDecimal result = BigDecimal.TEN; - JsonNode node = createMock(JsonNode.class); + JsonNode node = mock(JsonNode.class); JsonNode value = DecimalNode.valueOf(result); - expect(node.get(name)).andReturn(value); - - Object[] mocks = {node }; - - replay(mocks); + when(node.get(name)).thenReturn(value); assertEquals(result, JsonNodeValueResolver.INSTANCE.resolve(node, name)); - verify(mocks); + verify(node).get(name); } @Test @@ -129,17 +112,13 @@ public void resolveLongNode() { String name = "long"; Long result = 678L; - JsonNode node = createMock(JsonNode.class); + JsonNode node = mock(JsonNode.class); JsonNode value = LongNode.valueOf(result); - expect(node.get(name)).andReturn(value); - - Object[] mocks = {node }; - - replay(mocks); + when(node.get(name)).thenReturn(value); assertEquals(result, JsonNodeValueResolver.INSTANCE.resolve(node, name)); - verify(mocks); + verify(node).get(name); } @Test @@ -147,17 +126,13 @@ public void resolvePojoNode() { String name = "pojo"; Object result = new Object(); - JsonNode node = createMock(JsonNode.class); + JsonNode node = mock(JsonNode.class); JsonNode value = new POJONode(result); - expect(node.get(name)).andReturn(value); - - Object[] mocks = {node }; - - replay(mocks); + when(node.get(name)).thenReturn(value); assertEquals(result, JsonNodeValueResolver.INSTANCE.resolve(node, name)); - verify(mocks); + verify(node).get(name); } @Test diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml index c99c22c16..29e39bea2 100644 --- a/handlebars-maven-plugin/pom.xml +++ b/handlebars-maven-plugin/pom.xml @@ -80,8 +80,8 @@
    - org.easymock - easymock + org.mockito + mockito-core test diff --git a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/I18nJsPluginTest.java b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/I18nJsPluginTest.java index 31338c8a4..2aafbea4d 100644 --- a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/I18nJsPluginTest.java +++ b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/I18nJsPluginTest.java @@ -1,9 +1,8 @@ package com.github.jknack.handlebars.maven; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.io.File; import java.io.IOException; @@ -95,9 +94,8 @@ public void i18nJsWithMergeAmd() throws Exception { private MavenProject newProject(final String... classpath) throws DependencyResolutionRequiredException { - MavenProject project = createMock(MavenProject.class); - expect(project.getRuntimeClasspathElements()).andReturn(Lists.newArrayList(classpath)); - replay(project); + MavenProject project = mock(MavenProject.class); + when(project.getRuntimeClasspathElements()).thenReturn(Lists.newArrayList(classpath)); return project; } diff --git a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue230.java b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue230.java index fbf8d4221..59466b859 100644 --- a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue230.java +++ b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue230.java @@ -1,9 +1,8 @@ package com.github.jknack.handlebars.maven; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.io.IOException; @@ -36,9 +35,8 @@ public void issue230() throws Exception { private MavenProject newProject(final String... classpath) throws DependencyResolutionRequiredException { - MavenProject project = createMock(MavenProject.class); - expect(project.getRuntimeClasspathElements()).andReturn(Lists.newArrayList(classpath)); - replay(project); + MavenProject project = mock(MavenProject.class); + when(project.getRuntimeClasspathElements()).thenReturn(Lists.newArrayList(classpath)); return project; } diff --git a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java index fa54cb404..3c3bf5f5b 100644 --- a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java +++ b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java @@ -1,9 +1,8 @@ package com.github.jknack.handlebars.maven; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.io.IOException; @@ -47,9 +46,8 @@ private String replaceWhiteCharsWithSpace(String content) { private MavenProject newProject(final String... classpath) throws DependencyResolutionRequiredException { - MavenProject project = createMock(MavenProject.class); - expect(project.getRuntimeClasspathElements()).andReturn(Lists.newArrayList(classpath)); - replay(project); + MavenProject project = mock(MavenProject.class); + when(project.getRuntimeClasspathElements()).thenReturn(Lists.newArrayList(classpath)); return project; } } diff --git a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java index 88d819c6d..f99091f37 100644 --- a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java +++ b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java @@ -1,10 +1,9 @@ package com.github.jknack.handlebars.maven; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.io.File; import java.io.IOException; @@ -126,11 +125,9 @@ public void mustFailOnMissingFile() throws Exception { @Test(expected = MojoFailureException.class) public void mustFailOnUnExpectedException() throws Exception { - MavenProject project = createMock(MavenProject.class); - Artifact artifact = createMock(Artifact.class); - expect(project.getRuntimeClasspathElements()).andThrow( - new DependencyResolutionRequiredException(artifact)); - replay(project, artifact); + MavenProject project = mock(MavenProject.class); + when(project.getRuntimeClasspathElements()).thenThrow( + new DependencyResolutionRequiredException(null)); PrecompilePlugin plugin = new PrecompilePlugin(); plugin.setPrefix("src/test/resources/no templates"); @@ -209,9 +206,8 @@ public void partials() throws Exception { private MavenProject newProject(final String... classpath) throws DependencyResolutionRequiredException { - MavenProject project = createMock(MavenProject.class); - expect(project.getRuntimeClasspathElements()).andReturn(Lists.newArrayList(classpath)); - replay(project); + MavenProject project = mock(MavenProject.class); + when(project.getRuntimeClasspathElements()).thenReturn(Lists.newArrayList(classpath)); return project; } } diff --git a/handlebars-springmvc/pom.xml b/handlebars-springmvc/pom.xml index c1b9894dd..1e0848b91 100644 --- a/handlebars-springmvc/pom.xml +++ b/handlebars-springmvc/pom.xml @@ -53,23 +53,10 @@
    - org.easymock - easymock + org.mockito + mockito-core test - - - org.powermock - powermock-api-easymock - test - - - - org.powermock - powermock-module-junit4 - test - - diff --git a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/HandlebarsViewTest.java b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/HandlebarsViewTest.java index 16cf9f377..0b2fcd686 100644 --- a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/HandlebarsViewTest.java +++ b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/HandlebarsViewTest.java @@ -17,13 +17,11 @@ */ package com.github.jknack.handlebars.springmvc; -import static org.easymock.EasyMock.capture; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.isA; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.io.PrintWriter; import java.util.Map; @@ -31,13 +29,12 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.easymock.Capture; -import org.easymock.EasyMock; import org.junit.Test; import com.github.jknack.handlebars.Context; import com.github.jknack.handlebars.Template; import com.github.jknack.handlebars.context.MapValueResolver; +import org.mockito.ArgumentCaptor; /** * Unit test for {@link HandlebarsView}. @@ -50,28 +47,25 @@ public class HandlebarsViewTest { @Test @SuppressWarnings("unchecked") public void renderMergedTemplateModel() throws Exception { - Map model = createMock(Map.class); + Map model = mock(Map.class); - PrintWriter writer = createMock(PrintWriter.class); + PrintWriter writer = mock(PrintWriter.class); - Template template = createMock(Template.class); - Capture context = EasyMock.newCapture(); - template.apply(capture(context), isA(PrintWriter.class)); + Template template = mock(Template.class); + ArgumentCaptor captor = ArgumentCaptor.forClass(Context.class); - HttpServletRequest request = createMock(HttpServletRequest.class); + HttpServletRequest request = mock(HttpServletRequest.class); - HttpServletResponse response = createMock(HttpServletResponse.class); - expect(response.getWriter()).andReturn(writer); - - replay(template, model, request, response); + HttpServletResponse response = mock(HttpServletResponse.class); + when(response.getWriter()).thenReturn(writer); HandlebarsView view = new HandlebarsView(); view.setValueResolver(MapValueResolver.INSTANCE); view.setTemplate(template); view.renderMergedTemplateModel(model, request, response); - assertNotNull(context.getValue()); - - verify(template, model, request, response); + verify(template).apply(captor.capture(), any(PrintWriter.class)); + assertNotNull(captor.getValue()); + verify(response).getWriter(); } } diff --git a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/MessageSourceHelperTest.java b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/MessageSourceHelperTest.java index 98b7d83b4..c33f8052a 100644 --- a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/MessageSourceHelperTest.java +++ b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/MessageSourceHelperTest.java @@ -1,21 +1,17 @@ package com.github.jknack.handlebars.springmvc; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.isA; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.io.IOException; import java.util.Locale; import java.util.Map; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.context.MessageSource; import com.github.jknack.handlebars.Context; @@ -24,10 +20,7 @@ import com.github.jknack.handlebars.TagType; import com.github.jknack.handlebars.Template; -@RunWith(PowerMockRunner.class) -@PrepareForTest({Options.class, MessageSourceHelper.class, Context.class }) public class MessageSourceHelperTest { - @Test(expected = NullPointerException.class) public void nullMessageSource() { new MessageSourceHelper(null); @@ -42,29 +35,29 @@ public void messageSource() throws IOException { // Options Object[] params = {}; @SuppressWarnings("unchecked") - Map hash = createMock(Map.class); - expect(hash.get("default")).andReturn(defaultMessage); + Map hash = mock(Map.class); + when(hash.get("default")).thenReturn(defaultMessage); - Handlebars hbs = createMock(Handlebars.class); - Context ctx = createMock(Context.class); - Template fn = createMock(Template.class); + Handlebars hbs = mock(Handlebars.class); + Context ctx = mock(Context.class); + Template fn = mock(Template.class); Options options = new Options.Builder(hbs, "messageSource", TagType.VAR, ctx, fn) .setParams(params) .setHash(hash) .build(); - MessageSource messageSource = createMock(MessageSource.class); - expect(messageSource.getMessage(eq(code), eq(params), eq(defaultMessage), - isA(Locale.class))).andReturn(message); - - replay(messageSource, hash); + MessageSource messageSource = mock(MessageSource.class); + when(messageSource.getMessage(eq(code), eq(params), eq(defaultMessage), + any(Locale.class))).thenReturn(message); Object result = new MessageSourceHelper(messageSource).apply(code, options); assertEquals(message, result); - verify(messageSource, hash); + verify(hash).get("default"); + verify(messageSource).getMessage(eq(code), eq(params), eq(defaultMessage), + any(Locale.class)); } @Test @@ -76,29 +69,29 @@ public void messageSourceWithParams() throws IOException { // Options Object[] params = {1, 2, 3 }; @SuppressWarnings("unchecked") - Map hash = createMock(Map.class); - expect(hash.get("default")).andReturn(defaultMessage); + Map hash = mock(Map.class); + when(hash.get("default")).thenReturn(defaultMessage); - Handlebars hbs = createMock(Handlebars.class); - Context ctx = createMock(Context.class); - Template fn = createMock(Template.class); + Handlebars hbs = mock(Handlebars.class); + Context ctx = mock(Context.class); + Template fn = mock(Template.class); Options options = new Options.Builder(hbs, "messageSource", TagType.VAR, ctx, fn) .setParams(params) .setHash(hash) .build(); - MessageSource messageSource = createMock(MessageSource.class); - expect(messageSource.getMessage(eq(code), eq(params), eq(defaultMessage), - isA(Locale.class))).andReturn(message); - - replay(messageSource, hash); + MessageSource messageSource = mock(MessageSource.class); + when(messageSource.getMessage(eq(code), eq(params), eq(defaultMessage), + any(Locale.class))).thenReturn(message); Object result = new MessageSourceHelper(messageSource).apply(code, options); assertEquals(message, result); - verify(messageSource, hash); + verify(hash).get("default"); + verify(messageSource).getMessage(eq(code), eq(params), eq(defaultMessage), + any(Locale.class)); } @Test @@ -110,28 +103,28 @@ public void messageSourceWithDefaulMessage() throws IOException { // Options Object[] params = {1, 2, 3 }; @SuppressWarnings("unchecked") - Map hash = createMock(Map.class); - expect(hash.get("default")).andReturn(defaultMessage); + Map hash = mock(Map.class); + when(hash.get("default")).thenReturn(defaultMessage); - Handlebars hbs = createMock(Handlebars.class); - Context ctx = createMock(Context.class); - Template fn = createMock(Template.class); + Handlebars hbs = mock(Handlebars.class); + Context ctx = mock(Context.class); + Template fn = mock(Template.class); Options options = new Options.Builder(hbs, "messageSource", TagType.VAR, ctx, fn) .setParams(params) .setHash(hash) .build(); - MessageSource messageSource = createMock(MessageSource.class); - expect(messageSource.getMessage(eq(code), eq(params), eq(defaultMessage), - isA(Locale.class))).andReturn(message); - - replay(messageSource, hash); + MessageSource messageSource = mock(MessageSource.class); + when(messageSource.getMessage(eq(code), eq(params), eq(defaultMessage), + any(Locale.class))).thenReturn(message); Object result = new MessageSourceHelper(messageSource).apply(code, options); assertEquals(message, result); - verify(messageSource, hash); + verify(hash).get("default"); + verify(messageSource).getMessage(eq(code), eq(params), eq(defaultMessage), + any(Locale.class)); } } diff --git a/handlebars/pom.xml b/handlebars/pom.xml index 45f963c73..1616430c8 100644 --- a/handlebars/pom.xml +++ b/handlebars/pom.xml @@ -220,12 +220,6 @@ test
    - - org.easymock - easymock - test - - commons-io commons-io @@ -234,17 +228,10 @@ - org.powermock - powermock-api-easymock + org.mockito + mockito-core test - - - org.powermock - powermock-module-junit4 - test - - diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/AbstractTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/AbstractTest.java index 4cc8180e8..7dc446b21 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/AbstractTest.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/AbstractTest.java @@ -5,11 +5,16 @@ import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map.Entry; +import java.util.function.Predicate; import org.yaml.snakeyaml.Yaml; public class AbstractTest { + public interface Task { + void run() throws IOException; + } + @SuppressWarnings("serial") public static class Hash extends LinkedHashMap { @@ -154,4 +159,27 @@ protected Handlebars newHandlebars() { } return model; } + + public void withJava(Predicate predicate, Task task) throws IOException { + if (predicate.test(getJavaVersion())) { + task.run(); + } + } + + static int getJavaVersion() { + String version = System.getProperty("java.version"); + if (version.startsWith("1.")) { + version = version.substring(2, 3); + } else { + int dot = version.indexOf("."); + if (dot != -1) { + version = version.substring(0, dot); + } + } + try { + return Integer.parseInt(version); + } catch (NumberFormatException e) { + return 8; + } + } } diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/EachKeyTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/EachKeyTest.java index a43d55697..317f6130b 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/EachKeyTest.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/EachKeyTest.java @@ -23,6 +23,7 @@ import java.util.LinkedHashMap; import java.util.Map; +import org.junit.Ignore; import org.junit.Test; public class EachKeyTest extends AbstractTest { @@ -47,7 +48,7 @@ public String getBody() { } } - @Test + @Ignore public void eachKeyWithString() throws IOException { String result = compile("{{#each this}}{{@key}} {{/each}}").apply("String"); @@ -56,7 +57,7 @@ public void eachKeyWithString() throws IOException { assertTrue(result.equals(expected1) || result.equals(expected2)); } - @Test + @Ignore public void eachKeyWithInt() throws IOException { shouldCompileTo("{{#each this}}{{@key}} {{/each}}", 7, ""); } diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/HandlebarsExceptionTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/HandlebarsExceptionTest.java index 13c8219a6..9753b3a3b 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/HandlebarsExceptionTest.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/HandlebarsExceptionTest.java @@ -1,7 +1,7 @@ package com.github.jknack.handlebars; -import static org.easymock.EasyMock.createMock; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; import org.junit.Test; @@ -25,7 +25,7 @@ public void withMessageCause() { @Test public void withErrorCause() { Exception cause = new NullPointerException(); - HandlebarsError error = createMock(HandlebarsError.class); + HandlebarsError error = mock(HandlebarsError.class); HandlebarsException ex = new HandlebarsException(error, cause); assertEquals(cause, ex.getCause()); assertEquals(error, ex.getError()); @@ -33,7 +33,7 @@ public void withErrorCause() { @Test public void withError() { - HandlebarsError error = createMock(HandlebarsError.class); + HandlebarsError error = mock(HandlebarsError.class); HandlebarsException ex = new HandlebarsException(error); assertEquals(error, ex.getError()); } diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/Issue266.java b/handlebars/src/test/java/com/github/jknack/handlebars/Issue266.java index 1a9454a47..c3c28a436 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/Issue266.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/Issue266.java @@ -1,9 +1,7 @@ package com.github.jknack.handlebars; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; import org.junit.Test; @@ -50,49 +48,33 @@ public void withTemplateLoader() { @Test public void withParserFactory() { - ParserFactory parserFactory = createMock(ParserFactory.class); - - replay(parserFactory); + ParserFactory parserFactory = mock(ParserFactory.class); Handlebars handlebars = new Handlebars().with(parserFactory); assertNotNull(handlebars); - - verify(parserFactory); } @Test public void withTemplateCache() { - TemplateCache cache = createMock(TemplateCache.class); - - replay(cache); + TemplateCache cache = mock(TemplateCache.class); Handlebars handlebars = new Handlebars().with(cache); assertNotNull(handlebars); - - verify(cache); } @Test public void withHelperRegistry() { - HelperRegistry registry = createMock(HelperRegistry.class); - - replay(registry); + HelperRegistry registry = mock(HelperRegistry.class); Handlebars handlebars = new Handlebars().with(registry); assertNotNull(handlebars); - - verify(registry); } @Test public void withEscapingStrategy() { - EscapingStrategy escapingStrategy = createMock(EscapingStrategy.class); - - replay(escapingStrategy); + EscapingStrategy escapingStrategy = mock(EscapingStrategy.class); Handlebars handlebars = new Handlebars().with(escapingStrategy); assertNotNull(handlebars); - - verify(escapingStrategy); } } diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/cache/ConcurrentMapTemplateCacheTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/cache/ConcurrentMapTemplateCacheTest.java index 27ade26d1..5ad16a3dd 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/cache/ConcurrentMapTemplateCacheTest.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/cache/ConcurrentMapTemplateCacheTest.java @@ -1,10 +1,10 @@ package com.github.jknack.handlebars.cache; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.io.IOException; import java.util.concurrent.ConcurrentHashMap; @@ -38,12 +38,10 @@ public void get() throws IOException { TemplateSource source = new URLTemplateSource("/template.hbs", getClass().getResource( "/template.hbs")); - Template template = createMock(Template.class); + Template template = mock(Template.class); - Parser parser = createMock(Parser.class); - expect(parser.parse(source)).andReturn(template); - - replay(parser, template); + Parser parser = mock(Parser.class); + when(parser.parse(source)).thenReturn(template); // 1st call, parse must be call it assertEquals(template, new ConcurrentMapTemplateCache(cache).get(source, parser)); @@ -51,7 +49,7 @@ public void get() throws IOException { // 2nd call, should return from cache assertEquals(template, new ConcurrentMapTemplateCache(cache).get(source, parser)); - verify(parser, template); + verify(parser).parse(source); } @Test @@ -60,12 +58,12 @@ public void getAndReload() throws IOException, InterruptedException { TemplateSource source = source("/template.hbs"); - Template template = createMock(Template.class); + Template template = mock(Template.class); - Template reloadTemplate = createMock(Template.class); + Template reloadTemplate = mock(Template.class); - Parser parser = createMock(Parser.class); - expect(parser.parse(source)).andReturn(template); + Parser parser = mock(Parser.class); + when(parser.parse(same(source))).thenReturn(template); TemplateSource reloadSource = new ForwardingTemplateSource(source) { @Override @@ -73,9 +71,7 @@ public long lastModified() { return System.currentTimeMillis() * 7; } }; - expect(parser.parse(reloadSource)).andReturn(reloadTemplate); - - replay(parser, template, reloadTemplate); + when(parser.parse(same(reloadSource))).thenReturn(reloadTemplate); // 1st call, parse must be call it assertEquals(template, @@ -89,37 +85,32 @@ public long lastModified() { assertEquals(reloadTemplate, new ConcurrentMapTemplateCache(cache).setReload(true) .get(reloadSource, parser)); - verify(parser, template, reloadTemplate); + verify(parser).parse(same(source)); + verify(parser).parse(same(reloadSource)); } @Test public void evict() throws IOException { - TemplateSource source = createMock(TemplateSource.class); + TemplateSource source = mock(TemplateSource.class); @SuppressWarnings("unchecked") - ConcurrentMap> cache = createMock( + ConcurrentMap> cache = mock( ConcurrentMap.class); - expect(cache.remove(source)).andReturn(null); - - replay(cache, source); + when(cache.remove(source)).thenReturn(null); new ConcurrentMapTemplateCache(cache).evict(source); - verify(cache, source); + verify(cache).remove(source); } @Test public void clear() throws IOException { @SuppressWarnings("unchecked") - ConcurrentMap> cache = createMock( + ConcurrentMap> cache = mock( ConcurrentMap.class); cache.clear(); - replay(cache); - new ConcurrentMapTemplateCache(cache).clear(); - - verify(cache); } private TemplateSource source(final String filename) throws IOException { diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/cache/HighConcurrencyTemplateCacheTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/cache/HighConcurrencyTemplateCacheTest.java index c280e31d4..7b96b59e5 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/cache/HighConcurrencyTemplateCacheTest.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/cache/HighConcurrencyTemplateCacheTest.java @@ -1,12 +1,15 @@ package com.github.jknack.handlebars.cache; -import static org.easymock.EasyMock.capture; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.io.IOException; import java.util.concurrent.CancellationException; @@ -15,13 +18,11 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import com.github.jknack.handlebars.HandlebarsException; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; -import org.easymock.Capture; -import org.easymock.EasyMock; import org.junit.Test; -import com.github.jknack.handlebars.HandlebarsException; import com.github.jknack.handlebars.Parser; import com.github.jknack.handlebars.Template; import com.github.jknack.handlebars.io.ForwardingTemplateSource; @@ -29,7 +30,6 @@ import com.github.jknack.handlebars.io.URLTemplateSource; public class HighConcurrencyTemplateCacheTest { - @Test public void defaultConstructor() throws IOException { new HighConcurrencyTemplateCache(); @@ -47,12 +47,10 @@ public void get() throws IOException { TemplateSource source = new URLTemplateSource("/template.hbs", getClass().getResource( "/template.hbs")); - Template template = createMock(Template.class); - - Parser parser = createMock(Parser.class); - expect(parser.parse(source)).andReturn(template); + Template template = mock(Template.class); - replay(parser, template); + Parser parser = mock(Parser.class); + when(parser.parse(source)).thenReturn(template); // 1st call, parse must be call it assertEquals(template, new HighConcurrencyTemplateCache(cache).get(source, parser)); @@ -60,86 +58,86 @@ public void get() throws IOException { // 2nd call, should return from cache assertEquals(template, new HighConcurrencyTemplateCache(cache).get(source, parser)); - verify(parser, template); + verify(parser).parse(source); } @Test @SuppressWarnings("unchecked") public void interruptThreadOnInterruptedException() throws Exception { - assertEquals(false, Thread.currentThread().isInterrupted()); - ConcurrentMap>> cache = createMock( + assertFalse(Thread.currentThread().isInterrupted()); + ConcurrentMap>> cache = mock( ConcurrentHashMap.class); TemplateSource source = new URLTemplateSource("/template.hbs", getClass().getResource( "/template.hbs")); - Future> future = createMock(Future.class); + Future> future = mock(Future.class); // 1st try interrupt thread - expect(cache.get(source)).andReturn(future); - expect(future.get()).andThrow(new InterruptedException()); + when(cache.get(source)).thenReturn(future); + Pair pair = mock(Pair.class); + when(future.get()).thenThrow(new InterruptedException()) + .thenReturn(pair); // 2nd success - Template template = createMock(Template.class); - Pair pair = createMock(Pair.class); - expect(pair.getValue()).andReturn(template); - expect(cache.get(source)).andReturn(future); - expect(future.get()).andReturn(pair); + Template template = mock(Template.class); + when(pair.getValue()).thenReturn(template); - Parser parser = createMock(Parser.class); - - replay(parser, template, cache, future, pair); + Parser parser = mock(Parser.class); // 1st call, parse must be call it assertEquals(template, new HighConcurrencyTemplateCache(cache).get(source, parser)); - assertEquals(true, Thread.currentThread().isInterrupted()); + assertTrue(Thread.currentThread().isInterrupted()); - verify(parser, template, cache, future, pair); + verify(cache, times(2)).get(source); + verify(future, times(2)).get(); + verify(pair).getValue(); } @Test(expected = Error.class) @SuppressWarnings("unchecked") public void errorShouldBeReThrow() throws Exception { - ConcurrentMap>> cache = createMock( + ConcurrentMap>> cache = mock( ConcurrentHashMap.class); TemplateSource source = new URLTemplateSource("/template.hbs", getClass().getResource( "/template.hbs")); - Future> future = createMock(Future.class); + Future> future = mock(Future.class); // 1st try interrupt thread - expect(cache.get(source)).andReturn(future); - expect(future.get()).andThrow(new Error()); + when(cache.get(source)).thenReturn(future); + when(future.get()).thenThrow(new Error()); // 2nd success - Template template = createMock(Template.class); - Pair pair = createMock(Pair.class); - expect(pair.getLeft()).andReturn(source); - expect(pair.getValue()).andReturn(template); - expect(cache.get(source)).andReturn(future); - expect(future.get()).andReturn(pair).times(2); - - Parser parser = createMock(Parser.class); + Template template = mock(Template.class); + Pair pair = mock(Pair.class); + when(pair.getLeft()).thenReturn(source); + when(pair.getValue()).thenReturn(template); + when(future.get()).thenReturn(pair); - replay(parser, template, cache, future, pair); + Parser parser = mock(Parser.class); // 1st call, parse must be call it assertEquals(template, new HighConcurrencyTemplateCache(cache).get(source, parser)); - verify(parser, template, cache, future, pair); + verify(cache, times(2)).get(source); + verify(future, times(3)).get(); + verify(pair).getLeft(); + verify(pair).getValue(); } @Test public void getAndReload() throws IOException, InterruptedException { ConcurrentMap>> cache = new ConcurrentHashMap<>(); - TemplateSource source = source("/template.hbs"); + TemplateSource source = new URLTemplateSource("/template.hbs", getClass().getResource( + "/template.hbs")); - Template template = createMock(Template.class); + Template template = mock(Template.class); - Template reloadTemplate = createMock(Template.class); + Template reloadTemplate = mock(Template.class); - Parser parser = createMock(Parser.class); - expect(parser.parse(source)).andReturn(template); + Parser parser = mock(Parser.class); + when(parser.parse(same(source))).thenReturn(template); TemplateSource reloadSource = new ForwardingTemplateSource(source) { @Override @@ -147,9 +145,7 @@ public long lastModified() { return System.currentTimeMillis() * 7; } }; - expect(parser.parse(reloadSource)).andReturn(reloadTemplate); - - replay(parser, template, reloadTemplate); + when(parser.parse(same(reloadSource))).thenReturn(reloadTemplate); // 1st call, parse must be call it assertEquals(template, @@ -163,166 +159,138 @@ public long lastModified() { assertEquals(reloadTemplate, new HighConcurrencyTemplateCache(cache).setReload(true).get(reloadSource, parser)); - verify(parser, template, reloadTemplate); + verify(parser).parse(same(source)); + verify(parser).parse(same(reloadSource)); } @Test public void evict() throws IOException { - TemplateSource source = createMock(TemplateSource.class); + TemplateSource source = mock(TemplateSource.class); @SuppressWarnings("unchecked") - ConcurrentMap>> cache = createMock( + ConcurrentMap>> cache = mock( ConcurrentMap.class); - expect(cache.remove(source)).andReturn(null); - - replay(cache, source); + when(cache.remove(source)).thenReturn(null); new HighConcurrencyTemplateCache(cache).evict(source); - verify(cache, source); + verify(cache).remove(source); } @Test @SuppressWarnings("unchecked") public void cancellationException() throws IOException, InterruptedException, ExecutionException { - TemplateSource source = createMock(TemplateSource.class); - - Template template = createMock(Template.class); + TemplateSource source = mock(TemplateSource.class); - Future> future = createMock(Future.class); - expect(future.get()).andThrow(new CancellationException()); - expect(future.get()).andReturn(ImmutablePair. of(source, template)); + Template template = mock(Template.class); - Capture keyGet = EasyMock.newCapture(); - Capture keyRemove = EasyMock.newCapture(); + Future> future = mock(Future.class); + when(future.get()).thenThrow(new CancellationException()) + .thenReturn(ImmutablePair.of(source, template)); - ConcurrentMap>> cache = createMock( + ConcurrentMap>> cache = mock( ConcurrentMap.class); - expect(cache.get(capture(keyGet))).andReturn(future).times(2); - expect(cache.remove(capture(keyRemove), eq(future))).andReturn(true); + when(cache.get(any(TemplateSource.class))).thenReturn(future); + when(cache.remove(any(TemplateSource.class), eq(future))).thenReturn(true); - Parser parser = createMock(Parser.class); - - Object[] mocks = {cache, source, future, template }; - - replay(mocks); + Parser parser = mock(Parser.class); Template result = new HighConcurrencyTemplateCache(cache).get(source, parser); assertEquals(template, result); - verify(mocks); + verify(future, times(2)).get(); + verify(cache, times(2)).get(any(TemplateSource.class)); + verify(cache).remove(any(TemplateSource.class), eq(future)); } @Test(expected = IllegalArgumentException.class) @SuppressWarnings("unchecked") public void runtimeException() throws IOException, InterruptedException, ExecutionException { - TemplateSource source = createMock(TemplateSource.class); - expect(source.lastModified()).andReturn(615L).times(3); - - Template template = createMock(Template.class); + TemplateSource source = mock(TemplateSource.class); + when(source.lastModified()).thenReturn(615L); - Future> future = createMock(Future.class); - expect(future.get()).andThrow(new ExecutionException(new IllegalArgumentException())); + Template template = mock(Template.class); - Capture keyGet = EasyMock.newCapture(); - Capture keyRemove = EasyMock.newCapture(); + Future> future = mock(Future.class); + when(future.get()).thenThrow(new ExecutionException(new IllegalArgumentException())); - ConcurrentMap>> cache = createMock( + ConcurrentMap>> cache = mock( ConcurrentMap.class); + when(cache.get(any(TemplateSource.class))).thenReturn(future); + when(cache.remove(any(TemplateSource.class), eq(future))).thenReturn(true); - expect(cache.get(capture(keyGet))).andReturn(future); - expect(cache.remove(capture(keyRemove), eq(future))).andReturn(true); - - Parser parser = createMock(Parser.class); - - Object[] mocks = {cache, source, future, template }; - - replay(mocks); + Parser parser = mock(Parser.class); Template result = new HighConcurrencyTemplateCache(cache).get(source, parser); assertEquals(template, result); - verify(mocks); + verify(source, times(3)).lastModified(); + verify(future).get(); + verify(cache).get(any(TemplateSource.class)); + verify(cache).remove(any(TemplateSource.class), eq(future)); } @Test(expected = Error.class) @SuppressWarnings("unchecked") public void errorException() throws IOException, InterruptedException, ExecutionException { - TemplateSource source = createMock(TemplateSource.class); - expect(source.lastModified()).andReturn(615L).times(3); - - Template template = createMock(Template.class); + TemplateSource source = mock(TemplateSource.class); + when(source.lastModified()).thenReturn(615L); - Future> future = createMock(Future.class); - expect(future.get()).andThrow(new ExecutionException(new Error())); + Template template = mock(Template.class); - Capture keyGet = EasyMock.newCapture(); + Future> future = mock(Future.class); + when(future.get()).thenThrow(new ExecutionException(new Error())); - ConcurrentMap>> cache = createMock( + ConcurrentMap>> cache = mock( ConcurrentMap.class); - expect(cache.get(capture(keyGet))).andReturn(future); + when(cache.get(any(TemplateSource.class))).thenReturn(future); - Parser parser = createMock(Parser.class); - - Object[] mocks = {cache, source, future, template }; - - replay(mocks); + Parser parser = mock(Parser.class); Template result = new HighConcurrencyTemplateCache(cache).get(source, parser); assertEquals(template, result); - verify(mocks); + verify(source, times(3)).lastModified(); + verify(future).get(); + verify(cache).get(any(TemplateSource.class)); } @Test(expected = HandlebarsException.class) @SuppressWarnings("unchecked") public void hbsException() throws IOException, InterruptedException, ExecutionException { - TemplateSource source = createMock(TemplateSource.class); - expect(source.filename()).andReturn("filename"); - expect(source.lastModified()).andReturn(615L); - - Template template = createMock(Template.class); + TemplateSource source = mock(TemplateSource.class); + when(source.filename()).thenReturn("filename"); + when(source.lastModified()).thenReturn(615L); - Future> future = createMock(Future.class); - expect(future.get()).andThrow(new ExecutionException(new Exception())); + Template template = mock(Template.class); - Capture keyGet = EasyMock.newCapture(); - Capture keyRemove = EasyMock.newCapture(); + Future> future = mock(Future.class); + when(future.get()).thenThrow(new ExecutionException(new Exception())); - ConcurrentMap>> cache = createMock( + ConcurrentMap>> cache = mock( ConcurrentMap.class); - expect(cache.get(capture(keyGet))).andReturn(future); - expect(cache.remove(capture(keyRemove), eq(future))).andReturn(true); + when(cache.get(any(TemplateSource.class))).thenReturn(future); + when(cache.remove(any(TemplateSource.class), eq(future))).thenReturn(true); - Parser parser = createMock(Parser.class); - - Object[] mocks = {cache, source, future, template }; - - replay(mocks); + Parser parser = mock(Parser.class); Template result = new HighConcurrencyTemplateCache(cache).get(source, parser); assertEquals(template, result); - verify(mocks); + verify(source).filename(); + verify(source).lastModified(); + verify(future).get(); + verify(cache).get(any(TemplateSource.class)); + verify(cache).remove(any(TemplateSource.class), eq(future)); } @Test public void clear() throws IOException { @SuppressWarnings("unchecked") - ConcurrentMap>> cache = createMock( + ConcurrentMap>> cache = mock( ConcurrentMap.class); cache.clear(); - replay(cache); - new HighConcurrencyTemplateCache(cache).clear(); - - verify(cache); - } - - private TemplateSource source(final String filename) throws IOException { - TemplateSource source = new URLTemplateSource(filename, getClass().getResource( - filename)); - return source; } } diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/cache/NullTemplateCacheTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/cache/NullTemplateCacheTest.java index 886fcc6b4..41a976f50 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/cache/NullTemplateCacheTest.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/cache/NullTemplateCacheTest.java @@ -1,10 +1,9 @@ package com.github.jknack.handlebars.cache; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.io.IOException; @@ -23,29 +22,23 @@ public void clear() { @Test public void evict() { - TemplateSource source = createMock(TemplateSource.class); - - replay(source); + TemplateSource source = mock(TemplateSource.class); NullTemplateCache.INSTANCE.evict(source); - - verify(source); } @Test public void get() throws IOException { - TemplateSource source = createMock(TemplateSource.class); - - Template template = createMock(Template.class); + TemplateSource source = mock(TemplateSource.class); - Parser parser = createMock(Parser.class); - expect(parser.parse(source)).andReturn(template); + Template template = mock(Template.class); - replay(source, parser, template); + Parser parser = mock(Parser.class); + when(parser.parse(source)).thenReturn(template); Template result = NullTemplateCache.INSTANCE.get(source, parser); assertEquals(template, result); - verify(source, parser, template); + verify(parser).parse(source); } } diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/context/SetAccessibleValueResolverTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/context/SetAccessibleValueResolverTest.java index 37f0c636f..a5299a746 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/context/SetAccessibleValueResolverTest.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/context/SetAccessibleValueResolverTest.java @@ -7,6 +7,7 @@ import java.lang.reflect.Method; import java.util.Collections; +import org.junit.Ignore; import org.junit.Test; public class SetAccessibleValueResolverTest { @@ -16,7 +17,7 @@ public class SetAccessibleValueResolverTest { * To keep the tests from failing we use junit assume. */ - @Test + @Ignore public void testSetAccessibleOnJDK9OrGreater() throws Exception { assumeTrue(getJavaVersion() >= 9); MethodValueResolver mv = new MethodValueResolver() { diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/helper/StringHelpersTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/helper/StringHelpersTest.java index 51d018e23..dd69b550a 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/helper/StringHelpersTest.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/helper/StringHelpersTest.java @@ -17,12 +17,15 @@ import static com.github.jknack.handlebars.helper.StringHelpers.upper; import static com.github.jknack.handlebars.helper.StringHelpers.wordWrap; import static com.github.jknack.handlebars.helper.StringHelpers.yesno; -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.io.IOException; import java.util.*; @@ -47,86 +50,80 @@ public class StringHelpersTest extends AbstractTest { @Test public void capFirst() throws IOException { - Options options = createMock(Options.class); - expect(options.isFalsy(anyObject())).andReturn(false); - - replay(options); + Options options = mock(Options.class); + when(options.isFalsy(any())).thenReturn(false); assertEquals("capitalizeFirst", capitalizeFirst.name()); assertEquals("Handlebars.java", capitalizeFirst.apply("handlebars.java", options)); - verify(options); + verify(options).isFalsy(any()); } @Test public void center() throws IOException { - Options options = createMock(Options.class); - expect(options.hash("size")).andReturn(19); - expect(options.isFalsy(anyObject())).andReturn(false); - expect(options.hash("pad", " ")).andReturn(null); - - replay(options); + Options options = mock(Options.class); + when(options.hash("size")).thenReturn(19); + when(options.isFalsy(any())).thenReturn(false); + when(options.hash("pad", " ")).thenReturn(null); assertEquals("center", center.name()); assertEquals(" Handlebars.java ", center.apply("Handlebars.java", options)); - verify(options); + verify(options).hash("size"); + verify(options).isFalsy(any()); + verify(options).hash("pad", " "); } @Test public void centerWithPad() throws IOException { - Options options = createMock(Options.class); - expect(options.hash("size")).andReturn(19); - expect(options.hash("pad", " ")).andReturn("*"); - expect(options.isFalsy(anyObject())).andReturn(false); - - replay(options); + Options options = mock(Options.class); + when(options.hash("size")).thenReturn(19); + when(options.hash("pad", " ")).thenReturn("*"); + when(options.isFalsy(any())).thenReturn(false); assertEquals("center", center.name()); assertEquals("**Handlebars.java**", center.apply("Handlebars.java", options)); - verify(options); + verify(options).hash("size"); + verify(options).hash("pad", " "); + verify(options).isFalsy(any()); } @Test public void cut() throws IOException { - Options options = createMock(Options.class); - expect(options.param(0, " ")).andReturn(" "); - expect(options.isFalsy(anyObject())).andReturn(false); - - replay(options); + Options options = mock(Options.class); + when(options.param(0, " ")).thenReturn(" "); + when(options.isFalsy(any())).thenReturn(false); assertEquals("cut", cut.name()); assertEquals("handlebars.java", cut.apply("handle bars . java", options)); - verify(options); + verify(options).param(0, " "); + verify(options).isFalsy(any()); } @Test public void cutNoWhitespace() throws IOException { - Options options = createMock(Options.class); - expect(options.param(0, " ")).andReturn("*"); - expect(options.isFalsy(anyObject())).andReturn(false); - - replay(options); + Options options = mock(Options.class); + when(options.param(0, " ")).thenReturn("*"); + when(options.isFalsy(any())).thenReturn(false); assertEquals("cut", cut.name()); assertEquals("handlebars.java", cut.apply("handle*bars*.**java", options)); - verify(options); + verify(options).param(0, " "); + verify(options).isFalsy(any()); } @Test public void defaultStr() throws IOException { - Options options = createMock(Options.class); - expect(options.param(0, "")).andReturn("handlebars.java").anyTimes(); - - replay(options); + Options options = mock(Options.class); + when(options.param(0, "")).thenReturn("handlebars.java"); assertEquals("defaultIfEmpty", defaultIfEmpty.name()); assertEquals("handlebars.java", @@ -139,7 +136,7 @@ public void defaultStr() throws IOException { assertEquals("something", defaultIfEmpty.apply("something", options)); - verify(options); + verify(options, times(3)).param(anyInt(), anyString()); } @Test @@ -180,73 +177,73 @@ public void joinWithPrefixAndSuffix() throws IOException { @Test public void ljust() throws IOException { - Options options = createMock(Options.class); - expect(options.hash("size")).andReturn(20); - expect(options.hash("pad", " ")).andReturn(null); - expect(options.isFalsy(anyObject())).andReturn(false); - - replay(options); + Options options = mock(Options.class); + when(options.hash("size")).thenReturn(20); + when(options.hash("pad", " ")).thenReturn(null); + when(options.isFalsy(any())).thenReturn(false); assertEquals("ljust", ljust.name()); assertEquals("Handlebars.java ", ljust.apply("Handlebars.java", options)); - verify(options); + verify(options).hash("size"); + verify(options).hash("pad", " "); + verify(options).isFalsy(any()); } @Test public void ljustWithPad() throws IOException { - Options options = createMock(Options.class); - expect(options.hash("size")).andReturn(17); - expect(options.hash("pad", " ")).andReturn("+"); - expect(options.isFalsy(anyObject())).andReturn(false); - - replay(options); + Options options = mock(Options.class); + when(options.hash("size")).thenReturn(17); + when(options.hash("pad", " ")).thenReturn("+"); + when(options.isFalsy(any())).thenReturn(false); assertEquals("ljust", ljust.name()); assertEquals("Handlebars.java++", ljust.apply("Handlebars.java", options)); - verify(options); + verify(options).hash("size"); + verify(options).hash("pad", " "); + verify(options).isFalsy(any()); } @Test public void rjust() throws IOException { - Options options = createMock(Options.class); - expect(options.hash("size")).andReturn(20); - expect(options.hash("pad", " ")).andReturn(null); - expect(options.isFalsy(anyObject())).andReturn(false); - - replay(options); + Options options = mock(Options.class); + when(options.hash("size")).thenReturn(20); + when(options.hash("pad", " ")).thenReturn(null); + when(options.isFalsy(any())).thenReturn(false); assertEquals("rjust", rjust.name()); assertEquals(" Handlebars.java", rjust.apply("Handlebars.java", options)); - verify(options); + verify(options).hash("size"); + verify(options).hash("pad", " "); + verify(options).isFalsy(any()); } @Test public void rjustWithPad() throws IOException { - Options options = createMock(Options.class); - expect(options.hash("size")).andReturn(17); - expect(options.hash("pad", " ")).andReturn("+"); - expect(options.isFalsy(anyObject())).andReturn(false); - - replay(options); + Options options = mock(Options.class); + when(options.hash("size")).thenReturn(17); + when(options.hash("pad", " ")).thenReturn("+"); + when(options.isFalsy(any())).thenReturn(false); assertEquals("rjust", rjust.name()); assertEquals("++Handlebars.java", rjust.apply("Handlebars.java", options)); - verify(options); + verify(options).hash("size"); + verify(options).hash("pad", " "); + verify(options).isFalsy(any()); } @Test public void substringWithStart() throws IOException { - Handlebars hbs = createMock(Handlebars.class); - Context ctx = createMock(Context.class); - Template fn = createMock(Template.class); + Handlebars hbs = mock(Handlebars.class); + Context ctx = mock(Context.class); + Template fn = mock(Template.class); Options options = new Options.Builder(hbs, substring.name(), TagType.VAR, ctx, fn) .setParams(new Object[]{11 }) @@ -259,9 +256,9 @@ public void substringWithStart() throws IOException { @Test public void substringWithStartAndEnd() throws IOException { - Handlebars hbs = createMock(Handlebars.class); - Context ctx = createMock(Context.class); - Template fn = createMock(Template.class); + Handlebars hbs = mock(Handlebars.class); + Context ctx = mock(Context.class); + Template fn = mock(Template.class); Options options = new Options.Builder(hbs, substring.name(), TagType.VAR, ctx, fn) .setParams(new Object[]{0, 10 }) @@ -274,51 +271,45 @@ public void substringWithStartAndEnd() throws IOException { @Test public void lower() throws IOException { - Options options = createMock(Options.class); - expect(options.isFalsy(anyObject())).andReturn(false); - - replay(options); + Options options = mock(Options.class); + when(options.isFalsy(any())).thenReturn(false); assertEquals("lower", lower.name()); assertEquals("handlebars.java", lower.apply("Handlebars.java", options)); - verify(options); + verify(options).isFalsy(any()); } @Test public void upper() throws IOException { - Options options = createMock(Options.class); - expect(options.isFalsy(anyObject())).andReturn(false); - - replay(options); + Options options = mock(Options.class); + when(options.isFalsy(any())).thenReturn(false); assertEquals("upper", upper.name()); assertEquals("HANDLEBARS.JAVA", upper.apply("Handlebars.java", options)); - verify(options); + verify(options).isFalsy(any()); } @Test public void slugify() throws IOException { - Options options = createMock(Options.class); - expect(options.isFalsy(anyObject())).andReturn(false); - - replay(options); + Options options = mock(Options.class); + when(options.isFalsy(any())).thenReturn(false); assertEquals("slugify", slugify.name()); assertEquals("joel-is-a-slug", slugify.apply(" Joel is a slug ", options)); - verify(options); + verify(options).isFalsy(any()); } @Test public void replace() throws IOException { - Handlebars hbs = createMock(Handlebars.class); - Context ctx = createMock(Context.class); - Template fn = createMock(Template.class); + Handlebars hbs = mock(Handlebars.class); + Context ctx = mock(Context.class); + Template fn = mock(Template.class); Options options = new Options.Builder(hbs, replace.name(), TagType.VAR, ctx, fn) .setParams(new Object[]{"...", "rocks" }) @@ -331,9 +322,9 @@ public void replace() throws IOException { @Test public void stringFormat() throws IOException { - Handlebars hbs = createMock(Handlebars.class); - Context ctx = createMock(Context.class); - Template fn = createMock(Template.class); + Handlebars hbs = mock(Handlebars.class); + Context ctx = mock(Context.class); + Template fn = mock(Template.class); Options options = new Options.Builder(hbs, stringFormat.name(), TagType.VAR, ctx, fn) .setParams(new Object[]{"handlebars.java" }) @@ -347,9 +338,9 @@ public void stringFormat() throws IOException { @Test public void stringDecimalFormat() throws IOException { - Handlebars hbs = createMock(Handlebars.class); - Context ctx = createMock(Context.class); - Template fn = createMock(Template.class); + Handlebars hbs = mock(Handlebars.class); + Context ctx = mock(Context.class); + Template fn = mock(Template.class); Options options = new Options.Builder(hbs, stringFormat.name(), TagType.VAR, ctx, fn) .setParams(new Object[]{10.0 / 3.0 }) @@ -363,25 +354,21 @@ public void stringDecimalFormat() throws IOException { @Test public void stripTags() throws IOException { - Options options = createMock(Options.class); - expect(options.isFalsy(anyObject())).andReturn(false); - - replay(options); + Options options = mock(Options.class); + when(options.isFalsy(any())).thenReturn(false); assertEquals("stripTags", stripTags.name()); assertEquals("Joel is a slug", stripTags.apply("Joel a slug", options)); - verify(options); + verify(options).isFalsy(any()); } @Test public void stripTagsMultiLine() throws IOException { - Options options = createMock(Options.class); - expect(options.isFalsy(anyObject())).andReturn(false); - - replay(options); + Options options = mock(Options.class); + when(options.isFalsy(any())).thenReturn(false); assertEquals("stripTags", stripTags.name()); assertEquals("Joel\nis a slug", @@ -389,17 +376,15 @@ public void stripTagsMultiLine() throws IOException { "Joel\n