Blame view

src/main/java/etunicorn/GitHeaderInterceptor.java 1.95 KB
9182ba39   Geoffrey PREUD'HOMME   Ça affiche le num...
1
2
3
4
5
6
  package etunicorn;
  
  import org.springframework.web.servlet.ModelAndView;
  import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
  
  import javax.servlet.http.HttpServletResponse;
3064f583   Geoffrey PREUD'HOMME   Copyright
7
8
9
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
9182ba39   Geoffrey PREUD'HOMME   Ça affiche le num...
10
11
  
  /**
3064f583   Geoffrey PREUD'HOMME   Copyright
12
13
14
   * etunicorn-server
   * Copyright © 2017 Le Club Info Polytech Lille
   * Tous droits réservés
9182ba39   Geoffrey PREUD'HOMME   Ça affiche le num...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
   */
  public class GitHeaderInterceptor extends HandlerInterceptorAdapter {
  
      private String version = "inconnue";
  
      public GitHeaderInterceptor() {
          super();
          try {
              String[] commande = {"git", "describe", "--tags", "--dirty"};
              Process p = Runtime.getRuntime().exec(commande);
              BufferedReader output = new BufferedReader(new InputStreamReader(p.getInputStream()));
              p.waitFor();
              this.version = output.readLine();
          } catch(IOException e) {
          } catch (InterruptedException e) {
          }
      }
  
      @Override
      public boolean preHandle(javax.servlet.http.HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
          response.addHeader("X-Version", this.version);
          return super.preHandle(request, response, handler);
      }
  
      @Override
      public void postHandle(javax.servlet.http.HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
          super.postHandle(request, response, handler, modelAndView);
      }
  
      @Override
      public void afterCompletion(javax.servlet.http.HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
          super.afterCompletion(request, response, handler, ex);
      }
  
      @Override
      public void afterConcurrentHandlingStarted(javax.servlet.http.HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
          super.afterConcurrentHandlingStarted(request, response, handler);
      }
  }