2010-03-05 11:09:22 +01:00
|
|
|
{ src
|
2010-10-20 10:23:52 +02:00
|
|
|
, pkgs
|
2021-01-24 04:02:59 +01:00
|
|
|
, lib
|
2010-10-20 10:23:52 +02:00
|
|
|
, 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
|
2015-01-02 00:49:20 +01:00
|
|
|
, jre ? pkgs.jdk
|
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
|
2021-01-24 04:02:59 +01:00
|
|
|
antFlags = "-f ${buildfile} " + lib.concatMapStrings ({name, value}: "-D${name}=${value} " ) antProperties ;
|
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"];
|
|
|
|
|
2016-07-24 21:33:45 +02:00
|
|
|
prePhases =
|
2010-03-05 11:35:11 +01:00
|
|
|
["antSetupPhase"];
|
|
|
|
|
2021-01-24 04:02:59 +01:00
|
|
|
antSetupPhase = with 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 = ''
|
2016-07-24 21:33:45 +02:00
|
|
|
runHook preInstall
|
|
|
|
|
2014-01-09 13:01:38 +01:00
|
|
|
mkdir -p $out/share/java
|
2016-07-24 21:33:45 +02:00
|
|
|
${ if jars == [] then ''
|
2014-01-09 13:01:38 +01:00
|
|
|
find . -name "*.jar" | xargs -I{} cp -v {} $out/share/java
|
2021-01-24 04:02:59 +01:00
|
|
|
'' else 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
|
2016-07-24 21:33:45 +02:00
|
|
|
|
|
|
|
runHook postInstall
|
2010-03-05 11:09:22 +01:00
|
|
|
'';
|
|
|
|
|
2016-07-24 21:33:45 +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
|
2016-07-24 21:33:45 +02:00
|
|
|
''
|
2010-03-05 11:09:22 +01:00
|
|
|
header "Generating jar wrappers"
|
2021-01-24 04:02:59 +01:00
|
|
|
'' + (lib.concatMapStrings (w: ''
|
2010-03-05 11:09:22 +01:00
|
|
|
|
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
|
2019-02-26 12:45:54 +01:00
|
|
|
#!${pkgs.runtimeShell}
|
2010-03-05 11:09:22 +01:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
|
2016-07-24 21:33:45 +02:00
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
'' + (if antTargets == [] then ''
|
2010-03-05 11:09:22 +01:00
|
|
|
header "Building default ant target"
|
|
|
|
ant ${antFlags}
|
|
|
|
closeNest
|
2021-01-24 04:02:59 +01:00
|
|
|
'' else lib.concatMapStrings (t: ''
|
2010-03-05 11:09:22 +01:00
|
|
|
header "Building '${t}' target"
|
2016-07-24 21:33:45 +02:00
|
|
|
ant ${antFlags} ${t}
|
2010-03-05 11:09:22 +01:00
|
|
|
closeNest
|
2016-07-24 21:33:45 +02:00
|
|
|
'') antTargets) + ''
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
2010-03-05 11:09:22 +01: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
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
|
2021-01-24 04:02:59 +01:00
|
|
|
// removeAttrs args ["antProperties" "buildInputs" "pkgs" "lib" "jarWrappers"] //
|
2010-03-05 11:09:22 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
name = name + (if src ? version then "-" + src.version else "");
|
2016-07-24 21:33:45 +02:00
|
|
|
|
2021-02-20 22:01:53 +01:00
|
|
|
nativeBuildInputs = [ unzip ];
|
|
|
|
buildInputs = [ant jre zip] ++ 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
|
2014-11-05 18:21:44 +01:00
|
|
|
src=$(findTarball $src)
|
2016-07-24 21:33:45 +02:00
|
|
|
'';
|
2010-03-05 11:09:22 +01:00
|
|
|
}
|
|
|
|
)
|