take version from manifest V00.07.06
authorymh <ymh.work@gmail.com>
Thu, 13 Feb 2014 11:07:18 +0100
changeset 258 c14725cb24ae
parent 257 6bf1126c5add
child 259 f077b16e9d5f
take version from manifest
server/pom.xml
server/src/main/java/org/iri_research/renkan/Constants.java
server/src/main/java/org/iri_research/renkan/controller/VersionHandlerInterceptor.java
server/src/main/webapp/WEB-INF/applicationContext.xml
server/src/main/webapp/WEB-INF/spring-servlet.xml
server/src/main/webapp/WEB-INF/templates/fragment/pageFragment.html
server/src/test/java/org/iri_research/renkan/test/controller/GroupsAdminControllerTest.java
server/src/test/java/org/iri_research/renkan/test/controller/SpacesAdminControllerTest.java
server/src/test/java/org/iri_research/renkan/test/controller/UsersAdminControllerTest.java
server/src/test/resources/org/iri_research/renkan/test/controller/controller-context.xml
server/src/test/resources/org/iri_research/renkan/test/repositories/repositories-context.xml
server/src/test/resources/org/iri_research/renkan/test/rest/rest-context.xml
--- a/server/pom.xml	Tue Feb 11 10:18:29 2014 +0100
+++ b/server/pom.xml	Thu Feb 13 11:07:18 2014 +0100
@@ -4,7 +4,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.iri_research.renkan</groupId>
     <artifactId>renkan</artifactId>
-    <version>0.7.5</version>
+    <version>0.7.6</version>
     <packaging>war</packaging>
 
     <properties>
@@ -15,7 +15,7 @@
         <spring-version>3.2.6.RELEASE</spring-version>
         <spring-data-mongodb-version>1.3.3.RELEASE</spring-data-mongodb-version>
         <spring-security-version>3.2.0.RELEASE</spring-security-version>
-        <spring-data-commons-version>1.6.1.RELEASE</spring-data-commons-version>
+        <spring-data-commons-version>1.6.3.RELEASE</spring-data-commons-version>
         <spring-data-jpa-version>1.4.3.RELEASE</spring-data-jpa-version>
         <jetty-plugin-version>8.1.14.v20131031</jetty-plugin-version>
         <jetty-version>8.1.14.v20131031</jetty-version>
@@ -26,7 +26,7 @@
         <cometd-version>2.7.0</cometd-version>
         <jackson-version>2.2.3</jackson-version>
         <joda-version>2.3</joda-version>
-        <mongo-driver-version>2.11.3</mongo-driver-version>
+        <mongo-driver-version>2.11.4</mongo-driver-version>
         <jaxrs-api-version>2.0</jaxrs-api-version>
         <javax-annotation-version>1.2</javax-annotation-version>
         <javax-inject-version>1</javax-inject-version>
