From 91094df86b197662beba36f54e95396c19cc731a Mon Sep 17 00:00:00 2001 From: William Rey Date: Fri, 2 May 2014 12:12:00 +0200 Subject: [PATCH 1/7] Changed the GroupId and some other related stuff. --- pom.xml | 55 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 6095d21..12ed30a 100644 --- a/pom.xml +++ b/pom.xml @@ -7,14 +7,14 @@ oss-parent 7 - com.github.sps.mustache + com.github.wrey75.mustache mustache-spring-view jar 1.3-SNAPSHOT mustache spring view a spring view for the mustache templating language http://mustache.github.com/ - http://github.com/sps/mustache-spring-view + http://github.com/wrey75/mustache-spring-view The Apache Software License, Version 2.0 @@ -23,16 +23,16 @@ - http://github.com/sps/mustache-spring-view - scm:git:git@github.com:sps/mustache-spring-view.git - scm:git:git@github.com:sps/mustache-spring-view.git + http://github.com/wrey75/mustache-spring-view + scm:git:git@github.com:wrey75/mustache-spring-view.git + scm:git:git@github.com:wrey75/mustache-spring-view.git - sps - Sean Scanlon - sean.scanlon@gmail.com + wrey75 + William Rey + wrey75@gmail.com @@ -43,6 +43,42 @@ 1.5 + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.jacoco + jacoco-maven-plugin + [0.5,) + + + prepare-agent + + + + + + + + + + + + + + maven-compiler-plugin @@ -161,7 +197,6 @@ provided - org.springframework spring-context @@ -206,4 +241,6 @@ + + From 83122e7e99df33ee81bcbf2e612574dd4c006bbb Mon Sep 17 00:00:00 2001 From: William Rey Date: Mon, 26 May 2014 09:41:15 +0200 Subject: [PATCH 2/7] Catch of inexistent template --- pom.xml | 2 +- .../view/mustache/MustacheViewResolver.java | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index bd34c7b..82652b3 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ 4.0.3.RELEASE 1.9 0.8.14 - 1.9.0 + 1.8.5 4.11 1.5 diff --git a/src/main/java/org/springframework/web/servlet/view/mustache/MustacheViewResolver.java b/src/main/java/org/springframework/web/servlet/view/mustache/MustacheViewResolver.java index d2aa424..d1a5179 100644 --- a/src/main/java/org/springframework/web/servlet/view/mustache/MustacheViewResolver.java +++ b/src/main/java/org/springframework/web/servlet/view/mustache/MustacheViewResolver.java @@ -15,6 +15,10 @@ */ package org.springframework.web.servlet.view.mustache; +import java.io.FileNotFoundException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Required; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.view.AbstractTemplateViewResolver; @@ -24,7 +28,7 @@ * @author Sean Scanlon */ public class MustacheViewResolver extends AbstractTemplateViewResolver implements ViewResolver { - + private static Log LOG = LogFactory.getLog(MustacheViewResolver.class); private MustacheTemplateFactory templateFactory; public MustacheViewResolver() { @@ -41,9 +45,19 @@ protected AbstractUrlBasedView buildView(String viewName) throws Exception { final MustacheView view = (MustacheView) super.buildView(viewName); - final MustacheTemplate template = templateFactory.getTemplate(view.getUrl()); - view.setTemplate(template); - + try { + final MustacheTemplate template = templateFactory.getTemplate(view.getUrl()); + view.setTemplate(template); + } +// catch( FileNotFoundException ex ){ +// LOG.debug("Template [" + viewName + "] not found."); +// } + catch( MustacheTemplateException ex ){ + if( ex.getCause() != null && ex.getCause() instanceof FileNotFoundException ){ + LOG.debug("Template [" + viewName + "] not found."); + } + else throw ex; // simply rethrow! + } return view; } From 28dc83546f5e213275d8dfa7a6d4fdbbb97db939 Mon Sep 17 00:00:00 2001 From: William R Date: Mon, 26 May 2014 11:45:38 +0200 Subject: [PATCH 3/7] Travis for my own project --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 955e4ab..aaac36e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,9 @@ language: java install: echo "I trust Maven." -env: - global: - - secure: "Th3n6AmSSw5jkrkz77TW/YtCdOJ1bQDtDaDFmBUpSAnM2+PHnPnPl2yqtaPlYV5qV+0bTpQNqQ/mGuHHDYgOshPwtkAf1g5xNNCTFuETk6LXhv+JD//b3E4afjj9DFlQXmxWQSL1ffVt8yBL6/+Jkon/SH6y/jyp3OGlBWCh6D4=" +#env: +# global: +# - secure: "Th3n6AmSSw5jkrkz77TW/YtCdOJ1bQDtDaDFmBUpSAnM2+PHnPnPl2yqtaPlYV5qV+0bTpQNqQ/mGuHHDYgOshPwtkAf1g5xNNCTFuETk6LXhv+JD//b3E4afjj9DFlQXmxWQSL1ffVt8yBL6/+Jkon/SH6y/jyp3OGlBWCh6D4=" # don't just run the tests, also run Findbugs and friends script: mvn verify coveralls:jacoco @@ -17,4 +17,4 @@ notifications: # about configuring notification recipients and more. email: recipients: - - sean.scanlon@gmail.com + - wrey75@gmail.com From 46a1e416bc3b27e7da3557c8655b757329daebe7 Mon Sep 17 00:00:00 2001 From: William Rey Date: Mon, 26 May 2014 13:30:25 +0200 Subject: [PATCH 4/7] Updated the COVERALLS token --- .travis.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index aaac36e..721c9db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,15 +2,17 @@ language: java install: echo "I trust Maven." -#env: -# global: -# - secure: "Th3n6AmSSw5jkrkz77TW/YtCdOJ1bQDtDaDFmBUpSAnM2+PHnPnPl2yqtaPlYV5qV+0bTpQNqQ/mGuHHDYgOshPwtkAf1g5xNNCTFuETk6LXhv+JD//b3E4afjj9DFlQXmxWQSL1ffVt8yBL6/+Jkon/SH6y/jyp3OGlBWCh6D4=" +env: + global: + - secure: "rT6NzwhBiT1Ybvuuq5NfK0GZQ0woRHAXVaHCSRd7emJLa6lu/l7Vfit7qOIgB36RFLW23p0cFqcFmE1ewC9IE/xUnyvGmTvUBazeD8/u0VUYYV2fGDwP7yhVMf/pZbKTpbX6mjegLd0RYiLMvIK5fCRvy+op+3lrX/XYrPpAY24=" # don't just run the tests, also run Findbugs and friends script: mvn verify coveralls:jacoco jdk: - oraclejdk7 + - openjdk7 + - openjdk6 notifications: # See http://about.travis-ci.org/docs/user/build-configuration/ to learn more From 04d709ddcc9ed3db9829a8c26cd52867a0a60959 Mon Sep 17 00:00:00 2001 From: William Rey Date: Mon, 2 Jun 2014 18:08:58 +0200 Subject: [PATCH 5/7] Now compatible with ContentNegotiatingViewResolver The code is now aware of multiple view resolvers and a tests has been added for validating the stuff. --- .../servlet/view/mustache/MustacheView.java | 15 ++++++++- .../view/mustache/MustacheViewResolver.java | 6 +++- .../mustache/MustacheViewResolverTest.java | 33 +++++++++++++++++++ .../view/mustache/MustacheViewTest.java | 8 +++++ 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/web/servlet/view/mustache/MustacheView.java b/src/main/java/org/springframework/web/servlet/view/mustache/MustacheView.java index b9c5cb3..c9abcc9 100644 --- a/src/main/java/org/springframework/web/servlet/view/mustache/MustacheView.java +++ b/src/main/java/org/springframework/web/servlet/view/mustache/MustacheView.java @@ -15,12 +15,13 @@ */ package org.springframework.web.servlet.view.mustache; -import com.samskivert.mustache.Template; import org.springframework.web.servlet.view.AbstractTemplateView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import java.io.Writer; +import java.util.Locale; import java.util.Map; /** @@ -47,4 +48,16 @@ public void setTemplate(MustacheTemplate template) { public MustacheTemplate getTemplate() { return template; } + + /** + * Check whether the underlying resource that the configured URL points to + * actually exists. + * @param locale the desired Locale that we're looking for + * @return {@code true} if the resource exists (or is assumed to exist); + * {@code false} if we know that it does not exist + * @throws Exception if the resource exists but is invalid (e.g. could not be parsed) + */ + public boolean checkResource(Locale locale) throws Exception { + return template != null; + } } diff --git a/src/main/java/org/springframework/web/servlet/view/mustache/MustacheViewResolver.java b/src/main/java/org/springframework/web/servlet/view/mustache/MustacheViewResolver.java index d1a5179..a16e56a 100644 --- a/src/main/java/org/springframework/web/servlet/view/mustache/MustacheViewResolver.java +++ b/src/main/java/org/springframework/web/servlet/view/mustache/MustacheViewResolver.java @@ -16,6 +16,7 @@ package org.springframework.web.servlet.view.mustache; import java.io.FileNotFoundException; +import java.util.Locale; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -43,7 +44,7 @@ protected Class requiredViewClass() { @Override protected AbstractUrlBasedView buildView(String viewName) throws Exception { - final MustacheView view = (MustacheView) super.buildView(viewName); + MustacheView view = (MustacheView) super.buildView(viewName); try { final MustacheTemplate template = templateFactory.getTemplate(view.getUrl()); @@ -55,12 +56,15 @@ protected AbstractUrlBasedView buildView(String viewName) throws Exception { catch( MustacheTemplateException ex ){ if( ex.getCause() != null && ex.getCause() instanceof FileNotFoundException ){ LOG.debug("Template [" + viewName + "] not found."); + // view = null; } else throw ex; // simply rethrow! } return view; } + + @Required public void setTemplateFactory(MustacheTemplateFactory templateFactory) { this.templateFactory = templateFactory; diff --git a/src/test/java/org/springframework/web/servlet/view/mustache/MustacheViewResolverTest.java b/src/test/java/org/springframework/web/servlet/view/mustache/MustacheViewResolverTest.java index c4eb51a..2db3f1d 100644 --- a/src/test/java/org/springframework/web/servlet/view/mustache/MustacheViewResolverTest.java +++ b/src/test/java/org/springframework/web/servlet/view/mustache/MustacheViewResolverTest.java @@ -15,14 +15,21 @@ */ package org.springframework.web.servlet.view.mustache; +import java.io.FileNotFoundException; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.web.servlet.View; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; /** @@ -57,4 +64,30 @@ public void testBuildView() throws Exception { verify(templateFactory).getTemplate(viewName); } + @Test + public void testBuildViewReturnsNullWhenFileNotFound() throws Exception { + /* + * Test the exception is well trapped in the checkResource() + * used by Spring. + * + */ + doThrow(new MustacheTemplateException(new FileNotFoundException())) + .when(templateFactory).getTemplate(viewName); + View view = viewResolver.buildView(viewName); + + /* + * Check the view is a Mustache View! + */ + assertTrue( view instanceof MustacheView); + + /* + * If the view does not exists, then the template + * is "null" and the "checkResource" will return + * false. + * + */ + MustacheView mustacheView = (MustacheView)view; + assertNull( mustacheView.getTemplate() ); + assertFalse( mustacheView.checkResource(null) ); + } } diff --git a/src/test/java/org/springframework/web/servlet/view/mustache/MustacheViewTest.java b/src/test/java/org/springframework/web/servlet/view/mustache/MustacheViewTest.java index 61550e5..cbb8fb7 100644 --- a/src/test/java/org/springframework/web/servlet/view/mustache/MustacheViewTest.java +++ b/src/test/java/org/springframework/web/servlet/view/mustache/MustacheViewTest.java @@ -20,14 +20,19 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.web.servlet.View; import javax.servlet.http.HttpServletResponse; + +import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Collections; import java.util.Map; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; /** @@ -68,4 +73,7 @@ public void testRenderMergedTemplateModel() throws Exception { assertEquals(template, view.getTemplate()); } + + + } From 9b91b53be09ba326e40228cb73913f6d85408e1b Mon Sep 17 00:00:00 2001 From: William Rey Date: Tue, 3 Jun 2014 14:28:17 +0200 Subject: [PATCH 6/7] Use the original POM.XML --- pom.xml | 57 ++++++++++----------------------------------------------- 1 file changed, 10 insertions(+), 47 deletions(-) diff --git a/pom.xml b/pom.xml index 82652b3..6b8b441 100644 --- a/pom.xml +++ b/pom.xml @@ -5,14 +5,14 @@ oss-parent 9 - com.github.wrey75.mustache + com.github.sps.mustache mustache-spring-view jar 1.4-SNAPSHOT mustache spring view a spring view for the mustache templating language http://mustache.github.com/ - http://github.com/wrey75/mustache-spring-view + http://github.com/sps/mustache-spring-view The Apache Software License, Version 2.0 @@ -21,63 +21,27 @@ - http://github.com/wrey75/mustache-spring-view - scm:git:git@github.com:wrey75/mustache-spring-view.git - scm:git:git@github.com:wrey75/mustache-spring-view.git + http://github.com/sps/mustache-spring-view + scm:git:git@github.com:sps/mustache-spring-view.git + scm:git:git@github.com:sps/mustache-spring-view.git - wrey75 - William Rey - wrey75@gmail.com + sps + Sean Scanlon + sean.scanlon@gmail.com 4.0.3.RELEASE 1.9 0.8.14 - 1.8.5 + 1.9.0 4.11 1.5 - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.jacoco - jacoco-maven-plugin - [0.5,) - - - prepare-agent - - - - - - - - - - - - - - maven-compiler-plugin @@ -204,6 +168,7 @@ provided + org.springframework spring-context @@ -254,6 +219,4 @@ - - From 248d893409e39cb3ace23d4b63b32ea582670b44 Mon Sep 17 00:00:00 2001 From: William Rey Date: Tue, 3 Jun 2014 14:31:58 +0200 Subject: [PATCH 7/7] Original Travis file --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 721c9db..955e4ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,19 +4,17 @@ install: echo "I trust Maven." env: global: - - secure: "rT6NzwhBiT1Ybvuuq5NfK0GZQ0woRHAXVaHCSRd7emJLa6lu/l7Vfit7qOIgB36RFLW23p0cFqcFmE1ewC9IE/xUnyvGmTvUBazeD8/u0VUYYV2fGDwP7yhVMf/pZbKTpbX6mjegLd0RYiLMvIK5fCRvy+op+3lrX/XYrPpAY24=" + - secure: "Th3n6AmSSw5jkrkz77TW/YtCdOJ1bQDtDaDFmBUpSAnM2+PHnPnPl2yqtaPlYV5qV+0bTpQNqQ/mGuHHDYgOshPwtkAf1g5xNNCTFuETk6LXhv+JD//b3E4afjj9DFlQXmxWQSL1ffVt8yBL6/+Jkon/SH6y/jyp3OGlBWCh6D4=" # don't just run the tests, also run Findbugs and friends script: mvn verify coveralls:jacoco jdk: - oraclejdk7 - - openjdk7 - - openjdk6 notifications: # See http://about.travis-ci.org/docs/user/build-configuration/ to learn more # about configuring notification recipients and more. email: recipients: - - wrey75@gmail.com + - sean.scanlon@gmail.com