2010-03-05 13:09:22 +03:00
|
|
|
{ src
|
2010-10-20 12:23:52 +04:00
|
|
|
, pkgs
|
|
|
|
, stdenv ? pkgs.stdenv
|
2010-03-05 13:09:22 +03:00
|
|
|
, name
|
|
|
|
, antTargets ? []
|
|
|
|
, jars ? []
|
|
|
|
, jarWrappers ? []
|
|
|
|
, antProperties ? []
|
2010-06-07 17:58:13 +04:00
|
|
|
, antBuildInputs ? []
|
|
|
|
, buildfile ? "build.xml"
|
2014-01-03 18:58:20 +04:00
|
|
|
, ant ? pkgs.ant
|
2015-01-02 02:49:20 +03:00
|
|
|
, jre ? pkgs.jdk
|
2010-10-20 12:23:52 +04:00
|
|
|
, hydraAntLogger ? pkgs.hydraAntLogger
|
2014-08-14 09:20:44 +04:00
|
|
|
, zip ? pkgs.zip
|
|
|
|
, unzip ? pkgs.unzip
|
2010-03-05 13:09:22 +03:00
|
|
|
, ... } @ args:
|
|
|
|
|
|
|
|
let
|
2010-10-19 17:43:29 +04:00
|
|
|
antFlags = "-f ${buildfile} " + stdenv.lib.concatMapStrings ({name, value}: "-D${name}=${value} " ) antProperties ;
|
2010-10-20 16:30:03 +04:00
|
|
|
lib = stdenv.lib;
|
2010-03-05 13:09:22 +03:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation (
|
|
|
|
|
|
|
|
{
|
2010-10-20 16:30:03 +04:00
|
|
|
inherit jre ant;
|
2010-03-05 13:09:22 +03:00
|
|
|
showBuildStats = true;
|
|
|
|
|
|
|
|
postPhases =
|
|
|
|
["generateWrappersPhase" "finalPhase"];
|
|
|
|
|
2016-07-24 22:33:45 +03:00
|
|
|
prePhases =
|
2010-03-05 13:35:11 +03:00
|
|
|
["antSetupPhase"];
|
|
|
|
|
2010-06-07 17:58:13 +04:00
|
|
|
antSetupPhase = with stdenv.lib; ''
|
2010-03-05 13:35:11 +03:00
|
|
|
if test "$hydraAntLogger" != "" ; then
|
2014-01-09 16:01:38 +04:00
|
|
|
export ANT_ARGS="-logger org.hydra.ant.HydraLogger -lib `ls $hydraAntLogger/share/java/*.jar | head -1`"
|
2010-03-05 13:35:11 +03:00
|
|
|
fi
|
2010-06-07 17:58:13 +04:00
|
|
|
for abi in ${concatStringsSep " " (map (f: "`find ${f} -name '*.jar'`") antBuildInputs)}; do
|
|
|
|
export ANT_ARGS="$ANT_ARGS -lib $abi"
|
|
|
|
done
|
2010-03-05 13:35:11 +03:00
|
|
|
'';
|
|
|
|
|
2010-03-05 13:09:22 +03:00
|
|
|
installPhase = ''
|
2016-07-24 22:33:45 +03:00
|
|
|
runHook preInstall
|
|
|
|
|
2014-01-09 16:01:38 +04:00
|
|
|
mkdir -p $out/share/java
|
2016-07-24 22:33:45 +03:00
|
|
|
${ if jars == [] then ''
|
2014-01-09 16:01:38 +04:00
|
|
|
find . -name "*.jar" | xargs -I{} cp -v {} $out/share/java
|
2010-03-05 13:09:22 +03:00
|
|
|
'' else stdenv.lib.concatMapStrings (j: ''
|
2014-01-09 16:01:38 +04:00
|
|
|
cp -v ${j} $out/share/java
|
2010-03-05 13:09:22 +03:00
|
|
|
'') jars }
|
2014-08-14 09:20:44 +04:00
|
|
|
|
|
|
|
. ${./functions.sh}
|
2014-01-09 16:01:38 +04:00
|
|
|
for j in $out/share/java/*.jar ; do
|
2014-08-14 09:20:44 +04:00
|
|
|
canonicalizeJar $j
|
2010-06-07 18:24:57 +04:00
|
|
|
echo file jar $j >> $out/nix-support/hydra-build-products
|
2010-06-07 17:58:13 +04:00
|
|
|
done
|
2016-07-24 22:33:45 +03:00
|
|
|
|
|
|
|
runHook postInstall
|
2010-03-05 13:09:22 +03:00
|
|
|
'';
|
|
|
|
|
2016-07-24 22:33:45 +03:00
|
|
|
generateWrappersPhase =
|
|
|
|
let
|
2014-01-09 16:01:38 +04:00
|
|
|
cp = w: "-cp '${lib.optionalString (w ? classPath) w.classPath}${lib.optionalString (w ? mainClass) ":$out/share/java/*"}'";
|
2010-10-20 16:30:03 +04:00
|
|
|
in
|
2016-07-24 22:33:45 +03:00
|
|
|
''
|
2010-03-05 13:09:22 +03:00
|
|
|
header "Generating jar wrappers"
|
|
|
|
'' + (stdenv.lib.concatMapStrings (w: ''
|
|
|
|
|
2012-01-19 00:16:00 +04:00
|
|
|
mkdir -p $out/bin
|
2010-03-23 23:54:59 +03:00
|
|
|
cat >> $out/bin/${w.name} <<EOF
|
2017-01-15 15:44:52 +03:00
|
|
|
#!${stdenv.shell}
|
2010-03-05 13:09:22 +03:00
|
|
|
export JAVA_HOME=$jre
|
2010-10-20 16:30:03 +04:00
|
|
|
$jre/bin/java ${cp w} ${if w ? mainClass then w.mainClass else "-jar ${w.jar}"} \$@
|
2010-03-05 13:09:22 +03:00
|
|
|
EOF
|
|
|
|
|
|
|
|
chmod a+x $out/bin/${w.name} || exit 1
|
|
|
|
'') jarWrappers) + ''
|
|
|
|
closeNest
|
|
|
|
'';
|
|
|
|
|
2016-07-24 22:33:45 +03:00
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
'' + (if antTargets == [] then ''
|
2010-03-05 13:09:22 +03:00
|
|
|
header "Building default ant target"
|
|
|
|
ant ${antFlags}
|
|
|
|
closeNest
|
|
|
|
'' else stdenv.lib.concatMapStrings (t: ''
|
|
|
|
header "Building '${t}' target"
|
2016-07-24 22:33:45 +03:00
|
|
|
ant ${antFlags} ${t}
|
2010-03-05 13:09:22 +03:00
|
|
|
closeNest
|
2016-07-24 22:33:45 +03:00
|
|
|
'') antTargets) + ''
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
2010-03-05 13:09:22 +03:00
|
|
|
|
|
|
|
finalPhase =
|
|
|
|
''
|
|
|
|
# Propagate the release name of the source tarball. This is
|
|
|
|
# to get nice package names in channels.
|
|
|
|
if test -e $origSrc/nix-support/hydra-release-name; then
|
|
|
|
cp $origSrc/nix-support/hydra-release-name $out/nix-support/hydra-release-name
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
|
2016-07-24 22:33:45 +03:00
|
|
|
// removeAttrs args ["antProperties" "buildInputs" "pkgs" "jarWrappers"] //
|
2010-03-05 13:09:22 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
name = name + (if src ? version then "-" + src.version else "");
|
2016-07-24 22:33:45 +03:00
|
|
|
|
2014-08-14 09:20:44 +04:00
|
|
|
buildInputs = [ant jre zip unzip] ++ stdenv.lib.optional (args ? buildInputs) args.buildInputs ;
|
2010-10-20 12:23:52 +04:00
|
|
|
|
2010-03-05 13:09:22 +03:00
|
|
|
postHook = ''
|
2012-01-19 00:16:00 +04:00
|
|
|
mkdir -p $out/nix-support
|
2010-03-05 13:09:22 +03:00
|
|
|
echo "$system" > $out/nix-support/system
|
2012-07-13 22:58:39 +04:00
|
|
|
. ${./functions.sh}
|
2010-03-05 13:09:22 +03:00
|
|
|
|
|
|
|
origSrc=$src
|
2014-11-05 20:21:44 +03:00
|
|
|
src=$(findTarball $src)
|
2016-07-24 22:33:45 +03:00
|
|
|
'';
|
2010-03-05 13:09:22 +03:00
|
|
|
}
|
|
|
|
)
|