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