summary refs log tree commit diff
path: root/pkgs/build-support/release/maven-build.nix
blob: 71eb63b850d5b124af2cd84b6fcd3e891002db54 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{ stdenv
, name
, src
, doTest ? true
, doTestCompile ? true
, doJavadoc ? false
, doCheckstyle ? false
, doRelease ? false
, includeTestClasses ? true
, extraMvnFlags ? ""
, ...
} @ args :

let 
  mvnFlags = "-Dmaven.repo.local=$M2_REPO ${if doTest then "" else "-Dmaven.test.skip.exec=true"} ${extraMvnFlags}";
in

stdenv.mkDerivation ( {
  inherit name src; 
  phases = "setupPhase unpackPhase patchPhase mvnCompile ${if doTestCompile then "mvnTestCompile mvnTestJar" else ""} ${if doTest then "mvnTest" else ""} ${if doJavadoc then "mvnJavadoc" else ""} ${if doCheckstyle then "mvnCheckstyle" else ""} mvnJar mvnAssembly mvnRelease finalPhase";

  setupPhase = ''
    runHook preSetupPhase

    mkdir -p $out/nix-support
    export LANG="en_US.UTF-8"
    export LOCALE_ARCHIVE=$glibcLocales/lib/locale/locale-archive
    export M2_REPO=$TMPDIR/repository

    runHook postSetupPhase
  '';

  mvnCompile = ''
    mvn compile ${mvnFlags}
  '';  

  mvnTestCompile = ''
    mvn test-compile ${mvnFlags}
  '';  

  mvnTestJar = ''
    mvn jar:test-jar ${mvnFlags}
  '';  

  mvnTest = ''
    mvn test ${mvnFlags}

    if [ -d target/site/cobertura ] ; then
      echo "report coverage $out/site/cobertura" >> $out/nix-support/hydra-build-products
    fi

    if [ -d target/surefire-reports ] ; then
      mvn surefire-report:report-only
      echo "report coverage $out/site/surefire-report.html" >> $out/nix-support/hydra-build-products
    fi
  '';  

  mvnJavadoc = ''
    mvn javadoc:javadoc ${mvnFlags}
    echo "report javadoc $out/site/apidocs" >> $out/nix-support/hydra-build-products
  '';  

  mvnCheckstyle = ''
    mvn checkstyle:checkstyle ${mvnFlags}
    echo "report checkstyle $out/site/checkstyle.html" >> $out/nix-support/hydra-build-products
  '';  

  mvnJar = ''
    mvn jar:jar ${mvnFlags}
  '';  

  mvnAssembly = ''
    mvn assembly:assembly -Dmaven.test.skip=true ${mvnFlags}
  '';

  mvnRelease = ''
    mkdir -p $out/release

    zip=$(ls target/*.zip| head -1)
    releaseName=$(basename $zip .zip)
    releaseName="$releaseName-r${toString src.rev or "0"}"
    cp $zip $out/release/$releaseName.zip
    
    echo "$releaseName" > $out/nix-support/hydra-release-name

    ${if doRelease then  ''
    echo "file zip $out/release/$releaseName.zip" >> $out/nix-support/hydra-build-products
    '' else ""}
  '';  

  finalPhase = ''
    if [ -d target/site ] ; then
      cp -R target/site $out/
      echo "report site $out/site" >> $out/nix-support/hydra-build-products
    fi
  '';
} // args 
)