--- a/server/src/main/java/org/iri_research/renkan/Constants.java	Tue Feb 11 10:18:29 2014 +0100
+++ b/server/src/main/java/org/iri_research/renkan/Constants.java	Thu Feb 13 11:07:18 2014 +0100
@@ -10,42 +10,6 @@
 
 public class Constants {
 
-    static {
-
-    }
-
-    public final static List<String> VERSION = Collections
-            .unmodifiableList(new ArrayList<String>() {
-                private static final long serialVersionUID = -6935554100028328149L;
-                {
-                    add("0");
-                    add("7");
-                    add("5");
-                    add("final");
-                    add("0");
-                }
-            });
-
-    public static String getVersion() {
-
-        String[] version_array = VERSION.toArray(new String[VERSION.size()]);
-
-        String version = String.format("%s.%s", version_array[0],
-                version_array[1]);
-        if (version_array[2] != null && !version_array[2].isEmpty()
-                && Integer.parseInt(version_array[2]) > 0) {
-            version = String.format("%s.%s", version, version_array[2]);
-        }
-        if (version_array[3] == "alpha" && version_array[4] == "0") {
-            version = String.format("%s pre-alpha", version);
-        } else if (version_array[3] != "final") {
-            version = String.format("%s %s %s", version, version_array[3],
-                    version_array[4]);
-        }
-        return version;
-
-    }
-
     public final static String KEYHEX = "f2338d2299ac28ef64f82956fde37337b87a2b9e8fc03e28fa0768cac37d838113c7d0fc78c60fce1e23b1b3e03ac7db4676b3189c267f26baaab10f72544441";
     public final static int SALT_LENGTH = 24;
     public final static int PAGINATION_SIZE = 10;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/server/src/main/java/org/iri_research/renkan/controller/VersionHandlerInterceptor.java	Thu Feb 13 11:07:18 2014 +0100
@@ -0,0 +1,55 @@
+package org.iri_research.renkan.controller;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+
+@Component
+public class VersionHandlerInterceptor extends HandlerInterceptorAdapter {
+    
+    @SuppressWarnings("unused")
+    private final Logger logger = LoggerFactory
+            .getLogger(VersionHandlerInterceptor.class);
+    
+    private static String version = null;
+    
+    @Override
+    public void postHandle(HttpServletRequest request,
+            HttpServletResponse response, Object handler,
+            ModelAndView modelAndView) throws Exception {
+        if(modelAndView != null) {
+            if(version == null) {
+                ServletContext context = request.getServletContext();
+                InputStream inputStream = context.getResourceAsStream("/META-INF/MANIFEST.MF");
+                if(inputStream != null) {
+                    try {
+                        Manifest manifest = new Manifest(inputStream);
+                        Attributes att = manifest.getMainAttributes();
+                        version = att.getValue("Implementation-Version");
+                    }
+                    catch(IOException e) {
+                        version = "N/A";
+                    }
+                }
+                if(version == null) {
+                    version = "NULL";
+                }
+                else if (version == "") {
+                    version = "EMPTY";
+                }
+            }
+            modelAndView.addObject("version", version);
+        }
+    }
+}
--- a/server/src/main/webapp/WEB-INF/applicationContext.xml	Tue Feb 11 10:18:29 2014 +0100
+++ b/server/src/main/webapp/WEB-INF/applicationContext.xml	Thu Feb 13 11:07:18 2014 +0100
@@ -6,17 +6,18 @@
 	xmlns:mvc="http://www.springframework.org/schema/mvc"
 	xsi:schemaLocation="
 	        http://www.springframework.org/schema/beans
-	   		http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+	   		http://www.springframework.org/schema/beans/spring-beans.xsd
 	   		http://www.springframework.org/schema/context
-	   		http://www.springframework.org/schema/context/spring-context-3.0.xsd
+	   		http://www.springframework.org/schema/context/spring-context.xsd
 	   		http://www.springframework.org/schema/util
-	   		http://www.springframework.org/schema/util/spring-util-3.0.xsd
+	   		http://www.springframework.org/schema/util/spring-util.xsd
 	   		http://www.springframework.org/schema/mvc
-            http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"
+            http://www.springframework.org/schema/mvc/spring-mvc.xsd"
 >
-	
-	<!-- Activates various annotations to be detected in bean classes -->
-	<context:annotation-config />
+
+    <!-- Activates various annotations to be detected in bean classes -->
+    <context:annotation-config />
+    <mvc:annotation-driven />
 
     <util:properties id="propsLocations">
         <prop key="servletContextProps">WEB-INF/renkan.properties</prop>
@@ -82,6 +83,7 @@
             </bean>
         </mvc:argument-resolvers>
     </mvc:annotation-driven-->
+    
     <bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" id="messageSource">
         <property name="basenames">
             <list>
@@ -92,6 +94,5 @@
         <property name="defaultEncoding" value="UTF-8"/>
         <property name="fallbackToSystemLocale" value="true" />
     </bean>
-    
 
 </beans>
--- a/server/src/main/webapp/WEB-INF/spring-servlet.xml	Tue Feb 11 10:18:29 2014 +0100
+++ b/server/src/main/webapp/WEB-INF/spring-servlet.xml	Thu Feb 13 11:07:18 2014 +0100
@@ -30,6 +30,10 @@
 	        </bean>
 	    </mvc:argument-resolvers>
     </mvc:annotation-driven>
+    <mvc:interceptors>
+        <bean class="org.iri_research.renkan.controller.VersionHandlerInterceptor"/>
+    </mvc:interceptors>
+
     <context:component-scan
         base-package="org.iri_research.renkan.controller" />
          
@@ -54,12 +58,12 @@
     <bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
         <property name="templateResolver" ref="templateResolver" />
         <property name="additionalDialects">
-	        <set>
-	          <bean class="org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect"/>
-	        </set>
+            <set>
+              <bean class="org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect"/>
+            </set>
       </property>
     </bean>
-    
+
     <bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
         <property name="templateEngine" ref="templateEngine" />
         <property name="order" value="1" />
--- a/server/src/main/webapp/WEB-INF/templates/fragment/pageFragment.html	Tue Feb 11 10:18:29 2014 +0100
+++ b/server/src/main/webapp/WEB-INF/templates/fragment/pageFragment.html	Thu Feb 13 11:07:18 2014 +0100
@@ -22,7 +22,7 @@
         </div>
     </header>
     <footer id="footer" th:fragment="footerFragment" >
-        <div id="version">© <span th:text="${#dates.year(#dates.createNow())}" class="version-date">2013</span> <a href="http://www.iri.centrepompidou.fr" target="_blank">IRI</a> - Version <span th:text="${T(org.iri_research.renkan.Constants).version}" class="version-version">0.0a</span></div>
+        <div id="version">© <span th:text="${#dates.year(#dates.createNow())}" class="version-date">2013</span> <a href="http://www.iri.centrepompidou.fr" target="_blank">IRI</a> - Version <span th:text="${version}" class="version-version">0.0a</span></div>
     </footer>
 </body>
 </html>
\ No newline at end of file
--- a/server/src/test/java/org/iri_research/renkan/test/controller/GroupsAdminControllerTest.java	Tue Feb 11 10:18:29 2014 +0100
+++ b/server/src/test/java/org/iri_research/renkan/test/controller/GroupsAdminControllerTest.java	Thu Feb 13 11:07:18 2014 +0100
@@ -178,7 +178,7 @@
 
         this.mvc.perform(post)
                 .andExpect(MockMvcResultMatchers.status().isSeeOther())
-                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/groups"));
+                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/groups?version=NULL"));
 
         Group group = this.groupsRepository.findOne(this.groupsUuids.get(0));
 
@@ -204,7 +204,7 @@
 
         this.mvc.perform(post)
                 .andExpect(MockMvcResultMatchers.status().isSeeOther())
-                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/groups"));
+                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/groups?version=NULL"));
 
         Assert.assertEquals("Must have one more group", GROUP_NB + 1,
                 this.groupsRepository.count());
@@ -410,7 +410,7 @@
 
         this.mvc.perform(post)
                 .andExpect(MockMvcResultMatchers.status().isSeeOther())
-                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/groups"));
+                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/groups?version=NULL"));
 
         Assert.assertEquals("Must have one less space", GROUP_NB - 1,
                 this.groupsRepository.count());
@@ -441,7 +441,7 @@
 
         this.mvc.perform(post)
                 .andExpect(MockMvcResultMatchers.status().isSeeOther())
-                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/groups"));
+                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/groups?version=NULL"));
 
         Assert.assertEquals("Must have the same nb of group", GROUP_NB,
                 this.groupsRepository.count());
@@ -462,7 +462,7 @@
 
         this.mvc.perform(post)
                 .andExpect(MockMvcResultMatchers.status().isSeeOther())
-                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/groups"));
+                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/groups?version=NULL"));
 
         Group group = this.groupsRepository.findOne(this.groupsUuids.get(0));
 
--- a/server/src/test/java/org/iri_research/renkan/test/controller/SpacesAdminControllerTest.java	Tue Feb 11 10:18:29 2014 +0100
+++ b/server/src/test/java/org/iri_research/renkan/test/controller/SpacesAdminControllerTest.java	Thu Feb 13 11:07:18 2014 +0100
@@ -120,7 +120,7 @@
 
         this.mvc.perform(post)
                 .andExpect(MockMvcResultMatchers.status().isSeeOther())
-                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/spaces"));
+                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/spaces?version=NULL"));
 
         Space sp = this.spacesRepository.findOne(this.spacesUuids.get(0));
 
@@ -148,7 +148,7 @@
 
         this.mvc.perform(post)
                 .andExpect(MockMvcResultMatchers.status().isSeeOther())
-                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/spaces"));
+                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/spaces?version=NULL"));
 
         Assert.assertEquals("Must have one more space", SPACE_NB + 1,
                 this.spacesRepository.count());
@@ -481,7 +481,7 @@
 
         this.mvc.perform(post)
                 .andExpect(MockMvcResultMatchers.status().isSeeOther())
-                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/spaces"));
+                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/spaces?version=NULL"));
 
         Assert.assertEquals("Must have one less space", SPACE_NB - 1,
                 this.spacesRepository.count());
@@ -512,7 +512,7 @@
 
         this.mvc.perform(post)
                 .andExpect(MockMvcResultMatchers.status().isSeeOther())
-                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/spaces"));
+                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/spaces?version=NULL"));
 
         Assert.assertEquals("Must have the same nb of space", SPACE_NB,
                 this.spacesRepository.count());
--- a/server/src/test/java/org/iri_research/renkan/test/controller/UsersAdminControllerTest.java	Tue Feb 11 10:18:29 2014 +0100
+++ b/server/src/test/java/org/iri_research/renkan/test/controller/UsersAdminControllerTest.java	Thu Feb 13 11:07:18 2014 +0100
@@ -177,7 +177,7 @@
 
         this.mvc.perform(post)
                 .andExpect(MockMvcResultMatchers.status().isSeeOther())
-                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/users"));
+                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/users?version=NULL"));
 
         User user = this.usersRepository.findOne(this.usersUuids.get(0));
 
@@ -206,7 +206,7 @@
 
         this.mvc.perform(post)
                 .andExpect(MockMvcResultMatchers.status().isSeeOther())
-                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/users"));
+                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/users?version=NULL"));
 
         Assert.assertEquals("Must have one more space", USER_NB + 1,
                 this.usersRepository.count());
@@ -441,7 +441,7 @@
 
         this.mvc.perform(post)
                 .andExpect(MockMvcResultMatchers.status().isSeeOther())
-                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/users"));
+                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/users?version=NULL"));
 
         Assert.assertEquals("Must have one less user", USER_NB - 1,
                 this.usersRepository.count());
@@ -472,7 +472,7 @@
 
         this.mvc.perform(post)
                 .andExpect(MockMvcResultMatchers.status().isSeeOther())
-                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/users"));
+                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/users?version=NULL"));
 
         Assert.assertEquals("Must have the same nb of user", USER_NB,
                 this.usersRepository.count());
@@ -528,7 +528,7 @@
 
         this.mvc.perform(post)
                 .andExpect(MockMvcResultMatchers.status().isSeeOther())
-                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/users"));
+                .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/users?version=NULL"));
 
         User user = this.usersRepository.findOne(this.usersUuids.get(0));
 
--- a/server/src/test/resources/org/iri_research/renkan/test/controller/controller-context.xml	Tue Feb 11 10:18:29 2014 +0100
+++ b/server/src/test/resources/org/iri_research/renkan/test/controller/controller-context.xml	Thu Feb 13 11:07:18 2014 +0100
@@ -3,9 +3,9 @@
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
-            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+            http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
             http://www.springframework.org/schema/context
-            http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+            http://www.springframework.org/schema/context/spring-context-3.2.xsd">
     
     <!-- Activates various annotations to be detected in bean classes -->
     <context:annotation-config />
--- a/server/src/test/resources/org/iri_research/renkan/test/repositories/repositories-context.xml	Tue Feb 11 10:18:29 2014 +0100
+++ b/server/src/test/resources/org/iri_research/renkan/test/repositories/repositories-context.xml	Thu Feb 13 11:07:18 2014 +0100
@@ -3,9 +3,9 @@
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
-            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+            http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
             http://www.springframework.org/schema/context
-            http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+            http://www.springframework.org/schema/context/spring-context-3.2.xsd">
     
     <!-- Activates various annotations to be detected in bean classes -->
     <context:annotation-config />
--- a/server/src/test/resources/org/iri_research/renkan/test/rest/rest-context.xml	Tue Feb 11 10:18:29 2014 +0100
+++ b/server/src/test/resources/org/iri_research/renkan/test/rest/rest-context.xml	Thu Feb 13 11:07:18 2014 +0100
@@ -3,9 +3,9 @@
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
-            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+            http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
             http://www.springframework.org/schema/context
-            http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+            http://www.springframework.org/schema/context/spring-context-3.2.xsd">
     
     <!-- Activates various annotations to be detected in bean classes -->
     <context:annotation-config />