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