@weixin
        
        2015-07-13T20:57:22.000000Z
        字数 3113
        阅读 2345
    active-active git maven
#!/bin/bash# before push, do unit testcd app/webappmvn clean test
pretty simple.  
if you go to .git/hooks, you would find a file pre-push.sample, take it as a reference. then name the above script pre-push, no suffix, put it to .git/hooks folder. 
then give permissin: 
chmod +x pre-push.
then each time you do push, the unit test would be triggered.
you can not directly push the .git/hooks. so you need to find some other ways to do it. Here is my step: 
- create a folder, such as buildtool in your project, then put the pre-push script there. 
- write a Makefile, it would copy the script to .git/hooks, and assign it appropriate permission. 
- let maven to call make to build the makefile.
Makefile
SHELL = /bin/bashbuild : copyfile assignpermissioncopyfile :if [ -d "../../../.git/hooks" ]; then \cp -f pre-push ../../../.git/hooks; \fiassignpermission :if [ -e "../../../.git/hooks/pre-push" ]; then \chmod +x ../../../.git/hooks/pre-push; \fi
notice I use the relative path because the project I'm working on is a module of a bigger project.
for the parent pom.xml, I did something like this:
<pluginManagement><plugins>......<plugin><artifactId>maven-antrun-plugin</artifactId><version>1.8</version></plugin>
then in the project pom.xml, the change is :
<plugin><artifactId>maven-antrun-plugin</artifactId><executions><execution><id>make</id><phase>generate-sources</phase><goals><goal>run</goal></goals><configuration><target name="make"><exec executable="make" failonerror="true"dir="${project.basedir}/buildtool"/></target></configuration></execution></executions></plugin>
use maven-antrun-plugin to trigger the make command. 
then it is done.
then each time when other developer who run mvn clean install, he would see something like this :
[INFO] --- maven-antrun-plugin:1.8:run (make) @ webapp ---[INFO] Executing tasksmake:[exec] if [ -d "../../../.git/hooks" ]; then \[exec] cp -f pre-push ../../../.git/hooks; \[exec] fi[exec] if [ -e "../../../.git/hooks/pre-push" ]; then \[exec] chmod +x ../../../.git/hooks/pre-push; \[exec] fi[INFO] Executed tasks
then when they do push, unit test would be triggered:
842 [main] DEBUG - ==> Parameters: 98765432(Long), qbo(String)842 [main] DEBUG - <== Total: 1843 [main] DEBUG - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5d2a4eed]Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.363 secJul 13, 2015 1:29:30 PM org.springframework.context.support.GenericApplicationContext doCloseINFO: Closing org.springframework.context.support.GenericApplicationContext@cb644e: startup date [Mon Jul 13 13:29:29 PDT 2015]; root of context hierarchyResults :Tests run: 6, Failures: 0, Errors: 0, Skipped: 0[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 4.082 s[INFO] Finished at: 2015-07-13T13:29:30-07:00[INFO] Final Memory: 29M/491M[INFO] ------------------------------------------------------------------------Counting objects: 4, done.Delta compression using up to 8 threads.Compressing objects: 100% (4/4), done.Writing objects: 100% (4/4), 390 bytes | 0 bytes/s, done.Total 4 (delta 2), reused 0 (delta 0)To https://github.intuit.com/SBG/dispatcher-service/044f122..31dbf12 master -> master