core/pkgs/build-support/release/maven-build.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

107 lines
2.6 KiB
Nix
Raw Normal View History

2024-05-02 00:46:19 +00:00
{
stdenv,
lib,
name,
src,
doTest ? true,
doTestCompile ? true,
doJavadoc ? false,
doCheckstyle ? false,
doRelease ? false,
includeTestClasses ? true,
extraMvnFlags ? "",
...
}@args:
let
mvnFlags = lib.escapeShellArgs [
"-Dmaven.repo.local=$M2_REPO"
(lib.optionalString (!doTest) "-Dmaven.test.skip.exec=true")
"${extraMvnFlags}"
];
in
stdenv.mkDerivation (
{
inherit name src;
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";
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
setupPhase = ''
runHook preSetupPhase
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
mkdir -p $out/nix-support
export LANG="en_US.UTF-8"
export LOCALE_ARCHIVE=$glibcLocales/lib/locale/locale-archive
export M2_REPO=$TMPDIR/repository
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
runHook postSetupPhase
'';
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
mvnCompile = ''
mvn compile ${mvnFlags}
'';
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
mvnTestCompile = ''
mvn test-compile ${mvnFlags}
'';
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
mvnTestJar = ''
mvn jar:test-jar ${mvnFlags}
'';
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
mvnTest = ''
mvn test ${mvnFlags}
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
if [ -d target/site/cobertura ] ; then
echo "report coverage $out/site/cobertura" >> $out/nix-support/hydra-build-products
fi
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
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
'';
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
mvnJavadoc = ''
mvn javadoc:javadoc ${mvnFlags}
echo "report javadoc $out/site/apidocs" >> $out/nix-support/hydra-build-products
'';
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
mvnCheckstyle = ''
mvn checkstyle:checkstyle ${mvnFlags}
echo "report checkstyle $out/site/checkstyle.html" >> $out/nix-support/hydra-build-products
'';
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
mvnJar = ''
mvn jar:jar ${mvnFlags}
'';
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
mvnAssembly = ''
mvn assembly:assembly -Dmaven.test.skip=true ${mvnFlags}
'';
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
mvnRelease = ''
mkdir -p $out/release
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
zip=$(ls target/*.zip| head -1)
releaseName=$(basename $zip .zip)
releaseName="$releaseName-r${toString src.rev or "0"}"
cp $zip $out/release/$releaseName.zip
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
echo "$releaseName" > $out/nix-support/hydra-release-name
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
${lib.optionalString doRelease ''
echo "file zip $out/release/$releaseName.zip" >> $out/nix-support/hydra-build-products
''}
'';
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
finalPhase = ''
if [ -d target/site ] ; then
cp -R target/site $out/
echo "report site $out/site" >> $out/nix-support/hydra-build-products
fi
'';
}
// args
)