public void execute() throws MojoExecutionException, MojoFailureException { SourceInclusionScanner scanner = includeStale ? new StaleSourceScanner(1024, Collections.singleton("**/*." + extension), Collections.<String>emptySet()) : new SimpleSourceInclusionScanner(Collections.singleton("**/*." + extension), Collections.<String>emptySet()); scanner.addSourceMapping(new SuffixMapping("." + extension, "." + extension)); MustacheFactory mustacheFactory = new DefaultMustacheFactory(); try { Set<File> files = scanner.getIncludedSources(sourceDirectory, outputDirectory); for (File file : files) { try { mustacheFactory.compile(new FileReader(file), file.getAbsolutePath()); } catch (MustacheException e) { throw new MojoFailureException(e.getMessage(), e); } } } catch (InclusionScanException | FileNotFoundException e) { throw new MojoExecutionException(e.getMessage()); } } }
public void testEmptyMustache() { try { new DefaultMustacheFactory().compile(new StringReader("{{}}"), "test"); fail("Didn't throw an exception"); } catch (MustacheException e) { assertTrue(e.getMessage().startsWith("Empty mustache")); } }
public void testMalformedTag() { try { String template = "\n{{$value}}\n{/value}}"; Mustache mustache = new DefaultMustacheFactory().compile(new StringReader(template), "test"); StringWriter sw = new StringWriter(); mustache.execute(sw, new Object[0]); fail("Should have failed to compile"); } catch (MustacheException e) { assertEquals("Failed to close 'value' tag @[test:2]", e.getMessage()); } }
public void testImproperlyClosedVariable() throws IOException { try { new DefaultMustacheFactory().compile(new StringReader("{{{#containers}} {{/containers}}"), "example"); fail("Should have throw MustacheException"); } catch (MustacheException actual) { assertEquals("Improperly closed variable in example:1 @[example:1]", actual.getMessage()); } }
@Test public void testThrowMustacheExceptionInCaseOfNullHandler() throws Exception { try { String template = "<ol>\n" + " <li>{{test.1}}</li>\n" + " <li>{{test.0}}</li>\n" + " <li>{{test.3}}</li>\n" + "</ol>\n" + "<ol>\n" + "{{#test}}\n" + " <li>{{.}}</li>\n" + "{{/test}}\n" + "</ol>"; Object scope = new Object() { String[] test = new String[]{ "a", "b", "c", "d" }; }; DefaultMustacheFactory mf = new DefaultMustacheFactory(); mf.setObjectHandler(null); Mustache m = mf.compile(new StringReader(template), "template"); m.execute(new StringWriter(), scope).flush(); fail("should have thrown MustacheException"); } catch (MustacheException expected) { assertEquals("Failed to get value for test.1 @[template:2]", expected.getMessage()); } }
public void testLimitedDepthRecursion() { try { StringWriter sw = execute("infiniteparent.html", new Context()); fail("Should have failed"); } catch (StackOverflowError soe) { fail("Should not have overflowed the stack"); } catch (MustacheException e) { assertEquals("Maximum partial recursion limit reached: 100 @[infiniteparent.html:1]", e.getMessage()); } }
throw new OnlineToolException("Invalid SPDX Document: " + e.getMessage()); } catch (MustacheException e) { throw new OnlineToolException("Unexpected error reading the HTML template: " + e.getMessage()); } finally { if (writer != null) {
throw new OnlineToolException("Invalid SPDX Document: " + e.getMessage()); } catch (MustacheException e) { throw new OnlineToolException("Unexpected error reading the HTML template: " + e.getMessage()); } finally { if (writer != null) {
@Test public void testApplyMissingExceptionValueThrows() throws IOException { Map<String, String> env = new TreeMap<>(); env.put("foo", "bar"); env.put("bar", "baz"); env.put("baz", "foo"); try { TemplateUtils.renderMustacheThrowIfMissing( "testTemplate", "hello this is {{a_missing_parameter}},\nand {{another_missing_parameter}}. thanks for reading bye", env); Assert.fail("expected exception"); } catch (MustacheException e) { Assert.assertEquals(String.format( "Missing 2 values when rendering testTemplate:%n" + "- Missing values: [a_missing_parameter@L1, another_missing_parameter@L2]%n" + "- Provided values: %s", env), e.getMessage()); } }