nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 stdenv,
3 lib,
4 name,
5 src,
6 doTest ? true,
7 doTestCompile ? true,
8 doJavadoc ? false,
9 doCheckstyle ? false,
10 doRelease ? false,
11 includeTestClasses ? true,
12 extraMvnFlags ? "",
13 ...
14}@args:
15
16let
17 mvnFlags = lib.escapeShellArgs [
18 "-Dmaven.repo.local=$M2_REPO"
19 (lib.optionalString (!doTest) "-Dmaven.test.skip.exec=true")
20 "${extraMvnFlags}"
21 ];
22in
23
24stdenv.mkDerivation (
25 {
26 inherit name src;
27 phases = "setupPhase unpackPhase patchPhase mvnCompile ${lib.optionalString doTestCompile "mvnTestCompile mvnTestJar"} ${lib.optionalString doTest "mvnTest"} ${lib.optionalString doJavadoc "mvnJavadoc"} ${lib.optionalString doCheckstyle "mvnCheckstyle"} mvnJar mvnAssembly mvnRelease finalPhase";
28
29 setupPhase = ''
30 runHook preSetupPhase
31
32 mkdir -p $out/nix-support
33 export LANG="en_US.UTF-8"
34 export LOCALE_ARCHIVE=$glibcLocales/lib/locale/locale-archive
35 export M2_REPO=$TMPDIR/repository
36
37 runHook postSetupPhase
38 '';
39
40 mvnCompile = ''
41 mvn compile ${mvnFlags}
42 '';
43
44 mvnTestCompile = ''
45 mvn test-compile ${mvnFlags}
46 '';
47
48 mvnTestJar = ''
49 mvn jar:test-jar ${mvnFlags}
50 '';
51
52 mvnTest = ''
53 mvn test ${mvnFlags}
54
55 if [ -d target/site/cobertura ] ; then
56 echo "report coverage $out/site/cobertura" >> $out/nix-support/hydra-build-products
57 fi
58
59 if [ -d target/surefire-reports ] ; then
60 mvn surefire-report:report-only
61 echo "report coverage $out/site/surefire-report.html" >> $out/nix-support/hydra-build-products
62 fi
63 '';
64
65 mvnJavadoc = ''
66 mvn javadoc:javadoc ${mvnFlags}
67 echo "report javadoc $out/site/apidocs" >> $out/nix-support/hydra-build-products
68 '';
69
70 mvnCheckstyle = ''
71 mvn checkstyle:checkstyle ${mvnFlags}
72 echo "report checkstyle $out/site/checkstyle.html" >> $out/nix-support/hydra-build-products
73 '';
74
75 mvnJar = ''
76 mvn jar:jar ${mvnFlags}
77 '';
78
79 mvnAssembly = ''
80 mvn assembly:assembly -Dmaven.test.skip=true ${mvnFlags}
81 '';
82
83 mvnRelease = ''
84 mkdir -p $out/release
85
86 zip=$(ls target/*.zip| head -1)
87 releaseName=$(basename $zip .zip)
88 releaseName="$releaseName-r${toString src.rev or "0"}"
89 cp $zip $out/release/$releaseName.zip
90
91 echo "$releaseName" > $out/nix-support/hydra-release-name
92
93 ${lib.optionalString doRelease ''
94 echo "file zip $out/release/$releaseName.zip" >> $out/nix-support/hydra-build-products
95 ''}
96 '';
97
98 finalPhase = ''
99 if [ -d target/site ] ; then
100 cp -R target/site $out/
101 echo "report site $out/site" >> $out/nix-support/hydra-build-products
102 fi
103 '';
104 }
105 // args
106)